LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_ring.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 478 0.0 %
Date: 2026-04-01 20:02:27 Functions: 0 18 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 231 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2014-2023 Broadcom
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <rte_bitmap.h>
       7                 :            : #include <rte_memzone.h>
       8                 :            : #include <rte_malloc.h>
       9                 :            : #include <unistd.h>
      10                 :            : 
      11                 :            : #include "bnxt.h"
      12                 :            : #include "bnxt_hwrm.h"
      13                 :            : #include "bnxt_ring.h"
      14                 :            : #include "bnxt_rxq.h"
      15                 :            : #include "bnxt_rxr.h"
      16                 :            : #include "bnxt_txq.h"
      17                 :            : #include "bnxt_txr.h"
      18                 :            : 
      19                 :            : #include "hsi_struct_def_dpdk.h"
      20                 :            : 
      21                 :            : /*
      22                 :            :  * Generic ring handling
      23                 :            :  */
      24                 :            : 
      25                 :          0 : void bnxt_free_ring(struct bnxt_ring *ring)
      26                 :            : {
      27         [ #  # ]:          0 :         if (!ring)
      28                 :            :                 return;
      29                 :            : 
      30   [ #  #  #  # ]:          0 :         if (ring->vmem_size && *ring->vmem) {
      31                 :          0 :                 memset((char *)*ring->vmem, 0, ring->vmem_size);
      32                 :          0 :                 *ring->vmem = NULL;
      33                 :            :         }
      34                 :          0 :         ring->mem_zone = NULL;
      35                 :            : }
      36                 :            : 
      37                 :            : /*
      38                 :            :  * Ring groups
      39                 :            :  */
      40                 :            : 
      41                 :          0 : static void bnxt_init_ring_grps(struct bnxt *bp)
      42                 :            : {
      43                 :            :         unsigned int i;
      44                 :            : 
      45         [ #  # ]:          0 :         for (i = 0; i < bp->max_ring_grps; i++)
      46                 :          0 :                 memset(&bp->grp_info[i], (uint8_t)HWRM_NA_SIGNATURE,
      47                 :            :                        sizeof(struct bnxt_ring_grp_info));
      48                 :          0 : }
      49                 :            : 
      50                 :          0 : int bnxt_alloc_ring_grps(struct bnxt *bp)
      51                 :            : {
      52         [ #  # ]:          0 :         if (bp->max_tx_rings == 0) {
      53                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "No TX rings available!");
      54                 :          0 :                 return -EBUSY;
      55                 :            :         }
      56                 :            : 
      57                 :            :         /* P5 does not support ring groups.
      58                 :            :          * But we will use the array to save RSS context IDs.
      59                 :            :          */
      60                 :            :         /* TODO Revisit for Thor 2 */
      61         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp)) {
      62                 :          0 :                 bp->max_ring_grps = BNXT_MAX_RSS_CTXTS_P5;
      63         [ #  # ]:          0 :         } else if (bp->max_ring_grps < bp->rx_cp_nr_rings) {
      64                 :            :                 /* 1 ring is for default completion ring */
      65                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Insufficient resource: Ring Group");
      66                 :          0 :                 return -ENOSPC;
      67                 :            :         }
      68                 :            : 
      69         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp)) {
      70                 :          0 :                 bp->grp_info = rte_zmalloc("bnxt_grp_info",
      71                 :            :                                            sizeof(*bp->grp_info) *
      72                 :          0 :                                            bp->max_ring_grps, 0);
      73         [ #  # ]:          0 :                 if (!bp->grp_info) {
      74                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
      75                 :            :                                     "Failed to alloc grp info tbl.");
      76                 :          0 :                         return -ENOMEM;
      77                 :            :                 }
      78                 :          0 :                 bnxt_init_ring_grps(bp);
      79                 :            :         }
      80                 :            : 
      81                 :            :         return 0;
      82                 :            : }
      83                 :            : 
      84                 :            : /*
      85                 :            :  * Allocates a completion ring with vmem and stats optionally also allocating
      86                 :            :  * a TX and/or RX ring.  Passing NULL as tx_ring_info and/or rx_ring_info
      87                 :            :  * to not allocate them.
      88                 :            :  *
      89                 :            :  * Order in the allocation is:
      90                 :            :  * stats - Always non-zero length
      91                 :            :  * cp vmem - Always zero-length, supported for the bnxt_ring abstraction
      92                 :            :  * tx vmem - Only non-zero length if tx_ring_info is not NULL
      93                 :            :  * rx vmem - Only non-zero length if rx_ring_info is not NULL
      94                 :            :  * cp bd ring - Always non-zero length
      95                 :            :  * tx bd ring - Only non-zero length if tx_ring_info is not NULL
      96                 :            :  * rx bd ring - Only non-zero length if rx_ring_info is not NULL
      97                 :            :  */
      98                 :          0 : int bnxt_alloc_rings(struct bnxt *bp, unsigned int socket_id, uint16_t qidx,
      99                 :            :                             struct bnxt_tx_queue *txq,
     100                 :            :                             struct bnxt_rx_queue *rxq,
     101                 :            :                             struct bnxt_cp_ring_info *cp_ring_info,
     102                 :            :                             struct bnxt_cp_ring_info *nq_ring_info,
     103                 :            :                             const char *suffix)
     104                 :            : {
     105                 :          0 :         struct bnxt_ring *cp_ring = cp_ring_info->cp_ring_struct;
     106         [ #  # ]:          0 :         struct bnxt_rx_ring_info *rx_ring_info = rxq ? rxq->rx_ring : NULL;
     107         [ #  # ]:          0 :         struct bnxt_tx_ring_info *tx_ring_info = txq ? txq->tx_ring : NULL;
     108                 :          0 :         uint64_t rx_offloads = bp->eth_dev->data->dev_conf.rxmode.offloads;
     109                 :            :         int ag_ring_start, ag_bitmap_start, tpa_info_start;
     110                 :            :         int ag_vmem_start, cp_ring_start, nq_ring_start;
     111                 :            :         int total_alloc_len, rx_ring_start, rx_ring_len;
     112                 :          0 :         struct rte_pci_device *pdev = bp->pdev;
     113                 :            :         struct bnxt_ring *tx_ring, *rx_ring;
     114                 :            :         const struct rte_memzone *mz = NULL;
     115                 :            :         char mz_name[RTE_MEMZONE_NAMESIZE];
     116                 :            :         rte_iova_t mz_phys_addr;
     117                 :            :         int ag_bitmap_len =  0;
     118                 :            :         int tpa_info_len = 0;
     119                 :            :         int ag_vmem_len = 0;
     120                 :            :         int ag_ring_len = 0;
     121                 :            : 
     122         [ #  # ]:          0 :         int stats_len = (tx_ring_info || rx_ring_info) ?
     123                 :            :             RTE_CACHE_LINE_ROUNDUP(BNXT_HWRM_CTX_GET_SIZE(bp)) : 0;
     124                 :          0 :         stats_len = RTE_ALIGN(stats_len, 128);
     125                 :            : 
     126                 :            :         int cp_vmem_start = stats_len;
     127                 :          0 :         int cp_vmem_len = RTE_CACHE_LINE_ROUNDUP(cp_ring->vmem_size);
     128                 :          0 :         cp_vmem_len = RTE_ALIGN(cp_vmem_len, 128);
     129                 :            : 
     130                 :            :         int nq_vmem_len = nq_ring_info ?
     131         [ #  # ]:          0 :                 RTE_CACHE_LINE_ROUNDUP(cp_ring->vmem_size) : 0;
     132                 :          0 :         nq_vmem_len = RTE_ALIGN(nq_vmem_len, 128);
     133                 :            : 
     134                 :          0 :         int nq_vmem_start = cp_vmem_start + cp_vmem_len;
     135                 :            : 
     136                 :          0 :         int tx_vmem_start = nq_vmem_start + nq_vmem_len;
     137                 :            :         int tx_vmem_len =
     138                 :          0 :             tx_ring_info ? RTE_CACHE_LINE_ROUNDUP(tx_ring_info->
     139         [ #  # ]:          0 :                                                 tx_ring_struct->vmem_size) : 0;
     140                 :          0 :         tx_vmem_len = RTE_ALIGN(tx_vmem_len, 128);
     141                 :            : 
     142                 :          0 :         int rx_vmem_start = tx_vmem_start + tx_vmem_len;
     143                 :            :         int rx_vmem_len = rx_ring_info ?
     144                 :          0 :                 RTE_CACHE_LINE_ROUNDUP(rx_ring_info->
     145         [ #  # ]:          0 :                                                 rx_ring_struct->vmem_size) : 0;
     146                 :          0 :         rx_vmem_len = RTE_ALIGN(rx_vmem_len, 128);
     147                 :            : 
     148                 :          0 :         ag_vmem_start = rx_vmem_start + rx_vmem_len;
     149         [ #  # ]:          0 :         if (bnxt_need_agg_ring(bp->eth_dev))
     150         [ #  # ]:          0 :                 ag_vmem_len = rx_ring_info && rx_ring_info->ag_ring_struct ?
     151         [ #  # ]:          0 :                         RTE_CACHE_LINE_ROUNDUP(rx_ring_info->ag_ring_struct->vmem_size) : 0;
     152                 :            : 
     153                 :          0 :         cp_ring_start = ag_vmem_start + ag_vmem_len;
     154                 :          0 :         cp_ring_start = RTE_ALIGN(cp_ring_start, 4096);
     155                 :            : 
     156                 :          0 :         int cp_ring_len = RTE_CACHE_LINE_ROUNDUP(cp_ring->ring_size *
     157                 :            :                                                  sizeof(struct cmpl_base));
     158                 :          0 :         cp_ring_len = RTE_ALIGN(cp_ring_len, 128);
     159                 :          0 :         nq_ring_start = cp_ring_start + cp_ring_len;
     160                 :          0 :         nq_ring_start = RTE_ALIGN(nq_ring_start, 4096);
     161                 :            : 
     162         [ #  # ]:          0 :         int nq_ring_len = nq_ring_info ? cp_ring_len : 0;
     163                 :            : 
     164                 :          0 :         int tx_ring_start = nq_ring_start + nq_ring_len;
     165                 :          0 :         tx_ring_start = RTE_ALIGN(tx_ring_start, 4096);
     166         [ #  # ]:          0 :         int tx_ring_len = tx_ring_info ?
     167                 :          0 :             RTE_CACHE_LINE_ROUNDUP(tx_ring_info->tx_ring_struct->ring_size *
     168                 :            :                                    sizeof(struct tx_bd_long)) : 0;
     169                 :          0 :         tx_ring_len = RTE_ALIGN(tx_ring_len, 4096);
     170                 :            : 
     171                 :          0 :         rx_ring_start = tx_ring_start + tx_ring_len;
     172                 :          0 :         rx_ring_start = RTE_ALIGN(rx_ring_start, 4096);
     173         [ #  # ]:          0 :         rx_ring_len =  rx_ring_info ?
     174                 :          0 :                 RTE_CACHE_LINE_ROUNDUP(rx_ring_info->rx_ring_struct->ring_size *
     175                 :            :                 sizeof(struct rx_prod_pkt_bd)) : 0;
     176                 :          0 :         rx_ring_len = RTE_ALIGN(rx_ring_len, 4096);
     177                 :            : 
     178                 :          0 :         ag_ring_start = rx_ring_start + rx_ring_len;
     179                 :          0 :         ag_ring_start = RTE_ALIGN(ag_ring_start, 4096);
     180                 :            : 
     181         [ #  # ]:          0 :         if (bnxt_need_agg_ring(bp->eth_dev)) {
     182                 :          0 :                 ag_ring_len = rx_ring_len * AGG_RING_SIZE_FACTOR;
     183                 :          0 :                 ag_ring_len = RTE_ALIGN(ag_ring_len, 4096);
     184                 :            : 
     185                 :            :                 ag_bitmap_len =  rx_ring_info ?
     186                 :          0 :                 RTE_CACHE_LINE_ROUNDUP(rte_bitmap_get_memory_footprint(
     187                 :            :                         rx_ring_info->rx_ring_struct->ring_size *
     188         [ #  # ]:          0 :                         AGG_RING_SIZE_FACTOR)) : 0;
     189                 :            : 
     190   [ #  #  #  # ]:          0 :                 if (rx_ring_info && (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
     191         [ #  # ]:          0 :                         int tpa_max = BNXT_TPA_MAX_AGGS(bp);
     192                 :            : 
     193                 :          0 :                         tpa_info_len = tpa_max * sizeof(struct bnxt_tpa_info);
     194                 :          0 :                         tpa_info_len = RTE_CACHE_LINE_ROUNDUP(tpa_info_len);
     195                 :            :                 }
     196                 :            :         }
     197                 :            : 
     198                 :          0 :         ag_bitmap_start = ag_ring_start + ag_ring_len;
     199                 :          0 :         tpa_info_start = ag_bitmap_start + ag_bitmap_len;
     200                 :          0 :         total_alloc_len = tpa_info_start + tpa_info_len;
     201                 :            : 
     202                 :          0 :         snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
     203                 :            :                  "bnxt_" PCI_PRI_FMT "-%04x_%s", pdev->addr.domain,
     204                 :          0 :                  pdev->addr.bus, pdev->addr.devid, pdev->addr.function, qidx,
     205                 :            :                  suffix);
     206                 :          0 :         mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
     207                 :          0 :         mz = rte_memzone_lookup(mz_name);
     208         [ #  # ]:          0 :         if (!mz) {
     209                 :          0 :                 mz = rte_memzone_reserve_aligned(mz_name, total_alloc_len,
     210                 :            :                                 socket_id,
     211                 :            :                                 RTE_MEMZONE_2MB |
     212                 :            :                                 RTE_MEMZONE_SIZE_HINT_ONLY |
     213                 :            :                                 RTE_MEMZONE_IOVA_CONTIG,
     214                 :          0 :                                 getpagesize());
     215         [ #  # ]:          0 :                 if (mz == NULL)
     216                 :            :                         return -ENOMEM;
     217                 :            :         }
     218         [ #  # ]:          0 :         memset(mz->addr, 0, mz->len);
     219                 :          0 :         mz_phys_addr = mz->iova;
     220                 :            : 
     221         [ #  # ]:          0 :         if (tx_ring_info) {
     222                 :          0 :                 txq->mz = mz;
     223                 :          0 :                 tx_ring = tx_ring_info->tx_ring_struct;
     224                 :            : 
     225                 :          0 :                 tx_ring->bd = ((char *)mz->addr + tx_ring_start);
     226                 :          0 :                 tx_ring_info->tx_desc_ring = (struct tx_bd_long *)tx_ring->bd;
     227                 :          0 :                 tx_ring->bd_dma = mz_phys_addr + tx_ring_start;
     228                 :          0 :                 tx_ring_info->tx_desc_mapping = tx_ring->bd_dma;
     229                 :          0 :                 tx_ring->mem_zone = (const void *)mz;
     230                 :          0 :                 tx_ring_info->nr_bds = rte_zmalloc("bnxt_nr_bds",
     231                 :            :                                                    sizeof(unsigned short) *
     232                 :          0 :                                                    tx_ring->ring_size, 0);
     233                 :            : 
     234         [ #  # ]:          0 :                 if (!tx_ring->bd)
     235                 :            :                         return -ENOMEM;
     236         [ #  # ]:          0 :                 if (tx_ring->vmem_size) {
     237                 :          0 :                         tx_ring->vmem =
     238                 :          0 :                             (void **)((char *)mz->addr + tx_vmem_start);
     239                 :          0 :                         tx_ring_info->tx_buf_ring =
     240                 :            :                             (struct rte_mbuf **)tx_ring->vmem;
     241                 :            :                 }
     242                 :            :         }
     243                 :            : 
     244         [ #  # ]:          0 :         if (rx_ring_info) {
     245                 :          0 :                 rxq->mz = mz;
     246                 :          0 :                 rx_ring = rx_ring_info->rx_ring_struct;
     247                 :            : 
     248                 :          0 :                 rx_ring->bd = ((char *)mz->addr + rx_ring_start);
     249                 :          0 :                 rx_ring_info->rx_desc_ring =
     250                 :            :                     (struct rx_prod_pkt_bd *)rx_ring->bd;
     251                 :          0 :                 rx_ring->bd_dma = mz_phys_addr + rx_ring_start;
     252                 :          0 :                 rx_ring_info->rx_desc_mapping = rx_ring->bd_dma;
     253                 :          0 :                 rx_ring->mem_zone = (const void *)mz;
     254                 :            : 
     255         [ #  # ]:          0 :                 if (!rx_ring->bd)
     256                 :            :                         return -ENOMEM;
     257         [ #  # ]:          0 :                 if (rx_ring->vmem_size) {
     258                 :          0 :                         rx_ring->vmem =
     259                 :          0 :                             (void **)((char *)mz->addr + rx_vmem_start);
     260                 :          0 :                         rx_ring_info->rx_buf_ring =
     261                 :            :                             (struct rte_mbuf **)rx_ring->vmem;
     262                 :            :                 }
     263                 :            : 
     264         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev)) {
     265                 :          0 :                         rx_ring = rx_ring_info->ag_ring_struct;
     266                 :            : 
     267                 :          0 :                         rx_ring->bd = ((char *)mz->addr + ag_ring_start);
     268                 :          0 :                         rx_ring_info->ag_desc_ring =
     269                 :            :                             (struct rx_prod_pkt_bd *)rx_ring->bd;
     270                 :          0 :                         rx_ring->bd_dma = mz->iova + ag_ring_start;
     271                 :          0 :                         rx_ring_info->ag_desc_mapping = rx_ring->bd_dma;
     272                 :          0 :                         rx_ring->mem_zone = (const void *)mz;
     273                 :            : 
     274         [ #  # ]:          0 :                         if (!rx_ring->bd)
     275                 :            :                                 return -ENOMEM;
     276         [ #  # ]:          0 :                         if (rx_ring->vmem_size) {
     277                 :          0 :                                 rx_ring->vmem =
     278                 :          0 :                                     (void **)((char *)mz->addr + ag_vmem_start);
     279                 :          0 :                                 rx_ring_info->ag_buf_ring =
     280                 :            :                                     (struct rte_mbuf **)rx_ring->vmem;
     281                 :            :                         }
     282                 :            : 
     283                 :          0 :                         rx_ring_info->ag_bitmap =
     284                 :          0 :                             rte_bitmap_init(rx_ring_info->rx_ring_struct->ring_size *
     285                 :            :                                             AGG_RING_SIZE_FACTOR, (uint8_t *)mz->addr +
     286                 :            :                                             ag_bitmap_start, ag_bitmap_len);
     287                 :            : 
     288                 :            :                         /* TPA info */
     289         [ #  # ]:          0 :                         if (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)
     290                 :          0 :                                 rx_ring_info->tpa_info =
     291                 :          0 :                                         ((struct bnxt_tpa_info *)
     292                 :          0 :                                          ((char *)mz->addr + tpa_info_start));
     293                 :            :                 }
     294                 :            :         }
     295                 :            : 
     296                 :          0 :         cp_ring->bd = ((char *)mz->addr + cp_ring_start);
     297                 :          0 :         cp_ring->bd_dma = mz_phys_addr + cp_ring_start;
     298                 :          0 :         cp_ring_info->cp_desc_ring = cp_ring->bd;
     299                 :          0 :         cp_ring_info->cp_desc_mapping = cp_ring->bd_dma;
     300                 :          0 :         cp_ring->mem_zone = (const void *)mz;
     301                 :            : 
     302         [ #  # ]:          0 :         if (!cp_ring->bd)
     303                 :            :                 return -ENOMEM;
     304         [ #  # ]:          0 :         if (cp_ring->vmem_size)
     305                 :          0 :                 *cp_ring->vmem = ((char *)mz->addr + stats_len);
     306         [ #  # ]:          0 :         if (stats_len) {
     307                 :          0 :                 cp_ring_info->hw_stats = mz->addr;
     308                 :            :         }
     309                 :          0 :         cp_ring_info->hw_stats_map = mz_phys_addr;
     310                 :            : 
     311                 :          0 :         cp_ring_info->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
     312                 :            : 
     313         [ #  # ]:          0 :         if (nq_ring_info) {
     314                 :          0 :                 struct bnxt_ring *nq_ring = nq_ring_info->cp_ring_struct;
     315                 :            : 
     316                 :          0 :                 nq_ring->bd = (char *)mz->addr + nq_ring_start;
     317                 :          0 :                 nq_ring->bd_dma = mz_phys_addr + nq_ring_start;
     318                 :          0 :                 nq_ring_info->cp_desc_ring = nq_ring->bd;
     319                 :          0 :                 nq_ring_info->cp_desc_mapping = nq_ring->bd_dma;
     320                 :          0 :                 nq_ring->mem_zone = (const void *)mz;
     321                 :            : 
     322         [ #  # ]:          0 :                 if (!nq_ring->bd)
     323                 :            :                         return -ENOMEM;
     324         [ #  # ]:          0 :                 if (nq_ring->vmem_size)
     325                 :          0 :                         *nq_ring->vmem = (char *)mz->addr + nq_vmem_start;
     326                 :            : 
     327                 :          0 :                 nq_ring_info->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
     328                 :            :         }
     329                 :            : 
     330                 :            :         return 0;
     331                 :            : }
     332                 :            : 
     333                 :          0 : void bnxt_init_dflt_coal(struct bnxt_coal *coal)
     334                 :            : {
     335                 :            :         /* Tick values in micro seconds.
     336                 :            :          * 1 coal_buf x bufs_per_record = 1 completion record.
     337                 :            :          */
     338                 :          0 :         coal->num_cmpl_aggr_int = BNXT_NUM_CMPL_AGGR_INT;
     339                 :            :         /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
     340                 :          0 :         coal->num_cmpl_dma_aggr = BNXT_NUM_CMPL_DMA_AGGR;
     341                 :            :         /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
     342                 :          0 :         coal->num_cmpl_dma_aggr_during_int = BNXT_NUM_CMPL_DMA_AGGR_DURING_INT;
     343                 :          0 :         coal->int_lat_tmr_max = BNXT_INT_LAT_TMR_MAX;
     344                 :            :         /* min timer set to 1/2 of interrupt timer */
     345                 :          0 :         coal->int_lat_tmr_min = BNXT_INT_LAT_TMR_MIN;
     346                 :            :         /* buf timer set to 1/4 of interrupt timer */
     347                 :          0 :         coal->cmpl_aggr_dma_tmr = BNXT_CMPL_AGGR_DMA_TMR;
     348                 :          0 :         coal->cmpl_aggr_dma_tmr_during_int = BNXT_CMPL_AGGR_DMA_TMR_DURING_INT;
     349                 :          0 : }
     350                 :            : 
     351                 :          0 : void bnxt_set_db(struct bnxt *bp,
     352                 :            :                  struct bnxt_db_info *db,
     353                 :            :                  uint32_t ring_type,
     354                 :            :                  uint32_t map_idx,
     355                 :            :                  uint32_t fid,
     356                 :            :                  uint32_t ring_mask,
     357                 :            :                  uint16_t dpi)
     358                 :            : {
     359                 :            :         uint64_t dpi_offset;
     360                 :            : 
     361         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp)) {
     362                 :            :                 int db_offset = DB_PF_OFFSET;
     363   [ #  #  #  #  :          0 :                 switch (ring_type) {
                      # ]
     364                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
     365                 :          0 :                         db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SQ;
     366                 :          0 :                         break;
     367                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
     368                 :            :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
     369                 :          0 :                         db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SRQ;
     370                 :          0 :                         break;
     371                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
     372                 :          0 :                         db->db_key64 = DBR_PATH_L2 | DBR_TYPE_CQ;
     373                 :          0 :                         break;
     374                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
     375                 :          0 :                         db->db_key64 = DBR_PATH_L2;
     376                 :          0 :                         break;
     377                 :            :                 }
     378         [ #  # ]:          0 :                 if (BNXT_CHIP_P7(bp)) {
     379                 :          0 :                         db->db_key64 |= DBR_VALID;
     380                 :          0 :                         db_offset = bp->legacy_db_size;
     381                 :          0 :                         db->db_epoch_mask = ring_mask + 1;
     382         [ #  # ]:          0 :                 } else if (BNXT_VF(bp)) {
     383                 :            :                         db_offset = DB_VF_OFFSET;
     384                 :            :                 }
     385                 :          0 :                 db->doorbell = (char *)bp->doorbell_base + db_offset;
     386                 :            : 
     387   [ #  #  #  # ]:          0 :                 if (bp->fw_cap & BNXT_FW_CAP_MULTI_DB &&
     388                 :            :                                 dpi != BNXT_PRIVILEGED_DPI) {
     389                 :          0 :                         dpi_offset = (dpi - bp->nq_dpi_start) *
     390                 :          0 :                                         bp->db_page_size;
     391                 :          0 :                         db->doorbell = (char *)db->doorbell + dpi_offset;
     392                 :            :                 }
     393                 :          0 :                 db->db_key64 |= (uint64_t)fid << DBR_XID_SFT;
     394                 :          0 :                 db->db_64 = true;
     395                 :            :         } else {
     396                 :          0 :                 db->doorbell = (char *)bp->doorbell_base + map_idx * 0x80;
     397   [ #  #  #  # ]:          0 :                 switch (ring_type) {
     398                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
     399                 :          0 :                         db->db_key32 = DB_KEY_TX;
     400                 :          0 :                         break;
     401                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
     402                 :          0 :                         db->db_key32 = DB_KEY_RX;
     403                 :          0 :                         break;
     404                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
     405                 :          0 :                         db->db_key32 = DB_KEY_CP;
     406                 :          0 :                         break;
     407                 :            :                 }
     408                 :          0 :                 db->db_64 = false;
     409                 :            :         }
     410                 :          0 :         db->db_ring_mask = ring_mask;
     411                 :          0 : }
     412                 :            : 
     413                 :          0 : int bnxt_alloc_cmpl_ring(struct bnxt *bp, int queue_index,
     414                 :            :                          struct bnxt_cp_ring_info *cpr)
     415                 :            : {
     416                 :          0 :         int cp_ring_index = queue_index + BNXT_RX_VEC_START;
     417                 :          0 :         struct bnxt_cp_ring_info *nqr = bp->rxtx_nq_ring;
     418                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     419                 :            :         uint32_t nq_ring_id = HWRM_NA_SIGNATURE;
     420                 :            :         uint8_t dpi = BNXT_PRIVILEGED_DPI;
     421                 :            :         uint8_t ring_type;
     422                 :            :         int rc = 0;
     423                 :            : 
     424                 :            :         ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
     425                 :            : 
     426         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp)) {
     427         [ #  # ]:          0 :                 if (!nqr) {
     428                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "NQ ring is NULL");
     429                 :          0 :                         return -EINVAL;
     430                 :            :                 }
     431                 :          0 :                 nq_ring_id = nqr->cp_ring_struct->fw_ring_id;
     432                 :            :         }
     433                 :            : 
     434                 :          0 :         cpr->dpi = dpi;
     435                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, cp_ring_index,
     436                 :            :                                   HWRM_NA_SIGNATURE, nq_ring_id, 0, dpi);
     437         [ #  # ]:          0 :         if (rc)
     438                 :            :                 return rc;
     439                 :            : 
     440                 :          0 :         cpr->cp_raw_cons = 0;
     441                 :          0 :         bnxt_set_db(bp, &cpr->cp_db, ring_type, cp_ring_index,
     442                 :          0 :                     cp_ring->fw_ring_id, cp_ring->ring_mask, dpi);
     443                 :          0 :         bnxt_db_cq(cpr);
     444                 :            : 
     445                 :          0 :         return 0;
     446                 :            : }
     447                 :            : 
     448                 :          0 : int bnxt_alloc_rxtx_nq_ring(struct bnxt *bp)
     449                 :            : {
     450                 :            :         int ring_index = BNXT_NUM_ASYNC_CPR(bp);
     451                 :            :         uint8_t dpi = BNXT_PRIVILEGED_DPI;
     452                 :            :         struct bnxt_cp_ring_info *nqr;
     453                 :            :         struct bnxt_ring *ring;
     454                 :            :         uint8_t ring_type;
     455                 :            :         uint8_t offset;
     456                 :            :         int rc = 0;
     457                 :            : 
     458   [ #  #  #  # ]:          0 :         if (!BNXT_HAS_NQ(bp) || bp->rxtx_nq_ring)
     459                 :            :                 return 0;
     460                 :            : 
     461                 :          0 :         nqr = rte_zmalloc_socket("nqr",
     462                 :            :                                  sizeof(struct bnxt_cp_ring_info),
     463                 :            :                                  RTE_CACHE_LINE_SIZE,
     464                 :          0 :                                  bp->eth_dev->device->numa_node);
     465         [ #  # ]:          0 :         if (nqr == NULL)
     466                 :            :                 return -ENOMEM;
     467                 :            : 
     468                 :          0 :         ring = rte_zmalloc_socket("bnxt_cp_ring_struct",
     469                 :            :                                   sizeof(struct bnxt_ring),
     470                 :            :                                   RTE_CACHE_LINE_SIZE,
     471                 :          0 :                                   bp->eth_dev->device->numa_node);
     472         [ #  # ]:          0 :         if (ring == NULL) {
     473                 :          0 :                 rte_free(nqr);
     474                 :          0 :                 return -ENOMEM;
     475                 :            :         }
     476                 :            : 
     477                 :          0 :         ring->bd = (void *)nqr->cp_desc_ring;
     478                 :          0 :         ring->bd_dma = nqr->cp_desc_mapping;
     479                 :          0 :         ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE);
     480                 :          0 :         ring->ring_mask = ring->ring_size - 1;
     481                 :          0 :         ring->vmem_size = 0;
     482                 :          0 :         ring->vmem = NULL;
     483                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
     484                 :            : 
     485                 :          0 :         nqr->cp_ring_struct = ring;
     486                 :          0 :         rc = bnxt_alloc_rings(bp, bp->eth_dev->device->numa_node, 0, NULL,
     487                 :            :                               NULL, nqr, NULL, "l2_nqr");
     488         [ #  # ]:          0 :         if (rc) {
     489                 :          0 :                 rte_free(ring);
     490                 :          0 :                 rte_free(nqr);
     491                 :          0 :                 return -ENOMEM;
     492                 :            :         }
     493                 :            : 
     494                 :            :         ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ;
     495                 :            : 
     496                 :            :         /* Assign DPI using round-robin if multi-doorbell is enabled */
     497   [ #  #  #  # ]:          0 :         if (bp->fw_cap & BNXT_FW_CAP_MULTI_DB && bp->nq_dpi_count > 0) {
     498                 :          0 :                 offset = bp->nq_dpi_counter % bp->nq_dpi_count;
     499                 :          0 :                 dpi = bp->nq_dpi_start + offset;
     500                 :          0 :                 bp->nq_dpi_counter++;
     501                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG, "NQ ring assigned DPI %u", dpi);
     502                 :            :         }
     503                 :            : 
     504                 :          0 :         nqr->dpi = dpi;
     505                 :            : 
     506                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, ring_index,
     507                 :            :                                   HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE, 0, dpi);
     508         [ #  # ]:          0 :         if (rc) {
     509                 :          0 :                 rte_free(ring);
     510                 :          0 :                 rte_free(nqr);
     511                 :          0 :                 return rc;
     512                 :            :         }
     513                 :            : 
     514                 :          0 :         bnxt_set_db(bp, &nqr->cp_db, ring_type, ring_index,
     515                 :          0 :                     ring->fw_ring_id, ring->ring_mask, dpi);
     516                 :            :         bnxt_db_nq(nqr);
     517                 :            : 
     518                 :          0 :         bp->rxtx_nq_ring = nqr;
     519                 :            : 
     520                 :          0 :         return 0;
     521                 :            : }
     522                 :            : 
     523                 :            : /* Free RX/TX NQ ring.  */
     524                 :          0 : void bnxt_free_rxtx_nq_ring(struct bnxt *bp)
     525                 :            : {
     526                 :          0 :         struct bnxt_cp_ring_info *nqr = bp->rxtx_nq_ring;
     527                 :            : 
     528         [ #  # ]:          0 :         if (!nqr)
     529                 :            :                 return;
     530                 :            : 
     531                 :          0 :         bnxt_free_nq_ring(bp, nqr);
     532                 :            : 
     533                 :          0 :         bnxt_free_ring(nqr->cp_ring_struct);
     534                 :          0 :         rte_free(nqr->cp_ring_struct);
     535                 :          0 :         nqr->cp_ring_struct = NULL;
     536                 :          0 :         rte_free(nqr);
     537                 :          0 :         bp->rxtx_nq_ring = NULL;
     538                 :            : }
     539                 :            : 
     540                 :          0 : static int bnxt_alloc_rx_ring(struct bnxt *bp, int queue_index)
     541                 :            : {
     542                 :          0 :         struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
     543                 :          0 :         struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
     544                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     545                 :          0 :         struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
     546                 :          0 :         struct bnxt_ring *ring = rxr->rx_ring_struct;
     547                 :            :         uint8_t ring_type;
     548                 :            :         uint16_t dpi;
     549                 :            :         int rc = 0;
     550                 :            : 
     551                 :            :         ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
     552                 :            :         dpi = BNXT_PRIVILEGED_DPI;
     553                 :          0 :         rxr->dpi = dpi;
     554                 :            : 
     555                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type,
     556                 :            :                                   queue_index, cpr->hw_stats_ctx_id,
     557                 :          0 :                                   cp_ring->fw_ring_id, 0, dpi);
     558         [ #  # ]:          0 :         if (rc)
     559                 :            :                 return rc;
     560                 :            : 
     561                 :          0 :         rxr->rx_raw_prod = 0;
     562         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
     563                 :          0 :                 bp->grp_info[queue_index].rx_fw_ring_id = ring->fw_ring_id;
     564                 :          0 :         bnxt_set_db(bp, &rxr->rx_db, ring_type, queue_index, ring->fw_ring_id,
     565                 :            :                     ring->ring_mask, dpi);
     566         [ #  # ]:          0 :         bnxt_db_write(&rxr->rx_db, rxr->rx_raw_prod);
     567                 :            : 
     568                 :            :         return 0;
     569                 :            : }
     570                 :            : 
     571                 :          0 : static int bnxt_alloc_rx_agg_ring(struct bnxt *bp, int queue_index)
     572                 :            : {
     573                 :          0 :         unsigned int map_idx = queue_index + bp->rx_cp_nr_rings;
     574                 :          0 :         struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
     575                 :          0 :         struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
     576                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     577                 :          0 :         struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
     578                 :          0 :         struct bnxt_ring *ring = rxr->ag_ring_struct;
     579                 :            :         uint32_t hw_stats_ctx_id = HWRM_NA_SIGNATURE;
     580                 :            :         uint8_t ring_type;
     581                 :            :         int rc = 0;
     582                 :            : 
     583         [ #  # ]:          0 :         if (!bnxt_need_agg_ring(bp->eth_dev))
     584                 :            :                 return 0;
     585                 :            : 
     586                 :          0 :         ring->fw_rx_ring_id = rxr->rx_ring_struct->fw_ring_id;
     587                 :            : 
     588         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp)) {
     589                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG;
     590                 :          0 :                 hw_stats_ctx_id = cpr->hw_stats_ctx_id;
     591                 :            :         } else {
     592                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
     593                 :            :         }
     594                 :            : 
     595                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx,
     596                 :          0 :                                   hw_stats_ctx_id, cp_ring->fw_ring_id, 0,
     597                 :            :                                   BNXT_PRIVILEGED_DPI);
     598                 :            : 
     599         [ #  # ]:          0 :         if (rc)
     600                 :            :                 return rc;
     601                 :            : 
     602                 :          0 :         rxr->ag_raw_prod = 0;
     603                 :          0 :         rxr->ag_cons = 0;
     604         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
     605                 :          0 :                 bp->grp_info[queue_index].ag_fw_ring_id = ring->fw_ring_id;
     606                 :          0 :         bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx, ring->fw_ring_id,
     607                 :            :                     ring->ring_mask, BNXT_PRIVILEGED_DPI);
     608         [ #  # ]:          0 :         bnxt_db_write(&rxr->ag_db, rxr->ag_raw_prod);
     609                 :            : 
     610                 :            :         return 0;
     611                 :            : }
     612                 :            : 
     613                 :          0 : int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index)
     614                 :            : {
     615                 :          0 :         struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
     616                 :          0 :         struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
     617                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     618         [ #  # ]:          0 :         struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
     619                 :            :         struct bnxt_coal coal;
     620                 :            :         int rc;
     621                 :            : 
     622                 :            :         /*
     623                 :            :          * Storage for the cp ring is allocated based on worst-case
     624                 :            :          * usage, the actual size to be used by hw is computed here.
     625                 :            :          */
     626                 :            :         if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
     627         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev))
     628                 :            :                         /* Worst case scenario, needed to accommodate Rx flush
     629                 :            :                          * completion during RING_FREE.
     630                 :            :                          */
     631                 :          0 :                         cp_ring->ring_size = rxr->rx_ring_struct->ring_size * 2;
     632                 :            :                 else
     633                 :          0 :                         cp_ring->ring_size = rxr->rx_ring_struct->ring_size;
     634                 :            :         } else {
     635                 :          0 :                 cp_ring->ring_size = rxr->rx_ring_struct->ring_size * 2;
     636                 :            :         }
     637                 :            : 
     638         [ #  # ]:          0 :         if (bnxt_need_agg_ring(bp->eth_dev))
     639                 :          0 :                 cp_ring->ring_size *= AGG_RING_SIZE_FACTOR;
     640                 :            : 
     641                 :          0 :         cp_ring->ring_mask = cp_ring->ring_size - 1;
     642                 :            : 
     643                 :          0 :         rc = bnxt_alloc_cmpl_ring(bp, queue_index, cpr);
     644         [ #  # ]:          0 :         if (rc)
     645                 :          0 :                 goto err_out;
     646                 :            : 
     647                 :          0 :         rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr);
     648         [ #  # ]:          0 :         if (rc)
     649                 :          0 :                 goto err_out;
     650                 :            : 
     651         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp)) {
     652                 :          0 :                 bp->grp_info[queue_index].fw_stats_ctx = cpr->hw_stats_ctx_id;
     653                 :          0 :                 bp->grp_info[queue_index].cp_fw_ring_id = cp_ring->fw_ring_id;
     654                 :            :         }
     655                 :            : 
     656                 :          0 :         bnxt_init_dflt_coal(&coal);
     657                 :          0 :         bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id);
     658                 :            : 
     659                 :            :         if (!BNXT_NUM_ASYNC_CPR(bp) && !queue_index) {
     660                 :            :                 /*
     661                 :            :                  * If a dedicated async event completion ring is not enabled,
     662                 :            :                  * use the first completion ring from PF or VF as the default
     663                 :            :                  * completion ring for async event handling.
     664                 :            :                  */
     665                 :            :                 bp->async_cp_ring = cpr;
     666                 :            :                 rc = bnxt_hwrm_set_async_event_cr(bp);
     667                 :            :                 if (rc)
     668                 :            :                         goto err_out;
     669                 :            :         }
     670                 :            : 
     671                 :          0 :         rc = bnxt_alloc_rx_ring(bp, queue_index);
     672         [ #  # ]:          0 :         if (rc)
     673                 :          0 :                 goto err_out;
     674                 :            : 
     675                 :          0 :         rc = bnxt_alloc_rx_agg_ring(bp, queue_index);
     676         [ #  # ]:          0 :         if (rc)
     677                 :          0 :                 goto err_out;
     678                 :            : 
     679         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp)) {
     680                 :          0 :                 rc = bnxt_hwrm_ring_grp_alloc(bp, queue_index);
     681         [ #  # ]:          0 :                 if (rc)
     682                 :          0 :                         goto err_out;
     683                 :            :         }
     684                 :            : 
     685         [ #  # ]:          0 :         if (rxq->rx_started) {
     686         [ #  # ]:          0 :                 if (bnxt_init_one_rx_ring(rxq)) {
     687                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
     688                 :            :                                     "ring%d bnxt_init_one_rx_ring failed!",
     689                 :            :                                     queue_index);
     690                 :            :                         rc = -ENOMEM;
     691                 :          0 :                         goto err_out;
     692                 :            :                 }
     693         [ #  # ]:          0 :                 bnxt_db_write(&rxr->rx_db, rxr->rx_raw_prod);
     694         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev))
     695         [ #  # ]:          0 :                         bnxt_db_write(&rxr->ag_db, rxr->ag_raw_prod);
     696                 :            :         }
     697                 :          0 :         rxq->index = queue_index;
     698                 :            : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
     699                 :          0 :         bnxt_rxq_vec_setup(rxq);
     700                 :            : #endif
     701                 :            : 
     702                 :          0 :         return 0;
     703                 :            : 
     704                 :          0 : err_out:
     705                 :          0 :         PMD_DRV_LOG_LINE(ERR,
     706                 :            :                     "Failed to allocate receive queue %d, rc %d.",
     707                 :            :                     queue_index, rc);
     708                 :          0 :         return rc;
     709                 :            : }
     710                 :            : 
     711                 :            : /* Initialise all rings to -1, its used to free rings later if allocation
     712                 :            :  * of few rings fails.
     713                 :            :  */
     714                 :          0 : static void bnxt_init_all_rings(struct bnxt *bp)
     715                 :            : {
     716                 :            :         unsigned int i = 0;
     717                 :            :         struct bnxt_rx_queue *rxq;
     718                 :            :         struct bnxt_ring *cp_ring;
     719                 :            :         struct bnxt_ring *ring;
     720                 :            :         struct bnxt_rx_ring_info *rxr;
     721                 :            :         struct bnxt_tx_queue *txq;
     722                 :            : 
     723         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
     724                 :          0 :                 rxq = bp->rx_queues[i];
     725                 :            :                 /* Rx-compl */
     726                 :          0 :                 cp_ring = rxq->cp_ring->cp_ring_struct;
     727                 :          0 :                 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
     728                 :            :                 /* Rx-Reg */
     729                 :          0 :                 rxr = rxq->rx_ring;
     730                 :          0 :                 ring = rxr->rx_ring_struct;
     731                 :          0 :                 ring->fw_ring_id = INVALID_HW_RING_ID;
     732                 :            :                 /* Rx-AGG */
     733         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev)) {
     734                 :          0 :                         ring = rxr->ag_ring_struct;
     735         [ #  # ]:          0 :                         if (ring != NULL)
     736                 :          0 :                                 ring->fw_ring_id = INVALID_HW_RING_ID;
     737                 :            :                 }
     738                 :            :         }
     739         [ #  # ]:          0 :         for (i = 0; i < bp->tx_cp_nr_rings; i++) {
     740                 :          0 :                 txq = bp->tx_queues[i];
     741                 :            :                 /* Tx cmpl */
     742                 :          0 :                 cp_ring = txq->cp_ring->cp_ring_struct;
     743                 :          0 :                 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
     744                 :            :                 /*Tx Ring */
     745                 :          0 :                 ring = txq->tx_ring->tx_ring_struct;
     746                 :          0 :                 ring->fw_ring_id = INVALID_HW_RING_ID;
     747                 :            :         }
     748                 :          0 : }
     749                 :            : 
     750                 :            : /* ring_grp usage:
     751                 :            :  * [0] = default completion ring
     752                 :            :  * [1 -> +rx_cp_nr_rings] = rx_cp, rx rings
     753                 :            :  * [1+rx_cp_nr_rings + 1 -> +tx_cp_nr_rings] = tx_cp, tx rings
     754                 :            :  */
     755                 :          0 : int bnxt_alloc_hwrm_rings(struct bnxt *bp)
     756                 :            : {
     757                 :            :         struct bnxt_coal coal;
     758                 :            :         unsigned int i;
     759                 :            :         int rc = 0;
     760                 :            : 
     761                 :          0 :         bnxt_init_dflt_coal(&coal);
     762                 :          0 :         bnxt_init_all_rings(bp);
     763                 :            : 
     764         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
     765                 :          0 :                 unsigned int soc_id = bp->eth_dev->device->numa_node;
     766                 :          0 :                 struct bnxt_rx_queue *rxq  = bp->rx_queues[i];
     767                 :          0 :                 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
     768                 :            :                 struct bnxt_ring *ring;
     769                 :            : 
     770         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev)) {
     771                 :          0 :                         ring = rxr->ag_ring_struct;
     772         [ #  # ]:          0 :                         if (ring == NULL) {
     773                 :          0 :                                 bnxt_free_rxq_mem(rxq);
     774                 :            : 
     775                 :          0 :                                 rc = bnxt_init_rx_ring_struct(rxq, soc_id);
     776         [ #  # ]:          0 :                                 if (rc)
     777                 :          0 :                                         goto err_out;
     778                 :            : 
     779                 :          0 :                                 rc = bnxt_alloc_rings(bp, soc_id,
     780                 :            :                                                       i, NULL, rxq,
     781                 :            :                                                       rxq->cp_ring, NULL,
     782                 :            :                                                       "rxr");
     783         [ #  # ]:          0 :                                 if (rc)
     784                 :          0 :                                         goto err_out;
     785                 :            :                         }
     786                 :            :                 }
     787                 :            : 
     788                 :          0 :                 rc = bnxt_alloc_hwrm_rx_ring(bp, i);
     789         [ #  # ]:          0 :                 if (rc)
     790                 :          0 :                         goto err_out;
     791                 :          0 :                 bnxt_hwrm_set_ring_coal(bp, &coal,
     792                 :          0 :                                         rxq->cp_ring->cp_ring_struct->fw_ring_id);
     793                 :            :         }
     794                 :            : 
     795                 :            :         /* If something is wrong with Rx ring alloc, skip Tx ring alloc */
     796         [ #  # ]:          0 :         for (i = 0; i < bp->tx_cp_nr_rings; i++) {
     797                 :          0 :                 rc = bnxt_alloc_hwrm_tx_ring(bp, i);
     798         [ #  # ]:          0 :                 if (rc)
     799                 :          0 :                         goto err_out;
     800                 :            :         }
     801                 :            : 
     802                 :          0 : err_out:
     803                 :          0 :         return rc;
     804                 :            : }
     805                 :            : 
     806                 :            : /* Allocate dedicated async completion ring. */
     807                 :          0 : int bnxt_alloc_async_cp_ring(struct bnxt *bp)
     808                 :            : {
     809                 :          0 :         struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
     810                 :            :         struct bnxt_ring *cp_ring;
     811                 :            :         uint8_t ring_type;
     812                 :            :         int rc;
     813                 :            : 
     814         [ #  # ]:          0 :         if (BNXT_NUM_ASYNC_CPR(bp) == 0 || cpr == NULL)
     815                 :            :                 return 0;
     816                 :            : 
     817                 :          0 :         cp_ring = cpr->cp_ring_struct;
     818                 :            : 
     819         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp))
     820                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ;
     821                 :            :         else
     822                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
     823                 :            : 
     824                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, 0,
     825                 :            :                                   HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE, 0,
     826                 :            :                                   BNXT_PRIVILEGED_DPI);
     827                 :            : 
     828         [ #  # ]:          0 :         if (rc)
     829                 :            :                 return rc;
     830                 :            : 
     831                 :          0 :         cpr->cp_raw_cons = 0;
     832                 :          0 :         cpr->dpi = BNXT_PRIVILEGED_DPI;
     833                 :          0 :         bnxt_set_db(bp, &cpr->cp_db, ring_type, 0,
     834                 :          0 :                     cp_ring->fw_ring_id, cp_ring->ring_mask, BNXT_PRIVILEGED_DPI);
     835                 :            : 
     836         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp))
     837                 :            :                 bnxt_db_nq(cpr);
     838                 :            :         else
     839                 :          0 :                 bnxt_db_cq(cpr);
     840                 :            : 
     841                 :          0 :         return bnxt_hwrm_set_async_event_cr(bp);
     842                 :            : }
     843                 :            : 
     844                 :            : /* Free dedicated async completion ring. */
     845                 :          0 : void bnxt_free_async_cp_ring(struct bnxt *bp)
     846                 :            : {
     847                 :          0 :         struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
     848                 :            : 
     849         [ #  # ]:          0 :         if (BNXT_NUM_ASYNC_CPR(bp) == 0 || cpr == NULL)
     850                 :            :                 return;
     851                 :            : 
     852         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp))
     853                 :          0 :                 bnxt_free_nq_ring(bp, cpr);
     854                 :            :         else
     855                 :          0 :                 bnxt_free_cp_ring(bp, cpr);
     856                 :            : 
     857                 :          0 :         bnxt_free_ring(cpr->cp_ring_struct);
     858                 :          0 :         rte_free(cpr->cp_ring_struct);
     859                 :          0 :         cpr->cp_ring_struct = NULL;
     860                 :          0 :         rte_free(cpr);
     861                 :          0 :         bp->async_cp_ring = NULL;
     862                 :            : }
     863                 :            : 
     864                 :          0 : int bnxt_alloc_async_ring_struct(struct bnxt *bp)
     865                 :            : {
     866                 :            :         struct bnxt_cp_ring_info *cpr = NULL;
     867                 :            :         struct bnxt_ring *ring = NULL;
     868                 :            : 
     869                 :            :         if (BNXT_NUM_ASYNC_CPR(bp) == 0)
     870                 :            :                 return 0;
     871                 :            : 
     872                 :          0 :         cpr = rte_zmalloc_socket("cpr",
     873                 :            :                                  sizeof(struct bnxt_cp_ring_info),
     874                 :            :                                  RTE_CACHE_LINE_SIZE,
     875                 :          0 :                                  bp->eth_dev->device->numa_node);
     876         [ #  # ]:          0 :         if (cpr == NULL)
     877                 :            :                 return -ENOMEM;
     878                 :            : 
     879                 :          0 :         ring = rte_zmalloc_socket("bnxt_cp_ring_struct",
     880                 :            :                                   sizeof(struct bnxt_ring),
     881                 :            :                                   RTE_CACHE_LINE_SIZE,
     882                 :          0 :                                   bp->eth_dev->device->numa_node);
     883         [ #  # ]:          0 :         if (ring == NULL) {
     884                 :          0 :                 rte_free(cpr);
     885                 :          0 :                 return -ENOMEM;
     886                 :            :         }
     887                 :            : 
     888                 :          0 :         ring->bd = (void *)cpr->cp_desc_ring;
     889                 :          0 :         ring->bd_dma = cpr->cp_desc_mapping;
     890                 :          0 :         ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE);
     891                 :          0 :         ring->ring_mask = ring->ring_size - 1;
     892                 :          0 :         ring->vmem_size = 0;
     893                 :          0 :         ring->vmem = NULL;
     894                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
     895                 :            : 
     896                 :          0 :         bp->async_cp_ring = cpr;
     897                 :          0 :         cpr->cp_ring_struct = ring;
     898                 :            : 
     899                 :          0 :         return bnxt_alloc_rings(bp, bp->eth_dev->device->numa_node, 0, NULL,
     900                 :            :                                 NULL, bp->async_cp_ring, NULL, "def_cp");
     901                 :            : }
     902                 :            : 
     903                 :          0 : int bnxt_alloc_hwrm_tx_ring(struct bnxt *bp, int queue_index)
     904                 :            : {
     905                 :          0 :         struct bnxt_tx_queue *txq = bp->tx_queues[queue_index];
     906                 :          0 :         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
     907                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     908                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     909                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     910                 :          0 :         unsigned int idx = queue_index + bp->rx_cp_nr_rings;
     911                 :            :         uint16_t tx_cosq_id = 0;
     912                 :            :         struct bnxt_coal coal;
     913                 :            :         int rc = 0;
     914                 :            : 
     915                 :          0 :         rc = bnxt_alloc_cmpl_ring(bp, idx, cpr);
     916         [ #  # ]:          0 :         if (rc)
     917                 :          0 :                 goto err_out;
     918                 :            : 
     919                 :          0 :         bnxt_init_dflt_coal(&coal);
     920                 :          0 :         bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id);
     921                 :            : 
     922                 :          0 :         rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr);
     923         [ #  # ]:          0 :         if (rc)
     924                 :          0 :                 goto err_out;
     925                 :            : 
     926         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY)
     927         [ #  # ]:          0 :                 tx_cosq_id = bp->tx_cosq_id[queue_index < bp->max_lltc ? queue_index : 0];
     928                 :            :         else
     929                 :          0 :                 tx_cosq_id = bp->tx_cosq_id[0];
     930                 :            : 
     931                 :            :         /* TX ring inherits DPI from parent NQ */
     932         [ #  # ]:          0 :         txr->dpi = bp->rxtx_nq_ring ? bp->rxtx_nq_ring->dpi : BNXT_PRIVILEGED_DPI;
     933                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring,
     934                 :            :                                   HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
     935                 :            :                                   queue_index, cpr->hw_stats_ctx_id,
     936                 :          0 :                                   cp_ring->fw_ring_id,
     937                 :            :                                   tx_cosq_id, txr->dpi);
     938         [ #  # ]:          0 :         if (rc)
     939                 :          0 :                 goto err_out;
     940                 :            : 
     941                 :          0 :         bnxt_set_db(bp, &txr->tx_db, HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
     942                 :          0 :                     queue_index, ring->fw_ring_id,
     943                 :          0 :                     ring->ring_mask, txr->dpi);
     944                 :          0 :         txq->index = idx;
     945                 :            : 
     946                 :          0 :         return rc;
     947                 :          0 : err_out:
     948                 :          0 :         bnxt_free_hwrm_tx_ring(bp, queue_index);
     949                 :          0 :         return rc;
     950                 :            : }

Generated by: LCOV version 1.14