From: Vikas Gupta <vikas.gupta@broadcom.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bhargava.marreddy@broadcom.com, rahul-rg.gupta@broadcom.com,
vsrama-krishna.nemani@broadcom.com,
rajashekar.hudumula@broadcom.com, dharmender.garg@broadcom.com,
ajit.khaparde@broadcom.com,
Vikas Gupta <vikas.gupta@broadcom.com>
Subject: [net-next, v2 06/11] bnge: add ethtool support to manage RSS contexts
Date: Tue, 8 Sep 2026 15:00:48 +0530 [thread overview]
Message-ID: <20260908093053.2596020-7-vikas.gupta@broadcom.com> (raw)
In-Reply-To: <20260908093053.2596020-1-vikas.gupta@broadcom.com>
Introduce ethtool callbacks to manage RSS contexts.
Each context allocates a dedicated VNIC with its own RSS indirection
table and hash key, configured with TPA settings matching those of the
default VNIC.
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Reviewed-by: Bhargava Chenna Marreddy <bhargava.marreddy@broadcom.com>
Reviewed-by: Dharmender Garg <dharmender.garg@broadcom.com>
---
.../net/ethernet/broadcom/bnge/bnge_ethtool.c | 135 ++++++++++++++++++
.../net/ethernet/broadcom/bnge/bnge_netdev.c | 9 ++
.../net/ethernet/broadcom/bnge/bnge_resc.c | 13 +-
.../net/ethernet/broadcom/bnge/bnge_vnic.c | 26 +++-
.../net/ethernet/broadcom/bnge/bnge_vnic.h | 14 +-
5 files changed, 189 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c b/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c
index bb7d366a9841..460e66da6d1c 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c
@@ -1003,6 +1003,138 @@ static u32 bnge_get_rx_ring_count(struct net_device *dev)
return bd->rx_nr_rings;
}
+static int bnge_rxfh_context_check(struct bnge_net *bn,
+ const struct ethtool_rxfh_param *rxfh,
+ struct netlink_ext_ack *extack)
+{
+ if (rxfh->hfunc && rxfh->hfunc != ETH_RSS_HASH_TOP) {
+ NL_SET_ERR_MSG_MOD(extack, "RSS hash function not supported");
+ return -EOPNOTSUPP;
+ }
+
+ if (!(bn->priv_flags & BNGE_NET_EN_NTUPLE)) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Enable ntuple filtering before adding RSS contexts");
+ return -EOPNOTSUPP;
+ }
+
+ if (!netif_running(bn->netdev)) {
+ NL_SET_ERR_MSG_MOD(extack, "Unable to set RSS contexts when interface is down");
+ return -EAGAIN;
+ }
+
+ return 0;
+}
+
+static int bnge_create_rxfh_context(struct net_device *dev,
+ struct ethtool_rxfh_context *ctx,
+ const struct ethtool_rxfh_param *rxfh,
+ struct netlink_ext_ack *extack)
+{
+ struct bnge_net *bn = netdev_priv(dev);
+ struct bnge_rss_ctx *rss_ctx;
+ struct bnge_vnic_info *vnic;
+ int rc;
+
+ rc = bnge_rxfh_context_check(bn, rxfh, extack);
+ if (rc)
+ return rc;
+
+ if (bn->num_rss_ctx >= BNGE_MAX_ETH_RSS_CTX) {
+ NL_SET_ERR_MSG_FMT_MOD(extack, "Out of RSS contexts, maximum %u",
+ BNGE_MAX_ETH_RSS_CTX);
+ return -EINVAL;
+ }
+
+ if (!bnge_arfs_capable(bn->bd, true)) {
+ NL_SET_ERR_MSG_MOD(extack, "Out of hardware resources");
+ return -ENOMEM;
+ }
+
+ rss_ctx = ethtool_rxfh_context_priv(ctx);
+
+ bn->num_rss_ctx++;
+
+ vnic = &rss_ctx->vnic;
+
+ bnge_init_vnic_mem(vnic);
+
+ vnic->rss_ctx = ctx;
+ vnic->flags |= BNGE_VNIC_RSSCTX_FLAG;
+ rc = bnge_alloc_vnic_rss_table(bn, vnic);
+ if (rc)
+ goto err_del_rss_ctx;
+
+ /* Populate defaults in the context */
+ bnge_set_dflt_rss_indir_tbl(bn->bd, ctx);
+ ctx->hfunc = ETH_RSS_HASH_TOP;
+ memcpy(vnic->rss_hash_key, bn->rss_hash_key, HW_HASH_KEY_SIZE);
+ memcpy(ethtool_rxfh_context_key(ctx),
+ bn->rss_hash_key, HW_HASH_KEY_SIZE);
+
+ rc = bnge_hwrm_vnic_alloc(bn->bd, vnic, bn->bd->rx_nr_rings);
+ if (rc) {
+ NL_SET_ERR_MSG_MOD(extack, "Unable to allocate VNIC");
+ goto err_del_rss_ctx;
+ }
+
+ rc = bnge_hwrm_vnic_set_tpa(bn->bd, vnic,
+ bn->priv_flags & BNGE_NET_EN_TPA);
+ if (rc) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Unable to set TPA settings to vnic");
+ goto err_del_rss_ctx;
+ }
+ bnge_modify_rss(bn, ctx, rss_ctx, rxfh);
+
+ rc = bnge_setup_vnic(bn, vnic);
+ if (rc) {
+ NL_SET_ERR_MSG_MOD(extack, "Unable to setup vnic");
+ goto err_del_rss_ctx;
+ }
+
+ rss_ctx->index = rxfh->rss_context;
+ return 0;
+
+err_del_rss_ctx:
+ bnge_del_one_rss_ctx(bn, rss_ctx, true);
+ return rc;
+}
+
+static int bnge_modify_rxfh_context(struct net_device *dev,
+ struct ethtool_rxfh_context *ctx,
+ const struct ethtool_rxfh_param *rxfh,
+ struct netlink_ext_ack *extack)
+{
+ struct bnge_net *bn = netdev_priv(dev);
+ struct bnge_rss_ctx *rss_ctx;
+ int rc;
+
+ rc = bnge_rxfh_context_check(bn, rxfh, extack);
+ if (rc)
+ return rc;
+
+ rss_ctx = ethtool_rxfh_context_priv(ctx);
+
+ bnge_modify_rss(bn, ctx, rss_ctx, rxfh);
+
+ return bnge_hwrm_vnic_rss_cfg(bn, &rss_ctx->vnic);
+}
+
+static int bnge_remove_rxfh_context(struct net_device *dev,
+ struct ethtool_rxfh_context *ctx,
+ u32 rss_context,
+ struct netlink_ext_ack *extack)
+{
+ struct bnge_net *bn = netdev_priv(dev);
+ struct bnge_rss_ctx *rss_ctx;
+
+ rss_ctx = ethtool_rxfh_context_priv(ctx);
+
+ bnge_del_one_rss_ctx(bn, rss_ctx, true);
+ return 0;
+}
+
static const struct ethtool_ops bnge_ethtool_ops = {
.cap_link_lanes_supported = 1,
.get_link_ksettings = bnge_get_link_ksettings,
@@ -1032,6 +1164,9 @@ static const struct ethtool_ops bnge_ethtool_ops = {
.set_rxfh = bnge_set_rxfh,
.get_rxfh_fields = bnge_get_rxfh_fields,
.set_rxfh_fields = bnge_set_rxfh_fields,
+ .create_rxfh_context = bnge_create_rxfh_context,
+ .modify_rxfh_context = bnge_modify_rxfh_context,
+ .remove_rxfh_context = bnge_remove_rxfh_context,
};
void bnge_set_ethtool_ops(struct net_device *dev)
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
index 79a24d12b37e..656bdc3d1a7e 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
@@ -2788,6 +2788,8 @@ int bnge_open_core(struct bnge_net *bn)
/* Poll link status and check for SFP+ module status */
bnge_get_port_module_status(bn);
+ bnge_hwrm_realloc_rss_ctx_vnic(bn);
+
return 0;
err_free_irq:
@@ -3005,7 +3007,10 @@ void bnge_close_core(struct bnge_net *bn)
clear_bit(BNGE_STATE_OPEN, &bd->state);
timer_delete_sync(&bn->timer);
+
+ bnge_clear_rss_ctxs(bn);
bnge_shutdown_nic(bn);
+
bnge_disable_napi(bn);
/* Save ring stats before shutdown */
@@ -3139,6 +3144,10 @@ static int bnge_set_features(struct net_device *dev, netdev_features_t features)
if (flags == bn->priv_flags)
return 0;
+ if ((bn->priv_flags & BNGE_NET_EN_NTUPLE) &&
+ !(flags & BNGE_NET_EN_NTUPLE) && bn->num_rss_ctx)
+ return -EBUSY;
+
bn->priv_flags = flags;
return 0;
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_resc.c b/drivers/net/ethernet/broadcom/bnge/bnge_resc.c
index 2823be44a7ed..848cfff90b55 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_resc.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_resc.c
@@ -352,8 +352,17 @@ int bnge_reserve_rings(struct bnge_dev *bd)
if (!bnge_rings_ok(&hwr))
return -ENOMEM;
- if (old_rx_rings != bd->hw_resc.resv_rx_rings)
- bnge_set_dflt_rss_indir_tbl(bd);
+ if (old_rx_rings != bd->hw_resc.resv_rx_rings) {
+ bnge_set_dflt_rss_indir_tbl(bd, NULL);
+
+ if (bd->netdev) {
+ struct ethtool_rxfh_context *ctx;
+ unsigned long context;
+
+ xa_for_each(&bd->netdev->ethtool->rss_ctx, context, ctx)
+ bnge_set_dflt_rss_indir_tbl(bd, ctx);
+ }
+ }
if (!bnge_aux_registered(bd)) {
u16 resv_msix, resv_ctx, aux_ctxs;
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_vnic.c b/drivers/net/ethernet/broadcom/bnge/bnge_vnic.c
index 417abc7e8c74..f1aa6f1629a6 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_vnic.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_vnic.c
@@ -12,21 +12,26 @@
#include "bnge_filter.h"
#include "bnge_ethtool.h"
-void bnge_set_dflt_rss_indir_tbl(struct bnge_dev *bd)
+void bnge_set_dflt_rss_indir_tbl(struct bnge_dev *bd,
+ struct ethtool_rxfh_context *rss_ctx)
{
u16 max_entries, pad;
u32 *rss_indir_tbl;
u16 i;
max_entries = bnge_get_rxfh_indir_size(bd);
- rss_indir_tbl = &bd->rss_indir_tbl[0];
+
+ if (rss_ctx)
+ rss_indir_tbl = ethtool_rxfh_context_indir(rss_ctx);
+ else
+ rss_indir_tbl = &bd->rss_indir_tbl[0];
for (i = 0; i < max_entries; i++)
rss_indir_tbl[i] = ethtool_rxfh_indir_default(i,
bd->rx_nr_rings);
pad = bd->rss_indir_tbl_entries - max_entries;
- if (pad)
+ if (pad && !rss_ctx)
memset(&rss_indir_tbl[i], 0, pad * sizeof(*rss_indir_tbl));
}
@@ -44,6 +49,8 @@ void bnge_fill_hw_rss_tbl(struct bnge_net *bn, struct bnge_vnic_info *vnic)
if (vnic->flags & BNGE_VNIC_NTUPLE_FLAG)
j = ethtool_rxfh_indir_default(i, bd->rx_nr_rings);
+ else if (vnic->flags & BNGE_VNIC_RSSCTX_FLAG)
+ j = ethtool_rxfh_context_indir(vnic->rss_ctx)[i];
else
j = bd->rss_indir_tbl[i];
@@ -151,7 +158,7 @@ void bnge_modify_rss(struct bnge_net *bn, struct ethtool_rxfh_context *ctx,
for (i = 0; i < tbl_size; i++)
indir_tbl[i] = rxfh->indir[i];
pad = bd->rss_indir_tbl_entries - tbl_size;
- if (pad)
+ if (pad && !rss_ctx)
memset(&indir_tbl[i], 0, pad * sizeof(*indir_tbl));
}
}
@@ -238,3 +245,14 @@ int bnge_alloc_vnic_rss_table(struct bnge_net *bn,
vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
return 0;
}
+
+void bnge_init_vnic_mem(struct bnge_vnic_info *vnic)
+{
+ int i;
+
+ vnic->fw_vnic_id = INVALID_HW_RING_ID;
+ vnic->vnic_id = BNGE_VNIC_ID_INVALID;
+
+ for (i = 0; i < BNGE_MAX_CTX_PER_VNIC; i++)
+ vnic->fw_rss_cos_lb_ctx[i] = INVALID_HW_RING_ID;
+}
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h b/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
index b2a1d8332a5f..3954c450315d 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
@@ -21,6 +21,11 @@ struct bnge_l2_filter;
#define BNGE_MAX_MC_ADDRS 16
#define BNGE_MAX_UC_ADDRS 4
+#define BNGE_VNIC_ID_INVALID 0xffffffff
+
+struct ethtool_rxfh_context;
+struct ethtool_rxfh_param;
+
enum {
BNGE_VNIC_DEFAULT = 0,
BNGE_VNIC_NTUPLE = 1
@@ -30,7 +35,8 @@ enum {
BNGE_VNIC_RSS_FLAG = BIT(0),
BNGE_VNIC_MCAST_FLAG = BIT(1),
BNGE_VNIC_UCAST_FLAG = BIT(2),
- BNGE_VNIC_NTUPLE_FLAG = BIT(3)
+ BNGE_VNIC_NTUPLE_FLAG = BIT(3),
+ BNGE_VNIC_RSSCTX_FLAG = BIT(4)
};
struct bnge_vnic_info {
@@ -55,6 +61,8 @@ struct bnge_vnic_info {
u32 flags;
u32 vnic_id;
+
+ struct ethtool_rxfh_context *rss_ctx;
};
struct bnge_rss_ctx {
@@ -66,7 +74,8 @@ void bnge_fill_hw_rss_tbl(struct bnge_net *bn, struct bnge_vnic_info *vnic);
int bnge_hwrm_vnic_rss_cfg(struct bnge_net *bn,
struct bnge_vnic_info *vnic);
int bnge_setup_vnic(struct bnge_net *bn, struct bnge_vnic_info *vnic);
-void bnge_set_dflt_rss_indir_tbl(struct bnge_dev *bd);
+void bnge_set_dflt_rss_indir_tbl(struct bnge_dev *bd,
+ struct ethtool_rxfh_context *ctx);
int bnge_alloc_rfs_vnic(struct bnge_net *bn);
int bnge_alloc_vnic_rss_table(struct bnge_net *bn,
struct bnge_vnic_info *vnic);
@@ -78,4 +87,5 @@ void bnge_del_one_rss_ctx(struct bnge_net *bn, struct bnge_rss_ctx *rss_ctx,
bool all);
void bnge_hwrm_realloc_rss_ctx_vnic(struct bnge_net *bn);
void bnge_clear_rss_ctxs(struct bnge_net *bn);
+void bnge_init_vnic_mem(struct bnge_vnic_info *vnic);
#endif /* _BNGE_VNIC_H_ */
--
2.47.1
next prev parent reply other threads:[~2026-09-08 9:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 9:30 [net-next, v2 00/11] add features to bnge Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 01/11] bnge: update HSI Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 02/11] bnge: restructure VNIC and filter code Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 03/11] bnge: add NTUPLE/ARFS VNIC Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 04/11] bnge: add helper functions for multi RSS contexts Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 05/11] bnge: add RXFH ethtool support Vikas Gupta
2026-09-08 9:30 ` Vikas Gupta [this message]
2026-09-08 9:30 ` [net-next, v2 07/11] bnge: remove refcount from L2 filter Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 08/11] bnge: add NTUPLE filter infrastructure Vikas Gupta
2026-09-10 23:59 ` Jakub Kicinski
2026-09-08 9:30 ` [net-next, v2 09/11] bnge: add NTUPLE filter support in ethtool Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 10/11] bnge: add aRFS flow steering ndo support Vikas Gupta
2026-09-08 9:30 ` [net-next, v2 11/11] bnge: add cpu_rmap support for IRQ affinity Vikas Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260908093053.2596020-7-vikas.gupta@broadcom.com \
--to=vikas.gupta@broadcom.com \
--cc=ajit.khaparde@broadcom.com \
--cc=andrew+netdev@lunn.ch \
--cc=bhargava.marreddy@broadcom.com \
--cc=davem@davemloft.net \
--cc=dharmender.garg@broadcom.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rahul-rg.gupta@broadcom.com \
--cc=rajashekar.hudumula@broadcom.com \
--cc=vsrama-krishna.nemani@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.