[net-next, v4 04/10] bnge: add RXFH ethtool support
From: Vikas Gupta <vikas.gupta@broadcom.com>
Date: 2026-09-28 06:13:47
Also in:
lkml
Subsystem:
broadcom bng_en 800 gigabit ethernet driver, networking drivers, the rest · Maintainers:
Vikas Gupta, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
Introduce ethtool RXFH operations including get/set_rxfh for reading and programming the RSS hash key and indirection table. Currently set_rxfh and set_rxfh_fields are supported only while the device is down. A future patch series will rework bnge_close_core()/bnge_open_core() so they can be driven safely from the ethtool path, adding full functionality by applying the configuration on a live device. Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com> Reviewed-by: Bhargava Chenna Marreddy <redacted> Reviewed-by: Dharmender Garg <redacted> --- drivers/net/ethernet/broadcom/bnge/bnge.h | 1 + .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 281 ++++++++++++++++++ .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 2 + .../net/ethernet/broadcom/bnge/bnge_netdev.c | 10 +- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 1 + 5 files changed, 288 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge.h b/drivers/net/ethernet/broadcom/bnge/bnge.h
index a88aac140c7d..560b9d193dea 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge.h
+++ b/drivers/net/ethernet/broadcom/bnge/bnge.h@@ -86,6 +86,7 @@ enum { BNGE_RSS_CAP_AH_V6_RSS_CAP = BIT(5), BNGE_RSS_CAP_ESP_V4_RSS_CAP = BIT(6), BNGE_RSS_CAP_ESP_V6_RSS_CAP = BIT(7), + BNGE_RSS_CAP_IPV6_FLOW_LABEL_RSS_CAP = BIT(8), }; #define BNGE_MAX_QUEUE 8
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c b/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c
index 2467e44de291..6fbda4fc1a0c 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c@@ -10,6 +10,9 @@ #include <linux/ethtool_netlink.h> #include "bnge.h" +#include "bnge_netdev.h" +#include "bnge_vnic.h" +#include "bnge_resc.h" #include "bnge_ethtool.h" #include "bnge_hwrm_lib.h"
@@ -740,6 +743,272 @@ static int bnge_set_pauseparam(struct net_device *dev, return rc; } +static u64 bnge_get_ethtool_ipv4_rss(struct bnge_dev *bd) +{ + if (bd->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4) + return RXH_IP_SRC | RXH_IP_DST; + return 0; +} + +static u64 bnge_get_ethtool_ipv6_rss(struct bnge_dev *bd) +{ + if (bd->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6) + return RXH_IP_SRC | RXH_IP_DST; + if (bd->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6_FLOW_LABEL) + return RXH_IP_SRC | RXH_IP_DST | RXH_IP6_FL; + return 0; +} + +static int bnge_get_rxfh_fields(struct net_device *dev, + struct ethtool_rxfh_fields *cmd) +{ + struct bnge_net *bn = netdev_priv(dev); + struct bnge_dev *bd = bn->bd; + + cmd->data = 0; + switch (cmd->flow_type) { + case TCP_V4_FLOW: + if (bd->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) + cmd->data |= RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3; + cmd->data |= bnge_get_ethtool_ipv4_rss(bd); + break; + case UDP_V4_FLOW: + if (bd->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4) + cmd->data |= RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3; + cmd->data |= bnge_get_ethtool_ipv4_rss(bd); + break; + case AH_ESP_V4_FLOW: + if (bd->rss_hash_cfg & + (VNIC_RSS_CFG_REQ_HASH_TYPE_AH_SPI_IPV4 | + VNIC_RSS_CFG_REQ_HASH_TYPE_ESP_SPI_IPV4)) + cmd->data |= RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3; + cmd->data |= bnge_get_ethtool_ipv4_rss(bd); + break; + case SCTP_V4_FLOW: + case AH_V4_FLOW: + case ESP_V4_FLOW: + case IPV4_FLOW: + cmd->data |= bnge_get_ethtool_ipv4_rss(bd); + break; + case TCP_V6_FLOW: + if (bd->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) + cmd->data |= RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3; + cmd->data |= bnge_get_ethtool_ipv6_rss(bd); + break; + case UDP_V6_FLOW: + if (bd->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6) + cmd->data |= RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3; + cmd->data |= bnge_get_ethtool_ipv6_rss(bd); + break; + case AH_ESP_V6_FLOW: + if (bd->rss_hash_cfg & + (VNIC_RSS_CFG_REQ_HASH_TYPE_AH_SPI_IPV6 | + VNIC_RSS_CFG_REQ_HASH_TYPE_ESP_SPI_IPV6)) + cmd->data |= RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3; + cmd->data |= bnge_get_ethtool_ipv6_rss(bd); + break; + case SCTP_V6_FLOW: + case AH_V6_FLOW: + case ESP_V6_FLOW: + case IPV6_FLOW: + cmd->data |= bnge_get_ethtool_ipv6_rss(bd); + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +#define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3) +#define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST) + +static int bnge_set_rxfh_fields(struct net_device *dev, + const struct ethtool_rxfh_fields *cmd, + struct netlink_ext_ack *extack) +{ + struct bnge_net *bn = netdev_priv(dev); + struct bnge_dev *bd = bn->bd; + u32 rss_hash_cfg; + int tuple; + + rss_hash_cfg = bd->rss_hash_cfg; + + if (cmd->data == RXH_4TUPLE || + cmd->data == (RXH_4TUPLE | RXH_IP6_FL)) + tuple = 4; + else if (cmd->data == RXH_2TUPLE || + cmd->data == (RXH_2TUPLE | RXH_IP6_FL)) + tuple = 2; + else if (!cmd->data) + tuple = 0; + else + return -EINVAL; + + if (cmd->data & RXH_IP6_FL && + !(bd->rss_cap & BNGE_RSS_CAP_IPV6_FLOW_LABEL_RSS_CAP)) + return -EINVAL; + + if (cmd->flow_type == TCP_V4_FLOW) { + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; + if (tuple == 4) + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; + } else if (cmd->flow_type == UDP_V4_FLOW) { + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; + if (tuple == 4) + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; + } else if (cmd->flow_type == TCP_V6_FLOW) { + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; + if (tuple == 4) + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; + } else if (cmd->flow_type == UDP_V6_FLOW) { + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; + if (tuple == 4) + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; + } else if (cmd->flow_type == AH_ESP_V4_FLOW) { + if (tuple == 4 && + (!(bd->rss_cap & BNGE_RSS_CAP_AH_V4_RSS_CAP) || + !(bd->rss_cap & BNGE_RSS_CAP_ESP_V4_RSS_CAP))) + return -EINVAL; + rss_hash_cfg &= ~(VNIC_RSS_CFG_REQ_HASH_TYPE_AH_SPI_IPV4 | + VNIC_RSS_CFG_REQ_HASH_TYPE_ESP_SPI_IPV4); + if (tuple == 4) + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_AH_SPI_IPV4 | + VNIC_RSS_CFG_REQ_HASH_TYPE_ESP_SPI_IPV4; + } else if (cmd->flow_type == AH_ESP_V6_FLOW) { + if (tuple == 4 && + (!(bd->rss_cap & BNGE_RSS_CAP_AH_V6_RSS_CAP) || + !(bd->rss_cap & BNGE_RSS_CAP_ESP_V6_RSS_CAP))) + return -EINVAL; + rss_hash_cfg &= ~(VNIC_RSS_CFG_REQ_HASH_TYPE_AH_SPI_IPV6 | + VNIC_RSS_CFG_REQ_HASH_TYPE_ESP_SPI_IPV6); + if (tuple == 4) + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_AH_SPI_IPV6 | + VNIC_RSS_CFG_REQ_HASH_TYPE_ESP_SPI_IPV6; + } else if (tuple == 4) { + return -EINVAL; + } + + switch (cmd->flow_type) { + case TCP_V4_FLOW: + case UDP_V4_FLOW: + case SCTP_V4_FLOW: + case AH_ESP_V4_FLOW: + case AH_V4_FLOW: + case ESP_V4_FLOW: + case IPV4_FLOW: + if (tuple == 2) + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; + else if (!tuple && cmd->flow_type == IPV4_FLOW) + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; + break; + + case TCP_V6_FLOW: + case UDP_V6_FLOW: + case SCTP_V6_FLOW: + case AH_ESP_V6_FLOW: + case AH_V6_FLOW: + case ESP_V6_FLOW: + case IPV6_FLOW: + if (cmd->data & RXH_IP6_FL) { + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6_FLOW_LABEL; + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; + } else if (tuple == 2 || tuple == 4) { + rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6_FLOW_LABEL; + } else if (!tuple && cmd->flow_type == IPV6_FLOW) { + rss_hash_cfg &= ~(VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 | + VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6_FLOW_LABEL); + } + break; + default: + return -EOPNOTSUPP; + } + + if (bd->rss_hash_cfg == rss_hash_cfg) + return 0; + + if (netif_running(dev)) { + NL_SET_ERR_MSG_MOD(extack, + "RSS configuration can only be changed while the interface is down"); + return -EBUSY; + } + + bd->rss_hash_cfg = rss_hash_cfg; + + return 0; +} + +static u32 bnge_get_rxfh_indir_size_eth(struct net_device *dev) +{ + struct bnge_net *bn = netdev_priv(dev); + struct bnge_dev *bd = bn->bd; + + return bnge_get_rxfh_indir_size(bd); +} + +static u32 bnge_get_rxfh_key_size(struct net_device *dev) +{ + return HW_HASH_KEY_SIZE; +} + +static int bnge_get_rxfh(struct net_device *dev, + struct ethtool_rxfh_param *rxfh) +{ + struct bnge_net *bn = netdev_priv(dev); + struct bnge_dev *bd = bn->bd; + u32 i, tbl_size; + u32 *indir_tbl; + + indir_tbl = bd->rss_indir_tbl; + rxfh->hfunc = ETH_RSS_HASH_TOP; + + if (rxfh->indir && indir_tbl) { + tbl_size = bnge_get_rxfh_indir_size(bd); + for (i = 0; i < tbl_size; i++) + rxfh->indir[i] = indir_tbl[i]; + } + + if (rxfh->key) + memcpy(rxfh->key, bn->rss_hash_key, HW_HASH_KEY_SIZE); + + return 0; +} + +static int bnge_set_rxfh(struct net_device *dev, + struct ethtool_rxfh_param *rxfh, + struct netlink_ext_ack *extack) +{ + struct bnge_net *bn = netdev_priv(dev); + + if (rxfh->hfunc && rxfh->hfunc != ETH_RSS_HASH_TOP) + return -EOPNOTSUPP; + + if (netif_running(dev)) { + NL_SET_ERR_MSG_MOD(extack, + "RSS configuration can only be changed while the interface is down"); + return -EBUSY; + } + + bnge_modify_rss(bn, NULL, NULL, rxfh); + + return 0; +} + +static u32 bnge_get_rx_ring_count(struct net_device *dev) +{ + struct bnge_net *bn = netdev_priv(dev); + struct bnge_dev *bd = bn->bd; + + return bd->rx_nr_rings; +} + static const struct ethtool_ops bnge_ethtool_ops = { .cap_link_lanes_supported = 1, .get_link_ksettings = bnge_get_link_ksettings,
@@ -757,6 +1026,18 @@ static const struct ethtool_ops bnge_ethtool_ops = { .get_eth_ctrl_stats = bnge_get_eth_ctrl_stats, .get_pause_stats = bnge_get_pause_stats, .get_rmon_stats = bnge_get_rmon_stats, + /* RXFH */ + .rxfh_per_ctx_key = 1, + .rxfh_max_num_contexts = BNGE_MAX_ETH_RSS_CTX + 1, + .rxfh_indir_space = BNGE_MAX_RSS_TABLE_ENTRIES, + .rxfh_priv_size = sizeof(struct bnge_rss_ctx), + .get_rx_ring_count = bnge_get_rx_ring_count, + .get_rxfh_indir_size = bnge_get_rxfh_indir_size_eth, + .get_rxfh_key_size = bnge_get_rxfh_key_size, + .get_rxfh = bnge_get_rxfh, + .set_rxfh = bnge_set_rxfh, + .get_rxfh_fields = bnge_get_rxfh_fields, + .set_rxfh_fields = bnge_set_rxfh_fields, }; void bnge_set_ethtool_ops(struct net_device *dev)
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c b/drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c
index 91d246c8dcf2..86edb70d323e 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c@@ -676,6 +676,8 @@ int bnge_hwrm_vnic_qcaps(struct bnge_dev *bd) bd->rss_cap |= BNGE_RSS_CAP_ESP_V4_RSS_CAP; if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_IPSEC_ESP_SPI_IPV6_CAP) bd->rss_cap |= BNGE_RSS_CAP_ESP_V6_RSS_CAP; + if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_IPV6_FLOW_LABEL_CAP) + bd->rss_cap |= BNGE_RSS_CAP_IPV6_FLOW_LABEL_RSS_CAP; } bnge_hwrm_req_drop(bd, req);
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
index c6b9048586b3..ef5d13337e60 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c@@ -1739,13 +1739,6 @@ static void bnge_init_vnics(struct bnge_net *bn) u8 *key = (void *)vnic->rss_hash_key; int k; - if (!bn->rss_hash_key_valid && - !bn->rss_hash_key_updated) { - get_random_bytes(bn->rss_hash_key, - HW_HASH_KEY_SIZE); - bn->rss_hash_key_updated = true; - } - memcpy(vnic->rss_hash_key, bn->rss_hash_key, HW_HASH_KEY_SIZE);
@@ -3398,6 +3391,9 @@ int bnge_netdev_alloc(struct bnge_dev *bd, int max_irqs) bn->tx_ring_size = BNGE_DEFAULT_TX_RING_SIZE; bn->rx_dir = DMA_FROM_DEVICE; + netdev_rss_key_fill(bn->rss_hash_key, sizeof(bn->rss_hash_key)); + bn->rss_hash_key_updated = true; + bnge_set_tpa_flags(bd); bnge_init_ring_params(bn); bnge_set_ring_params(bd);
diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h b/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
index ff7244cdf1a8..bc2ed911ced3 100644
--- a/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
+++ b/drivers/net/ethernet/broadcom/bnge/bnge_vnic.h@@ -16,6 +16,7 @@ struct bnge_l2_filter; #define BNGE_MAX_RSS_TABLE_ENTRIES \ (BNGE_RSS_TABLE_ENTRIES * BNGE_RSS_TABLE_MAX_TBL) +#define BNGE_MAX_ETH_RSS_CTX 32 #define BNGE_MAX_CTX_PER_VNIC 8 #define BNGE_MAX_MC_ADDRS 16
--
2.52.0