Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by "illusion.wang"
Thu, 19 Nov 2026 11:35
[PATCH v35 net-next 6/8] net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id
Author: "illusion.wang"
Date: Thu, 19 Nov 2026 11:35
Date: Thu, 19 Nov 2026 11:35
735 lines
34359 bytes
34359 bytes
From: illusion wang <illusion.wang@nebula-matrix.com>
Add request and response handlers for five dispatch operations:
cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and
get_eth_id. Each op is resolved by capability level: a function with
has_ctrl calls the resource op locally, a function with has_net forwards
it to the management PF over the channel, and a function with neither
leaves the op pointer NULL, so the caller must not invoke it. The
channel framework itself - send_msg, the ACK plumbing and handler
registration - is already in place from the channel layer patch; this one
adds the five message handlers on top of it.
A request builds the payload, sends it synchronously and checks the ACK
length before parsing; a short ACK returns -EBADMSG. A responder rejects
VFs and out-of-range source PF ids with -EPERM, checks the payload length
before parsing, and forwards the resource layer's errno verbatim so the
requester can tell a protocol error from a failed operation. If the
resource op is not installed the responder answers -EOPNOTSUPP. A peer
PF is treated as trusted: hardware and firmware forbid PF passthrough to
guests, so every peer runs this host driver, and the resource layer
bounds the requested vector counts by the global pool.
The cfg_msix_map, destroy_msix_map and set_mailbox_irq requests carry a
caller precondition: clear the mailbox IRQ_RDY flag and use the polling
send path, because the responder changes mailbox MSI-X routing and an
interrupt-driven ACK wakeup cannot be relied on while routing is in
flux. The precondition is documented on struct nbl_dispatch_ops, which
is what callers program against, not only next to the static helpers.
No serialization is added here. The resource layer serializes
concurrent callers itself through intr_mgt->lock, and the dispatch layer
has no mutable state of its own to protect; the read-only
get_vsi_id/get_eth_id paths only touch static init metadata.
This is also the first path that lets a sibling PF tear its MSI-X map
down on the control PF at runtime. That teardown runs while the control
PF is still bus master, which is why the interrupt layer keeps each
coherent map table for the function's lifetime and releases it only in
nbl_intr_mgt_stop(), instead of relying on the per-destroy quiesce
window.
The five responders are registered with the channel layer and owned by
it: they live in the channel's handler xarray and are freed with it, so
nbl_disp_remove() has nothing to undo. Nothing can enter them in this
patch because no mailbox queue is running yet. Once a queue is brought
up, the invariant they rely on is that it must be torn down before
nbl_res_remove_leonis() runs, so no responder can outlive the resource
layer it forwards into.
Signed-off-by: illusion wang <illusion.wang@nebula-matrix.com>
---
.../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 496 ++++++++++++++++++
.../nbl/nbl_include/nbl_def_channel.h | 40 ++
.../nbl/nbl_include/nbl_def_dispatch.h | 45 +-
3 files changed, 578 insertions(+), 3 deletions(-)
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
index 58f6ac834..d256394a5 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
@@ -6,6 +6,163 @@
#include <linux/pci.h>
#include "nbl_dispatch.h"
#include "../nbl_hw/nbl_chip.h"
+#include "../nbl_hw/nbl_interrupt.h"
+
+static int nbl_disp_chan_get_vsi_id_req(struct nbl_dispatch_mgt *disp_mgt,
+ u16 type, u16 *vsi_id)
+{
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_common_info *common = disp_mgt->common;
+ struct nbl_chan_param_get_vsi_id result = { 0 };
+ struct nbl_chan_param_get_vsi_id param = { 0 };
+ struct nbl_chan_send_info chan_send = {0};
+ int ret;
+
+ param.type = cpu_to_le16(type);
+
+ nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+ NBL_CHAN_MSG_GET_VSI_ID,
+ ¶m, sizeof(param), &result,
+ sizeof(result), 1);
+ ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+ if (ret)
+ return ret;
+ if (chan_send.ack_len != sizeof(result)) {
+ dev_err(disp_mgt->common->dev,
+ "get_vsi_id: short ACK, ack_len=%u expected %zu\n",
+ chan_send.ack_len, sizeof(result));
+ return -EBADMSG;
+ }
+ *vsi_id = le16_to_cpu(result.vsi_id);
+ return 0;
+}
+
+static void nbl_disp_chan_get_vsi_id_resp(void *priv, u16 src_id, u16 msg_id,
+ void *data, u32 data_len)
+{
+ struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct device *dev = disp_mgt->common->dev;
+ struct nbl_chan_param_get_vsi_id result = { 0 };
+ struct nbl_chan_param_get_vsi_id param = { 0 };
+ struct nbl_chan_ack_info chan_ack;
+ int err = 0;
+ u16 vsi_id = 0;
+ u32 rel_pf_id;
+ int ret;
+
+ ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+ &rel_pf_id);
+ if (ret) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (rel_pf_id >= disp_mgt->common->max_pf) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (data_len < sizeof(param)) {
+ err = -EBADMSG;
+ goto ack_out;
+ }
+ memcpy(¶m, data, sizeof(param));
+
+ ret = nbl_res_func_id_to_vsi_id(disp_mgt->res_mgt, src_id,
+ le16_to_cpu(param.type), &vsi_id);
+ /* Forward the resource errno verbatim to the requester */
+ if (ret)
+ err = ret;
+
+ result.vsi_id = cpu_to_le16(vsi_id);
+ack_out:
+ nbl_chan_fill_ack_info(&chan_ack, src_id,
+ NBL_CHAN_MSG_GET_VSI_ID, msg_id, err,
+ &result, sizeof(result));
+ ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+ if (ret)
+ dev_err(dev,
+ "channel send ack failed with ret: %d, msg_type: %d\n",
+ ret, NBL_CHAN_MSG_GET_VSI_ID);
+}
+
+static int nbl_disp_chan_get_eth_id_req(struct nbl_dispatch_mgt *disp_mgt,
+ u16 vsi_id, u8 *eth_num, u8 *eth_id,
+ u8 *logic_eth_id)
+{
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_common_info *common = disp_mgt->common;
+ struct nbl_chan_param_get_eth_id result = { 0 };
+ struct nbl_chan_param_get_eth_id param = { 0 };
+ struct nbl_chan_send_info chan_send = {0};
+ int ret;
+
+ param.vsi_id = cpu_to_le16(vsi_id);
+
+ nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+ NBL_CHAN_MSG_GET_ETH_ID,
+ ¶m, sizeof(param), &result,
+ sizeof(result), 1);
+ ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+ if (ret)
+ return ret;
+ if (chan_send.ack_len != sizeof(result)) {
+ dev_err(disp_mgt->common->dev,
+ "get_eth_id: short ACK, ack_len=%u expected %zu\n",
+ chan_send.ack_len, sizeof(result));
+ return -EBADMSG;
+ }
+ *eth_num = result.eth_num;
+ *eth_id = result.eth_id;
+ *logic_eth_id = result.logic_eth_id;
+
+ return 0;
+}
+
+static void nbl_disp_chan_get_eth_id_resp(void *priv, u16 src_id, u16 msg_id,
+ void *data, u32 data_len)
+{
+ struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_chan_param_get_eth_id result = { 0 };
+ struct nbl_chan_param_get_eth_id param = { 0 };
+ struct device *dev = disp_mgt->common->dev;
+ struct nbl_chan_ack_info chan_ack;
+ int err = 0;
+ u32 rel_pf_id;
+ int ret;
+
+ ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+ &rel_pf_id);
+ if (ret) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (rel_pf_id >= disp_mgt->common->max_pf) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (data_len < sizeof(param)) {
+ err = -EBADMSG;
+ goto ack_out;
+ }
+ memcpy(¶m, data, sizeof(param));
+
+ ret = nbl_res_get_eth_id(disp_mgt->res_mgt, src_id,
+ le16_to_cpu(param.vsi_id), &result.eth_num,
+ &result.eth_id, &result.logic_eth_id);
+ /* Forward the resource errno verbatim to the requester */
+ if (ret)
+ err = ret;
+ack_out:
+ nbl_chan_fill_ack_info(&chan_ack, src_id,
+ NBL_CHAN_MSG_GET_ETH_ID, msg_id, err,
+ &result, sizeof(result));
+ ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+ if (ret)
+ dev_err(dev,
+ "channel send ack failed with ret: %d, msg_type: %d\n",
+ ret, NBL_CHAN_MSG_GET_ETH_ID);
+}
static void nbl_disp_deinit_module(struct nbl_dispatch_mgt *disp_mgt)
{
@@ -17,6 +174,326 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)
return nbl_res_chip_init_module(disp_mgt->res_mgt);
}
+static int nbl_disp_cfg_msix_map(struct nbl_dispatch_mgt *disp_mgt,
+ u16 num_net_msix, u16 num_others_msix,
+ bool net_msix_mask_en)
+{
+ struct nbl_common_info *common = disp_mgt->common;
+
+ /*
+ * No core-layer lock is taken here: the resource layer serializes
+ * concurrent callers itself (intr_mgt->lock), and the dispatch
+ * layer has no mutable state of its own for this op to protect.
+ */
+ return nbl_res_intr_cfg_msix_map(disp_mgt->res_mgt, common->mgt_pf,
+ num_net_msix, num_others_msix,
+ net_msix_mask_en);
+}
+
+/*
+ * Precondition: caller must disable mailbox IRQ_RDY and switch send_msg
+ * to the polling path before issuing this RPC. The responder rewrites
+ * the requester's mailbox MSI-X routing during the resource op, so the
+ * ACK cannot rely on interrupt wakeup while routing is in flux.
+ */
+static int
+nbl_disp_chan_cfg_msix_map_req(struct nbl_dispatch_mgt *disp_mgt,
+ u16 num_net_msix, u16 num_others_msix,
+ bool net_msix_mask_en)
+{
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_common_info *common = disp_mgt->common;
+ struct nbl_chan_param_cfg_msix_map param = { 0 };
+ struct nbl_chan_send_info chan_send = {0};
+ int ret;
+
+ param.num_net_msix = cpu_to_le16(num_net_msix);
+ param.num_others_msix = cpu_to_le16(num_others_msix);
+ param.msix_mask_en = cpu_to_le16(!!net_msix_mask_en);
+
+ nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+ NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,
+ ¶m, sizeof(param),
+ NULL, 0, 1);
+ ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+ if (ret)
+ return ret;
+ return 0;
+}
+
+static void nbl_disp_chan_cfg_msix_map_resp(void *priv, u16 src_id, u16 msg_id,
+ void *data, u32 data_len)
+{
+ struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct device *dev = disp_mgt->common->dev;
+ struct nbl_chan_param_cfg_msix_map param = { 0 };
+ struct nbl_chan_ack_info chan_ack;
+ int err = 0;
+ u32 rel_pf_id;
+ int ret;
+
+ ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+ &rel_pf_id);
+ if (ret) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (rel_pf_id >= disp_mgt->common->max_pf) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (data_len < sizeof(param)) {
+ err = -EBADMSG;
+ goto ack_out;
+ }
+ memcpy(¶m, data, sizeof(param));
+
+ /*
+ * The vector counts come from the peer PF. A peer is
+ * trusted: hardware and firmware forbid PF passthrough to
+ * guests (see nbl_get_func_param()), so every peer runs this
+ * same host driver, and the resource layer bounds each count
+ * and their sum by the per-function map table size.
+ *
+ * No per-function quota is enforced: the mailbox is an
+ * internal interface between instances of this same driver,
+ * not a boundary against untrusted code. The only outcome of
+ * an oversized request within those bounds is -EAGAIN for the
+ * functions that configure afterwards; it cannot corrupt
+ * state. The request's slow path (an allocation plus a
+ * quiesce wait under intr_mgt->lock) is bounded per request
+ * and sits inside the same trust boundary.
+ */
+ ret = nbl_res_intr_cfg_msix_map(disp_mgt->res_mgt, src_id,
+ le16_to_cpu(param.num_net_msix),
+ le16_to_cpu(param.num_others_msix),
+ !!le16_to_cpu(param.msix_mask_en));
+ /* Forward the resource errno verbatim to the requester */
+ if (ret)
+ err = ret;
+ack_out:
+ nbl_chan_fill_ack_info(&chan_ack, src_id,
+ NBL_CHAN_MSG_CONFIGURE_MSIX_MAP, msg_id,
+ err, NULL, 0);
+ ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+ if (ret)
+ dev_err(dev,
+ "channel send ack failed with ret: %d, msg_type: %d\n",
+ ret, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP);
+}
+
+/*
+ * Precondition: caller must disable mailbox IRQ_RDY and switch send_msg
+ * to the polling path before issuing this RPC. The responder retargets
+ * the requester's mailbox MSI-X routing during the resource op, so the
+ * ACK cannot rely on interrupt wakeup while routing is in flux.
+ */
+static int nbl_disp_chan_destroy_msix_map_req(struct nbl_dispatch_mgt *disp_mgt)
+{
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_common_info *common = disp_mgt->common;
+ struct nbl_chan_send_info chan_send = {0};
+ int ret;
+
+ nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+ NBL_CHAN_MSG_DESTROY_MSIX_MAP,
+ NULL, 0, NULL, 0, 1);
+ ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+ if (ret)
+ return ret;
+ return 0;
+}
+
+static void nbl_disp_chan_destroy_msix_map_resp(void *priv, u16 src_id,
+ u16 msg_id, void *data,
+ u32 data_len)
+{
+ struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct device *dev = disp_mgt->common->dev;
+ struct nbl_chan_ack_info chan_ack;
+ int err = 0;
+ u32 rel_pf_id;
+ int ret;
+
+ ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+ &rel_pf_id);
+ if (ret) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (rel_pf_id >= disp_mgt->common->max_pf) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ ret = nbl_res_intr_destroy_msix_map(disp_mgt->res_mgt, src_id);
+ /* Forward the resource errno verbatim to the requester */
+ if (ret)
+ err = ret;
+ack_out:
+ nbl_chan_fill_ack_info(&chan_ack, src_id,
+ NBL_CHAN_MSG_DESTROY_MSIX_MAP, msg_id,
+ err, NULL, 0);
+ ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+ if (ret)
+ dev_err(dev,
+ "channel send ack failed with ret: %d, msg_type: %d\n",
+ ret, NBL_CHAN_MSG_DESTROY_MSIX_MAP);
+}
+
+/*
+ * Precondition: caller must disable mailbox IRQ_RDY and switch send_msg
+ * to the polling path before issuing this RPC. The responder rewrites
+ * the requester's own mailbox MSI-X routing (MSIX_IDX / MSIX_IDX_VALID)
+ * before the ACK is sent, so the ACK cannot rely on interrupt wakeup
+ * while routing is in flux.
+ */
+static int nbl_disp_chan_set_mailbox_irq_req(struct nbl_dispatch_mgt *disp_mgt,
+ u16 vector_id, bool en_msix)
+{
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_chan_param_set_mailbox_irq param = { 0 };
+ struct nbl_common_info *common = disp_mgt->common;
+ struct nbl_chan_send_info chan_send = {0};
+ int ret;
+
+ param.vector_id = cpu_to_le16(vector_id);
+ param.en_msix = !!en_msix;
+
+ nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+ NBL_CHAN_MSG_MAILBOX_SET_IRQ,
+ ¶m, sizeof(param), NULL, 0, 1);
+ ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+ if (ret)
+ return ret;
+ return 0;
+}
+
+static void nbl_disp_chan_set_mailbox_irq_resp(void *priv, u16 src_id,
+ u16 msg_id, void *data,
+ u32 data_len)
+{
+ struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_chan_param_set_mailbox_irq param = { 0 };
+ struct device *dev = disp_mgt->common->dev;
+ struct nbl_chan_ack_info chan_ack;
+ int err = 0;
+ u16 vector_id;
+ u32 rel_pf_id;
+ bool en_msix;
+ int ret;
+
+ ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+ &rel_pf_id);
+ if (ret) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (rel_pf_id >= disp_mgt->common->max_pf) {
+ err = -EPERM;
+ goto ack_out;
+ }
+ if (data_len < sizeof(param)) {
+ err = -EBADMSG;
+ goto ack_out;
+ }
+ memcpy(¶m, data, sizeof(param));
+ vector_id = le16_to_cpu(param.vector_id);
+ en_msix = !!param.en_msix;
+
+ ret = nbl_res_intr_set_mailbox_irq(disp_mgt->res_mgt, src_id, vector_id,
+ en_msix);
+ /* Forward the resource errno verbatim to the requester */
+ if (ret)
+ err = ret;
+
+ack_out:
+ nbl_chan_fill_ack_info(&chan_ack, src_id,
+ NBL_CHAN_MSG_MAILBOX_SET_IRQ, msg_id,
+ err, NULL, 0);
+ ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+ if (ret)
+ dev_err(dev,
+ "channel send ack failed with ret: %d, msg_type: %d\n",
+ ret, NBL_CHAN_MSG_MAILBOX_SET_IRQ);
+}
+
+static int nbl_disp_destroy_msix_map(struct nbl_dispatch_mgt *disp_mgt)
+{
+ struct nbl_common_info *common = disp_mgt->common;
+
+ return nbl_res_intr_destroy_msix_map(disp_mgt->res_mgt, common->mgt_pf);
+}
+
+static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,
+ u16 vector_id, bool en_msix)
+{
+ struct nbl_common_info *common = disp_mgt->common;
+
+ return nbl_res_intr_set_mailbox_irq(disp_mgt->res_mgt, common->mgt_pf,
+ vector_id, en_msix);
+}
+
+static int nbl_disp_get_vsi_id(struct nbl_dispatch_mgt *disp_mgt, u16 type,
+ u16 *vsi_id)
+{
+ struct nbl_common_info *common = disp_mgt->common;
+
+ return nbl_res_func_id_to_vsi_id(disp_mgt->res_mgt, common->mgt_pf,
+ type, vsi_id);
+}
+
+static int nbl_disp_get_eth_id(struct nbl_dispatch_mgt *disp_mgt, u16 vsi_id,
+ u8 *eth_num, u8 *eth_id, u8 *logic_eth_id)
+{
+ struct nbl_common_info *common = disp_mgt->common;
+
+ return nbl_res_get_eth_id(disp_mgt->res_mgt, common->mgt_pf, vsi_id,
+ eth_num, eth_id, logic_eth_id);
+}
+
+static int nbl_disp_setup_msg(struct nbl_dispatch_mgt *disp_mgt)
+{
+ struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+ struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv;
+ int ret = 0;
+ int _ret;
+
+ _ret = chan_ops->register_msg(p, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,
+ nbl_disp_chan_cfg_msix_map_resp,
+ disp_mgt);
+ if (_ret < 0 && !ret)
+ ret = _ret;
+
+ _ret = chan_ops->register_msg(p, NBL_CHAN_MSG_DESTROY_MSIX_MAP,
+ nbl_disp_chan_destroy_msix_map_resp,
+ disp_mgt);
+ if (_ret < 0 && !ret)
+ ret = _ret;
+
+ _ret = chan_ops->register_msg(p, NBL_CHAN_MSG_MAILBOX_SET_IRQ,
+ nbl_disp_chan_set_mailbox_irq_resp,
+ disp_mgt);
+ if (_ret < 0 && !ret)
+ ret = _ret;
+
+ _ret = chan_ops->register_msg(p, NBL_CHAN_MSG_GET_VSI_ID,
+ nbl_disp_chan_get_vsi_id_resp,
+ disp_mgt);
+ if (_ret < 0 && !ret)
+ ret = _ret;
+
+ _ret = chan_ops->register_msg(p, NBL_CHAN_MSG_GET_ETH_ID,
+ nbl_disp_chan_get_eth_id_resp,
+ disp_mgt);
+ if (_ret < 0 && !ret)
+ ret = _ret;
+
+ return ret;
+}
+
static void nbl_disp_set_ctrl_bit(struct nbl_dispatch_mgt *disp_mgt, u32 lvl)
{
set_bit(lvl, disp_mgt->ctrl_lvl);
@@ -26,9 +503,22 @@ 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;
+ memset(disp_ops, 0, sizeof(*disp_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;
+ disp_ops->cfg_msix_map = nbl_disp_cfg_msix_map;
+ disp_ops->destroy_msix_map = nbl_disp_destroy_msix_map;
+ disp_ops->set_mailbox_irq = nbl_disp_set_mailbox_irq;
+ disp_ops->get_vsi_id = nbl_disp_get_vsi_id;
+ disp_ops->get_eth_id = nbl_disp_get_eth_id;
+ } else if (test_bit(NBL_DISP_CTRL_LVL_NET, disp_mgt->ctrl_lvl)) {
+ disp_ops->cfg_msix_map =
+ nbl_disp_chan_cfg_msix_map_req;
+ disp_ops->destroy_msix_map = nbl_disp_chan_destroy_msix_map_req;
+ disp_ops->set_mailbox_irq = nbl_disp_chan_set_mailbox_irq_req;
+ disp_ops->get_vsi_id = nbl_disp_chan_get_vsi_id_req;
+ disp_ops->get_eth_id = nbl_disp_chan_get_eth_id_req;
}
}
@@ -94,9 +584,15 @@ int nbl_disp_init(struct nbl_adapter *adapter)
adapter->core.disp_mgt = disp_mgt;
adapter->intf.dispatch_ops_tbl = disp_ops_tbl;
+ ret = nbl_disp_setup_msg(disp_mgt);
+ if (ret)
+ return ret;
+
if (common->has_ctrl)
nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
+ if (common->has_net)
+ nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_NET);
nbl_disp_refresh_ctrl_ops(disp_mgt);
return 0;
}
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
index bf971121d..5aa16d4cd 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
@@ -7,6 +7,7 @@
#define _NBL_DEF_CHANNEL_H_
#include <linux/types.h>
+#include <linux/build_bug.h>
struct nbl_channel_mgt;
struct nbl_adapter;
@@ -30,6 +31,11 @@ typedef void (*nbl_chan_resp)(void *, u16, u16, void *, u32);
*/
enum nbl_chan_msg_type {
NBL_CHAN_MSG_ACK = 0,
+ NBL_CHAN_MSG_CONFIGURE_MSIX_MAP = 17,
+ NBL_CHAN_MSG_DESTROY_MSIX_MAP = 18,
+ NBL_CHAN_MSG_MAILBOX_SET_IRQ = 19,
+ NBL_CHAN_MSG_GET_VSI_ID = 21,
+ NBL_CHAN_MSG_GET_ETH_ID = 67,
/* mailbox msg end */
NBL_CHAN_MSG_MAILBOX_MAX,
};
@@ -39,6 +45,32 @@ enum nbl_chan_state {
NBL_CHAN_STATE_NBITS
};
+struct nbl_chan_param_cfg_msix_map {
+ __le16 num_net_msix;
+ __le16 num_others_msix;
+ __le16 msix_mask_en;
+ __le16 rsvd;
+};
+
+struct nbl_chan_param_set_mailbox_irq {
+ __le16 vector_id;
+ u8 en_msix;
+ u8 rsvd;
+};
+
+struct nbl_chan_param_get_vsi_id {
+ __le16 vsi_id;
+ __le16 type;
+};
+
+struct nbl_chan_param_get_eth_id {
+ __le16 vsi_id;
+ u8 eth_num;
+ u8 eth_id;
+ u8 logic_eth_id;
+ u8 rsvd[3];
+};
+
struct nbl_board_port_info {
u8 eth_num;
u8 eth_speed;
@@ -46,6 +78,14 @@ struct nbl_board_port_info {
u8 rsv[5];
};
+static_assert(sizeof(struct nbl_chan_param_cfg_msix_map) == 8,
+ "nbl_chan_param_cfg_msix_map size must be 8 bytes");
+static_assert(sizeof(struct nbl_chan_param_set_mailbox_irq) == 4,
+ "nbl_chan_param_set_mailbox_irq size must be 4 bytes");
+static_assert(sizeof(struct nbl_chan_param_get_vsi_id) == 4,
+ "nbl_chan_param_get_vsi_id size must be 4 bytes");
+static_assert(sizeof(struct nbl_chan_param_get_eth_id) == 8,
+ "nbl_chan_param_get_eth_id size must be 8 bytes");
static_assert(sizeof(struct nbl_board_port_info) == 8,
"nbl_board_port_info size must be 8 bytes");
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
index c90dd4e11..f73d32ec2 100644
--- 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
@@ -12,6 +12,7 @@ struct nbl_dispatch_mgt;
struct nbl_adapter;
enum {
NBL_DISP_CTRL_LVL_MGT,
+ NBL_DISP_CTRL_LVL_NET,
NBL_DISP_CTRL_LVL_MAX,
};
@@ -31,16 +32,54 @@ enum {
* mailbox DMA before calling it.
* Returns void. Control-PF exclusive, same NULL rule as
* @init_module.
+ * @cfg_msix_map: configure function msix mapping table. On a non-control
+ * PF this is an RPC, and the caller must have cleared
+ * NBL_CHAN_IRQ_RDY and switched the channel to its polling
+ * send path first: the responder rewrites this function's
+ * mailbox MSI-X routing, so the ACK cannot depend on the
+ * interrupt being reprogrammed.
+ * @destroy_msix_map: tear down msix mapping resource. Same caller
+ * precondition as @cfg_msix_map.
+ * @set_mailbox_irq: bind mailbox interrupt to specified msix vector.
+ * Same caller precondition as @cfg_msix_map.
+ * @get_vsi_id: resolve VSI ID by type
+ * @get_eth_id: resolve eth port info from VSI ID
*
* These callbacks are not dispatch-layer setup/teardown: the dispatch
- * structures are devm-allocated in nbl_disp_init(), and nbl_disp_remove()
- * only documents why no explicit teardown is needed. They forward
+ * structures are devm-allocated in nbl_disp_init(), so nbl_disp_remove()
+ * has nothing to undo. The five responders registered by
+ * nbl_disp_setup_msg() live in the channel layer's handler xarray and go
+ * away with it, so they need no explicit unregistration either. Nothing
+ * can enter them until a mailbox queue is running, and a queue must be
+ * torn down before nbl_res_remove_leonis() runs: nbl_chan_teardown_queue()
+ * stops the RX path and nbl_chan_remove_common() frees the handler nodes,
+ * so once the resource layer starts disappearing there is no responder
+ * left that could still be running, or be entered. They forward
* chip/firmware control down to the layers below instead: a control-PF
- * function calls the resource helpers directly.
+ * function calls the resource helpers directly, a non-control function
+ * sends a mailbox request over the channel layer.
+ *
+ * Warning: init_module/deinit_module are control-PF exclusive. The five
+ * resource operations (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);
+ int (*cfg_msix_map)(struct nbl_dispatch_mgt *disp_mgt,
+ u16 num_net_msix, u16 num_others_msix,
+ bool net_msix_mask_en);
+ int (*destroy_msix_map)(struct nbl_dispatch_mgt *disp_mgt);
+ int (*set_mailbox_irq)(struct nbl_dispatch_mgt *disp_mgt,
+ u16 vector_id, bool en_msix);
+ int (*get_vsi_id)(struct nbl_dispatch_mgt *disp_mgt, u16 type,
+ u16 *vsi_id);
+ int (*get_eth_id)(struct nbl_dispatch_mgt *disp_mgt, u16 vsi_id,
+ u8 *eth_num, u8 *eth_id, u8 *logic_eth_id);
};
struct nbl_dispatch_ops_tbl {
--
2.51.0.windows.1
Re: [PATCH v35 net-next 6/8] net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 12:52
Date: Mon, 23 Nov 2026 12:52
216 lines
16858 bytes
16858 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message says "If the resource op is not installed the
responder answers -EOPNOTSUPP." No code does this.
- [Low] The kernel-doc on struct nbl_dispatch_ops says the mailbox queue
must be torn down before nbl_res_remove_leonis(), via…
- [Low] The concern was that when cfg_msix_map, set_mailbox_irq or
destroy_msix_map fails with a lost ACK or timeout, the hardware stays…
- [Low] The concern was that on the control PF, local cfg_msix_map
(reconfigure) and destroy_msix_map turn off the function's own mailbox…
--
net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id
This patch adds request and response handlers for five dispatch
operations: cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id
and get_eth_id. A control PF calls the resource helpers locally, and a
has_net PF forwards the op to the management PF over the mailbox channel.
The five responders are registered with the channel layer from
nbl_disp_setup_msg().
> requester can tell a protocol error from a failed operation. If the
> resource op is not installed the responder answers -EOPNOTSUPP. A peer
[Severity: Low]
Is this sentence accurate? None of the five responders has an "op not
installed" branch, and none of them sets err = -EOPNOTSUPP. For example,
nbl_disp_chan_cfg_msix_map_resp() calls the resource helper directly:
ret = nbl_res_intr_cfg_msix_map(disp_mgt->res_mgt, src_id, ...);
/* Forward the resource errno verbatim to the requester */
if (ret)
err = ret;
When the resource layer can't serve the request, the helpers return
-EINVAL:
nbl_res_intr_destroy_msix_map() {
if (!intr_mgt)
return -EINVAL;
...
}
On these paths, -EOPNOTSUPP only comes from nbl_res_func_id_to_bdf(),
where it means the func_id is not a PF present on this board.
If a msg_type has no registered handler, nbl_chan_recv_msg() logs an
error and returns without sending an ACK. The requester then times out
and never sees -EOPNOTSUPP:
msg_handler = xa_load(&chan_mgt->handler_xa, msg_type);
if (!msg_handler || !msg_handler->func) {
dev_err_ratelimited(dev,
"No handler for msg_type: %u (srcid=%u, msgid=%u)\n",
msg_type, srcid, msgid);
return;
}
If nbl_disp_setup_msg() fails, nbl_disp_init() fails the probe, so the
device can never run with an op that is not installed. This is still
true at the end of the series.
Should this sentence be dropped, or is the -EOPNOTSUPP behaviour meant
to be implemented?
> 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
> index 58f6ac8343852..d256394a5cbb1 100644
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
[ ... ]
> @@ -17,6 +174,326 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)
> return nbl_res_chip_init_module(disp_mgt->res_mgt);
> }
>
[ ... ]
> +/*
> + * Precondition: caller must disable mailbox IRQ_RDY and switch send_msg
> + * to the polling path before issuing this RPC. The responder rewrites
> + * the requester's mailbox MSI-X routing during the resource op, so the
> + * ACK cannot rely on interrupt wakeup while routing is in flux.
> + */
> +static int
> +nbl_disp_chan_cfg_msix_map_req(struct nbl_dispatch_mgt *disp_mgt,
> + u16 num_net_msix, u16 num_others_msix,
> + bool net_msix_mask_en)
> +{
[ ... ]
> + nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
> + NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,
> + ¶m, sizeof(param),
> + NULL, 0, 1);
> + ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
> + if (ret)
> + return ret;
> + return 0;
> +}
[Severity: Low]
Suppose send_msg() returns -ETIMEDOUT because the ACK was lost. Could
the responder already have committed the new map in
nbl_res_intr_cfg_msix_map() and armed the hardware? This helper only
passes the error up, so undoing the change is left to the caller. The
set_mailbox_irq and destroy_msix_map requests have the same issue.
Nothing calls these helpers in this patch. Later in the series,
"net/nebula-matrix: add common dev start/stop operation" handles this.
nbl_dev_start() jumps to err_destroy_map on any cfg_msix_map, get_vsi_id
or get_eth_id failure, and that path always calls
nbl_dev_destroy_msix_map(). A failed set_mailbox_irq enable goes through
err_free_irq -> err_destroy_map. So this looks resolved by the end of
the series.
[ ... ]
> 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
> index c90dd4e119160..f73d32ec2c8a9 100644
> --- 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
[ ... ]
> @@ -31,16 +32,54 @@ enum {
> * mailbox DMA before calling it.
> * Returns void. Control-PF exclusive, same NULL rule as
> * @init_module.
> + * @cfg_msix_map: configure function msix mapping table. On a non-control
> + * PF this is an RPC, and the caller must have cleared
> + * NBL_CHAN_IRQ_RDY and switched the channel to its polling
> + * send path first: the responder rewrites this function's
> + * mailbox MSI-X routing, so the ACK cannot depend on the
> + * interrupt being reprogrammed.
> + * @destroy_msix_map: tear down msix mapping resource. Same caller
> + * precondition as @cfg_msix_map.
[Severity: Low]
As written, the IRQ_RDY/polling precondition seems to apply only to a
non-control PF. On the control PF, nbl_disp_cfg_msix_map() and
nbl_disp_destroy_msix_map() call the resource layer directly.
A reconfiguration (had_config) in nbl_res_intr_cfg_msix_map() turns off
the function's own mailbox routing and does not restore it:
if (had_config) {
...
ret = __nbl_res_intr_set_mailbox_irq(intr_mgt, res_mgt, func_id,
0, false);
Destroy does the same. If NBL_CHAN_IRQ_RDY were still set at that point,
could the control PF stop receiving mailbox interrupts?
This isn't reached anywhere in the series:
- The control PF's only cfg_msix_map is the first configuration in
nbl_dev_start(), where had_config is false.
- Its destroy_msix_map runs in nbl_dev_stop() after
nbl_dev_disable_mailbox_irq() has cleared IRQ_RDY.
- When a peer is reconfigured, nbl_dev_start() calls
set_mailbox_irq(true) to re-arm routing before IRQ_RDY is set.
Could the kernel-doc say that the precondition also applies to the local
path? It could also say that mailbox routing stays disabled until
set_mailbox_irq() re-arms it.
[ ... ]
> * These callbacks are not dispatch-layer setup/teardown: the dispatch
> - * structures are devm-allocated in nbl_disp_init(), and nbl_disp_remove()
> - * only documents why no explicit teardown is needed. They forward
> + * structures are devm-allocated in nbl_disp_init(), so nbl_disp_remove()
> + * has nothing to undo. The five responders registered by
> + * nbl_disp_setup_msg() live in the channel layer's handler xarray and go
> + * away with it, so they need no explicit unregistration either. Nothing
> + * can enter them until a mailbox queue is running, and a queue must be
> + * torn down before nbl_res_remove_leonis() runs: nbl_chan_teardown_queue()
> + * stops the RX path and nbl_chan_remove_common() frees the handler nodes,
> + * so once the resource layer starts disappearing there is no responder
> + * left that could still be running, or be entered. They forward
[Severity: Low]
This isn't a bug, but the ordering described here doesn't match
nbl_core_remove(). The handler nodes are freed after the resource layer
is removed:
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);
}
Also, nothing calls ->teardown_queue in this patch.
The RX-stop part does hold at the end of the series.
"net/nebula-matrix: add common/ctrl dev init/remove operation" makes
nbl_dev_remove() the first step of nbl_core_remove(). That path calls
nbl_dev_remove_common_dev()->nbl_dev_remove_chan_queue()->teardown_queue()
before nbl_res_remove_leonis() runs.
Could the comment be reworded so it doesn't say nbl_chan_remove_common()
runs before nbl_res_remove_leonis()?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads