From nobody Fri Apr 3 10:04:29 2026 Received: from out198-14.us.a.mail.aliyun.com (out198-14.us.a.mail.aliyun.com [47.90.198.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4337032E72F; Wed, 1 Apr 2026 02:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.198.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775010243; cv=none; b=loWLFokcL9PShekZrkpE7nSG1nfsTZU2Xmye32iUPbYI0uz8xFPaLpFAMVV3KmoLsDLOEAI3oDmTcRkaW1I7u9VXddgktjfRaQOkpz0s2F7jTydbH5yDz+oUS88yvZdzJH1NCN1M52KXsnCjGp/4aukJRSHt8I+0Xa6/ScLjPHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775010243; c=relaxed/simple; bh=ypCrhlJZ7hOcGOks+Pgl+cFN+ALiS2brilsUhnZ/IFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lYfqYYkaq+fnKZpAz5ixJLHRHyKhENheV+YGSm8FVhOzllt38uwGkNy8B4grgpU7Do990/WBr5k5uPXBFBj3CvX22rKjiwzy4YSqlQ5sj0b+ZLLVOr5pSDVvnK9eM5b0Z97p0e6praPnhG7VEwODNGdHstO3GAZEiVeYt+adu34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nebula-matrix.com; spf=pass smtp.mailfrom=nebula-matrix.com; arc=none smtp.client-ip=47.90.198.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nebula-matrix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nebula-matrix.com X-Alimail-AntiSpam: AC=CONTINUE;BC=0.06712908|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_alarm|0.00656462-0.000511196-0.992924;FP=14588669981210861058|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037006180;MF=illusion.wang@nebula-matrix.com;NM=1;PH=DS;RN=20;RT=20;SR=0;TI=SMTPD_---.h2VrTUz_1775010214; Received: from localhost.localdomain(mailfrom:illusion.wang@nebula-matrix.com fp:SMTPD_---.h2VrTUz_1775010214 cluster:ay29) by smtp.aliyun-inc.com; Wed, 01 Apr 2026 10:23:35 +0800 From: "illusion.wang" To: dimon.zhao@nebula-matrix.com, illusion.wang@nebula-matrix.com, alvin.wang@nebula-matrix.com, sam.chen@nebula-matrix.com, netdev@vger.kernel.org Cc: andrew+netdev@lunn.ch, corbet@lwn.net, kuba@kernel.org, linux-doc@vger.kernel.org, lorenzo@kernel.org, pabeni@redhat.com, horms@kernel.org, vadim.fedorenko@linux.dev, lukas.bulwahn@redhat.com, edumazet@google.com, enelsonmoore@gmail.com, skhan@linuxfoundation.org, hkallweit1@gmail.com, jani.nikula@intel.com, linux-kernel@vger.kernel.org (open list) Subject: [PATCH v10 net-next 10/11] net/nebula-matrix: add common/ctrl dev init/reinit operation Date: Wed, 1 Apr 2026 10:23:13 +0800 Message-ID: <20260401022318.28550-11-illusion.wang@nebula-matrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260401022318.28550-1-illusion.wang@nebula-matrix.com> References: <20260401022318.28550-1-illusion.wang@nebula-matrix.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Common Device Setup: nbl_dev_setup_common_dev configures mailbox queues, registers cleanup tasks, and MSI-X interrupt counter initialization. Control Device Setup (optional): nbl_dev_setup_ctrl_dev initializes the chip and configures all channel queues. Signed-off-by: illusion.wang --- .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 169 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 31 ++++ 2 files changed, 200 insertions(+) diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c b/dr= ivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c index 5deb21e35f8e..4c97832a25a6 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c @@ -6,6 +6,156 @@ #include #include "nbl_dev.h" =20 +static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) +{ + struct nbl_dev_common *dev_common =3D dev_mgt->common_dev; + struct nbl_msix_info *msix_info =3D &dev_common->msix_info; + + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num =3D 1; +} + +/* ---------- Channel config ---------- */ +static int nbl_dev_setup_chan_qinfo(struct nbl_dev_mgt *dev_mgt, u8 chan_t= ype) +{ + struct nbl_channel_ops *chan_ops =3D dev_mgt->chan_ops_tbl->ops; + struct nbl_channel_mgt *priv =3D dev_mgt->chan_ops_tbl->priv; + struct device *dev =3D dev_mgt->common->dev; + int ret; + + if (!chan_ops->check_queue_exist(priv, chan_type)) + return 0; + + ret =3D chan_ops->cfg_chan_qinfo_map_table(priv, chan_type); + if (ret) + dev_err(dev, "setup chan:%d, qinfo map table failed\n", + chan_type); + + return ret; +} + +static int nbl_dev_setup_chan_queue(struct nbl_dev_mgt *dev_mgt, u8 chan_t= ype) +{ + struct nbl_channel_ops *chan_ops =3D dev_mgt->chan_ops_tbl->ops; + struct nbl_channel_mgt *priv =3D dev_mgt->chan_ops_tbl->priv; + int ret =3D 0; + + if (chan_ops->check_queue_exist(priv, chan_type)) + ret =3D chan_ops->setup_queue(priv, chan_type); + + return ret; +} + +static int nbl_dev_remove_chan_queue(struct nbl_dev_mgt *dev_mgt, u8 chan_= type) +{ + struct nbl_channel_ops *chan_ops =3D dev_mgt->chan_ops_tbl->ops; + struct nbl_channel_mgt *priv =3D dev_mgt->chan_ops_tbl->priv; + int ret =3D 0; + + if (chan_ops->check_queue_exist(priv, chan_type)) + ret =3D chan_ops->teardown_queue(priv, chan_type); + + return ret; +} + +static void nbl_dev_register_chan_task(struct nbl_dev_mgt *dev_mgt, + u8 chan_type, struct work_struct *task) +{ + struct nbl_channel_ops *chan_ops =3D dev_mgt->chan_ops_tbl->ops; + + if (chan_ops->check_queue_exist(dev_mgt->chan_ops_tbl->priv, chan_type)) + chan_ops->register_chan_task(dev_mgt->chan_ops_tbl->priv, + chan_type, task); +} + +/* ---------- Tasks config ---------- */ +static void nbl_dev_clean_mailbox_task(struct work_struct *work) +{ + struct nbl_dev_common *common_dev =3D + container_of(work, struct nbl_dev_common, clean_mbx_task); + struct nbl_dev_mgt *dev_mgt =3D common_dev->dev_mgt; + struct nbl_channel_ops *chan_ops =3D dev_mgt->chan_ops_tbl->ops; + + chan_ops->clean_queue_subtask(dev_mgt->chan_ops_tbl->priv, + NBL_CHAN_TYPE_MAILBOX); +} + +/* ---------- Dev init process ---------- */ +static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter) +{ + struct nbl_dev_mgt *dev_mgt =3D adapter->core.dev_mgt; + struct nbl_dispatch_ops *disp_ops =3D dev_mgt->disp_ops_tbl->ops; + struct nbl_dispatch_mgt *priv =3D dev_mgt->disp_ops_tbl->priv; + struct nbl_common_info *common =3D dev_mgt->common; + struct nbl_dev_common *common_dev; + int ret; + + common_dev =3D devm_kzalloc(&adapter->pdev->dev, sizeof(*common_dev), + GFP_KERNEL); + if (!common_dev) + return -ENOMEM; + common_dev->dev_mgt =3D dev_mgt; + + ret =3D nbl_dev_setup_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX); + if (ret) + return ret; + + INIT_WORK(&common_dev->clean_mbx_task, nbl_dev_clean_mailbox_task); + common->vsi_id =3D disp_ops->get_vsi_id(priv, 0, NBL_VSI_DATA); + disp_ops->get_eth_id(priv, common->vsi_id, &common->eth_mode, + &common->eth_id, &common->logic_eth_id); + + nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX, + &common_dev->clean_mbx_task); + + dev_mgt->common_dev =3D common_dev; + nbl_dev_init_msix_cnt(dev_mgt); + return 0; +} + +static void nbl_dev_remove_common_dev(struct nbl_adapter *adapter) +{ + struct nbl_dev_mgt *dev_mgt =3D adapter->core.dev_mgt; + struct nbl_dev_common *common_dev =3D dev_mgt->common_dev; + + if (!common_dev) + return; + + nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX, NULL); + cancel_work_sync(&common_dev->clean_mbx_task); + nbl_dev_remove_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX); +} + +static int nbl_dev_setup_ctrl_dev(struct nbl_adapter *adapter) +{ + struct nbl_dev_mgt *dev_mgt =3D adapter->core.dev_mgt; + struct nbl_dispatch_ops *disp_ops =3D dev_mgt->disp_ops_tbl->ops; + int i, ret; + + ret =3D disp_ops->init_chip_module(dev_mgt->disp_ops_tbl->priv); + if (ret) + goto chip_init_fail; + + for (i =3D 0; i < NBL_CHAN_TYPE_MAX; i++) { + ret =3D nbl_dev_setup_chan_qinfo(dev_mgt, i); + if (ret) + goto setup_chan_q_fail; + } + + return 0; +setup_chan_q_fail: + disp_ops->deinit_chip_module(dev_mgt->disp_ops_tbl->priv); +chip_init_fail: + return ret; +} + +static void nbl_dev_remove_ctrl_dev(struct nbl_adapter *adapter) +{ + struct nbl_dev_mgt *dev_mgt =3D adapter->core.dev_mgt; + struct nbl_dispatch_ops *disp_ops =3D dev_mgt->disp_ops_tbl->ops; + + disp_ops->deinit_chip_module(dev_mgt->disp_ops_tbl->priv); +} + static struct nbl_dev_mgt *nbl_dev_setup_dev_mgt(struct nbl_common_info *c= ommon) { struct nbl_dev_mgt *dev_mgt; @@ -38,11 +188,30 @@ int nbl_dev_init(struct nbl_adapter *adapter) dev_mgt->chan_ops_tbl =3D chan_ops_tbl; adapter->core.dev_mgt =3D dev_mgt; =20 + ret =3D nbl_dev_setup_common_dev(adapter); + if (ret) + return ret; + + if (common->has_ctrl) { + ret =3D nbl_dev_setup_ctrl_dev(adapter); + if (ret) + goto setup_ctrl_dev_fail; + } + return 0; + +setup_ctrl_dev_fail: + nbl_dev_remove_common_dev(adapter); + return ret; } =20 void nbl_dev_remove(struct nbl_adapter *adapter) { + struct nbl_common_info *common =3D &adapter->common; + + if (common->has_ctrl) + nbl_dev_remove_ctrl_dev(adapter); + nbl_dev_remove_common_dev(adapter); } =20 /* ---------- Dev start process ---------- */ diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h b/dr= ivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h index 9b71092b99a0..b51c8a4424c5 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h @@ -18,10 +18,41 @@ #include "../nbl_include/nbl_def_common.h" #include "../nbl_core.h" =20 +#define NBL_STRING_NAME_LEN 32 + +enum nbl_msix_serv_type { + /* virtio_dev has a config vector_id, and the vector_id need is 0 */ + NBL_MSIX_VIRTIO_TYPE =3D 0, + NBL_MSIX_NET_TYPE, + NBL_MSIX_MAILBOX_TYPE, + NBL_MSIX_TYPE_MAX +}; + +struct nbl_msix_serv_info { + char irq_name[NBL_STRING_NAME_LEN]; + u16 num; + u16 base_vector_id; + /* true: hw report msix, hw need to mask actively */ + bool hw_self_mask_en; +}; + +struct nbl_msix_info { + struct nbl_msix_serv_info serv_info[NBL_MSIX_TYPE_MAX]; +}; + +struct nbl_dev_common { + struct nbl_dev_mgt *dev_mgt; + struct nbl_msix_info msix_info; + char mailbox_name[NBL_STRING_NAME_LEN]; + /* for ctrl-dev/net-dev mailbox recv msg */ + struct work_struct clean_mbx_task; +}; + struct nbl_dev_mgt { struct nbl_common_info *common; struct nbl_dispatch_ops_tbl *disp_ops_tbl; struct nbl_channel_ops_tbl *chan_ops_tbl; + struct nbl_dev_common *common_dev; }; =20 #endif --=20 2.47.3