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

Generated by: LCOV version 1.14