If the firmware supports MPC channels and CONFIG_BNXT_TLS is set, set the default number of MPC channels. These MPC rings will share MSIX with the TX rings. The number of MPC channels for each type must not exceed the ethtool TX channel count. When changing ethtool channels, bnxt_calc_dflt_mpc_rings() will determine the default MPC rings for the newly requested channel count and we call bnxt_check_rings() to check before we commit. bnxt_set_dflt_mpc_rings() will set the committed MPC rings for the new committed channel count. We also add bnxt_trim_mpc_rings() to make final adjustments in case the number of reserved TX channels is less than expected. Reviewed-by: Ajit Khaparde Reviewed-by: Andy Gospodarek Reviewed-by: Pavan Chebbi Signed-off-by: Michael Chan --- v5: Improve the ethtool -L MPC calculation to use the actual MPC rings during ring check. Add a comment in the code to explain the bnxt_trim_mpc_ring() call. v3: https://lore.kernel.org/netdev/20260614072407.2761092-4-michael.chan@broadcom.com/ Use proper int type for min_t(). v2: https://lore.kernel.org/netdev/20260512212105.3488258-4-michael.chan@broadcom.com/ --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 11 +++ .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 8 ++- drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c | 72 +++++++++++++++++++ drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h | 27 +++++++ 4 files changed, 117 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 519437d61298..56de663f3027 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -13196,6 +13196,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) return rc; bnxt_adj_tx_rings(bp); + bnxt_trim_mpc_rings(bp); rc = bnxt_alloc_mem(bp, irq_re_init); if (rc) { netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc); @@ -16745,6 +16746,7 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp) bp->rx_nr_rings = bp->cp_nr_rings; bp->tx_nr_rings_per_tc = bp->cp_nr_rings; bp->tx_nr_rings = bnxt_tx_nr_rings(bp); + bnxt_trim_mpc_rings(bp); } static void bnxt_adj_dflt_rings(struct bnxt *bp, bool sh) @@ -16796,6 +16798,8 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) bnxt_set_dflt_ulp_stat_ctxs(bp); } + bnxt_set_dflt_mpc_rings(bp); + rc = __bnxt_reserve_rings(bp); if (rc && rc != -ENODEV) netdev_warn(bp->dev, "Unable to reserve tx rings\n"); @@ -16810,6 +16814,11 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) if (rc && rc != -ENODEV) netdev_warn(bp->dev, "2nd rings reservation failed.\n"); bnxt_adj_tx_rings(bp); + /* Re-cap MPC ring counts against the reduced TX rings. + * Any extra reserved MPC rings will be reconciled on + * the next open. + */ + bnxt_trim_mpc_rings(bp); } if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { bp->rx_nr_rings++; @@ -16844,6 +16853,7 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp) goto init_dflt_ring_err; bnxt_adj_tx_rings(bp); + bnxt_trim_mpc_rings(bp); bnxt_set_dflt_rfs(bp); @@ -17187,6 +17197,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) * limited MSIX, so we re-initialize the TX rings per TC. */ bp->tx_nr_rings_per_tc = bp->tx_nr_rings; + bnxt_trim_mpc_rings(bp); if (BNXT_PF(bp)) { if (!bnxt_pf_wq) { diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index 88d879a27820..4bc3cac57b13 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -960,7 +960,7 @@ static int bnxt_set_channels(struct net_device *dev, struct bnxt *bp = netdev_priv(dev); int req_tx_rings, req_rx_rings, tcs; u32 new_tbl_size = 0, old_tbl_size; - int mpc_per_type = 0, mpc_cp = 0; + int mpc_per_type, mpc_cp; bool sh = false; int tx_xdp = 0; int rc = 0; @@ -995,6 +995,10 @@ static int bnxt_set_channels(struct net_device *dev, tx_xdp = req_rx_rings; } + bnxt_calc_dflt_mpc_rings(bp, + req_tx_rings * (tcs > 1 ? tcs : 1) + tx_xdp, + req_tx_rings, req_rx_rings, &mpc_per_type, + &mpc_cp); rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp, mpc_per_type * BNXT_MPC_TYPE_MAX, mpc_cp); if (rc) { @@ -1054,6 +1058,8 @@ static int bnxt_set_channels(struct net_device *dev, bnxt_set_cp_rings(bp, sh); + bnxt_set_dflt_mpc_rings(bp); + /* After changing number of rx channels, update NTUPLE feature. */ netdev_update_features(dev); if (netif_running(dev)) { diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c index 9859a5f86268..26eef764c544 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -45,3 +46,74 @@ int bnxt_mpc_cp_rings_in_use(struct bnxt *bp) return 0; return mpc->mpc_cp_rings; } + +void bnxt_trim_mpc_rings(struct bnxt *bp) +{ + struct bnxt_mpc_info *mpc = bp->mpc_info; + int max = bp->tx_nr_rings_per_tc; + u8 max_cp = 0; + int i; + + if (!mpc) + return; + + for (i = 0; i < BNXT_MPC_TYPE_MAX; i++) { + mpc->mpc_ring_count[i] = min_t(int, mpc->mpc_ring_count[i], + max); + max_cp = max(max_cp, mpc->mpc_ring_count[i]); + } + mpc->mpc_cp_rings = max_cp; +} + +void bnxt_calc_dflt_mpc_rings(struct bnxt *bp, int tx_nr_rings, + int tx_nr_rings_per_tc, int rx_nr_rings, + int *mpc_per_type, int *mpc_cp) +{ + struct bnxt_hw_resc *hw_resc = &bp->hw_resc; + int mpc_tce, avail; + + *mpc_per_type = 0; + *mpc_cp = 0; + + if (!BNXT_MPC_CRYPTO_CAPABLE(bp)) + return; + + avail = hw_resc->max_tx_rings - tx_nr_rings; + /* don't use more than 80% */ + avail = avail * 4 / 5; + + if (avail < (BNXT_MIN_MPC_TCE + BNXT_MIN_MPC_RCE)) + return; + + mpc_tce = min_t(int, avail / 2, tx_nr_rings_per_tc); + mpc_tce = min_t(int, mpc_tce, BNXT_DFLT_MPC_TCE); + + avail = hw_resc->max_cp_rings - tx_nr_rings - rx_nr_rings; + + if (avail < BNXT_MIN_MPC_TCE || avail < BNXT_MIN_MPC_RCE) + return; + + mpc_tce = min(mpc_tce, avail); + + /* TCE and RCE are sized equally, so the per-type count is also the + * MPC CP ring count (max(mpc_tce, mpc_rce)). + */ + *mpc_per_type = mpc_tce; + *mpc_cp = mpc_tce; +} + +void bnxt_set_dflt_mpc_rings(struct bnxt *bp) +{ + struct bnxt_mpc_info *mpc = bp->mpc_info; + int per_type, mpc_cp, i; + + if (!BNXT_MPC_CRYPTO_CAPABLE(bp)) + return; + + bnxt_calc_dflt_mpc_rings(bp, bp->tx_nr_rings, bp->tx_nr_rings_per_tc, + bp->rx_nr_rings, &per_type, &mpc_cp); + + for (i = 0; i < BNXT_MPC_TYPE_MAX; i++) + mpc->mpc_ring_count[i] = per_type; + mpc->mpc_cp_rings = mpc_cp; +} diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h index 7a7d81197ea6..6d50ca8c45ab 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h @@ -17,6 +17,11 @@ enum bnxt_mpc_type { #define BNXT_MAX_MPC 8 +#define BNXT_MIN_MPC_TCE 1 +#define BNXT_MIN_MPC_RCE 1 +#define BNXT_DFLT_MPC_TCE BNXT_MAX_MPC +#define BNXT_DFLT_MPC_RCE BNXT_MAX_MPC + struct bnxt_mpc_info { u8 mpc_chnls_cap; u8 mpc_cp_rings; @@ -37,6 +42,11 @@ void bnxt_alloc_mpc_info(struct bnxt *bp, u8 mpc_chnls_cap); void bnxt_free_mpc_info(struct bnxt *bp); int bnxt_mpc_tx_rings_in_use(struct bnxt *bp); int bnxt_mpc_cp_rings_in_use(struct bnxt *bp); +void bnxt_trim_mpc_rings(struct bnxt *bp); +void bnxt_calc_dflt_mpc_rings(struct bnxt *bp, int tx_nr_rings, + int tx_nr_rings_per_tc, int rx_nr_rings, + int *mpc_per_type, int *mpc_cp); +void bnxt_set_dflt_mpc_rings(struct bnxt *bp); #else static inline void bnxt_alloc_mpc_info(struct bnxt *bp, u8 mpc_chnls_cap) { @@ -55,5 +65,22 @@ static inline int bnxt_mpc_cp_rings_in_use(struct bnxt *bp) { return 0; } + +static inline void bnxt_trim_mpc_rings(struct bnxt *bp) +{ +} + +static inline void bnxt_calc_dflt_mpc_rings(struct bnxt *bp, int tx_nr_rings, + int tx_nr_rings_per_tc, + int rx_nr_rings, int *mpc_per_type, + int *mpc_cp) +{ + *mpc_per_type = 0; + *mpc_cp = 0; +} + +static inline void bnxt_set_dflt_mpc_rings(struct bnxt *bp) +{ +} #endif /* CONFIG_BNXT_TLS */ #endif /* BNXT_MPC_H */ -- 2.51.0