From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out28-148.mail.aliyun.com (out28-148.mail.aliyun.com [115.124.28.148]) (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 95FDB25228D; Mon, 28 Sep 2026 12:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.148 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790599100; cv=none; b=O/tUMTerPo/uxaBLcCkuHZc5a7ndFCIrfY+NIjPIZWOrAHosVrdzBLhHuWMPBEouZ71Lq9nryPnIy4AeTOiXyTqkNHON1XZoFBfNe+a/Jtjvguu5XDkSdZjvvOBUYHfV3N2fvNUGRAmhdghPvBcEmkUbbCJM9/U5OlBNowTBNF8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790599100; c=relaxed/simple; bh=JqTEbRMZt/qRoV2k/yt93V8wYd3uGIEGGN6rjnT6dFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vk3ogaMTn11z/JAVLnbtSDtMPOzIOPyb9644iO/AhgawvEMCBk6s5FBYCqFtGHFCPnHobbBU0l6DLnE+HZSPE9SdbUtvraSaMoC9gyRUM0m//i6LO8VRdPoT8PZuLXEesdU2yqX/HABoP2pXAaTZyVdgnJOd6Ab5MTzhoUjKkJk= 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=115.124.28.148 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.0296641-0.00568381-0.964652;FP=11986132744289129986|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033068016216;MF=illusion.wang@nebula-matrix.com;NM=1;PH=DS;RN=9;RT=9;SR=0;TI=SMTPD_---.jQ6tplI_1790598764; Received: from localhost.localdomain(mailfrom:illusion.wang@nebula-matrix.com fp:SMTPD_---.jQ6tplI_1790598764 cluster:ay29) by smtp.aliyun-inc.com; Mon, 28 Sep 2026 20:32:45 +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: kuba@kernel.org, edumazet@google.com, horms@kernel.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH v30 net-next 5/8] net/nebula-matrix: dispatch: add control-level routing core infrastructure Date: Mon, 28 Sep 2026 20:32:30 +0800 Message-ID: <20260928123237.88994-6-illusion.wang@nebula-matrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260928123237.88994-1-illusion.wang@nebula-matrix.com> References: <20260928123237.88994-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: 8bit From: illusion wang Allocate dispatch management state and ops table, add ctrl_lvl bitmap to track control privileges, and hook init_module/deinit_module wrappers to resource ops. MGT level is only enabled for Control PF. Add kerneldoc for caller permission constraints. Add wire ABI structures with static_assert for upcoming mailbox RPC. Dispatch objects are devm-managed and require no explicit remove logic. Signed-off-by: illusion wang --- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 117 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 23 ++++ .../nbl/nbl_include/nbl_def_dispatch.h | 45 +++++++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 ++ 6 files changed, 196 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h diff --git a/drivers/net/ethernet/nebula-matrix/nbl/Makefile b/drivers/net/ethernet/nebula-matrix/nbl/Makefile index be314b909d66..b7eebd89b4d1 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/Makefile +++ b/drivers/net/ethernet/nebula-matrix/nbl/Makefile @@ -10,4 +10,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_resource.o \ nbl_hw/nbl_interrupt.o \ nbl_hw/nbl_chip.o \ + nbl_core/nbl_dispatch.o \ nbl_main.o diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h index dd24ebec0171..4d8cea8d8ab3 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h @@ -17,12 +17,14 @@ enum { struct nbl_interface { struct nbl_hw_ops_tbl *hw_ops_tbl; struct nbl_resource_ops_tbl *resource_ops_tbl; + struct nbl_dispatch_ops_tbl *dispatch_ops_tbl; struct nbl_channel_ops_tbl *channel_ops_tbl; }; struct nbl_core { struct nbl_hw_mgt *hw_mgt; struct nbl_resource_mgt *res_mgt; + struct nbl_dispatch_mgt *disp_mgt; struct nbl_channel_mgt *chan_mgt; }; diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file mode 100644 index 000000000000..966fee2dec8b --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ +#include +#include +#include "nbl_dispatch.h" + +static void nbl_disp_deinit_module(struct nbl_dispatch_mgt *disp_mgt) +{ + struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; + struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; + + if (res_ops->deinit_module) + res_ops->deinit_module(p); +} + +static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) +{ + struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; + struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; + + if (res_ops->init_module) + return res_ops->init_module(p); + return -EOPNOTSUPP; +} + +static void nbl_disp_set_ctrl_bit(struct nbl_dispatch_mgt *disp_mgt, u32 lvl) +{ + set_bit(lvl, disp_mgt->ctrl_lvl); +} + +static void nbl_disp_refresh_ctrl_ops(struct nbl_dispatch_mgt *disp_mgt) +{ + struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops; + + if (test_bit(NBL_DISP_CTRL_LVL_MGT, disp_mgt->ctrl_lvl)) { + disp_ops->init_module = nbl_disp_init_module; + disp_ops->deinit_module = nbl_disp_deinit_module; + } +} + +static struct nbl_dispatch_mgt * +nbl_disp_setup_disp_mgt(struct nbl_common_info *common) +{ + struct nbl_dispatch_mgt *disp_mgt; + struct device *dev = common->dev; + + disp_mgt = devm_kzalloc(dev, sizeof(*disp_mgt), GFP_KERNEL); + if (!disp_mgt) + return ERR_PTR(-ENOMEM); + + disp_mgt->common = common; + return disp_mgt; +} + +static struct nbl_dispatch_ops_tbl * +nbl_disp_setup_ops(struct device *dev, struct nbl_dispatch_mgt *disp_mgt) +{ + struct nbl_dispatch_ops_tbl *disp_ops_tbl; + struct nbl_dispatch_ops *disp_ops; + + disp_ops_tbl = devm_kzalloc(dev, sizeof(*disp_ops_tbl), GFP_KERNEL); + if (!disp_ops_tbl) + return ERR_PTR(-ENOMEM); + + disp_ops = devm_kzalloc(dev, sizeof(*disp_ops), GFP_KERNEL); + if (!disp_ops) + return ERR_PTR(-ENOMEM); + + disp_ops_tbl->ops = disp_ops; + disp_ops_tbl->priv = disp_mgt; + + return disp_ops_tbl; +} + +int nbl_disp_init(struct nbl_adapter *adapter) +{ + struct nbl_common_info *common = &adapter->common; + struct nbl_dispatch_ops_tbl *disp_ops_tbl; + struct nbl_resource_ops_tbl *res_ops_tbl = + adapter->intf.resource_ops_tbl; + struct nbl_channel_ops_tbl *chan_ops_tbl = + adapter->intf.channel_ops_tbl; + struct device *dev = &adapter->pdev->dev; + struct nbl_dispatch_mgt *disp_mgt; + int ret; + + disp_mgt = nbl_disp_setup_disp_mgt(common); + if (IS_ERR(disp_mgt)) { + ret = PTR_ERR(disp_mgt); + return ret; + } + + disp_ops_tbl = nbl_disp_setup_ops(dev, disp_mgt); + if (IS_ERR(disp_ops_tbl)) { + ret = PTR_ERR(disp_ops_tbl); + return ret; + } + + disp_mgt->res_ops_tbl = res_ops_tbl; + disp_mgt->chan_ops_tbl = chan_ops_tbl; + disp_mgt->disp_ops_tbl = disp_ops_tbl; + adapter->core.disp_mgt = disp_mgt; + adapter->intf.dispatch_ops_tbl = disp_ops_tbl; + + if (common->has_ctrl) + nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_MGT); + + nbl_disp_refresh_ctrl_ops(disp_mgt); + return 0; +} + +void nbl_disp_remove(struct nbl_adapter *adapter) +{ + /* Dispatch structures are allocated via devm */ +} diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file mode 100644 index 000000000000..a7e5802344b4 --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_DISPATCH_H_ +#define _NBL_DISPATCH_H_ +#include "../nbl_include/nbl_include.h" +#include "../nbl_include/nbl_def_channel.h" +#include "../nbl_include/nbl_def_resource.h" +#include "../nbl_include/nbl_def_dispatch.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +struct nbl_dispatch_mgt { + struct nbl_common_info *common; + struct nbl_resource_ops_tbl *res_ops_tbl; + struct nbl_channel_ops_tbl *chan_ops_tbl; + struct nbl_dispatch_ops_tbl *disp_ops_tbl; + DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX); +}; + +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file mode 100644 index 000000000000..b3398591035b --- /dev/null +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Nebula Matrix Limited. + */ + +#ifndef _NBL_DEF_DISPATCH_H_ +#define _NBL_DEF_DISPATCH_H_ + +#include + +struct nbl_dispatch_mgt; +struct nbl_adapter; +enum { + NBL_DISP_CTRL_LVL_MGT, + NBL_DISP_CTRL_LVL_MAX, +}; + +/** + * struct nbl_dispatch_ops - dispatch control plane operation callbacks + * @init_module: dispatch layer initialization, control-PF exclusive, + * caller must check has_ctrl guard + * @deinit_module: dispatch layer cleanup, control-PF exclusive, + * caller must check has_ctrl guard + * + * Warning: init_module/deinit_module are control-PF exclusive. The five + * resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq, + * get_vsi_id, get_eth_id) are PF-only and resolve to either a local + * resource call (control PF) or a mailbox RPC (non-control PF with + * has_net). A function with neither has_ctrl nor has_net leaves these + * pointers NULL; callers must not invoke them on such functions. VFs are + * rejected by the responders with -EPERM. + */ +struct nbl_dispatch_ops { + int (*init_module)(struct nbl_dispatch_mgt *disp_mgt); + void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt); +}; + +struct nbl_dispatch_ops_tbl { + struct nbl_dispatch_ops *ops; + struct nbl_dispatch_mgt *priv; +}; + +int nbl_disp_init(struct nbl_adapter *adapter); +void nbl_disp_remove(struct nbl_adapter *adapter); +#endif diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c index e1a30b5ba0cd..bf4a5ea3e410 100644 --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c @@ -11,6 +11,7 @@ #include "nbl_include/nbl_def_channel.h" #include "nbl_include/nbl_def_hw.h" #include "nbl_include/nbl_def_resource.h" +#include "nbl_include/nbl_def_dispatch.h" #include "nbl_include/nbl_def_common.h" #include "nbl_core.h" @@ -48,7 +49,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret = nbl_res_init_leonis(adapter); if (ret) goto res_init_fail; + + ret = nbl_disp_init(adapter); + if (ret) + goto disp_init_fail; return adapter; +disp_init_fail: + nbl_res_remove_leonis(adapter); res_init_fail: nbl_chan_remove_common(adapter); chan_init_fail: @@ -59,6 +66,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, void nbl_core_remove(struct nbl_adapter *adapter) { + nbl_disp_remove(adapter); nbl_res_remove_leonis(adapter); nbl_chan_remove_common(adapter); nbl_hw_remove_leonis(adapter); -- 2.47.3