LCOV - code coverage report
Current view: top level - drivers/net/gve - gve_rx.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 295 0.0 %
Date: 2026-12-01 19:01:22 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 166 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2022 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "gve_ethdev.h"
       6                 :            : #include "base/gve_adminq.h"
       7                 :            : 
       8                 :            : #define GVE_PKT_CONT_BIT_IS_SET(x) (GVE_RXF_PKT_CONT & (x))
       9                 :            : 
      10                 :            : static inline void
      11                 :          0 : gve_rx_refill(struct gve_rx_queue *rxq)
      12                 :            : {
      13                 :          0 :         uint16_t mask = rxq->nb_rx_desc - 1;
      14                 :          0 :         uint16_t idx = rxq->next_avail & mask;
      15                 :            :         uint32_t next_avail = rxq->next_avail;
      16                 :            :         uint16_t nb_alloc, i;
      17                 :            :         struct rte_mbuf *nmb;
      18                 :            :         int diag;
      19                 :            : 
      20                 :            :         /* wrap around */
      21                 :          0 :         nb_alloc = rxq->nb_rx_desc - idx;
      22         [ #  # ]:          0 :         if (nb_alloc <= rxq->nb_avail) {
      23                 :          0 :                 diag = rte_pktmbuf_alloc_bulk(rxq->mpool, &rxq->sw_ring[idx], nb_alloc);
      24         [ #  # ]:          0 :                 if (diag < 0) {
      25                 :          0 :                         rxq->stats.no_mbufs_bulk++;
      26         [ #  # ]:          0 :                         for (i = 0; i < nb_alloc; i++) {
      27                 :          0 :                                 nmb = rte_pktmbuf_alloc(rxq->mpool);
      28         [ #  # ]:          0 :                                 if (!nmb)
      29                 :            :                                         break;
      30                 :          0 :                                 rxq->sw_ring[idx + i] = nmb;
      31                 :            :                         }
      32         [ #  # ]:          0 :                         if (i != nb_alloc) {
      33                 :          0 :                                 rxq->stats.no_mbufs += nb_alloc - i;
      34                 :            :                                 nb_alloc = i;
      35                 :            :                         }
      36                 :            :                 }
      37                 :          0 :                 rxq->nb_avail -= nb_alloc;
      38                 :          0 :                 next_avail += nb_alloc;
      39                 :            : 
      40                 :            :                 /* queue page list mode doesn't need real refill. */
      41         [ #  # ]:          0 :                 if (rxq->is_gqi_qpl) {
      42                 :          0 :                         idx += nb_alloc;
      43                 :            :                 } else {
      44         [ #  # ]:          0 :                         for (i = 0; i < nb_alloc; i++) {
      45                 :          0 :                                 nmb = rxq->sw_ring[idx];
      46                 :          0 :                                 rxq->rx_data_ring[idx].addr =
      47                 :            :                                         rte_cpu_to_be_64(rte_mbuf_data_iova(nmb));
      48                 :          0 :                                 idx++;
      49                 :            :                         }
      50                 :            :                 }
      51         [ #  # ]:          0 :                 if (idx == rxq->nb_rx_desc)
      52                 :            :                         idx = 0;
      53                 :            :         }
      54                 :            : 
      55         [ #  # ]:          0 :         if (rxq->nb_avail > 0) {
      56                 :          0 :                 nb_alloc = rxq->nb_avail;
      57         [ #  # ]:          0 :                 if (rxq->nb_rx_desc < idx + rxq->nb_avail)
      58                 :          0 :                         nb_alloc = rxq->nb_rx_desc - idx;
      59                 :          0 :                 diag = rte_pktmbuf_alloc_bulk(rxq->mpool, &rxq->sw_ring[idx], nb_alloc);
      60         [ #  # ]:          0 :                 if (diag < 0) {
      61                 :          0 :                         rxq->stats.no_mbufs_bulk++;
      62         [ #  # ]:          0 :                         for (i = 0; i < nb_alloc; i++) {
      63                 :          0 :                                 nmb = rte_pktmbuf_alloc(rxq->mpool);
      64         [ #  # ]:          0 :                                 if (!nmb)
      65                 :            :                                         break;
      66                 :          0 :                                 rxq->sw_ring[idx + i] = nmb;
      67                 :            :                         }
      68         [ #  # ]:          0 :                         if (i != nb_alloc) {
      69                 :          0 :                                 rxq->stats.no_mbufs += nb_alloc - i;
      70                 :            :                                 nb_alloc = i;
      71                 :            :                         }
      72                 :            :                 }
      73                 :          0 :                 rxq->nb_avail -= nb_alloc;
      74                 :          0 :                 next_avail += nb_alloc;
      75                 :            : 
      76         [ #  # ]:          0 :                 if (!rxq->is_gqi_qpl) {
      77         [ #  # ]:          0 :                         for (i = 0; i < nb_alloc; i++) {
      78                 :          0 :                                 nmb = rxq->sw_ring[idx];
      79                 :          0 :                                 rxq->rx_data_ring[idx].addr =
      80                 :            :                                         rte_cpu_to_be_64(rte_mbuf_data_iova(nmb));
      81                 :          0 :                                 idx++;
      82                 :            :                         }
      83                 :            :                 }
      84                 :            :         }
      85                 :            : 
      86         [ #  # ]:          0 :         if (next_avail != rxq->next_avail) {
      87         [ #  # ]:          0 :                 rte_write32(rte_cpu_to_be_32(next_avail), rxq->qrx_tail);
      88                 :          0 :                 rxq->next_avail = next_avail;
      89                 :            :         }
      90                 :          0 : }
      91                 :            : 
      92                 :            : /*
      93                 :            :  * This method processes a single rte_mbuf and handles packet segmentation
      94                 :            :  * In QPL mode it copies data from the mbuf to the gve_rx_queue.
      95                 :            :  */
      96                 :            : static void
      97                 :          0 : gve_rx_mbuf(struct gve_rx_queue *rxq, struct rte_mbuf *rxe, uint16_t len,
      98                 :            :             uint16_t rx_id)
      99                 :            : {
     100                 :            :         uint16_t padding = 0;
     101                 :            :         uint64_t addr;
     102                 :            : 
     103                 :          0 :         rxe->data_len = len;
     104         [ #  # ]:          0 :         if (!rxq->ctx.mbuf_head) {
     105                 :          0 :                 rxq->ctx.mbuf_head = rxe;
     106                 :          0 :                 rxq->ctx.mbuf_tail = rxe;
     107                 :          0 :                 rxe->nb_segs = 1;
     108                 :          0 :                 rxe->pkt_len = len;
     109                 :          0 :                 rxe->data_len = len;
     110                 :          0 :                 rxe->port = rxq->port_id;
     111                 :          0 :                 rxe->ol_flags = 0;
     112                 :            :                 padding = GVE_RX_PAD;
     113                 :            :         } else {
     114                 :          0 :                 rxq->ctx.mbuf_head->pkt_len += len;
     115                 :          0 :                 rxq->ctx.mbuf_head->nb_segs += 1;
     116                 :          0 :                 rxq->ctx.mbuf_tail->next = rxe;
     117                 :          0 :                 rxq->ctx.mbuf_tail = rxe;
     118                 :            :         }
     119         [ #  # ]:          0 :         if (rxq->is_gqi_qpl) {
     120                 :          0 :                 addr = (uint64_t)rxq->qpl->qpl_bufs[rx_id] + padding;
     121         [ #  # ]:          0 :                 rte_memcpy((void *)((size_t)rxe->buf_addr + rxe->data_off),
     122                 :            :                                     (void *)(size_t)addr, len);
     123                 :            :         }
     124                 :          0 : }
     125                 :            : 
     126                 :            : /*
     127                 :            :  * This method processes a single packet fragment associated with the
     128                 :            :  * passed packet descriptor.
     129                 :            :  * This methods returns whether the fragment is the last fragment
     130                 :            :  * of a packet.
     131                 :            :  */
     132                 :            : static bool
     133                 :          0 : gve_rx(struct gve_rx_queue *rxq, volatile struct gve_rx_desc *rxd, uint16_t rx_id)
     134                 :            : {
     135                 :          0 :         bool is_last_frag = !GVE_PKT_CONT_BIT_IS_SET(rxd->flags_seq);
     136                 :          0 :         uint16_t frag_size = rte_be_to_cpu_16(rxd->len);
     137                 :            :         struct gve_rx_ctx *ctx = &rxq->ctx;
     138                 :          0 :         bool is_first_frag = ctx->total_frags == 0;
     139                 :            :         struct rte_mbuf *rxe;
     140                 :            : 
     141         [ #  # ]:          0 :         if (ctx->drop_pkt)
     142                 :          0 :                 goto drop_frag;
     143                 :            : 
     144         [ #  # ]:          0 :         if (rxd->flags_seq & GVE_RXF_ERR) {
     145                 :          0 :                 ctx->drop_pkt = true;
     146                 :          0 :                 rxq->stats.errors++;
     147                 :          0 :                 goto drop_frag;
     148                 :            :         }
     149                 :            : 
     150                 :            :         /* The device chains a frame larger than one Rx buffer whatever MTU
     151                 :            :          * it was given, so drop it unless the application enabled scatter.
     152                 :            :          */
     153   [ #  #  #  # ]:          0 :         if (is_first_frag && !is_last_frag && !rxq->scatter) {
     154                 :          0 :                 ctx->drop_pkt = true;
     155                 :          0 :                 rxq->stats.errors++;
     156                 :          0 :                 goto drop_frag;
     157                 :            :         }
     158                 :            : 
     159         [ #  # ]:          0 :         if (is_first_frag)
     160                 :          0 :                 frag_size -= GVE_RX_PAD;
     161                 :            : 
     162                 :          0 :         rxe = rxq->sw_ring[rx_id];
     163                 :          0 :         gve_rx_mbuf(rxq, rxe, frag_size, rx_id);
     164                 :          0 :         rxq->sw_ring[rx_id] = NULL;
     165                 :          0 :         rxq->stats.bytes += frag_size;
     166                 :            : 
     167         [ #  # ]:          0 :         if (is_first_frag) {
     168         [ #  # ]:          0 :                 if (rxd->flags_seq & GVE_RXF_TCP)
     169                 :          0 :                         rxe->packet_type |= RTE_PTYPE_L4_TCP;
     170         [ #  # ]:          0 :                 if (rxd->flags_seq & GVE_RXF_UDP)
     171                 :          0 :                         rxe->packet_type |= RTE_PTYPE_L4_UDP;
     172         [ #  # ]:          0 :                 if (rxd->flags_seq & GVE_RXF_IPV4)
     173                 :          0 :                         rxe->packet_type |= RTE_PTYPE_L3_IPV4;
     174         [ #  # ]:          0 :                 if (rxd->flags_seq & GVE_RXF_IPV6)
     175                 :          0 :                         rxe->packet_type |= RTE_PTYPE_L3_IPV6;
     176                 :            : 
     177         [ #  # ]:          0 :                 if (gve_needs_rss(rxd->flags_seq)) {
     178                 :          0 :                         rxe->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
     179                 :          0 :                         rxe->hash.rss = rte_be_to_cpu_32(rxd->rss_hash);
     180                 :            :                 }
     181                 :            :         }
     182                 :            : 
     183                 :          0 :         goto finish_frag;
     184                 :            : 
     185                 :          0 : drop_frag:
     186                 :            :         /* The refill puts a new mbuf in this slot, so free the old one. */
     187                 :          0 :         rte_pktmbuf_free(rxq->sw_ring[rx_id]);
     188                 :          0 :         rxq->sw_ring[rx_id] = NULL;
     189                 :          0 : finish_frag:
     190                 :          0 :         ctx->total_frags++;
     191                 :          0 :         return is_last_frag;
     192                 :            : }
     193                 :            : 
     194                 :            : static void
     195                 :            : gve_rx_ctx_clear(struct gve_rx_ctx *ctx)
     196                 :            : {
     197                 :          0 :         ctx->mbuf_head = NULL;
     198                 :          0 :         ctx->mbuf_tail = NULL;
     199                 :          0 :         ctx->drop_pkt = false;
     200                 :          0 :         ctx->total_frags = 0;
     201                 :          0 : }
     202                 :            : 
     203                 :            : uint16_t
     204                 :          0 : gve_rx_burst(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
     205                 :            : {
     206                 :            :         volatile struct gve_rx_desc *rxr, *rxd;
     207                 :            :         struct gve_rx_queue *rxq = rx_queue;
     208                 :            :         struct gve_rx_ctx *ctx = &rxq->ctx;
     209                 :          0 :         uint16_t rx_id = rxq->rx_tail;
     210                 :            :         uint16_t nb_rx;
     211                 :            : 
     212                 :          0 :         rxr = rxq->rx_desc_ring;
     213                 :            :         nb_rx = 0;
     214                 :            : 
     215         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
     216                 :          0 :                 rxd = &rxr[rx_id];
     217         [ #  # ]:          0 :                 if (GVE_SEQNO(rxd->flags_seq) != rxq->expected_seqno)
     218                 :            :                         break;
     219                 :            : 
     220         [ #  # ]:          0 :                 if (gve_rx(rxq, rxd, rx_id)) {
     221         [ #  # ]:          0 :                         if (!ctx->drop_pkt)
     222                 :          0 :                                 rx_pkts[nb_rx++] = ctx->mbuf_head;
     223                 :            :                         else
     224                 :          0 :                                 rte_pktmbuf_free(ctx->mbuf_head);
     225                 :          0 :                         rxq->nb_avail += ctx->total_frags;
     226                 :            :                         gve_rx_ctx_clear(ctx);
     227                 :            :                 }
     228                 :            : 
     229                 :          0 :                 rx_id++;
     230         [ #  # ]:          0 :                 if (rx_id == rxq->nb_rx_desc)
     231                 :            :                         rx_id = 0;
     232                 :            : 
     233         [ #  # ]:          0 :                 rxq->expected_seqno = gve_next_seqno(rxq->expected_seqno);
     234                 :            :         }
     235                 :            : 
     236                 :          0 :         rxq->rx_tail = rx_id;
     237                 :            : 
     238         [ #  # ]:          0 :         if (rxq->nb_avail > rxq->free_thresh)
     239                 :          0 :                 gve_rx_refill(rxq);
     240                 :            : 
     241         [ #  # ]:          0 :         if (nb_rx)
     242                 :          0 :                 rxq->stats.packets += nb_rx;
     243                 :            : 
     244                 :          0 :         return nb_rx;
     245                 :            : }
     246                 :            : 
     247                 :            : static inline void
     248                 :          0 : gve_reset_rxq(struct gve_rx_queue *rxq)
     249                 :            : {
     250                 :            :         struct rte_mbuf **sw_ring;
     251                 :            :         uint32_t size, i;
     252                 :            : 
     253         [ #  # ]:          0 :         if (rxq == NULL) {
     254                 :          0 :                 PMD_DRV_LOG(ERR, "pointer to rxq is NULL");
     255                 :          0 :                 return;
     256                 :            :         }
     257                 :            : 
     258                 :          0 :         size = rxq->nb_rx_desc * sizeof(struct gve_rx_desc);
     259         [ #  # ]:          0 :         for (i = 0; i < size; i++)
     260                 :          0 :                 ((volatile char *)rxq->rx_desc_ring)[i] = 0;
     261                 :            : 
     262                 :          0 :         size = rxq->nb_rx_desc * sizeof(union gve_rx_data_slot);
     263         [ #  # ]:          0 :         for (i = 0; i < size; i++)
     264                 :          0 :                 ((volatile char *)rxq->rx_data_ring)[i] = 0;
     265                 :            : 
     266                 :          0 :         sw_ring = rxq->sw_ring;
     267         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++)
     268                 :          0 :                 sw_ring[i] = NULL;
     269                 :            : 
     270                 :          0 :         rxq->rx_tail = 0;
     271                 :          0 :         rxq->next_avail = 0;
     272                 :          0 :         rxq->nb_avail = rxq->nb_rx_desc;
     273                 :          0 :         rxq->expected_seqno = 1;
     274                 :            : }
     275                 :            : 
     276                 :            : static inline void
     277                 :          0 : gve_release_rxq_mbufs(struct gve_rx_queue *rxq)
     278                 :            : {
     279                 :            :         uint16_t i;
     280                 :            : 
     281         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
     282         [ #  # ]:          0 :                 if (rxq->sw_ring[i]) {
     283                 :            :                         rte_pktmbuf_free_seg(rxq->sw_ring[i]);
     284                 :          0 :                         rxq->sw_ring[i] = NULL;
     285                 :            :                 }
     286                 :            :         }
     287                 :            : 
     288                 :          0 :         rxq->nb_avail = rxq->nb_rx_desc;
     289                 :          0 : }
     290                 :            : 
     291                 :            : void
     292                 :          0 : gve_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
     293                 :            : {
     294                 :          0 :         struct gve_rx_queue *q = dev->data->rx_queues[qid];
     295                 :            : 
     296         [ #  # ]:          0 :         if (!q)
     297                 :            :                 return;
     298                 :            : 
     299         [ #  # ]:          0 :         if (q->is_gqi_qpl) {
     300                 :          0 :                 gve_teardown_queue_page_list(q->hw, q->qpl);
     301                 :          0 :                 q->qpl = NULL;
     302                 :            :         }
     303                 :            : 
     304                 :          0 :         gve_release_rxq_mbufs(q);
     305                 :          0 :         rte_free(q->sw_ring);
     306                 :          0 :         rte_memzone_free(q->data_mz);
     307                 :          0 :         rte_memzone_free(q->mz);
     308                 :          0 :         rte_memzone_free(q->qres_mz);
     309                 :          0 :         q->qres = NULL;
     310                 :          0 :         rte_free(q);
     311                 :            : 
     312                 :          0 :         dev->data->rx_queues[qid] = NULL;
     313                 :            : }
     314                 :            : 
     315                 :            : static uint16_t
     316                 :            : gve_rx_buf_len_gqi(struct rte_mempool *pool)
     317                 :            : {
     318                 :          0 :         uint32_t mbuf_len =
     319                 :          0 :                 rte_pktmbuf_data_room_size(pool) - RTE_PKTMBUF_HEADROOM;
     320                 :            : 
     321                 :          0 :         return RTE_MIN((uint16_t)GVE_RX_MAX_BUF_SIZE_GQI,
     322                 :            :                        RTE_ALIGN_FLOOR(mbuf_len, GVE_RX_BUF_ALIGN_GQI));
     323                 :            : }
     324                 :            : 
     325                 :            : int
     326                 :          0 : gve_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
     327                 :            :                 uint16_t nb_desc, unsigned int socket_id,
     328                 :            :                 const struct rte_eth_rxconf *conf, struct rte_mempool *pool)
     329                 :            : {
     330                 :          0 :         struct gve_priv *hw = dev->data->dev_private;
     331                 :            :         const struct rte_memzone *mz;
     332                 :            :         struct gve_rx_queue *rxq;
     333                 :            :         uint16_t free_thresh;
     334                 :            :         uint16_t rx_buf_len;
     335                 :            :         uint64_t offloads;
     336                 :            :         int err = 0;
     337                 :            : 
     338                 :            :         /* Ring size is required to be a power of two. */
     339         [ #  # ]:          0 :         if (!rte_is_power_of_2(nb_desc)) {
     340                 :          0 :                 PMD_DRV_LOG(ERR, "Invalid ring size %u. GVE ring size must be a power of 2.",
     341                 :            :                             nb_desc);
     342                 :          0 :                 return -EINVAL;
     343                 :            :         }
     344                 :            : 
     345                 :            :         /* A frame larger than one Rx buffer is chained into a multi-segment
     346                 :            :          * mbuf, which the application must have asked for.
     347                 :            :          */
     348         [ #  # ]:          0 :         offloads = dev->data->dev_conf.rxmode.offloads | conf->offloads;
     349                 :            :         rx_buf_len = gve_rx_buf_len_gqi(pool);
     350   [ #  #  #  # ]:          0 :         if (!(offloads & RTE_ETH_RX_OFFLOAD_SCATTER) &&
     351         [ #  # ]:          0 :             gve_rx_gqi_needs_scatter(dev->data->mtu, rx_buf_len)) {
     352                 :          0 :                 PMD_DRV_LOG(ERR, "MTU %u needs Rx scatter with %u byte Rx buffers",
     353                 :            :                             dev->data->mtu, rx_buf_len);
     354                 :          0 :                 return -EINVAL;
     355                 :            :         }
     356                 :            : 
     357                 :            :         /* Free memory if needed. */
     358         [ #  # ]:          0 :         if (dev->data->rx_queues[queue_id]) {
     359                 :          0 :                 gve_rx_queue_release(dev, queue_id);
     360                 :          0 :                 dev->data->rx_queues[queue_id] = NULL;
     361                 :            :         }
     362                 :            : 
     363                 :            :         /* Allocate the RX queue data structure. */
     364                 :          0 :         rxq = rte_zmalloc_socket("gve rxq",
     365                 :            :                                  sizeof(struct gve_rx_queue),
     366                 :            :                                  RTE_CACHE_LINE_SIZE,
     367                 :            :                                  socket_id);
     368         [ #  # ]:          0 :         if (!rxq) {
     369                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for rx queue structure");
     370                 :            :                 err = -ENOMEM;
     371                 :          0 :                 goto err_rxq;
     372                 :            :         }
     373                 :            : 
     374         [ #  # ]:          0 :         free_thresh = conf->rx_free_thresh ? conf->rx_free_thresh : GVE_DEFAULT_RX_FREE_THRESH;
     375         [ #  # ]:          0 :         if (free_thresh >= nb_desc) {
     376                 :          0 :                 PMD_DRV_LOG(ERR, "rx_free_thresh (%u) must be less than nb_desc (%u) minus 3.",
     377                 :            :                             free_thresh, rxq->nb_rx_desc);
     378                 :            :                 err = -EINVAL;
     379                 :          0 :                 goto err_rxq;
     380                 :            :         }
     381                 :            : 
     382                 :          0 :         rxq->nb_rx_desc = nb_desc;
     383                 :          0 :         rxq->free_thresh = free_thresh;
     384                 :          0 :         rxq->queue_id = queue_id;
     385                 :          0 :         rxq->port_id = dev->data->port_id;
     386                 :          0 :         rxq->ntfy_id = hw->num_ntfy_blks / 2 + queue_id;
     387                 :          0 :         rxq->is_gqi_qpl = hw->queue_format == GVE_GQI_QPL_FORMAT;
     388                 :          0 :         rxq->mpool = pool;
     389                 :          0 :         rxq->hw = hw;
     390         [ #  # ]:          0 :         rxq->ntfy_addr = &hw->db_bar[rte_be_to_cpu_32(hw->irq_dbs[rxq->ntfy_id].id)];
     391                 :            : 
     392                 :          0 :         rxq->rx_buf_len = rx_buf_len;
     393                 :          0 :         rxq->scatter = !!(offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
     394                 :            : 
     395                 :            :         /* Allocate software ring */
     396                 :          0 :         rxq->sw_ring = rte_zmalloc_socket("gve rx sw ring", sizeof(struct rte_mbuf *) * nb_desc,
     397                 :            :                                           RTE_CACHE_LINE_SIZE, socket_id);
     398         [ #  # ]:          0 :         if (!rxq->sw_ring) {
     399                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW RX ring");
     400                 :            :                 err = -ENOMEM;
     401                 :          0 :                 goto err_rxq;
     402                 :            :         }
     403                 :            : 
     404                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_id,
     405                 :            :                                       nb_desc * sizeof(struct gve_rx_desc),
     406                 :            :                                       PAGE_SIZE, socket_id);
     407         [ #  # ]:          0 :         if (mz == NULL) {
     408                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX");
     409                 :            :                 err = -ENOMEM;
     410                 :          0 :                 goto err_sw_ring;
     411                 :            :         }
     412                 :          0 :         rxq->rx_desc_ring = (struct gve_rx_desc *)mz->addr;
     413                 :          0 :         rxq->rx_ring_phys_addr = mz->iova;
     414                 :          0 :         rxq->mz = mz;
     415                 :            : 
     416                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "gve rx data ring", queue_id,
     417                 :            :                                       sizeof(union gve_rx_data_slot) * nb_desc,
     418                 :            :                                       PAGE_SIZE, socket_id);
     419         [ #  # ]:          0 :         if (mz == NULL) {
     420                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for RX data ring");
     421                 :            :                 err = -ENOMEM;
     422                 :          0 :                 goto err_rx_ring;
     423                 :            :         }
     424                 :          0 :         rxq->rx_data_ring = (union gve_rx_data_slot *)mz->addr;
     425                 :          0 :         rxq->data_mz = mz;
     426                 :            : 
     427                 :            :         /* Allocate and register QPL for the queue. */
     428         [ #  # ]:          0 :         if (rxq->is_gqi_qpl) {
     429                 :          0 :                 rxq->qpl = gve_setup_queue_page_list(hw, queue_id, true,
     430                 :            :                                                      nb_desc);
     431         [ #  # ]:          0 :                 if (!rxq->qpl) {
     432                 :            :                         err = -ENOMEM;
     433                 :          0 :                         PMD_DRV_LOG(ERR,
     434                 :            :                                     "Failed to alloc rx qpl for queue %hu.",
     435                 :            :                                     queue_id);
     436                 :          0 :                         goto err_data_ring;
     437                 :            :                 }
     438                 :            :         }
     439                 :            : 
     440                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "rxq_res", queue_id,
     441                 :            :                                       sizeof(struct gve_queue_resources),
     442                 :            :                                       PAGE_SIZE, socket_id);
     443         [ #  # ]:          0 :         if (mz == NULL) {
     444                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX resource");
     445                 :            :                 err = -ENOMEM;
     446                 :          0 :                 goto err_qpl;
     447                 :            :         }
     448                 :          0 :         rxq->qres = (struct gve_queue_resources *)mz->addr;
     449                 :          0 :         rxq->qres_mz = mz;
     450                 :            : 
     451                 :          0 :         gve_reset_rxq(rxq);
     452                 :            : 
     453                 :          0 :         dev->data->rx_queues[queue_id] = rxq;
     454                 :            : 
     455                 :          0 :         return 0;
     456                 :            : err_qpl:
     457         [ #  # ]:          0 :         if (rxq->is_gqi_qpl) {
     458                 :          0 :                 gve_teardown_queue_page_list(hw, rxq->qpl);
     459                 :          0 :                 rxq->qpl = NULL;
     460                 :            :         }
     461                 :          0 : err_data_ring:
     462                 :          0 :         rte_memzone_free(rxq->data_mz);
     463                 :          0 : err_rx_ring:
     464                 :          0 :         rte_memzone_free(rxq->mz);
     465                 :          0 : err_sw_ring:
     466                 :          0 :         rte_free(rxq->sw_ring);
     467                 :          0 : err_rxq:
     468                 :          0 :         rte_free(rxq);
     469                 :          0 :         return err;
     470                 :            : }
     471                 :            : 
     472                 :            : static int
     473                 :          0 : gve_rxq_mbufs_alloc(struct gve_rx_queue *rxq)
     474                 :            : {
     475                 :            :         struct rte_mbuf *nmb;
     476                 :            :         uint16_t i;
     477                 :            :         int diag;
     478                 :            : 
     479                 :          0 :         diag = rte_pktmbuf_alloc_bulk(rxq->mpool, &rxq->sw_ring[0], rxq->nb_rx_desc);
     480         [ #  # ]:          0 :         if (diag < 0) {
     481         [ #  # ]:          0 :                 for (i = 0; i < rxq->nb_rx_desc - 1; i++) {
     482                 :          0 :                         nmb = rte_pktmbuf_alloc(rxq->mpool);
     483         [ #  # ]:          0 :                         if (!nmb)
     484                 :            :                                 break;
     485                 :          0 :                         rxq->sw_ring[i] = nmb;
     486                 :            :                 }
     487         [ #  # ]:          0 :                 if (i < rxq->nb_rx_desc - 1)
     488                 :            :                         return -ENOMEM;
     489                 :            :         }
     490                 :          0 :         rxq->nb_avail = 0;
     491                 :          0 :         rxq->next_avail = rxq->nb_rx_desc - 1;
     492                 :            : 
     493         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
     494         [ #  # ]:          0 :                 if (rxq->is_gqi_qpl) {
     495         [ #  # ]:          0 :                         rxq->rx_data_ring[i].addr = rte_cpu_to_be_64(i * PAGE_SIZE);
     496                 :            :                 } else {
     497         [ #  # ]:          0 :                         if (i == rxq->nb_rx_desc - 1)
     498                 :            :                                 break;
     499                 :          0 :                         nmb = rxq->sw_ring[i];
     500                 :          0 :                         rxq->rx_data_ring[i].addr = rte_cpu_to_be_64(rte_mbuf_data_iova(nmb));
     501                 :            :                 }
     502                 :            :         }
     503                 :            : 
     504         [ #  # ]:          0 :         rte_write32(rte_cpu_to_be_32(rxq->next_avail), rxq->qrx_tail);
     505                 :            : 
     506                 :          0 :         return 0;
     507                 :            : }
     508                 :            : 
     509                 :            : int
     510                 :          0 : gve_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
     511                 :            : {
     512                 :          0 :         struct gve_priv *hw = dev->data->dev_private;
     513                 :            :         struct gve_rx_queue *rxq;
     514                 :            :         int ret;
     515                 :            : 
     516         [ #  # ]:          0 :         if (rx_queue_id >= dev->data->nb_rx_queues)
     517                 :            :                 return -EINVAL;
     518                 :            : 
     519                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
     520                 :            : 
     521         [ #  # ]:          0 :         rxq->qrx_tail = &hw->db_bar[rte_be_to_cpu_32(rxq->qres->db_index)];
     522                 :            : 
     523                 :          0 :         rte_write32(rte_cpu_to_be_32(GVE_IRQ_MASK), rxq->ntfy_addr);
     524                 :            : 
     525                 :          0 :         ret = gve_rxq_mbufs_alloc(rxq);
     526         [ #  # ]:          0 :         if (ret != 0) {
     527                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to alloc Rx queue mbuf");
     528                 :          0 :                 return ret;
     529                 :            :         }
     530                 :            : 
     531                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
     532                 :            : 
     533                 :          0 :         return 0;
     534                 :            : }
     535                 :            : 
     536                 :            : int
     537                 :          0 : gve_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
     538                 :            : {
     539                 :            :         struct gve_rx_queue *rxq;
     540                 :            : 
     541         [ #  # ]:          0 :         if (rx_queue_id >= dev->data->nb_rx_queues)
     542                 :            :                 return -EINVAL;
     543                 :            : 
     544                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
     545                 :          0 :         gve_release_rxq_mbufs(rxq);
     546                 :          0 :         gve_reset_rxq(rxq);
     547                 :            : 
     548                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
     549                 :            : 
     550                 :          0 :         return 0;
     551                 :            : }
     552                 :            : 
     553                 :            : void
     554                 :          0 : gve_stop_rx_queues(struct rte_eth_dev *dev)
     555                 :            : {
     556                 :          0 :         struct gve_process_private *process_priv = dev->process_private;
     557         [ #  # ]:          0 :         struct gve_priv *hw = dev->data->dev_private;
     558                 :            :         uint16_t i;
     559                 :            :         int err;
     560                 :            : 
     561         [ #  # ]:          0 :         if (!gve_is_gqi(hw))
     562                 :          0 :                 return gve_stop_rx_queues_dqo(dev);
     563                 :            : 
     564                 :          0 :         err = process_priv->ctrl_ops->destroy_rx_queues(hw, dev->data->nb_rx_queues);
     565         [ #  # ]:          0 :         if (err != 0)
     566                 :          0 :                 PMD_DRV_LOG(WARNING, "failed to destroy rxqs");
     567                 :            : 
     568         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     569         [ #  # ]:          0 :                 if (gve_rx_queue_stop(dev, i) != 0)
     570                 :          0 :                         PMD_DRV_LOG(WARNING, "Fail to stop Rx queue %d", i);
     571                 :            : }
     572                 :            : 
     573                 :            : void
     574                 :          0 : gve_set_rx_function(struct rte_eth_dev *dev)
     575                 :            : {
     576                 :          0 :         dev->rx_pkt_burst = gve_rx_burst;
     577                 :          0 : }

Generated by: LCOV version 1.14