LCOV - code coverage report
Current view: top level - drivers/net/mlx5 - mlx5_rxq.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1213 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 76 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 732 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2015 6WIND S.A.
       3                 :            :  * Copyright 2015 Mellanox Technologies, Ltd
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <stddef.h>
       7                 :            : #include <errno.h>
       8                 :            : #include <string.h>
       9                 :            : #include <stdint.h>
      10                 :            : #include <fcntl.h>
      11                 :            : #include <sys/queue.h>
      12                 :            : 
      13                 :            : #include <rte_mbuf.h>
      14                 :            : #include <rte_malloc.h>
      15                 :            : #include <ethdev_driver.h>
      16                 :            : #include <rte_common.h>
      17                 :            : #include <rte_interrupts.h>
      18                 :            : #include <rte_debug.h>
      19                 :            : #include <rte_io.h>
      20                 :            : #include <rte_eal_paging.h>
      21                 :            : 
      22                 :            : #include <mlx5_glue.h>
      23                 :            : #include <mlx5_malloc.h>
      24                 :            : #include <mlx5_common.h>
      25                 :            : #include <mlx5_common_mr.h>
      26                 :            : 
      27                 :            : #include "mlx5_defs.h"
      28                 :            : #include "mlx5.h"
      29                 :            : #include "mlx5_rx.h"
      30                 :            : #include "mlx5_utils.h"
      31                 :            : #include "mlx5_autoconf.h"
      32                 :            : #include "mlx5_devx.h"
      33                 :            : #include "rte_pmd_mlx5.h"
      34                 :            : 
      35                 :            : 
      36                 :            : /* Default RSS hash key also used for ConnectX-3. */
      37                 :            : uint8_t rss_hash_default_key[] = {
      38                 :            :         0x2c, 0xc6, 0x81, 0xd1,
      39                 :            :         0x5b, 0xdb, 0xf4, 0xf7,
      40                 :            :         0xfc, 0xa2, 0x83, 0x19,
      41                 :            :         0xdb, 0x1a, 0x3e, 0x94,
      42                 :            :         0x6b, 0x9e, 0x38, 0xd9,
      43                 :            :         0x2c, 0x9c, 0x03, 0xd1,
      44                 :            :         0xad, 0x99, 0x44, 0xa7,
      45                 :            :         0xd9, 0x56, 0x3d, 0x59,
      46                 :            :         0x06, 0x3c, 0x25, 0xf3,
      47                 :            :         0xfc, 0x1f, 0xdc, 0x2a,
      48                 :            : };
      49                 :            : 
      50                 :            : /* Length of the default RSS hash key. */
      51                 :            : static_assert(MLX5_RSS_HASH_KEY_LEN ==
      52                 :            :               (unsigned int)sizeof(rss_hash_default_key),
      53                 :            :               "wrong RSS default key size.");
      54                 :            : 
      55                 :            : /**
      56                 :            :  * Calculate the number of CQEs in CQ for the Rx queue.
      57                 :            :  *
      58                 :            :  *  @param rxq_data
      59                 :            :  *     Pointer to receive queue structure.
      60                 :            :  *
      61                 :            :  * @return
      62                 :            :  *   Number of CQEs in CQ.
      63                 :            :  */
      64                 :            : unsigned int
      65                 :          0 : mlx5_rxq_cqe_num(struct mlx5_rxq_data *rxq_data)
      66                 :            : {
      67                 :            :         unsigned int cqe_n;
      68         [ #  # ]:          0 :         unsigned int wqe_n = 1 << rxq_data->elts_n;
      69                 :            : 
      70         [ #  # ]:          0 :         if (mlx5_rxq_mprq_enabled(rxq_data))
      71                 :          0 :                 cqe_n = wqe_n * RTE_BIT32(rxq_data->log_strd_num) - 1;
      72                 :            :         else
      73                 :          0 :                 cqe_n = wqe_n - 1;
      74                 :          0 :         return cqe_n;
      75                 :            : }
      76                 :            : 
      77                 :            : /**
      78                 :            :  * Allocate RX queue elements for Multi-Packet RQ.
      79                 :            :  *
      80                 :            :  * @param rxq_ctrl
      81                 :            :  *   Pointer to RX queue structure.
      82                 :            :  *
      83                 :            :  * @return
      84                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
      85                 :            :  */
      86                 :            : static int
      87                 :          0 : rxq_alloc_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
      88                 :            : {
      89                 :            :         struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
      90                 :          0 :         unsigned int wqe_n = 1 << rxq->elts_n;
      91                 :            :         unsigned int i;
      92                 :            :         int err;
      93                 :            : 
      94                 :            :         /* Iterate on segments. */
      95         [ #  # ]:          0 :         for (i = 0; i <= wqe_n; ++i) {
      96                 :            :                 struct mlx5_mprq_buf *buf;
      97                 :            : 
      98   [ #  #  #  # ]:          0 :                 if (rte_mempool_get(rxq->mprq_mp, (void **)&buf) < 0) {
      99                 :          0 :                         DRV_LOG(ERR, "port %u empty mbuf pool", rxq->port_id);
     100                 :          0 :                         rte_errno = ENOMEM;
     101                 :          0 :                         goto error;
     102                 :            :                 }
     103         [ #  # ]:          0 :                 if (i < wqe_n)
     104                 :          0 :                         (*rxq->mprq_bufs)[i] = buf;
     105                 :            :                 else
     106                 :          0 :                         rxq->mprq_repl = buf;
     107                 :            :         }
     108                 :          0 :         DRV_LOG(DEBUG,
     109                 :            :                 "port %u MPRQ queue %u allocated and configured %u segments",
     110                 :            :                 rxq->port_id, rxq->idx, wqe_n);
     111                 :          0 :         return 0;
     112                 :            : error:
     113                 :            :         err = rte_errno; /* Save rte_errno before cleanup. */
     114                 :            :         wqe_n = i;
     115         [ #  # ]:          0 :         for (i = 0; (i != wqe_n); ++i) {
     116         [ #  # ]:          0 :                 if ((*rxq->mprq_bufs)[i] != NULL)
     117         [ #  # ]:          0 :                         rte_mempool_put(rxq->mprq_mp,
     118                 :            :                                         (*rxq->mprq_bufs)[i]);
     119                 :          0 :                 (*rxq->mprq_bufs)[i] = NULL;
     120                 :            :         }
     121                 :          0 :         DRV_LOG(DEBUG, "port %u MPRQ queue %u failed, freed everything",
     122                 :            :                 rxq->port_id, rxq->idx);
     123                 :          0 :         rte_errno = err; /* Restore rte_errno. */
     124                 :          0 :         return -rte_errno;
     125                 :            : }
     126                 :            : 
     127                 :            : /**
     128                 :            :  * Allocate RX queue elements for Single-Packet RQ.
     129                 :            :  *
     130                 :            :  * @param rxq_ctrl
     131                 :            :  *   Pointer to RX queue structure.
     132                 :            :  *
     133                 :            :  * @return
     134                 :            :  *   0 on success, negative errno value on failure.
     135                 :            :  */
     136                 :            : static int
     137                 :          0 : rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
     138                 :            : {
     139         [ #  # ]:          0 :         const unsigned int sges_n = 1 << rxq_ctrl->rxq.sges_n;
     140                 :            :         unsigned int elts_n = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
     141                 :          0 :                               RTE_BIT32(rxq_ctrl->rxq.elts_n) *
     142         [ #  # ]:          0 :                               RTE_BIT32(rxq_ctrl->rxq.log_strd_num) :
     143                 :          0 :                               RTE_BIT32(rxq_ctrl->rxq.elts_n);
     144                 :          0 :         bool has_vec_support = mlx5_rxq_check_vec_support(&rxq_ctrl->rxq) > 0;
     145                 :            :         unsigned int i;
     146                 :            :         int err;
     147                 :            : 
     148                 :            :         /* Iterate on segments. */
     149         [ #  # ]:          0 :         for (i = 0; (i != elts_n); ++i) {
     150                 :          0 :                 struct mlx5_eth_rxseg *seg = &rxq_ctrl->rxq.rxseg[i % sges_n];
     151                 :            :                 struct rte_mbuf *buf;
     152                 :            : 
     153                 :          0 :                 buf = rte_pktmbuf_alloc(seg->mp);
     154         [ #  # ]:          0 :                 if (buf == NULL) {
     155         [ #  # ]:          0 :                         if (rxq_ctrl->share_group == 0)
     156                 :          0 :                                 DRV_LOG(ERR, "port %u queue %u empty mbuf pool",
     157                 :            :                                         RXQ_PORT_ID(rxq_ctrl),
     158                 :            :                                         rxq_ctrl->rxq.idx);
     159                 :            :                         else
     160                 :          0 :                                 DRV_LOG(ERR, "share group %u queue %u empty mbuf pool",
     161                 :            :                                         rxq_ctrl->share_group,
     162                 :            :                                         rxq_ctrl->share_qid);
     163                 :          0 :                         rte_errno = ENOMEM;
     164                 :          0 :                         goto error;
     165                 :            :                 }
     166                 :            :                 /* Only vectored Rx routines rely on headroom size. */
     167                 :            :                 MLX5_ASSERT(!has_vec_support ||
     168                 :            :                             DATA_OFF(buf) >= RTE_PKTMBUF_HEADROOM);
     169                 :            :                 /* Buffer is supposed to be empty. */
     170                 :            :                 MLX5_ASSERT(rte_pktmbuf_data_len(buf) == 0);
     171                 :            :                 MLX5_ASSERT(rte_pktmbuf_pkt_len(buf) == 0);
     172                 :            :                 MLX5_ASSERT(!buf->next);
     173                 :          0 :                 SET_DATA_OFF(buf, seg->offset);
     174                 :          0 :                 PORT(buf) = rxq_ctrl->rxq.port_id;
     175                 :          0 :                 DATA_LEN(buf) = seg->length;
     176                 :          0 :                 PKT_LEN(buf) = seg->length;
     177                 :          0 :                 NB_SEGS(buf) = 1;
     178                 :          0 :                 (*rxq_ctrl->rxq.elts)[i] = buf;
     179                 :            :         }
     180                 :            :         /* If Rx vector is activated. */
     181         [ #  # ]:          0 :         if (has_vec_support) {
     182                 :            :                 struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
     183                 :          0 :                 struct rte_mbuf *mbuf_init = &rxq->fake_mbuf;
     184                 :            :                 struct rte_pktmbuf_pool_private *priv =
     185                 :            :                         (struct rte_pktmbuf_pool_private *)
     186         [ #  # ]:          0 :                                 rte_mempool_get_priv(rxq_ctrl->rxq.mp);
     187                 :            :                 int j;
     188                 :            : 
     189                 :            :                 /* Initialize default rearm_data for vPMD. */
     190         [ #  # ]:          0 :                 mbuf_init->data_off = RTE_PKTMBUF_HEADROOM;
     191                 :            :                 rte_mbuf_refcnt_set(mbuf_init, 1);
     192                 :          0 :                 mbuf_init->nb_segs = 1;
     193                 :            :                 /* For shared queues port is provided in CQE */
     194         [ #  # ]:          0 :                 mbuf_init->port = rxq->shared ? 0 : rxq->port_id;
     195         [ #  # ]:          0 :                 if (priv->flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
     196                 :          0 :                         mbuf_init->ol_flags = RTE_MBUF_F_EXTERNAL;
     197                 :            :                 /*
     198                 :            :                  * prevent compiler reordering:
     199                 :            :                  * rearm_data covers previous fields.
     200                 :            :                  */
     201                 :          0 :                 rte_compiler_barrier();
     202                 :          0 :                 rxq->mbuf_initializer =
     203                 :            :                         *(rte_xmm_t *)&mbuf_init->rearm_data;
     204                 :            :                 /* Padding with a fake mbuf for vectorized Rx. */
     205         [ #  # ]:          0 :                 for (j = 0; j < MLX5_VPMD_DESCS_PER_LOOP; ++j)
     206                 :          0 :                         (*rxq->elts)[elts_n + j] = &rxq->fake_mbuf;
     207                 :            :         }
     208         [ #  # ]:          0 :         if (rxq_ctrl->share_group == 0)
     209                 :          0 :                 DRV_LOG(DEBUG,
     210                 :            :                         "port %u SPRQ queue %u allocated and configured %u segments (max %u packets)",
     211                 :            :                         RXQ_PORT_ID(rxq_ctrl), rxq_ctrl->rxq.idx, elts_n,
     212                 :            :                         elts_n / (1 << rxq_ctrl->rxq.sges_n));
     213                 :            :         else
     214                 :          0 :                 DRV_LOG(DEBUG,
     215                 :            :                         "share group %u SPRQ queue %u allocated and configured %u segments (max %u packets)",
     216                 :            :                         rxq_ctrl->share_group, rxq_ctrl->share_qid, elts_n,
     217                 :            :                         elts_n / (1 << rxq_ctrl->rxq.sges_n));
     218                 :            :         return 0;
     219                 :            : error:
     220                 :            :         err = rte_errno; /* Save rte_errno before cleanup. */
     221                 :            :         elts_n = i;
     222         [ #  # ]:          0 :         for (i = 0; (i != elts_n); ++i) {
     223         [ #  # ]:          0 :                 if ((*rxq_ctrl->rxq.elts)[i] != NULL)
     224                 :            :                         rte_pktmbuf_free_seg((*rxq_ctrl->rxq.elts)[i]);
     225                 :          0 :                 (*rxq_ctrl->rxq.elts)[i] = NULL;
     226                 :            :         }
     227         [ #  # ]:          0 :         if (rxq_ctrl->share_group == 0)
     228                 :          0 :                 DRV_LOG(DEBUG, "port %u SPRQ queue %u failed, freed everything",
     229                 :            :                         RXQ_PORT_ID(rxq_ctrl), rxq_ctrl->rxq.idx);
     230                 :            :         else
     231                 :          0 :                 DRV_LOG(DEBUG, "share group %u SPRQ queue %u failed, freed everything",
     232                 :            :                         rxq_ctrl->share_group, rxq_ctrl->share_qid);
     233                 :          0 :         rte_errno = err; /* Restore rte_errno. */
     234                 :          0 :         return -rte_errno;
     235                 :            : }
     236                 :            : 
     237                 :            : /**
     238                 :            :  * Allocate RX queue elements.
     239                 :            :  *
     240                 :            :  * @param rxq_ctrl
     241                 :            :  *   Pointer to RX queue structure.
     242                 :            :  *
     243                 :            :  * @return
     244                 :            :  *   0 on success, negative errno value on failure.
     245                 :            :  */
     246                 :            : int
     247         [ #  # ]:          0 : rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
     248                 :            : {
     249                 :            :         int ret = 0;
     250                 :            : 
     251                 :            :         /**
     252                 :            :          * For MPRQ we need to allocate both MPRQ buffers
     253                 :            :          * for WQEs and simple mbufs for vector processing.
     254                 :            :          */
     255         [ #  # ]:          0 :         if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
     256                 :          0 :                 ret = rxq_alloc_elts_mprq(rxq_ctrl);
     257         [ #  # ]:          0 :         if (ret == 0)
     258                 :          0 :                 ret = rxq_alloc_elts_sprq(rxq_ctrl);
     259                 :          0 :         return ret;
     260                 :            : }
     261                 :            : 
     262                 :            : /**
     263                 :            :  * Free RX queue elements for Multi-Packet RQ.
     264                 :            :  *
     265                 :            :  * @param rxq_ctrl
     266                 :            :  *   Pointer to RX queue structure.
     267                 :            :  */
     268                 :            : static void
     269                 :          0 : rxq_free_elts_mprq(struct mlx5_rxq_ctrl *rxq_ctrl)
     270                 :            : {
     271                 :            :         struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
     272                 :            :         uint16_t i;
     273                 :            : 
     274                 :          0 :         DRV_LOG(DEBUG, "port %u Multi-Packet Rx queue %u freeing %d WRs",
     275                 :            :                 rxq->port_id, rxq->idx, (1u << rxq->elts_n));
     276         [ #  # ]:          0 :         if (rxq->mprq_bufs == NULL)
     277                 :            :                 return;
     278         [ #  # ]:          0 :         for (i = 0; (i != (1u << rxq->elts_n)); ++i) {
     279         [ #  # ]:          0 :                 if ((*rxq->mprq_bufs)[i] != NULL)
     280                 :          0 :                         mlx5_mprq_buf_free((*rxq->mprq_bufs)[i]);
     281                 :          0 :                 (*rxq->mprq_bufs)[i] = NULL;
     282                 :            :         }
     283         [ #  # ]:          0 :         if (rxq->mprq_repl != NULL) {
     284                 :          0 :                 mlx5_mprq_buf_free(rxq->mprq_repl);
     285                 :          0 :                 rxq->mprq_repl = NULL;
     286                 :            :         }
     287                 :            : }
     288                 :            : 
     289                 :            : /**
     290                 :            :  * Free RX queue elements for Single-Packet RQ.
     291                 :            :  *
     292                 :            :  * @param rxq_ctrl
     293                 :            :  *   Pointer to RX queue structure.
     294                 :            :  */
     295                 :            : static void
     296                 :          0 : rxq_free_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
     297                 :            : {
     298         [ #  # ]:          0 :         struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
     299         [ #  # ]:          0 :         const uint16_t q_n = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
     300                 :          0 :                 RTE_BIT32(rxq->elts_n) * RTE_BIT32(rxq->log_strd_num) :
     301                 :          0 :                 RTE_BIT32(rxq->elts_n);
     302                 :          0 :         const uint16_t q_mask = q_n - 1;
     303         [ #  # ]:          0 :         uint16_t elts_ci = mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq) ?
     304                 :          0 :                 rxq->elts_ci : rxq->rq_ci;
     305                 :          0 :         uint16_t used = q_n - (elts_ci - rxq->rq_pi);
     306                 :            :         uint16_t i;
     307                 :            : 
     308         [ #  # ]:          0 :         if (rxq_ctrl->share_group == 0)
     309                 :          0 :                 DRV_LOG(DEBUG, "port %u Rx queue %u freeing %d WRs",
     310                 :            :                         RXQ_PORT_ID(rxq_ctrl), rxq->idx, q_n);
     311                 :            :         else
     312                 :          0 :                 DRV_LOG(DEBUG, "share group %u Rx queue %u freeing %d WRs",
     313                 :            :                         rxq_ctrl->share_group, rxq_ctrl->share_qid, q_n);
     314         [ #  # ]:          0 :         if (rxq->elts == NULL)
     315                 :            :                 return;
     316                 :            :         /**
     317                 :            :          * Some mbuf in the Ring belongs to the application.
     318                 :            :          * They cannot be freed.
     319                 :            :          */
     320         [ #  # ]:          0 :         if (mlx5_rxq_check_vec_support(rxq) > 0) {
     321         [ #  # ]:          0 :                 for (i = 0; i < used; ++i)
     322                 :          0 :                         (*rxq->elts)[(elts_ci + i) & q_mask] = NULL;
     323                 :          0 :                 rxq->rq_pi = elts_ci;
     324                 :            :         }
     325         [ #  # ]:          0 :         for (i = 0; i != q_n; ++i) {
     326         [ #  # ]:          0 :                 if ((*rxq->elts)[i] != NULL)
     327                 :            :                         rte_pktmbuf_free_seg((*rxq->elts)[i]);
     328                 :          0 :                 (*rxq->elts)[i] = NULL;
     329                 :            :         }
     330                 :            : }
     331                 :            : 
     332                 :            : /**
     333                 :            :  * Free RX queue elements.
     334                 :            :  *
     335                 :            :  * @param rxq_ctrl
     336                 :            :  *   Pointer to RX queue structure.
     337                 :            :  */
     338                 :            : static void
     339         [ #  # ]:          0 : rxq_free_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
     340                 :            : {
     341                 :            :         /*
     342                 :            :          * For MPRQ we need to allocate both MPRQ buffers
     343                 :            :          * for WQEs and simple mbufs for vector processing.
     344                 :            :          */
     345         [ #  # ]:          0 :         if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
     346                 :          0 :                 rxq_free_elts_mprq(rxq_ctrl);
     347                 :          0 :         rxq_free_elts_sprq(rxq_ctrl);
     348                 :          0 : }
     349                 :            : 
     350                 :            : /**
     351                 :            :  * Returns the per-queue supported offloads.
     352                 :            :  *
     353                 :            :  * @param dev
     354                 :            :  *   Pointer to Ethernet device.
     355                 :            :  *
     356                 :            :  * @return
     357                 :            :  *   Supported Rx offloads.
     358                 :            :  */
     359                 :            : uint64_t
     360                 :          0 : mlx5_get_rx_queue_offloads(struct rte_eth_dev *dev)
     361                 :            : {
     362                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     363                 :            :         uint64_t offloads = (RTE_ETH_RX_OFFLOAD_SCATTER |
     364                 :            :                              RTE_ETH_RX_OFFLOAD_TIMESTAMP |
     365                 :            :                              RTE_ETH_RX_OFFLOAD_RSS_HASH);
     366                 :            : 
     367         [ #  # ]:          0 :         if (!priv->config.mprq.enabled)
     368                 :            :                 offloads |= RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
     369         [ #  # ]:          0 :         if (priv->sh->config.hw_fcs_strip)
     370                 :          0 :                 offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
     371         [ #  # ]:          0 :         if (priv->sh->dev_cap.hw_csum)
     372                 :          0 :                 offloads |= (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
     373                 :            :                              RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
     374                 :            :                              RTE_ETH_RX_OFFLOAD_TCP_CKSUM);
     375         [ #  # ]:          0 :         if (priv->sh->dev_cap.hw_vlan_strip)
     376                 :          0 :                 offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
     377         [ #  # ]:          0 :         if (priv->sh->config.lro_allowed)
     378                 :          0 :                 offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
     379                 :          0 :         return offloads;
     380                 :            : }
     381                 :            : 
     382                 :            : 
     383                 :            : /**
     384                 :            :  * Returns the per-port supported offloads.
     385                 :            :  *
     386                 :            :  * @return
     387                 :            :  *   Supported Rx offloads.
     388                 :            :  */
     389                 :            : uint64_t
     390                 :          0 : mlx5_get_rx_port_offloads(void)
     391                 :            : {
     392                 :            :         uint64_t offloads = RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
     393                 :            : 
     394                 :          0 :         return offloads;
     395                 :            : }
     396                 :            : 
     397                 :            : /**
     398                 :            :  * Verify if the queue can be released.
     399                 :            :  *
     400                 :            :  * @param dev
     401                 :            :  *   Pointer to Ethernet device.
     402                 :            :  * @param idx
     403                 :            :  *   RX queue index.
     404                 :            :  *
     405                 :            :  * @return
     406                 :            :  *   1 if the queue can be released
     407                 :            :  *   0 if the queue can not be released, there are references to it.
     408                 :            :  *   Negative errno and rte_errno is set if queue doesn't exist.
     409                 :            :  */
     410                 :            : static int
     411                 :          0 : mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx)
     412                 :            : {
     413                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
     414                 :            : 
     415         [ #  # ]:          0 :         if (rxq == NULL) {
     416                 :          0 :                 rte_errno = EINVAL;
     417                 :          0 :                 return -rte_errno;
     418                 :            :         }
     419                 :          0 :         return (rte_atomic_load_explicit(&rxq->refcnt, rte_memory_order_relaxed) == 1);
     420                 :            : }
     421                 :            : 
     422                 :            : /* Fetches and drops all SW-owned and error CQEs to synchronize CQ. */
     423                 :            : static void
     424                 :          0 : rxq_sync_cq(struct mlx5_rxq_data *rxq)
     425                 :            : {
     426                 :          0 :         const uint16_t cqe_n = 1 << rxq->cqe_n;
     427                 :          0 :         const uint16_t cqe_mask = cqe_n - 1;
     428                 :            :         volatile struct mlx5_cqe *cqe;
     429                 :            :         int ret, i;
     430                 :            : 
     431                 :            :         i = cqe_n;
     432                 :            :         do {
     433                 :          0 :                 cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_mask];
     434         [ #  # ]:          0 :                 ret = check_cqe(cqe, cqe_n, rxq->cq_ci);
     435                 :            :                 if (ret == MLX5_CQE_STATUS_HW_OWN)
     436                 :            :                         break;
     437         [ #  # ]:          0 :                 if (ret == MLX5_CQE_STATUS_ERR) {
     438                 :          0 :                         rxq->cq_ci++;
     439                 :          0 :                         continue;
     440                 :            :                 }
     441                 :            :                 MLX5_ASSERT(ret == MLX5_CQE_STATUS_SW_OWN);
     442         [ #  # ]:          0 :                 if (MLX5_CQE_FORMAT(cqe->op_own) != MLX5_COMPRESSED) {
     443                 :          0 :                         rxq->cq_ci++;
     444                 :          0 :                         continue;
     445                 :            :                 }
     446                 :            :                 /* Compute the next non compressed CQE. */
     447                 :          0 :                 rxq->cq_ci += rxq->cqe_comp_layout ?
     448         [ #  # ]:          0 :                         (MLX5_CQE_NUM_MINIS(cqe->op_own) + 1U) :
     449                 :          0 :                         rte_be_to_cpu_32(cqe->byte_cnt);
     450                 :            : 
     451         [ #  # ]:          0 :         } while (--i);
     452                 :            :         /* Move all CQEs to HW ownership, including possible MiniCQEs. */
     453         [ #  # ]:          0 :         for (i = 0; i < cqe_n; i++) {
     454                 :          0 :                 cqe = &(*rxq->cqes)[i];
     455                 :          0 :                 cqe->validity_iteration_count = MLX5_CQE_VIC_INIT;
     456                 :          0 :                 cqe->op_own = MLX5_CQE_INVALIDATE;
     457                 :            :         }
     458                 :            :         /* Resync CQE and WQE (WQ in RESET state). */
     459                 :          0 :         rte_io_wmb();
     460         [ #  # ]:          0 :         *rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
     461                 :          0 :         rte_io_wmb();
     462                 :          0 :         *rxq->rq_db = rte_cpu_to_be_32(0);
     463                 :          0 :         rte_io_wmb();
     464                 :          0 : }
     465                 :            : 
     466                 :            : /**
     467                 :            :  * Rx queue stop. Device queue goes to the RESET state,
     468                 :            :  * all involved mbufs are freed from WQ.
     469                 :            :  *
     470                 :            :  * @param dev
     471                 :            :  *   Pointer to Ethernet device structure.
     472                 :            :  * @param idx
     473                 :            :  *   RX queue index.
     474                 :            :  *
     475                 :            :  * @return
     476                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     477                 :            :  */
     478                 :            : int
     479                 :          0 : mlx5_rx_queue_stop_primary(struct rte_eth_dev *dev, uint16_t idx)
     480                 :            : {
     481                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     482                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
     483                 :          0 :         struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
     484                 :            :         int ret;
     485                 :            : 
     486                 :            :         MLX5_ASSERT(rxq != NULL && rxq_ctrl != NULL);
     487                 :            :         MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
     488                 :          0 :         ret = priv->obj_ops.rxq_obj_modify(rxq, MLX5_RXQ_MOD_RDY2RST);
     489         [ #  # ]:          0 :         if (ret) {
     490                 :          0 :                 DRV_LOG(ERR, "Cannot change Rx WQ state to RESET:  %s",
     491                 :            :                         strerror(errno));
     492                 :          0 :                 rte_errno = errno;
     493                 :          0 :                 return ret;
     494                 :            :         }
     495                 :            :         /* Remove all processes CQEs. */
     496                 :          0 :         rxq_sync_cq(&rxq_ctrl->rxq);
     497                 :            :         /* Free all involved mbufs. */
     498                 :          0 :         rxq_free_elts(rxq_ctrl);
     499                 :            :         /* Set the actual queue state. */
     500                 :          0 :         dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
     501                 :          0 :         return 0;
     502                 :            : }
     503                 :            : 
     504                 :            : /**
     505                 :            :  * Rx queue stop. Device queue goes to the RESET state,
     506                 :            :  * all involved mbufs are freed from WQ.
     507                 :            :  *
     508                 :            :  * @param dev
     509                 :            :  *   Pointer to Ethernet device structure.
     510                 :            :  * @param idx
     511                 :            :  *   RX queue index.
     512                 :            :  *
     513                 :            :  * @return
     514                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     515                 :            :  */
     516                 :            : int
     517                 :          0 : mlx5_rx_queue_stop(struct rte_eth_dev *dev, uint16_t idx)
     518                 :            : {
     519                 :          0 :         eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
     520                 :            :         int ret;
     521                 :            : 
     522         [ #  # ]:          0 :         if (rte_eth_dev_is_rx_hairpin_queue(dev, idx)) {
     523                 :          0 :                 DRV_LOG(ERR, "Hairpin queue can't be stopped");
     524                 :          0 :                 rte_errno = EINVAL;
     525                 :          0 :                 return -EINVAL;
     526                 :            :         }
     527         [ #  # ]:          0 :         if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STOPPED)
     528                 :            :                 return 0;
     529                 :            :         /*
     530                 :            :          * Vectorized Rx burst requires the CQ and RQ indices
     531                 :            :          * synchronized, that might be broken on RQ restart
     532                 :            :          * and cause Rx malfunction, so queue stopping is
     533                 :            :          * not supported if vectorized Rx burst is engaged.
     534                 :            :          * The routine pointer depends on the process type,
     535                 :            :          * should perform check there. MPRQ is not supported as well.
     536                 :            :          */
     537         [ #  # ]:          0 :         if (pkt_burst != mlx5_rx_burst) {
     538                 :          0 :                 DRV_LOG(ERR, "Rx queue stop is only supported "
     539                 :            :                         "for non-vectorized single-packet Rx");
     540                 :          0 :                 rte_errno = EINVAL;
     541                 :          0 :                 return -EINVAL;
     542                 :            :         }
     543         [ #  # ]:          0 :         if (rte_eal_process_type() ==  RTE_PROC_SECONDARY) {
     544                 :          0 :                 ret = mlx5_mp_os_req_queue_control(dev, idx,
     545                 :            :                                                    MLX5_MP_REQ_QUEUE_RX_STOP);
     546                 :            :         } else {
     547                 :          0 :                 ret = mlx5_rx_queue_stop_primary(dev, idx);
     548                 :            :         }
     549                 :            :         return ret;
     550                 :            : }
     551                 :            : 
     552                 :            : /**
     553                 :            :  * Rx queue start. Device queue goes to the ready state,
     554                 :            :  * all required mbufs are allocated and WQ is replenished.
     555                 :            :  *
     556                 :            :  * @param dev
     557                 :            :  *   Pointer to Ethernet device structure.
     558                 :            :  * @param idx
     559                 :            :  *   RX queue index.
     560                 :            :  *
     561                 :            :  * @return
     562                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     563                 :            :  */
     564                 :            : int
     565                 :          0 : mlx5_rx_queue_start_primary(struct rte_eth_dev *dev, uint16_t idx)
     566                 :            : {
     567                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     568                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
     569                 :          0 :         struct mlx5_rxq_data *rxq_data = &rxq->ctrl->rxq;
     570                 :            :         int ret;
     571                 :            : 
     572                 :            :         MLX5_ASSERT(rxq != NULL && rxq->ctrl != NULL);
     573                 :            :         MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
     574                 :            :         /* Allocate needed buffers. */
     575                 :          0 :         ret = rxq_alloc_elts(rxq->ctrl);
     576         [ #  # ]:          0 :         if (ret) {
     577                 :          0 :                 DRV_LOG(ERR, "Cannot reallocate buffers for Rx WQ");
     578                 :          0 :                 rte_errno = errno;
     579                 :          0 :                 return ret;
     580                 :            :         }
     581                 :          0 :         rte_io_wmb();
     582         [ #  # ]:          0 :         *rxq_data->cq_db = rte_cpu_to_be_32(rxq_data->cq_ci);
     583                 :          0 :         rte_io_wmb();
     584                 :            :         /* Reset RQ consumer before moving queue to READY state. */
     585                 :          0 :         *rxq_data->rq_db = rte_cpu_to_be_32(0);
     586                 :          0 :         rte_io_wmb();
     587                 :          0 :         ret = priv->obj_ops.rxq_obj_modify(rxq, MLX5_RXQ_MOD_RST2RDY);
     588         [ #  # ]:          0 :         if (ret) {
     589                 :          0 :                 DRV_LOG(ERR, "Cannot change Rx WQ state to READY:  %s",
     590                 :            :                         strerror(errno));
     591                 :          0 :                 rte_errno = errno;
     592                 :          0 :                 return ret;
     593                 :            :         }
     594                 :            :         /* Reinitialize RQ - set WQEs. */
     595                 :          0 :         mlx5_rxq_initialize(rxq_data);
     596                 :          0 :         rxq_data->err_state = MLX5_RXQ_ERR_STATE_NO_ERROR;
     597                 :            :         /* Set actual queue state. */
     598                 :          0 :         dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
     599                 :          0 :         return 0;
     600                 :            : }
     601                 :            : 
     602                 :            : /**
     603                 :            :  * Rx queue start. Device queue goes to the ready state,
     604                 :            :  * all required mbufs are allocated and WQ is replenished.
     605                 :            :  *
     606                 :            :  * @param dev
     607                 :            :  *   Pointer to Ethernet device structure.
     608                 :            :  * @param idx
     609                 :            :  *   RX queue index.
     610                 :            :  *
     611                 :            :  * @return
     612                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     613                 :            :  */
     614                 :            : int
     615                 :          0 : mlx5_rx_queue_start(struct rte_eth_dev *dev, uint16_t idx)
     616                 :            : {
     617                 :            :         int ret;
     618                 :            : 
     619         [ #  # ]:          0 :         if (rte_eth_dev_is_rx_hairpin_queue(dev, idx)) {
     620                 :          0 :                 DRV_LOG(ERR, "Hairpin queue can't be started");
     621                 :          0 :                 rte_errno = EINVAL;
     622                 :          0 :                 return -EINVAL;
     623                 :            :         }
     624         [ #  # ]:          0 :         if (dev->data->rx_queue_state[idx] == RTE_ETH_QUEUE_STATE_STARTED)
     625                 :            :                 return 0;
     626         [ #  # ]:          0 :         if (rte_eal_process_type() ==  RTE_PROC_SECONDARY) {
     627                 :          0 :                 ret = mlx5_mp_os_req_queue_control(dev, idx,
     628                 :            :                                                    MLX5_MP_REQ_QUEUE_RX_START);
     629                 :            :         } else {
     630                 :          0 :                 ret = mlx5_rx_queue_start_primary(dev, idx);
     631                 :            :         }
     632                 :            :         return ret;
     633                 :            : }
     634                 :            : 
     635                 :            : /**
     636                 :            :  * Rx queue presetup checks.
     637                 :            :  *
     638                 :            :  * @param dev
     639                 :            :  *   Pointer to Ethernet device structure.
     640                 :            :  * @param idx
     641                 :            :  *   RX queue index.
     642                 :            :  * @param desc
     643                 :            :  *   Number of descriptors to configure in queue.
     644                 :            :  * @param[out] rxq_ctrl
     645                 :            :  *   Address of pointer to shared Rx queue control.
     646                 :            :  *
     647                 :            :  * @return
     648                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     649                 :            :  */
     650                 :            : static int
     651                 :          0 : mlx5_rx_queue_pre_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t *desc,
     652                 :            :                         struct mlx5_rxq_ctrl **rxq_ctrl)
     653                 :            : {
     654                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     655                 :            :         struct mlx5_rxq_priv *rxq;
     656                 :            :         bool empty;
     657                 :            : 
     658         [ #  # ]:          0 :         if (*desc > 1 << priv->sh->cdev->config.hca_attr.log_max_wq_sz) {
     659                 :          0 :                 DRV_LOG(ERR,
     660                 :            :                         "port %u number of descriptors requested for Rx queue"
     661                 :            :                         " %u is more than supported",
     662                 :            :                         dev->data->port_id, idx);
     663                 :          0 :                 rte_errno = EINVAL;
     664                 :          0 :                 return -EINVAL;
     665                 :            :         }
     666         [ #  # ]:          0 :         if (!rte_is_power_of_2(*desc)) {
     667                 :          0 :                 *desc = 1 << log2above(*desc);
     668                 :          0 :                 DRV_LOG(WARNING,
     669                 :            :                         "port %u increased number of descriptors in Rx queue %u"
     670                 :            :                         " to the next power of two (%d)",
     671                 :            :                         dev->data->port_id, idx, *desc);
     672                 :            :         }
     673                 :          0 :         DRV_LOG(DEBUG, "port %u configuring Rx queue %u for %u descriptors",
     674                 :            :                 dev->data->port_id, idx, *desc);
     675         [ #  # ]:          0 :         if (idx >= priv->rxqs_n) {
     676                 :          0 :                 DRV_LOG(ERR, "port %u Rx queue index out of range (%u >= %u)",
     677                 :            :                         dev->data->port_id, idx, priv->rxqs_n);
     678                 :          0 :                 rte_errno = EOVERFLOW;
     679                 :          0 :                 return -rte_errno;
     680                 :            :         }
     681   [ #  #  #  # ]:          0 :         if (rxq_ctrl == NULL || *rxq_ctrl == NULL)
     682                 :            :                 return 0;
     683         [ #  # ]:          0 :         if (!(*rxq_ctrl)->rxq.shared) {
     684         [ #  # ]:          0 :                 if (!mlx5_rxq_releasable(dev, idx)) {
     685                 :          0 :                         DRV_LOG(ERR, "port %u unable to release queue index %u",
     686                 :            :                                 dev->data->port_id, idx);
     687                 :          0 :                         rte_errno = EBUSY;
     688                 :          0 :                         return -rte_errno;
     689                 :            :                 }
     690                 :          0 :                 mlx5_rxq_release(dev, idx);
     691                 :            :         } else {
     692         [ #  # ]:          0 :                 if ((*rxq_ctrl)->obj != NULL)
     693                 :            :                         /* Some port using shared Rx queue has been started. */
     694                 :            :                         return 0;
     695                 :            :                 /* Release all owner RxQ to reconfigure Shared RxQ. */
     696                 :            :                 do {
     697                 :          0 :                         rxq = LIST_FIRST(&(*rxq_ctrl)->owners);
     698         [ #  # ]:          0 :                         LIST_REMOVE(rxq, owner_entry);
     699                 :          0 :                         empty = LIST_EMPTY(&(*rxq_ctrl)->owners);
     700                 :          0 :                         mlx5_rxq_release(ETH_DEV(rxq->priv), rxq->idx);
     701         [ #  # ]:          0 :                 } while (!empty);
     702                 :          0 :                 *rxq_ctrl = NULL;
     703                 :            :         }
     704                 :            :         return 0;
     705                 :            : }
     706                 :            : 
     707                 :            : /**
     708                 :            :  * Get the shared Rx queue object that matches group and queue index.
     709                 :            :  *
     710                 :            :  * @param dev
     711                 :            :  *   Pointer to Ethernet device structure.
     712                 :            :  * @param group
     713                 :            :  *   Shared RXQ group.
     714                 :            :  * @param share_qid
     715                 :            :  *   Shared RX queue index.
     716                 :            :  *
     717                 :            :  * @return
     718                 :            :  *   Shared RXQ object that matching, or NULL if not found.
     719                 :            :  */
     720                 :            : static struct mlx5_rxq_ctrl *
     721                 :            : mlx5_shared_rxq_get(struct rte_eth_dev *dev, uint32_t group, uint16_t share_qid)
     722                 :            : {
     723                 :            :         struct mlx5_rxq_ctrl *rxq_ctrl;
     724                 :            :         struct mlx5_priv *priv = dev->data->dev_private;
     725                 :            : 
     726         [ #  # ]:          0 :         LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, share_entry) {
     727         [ #  # ]:          0 :                 if (rxq_ctrl->share_group == group &&
     728         [ #  # ]:          0 :                     rxq_ctrl->share_qid == share_qid)
     729                 :            :                         return rxq_ctrl;
     730                 :            :         }
     731                 :            :         return NULL;
     732                 :            : }
     733                 :            : 
     734                 :            : /**
     735                 :            :  * Check whether requested Rx queue configuration matches shared RXQ.
     736                 :            :  *
     737                 :            :  * @param rxq_ctrl
     738                 :            :  *   Pointer to shared RXQ.
     739                 :            :  * @param dev
     740                 :            :  *   Pointer to Ethernet device structure.
     741                 :            :  * @param idx
     742                 :            :  *   Queue index.
     743                 :            :  * @param desc
     744                 :            :  *   Number of descriptors to configure in queue.
     745                 :            :  * @param socket
     746                 :            :  *   NUMA socket on which memory must be allocated.
     747                 :            :  * @param[in] conf
     748                 :            :  *   Thresholds parameters.
     749                 :            :  * @param mp
     750                 :            :  *   Memory pool for buffer allocations.
     751                 :            :  *
     752                 :            :  * @return
     753                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     754                 :            :  */
     755                 :            : static bool
     756                 :          0 : mlx5_shared_rxq_match(struct mlx5_rxq_ctrl *rxq_ctrl, struct rte_eth_dev *dev,
     757                 :            :                       uint16_t idx, uint16_t desc, unsigned int socket,
     758                 :            :                       const struct rte_eth_rxconf *conf,
     759                 :            :                       struct rte_mempool *mp)
     760                 :            : {
     761                 :          0 :         struct mlx5_priv *spriv = LIST_FIRST(&rxq_ctrl->owners)->priv;
     762                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     763                 :            :         unsigned int i;
     764                 :            : 
     765                 :            :         RTE_SET_USED(conf);
     766         [ #  # ]:          0 :         if (rxq_ctrl->socket != socket) {
     767                 :          0 :                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: socket mismatch",
     768                 :            :                         dev->data->port_id, idx);
     769                 :          0 :                 return false;
     770                 :            :         }
     771         [ #  # ]:          0 :         if (rxq_ctrl->rxq.elts_n != log2above(desc)) {
     772                 :          0 :                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: descriptor number mismatch",
     773                 :            :                         dev->data->port_id, idx);
     774                 :          0 :                 return false;
     775                 :            :         }
     776         [ #  # ]:          0 :         if (priv->mtu != spriv->mtu) {
     777                 :          0 :                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: mtu mismatch",
     778                 :            :                         dev->data->port_id, idx);
     779                 :          0 :                 return false;
     780                 :            :         }
     781                 :          0 :         if (priv->dev_data->dev_conf.intr_conf.rxq !=
     782         [ #  # ]:          0 :             spriv->dev_data->dev_conf.intr_conf.rxq) {
     783                 :          0 :                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: interrupt mismatch",
     784                 :            :                         dev->data->port_id, idx);
     785                 :          0 :                 return false;
     786                 :            :         }
     787   [ #  #  #  # ]:          0 :         if (mp != NULL && rxq_ctrl->rxq.mp != mp) {
     788                 :          0 :                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: mempool mismatch",
     789                 :            :                         dev->data->port_id, idx);
     790                 :          0 :                 return false;
     791         [ #  # ]:          0 :         } else if (mp == NULL) {
     792         [ #  # ]:          0 :                 if (conf->rx_nseg != rxq_ctrl->rxseg_n) {
     793                 :          0 :                         DRV_LOG(ERR, "port %u queue index %u failed to join shared group: segment number mismatch",
     794                 :            :                                 dev->data->port_id, idx);
     795                 :          0 :                         return false;
     796                 :            :                 }
     797         [ #  # ]:          0 :                 for (i = 0; i < conf->rx_nseg; i++) {
     798         [ #  # ]:          0 :                         if (memcmp(&conf->rx_seg[i].split, &rxq_ctrl->rxseg[i],
     799                 :            :                                    sizeof(struct rte_eth_rxseg_split))) {
     800                 :          0 :                                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: segment %u configuration mismatch",
     801                 :            :                                         dev->data->port_id, idx, i);
     802                 :          0 :                                 return false;
     803                 :            :                         }
     804                 :            :                 }
     805                 :            :         }
     806         [ #  # ]:          0 :         if (priv->config.hw_padding != spriv->config.hw_padding) {
     807                 :          0 :                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: padding mismatch",
     808                 :            :                         dev->data->port_id, idx);
     809                 :          0 :                 return false;
     810                 :            :         }
     811         [ #  # ]:          0 :         if (priv->config.cqe_comp != spriv->config.cqe_comp ||
     812         [ #  # ]:          0 :             (priv->config.cqe_comp &&
     813         [ #  # ]:          0 :              priv->config.cqe_comp_fmt != spriv->config.cqe_comp_fmt)) {
     814                 :          0 :                 DRV_LOG(ERR, "port %u queue index %u failed to join shared group: CQE compression mismatch",
     815                 :            :                         dev->data->port_id, idx);
     816                 :          0 :                 return false;
     817                 :            :         }
     818                 :            :         return true;
     819                 :            : }
     820                 :            : 
     821                 :            : /**
     822                 :            :  *
     823                 :            :  * @param dev
     824                 :            :  *   Pointer to Ethernet device structure.
     825                 :            :  * @param idx
     826                 :            :  *   RX queue index.
     827                 :            :  * @param desc
     828                 :            :  *   Number of descriptors to configure in queue.
     829                 :            :  * @param socket
     830                 :            :  *   NUMA socket on which memory must be allocated.
     831                 :            :  * @param[in] conf
     832                 :            :  *   Thresholds parameters.
     833                 :            :  * @param mp
     834                 :            :  *   Memory pool for buffer allocations.
     835                 :            :  *
     836                 :            :  * @return
     837                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     838                 :            :  */
     839                 :            : int
     840                 :          0 : mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
     841                 :            :                     unsigned int socket, const struct rte_eth_rxconf *conf,
     842                 :            :                     struct rte_mempool *mp)
     843                 :            : {
     844                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     845                 :            :         struct mlx5_rxq_priv *rxq;
     846                 :          0 :         struct mlx5_rxq_ctrl *rxq_ctrl = NULL;
     847                 :          0 :         struct rte_eth_rxseg_split *rx_seg =
     848                 :            :                                 (struct rte_eth_rxseg_split *)conf->rx_seg;
     849                 :          0 :         struct rte_eth_rxseg_split rx_single = {.mp = mp};
     850                 :          0 :         uint16_t n_seg = conf->rx_nseg;
     851                 :            :         int res;
     852                 :          0 :         uint64_t offloads = conf->offloads |
     853                 :          0 :                             dev->data->dev_conf.rxmode.offloads;
     854                 :            :         bool is_extmem = false;
     855                 :            : 
     856         [ #  # ]:          0 :         if ((offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) &&
     857         [ #  # ]:          0 :             !priv->sh->config.lro_allowed) {
     858                 :          0 :                 DRV_LOG(ERR,
     859                 :            :                         "Port %u queue %u LRO is configured but not allowed.",
     860                 :            :                         dev->data->port_id, idx);
     861                 :          0 :                 rte_errno = EINVAL;
     862                 :          0 :                 return -rte_errno;
     863                 :            :         }
     864         [ #  # ]:          0 :         if (mp) {
     865                 :            :                 /*
     866                 :            :                  * The parameters should be checked on rte_eth_dev layer.
     867                 :            :                  * If mp is specified it means the compatible configuration
     868                 :            :                  * without buffer split feature tuning.
     869                 :            :                  */
     870                 :            :                 rx_seg = &rx_single;
     871                 :            :                 n_seg = 1;
     872                 :          0 :                 is_extmem = rte_pktmbuf_priv_flags(mp) &
     873                 :            :                             RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF;
     874                 :            :         }
     875         [ #  # ]:          0 :         if (n_seg > 1) {
     876                 :            :                 /* The offloads should be checked on rte_eth_dev layer. */
     877                 :            :                 MLX5_ASSERT(offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
     878         [ #  # ]:          0 :                 if (!(offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
     879                 :          0 :                         DRV_LOG(ERR, "port %u queue index %u split "
     880                 :            :                                      "offload not configured",
     881                 :            :                                      dev->data->port_id, idx);
     882                 :          0 :                         rte_errno = ENOSPC;
     883                 :          0 :                         return -rte_errno;
     884                 :            :                 }
     885                 :            :                 MLX5_ASSERT(n_seg < MLX5_MAX_RXQ_NSEG);
     886                 :            :         }
     887         [ #  # ]:          0 :         if (conf->share_group > 0) {
     888         [ #  # ]:          0 :                 if (!priv->sh->cdev->config.hca_attr.mem_rq_rmp) {
     889                 :          0 :                         DRV_LOG(ERR, "port %u queue index %u shared Rx queue not supported by fw",
     890                 :            :                                      dev->data->port_id, idx);
     891                 :          0 :                         rte_errno = EINVAL;
     892                 :          0 :                         return -rte_errno;
     893                 :            :                 }
     894         [ #  # ]:          0 :                 if (priv->obj_ops.rxq_obj_new != devx_obj_ops.rxq_obj_new) {
     895                 :          0 :                         DRV_LOG(ERR, "port %u queue index %u shared Rx queue needs DevX api",
     896                 :            :                                      dev->data->port_id, idx);
     897                 :          0 :                         rte_errno = EINVAL;
     898                 :          0 :                         return -rte_errno;
     899                 :            :                 }
     900         [ #  # ]:          0 :                 if (conf->share_qid >= priv->rxqs_n) {
     901                 :          0 :                         DRV_LOG(ERR, "port %u shared Rx queue index %u > number of Rx queues %u",
     902                 :            :                                 dev->data->port_id, conf->share_qid,
     903                 :            :                                 priv->rxqs_n);
     904                 :          0 :                         rte_errno = EINVAL;
     905                 :          0 :                         return -rte_errno;
     906                 :            :                 }
     907         [ #  # ]:          0 :                 if (priv->config.mprq.enabled) {
     908                 :          0 :                         DRV_LOG(ERR, "port %u shared Rx queue index %u: not supported when MPRQ enabled",
     909                 :            :                                 dev->data->port_id, conf->share_qid);
     910                 :          0 :                         rte_errno = EINVAL;
     911                 :          0 :                         return -rte_errno;
     912                 :            :                 }
     913                 :            :                 /* Try to reuse shared RXQ. */
     914                 :          0 :                 rxq_ctrl = mlx5_shared_rxq_get(dev, conf->share_group,
     915                 :            :                                                conf->share_qid);
     916                 :          0 :                 res = mlx5_rx_queue_pre_setup(dev, idx, &desc, &rxq_ctrl);
     917         [ #  # ]:          0 :                 if (res)
     918                 :            :                         return res;
     919   [ #  #  #  # ]:          0 :                 if (rxq_ctrl != NULL &&
     920                 :          0 :                     !mlx5_shared_rxq_match(rxq_ctrl, dev, idx, desc, socket,
     921                 :            :                                            conf, mp)) {
     922                 :          0 :                         rte_errno = EINVAL;
     923                 :          0 :                         return -rte_errno;
     924                 :            :                 }
     925                 :            :         } else {
     926                 :          0 :                 res = mlx5_rx_queue_pre_setup(dev, idx, &desc, &rxq_ctrl);
     927         [ #  # ]:          0 :                 if (res)
     928                 :            :                         return res;
     929                 :            :         }
     930                 :            :         /* Allocate RXQ. */
     931                 :          0 :         rxq = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*rxq), 0,
     932                 :            :                           SOCKET_ID_ANY);
     933         [ #  # ]:          0 :         if (!rxq) {
     934                 :          0 :                 DRV_LOG(ERR, "port %u unable to allocate rx queue index %u private data",
     935                 :            :                         dev->data->port_id, idx);
     936                 :          0 :                 rte_errno = ENOMEM;
     937                 :          0 :                 return -rte_errno;
     938                 :            :         }
     939         [ #  # ]:          0 :         if (rxq_ctrl == NULL) {
     940                 :          0 :                 rxq_ctrl = mlx5_rxq_new(dev, idx, desc, socket, conf, rx_seg,
     941                 :            :                                         n_seg, is_extmem);
     942         [ #  # ]:          0 :                 if (rxq_ctrl == NULL) {
     943                 :          0 :                         DRV_LOG(ERR, "port %u unable to allocate rx queue index %u",
     944                 :            :                                 dev->data->port_id, idx);
     945                 :          0 :                         mlx5_free(rxq);
     946                 :          0 :                         rte_errno = ENOMEM;
     947                 :          0 :                         return -rte_errno;
     948                 :            :                 }
     949                 :            :         }
     950                 :          0 :         rxq->priv = priv;
     951                 :          0 :         rxq->idx = idx;
     952                 :          0 :         (*priv->rxq_privs)[idx] = rxq;
     953                 :            :         /* Join owner list. */
     954         [ #  # ]:          0 :         LIST_INSERT_HEAD(&rxq_ctrl->owners, rxq, owner_entry);
     955                 :          0 :         rxq->ctrl = rxq_ctrl;
     956                 :          0 :         rte_atomic_fetch_add_explicit(&rxq_ctrl->ctrl_ref, 1, rte_memory_order_relaxed);
     957                 :          0 :         mlx5_rxq_ref(dev, idx);
     958                 :          0 :         DRV_LOG(DEBUG, "port %u adding Rx queue %u to list",
     959                 :            :                 dev->data->port_id, idx);
     960                 :          0 :         dev->data->rx_queues[idx] = &rxq_ctrl->rxq;
     961                 :          0 :         return 0;
     962                 :            : }
     963                 :            : 
     964                 :            : /**
     965                 :            :  *
     966                 :            :  * @param dev
     967                 :            :  *   Pointer to Ethernet device structure.
     968                 :            :  * @param idx
     969                 :            :  *   RX queue index.
     970                 :            :  * @param desc
     971                 :            :  *   Number of descriptors to configure in queue.
     972                 :            :  * @param hairpin_conf
     973                 :            :  *   Hairpin configuration parameters.
     974                 :            :  *
     975                 :            :  * @return
     976                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     977                 :            :  */
     978                 :            : int
     979                 :          0 : mlx5_rx_hairpin_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
     980                 :            :                             uint16_t desc,
     981                 :            :                             const struct rte_eth_hairpin_conf *hairpin_conf)
     982                 :            : {
     983                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     984                 :            :         struct mlx5_rxq_priv *rxq;
     985                 :            :         struct mlx5_rxq_ctrl *rxq_ctrl;
     986                 :            :         int res;
     987                 :            : 
     988                 :          0 :         res = mlx5_rx_queue_pre_setup(dev, idx, &desc, NULL);
     989         [ #  # ]:          0 :         if (res)
     990                 :            :                 return res;
     991         [ #  # ]:          0 :         if (hairpin_conf->peer_count != 1) {
     992                 :          0 :                 rte_errno = EINVAL;
     993                 :          0 :                 DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue index %u"
     994                 :            :                         " peer count is %u", dev->data->port_id,
     995                 :            :                         idx, hairpin_conf->peer_count);
     996                 :          0 :                 return -rte_errno;
     997                 :            :         }
     998         [ #  # ]:          0 :         if (hairpin_conf->peers[0].port == dev->data->port_id) {
     999         [ #  # ]:          0 :                 if (hairpin_conf->peers[0].queue >= priv->txqs_n) {
    1000                 :          0 :                         rte_errno = EINVAL;
    1001                 :          0 :                         DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue"
    1002                 :            :                                 " index %u, Tx %u is larger than %u",
    1003                 :            :                                 dev->data->port_id, idx,
    1004                 :            :                                 hairpin_conf->peers[0].queue, priv->txqs_n);
    1005                 :          0 :                         return -rte_errno;
    1006                 :            :                 }
    1007                 :            :         } else {
    1008         [ #  # ]:          0 :                 if (hairpin_conf->manual_bind == 0 ||
    1009                 :            :                     hairpin_conf->tx_explicit == 0) {
    1010                 :          0 :                         rte_errno = EINVAL;
    1011                 :          0 :                         DRV_LOG(ERR, "port %u unable to setup Rx hairpin queue"
    1012                 :            :                                 " index %u peer port %u with attributes %u %u",
    1013                 :            :                                 dev->data->port_id, idx,
    1014                 :            :                                 hairpin_conf->peers[0].port,
    1015                 :            :                                 hairpin_conf->manual_bind,
    1016                 :            :                                 hairpin_conf->tx_explicit);
    1017                 :          0 :                         return -rte_errno;
    1018                 :            :                 }
    1019                 :            :         }
    1020                 :          0 :         rxq = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*rxq), 0,
    1021                 :            :                           SOCKET_ID_ANY);
    1022         [ #  # ]:          0 :         if (!rxq) {
    1023                 :          0 :                 DRV_LOG(ERR, "port %u unable to allocate hairpin rx queue index %u private data",
    1024                 :            :                         dev->data->port_id, idx);
    1025                 :          0 :                 rte_errno = ENOMEM;
    1026                 :          0 :                 return -rte_errno;
    1027                 :            :         }
    1028                 :          0 :         rxq->priv = priv;
    1029                 :          0 :         rxq->idx = idx;
    1030                 :          0 :         (*priv->rxq_privs)[idx] = rxq;
    1031                 :          0 :         rxq_ctrl = mlx5_rxq_hairpin_new(dev, rxq, desc, hairpin_conf);
    1032         [ #  # ]:          0 :         if (!rxq_ctrl) {
    1033                 :          0 :                 DRV_LOG(ERR, "port %u unable to allocate hairpin queue index %u",
    1034                 :            :                         dev->data->port_id, idx);
    1035                 :          0 :                 mlx5_free(rxq);
    1036                 :          0 :                 (*priv->rxq_privs)[idx] = NULL;
    1037                 :          0 :                 rte_errno = ENOMEM;
    1038                 :          0 :                 return -rte_errno;
    1039                 :            :         }
    1040                 :          0 :         DRV_LOG(DEBUG, "port %u adding hairpin Rx queue %u to list",
    1041                 :            :                 dev->data->port_id, idx);
    1042                 :          0 :         dev->data->rx_queues[idx] = &rxq_ctrl->rxq;
    1043                 :          0 :         return 0;
    1044                 :            : }
    1045                 :            : 
    1046                 :            : /**
    1047                 :            :  * DPDK callback to release a RX queue.
    1048                 :            :  *
    1049                 :            :  * @param dev
    1050                 :            :  *   Pointer to Ethernet device structure.
    1051                 :            :  * @param qid
    1052                 :            :  *   Receive queue index.
    1053                 :            :  */
    1054                 :            : void
    1055                 :          0 : mlx5_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    1056                 :            : {
    1057                 :          0 :         struct mlx5_rxq_data *rxq = dev->data->rx_queues[qid];
    1058                 :            : 
    1059         [ #  # ]:          0 :         if (rxq == NULL)
    1060                 :            :                 return;
    1061         [ #  # ]:          0 :         if (!mlx5_rxq_releasable(dev, qid))
    1062                 :          0 :                 rte_panic("port %u Rx queue %u is still used by a flow and"
    1063                 :            :                           " cannot be removed\n", dev->data->port_id, qid);
    1064                 :          0 :         mlx5_rxq_release(dev, qid);
    1065                 :            : }
    1066                 :            : 
    1067                 :            : /**
    1068                 :            :  * Allocate queue vector and fill epoll fd list for Rx interrupts.
    1069                 :            :  *
    1070                 :            :  * @param dev
    1071                 :            :  *   Pointer to Ethernet device.
    1072                 :            :  *
    1073                 :            :  * @return
    1074                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    1075                 :            :  */
    1076                 :            : int
    1077                 :          0 : mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev)
    1078                 :            : {
    1079                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1080                 :            :         unsigned int i;
    1081                 :          0 :         unsigned int rxqs_n = priv->rxqs_n;
    1082                 :          0 :         unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
    1083                 :            :         unsigned int count = 0;
    1084                 :          0 :         struct rte_intr_handle *intr_handle = dev->intr_handle;
    1085                 :            : 
    1086         [ #  # ]:          0 :         if (!dev->data->dev_conf.intr_conf.rxq)
    1087                 :            :                 return 0;
    1088                 :          0 :         mlx5_rx_intr_vec_disable(dev);
    1089         [ #  # ]:          0 :         if (rte_intr_vec_list_alloc(intr_handle, NULL, n)) {
    1090                 :          0 :                 DRV_LOG(ERR,
    1091                 :            :                         "port %u failed to allocate memory for interrupt"
    1092                 :            :                         " vector, Rx interrupts will not be supported",
    1093                 :            :                         dev->data->port_id);
    1094                 :          0 :                 rte_errno = ENOMEM;
    1095                 :          0 :                 return -rte_errno;
    1096                 :            :         }
    1097                 :            : 
    1098         [ #  # ]:          0 :         if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_EXT))
    1099                 :          0 :                 return -rte_errno;
    1100                 :            : 
    1101         [ #  # ]:          0 :         for (i = 0; i != n; ++i) {
    1102                 :            :                 /* This rxq obj must not be released in this function. */
    1103                 :          0 :                 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
    1104         [ #  # ]:          0 :                 struct mlx5_rxq_obj *rxq_obj = rxq ? rxq->ctrl->obj : NULL;
    1105                 :            :                 int rc;
    1106                 :            : 
    1107                 :            :                 /* Skip queues that cannot request interrupts. */
    1108   [ #  #  #  # ]:          0 :                 if (!rxq_obj || (!rxq_obj->ibv_channel &&
    1109         [ #  # ]:          0 :                                  !rxq_obj->devx_channel)) {
    1110                 :            :                         /* Use invalid intr_vec[] index to disable entry. */
    1111         [ #  # ]:          0 :                         if (rte_intr_vec_list_index_set(intr_handle, i,
    1112                 :            :                            RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
    1113                 :          0 :                                 return -rte_errno;
    1114                 :          0 :                         continue;
    1115                 :            :                 }
    1116                 :          0 :                 mlx5_rxq_ref(dev, i);
    1117         [ #  # ]:          0 :                 if (count >= RTE_MAX_RXTX_INTR_VEC_ID) {
    1118                 :          0 :                         DRV_LOG(ERR,
    1119                 :            :                                 "port %u too many Rx queues for interrupt"
    1120                 :            :                                 " vector size (%d), Rx interrupts cannot be"
    1121                 :            :                                 " enabled",
    1122                 :            :                                 dev->data->port_id, RTE_MAX_RXTX_INTR_VEC_ID);
    1123                 :          0 :                         mlx5_rx_intr_vec_disable(dev);
    1124                 :          0 :                         rte_errno = ENOMEM;
    1125                 :          0 :                         return -rte_errno;
    1126                 :            :                 }
    1127                 :          0 :                 rc = mlx5_os_set_nonblock_channel_fd(rxq_obj->fd);
    1128         [ #  # ]:          0 :                 if (rc < 0) {
    1129                 :          0 :                         rte_errno = errno;
    1130                 :          0 :                         DRV_LOG(ERR,
    1131                 :            :                                 "port %u failed to make Rx interrupt file"
    1132                 :            :                                 " descriptor %d non-blocking for queue index"
    1133                 :            :                                 " %d",
    1134                 :            :                                 dev->data->port_id, rxq_obj->fd, i);
    1135                 :          0 :                         mlx5_rx_intr_vec_disable(dev);
    1136                 :          0 :                         return -rte_errno;
    1137                 :            :                 }
    1138                 :            : 
    1139         [ #  # ]:          0 :                 if (rte_intr_vec_list_index_set(intr_handle, i,
    1140                 :          0 :                                         RTE_INTR_VEC_RXTX_OFFSET + count))
    1141                 :          0 :                         return -rte_errno;
    1142         [ #  # ]:          0 :                 if (rte_intr_efds_index_set(intr_handle, count,
    1143                 :            :                                                    rxq_obj->fd))
    1144                 :          0 :                         return -rte_errno;
    1145                 :            :                 count++;
    1146                 :            :         }
    1147         [ #  # ]:          0 :         if (!count)
    1148                 :          0 :                 mlx5_rx_intr_vec_disable(dev);
    1149         [ #  # ]:          0 :         else if (rte_intr_nb_efd_set(intr_handle, count))
    1150                 :          0 :                 return -rte_errno;
    1151                 :            :         return 0;
    1152                 :            : }
    1153                 :            : 
    1154                 :            : /**
    1155                 :            :  * Clean up Rx interrupts handler.
    1156                 :            :  *
    1157                 :            :  * @param dev
    1158                 :            :  *   Pointer to Ethernet device.
    1159                 :            :  */
    1160                 :            : void
    1161                 :          0 : mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev)
    1162                 :            : {
    1163                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1164                 :          0 :         struct rte_intr_handle *intr_handle = dev->intr_handle;
    1165                 :            :         unsigned int i;
    1166                 :          0 :         unsigned int rxqs_n = priv->rxqs_n;
    1167                 :          0 :         unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
    1168                 :            : 
    1169         [ #  # ]:          0 :         if (!dev->data->dev_conf.intr_conf.rxq)
    1170                 :            :                 return;
    1171         [ #  # ]:          0 :         if (rte_intr_vec_list_index_get(intr_handle, 0) < 0)
    1172                 :          0 :                 goto free;
    1173         [ #  # ]:          0 :         for (i = 0; i != n; ++i) {
    1174         [ #  # ]:          0 :                 if (rte_intr_vec_list_index_get(intr_handle, i) ==
    1175                 :            :                     RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID)
    1176                 :          0 :                         continue;
    1177                 :            :                 /**
    1178                 :            :                  * Need to access directly the queue to release the reference
    1179                 :            :                  * kept in mlx5_rx_intr_vec_enable().
    1180                 :            :                  */
    1181                 :          0 :                 mlx5_rxq_deref(dev, i);
    1182                 :            :         }
    1183                 :          0 : free:
    1184                 :          0 :         rte_intr_free_epoll_fd(intr_handle);
    1185                 :            : 
    1186                 :          0 :         rte_intr_vec_list_free(intr_handle);
    1187                 :            : 
    1188                 :          0 :         rte_intr_nb_efd_set(intr_handle, 0);
    1189                 :            : }
    1190                 :            : 
    1191                 :            : /**
    1192                 :            :  *  MLX5 CQ notification .
    1193                 :            :  *
    1194                 :            :  *  @param rxq
    1195                 :            :  *     Pointer to receive queue structure.
    1196                 :            :  *  @param sq_n_rxq
    1197                 :            :  *     Sequence number per receive queue .
    1198                 :            :  */
    1199                 :            : static inline void
    1200                 :          0 : mlx5_arm_cq(struct mlx5_rxq_data *rxq, int sq_n_rxq)
    1201                 :            : {
    1202                 :            :         int sq_n = 0;
    1203                 :            :         uint32_t doorbell_hi;
    1204                 :            :         uint64_t doorbell;
    1205                 :            : 
    1206                 :            :         sq_n = sq_n_rxq & MLX5_CQ_SQN_MASK;
    1207                 :          0 :         doorbell_hi = sq_n << MLX5_CQ_SQN_OFFSET | (rxq->cq_ci & MLX5_CI_MASK);
    1208                 :          0 :         doorbell = (uint64_t)doorbell_hi << 32;
    1209                 :          0 :         doorbell |= rxq->cqn;
    1210                 :          0 :         mlx5_doorbell_ring(&rxq->uar_data, rte_cpu_to_be_64(doorbell),
    1211         [ #  # ]:          0 :                            doorbell_hi, &rxq->cq_db[MLX5_CQ_ARM_DB], 0);
    1212                 :          0 : }
    1213                 :            : 
    1214                 :            : /**
    1215                 :            :  * DPDK callback for Rx queue interrupt enable.
    1216                 :            :  *
    1217                 :            :  * @param dev
    1218                 :            :  *   Pointer to Ethernet device structure.
    1219                 :            :  * @param rx_queue_id
    1220                 :            :  *   Rx queue number.
    1221                 :            :  *
    1222                 :            :  * @return
    1223                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    1224                 :            :  */
    1225                 :            : int
    1226                 :          0 : mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
    1227                 :            : {
    1228                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
    1229         [ #  # ]:          0 :         if (!rxq)
    1230                 :          0 :                 goto error;
    1231         [ #  # ]:          0 :         if (rxq->ctrl->irq) {
    1232         [ #  # ]:          0 :                 if (!rxq->ctrl->obj)
    1233                 :          0 :                         goto error;
    1234                 :          0 :                 mlx5_arm_cq(&rxq->ctrl->rxq, rxq->ctrl->rxq.cq_arm_sn);
    1235                 :            :         }
    1236                 :            :         return 0;
    1237                 :          0 : error:
    1238                 :          0 :         rte_errno = EINVAL;
    1239                 :          0 :         return -rte_errno;
    1240                 :            : }
    1241                 :            : 
    1242                 :            : /**
    1243                 :            :  * DPDK callback for Rx queue interrupt disable.
    1244                 :            :  *
    1245                 :            :  * @param dev
    1246                 :            :  *   Pointer to Ethernet device structure.
    1247                 :            :  * @param rx_queue_id
    1248                 :            :  *   Rx queue number.
    1249                 :            :  *
    1250                 :            :  * @return
    1251                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    1252                 :            :  */
    1253                 :            : int
    1254                 :          0 : mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
    1255                 :            : {
    1256                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1257                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id);
    1258                 :            :         int ret = 0;
    1259                 :            : 
    1260         [ #  # ]:          0 :         if (!rxq) {
    1261                 :          0 :                 rte_errno = EINVAL;
    1262                 :          0 :                 return -rte_errno;
    1263                 :            :         }
    1264         [ #  # ]:          0 :         if (!rxq->ctrl->obj)
    1265                 :          0 :                 goto error;
    1266         [ #  # ]:          0 :         if (rxq->ctrl->irq) {
    1267                 :          0 :                 ret = priv->obj_ops.rxq_event_get(rxq->ctrl->obj);
    1268         [ #  # ]:          0 :                 if (ret < 0)
    1269                 :          0 :                         goto error;
    1270                 :          0 :                 rxq->ctrl->rxq.cq_arm_sn++;
    1271                 :            :         }
    1272                 :            :         return 0;
    1273                 :            : error:
    1274                 :            :         /**
    1275                 :            :          * The ret variable may be EAGAIN which means the get_event function was
    1276                 :            :          * called before receiving one.
    1277                 :            :          */
    1278                 :            :         if (ret < 0)
    1279                 :          0 :                 rte_errno = errno;
    1280                 :            :         else
    1281                 :          0 :                 rte_errno = EINVAL;
    1282         [ #  # ]:          0 :         if (rte_errno != EAGAIN)
    1283                 :          0 :                 DRV_LOG(WARNING, "port %u unable to disable interrupt on Rx queue %d",
    1284                 :            :                         dev->data->port_id, rx_queue_id);
    1285                 :          0 :         return -rte_errno;
    1286                 :            : }
    1287                 :            : 
    1288                 :            : /**
    1289                 :            :  * Verify the Rx queue objects list is empty
    1290                 :            :  *
    1291                 :            :  * @param dev
    1292                 :            :  *   Pointer to Ethernet device.
    1293                 :            :  *
    1294                 :            :  * @return
    1295                 :            :  *   The number of objects not released.
    1296                 :            :  */
    1297                 :            : int
    1298                 :          0 : mlx5_rxq_obj_verify(struct rte_eth_dev *dev)
    1299                 :            : {
    1300                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1301                 :            :         int ret = 0;
    1302                 :            :         struct mlx5_rxq_obj *rxq_obj;
    1303                 :            : 
    1304         [ #  # ]:          0 :         LIST_FOREACH(rxq_obj, &priv->rxqsobj, next) {
    1305         [ #  # ]:          0 :                 if (rxq_obj->rxq_ctrl == NULL)
    1306                 :          0 :                         continue;
    1307         [ #  # ]:          0 :                 if (rxq_obj->rxq_ctrl->rxq.shared &&
    1308         [ #  # ]:          0 :                     !LIST_EMPTY(&rxq_obj->rxq_ctrl->owners))
    1309                 :          0 :                         continue;
    1310                 :          0 :                 DRV_LOG(DEBUG, "port %u Rx queue %u still referenced",
    1311                 :            :                         dev->data->port_id, rxq_obj->rxq_ctrl->rxq.idx);
    1312                 :          0 :                 ++ret;
    1313                 :            :         }
    1314                 :          0 :         return ret;
    1315                 :            : }
    1316                 :            : 
    1317                 :            : /**
    1318                 :            :  * Destroy all queue counters.
    1319                 :            :  *
    1320                 :            :  * @param dev
    1321                 :            :  *   Pointer to Ethernet device.
    1322                 :            :  */
    1323                 :            : void
    1324                 :          0 : mlx5_q_counters_destroy(struct rte_eth_dev *dev)
    1325                 :            : {
    1326                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1327                 :            :         unsigned int i;
    1328                 :            : 
    1329                 :            :         /* Destroy port q counter */
    1330         [ #  # ]:          0 :         if (priv->q_counters) {
    1331                 :          0 :                 mlx5_devx_cmd_destroy(priv->q_counters);
    1332                 :          0 :                 priv->q_counters = NULL;
    1333                 :            :         }
    1334                 :            : 
    1335                 :            :         /* Destroy port global hairpin q counter */
    1336         [ #  # ]:          0 :         if (priv->q_counter_hairpin) {
    1337                 :          0 :                 mlx5_devx_cmd_destroy(priv->q_counter_hairpin);
    1338                 :          0 :                 priv->q_counter_hairpin = NULL;
    1339                 :            :         }
    1340                 :            : 
    1341                 :            :         /* Destroy per hairpin queue counter */
    1342         [ #  # ]:          0 :         for (i = 0; i != priv->rxqs_n; ++i) {
    1343                 :          0 :                 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
    1344                 :            : 
    1345   [ #  #  #  # ]:          0 :                 if (rxq == NULL || rxq->q_counter == NULL)
    1346                 :          0 :                         continue;
    1347                 :            : 
    1348                 :          0 :                 mlx5_devx_cmd_destroy(rxq->q_counter);
    1349                 :          0 :                 rxq->q_counter = NULL;
    1350                 :            :         }
    1351                 :          0 : }
    1352                 :            : 
    1353                 :            : /**
    1354                 :            :  * Callback function to initialize mbufs for Multi-Packet RQ.
    1355                 :            :  */
    1356                 :            : static inline void
    1357                 :          0 : mlx5_mprq_buf_init(struct rte_mempool *mp, void *opaque_arg,
    1358                 :            :                     void *_m, unsigned int i __rte_unused)
    1359                 :            : {
    1360                 :            :         struct mlx5_mprq_buf *buf = _m;
    1361                 :            :         struct rte_mbuf_ext_shared_info *shinfo;
    1362                 :          0 :         unsigned int strd_n = (unsigned int)(uintptr_t)opaque_arg;
    1363                 :            :         unsigned int j;
    1364                 :            : 
    1365                 :            :         memset(_m, 0, sizeof(*buf));
    1366                 :          0 :         buf->mp = mp;
    1367                 :          0 :         rte_atomic_store_explicit(&buf->refcnt, 1, rte_memory_order_relaxed);
    1368         [ #  # ]:          0 :         for (j = 0; j != strd_n; ++j) {
    1369                 :            :                 shinfo = &buf->shinfos[j];
    1370                 :          0 :                 shinfo->free_cb = mlx5_mprq_buf_free_cb;
    1371                 :          0 :                 shinfo->fcb_opaque = buf;
    1372                 :            :         }
    1373                 :          0 : }
    1374                 :            : 
    1375                 :            : /**
    1376                 :            :  * Free mempool of Multi-Packet RQ.
    1377                 :            :  *
    1378                 :            :  * @param dev
    1379                 :            :  *   Pointer to Ethernet device.
    1380                 :            :  *
    1381                 :            :  * @return
    1382                 :            :  *   0 on success, negative errno value on failure.
    1383                 :            :  */
    1384                 :            : int
    1385                 :          0 : mlx5_mprq_free_mp(struct rte_eth_dev *dev)
    1386                 :            : {
    1387                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1388                 :          0 :         struct rte_mempool *mp = priv->mprq_mp;
    1389                 :            :         unsigned int i;
    1390                 :            : 
    1391         [ #  # ]:          0 :         if (mp == NULL)
    1392                 :            :                 return 0;
    1393                 :          0 :         DRV_LOG(DEBUG, "port %u freeing mempool (%s) for Multi-Packet RQ",
    1394                 :            :                 dev->data->port_id, mp->name);
    1395                 :            :         /*
    1396                 :            :          * If a buffer in the pool has been externally attached to a mbuf and it
    1397                 :            :          * is still in use by application, destroying the Rx queue can spoil
    1398                 :            :          * the packet. It is unlikely to happen but if application dynamically
    1399                 :            :          * creates and destroys with holding Rx packets, this can happen.
    1400                 :            :          *
    1401                 :            :          * TODO: It is unavoidable for now because the mempool for Multi-Packet
    1402                 :            :          * RQ isn't provided by application but managed by PMD.
    1403                 :            :          */
    1404         [ #  # ]:          0 :         if (!rte_mempool_full(mp)) {
    1405                 :          0 :                 DRV_LOG(ERR,
    1406                 :            :                         "port %u mempool for Multi-Packet RQ is still in use",
    1407                 :            :                         dev->data->port_id);
    1408                 :          0 :                 rte_errno = EBUSY;
    1409                 :          0 :                 return -rte_errno;
    1410                 :            :         }
    1411                 :          0 :         rte_mempool_free(mp);
    1412                 :            :         /* Unset mempool for each Rx queue. */
    1413         [ #  # ]:          0 :         for (i = 0; i != priv->rxqs_n; ++i) {
    1414                 :          0 :                 struct mlx5_rxq_data *rxq = mlx5_rxq_data_get(dev, i);
    1415                 :            : 
    1416         [ #  # ]:          0 :                 if (rxq == NULL)
    1417                 :          0 :                         continue;
    1418                 :          0 :                 rxq->mprq_mp = NULL;
    1419                 :            :         }
    1420                 :          0 :         priv->mprq_mp = NULL;
    1421                 :          0 :         return 0;
    1422                 :            : }
    1423                 :            : 
    1424                 :            : /**
    1425                 :            :  * Allocate a mempool for Multi-Packet RQ. All configured Rx queues share the
    1426                 :            :  * mempool. If already allocated, reuse it if there're enough elements.
    1427                 :            :  * Otherwise, resize it.
    1428                 :            :  *
    1429                 :            :  * @param dev
    1430                 :            :  *   Pointer to Ethernet device.
    1431                 :            :  *
    1432                 :            :  * @return
    1433                 :            :  *   0 on success, negative errno value on failure.
    1434                 :            :  */
    1435                 :            : int
    1436                 :          0 : mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)
    1437                 :            : {
    1438                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1439         [ #  # ]:          0 :         struct rte_mempool *mp = priv->mprq_mp;
    1440                 :            :         char name[RTE_MEMPOOL_NAMESIZE];
    1441                 :            :         unsigned int desc = 0;
    1442                 :            :         unsigned int buf_len;
    1443                 :            :         unsigned int obj_num;
    1444                 :            :         unsigned int obj_size;
    1445                 :            :         unsigned int log_strd_num = 0;
    1446                 :            :         unsigned int log_strd_sz = 0;
    1447                 :            :         unsigned int i;
    1448                 :            :         unsigned int n_ibv = 0;
    1449                 :            :         int ret;
    1450                 :            : 
    1451         [ #  # ]:          0 :         if (!mlx5_mprq_enabled(dev))
    1452                 :          0 :                 return 0;
    1453                 :            :         /* Count the total number of descriptors configured. */
    1454         [ #  # ]:          0 :         for (i = 0; i != priv->rxqs_n; ++i) {
    1455                 :          0 :                 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
    1456                 :            :                 struct mlx5_rxq_data *rxq;
    1457                 :            : 
    1458   [ #  #  #  # ]:          0 :                 if (rxq_ctrl == NULL || rxq_ctrl->is_hairpin)
    1459                 :          0 :                         continue;
    1460                 :            :                 rxq = &rxq_ctrl->rxq;
    1461                 :          0 :                 n_ibv++;
    1462                 :          0 :                 desc += 1 << rxq->elts_n;
    1463                 :            :                 /* Get the max number of strides. */
    1464                 :          0 :                 if (log_strd_num < rxq->log_strd_num)
    1465                 :            :                         log_strd_num = rxq->log_strd_num;
    1466                 :            :                 /* Get the max size of a stride. */
    1467                 :          0 :                 if (log_strd_sz < rxq->log_strd_sz)
    1468                 :            :                         log_strd_sz = rxq->log_strd_sz;
    1469                 :            :         }
    1470                 :            :         MLX5_ASSERT(log_strd_num && log_strd_sz);
    1471                 :          0 :         buf_len = RTE_BIT32(log_strd_num) * RTE_BIT32(log_strd_sz);
    1472                 :          0 :         obj_size = sizeof(struct mlx5_mprq_buf) + buf_len +
    1473                 :          0 :                    RTE_BIT32(log_strd_num) *
    1474                 :            :                    sizeof(struct rte_mbuf_ext_shared_info) +
    1475                 :            :                    RTE_PKTMBUF_HEADROOM;
    1476                 :            :         /*
    1477                 :            :          * Received packets can be either memcpy'd or externally referenced. In
    1478                 :            :          * case that the packet is attached to an mbuf as an external buffer, as
    1479                 :            :          * it isn't possible to predict how the buffers will be queued by
    1480                 :            :          * application, there's no option to exactly pre-allocate needed buffers
    1481                 :            :          * in advance but to speculatively prepares enough buffers.
    1482                 :            :          *
    1483                 :            :          * In the data path, if this Mempool is depleted, PMD will try to memcpy
    1484                 :            :          * received packets to buffers provided by application (rxq->mp) until
    1485                 :            :          * this Mempool gets available again.
    1486                 :            :          */
    1487                 :          0 :         desc *= 4;
    1488                 :          0 :         obj_num = desc + MLX5_MPRQ_MP_CACHE_SZ * n_ibv;
    1489                 :            :         /*
    1490                 :            :          * rte_mempool_create_empty() has sanity check to refuse large cache
    1491                 :            :          * size compared to the number of elements.
    1492                 :            :          * CALC_CACHE_FLUSHTHRESH() is defined in a C file, so using a
    1493                 :            :          * constant number 2 instead.
    1494                 :            :          */
    1495                 :          0 :         obj_num = RTE_MAX(obj_num, MLX5_MPRQ_MP_CACHE_SZ * 2);
    1496                 :            :         /* Check a mempool is already allocated and if it can be resued. */
    1497   [ #  #  #  #  :          0 :         if (mp != NULL && mp->elt_size >= obj_size && mp->size >= obj_num) {
                   #  # ]
    1498                 :          0 :                 DRV_LOG(DEBUG, "port %u mempool %s is being reused",
    1499                 :            :                         dev->data->port_id, mp->name);
    1500                 :            :                 /* Reuse. */
    1501                 :          0 :                 goto exit;
    1502         [ #  # ]:          0 :         } else if (mp != NULL) {
    1503                 :          0 :                 DRV_LOG(DEBUG, "port %u mempool %s should be resized, freeing it",
    1504                 :            :                         dev->data->port_id, mp->name);
    1505                 :            :                 /*
    1506                 :            :                  * If failed to free, which means it may be still in use, no way
    1507                 :            :                  * but to keep using the existing one. On buffer underrun,
    1508                 :            :                  * packets will be memcpy'd instead of external buffer
    1509                 :            :                  * attachment.
    1510                 :            :                  */
    1511         [ #  # ]:          0 :                 if (mlx5_mprq_free_mp(dev)) {
    1512         [ #  # ]:          0 :                         if (mp->elt_size >= obj_size)
    1513                 :          0 :                                 goto exit;
    1514                 :            :                         else
    1515                 :          0 :                                 return -rte_errno;
    1516                 :            :                 }
    1517                 :            :         }
    1518                 :          0 :         snprintf(name, sizeof(name), "port-%u-mprq", dev->data->port_id);
    1519                 :          0 :         mp = rte_mempool_create(name, obj_num, obj_size, MLX5_MPRQ_MP_CACHE_SZ,
    1520                 :            :                                 0, NULL, NULL, mlx5_mprq_buf_init,
    1521                 :          0 :                                 (void *)((uintptr_t)1 << log_strd_num),
    1522                 :          0 :                                 dev->device->numa_node, 0);
    1523         [ #  # ]:          0 :         if (mp == NULL) {
    1524                 :          0 :                 DRV_LOG(ERR,
    1525                 :            :                         "port %u failed to allocate a mempool for"
    1526                 :            :                         " Multi-Packet RQ, count=%u, size=%u",
    1527                 :            :                         dev->data->port_id, obj_num, obj_size);
    1528                 :          0 :                 rte_errno = ENOMEM;
    1529                 :          0 :                 return -rte_errno;
    1530                 :            :         }
    1531                 :          0 :         ret = mlx5_mr_mempool_register(priv->sh->cdev, mp, false);
    1532   [ #  #  #  # ]:          0 :         if (ret < 0 && rte_errno != EEXIST) {
    1533                 :            :                 ret = rte_errno;
    1534                 :          0 :                 DRV_LOG(ERR, "port %u failed to register a mempool for Multi-Packet RQ",
    1535                 :            :                         dev->data->port_id);
    1536                 :          0 :                 rte_mempool_free(mp);
    1537                 :          0 :                 rte_errno = ret;
    1538                 :          0 :                 return -rte_errno;
    1539                 :            :         }
    1540                 :          0 :         priv->mprq_mp = mp;
    1541                 :          0 : exit:
    1542                 :            :         /* Set mempool for each Rx queue. */
    1543         [ #  # ]:          0 :         for (i = 0; i != priv->rxqs_n; ++i) {
    1544                 :          0 :                 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
    1545                 :            : 
    1546   [ #  #  #  # ]:          0 :                 if (rxq_ctrl == NULL || rxq_ctrl->is_hairpin)
    1547                 :          0 :                         continue;
    1548                 :          0 :                 rxq_ctrl->rxq.mprq_mp = mp;
    1549                 :            :         }
    1550                 :          0 :         DRV_LOG(INFO, "port %u Multi-Packet RQ is configured",
    1551                 :            :                 dev->data->port_id);
    1552                 :          0 :         return 0;
    1553                 :            : }
    1554                 :            : 
    1555                 :            : #define MLX5_MAX_TCP_HDR_OFFSET ((unsigned int)(sizeof(struct rte_ether_hdr) + \
    1556                 :            :                                         sizeof(struct rte_vlan_hdr) * 2 + \
    1557                 :            :                                         sizeof(struct rte_ipv6_hdr)))
    1558                 :            : #define MAX_TCP_OPTION_SIZE 40u
    1559                 :            : #define MLX5_MAX_LRO_HEADER_FIX ((unsigned int)(MLX5_MAX_TCP_HDR_OFFSET + \
    1560                 :            :                                  sizeof(struct rte_tcp_hdr) + \
    1561                 :            :                                  MAX_TCP_OPTION_SIZE))
    1562                 :            : 
    1563                 :            : /**
    1564                 :            :  * Adjust the maximum LRO massage size.
    1565                 :            :  *
    1566                 :            :  * @param dev
    1567                 :            :  *   Pointer to Ethernet device.
    1568                 :            :  * @param idx
    1569                 :            :  *   RX queue index.
    1570                 :            :  * @param max_lro_size
    1571                 :            :  *   The maximum size for LRO packet.
    1572                 :            :  */
    1573                 :            : static void
    1574                 :          0 : mlx5_max_lro_msg_size_adjust(struct rte_eth_dev *dev, uint16_t idx,
    1575                 :            :                              uint32_t max_lro_size)
    1576                 :            : {
    1577                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1578                 :            : 
    1579         [ #  # ]:          0 :         if (priv->sh->cdev->config.hca_attr.lro_max_msg_sz_mode ==
    1580         [ #  # ]:          0 :             MLX5_LRO_MAX_MSG_SIZE_START_FROM_L4 && max_lro_size >
    1581                 :            :             MLX5_MAX_TCP_HDR_OFFSET)
    1582                 :          0 :                 max_lro_size -= MLX5_MAX_TCP_HDR_OFFSET;
    1583                 :          0 :         max_lro_size = RTE_MIN(max_lro_size, MLX5_MAX_LRO_SIZE);
    1584         [ #  # ]:          0 :         if (priv->max_lro_msg_size)
    1585                 :          0 :                 priv->max_lro_msg_size =
    1586                 :          0 :                         RTE_MIN((uint32_t)priv->max_lro_msg_size, max_lro_size);
    1587                 :            :         else
    1588                 :          0 :                 priv->max_lro_msg_size = max_lro_size;
    1589                 :          0 :         DRV_LOG(DEBUG,
    1590                 :            :                 "port %u Rx Queue %u max LRO message size adjusted to %u bytes",
    1591                 :            :                 dev->data->port_id, idx, priv->max_lro_msg_size);
    1592                 :          0 : }
    1593                 :            : 
    1594                 :            : /**
    1595                 :            :  * Prepare both size and number of stride for Multi-Packet RQ.
    1596                 :            :  *
    1597                 :            :  * @param dev
    1598                 :            :  *   Pointer to Ethernet device.
    1599                 :            :  * @param idx
    1600                 :            :  *   RX queue index.
    1601                 :            :  * @param desc
    1602                 :            :  *   Number of descriptors to configure in queue.
    1603                 :            :  * @param rx_seg_en
    1604                 :            :  *   Indicator if Rx segment enables, if so Multi-Packet RQ doesn't enable.
    1605                 :            :  * @param min_mbuf_size
    1606                 :            :  *   Non scatter min mbuf size, max_rx_pktlen plus overhead.
    1607                 :            :  * @param actual_log_stride_num
    1608                 :            :  *   Log number of strides to configure for this queue.
    1609                 :            :  * @param actual_log_stride_size
    1610                 :            :  *   Log stride size to configure for this queue.
    1611                 :            :  * @param is_extmem
    1612                 :            :  *   Is external pinned memory pool used.
    1613                 :            :  * @return
    1614                 :            :  *   0 if Multi-Packet RQ is supported, otherwise -1.
    1615                 :            :  */
    1616                 :            : static int
    1617                 :          0 : mlx5_mprq_prepare(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
    1618                 :            :                   bool rx_seg_en, uint32_t min_mbuf_size,
    1619                 :            :                   uint32_t *actual_log_stride_num,
    1620                 :            :                   uint32_t *actual_log_stride_size,
    1621                 :            :                   bool is_extmem)
    1622                 :            : {
    1623                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1624                 :            :         struct mlx5_port_config *config = &priv->config;
    1625                 :          0 :         struct mlx5_dev_cap *dev_cap = &priv->sh->dev_cap;
    1626                 :          0 :         uint32_t log_min_stride_num = dev_cap->mprq.log_min_stride_num;
    1627                 :          0 :         uint32_t log_max_stride_num = dev_cap->mprq.log_max_stride_num;
    1628                 :            :         uint32_t log_def_stride_num =
    1629                 :          0 :                         RTE_MIN(RTE_MAX(MLX5_MPRQ_DEFAULT_LOG_STRIDE_NUM,
    1630                 :            :                                         log_min_stride_num),
    1631                 :            :                                 log_max_stride_num);
    1632                 :          0 :         uint32_t log_min_stride_size = dev_cap->mprq.log_min_stride_size;
    1633                 :          0 :         uint32_t log_max_stride_size = dev_cap->mprq.log_max_stride_size;
    1634                 :            :         uint32_t log_def_stride_size =
    1635         [ #  # ]:          0 :                         RTE_MIN(RTE_MAX(MLX5_MPRQ_DEFAULT_LOG_STRIDE_SIZE,
    1636                 :            :                                         log_min_stride_size),
    1637                 :            :                                 log_max_stride_size);
    1638                 :            :         uint32_t log_stride_wqe_size;
    1639                 :            : 
    1640         [ #  # ]:          0 :         if (mlx5_check_mprq_support(dev) != 1 || rx_seg_en || is_extmem)
    1641                 :          0 :                 goto unsupport;
    1642                 :            :         /* Checks if chosen number of strides is in supported range. */
    1643   [ #  #  #  # ]:          0 :         if (config->mprq.log_stride_num > log_max_stride_num ||
    1644                 :            :             config->mprq.log_stride_num < log_min_stride_num) {
    1645                 :          0 :                 *actual_log_stride_num = log_def_stride_num;
    1646                 :          0 :                 DRV_LOG(WARNING,
    1647                 :            :                         "Port %u Rx queue %u number of strides for Multi-Packet RQ is out of range, setting default value (%u)",
    1648                 :            :                         dev->data->port_id, idx, RTE_BIT32(log_def_stride_num));
    1649                 :            :         } else {
    1650                 :          0 :                 *actual_log_stride_num = config->mprq.log_stride_num;
    1651                 :            :         }
    1652                 :            :         /* Checks if chosen size of stride is in supported range. */
    1653         [ #  # ]:          0 :         if (config->mprq.log_stride_size != (uint32_t)MLX5_ARG_UNSET) {
    1654   [ #  #  #  # ]:          0 :                 if (config->mprq.log_stride_size > log_max_stride_size ||
    1655                 :            :                         config->mprq.log_stride_size < log_min_stride_size) {
    1656                 :          0 :                         *actual_log_stride_size = log_def_stride_size;
    1657                 :          0 :                         DRV_LOG(WARNING,
    1658                 :            :                                 "Port %u Rx queue %u size of a stride for Multi-Packet RQ is out of range, setting default value (%u)",
    1659                 :            :                                 dev->data->port_id, idx,
    1660                 :            :                                 RTE_BIT32(log_def_stride_size));
    1661                 :            :                 } else {
    1662                 :          0 :                         *actual_log_stride_size = config->mprq.log_stride_size;
    1663                 :            :                 }
    1664                 :            :         } else {
    1665                 :            :                 /* Make the stride fit the mbuf size by default. */
    1666         [ #  # ]:          0 :                 if (min_mbuf_size <= RTE_BIT32(log_max_stride_size)) {
    1667                 :          0 :                         DRV_LOG(WARNING,
    1668                 :            :                                 "Port %u Rx queue %u size of a stride for Multi-Packet RQ is adjusted to match the mbuf size (%u)",
    1669                 :            :                                 dev->data->port_id, idx, min_mbuf_size);
    1670                 :          0 :                         *actual_log_stride_size = log2above(min_mbuf_size);
    1671                 :            :                 } else {
    1672                 :          0 :                         goto unsupport;
    1673                 :            :                 }
    1674                 :            :         }
    1675                 :            :         /* Make sure the stride size is greater than the headroom. */
    1676         [ #  # ]:          0 :         if (RTE_BIT32(*actual_log_stride_size) < RTE_PKTMBUF_HEADROOM) {
    1677         [ #  # ]:          0 :                 if (RTE_BIT32(log_max_stride_size) > RTE_PKTMBUF_HEADROOM) {
    1678                 :          0 :                         DRV_LOG(WARNING,
    1679                 :            :                                 "Port %u Rx queue %u size of a stride for Multi-Packet RQ is adjusted to accommodate the headroom (%u)",
    1680                 :            :                                 dev->data->port_id, idx, RTE_PKTMBUF_HEADROOM);
    1681                 :          0 :                         *actual_log_stride_size = log2above(RTE_PKTMBUF_HEADROOM);
    1682                 :            :                 } else {
    1683                 :          0 :                         goto unsupport;
    1684                 :            :                 }
    1685                 :            :         }
    1686                 :          0 :         log_stride_wqe_size = *actual_log_stride_num + *actual_log_stride_size;
    1687                 :            :         /* Check if WQE buffer size is supported by hardware. */
    1688         [ #  # ]:          0 :         if (log_stride_wqe_size < dev_cap->mprq.log_min_stride_wqe_size) {
    1689                 :          0 :                 *actual_log_stride_num = log_def_stride_num;
    1690                 :          0 :                 *actual_log_stride_size = log_def_stride_size;
    1691                 :          0 :                 DRV_LOG(WARNING,
    1692                 :            :                         "Port %u Rx queue %u size of WQE buffer for Multi-Packet RQ is too small, setting default values (stride_num_n=%u, stride_size_n=%u)",
    1693                 :            :                         dev->data->port_id, idx, RTE_BIT32(log_def_stride_num),
    1694                 :            :                         RTE_BIT32(log_def_stride_size));
    1695                 :          0 :                 log_stride_wqe_size = log_def_stride_num + log_def_stride_size;
    1696                 :            :         }
    1697                 :            :         MLX5_ASSERT(log_stride_wqe_size >=
    1698                 :            :                     dev_cap->mprq.log_min_stride_wqe_size);
    1699         [ #  # ]:          0 :         if (desc <= RTE_BIT32(*actual_log_stride_num))
    1700                 :          0 :                 goto unsupport;
    1701         [ #  # ]:          0 :         if (min_mbuf_size > RTE_BIT32(log_stride_wqe_size)) {
    1702                 :          0 :                 DRV_LOG(WARNING, "Port %u Rx queue %u "
    1703                 :            :                         "Multi-Packet RQ is unsupported, WQE buffer size (%u) "
    1704                 :            :                         "is smaller than min mbuf size (%u)",
    1705                 :            :                         dev->data->port_id, idx, RTE_BIT32(log_stride_wqe_size),
    1706                 :            :                         min_mbuf_size);
    1707                 :          0 :                 goto unsupport;
    1708                 :            :         }
    1709                 :          0 :         DRV_LOG(DEBUG, "Port %u Rx queue %u "
    1710                 :            :                 "Multi-Packet RQ is enabled strd_num_n = %u, strd_sz_n = %u",
    1711                 :            :                 dev->data->port_id, idx, RTE_BIT32(*actual_log_stride_num),
    1712                 :            :                 RTE_BIT32(*actual_log_stride_size));
    1713                 :          0 :         return 0;
    1714                 :          0 : unsupport:
    1715         [ #  # ]:          0 :         if (config->mprq.enabled)
    1716   [ #  #  #  #  :          0 :                 DRV_LOG(WARNING,
                   #  # ]
    1717                 :            :                         "Port %u MPRQ is requested but cannot be enabled\n"
    1718                 :            :                         " (requested: pkt_sz = %u, desc_num = %u,"
    1719                 :            :                         " rxq_num = %u, stride_sz = %u, stride_num = %u\n"
    1720                 :            :                         "  supported: min_rxqs_num = %u, min_buf_wqe_sz = %u"
    1721                 :            :                         " min_stride_sz = %u, max_stride_sz = %u).\n"
    1722                 :            :                         "Rx segment is %senabled. External mempool is %sused.",
    1723                 :            :                         dev->data->port_id, min_mbuf_size, desc, priv->rxqs_n,
    1724                 :            :                         config->mprq.log_stride_size == (uint32_t)MLX5_ARG_UNSET ?
    1725                 :            :                         RTE_BIT32(MLX5_MPRQ_DEFAULT_LOG_STRIDE_SIZE) :
    1726                 :            :                         RTE_BIT32(config->mprq.log_stride_size),
    1727                 :            :                         RTE_BIT32(config->mprq.log_stride_num),
    1728                 :            :                         config->mprq.min_rxqs_num,
    1729                 :            :                         RTE_BIT32(dev_cap->mprq.log_min_stride_wqe_size),
    1730                 :            :                         RTE_BIT32(dev_cap->mprq.log_min_stride_size),
    1731                 :            :                         RTE_BIT32(dev_cap->mprq.log_max_stride_size),
    1732                 :            :                         rx_seg_en ? "" : "not ", is_extmem ? "" : "not ");
    1733                 :            :         return -1;
    1734                 :            : }
    1735                 :            : 
    1736                 :            : /**
    1737                 :            :  * Create a DPDK Rx queue.
    1738                 :            :  *
    1739                 :            :  * @param dev
    1740                 :            :  *   Pointer to Ethernet device.
    1741                 :            :  * @param idx
    1742                 :            :  *   RX queue index.
    1743                 :            :  * @param desc
    1744                 :            :  *   Number of descriptors to configure in queue.
    1745                 :            :  * @param socket
    1746                 :            :  *   NUMA socket on which memory must be allocated.
    1747                 :            :  *
    1748                 :            :  * @return
    1749                 :            :  *   A DPDK queue object on success, NULL otherwise and rte_errno is set.
    1750                 :            :  */
    1751                 :            : struct mlx5_rxq_ctrl *
    1752                 :          0 : mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
    1753                 :            :              unsigned int socket, const struct rte_eth_rxconf *conf,
    1754                 :            :              const struct rte_eth_rxseg_split *rx_seg, uint16_t n_seg,
    1755                 :            :              bool is_extmem)
    1756                 :            : {
    1757                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1758                 :            :         struct mlx5_rxq_ctrl *tmpl;
    1759         [ #  # ]:          0 :         unsigned int mb_len = rte_pktmbuf_data_room_size(rx_seg[0].mp);
    1760                 :            :         struct mlx5_port_config *config = &priv->config;
    1761                 :          0 :         uint64_t offloads = conf->offloads |
    1762                 :          0 :                            dev->data->dev_conf.rxmode.offloads;
    1763                 :          0 :         unsigned int lro_on_queue = !!(offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO);
    1764                 :            :         unsigned int max_rx_pktlen = lro_on_queue ?
    1765         [ #  # ]:          0 :                         dev->data->dev_conf.rxmode.max_lro_pkt_size :
    1766                 :          0 :                         dev->data->mtu + (unsigned int)RTE_ETHER_HDR_LEN +
    1767                 :            :                                 RTE_ETHER_CRC_LEN;
    1768                 :          0 :         unsigned int non_scatter_min_mbuf_size = max_rx_pktlen +
    1769                 :            :                                                         RTE_PKTMBUF_HEADROOM;
    1770                 :            :         unsigned int max_lro_size = 0;
    1771                 :          0 :         unsigned int first_mb_free_size = mb_len - RTE_PKTMBUF_HEADROOM;
    1772                 :          0 :         uint32_t mprq_log_actual_stride_num = 0;
    1773                 :          0 :         uint32_t mprq_log_actual_stride_size = 0;
    1774   [ #  #  #  # ]:          0 :         bool rx_seg_en = n_seg != 1 || rx_seg[0].offset || rx_seg[0].length;
    1775                 :          0 :         const int mprq_en = !mlx5_mprq_prepare(dev, idx, desc, rx_seg_en,
    1776                 :            :                                                non_scatter_min_mbuf_size,
    1777                 :            :                                                &mprq_log_actual_stride_num,
    1778                 :            :                                                &mprq_log_actual_stride_size,
    1779                 :            :                                                is_extmem);
    1780                 :            :         /*
    1781                 :            :          * Always allocate extra slots, even if eventually
    1782                 :            :          * the vector Rx will not be used.
    1783                 :            :          */
    1784                 :          0 :         uint16_t desc_n = desc + config->rx_vec_en * MLX5_VPMD_DESCS_PER_LOOP;
    1785                 :          0 :         size_t alloc_size = sizeof(*tmpl) + desc_n * sizeof(struct rte_mbuf *);
    1786                 :            :         const struct rte_eth_rxseg_split *qs_seg = rx_seg;
    1787                 :            :         unsigned int tail_len;
    1788                 :            : 
    1789         [ #  # ]:          0 :         if (mprq_en) {
    1790                 :            :                 /* Trim the number of descs needed. */
    1791                 :          0 :                 desc >>= mprq_log_actual_stride_num;
    1792                 :          0 :                 alloc_size += desc * sizeof(struct mlx5_mprq_buf *);
    1793                 :            :         }
    1794                 :          0 :         tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, alloc_size, 0, socket);
    1795         [ #  # ]:          0 :         if (!tmpl) {
    1796                 :          0 :                 rte_errno = ENOMEM;
    1797                 :          0 :                 return NULL;
    1798                 :            :         }
    1799                 :          0 :         LIST_INIT(&tmpl->owners);
    1800                 :            :         MLX5_ASSERT(n_seg && n_seg <= MLX5_MAX_RXQ_NSEG);
    1801                 :            :         /*
    1802                 :            :          * Save the original segment configuration in the shared queue
    1803                 :            :          * descriptor for the later check on the sibling queue creation.
    1804                 :            :          */
    1805                 :          0 :         tmpl->rxseg_n = n_seg;
    1806         [ #  # ]:          0 :         rte_memcpy(tmpl->rxseg, qs_seg,
    1807                 :            :                    sizeof(struct rte_eth_rxseg_split) * n_seg);
    1808                 :            :         /*
    1809                 :            :          * Build the array of actual buffer offsets and lengths.
    1810                 :            :          * Pad with the buffers from the last memory pool if
    1811                 :            :          * needed to handle max size packets, replace zero length
    1812                 :            :          * with the buffer length from the pool.
    1813                 :            :          */
    1814                 :            :         tail_len = max_rx_pktlen;
    1815                 :            :         do {
    1816                 :            :                 struct mlx5_eth_rxseg *hw_seg =
    1817                 :          0 :                                         &tmpl->rxq.rxseg[tmpl->rxq.rxseg_n];
    1818                 :            :                 uint32_t buf_len, offset, seg_len;
    1819                 :            : 
    1820                 :            :                 /*
    1821                 :            :                  * For the buffers beyond descriptions offset is zero,
    1822                 :            :                  * the first buffer contains head room.
    1823                 :            :                  */
    1824         [ #  # ]:          0 :                 buf_len = rte_pktmbuf_data_room_size(qs_seg->mp);
    1825         [ #  # ]:          0 :                 offset = (tmpl->rxq.rxseg_n >= n_seg ? 0 : qs_seg->offset) +
    1826         [ #  # ]:          0 :                          (tmpl->rxq.rxseg_n ? 0 : RTE_PKTMBUF_HEADROOM);
    1827                 :            :                 /*
    1828                 :            :                  * For the buffers beyond descriptions the length is
    1829                 :            :                  * pool buffer length, zero lengths are replaced with
    1830                 :            :                  * pool buffer length either.
    1831                 :            :                  */
    1832         [ #  # ]:          0 :                 seg_len = tmpl->rxq.rxseg_n >= n_seg ? buf_len :
    1833                 :          0 :                                                        qs_seg->length ?
    1834         [ #  # ]:          0 :                                                        qs_seg->length :
    1835                 :            :                                                        (buf_len - offset);
    1836                 :            :                 /* Check is done in long int, now overflows. */
    1837         [ #  # ]:          0 :                 if (buf_len < seg_len + offset) {
    1838                 :          0 :                         DRV_LOG(ERR, "port %u Rx queue %u: Split offset/length "
    1839                 :            :                                      "%u/%u can't be satisfied",
    1840                 :            :                                      dev->data->port_id, idx,
    1841                 :            :                                      qs_seg->length, qs_seg->offset);
    1842                 :          0 :                         rte_errno = EINVAL;
    1843                 :          0 :                         goto error;
    1844                 :            :                 }
    1845         [ #  # ]:          0 :                 if (seg_len > tail_len)
    1846                 :          0 :                         seg_len = buf_len - offset;
    1847         [ #  # ]:          0 :                 if (++tmpl->rxq.rxseg_n > MLX5_MAX_RXQ_NSEG) {
    1848                 :          0 :                         DRV_LOG(ERR,
    1849                 :            :                                 "port %u too many SGEs (%u) needed to handle"
    1850                 :            :                                 " requested maximum packet size %u, the maximum"
    1851                 :            :                                 " supported are %u", dev->data->port_id,
    1852                 :            :                                 tmpl->rxq.rxseg_n, max_rx_pktlen,
    1853                 :            :                                 MLX5_MAX_RXQ_NSEG);
    1854                 :          0 :                         rte_errno = ENOTSUP;
    1855                 :          0 :                         goto error;
    1856                 :            :                 }
    1857                 :            :                 /* Build the actual scattering element in the queue object. */
    1858                 :          0 :                 hw_seg->mp = qs_seg->mp;
    1859                 :            :                 MLX5_ASSERT(offset <= UINT16_MAX);
    1860                 :            :                 MLX5_ASSERT(seg_len <= UINT16_MAX);
    1861                 :          0 :                 hw_seg->offset = (uint16_t)offset;
    1862                 :          0 :                 hw_seg->length = (uint16_t)seg_len;
    1863                 :            :                 /*
    1864                 :            :                  * Advance the segment descriptor, the padding is the based
    1865                 :            :                  * on the attributes of the last descriptor.
    1866                 :            :                  */
    1867         [ #  # ]:          0 :                 if (tmpl->rxq.rxseg_n < n_seg)
    1868                 :          0 :                         qs_seg++;
    1869                 :          0 :                 tail_len -= RTE_MIN(tail_len, seg_len);
    1870         [ #  # ]:          0 :         } while (tail_len || !rte_is_power_of_2(tmpl->rxq.rxseg_n));
    1871                 :            :         MLX5_ASSERT(tmpl->rxq.rxseg_n &&
    1872                 :            :                     tmpl->rxq.rxseg_n <= MLX5_MAX_RXQ_NSEG);
    1873   [ #  #  #  # ]:          0 :         if (tmpl->rxq.rxseg_n > 1 && !(offloads & RTE_ETH_RX_OFFLOAD_SCATTER)) {
    1874                 :          0 :                 DRV_LOG(ERR, "port %u Rx queue %u: Scatter offload is not"
    1875                 :            :                         " configured and no enough mbuf space(%u) to contain "
    1876                 :            :                         "the maximum RX packet length(%u) with head-room(%u)",
    1877                 :            :                         dev->data->port_id, idx, mb_len, max_rx_pktlen,
    1878                 :            :                         RTE_PKTMBUF_HEADROOM);
    1879                 :          0 :                 rte_errno = ENOSPC;
    1880                 :          0 :                 goto error;
    1881                 :            :         }
    1882                 :          0 :         tmpl->is_hairpin = false;
    1883         [ #  # ]:          0 :         if (mlx5_mr_ctrl_init(&tmpl->rxq.mr_ctrl,
    1884                 :          0 :                               &priv->sh->cdev->mr_scache.dev_gen, socket)) {
    1885                 :            :                 /* rte_errno is already set. */
    1886                 :          0 :                 goto error;
    1887                 :            :         }
    1888                 :          0 :         tmpl->socket = socket;
    1889         [ #  # ]:          0 :         if (dev->data->dev_conf.intr_conf.rxq)
    1890                 :          0 :                 tmpl->irq = 1;
    1891         [ #  # ]:          0 :         if (mprq_en) {
    1892                 :            :                 /* TODO: Rx scatter isn't supported yet. */
    1893                 :          0 :                 tmpl->rxq.sges_n = 0;
    1894                 :          0 :                 tmpl->rxq.log_strd_num = mprq_log_actual_stride_num;
    1895                 :          0 :                 tmpl->rxq.log_strd_sz = mprq_log_actual_stride_size;
    1896                 :          0 :                 tmpl->rxq.strd_shift_en = MLX5_MPRQ_TWO_BYTE_SHIFT;
    1897                 :          0 :                 tmpl->rxq.strd_scatter_en =
    1898                 :          0 :                                 !!(offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
    1899                 :          0 :                 tmpl->rxq.mprq_max_memcpy_len = RTE_MIN(first_mb_free_size,
    1900                 :            :                                 config->mprq.max_memcpy_len);
    1901                 :          0 :                 max_lro_size = RTE_MIN(max_rx_pktlen,
    1902                 :            :                                        RTE_BIT32(tmpl->rxq.log_strd_num) *
    1903                 :            :                                        RTE_BIT32(tmpl->rxq.log_strd_sz));
    1904         [ #  # ]:          0 :         } else if (tmpl->rxq.rxseg_n == 1) {
    1905                 :            :                 MLX5_ASSERT(max_rx_pktlen <= first_mb_free_size);
    1906                 :          0 :                 tmpl->rxq.sges_n = 0;
    1907                 :            :                 max_lro_size = max_rx_pktlen;
    1908         [ #  # ]:          0 :         } else if (offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
    1909                 :            :                 unsigned int sges_n;
    1910                 :            : 
    1911         [ #  # ]:          0 :                 if (lro_on_queue && first_mb_free_size <
    1912                 :            :                     MLX5_MAX_LRO_HEADER_FIX) {
    1913                 :          0 :                         DRV_LOG(ERR, "Not enough space in the first segment(%u)"
    1914                 :            :                                 " to include the max header size(%u) for LRO",
    1915                 :            :                                 first_mb_free_size, MLX5_MAX_LRO_HEADER_FIX);
    1916                 :          0 :                         rte_errno = ENOTSUP;
    1917                 :          0 :                         goto error;
    1918                 :            :                 }
    1919                 :            :                 /*
    1920                 :            :                  * Determine the number of SGEs needed for a full packet
    1921                 :            :                  * and round it to the next power of two.
    1922                 :            :                  */
    1923                 :            :                 sges_n = log2above(tmpl->rxq.rxseg_n);
    1924         [ #  # ]:          0 :                 if (sges_n > MLX5_MAX_LOG_RQ_SEGS) {
    1925                 :          0 :                         DRV_LOG(ERR,
    1926                 :            :                                 "port %u too many SGEs (%u) needed to handle"
    1927                 :            :                                 " requested maximum packet size %u, the maximum"
    1928                 :            :                                 " supported are %u", dev->data->port_id,
    1929                 :            :                                 1 << sges_n, max_rx_pktlen,
    1930                 :            :                                 1u << MLX5_MAX_LOG_RQ_SEGS);
    1931                 :          0 :                         rte_errno = ENOTSUP;
    1932                 :          0 :                         goto error;
    1933                 :            :                 }
    1934                 :          0 :                 tmpl->rxq.sges_n = sges_n;
    1935                 :            :                 max_lro_size = max_rx_pktlen;
    1936                 :            :         }
    1937                 :          0 :         DRV_LOG(DEBUG, "port %u maximum number of segments per packet: %u",
    1938                 :            :                 dev->data->port_id, 1 << tmpl->rxq.sges_n);
    1939         [ #  # ]:          0 :         if (desc % (1 << tmpl->rxq.sges_n)) {
    1940                 :          0 :                 DRV_LOG(ERR,
    1941                 :            :                         "port %u number of Rx queue descriptors (%u) is not a"
    1942                 :            :                         " multiple of SGEs per packet (%u)",
    1943                 :            :                         dev->data->port_id,
    1944                 :            :                         desc,
    1945                 :            :                         1 << tmpl->rxq.sges_n);
    1946                 :          0 :                 rte_errno = EINVAL;
    1947                 :          0 :                 goto error;
    1948                 :            :         }
    1949                 :          0 :         mlx5_max_lro_msg_size_adjust(dev, idx, max_lro_size);
    1950                 :            :         /* Toggle RX checksum offload if hardware supports it. */
    1951                 :          0 :         tmpl->rxq.csum = !!(offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM);
    1952                 :            :         /* Configure Rx timestamp. */
    1953                 :          0 :         tmpl->rxq.hw_timestamp = !!(offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP);
    1954                 :          0 :         tmpl->rxq.timestamp_rx_flag = 0;
    1955   [ #  #  #  # ]:          0 :         if (tmpl->rxq.hw_timestamp && rte_mbuf_dyn_rx_timestamp_register(
    1956                 :            :                         &tmpl->rxq.timestamp_offset,
    1957                 :            :                         &tmpl->rxq.timestamp_rx_flag) != 0) {
    1958                 :          0 :                 DRV_LOG(ERR, "Cannot register Rx timestamp field/flag");
    1959                 :          0 :                 goto error;
    1960                 :            :         }
    1961                 :            :         /* Configure VLAN stripping. */
    1962                 :          0 :         tmpl->rxq.vlan_strip = !!(offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
    1963                 :            :         /* By default, FCS (CRC) is stripped by hardware. */
    1964                 :          0 :         tmpl->rxq.crc_present = 0;
    1965                 :          0 :         tmpl->rxq.lro = lro_on_queue;
    1966         [ #  # ]:          0 :         if (offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
    1967         [ #  # ]:          0 :                 if (priv->sh->config.hw_fcs_strip) {
    1968                 :            :                         /*
    1969                 :            :                          * RQs used for LRO-enabled TIRs should not be
    1970                 :            :                          * configured to scatter the FCS.
    1971                 :            :                          */
    1972         [ #  # ]:          0 :                         if (lro_on_queue)
    1973                 :          0 :                                 DRV_LOG(WARNING,
    1974                 :            :                                         "port %u CRC stripping has been "
    1975                 :            :                                         "disabled but will still be performed "
    1976                 :            :                                         "by hardware, because LRO is enabled",
    1977                 :            :                                         dev->data->port_id);
    1978                 :            :                         else
    1979                 :          0 :                                 tmpl->rxq.crc_present = 1;
    1980                 :            :                 } else {
    1981                 :          0 :                         DRV_LOG(WARNING,
    1982                 :            :                                 "port %u CRC stripping has been disabled but will"
    1983                 :            :                                 " still be performed by hardware, make sure MLNX_OFED"
    1984                 :            :                                 " and firmware are up to date",
    1985                 :            :                                 dev->data->port_id);
    1986                 :            :                 }
    1987                 :            :         }
    1988         [ #  # ]:          0 :         DRV_LOG(DEBUG,
    1989                 :            :                 "port %u CRC stripping is %s, %u bytes will be subtracted from"
    1990                 :            :                 " incoming frames to hide it",
    1991                 :            :                 dev->data->port_id,
    1992                 :            :                 tmpl->rxq.crc_present ? "disabled" : "enabled",
    1993                 :            :                 tmpl->rxq.crc_present << 2);
    1994         [ #  # ]:          0 :         tmpl->rxq.rss_hash = !!priv->rss_conf.rss_hf &&
    1995         [ #  # ]:          0 :                 (!!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS));
    1996                 :            :         /* Save port ID. */
    1997                 :          0 :         tmpl->rxq.port_id = dev->data->port_id;
    1998                 :          0 :         tmpl->sh = priv->sh;
    1999                 :          0 :         tmpl->rxq.mp = rx_seg[0].mp;
    2000                 :          0 :         tmpl->rxq.elts_n = log2above(desc);
    2001                 :          0 :         tmpl->rxq.rq_repl_thresh = MLX5_VPMD_RXQ_RPLNSH_THRESH(desc_n);
    2002                 :          0 :         tmpl->rxq.elts = (struct rte_mbuf *(*)[])(tmpl + 1);
    2003                 :          0 :         tmpl->rxq.mprq_bufs = (struct mlx5_mprq_buf *(*)[])(*tmpl->rxq.elts + desc_n);
    2004                 :          0 :         tmpl->rxq.idx = idx;
    2005         [ #  # ]:          0 :         if (conf->share_group > 0) {
    2006                 :          0 :                 tmpl->rxq.shared = 1;
    2007                 :          0 :                 tmpl->share_group = conf->share_group;
    2008                 :          0 :                 tmpl->share_qid = conf->share_qid;
    2009                 :            :         }
    2010         [ #  # ]:          0 :         LIST_INSERT_HEAD(&priv->sh->shared_rxqs, tmpl, share_entry);
    2011                 :          0 :         rte_atomic_store_explicit(&tmpl->ctrl_ref, 1, rte_memory_order_relaxed);
    2012                 :          0 :         return tmpl;
    2013                 :          0 : error:
    2014                 :          0 :         mlx5_mr_btree_free(&tmpl->rxq.mr_ctrl.cache_bh);
    2015                 :          0 :         mlx5_free(tmpl);
    2016                 :          0 :         return NULL;
    2017                 :            : }
    2018                 :            : 
    2019                 :            : /**
    2020                 :            :  * Create a DPDK Rx hairpin queue.
    2021                 :            :  *
    2022                 :            :  * @param dev
    2023                 :            :  *   Pointer to Ethernet device.
    2024                 :            :  * @param rxq
    2025                 :            :  *   RX queue.
    2026                 :            :  * @param desc
    2027                 :            :  *   Number of descriptors to configure in queue.
    2028                 :            :  * @param hairpin_conf
    2029                 :            :  *   The hairpin binding configuration.
    2030                 :            :  *
    2031                 :            :  * @return
    2032                 :            :  *   A DPDK queue object on success, NULL otherwise and rte_errno is set.
    2033                 :            :  */
    2034                 :            : struct mlx5_rxq_ctrl *
    2035                 :          0 : mlx5_rxq_hairpin_new(struct rte_eth_dev *dev, struct mlx5_rxq_priv *rxq,
    2036                 :            :                      uint16_t desc,
    2037                 :            :                      const struct rte_eth_hairpin_conf *hairpin_conf)
    2038                 :            : {
    2039                 :          0 :         uint16_t idx = rxq->idx;
    2040                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2041                 :            :         struct mlx5_rxq_ctrl *tmpl;
    2042                 :            : 
    2043                 :          0 :         tmpl = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, sizeof(*tmpl), 0,
    2044                 :            :                            SOCKET_ID_ANY);
    2045         [ #  # ]:          0 :         if (!tmpl) {
    2046                 :          0 :                 rte_errno = ENOMEM;
    2047                 :          0 :                 return NULL;
    2048                 :            :         }
    2049                 :            :         LIST_INIT(&tmpl->owners);
    2050                 :          0 :         rxq->ctrl = tmpl;
    2051                 :          0 :         LIST_INSERT_HEAD(&tmpl->owners, rxq, owner_entry);
    2052                 :          0 :         tmpl->is_hairpin = true;
    2053                 :          0 :         tmpl->socket = SOCKET_ID_ANY;
    2054                 :          0 :         tmpl->rxq.rss_hash = 0;
    2055                 :          0 :         tmpl->rxq.port_id = dev->data->port_id;
    2056                 :          0 :         tmpl->sh = priv->sh;
    2057                 :          0 :         tmpl->rxq.mp = NULL;
    2058                 :          0 :         tmpl->rxq.elts_n = log2above(desc);
    2059                 :          0 :         tmpl->rxq.elts = NULL;
    2060                 :          0 :         tmpl->rxq.mr_ctrl.cache_bh = (struct mlx5_mr_btree) { 0 };
    2061                 :          0 :         tmpl->rxq.idx = idx;
    2062                 :          0 :         rxq->hairpin_conf = *hairpin_conf;
    2063                 :          0 :         mlx5_rxq_ref(dev, idx);
    2064         [ #  # ]:          0 :         LIST_INSERT_HEAD(&priv->sh->shared_rxqs, tmpl, share_entry);
    2065                 :          0 :         rte_atomic_store_explicit(&tmpl->ctrl_ref, 1, rte_memory_order_relaxed);
    2066                 :          0 :         return tmpl;
    2067                 :            : }
    2068                 :            : 
    2069                 :            : /**
    2070                 :            :  * Increase Rx queue reference count.
    2071                 :            :  *
    2072                 :            :  * @param dev
    2073                 :            :  *   Pointer to Ethernet device.
    2074                 :            :  * @param idx
    2075                 :            :  *   RX queue index.
    2076                 :            :  *
    2077                 :            :  * @return
    2078                 :            :  *   A pointer to the queue if it exists, NULL otherwise.
    2079                 :            :  */
    2080                 :            : struct mlx5_rxq_priv *
    2081                 :          0 : mlx5_rxq_ref(struct rte_eth_dev *dev, uint16_t idx)
    2082                 :            : {
    2083                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
    2084                 :            : 
    2085         [ #  # ]:          0 :         if (rxq != NULL)
    2086                 :          0 :                 rte_atomic_fetch_add_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed);
    2087                 :          0 :         return rxq;
    2088                 :            : }
    2089                 :            : 
    2090                 :            : /**
    2091                 :            :  * Dereference a Rx queue.
    2092                 :            :  *
    2093                 :            :  * @param dev
    2094                 :            :  *   Pointer to Ethernet device.
    2095                 :            :  * @param idx
    2096                 :            :  *   RX queue index.
    2097                 :            :  *
    2098                 :            :  * @return
    2099                 :            :  *   Updated reference count.
    2100                 :            :  */
    2101                 :            : uint32_t
    2102                 :          0 : mlx5_rxq_deref(struct rte_eth_dev *dev, uint16_t idx)
    2103                 :            : {
    2104                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
    2105                 :            : 
    2106         [ #  # ]:          0 :         if (rxq == NULL)
    2107                 :            :                 return 0;
    2108                 :          0 :         return rte_atomic_fetch_sub_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed) - 1;
    2109                 :            : }
    2110                 :            : 
    2111                 :            : /**
    2112                 :            :  * Get a Rx queue.
    2113                 :            :  *
    2114                 :            :  * @param dev
    2115                 :            :  *   Pointer to Ethernet device.
    2116                 :            :  * @param idx
    2117                 :            :  *   RX queue index.
    2118                 :            :  *
    2119                 :            :  * @return
    2120                 :            :  *   A pointer to the queue if it exists, NULL otherwise.
    2121                 :            :  */
    2122                 :            : struct mlx5_rxq_priv *
    2123                 :          0 : mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx)
    2124                 :            : {
    2125                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2126                 :            : 
    2127         [ #  # ]:          0 :         if (idx >= priv->rxqs_n)
    2128                 :            :                 return NULL;
    2129                 :            :         MLX5_ASSERT(priv->rxq_privs != NULL);
    2130                 :          0 :         return (*priv->rxq_privs)[idx];
    2131                 :            : }
    2132                 :            : 
    2133                 :            : /**
    2134                 :            :  * Get Rx queue shareable control.
    2135                 :            :  *
    2136                 :            :  * @param dev
    2137                 :            :  *   Pointer to Ethernet device.
    2138                 :            :  * @param idx
    2139                 :            :  *   RX queue index.
    2140                 :            :  *
    2141                 :            :  * @return
    2142                 :            :  *   A pointer to the queue control if it exists, NULL otherwise.
    2143                 :            :  */
    2144                 :            : struct mlx5_rxq_ctrl *
    2145                 :          0 : mlx5_rxq_ctrl_get(struct rte_eth_dev *dev, uint16_t idx)
    2146                 :            : {
    2147                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
    2148                 :            : 
    2149         [ #  # ]:          0 :         return rxq == NULL ? NULL : rxq->ctrl;
    2150                 :            : }
    2151                 :            : 
    2152                 :            : /**
    2153                 :            :  * Get Rx queue shareable data.
    2154                 :            :  *
    2155                 :            :  * @param dev
    2156                 :            :  *   Pointer to Ethernet device.
    2157                 :            :  * @param idx
    2158                 :            :  *   RX queue index.
    2159                 :            :  *
    2160                 :            :  * @return
    2161                 :            :  *   A pointer to the queue data if it exists, NULL otherwise.
    2162                 :            :  */
    2163                 :            : struct mlx5_rxq_data *
    2164                 :          0 : mlx5_rxq_data_get(struct rte_eth_dev *dev, uint16_t idx)
    2165                 :            : {
    2166                 :          0 :         struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
    2167                 :            : 
    2168         [ #  # ]:          0 :         return rxq == NULL ? NULL : &rxq->ctrl->rxq;
    2169                 :            : }
    2170                 :            : 
    2171                 :            : /**
    2172                 :            :  * Increase an external Rx queue reference count.
    2173                 :            :  *
    2174                 :            :  * @param dev
    2175                 :            :  *   Pointer to Ethernet device.
    2176                 :            :  * @param idx
    2177                 :            :  *   External RX queue index.
    2178                 :            :  *
    2179                 :            :  * @return
    2180                 :            :  *   A pointer to the queue if it exists, NULL otherwise.
    2181                 :            :  */
    2182                 :            : struct mlx5_external_q *
    2183                 :          0 : mlx5_ext_rxq_ref(struct rte_eth_dev *dev, uint16_t idx)
    2184                 :            : {
    2185                 :          0 :         struct mlx5_external_q *rxq = mlx5_ext_rxq_get(dev, idx);
    2186                 :            : 
    2187                 :          0 :         rte_atomic_fetch_add_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed);
    2188                 :          0 :         return rxq;
    2189                 :            : }
    2190                 :            : 
    2191                 :            : /**
    2192                 :            :  * Decrease an external Rx queue reference count.
    2193                 :            :  *
    2194                 :            :  * @param dev
    2195                 :            :  *   Pointer to Ethernet device.
    2196                 :            :  * @param idx
    2197                 :            :  *   External RX queue index.
    2198                 :            :  *
    2199                 :            :  * @return
    2200                 :            :  *   Updated reference count.
    2201                 :            :  */
    2202                 :            : uint32_t
    2203                 :          0 : mlx5_ext_rxq_deref(struct rte_eth_dev *dev, uint16_t idx)
    2204                 :            : {
    2205                 :          0 :         struct mlx5_external_q *rxq = mlx5_ext_rxq_get(dev, idx);
    2206                 :            : 
    2207                 :          0 :         return rte_atomic_fetch_sub_explicit(&rxq->refcnt, 1, rte_memory_order_relaxed) - 1;
    2208                 :            : }
    2209                 :            : 
    2210                 :            : /**
    2211                 :            :  * Get an external Rx queue.
    2212                 :            :  *
    2213                 :            :  * @param dev
    2214                 :            :  *   Pointer to Ethernet device.
    2215                 :            :  * @param idx
    2216                 :            :  *   External Rx queue index.
    2217                 :            :  *
    2218                 :            :  * @return
    2219                 :            :  *   A pointer to the queue if it exists, NULL otherwise.
    2220                 :            :  */
    2221                 :            : struct mlx5_external_q *
    2222                 :          0 : mlx5_ext_rxq_get(struct rte_eth_dev *dev, uint16_t idx)
    2223                 :            : {
    2224                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2225                 :            : 
    2226                 :            :         MLX5_ASSERT(mlx5_is_external_rxq(dev, idx));
    2227                 :          0 :         return &priv->ext_rxqs[idx - RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN];
    2228                 :            : }
    2229                 :            : 
    2230                 :            : /**
    2231                 :            :  * Dereference a list of Rx queues.
    2232                 :            :  *
    2233                 :            :  * @param dev
    2234                 :            :  *   Pointer to Ethernet device.
    2235                 :            :  * @param queues
    2236                 :            :  *   List of Rx queues to deref.
    2237                 :            :  * @param queues_n
    2238                 :            :  *   Number of queues in the array.
    2239                 :            :  */
    2240                 :            : static void
    2241                 :          0 : mlx5_rxqs_deref(struct rte_eth_dev *dev, uint16_t *queues,
    2242                 :            :                 const uint32_t queues_n)
    2243                 :            : {
    2244                 :            :         uint32_t i;
    2245                 :            : 
    2246         [ #  # ]:          0 :         for (i = 0; i < queues_n; i++) {
    2247   [ #  #  #  # ]:          0 :                 if (mlx5_is_external_rxq(dev, queues[i]))
    2248                 :          0 :                         claim_nonzero(mlx5_ext_rxq_deref(dev, queues[i]));
    2249                 :            :                 else
    2250                 :          0 :                         claim_nonzero(mlx5_rxq_deref(dev, queues[i]));
    2251                 :            :         }
    2252                 :          0 : }
    2253                 :            : 
    2254                 :            : /**
    2255                 :            :  * Increase reference count for list of Rx queues.
    2256                 :            :  *
    2257                 :            :  * @param dev
    2258                 :            :  *   Pointer to Ethernet device.
    2259                 :            :  * @param queues
    2260                 :            :  *   List of Rx queues to ref.
    2261                 :            :  * @param queues_n
    2262                 :            :  *   Number of queues in the array.
    2263                 :            :  *
    2264                 :            :  * @return
    2265                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2266                 :            :  */
    2267                 :            : static int
    2268                 :          0 : mlx5_rxqs_ref(struct rte_eth_dev *dev, uint16_t *queues,
    2269                 :            :               const uint32_t queues_n)
    2270                 :            : {
    2271                 :            :         uint32_t i;
    2272                 :            : 
    2273         [ #  # ]:          0 :         for (i = 0; i != queues_n; ++i) {
    2274   [ #  #  #  # ]:          0 :                 if (mlx5_is_external_rxq(dev, queues[i])) {
    2275         [ #  # ]:          0 :                         if (mlx5_ext_rxq_ref(dev, queues[i]) == NULL)
    2276                 :          0 :                                 goto error;
    2277                 :            :                 } else {
    2278         [ #  # ]:          0 :                         if (mlx5_rxq_ref(dev, queues[i]) == NULL)
    2279                 :          0 :                                 goto error;
    2280                 :            :                 }
    2281                 :            :         }
    2282                 :            :         return 0;
    2283                 :          0 : error:
    2284                 :          0 :         mlx5_rxqs_deref(dev, queues, i);
    2285                 :          0 :         rte_errno = EINVAL;
    2286                 :          0 :         return -rte_errno;
    2287                 :            : }
    2288                 :            : 
    2289                 :            : /**
    2290                 :            :  * Release a Rx queue.
    2291                 :            :  *
    2292                 :            :  * @param dev
    2293                 :            :  *   Pointer to Ethernet device.
    2294                 :            :  * @param idx
    2295                 :            :  *   RX queue index.
    2296                 :            :  *
    2297                 :            :  * @return
    2298                 :            :  *   1 while a reference on it exists, 0 when freed.
    2299                 :            :  */
    2300                 :            : int
    2301                 :          0 : mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx)
    2302                 :            : {
    2303                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2304                 :            :         struct mlx5_rxq_priv *rxq;
    2305                 :            :         struct mlx5_rxq_ctrl *rxq_ctrl;
    2306                 :            :         uint32_t refcnt;
    2307                 :            :         int32_t ctrl_ref;
    2308                 :            : 
    2309         [ #  # ]:          0 :         if (priv->rxq_privs == NULL)
    2310                 :            :                 return 0;
    2311                 :          0 :         rxq = mlx5_rxq_get(dev, idx);
    2312   [ #  #  #  # ]:          0 :         if (rxq == NULL || rxq->refcnt == 0)
    2313                 :            :                 return 0;
    2314                 :          0 :         rxq_ctrl = rxq->ctrl;
    2315                 :          0 :         refcnt = mlx5_rxq_deref(dev, idx);
    2316         [ #  # ]:          0 :         if (refcnt > 1) {
    2317                 :            :                 return 1;
    2318         [ #  # ]:          0 :         } else if (refcnt == 1) { /* RxQ stopped. */
    2319                 :          0 :                 priv->obj_ops.rxq_obj_release(rxq);
    2320   [ #  #  #  # ]:          0 :                 if (!rxq_ctrl->started && rxq_ctrl->obj != NULL) {
    2321         [ #  # ]:          0 :                         LIST_REMOVE(rxq_ctrl->obj, next);
    2322                 :          0 :                         mlx5_free(rxq_ctrl->obj);
    2323                 :          0 :                         rxq_ctrl->obj = NULL;
    2324                 :            :                 }
    2325         [ #  # ]:          0 :                 if (!rxq_ctrl->is_hairpin) {
    2326         [ #  # ]:          0 :                         if (!rxq_ctrl->started)
    2327                 :          0 :                                 rxq_free_elts(rxq_ctrl);
    2328                 :          0 :                         dev->data->rx_queue_state[idx] =
    2329                 :            :                                         RTE_ETH_QUEUE_STATE_STOPPED;
    2330                 :            :                 }
    2331                 :            :         } else { /* Refcnt zero, closing device. */
    2332         [ #  # ]:          0 :                 LIST_REMOVE(rxq, owner_entry);
    2333                 :          0 :                 ctrl_ref = rte_atomic_fetch_sub_explicit(&rxq_ctrl->ctrl_ref, 1,
    2334                 :            :                                                          rte_memory_order_relaxed) - 1;
    2335   [ #  #  #  # ]:          0 :                 if (ctrl_ref == 1 && LIST_EMPTY(&rxq_ctrl->owners)) {
    2336         [ #  # ]:          0 :                         if (!rxq_ctrl->is_hairpin)
    2337                 :          0 :                                 mlx5_mr_btree_free
    2338                 :            :                                         (&rxq_ctrl->rxq.mr_ctrl.cache_bh);
    2339         [ #  # ]:          0 :                         LIST_REMOVE(rxq_ctrl, share_entry);
    2340                 :          0 :                         mlx5_free(rxq_ctrl);
    2341                 :            :                 }
    2342                 :          0 :                 dev->data->rx_queues[idx] = NULL;
    2343                 :          0 :                 mlx5_free(rxq);
    2344                 :          0 :                 (*priv->rxq_privs)[idx] = NULL;
    2345                 :            :         }
    2346                 :            :         return 0;
    2347                 :            : }
    2348                 :            : 
    2349                 :            : /**
    2350                 :            :  * Verify the Rx Queue list is empty
    2351                 :            :  *
    2352                 :            :  * @param dev
    2353                 :            :  *   Pointer to Ethernet device.
    2354                 :            :  *
    2355                 :            :  * @return
    2356                 :            :  *   The number of object not released.
    2357                 :            :  */
    2358                 :            : int
    2359                 :          0 : mlx5_rxq_verify(struct rte_eth_dev *dev)
    2360                 :            : {
    2361                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2362                 :            :         struct mlx5_rxq_ctrl *rxq_ctrl;
    2363                 :            :         int ret = 0;
    2364                 :            : 
    2365         [ #  # ]:          0 :         LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, share_entry) {
    2366                 :          0 :                 DRV_LOG(DEBUG, "port %u Rx Queue %u still referenced",
    2367                 :            :                         dev->data->port_id, rxq_ctrl->rxq.idx);
    2368                 :          0 :                 ++ret;
    2369                 :            :         }
    2370                 :          0 :         return ret;
    2371                 :            : }
    2372                 :            : 
    2373                 :            : /**
    2374                 :            :  * Verify the external Rx Queue list is empty.
    2375                 :            :  *
    2376                 :            :  * @param dev
    2377                 :            :  *   Pointer to Ethernet device.
    2378                 :            :  *
    2379                 :            :  * @return
    2380                 :            :  *   The number of object not released.
    2381                 :            :  */
    2382                 :            : int
    2383                 :          0 : mlx5_ext_rxq_verify(struct rte_eth_dev *dev)
    2384                 :            : {
    2385                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2386                 :            :         struct mlx5_external_q *rxq;
    2387                 :            :         uint32_t i;
    2388                 :            :         int ret = 0;
    2389                 :            : 
    2390         [ #  # ]:          0 :         if (priv->ext_rxqs == NULL)
    2391                 :            :                 return 0;
    2392                 :            : 
    2393         [ #  # ]:          0 :         for (i = RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN; i <= UINT16_MAX ; ++i) {
    2394                 :          0 :                 rxq = mlx5_ext_rxq_get(dev, i);
    2395         [ #  # ]:          0 :                 if (rxq->refcnt < 2)
    2396                 :          0 :                         continue;
    2397                 :          0 :                 DRV_LOG(DEBUG, "Port %u external RxQ %u still referenced.",
    2398                 :            :                         dev->data->port_id, i);
    2399                 :          0 :                 ++ret;
    2400                 :            :         }
    2401                 :            :         return ret;
    2402                 :            : }
    2403                 :            : 
    2404                 :            : /**
    2405                 :            :  * Check whether RxQ type is Hairpin.
    2406                 :            :  *
    2407                 :            :  * @param dev
    2408                 :            :  *   Pointer to Ethernet device.
    2409                 :            :  * @param idx
    2410                 :            :  *   Rx queue index.
    2411                 :            :  *
    2412                 :            :  * @return
    2413                 :            :  *   True if Rx queue type is Hairpin, otherwise False.
    2414                 :            :  */
    2415                 :            : bool
    2416                 :          0 : mlx5_rxq_is_hairpin(struct rte_eth_dev *dev, uint16_t idx)
    2417                 :            : {
    2418                 :            :         struct mlx5_rxq_ctrl *rxq_ctrl;
    2419                 :            : 
    2420   [ #  #  #  # ]:          0 :         if (mlx5_is_external_rxq(dev, idx))
    2421                 :            :                 return false;
    2422                 :          0 :         rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
    2423   [ #  #  #  # ]:          0 :         return (rxq_ctrl != NULL && rxq_ctrl->is_hairpin);
    2424                 :            : }
    2425                 :            : 
    2426                 :            : /*
    2427                 :            :  * Get a Rx hairpin queue configuration.
    2428                 :            :  *
    2429                 :            :  * @param dev
    2430                 :            :  *   Pointer to Ethernet device.
    2431                 :            :  * @param idx
    2432                 :            :  *   Rx queue index.
    2433                 :            :  *
    2434                 :            :  * @return
    2435                 :            :  *   Pointer to the configuration if a hairpin RX queue, otherwise NULL.
    2436                 :            :  */
    2437                 :            : const struct rte_eth_hairpin_conf *
    2438                 :          0 : mlx5_rxq_get_hairpin_conf(struct rte_eth_dev *dev, uint16_t idx)
    2439                 :            : {
    2440         [ #  # ]:          0 :         if (mlx5_rxq_is_hairpin(dev, idx)) {
    2441                 :          0 :                 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, idx);
    2442                 :            : 
    2443         [ #  # ]:          0 :                 return rxq != NULL ? &rxq->hairpin_conf : NULL;
    2444                 :            :         }
    2445                 :            :         return NULL;
    2446                 :            : }
    2447                 :            : 
    2448                 :            : /**
    2449                 :            :  * Match queues listed in arguments to queues contained in indirection table
    2450                 :            :  * object.
    2451                 :            :  *
    2452                 :            :  * @param ind_tbl
    2453                 :            :  *   Pointer to indirection table to match.
    2454                 :            :  * @param queues
    2455                 :            :  *   Queues to match to queues in indirection table.
    2456                 :            :  * @param queues_n
    2457                 :            :  *   Number of queues in the array.
    2458                 :            :  *
    2459                 :            :  * @return
    2460                 :            :  *   1 if all queues in indirection table match 0 otherwise.
    2461                 :            :  */
    2462                 :            : static int
    2463                 :            : mlx5_ind_table_obj_match_queues(const struct mlx5_ind_table_obj *ind_tbl,
    2464                 :            :                                 const uint16_t *queues, uint32_t queues_n)
    2465                 :            : {
    2466                 :          0 :         return (ind_tbl->queues_n == queues_n) &&
    2467                 :          0 :                 (!memcmp(ind_tbl->queues, queues,
    2468         [ #  # ]:          0 :                          ind_tbl->queues_n * sizeof(ind_tbl->queues[0])));
    2469                 :            : }
    2470                 :            : 
    2471                 :            : /**
    2472                 :            :  * Get an indirection table.
    2473                 :            :  *
    2474                 :            :  * @param dev
    2475                 :            :  *   Pointer to Ethernet device.
    2476                 :            :  * @param queues
    2477                 :            :  *   Queues entering in the indirection table.
    2478                 :            :  * @param queues_n
    2479                 :            :  *   Number of queues in the array.
    2480                 :            :  *
    2481                 :            :  * @return
    2482                 :            :  *   An indirection table if found.
    2483                 :            :  */
    2484                 :            : struct mlx5_ind_table_obj *
    2485                 :          0 : mlx5_ind_table_obj_get(struct rte_eth_dev *dev, const uint16_t *queues,
    2486                 :            :                        uint32_t queues_n)
    2487                 :            : {
    2488                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2489                 :            :         struct mlx5_ind_table_obj *ind_tbl;
    2490                 :            : 
    2491                 :          0 :         rte_rwlock_read_lock(&priv->ind_tbls_lock);
    2492         [ #  # ]:          0 :         LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
    2493         [ #  # ]:          0 :                 if ((ind_tbl->queues_n == queues_n) &&
    2494                 :          0 :                     (memcmp(ind_tbl->queues, queues,
    2495         [ #  # ]:          0 :                             ind_tbl->queues_n * sizeof(ind_tbl->queues[0]))
    2496                 :            :                      == 0)) {
    2497                 :          0 :                         rte_atomic_fetch_add_explicit(&ind_tbl->refcnt, 1,
    2498                 :            :                                            rte_memory_order_relaxed);
    2499                 :          0 :                         break;
    2500                 :            :                 }
    2501                 :            :         }
    2502                 :            :         rte_rwlock_read_unlock(&priv->ind_tbls_lock);
    2503                 :          0 :         return ind_tbl;
    2504                 :            : }
    2505                 :            : 
    2506                 :            : /**
    2507                 :            :  * Release an indirection table.
    2508                 :            :  *
    2509                 :            :  * @param dev
    2510                 :            :  *   Pointer to Ethernet device.
    2511                 :            :  * @param ind_table
    2512                 :            :  *   Indirection table to release.
    2513                 :            :  * @param deref_rxqs
    2514                 :            :  *   If true, then dereference RX queues related to indirection table.
    2515                 :            :  *   Otherwise, no additional action will be taken.
    2516                 :            :  *
    2517                 :            :  * @return
    2518                 :            :  *   1 while a reference on it exists, 0 when freed.
    2519                 :            :  */
    2520                 :            : int
    2521                 :          0 : mlx5_ind_table_obj_release(struct rte_eth_dev *dev,
    2522                 :            :                            struct mlx5_ind_table_obj *ind_tbl,
    2523                 :            :                            bool deref_rxqs)
    2524                 :            : {
    2525                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2526                 :            :         unsigned int ret;
    2527                 :            : 
    2528                 :          0 :         rte_rwlock_write_lock(&priv->ind_tbls_lock);
    2529                 :          0 :         ret = rte_atomic_fetch_sub_explicit(&ind_tbl->refcnt, 1, rte_memory_order_relaxed) - 1;
    2530         [ #  # ]:          0 :         if (!ret)
    2531         [ #  # ]:          0 :                 LIST_REMOVE(ind_tbl, next);
    2532                 :            :         rte_rwlock_write_unlock(&priv->ind_tbls_lock);
    2533         [ #  # ]:          0 :         if (ret)
    2534                 :            :                 return 1;
    2535                 :          0 :         priv->obj_ops.ind_table_destroy(ind_tbl);
    2536         [ #  # ]:          0 :         if (deref_rxqs)
    2537                 :          0 :                 mlx5_rxqs_deref(dev, ind_tbl->queues, ind_tbl->queues_n);
    2538                 :          0 :         mlx5_free(ind_tbl);
    2539                 :          0 :         return 0;
    2540                 :            : }
    2541                 :            : 
    2542                 :            : /**
    2543                 :            :  * Verify the Rx Queue list is empty
    2544                 :            :  *
    2545                 :            :  * @param dev
    2546                 :            :  *   Pointer to Ethernet device.
    2547                 :            :  *
    2548                 :            :  * @return
    2549                 :            :  *   The number of object not released.
    2550                 :            :  */
    2551                 :            : int
    2552                 :          0 : mlx5_ind_table_obj_verify(struct rte_eth_dev *dev)
    2553                 :            : {
    2554                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2555                 :            :         struct mlx5_ind_table_obj *ind_tbl;
    2556                 :            :         int ret = 0;
    2557                 :            : 
    2558                 :          0 :         rte_rwlock_read_lock(&priv->ind_tbls_lock);
    2559         [ #  # ]:          0 :         LIST_FOREACH(ind_tbl, &priv->ind_tbls, next) {
    2560                 :          0 :                 DRV_LOG(DEBUG,
    2561                 :            :                         "port %u indirection table obj %p still referenced",
    2562                 :            :                         dev->data->port_id, (void *)ind_tbl);
    2563                 :          0 :                 ++ret;
    2564                 :            :         }
    2565                 :            :         rte_rwlock_read_unlock(&priv->ind_tbls_lock);
    2566                 :          0 :         return ret;
    2567                 :            : }
    2568                 :            : 
    2569                 :            : /**
    2570                 :            :  * Setup an indirection table structure fields.
    2571                 :            :  *
    2572                 :            :  * @param dev
    2573                 :            :  *   Pointer to Ethernet device.
    2574                 :            :  * @param ind_table
    2575                 :            :  *   Indirection table to modify.
    2576                 :            :  * @param ref_qs
    2577                 :            :  *   Whether to increment RxQ reference counters.
    2578                 :            :  *
    2579                 :            :  * @return
    2580                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2581                 :            :  */
    2582                 :            : int
    2583                 :          0 : mlx5_ind_table_obj_setup(struct rte_eth_dev *dev,
    2584                 :            :                          struct mlx5_ind_table_obj *ind_tbl,
    2585                 :            :                          bool ref_qs)
    2586                 :            : {
    2587                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2588         [ #  # ]:          0 :         uint32_t queues_n = ind_tbl->queues_n;
    2589                 :            :         int ret;
    2590                 :            :         const unsigned int n = rte_is_power_of_2(queues_n) ?
    2591                 :            :                                log2above(queues_n) :
    2592                 :          0 :                                log2above(priv->sh->dev_cap.ind_table_max_size);
    2593                 :            : 
    2594   [ #  #  #  # ]:          0 :         if (ref_qs && mlx5_rxqs_ref(dev, ind_tbl->queues, queues_n) < 0) {
    2595                 :          0 :                 DRV_LOG(DEBUG, "Port %u invalid indirection table queues.",
    2596                 :            :                         dev->data->port_id);
    2597                 :          0 :                 return -rte_errno;
    2598                 :            :         }
    2599                 :          0 :         ret = priv->obj_ops.ind_table_new(dev, n, ind_tbl);
    2600         [ #  # ]:          0 :         if (ret) {
    2601                 :          0 :                 DRV_LOG(DEBUG, "Port %u cannot create a new indirection table.",
    2602                 :            :                         dev->data->port_id);
    2603         [ #  # ]:          0 :                 if (ref_qs) {
    2604                 :          0 :                         int err = rte_errno;
    2605                 :            : 
    2606                 :          0 :                         mlx5_rxqs_deref(dev, ind_tbl->queues, queues_n);
    2607                 :          0 :                         rte_errno = err;
    2608                 :            :                 }
    2609                 :          0 :                 return ret;
    2610                 :            :         }
    2611                 :          0 :         rte_atomic_fetch_add_explicit(&ind_tbl->refcnt, 1, rte_memory_order_relaxed);
    2612                 :          0 :         return 0;
    2613                 :            : }
    2614                 :            : 
    2615                 :            : /**
    2616                 :            :  * Create an indirection table.
    2617                 :            :  *
    2618                 :            :  * @param dev
    2619                 :            :  *   Pointer to Ethernet device.
    2620                 :            :  * @param queues
    2621                 :            :  *   Queues entering in the indirection table.
    2622                 :            :  * @param queues_n
    2623                 :            :  *   Number of queues in the array.
    2624                 :            :  * @param standalone
    2625                 :            :  *   Indirection table for Standalone queue.
    2626                 :            :  * @param ref_qs
    2627                 :            :  *   Whether to increment RxQ reference counters.
    2628                 :            :  *
    2629                 :            :  * @return
    2630                 :            :  *   The Verbs/DevX object initialized, NULL otherwise and rte_errno is set.
    2631                 :            :  */
    2632                 :            : struct mlx5_ind_table_obj *
    2633                 :          0 : mlx5_ind_table_obj_new(struct rte_eth_dev *dev, const uint16_t *queues,
    2634                 :            :                        uint32_t queues_n, bool standalone, bool ref_qs)
    2635                 :            : {
    2636                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2637                 :            :         struct mlx5_ind_table_obj *ind_tbl;
    2638                 :            :         int ret;
    2639                 :          0 :         uint32_t max_queues_n = priv->rxqs_n > queues_n ? priv->rxqs_n : queues_n;
    2640                 :            : 
    2641                 :            :         /*
    2642                 :            :          * Allocate maximum queues for shared action as queue number
    2643                 :            :          * maybe modified later.
    2644                 :            :          */
    2645         [ #  # ]:          0 :         ind_tbl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ind_tbl) +
    2646                 :          0 :                               (standalone ? max_queues_n : queues_n) *
    2647                 :            :                               sizeof(uint16_t), 0, SOCKET_ID_ANY);
    2648         [ #  # ]:          0 :         if (!ind_tbl) {
    2649                 :          0 :                 rte_errno = ENOMEM;
    2650                 :          0 :                 return NULL;
    2651                 :            :         }
    2652                 :          0 :         ind_tbl->queues_n = queues_n;
    2653                 :          0 :         ind_tbl->queues = (uint16_t *)(ind_tbl + 1);
    2654                 :          0 :         memcpy(ind_tbl->queues, queues, queues_n * sizeof(*queues));
    2655                 :          0 :         ret = mlx5_ind_table_obj_setup(dev, ind_tbl, ref_qs);
    2656         [ #  # ]:          0 :         if (ret < 0) {
    2657                 :          0 :                 mlx5_free(ind_tbl);
    2658                 :          0 :                 return NULL;
    2659                 :            :         }
    2660                 :          0 :         rte_rwlock_write_lock(&priv->ind_tbls_lock);
    2661         [ #  # ]:          0 :         if (!standalone)
    2662         [ #  # ]:          0 :                 LIST_INSERT_HEAD(&priv->ind_tbls, ind_tbl, next);
    2663                 :            :         else
    2664         [ #  # ]:          0 :                 LIST_INSERT_HEAD(&priv->standalone_ind_tbls, ind_tbl, next);
    2665                 :            :         rte_rwlock_write_unlock(&priv->ind_tbls_lock);
    2666                 :            : 
    2667                 :          0 :         return ind_tbl;
    2668                 :            : }
    2669                 :            : 
    2670                 :            : static int
    2671                 :          0 : mlx5_ind_table_obj_check_standalone(struct rte_eth_dev *dev __rte_unused,
    2672                 :            :                                     struct mlx5_ind_table_obj *ind_tbl)
    2673                 :            : {
    2674                 :            :         uint32_t refcnt;
    2675                 :            : 
    2676                 :          0 :         refcnt = rte_atomic_load_explicit(&ind_tbl->refcnt, rte_memory_order_relaxed);
    2677         [ #  # ]:          0 :         if (refcnt <= 1)
    2678                 :            :                 return 0;
    2679                 :            :         /*
    2680                 :            :          * Modification of indirection tables having more than 1
    2681                 :            :          * reference is unsupported.
    2682                 :            :          */
    2683                 :          0 :         DRV_LOG(DEBUG,
    2684                 :            :                 "Port %u cannot modify indirection table %p (refcnt %u > 1).",
    2685                 :            :                 dev->data->port_id, (void *)ind_tbl, refcnt);
    2686                 :          0 :         rte_errno = EINVAL;
    2687                 :          0 :         return -rte_errno;
    2688                 :            : }
    2689                 :            : 
    2690                 :            : /**
    2691                 :            :  * Modify an indirection table.
    2692                 :            :  *
    2693                 :            :  * @param dev
    2694                 :            :  *   Pointer to Ethernet device.
    2695                 :            :  * @param ind_table
    2696                 :            :  *   Indirection table to modify.
    2697                 :            :  * @param queues
    2698                 :            :  *   Queues replacement for the indirection table.
    2699                 :            :  * @param queues_n
    2700                 :            :  *   Number of queues in the array.
    2701                 :            :  * @param standalone
    2702                 :            :  *   Indirection table for Standalone queue.
    2703                 :            :  * @param ref_new_qs
    2704                 :            :  *   Whether to increment new RxQ set reference counters.
    2705                 :            :  * @param deref_old_qs
    2706                 :            :  *   Whether to decrement old RxQ set reference counters.
    2707                 :            :  *
    2708                 :            :  * @return
    2709                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2710                 :            :  */
    2711                 :            : int
    2712                 :          0 : mlx5_ind_table_obj_modify(struct rte_eth_dev *dev,
    2713                 :            :                           struct mlx5_ind_table_obj *ind_tbl,
    2714                 :            :                           uint16_t *queues, const uint32_t queues_n,
    2715                 :            :                           bool standalone, bool ref_new_qs, bool deref_old_qs)
    2716                 :            : {
    2717         [ #  # ]:          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2718                 :            :         int ret;
    2719                 :            :         const unsigned int n = rte_is_power_of_2(queues_n) ?
    2720                 :            :                                log2above(queues_n) :
    2721                 :          0 :                                log2above(priv->sh->dev_cap.ind_table_max_size);
    2722                 :            : 
    2723                 :            :         MLX5_ASSERT(standalone);
    2724                 :            :         RTE_SET_USED(standalone);
    2725         [ #  # ]:          0 :         if (mlx5_ind_table_obj_check_standalone(dev, ind_tbl) < 0)
    2726                 :          0 :                 return -rte_errno;
    2727   [ #  #  #  # ]:          0 :         if (ref_new_qs && mlx5_rxqs_ref(dev, queues, queues_n) < 0) {
    2728                 :          0 :                 DRV_LOG(DEBUG, "Port %u invalid indirection table queues.",
    2729                 :            :                         dev->data->port_id);
    2730                 :          0 :                 return -rte_errno;
    2731                 :            :         }
    2732                 :            :         MLX5_ASSERT(priv->obj_ops.ind_table_modify);
    2733                 :          0 :         ret = priv->obj_ops.ind_table_modify(dev, n, queues, queues_n, ind_tbl);
    2734         [ #  # ]:          0 :         if (ret) {
    2735                 :          0 :                 DRV_LOG(DEBUG, "Port %u cannot modify indirection table.",
    2736                 :            :                         dev->data->port_id);
    2737         [ #  # ]:          0 :                 if (ref_new_qs) {
    2738                 :          0 :                         int err = rte_errno;
    2739                 :            : 
    2740                 :          0 :                         mlx5_rxqs_deref(dev, queues, queues_n);
    2741                 :          0 :                         rte_errno = err;
    2742                 :            :                 }
    2743                 :          0 :                 return ret;
    2744                 :            :         }
    2745         [ #  # ]:          0 :         if (deref_old_qs)
    2746                 :          0 :                 mlx5_rxqs_deref(dev, ind_tbl->queues, ind_tbl->queues_n);
    2747                 :          0 :         ind_tbl->queues_n = queues_n;
    2748                 :          0 :         ind_tbl->queues = queues;
    2749                 :          0 :         return 0;
    2750                 :            : }
    2751                 :            : 
    2752                 :            : /**
    2753                 :            :  * Attach an indirection table to its queues.
    2754                 :            :  *
    2755                 :            :  * @param dev
    2756                 :            :  *   Pointer to Ethernet device.
    2757                 :            :  * @param ind_table
    2758                 :            :  *   Indirection table to attach.
    2759                 :            :  *
    2760                 :            :  * @return
    2761                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2762                 :            :  */
    2763                 :            : int
    2764                 :          0 : mlx5_ind_table_obj_attach(struct rte_eth_dev *dev,
    2765                 :            :                           struct mlx5_ind_table_obj *ind_tbl)
    2766                 :            : {
    2767                 :            :         int ret;
    2768                 :            : 
    2769                 :          0 :         ret = mlx5_ind_table_obj_modify(dev, ind_tbl, ind_tbl->queues,
    2770                 :            :                                         ind_tbl->queues_n,
    2771                 :            :                                         true /* standalone */,
    2772                 :            :                                         true /* ref_new_qs */,
    2773                 :            :                                         false /* deref_old_qs */);
    2774         [ #  # ]:          0 :         if (ret != 0)
    2775                 :          0 :                 DRV_LOG(ERR, "Port %u could not modify indirect table obj %p",
    2776                 :            :                         dev->data->port_id, (void *)ind_tbl);
    2777                 :          0 :         return ret;
    2778                 :            : }
    2779                 :            : 
    2780                 :            : /**
    2781                 :            :  * Detach an indirection table from its queues.
    2782                 :            :  *
    2783                 :            :  * @param dev
    2784                 :            :  *   Pointer to Ethernet device.
    2785                 :            :  * @param ind_table
    2786                 :            :  *   Indirection table to detach.
    2787                 :            :  *
    2788                 :            :  * @return
    2789                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2790                 :            :  */
    2791                 :            : int
    2792                 :          0 : mlx5_ind_table_obj_detach(struct rte_eth_dev *dev,
    2793                 :            :                           struct mlx5_ind_table_obj *ind_tbl)
    2794                 :            : {
    2795                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2796         [ #  # ]:          0 :         const unsigned int n = rte_is_power_of_2(ind_tbl->queues_n) ?
    2797                 :            :                                log2above(ind_tbl->queues_n) :
    2798                 :          0 :                                log2above(priv->sh->dev_cap.ind_table_max_size);
    2799                 :            :         unsigned int i;
    2800                 :            :         int ret;
    2801                 :            : 
    2802                 :          0 :         ret = mlx5_ind_table_obj_check_standalone(dev, ind_tbl);
    2803         [ #  # ]:          0 :         if (ret != 0)
    2804                 :            :                 return ret;
    2805                 :            :         MLX5_ASSERT(priv->obj_ops.ind_table_modify);
    2806                 :          0 :         ret = priv->obj_ops.ind_table_modify(dev, n, NULL, 0, ind_tbl);
    2807         [ #  # ]:          0 :         if (ret != 0) {
    2808                 :          0 :                 DRV_LOG(ERR, "Port %u could not modify indirect table obj %p",
    2809                 :            :                         dev->data->port_id, (void *)ind_tbl);
    2810                 :          0 :                 return ret;
    2811                 :            :         }
    2812         [ #  # ]:          0 :         for (i = 0; i < ind_tbl->queues_n; i++)
    2813                 :          0 :                 mlx5_rxq_release(dev, ind_tbl->queues[i]);
    2814                 :            :         return ret;
    2815                 :            : }
    2816                 :            : 
    2817                 :            : int
    2818                 :          0 : mlx5_hrxq_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
    2819                 :            :                    void *cb_ctx)
    2820                 :            : {
    2821                 :            :         struct mlx5_flow_cb_ctx *ctx = cb_ctx;
    2822                 :          0 :         struct mlx5_flow_rss_desc *rss_desc = ctx->data;
    2823                 :            :         struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
    2824                 :            : 
    2825                 :          0 :         return (hrxq->rss_key_len != rss_desc->key_len ||
    2826         [ #  # ]:          0 :             hrxq->symmetric_hash_function != rss_desc->symmetric_hash_function ||
    2827         [ #  # ]:          0 :             memcmp(hrxq->rss_key, rss_desc->key, rss_desc->key_len) ||
    2828         [ #  # ]:          0 :             hrxq->hws_flags != rss_desc->hws_flags ||
    2829         [ #  # ]:          0 :             hrxq->hash_fields != rss_desc->hash_fields ||
    2830   [ #  #  #  # ]:          0 :             hrxq->ind_table->queues_n != rss_desc->queue_num ||
    2831                 :          0 :             memcmp(hrxq->ind_table->queues, rss_desc->queue,
    2832         [ #  # ]:          0 :             rss_desc->queue_num * sizeof(rss_desc->queue[0])));
    2833                 :            : }
    2834                 :            : 
    2835                 :            : /**
    2836                 :            :  * Modify an Rx Hash queue configuration.
    2837                 :            :  *
    2838                 :            :  * @param dev
    2839                 :            :  *   Pointer to Ethernet device.
    2840                 :            :  * @param hrxq
    2841                 :            :  *   Index to Hash Rx queue to modify.
    2842                 :            :  * @param rss_key
    2843                 :            :  *   RSS key for the Rx hash queue.
    2844                 :            :  * @param rss_key_len
    2845                 :            :  *   RSS key length.
    2846                 :            :  * @param hash_fields
    2847                 :            :  *   Verbs protocol hash field to make the RSS on.
    2848                 :            :  * @param queues
    2849                 :            :  *   Queues entering in hash queue. In case of empty hash_fields only the
    2850                 :            :  *   first queue index will be taken for the indirection table.
    2851                 :            :  * @param queues_n
    2852                 :            :  *   Number of queues.
    2853                 :            :  *
    2854                 :            :  * @return
    2855                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2856                 :            :  */
    2857                 :            : int
    2858                 :          0 : mlx5_hrxq_modify(struct rte_eth_dev *dev, uint32_t hrxq_idx,
    2859                 :            :                  const uint8_t *rss_key, uint32_t rss_key_len,
    2860                 :            :                  uint64_t hash_fields, bool symmetric_hash_function,
    2861                 :            :                  const uint16_t *queues, uint32_t queues_n)
    2862                 :            : {
    2863                 :            :         int err;
    2864                 :            :         struct mlx5_ind_table_obj *ind_tbl = NULL;
    2865                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2866                 :            :         struct mlx5_hrxq *hrxq =
    2867                 :          0 :                 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
    2868                 :          0 :         bool dev_started = !!dev->data->dev_started;
    2869                 :            :         int ret;
    2870                 :            : 
    2871         [ #  # ]:          0 :         if (!hrxq) {
    2872                 :          0 :                 rte_errno = EINVAL;
    2873                 :          0 :                 return -rte_errno;
    2874                 :            :         }
    2875                 :            :         /* validations */
    2876         [ #  # ]:          0 :         if (hrxq->rss_key_len != rss_key_len) {
    2877                 :            :                 /* rss_key_len is fixed size 40 byte & not supposed to change */
    2878                 :          0 :                 rte_errno = EINVAL;
    2879                 :          0 :                 return -rte_errno;
    2880                 :            :         }
    2881         [ #  # ]:          0 :         queues_n = hash_fields ? queues_n : 1;
    2882         [ #  # ]:          0 :         if (mlx5_ind_table_obj_match_queues(hrxq->ind_table,
    2883                 :            :                                             queues, queues_n)) {
    2884                 :            :                 ind_tbl = hrxq->ind_table;
    2885                 :            :         } else {
    2886         [ #  # ]:          0 :                 if (hrxq->standalone) {
    2887                 :            :                         /*
    2888                 :            :                          * Replacement of indirection table unsupported for
    2889                 :            :                          * standalone hrxq objects (used by shared RSS).
    2890                 :            :                          */
    2891                 :          0 :                         rte_errno = ENOTSUP;
    2892                 :          0 :                         return -rte_errno;
    2893                 :            :                 }
    2894                 :          0 :                 ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
    2895         [ #  # ]:          0 :                 if (!ind_tbl)
    2896                 :          0 :                         ind_tbl = mlx5_ind_table_obj_new(dev, queues, queues_n,
    2897                 :          0 :                                                          hrxq->standalone,
    2898                 :            :                                                          dev_started);
    2899                 :            :         }
    2900         [ #  # ]:          0 :         if (!ind_tbl) {
    2901                 :          0 :                 rte_errno = ENOMEM;
    2902                 :          0 :                 return -rte_errno;
    2903                 :            :         }
    2904                 :            :         MLX5_ASSERT(priv->obj_ops.hrxq_modify);
    2905                 :          0 :         ret = priv->obj_ops.hrxq_modify(dev, hrxq, rss_key, hash_fields,
    2906                 :            :                                         symmetric_hash_function, ind_tbl);
    2907         [ #  # ]:          0 :         if (ret) {
    2908                 :          0 :                 rte_errno = errno;
    2909                 :          0 :                 goto error;
    2910                 :            :         }
    2911         [ #  # ]:          0 :         if (ind_tbl != hrxq->ind_table) {
    2912                 :            :                 MLX5_ASSERT(!hrxq->standalone);
    2913                 :          0 :                 mlx5_ind_table_obj_release(dev, hrxq->ind_table, true);
    2914                 :          0 :                 hrxq->ind_table = ind_tbl;
    2915                 :            :         }
    2916                 :          0 :         hrxq->hash_fields = hash_fields;
    2917                 :          0 :         memcpy(hrxq->rss_key, rss_key, rss_key_len);
    2918                 :          0 :         return 0;
    2919                 :            : error:
    2920                 :            :         err = rte_errno;
    2921         [ #  # ]:          0 :         if (ind_tbl != hrxq->ind_table) {
    2922                 :            :                 MLX5_ASSERT(!hrxq->standalone);
    2923                 :          0 :                 mlx5_ind_table_obj_release(dev, ind_tbl, true);
    2924                 :            :         }
    2925                 :          0 :         rte_errno = err;
    2926                 :          0 :         return -rte_errno;
    2927                 :            : }
    2928                 :            : 
    2929                 :            : static void
    2930                 :          0 : __mlx5_hrxq_remove(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq)
    2931                 :            : {
    2932                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2933                 :            :         bool deref_rxqs = true;
    2934                 :            : 
    2935                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
    2936         [ #  # ]:          0 :         if (hrxq->hws_flags)
    2937                 :          0 :                 mlx5dr_action_destroy(hrxq->action);
    2938                 :            :         else
    2939                 :          0 :                 mlx5_glue->destroy_flow_action(hrxq->action);
    2940                 :            : #endif
    2941                 :          0 :         priv->obj_ops.hrxq_destroy(hrxq);
    2942         [ #  # ]:          0 :         if (!hrxq->standalone) {
    2943   [ #  #  #  # ]:          0 :                 if (!dev->data->dev_started && hrxq->hws_flags &&
    2944         [ #  # ]:          0 :                     !priv->hws_rule_flushing)
    2945                 :            :                         deref_rxqs = false;
    2946                 :          0 :                 mlx5_ind_table_obj_release(dev, hrxq->ind_table, deref_rxqs);
    2947                 :            :         }
    2948                 :          0 :         mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq->idx);
    2949                 :          0 : }
    2950                 :            : 
    2951                 :            : /**
    2952                 :            :  * Release the hash Rx queue.
    2953                 :            :  *
    2954                 :            :  * @param dev
    2955                 :            :  *   Pointer to Ethernet device.
    2956                 :            :  * @param hrxq
    2957                 :            :  *   Index to Hash Rx queue to release.
    2958                 :            :  *
    2959                 :            :  * @param list
    2960                 :            :  *   mlx5 list pointer.
    2961                 :            :  * @param entry
    2962                 :            :  *   Hash queue entry pointer.
    2963                 :            :  */
    2964                 :            : void
    2965                 :          0 : mlx5_hrxq_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
    2966                 :            : {
    2967                 :            :         struct rte_eth_dev *dev = tool_ctx;
    2968                 :            :         struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
    2969                 :            : 
    2970                 :          0 :         __mlx5_hrxq_remove(dev, hrxq);
    2971                 :          0 : }
    2972                 :            : 
    2973                 :            : static struct mlx5_hrxq *
    2974                 :          0 : __mlx5_hrxq_create(struct rte_eth_dev *dev,
    2975                 :            :                    struct mlx5_flow_rss_desc *rss_desc)
    2976                 :            : {
    2977                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2978                 :          0 :         const uint8_t *rss_key = rss_desc->key;
    2979                 :          0 :         uint32_t rss_key_len =  rss_desc->key_len;
    2980                 :          0 :         bool standalone = !!rss_desc->shared_rss;
    2981                 :            :         const uint16_t *queues =
    2982         [ #  # ]:          0 :                 standalone ? rss_desc->const_q : rss_desc->queue;
    2983                 :          0 :         uint32_t queues_n = rss_desc->queue_num;
    2984                 :            :         struct mlx5_hrxq *hrxq = NULL;
    2985                 :          0 :         uint32_t hrxq_idx = 0;
    2986                 :          0 :         struct mlx5_ind_table_obj *ind_tbl = rss_desc->ind_tbl;
    2987                 :            :         int ret;
    2988                 :            : 
    2989         [ #  # ]:          0 :         queues_n = rss_desc->hash_fields ? queues_n : 1;
    2990   [ #  #  #  # ]:          0 :         if (!ind_tbl && !rss_desc->hws_flags)
    2991                 :          0 :                 ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
    2992         [ #  # ]:          0 :         if (!ind_tbl)
    2993                 :          0 :                 ind_tbl = mlx5_ind_table_obj_new(dev, queues, queues_n,
    2994                 :          0 :                                                  standalone ||
    2995         [ #  # ]:          0 :                                                  rss_desc->hws_flags,
    2996         [ #  # ]:          0 :                                                  !!dev->data->dev_started);
    2997         [ #  # ]:          0 :         if (!ind_tbl)
    2998                 :            :                 return NULL;
    2999                 :          0 :         hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
    3000         [ #  # ]:          0 :         if (!hrxq)
    3001                 :          0 :                 goto error;
    3002                 :          0 :         hrxq->standalone = standalone;
    3003                 :          0 :         hrxq->idx = hrxq_idx;
    3004                 :          0 :         hrxq->ind_table = ind_tbl;
    3005                 :          0 :         hrxq->rss_key_len = rss_key_len;
    3006                 :          0 :         hrxq->hash_fields = rss_desc->hash_fields;
    3007                 :          0 :         hrxq->hws_flags = rss_desc->hws_flags;
    3008                 :          0 :         hrxq->symmetric_hash_function = rss_desc->symmetric_hash_function;
    3009                 :          0 :         memcpy(hrxq->rss_key, rss_key, rss_key_len);
    3010                 :          0 :         ret = priv->obj_ops.hrxq_new(dev, hrxq, rss_desc->tunnel);
    3011         [ #  # ]:          0 :         if (ret < 0)
    3012                 :          0 :                 goto error;
    3013                 :            :         return hrxq;
    3014                 :          0 : error:
    3015         [ #  # ]:          0 :         if (!rss_desc->ind_tbl)
    3016                 :          0 :                 mlx5_ind_table_obj_release(dev, ind_tbl, true);
    3017         [ #  # ]:          0 :         if (hrxq)
    3018                 :          0 :                 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
    3019                 :            :         return NULL;
    3020                 :            : }
    3021                 :            : 
    3022                 :            : struct mlx5_list_entry *
    3023                 :          0 : mlx5_hrxq_create_cb(void *tool_ctx, void *cb_ctx)
    3024                 :            : {
    3025                 :            :         struct rte_eth_dev *dev = tool_ctx;
    3026                 :            :         struct mlx5_flow_cb_ctx *ctx = cb_ctx;
    3027                 :          0 :         struct mlx5_flow_rss_desc *rss_desc = ctx->data;
    3028                 :            :         struct mlx5_hrxq *hrxq;
    3029                 :            : 
    3030                 :          0 :         hrxq = __mlx5_hrxq_create(dev, rss_desc);
    3031         [ #  # ]:          0 :         return hrxq ? &hrxq->entry : NULL;
    3032                 :            : }
    3033                 :            : 
    3034                 :            : struct mlx5_list_entry *
    3035                 :          0 : mlx5_hrxq_clone_cb(void *tool_ctx, struct mlx5_list_entry *entry,
    3036                 :            :                     void *cb_ctx __rte_unused)
    3037                 :            : {
    3038                 :            :         struct rte_eth_dev *dev = tool_ctx;
    3039                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3040                 :            :         struct mlx5_hrxq *hrxq;
    3041                 :          0 :         uint32_t hrxq_idx = 0;
    3042                 :            : 
    3043                 :          0 :         hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
    3044         [ #  # ]:          0 :         if (!hrxq)
    3045                 :            :                 return NULL;
    3046                 :            :         memcpy(hrxq, entry, sizeof(*hrxq) + MLX5_RSS_HASH_KEY_LEN);
    3047                 :          0 :         hrxq->idx = hrxq_idx;
    3048                 :          0 :         return &hrxq->entry;
    3049                 :            : }
    3050                 :            : 
    3051                 :            : void
    3052                 :          0 : mlx5_hrxq_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
    3053                 :            : {
    3054                 :            :         struct rte_eth_dev *dev = tool_ctx;
    3055                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3056                 :            :         struct mlx5_hrxq *hrxq = container_of(entry, typeof(*hrxq), entry);
    3057                 :            : 
    3058                 :          0 :         mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq->idx);
    3059                 :          0 : }
    3060                 :            : 
    3061                 :            : /**
    3062                 :            :  * Get an Rx Hash queue.
    3063                 :            :  *
    3064                 :            :  * @param dev
    3065                 :            :  *   Pointer to Ethernet device.
    3066                 :            :  * @param rss_desc
    3067                 :            :  *   RSS configuration for the Rx hash queue.
    3068                 :            :  *
    3069                 :            :  * @return
    3070                 :            :  *   An hash Rx queue on success.
    3071                 :            :  */
    3072                 :          0 : struct mlx5_hrxq *mlx5_hrxq_get(struct rte_eth_dev *dev,
    3073                 :            :                        struct mlx5_flow_rss_desc *rss_desc)
    3074                 :            : {
    3075                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3076                 :            :         struct mlx5_hrxq *hrxq = NULL;
    3077                 :            :         struct mlx5_list_entry *entry;
    3078                 :          0 :         struct mlx5_flow_cb_ctx ctx = {
    3079                 :            :                 .data = rss_desc,
    3080                 :            :         };
    3081                 :            : 
    3082         [ #  # ]:          0 :         if (rss_desc->shared_rss) {
    3083                 :          0 :                 hrxq = __mlx5_hrxq_create(dev, rss_desc);
    3084                 :            :         } else {
    3085                 :          0 :                 entry = mlx5_list_register(priv->hrxqs, &ctx);
    3086         [ #  # ]:          0 :                 if (!entry)
    3087                 :          0 :                         return NULL;
    3088                 :            :                 hrxq = container_of(entry, typeof(*hrxq), entry);
    3089                 :            :         }
    3090                 :            :         return hrxq;
    3091                 :            : }
    3092                 :            : 
    3093                 :            : /**
    3094                 :            :  * Release the hash Rx queue.
    3095                 :            :  *
    3096                 :            :  * @param dev
    3097                 :            :  *   Pointer to Ethernet device.
    3098                 :            :  * @param hrxq_idx
    3099                 :            :  *   Hash Rx queue to release.
    3100                 :            :  *
    3101                 :            :  * @return
    3102                 :            :  *   1 while a reference on it exists, 0 when freed.
    3103                 :            :  */
    3104                 :          0 : int mlx5_hrxq_obj_release(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq)
    3105                 :            : {
    3106                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3107                 :            : 
    3108         [ #  # ]:          0 :         if (!hrxq)
    3109                 :            :                 return 0;
    3110         [ #  # ]:          0 :         if (!hrxq->standalone)
    3111                 :          0 :                 return mlx5_list_unregister(priv->hrxqs, &hrxq->entry);
    3112                 :          0 :         __mlx5_hrxq_remove(dev, hrxq);
    3113                 :          0 :         return 0;
    3114                 :            : }
    3115                 :            : 
    3116                 :            : /**
    3117                 :            :  * Release the hash Rx queue with index.
    3118                 :            :  *
    3119                 :            :  * @param dev
    3120                 :            :  *   Pointer to Ethernet device.
    3121                 :            :  * @param hrxq_idx
    3122                 :            :  *   Index to Hash Rx queue to release.
    3123                 :            :  *
    3124                 :            :  * @return
    3125                 :            :  *   1 while a reference on it exists, 0 when freed.
    3126                 :            :  */
    3127                 :          0 : int mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hrxq_idx)
    3128                 :            : {
    3129                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3130                 :            :         struct mlx5_hrxq *hrxq;
    3131                 :            : 
    3132                 :          0 :         hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
    3133                 :          0 :         return mlx5_hrxq_obj_release(dev, hrxq);
    3134                 :            : }
    3135                 :            : 
    3136                 :            : /**
    3137                 :            :  * Create a drop Rx Hash queue.
    3138                 :            :  *
    3139                 :            :  * @param dev
    3140                 :            :  *   Pointer to Ethernet device.
    3141                 :            :  *
    3142                 :            :  * @return
    3143                 :            :  *   The Verbs/DevX object initialized, NULL otherwise and rte_errno is set.
    3144                 :            :  */
    3145                 :            : struct mlx5_hrxq *
    3146                 :          0 : mlx5_drop_action_create(struct rte_eth_dev *dev)
    3147                 :            : {
    3148                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3149                 :            :         struct mlx5_hrxq *hrxq = NULL;
    3150                 :            :         int ret;
    3151                 :            : 
    3152         [ #  # ]:          0 :         if (priv->drop_queue.hrxq)
    3153                 :            :                 return priv->drop_queue.hrxq;
    3154                 :          0 :         hrxq = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hrxq) + MLX5_RSS_HASH_KEY_LEN, 0, SOCKET_ID_ANY);
    3155         [ #  # ]:          0 :         if (!hrxq) {
    3156                 :          0 :                 DRV_LOG(WARNING,
    3157                 :            :                         "Port %u cannot allocate memory for drop queue.",
    3158                 :            :                         dev->data->port_id);
    3159                 :          0 :                 rte_errno = ENOMEM;
    3160                 :          0 :                 goto error;
    3161                 :            :         }
    3162                 :          0 :         priv->drop_queue.hrxq = hrxq;
    3163                 :          0 :         hrxq->ind_table = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*hrxq->ind_table),
    3164                 :            :                                       0, SOCKET_ID_ANY);
    3165         [ #  # ]:          0 :         if (!hrxq->ind_table) {
    3166                 :          0 :                 rte_errno = ENOMEM;
    3167                 :          0 :                 goto error;
    3168                 :            :         }
    3169                 :          0 :         ret = priv->obj_ops.drop_action_create(dev);
    3170         [ #  # ]:          0 :         if (ret < 0)
    3171                 :          0 :                 goto error;
    3172                 :            :         return hrxq;
    3173                 :          0 : error:
    3174         [ #  # ]:          0 :         if (hrxq) {
    3175         [ #  # ]:          0 :                 if (hrxq->ind_table)
    3176                 :          0 :                         mlx5_free(hrxq->ind_table);
    3177                 :          0 :                 priv->drop_queue.hrxq = NULL;
    3178                 :          0 :                 mlx5_free(hrxq);
    3179                 :            :         }
    3180                 :            :         return NULL;
    3181                 :            : }
    3182                 :            : 
    3183                 :            : /**
    3184                 :            :  * Release a drop hash Rx queue.
    3185                 :            :  *
    3186                 :            :  * @param dev
    3187                 :            :  *   Pointer to Ethernet device.
    3188                 :            :  */
    3189                 :            : void
    3190                 :          0 : mlx5_drop_action_destroy(struct rte_eth_dev *dev)
    3191                 :            : {
    3192                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3193                 :          0 :         struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
    3194                 :            : 
    3195         [ #  # ]:          0 :         if (!priv->drop_queue.hrxq)
    3196                 :            :                 return;
    3197                 :          0 :         priv->obj_ops.drop_action_destroy(dev);
    3198                 :          0 :         mlx5_free(priv->drop_queue.rxq);
    3199                 :          0 :         mlx5_free(hrxq->ind_table);
    3200                 :          0 :         mlx5_free(hrxq);
    3201                 :          0 :         priv->drop_queue.rxq = NULL;
    3202                 :          0 :         priv->drop_queue.hrxq = NULL;
    3203                 :            : }
    3204                 :            : 
    3205                 :            : /**
    3206                 :            :  * Verify the Rx Queue list is empty
    3207                 :            :  *
    3208                 :            :  * @param dev
    3209                 :            :  *   Pointer to Ethernet device.
    3210                 :            :  *
    3211                 :            :  * @return
    3212                 :            :  *   The number of object not released.
    3213                 :            :  */
    3214                 :            : uint32_t
    3215                 :          0 : mlx5_hrxq_verify(struct rte_eth_dev *dev)
    3216                 :            : {
    3217                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3218                 :            : 
    3219                 :          0 :         return mlx5_list_get_entry_num(priv->hrxqs);
    3220                 :            : }
    3221                 :            : 
    3222                 :            : /**
    3223                 :            :  * Set the Rx queue timestamp conversion parameters
    3224                 :            :  *
    3225                 :            :  * @param[in] dev
    3226                 :            :  *   Pointer to the Ethernet device structure.
    3227                 :            :  */
    3228                 :            : void
    3229                 :          0 : mlx5_rxq_timestamp_set(struct rte_eth_dev *dev)
    3230                 :            : {
    3231                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3232                 :          0 :         struct mlx5_dev_ctx_shared *sh = priv->sh;
    3233                 :            :         unsigned int i;
    3234                 :            : 
    3235         [ #  # ]:          0 :         for (i = 0; i != priv->rxqs_n; ++i) {
    3236                 :          0 :                 struct mlx5_rxq_data *data = mlx5_rxq_data_get(dev, i);
    3237                 :            : 
    3238         [ #  # ]:          0 :                 if (data == NULL)
    3239                 :          0 :                         continue;
    3240                 :          0 :                 data->sh = sh;
    3241                 :          0 :                 data->rt_timestamp = sh->dev_cap.rt_timestamp;
    3242                 :            :         }
    3243                 :          0 : }
    3244                 :            : 
    3245                 :            : /**
    3246                 :            :  * Validate given external RxQ rte_plow index, and get pointer to concurrent
    3247                 :            :  * external RxQ object to map/unmap.
    3248                 :            :  *
    3249                 :            :  * @param[in] port_id
    3250                 :            :  *   The port identifier of the Ethernet device.
    3251                 :            :  * @param[in] dpdk_idx
    3252                 :            :  *   Queue index in rte_flow.
    3253                 :            :  *
    3254                 :            :  * @return
    3255                 :            :  *   Pointer to concurrent external RxQ on success,
    3256                 :            :  *   NULL otherwise and rte_errno is set.
    3257                 :            :  */
    3258                 :            : static struct mlx5_external_q *
    3259                 :          0 : mlx5_external_rx_queue_get_validate(uint16_t port_id, uint16_t dpdk_idx)
    3260                 :            : {
    3261                 :            :         struct rte_eth_dev *dev;
    3262                 :            :         struct mlx5_priv *priv;
    3263                 :            :         int ret;
    3264                 :            : 
    3265         [ #  # ]:          0 :         if (dpdk_idx < RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN) {
    3266                 :          0 :                 DRV_LOG(ERR, "Queue index %u should be in range: [%u, %u].",
    3267                 :            :                         dpdk_idx, RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN, UINT16_MAX);
    3268                 :          0 :                 rte_errno = EINVAL;
    3269                 :          0 :                 return NULL;
    3270                 :            :         }
    3271                 :          0 :         ret = mlx5_devx_extq_port_validate(port_id);
    3272         [ #  # ]:          0 :         if (unlikely(ret))
    3273                 :            :                 return NULL;
    3274                 :            :         dev = &rte_eth_devices[port_id];
    3275                 :          0 :         priv = dev->data->dev_private;
    3276                 :            :         /*
    3277                 :            :          * When user configures remote PD and CTX and device creates RxQ by
    3278                 :            :          * DevX, external RxQs array is allocated.
    3279                 :            :          */
    3280                 :            :         MLX5_ASSERT(priv->ext_rxqs != NULL);
    3281                 :          0 :         return &priv->ext_rxqs[dpdk_idx - RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN];
    3282                 :            : }
    3283                 :            : 
    3284                 :            : int
    3285                 :          0 : rte_pmd_mlx5_external_rx_queue_id_map(uint16_t port_id, uint16_t dpdk_idx,
    3286                 :            :                                       uint32_t hw_idx)
    3287                 :            : {
    3288                 :            :         struct mlx5_external_q *ext_rxq;
    3289                 :            :         uint32_t unmapped = 0;
    3290                 :            : 
    3291                 :          0 :         ext_rxq = mlx5_external_rx_queue_get_validate(port_id, dpdk_idx);
    3292         [ #  # ]:          0 :         if (ext_rxq == NULL)
    3293                 :          0 :                 return -rte_errno;
    3294         [ #  # ]:          0 :         if (!rte_atomic_compare_exchange_strong_explicit(&ext_rxq->refcnt, &unmapped, 1,
    3295                 :            :                                          rte_memory_order_relaxed, rte_memory_order_relaxed)) {
    3296         [ #  # ]:          0 :                 if (ext_rxq->hw_id != hw_idx) {
    3297                 :          0 :                         DRV_LOG(ERR, "Port %u external RxQ index %u "
    3298                 :            :                                 "is already mapped to HW index (requesting is "
    3299                 :            :                                 "%u, existing is %u).",
    3300                 :            :                                 port_id, dpdk_idx, hw_idx, ext_rxq->hw_id);
    3301                 :          0 :                         rte_errno = EEXIST;
    3302                 :          0 :                         return -rte_errno;
    3303                 :            :                 }
    3304                 :          0 :                 DRV_LOG(WARNING, "Port %u external RxQ index %u "
    3305                 :            :                         "is already mapped to the requested HW index (%u)",
    3306                 :            :                         port_id, dpdk_idx, hw_idx);
    3307                 :            : 
    3308                 :            :         } else {
    3309                 :          0 :                 ext_rxq->hw_id = hw_idx;
    3310                 :          0 :                 DRV_LOG(DEBUG, "Port %u external RxQ index %u "
    3311                 :            :                         "is successfully mapped to the requested HW index (%u)",
    3312                 :            :                         port_id, dpdk_idx, hw_idx);
    3313                 :            :         }
    3314                 :            :         return 0;
    3315                 :            : }
    3316                 :            : 
    3317                 :            : int
    3318                 :          0 : rte_pmd_mlx5_external_rx_queue_id_unmap(uint16_t port_id, uint16_t dpdk_idx)
    3319                 :            : {
    3320                 :            :         struct mlx5_external_q *ext_rxq;
    3321                 :            :         uint32_t mapped = 1;
    3322                 :            : 
    3323                 :          0 :         ext_rxq = mlx5_external_rx_queue_get_validate(port_id, dpdk_idx);
    3324         [ #  # ]:          0 :         if (ext_rxq == NULL)
    3325                 :          0 :                 return -rte_errno;
    3326         [ #  # ]:          0 :         if (ext_rxq->refcnt > 1) {
    3327                 :          0 :                 DRV_LOG(ERR, "Port %u external RxQ index %u still referenced.",
    3328                 :            :                         port_id, dpdk_idx);
    3329                 :          0 :                 rte_errno = EINVAL;
    3330                 :          0 :                 return -rte_errno;
    3331                 :            :         }
    3332         [ #  # ]:          0 :         if (!rte_atomic_compare_exchange_strong_explicit(&ext_rxq->refcnt, &mapped, 0,
    3333                 :            :                                          rte_memory_order_relaxed, rte_memory_order_relaxed)) {
    3334                 :          0 :                 DRV_LOG(ERR, "Port %u external RxQ index %u doesn't exist.",
    3335                 :            :                         port_id, dpdk_idx);
    3336                 :          0 :                 rte_errno = EINVAL;
    3337                 :          0 :                 return -rte_errno;
    3338                 :            :         }
    3339                 :          0 :         DRV_LOG(DEBUG,
    3340                 :            :                 "Port %u external RxQ index %u is successfully unmapped.",
    3341                 :            :                 port_id, dpdk_idx);
    3342                 :          0 :         return 0;
    3343                 :            : }

Generated by: LCOV version 1.14