LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_ring.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 482 0.0 %
Date: 2026-07-01 18:02:41 Functions: 0 18 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 237 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                 :          0 :                     dpi != BNXT_PRIVILEGED_DPI &&
     389         [ #  # ]:          0 :                     dpi >= bp->nq_dpi_start) {
     390                 :          0 :                         dpi_offset = (uint64_t)(dpi - bp->nq_dpi_start) *
     391                 :          0 :                                                         bp->db_page_size;
     392                 :          0 :                         db->doorbell = (char *)db->doorbell + dpi_offset;
     393                 :            :                 }
     394                 :          0 :                 db->db_key64 |= (uint64_t)fid << DBR_XID_SFT;
     395                 :          0 :                 db->db_64 = true;
     396                 :            :         } else {
     397                 :          0 :                 db->doorbell = (char *)bp->doorbell_base + map_idx * 0x80;
     398   [ #  #  #  # ]:          0 :                 switch (ring_type) {
     399                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
     400                 :          0 :                         db->db_key32 = DB_KEY_TX;
     401                 :          0 :                         break;
     402                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
     403                 :          0 :                         db->db_key32 = DB_KEY_RX;
     404                 :          0 :                         break;
     405                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
     406                 :          0 :                         db->db_key32 = DB_KEY_CP;
     407                 :          0 :                         break;
     408                 :            :                 }
     409                 :          0 :                 db->db_64 = false;
     410                 :            :         }
     411                 :          0 :         db->db_ring_mask = ring_mask;
     412                 :          0 : }
     413                 :            : 
     414                 :          0 : int bnxt_alloc_cmpl_ring(struct bnxt *bp, int queue_index,
     415                 :            :                          struct bnxt_cp_ring_info *cpr)
     416                 :            : {
     417                 :          0 :         int cp_ring_index = queue_index + BNXT_RX_VEC_START;
     418                 :          0 :         struct bnxt_cp_ring_info *nqr = bp->rxtx_nq_ring;
     419                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     420                 :            :         uint32_t nq_ring_id = HWRM_NA_SIGNATURE;
     421                 :            :         uint8_t dpi = BNXT_PRIVILEGED_DPI;
     422                 :            :         uint8_t ring_type;
     423                 :            :         int rc = 0;
     424                 :            : 
     425                 :            :         ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
     426                 :            : 
     427         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp)) {
     428         [ #  # ]:          0 :                 if (!nqr) {
     429                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "NQ ring is NULL");
     430                 :          0 :                         return -EINVAL;
     431                 :            :                 }
     432                 :          0 :                 nq_ring_id = nqr->cp_ring_struct->fw_ring_id;
     433                 :            :         }
     434                 :            : 
     435                 :          0 :         cpr->dpi = dpi;
     436                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, cp_ring_index,
     437                 :            :                                   HWRM_NA_SIGNATURE, nq_ring_id, 0, dpi);
     438         [ #  # ]:          0 :         if (rc)
     439                 :            :                 return rc;
     440                 :            : 
     441                 :          0 :         cpr->cp_raw_cons = 0;
     442                 :          0 :         bnxt_set_db(bp, &cpr->cp_db, ring_type, cp_ring_index,
     443                 :          0 :                     cp_ring->fw_ring_id, cp_ring->ring_mask, dpi);
     444                 :          0 :         bnxt_db_cq(cpr);
     445                 :            : 
     446                 :          0 :         return 0;
     447                 :            : }
     448                 :            : 
     449                 :          0 : int bnxt_alloc_rxtx_nq_ring(struct bnxt *bp)
     450                 :            : {
     451                 :            :         int ring_index = BNXT_NUM_ASYNC_CPR(bp);
     452                 :            :         uint8_t dpi = BNXT_PRIVILEGED_DPI;
     453                 :            :         struct bnxt_cp_ring_info *nqr;
     454                 :            :         struct bnxt_ring *ring;
     455                 :            :         uint8_t ring_type;
     456                 :            :         uint8_t offset;
     457                 :            :         int rc = 0;
     458                 :            : 
     459   [ #  #  #  # ]:          0 :         if (!BNXT_HAS_NQ(bp) || bp->rxtx_nq_ring)
     460                 :            :                 return 0;
     461                 :            : 
     462                 :          0 :         nqr = rte_zmalloc_socket("nqr",
     463                 :            :                                  sizeof(struct bnxt_cp_ring_info),
     464                 :            :                                  RTE_CACHE_LINE_SIZE,
     465                 :          0 :                                  bp->eth_dev->device->numa_node);
     466         [ #  # ]:          0 :         if (nqr == NULL)
     467                 :            :                 return -ENOMEM;
     468                 :            : 
     469                 :          0 :         ring = rte_zmalloc_socket("bnxt_cp_ring_struct",
     470                 :            :                                   sizeof(struct bnxt_ring),
     471                 :            :                                   RTE_CACHE_LINE_SIZE,
     472                 :          0 :                                   bp->eth_dev->device->numa_node);
     473         [ #  # ]:          0 :         if (ring == NULL) {
     474                 :          0 :                 rte_free(nqr);
     475                 :          0 :                 return -ENOMEM;
     476                 :            :         }
     477                 :            : 
     478                 :          0 :         ring->bd = (void *)nqr->cp_desc_ring;
     479                 :          0 :         ring->bd_dma = nqr->cp_desc_mapping;
     480                 :          0 :         ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE);
     481                 :          0 :         ring->ring_mask = ring->ring_size - 1;
     482                 :          0 :         ring->vmem_size = 0;
     483                 :          0 :         ring->vmem = NULL;
     484                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
     485                 :            : 
     486                 :          0 :         nqr->cp_ring_struct = ring;
     487                 :          0 :         rc = bnxt_alloc_rings(bp, bp->eth_dev->device->numa_node, 0, NULL,
     488                 :            :                               NULL, nqr, NULL, "l2_nqr");
     489         [ #  # ]:          0 :         if (rc) {
     490                 :          0 :                 rte_free(ring);
     491                 :          0 :                 rte_free(nqr);
     492                 :          0 :                 return -ENOMEM;
     493                 :            :         }
     494                 :            : 
     495                 :            :         ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ;
     496                 :            : 
     497                 :            :         /* Assign DPI using round-robin if multi-doorbell is enabled */
     498   [ #  #  #  # ]:          0 :         if (bp->fw_cap & BNXT_FW_CAP_MULTI_DB && bp->nq_dpi_count > 0) {
     499                 :          0 :                 offset = bp->nq_dpi_counter % bp->nq_dpi_count;
     500                 :          0 :                 dpi = bp->nq_dpi_start + offset;
     501                 :          0 :                 bp->nq_dpi_counter++;
     502                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG, "NQ ring assigned DPI %u", dpi);
     503                 :            :         }
     504                 :            : 
     505                 :          0 :         nqr->dpi = dpi;
     506                 :            : 
     507                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, ring_index,
     508                 :            :                                   HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE, 0, dpi);
     509         [ #  # ]:          0 :         if (rc) {
     510                 :          0 :                 rte_free(ring);
     511                 :          0 :                 rte_free(nqr);
     512                 :          0 :                 return rc;
     513                 :            :         }
     514                 :            : 
     515                 :          0 :         bnxt_set_db(bp, &nqr->cp_db, ring_type, ring_index,
     516                 :          0 :                     ring->fw_ring_id, ring->ring_mask, dpi);
     517                 :            :         bnxt_db_nq(nqr);
     518                 :            : 
     519                 :          0 :         bp->rxtx_nq_ring = nqr;
     520                 :            : 
     521                 :          0 :         return 0;
     522                 :            : }
     523                 :            : 
     524                 :            : /* Free RX/TX NQ ring.  */
     525                 :          0 : void bnxt_free_rxtx_nq_ring(struct bnxt *bp)
     526                 :            : {
     527                 :          0 :         struct bnxt_cp_ring_info *nqr = bp->rxtx_nq_ring;
     528                 :            : 
     529         [ #  # ]:          0 :         if (!nqr)
     530                 :            :                 return;
     531                 :            : 
     532                 :          0 :         bnxt_free_nq_ring(bp, nqr);
     533                 :            : 
     534                 :          0 :         bnxt_free_ring(nqr->cp_ring_struct);
     535                 :          0 :         rte_free(nqr->cp_ring_struct);
     536                 :          0 :         nqr->cp_ring_struct = NULL;
     537                 :          0 :         rte_free(nqr);
     538                 :          0 :         bp->rxtx_nq_ring = NULL;
     539                 :            : }
     540                 :            : 
     541                 :          0 : static int bnxt_alloc_rx_ring(struct bnxt *bp, int queue_index)
     542                 :            : {
     543                 :          0 :         struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
     544                 :          0 :         struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
     545                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     546                 :          0 :         struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
     547                 :          0 :         struct bnxt_ring *ring = rxr->rx_ring_struct;
     548                 :            :         uint8_t ring_type;
     549                 :            :         uint16_t dpi;
     550                 :            :         int rc = 0;
     551                 :            : 
     552                 :            :         ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
     553                 :            :         dpi = BNXT_PRIVILEGED_DPI;
     554                 :          0 :         rxr->dpi = dpi;
     555                 :            : 
     556                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type,
     557                 :            :                                   queue_index, cpr->hw_stats_ctx_id,
     558                 :          0 :                                   cp_ring->fw_ring_id, 0, dpi);
     559         [ #  # ]:          0 :         if (rc)
     560                 :            :                 return rc;
     561                 :            : 
     562                 :          0 :         rxr->rx_raw_prod = 0;
     563         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
     564                 :          0 :                 bp->grp_info[queue_index].rx_fw_ring_id = ring->fw_ring_id;
     565                 :          0 :         bnxt_set_db(bp, &rxr->rx_db, ring_type, queue_index, ring->fw_ring_id,
     566                 :            :                     ring->ring_mask, dpi);
     567         [ #  # ]:          0 :         bnxt_db_write(&rxr->rx_db, rxr->rx_raw_prod);
     568                 :            : 
     569                 :            :         return 0;
     570                 :            : }
     571                 :            : 
     572                 :          0 : static int bnxt_alloc_rx_agg_ring(struct bnxt *bp, int queue_index)
     573                 :            : {
     574                 :          0 :         unsigned int map_idx = queue_index + bp->rx_cp_nr_rings;
     575                 :          0 :         struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
     576                 :          0 :         struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
     577                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     578                 :          0 :         struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
     579                 :          0 :         struct bnxt_ring *ring = rxr->ag_ring_struct;
     580                 :            :         uint32_t hw_stats_ctx_id = HWRM_NA_SIGNATURE;
     581                 :            :         uint8_t ring_type;
     582                 :            :         int rc = 0;
     583                 :            : 
     584         [ #  # ]:          0 :         if (!bnxt_need_agg_ring(bp->eth_dev))
     585                 :            :                 return 0;
     586                 :            : 
     587                 :          0 :         ring->fw_rx_ring_id = rxr->rx_ring_struct->fw_ring_id;
     588                 :            : 
     589         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp)) {
     590                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG;
     591                 :          0 :                 hw_stats_ctx_id = cpr->hw_stats_ctx_id;
     592                 :            :         } else {
     593                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX;
     594                 :            :         }
     595                 :            : 
     596                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx,
     597                 :          0 :                                   hw_stats_ctx_id, cp_ring->fw_ring_id, 0,
     598                 :            :                                   BNXT_PRIVILEGED_DPI);
     599                 :            : 
     600         [ #  # ]:          0 :         if (rc)
     601                 :            :                 return rc;
     602                 :            : 
     603                 :          0 :         rxr->ag_raw_prod = 0;
     604                 :          0 :         rxr->ag_cons = 0;
     605         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
     606                 :          0 :                 bp->grp_info[queue_index].ag_fw_ring_id = ring->fw_ring_id;
     607                 :          0 :         bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx, ring->fw_ring_id,
     608                 :            :                     ring->ring_mask, BNXT_PRIVILEGED_DPI);
     609         [ #  # ]:          0 :         bnxt_db_write(&rxr->ag_db, rxr->ag_raw_prod);
     610                 :            : 
     611                 :            :         return 0;
     612                 :            : }
     613                 :            : 
     614                 :          0 : int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index)
     615                 :            : {
     616                 :          0 :         struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
     617                 :          0 :         struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
     618                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     619         [ #  # ]:          0 :         struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
     620                 :            :         struct bnxt_coal coal;
     621                 :            :         int rc;
     622                 :            : 
     623                 :            :         /*
     624                 :            :          * Storage for the cp ring is allocated based on worst-case
     625                 :            :          * usage, the actual size to be used by hw is computed here.
     626                 :            :          */
     627                 :            :         if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
     628         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev))
     629                 :            :                         /* Worst case scenario, needed to accommodate Rx flush
     630                 :            :                          * completion during RING_FREE.
     631                 :            :                          */
     632                 :          0 :                         cp_ring->ring_size = rxr->rx_ring_struct->ring_size * 2;
     633                 :            :                 else
     634                 :          0 :                         cp_ring->ring_size = rxr->rx_ring_struct->ring_size;
     635                 :            :         } else {
     636                 :          0 :                 cp_ring->ring_size = rxr->rx_ring_struct->ring_size * 2;
     637                 :            :         }
     638                 :            : 
     639         [ #  # ]:          0 :         if (bnxt_need_agg_ring(bp->eth_dev))
     640                 :          0 :                 cp_ring->ring_size *= AGG_RING_SIZE_FACTOR;
     641                 :            : 
     642                 :          0 :         cp_ring->ring_mask = cp_ring->ring_size - 1;
     643                 :            : 
     644                 :          0 :         rc = bnxt_alloc_cmpl_ring(bp, queue_index, cpr);
     645         [ #  # ]:          0 :         if (rc)
     646                 :          0 :                 goto err_out;
     647                 :            : 
     648                 :          0 :         rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr);
     649         [ #  # ]:          0 :         if (rc)
     650                 :          0 :                 goto err_out;
     651                 :            : 
     652         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp)) {
     653                 :          0 :                 bp->grp_info[queue_index].fw_stats_ctx = cpr->hw_stats_ctx_id;
     654                 :          0 :                 bp->grp_info[queue_index].cp_fw_ring_id = cp_ring->fw_ring_id;
     655                 :            :         }
     656                 :            : 
     657                 :          0 :         bnxt_init_dflt_coal(&coal);
     658                 :          0 :         bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id);
     659                 :            : 
     660                 :            :         if (!BNXT_NUM_ASYNC_CPR(bp) && !queue_index) {
     661                 :            :                 /*
     662                 :            :                  * If a dedicated async event completion ring is not enabled,
     663                 :            :                  * use the first completion ring from PF or VF as the default
     664                 :            :                  * completion ring for async event handling.
     665                 :            :                  */
     666                 :            :                 bp->async_cp_ring = cpr;
     667                 :            :                 rc = bnxt_hwrm_set_async_event_cr(bp);
     668                 :            :                 if (rc)
     669                 :            :                         goto err_out;
     670                 :            :         }
     671                 :            : 
     672                 :          0 :         rc = bnxt_alloc_rx_ring(bp, queue_index);
     673         [ #  # ]:          0 :         if (rc)
     674                 :          0 :                 goto err_out;
     675                 :            : 
     676                 :          0 :         rc = bnxt_alloc_rx_agg_ring(bp, queue_index);
     677         [ #  # ]:          0 :         if (rc)
     678                 :          0 :                 goto err_out;
     679                 :            : 
     680         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp)) {
     681                 :          0 :                 rc = bnxt_hwrm_ring_grp_alloc(bp, queue_index);
     682         [ #  # ]:          0 :                 if (rc)
     683                 :          0 :                         goto err_out;
     684                 :            :         }
     685                 :            : 
     686         [ #  # ]:          0 :         if (rxq->rx_started) {
     687         [ #  # ]:          0 :                 if (bnxt_init_one_rx_ring(rxq)) {
     688                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
     689                 :            :                                     "ring%d bnxt_init_one_rx_ring failed!",
     690                 :            :                                     queue_index);
     691                 :            :                         rc = -ENOMEM;
     692                 :          0 :                         goto err_out;
     693                 :            :                 }
     694         [ #  # ]:          0 :                 bnxt_db_write(&rxr->rx_db, rxr->rx_raw_prod);
     695         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev))
     696         [ #  # ]:          0 :                         bnxt_db_write(&rxr->ag_db, rxr->ag_raw_prod);
     697                 :            :         }
     698                 :          0 :         rxq->index = queue_index;
     699                 :            : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
     700                 :          0 :         bnxt_rxq_vec_setup(rxq);
     701                 :            : #endif
     702                 :            : 
     703                 :          0 :         return 0;
     704                 :            : 
     705                 :          0 : err_out:
     706                 :          0 :         PMD_DRV_LOG_LINE(ERR,
     707                 :            :                     "Failed to allocate receive queue %d, rc %d.",
     708                 :            :                     queue_index, rc);
     709                 :          0 :         return rc;
     710                 :            : }
     711                 :            : 
     712                 :            : /* Initialise all rings to -1, its used to free rings later if allocation
     713                 :            :  * of few rings fails.
     714                 :            :  */
     715                 :          0 : static void bnxt_init_all_rings(struct bnxt *bp)
     716                 :            : {
     717                 :            :         unsigned int i = 0;
     718                 :            :         struct bnxt_rx_queue *rxq;
     719                 :            :         struct bnxt_ring *cp_ring;
     720                 :            :         struct bnxt_ring *ring;
     721                 :            :         struct bnxt_rx_ring_info *rxr;
     722                 :            :         struct bnxt_tx_queue *txq;
     723                 :            : 
     724         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
     725                 :          0 :                 rxq = bp->rx_queues[i];
     726                 :            : 
     727         [ #  # ]:          0 :                 if (rxq == NULL)
     728                 :          0 :                         continue;
     729                 :            :                 /* Rx-compl */
     730                 :          0 :                 cp_ring = rxq->cp_ring->cp_ring_struct;
     731                 :          0 :                 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
     732                 :            :                 /* Rx-Reg */
     733                 :          0 :                 rxr = rxq->rx_ring;
     734                 :          0 :                 ring = rxr->rx_ring_struct;
     735                 :          0 :                 ring->fw_ring_id = INVALID_HW_RING_ID;
     736                 :            :                 /* Rx-AGG */
     737         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev)) {
     738                 :          0 :                         ring = rxr->ag_ring_struct;
     739         [ #  # ]:          0 :                         if (ring != NULL)
     740                 :          0 :                                 ring->fw_ring_id = INVALID_HW_RING_ID;
     741                 :            :                 }
     742                 :            :         }
     743         [ #  # ]:          0 :         for (i = 0; i < bp->tx_cp_nr_rings; i++) {
     744                 :          0 :                 txq = bp->tx_queues[i];
     745                 :            :                 /* Tx cmpl */
     746                 :          0 :                 cp_ring = txq->cp_ring->cp_ring_struct;
     747                 :          0 :                 cp_ring->fw_ring_id = INVALID_HW_RING_ID;
     748                 :            :                 /*Tx Ring */
     749                 :          0 :                 ring = txq->tx_ring->tx_ring_struct;
     750                 :          0 :                 ring->fw_ring_id = INVALID_HW_RING_ID;
     751                 :            :         }
     752                 :          0 : }
     753                 :            : 
     754                 :            : /* ring_grp usage:
     755                 :            :  * [0] = default completion ring
     756                 :            :  * [1 -> +rx_cp_nr_rings] = rx_cp, rx rings
     757                 :            :  * [1+rx_cp_nr_rings + 1 -> +tx_cp_nr_rings] = tx_cp, tx rings
     758                 :            :  */
     759                 :          0 : int bnxt_alloc_hwrm_rings(struct bnxt *bp)
     760                 :            : {
     761                 :            :         struct bnxt_coal coal;
     762                 :            :         unsigned int i;
     763                 :            :         int rc = 0;
     764                 :            : 
     765                 :          0 :         bnxt_init_dflt_coal(&coal);
     766                 :          0 :         bnxt_init_all_rings(bp);
     767                 :            : 
     768         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
     769                 :          0 :                 unsigned int soc_id = bp->eth_dev->device->numa_node;
     770                 :          0 :                 struct bnxt_rx_queue *rxq  = bp->rx_queues[i];
     771                 :            :                 struct bnxt_rx_ring_info *rxr;
     772                 :            :                 struct bnxt_ring *ring;
     773                 :            : 
     774                 :            : 
     775         [ #  # ]:          0 :                 if (rxq == NULL)
     776                 :            :                         return -EINVAL;
     777                 :            : 
     778                 :          0 :                 rxr = rxq->rx_ring;
     779                 :            : 
     780         [ #  # ]:          0 :                 if (bnxt_need_agg_ring(bp->eth_dev)) {
     781                 :          0 :                         ring = rxr->ag_ring_struct;
     782         [ #  # ]:          0 :                         if (ring == NULL) {
     783                 :          0 :                                 bnxt_free_rxq_mem(rxq);
     784                 :            : 
     785                 :          0 :                                 rc = bnxt_init_rx_ring_struct(rxq, soc_id);
     786         [ #  # ]:          0 :                                 if (rc)
     787                 :          0 :                                         goto err_out;
     788                 :            : 
     789                 :          0 :                                 rc = bnxt_alloc_rings(bp, soc_id,
     790                 :            :                                                       i, NULL, rxq,
     791                 :            :                                                       rxq->cp_ring, NULL,
     792                 :            :                                                       "rxr");
     793         [ #  # ]:          0 :                                 if (rc)
     794                 :          0 :                                         goto err_out;
     795                 :            :                         }
     796                 :            :                 }
     797                 :            : 
     798                 :          0 :                 rc = bnxt_alloc_hwrm_rx_ring(bp, i);
     799         [ #  # ]:          0 :                 if (rc)
     800                 :          0 :                         goto err_out;
     801                 :          0 :                 bnxt_hwrm_set_ring_coal(bp, &coal,
     802                 :          0 :                                         rxq->cp_ring->cp_ring_struct->fw_ring_id);
     803                 :            :         }
     804                 :            : 
     805                 :            :         /* If something is wrong with Rx ring alloc, skip Tx ring alloc */
     806         [ #  # ]:          0 :         for (i = 0; i < bp->tx_cp_nr_rings; i++) {
     807                 :          0 :                 rc = bnxt_alloc_hwrm_tx_ring(bp, i);
     808         [ #  # ]:          0 :                 if (rc)
     809                 :          0 :                         goto err_out;
     810                 :            :         }
     811                 :            : 
     812                 :          0 : err_out:
     813                 :            :         return rc;
     814                 :            : }
     815                 :            : 
     816                 :            : /* Allocate dedicated async completion ring. */
     817                 :          0 : int bnxt_alloc_async_cp_ring(struct bnxt *bp)
     818                 :            : {
     819                 :          0 :         struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
     820                 :            :         struct bnxt_ring *cp_ring;
     821                 :            :         uint8_t ring_type;
     822                 :            :         int rc;
     823                 :            : 
     824         [ #  # ]:          0 :         if (BNXT_NUM_ASYNC_CPR(bp) == 0 || cpr == NULL)
     825                 :            :                 return 0;
     826                 :            : 
     827                 :          0 :         cp_ring = cpr->cp_ring_struct;
     828                 :            : 
     829         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp))
     830                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ;
     831                 :            :         else
     832                 :            :                 ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL;
     833                 :            : 
     834                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, 0,
     835                 :            :                                   HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE, 0,
     836                 :            :                                   BNXT_PRIVILEGED_DPI);
     837                 :            : 
     838         [ #  # ]:          0 :         if (rc)
     839                 :            :                 return rc;
     840                 :            : 
     841                 :          0 :         cpr->cp_raw_cons = 0;
     842                 :          0 :         cpr->dpi = BNXT_PRIVILEGED_DPI;
     843                 :          0 :         bnxt_set_db(bp, &cpr->cp_db, ring_type, 0,
     844                 :          0 :                     cp_ring->fw_ring_id, cp_ring->ring_mask, BNXT_PRIVILEGED_DPI);
     845                 :            : 
     846         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp))
     847                 :            :                 bnxt_db_nq(cpr);
     848                 :            :         else
     849                 :          0 :                 bnxt_db_cq(cpr);
     850                 :            : 
     851                 :          0 :         return bnxt_hwrm_set_async_event_cr(bp);
     852                 :            : }
     853                 :            : 
     854                 :            : /* Free dedicated async completion ring. */
     855                 :          0 : void bnxt_free_async_cp_ring(struct bnxt *bp)
     856                 :            : {
     857                 :          0 :         struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
     858                 :            : 
     859         [ #  # ]:          0 :         if (BNXT_NUM_ASYNC_CPR(bp) == 0 || cpr == NULL)
     860                 :            :                 return;
     861                 :            : 
     862         [ #  # ]:          0 :         if (BNXT_HAS_NQ(bp))
     863                 :          0 :                 bnxt_free_nq_ring(bp, cpr);
     864                 :            :         else
     865                 :          0 :                 bnxt_free_cp_ring(bp, cpr);
     866                 :            : 
     867                 :          0 :         bnxt_free_ring(cpr->cp_ring_struct);
     868                 :          0 :         rte_free(cpr->cp_ring_struct);
     869                 :          0 :         cpr->cp_ring_struct = NULL;
     870                 :          0 :         rte_free(cpr);
     871                 :          0 :         bp->async_cp_ring = NULL;
     872                 :            : }
     873                 :            : 
     874                 :          0 : int bnxt_alloc_async_ring_struct(struct bnxt *bp)
     875                 :            : {
     876                 :            :         struct bnxt_cp_ring_info *cpr = NULL;
     877                 :            :         struct bnxt_ring *ring = NULL;
     878                 :            : 
     879                 :            :         if (BNXT_NUM_ASYNC_CPR(bp) == 0)
     880                 :            :                 return 0;
     881                 :            : 
     882                 :          0 :         cpr = rte_zmalloc_socket("cpr",
     883                 :            :                                  sizeof(struct bnxt_cp_ring_info),
     884                 :            :                                  RTE_CACHE_LINE_SIZE,
     885                 :          0 :                                  bp->eth_dev->device->numa_node);
     886         [ #  # ]:          0 :         if (cpr == NULL)
     887                 :            :                 return -ENOMEM;
     888                 :            : 
     889                 :          0 :         ring = rte_zmalloc_socket("bnxt_cp_ring_struct",
     890                 :            :                                   sizeof(struct bnxt_ring),
     891                 :            :                                   RTE_CACHE_LINE_SIZE,
     892                 :          0 :                                   bp->eth_dev->device->numa_node);
     893         [ #  # ]:          0 :         if (ring == NULL) {
     894                 :          0 :                 rte_free(cpr);
     895                 :          0 :                 return -ENOMEM;
     896                 :            :         }
     897                 :            : 
     898                 :          0 :         ring->bd = (void *)cpr->cp_desc_ring;
     899                 :          0 :         ring->bd_dma = cpr->cp_desc_mapping;
     900                 :          0 :         ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE);
     901                 :          0 :         ring->ring_mask = ring->ring_size - 1;
     902                 :          0 :         ring->vmem_size = 0;
     903                 :          0 :         ring->vmem = NULL;
     904                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
     905                 :            : 
     906                 :          0 :         bp->async_cp_ring = cpr;
     907                 :          0 :         cpr->cp_ring_struct = ring;
     908                 :            : 
     909                 :          0 :         return bnxt_alloc_rings(bp, bp->eth_dev->device->numa_node, 0, NULL,
     910                 :            :                                 NULL, bp->async_cp_ring, NULL, "def_cp");
     911                 :            : }
     912                 :            : 
     913                 :          0 : int bnxt_alloc_hwrm_tx_ring(struct bnxt *bp, int queue_index)
     914                 :            : {
     915                 :          0 :         struct bnxt_tx_queue *txq = bp->tx_queues[queue_index];
     916                 :          0 :         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
     917                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
     918                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     919                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     920                 :          0 :         unsigned int idx = queue_index + bp->rx_cp_nr_rings;
     921                 :            :         uint16_t tx_cosq_id = 0;
     922                 :            :         struct bnxt_coal coal;
     923                 :            :         int rc = 0;
     924                 :            : 
     925                 :          0 :         rc = bnxt_alloc_cmpl_ring(bp, idx, cpr);
     926         [ #  # ]:          0 :         if (rc)
     927                 :          0 :                 goto err_out;
     928                 :            : 
     929                 :          0 :         bnxt_init_dflt_coal(&coal);
     930                 :          0 :         bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id);
     931                 :            : 
     932                 :          0 :         rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr);
     933         [ #  # ]:          0 :         if (rc)
     934                 :          0 :                 goto err_out;
     935                 :            : 
     936         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY)
     937         [ #  # ]:          0 :                 tx_cosq_id = bp->tx_cosq_id[queue_index < bp->max_lltc ? queue_index : 0];
     938                 :            :         else
     939                 :          0 :                 tx_cosq_id = bp->tx_cosq_id[0];
     940                 :            : 
     941                 :            :         /* TX ring inherits DPI from parent NQ */
     942         [ #  # ]:          0 :         txr->dpi = bp->rxtx_nq_ring ? bp->rxtx_nq_ring->dpi : BNXT_PRIVILEGED_DPI;
     943                 :          0 :         rc = bnxt_hwrm_ring_alloc(bp, ring,
     944                 :            :                                   HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
     945                 :            :                                   queue_index, cpr->hw_stats_ctx_id,
     946                 :          0 :                                   cp_ring->fw_ring_id,
     947                 :            :                                   tx_cosq_id, txr->dpi);
     948         [ #  # ]:          0 :         if (rc)
     949                 :          0 :                 goto err_out;
     950                 :            : 
     951                 :          0 :         bnxt_set_db(bp, &txr->tx_db, HWRM_RING_ALLOC_INPUT_RING_TYPE_TX,
     952                 :          0 :                     queue_index, ring->fw_ring_id,
     953                 :          0 :                     ring->ring_mask, txr->dpi);
     954                 :          0 :         txq->index = idx;
     955                 :            : 
     956                 :          0 :         return rc;
     957                 :          0 : err_out:
     958                 :          0 :         bnxt_free_hwrm_tx_ring(bp, queue_index);
     959                 :          0 :         return rc;
     960                 :            : }

Generated by: LCOV version 1.14