add features to bnge
Vikas Gupta
maintainerv11 cover add features to bnge
Hi,
This series adds ntuple filter, RSS context, and flow steering support to bnge driver.
Patch 1 is a pure refactor (no functional change) that relocates the filter and VNIC related code into the appropriate files. Patch 7 drops the refcount usage from L2 filters, also with no functional change. The subsequent patches then add the ethtool commands for configuring ntuple flows and RSS contexts.
Thanks,
Vikas
v10-v11:
- Addressed valid comments from Sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125115434.2080590-1-vikas.gupta%40broadcom.com
The fix is in patch 10. The other medium/low findings in the remaining patches need no changes from v10.
v9-v10:
- Addressed valid comments from Sashiko
https://sashiko.dev/#/patchset/20261123100746.1975030-1-vikas.gupta%40broadcom.com
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123100746.1975030-1-vikas.gupta%40broadcom.comv8-v9:
- Addressed valid comments from Sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116140653.1685797-1-vikas.gupta%40broadcom.com
https://sashiko.dev/#/patchset/20261116140653.1685797-1-vikas.gupta%40broadcom.comv7-v8:
- Addressed valid comments from Sashiko
https://sashiko.dev/#/patchset/20261114074742.1484603-1-vikas.gupta%40broadcom.com
v6-v7:
- Addressed valid comments from Sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.com
https://sashiko.dev/#/patchset/20261106093524.838341-1-vikas.gupta%40broadcom.comv5->v6:
- Addressed comments from Sashiko
https://sashiko.dev/#/patchset/20261103123651.442893-1-vikas.gupta%40broadcom.com
- Fix inline keyword use in C file.
v4->v5:
- Addressed comments from Sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928061307.1172344-1-vikas.gupta%40broadcom.com
v3->v4:
- Addressed comments from Sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917064548.773334-1-vikas.gupta%40broadcom.com
https://sashiko.dev/#/patchset/20260917064548.773334-1-vikas.gupta%40broadcom.com
- The patch count drops to 10 now that the HSI patches have been merged.
v2->v3:
- Build fix.
- Addressed comments from Sashiko
https://sashiko.dev/#/patchset/20260908093053.2596020-1-vikas.gupta%40broadcom.com
Below Sashiko comments are not valid:
Patch-8:
Comment under bnge_toeplitz().
Explanation: bnge_toeplitz() is not used for aRFS.
Patch-9:
Comment regarding bnge_clear_usr_fltrs().
Explanation:
Both bnge_clear_usr_fltrs() (only invoked while the interface is down) and bnge_grxclsrule() execute under the netdev instance lock, so they are serialized and never touch the filter list at the same time.
Patch-10:
Comment "Does this direct dereference of the MAC header need a linearization ...".
Explanation: ndo_rx_flow_steer runs on the RX path
after eth_type_trans(), which already accesses and pulls the Ethernet header.
Comment Related to bnge_cfg_ntp_filters().
Explanation:
bnge_cfg_ntp_filters() runs from bnge_sp_task(), which holds the netdev instance lock while executing.v1->v2:
- Build fixes.
- Addressed comments from Sashiko
https://sashiko.dev/#/patchset/20260814011435.194631-1-vikas.gupta%40broadcom.com
Vikas Gupta (10):
bnge: restructure VNIC and filter code
bnge: add NTUPLE/ARFS VNIC
bnge: add helper functions for multi RSS contexts
bnge: add RXFH ethtool support
bnge: add ethtool support to manage RSS contexts
bnge: remove refcount from L2 filter
bnge: add NTUPLE filter infrastructure
bnge: add NTUPLE filter support in ethtool
bnge: add aRFS flow steering ndo support
bnge: add cpu_rmap support for IRQ affinity
drivers/net/ethernet/broadcom/bnge/Makefile | 4 +- drivers/net/ethernet/broadcom/bnge/bnge.h | 28 +- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 1140 +++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.c | 839 ++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.h | 137 ++ .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 192 ++- .../ethernet/broadcom/bnge/bnge_hwrm_lib.h | 9 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 689 +++++++--- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 102 +- .../net/ethernet/broadcom/bnge/bnge_resc.c | 164 ++- .../net/ethernet/broadcom/bnge/bnge_resc.h | 11 +- .../net/ethernet/broadcom/bnge/bnge_vnic.c | 379 ++++++ .../net/ethernet/broadcom/bnge/bnge_vnic.h | 96 ++ 13 files changed, 3423 insertions(+), 367 deletions(-) create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.h create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
Signature · 1 line
2.52.0
Vikas Gupta
maintainerPATCH v11 1/10 bnge: restructure VNIC and filter code
Move VNIC and L2 filter code out of bnge_netdev.c into dedicated bnge_vnic.c/h and bnge_filter.c/h files in preparation for multi-VNIC, RSS context, and NTUPLE filter support.
This is a code reorganization with no functional change, which helps centralize the functions into their respective modules.
The move comes with a few small cleanups:
- The BNGE_FLTR_TYPE_*, BNGE_FLTR_* state and BNGE_VNIC_*_FLAG macros become enums with new values. None of them reaches firmware, and all users are inside the driver.
- struct bnge_filter_base members hash and list are renamed to hlist and list_node.
- bnge_rss_ctxs_in_use() is renamed to bnge_get_total_rss_ctxs(), and bnge_get_total_vnics() no longer takes the rx_rings argument.
- bnge_fill_hw_rss_tbl() and bnge_set_dflt_rss_indir_tbl() use u16 indexes and temporaries; the values fit.
--- drivers/net/ethernet/broadcom/bnge/Makefile | 4 +- drivers/net/ethernet/broadcom/bnge/bnge.h | 7 - .../net/ethernet/broadcom/bnge/bnge_filter.c | 113 ++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.h | 58 ++++++ .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 2 + .../ethernet/broadcom/bnge/bnge_hwrm_lib.h | 2 + .../net/ethernet/broadcom/bnge/bnge_netdev.c | 170 +----------------- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 72 -------- .../net/ethernet/broadcom/bnge/bnge_resc.c | 31 +--- .../net/ethernet/broadcom/bnge/bnge_vnic.c | 100 +++++++++++ .../net/ethernet/broadcom/bnge/bnge_vnic.h | 63 +++++++ 11 files changed, 350 insertions(+), 272 deletions(-) create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_filter.h create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.c create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_vnic.h
drivers/net/ethernet/broadcom/bnge/Makefile +3 -1
@@ -12,4 +12,6 @@ bng_en-y := bnge_core.o \ bnge_ethtool.o \ bnge_auxr.o \ bnge_txrx.o \ - bnge_link.o + bnge_link.o \ + bnge_vnic.o \ + bnge_filter.o
drivers/net/ethernet/broadcom/bnge/bnge.h +0 -7
@@ -163,13 +163,6 @@ struct bnge_dev {#define BNGE_L2_FLTR_MAX_FLTR 1024u32 *rss_indir_tbl; -#define BNGE_RSS_TABLE_ENTRIES 64 -#define BNGE_RSS_TABLE_SIZE (BNGE_RSS_TABLE_ENTRIES * 4) -#define BNGE_RSS_TABLE_MAX_TBL 8 -#define BNGE_MAX_RSS_TABLE_SIZE \ - (BNGE_RSS_TABLE_SIZE * BNGE_RSS_TABLE_MAX_TBL) -#define BNGE_MAX_RSS_TABLE_ENTRIES \ - (BNGE_RSS_TABLE_ENTRIES * BNGE_RSS_TABLE_MAX_TBL)u16 rss_indir_tbl_entries;u32 rss_cap;
drivers/net/ethernet/broadcom/bnge/bnge_filter.c new file +113 -0
113 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h new file +58 -0
58 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +2 -0
@@ -15,6 +15,8 @@#include "bnge_rmem.h" #include "bnge_resc.h" #include "bnge_netdev.h" +#include "bnge_vnic.h" +#include "bnge_filter.h" static const u16 bnge_async_events_arr[] = {ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE ,
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.h +2 -0
@@ -4,6 +4,8 @@#ifndef _BNGE_HWRM_LIB_H_#define _BNGE_HWRM_LIB_H_ +struct bnge_l2_filter ; +#define BNGE_PLC_EN_JUMBO_THRES_VALID \ VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID#define BNGE_PLC_EN_HDS_THRES_VALID \
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +2 -168
182 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +0 -72
86 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +7 -24
@@ -11,6 +11,7 @@#include "bnge_hwrm.h" #include "bnge_hwrm_lib.h" #include "bnge_resc.h" +#include "bnge_vnic.h" static u16 bnge_num_tx_to_cp (struct bnge_dev *bd,u16 tx) {
@@ -202,13 +203,13 @@ int bnge_cal_nr_rss_ctxs(u16 rx_rings) BNGE_RSS_TABLE_MAX_TBL); } -static u16 bnge_rss_ctxs_in_use (struct bnge_dev *bd, -struct bnge_hw_rings *hwr) +static u16 bnge_get_total_rss_ctxs (struct bnge_dev *bd, +struct bnge_hw_rings *hwr) {return bnge_cal_nr_rss_ctxs (hwr->grp); } -static u16 bnge_get_total_vnics (struct bnge_dev *bd,u16 rx_rings) +static u16 bnge_get_total_vnics (struct bnge_dev *bd) {return 1 ; }
@@ -219,24 +220,6 @@ u32 bnge_get_rxfh_indir_size(struct bnge_dev *bd)BNGE_RSS_TABLE_ENTRIES ; } -static void bnge_set_dflt_rss_indir_tbl (struct bnge_dev *bd) -{ -u16 max_entries, pad; -u32 *rss_indir_tbl; -int i; - - max_entries =bnge_get_rxfh_indir_size (bd); - 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) -memset (&rss_indir_tbl[i],0 , pad *sizeof (*rss_indir_tbl)); -} -static void bnge_copy_reserved_rings (struct bnge_dev *bd,struct bnge_hw_rings *hwr) {
@@ -269,7 +252,7 @@ static bool bnge_need_reserve_rings(struct bnge_dev *bd)if (hw_resc->resv_tx_rings !=bnge_tx_rings_demand (bd))return true; - vnic =bnge_get_total_vnics (bd, rx); + vnic =bnge_get_total_vnics (bd);if (bnge_is_agg_reqd (bd)) rx <<=1 ;
@@ -315,12 +298,12 @@ int bnge_reserve_rings(struct bnge_dev *bd) sh = true; hwr.cmpl =bnge_cprs_demand (bd); - hwr.vnic =bnge_get_total_vnics (bd, hwr.rx); + hwr.vnic =bnge_get_total_vnics (bd);if (bnge_is_agg_reqd (bd)) hwr.rx <<=1 ; hwr.grp = bd->rx_nr_rings; - hwr.rss_ctx =bnge_rss_ctxs_in_use (bd, &hwr); + hwr.rss_ctx =bnge_get_total_rss_ctxs (bd, &hwr); hwr.stat =bnge_func_stat_ctxs_demand (bd); old_rx_rings = bd->hw_resc.resv_rx_rings; old_rx_nr_rings = bd->rx_nr_rings;
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c new file +100 -0
100 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.52.0
Vikas Gupta
maintainerPATCH v11 2/10 bnge: add NTUPLE/ARFS VNIC
In reply to Vikas GuptaInitialize the second VNIC, which is specifically used for the NTUPLE/ARFS feature. This VNIC helps support the aRFS/NTUPLE functionality. With this change, the total number of VNICs becomes 2.
The NTUPLE/aRFS VNIC is always allocated, so the function needs at least BNGE_BASE_VNICS (2) VNICs and the matching RSS contexts. Firmware grants these to every supported function. If it grants fewer, bnge_reserve_rings() fails with -ENOMEM and the device does not probe, so there is no fallback to a single VNIC.
NETIF_F_NTUPLE can only be changed while the interface is down. bnge_fix_features() keeps the current NTUPLE state while the interface is running, so a request made then stays in wanted_features. bnge_close() calls netdev_update_features() once netif_running() is false, which applies it through bnge_set_features(). The feature is not advertised yet; the patch that adds the ethtool rxnfc ops enables it.
bnge_reserve_rings() checks bnge_rings_ok() before it changes the driver ring counts (tx, rx and nq), so a failed reservation leaves them as they were. bnge_net_init_dflt_rings() calls it a second time at probe; a later call computes the reduction again and resets the default indirection table, instead of finding the reduced counts already in place.
The patch also removes BNGE_FW_CAP_CFA_NTUPLE_RX_EXT_IP_PROTO and BNGE_FW_CAP_CFA_RFS_RING_TBL_IDX_V3, which nothing uses, and renumbers BNGE_FW_CAP_VNIC_RE_FLUSH.
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 4 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 55 +++++++++++++++++-- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 1 + .../net/ethernet/broadcom/bnge/bnge_resc.c | 38 +++++++++---- .../net/ethernet/broadcom/bnge/bnge_vnic.c | 33 ++++++++++- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 8 ++- 6 files changed, 117 insertions(+), 22 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +1 -3
@@ -63,9 +63,7 @@ enum {BNGE_FW_CAP_THRESHOLD_TEMP_SUPPORTED =BIT_ULL (21 ),BNGE_FW_CAP_DFLT_VLAN_TPID_PCP =BIT_ULL (22 ),BNGE_FW_CAP_VNIC_TUNNEL_TPA =BIT_ULL (23 ), -BNGE_FW_CAP_CFA_NTUPLE_RX_EXT_IP_PROTO =BIT_ULL (24 ), -BNGE_FW_CAP_CFA_RFS_RING_TBL_IDX_V3 =BIT_ULL (25 ), - BNGE_FW_CAP_VNIC_RE_FLUSH = BIT_ULL(26), + BNGE_FW_CAP_VNIC_RE_FLUSH = BIT_ULL(24), }; enum {
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +49 -6
97 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +1 -0
@@ -152,6 +152,7 @@ enum {BNGE_NET_EN_GRO =BIT (0 ),BNGE_NET_EN_LRO =BIT (1 ),BNGE_NET_EN_JUMBO =BIT (2 ), + BNGE_NET_EN_NTUPLE = BIT(3), };#define BNGE_NET_EN_TPA (BNGE_NET_EN_GRO | BNGE_NET_EN_LRO)
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +28 -10
@@ -206,12 +206,16 @@ int bnge_cal_nr_rss_ctxs(u16 rx_rings)static u16 bnge_get_total_rss_ctxs (struct bnge_dev *bd,struct bnge_hw_rings *hwr) { -return bnge_cal_nr_rss_ctxs (hwr->grp); +u16 rss_ctx =bnge_cal_nr_rss_ctxs (hwr->grp); + + rss_ctx *= hwr->vnic; + +return rss_ctx; }static u16 bnge_get_total_vnics (struct bnge_dev *bd) { -return 1 ; +return BNGE_BASE_VNICS ; }u32 bnge_get_rxfh_indir_size (struct bnge_dev *bd)
@@ -237,8 +241,12 @@ static void bnge_copy_reserved_rings(struct bnge_dev *bd,static bool bnge_rings_ok (struct bnge_hw_rings *hwr) { -return hwr->tx && hwr->rx && hwr->nq && hwr->grp && hwr->vnic && - hwr->stat && hwr->cmpl; +/* The default and the NTUPLE VNICs each need a full set of RSS +* contexts for the final number of ring groups. +*/ +return hwr->tx && hwr->rx && hwr->nq && hwr->grp && + hwr->vnic >=BNGE_BASE_VNICS && hwr->stat && hwr->cmpl && + hwr->rss_ctx >=bnge_cal_nr_rss_ctxs (hwr->grp) *BNGE_BASE_VNICS ; }static bool bnge_need_reserve_rings (struct bnge_dev *bd)
@@ -247,18 +255,21 @@ static bool bnge_need_reserve_rings(struct bnge_dev *bd)u16 cprs =bnge_cprs_demand (bd);u16 rx = bd->rx_nr_rings, stat;u16 nqs =bnge_nqs_demand (bd); -u16 vnic; +struct bnge_hw_rings hwr = {};if (hw_resc->resv_tx_rings !=bnge_tx_rings_demand (bd))return true; - vnic =bnge_get_total_vnics (bd); + hwr.grp = bd->rx_nr_rings; + hwr.vnic =bnge_get_total_vnics (bd);if (bnge_is_agg_reqd (bd)) rx <<=1 ; stat =bnge_func_stat_ctxs_demand (bd);if (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cprs || - hw_resc->resv_vnics != vnic || hw_resc->resv_stat_ctxs != stat) + hw_resc->resv_vnics != hwr.vnic || + hw_resc->resv_rsscos_ctxs !=bnge_get_total_rss_ctxs (bd, &hwr) || + hw_resc->resv_stat_ctxs != stat)return true;if (hw_resc->resv_irqs != nqs)return true;
@@ -347,6 +358,16 @@ int bnge_reserve_rings(struct bnge_dev *bd) hwr.rx = rx_rings <<1 ; tx_cp = hwr.tx; hwr.nq = sh ?max_t (u16, tx_cp, rx_rings) : tx_cp + rx_rings; + +/* One ring group per rx ring, so rss_ctx is checked against the final +* rx ring count. Fail before the driver ring counts (tx, rx and nq) are +* changed, so that a failed call does not leave reduced counts behind +* for the next call to find unchanged. +*/ + hwr.grp = rx_rings; +if (!bnge_rings_ok (&hwr)) +return -ENOMEM ; + bd->tx_nr_rings = hwr.tx;if (!bd->num_tc) bd->tx_nr_rings_per_tc = bd->tx_nr_rings;
@@ -358,9 +379,6 @@ int bnge_reserve_rings(struct bnge_dev *bd) bd->rx_nr_rings = rx_rings; bd->nq_nr_rings = hwr.nq; -if (!bnge_rings_ok (&hwr)) -return -ENOMEM ; -if (old_rx_rings != bd->hw_resc.resv_rx_rings || old_rx_nr_rings != bd->rx_nr_rings)bnge_set_dflt_rss_indir_tbl (bd);
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +32 -1
@@ -42,7 +42,11 @@ void bnge_fill_hw_rss_tbl(struct bnge_net *bn, struct bnge_vnic_info *vnic)for (i =0 ; i < tbl_size; i++) {u16 ring_id, j; - j = bd->rss_indir_tbl[i]; +if (vnic->flags &BNGE_VNIC_NTUPLE_FLAG ) + j =ethtool_rxfh_indir_default (i, bd->rx_nr_rings); +else + j = bd->rss_indir_tbl[i]; + rxr = &bn->rx_ring[j]; ring_id = rxr->rx_ring_struct.fw_ring_id;
@@ -98,3 +102,30 @@ int bnge_setup_vnic(struct bnge_net *bn, struct bnge_vnic_info *vnic) }return rc; } + +static int bnge_alloc_and_setup_vnic (struct bnge_net *bn, +struct bnge_vnic_info *vnic, +u16 rx_rings) +{ +int rc; + + rc =bnge_hwrm_vnic_alloc (bn->bd, vnic, rx_rings); +if (rc) { +netdev_err (bn->netdev,"hwrm vnic %u alloc failure rc: %d\n" , + vnic->vnic_id, rc); +return rc; + } + +/* If bnge_setup_vnic() fails, the VNIC allocated above is not freed +* here; the caller (bnge_init_chip) unwinds via its err_out path. +*/ +return bnge_setup_vnic (bn, vnic); +} + +int bnge_alloc_rfs_vnic (struct bnge_net *bn) +{ +struct bnge_vnic_info *vnic; + + vnic = &bn->vnic_info[BNGE_VNIC_NTUPLE ]; +return bnge_alloc_and_setup_vnic (bn, vnic, bn->bd->rx_nr_rings); +}
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +6 -2
@@ -22,13 +22,16 @@ struct bnge_l2_filter;#define BNGE_MAX_UC_ADDRS 4enum { -BNGE_VNIC_DEFAULT =0 +BNGE_VNIC_DEFAULT =0 , +BNGE_VNIC_NTUPLE =1 , +BNGE_BASE_VNICS =2 };enum {BNGE_VNIC_RSS_FLAG =BIT (0 ),BNGE_VNIC_MCAST_FLAG =BIT (1 ), -BNGE_VNIC_UCAST_FLAG =BIT (2 ) +BNGE_VNIC_UCAST_FLAG =BIT (2 ), +BNGE_VNIC_NTUPLE_FLAG =BIT (3 ) };struct bnge_vnic_info {
@@ -60,4 +63,5 @@ 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); +int bnge_alloc_rfs_vnic (struct bnge_net *bn);#endif /* _BNGE_VNIC_H_ */
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 02/10] bnge: add NTUPLE/ARFS VNIC
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The patch makes the NTUPLE VNIC mandatory, which doubles the RSS-context demand, and nothing reduces the RX ring count to fit when…
--
bnge: add NTUPLE/ARFS VNIC
This patch sets up a second VNIC for NTUPLE/aRFS, which brings the total VNIC count to 2 and doubles the RSS context request. It adds ndo_fix_features/ndo_set_features handling for NETIF_F_NTUPLE. It also moves the bnge_rings_ok() check in bnge_reserve_rings() ahead of the ring count updates.
Quoted 15 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +5
-1@@ -206,12 +206,16 @@ int bnge_cal_nr_rss_ctxs(u16 rx_rings)static u16 bnge_get_total_rss_ctxs (struct bnge_dev *bd,struct bnge_hw_rings *hwr) { -return bnge_cal_nr_rss_ctxs (hwr->grp); +u16 rss_ctx =bnge_cal_nr_rss_ctxs (hwr->grp); + + rss_ctx *= hwr->vnic; + +return rss_ctx; }
[ ... ]
Quoted 11 lines
static bool
bnge_rings_ok(struct bnge_hw_rings *hwr){drivers/net/ethernet/broadcom/bnge/bnge_resc.c +6
-2-return hwr->tx && hwr->rx && hwr->nq && hwr->grp && hwr->vnic && - hwr->stat && hwr->cmpl; +/* The default and the NTUPLE VNICs each need a full set of RSS +* contexts for the final number of ring groups. +*/ +return hwr->tx && hwr->rx && hwr->nq && hwr->grp && + hwr->vnic >=BNGE_BASE_VNICS && hwr->stat && hwr->cmpl && + hwr->rss_ctx >=bnge_cal_nr_rss_ctxs (hwr->grp) *BNGE_BASE_VNICS ; }
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +0
-0@@ -347,6 +358,16 @@ int bnge_reserve_rings(struct bnge_dev *bd) hwr.rx = rx_rings <<1 ; tx_cp = hwr.tx; hwr.nq = sh ?max_t (u16, tx_cp, rx_rings) : tx_cp + rx_rings;
drivers/net/ethernet/broadcom/bnge/bnge_resc.c int bnge_reserve_rings(struct bnge_dev *bd) · line 370
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +10
-0+ +/* One ring group per rx ring, so rss_ctx is checked against the final +* rx ring count. Fail before the driver ring counts (tx, rx and nq) are +* changed, so that a failed call does not leave reduced counts behind +* for the next call to find unchanged. +*/ + hwr.grp = rx_rings; +if (!bnge_rings_ok (&hwr)) +return -ENOMEM ; +
[Severity: Medium]
If firmware grants fewer RSS contexts than requested, does this -ENOMEM now make the device fail to probe even when a smaller rx ring count would fit?
The number of contexts each VNIC needs grows with the rx ring count, because it comes from bnge_cal_nr_rss_ctxs(): 1 up to 64 rings, 2 for 65-128, 4 for 129-192, and so on up to 8. With two mandatory VNICs, the requirement checked in bnge_rings_ok() doubles.
Nothing on the default ring sizing path seems to limit rx rings by hw_resc->max_rsscos_ctxs or max_vnics. _bnge_get_max_rings() only clamps by ring groups and table size:
*max_rx = min_t(int, *max_rx, max_ring_grps);
*max_rx = min_t(int, *max_rx, BNGE_MAX_RSS_TABLE_ENTRIES);At probe, bnge_net_init_dflt_rings() calls bnge_reserve_rings() a second time. Now that the failure happens before the ring counts change, the retry uses the same counts and fails the same way. The code then does:
if (rc) {
bd->tx_nr_rings = 0;
bd->rx_nr_rings = 0;
}and probe fails.
For example, netif_get_num_default_rss_queues() can return more than 64 on a host with many cores. In that case each VNIC needs 2 contexts and the request is 4. If firmware grants only 2, the function could still run 64 rings on two VNICs, or keep the previous single-VNIC setup at the original ring count. Instead, it does not probe.
bnge_open() hits the same failure if the ring count is later raised past one of these context boundaries.
Would it make sense to reduce rx_rings to the largest count the granted resv_rsscos_ctxs can serve across BNGE_BASE_VNICS, instead of returning -ENOMEM? Later in the series, bnge_rss_ctx_capable() treats max_rsscos_ctxs and max_vnics as real limits for user RSS contexts. The base ring sizing does not use them.
The commit message says:
The NTUPLE/aRFS VNIC is always allocated, so the function needs at least BNGE_BASE_VNICS (2) VNICs and the matching RSS contexts. Firmware grants these to every supported function.
Could it also say that the number of RSS contexts needed grows with the rx ring count, and that rx rings are not reduced to fit the grant?
Quoted 3 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +0
-0bd->tx_nr_rings = hwr.tx;if (!bd->num_tc) bd->tx_nr_rings_per_tc = bd->tx_nr_rings;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v11 3/10 bnge: add helper functions for multi RSS contexts
In reply to Vikas GuptaAdd infrastructure for creating, modifying, and deleting user-defined RSS contexts. This helps the next patch implement commands for ethtool. For each user RSS context, a VNIC is allocated.
--- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 14 +-- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 2 + .../net/ethernet/broadcom/bnge/bnge_vnic.c | 113 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_vnic.h | 15 +++ 4 files changed, 132 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +2 -12
@@ -1126,7 +1126,7 @@ static int bnge_alloc_vnic_attributes(struct bnge_net *bn) {struct bnge_dev *bd = bn->bd;struct bnge_vnic_info *vnic; -int i, size; +int i;for (i =0 ; i < bn->nr_vnics; i++) { vnic = &bn->vnic_info[i];
@@ -1151,18 +1151,8 @@ static int bnge_alloc_vnic_attributes(struct bnge_net *bn) }/* Allocate rss table and hash key */ - size =L1_CACHE_ALIGN (BNGE_MAX_RSS_TABLE_SIZE ); - - vnic->rss_table_size = size +HW_HASH_KEY_SIZE ; - vnic->rss_table =dma_alloc_coherent (bd->dev, - vnic->rss_table_size, - &vnic->rss_table_dma_addr, -GFP_KERNEL ); -if (!vnic->rss_table) +if (bnge_alloc_vnic_rss_table (bn, vnic)) goto err_free_vnic_attributes; - - vnic->rss_hash_key = ((void *)vnic->rss_table) + size; - vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size; }return 0 ;
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +2 -0
@@ -376,6 +376,8 @@ struct bnge_net {u8 pri2cos_idx[8 ];bool pri2cos_valid; + +u16 num_rss_ctx; };#define BNGE_DEFAULT_RX_RING_SIZE 511
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +113 -0
116 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +15 -0
@@ -58,10 +58,25 @@ struct bnge_vnic_info {u32 vnic_id; }; +struct bnge_rss_ctx { +struct bnge_vnic_info vnic; +u32 index; +}; +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);int bnge_alloc_rfs_vnic (struct bnge_net *bn); +int bnge_alloc_vnic_rss_table (struct bnge_net *bn, +struct bnge_vnic_info *vnic); +struct bnge_rss_ctx *bnge_get_rss_ctx_from_index (struct bnge_net *bn,u32 idx); +void bnge_modify_rss (struct bnge_net *bn,struct ethtool_rxfh_context *ctx, +struct bnge_rss_ctx *rss_ctx, +const struct ethtool_rxfh_param *rxfh); +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);#endif /* _BNGE_VNIC_H_ */
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 03/10] bnge: add helper functions for multi RSS contexts
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] At this commit, bnge_modify_rss() stores a user RSS context's indirection table in ethtool_rxfh_context_indir(ctx).
- [Medium] At this commit, bnge_modify_rss() zero-pads a user context's indirection table out to bd->rss_indir_tbl_entries (512) with…
- [Medium] This patch adds bn->num_rss_ctx but nothing reads it, and only bnge_del_one_rss_ctx() decrements it.
- [Medium] struct bnge_rss_ctx sits in the ethtool core's kzalloc'ed private area, so the embedded bnge_vnic_info starts with vnic_id == 0…
- [Low] At this commit, bnge_hwrm_realloc_rss_ctx_vnic() walks netdev->ethtool->rss_ctx and calls ethtool_rxfh_context_lost()…
- [Low] bnge_hwrm_realloc_rss_ctx_vnic() prints the u32 field rss_ctx->index with a signed %d: netdev_err(bn->netdev, "Failed to…
- [Low] With all=true, bnge_del_one_rss_ctx() calls dma_free_coherent() on vnic->rss_table but does not set vnic->rss_table or…
--
bnge: add helper functions for multi RSS contexts
This commit moves the per-VNIC RSS table allocation into a new helper, bnge_alloc_vnic_rss_table(). It also adds helpers to modify, restore, clear and delete user-defined RSS contexts, and each context gets its own VNIC. Finally, it adds struct bnge_rss_ctx and a num_rss_ctx counter to struct bnge_net.
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h struct bnge_net { · line 381
Quoted 11 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +2
-0@@ -376,6 +376,8 @@ struct bnge_net {u8 pri2cos_idx[8 ];bool pri2cos_valid; + +u16 num_rss_ctx; };
[Severity: Medium]
In this patch nothing reads or increments num_rss_ctx. The only access is the decrement in bnge_del_one_rss_ctx(). Also, bnge_get_total_vnics() still returns a constant:
drivers/net/ethernet/broadcom/bnge/bnge_resc.c:bnge_get_total_vnics() {
return BNGE_BASE_VNICS;
}Would the firmware VNIC and RSS context reservation then miss the VNICs that bnge_hwrm_realloc_rss_ctx_vnic() allocates for user contexts?
The helpers have no callers yet. The follow-up commit "bnge: add ethtool support to manage RSS contexts" adds bn->num_rss_ctx to bnge_get_total_vnics(), increments the counter in bnge_create_rxfh_context() and checks bnge_rss_ctx_capable(). Could the counter be added in the same patch as its users?
Quoted 15 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +7
-0@@ -129,3 +129,116 @@ int bnge_alloc_rfs_vnic(struct bnge_net *bn) vnic = &bn->vnic_info[BNGE_VNIC_NTUPLE ];return bnge_alloc_and_setup_vnic (bn, vnic, bn->bd->rx_nr_rings); } + +void bnge_modify_rss (struct bnge_net *bn,struct ethtool_rxfh_context *ctx, +struct bnge_rss_ctx *rss_ctx, +const struct ethtool_rxfh_param *rxfh) +{ +struct bnge_dev *bd = bn->bd; +
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c int bnge_alloc_rfs_vnic(struct bnge_net *bn) · line 154
Quoted 6 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +6
-0+if (rxfh->indir) { +u32 i, pad, tbl_size =bnge_get_rxfh_indir_size (bd); +u32 *indir_tbl = bd->rss_indir_tbl; + +if (rss_ctx) + indir_tbl =ethtool_rxfh_context_indir (ctx);
[Severity: Medium]
For a user context, the indirection table goes into ethtool_rxfh_context_indir(ctx). Is that table ever read when the hardware is programmed?
The context VNIC is set up through this chain:
bnge_hwrm_realloc_rss_ctx_vnic()
bnge_setup_vnic()
bnge_hwrm_vnic_rss_cfg()
bnge_hwrm_vnic_set_rss()
bnge_fill_hw_rss_tbl()bnge_fill_hw_rss_tbl() only handles the ntuple VNIC and the default table:
if (vnic->flags & BNGE_VNIC_NTUPLE_FLAG) j = ethtool_rxfh_indir_default(i, bd->rx_nr_rings); else j = bd->rss_indir_tbl[i];
struct bnge_vnic_info has no back-pointer to the ethtool context, and there is no RSS context VNIC flag. Would a context VNIC then be programmed with the default context's queue spread?
These helpers have no callers at this commit. Later in the series, "bnge:
add ethtool support to manage RSS contexts" adds BNGE_VNIC_RSSCTX_FLAG and vnic->rss_ctx, and makes bnge_fill_hw_rss_tbl() read the per-context table.
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c int bnge_alloc_rfs_vnic(struct bnge_net *bn) · line 159
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +5
-0+for (i =0 ; i < tbl_size; i++) + indir_tbl[i] = rxfh->indir[i]; + pad = bd->rss_indir_tbl_entries - tbl_size; +if (pad) +memset (&indir_tbl[i],0 , pad *sizeof (*indir_tbl));
[Severity: Medium]
When rss_ctx is set, indir_tbl points into the context, and the ethtool core sizes that area in ethtool_rxfh_ctx_alloc() as:
indir_max = max(indir_size, ops->rxfh_indir_space)
bnge does not set rxfh_indir_space at this commit. If a context were created with a 64-entry table, could this memset() pad out to bd->rss_indir_tbl_entries and write past the end of that area?
Nothing calls this with a non-NULL ctx yet. Later in the series, "bnge:
add RXFH ethtool support" sets .rxfh_indir_space to BNGE_MAX_RSS_TABLE_ENTRIES. Then "bnge: add ethtool support to manage RSS contexts" changes the condition to if (pad && !rss_ctx), so context tables are never padded.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +4
-0+ } +} + +void bnge_del_one_rss_ctx(struct bnge_net *bn, struct bnge_rss_ctx *rss_ctx,
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c int bnge_alloc_rfs_vnic(struct bnge_net *bn) · line 173
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +10
-0+ bool all) +{ +struct bnge_vnic_info *vnic = &rss_ctx->vnic; +int i; + +bnge_hwrm_vnic_free_one (bn->bd, &rss_ctx->vnic); +for (i =0 ; i <BNGE_MAX_CTX_PER_VNIC ; i++) { +if (vnic->fw_rss_cos_lb_ctx[i] !=INVALID_HW_RING_ID ) +bnge_hwrm_vnic_ctx_free_one (bn->bd, vnic, i); + }
[Severity: Medium]
struct bnge_rss_ctx lives in the ethtool core's kzalloc'ed private area. So the embedded vnic starts with vnic_id, fw_vnic_id and fw_rss_cos_lb_ctx[] all set to 0, and none of the helpers here initialize them.
bnge_hwrm_vnic_free_one() only skips the free when fw_vnic_id is INVALID_HW_RING_ID. For a context that never got a firmware VNIC, would this send HWRM_VNIC_FREE for VNIC ID 0? The fw_rss_cos_lb_ctx[] loop above has the same problem.
The same issue shows up in bnge_hwrm_vnic_alloc():
if (vnic->vnic_id == BNGE_VNIC_DEFAULT) req->flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
If bnge_hwrm_realloc_rss_ctx_vnic() passes a context VNIC that still has vnic_id 0, is it requested as a default VNIC?
There are no callers at this commit. Later, "bnge: add ethtool support to manage RSS contexts" adds bnge_init_vnic_mem(), and bnge_create_rxfh_context() calls it and sets a non-default vnic_id before any firmware call.
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c int bnge_alloc_rfs_vnic(struct bnge_net *bn) · line 182
Quoted 9 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +9
-0+ +if (!all) +return ; + +if (vnic->rss_table) +dma_free_coherent (bn->bd->dev, vnic->rss_table_size, + vnic->rss_table, + vnic->rss_table_dma_addr); + bn->num_rss_ctx--;
[Severity: Low]
This isn't a bug, but vnic->rss_table and vnic->rss_hash_key still point at the freed DMA buffer after dma_free_coherent(). A second all=true call on the same context would free it twice.
As far as I can tell, no path does that. Every all=true caller in the series is followed by the ethtool core or ethtool_rxfh_context_lost() erasing and freeing the context. bnxt_del_one_rss_ctx() works the same way. Would it still be worth setting the pointers to NULL here?
Quoted 7 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +7
-0+} + +void bnge_hwrm_realloc_rss_ctx_vnic (struct bnge_net *bn) +{ +u32 tpa_flags = bn->priv_flags &BNGE_NET_EN_TPA ; +struct ethtool_rxfh_context *ctx; +unsigned long context;
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c int bnge_alloc_rfs_vnic(struct bnge_net *bn) · line 199
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +10
-0+ +xa_for_each (&bn->netdev->ethtool->rss_ctx, context, ctx) { +struct bnge_rss_ctx *rss_ctx =ethtool_rxfh_context_priv (ctx); +struct bnge_vnic_info *vnic = &rss_ctx->vnic; + +if (bnge_hwrm_vnic_alloc (bn->bd, vnic, bn->bd->rx_nr_rings) || +bnge_hwrm_vnic_set_tpa (bn->bd, vnic, tpa_flags) || +bnge_setup_vnic (bn, vnic)) { +netdev_err (bn->netdev,"Failed to restore RSS ctx %d\n" , + rss_ctx->index);
[Severity: Low]
This isn't a bug, but rss_ctx->index is a u32 and is printed with %d. The vnic_id prints in bnge_vnic.c use %u, and bnge_modify_rxfh_context() later in the series prints this same field with %u. Should this be %u too?
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c int bnge_alloc_rfs_vnic(struct bnge_net *bn) · line 201
Quoted 2 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +2
-0+bnge_del_one_rss_ctx (bn, rss_ctx, true); +ethtool_rxfh_context_lost (bn->netdev, rss_ctx->index);
[Severity: Low]
This loop walks netdev->ethtool->rss_ctx and calls ethtool_rxfh_context_lost(), which does xa_erase() and kfree(), without holding netdev->ethtool->rss_lock. bnge uses request_ops_lock, so rtnl is not guaranteed to be held either. ethtool_rxfh_context_lost() checks:
WARN_ONCE(!rtnl_is_locked() && !lockdep_is_held_type(&dev->ethtool->rss_lock, -1), "RSS context lock assertion failed\n");
Would a caller of this function hit that warning?
Nothing calls this yet, and "bnge: add ethtool support to manage RSS contexts" wraps the loop in rss_lock. bnge_clear_rss_ctxs() is still unlocked at the end of the series. However, it only runs from bnge_close_core() under the netdev instance lock, that lock also serializes context create and delete in net/ethtool/rss.c, and the function does not change the xarray.
Quoted 3 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +3
-0+ } + } +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v11 4/10 bnge: add RXFH ethtool support
In reply to Vikas GuptaIntroduce 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.
The default RSS key changes. It used to be a per-device get_random_bytes() key created on first open in bnge_init_vnics(). It is now the system-wide netdev_rss_key_fill() key set in bnge_netdev_alloc(), and rss_hash_key_valid is removed.
bnge_alloc_irqs() can reduce the RX ring count after the default indirection table was filled in bnge_net_init_dflt_config(). Reset the table when the count changes, so get_rxfh and the first open do not see entries for rings that no longer exist.
bnge_reserve_rings() keeps a user-configured default indirection table when the RX ring count changes and the table still fits, and resets it otherwise. A table that is reset is reported with ethtool_rxfh_indir_lost(), so the core stops reporting it as user-configured. Before, the table was always reset while rss_indir_user_size stayed set.
Also remove the VNIC_QCAPS_RESP_FLAGS_RSS_HASH_TYPE_DELTA_CAP handling, since firmware never sets this flag.
Add BNGE_RSS_CAP_IPV6_FLOW_LABEL_RSS_CAP, set from VNIC_QCAPS_RESP_FLAGS_RSS_IPV6_FLOW_LABEL_CAP and used by set_rxfh_fields. Dropping the DELTA bit renumbers the BNGE_RSS_CAP_* values.
The ethtool ops also declare the RSS context limits (per-context key, maximum number of contexts, indirection table space and private size). They take effect with the context callbacks added in
"bnge: add ethtool support to manage RSS contexts".
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 16 +- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 345 ++++++++++++++++++ .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 24 +- .../ethernet/broadcom/bnge/bnge_hwrm_lib.h | 1 - .../net/ethernet/broadcom/bnge/bnge_netdev.c | 14 +- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 1 - .../net/ethernet/broadcom/bnge/bnge_resc.c | 48 ++- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 1 + 8 files changed, 400 insertions(+), 50 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +8 -8
@@ -77,14 +77,14 @@ enum {#define BNGE_EN_ROCE (BNGE_EN_ROCE_V1 | BNGE_EN_ROCE_V2)enum { -BNGE_RSS_CAP_RSS_HASH_TYPE_DELTA =BIT (0 ), -BNGE_RSS_CAP_UDP_RSS_CAP =BIT (1 ), -BNGE_RSS_CAP_NEW_RSS_CAP =BIT (2 ), -BNGE_RSS_CAP_RSS_TCAM =BIT (3 ), -BNGE_RSS_CAP_AH_V4_RSS_CAP =BIT (4 ), -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_UDP_RSS_CAP =BIT (0 ), +BNGE_RSS_CAP_NEW_RSS_CAP =BIT (1 ), +BNGE_RSS_CAP_RSS_TCAM =BIT (2 ), +BNGE_RSS_CAP_AH_V4_RSS_CAP =BIT (3 ), +BNGE_RSS_CAP_AH_V6_RSS_CAP =BIT (4 ), +BNGE_RSS_CAP_ESP_V4_RSS_CAP =BIT (5 ), +BNGE_RSS_CAP_ESP_V6_RSS_CAP =BIT (6 ), +BNGE_RSS_CAP_IPV6_FLOW_LABEL_RSS_CAP =BIT (7 ), };#define BNGE_MAX_QUEUE 8
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +345 -0
363 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +2 -22
@@ -660,8 +660,6 @@ int bnge_hwrm_vnic_qcaps(struct bnge_dev *bd)if (flags &VNIC_QCAPS_RESP_FLAGS_VLAN_STRIP_CAP ) bd->fw_cap |=BNGE_FW_CAP_VLAN_RX_STRIP ; -if (flags &VNIC_QCAPS_RESP_FLAGS_RSS_HASH_TYPE_DELTA_CAP ) - bd->rss_cap |=BNGE_RSS_CAP_RSS_HASH_TYPE_DELTA ;if (flags &VNIC_QCAPS_RESP_FLAGS_RSS_PROF_TCAM_MODE_ENABLED ) bd->rss_cap |=BNGE_RSS_CAP_RSS_TCAM ; bd->max_tpa_v2 =le16_to_cpu (resp->max_aggs_supported);
@@ -677,6 +675,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);
@@ -867,26 +867,6 @@ int bnge_hwrm_vnic_cfg(struct bnge_net *bn, struct bnge_vnic_info *vnic)return bnge_hwrm_req_send (bd, req); } -void bnge_hwrm_update_rss_hash_cfg (struct bnge_net *bn) -{ -struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ]; -struct hwrm_vnic_rss_qcfg_output *resp; -struct hwrm_vnic_rss_qcfg_input *req; -struct bnge_dev *bd = bn->bd; - -if (bnge_hwrm_req_init (bd, req,HWRM_VNIC_RSS_QCFG )) -return ; - - req->vnic_id =cpu_to_le16 (vnic->fw_vnic_id); -/* all contexts configured to same hash_type, zero always exists */ - req->rss_ctx_idx =cpu_to_le16 (vnic->fw_rss_cos_lb_ctx[0 ]); - resp =bnge_hwrm_req_hold (bd, req); -if (!bnge_hwrm_req_send (bd, req)) - bd->rss_hash_cfg = -le32_to_cpu (resp->hash_type) ?: bd->rss_hash_cfg; -bnge_hwrm_req_drop (bd, req); -} -int bnge_hwrm_l2_filter_free (struct bnge_dev *bd,struct bnge_l2_filter *fltr) {struct hwrm_cfa_l2_filter_free_input *req;
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.h +0 -1
@@ -39,7 +39,6 @@ int bnge_hwrm_vnic_ctx_alloc(struct bnge_dev *bd,int bnge_hwrm_vnic_set_rss (struct bnge_net *bn,struct bnge_vnic_info *vnic,bool set_rss);int bnge_hwrm_vnic_cfg (struct bnge_net *bn,struct bnge_vnic_info *vnic); -void bnge_hwrm_update_rss_hash_cfg (struct bnge_net *bn);int bnge_hwrm_vnic_alloc (struct bnge_dev *bd,struct bnge_vnic_info *vnic,unsigned int nr_rings);void bnge_hwrm_vnic_free_one (struct bnge_dev *bd,struct bnge_vnic_info *vnic);
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +3 -11
@@ -1780,13 +1780,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 );
@@ -1794,7 +1787,6 @@ static void bnge_init_vnics(struct bnge_net *bn)continue ; bn->rss_hash_key_updated = false; - bn->rss_hash_key_valid = true; bn->toeplitz_prefix =0 ;for (k =0 ; k <8 ; k++) {
@@ -2637,9 +2629,6 @@ static int bnge_init_chip(struct bnge_net *bn) goto err_out; } -if (bd->rss_cap &BNGE_RSS_CAP_RSS_HASH_TYPE_DELTA ) -bnge_hwrm_update_rss_hash_cfg (bn); -if (bn->priv_flags &BNGE_NET_EN_TPA ) { rc =bnge_set_tpa (bn, true);if (rc)
@@ -3616,6 +3605,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);
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +0 -1
@@ -338,7 +338,6 @@ struct bnge_net {u16 rx_dma_offset;u8 rss_hash_key[HW_HASH_KEY_SIZE ]; - u8 rss_hash_key_valid:1; u8 rss_hash_key_updated:1;int rsscos_nr_ctxs;u32 stats_coal_ticks;
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +41 -7
99 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +1 -0
@@ -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
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 04/10] bnge: add RXFH ethtool support
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In bnge_get_rxfh_fields() (drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c), the…
- [Low] bnge_reserve_rings() (drivers/net/ethernet/broadcom/bnge/bnge_resc.c) treats any change in…
--
bnge: add RXFH ethtool support
This adds ethtool get/set_rxfh and get/set_rxfh_fields support to bnge. Configuration changes are only allowed while the device is down. It also moves the default RSS key to netdev_rss_key_fill(), and makes bnge_reserve_rings() keep a user-configured indirection table when it still fits, reporting a reset table with ethtool_rxfh_indir_lost().
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +8
-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 ; +}
[ ... ]
Quoted 6 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +6
-0+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 ;
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +4
-0+static int bnge_set_rxfh_fields (struct net_device *dev, +const struct ethtool_rxfh_fields *cmd, +struct netlink_ext_ack *extack) +{
[ ... ]
Quoted 3 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +3
-0+if (cmd->data ==RXH_4TUPLE || + cmd->data == (RXH_4TUPLE |RXH_IP6_FL )) + tuple =4 ;
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c static int bnge_set_pauseparam(struct net_device *dev, · line 978
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +10
-0+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_FLOW_LABEL ))) { + rss_hash_cfg |=VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 ; + rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6_FLOW_LABEL ;
[Severity: Medium]
Can the hardware hash on the L4 ports and the IPv6 flow label at the same time?
bnge_set_rxfh_fields() accepts RXH_4TUPLE | RXH_IP6_FL as tuple 4. For tcp6 this sets TCP_IPV6 and IPV6_FLOW_LABEL and clears IPV6. After that, bnge_get_rxfh_fields() reports tcp6 as RXH_4TUPLE | RXH_IP6_FL, because the TCP_V6_FLOW case ORs in bnge_get_ethtool_ipv6_rss().
The RX completion hash types decoded by bnge_rss_ext_op() in bnge_hw_def.h appear to cover only the 4-tuple or the flow-label 3-tuple:
#define EXT_OP_INNER_4 0x0
#define EXT_OP_OUTER_4 0x2
#define EXT_OP_INNFL_3 0x8
#define EXT_OP_OUTFL_3 0xa
None of these is a ports-plus-flow-label type. That would mean TCP over IPv6 is still hashed on the 4-tuple only.
If so, "ethtool -N <dev> rx-flow-hash tcp6 sdfnl" doesn't change tcp6 hashing. What it does change is all other IPv6 traffic, which moves from the 2-tuple hash to the flow-label 3-tuple hash.
The reverse also happens. Setting plain RXH_4TUPLE on tcp6 while the flow label is enabled takes the "tuple == 4 && IPV6_FLOW_LABEL" branch above. That turns off flow-label hashing for every IPv6 flow type.
For comparison, bnxt_set_rxfh_fields() only accepts RXH_IP6_FL with the 2-tuple. Should bnge reject RXH_4TUPLE | RXH_IP6_FL in the same way? And should bnge_get_rxfh_fields() stop reporting RXH_IP6_FL for an L4 flow type when that type's 4-tuple hash is enabled?
This code is unchanged at the end of the series.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +0
-1@@ -372,16 +386,31 @@ int bnge_reserve_rings(struct bnge_dev *bd)if (!bd->num_tc) bd->tx_nr_rings_per_tc = bd->tx_nr_rings; -if (rx_rings != bd->rx_nr_rings)
drivers/net/ethernet/broadcom/bnge/bnge_resc.c int bnge_reserve_rings(struct bnge_dev *bd) · line 398
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +8
-0+ rx_changed = rx_rings != bd->rx_nr_rings; +if (rx_changed) {dev_warn (bd->dev,"RX rings resv reduced to %d than earlier %d requested\n" , rx_rings, bd->rx_nr_rings); + indir_lost = bd->netdev && +netif_is_rxfh_configured (bd->netdev) && + (bnge_cal_nr_rss_ctxs (bd->rx_nr_rings) != +bnge_cal_nr_rss_ctxs (rx_rings) || +bnge_get_max_rss_ring (bd) >= rx_rings); + }
[Severity: Low]
Is a change in bnge_cal_nr_rss_ctxs() enough by itself to treat the user's table as lost?
bnge_get_rxfh_indir_size() is nr_rss_ctxs * BNGE_RSS_TABLE_ENTRIES, so a change in the context count means the table shrinks. The ethtool core already provides ethtool_rxfh_indir_can_resize() and ethtool_rxfh_indir_resize() for this case. ethtool_rxfh_can_resize() allows a shrink when the table is periodic:
if (new_size < old_size) {
if (new_size < user_size)
return false;
if (old_size % new_size)
return false;
if (!ethtool_rxfh_is_periodic(tbl, old_size, new_size))
return false;
return true;
}A short table set over netlink is replicated across the device table, so it meets these conditions. One example is a 64-entry user table whose entries all point at rings below the new rx count.
In bnge_reserve_rings() such a table is still reset by bnge_set_dflt_rss_indir_tbl(). ethtool_rxfh_indir_lost() is then called, which does three things:
- logs "device error, RSS indirection table lost"
- clears rss_indir_user_size
- sends ETHTOOL_MSG_RSS_NTF
The ethtool_rxfh_indir_lost() kernel-doc says to call it when the device can no longer maintain the user-configured indirection table.
bnxt_reserve_rings() uses the same conservative condition. The commit message also says the table is reset when it no longer "fits", so this looks intentional.
Would it make sense to check with the core helpers whether the table can be folded into the smaller size before dropping it?
This code is unchanged at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v11 5/10 bnge: add ethtool support to manage RSS contexts
In reply to Vikas GuptaIntroduce 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.
The patch also changes existing behaviour:
- bnge_fill_hw_rss_tbl() remaps out-of-range entries for every VNIC, including the default one.
- bnge_del_one_rss_ctx() resets fw_rss_cos_lb_ctx[] and decrements rsscos_nr_ctxs, and bnge_hwrm_realloc_rss_ctx_vnic() takes rss_lock.
RSS contexts do not depend on NTUPLE. They can be created and kept whether NTUPLE is on or off. Turning NTUPLE off deletes the user rules but keeps the contexts.
When the number of RX rings changes at open, a user RSS context whose table no longer fits is deleted and reported with ethtool_rxfh_context_lost(): either the RSS table size changes with the ring count, or the table names a ring that no longer exists. A table is not folded to the new size, even when that would be possible. The NTUPLE rules steered to a deleted context (added later in the series) are deleted with it. Contexts that use the default table are resized.
--- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 172 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_netdev.c | 4 + .../net/ethernet/broadcom/bnge/bnge_resc.c | 61 ++++++- .../net/ethernet/broadcom/bnge/bnge_resc.h | 1 + .../net/ethernet/broadcom/bnge/bnge_vnic.c | 133 +++++++++++++- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 16 +- 6 files changed, 372 insertions(+), 15 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +172 -0
@@ -1073,6 +1073,175 @@ 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 (!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_rss_ctx_capable (bn->bd)) { +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); +/* Number the VNIC after the base VNICs, so that its error messages +* tell the RSS contexts apart. The invalid id would print the same +* for every context. +*/ + vnic->vnic_id =BNGE_BASE_VNICS + rxfh->rss_context; + + 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); +u8 old_key[HW_HASH_KEY_SIZE ]; +struct bnge_rss_ctx *rss_ctx; +u32 *old_indir =NULL ; +u32 tbl_size; +int rc; + + rc =bnge_rxfh_context_check (bn, rxfh, extack); +if (rc) +return rc; + + rss_ctx =ethtool_rxfh_context_priv (ctx); + tbl_size =bnge_get_rxfh_indir_size (bn->bd); + +if (ctx->indir_size != tbl_size) { +NL_SET_ERR_MSG_MOD (extack, +"RSS context indirection table size mismatch" ); +return -EINVAL ; + } + +/* Snapshot the software state so it can be restored if the hardware +* update fails, keeping the reported config consistent with the +* hardware. +*/ +if (rxfh->key) +memcpy (old_key, rss_ctx->vnic.rss_hash_key,HW_HASH_KEY_SIZE ); +if (rxfh->indir) { + old_indir =kmemdup (ethtool_rxfh_context_indir (ctx), + tbl_size *sizeof (*old_indir),GFP_KERNEL ); +if (!old_indir) +return -ENOMEM ; + } + +bnge_modify_rss (bn, ctx, rss_ctx, rxfh); + + rc =bnge_hwrm_vnic_rss_cfg (bn, &rss_ctx->vnic); +if (rc) { +if (rxfh->key) +memcpy (rss_ctx->vnic.rss_hash_key, old_key, +HW_HASH_KEY_SIZE ); +if (rxfh->indir) +memcpy (ethtool_rxfh_context_indir (ctx), old_indir, + tbl_size *sizeof (*old_indir)); +/* Part of the update may have reached the device */ +if (bnge_hwrm_vnic_rss_cfg (bn, &rss_ctx->vnic)) +netdev_warn (dev,"Failed to restore RSS context %u\n" , + rss_ctx->index); + } + +kfree (old_indir); +return rc; +} + +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,
@@ -1102,6 +1271,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)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +4 -0
@@ -2974,6 +2974,8 @@ static 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:
@@ -3219,6 +3221,8 @@ static 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_nq0_napi_to_wq (bn);
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +57 -4
103 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_resc.h +1 -0
@@ -75,6 +75,7 @@ void bnge_aux_init_dflt_config(struct bnge_dev *bd);u32 bnge_get_rxfh_indir_size (struct bnge_dev *bd);int bnge_cal_nr_rss_ctxs (u16 rx_rings);bool bnge_aux_has_enough_resources (struct bnge_dev *bd); +bool bnge_rss_ctx_capable (struct bnge_dev *bd);static inline u32 bnge_adjust_pow_two (u32 total_ent,u16 ent_per_blk)
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +124 -9
211 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +14 -2
@@ -22,6 +22,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 ,
@@ -32,7 +37,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 {
@@ -57,6 +63,8 @@ struct bnge_vnic_info {u32 flags;u32 vnic_id; + +struct ethtool_rxfh_context *rss_ctx; };struct bnge_rss_ctx {
@@ -68,7 +76,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,6 +87,9 @@ void bnge_modify_rss(struct bnge_net *bn, struct ethtool_rxfh_context *ctx, const struct ethtool_rxfh_param *rxfh);void bnge_del_one_rss_ctx (struct bnge_net *bn,struct bnge_rss_ctx *rss_ctx,bool all); +void bnge_check_rss_ctxs_lost (struct bnge_dev *bd,u16 new_rx_rings); +void bnge_refill_dflt_rss_ctxs (struct bnge_dev *bd);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_ */
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 05/10] bnge: add ethtool support to manage RSS contexts
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In drivers/net/ethernet/broadcom/bnge/bnge_vnic.c, bnge_refill_dflt_rss_ctxs() sends RSS notifications with the wrong…
--
bnge: add ethtool support to manage RSS contexts
This patch adds ethtool callbacks to create, modify and remove RSS contexts. Each context gets its own VNIC with its own indirection table and hash key. When the RX ring count changes, contexts whose user tables no longer fit are deleted. Contexts that use the default table are resized and refilled.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +2
-1@@ -403,7 +422,8 @@ int bnge_reserve_rings(struct bnge_dev *bd)if (old_rx_rings != bd->hw_resc.resv_rx_rings || rx_changed) {if (!bd->netdev || indir_lost || !netif_is_rxfh_configured (bd->netdev)) -bnge_set_dflt_rss_indir_tbl (bd); +bnge_set_dflt_rss_indir_tbl (bd,NULL ); +bnge_refill_dflt_rss_ctxs (bd); }
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +0
-0
[ ... ]
Quoted 31 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +31
-0+void bnge_refill_dflt_rss_ctxs (struct bnge_dev *bd) +{ +struct ethtool_rxfh_context *ctx; +unsigned long context; +bool resize = false; +u32 tbl_size; + +if (!bd->netdev) +return ; + + tbl_size =bnge_get_rxfh_indir_size (bd); +mutex_lock (&bd->netdev->ethtool->rss_lock); +xa_for_each (&bd->netdev->ethtool->rss_ctx, context, ctx) { +if (ctx->indir_size != tbl_size) { + resize = true; +break ; + } + } +mutex_unlock (&bd->netdev->ethtool->rss_lock); + +/* bnge_check_rss_ctxs_lost() already dropped every context with a +* user table when the table size changed, even if the table could +* have been folded. Only the default contexts are resized here. +*/ +if (resize) { +if (ethtool_rxfh_ctxs_can_resize (bd->netdev, tbl_size)) { +dev_warn (bd->dev, +"RSS contexts cannot be resized to %u entries\n" , + tbl_size); +return ; + }
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c void bnge_hwrm_realloc_rss_ctx_vnic(struct bnge_net *bn) · line 308
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +9
-0+ethtool_rxfh_ctxs_resize (bd->netdev, tbl_size); + } + +mutex_lock (&bd->netdev->ethtool->rss_lock); +xa_for_each (&bd->netdev->ethtool->rss_ctx, context, ctx) { +if (!ctx->indir_user_size) +bnge_set_dflt_rss_indir_tbl (bd, ctx); + } +mutex_unlock (&bd->netdev->ethtool->rss_lock); }
[Severity: Medium]
Does this send RSS notifications that carry the wrong indirection table for contexts using the default table?
ethtool_rxfh_ctxs_resize() in net/ethtool/common.c replicates the old entries into the new size and then notifies each context:
net/ethtool/common.c:ethtool_rxfh_ctxs_resize() {
...
xa_for_each(&dev->ethtool->rss_ctx, context, ctx) {
ethtool_rxfh_resize(ethtool_rxfh_context_indir(ctx),
ctx->indir_size, new_indir_size);
ctx->indir_size = new_indir_size;
}
mutex_unlock(&dev->ethtool->rss_lock);
xa_for_each(&dev->ethtool->rss_ctx, context, ctx)
ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_NTF, context);
}The ETHTOOL_MSG_RSS_NTF payload is built right away from ethtool_rxfh_context_indir(ctx), so it contains the old ring layout stretched to the new size.
Only after that does bnge_refill_dflt_rss_ctxs() overwrite the table with i % bd->rx_nr_rings for the new ring count. bnge_fill_hw_rss_tbl() later programs that rewritten table into the VNIC. No second notification is sent.
For example, going from 64 to 128 entries, the notified entry 64 is the old tbl[0] == 0. The stored and programmed value is 64 % M, where M is the new ring count.
When the ring count changes but bnge_get_rxfh_indir_size() stays the same, there is no resize at all. The default context tables are rewritten and no notification goes out.
In both cases, a listener such as ethtool --monitor ends up with a table that matches neither the kernel state nor the hardware. Could the default contexts be refilled first, with the notifications sent after the final table is written?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v11 6/10 bnge: remove refcount from L2 filter
In reply to Vikas GuptaA reference count was previously used under the assumption that any context holding the last reference could delete the L2 filter.
However, going forward, the filter will only be removed by the same context that created it, making refcount unnecessary.
With no reference to take, bnge_alloc_l2_filter() now returns ERR_PTR(-EEXIST) when a filter for the same MAC/VLAN key already exists, instead of taking a reference and returning that filter.
The L2 filter hash table is no longer walked under RCU. bnge_lookup_l2_filter(), which also takes over the RCU lookup wrapper, and bnge_del_l2_filter() now rely on the netdev instance lock, and assert it with netdev_assert_locked_or_invisible().
--- .../net/ethernet/broadcom/bnge/bnge_filter.c | 33 +++++++------------ .../net/ethernet/broadcom/bnge/bnge_filter.h | 2 -- 2 files changed, 11 insertions(+), 24 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +11 -22
@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/dma-mapping.h> #include <linux/jhash.h> +#include <net/netdev_lock.h> #include "bnge.h" #include "bnge_netdev.h"
@@ -13,8 +14,8 @@void bnge_del_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr) { -if (!refcount_dec_and_test (&fltr->refcnt)) -return ; +netdev_assert_locked_or_invisible (bn->netdev); +hlist_del_rcu (&fltr->base.hlist);kfree_rcu (fltr, base.rcu); }
@@ -31,18 +32,19 @@ static void bnge_init_l2_filter(struct bnge_net *bn, head = &bn->l2_fltr_hash_tbl[idx];hlist_add_head_rcu (&fltr->base.hlist, head); -refcount_set (&fltr->refcnt,1 ); } -static struct bnge_l2_filter *__bnge_lookup_l2_filter (struct bnge_net *bn, -struct bnge_l2_key *key, -u32 idx) +static struct bnge_l2_filter *bnge_lookup_l2_filter (struct bnge_net *bn, +struct bnge_l2_key *key, +u32 idx) {struct bnge_l2_filter *fltr;struct hlist_head *head; +netdev_assert_locked_or_invisible (bn->netdev); + head = &bn->l2_fltr_hash_tbl[idx]; -hlist_for_each_entry_rcu (fltr, head, base.hlist) { +hlist_for_each_entry (fltr, head, base.hlist) {struct bnge_l2_key *l2_key = &fltr->l2_key; if (ether_addr_equal(l2_key->dst_mac_addr, key->dst_mac_addr) &&
@@ -52,20 +54,6 @@ static struct bnge_l2_filter *__bnge_lookup_l2_filter(struct bnge_net *bn,return NULL ; } -static struct bnge_l2_filter *bnge_lookup_l2_filter (struct bnge_net *bn, -struct bnge_l2_key *key, -u32 idx) -{ -struct bnge_l2_filter *fltr; - -rcu_read_lock (); - fltr =__bnge_lookup_l2_filter (bn, key, idx); -if (fltr) -refcount_inc (&fltr->refcnt); -rcu_read_unlock (); -return fltr; -} -static struct bnge_l2_filter *bnge_alloc_l2_filter (struct bnge_net *bn,struct bnge_l2_key *key,gfp_t gfp)
@@ -75,9 +63,10 @@ static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn, idx =jhash2 (&key->filter_key,BNGE_L2_KEY_SIZE , bn->hash_seed) &BNGE_L2_FLTR_HASH_MASK ; + fltr =bnge_lookup_l2_filter (bn, key, idx);if (fltr) -return fltr; +return ERR_PTR (-EEXIST ); fltr =kzalloc_obj (*fltr, gfp);if (!fltr)
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +0 -2
@@ -6,7 +6,6 @@#include <linux/types.h> #include <linux/if_ether.h> -#include <linux/refcount.h> #include <linux/jhash.h> struct bnge_net ;
@@ -49,7 +48,6 @@ struct bnge_l2_filter {/* base filter must be the first member */ struct bnge_filter_base base;struct bnge_l2_key l2_key; -refcount_t refcnt; };void bnge_del_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr);
Signature · 1 line
2.52.0
Vikas Gupta
maintainerPATCH v11 7/10 bnge: add NTUPLE filter infrastructure
In reply to Vikas GuptaAdd the core NTUPLE filter data structures and firmware command wrappers needed for flow rule management.
This helps further patches implement user-created NTUPLE rules as well as rules via kernel flow steering.
bd->max_fltr is the fixed BNGE_MAX_NTUPLE_FLTRS (8192). It is no longer the sum of the firmware EM and WM flow counts and the L2 filter count. It sizes ntp_fltr_bmap, limits bnge_insert_ntp_filter() and, with the 128 L2 rules, is the rule count that ethtool reports.
The patch also changes existing behaviour:
- bnge_del_l2_filter() frees the filter at once, without an RCU grace period, and no longer asserts the netdev instance lock. The RCU-deferred free is now bnge_del_l2_filter_rcu(), which bnge_cfg_rx_mode(), bnge_hwrm_clear_vnic_filter() and bnge_hwrm_set_vnic_filter() use. Both also remove the filter from usr_fltr_list and release its sw_id.
- bnge_init_l2_filter() takes a sw_id from the new l2_fltr_bmap (BNGE_MAX_L2_FLTRS entries) for every L2 filter, including the default and unicast ones, and can fail with -ENOMEM.
- bnge_hwrm_l2_filter_alloc() sets BNGE_FLTR_VALID after smp_wmb(), and programs RFS_RING_TBL_IDX for BNGE_ACT_RING_DST filters.
- bnge_del_one_rss_ctx() deletes the NTUPLE filters bound to the context, in firmware and in software, when the context is deleted.
- bnge_close_core() invalidates the state of the user filters, so that they can be programmed again on the next open.
- bnge_alloc_core(), bnge_free_core() and bnge_netdev_free() set up and release the filter memory.
The fields max_rx_em_flows and max_rx_wm_flows of struct bnge_hw_resc were only used by the old max_fltr sum. Nothing writes them and, with this patch, nothing reads them, so remove them.
--- drivers/net/ethernet/broadcom/bnge/bnge.h | 1 - .../net/ethernet/broadcom/bnge/bnge_filter.c | 498 +++++++++++++++++- .../net/ethernet/broadcom/bnge/bnge_filter.h | 69 ++- .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 157 +++++- .../ethernet/broadcom/bnge/bnge_hwrm_lib.h | 6 + .../net/ethernet/broadcom/bnge/bnge_netdev.c | 33 +- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 17 + .../net/ethernet/broadcom/bnge/bnge_resc.c | 6 +- .../net/ethernet/broadcom/bnge/bnge_resc.h | 2 - .../net/ethernet/broadcom/bnge/bnge_vnic.c | 20 + 10 files changed, 791 insertions(+), 18 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge.h +0 -1
@@ -158,7 +158,6 @@ struct bnge_dev {u16 tso_max_segs;int max_fltr; -#define BNGE_L2_FLTR_MAX_FLTR 1024u32 *rss_indir_tbl;u16 rss_indir_tbl_entries;
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +491 -7
551 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +68 -1
98 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +156 -1
173 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.h +6 -0
@@ -13,6 +13,8 @@ struct bnge_l2_filter;#define BNGE_VNIC_CFG_ROCE_DUAL_MODE \ VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE +struct bnge_ntuple_filter ; +int bnge_hwrm_ver_get (struct bnge_dev *bd);int bnge_hwrm_func_reset (struct bnge_dev *bd);int bnge_hwrm_fw_set_time (struct bnge_dev *bd);
@@ -66,4 +68,8 @@ int bnge_hwrm_shutdown_link(struct bnge_dev *bd);int bnge_hwrm_port_qstats (struct bnge_dev *bd,u8 flags);int bnge_hwrm_port_qstats_ext (struct bnge_dev *bd,u8 flags);int bnge_hwrm_func_qstat_ext (struct bnge_dev *bd,struct bnge_stats_mem *stats); +int bnge_hwrm_cfa_ntuple_filter_alloc (struct bnge_dev *bd, +struct bnge_ntuple_filter *fltr); +int bnge_hwrm_cfa_ntuple_filter_free (struct bnge_dev *bd, +struct bnge_ntuple_filter *fltr);#endif /* _BNGE_HWRM_LIB_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +31 -2
@@ -1226,6 +1226,10 @@ static void bnge_free_core(struct bnge_net *bn)bnge_free_ring_stats (bn);bnge_free_ring_grps (bn);bnge_free_vnics (bn); + +/* Free non-user filters only */ +bnge_free_ntp_fltrs (bn, true); +kfree (bn->tx_ring_map); bn->tx_ring_map =NULL ;kfree (bn->tx_ring);
@@ -1315,6 +1319,10 @@ static int bnge_alloc_core(struct bnge_net *bn)bnge_init_stats (bn); + rc =bnge_fltrs_mem (bn); +if (rc) + goto err_free_ring_stats; + rc =bnge_alloc_vnics (bn);if (rc) goto err_free_ring_stats;
@@ -2110,7 +2118,7 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc,struct bnge_l2_filter *fltr = vnic->l2_filters[i];bnge_hwrm_l2_filter_free (bd, fltr); -bnge_del_l2_filter (bn, fltr); +bnge_del_l2_filter_rcu (bn, fltr); } vnic->uc_filter_count =1 ;
@@ -2330,7 +2338,7 @@ static void bnge_hwrm_clear_vnic_filter(struct bnge_net *bn)struct bnge_l2_filter *fltr = vnic->l2_filters[i];bnge_hwrm_l2_filter_free (bn->bd, fltr); -bnge_del_l2_filter (bn, fltr); +bnge_del_l2_filter_rcu (bn, fltr); } vnic->uc_filter_count =0 ;
@@ -3214,6 +3222,7 @@ static void bnge_nq0_napi_to_wq(struct bnge_net *bn)static void bnge_close_core (struct bnge_net *bn) { +struct bnge_filter_base *fltr;struct bnge_dev *bd = bn->bd;bnge_tx_disable (bn);
@@ -3227,6 +3236,20 @@ static void bnge_close_core(struct bnge_net *bn)bnge_nq0_napi_to_wq (bn); +/* Invalidate user L2 filters now that NAPI is disabled so that +* subsequent re-enabling during open cannot read a stale or torn +* filter_id before bnge_cfg_usr_fltrs() completes reallocation. +*/ +/* Only the driver's tracking is reset here. The user filters are +* programmed again by bnge_cfg_usr_fltrs() on the next open. +*/ +list_for_each_entry (fltr, &bn->usr_fltr_list, list_node) { +if (fltr->type ==BNGE_FLTR_TYPE_L2 ) +clear_bit (BNGE_FLTR_VALID , &fltr->state); +else + fltr->filter_id =BNGE_FLTR_ID_INVALID ; + } +/* Save ring stats before shutdown */ spin_lock_bh (&bn->stats_lock);bnge_save_ring_stats (bn);
@@ -3629,6 +3652,9 @@ int bnge_netdev_alloc(struct bnge_dev *bd, int max_irqs) goto err_free_nq0_wq;spin_lock_init (&bn->stats_lock); +spin_lock_init (&bn->ntp_fltr_lock); +INIT_LIST_HEAD (&bn->usr_fltr_list); + netdev->request_ops_lock = true; rc =bnge_nq0_init (bn);
@@ -3672,6 +3698,9 @@ void bnge_netdev_free(struct bnge_dev *bd)bnge_nq0_uninit (bn);destroy_workqueue (bn->nq0_wq); +bnge_free_ntp_fltrs (bn, false); +bnge_free_l2_filters (bn); +timer_shutdown_sync (&bn->timer);cancel_work_sync (&bn->sp_task); bn->sp_event =0 ;
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +17 -0
@@ -285,6 +285,9 @@ enum bnge_sp_event { BNGE_PERIODIC_STATS_SP_EVENT, }; +#define BNGE_NTP_FLTR_HASH_SIZE 512 +#define BNGE_NTP_FLTR_HASH_MASK (BNGE_NTP_FLTR_HASH_SIZE - 1) +struct bnge_net {struct bnge_dev *bd;struct net_device *netdev;
@@ -377,6 +380,20 @@ struct bnge_net {bool pri2cos_valid;u16 num_rss_ctx; + +struct list_head usr_fltr_list; +unsigned long *ntp_fltr_bmap; +unsigned long *l2_fltr_bmap; +int ntp_fltr_count; +int l2_fltr_count; +int user_fltr_count; + +struct hlist_head ntp_fltr_hash_tbl[BNGE_NTP_FLTR_HASH_SIZE ]; +/* Protects the aRFS/ntuple hash table add and delete. usr_fltr_list, +* l2_fltr_hash_tbl and l2_fltr_bmap are covered by the netdev instance +* lock instead. +*/ +spinlock_t ntp_fltr_lock; };#define BNGE_DEFAULT_RX_RING_SIZE 511
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +2 -4
@@ -12,6 +12,7 @@#include "bnge_hwrm_lib.h" #include "bnge_resc.h" #include "bnge_vnic.h" +#include "bnge_filter.h" static u16 bnge_num_tx_to_cp (struct bnge_dev *bd,u16 tx) {
@@ -715,7 +716,6 @@ bool bnge_rss_ctx_capable(struct bnge_dev *bd)int bnge_net_init_dflt_config (struct bnge_dev *bd) { -struct bnge_hw_resc *hw_resc;int rc; rc =bnge_alloc_rss_indir_tbl (bd);
@@ -727,9 +727,7 @@ int bnge_net_init_dflt_config(struct bnge_dev *bd) goto err_free_tbl;bnge_set_dflt_rss_indir_tbl (bd,NULL ); - hw_resc = &bd->hw_resc; - bd->max_fltr = hw_resc->max_rx_em_flows + hw_resc->max_rx_wm_flows + -BNGE_L2_FLTR_MAX_FLTR ; + bd->max_fltr =BNGE_MAX_NTUPLE_FLTRS ;return 0 ;
drivers/net/ethernet/broadcom/bnge/bnge_resc.h +0 -2
@@ -39,8 +39,6 @@ struct bnge_hw_resc {u32 max_decap_records;u32 max_tx_em_flows;u32 max_tx_wm_flows; -u32 max_rx_em_flows; -u32 max_rx_wm_flows; };struct bnge_hw_rings {
drivers/net/ethernet/broadcom/bnge/bnge_vnic.c +20 -0
@@ -178,8 +178,15 @@ void bnge_del_one_rss_ctx(struct bnge_net *bn, struct bnge_rss_ctx *rss_ctx, bool all) {struct bnge_vnic_info *vnic = &rss_ctx->vnic; +struct bnge_filter_base *usr_fltr, *tmp; +struct bnge_ntuple_filter *ntp_fltr;int i; +/* The kernel ethtool core prevents deleting a busy RSS context via +* ethtool_check_rss_ctx_busy(). +* When all == false (interface down), software filters are deliberately +* preserved so they can be restored when the interface is brought up. +*/ bnge_hwrm_vnic_free_one (bn->bd, &rss_ctx->vnic);for (i =0 ; i <BNGE_MAX_CTX_PER_VNIC ; i++) {if (vnic->fw_rss_cos_lb_ctx[i] !=INVALID_HW_RING_ID ) {
@@ -192,6 +199,19 @@ void bnge_del_one_rss_ctx(struct bnge_net *bn, struct bnge_rss_ctx *rss_ctx,if (!all)return ; +/* Delete all filters associated with this user RSS context */ +list_for_each_entry_safe (usr_fltr, tmp, &bn->usr_fltr_list, list_node) { +if (usr_fltr->type ==BNGE_FLTR_TYPE_NTUPLE && + (usr_fltr->flags &BNGE_ACT_RSS_CTX ) && + usr_fltr->fw_vnic_id == rss_ctx->index) { + ntp_fltr =container_of (usr_fltr, + struct bnge_ntuple_filter, + base); +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, ntp_fltr); +bnge_del_ntp_filter_rcu (bn, ntp_fltr); + } + } +if (vnic->rss_table) dma_free_coherent(bn->bd->dev, vnic->rss_table_size, vnic->rss_table,
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 07/10] bnge: add NTUPLE filter infrastructure
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…
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] bnge: duplicate L2 filter allocation in
bnge_alloc_user_l2_filter()
--
Quoted 334 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +323
-1@@ -72,10 +227,339 @@ static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn,if (!fltr)return ERR_PTR (-ENOMEM ); -bnge_init_l2_filter (bn, fltr, key, idx); + rc =bnge_init_l2_filter (bn, fltr, key, idx); +if (rc) { +kfree (fltr); + fltr =ERR_PTR (rc); + } +return fltr; } +struct bnge_l2_filter *bnge_alloc_user_l2_filter (struct bnge_net *bn, +struct bnge_l2_key *key, +u8 flags) +{ +struct bnge_l2_filter *fltr; +u32 idx; +int rc; + + idx =jhash2 (&key->filter_key,BNGE_L2_KEY_SIZE , bn->hash_seed) & +BNGE_L2_FLTR_HASH_MASK ; + fltr =bnge_lookup_l2_filter (bn, key, idx); +if (fltr) { + fltr =ERR_PTR (-EEXIST ); + goto l2_filter_exit; + } + fltr =kzalloc_obj (*fltr,GFP_KERNEL ); +if (!fltr) { + fltr =ERR_PTR (-ENOMEM ); + goto l2_filter_exit; + } + fltr->base.flags = flags; + rc =bnge_init_l2_filter (bn, fltr, key, idx); +if (rc) { +kfree (fltr); +return ERR_PTR (rc); + } + +l2_filter_exit: +return fltr; +} + +void bnge_free_l2_filters (struct bnge_net *bn) +{ +int i; + +netdev_assert_locked_or_invisible (bn->netdev); + +for (i =0 ; i <BNGE_L2_FLTR_HASH_SIZE ; i++) { +struct bnge_l2_filter *fltr; +struct hlist_head *head; +struct hlist_node *tmp; + + head = &bn->l2_fltr_hash_tbl[i]; +hlist_for_each_entry_safe (fltr, tmp, head, base.hlist) +bnge_del_l2_filter (bn, fltr); + } + +bitmap_free (bn->l2_fltr_bmap); + bn->l2_fltr_bmap =NULL ; + bn->l2_fltr_count =0 ; +} + +void bnge_free_ntp_fltrs (struct bnge_net *bn,bool skip_user) +{ +int i; + +netdev_assert_locked_or_invisible (bn->netdev); + +/* Under netdev instance lock and all our NAPIs have been disabled. +* It's safe to delete the hash table. +*/ +for (i =0 ; i <BNGE_NTP_FLTR_HASH_SIZE ; i++) { +struct bnge_ntuple_filter *fltr; +struct hlist_head *head; +struct hlist_node *tmp; + + head = &bn->ntp_fltr_hash_tbl[i]; +hlist_for_each_entry_safe (fltr, tmp, head, base.hlist) { +if (skip_user &&bnge_is_usr_fltr (&fltr->base)) +continue ; +bnge_del_ntp_filter (bn, fltr); + } + } + +if (skip_user) +return ; + +bitmap_free (bn->ntp_fltr_bmap); + bn->ntp_fltr_bmap =NULL ; + bn->ntp_fltr_count =0 ; +} + +static int bnge_alloc_l2_fltrs_mem (struct bnge_net *bn) +{ +int i, rc =0 ; + +if (bn->l2_fltr_bmap) +return 0 ; + +for (i =0 ; i <BNGE_L2_FLTR_HASH_SIZE ; i++) +INIT_HLIST_HEAD (&bn->l2_fltr_hash_tbl[i]); + + bn->l2_fltr_count =0 ; + bn->l2_fltr_bmap =bitmap_zalloc (BNGE_MAX_L2_FLTRS ,GFP_KERNEL ); + +if (!bn->l2_fltr_bmap) + rc = -ENOMEM ; + +return rc; +} + +static int bnge_alloc_ntp_fltrs_mem (struct bnge_net *bn) +{ +struct bnge_dev *bd = bn->bd; +int i, rc =0 ; + +if (!(bn->priv_flags &BNGE_NET_EN_NTUPLE ) || bn->ntp_fltr_bmap) +return 0 ; + +for (i =0 ; i <BNGE_NTP_FLTR_HASH_SIZE ; i++) +INIT_HLIST_HEAD (&bn->ntp_fltr_hash_tbl[i]); + + bn->ntp_fltr_count =0 ; + bn->ntp_fltr_bmap =bitmap_zalloc (bd->max_fltr,GFP_KERNEL ); + +if (!bn->ntp_fltr_bmap) + rc = -ENOMEM ; + +return rc; +} + +int bnge_fltrs_mem (struct bnge_net *bn) +{ +bool ntp_alloced = !bn->ntp_fltr_bmap; +int rc; + + rc =bnge_alloc_ntp_fltrs_mem (bn); +if (rc) +return rc; + + rc =bnge_alloc_l2_fltrs_mem (bn); +if (rc) + goto err_free_ntp_mem; + +return 0 ; + +err_free_ntp_mem: +if (ntp_alloced) { +bitmap_free (bn->ntp_fltr_bmap); + bn->ntp_fltr_bmap =NULL ; + } +return rc; +} + +#define BNGE_IPV4_4TUPLE (bd, fkeys) \ + (((fkeys)->basic.ip_proto == IPPROTO_TCP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) || \ + ((fkeys)->basic.ip_proto == IPPROTO_UDP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4)) + +#define BNGE_IPV6_4TUPLE (bd, fkeys) \ + (((fkeys)->basic.ip_proto == IPPROTO_TCP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) || \ + ((fkeys)->basic.ip_proto == IPPROTO_UDP && \ + (bd)->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6)) + +static u32 bnge_get_rss_flow_tuple_len (struct bnge_dev *bd, +struct flow_keys *fkeys) +{ +if (fkeys->basic.n_proto ==htons (ETH_P_IP )) { +if (BNGE_IPV4_4TUPLE (bd, fkeys)) +return sizeof (fkeys->addrs.v4addrs) + +sizeof (fkeys->ports); + +if (bd->rss_hash_cfg &VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 ) +return sizeof (fkeys->addrs.v4addrs); + } + +if (fkeys->basic.n_proto ==htons (ETH_P_IPV6 )) { +if (BNGE_IPV6_4TUPLE (bd, fkeys)) +return sizeof (fkeys->addrs.v6addrs) + +sizeof (fkeys->ports); + +if (bd->rss_hash_cfg &VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 ) +return sizeof (fkeys->addrs.v6addrs); + } + +return 0 ; +} + +static u32 bnge_toeplitz (struct bnge_net *bn,struct flow_keys *fkeys, +const unsigned char *key) +{ +u64 prefix = bn->toeplitz_prefix, hash =0 ; +struct bnge_ipv4_tuple tuple4; +struct bnge_ipv6_tuple tuple6; +struct bnge_dev *bd = bn->bd; +u8 *four_tuple; +int i, j, len; + + len =bnge_get_rss_flow_tuple_len (bd, fkeys); +if (!len) +return 0 ; + +if (fkeys->basic.n_proto ==htons (ETH_P_IP )) { + tuple4.v4addrs = fkeys->addrs.v4addrs; + tuple4.ports = fkeys->ports; + four_tuple = (u8 *)&tuple4; + }else { + tuple6.v6addrs = fkeys->addrs.v6addrs; + tuple6.ports = fkeys->ports; + four_tuple = (u8 *)&tuple6; + } + +for (i =0 , j =8 ; i < len; i++, j++) { +u8 byte = four_tuple[i]; +int bit; + +for (bit =0 ; bit <8 ; bit++, prefix <<=1 , byte <<=1 ) { +if (byte &0x80 ) + hash ^= prefix; + } + prefix |= (j <HW_HASH_KEY_SIZE ) ? key[j] :0 ; + } + +/* The valid part of the hash is in the upper 32 bits. */ +return (hash >>32 ) &BNGE_NTP_FLTR_HASH_MASK ; +} + +u32 bnge_get_ntp_filter_idx (struct bnge_net *bn,struct flow_keys *fkeys, +const struct sk_buff *skb) +{ +struct bnge_vnic_info *vnic; + +if (skb) +return skb_get_hash_raw (skb) &BNGE_NTP_FLTR_HASH_MASK ; + + vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ]; +return bnge_toeplitz (bn, fkeys, (void *)vnic->rss_hash_key); +} + +static bool bnge_fltr_match (struct bnge_ntuple_filter *f1, +struct bnge_ntuple_filter *f2) +{ +struct bnge_flow_masks *masks1 = &f1->fmasks; +struct bnge_flow_masks *masks2 = &f2->fmasks; +struct flow_keys *keys1 = &f1->fkeys; +struct flow_keys *keys2 = &f2->fkeys; + +if (keys1->basic.n_proto != keys2->basic.n_proto || + keys1->basic.ip_proto != keys2->basic.ip_proto) +return false; + +if (keys1->basic.n_proto ==htons (ETH_P_IP )) { +if (keys1->addrs.v4addrs.src != keys2->addrs.v4addrs.src || + masks1->addrs.v4addrs.src != masks2->addrs.v4addrs.src || + keys1->addrs.v4addrs.dst != keys2->addrs.v4addrs.dst || + masks1->addrs.v4addrs.dst != masks2->addrs.v4addrs.dst) +return false; + }else { +if (!ipv6_addr_equal (&keys1->addrs.v6addrs.src, + &keys2->addrs.v6addrs.src) || + !ipv6_addr_equal (&masks1->addrs.v6addrs.src, + &masks2->addrs.v6addrs.src) || + !ipv6_addr_equal (&keys1->addrs.v6addrs.dst, + &keys2->addrs.v6addrs.dst) || + !ipv6_addr_equal (&masks1->addrs.v6addrs.dst, + &masks2->addrs.v6addrs.dst)) +return false; + } + +return keys1->ports.src == keys2->ports.src && + masks1->ports.src == masks2->ports.src && + keys1->ports.dst == keys2->ports.dst && + masks1->ports.dst == masks2->ports.dst && + keys1->control.flags == keys2->control.flags && + f1->l2_filter_id == f2->l2_filter_id; +} + +int bnge_insert_ntp_filter (struct bnge_net *bn,struct bnge_ntuple_filter *fltr, +u32 idx) +{ +struct bnge_ntuple_filter *f; +struct hlist_head *head; +int bit_id; + +spin_lock_bh (&bn->ntp_fltr_lock); + + head = &bn->ntp_fltr_hash_tbl[idx]; +hlist_for_each_entry (f, head, base.hlist) { +if (bnge_fltr_match (f, fltr)) { +spin_unlock_bh (&bn->ntp_fltr_lock); +return -EEXIST ; + } + } + + bit_id =bitmap_find_free_region (bn->ntp_fltr_bmap, + bn->bd->max_fltr,0 ); +if (bit_id <0 ) { +spin_unlock_bh (&bn->ntp_fltr_lock); +return -ENOMEM ; + } + + fltr->base.sw_id = (u16 )bit_id; + fltr->base.filter_id =BNGE_FLTR_ID_INVALID ; + fltr->base.type =BNGE_FLTR_TYPE_NTUPLE ; + fltr->base.flags |=BNGE_ACT_RING_DST ; + + head = &bn->ntp_fltr_hash_tbl[idx]; +hlist_add_head_rcu (&fltr->base.hlist, head); + +bnge_insert_usr_fltr (bn, &fltr->base); + bn->ntp_fltr_count++; + +spin_unlock_bh (&bn->ntp_fltr_lock); + +return 0 ; +} + +struct bnge_ntuple_filter * +bnge_lookup_ntp_filter_from_idx (struct bnge_net *bn, +struct bnge_ntuple_filter *fltr,u32 idx) +{ +struct bnge_ntuple_filter *f; +struct hlist_head *head; + + head = &bn->ntp_fltr_hash_tbl[idx];
drivers/net/ethernet/broadcom/bnge/bnge_filter.c static struct bnge_l2_filter *bnge_alloc_l2_filter(struct bnge_net *bn, · line 565
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +7
-0+hlist_for_each_entry_rcu (f, head, base.hlist) { +if (bnge_fltr_match (f, fltr)) +return f; + } +return NULL ; +} +int bnge_hwrm_set_vnic_filter (struct bnge_net *bn,u16 vnic_id,u16 idx,const u8 *mac_addr) {
[Severity: Low]bnge_alloc_user_l2_filter() is almost a line-for-line copy of bnge_alloc_l2_filter() just above it. Both do the same jhash2() bucket computation, the same bnge_lookup_l2_filter() check returning -EEXIST, the same kzalloc_obj(), and the same bnge_init_l2_filter() call with kfree() on failure.
The only difference is that the user variant sets fltr->base.flags before the init. bnge_init_l2_filter() already handles user and non-user filters through bnge_insert_usr_fltr(), so it needs nothing else from the caller.
The gfp argument of bnge_alloc_l2_filter() doesn't help either. Its only caller, bnge_hwrm_set_vnic_filter(), always passes GFP_KERNEL.
Could you fold these into a single helper that takes the flags, with 0 for the default and unicast filters? If you want to keep the bnge_alloc_user_l2_filter() name, it can be a thin wrapper around that helper.
That keeps the lookup, the sw_id allocation and the error unwinding in one place, so a later fix to one path can't silently miss the other. It would also get rid of the mix of goto l2_filter_exit and a direct return in the new function.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v11 8/10 bnge: add NTUPLE filter support in ethtool
In reply to Vikas GuptaIntroduce ethtool rx flow classification (rxnfc) operations for NTUPLE filter management.
User filters stay in software while the interface is down. bnge_cfg_usr_fltrs() programs them in firmware again on open, and bnge_clear_usr_fltrs() deletes them when NTUPLE is turned off.
While a user ntuple rule exists, changing the RSS hash key or the hash fields (ethtool -X ... hkey, ethtool -N ... rx-flow-hash) fails with -EBUSY, because the rules are indexed by a hash of the key and the fields and are not rehashed.
bnge_hwrm_l2_filter_alloc() sets CFA_L2_FILTER_ALLOC_REQ_FLAGS_TRAFFIC_L2 only for user ETHER_FLOW ring rules. The default and unicast MAC filters keep the traffic type they had before this patch.
User ETHER_FLOW rules and the unicast address filters share the L2 filter table, so the result depends on the order in which a MAC is added. If the rule is added first, a later unicast address for the same MAC (a macvlan, for example) is left to the rule and is delivered only to the rule's ring, not through the default VNIC. If the unicast address is added first and has an L2 filter, adding a rule for the same MAC fails with -EEXIST. An address without an L2 filter, because it is received in promiscuous mode or the firmware refused its filter, does not block a rule. If that address is programmed later, it is left to the rule, as above.
When such a rule is deleted, bnge_del_usr_l2_filter() programs the unicast filter of the MAC that the rule had been serving. If the firmware refuses it, a warning is logged and the address is left without a filter until its address list changes.
After the old unicast filters are freed, bnge_cfg_rx_mode() counts the free L2 filters, and when the addresses do not fit it receives them in promiscuous mode. Before this patch the limit was BNGE_MAX_UC_ADDRS - 1, so four or more additional unicast addresses used promiscuous mode. Now up to BNGE_MAX_L2_FLTRS - 1 (127) addresses are programmed, fewer when user ETHER_FLOW rules hold L2 filters. BNGE_MAX_L2_FLTRS (128) is a driver limit; the firmware supports many more L2 filters, so a refusal in this path is not expected.
BNGE_MAX_UC_ADDRS (4) is removed. The per-VNIC l2_filters[] array and the uc_list buffer are sized by BNGE_MAX_L2_FLTRS, the driver's L2 filter limit, because the unicast address filters and the user rules share that pool and the free-L2-filter check above is what limits them.
NETIF_F_NTUPLE is enabled by default from this patch on, through bnge_set_dflt_rfs() at netdev allocation time, because this is the first patch where ntuple rules can be added.
--- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 621 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_filter.c | 132 ++++ .../net/ethernet/broadcom/bnge/bnge_filter.h | 4 + .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 9 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 63 +- .../net/ethernet/broadcom/bnge/bnge_vnic.h | 5 +- 6 files changed, 824 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +621 -0
@@ -7,6 +7,7 @@#include <net/devlink.h> #include <linux/ethtool.h> #include <linux/etherdevice.h> +#include <linux/if_vlan.h> #include <linux/ethtool_netlink.h> #include "bnge.h"
@@ -15,6 +16,7 @@#include "bnge_resc.h" #include "bnge_ethtool.h" #include "bnge_hwrm_lib.h" +#include "bnge_filter.h" static int bnge_nway_reset (struct net_device *dev) {
@@ -999,6 +1001,12 @@ static int bnge_set_rxfh_fields(struct net_device *dev,return -EBUSY ; } +if (bnge_has_usr_ntp_fltr (bn)) { +NL_SET_ERR_MSG_MOD (extack, +"Delete user ntuple rules before changing the RSS hash fields" ); +return -EBUSY ; + } + bd->rss_hash_cfg = rss_hash_cfg;return 0 ;
@@ -1060,6 +1068,12 @@ static int bnge_set_rxfh(struct net_device *dev,return -EBUSY ; } +if (rxfh->key &&bnge_has_usr_ntp_fltr (bn)) { +NL_SET_ERR_MSG_MOD (extack, +"Delete user ntuple rules before changing the RSS hash key" ); +return -EBUSY ; + } +bnge_modify_rss (bn,NULL ,NULL , rxfh);return 0 ;
@@ -1242,6 +1256,611 @@ static int bnge_remove_rxfh_context(struct net_device *dev,return 0 ; } +#define BNGE_IP_PROTO_FULL_MASK 0xFF +#define BNGE_IP_PROTO_WILDCARD 0x0 + +static int bnge_get_all_fltr_ids_rcu (struct bnge_net *bn, +struct hlist_head tbl[], +u32 tbl_size,u32 *ids,u32 start, +u32 id_cnt,u32 offset) +{ +u32 i, j = start; + +for (i =0 ; i < tbl_size; i++) { +struct bnge_filter_base *fltr; +struct hlist_head *head; + + head = &tbl[i]; +hlist_for_each_entry_rcu (fltr, head, hlist) { +if (!fltr->flags || +test_bit (BNGE_FLTR_FW_DELETED , &fltr->state)) +continue ; +if (j == id_cnt) +return -EMSGSIZE ; + ids[j++] = fltr->sw_id + offset; + } + } +return j; +} + +static struct bnge_filter_base *bnge_get_one_fltr_rcu (struct bnge_net *bn, +struct hlist_head tbl[], +u32 tbl_size,u32 id, +u32 offset) +{ +u32 i; + +for (i =0 ; i < tbl_size; i++) { +struct bnge_filter_base *fltr; +struct hlist_head *head; + + head = &tbl[i]; +hlist_for_each_entry_rcu (fltr, head, hlist) { +if (fltr->flags && fltr->sw_id + offset == id) +return fltr; + } + } +return NULL ; +} + +static int bnge_grxclsrlall (struct bnge_net *bn,struct ethtool_rxnfc *cmd, +u32 *rule_locs) +{ +int count; + + cmd->data =BNGE_MAX_L2_FLTRS + bn->bd->max_fltr; +rcu_read_lock (); + count =bnge_get_all_fltr_ids_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , rule_locs,0 , + cmd->rule_cnt,0 ); +if (count >=0 ) + count =bnge_get_all_fltr_ids_rcu (bn, bn->ntp_fltr_hash_tbl, +BNGE_NTP_FLTR_HASH_SIZE , + rule_locs, count, + cmd->rule_cnt, +BNGE_MAX_L2_FLTRS ); +rcu_read_unlock (); +if (count <0 ) +return count; + + cmd->rule_cnt = count; +return 0 ; +} + +static int bnge_grxclsrule (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = + (struct ethtool_rx_flow_spec *)&cmd->fs; +struct bnge_filter_base *fltr_base; +struct bnge_ntuple_filter *fltr; +struct bnge_flow_masks *fmasks; +struct bnge_dev *bd = bn->bd; +struct flow_keys *fkeys; +int rc = -EINVAL ; + +if (fs->location >=BNGE_MAX_L2_FLTRS + bd->max_fltr) +return rc; + +rcu_read_lock (); + fltr_base =bnge_get_one_fltr_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , + fs->location,0 ); +if (fltr_base) { +struct ethhdr *h_ether = &fs->h_u.ether_spec; +struct ethhdr *m_ether = &fs->m_u.ether_spec; +struct bnge_l2_filter *l2_fltr; +struct bnge_l2_key *l2_key; + + l2_fltr = container_of(fltr_base, struct bnge_l2_filter, base); + l2_key = &l2_fltr->l2_key; + fs->flow_type =ETHER_FLOW ; +ether_addr_copy (h_ether->h_dest, l2_key->dst_mac_addr); +eth_broadcast_addr (m_ether->h_dest); +if (l2_key->vlan) { +struct ethtool_flow_ext *m_ext = &fs->m_ext; +struct ethtool_flow_ext *h_ext = &fs->h_ext; + + fs->flow_type |=FLOW_EXT ; + m_ext->vlan_tci =htons (0xfff ); + h_ext->vlan_tci =htons (l2_key->vlan); + } +if (fltr_base->flags &BNGE_ACT_RING_DST ) + fs->ring_cookie = fltr_base->rxq; +rcu_read_unlock (); +return 0 ; + } + fltr_base =bnge_get_one_fltr_rcu (bn, bn->ntp_fltr_hash_tbl, +BNGE_NTP_FLTR_HASH_SIZE , + fs->location,BNGE_MAX_L2_FLTRS ); +if (!fltr_base) { +rcu_read_unlock (); +return rc; + } + fltr = container_of(fltr_base, struct bnge_ntuple_filter, base); + + fkeys = &fltr->fkeys; + fmasks = &fltr->fmasks; +if (fkeys->basic.n_proto ==htons (ETH_P_IP )) { +if (fkeys->basic.ip_proto ==BNGE_IP_PROTO_WILDCARD ) { + fs->flow_type =IP_USER_FLOW ; + fs->h_u.usr_ip4_spec.ip_ver =ETH_RX_NFC_IP4 ; + fs->h_u.usr_ip4_spec.proto =BNGE_IP_PROTO_WILDCARD ; + fs->m_u.usr_ip4_spec.proto =0 ; + }else if (fkeys->basic.ip_proto ==IPPROTO_ICMP ) { + fs->flow_type =IP_USER_FLOW ; + fs->h_u.usr_ip4_spec.ip_ver =ETH_RX_NFC_IP4 ; + fs->h_u.usr_ip4_spec.proto =IPPROTO_ICMP ; + fs->m_u.usr_ip4_spec.proto =BNGE_IP_PROTO_FULL_MASK ; + }else if (fkeys->basic.ip_proto ==IPPROTO_TCP ) { + fs->flow_type =TCP_V4_FLOW ; + }else if (fkeys->basic.ip_proto ==IPPROTO_UDP ) { + fs->flow_type =UDP_V4_FLOW ; + }else { + goto fltr_err; + } + + fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; + fs->m_u.tcp_ip4_spec.ip4src = fmasks->addrs.v4addrs.src; + fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; + fs->m_u.tcp_ip4_spec.ip4dst = fmasks->addrs.v4addrs.dst; +if (fs->flow_type ==TCP_V4_FLOW || + fs->flow_type ==UDP_V4_FLOW ) { + fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; + fs->m_u.tcp_ip4_spec.psrc = fmasks->ports.src; + fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; + fs->m_u.tcp_ip4_spec.pdst = fmasks->ports.dst; + } + }else { +if (fkeys->basic.ip_proto ==BNGE_IP_PROTO_WILDCARD ) { + fs->flow_type =IPV6_USER_FLOW ; + fs->h_u.usr_ip6_spec.l4_proto = +BNGE_IP_PROTO_WILDCARD ; + fs->m_u.usr_ip6_spec.l4_proto =0 ; + }else if (fkeys->basic.ip_proto ==IPPROTO_ICMPV6 ) { + fs->flow_type =IPV6_USER_FLOW ; + fs->h_u.usr_ip6_spec.l4_proto =IPPROTO_ICMPV6 ; + fs->m_u.usr_ip6_spec.l4_proto = +BNGE_IP_PROTO_FULL_MASK ; + }else if (fkeys->basic.ip_proto ==IPPROTO_TCP ) { + fs->flow_type =TCP_V6_FLOW ; + }else if (fkeys->basic.ip_proto ==IPPROTO_UDP ) { + fs->flow_type =UDP_V6_FLOW ; + }else { + goto fltr_err; + } + +memcpy (fs->h_u.tcp_ip6_spec.ip6src, + &fkeys->addrs.v6addrs.src, +sizeof (struct in6_addr )); +memcpy (fs->m_u.tcp_ip6_spec.ip6src, + &fmasks->addrs.v6addrs.src, +sizeof (struct in6_addr )); +memcpy (fs->h_u.tcp_ip6_spec.ip6dst, + &fkeys->addrs.v6addrs.dst, +sizeof (struct in6_addr )); +memcpy (fs->m_u.tcp_ip6_spec.ip6dst, + &fmasks->addrs.v6addrs.dst, +sizeof (struct in6_addr )); + +if (fs->flow_type ==TCP_V6_FLOW || + fs->flow_type ==UDP_V6_FLOW ) { + fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; + fs->m_u.tcp_ip6_spec.psrc = fmasks->ports.src; + fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; + fs->m_u.tcp_ip6_spec.pdst = fmasks->ports.dst; + } + } + +if (fltr->base.flags &BNGE_ACT_DROP ) { + fs->ring_cookie =RX_CLS_FLOW_DISC ; + }else if (fltr->base.flags &BNGE_ACT_RSS_CTX ) { + fs->flow_type |=FLOW_RSS ; + fs->ring_cookie = fltr->base.rxq; + cmd->rss_context = fltr->base.fw_vnic_id; + }else { + fs->ring_cookie = fltr->base.rxq; + } + rc =0 ; + +fltr_err: +rcu_read_unlock (); + +return rc; +} + +static bool bnge_verify_ntuple_ip4_flow (struct ethtool_usrip4_spec *ip_spec, +struct ethtool_usrip4_spec *ip_mask) +{ +u8 mproto = ip_mask->proto; +u8 sproto = ip_spec->proto; + +if (ip_mask->l4_4_bytes || ip_mask->tos || + ip_spec->ip_ver !=ETH_RX_NFC_IP4 || + (mproto && (mproto !=BNGE_IP_PROTO_FULL_MASK || + sproto !=IPPROTO_ICMP ))) +return false; +return true; +} + +static bool bnge_verify_ntuple_ip6_flow (struct ethtool_usrip6_spec *ip_spec, +struct ethtool_usrip6_spec *ip_mask) +{ +u8 mproto = ip_mask->l4_proto; +u8 sproto = ip_spec->l4_proto; + +if (ip_mask->l4_4_bytes || ip_mask->tclass || + (mproto && (mproto !=BNGE_IP_PROTO_FULL_MASK || + sproto !=IPPROTO_ICMPV6 ))) +return false; +return true; +} + +static int bnge_add_ntuple_cls_rule (struct bnge_net *bn, +struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_ntuple_filter *new_fltr, *fltr; +u32 flow_type = fs->flow_type &0xff ; +struct bnge_l2_filter *l2_fltr; +struct bnge_flow_masks *fmasks; +struct flow_keys *fkeys; +u32 idx; +int rc; + +if (!bn->vnic_info) +return -EAGAIN ; + +if (fs->flow_type & (FLOW_MAC_EXT |FLOW_EXT )) +return -EOPNOTSUPP ; + +if (fs->ring_cookie !=RX_CLS_FLOW_DISC && +ethtool_get_flow_spec_ring_vf (fs->ring_cookie)) +return -EOPNOTSUPP ; + +if (flow_type ==IP_USER_FLOW ) { +if (!bnge_verify_ntuple_ip4_flow (&fs->h_u.usr_ip4_spec, + &fs->m_u.usr_ip4_spec)) +return -EOPNOTSUPP ; + } + +if (flow_type ==IPV6_USER_FLOW ) { +if (!bnge_verify_ntuple_ip6_flow (&fs->h_u.usr_ip6_spec, + &fs->m_u.usr_ip6_spec)) +return -EOPNOTSUPP ; + } + + new_fltr =kzalloc_obj (*new_fltr,GFP_KERNEL ); +if (!new_fltr) +return -ENOMEM ; + + l2_fltr = bn->vnic_info[BNGE_VNIC_DEFAULT ].l2_filters[0 ]; + new_fltr->l2_filter_id = l2_fltr->base.filter_id; + fmasks = &new_fltr->fmasks; + fkeys = &new_fltr->fkeys; + + rc = -EOPNOTSUPP ; +switch (flow_type) { +case IP_USER_FLOW : { +struct ethtool_usrip4_spec *ip_spec = &fs->h_u.usr_ip4_spec; +struct ethtool_usrip4_spec *ip_mask = &fs->m_u.usr_ip4_spec; + + fkeys->basic.ip_proto = ip_mask->proto ? ip_spec->proto + :BNGE_IP_PROTO_WILDCARD ; + fkeys->basic.n_proto =htons (ETH_P_IP ); + fkeys->addrs.v4addrs.src = ip_spec->ip4src; + fmasks->addrs.v4addrs.src = ip_mask->ip4src; + fkeys->addrs.v4addrs.dst = ip_spec->ip4dst; + fmasks->addrs.v4addrs.dst = ip_mask->ip4dst; +break ; + } +case TCP_V4_FLOW : +case UDP_V4_FLOW : { +struct ethtool_tcpip4_spec *ip_spec = &fs->h_u.tcp_ip4_spec; +struct ethtool_tcpip4_spec *ip_mask = &fs->m_u.tcp_ip4_spec; + +if (ip_mask->tos) + goto err_free_fltr; + + fkeys->basic.ip_proto =IPPROTO_TCP ; +if (flow_type ==UDP_V4_FLOW ) + fkeys->basic.ip_proto =IPPROTO_UDP ; + fkeys->basic.n_proto =htons (ETH_P_IP ); + fkeys->addrs.v4addrs.src = ip_spec->ip4src; + fmasks->addrs.v4addrs.src = ip_mask->ip4src; + fkeys->addrs.v4addrs.dst = ip_spec->ip4dst; + fmasks->addrs.v4addrs.dst = ip_mask->ip4dst; + fkeys->ports.src = ip_spec->psrc; + fmasks->ports.src = ip_mask->psrc; + fkeys->ports.dst = ip_spec->pdst; + fmasks->ports.dst = ip_mask->pdst; +break ; + } +case IPV6_USER_FLOW : { +struct ethtool_usrip6_spec *ip_spec = &fs->h_u.usr_ip6_spec; +struct ethtool_usrip6_spec *ip_mask = &fs->m_u.usr_ip6_spec; + + fkeys->basic.ip_proto = ip_mask->l4_proto ? ip_spec->l4_proto + :BNGE_IP_PROTO_WILDCARD ; + fkeys->basic.n_proto =htons (ETH_P_IPV6 ); + +memcpy (&fkeys->addrs.v6addrs.src, ip_spec->ip6src, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.src, ip_mask->ip6src, +sizeof (struct in6_addr )); +memcpy (&fkeys->addrs.v6addrs.dst, ip_spec->ip6dst, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.dst, ip_mask->ip6dst, +sizeof (struct in6_addr )); +break ; + } +case TCP_V6_FLOW : +case UDP_V6_FLOW : { +struct ethtool_tcpip6_spec *ip_spec = &fs->h_u.tcp_ip6_spec; +struct ethtool_tcpip6_spec *ip_mask = &fs->m_u.tcp_ip6_spec; + +if (ip_mask->tclass) + goto err_free_fltr; + + fkeys->basic.ip_proto =IPPROTO_TCP ; +if (flow_type ==UDP_V6_FLOW ) + fkeys->basic.ip_proto =IPPROTO_UDP ; + fkeys->basic.n_proto =htons (ETH_P_IPV6 ); + +memcpy (&fkeys->addrs.v6addrs.src, ip_spec->ip6src, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.src, ip_mask->ip6src, +sizeof (struct in6_addr )); +memcpy (&fkeys->addrs.v6addrs.dst, ip_spec->ip6dst, +sizeof (struct in6_addr )); +memcpy (&fmasks->addrs.v6addrs.dst, ip_mask->ip6dst, +sizeof (struct in6_addr )); + + fkeys->ports.src = ip_spec->psrc; + fmasks->ports.src = ip_mask->psrc; + fkeys->ports.dst = ip_spec->pdst; + fmasks->ports.dst = ip_mask->pdst; +break ; + } +default : + rc = -EOPNOTSUPP ; + goto err_free_fltr; + } +/* A rule with no address or port mask is accepted only as an ICMP or +* ICMPv6 protocol match; the verify helpers above admit no other +* protocol-only rule. +*/ +if (!memcmp (&BNGE_FLOW_MASK_NONE , fmasks,sizeof (*fmasks)) && + !((flow_type ==IP_USER_FLOW || flow_type ==IPV6_USER_FLOW ) && + fkeys->basic.ip_proto)) + goto err_free_fltr; + + idx =bnge_get_ntp_filter_idx (bn, fkeys,NULL ); +rcu_read_lock (); + fltr =bnge_lookup_ntp_filter_from_idx (bn, new_fltr, idx); +if (fltr) { +rcu_read_unlock (); + rc = -EEXIST ; + goto err_free_fltr; + } +rcu_read_unlock (); + + new_fltr->base.flags =BNGE_ACT_NO_AGING ; +if (fs->flow_type &FLOW_RSS ) { +struct bnge_rss_ctx *rss_ctx; + + new_fltr->base.fw_vnic_id =0 ; + new_fltr->base.flags |=BNGE_ACT_RSS_CTX ; + rss_ctx =bnge_get_rss_ctx_from_index (bn, cmd->rss_context); +if (rss_ctx) { + new_fltr->base.fw_vnic_id = rss_ctx->index; + }else { + rc = -EINVAL ; + goto err_free_fltr; + } + } +if (fs->ring_cookie ==RX_CLS_FLOW_DISC ) + new_fltr->base.flags |=BNGE_ACT_DROP ; +else + new_fltr->base.rxq =ethtool_get_flow_spec_ring (fs->ring_cookie); +__set_bit (BNGE_FLTR_VALID , &new_fltr->base.state); + rc =bnge_insert_ntp_filter (bn, new_fltr, idx); +if (!rc) { + rc =bnge_hwrm_cfa_ntuple_filter_alloc (bn->bd, new_fltr); +if (rc) { +bnge_del_ntp_filter_rcu (bn, new_fltr); +return rc; + } + fs->location =BNGE_MAX_L2_FLTRS + new_fltr->base.sw_id; +return 0 ; + } + +err_free_fltr: +kfree (new_fltr); +return rc; +} + +static int bnge_add_l2_cls_rule (struct bnge_net *bn, +struct ethtool_rx_flow_spec *fs) +{ +u32 ring =ethtool_get_flow_spec_ring (fs->ring_cookie); +struct ethhdr *h_ether = &fs->h_u.ether_spec; +struct ethhdr *m_ether = &fs->m_u.ether_spec; +struct bnge_l2_filter *fltr; +struct bnge_l2_key key; +u16 vnic_id; +u8 flags; +int rc; + +if (ethtool_get_flow_spec_ring_vf (fs->ring_cookie)) +return -EOPNOTSUPP ; + +if (!is_broadcast_ether_addr (m_ether->h_dest)) +return -EINVAL ; + +if (!is_zero_ether_addr (m_ether->h_source) || m_ether->h_proto) +return -EOPNOTSUPP ; + +if (is_broadcast_ether_addr (h_ether->h_dest) || +is_multicast_ether_addr (h_ether->h_dest)) +return -EINVAL ; + +ether_addr_copy (key.dst_mac_addr, h_ether->h_dest); + key.vlan =0 ; +if (fs->flow_type &FLOW_EXT ) { +struct ethtool_flow_ext *m_ext = &fs->m_ext; +struct ethtool_flow_ext *h_ext = &fs->h_ext; + +if (m_ext->vlan_etype || m_ext->data[0 ] || m_ext->data[1 ]) +return -EOPNOTSUPP ; + + key.vlan =ntohs (h_ext->vlan_tci) &VLAN_VID_MASK ; +if (m_ext->vlan_tci !=htons (VLAN_VID_MASK ) || !key.vlan) +return -EINVAL ; + } + + flags =BNGE_ACT_RING_DST ; + vnic_id = bn->vnic_info[BNGE_VNIC_NTUPLE ].fw_vnic_id; + + fltr =bnge_alloc_user_l2_filter (bn, &key, flags); +if (IS_ERR (fltr)) +return PTR_ERR (fltr); + + fltr->base.fw_vnic_id = vnic_id; + fltr->base.rxq = ring; + rc =bnge_hwrm_l2_filter_alloc (bn->bd, fltr); +if (rc) +bnge_del_l2_filter_rcu (bn, fltr); +else + fs->location = fltr->base.sw_id; +return rc; +} + +static int bnge_srxclsrlins (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_dev *bd = bn->bd; +u32 ring, flow_type; +int rc; + +if (!netif_running (bn->netdev)) +return -EAGAIN ; +if (!(bn->priv_flags &BNGE_NET_EN_NTUPLE )) +return -EPERM ; +if (fs->location !=RX_CLS_LOC_ANY ) +return -EINVAL ; + + flow_type = fs->flow_type; + +if (flow_type &FLOW_MAC_EXT ) +return -EINVAL ; + + flow_type &= ~FLOW_EXT ; + +if (fs->ring_cookie ==RX_CLS_FLOW_DISC && flow_type !=ETHER_FLOW ) +return bnge_add_ntuple_cls_rule (bn, cmd); + + ring =ethtool_get_flow_spec_ring (fs->ring_cookie); +if (ring >= bd->rx_nr_rings) +return -EINVAL ; + +if (flow_type ==ETHER_FLOW ) + rc =bnge_add_l2_cls_rule (bn, fs); +else + rc =bnge_add_ntuple_cls_rule (bn, cmd); +return rc; +} + +static int bnge_srxclsrldel (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_filter_base *fltr_base; +struct bnge_ntuple_filter *fltr; +u32 id = fs->location; + +rcu_read_lock (); + fltr_base =bnge_get_one_fltr_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , id,0 ); +if (fltr_base) { +struct bnge_l2_filter *l2_fltr; + + l2_fltr = container_of(fltr_base, struct bnge_l2_filter, base); +rcu_read_unlock (); +/* The firmware filter is gone once the interface is closed. */ +if (test_bit (BNGE_FLTR_VALID , &l2_fltr->base.state)) +bnge_hwrm_l2_filter_free (bn->bd, l2_fltr); +bnge_del_usr_l2_filter (bn, l2_fltr); +return 0 ; + } + fltr_base =bnge_get_one_fltr_rcu (bn, bn->ntp_fltr_hash_tbl, +BNGE_NTP_FLTR_HASH_SIZE , id, +BNGE_MAX_L2_FLTRS ); +if (!fltr_base) { +rcu_read_unlock (); +return -ENOENT ; + } + + fltr = container_of(fltr_base, struct bnge_ntuple_filter, base); +if (!(fltr->base.flags &BNGE_ACT_NO_AGING )) { +rcu_read_unlock (); +return -EINVAL ; + } +rcu_read_unlock (); +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr); +bnge_del_ntp_filter_rcu (bn, fltr); +return 0 ; +} + +static int bnge_get_rxnfc (struct net_device *dev,struct ethtool_rxnfc *cmd, +u32 *rule_locs) +{ +struct bnge_net *bn =netdev_priv (dev); +struct bnge_dev *bd = bn->bd; +int rc =0 ; + +switch (cmd->cmd) { +case ETHTOOL_GRXCLSRLCNT : + cmd->rule_cnt = bn->user_fltr_count; + cmd->data = (BNGE_MAX_L2_FLTRS + bd->max_fltr) | +RX_CLS_LOC_SPECIAL ; +break ; + +case ETHTOOL_GRXCLSRLALL : + rc =bnge_grxclsrlall (bn, cmd, (u32 *)rule_locs); +break ; + +case ETHTOOL_GRXCLSRULE : + rc =bnge_grxclsrule (bn, cmd); +break ; + +default : + rc = -EOPNOTSUPP ; +break ; + } + +return rc; +} + +static int bnge_set_rxnfc (struct net_device *dev,struct ethtool_rxnfc *cmd) +{ +struct bnge_net *bn =netdev_priv (dev); +int rc; + +switch (cmd->cmd) { +case ETHTOOL_SRXCLSRLINS : + rc =bnge_srxclsrlins (bn, cmd); +break ; + +case ETHTOOL_SRXCLSRLDEL : + rc =bnge_srxclsrldel (bn, cmd); +break ; + +default : + rc = -EOPNOTSUPP ; +break ; + } +return rc; +} +static const struct ethtool_ops bnge_ethtool_ops = { .cap_link_lanes_supported =1 , .get_link_ksettings = bnge_get_link_ksettings,
@@ -1274,6 +1893,8 @@ static const struct ethtool_ops bnge_ethtool_ops = { .create_rxfh_context = bnge_create_rxfh_context, .modify_rxfh_context = bnge_modify_rxfh_context, .remove_rxfh_context = bnge_remove_rxfh_context, + .get_rxnfc = bnge_get_rxnfc, + .set_rxnfc = bnge_set_rxnfc, };void bnge_set_ethtool_ops (struct net_device *dev)
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +132 -0
135 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +4 -0
@@ -106,6 +106,7 @@ bnge_lookup_ntp_filter_from_idx(struct bnge_net *bn, struct bnge_ntuple_filter *fltr, u32 idx);void bnge_del_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr);void bnge_del_l2_filter_rcu (struct bnge_net *bn,struct bnge_l2_filter *fltr); +void bnge_del_usr_l2_filter (struct bnge_net *bn,struct bnge_l2_filter *fltr);__le64 bnge_lookup_l2_filter_rcu (struct bnge_net *bn,struct bnge_l2_key *key,u32 idx);
@@ -120,4 +121,7 @@ void bnge_del_ntp_filter(struct bnge_net *bn, struct bnge_ntuple_filter *nfltr);void bnge_del_ntp_filter_rcu (struct bnge_net *bn,struct bnge_ntuple_filter *fltr); +void bnge_cfg_usr_fltrs (struct bnge_net *bn); +void bnge_clear_usr_fltrs (struct bnge_net *bn); +bool bnge_has_usr_ntp_fltr (struct bnge_net *bn);#endif /* _BNGE_FILTER_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +6 -3
@@ -885,15 +885,18 @@ int bnge_hwrm_l2_filter_alloc(struct bnge_dev *bd, struct bnge_l2_filter *fltr) {struct hwrm_cfa_l2_filter_alloc_output *resp;struct hwrm_cfa_l2_filter_alloc_input *req; +u32 flags;int rc; rc =bnge_hwrm_req_init (bd, req,HWRM_CFA_L2_FILTER_ALLOC );if (rc)return rc; - req->flags =cpu_to_le32 (CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX ); - - req->flags |=cpu_to_le32 (CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST ); + flags =CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX | +CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST ; +if (BNGE_L2_FLTR_IS_NTP_MAC (fltr)) + flags |=CFA_L2_FILTER_ALLOC_REQ_FLAGS_TRAFFIC_L2 ; + req->flags =cpu_to_le32 (flags); req->dst_id =cpu_to_le16 (fltr->base.fw_vnic_id); req->enables = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +58 -5
135 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_vnic.h +3 -2
@@ -4,6 +4,8 @@#ifndef _BNGE_VNIC_H_#define _BNGE_VNIC_H_ +#include "bnge_filter.h" +struct bnge_net ;struct bnge_dev ;struct bnge_l2_filter ;
@@ -20,7 +22,6 @@ struct bnge_l2_filter;#define BNGE_MAX_CTX_PER_VNIC 8#define BNGE_MAX_MC_ADDRS 16 -#define BNGE_MAX_UC_ADDRS 4#define BNGE_VNIC_ID_INVALID 0xffffffff
@@ -46,7 +47,7 @@ struct bnge_vnic_info {u16 fw_rss_cos_lb_ctx[BNGE_MAX_CTX_PER_VNIC ];u16 mru;/* index 0 always dev_addr */ -struct bnge_l2_filter *l2_filters[BNGE_MAX_UC_ADDRS ]; +struct bnge_l2_filter *l2_filters[BNGE_MAX_L2_FLTRS ];u16 uc_filter_count;u8 *uc_list;dma_addr_t rss_table_dma_addr;
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 08/10] bnge: add NTUPLE filter support in ethtool
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…
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] A user rule that cannot be restored on open is deleted for good, and the commit message does not say so.
- [Low] After this patch, the comment and the L2 branch of the loop in bnge_close_core() (drivers/net/ethernet/broadcom/bnge/bnge_netdev.c)…
- [Low] bnge_srxclsrldel() (drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c) ignores the return…
--
bnge: add NTUPLE filter support in ethtool
This adds ethtool rxnfc get/set operations to the bnge driver for managing ntuple and ETHER_FLOW filters. User filters are kept in software across close/open, and bnge_cfg_usr_fltrs() programs them again on open. NETIF_F_NTUPLE is enabled by default, and the unicast L2 filter limit is raised to BNGE_MAX_L2_FLTRS.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +0
-0@@ -1242,6 +1256,611 @@ static int bnge_remove_rxfh_context(struct net_device *dev,
[ ... ]
Quoted 21 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +21
-0+static int bnge_srxclsrldel (struct bnge_net *bn,struct ethtool_rxnfc *cmd) +{ +struct ethtool_rx_flow_spec *fs = &cmd->fs; +struct bnge_filter_base *fltr_base; +struct bnge_ntuple_filter *fltr; +u32 id = fs->location; + +rcu_read_lock (); + fltr_base =bnge_get_one_fltr_rcu (bn, bn->l2_fltr_hash_tbl, +BNGE_L2_FLTR_HASH_SIZE , id,0 ); +if (fltr_base) { +struct bnge_l2_filter *l2_fltr; + + l2_fltr = container_of(fltr_base, struct bnge_l2_filter, base); +rcu_read_unlock (); +/* The firmware filter is gone once the interface is closed. */ +if (test_bit (BNGE_FLTR_VALID , &l2_fltr->base.state)) +bnge_hwrm_l2_filter_free (bn->bd, l2_fltr); +bnge_del_usr_l2_filter (bn, l2_fltr); +return 0 ; + }
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c static int bnge_remove_rxfh_context(struct net_device *dev, · line 1811
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +5
-0+rcu_read_unlock (); +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr); +bnge_del_ntp_filter_rcu (bn, fltr); +return 0 ; +}
[Severity: Low]
What happens here if the firmware free fails?
bnge_hwrm_l2_filter_free() returns the HWRM send result. bnge_hwrm_cfa_ntuple_filter_free() resets filter_id only on success. bnge_srxclsrldel() ignores both return values, always deletes the software entry and returns 0.
Suppose HWRM rejects or times out the free, for example with -EAGAIN while the firmware is busy. Wouldn't the CFA filter stay programmed in the NIC while the driver loses its filter_id through kfree_rcu()?
Until the next close, the NIC would still steer or drop matching traffic for a rule that ethtool -n no longer lists and that the user cannot delete. The sw_id is also released, so a new rule can reuse the same location.
In the L2 case, bnge_del_usr_l2_filter() then calls bnge_hwrm_set_vnic_filter(). That programs the same MAC towards the default VNIC while the stale NTUPLE VNIC filter for that MAC may still exist in firmware. The l2_free count in bnge_cfg_rx_mode() is based on l2_fltr_bmap, so it would also undercount what the firmware holds.
Would it make sense to return the error and keep the software entry when the firmware free fails?
Quoted 5 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0@@ -584,3 +584,135 @@ int bnge_hwrm_set_vnic_filter(struct bnge_net *bn, u16 vnic_id, u16 idx,
[ ... ]
Quoted 35 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +35
-0+static bool bnge_usr_fltr_ring_lost (struct bnge_net *bn, +struct bnge_filter_base *fltr) +{ +if (fltr->flags & (BNGE_ACT_DROP |BNGE_ACT_RSS_CTX ) || + fltr->rxq < bn->bd->rx_nr_rings) +return false; + +netdev_warn (bn->netdev,"filter id %d: rx ring %u no longer exists\n" , + fltr->type ==BNGE_FLTR_TYPE_NTUPLE ? +BNGE_MAX_L2_FLTRS + fltr->sw_id : fltr->sw_id, fltr->rxq); +return true; +} + +static void bnge_cfg_one_usr_fltr (struct bnge_net *bn, +struct bnge_filter_base *fltr) +{ +struct bnge_ntuple_filter *ntp_fltr; +struct bnge_l2_filter *l2_fltr; + +if (list_empty (&fltr->list_node)) +return ; + +if (fltr->type ==BNGE_FLTR_TYPE_NTUPLE ) { + ntp_fltr = container_of(fltr, struct bnge_ntuple_filter, base); + l2_fltr = bn->vnic_info[BNGE_VNIC_DEFAULT ].l2_filters[0 ]; + ntp_fltr->l2_filter_id = l2_fltr->base.filter_id; +if (bnge_usr_fltr_ring_lost (bn, fltr) || +bnge_hwrm_cfa_ntuple_filter_alloc (bn->bd, ntp_fltr)) { +netdev_err (bn->netdev, +"restoring previously configured ntuple filter id %d failed\n" , +BNGE_MAX_L2_FLTRS + fltr->sw_id); +bnge_del_ntp_filter_rcu (bn, ntp_fltr); + } + }else if (fltr->type ==BNGE_FLTR_TYPE_L2 ) { + l2_fltr = container_of(fltr, struct bnge_l2_filter, base);
drivers/net/ethernet/broadcom/bnge/bnge_filter.c int bnge_hwrm_set_vnic_filter(struct bnge_net *bn, u16 vnic_id, u16 idx, · line 665
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +10
-0+ fltr->fw_vnic_id = bn->vnic_info[BNGE_VNIC_NTUPLE ].fw_vnic_id; +if (bnge_usr_fltr_ring_lost (bn, fltr) || +bnge_hwrm_l2_filter_alloc (bn->bd, l2_fltr)) { +netdev_err (bn->netdev, +"restoring previously configured l2 filter id %d failed\n" , + fltr->sw_id); +bnge_del_usr_l2_filter (bn, l2_fltr); + } + } +}
[Severity: Low]
This isn't a bug, but the commit message says:
User filters stay in software while the interface is down. bnge_cfg_usr_fltrs() programs them in firmware again on open, ...
bnge_cfg_one_usr_fltr() deletes a rule permanently in two cases:
- bnge_usr_fltr_ring_lost() finds fltr->rxq >= rx_nr_rings for a rule that is neither a drop rule nor an RSS context rule.
- bnge_hwrm_cfa_ntuple_filter_alloc() or bnge_hwrm_l2_filter_alloc() fails.
The rule is then removed with bnge_del_ntp_filter_rcu() or bnge_del_usr_l2_filter(). After a down/up cycle it no longer shows up in ethtool -n, and the only trace is a netdev_warn() or netdev_err() in dmesg.
bnxt_cfg_one_usr_fltr() behaves the same way, so this is only about the commit message. Could it say that the restore is best effort, and that rules which cannot be restored are dropped, including those caught by the new ring-lost check?
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0
[ ... ]
Quoted 20 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +16
-0@@ -2344,8 +2364,29 @@ static void bnge_hwrm_clear_vnic_filter(struct bnge_net *bn) vnic->uc_filter_count =0 ; } +/* User ETHER_FLOW rules are L2 filters whose destination is the NTUPLE VNIC. +* Free them in firmware before that VNIC goes away, as is done for the +* default VNIC filters. The rules stay in usr_fltr_list and are programmed +* again by bnge_cfg_usr_fltrs() on the next open. +*/ +static void bnge_hwrm_clear_usr_l2_fltrs (struct bnge_net *bn) +{ +struct bnge_filter_base *fltr; + +list_for_each_entry (fltr, &bn->usr_fltr_list, list_node) { +if (fltr->type !=BNGE_FLTR_TYPE_L2 || + !test_and_clear_bit (BNGE_FLTR_VALID , &fltr->state)) +continue ; + bnge_hwrm_l2_filter_free(bn->bd, + container_of(fltr, + struct bnge_l2_filter,
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static void bnge_hwrm_clear_vnic_filter(struct bnge_net *bn) · line 2392
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +5
-0+ base)); + } +} +static void bnge_clear_vnic (struct bnge_net *bn) { +bnge_hwrm_clear_usr_l2_fltrs (bn);bnge_hwrm_clear_vnic_filter (bn);bnge_hwrm_vnic_free (bn);bnge_hwrm_vnic_ctx_free (bn);
[Severity: Low]
With this change, does the L2 branch of the loop in bnge_close_core() still do anything, and is its comment still accurate?
bnge_close_core() {
...
bnge_shutdown_nic(bn);
bnge_nq0_napi_to_wq(bn);
/* Invalidate user L2 filters now that NAPI is disabled so that
* subsequent re-enabling during open cannot read a stale or torn
* filter_id before bnge_cfg_usr_fltrs() completes reallocation.
*/
/* Only the driver's tracking is reset here. The user filters are
* programmed again by bnge_cfg_usr_fltrs() on the next open.
*/
list_for_each_entry(fltr, &bn->usr_fltr_list, list_node) {
if (fltr->type == BNGE_FLTR_TYPE_L2)
clear_bit(BNGE_FLTR_VALID, &fltr->state);
...
}The new bnge_hwrm_clear_usr_l2_fltrs() already calls test_and_clear_bit(BNGE_FLTR_VALID) and frees the firmware filter for every user L2 filter. It does this earlier in the same close sequence:
bnge_close_core()->bnge_shutdown_nic()->bnge_hwrm_resource_free()->
bnge_clear_vnic()->bnge_hwrm_clear_usr_l2_fltrs()
That runs before bnge_nq0_napi_to_wq(). So the later clear_bit() for L2 entries is always a no-op, and the comment points to the wrong place for the invalidation.
Could the comment and the L2 branch be updated to match?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v11 9/10 bnge: add aRFS flow steering ndo support
In reply to Vikas GuptaIntroduce the ndo_rx_flow_steer callback (bnge_rx_flow_steer) to support aRFS.
This callback creates an NTUPLE filter that steers matching packets to the appropriate RX queue. The implementation dissects flow keys from the SKB, creates an NTUPLE filter with the associated L2 filter, inserts it into the NTUPLE hash table, and schedules the sp_task workqueue via BNGE_RX_NTP_FLTR_SP_EVENT to program the filter in the firmware.
bnge_rx_flow_steer() is not called yet. set_rps_cpu() calls ndo_rx_flow_steer only when dev->rx_cpu_rmap is set, which is first done in "bnge: add cpu_rmap support for IRQ affinity". That patch turns aRFS on.
Add bnge_cfg_ntp_filters() called from the periodic timer via sp_task to handle deferred filter programming and expiration via rps_may_expire_flow().
bnge_timer() queues aRFS aging only while NTUPLE is enabled. NTUPLE can only be turned off with the interface closed, and bnge_close_core() then deletes the timer and purges dynamic aRFS filters.
An aRFS rule records the L2 filter it is bound to by key (MAC and VLAN), and so does a user ntuple rule. The firmware id of the L2 filter changes whenever the filter is recreated, for example on open or after a unicast address list change, so the id is only used to program the rule: sp_task looks it up again from the key just before it programs an aRFS rule, and drops the rule if the L2 filter is gone.
The patch also changes the existing ethtool n-tuple code:
- bnge_fltr_match() compares l2_key and not l2_filter_id.
- bnge_add_ntuple_cls_rule() and bnge_cfg_one_usr_fltr() set l2_key, the latter does it together with l2_filter_id, under ntp_fltr_lock.
- bnge_get_all_fltr_ids_rcu() and bnge_get_one_fltr_rcu() select user rules with bnge_is_usr_fltr(), which is no longer static, and not with fltr->flags.
- bnge_del_ntp_filter_rcu() uses hlist_del_init_rcu().
--- .../net/ethernet/broadcom/bnge/bnge_ethtool.c | 6 +- .../net/ethernet/broadcom/bnge/bnge_filter.c | 133 ++++++++++++++- .../net/ethernet/broadcom/bnge/bnge_filter.h | 12 +- .../ethernet/broadcom/bnge/bnge_hwrm_lib.c | 2 +- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 152 ++++++++++++++++++ .../net/ethernet/broadcom/bnge/bnge_netdev.h | 1 + 6 files changed, 296 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_ethtool.c +4 -2
@@ -1272,7 +1272,7 @@ static int bnge_get_all_fltr_ids_rcu(struct bnge_net *bn, head = &tbl[i];hlist_for_each_entry_rcu (fltr, head, hlist) { -if (!fltr->flags || +if (!bnge_is_usr_fltr (fltr) ||test_bit (BNGE_FLTR_FW_DELETED , &fltr->state))continue ;if (j == id_cnt)
@@ -1296,7 +1296,8 @@ static struct bnge_filter_base *bnge_get_one_fltr_rcu(struct bnge_net *bn, head = &tbl[i];hlist_for_each_entry_rcu (fltr, head, hlist) { -if (fltr->flags && fltr->sw_id + offset == id) +if (bnge_is_usr_fltr (fltr) && + fltr->sw_id + offset == id)return fltr; } }
@@ -1535,6 +1536,7 @@ static int bnge_add_ntuple_cls_rule(struct bnge_net *bn, l2_fltr = bn->vnic_info[BNGE_VNIC_DEFAULT ].l2_filters[0 ]; new_fltr->l2_filter_id = l2_fltr->base.filter_id; + new_fltr->l2_key = l2_fltr->l2_key; fmasks = &new_fltr->fmasks; fkeys = &new_fltr->fkeys;
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +127 -6
186 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_filter.h +11 -1
@@ -19,7 +19,8 @@ enum {enum {BNGE_FLTR_VALID , -BNGE_FLTR_FW_DELETED +BNGE_FLTR_FW_DELETED , +BNGE_FLTR_RXQ_UPDATE };enum {
@@ -88,6 +89,11 @@ struct bnge_ntuple_filter {struct bnge_filter_base base;struct flow_keys fkeys;struct bnge_flow_masks fmasks; +/* Key of the L2 filter the rule is bound to. It identifies the filter +* across close/open, unlike l2_filter_id, which is reassigned by +* firmware on every open and is only used to program the rule. +*/ +struct bnge_l2_key l2_key;__le64 l2_filter_id;u32 flow_id; };
@@ -97,6 +103,7 @@ struct bnge_ntuple_filter {#define BNGE_FLTR_ID_INVALID cpu_to_le64(0xffffffffffffffffULL)void bnge_free_ntp_fltrs (struct bnge_net *bn,bool skip_user_filters); +bool bnge_is_usr_fltr (struct bnge_filter_base *fltr);u32 bnge_get_ntp_filter_idx (struct bnge_net *bn,struct flow_keys *fkeys,const struct sk_buff *skb); int bnge_insert_ntp_filter(struct bnge_net *bn, struct bnge_ntuple_filter *fltr,
@@ -110,6 +117,8 @@ void bnge_del_usr_l2_filter(struct bnge_net *bn, struct bnge_l2_filter *fltr);__le64 bnge_lookup_l2_filter_rcu (struct bnge_net *bn,struct bnge_l2_key *key,u32 idx); +__le64 bnge_lookup_l2_filter_from_key (struct bnge_net *bn, +struct bnge_l2_key *key);void bnge_free_l2_filters (struct bnge_net *bn);int bnge_hwrm_set_vnic_filter (struct bnge_net *bn,u16 vnic_id,u16 idx,const u8 *mac_addr);
@@ -124,4 +133,5 @@ void bnge_del_ntp_filter_rcu(struct bnge_net *bn,void bnge_cfg_usr_fltrs (struct bnge_net *bn);void bnge_clear_usr_fltrs (struct bnge_net *bn);bool bnge_has_usr_ntp_fltr (struct bnge_net *bn); +void bnge_cfg_ntp_filters (struct bnge_net *bn);#endif /* _BNGE_FILTER_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c +1 -1
@@ -986,8 +986,8 @@ bnge_cfg_rfs_ring_tbl_idx(struct bnge_dev *bd, struct bnge_ntuple_filter *fltr) {struct bnge_net *bn =netdev_priv (bd->netdev); +u32 rxq =READ_ONCE (fltr->base.rxq);struct bnge_vnic_info *def_vnic; -u32 rxq = fltr->base.rxq;u32 enables;if (fltr->base.flags &BNGE_ACT_RSS_CTX ) {
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +152 -0
176 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +1 -0
@@ -283,6 +283,7 @@ enum bnge_sp_event {BNGE_LINK_CFG_CHANGE_SP_EVENT ,BNGE_UPDATE_PHY_SP_EVENT ,BNGE_PERIODIC_STATS_SP_EVENT , + BNGE_RX_NTP_FLTR_SP_EVENT, };#define BNGE_NTP_FLTR_HASH_SIZE 512
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 09/10] bnge: add aRFS flow steering ndo support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In the expire loop of bnge_cfg_ntp_filters() (bnge_filter.c:835-836), the return value of…
--
bnge: add aRFS flow steering ndo support
This patch adds the ndo_rx_flow_steer callback to bnge. The callback builds an ntuple filter from the skb flow keys and queues sp_task to program it in firmware. It also adds bnge_cfg_ntp_filters(), which installs, retargets and expires aRFS filters from sp_task, and changes ntuple filter matching to compare the L2 filter by key rather than by firmware id.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +0
-0
[ ... ]
Quoted 7 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +3
-0@@ -716,3 +735,105 @@ void bnge_clear_usr_fltrs(struct bnge_net *bn) } } } + +void bnge_cfg_ntp_filters (struct bnge_net *bn) +{
[ ... ]
Quoted 12 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +12
-0+/* Free the old HW rule; reinstall it below on the new queue. */ +list_for_each_entry_safe (fltr, tmp, &update_list, base.list_node) { +list_del_init (&fltr->base.list_node); +/* If the free fails the rule stays on the old queue. It is not +* retried, so a firmware that keeps failing is not hit on every +* tick. +*/ +if (bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr)) +continue ; +clear_bit (BNGE_FLTR_FW_DELETED , &fltr->base.state); +list_add (&fltr->base.list_node, &install_list); + }
[ ... ]
Quoted 11 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +11
-0+list_for_each_entry_safe (fltr, tmp, &expire_list, base.list_node) { +list_del_init (&fltr->base.list_node); +/* Decide again under ntp_fltr_lock: the scan ran without it and +* the firmware calls above can take long. Use the rxq and +* flow_id that bnge_rx_flow_steer() writes under it. Unlink +* here too, so a flow cannot be retargeted onto a filter that +* is about to be freed. The firmware free comes after the +* unlock. +*/ +spin_lock_bh (&bn->ntp_fltr_lock); + if (test_bit(BNGE_FLTR_RXQ_UPDATE, &fltr->base.state) ||
drivers/net/ethernet/broadcom/bnge/bnge_filter.c void bnge_clear_usr_fltrs(struct bnge_net *bn) · line 836
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +10
-0+ !rps_may_expire_flow(bn->netdev, fltr->base.rxq, + fltr->flow_id, fltr->base.sw_id)) { +spin_unlock_bh (&bn->ntp_fltr_lock); +continue ; + } +hlist_del_init_rcu (&fltr->base.hlist); +spin_unlock_bh (&bn->ntp_fltr_lock); + +bnge_hwrm_cfa_ntuple_filter_free (bn->bd, fltr); +bnge_del_ntp_filter_rcu (bn, fltr);
^^^^
[Severity: Medium]
What happens to the firmware ntuple rule in the expire loop of bnge_cfg_ntp_filters() if bnge_hwrm_cfa_ntuple_filter_free() fails?
bnge_hwrm_cfa_ntuple_filter_free() in bnge_hwrm_lib.c only invalidates filter_id on success:
rc = bnge_hwrm_req_send(bd, req); if (!rc) fltr->base.filter_id = BNGE_FLTR_ID_INVALID; return rc;
Here the return value is ignored and bnge_del_ntp_filter_rcu() always runs. That clears sw_id in ntp_fltr_bmap, decrements ntp_fltr_count and calls kfree_rcu() on the only object that holds the firmware handle.
If bnge_hwrm_req_init() or bnge_hwrm_req_send() fails, does the rule stay programmed in the CFA table? It would then keep steering the flow to its old RX ring, and the driver would have no record of it.
Close won't free it either. bnge_hwrm_cfa_ntuple_filter_free() returns 0 when BNGE_STATE_OPEN is clear, so the rule looks like it stays in place until VNIC teardown.
A later aRFS request for the same flow would send HWRM_CFA_NTUPLE_FILTER_ALLOC for an identical tuple. Depending on the firmware, that could be rejected as a duplicate, in which case sp_task deletes the new entry and the flow can no longer be steered. It could also install a second rule that conflicts with the first.
The update loop above checks the same return value and keeps the software entry when the free fails. Should the expire loop handle a failure the same way, instead of dropping the only record of the firmware filter?
This path becomes reachable once "bnge: add cpu_rmap support for IRQ affinity" turns aRFS on.
Quoted 3 lines
drivers/net/ethernet/broadcom/bnge/bnge_filter.c +3
-0+ } +#endif +}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerPATCH v11 10/10 bnge: add cpu_rmap support for IRQ affinity
In reply to Vikas GuptaWhen CONFIG_RFS_ACCEL is enabled, allocate and populate a cpu_rmap for the RX IRQ vectors so that the kernel's aRFS infrastructure can correctly map flows to the RX queues serviced by the nearest CPU.
This ensures that NTUPLE rules created by the kernel steer packets to the optimal queue based on CPU/IRQ affinity.
Also, This is the patch that turns aRFS on. Before it dev->rx_cpu_rmap was never set, so set_rps_cpu() took its early exit and bnge_rx_flow_steer() from the previous patch was never called. A failed rmap allocation does not fail the open; aRFS stays off. If adding an IRQ to the rmap fails for one ring, aRFS is turned off for all rings, because a later ring would otherwise take the free slot and map to the wrong RX queue.
NQ0 is requested at probe, before the rmap exists, and is not one of the open NQs that bnge_request_irq() loops over. Add its vector to the rmap first, so that the index of every vector in the rmap is its RX ring index. Otherwise each vector lands one slot too low, and aRFS steers a flow to the wrong RX queue.
--- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 186 +++++++++++++++++- .../net/ethernet/broadcom/bnge/bnge_netdev.h | 8 + .../net/ethernet/broadcom/bnge/bnge_resc.h | 8 + 3 files changed, 199 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +183 -3
@@ -6,6 +6,7 @@#include <linux/dmapool.h> #include <linux/delay.h> #include <linux/errno.h> +#include <linux/irq.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/pci.h>
@@ -18,6 +19,7 @@#include <net/ip.h> #include <linux/skbuff.h> #include <net/page_pool/helpers.h> +#include <linux/cpu_rmap.h> #include "bnge.h" #include "bnge_hwrm.h"
@@ -2539,10 +2541,28 @@ static int bnge_setup_interrupts(struct bnge_net *bn) {struct net_device *dev = bn->netdev;struct bnge_dev *bd = bn->bd; +int rc;bnge_setup_msix (bn); -return netif_set_real_num_queues (dev, bd->tx_nr_rings, bd->rx_nr_rings); + rc =netif_set_real_num_queues (dev, bd->tx_nr_rings, bd->rx_nr_rings); +if (rc) +return rc; + +#ifdef CONFIG_RFS_ACCEL +if (bn->priv_flags &BNGE_NET_EN_NTUPLE ) { +struct cpu_rmap *rmap =alloc_irq_cpu_rmap (bd->rx_nr_rings); + +if (!rmap) +netdev_warn (dev,"Unable to allocate the CPU rmap, aRFS disabled\n" ); +/* Publish under rmap_lock: the NQ0 notifier reads it. */ +mutex_lock (&bn->rmap_lock); + dev->rx_cpu_rmap = rmap; +mutex_unlock (&bn->rmap_lock); + } +#endif + +return rc; }static void bnge_hwrm_resource_free (struct bnge_net *bn,bool close_path)
@@ -2552,14 +2572,140 @@ static void bnge_hwrm_resource_free(struct bnge_net *bn, bool close_path)bnge_hwrm_stat_ctx_free (bn); } +#ifdef CONFIG_RFS_ACCEL +/* The aRFS cpu_rmap is indexed by RX ring number. The affinity notifier updates +* the rmap entry of a ring whenever the affinity of its IRQ changes, and +* bnge_nq0_seed_cpu_rmap() writes the first entry of ring 0 at open. The +* notifier does not touch @cpu_mask, which only holds the affinity hint of the +* IRQ. bn->rmap_lock orders both writers against each other and against +* bnge_free_cpu_rmap() tearing the rmap down, which matters because NQ0's +* notifier is persistent (probe to remove) and can fire while the interface is +* down. +*/ +static void bnge_irq_affinity_notify (struct irq_affinity_notify *notify, +const cpumask_t *mask) +{ + struct bnge_irq *irq = container_of(notify, struct bnge_irq, + affinity_notify); +struct bnge_net *bn = irq->bn; +struct cpu_rmap *rmap; +int rc; + +mutex_lock (&bn->rmap_lock); + rmap = bn->netdev->rx_cpu_rmap; +if (rmap && irq->ring_nr < bn->bd->rx_nr_rings) { + rc =cpu_rmap_update (rmap, irq->ring_nr, mask); +if (rc) +netdev_warn (bn->netdev, +"aRFS rmap update failed: %d\n" , rc); + } +mutex_unlock (&bn->rmap_lock); +} + +static void bnge_irq_affinity_release (struct kref *ref) +{ +/* The bnge_irq and its notifier are owned by irq_tbl, nothing to do. */ +} + +static void bnge_register_irq_notifier (struct bnge_net *bn, +struct bnge_irq *irq) +{ +struct irq_affinity_notify *notify = &irq->affinity_notify; +int rc; + + irq->bn = bn; + notify->irq = irq->vector; + notify->notify = bnge_irq_affinity_notify; + notify->release = bnge_irq_affinity_release; + rc =irq_set_affinity_notifier (irq->vector, notify); +if (rc) +netdev_warn (bn->netdev, +"Set affinity notifier failed, IRQ = %d: %d\n" , + irq->vector, rc); +} + +static void bnge_release_irq_notifier (struct bnge_irq *irq) +{ +/* Cancels any pending notify work, so it cannot touch the rmap after +* this returns. +*/ +irq_set_affinity_notifier (irq->vector,NULL ); +} + +/* set_rps_cpu() reads rx_cpu_rmap under rcu_read_lock(). Hide the pointer so +* that new readers do not see it, wait for the readers that already loaded it, +* and serialise against the affinity notifier via rmap_lock before the rmap is +* freed. set_rps_cpu() loads the pointer twice with plain loads, so a reader +* that is between the two loads is not covered; that has to be fixed in the +* core. +*/ +static void bnge_free_cpu_rmap (struct bnge_net *bn) +{ +struct cpu_rmap *rmap; + +mutex_lock (&bn->rmap_lock); + rmap = bn->netdev->rx_cpu_rmap; +WRITE_ONCE (bn->netdev->rx_cpu_rmap,NULL ); +mutex_unlock (&bn->rmap_lock); + +if (!rmap) +return ; + +synchronize_net (); +free_irq_cpu_rmap (rmap); +} + +static void bnge_nq0_seed_cpu_rmap (struct bnge_net *bn) +{ +const struct cpumask *mask; +unsigned int vector; +u16 map_idx; +int rc; + + map_idx = bn->nq0->nq_ring.ring_struct.map_idx; + vector = bn->bd->irq_tbl[map_idx].vector; + mask =irq_get_affinity_mask (vector); + +mutex_lock (&bn->rmap_lock); +if (bn->netdev->rx_cpu_rmap && mask) { + rc =cpu_rmap_update (bn->netdev->rx_cpu_rmap,0 , mask); +if (rc) +netdev_warn (bn->netdev, +"aRFS rmap seed failed: %d\n" , rc); + } +mutex_unlock (&bn->rmap_lock); +} +#else +static void bnge_register_irq_notifier (struct bnge_net *bn, +struct bnge_irq *irq) +{ +} + +static void bnge_release_irq_notifier (struct bnge_irq *irq) +{ +} + +static void bnge_free_cpu_rmap (struct bnge_net *bn) +{ +} + +static void bnge_nq0_seed_cpu_rmap (struct bnge_net *bn) +{ +} +#endif +static void bnge_nq_free_irq (struct bnge_net *bn,struct bnge_napi *bnapi) {int map_idx = bnapi->nq_ring.ring_struct.map_idx;struct bnge_irq *irq = &bn->bd->irq_tbl[map_idx];if (irq->requested) { +/* Drop the affinity notifier before freeing the IRQ and the +* rmap. +*/ +bnge_release_irq_notifier (irq);if (irq->have_cpumask) { -irq_set_affinity_hint (irq->vector,NULL ); +irq_update_affinity_hint (irq->vector,NULL );free_cpumask_var (irq->cpu_mask); irq->have_cpumask =0 ; }
@@ -2583,6 +2729,16 @@ static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi)return rc; irq->requested =1 ; + irq->ring_nr = bnapi->index; + +/* The affinity notifier keeps the aRFS rmap entry of this ring +* current. It does not use cpu_mask, so install it independent of +* the allocation of the hint mask below. NQ0 is requested at probe, +* when it has no rx_ring yet, and its notifier must exist from then +* on. +*/ +if (bnapi->rx_ring || bnapi == bn->nq0) +bnge_register_irq_notifier (bn, irq);if (zalloc_cpumask_var (&irq->cpu_mask,GFP_KERNEL )) {int numa_node =dev_to_node (&bd->pdev->dev);
@@ -2590,9 +2746,12 @@ static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi) irq->have_cpumask =1 ;cpumask_set_cpu (cpumask_local_spread (bnapi->index, numa_node), irq->cpu_mask); -if (irq_set_affinity_hint (irq->vector, irq->cpu_mask)) +if (irq_set_affinity_and_hint (irq->vector, irq->cpu_mask))bnge_warn (bd,"Set affinity failed, IRQ = %d\n" , irq->vector); + }else { +bnge_warn (bd,"No affinity hint mask, IRQ = %d\n" , + irq->vector); }return 0 ; }
@@ -2602,8 +2761,14 @@ static void bnge_free_irq(struct bnge_net *bn)struct bnge_dev *bd = bn->bd;int i; +/* Release the open NQ notifiers (and their IRQs) before the rmap, so no +* notify work can reference it while it is freed. NQ0's notifier is +* persistent and is serialised against the free via rmap_lock instead. +*/ bnge_for_each_open_nq (i, bd)bnge_nq_free_irq (bn, bn->bnapi[i]); + +bnge_free_cpu_rmap (bn); }static int bnge_request_irq (struct bnge_net *bn)
@@ -2616,6 +2781,14 @@ static int bnge_request_irq(struct bnge_net *bn)netdev_err (bn->netdev,"bnge_setup_interrupts err: %d\n" , rc);return rc; } + +/* NQ0 is persistent (requested at probe) and is not one of the open NQs +* below, so it is not re-requested here and its affinity is left +* untouched. Seed the freshly allocated rmap entry of RX ring 0 from +* the current affinity of NQ0. +*/ +bnge_nq0_seed_cpu_rmap (bn); +bnge_for_each_open_nq (i, bd) { rc =bnge_nq_request_irq (bn, bn->bnapi[i]);if (rc)
@@ -3749,6 +3922,11 @@ int bnge_netdev_alloc(struct bnge_dev *bd, int max_irqs) bn->netdev = netdev; bn->bd = bd; +/* Must be ready before bnge_nq0_init() requests NQ0's IRQ, whose +* affinity notifier takes this lock. +*/ +mutex_init (&bn->rmap_lock); + netdev->min_mtu =ETH_ZLEN ; netdev->max_mtu = bd->max_mtu;
@@ -3885,6 +4063,7 @@ int bnge_netdev_alloc(struct bnge_dev *bd, int max_irqs) err_free_workq:destroy_workqueue (bn->bnge_pf_wq); err_netdev: +mutex_destroy (&bn->rmap_lock);free_netdev (netdev); bd->netdev =NULL ;return rc;
@@ -3913,6 +4092,7 @@ void bnge_netdev_free(struct bnge_dev *bd)bnge_free_port_stats (bn); +mutex_destroy (&bn->rmap_lock);free_netdev (netdev); bd->netdev =NULL ; }
drivers/net/ethernet/broadcom/bnge/bnge_netdev.h +8 -0
@@ -6,6 +6,7 @@#include <linux/bnge/hsi.h> #include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/mutex.h> #include <linux/refcount.h> #include <linux/u64_stats_sync.h> #include <net/netdev_queues.h>
@@ -395,6 +396,13 @@ struct bnge_net {* lock instead. */ spinlock_t ntp_fltr_lock; + +/* Serialises aRFS cpu_rmap updates (IRQ affinity notifier, NQ0 seed) +* against the creation and teardown of the rmap. Needed because NQ0's +* notifier is persistent (probe to remove) and can fire while the +* interface is down and the rmap is being freed. +*/ +struct mutex rmap_lock; };#define BNGE_DEFAULT_RX_RING_SIZE 511
drivers/net/ethernet/broadcom/bnge/bnge_resc.h +8 -0
@@ -4,6 +4,7 @@#ifndef _BNGE_RESC_H_#define _BNGE_RESC_H_ +#include <linux/interrupt.h> #include "bnge_netdev.h" #include "bnge_rmem.h"
@@ -61,6 +62,13 @@ struct bnge_irq { u8 have_cpumask:1;char name[IFNAMSIZ +BNGE_IRQ_NAME_EXTRA ];cpumask_var_t cpu_mask; +/* aRFS IRQ affinity notifier state. @cpu_mask above only holds the +* affinity hint of the IRQ. @bn and @ring_nr are used by the notifier: +* @ring_nr is the RX ring (and rmap) index this vector serves. +*/ +struct bnge_net *bn; +int ring_nr; +struct irq_affinity_notify affinity_notify; };int bnge_reserve_rings (struct bnge_dev *bd);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v11 10/10] bnge: add cpu_rmap support for IRQ affinity
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message describes an irq_cpu_rmap_add() design that the patch does not implement.
- [Low] If one ring's rmap entry cannot be filled in, the driver only warns and keeps aRFS on with that entry left at its default.
- [Low] bnge_nq0_seed_cpu_rmap() (bnge_netdev.c:2658-2677) takes NQ0's mask from irq_get_affinity_mask(vector), which is…
--
bnge: add cpu_rmap support for IRQ affinity
When CONFIG_RFS_ACCEL is enabled and ntuple is on, this patch allocates a cpu_rmap sized to the RX rings and publishes it in dev->rx_cpu_rmap, which turns aRFS on. Per-ring IRQ affinity notifiers update the rmap entries, and entry 0 is seeded from the affinity of the persistent NQ0 vector at open.
Quoted 9 lines
If adding an IRQ to the rmap fails for one ring, aRFS is turned off for all rings, because a later ring would otherwise take the free slot and map to the wrong RX queue.
NQ0 is requested at probe, before the rmap exists, and is not one of the open NQs that
bnge_request_irq()loops over. Add its vector to the rmap first, so that the index of every vector in the rmap is its RX ring index. Otherwise each vector lands one slot too low, and aRFS steers a flow to the wrong RX queue.
[Severity: Medium]
Do these two paragraphs describe what the patch does?
The driver never calls irq_cpu_rmap_add() or cpu_rmap_add(), so no code hands out rmap slots in sequence. Every update passes an explicit index:
bnge_irq_affinity_notify():
rc = cpu_rmap_update(rmap, irq->ring_nr, mask);
bnge_nq0_seed_cpu_rmap():
rc = cpu_rmap_update(bn->netdev->rx_cpu_rmap, 0, mask);
With explicit indices, a later ring cannot take a free slot, and no vector can land one slot too low. The NQ0 step only copies NQ0's current affinity into entry 0.
The failure behaviour also differs from the description. On failure, bnge_register_irq_notifier(), bnge_irq_affinity_notify() and bnge_nq0_seed_cpu_rmap() only call netdev_warn(). dev->rx_cpu_rmap stays published and BNGE_NET_EN_NTUPLE is not cleared, so aRFS stays on rather than being turned off for all rings.
Is this text left over from an earlier version based on irq_cpu_rmap_add()? Could the commit message be updated to describe the explicit-index scheme and the warn-only failure handling?
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +4
-0+static void bnge_nq0_seed_cpu_rmap (struct bnge_net *bn) +{ +const struct cpumask *mask; +unsigned int vector;
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static void bnge_hwrm_resource_free(struct bnge_net *bn, bool close_path) · line 2671
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +10
-0+u16 map_idx; +int rc; + + map_idx = bn->nq0->nq_ring.ring_struct.map_idx; + vector = bn->bd->irq_tbl[map_idx].vector; + mask =irq_get_affinity_mask (vector); + +mutex_lock (&bn->rmap_lock); +if (bn->netdev->rx_cpu_rmap && mask) { + rc =cpu_rmap_update (bn->netdev->rx_cpu_rmap,0 , mask);
[Severity: Low]
Can this seed write a stale mask into entry 0?
irq_get_affinity_mask() returns desc->irq_common_data.affinity. It is read here without desc->lock, and any pending affinity move is ignored. The core notifier that drives bnge_irq_affinity_notify() for NQ0 uses the pending mask instead:
kernel/irq/manage.c:irq_affinity_notify() {
...
if (irq_move_pending(&desc->irq_data))
irq_get_pending(cpumask, desc);
else
cpumask_copy(cpumask, desc->irq_common_data.affinity);
...
}On a chip with IRQCHIP_MOVE_DEFERRED, such as x86 PCI MSI without interrupt remapping, the following sequence looks possible:
- NQ0's smp_affinity is changed. irq_set_affinity_locked() only records the new mask as pending and schedules the notify work.
- bnge_open_core() calls disable_irq(vector0) before bnge_request_irq(), so the pending move cannot complete in this window.
- The NQ0 notify work runs after bnge_setup_interrupts() has published the rmap and writes the new mask into entry 0. Alternatively it ran while the interface was down, when the rmap was NULL, and did nothing.
- bnge_nq0_seed_cpu_rmap() then reads the old live mask and writes it into entry 0.
- When the move later completes, irq_move_masked_irq() does not schedule the notifier again.
Entry 0 would then stay stale until the next NQ0 affinity change. aRFS would steer flows from the old CPUs to RX ring 0 while NQ0 runs on the new CPUs.
Quoted 6 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +6
-0+if (rc) +netdev_warn (bn->netdev, +"aRFS rmap seed failed: %d\n" , rc); + } +mutex_unlock (&bn->rmap_lock); +}
[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi) · line 2755
Quoted 12 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +4
-1@@ -2590,9 +2746,12 @@ static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi) irq->have_cpumask =1 ;cpumask_set_cpu (cpumask_local_spread (bnapi->index, numa_node), irq->cpu_mask); -if (irq_set_affinity_hint (irq->vector, irq->cpu_mask)) +if (irq_set_affinity_and_hint (irq->vector, irq->cpu_mask))bnge_warn (bd,"Set affinity failed, IRQ = %d\n" , irq->vector); + }else { +bnge_warn (bd,"No affinity hint mask, IRQ = %d\n" , + irq->vector); }
[Severity: Low]
What happens to this ring's rmap entry when zalloc_cpumask_var() fails?
In that case irq_set_affinity_and_hint() is never called and the notify work never runs for this ring, so its rmap entry is never written. But bnge_setup_interrupts() has already published dev->rx_cpu_rmap, and alloc_cpu_rmap() only sets placeholder values:
lib/cpu_rmap.c:alloc_cpu_rmap() {
...
for_each_possible_cpu(cpu) {
rmap->near[cpu].index = cpu % size;
rmap->near[cpu].dist = CPU_RMAP_DIST_INF;
}
...
}The same applies when cpu_rmap_update() returns -ENOMEM in bnge_irq_affinity_notify() or bnge_nq0_seed_cpu_rmap(), since both only warn. A failed irq_set_affinity_notifier() in bnge_register_irq_notifier() is handled the same way, although it can only fail for a missing desc or an NMI.
Would set_rps_cpu() then keep steering flows by the cpu % size placeholder while aRFS stays on? Those RX queues' IRQs may not be near the consuming CPU.
This needs CONFIG_CPUMASK_OFFSTACK=y and an allocation failure, and it only affects steering quality. It does differ from the commit message's description that a per-ring failure turns aRFS off.
Quoted 2 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0return 0 ; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
Vikas Gupta
maintainerRe: [PATCH net-next v11 10/10] bnge: add cpu_rmap support for IRQ affinity
Hi,
I see a valid comment in patch-10 and will send out v12.
Thanks,
Vikas
Quoted 183 lines · On Tue, Dec 1, 2026 at 12:09 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message describes an
irq_cpu_rmap_add()design that the patch does not implement.
- [Low] If one ring's rmap entry cannot be filled in, the driver only warns and keeps aRFS on with that entry left at its default.
- [Low]bnge_nq0_seed_cpu_rmap()(bnge_netdev.c:2658-2677) takes NQ0's mask fromirq_get_affinity_mask(vector), which is…--
bnge: add
cpu_rmapsupport for IRQ affinityWhen
CONFIG_RFS_ACCELis enabled and ntuple is on, this patch allocates acpu_rmapsized to the RX rings and publishes it indev->rx_cpu_rmap, which turns aRFS on. Per-ring IRQ affinity notifiers update the rmap entries, and entry 0 is seeded from the affinity of the persistent NQ0 vector at open.Quoted 9 lines
If adding an IRQ to the rmap fails for one ring, aRFS is turned off for all rings, because a later ring would otherwise take the free slot and map to the wrong RX queue.
NQ0 is requested at probe, before the rmap exists, and is not one of the open NQs that
bnge_request_irq()loops over. Add its vector to the rmap first, so that the index of every vector in the rmap is its RX ring index. Otherwise each vector lands one slot too low, and aRFS steers a flow to the wrong RX queue.[Severity: Medium]
Do these two paragraphs describe what the patch does?
The driver never calls
irq_cpu_rmap_add()orcpu_rmap_add(), so no code hands out rmap slots in sequence. Every update passes an explicit index:
bnge_irq_affinity_notify():rc = cpu_rmap_update(rmap, irq->ring_nr, mask);
bnge_nq0_seed_cpu_rmap():rc = cpu_rmap_update(bn->netdev->rx_cpu_rmap, 0, mask);With explicit indices, a later ring cannot take a free slot, and no vector can land one slot too low. The NQ0 step only copies NQ0's current affinity into entry 0.
The failure behaviour also differs from the description. On failure,
bnge_register_irq_notifier(),bnge_irq_affinity_notify()andbnge_nq0_seed_cpu_rmap()only callnetdev_warn().dev->rx_cpu_rmapstays published andBNGE_NET_EN_NTUPLEis not cleared, so aRFS stays on rather than being turned off for all rings.Is this text left over from an earlier version based on
irq_cpu_rmap_add()? Could the commit message be updated to describe the explicit-index scheme and the warn-only failure handling?Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0[ ... ]
Quoted 4 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +4
-0+static void bnge_nq0_seed_cpu_rmap (struct bnge_net *bn) +{ +const struct cpumask *mask; +unsigned int vector;drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static void bnge_hwrm_resource_free(struct bnge_net *bn, bool close_path) · line 2671
Quoted 10 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +10
-0+u16 map_idx; +int rc; + + map_idx = bn->nq0->nq_ring.ring_struct.map_idx; + vector = bn->bd->irq_tbl[map_idx].vector; + mask =irq_get_affinity_mask (vector); + +mutex_lock (&bn->rmap_lock); +if (bn->netdev->rx_cpu_rmap && mask) { + rc =cpu_rmap_update (bn->netdev->rx_cpu_rmap,0 , mask);[Severity: Low]
Can this seed write a stale mask into entry 0?
irq_get_affinity_mask()returnsdesc->irq_common_data.affinity. It is read here withoutdesc->lock, and any pending affinity move is ignored. The core notifier that drivesbnge_irq_affinity_notify()for NQ0 uses the pending mask instead:kernel/irq/manage.c:irq_affinity_notify() { ... if (irq_move_pending(&desc->irq_data)) irq_get_pending(cpumask, desc); else cpumask_copy(cpumask, desc->irq_common_data.affinity); ... }On a chip with
IRQCHIP_MOVE_DEFERRED, such as x86 PCI MSI without interrupt remapping, the following sequence looks possible:- NQ0's
smp_affinityis changed.irq_set_affinity_locked()only records the new mask as pending and schedules the notify work.-
bnge_open_core()callsdisable_irq(vector0)beforebnge_request_irq(), so the pending move cannot complete in this window.- The NQ0 notify work runs after
bnge_setup_interrupts()has published the rmap and writes the new mask into entry 0. Alternatively it ran while the interface was down, when the rmap was NULL, and did nothing.-
bnge_nq0_seed_cpu_rmap()then reads the old live mask and writes it into entry 0.- When the move later completes,
irq_move_masked_irq()does not schedule the notifier again.Entry 0 would then stay stale until the next NQ0 affinity change. aRFS would steer flows from the old CPUs to RX ring 0 while NQ0 runs on the new CPUs.
Quoted 6 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +6
-0+if (rc) +netdev_warn (bn->netdev, +"aRFS rmap seed failed: %d\n" , rc); + } +mutex_unlock (&bn->rmap_lock); +}[ ... ]
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi) · line 2755
Quoted 12 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +4
-1@@ -2590,9 +2746,12 @@ static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi) irq->have_cpumask =1 ;cpumask_set_cpu (cpumask_local_spread (bnapi->index, numa_node), irq->cpu_mask); -if (irq_set_affinity_hint (irq->vector, irq->cpu_mask)) +if (irq_set_affinity_and_hint (irq->vector, irq->cpu_mask))bnge_warn (bd,"Set affinity failed, IRQ = %d\n" , irq->vector); + }else { +bnge_warn (bd,"No affinity hint mask, IRQ = %d\n" , + irq->vector); }[Severity: Low]
What happens to this ring's rmap entry when
zalloc_cpumask_var()fails?In that case
irq_set_affinity_and_hint()is never called and the notify work never runs for this ring, so its rmap entry is never written. Butbnge_setup_interrupts()has already publisheddev->rx_cpu_rmap, andalloc_cpu_rmap()only sets placeholder values:lib/cpu_rmap.c:alloc_cpu_rmap() { ... for_each_possible_cpu(cpu) { rmap->near[cpu].index = cpu % size; rmap->near[cpu].dist = CPU_RMAP_DIST_INF; } ... }The same applies when
cpu_rmap_update()returns-ENOMEMinbnge_irq_affinity_notify()orbnge_nq0_seed_cpu_rmap(), since both only warn. A failedirq_set_affinity_notifier()inbnge_register_irq_notifier()is handled the same way, although it can only fail for a missing desc or an NMI.Would
set_rps_cpu()then keep steering flows by the cpu % size placeholder while aRFS stays on? Those RX queues' IRQs may not be near the consuming CPU.This needs
CONFIG_CPUMASK_OFFSTACK=yand an allocation failure, and it only affects steering quality. It does differ from the commit message's description that a per-ring failure turns aRFS off.
Quoted 7 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi) · line 2757
Quoted 2 lines
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +0
-0return 0 ; }[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130055736.2306367-1-vikas.gupta%40broadcom.com
pw-bot: cr