Skip to content

Commit

Permalink
net/bnxt: fix max rings computation
Browse files Browse the repository at this point in the history
[ upstream commit c72fe7a ]

The current max_rings computation does not take into account the case
when max_nq_rings is <= num_async_cpr. This results in a wrong value
like 0, when max_nq_rings is 1. Fix this by subtracting num_async_cpr
only when max_cp_rings > num_async_cpr.

Apart from this, the entire logic is currently spread across a few
macros, making it hard to read and debug this code. Move this code
into an inline function.

max_msix is not used in the max_rings calculation.
Apparently the max_msix field returned in HWRM_RESC_QCAPS is only valid
for Thor and newer chips. On Wh+ it will be equal to min_compl_rings.
Also, when a function reset is performed on an application quit, FW
will not reset the VF resource pool as per design.
This can lead to a strange condition wherein the max_msix field
on Wh+ keeps changing on each application re-load thereby throwing
throwing off the max_rings computation.

Fixes: f03e66c ("net/bnxt: limit queue count for NS3/Stingray devices")

Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
  • Loading branch information
sbasavapatna authored and cpaelzer committed Feb 3, 2021
1 parent ce45afa commit aa28e79
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
41 changes: 28 additions & 13 deletions drivers/net/bnxt/bnxt.h
Expand Up @@ -620,19 +620,6 @@ struct bnxt {
uint16_t max_tx_rings;
uint16_t max_rx_rings;
#define MAX_STINGRAY_RINGS 128U
/* For sake of symmetry, max Tx rings == max Rx rings, one stat ctx for each */
#define BNXT_MAX_RX_RINGS(bp) \
(BNXT_STINGRAY(bp) ? RTE_MIN(RTE_MIN(bp->max_rx_rings / 2U, \
MAX_STINGRAY_RINGS), \
bp->max_stat_ctx / 2U) : \
RTE_MIN(bp->max_rx_rings / 2U, \
bp->max_stat_ctx / 2U))
#define BNXT_MAX_TX_RINGS(bp) \
(RTE_MIN((bp)->max_tx_rings, BNXT_MAX_RX_RINGS(bp)))

#define BNXT_MAX_RINGS(bp) \
(RTE_MIN((((bp)->max_cp_rings - BNXT_NUM_ASYNC_CPR(bp)) / 2U), \
BNXT_MAX_TX_RINGS(bp)))
uint16_t max_nq_rings;
uint16_t max_l2_ctx;
uint16_t max_rx_em_flows;
Expand Down Expand Up @@ -668,6 +655,34 @@ struct bnxt {
struct bnxt_error_recovery_info *recovery_info;
};

static
inline uint16_t bnxt_max_rings(struct bnxt *bp)
{
uint16_t max_tx_rings = bp->max_tx_rings;
uint16_t max_rx_rings = bp->max_rx_rings;
uint16_t max_cp_rings = bp->max_cp_rings;
uint16_t max_rings;

/* For the sake of symmetry:
* max Tx rings == max Rx rings, one stat ctx for each.
*/
if (BNXT_STINGRAY(bp)) {
max_rx_rings = RTE_MIN(RTE_MIN(max_rx_rings / 2U,
MAX_STINGRAY_RINGS),
bp->max_stat_ctx / 2U);
} else {
max_rx_rings = RTE_MIN(max_rx_rings / 2U,
bp->max_stat_ctx / 2U);
}

max_tx_rings = RTE_MIN(max_tx_rings, max_rx_rings);
if (max_cp_rings > BNXT_NUM_ASYNC_CPR(bp))
max_cp_rings -= BNXT_NUM_ASYNC_CPR(bp);
max_rings = RTE_MIN(max_cp_rings / 2U, max_tx_rings);

return max_rings;
}

int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu);
int bnxt_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete,
bool exp_link_status);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/bnxt/bnxt_ethdev.c
Expand Up @@ -526,7 +526,7 @@ static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
if (BNXT_PF(bp))
dev_info->max_vfs = pdev->max_vfs;

max_rx_rings = BNXT_MAX_RINGS(bp);
max_rx_rings = bnxt_max_rings(bp);
/* For the sake of symmetry, max_rx_queues = max_tx_queues */
dev_info->max_rx_queues = max_rx_rings;
dev_info->max_tx_queues = max_rx_rings;
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/bnxt/bnxt_rxq.c
Expand Up @@ -304,7 +304,7 @@ int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
if (rc)
return rc;

if (queue_idx >= BNXT_MAX_RINGS(bp)) {
if (queue_idx >= bnxt_max_rings(bp)) {
PMD_DRV_LOG(ERR,
"Cannot create Rx ring %d. Only %d rings available\n",
queue_idx, bp->max_rx_rings);
Expand Down Expand Up @@ -356,8 +356,9 @@ int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,

eth_dev->data->rx_queues[queue_idx] = rxq;
/* Allocate RX ring hardware descriptors */
if (bnxt_alloc_rings(bp, queue_idx, NULL, rxq, rxq->cp_ring, NULL,
"rxr")) {
rc = bnxt_alloc_rings(bp, queue_idx, NULL, rxq, rxq->cp_ring, NULL,
"rxr");
if (rc) {
PMD_DRV_LOG(ERR,
"ring_dma_zone_reserve for rx_ring failed!\n");
goto err;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/bnxt/bnxt_txq.c
Expand Up @@ -98,7 +98,7 @@ int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
if (rc)
return rc;

if (queue_idx >= BNXT_MAX_RINGS(bp)) {
if (queue_idx >= bnxt_max_rings(bp)) {
PMD_DRV_LOG(ERR,
"Cannot create Tx ring %d. Only %d rings available\n",
queue_idx, bp->max_tx_rings);
Expand Down

0 comments on commit aa28e79

Please sign in to comment.