LCOV - code coverage report
Current view: top level - drivers/net/mlx5 - mlx5_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 367 0.0 %
Date: 2026-07-01 18:02:41 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 205 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 <unistd.h>
       8                 :            : #include <string.h>
       9                 :            : #include <stdint.h>
      10                 :            : #include <stdlib.h>
      11                 :            : #include <errno.h>
      12                 :            : 
      13                 :            : #include <ethdev_driver.h>
      14                 :            : #include <bus_pci_driver.h>
      15                 :            : #include <rte_mbuf.h>
      16                 :            : #include <rte_common.h>
      17                 :            : #include <rte_interrupts.h>
      18                 :            : #include <rte_malloc.h>
      19                 :            : #include <rte_string_fns.h>
      20                 :            : #include <rte_rwlock.h>
      21                 :            : #include <rte_cycles.h>
      22                 :            : 
      23                 :            : #include <mlx5_malloc.h>
      24                 :            : 
      25                 :            : #include "mlx5_rxtx.h"
      26                 :            : #include "mlx5_rx.h"
      27                 :            : #include "mlx5_tx.h"
      28                 :            : #include "mlx5_autoconf.h"
      29                 :            : #include "mlx5_devx.h"
      30                 :            : #include "rte_pmd_mlx5.h"
      31                 :            : 
      32                 :            : /**
      33                 :            :  * Get the interface index from device name.
      34                 :            :  *
      35                 :            :  * @param[in] dev
      36                 :            :  *   Pointer to Ethernet device.
      37                 :            :  *
      38                 :            :  * @return
      39                 :            :  *   Nonzero interface index on success, zero otherwise and rte_errno is set.
      40                 :            :  */
      41                 :            : unsigned int
      42                 :          0 : mlx5_ifindex(const struct rte_eth_dev *dev)
      43                 :            : {
      44                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
      45                 :            :         unsigned int ifindex;
      46                 :            : 
      47                 :            :         MLX5_ASSERT(priv);
      48                 :            :         MLX5_ASSERT(priv->if_index);
      49   [ #  #  #  # ]:          0 :         if (priv->master && priv->sh->bond.ifindex > 0)
      50                 :            :                 ifindex = priv->sh->bond.ifindex;
      51                 :            :         else
      52                 :          0 :                 ifindex = priv->if_index;
      53         [ #  # ]:          0 :         if (!ifindex)
      54                 :          0 :                 rte_errno = ENXIO;
      55                 :          0 :         return ifindex;
      56                 :            : }
      57                 :            : 
      58                 :            : /**
      59                 :            :  * DPDK callback for Ethernet device configuration.
      60                 :            :  *
      61                 :            :  * @param dev
      62                 :            :  *   Pointer to Ethernet device structure.
      63                 :            :  *
      64                 :            :  * @return
      65                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
      66                 :            :  */
      67                 :            : int
      68                 :          0 : mlx5_dev_configure(struct rte_eth_dev *dev)
      69                 :            : {
      70                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
      71                 :          0 :         unsigned int rxqs_n = dev->data->nb_rx_queues;
      72                 :          0 :         unsigned int txqs_n = dev->data->nb_tx_queues;
      73                 :            :         const uint8_t use_app_rss_key =
      74                 :          0 :                 !!dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key;
      75                 :            :         int ret = 0;
      76                 :            : 
      77         [ #  # ]:          0 :         if (use_app_rss_key &&
      78         [ #  # ]:          0 :             (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key_len !=
      79                 :            :              MLX5_RSS_HASH_KEY_LEN)) {
      80                 :          0 :                 DRV_LOG(ERR, "port %u RSS key len must be %s Bytes long",
      81                 :            :                         dev->data->port_id, RTE_STR(MLX5_RSS_HASH_KEY_LEN));
      82                 :          0 :                 rte_errno = EINVAL;
      83                 :          0 :                 return -rte_errno;
      84                 :            :         }
      85                 :          0 :         priv->rss_conf.rss_key = mlx5_realloc(priv->rss_conf.rss_key,
      86                 :            :                                               MLX5_MEM_RTE,
      87                 :            :                                               MLX5_RSS_HASH_KEY_LEN, 0,
      88                 :            :                                               SOCKET_ID_ANY);
      89         [ #  # ]:          0 :         if (!priv->rss_conf.rss_key) {
      90                 :          0 :                 DRV_LOG(ERR, "port %u cannot allocate RSS hash key memory (%u)",
      91                 :            :                         dev->data->port_id, rxqs_n);
      92                 :          0 :                 rte_errno = ENOMEM;
      93                 :          0 :                 return -rte_errno;
      94                 :            :         }
      95                 :            : 
      96         [ #  # ]:          0 :         if ((dev->data->dev_conf.txmode.offloads &
      97         [ #  # ]:          0 :                         RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) &&
      98                 :          0 :                         rte_mbuf_dyn_tx_timestamp_register(NULL, NULL) != 0) {
      99                 :          0 :                 DRV_LOG(ERR, "port %u cannot register Tx timestamp field/flag",
     100                 :            :                         dev->data->port_id);
     101                 :          0 :                 return -rte_errno;
     102                 :            :         }
     103         [ #  # ]:          0 :         memcpy(priv->rss_conf.rss_key,
     104                 :            :                use_app_rss_key ?
     105                 :          0 :                dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key :
     106                 :            :                mlx5_rss_hash_default_key,
     107                 :            :                MLX5_RSS_HASH_KEY_LEN);
     108                 :          0 :         priv->rss_conf.rss_key_len = MLX5_RSS_HASH_KEY_LEN;
     109                 :          0 :         priv->rss_conf.rss_hf = dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
     110                 :          0 :         priv->rxq_privs = mlx5_realloc(priv->rxq_privs,
     111                 :            :                                        MLX5_MEM_RTE | MLX5_MEM_ZERO,
     112                 :            :                                        sizeof(void *) * rxqs_n, 0,
     113                 :            :                                        SOCKET_ID_ANY);
     114   [ #  #  #  # ]:          0 :         if (rxqs_n && priv->rxq_privs == NULL) {
     115                 :          0 :                 DRV_LOG(ERR, "port %u cannot allocate rxq private data",
     116                 :            :                         dev->data->port_id);
     117                 :          0 :                 rte_errno = ENOMEM;
     118                 :          0 :                 return -rte_errno;
     119                 :            :         }
     120                 :          0 :         priv->txqs = (void *)dev->data->tx_queues;
     121         [ #  # ]:          0 :         if (txqs_n != priv->txqs_n) {
     122                 :          0 :                 DRV_LOG(INFO, "port %u Tx queues number update: %u -> %u",
     123                 :            :                         dev->data->port_id, priv->txqs_n, txqs_n);
     124                 :          0 :                 priv->txqs_n = txqs_n;
     125                 :            :         }
     126   [ #  #  #  # ]:          0 :         if (priv->ext_txqs && txqs_n >= MLX5_EXTERNAL_TX_QUEUE_ID_MIN) {
     127                 :          0 :                 DRV_LOG(ERR, "port %u cannot handle this many Tx queues (%u), "
     128                 :            :                         "the maximal number of internal Tx queues is %u",
     129                 :            :                         dev->data->port_id, txqs_n,
     130                 :            :                         MLX5_EXTERNAL_TX_QUEUE_ID_MIN - 1);
     131                 :          0 :                 rte_errno = EINVAL;
     132                 :          0 :                 return -rte_errno;
     133                 :            :         }
     134         [ #  # ]:          0 :         if (rxqs_n > priv->sh->dev_cap.ind_table_max_size) {
     135                 :          0 :                 DRV_LOG(ERR, "port %u cannot handle this many Rx queues (%u)",
     136                 :            :                         dev->data->port_id, rxqs_n);
     137                 :          0 :                 rte_errno = EINVAL;
     138                 :          0 :                 return -rte_errno;
     139                 :            :         }
     140   [ #  #  #  # ]:          0 :         if (priv->ext_rxqs && rxqs_n >= RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN) {
     141                 :          0 :                 DRV_LOG(ERR, "port %u cannot handle this many Rx queues (%u), "
     142                 :            :                         "the maximal number of internal Rx queues is %u",
     143                 :            :                         dev->data->port_id, rxqs_n,
     144                 :            :                         RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN - 1);
     145                 :          0 :                 rte_errno = EINVAL;
     146                 :          0 :                 return -rte_errno;
     147                 :            :         }
     148         [ #  # ]:          0 :         if (rxqs_n != priv->rxqs_n) {
     149                 :          0 :                 DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
     150                 :            :                         dev->data->port_id, priv->rxqs_n, rxqs_n);
     151                 :          0 :                 priv->rxqs_n = rxqs_n;
     152                 :            :         }
     153                 :          0 :         priv->skip_default_rss_reta = 0;
     154                 :          0 :         ret = mlx5_proc_priv_init(dev);
     155         [ #  # ]:          0 :         if (ret)
     156                 :            :                 return ret;
     157                 :          0 :         ret = mlx5_dev_set_mtu(dev, dev->data->mtu);
     158         [ #  # ]:          0 :         if (ret) {
     159                 :          0 :                 DRV_LOG(ERR, "port %u failed to set MTU to %u", dev->data->port_id,
     160                 :            :                         dev->data->mtu);
     161                 :          0 :                 return ret;
     162                 :            :         }
     163                 :            :         return 0;
     164                 :            : }
     165                 :            : 
     166                 :            : /**
     167                 :            :  * Configure default RSS reta.
     168                 :            :  *
     169                 :            :  * @param dev
     170                 :            :  *   Pointer to Ethernet device structure.
     171                 :            :  *
     172                 :            :  * @return
     173                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     174                 :            :  */
     175                 :            : int
     176                 :          0 : mlx5_dev_configure_rss_reta(struct rte_eth_dev *dev)
     177                 :            : {
     178                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     179                 :          0 :         unsigned int rxqs_n = dev->data->nb_rx_queues;
     180                 :            :         unsigned int i;
     181                 :            :         unsigned int j;
     182                 :            :         unsigned int reta_idx_n;
     183                 :            :         int ret = 0;
     184                 :            :         unsigned int *rss_queue_arr = NULL;
     185                 :            :         unsigned int rss_queue_n = 0;
     186                 :            : 
     187         [ #  # ]:          0 :         if (priv->skip_default_rss_reta)
     188                 :            :                 return ret;
     189                 :          0 :         rss_queue_arr = mlx5_malloc(0, rxqs_n * sizeof(unsigned int), 0,
     190                 :            :                                     SOCKET_ID_ANY);
     191         [ #  # ]:          0 :         if (!rss_queue_arr) {
     192                 :          0 :                 DRV_LOG(ERR, "port %u cannot allocate RSS queue list (%u)",
     193                 :            :                         dev->data->port_id, rxqs_n);
     194                 :          0 :                 rte_errno = ENOMEM;
     195                 :          0 :                 return -rte_errno;
     196                 :            :         }
     197         [ #  # ]:          0 :         for (i = 0, j = 0; i < rxqs_n; i++) {
     198                 :          0 :                 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
     199                 :            : 
     200   [ #  #  #  # ]:          0 :                 if (rxq_ctrl && !rxq_ctrl->is_hairpin)
     201                 :          0 :                         rss_queue_arr[j++] = i;
     202                 :            :         }
     203                 :            :         rss_queue_n = j;
     204         [ #  # ]:          0 :         if (rss_queue_n > priv->sh->dev_cap.ind_table_max_size) {
     205                 :          0 :                 DRV_LOG(ERR, "port %u cannot handle this many Rx queues (%u)",
     206                 :            :                         dev->data->port_id, rss_queue_n);
     207                 :          0 :                 rte_errno = EINVAL;
     208                 :          0 :                 mlx5_free(rss_queue_arr);
     209                 :          0 :                 return -rte_errno;
     210                 :            :         }
     211                 :          0 :         DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
     212                 :            :                 dev->data->port_id, priv->rxqs_n, rxqs_n);
     213                 :          0 :         priv->rxqs_n = rxqs_n;
     214                 :            :         /*
     215                 :            :          * If the requested number of RX queues is not a power of two,
     216                 :            :          * use the maximum indirection table size for better balancing.
     217                 :            :          * The result is always rounded to the next power of two.
     218                 :            :          */
     219         [ #  # ]:          0 :         reta_idx_n = (1 << log2above((rss_queue_n & (rss_queue_n - 1)) ?
     220                 :          0 :                                      priv->sh->dev_cap.ind_table_max_size :
     221                 :            :                                      rss_queue_n));
     222                 :          0 :         ret = mlx5_rss_reta_index_resize(dev, reta_idx_n);
     223         [ #  # ]:          0 :         if (ret) {
     224                 :          0 :                 mlx5_free(rss_queue_arr);
     225                 :          0 :                 return ret;
     226                 :            :         }
     227                 :            :         /*
     228                 :            :          * When the number of RX queues is not a power of two,
     229                 :            :          * the remaining table entries are padded with reused WQs
     230                 :            :          * and hashes are not spread uniformly.
     231                 :            :          */
     232         [ #  # ]:          0 :         for (i = 0, j = 0; (i != reta_idx_n); ++i) {
     233                 :          0 :                 (*priv->reta_idx)[i] = rss_queue_arr[j];
     234         [ #  # ]:          0 :                 if (++j == rss_queue_n)
     235                 :            :                         j = 0;
     236                 :            :         }
     237                 :          0 :         mlx5_free(rss_queue_arr);
     238                 :          0 :         return ret;
     239                 :            : }
     240                 :            : 
     241                 :            : /**
     242                 :            :  * Sets default tuning parameters.
     243                 :            :  *
     244                 :            :  * @param dev
     245                 :            :  *   Pointer to Ethernet device.
     246                 :            :  * @param[out] info
     247                 :            :  *   Info structure output buffer.
     248                 :            :  */
     249                 :            : static void
     250                 :          0 : mlx5_set_default_params(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
     251                 :            : {
     252                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     253                 :            : 
     254                 :            :         /* Minimum CPU utilization. */
     255                 :          0 :         info->default_rxportconf.ring_size = 256;
     256                 :          0 :         info->default_txportconf.ring_size = 256;
     257                 :          0 :         info->default_rxportconf.burst_size = MLX5_RX_DEFAULT_BURST;
     258                 :          0 :         info->default_txportconf.burst_size = MLX5_TX_DEFAULT_BURST;
     259         [ #  # ]:          0 :         if (priv->link_speed_capa >> rte_bsf32(RTE_ETH_LINK_SPEED_100G)) {
     260                 :            :                 /* if supports at least 100G */
     261                 :          0 :                 info->default_rxportconf.nb_queues = 16;
     262                 :          0 :                 info->default_txportconf.nb_queues = 16;
     263         [ #  # ]:          0 :                 if (dev->data->nb_rx_queues > 2 ||
     264         [ #  # ]:          0 :                     dev->data->nb_tx_queues > 2) {
     265                 :            :                         /* Max Throughput. */
     266                 :          0 :                         info->default_rxportconf.ring_size = 2048;
     267                 :          0 :                         info->default_txportconf.ring_size = 2048;
     268                 :            :                 }
     269                 :            :         } else {
     270                 :          0 :                 info->default_rxportconf.nb_queues = 8;
     271                 :          0 :                 info->default_txportconf.nb_queues = 8;
     272         [ #  # ]:          0 :                 if (dev->data->nb_rx_queues > 2 ||
     273         [ #  # ]:          0 :                     dev->data->nb_tx_queues > 2) {
     274                 :            :                         /* Max Throughput. */
     275                 :          0 :                         info->default_rxportconf.ring_size = 4096;
     276                 :          0 :                         info->default_txportconf.ring_size = 4096;
     277                 :            :                 }
     278                 :            :         }
     279                 :          0 : }
     280                 :            : 
     281                 :            : /**
     282                 :            :  * Sets tx mbuf limiting parameters.
     283                 :            :  *
     284                 :            :  * @param dev
     285                 :            :  *   Pointer to Ethernet device.
     286                 :            :  * @param[out] info
     287                 :            :  *   Info structure output buffer.
     288                 :            :  */
     289                 :            : static void
     290                 :            : mlx5_set_txlimit_params(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
     291                 :            : {
     292                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     293                 :            :         struct mlx5_port_config *config = &priv->config;
     294                 :            :         unsigned int inlen;
     295                 :            :         uint16_t nb_max;
     296                 :            : 
     297         [ #  # ]:          0 :         inlen = (config->txq_inline_max == MLX5_ARG_UNSET) ?
     298                 :            :                 MLX5_SEND_DEF_INLINE_LEN :
     299                 :            :                 (unsigned int)config->txq_inline_max;
     300                 :            :         MLX5_ASSERT(config->txq_inline_min >= 0);
     301                 :          0 :         inlen = RTE_MAX(inlen, (unsigned int)config->txq_inline_min);
     302                 :          0 :         inlen = RTE_MIN(inlen, MLX5_WQE_SIZE_MAX +
     303                 :            :                                MLX5_ESEG_MIN_INLINE_SIZE -
     304                 :            :                                MLX5_WQE_CSEG_SIZE -
     305                 :            :                                MLX5_WQE_ESEG_SIZE -
     306                 :            :                                MLX5_WQE_DSEG_SIZE * 2);
     307                 :          0 :         nb_max = (MLX5_WQE_SIZE_MAX +
     308                 :            :                   MLX5_ESEG_MIN_INLINE_SIZE -
     309                 :            :                   MLX5_WQE_CSEG_SIZE -
     310                 :            :                   MLX5_WQE_ESEG_SIZE -
     311                 :          0 :                   MLX5_WQE_DSEG_SIZE -
     312                 :          0 :                   inlen) / MLX5_WSEG_SIZE;
     313                 :          0 :         info->tx_desc_lim.nb_seg_max = nb_max;
     314                 :          0 :         info->tx_desc_lim.nb_mtu_seg_max = nb_max;
     315                 :            : }
     316                 :            : 
     317                 :            : /**
     318                 :            :  * Get maximal work queue size in WQEs
     319                 :            :  *
     320                 :            :  * @param sh
     321                 :            :  *   Pointer to the device shared context.
     322                 :            :  * @return
     323                 :            :  *   Maximal number of WQEs in queue
     324                 :            :  */
     325                 :            : uint16_t
     326                 :          0 : mlx5_dev_get_max_wq_size(struct mlx5_dev_ctx_shared *sh)
     327                 :            : {
     328                 :            :         uint16_t max_wqe = MLX5_WQ_INDEX_MAX;
     329                 :            : 
     330         [ #  # ]:          0 :         if (sh->cdev->config.devx) {
     331                 :            :                 /* use HCA properties for DevX config */
     332                 :            :                 MLX5_ASSERT(sh->cdev->config.hca_attr.log_max_wq_sz != 0);
     333                 :            :                 MLX5_ASSERT(sh->cdev->config.hca_attr.log_max_wq_sz < MLX5_WQ_INDEX_WIDTH);
     334         [ #  # ]:          0 :                 if (sh->cdev->config.hca_attr.log_max_wq_sz != 0 &&
     335                 :            :                     sh->cdev->config.hca_attr.log_max_wq_sz < MLX5_WQ_INDEX_WIDTH)
     336                 :          0 :                         max_wqe = 1u << sh->cdev->config.hca_attr.log_max_wq_sz;
     337                 :            :         } else {
     338                 :            :                 /* use IB device capabilities */
     339                 :            :                 MLX5_ASSERT(sh->dev_cap.max_qp_wr > 0);
     340                 :            :                 MLX5_ASSERT((unsigned int)sh->dev_cap.max_qp_wr <= MLX5_WQ_INDEX_MAX);
     341         [ #  # ]:          0 :                 if (sh->dev_cap.max_qp_wr > 0 &&
     342                 :            :                     (uint32_t)sh->dev_cap.max_qp_wr <= MLX5_WQ_INDEX_MAX)
     343                 :          0 :                         max_wqe = (uint16_t)sh->dev_cap.max_qp_wr;
     344                 :            :         }
     345                 :          0 :         return max_wqe;
     346                 :            : }
     347                 :            : 
     348                 :            : /**
     349                 :            :  * Get switch port ID for given DPDK port.
     350                 :            :  *
     351                 :            :  * @param dev
     352                 :            :  *   Pointer to Ethernet device structure.
     353                 :            :  * @return
     354                 :            :  *   Switch port ID reported through rte_eth_dev_info_get().
     355                 :            :  */
     356                 :            : static uint16_t
     357                 :            : mlx5_dev_switch_info_port_id_get(struct rte_eth_dev *dev)
     358                 :            : {
     359         [ #  # ]:          0 :         if (rte_eth_dev_is_repr(dev))
     360                 :          0 :                 return dev->data->port_id;
     361                 :            : 
     362                 :            :         return UINT16_MAX;
     363                 :            : }
     364                 :            : 
     365                 :            : /**
     366                 :            :  * DPDK callback to get information about the device.
     367                 :            :  *
     368                 :            :  * @param dev
     369                 :            :  *   Pointer to Ethernet device structure.
     370                 :            :  * @param[out] info
     371                 :            :  *   Info structure output buffer.
     372                 :            :  */
     373                 :            : int
     374                 :          0 : mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
     375                 :            : {
     376                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     377                 :            :         unsigned int max;
     378                 :            :         uint16_t max_wqe;
     379                 :            : 
     380                 :          0 :         info->min_mtu = priv->min_mtu;
     381                 :          0 :         info->max_mtu = priv->max_mtu;
     382                 :          0 :         info->max_rx_pktlen = info->max_mtu + MLX5_ETH_OVERHEAD;
     383                 :          0 :         info->min_rx_bufsize = 32;
     384                 :          0 :         info->max_lro_pkt_size = priv->sh->config.lro_allowed ?
     385         [ #  # ]:          0 :                                  MLX5_MAX_LRO_SIZE : 0;
     386                 :            :         /*
     387                 :            :          * Since we need one CQ per QP, the limit is the minimum number
     388                 :            :          * between the two values.
     389                 :            :          */
     390                 :          0 :         max = RTE_MIN(priv->sh->dev_cap.max_cq, priv->sh->dev_cap.max_qp);
     391                 :            :         /* max_rx_queues is uint16_t. */
     392                 :          0 :         max = RTE_MIN(max, (unsigned int)UINT16_MAX);
     393                 :          0 :         info->max_rx_queues = max;
     394                 :          0 :         info->max_tx_queues = max;
     395                 :          0 :         info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;
     396                 :          0 :         info->rx_queue_offload_capa = mlx5_get_rx_queue_offloads(dev);
     397                 :          0 :         info->rx_seg_capa.max_nseg = MLX5_MAX_RXQ_NSEG;
     398                 :          0 :         info->rx_seg_capa.multi_pools = !priv->config.mprq.enabled;
     399                 :          0 :         info->rx_seg_capa.offset_allowed = !priv->config.mprq.enabled;
     400                 :          0 :         info->rx_seg_capa.offset_align_log2 = 0;
     401                 :          0 :         info->rx_seg_capa.selective_rx = !!priv->sh->null_mr;
     402                 :          0 :         info->rx_offload_capa = (mlx5_get_rx_port_offloads() |
     403                 :          0 :                                  info->rx_queue_offload_capa);
     404                 :          0 :         info->tx_offload_capa = mlx5_get_tx_port_offloads(dev);
     405                 :          0 :         info->dev_capa = RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP;
     406                 :          0 :         info->if_index = mlx5_ifindex(dev);
     407         [ #  # ]:          0 :         info->reta_size = priv->reta_idx_n ?
     408                 :          0 :                 priv->reta_idx_n : priv->sh->dev_cap.ind_table_max_size;
     409                 :          0 :         info->hash_key_size = MLX5_RSS_HASH_KEY_LEN;
     410                 :          0 :         info->speed_capa = priv->link_speed_capa;
     411                 :          0 :         info->flow_type_rss_offloads = ~MLX5_RSS_HF_MASK;
     412                 :          0 :         mlx5_set_default_params(dev, info);
     413                 :            :         mlx5_set_txlimit_params(dev, info);
     414                 :          0 :         max_wqe = mlx5_dev_get_max_wq_size(priv->sh);
     415                 :          0 :         info->rx_desc_lim.nb_max = max_wqe;
     416                 :          0 :         info->tx_desc_lim.nb_max = max_wqe;
     417         [ #  # ]:          0 :         if (priv->sh->cdev->config.hca_attr.mem_rq_rmp &&
     418         [ #  # ]:          0 :             priv->obj_ops.rxq_obj_new == mlx5_devx_obj_ops.rxq_obj_new)
     419                 :          0 :                 info->dev_capa |= RTE_ETH_DEV_CAPA_RXQ_SHARE;
     420                 :          0 :         info->switch_info.name = dev->data->name;
     421         [ #  # ]:          0 :         info->switch_info.domain_id = priv->domain_id;
     422                 :          0 :         info->switch_info.port_id = mlx5_dev_switch_info_port_id_get(dev);
     423                 :          0 :         info->switch_info.rx_domain = 0; /* No sub Rx domains. */
     424         [ #  # ]:          0 :         if (priv->representor) {
     425                 :            :                 uint16_t port_id;
     426                 :            : 
     427         [ #  # ]:          0 :                 MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
     428                 :          0 :                         struct mlx5_priv *opriv =
     429                 :          0 :                                 rte_eth_devices[port_id].data->dev_private;
     430                 :            : 
     431   [ #  #  #  # ]:          0 :                         if (!opriv ||
     432                 :          0 :                             opriv->representor ||
     433         [ #  # ]:          0 :                             opriv->sh != priv->sh ||
     434         [ #  # ]:          0 :                             opriv->domain_id != priv->domain_id)
     435                 :            :                                 continue;
     436                 :            :                         /*
     437                 :            :                          * Override switch name with that of the master
     438                 :            :                          * device.
     439                 :            :                          */
     440                 :          0 :                         info->switch_info.name = opriv->dev_data->name;
     441                 :          0 :                         break;
     442                 :            :                 }
     443                 :            :         }
     444                 :          0 :         return 0;
     445                 :            : }
     446                 :            : 
     447                 :            : /**
     448                 :            :  * Calculate representor ID from port switch info.
     449                 :            :  *
     450                 :            :  * Uint16 representor ID bits definition:
     451                 :            :  *   pf: 2
     452                 :            :  *   type: 2
     453                 :            :  *   vf/sf: 12
     454                 :            :  *
     455                 :            :  * @param info
     456                 :            :  *   Port switch info.
     457                 :            :  * @param hpf_type
     458                 :            :  *   Use this type if port is HPF.
     459                 :            :  *
     460                 :            :  * @return
     461                 :            :  *   Encoded representor ID.
     462                 :            :  */
     463                 :            : uint16_t
     464                 :          0 : mlx5_representor_id_encode(const struct mlx5_switch_info *info,
     465                 :            :                            enum rte_eth_representor_type hpf_type)
     466                 :            : {
     467                 :            :         enum rte_eth_representor_type type;
     468                 :          0 :         uint16_t repr = info->port_name;
     469                 :          0 :         int32_t pf = info->pf_num;
     470                 :            : 
     471   [ #  #  #  # ]:          0 :         switch (info->name_type) {
     472                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
     473         [ #  # ]:          0 :                 if (!info->representor)
     474                 :            :                         return UINT16_MAX;
     475                 :            :                 type = RTE_ETH_REPRESENTOR_PF;
     476                 :          0 :                 pf = info->mpesw_owner;
     477                 :          0 :                 break;
     478                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
     479                 :            :                 type = RTE_ETH_REPRESENTOR_SF;
     480                 :            :                 break;
     481                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
     482                 :            :                 type = hpf_type;
     483                 :            :                 repr = UINT16_MAX;
     484                 :          0 :                 break;
     485                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
     486                 :            :         default:
     487                 :            :                 type = RTE_ETH_REPRESENTOR_VF;
     488                 :          0 :                 break;
     489                 :            :         }
     490                 :          0 :         return MLX5_REPRESENTOR_ID(pf, type, repr);
     491                 :            : }
     492                 :            : 
     493                 :            : static unsigned int
     494                 :            : mlx5_representor_info_count_one(struct mlx5_priv *priv)
     495                 :            : {
     496      [ #  #  # ]:          0 :         switch (priv->port_info.type) {
     497                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
     498                 :            :                 return 2;
     499                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
     500                 :            :                 /* Only representor uplinks should be reported */
     501   [ #  #  #  # ]:          0 :                 if (!priv->representor)
     502                 :          0 :                         return 0;
     503                 :            :                 return 1;
     504                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_NOTSET:
     505                 :            :                 /* FALLTHROUGH */
     506                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_LEGACY:
     507                 :            :                 /* FALLTHROUGH */
     508                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
     509                 :            :                 /* FALLTHROUGH */
     510                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
     511                 :            :                 /* FALLTHROUGH */
     512                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN:
     513                 :            :                 /* FALLTHROUGH */
     514                 :            :         default:
     515                 :          0 :                 return 1;
     516                 :            :         }
     517                 :            : }
     518                 :            : 
     519                 :            : static unsigned int
     520                 :          0 : mlx5_representor_info_count(struct rte_eth_dev *dev)
     521                 :            : {
     522                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     523                 :            :         uint16_t port_id;
     524                 :            :         unsigned int count = 0;
     525                 :            : 
     526         [ #  # ]:          0 :         MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
     527                 :          0 :                 struct mlx5_priv *opriv = rte_eth_devices[port_id].data->dev_private;
     528                 :            : 
     529         [ #  # ]:          0 :                 if (!opriv ||
     530         [ #  # ]:          0 :                     opriv->sh != priv->sh ||
     531         [ #  # ]:          0 :                     opriv->domain_id != priv->domain_id)
     532                 :          0 :                         continue;
     533                 :            : 
     534                 :          0 :                 count += mlx5_representor_info_count_one(opriv);
     535                 :            :         }
     536                 :            : 
     537                 :          0 :         return count;
     538                 :            : }
     539                 :            : 
     540                 :            : static void
     541      [ #  #  # ]:          0 : mlx5_representor_info_fill_one(struct mlx5_priv *priv,
     542                 :            :                                struct rte_eth_representor_info *info)
     543                 :            : {
     544                 :            :         struct rte_eth_representor_range *range;
     545                 :            :         unsigned int count;
     546                 :            : 
     547                 :            :         count = mlx5_representor_info_count_one(priv);
     548                 :            :         if (count == 0)
     549                 :            :                 return;
     550                 :            : 
     551         [ #  # ]:          0 :         if (info->nb_ranges + count > info->nb_ranges_alloc) {
     552                 :          0 :                 DRV_LOG(ERR, "port %u representor info already full", priv->dev_data->port_id);
     553                 :          0 :                 return;
     554                 :            :         }
     555                 :            : 
     556                 :          0 :         range = &info->ranges[info->nb_ranges];
     557                 :            : 
     558   [ #  #  #  #  :          0 :         switch (priv->port_info.type) {
                      # ]
     559                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
     560                 :          0 :                 range->type = RTE_ETH_REPRESENTOR_PF;
     561                 :          0 :                 range->controller = priv->port_info.ctrl_num;
     562                 :          0 :                 range->pf = priv->port_info.port_num;
     563                 :          0 :                 range->id_base = priv->dev_data->port_id;
     564                 :          0 :                 range->id_end = range->id_base;
     565                 :          0 :                 snprintf(range->name, sizeof(range->name), "pf%d", range->pf);
     566                 :            :                 break;
     567                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
     568                 :            :                 /* Secondly, fill in SF variant. */
     569                 :          0 :                 range->type = RTE_ETH_REPRESENTOR_SF;
     570                 :          0 :                 range->controller = priv->port_info.ctrl_num;
     571                 :          0 :                 range->pf = priv->port_info.pf_num;
     572                 :          0 :                 range->sf = priv->port_info.port_num;
     573                 :          0 :                 range->id_base = priv->dev_data->port_id;
     574                 :          0 :                 range->id_end = range->id_base;
     575                 :          0 :                 snprintf(range->name, sizeof(range->name), "pf%dsf", range->pf);
     576                 :            :                 break;
     577                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
     578                 :            :                 /*
     579                 :            :                  * Host PF can be probed either through VF(0xffff) or SF(0xffff).
     580                 :            :                  * Firstly fill in VF variant.
     581                 :            :                  */
     582                 :          0 :                 range->type = RTE_ETH_REPRESENTOR_VF;
     583                 :          0 :                 range->controller = priv->port_info.ctrl_num;
     584                 :          0 :                 range->pf = priv->port_info.pf_num;
     585                 :          0 :                 range->vf = UINT16_MAX;
     586                 :          0 :                 range->id_base = priv->dev_data->port_id;
     587                 :          0 :                 range->id_end = range->id_base;
     588                 :          0 :                 snprintf(range->name, sizeof(range->name), "pf%dvf", range->pf);
     589                 :            : 
     590                 :            :                 /* Move the SF variant. */
     591                 :            :                 range++;
     592                 :            : 
     593                 :            :                 /* Fill in SF variant. */
     594                 :          0 :                 range->type = RTE_ETH_REPRESENTOR_SF;
     595                 :          0 :                 range->controller = priv->port_info.ctrl_num;
     596                 :          0 :                 range->pf = priv->port_info.pf_num;
     597                 :          0 :                 range->sf = UINT16_MAX;
     598                 :          0 :                 range->id_base = priv->dev_data->port_id;
     599                 :          0 :                 range->id_end = range->id_base;
     600                 :          0 :                 snprintf(range->name, sizeof(range->name), "pf%dsf", range->pf);
     601                 :            :                 break;
     602                 :          0 :         case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
     603                 :            :                 /* FALLTHROUGH */
     604                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_NOTSET:
     605                 :            :                 /* FALLTHROUGH */
     606                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_LEGACY:
     607                 :            :                 /* FALLTHROUGH */
     608                 :            :         case MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN:
     609                 :          0 :                 range->type = RTE_ETH_REPRESENTOR_VF;
     610                 :          0 :                 range->controller = priv->port_info.ctrl_num;
     611                 :          0 :                 range->pf = priv->port_info.pf_num;
     612                 :          0 :                 range->vf = priv->port_info.port_num;
     613                 :          0 :                 range->id_base = priv->dev_data->port_id;
     614                 :          0 :                 range->id_end = range->id_base;
     615                 :          0 :                 snprintf(range->name, sizeof(range->name), "pf%dvf", range->pf);
     616                 :            :                 break;
     617                 :            :         }
     618                 :            : 
     619                 :          0 :         info->nb_ranges += count;
     620                 :            : }
     621                 :            : 
     622                 :            : static unsigned int
     623                 :          0 : mlx5_representor_info_fill(struct rte_eth_dev *dev,
     624                 :            :                            struct rte_eth_representor_info *info)
     625                 :            : {
     626                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     627                 :            :         uint16_t port_id;
     628                 :            : 
     629                 :          0 :         info->controller = priv->port_info.ctrl_num;
     630                 :          0 :         info->pf = RTE_BUS_DEVICE(dev->device, struct rte_pci_device)->addr.function;
     631                 :            : 
     632         [ #  # ]:          0 :         MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
     633                 :          0 :                 struct mlx5_priv *opriv = rte_eth_devices[port_id].data->dev_private;
     634                 :            : 
     635         [ #  # ]:          0 :                 if (!opriv ||
     636         [ #  # ]:          0 :                     opriv->sh != priv->sh ||
     637         [ #  # ]:          0 :                     opriv->domain_id != priv->domain_id)
     638                 :          0 :                         continue;
     639                 :            : 
     640                 :          0 :                 mlx5_representor_info_fill_one(opriv, info);
     641                 :            :         }
     642                 :            : 
     643                 :          0 :         return info->nb_ranges;
     644                 :            : }
     645                 :            : 
     646                 :            : /**
     647                 :            :  * DPDK callback to get information about representor.
     648                 :            :  *
     649                 :            :  * @param dev
     650                 :            :  *   Pointer to Ethernet device structure.
     651                 :            :  * @param[out] info
     652                 :            :  *   Nullable info structure output buffer.
     653                 :            :  *
     654                 :            :  * @return
     655                 :            :  *   negative on error, or the number of representor ranges.
     656                 :            :  */
     657                 :            : int
     658                 :          0 : mlx5_representor_info_get(struct rte_eth_dev *dev,
     659                 :            :                           struct rte_eth_representor_info *info)
     660                 :            : {
     661         [ #  # ]:          0 :         if (info == NULL)
     662                 :          0 :                 return mlx5_representor_info_count(dev);
     663                 :            : 
     664                 :          0 :         return mlx5_representor_info_fill(dev, info);
     665                 :            : 
     666                 :            : }
     667                 :            : 
     668                 :            : /**
     669                 :            :  * Get firmware version of a device.
     670                 :            :  *
     671                 :            :  * @param dev
     672                 :            :  *   Ethernet device port.
     673                 :            :  * @param fw_ver
     674                 :            :  *   String output allocated by caller.
     675                 :            :  * @param fw_size
     676                 :            :  *   Size of the output string, including terminating null byte.
     677                 :            :  *
     678                 :            :  * @return
     679                 :            :  *   0 on success, or the size of the non truncated string if too big.
     680                 :            :  */
     681                 :            : int
     682                 :          0 : mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
     683                 :            : {
     684                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     685                 :          0 :         struct mlx5_dev_cap *attr = &priv->sh->dev_cap;
     686                 :          0 :         size_t size = strnlen(attr->fw_ver, sizeof(attr->fw_ver)) + 1;
     687                 :            : 
     688         [ #  # ]:          0 :         if (fw_size < size)
     689                 :          0 :                 return size;
     690         [ #  # ]:          0 :         if (fw_ver != NULL)
     691                 :            :                 strlcpy(fw_ver, attr->fw_ver, fw_size);
     692                 :            :         return 0;
     693                 :            : }
     694                 :            : 
     695                 :            : /**
     696                 :            :  * Get supported packet types.
     697                 :            :  *
     698                 :            :  * @param dev
     699                 :            :  *   Pointer to Ethernet device structure.
     700                 :            :  *
     701                 :            :  * @return
     702                 :            :  *   A pointer to the supported Packet types array.
     703                 :            :  */
     704                 :            : const uint32_t *
     705                 :          0 : mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
     706                 :            : {
     707                 :            :         static const uint32_t ptypes[] = {
     708                 :            :                 /* refers to rxq_cq_to_pkt_type() */
     709                 :            :                 RTE_PTYPE_L2_ETHER,
     710                 :            :                 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
     711                 :            :                 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
     712                 :            :                 RTE_PTYPE_L4_NONFRAG,
     713                 :            :                 RTE_PTYPE_L4_FRAG,
     714                 :            :                 RTE_PTYPE_L4_TCP,
     715                 :            :                 RTE_PTYPE_L4_UDP,
     716                 :            :                 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
     717                 :            :                 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
     718                 :            :                 RTE_PTYPE_INNER_L4_NONFRAG,
     719                 :            :                 RTE_PTYPE_INNER_L4_FRAG,
     720                 :            :                 RTE_PTYPE_INNER_L4_TCP,
     721                 :            :                 RTE_PTYPE_INNER_L4_UDP,
     722                 :            :         };
     723                 :            : 
     724   [ #  #  #  # ]:          0 :         if (dev->rx_pkt_burst == mlx5_rx_burst ||
     725         [ #  # ]:          0 :             dev->rx_pkt_burst == mlx5_rx_burst_out_of_order ||
     726         [ #  # ]:          0 :             dev->rx_pkt_burst == mlx5_rx_burst_mprq ||
     727         [ #  # ]:          0 :             dev->rx_pkt_burst == mlx5_rx_burst_vec ||
     728                 :            :             dev->rx_pkt_burst == mlx5_rx_burst_mprq_vec) {
     729                 :          0 :                 *no_of_elements = RTE_DIM(ptypes);
     730                 :          0 :                 return ptypes;
     731                 :            :         }
     732                 :            :         return NULL;
     733                 :            : }
     734                 :            : 
     735                 :            : /**
     736                 :            :  * DPDK callback to change the MTU.
     737                 :            :  *
     738                 :            :  * @param dev
     739                 :            :  *   Pointer to Ethernet device structure.
     740                 :            :  * @param in_mtu
     741                 :            :  *   New MTU.
     742                 :            :  *
     743                 :            :  * @return
     744                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     745                 :            :  */
     746                 :            : int
     747                 :          0 : mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
     748                 :            : {
     749                 :          0 :         uint16_t kern_mtu = 0;
     750                 :            :         int ret;
     751                 :            : 
     752                 :          0 :         ret = mlx5_get_mtu(dev, &kern_mtu);
     753         [ #  # ]:          0 :         if (ret)
     754                 :            :                 return ret;
     755                 :            : 
     756         [ #  # ]:          0 :         if (kern_mtu == mtu) {
     757                 :          0 :                 DRV_LOG(DEBUG, "port %u adapter MTU was already set to %u",
     758                 :            :                         dev->data->port_id, mtu);
     759                 :          0 :                 return 0;
     760                 :            :         }
     761                 :            : 
     762                 :            :         /* Set kernel interface MTU first. */
     763                 :          0 :         ret = mlx5_set_mtu(dev, mtu);
     764         [ #  # ]:          0 :         if (ret)
     765                 :            :                 return ret;
     766                 :          0 :         ret = mlx5_get_mtu(dev, &kern_mtu);
     767         [ #  # ]:          0 :         if (ret)
     768                 :            :                 return ret;
     769         [ #  # ]:          0 :         if (kern_mtu == mtu) {
     770                 :          0 :                 DRV_LOG(DEBUG, "port %u adapter MTU set to %u",
     771                 :            :                         dev->data->port_id, mtu);
     772                 :          0 :                 return 0;
     773                 :            :         }
     774                 :          0 :         rte_errno = EAGAIN;
     775                 :          0 :         return -rte_errno;
     776                 :            : }
     777                 :            : 
     778                 :            : static bool
     779                 :          0 : mlx5_selective_rx_enabled(struct rte_eth_dev *dev)
     780                 :            : {
     781                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     782                 :            : 
     783         [ #  # ]:          0 :         for (uint32_t q = 0; q < priv->rxqs_n; ++q) {
     784                 :          0 :                 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, q);
     785                 :            : 
     786   [ #  #  #  # ]:          0 :                 if (rxq_ctrl == NULL || rxq_ctrl->is_hairpin)
     787                 :          0 :                         continue;
     788         [ #  # ]:          0 :                 for (uint16_t s = 0; s < rxq_ctrl->rxq.rxseg_n; s++) {
     789         [ #  # ]:          0 :                         if (rxq_ctrl->rxq.rxseg[s].mp == NULL)
     790                 :            :                                 return true;
     791                 :            :                 }
     792                 :            :         }
     793                 :            : 
     794                 :            :         return false;
     795                 :            : }
     796                 :            : 
     797                 :            : /**
     798                 :            :  * Configure the RX function to use.
     799                 :            :  *
     800                 :            :  * @param dev
     801                 :            :  *   Pointer to private data structure.
     802                 :            :  *
     803                 :            :  * @return
     804                 :            :  *   Pointer to selected Rx burst function.
     805                 :            :  */
     806                 :            : eth_rx_burst_t
     807                 :          0 : mlx5_select_rx_function(struct rte_eth_dev *dev)
     808                 :            : {
     809                 :            :         eth_rx_burst_t rx_pkt_burst = mlx5_rx_burst;
     810                 :            : 
     811                 :            :         MLX5_ASSERT(dev != NULL);
     812         [ #  # ]:          0 :         if (mlx5_selective_rx_enabled(dev)) {
     813                 :          0 :                 DRV_LOG(DEBUG, "port %u forced to scalar SPRQ Rx (selective Rx configured)",
     814                 :            :                         dev->data->port_id);
     815                 :          0 :                 return rx_pkt_burst;
     816                 :            :         }
     817         [ #  # ]:          0 :         if (mlx5_shared_rq_enabled(dev)) {
     818                 :            :                 rx_pkt_burst = mlx5_rx_burst_out_of_order;
     819                 :          0 :                 DRV_LOG(DEBUG, "port %u forced to use SPRQ"
     820                 :            :                         " Rx function with Out-of-Order completions",
     821                 :            :                         dev->data->port_id);
     822         [ #  # ]:          0 :         } else if (mlx5_check_vec_rx_support(dev) > 0) {
     823         [ #  # ]:          0 :                 if (mlx5_mprq_enabled(dev)) {
     824                 :            :                         rx_pkt_burst = mlx5_rx_burst_mprq_vec;
     825                 :          0 :                         DRV_LOG(DEBUG, "port %u selected vectorized"
     826                 :            :                                 " MPRQ Rx function", dev->data->port_id);
     827                 :            :                 } else {
     828                 :            :                         rx_pkt_burst = mlx5_rx_burst_vec;
     829                 :          0 :                         DRV_LOG(DEBUG, "port %u selected vectorized"
     830                 :            :                                 " SPRQ Rx function", dev->data->port_id);
     831                 :            :                 }
     832         [ #  # ]:          0 :         } else if (mlx5_mprq_enabled(dev)) {
     833                 :            :                 rx_pkt_burst = mlx5_rx_burst_mprq;
     834                 :          0 :                 DRV_LOG(DEBUG, "port %u selected MPRQ Rx function",
     835                 :            :                         dev->data->port_id);
     836                 :            :         } else {
     837                 :          0 :                 DRV_LOG(DEBUG, "port %u selected SPRQ Rx function",
     838                 :            :                         dev->data->port_id);
     839                 :            :         }
     840                 :            :         return rx_pkt_burst;
     841                 :            : }
     842                 :            : 
     843                 :            : /**
     844                 :            :  * Get the E-Switch parameters by port id.
     845                 :            :  *
     846                 :            :  * @param[in] port
     847                 :            :  *   Device port id.
     848                 :            :  * @param[in] valid
     849                 :            :  *   Device port id is valid, skip check. This flag is useful
     850                 :            :  *   when trials are performed from probing and device is not
     851                 :            :  *   flagged as valid yet (in attaching process).
     852                 :            :  * @param[out] es_domain_id
     853                 :            :  *   E-Switch domain id.
     854                 :            :  * @param[out] es_port_id
     855                 :            :  *   The port id of the port in the E-Switch.
     856                 :            :  *
     857                 :            :  * @return
     858                 :            :  *   pointer to device private data structure containing data needed
     859                 :            :  *   on success, NULL otherwise and rte_errno is set.
     860                 :            :  */
     861                 :            : struct mlx5_priv *
     862                 :          0 : mlx5_port_to_eswitch_info(uint16_t port, bool valid)
     863                 :            : {
     864                 :            :         struct rte_eth_dev *dev;
     865                 :            :         struct mlx5_priv *priv;
     866                 :            : 
     867         [ #  # ]:          0 :         if (port >= RTE_MAX_ETHPORTS) {
     868                 :          0 :                 rte_errno = EINVAL;
     869                 :          0 :                 return NULL;
     870                 :            :         }
     871   [ #  #  #  # ]:          0 :         if (!valid && !rte_eth_dev_is_valid_port(port)) {
     872                 :          0 :                 rte_errno = ENODEV;
     873                 :          0 :                 return NULL;
     874                 :            :         }
     875                 :          0 :         dev = &rte_eth_devices[port];
     876                 :          0 :         priv = dev->data->dev_private;
     877         [ #  # ]:          0 :         if (!priv->sh->esw_mode) {
     878                 :          0 :                 rte_errno = EINVAL;
     879                 :          0 :                 return NULL;
     880                 :            :         }
     881                 :            :         return priv;
     882                 :            : }
     883                 :            : 
     884                 :            : /**
     885                 :            :  * Get the E-Switch parameters by device instance.
     886                 :            :  *
     887                 :            :  * @param[in] port
     888                 :            :  *   Device port id.
     889                 :            :  * @param[out] es_domain_id
     890                 :            :  *   E-Switch domain id.
     891                 :            :  * @param[out] es_port_id
     892                 :            :  *   The port id of the port in the E-Switch.
     893                 :            :  *
     894                 :            :  * @return
     895                 :            :  *   pointer to device private data structure containing data needed
     896                 :            :  *   on success, NULL otherwise and rte_errno is set.
     897                 :            :  */
     898                 :            : struct mlx5_priv *
     899                 :          0 : mlx5_dev_to_eswitch_info(struct rte_eth_dev *dev)
     900                 :            : {
     901                 :            :         struct mlx5_priv *priv;
     902                 :            : 
     903                 :          0 :         priv = dev->data->dev_private;
     904         [ #  # ]:          0 :         if (!priv->sh->esw_mode) {
     905                 :          0 :                 rte_errno = EINVAL;
     906                 :          0 :                 return NULL;
     907                 :            :         }
     908                 :            :         return priv;
     909                 :            : }
     910                 :            : 
     911                 :            : /**
     912                 :            :  * DPDK callback to retrieve hairpin capabilities.
     913                 :            :  *
     914                 :            :  * @param dev
     915                 :            :  *   Pointer to Ethernet device structure.
     916                 :            :  * @param[out] cap
     917                 :            :  *   Storage for hairpin capability data.
     918                 :            :  *
     919                 :            :  * @return
     920                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     921                 :            :  */
     922                 :            : int
     923                 :          0 : mlx5_hairpin_cap_get(struct rte_eth_dev *dev, struct rte_eth_hairpin_cap *cap)
     924                 :            : {
     925                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     926                 :            :         struct mlx5_hca_attr *hca_attr;
     927                 :            : 
     928   [ #  #  #  # ]:          0 :         if (!mlx5_devx_obj_ops_en(priv->sh)) {
     929                 :          0 :                 rte_errno = ENOTSUP;
     930                 :          0 :                 return -rte_errno;
     931                 :            :         }
     932                 :          0 :         cap->max_nb_queues = UINT16_MAX;
     933                 :          0 :         cap->max_rx_2_tx = 1;
     934                 :          0 :         cap->max_tx_2_rx = 1;
     935                 :          0 :         cap->max_nb_desc = 8192;
     936                 :            :         hca_attr = &priv->sh->cdev->config.hca_attr;
     937                 :          0 :         cap->rx_cap.locked_device_memory = hca_attr->hairpin_data_buffer_locked;
     938                 :          0 :         cap->rx_cap.rte_memory = 0;
     939                 :          0 :         cap->tx_cap.locked_device_memory = 0;
     940                 :          0 :         cap->tx_cap.rte_memory = hca_attr->hairpin_sq_wq_in_host_mem;
     941                 :          0 :         return 0;
     942                 :            : }
     943                 :            : 
     944                 :            : /**
     945                 :            :  * Indicate to ethdev layer, what configuration must be restored.
     946                 :            :  *
     947                 :            :  * @param[in] dev
     948                 :            :  *   Pointer to Ethernet device structure.
     949                 :            :  * @param[in] op
     950                 :            :  *   Type of operation which might require.
     951                 :            :  * @param[out] flags
     952                 :            :  *   Restore flags will be stored here.
     953                 :            :  */
     954                 :            : uint64_t
     955                 :          0 : mlx5_get_restore_flags(__rte_unused struct rte_eth_dev *dev,
     956                 :            :                        __rte_unused enum rte_eth_dev_operation op)
     957                 :            : {
     958                 :            :         /* mlx5 PMD does not require any configuration restore. */
     959                 :          0 :         return 0;
     960                 :            : }
     961                 :            : 
     962                 :            : /**
     963                 :            :  * Query minimum and maximum allowed MTU value on the device.
     964                 :            :  *
     965                 :            :  * This functions will always return valid MTU bounds.
     966                 :            :  * In case platform-specific implementation fails or current platform does not support it,
     967                 :            :  * the fallback default values will be used.
     968                 :            :  *
     969                 :            :  * @param[in] dev
     970                 :            :  *   Pointer to Ethernet device
     971                 :            :  * @param[out] min_mtu
     972                 :            :  *   Minimum MTU value output buffer.
     973                 :            :  * @param[out] max_mtu
     974                 :            :  *   Maximum MTU value output buffer.
     975                 :            :  */
     976                 :            : void
     977                 :          0 : mlx5_get_mtu_bounds(struct rte_eth_dev *dev, uint16_t *min_mtu, uint16_t *max_mtu)
     978                 :            : {
     979                 :            :         int ret;
     980                 :            : 
     981                 :            :         MLX5_ASSERT(min_mtu != NULL);
     982                 :            :         MLX5_ASSERT(max_mtu != NULL);
     983                 :            : 
     984                 :          0 :         ret = mlx5_os_get_mtu_bounds(dev, min_mtu, max_mtu);
     985         [ #  # ]:          0 :         if (ret < 0) {
     986         [ #  # ]:          0 :                 if (ret != -ENOTSUP)
     987                 :          0 :                         DRV_LOG(INFO, "port %u failed to query MTU bounds, using fallback values",
     988                 :            :                                 dev->data->port_id);
     989                 :          0 :                 *min_mtu = MLX5_ETH_MIN_MTU;
     990                 :          0 :                 *max_mtu = MLX5_ETH_MAX_MTU;
     991                 :            : 
     992                 :            :                 /* This function does not fail. Clear rte_errno. */
     993                 :          0 :                 rte_errno = 0;
     994                 :            :         }
     995                 :            : 
     996                 :          0 :         DRV_LOG(INFO, "port %u minimum MTU is %u", dev->data->port_id, *min_mtu);
     997                 :          0 :         DRV_LOG(INFO, "port %u maximum MTU is %u", dev->data->port_id, *max_mtu);
     998                 :          0 : }

Generated by: LCOV version 1.14