Modify bnxt_cp_rings_in_use(), bnxt_get_max_func_cp_rings_for_en(), and _bnxt_get_max_rings() to account for any TX rings and CP rings used by MPCs. Add a new helper bnxt_total_tx_rings() to include MPC TX rings. Ring reservations will now include the MPC rings. Reviewed-by: Ajit Khaparde Reviewed-by: Kalesh AP Reviewed-by: Andy Gospodarek Reviewed-by: Pavan Chebbi Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 45 ++++++++++++++----- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 1 + drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c | 21 +++++++++ drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h | 12 +++++ .../net/ethernet/broadcom/bnxt/bnxt_sriov.c | 6 +-- 5 files changed, 71 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 06d0c82b4022..e02909511f54 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -7746,6 +7746,11 @@ static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path) } } +int bnxt_total_tx_rings(struct bnxt *bp) +{ + return bp->tx_nr_rings + bnxt_mpc_tx_rings_in_use(bp); +} + static int __bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, bool shared); static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, @@ -7786,19 +7791,28 @@ static int bnxt_hwrm_get_rings(struct bnxt *bp) stats = le16_to_cpu(resp->alloc_stat_ctx); hw_resc->resv_irqs = cp; if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) { + int mpc_tx = bnxt_mpc_tx_rings_in_use(bp); + int mpc_cp = bnxt_mpc_cp_rings_in_use(bp); int rx = hw_resc->resv_rx_rings; int tx = hw_resc->resv_tx_rings; + int cp_p5; + if (tx <= mpc_tx || cp <= mpc_cp) { + rc = -ENOMEM; + goto get_rings_exit; + } + tx -= mpc_tx; + cp_p5 = cp - mpc_cp; if (bp->flags & BNXT_FLAG_AGG_RINGS) rx >>= 1; - if (cp < (rx + tx)) { - rc = __bnxt_trim_rings(bp, &rx, &tx, cp, false); + if (cp_p5 < (rx + tx)) { + rc = __bnxt_trim_rings(bp, &rx, &tx, cp_p5, false); if (rc) goto get_rings_exit; if (bp->flags & BNXT_FLAG_AGG_RINGS) rx <<= 1; hw_resc->resv_rx_rings = rx; - hw_resc->resv_tx_rings = tx; + hw_resc->resv_tx_rings = tx + mpc_tx; } hw_resc->resv_irqs = le16_to_cpu(resp->alloc_msix); hw_resc->resv_hw_ring_grps = rx; @@ -7990,7 +8004,7 @@ static int bnxt_cp_rings_in_use(struct bnxt *bp) return bnxt_nq_rings_in_use(bp); cp = bp->tx_nr_rings + bp->rx_nr_rings; - return cp; + return cp + bnxt_mpc_cp_rings_in_use(bp); } static int bnxt_get_func_stat_ctxs(struct bnxt *bp) @@ -8048,7 +8062,7 @@ static void bnxt_get_total_resources(struct bnxt *bp, struct bnxt_hw_rings *hwr) hwr->cp_p5 = 0; if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) hwr->cp_p5 = bnxt_cp_rings_in_use(bp); - hwr->tx = bp->tx_nr_rings; + hwr->tx = bnxt_total_tx_rings(bp); hwr->rx = bp->rx_nr_rings; hwr->grp = hwr->rx; hwr->vnic = bnxt_get_total_vnics(bp, hwr->rx); @@ -8154,8 +8168,10 @@ static int __bnxt_reserve_rings(struct bnxt *bp) hwr.rx = bp->rx_nr_rings; if (bp->flags & BNXT_FLAG_SHARED_RINGS) sh = true; - if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) - hwr.cp_p5 = hwr.rx + hwr.tx; + if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) { + hwr.cp_p5 = hwr.rx + hwr.tx + bnxt_mpc_cp_rings_in_use(bp); + hwr.tx += bnxt_mpc_tx_rings_in_use(bp); + } hwr.vnic = bnxt_get_total_vnics(bp, hwr.rx); @@ -8192,6 +8208,9 @@ static int __bnxt_reserve_rings(struct bnxt *bp) if (bnxt_ulp_registered(edev) && hwr.stat > bnxt_get_ulp_stat_ctxs(bp)) hwr.stat -= bnxt_get_ulp_stat_ctxs(bp); hwr.cp = min_t(int, hwr.cp, hwr.stat); + hwr.tx -= bnxt_mpc_tx_rings_in_use(bp); + if (hwr.tx < 0) + return -ENOMEM; rc = bnxt_trim_rings(bp, &rx_rings, &hwr.tx, hwr.cp, sh); if (bp->flags & BNXT_FLAG_AGG_RINGS) hwr.rx = rx_rings << 1; @@ -11468,12 +11487,13 @@ unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp) static unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt *bp) { + unsigned int mpc_cp = (unsigned int)bnxt_mpc_cp_rings_in_use(bp); unsigned int cp = bp->hw_resc.max_cp_rings; if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS)) cp -= bnxt_get_ulp_msix_num(bp); - return cp; + return mpc_cp >= cp ? 0 : cp - mpc_cp; } static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp) @@ -14868,8 +14888,10 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, hwr.grp = rx; hwr.rss_ctx = bnxt_get_total_rss_ctxs(bp, &hwr); } - if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) - hwr.cp_p5 = hwr.tx + rx; + if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) { + hwr.cp_p5 = hwr.tx + rx + bnxt_mpc_cp_rings_in_use(bp); + hwr.tx += bnxt_mpc_tx_rings_in_use(bp); + } rc = bnxt_hwrm_check_rings(bp, &hwr); if (!rc && pci_msix_can_alloc_dyn(bp->pdev)) { if (!bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) { @@ -16561,7 +16583,8 @@ static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, struct bnxt_hw_resc *hw_resc = &bp->hw_resc; int max_ring_grps = 0, max_irq; - *max_tx = hw_resc->max_tx_rings; + *max_tx = max(0, (int)hw_resc->max_tx_rings - + bnxt_mpc_tx_rings_in_use(bp)); *max_rx = hw_resc->max_rx_rings; *max_cp = bnxt_get_max_func_cp_rings_for_en(bp); max_irq = min_t(int, bnxt_get_max_func_irqs(bp) - diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h index ab88d96f807c..beea928d8c49 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h @@ -2989,6 +2989,7 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic); int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic, unsigned int start_rx_ring_idx, unsigned int nr_rings); +int bnxt_total_tx_rings(struct bnxt *bp); int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings); int bnxt_nq_rings_in_use(struct bnxt *bp); int bnxt_hwrm_set_coal(struct bnxt *); diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c index 86087e538550..9859a5f86268 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.c @@ -24,3 +24,24 @@ void bnxt_free_mpc_info(struct bnxt *bp) kfree(bp->mpc_info); bp->mpc_info = NULL; } + +int bnxt_mpc_tx_rings_in_use(struct bnxt *bp) +{ + struct bnxt_mpc_info *mpc = bp->mpc_info; + int i, mpc_tx = 0; + + if (!mpc) + return 0; + for (i = 0; i < BNXT_MPC_TYPE_MAX; i++) + mpc_tx += mpc->mpc_ring_count[i]; + return mpc_tx; +} + +int bnxt_mpc_cp_rings_in_use(struct bnxt *bp) +{ + struct bnxt_mpc_info *mpc = bp->mpc_info; + + if (!mpc) + return 0; + return mpc->mpc_cp_rings; +} diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h index cd3f268a3a29..7a7d81197ea6 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_mpc.h @@ -35,6 +35,8 @@ struct bnxt_mpc_info { #ifdef CONFIG_BNXT_TLS 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); #else static inline void bnxt_alloc_mpc_info(struct bnxt *bp, u8 mpc_chnls_cap) { @@ -43,5 +45,15 @@ static inline void bnxt_alloc_mpc_info(struct bnxt *bp, u8 mpc_chnls_cap) static inline void bnxt_free_mpc_info(struct bnxt *bp) { } + +static inline int bnxt_mpc_tx_rings_in_use(struct bnxt *bp) +{ + return 0; +} + +static inline int bnxt_mpc_cp_rings_in_use(struct bnxt *bp) +{ + return 0; +} #endif /* CONFIG_BNXT_TLS */ #endif /* BNXT_MPC_H */ diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c index edcc002e4ca3..d57059722f5b 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c @@ -640,7 +640,7 @@ static int bnxt_hwrm_func_vf_resc_cfg(struct bnxt *bp, int num_vfs, bool reset) vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings * 2; else vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings; - vf_tx_rings = hw_resc->max_tx_rings - bp->tx_nr_rings; + vf_tx_rings = hw_resc->max_tx_rings - bnxt_total_tx_rings(bp); vf_vnics = hw_resc->max_vnics - bp->nr_vnics; vf_rss = hw_resc->max_rsscos_ctxs - bp->rsscos_nr_ctxs; @@ -903,8 +903,8 @@ static int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs) avail_cp < min_rx_rings) rx_ok = 0; - if (hw_resc->max_tx_rings - bp->tx_nr_rings >= min_tx_rings && - avail_cp >= min_tx_rings) + if (hw_resc->max_tx_rings - bnxt_total_tx_rings(bp) >= + min_tx_rings && avail_cp >= min_tx_rings) tx_ok = 1; if (hw_resc->max_rsscos_ctxs - bp->rsscos_nr_ctxs >= -- 2.51.0