LCOV - code coverage report
Current view: top level - drivers/net/gve - gve_rx_dqo.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 266 0.0 %
Date: 2026-06-01 18:36:17 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 100 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2022-2023 Google LLC
       3                 :            :  * Copyright (c) 2022-2023 Intel Corporation
       4                 :            :  */
       5                 :            : 
       6                 :            : 
       7                 :            : #include "gve_ethdev.h"
       8                 :            : #include "base/gve_adminq.h"
       9                 :            : #include "rte_mbuf_ptype.h"
      10                 :            : #include "rte_atomic.h"
      11                 :            : 
      12                 :            : static inline void
      13                 :            : gve_completed_buf_list_init(struct gve_rx_queue *rxq)
      14                 :            : {
      15         [ #  # ]:          0 :         for (int i = 0; i < rxq->nb_rx_desc; i++)
      16                 :          0 :                 rxq->completed_buf_list[i] = -1;
      17                 :            : 
      18                 :          0 :         rxq->completed_buf_list_head = -1;
      19                 :            : }
      20                 :            : 
      21                 :            : /* Assumes buf_id < nb_rx_desc */
      22                 :            : static inline void
      23                 :            : gve_completed_buf_list_push(struct gve_rx_queue *rxq, uint16_t buf_id)
      24                 :            : {
      25                 :          0 :         rxq->completed_buf_list[buf_id] = rxq->completed_buf_list_head;
      26                 :          0 :         rxq->completed_buf_list_head = buf_id;
      27                 :            : }
      28                 :            : 
      29                 :            : static inline int16_t
      30                 :            : gve_completed_buf_list_pop(struct gve_rx_queue *rxq)
      31                 :            : {
      32                 :          0 :         int16_t head = rxq->completed_buf_list_head;
      33                 :          0 :         if (head != -1)
      34                 :          0 :                 rxq->completed_buf_list_head = rxq->completed_buf_list[head];
      35                 :            : 
      36                 :            :         return head;
      37                 :            : }
      38                 :            : 
      39                 :            : static inline void
      40                 :          0 : gve_rx_refill_dqo(struct gve_rx_queue *rxq)
      41                 :            : {
      42                 :            :         volatile struct gve_rx_desc_dqo *rx_buf_desc;
      43                 :          0 :         uint16_t rx_mask = rxq->nb_rx_desc - 1;
      44                 :          0 :         uint16_t next_avail = rxq->bufq_tail;
      45                 :            :         struct rte_eth_dev *dev;
      46                 :            :         uint16_t nb_refill;
      47                 :            :         uint64_t dma_addr;
      48                 :            :         rte_iova_t iova;
      49                 :            :         int16_t buf_id;
      50                 :            :         int diag;
      51                 :            :         int i;
      52                 :            : 
      53                 :          0 :         nb_refill = rxq->nb_rx_hold;
      54         [ #  # ]:          0 :         if (nb_refill < rxq->free_thresh)
      55                 :            :                 return;
      56                 :            : 
      57                 :          0 :         diag = rte_pktmbuf_alloc_bulk(rxq->mpool, rxq->refill_bufs, nb_refill);
      58         [ #  # ]:          0 :         if (unlikely(diag < 0)) {
      59                 :          0 :                 rxq->stats.no_mbufs_bulk++;
      60                 :          0 :                 rxq->stats.no_mbufs += nb_refill;
      61                 :          0 :                 dev = &rte_eth_devices[rxq->port_id];
      62                 :          0 :                 dev->data->rx_mbuf_alloc_failed += nb_refill;
      63                 :            :                 PMD_DRV_DP_LOG(DEBUG,
      64                 :            :                                "RX mbuf alloc failed port_id=%u queue_id=%u",
      65                 :            :                                rxq->port_id, rxq->queue_id);
      66                 :          0 :                 return;
      67                 :            :         }
      68                 :            : 
      69                 :            :         /* Mbuf allocation succeeded, so refill buffers. */
      70         [ #  # ]:          0 :         for (i = 0; i < nb_refill; i++) {
      71         [ #  # ]:          0 :                 rx_buf_desc = &rxq->rx_ring[next_avail];
      72                 :            :                 buf_id = gve_completed_buf_list_pop(rxq);
      73                 :            : 
      74                 :            :                 /* Out of buffers. Free remaining mbufs and return. */
      75         [ #  # ]:          0 :                 if (unlikely(buf_id == -1)) {
      76                 :          0 :                         PMD_DRV_DP_LOG(ERR,
      77                 :            :                                        "No free entries in sw_ring for port %d, queue %d.",
      78                 :            :                                        rxq->port_id, rxq->queue_id);
      79                 :          0 :                         rte_pktmbuf_free_bulk(rxq->refill_bufs + i,
      80                 :          0 :                                               nb_refill - i);
      81                 :          0 :                         nb_refill = i;
      82                 :          0 :                         break;
      83                 :            :                 }
      84                 :          0 :                 rxq->sw_ring[buf_id] = rxq->refill_bufs[i];
      85                 :          0 :                 iova = rte_mbuf_data_iova_default(rxq->refill_bufs[i]);
      86                 :            :                 dma_addr = rte_cpu_to_le_64(iova);
      87                 :          0 :                 rx_buf_desc->buf_id = buf_id;
      88                 :          0 :                 rx_buf_desc->header_buf_addr = 0;
      89                 :          0 :                 rx_buf_desc->buf_addr = dma_addr;
      90                 :            : 
      91                 :          0 :                 next_avail = (next_avail + 1) & rx_mask;
      92                 :            :         }
      93                 :            : 
      94                 :          0 :         rxq->nb_rx_hold -= nb_refill;
      95                 :          0 :         rte_write32(next_avail, rxq->qrx_tail);
      96                 :          0 :         rxq->bufq_tail = next_avail;
      97                 :            : }
      98                 :            : 
      99                 :            : static inline void
     100                 :          0 : gve_parse_csum_ol_flags(struct rte_mbuf *rx_mbuf,
     101                 :            :         volatile struct gve_rx_compl_desc_dqo *rx_desc)
     102                 :            : {
     103         [ #  # ]:          0 :         if (!rx_desc->l3_l4_processed)
     104                 :            :                 return;
     105                 :            : 
     106         [ #  # ]:          0 :         if (rx_mbuf->packet_type & RTE_PTYPE_L3_IPV4) {
     107         [ #  # ]:          0 :                 if (rx_desc->csum_ip_err)
     108                 :          0 :                         rx_mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
     109                 :            :                 else
     110                 :          0 :                         rx_mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
     111                 :            :         }
     112                 :            : 
     113         [ #  # ]:          0 :         if (rx_desc->csum_l4_err) {
     114                 :          0 :                 rx_mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
     115                 :          0 :                 return;
     116                 :            :         }
     117         [ #  # ]:          0 :         if (rx_mbuf->packet_type & RTE_PTYPE_L4_MASK)
     118                 :          0 :                 rx_mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
     119                 :            : }
     120                 :            : 
     121                 :            : static inline void
     122                 :          0 : gve_rx_set_mbuf_ptype(struct gve_priv *priv, struct rte_mbuf *rx_mbuf,
     123                 :            :                       volatile struct gve_rx_compl_desc_dqo *rx_desc)
     124                 :            : {
     125                 :          0 :         struct gve_ptype ptype =
     126                 :          0 :                 priv->ptype_lut_dqo->ptypes[rx_desc->packet_type];
     127                 :          0 :         rx_mbuf->packet_type = 0;
     128                 :            : 
     129      [ #  #  # ]:          0 :         switch (ptype.l3_type) {
     130                 :          0 :         case GVE_L3_TYPE_IPV4:
     131                 :          0 :                 rx_mbuf->packet_type |= RTE_PTYPE_L3_IPV4;
     132                 :          0 :                 break;
     133                 :          0 :         case GVE_L3_TYPE_IPV6:
     134                 :          0 :                 rx_mbuf->packet_type |= RTE_PTYPE_L3_IPV6;
     135                 :          0 :                 break;
     136                 :            :         default:
     137                 :            :                 break;
     138                 :            :         }
     139                 :            : 
     140   [ #  #  #  #  :          0 :         switch (ptype.l4_type) {
                      # ]
     141                 :          0 :         case GVE_L4_TYPE_TCP:
     142                 :          0 :                 rx_mbuf->packet_type |= RTE_PTYPE_L4_TCP;
     143                 :          0 :                 break;
     144                 :          0 :         case GVE_L4_TYPE_UDP:
     145                 :          0 :                 rx_mbuf->packet_type |= RTE_PTYPE_L4_UDP;
     146                 :          0 :                 break;
     147                 :          0 :         case GVE_L4_TYPE_ICMP:
     148                 :          0 :                 rx_mbuf->packet_type |= RTE_PTYPE_L4_ICMP;
     149                 :          0 :                 break;
     150                 :          0 :         case GVE_L4_TYPE_SCTP:
     151                 :          0 :                 rx_mbuf->packet_type |= RTE_PTYPE_L4_SCTP;
     152                 :          0 :                 break;
     153                 :            :         default:
     154                 :            :                 break;
     155                 :            :         }
     156                 :          0 : }
     157                 :            : 
     158                 :            : uint16_t
     159                 :          0 : gve_rx_burst_dqo(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
     160                 :            : {
     161                 :            :         volatile struct gve_rx_compl_desc_dqo *rx_desc;
     162                 :            :         struct gve_rx_queue *rxq;
     163                 :            :         struct rte_mbuf *rxm;
     164                 :            :         uint16_t rx_buf_id;
     165                 :            :         uint16_t pkt_len;
     166                 :            :         uint16_t rx_id;
     167                 :            :         uint16_t nb_rx;
     168                 :            :         uint64_t bytes;
     169                 :            : 
     170                 :            :         bytes = 0;
     171                 :            :         nb_rx = 0;
     172                 :            :         rxq = rx_queue;
     173                 :          0 :         rx_id = rxq->rx_tail;
     174                 :            : 
     175         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
     176                 :          0 :                 rx_desc = &rxq->compl_ring[rx_id];
     177                 :            : 
     178                 :            :                 /* check status */
     179         [ #  # ]:          0 :                 if (rx_desc->generation != rxq->cur_gen_bit)
     180                 :            :                         break;
     181                 :            : 
     182                 :          0 :                 rte_io_rmb();
     183                 :            : 
     184                 :          0 :                 rxq->nb_rx_hold++;
     185                 :          0 :                 rx_id++;
     186         [ #  # ]:          0 :                 if (rx_id == rxq->nb_rx_desc) {
     187                 :            :                         rx_id = 0;
     188                 :          0 :                         rxq->cur_gen_bit ^= 1;
     189                 :            :                 }
     190                 :            : 
     191                 :          0 :                 rx_buf_id = rte_le_to_cpu_16(rx_desc->buf_id);
     192                 :          0 :                 rxm = rxq->sw_ring[rx_buf_id];
     193                 :            :                 gve_completed_buf_list_push(rxq, rx_buf_id);
     194                 :            : 
     195                 :            :                 /* Free buffer and report error. */
     196         [ #  # ]:          0 :                 if (unlikely(rx_desc->rx_error)) {
     197                 :          0 :                         rxq->stats.errors++;
     198                 :          0 :                         rte_pktmbuf_free(rxm);
     199                 :          0 :                         continue;
     200                 :            :                 }
     201                 :            : 
     202                 :          0 :                 pkt_len = rte_le_to_cpu_16(rx_desc->packet_len);
     203                 :          0 :                 rxm->pkt_len = pkt_len;
     204                 :          0 :                 rxm->data_len = pkt_len;
     205                 :          0 :                 rxm->port = rxq->port_id;
     206                 :          0 :                 gve_rx_set_mbuf_ptype(rxq->hw, rxm, rx_desc);
     207                 :          0 :                 rxm->ol_flags = RTE_MBUF_F_RX_RSS_HASH;
     208                 :          0 :                 gve_parse_csum_ol_flags(rxm, rx_desc);
     209                 :          0 :                 rxm->hash.rss = rte_le_to_cpu_32(rx_desc->hash);
     210                 :            : 
     211                 :          0 :                 rx_pkts[nb_rx++] = rxm;
     212                 :          0 :                 bytes += pkt_len;
     213                 :            :         }
     214                 :            : 
     215         [ #  # ]:          0 :         if (nb_rx > 0) {
     216                 :          0 :                 rxq->rx_tail = rx_id;
     217                 :            : 
     218                 :          0 :                 rxq->stats.packets += nb_rx;
     219                 :          0 :                 rxq->stats.bytes += bytes;
     220                 :            :         }
     221                 :          0 :         gve_rx_refill_dqo(rxq);
     222                 :            : 
     223                 :          0 :         return nb_rx;
     224                 :            : }
     225                 :            : 
     226                 :            : static inline void
     227                 :          0 : gve_release_rxq_mbufs_dqo(struct gve_rx_queue *rxq)
     228                 :            : {
     229                 :            :         uint16_t i;
     230                 :            : 
     231         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
     232         [ #  # ]:          0 :                 if (rxq->sw_ring[i]) {
     233                 :            :                         rte_pktmbuf_free_seg(rxq->sw_ring[i]);
     234                 :          0 :                         rxq->sw_ring[i] = NULL;
     235                 :            :                 }
     236                 :            :         }
     237                 :            : 
     238                 :          0 :         rxq->nb_avail = rxq->nb_rx_desc;
     239                 :          0 : }
     240                 :            : 
     241                 :            : void
     242                 :          0 : gve_rx_queue_release_dqo(struct rte_eth_dev *dev, uint16_t qid)
     243                 :            : {
     244                 :          0 :         struct gve_rx_queue *q = dev->data->rx_queues[qid];
     245                 :            : 
     246         [ #  # ]:          0 :         if (q == NULL)
     247                 :            :                 return;
     248                 :            : 
     249                 :          0 :         gve_release_rxq_mbufs_dqo(q);
     250                 :          0 :         rte_free(q->sw_ring);
     251                 :          0 :         rte_free(q->completed_buf_list);
     252                 :          0 :         rte_free(q->refill_bufs);
     253                 :          0 :         rte_memzone_free(q->compl_ring_mz);
     254                 :          0 :         rte_memzone_free(q->mz);
     255                 :          0 :         rte_memzone_free(q->qres_mz);
     256                 :          0 :         q->qres = NULL;
     257                 :          0 :         rte_free(q);
     258                 :            : 
     259                 :          0 :         dev->data->rx_queues[qid] = NULL;
     260                 :            : }
     261                 :            : 
     262                 :            : static void
     263                 :          0 : gve_reset_rx_ring_state_dqo(struct gve_rx_queue *rxq)
     264                 :            : {
     265                 :            :         struct rte_mbuf **sw_ring;
     266                 :            :         uint32_t size, i;
     267                 :            : 
     268         [ #  # ]:          0 :         if (rxq == NULL) {
     269                 :          0 :                 PMD_DRV_LOG(ERR, "pointer to rxq is NULL");
     270                 :          0 :                 return;
     271                 :            :         }
     272                 :            : 
     273                 :          0 :         size = rxq->nb_rx_desc * sizeof(struct gve_rx_desc_dqo);
     274         [ #  # ]:          0 :         for (i = 0; i < size; i++)
     275                 :          0 :                 ((volatile char *)rxq->rx_ring)[i] = 0;
     276                 :            : 
     277                 :          0 :         size = rxq->nb_rx_desc * sizeof(struct gve_rx_compl_desc_dqo);
     278         [ #  # ]:          0 :         for (i = 0; i < size; i++)
     279                 :          0 :                 ((volatile char *)rxq->compl_ring)[i] = 0;
     280                 :            : 
     281                 :          0 :         sw_ring = rxq->sw_ring;
     282         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++)
     283                 :          0 :                 sw_ring[i] = NULL;
     284                 :            : 
     285                 :            :         gve_completed_buf_list_init(rxq);
     286                 :            : 
     287                 :          0 :         rxq->bufq_tail = 0;
     288                 :          0 :         rxq->nb_rx_hold = rxq->nb_rx_desc - 1;
     289                 :            : 
     290                 :          0 :         rxq->rx_tail = 0;
     291                 :          0 :         rxq->cur_gen_bit = 1;
     292                 :            : }
     293                 :            : 
     294                 :            : int
     295                 :          0 : gve_rx_queue_setup_dqo(struct rte_eth_dev *dev, uint16_t queue_id,
     296                 :            :                        uint16_t nb_desc, unsigned int socket_id,
     297                 :            :                        const struct rte_eth_rxconf *conf,
     298                 :            :                        struct rte_mempool *pool)
     299                 :            : {
     300                 :          0 :         struct gve_priv *hw = dev->data->dev_private;
     301                 :            :         const struct rte_memzone *mz;
     302                 :            :         struct gve_rx_queue *rxq;
     303                 :            :         uint16_t free_thresh;
     304                 :            :         uint32_t mbuf_len;
     305                 :            :         int err = 0;
     306                 :            : 
     307                 :            :         /* Free memory if needed */
     308         [ #  # ]:          0 :         if (dev->data->rx_queues[queue_id]) {
     309                 :          0 :                 gve_rx_queue_release_dqo(dev, queue_id);
     310                 :          0 :                 dev->data->rx_queues[queue_id] = NULL;
     311                 :            :         }
     312                 :            : 
     313                 :            :         /* Allocate the RX queue data structure. */
     314                 :          0 :         rxq = rte_zmalloc_socket("gve rxq",
     315                 :            :                                  sizeof(struct gve_rx_queue),
     316                 :            :                                  RTE_CACHE_LINE_SIZE,
     317                 :            :                                  socket_id);
     318         [ #  # ]:          0 :         if (rxq == NULL) {
     319                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for rx queue structure");
     320                 :          0 :                 return -ENOMEM;
     321                 :            :         }
     322                 :            : 
     323                 :            :         /* check free_thresh here */
     324         [ #  # ]:          0 :         free_thresh = conf->rx_free_thresh ?
     325                 :            :                         conf->rx_free_thresh : GVE_DEFAULT_RX_FREE_THRESH;
     326         [ #  # ]:          0 :         if (free_thresh >= nb_desc) {
     327                 :          0 :                 PMD_DRV_LOG(ERR, "rx_free_thresh (%u) must be less than nb_desc (%u).",
     328                 :            :                             free_thresh, rxq->nb_rx_desc);
     329                 :            :                 err = -EINVAL;
     330                 :          0 :                 goto free_rxq;
     331                 :            :         }
     332                 :            : 
     333                 :          0 :         rxq->nb_rx_desc = nb_desc;
     334                 :          0 :         rxq->free_thresh = free_thresh;
     335                 :          0 :         rxq->queue_id = queue_id;
     336                 :          0 :         rxq->port_id = dev->data->port_id;
     337                 :          0 :         rxq->ntfy_id = hw->num_ntfy_blks / 2 + queue_id;
     338                 :            : 
     339                 :          0 :         rxq->mpool = pool;
     340                 :          0 :         rxq->hw = hw;
     341   [ #  #  #  # ]:          0 :         rxq->ntfy_addr = &hw->db_bar2[rte_be_to_cpu_32(hw->irq_dbs[rxq->ntfy_id].id)];
     342                 :            : 
     343                 :          0 :         mbuf_len =
     344                 :          0 :                 rte_pktmbuf_data_room_size(rxq->mpool) - RTE_PKTMBUF_HEADROOM;
     345                 :          0 :         rxq->rx_buf_len =
     346                 :          0 :                 RTE_MIN((uint16_t)GVE_RX_MAX_BUF_SIZE_DQO,
     347                 :            :                         RTE_ALIGN_FLOOR(mbuf_len, GVE_RX_BUF_ALIGN_DQO));
     348                 :            : 
     349                 :            :         /* Allocate software ring */
     350                 :          0 :         rxq->sw_ring = rte_zmalloc_socket("gve rx sw ring",
     351                 :            :                                           nb_desc * sizeof(struct rte_mbuf *),
     352                 :            :                                           RTE_CACHE_LINE_SIZE, socket_id);
     353         [ #  # ]:          0 :         if (rxq->sw_ring == NULL) {
     354                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW RX ring");
     355                 :            :                 err = -ENOMEM;
     356                 :          0 :                 goto free_rxq;
     357                 :            :         }
     358                 :            : 
     359                 :            :         /* Allocate completed bufs list */
     360                 :          0 :         rxq->completed_buf_list = rte_zmalloc_socket("gve completed buf list",
     361                 :            :                 nb_desc * sizeof(*rxq->completed_buf_list), RTE_CACHE_LINE_SIZE,
     362                 :            :                 socket_id);
     363         [ #  # ]:          0 :         if (rxq->completed_buf_list == NULL) {
     364                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate completed buffer list.");
     365                 :            :                 err = -ENOMEM;
     366                 :          0 :                 goto free_rxq_sw_ring;
     367                 :            :         }
     368                 :            : 
     369                 :            :         /* Allocate buffer for reallocating mbufs */
     370                 :          0 :         rxq->refill_bufs = rte_zmalloc_socket("gve rx refill bufs",
     371                 :            :                 nb_desc * sizeof(*rxq->refill_bufs), RTE_CACHE_LINE_SIZE,
     372                 :            :                 socket_id);
     373         [ #  # ]:          0 :         if (rxq->refill_bufs == NULL) {
     374                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate rx refill bufs.");
     375                 :            :                 err = -ENOMEM;
     376                 :          0 :                 goto free_rxq_completed_buf_list;
     377                 :            :         }
     378                 :            : 
     379                 :            :         /* Allocate RX buffer queue */
     380                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_id,
     381                 :            :                                       nb_desc * sizeof(struct gve_rx_desc_dqo),
     382                 :            :                                       PAGE_SIZE, socket_id);
     383         [ #  # ]:          0 :         if (mz == NULL) {
     384                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX buffer queue");
     385                 :            :                 err = -ENOMEM;
     386                 :          0 :                 goto free_rxq_refill_bufs;
     387                 :            :         }
     388                 :          0 :         rxq->rx_ring = (struct gve_rx_desc_dqo *)mz->addr;
     389                 :          0 :         rxq->rx_ring_phys_addr = mz->iova;
     390                 :          0 :         rxq->mz = mz;
     391                 :            : 
     392                 :            :         /* Allocate RX completion queue */
     393                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "compl_ring", queue_id,
     394                 :            :                                       nb_desc * sizeof(struct gve_rx_compl_desc_dqo),
     395                 :            :                                       PAGE_SIZE, socket_id);
     396         [ #  # ]:          0 :         if (mz == NULL) {
     397                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX completion queue");
     398                 :            :                 err = -ENOMEM;
     399                 :          0 :                 goto free_rxq_mz;
     400                 :            :         }
     401                 :            :         /* Zero all the descriptors in the ring */
     402                 :          0 :         memset(mz->addr, 0, nb_desc * sizeof(struct gve_rx_compl_desc_dqo));
     403                 :          0 :         rxq->compl_ring = (struct gve_rx_compl_desc_dqo *)mz->addr;
     404                 :          0 :         rxq->compl_ring_phys_addr = mz->iova;
     405                 :          0 :         rxq->compl_ring_mz = mz;
     406                 :            : 
     407                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "rxq_res", queue_id,
     408                 :            :                                       sizeof(struct gve_queue_resources),
     409                 :            :                                       PAGE_SIZE, socket_id);
     410         [ #  # ]:          0 :         if (mz == NULL) {
     411                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX resource");
     412                 :            :                 err = -ENOMEM;
     413                 :          0 :                 goto free_rxq_cq_mz;
     414                 :            :         }
     415                 :          0 :         rxq->qres = (struct gve_queue_resources *)mz->addr;
     416                 :          0 :         rxq->qres_mz = mz;
     417                 :            : 
     418                 :          0 :         gve_reset_rx_ring_state_dqo(rxq);
     419                 :            : 
     420                 :          0 :         dev->data->rx_queues[queue_id] = rxq;
     421                 :            : 
     422                 :          0 :         return 0;
     423                 :            : 
     424                 :            : free_rxq_cq_mz:
     425                 :          0 :         rte_memzone_free(rxq->compl_ring_mz);
     426                 :          0 : free_rxq_mz:
     427                 :          0 :         rte_memzone_free(rxq->mz);
     428                 :          0 : free_rxq_refill_bufs:
     429                 :          0 :         rte_free(rxq->refill_bufs);
     430                 :          0 : free_rxq_completed_buf_list:
     431                 :          0 :         rte_free(rxq->completed_buf_list);
     432                 :          0 : free_rxq_sw_ring:
     433                 :          0 :         rte_free(rxq->sw_ring);
     434                 :          0 : free_rxq:
     435                 :          0 :         rte_free(rxq);
     436                 :          0 :         return err;
     437                 :            : }
     438                 :            : 
     439                 :            : static int
     440                 :          0 : gve_rxq_mbufs_alloc_dqo(struct gve_rx_queue *rxq)
     441                 :            : {
     442                 :            :         struct rte_mbuf *nmb;
     443                 :            :         uint16_t rx_mask;
     444                 :            :         uint16_t i;
     445                 :            :         int diag;
     446                 :            : 
     447                 :          0 :         rx_mask = rxq->nb_rx_desc - 1;
     448                 :          0 :         diag = rte_pktmbuf_alloc_bulk(rxq->mpool, &rxq->sw_ring[0],
     449                 :            :                                       rx_mask);
     450         [ #  # ]:          0 :         if (diag < 0) {
     451                 :          0 :                 rxq->stats.no_mbufs_bulk++;
     452         [ #  # ]:          0 :                 for (i = 0; i < rx_mask; i++) {
     453                 :          0 :                         nmb = rte_pktmbuf_alloc(rxq->mpool);
     454         [ #  # ]:          0 :                         if (!nmb) {
     455                 :          0 :                                 rxq->stats.no_mbufs++;
     456                 :          0 :                                 gve_release_rxq_mbufs_dqo(rxq);
     457                 :          0 :                                 return -ENOMEM;
     458                 :            :                         }
     459                 :          0 :                         rxq->sw_ring[i] = nmb;
     460                 :            :                 }
     461                 :            :         }
     462                 :            : 
     463         [ #  # ]:          0 :         for (i = 0; i < rx_mask; i++) {
     464                 :          0 :                 nmb = rxq->sw_ring[i];
     465                 :          0 :                 rxq->rx_ring[i].buf_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
     466                 :          0 :                 rxq->rx_ring[i].buf_id = rte_cpu_to_le_16(i);
     467                 :            :         }
     468                 :          0 :         rxq->rx_ring[rx_mask].buf_id = rte_cpu_to_le_16(rx_mask);
     469                 :            : 
     470                 :          0 :         rxq->nb_rx_hold = 0;
     471                 :          0 :         rxq->bufq_tail = rx_mask;
     472                 :            : 
     473                 :          0 :         rte_write32(rxq->bufq_tail, rxq->qrx_tail);
     474                 :            : 
     475                 :          0 :         return 0;
     476                 :            : }
     477                 :            : 
     478                 :            : int
     479                 :          0 : gve_rx_queue_start_dqo(struct rte_eth_dev *dev, uint16_t rx_queue_id)
     480                 :            : {
     481                 :          0 :         struct gve_priv *hw = dev->data->dev_private;
     482                 :            :         struct gve_rx_queue *rxq;
     483                 :            :         int ret;
     484                 :            : 
     485         [ #  # ]:          0 :         if (rx_queue_id >= dev->data->nb_rx_queues)
     486                 :            :                 return -EINVAL;
     487                 :            : 
     488                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
     489                 :            : 
     490         [ #  # ]:          0 :         rxq->qrx_tail = &hw->db_bar2[rte_be_to_cpu_32(rxq->qres->db_index)];
     491                 :            : 
     492                 :            :         rte_write32(rte_cpu_to_le_32(GVE_NO_INT_MODE_DQO |
     493                 :            :                                      GVE_ITR_NO_UPDATE_DQO),
     494                 :          0 :                     rxq->ntfy_addr);
     495                 :            : 
     496                 :          0 :         ret = gve_rxq_mbufs_alloc_dqo(rxq);
     497         [ #  # ]:          0 :         if (ret != 0) {
     498                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to alloc Rx queue mbuf");
     499                 :          0 :                 return ret;
     500                 :            :         }
     501                 :            : 
     502                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
     503                 :            : 
     504                 :          0 :         return 0;
     505                 :            : }
     506                 :            : 
     507                 :            : int
     508                 :          0 : gve_rx_queue_stop_dqo(struct rte_eth_dev *dev, uint16_t rx_queue_id)
     509                 :            : {
     510                 :            :         struct gve_rx_queue *rxq;
     511                 :            : 
     512         [ #  # ]:          0 :         if (rx_queue_id >= dev->data->nb_rx_queues)
     513                 :            :                 return -EINVAL;
     514                 :            : 
     515                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
     516                 :          0 :         gve_release_rxq_mbufs_dqo(rxq);
     517                 :          0 :         gve_reset_rx_ring_state_dqo(rxq);
     518                 :            : 
     519                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
     520                 :            : 
     521                 :          0 :         return 0;
     522                 :            : }
     523                 :            : 
     524                 :            : void
     525                 :          0 : gve_stop_rx_queues_dqo(struct rte_eth_dev *dev)
     526                 :            : {
     527                 :          0 :         struct gve_priv *hw = dev->data->dev_private;
     528                 :            :         uint16_t i;
     529                 :            :         int err;
     530                 :            : 
     531                 :          0 :         err = gve_adminq_destroy_rx_queues(hw, dev->data->nb_rx_queues);
     532         [ #  # ]:          0 :         if (err != 0)
     533                 :          0 :                 PMD_DRV_LOG(WARNING, "failed to destroy rxqs");
     534                 :            : 
     535         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     536         [ #  # ]:          0 :                 if (gve_rx_queue_stop_dqo(dev, i) != 0)
     537                 :          0 :                         PMD_DRV_LOG(WARNING, "Fail to stop Rx queue %d", i);
     538                 :          0 : }
     539                 :            : 
     540                 :            : void
     541                 :          0 : gve_set_rx_function_dqo(struct rte_eth_dev *dev)
     542                 :            : {
     543                 :          0 :         dev->rx_pkt_burst = gve_rx_burst_dqo;
     544                 :          0 : }

Generated by: LCOV version 1.14