LCOV - code coverage report
Current view: top level - lib/ethdev - rte_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 887 2873 30.9 %
Date: 2026-10-01 18:19:24 Functions: 82 194 42.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 510 2142 23.8 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <errno.h>
       6                 :            : #include <inttypes.h>
       7                 :            : #include <stdbool.h>
       8                 :            : #include <stdint.h>
       9                 :            : #include <stdio.h>
      10                 :            : #include <stdlib.h>
      11                 :            : #include <string.h>
      12                 :            : #include <sys/queue.h>
      13                 :            : 
      14                 :            : #include <bus_driver.h>
      15                 :            : #include <eal_export.h>
      16                 :            : #include <rte_log.h>
      17                 :            : #include <rte_interrupts.h>
      18                 :            : #include <rte_kvargs.h>
      19                 :            : #include <rte_memcpy.h>
      20                 :            : #include <rte_common.h>
      21                 :            : #include <rte_mempool.h>
      22                 :            : #include <rte_malloc.h>
      23                 :            : #include <rte_mbuf.h>
      24                 :            : #include <rte_errno.h>
      25                 :            : #include <rte_spinlock.h>
      26                 :            : #include <rte_string_fns.h>
      27                 :            : #include <rte_class.h>
      28                 :            : #include <rte_ether.h>
      29                 :            : #include <rte_telemetry.h>
      30                 :            : 
      31                 :            : #include "rte_ethdev.h"
      32                 :            : #include "rte_ethdev_trace_fp.h"
      33                 :            : #include "ethdev_driver.h"
      34                 :            : #include "rte_flow_driver.h"
      35                 :            : #include "ethdev_profile.h"
      36                 :            : #include "ethdev_private.h"
      37                 :            : #include "ethdev_trace.h"
      38                 :            : #include "sff_telemetry.h"
      39                 :            : 
      40                 :            : #define ETH_XSTATS_ITER_NUM     0x100
      41                 :            : 
      42                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_eth_devices)
      43                 :            : struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
      44                 :            : 
      45                 :            : /* public fast-path API */
      46                 :            : RTE_EXPORT_SYMBOL(rte_eth_fp_ops)
      47                 :            : struct rte_eth_fp_ops rte_eth_fp_ops[RTE_MAX_ETHPORTS];
      48                 :            : 
      49                 :            : /* spinlock for add/remove Rx callbacks */
      50                 :            : static rte_spinlock_t eth_dev_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
      51                 :            : 
      52                 :            : /* spinlock for add/remove Tx callbacks */
      53                 :            : static rte_spinlock_t eth_dev_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
      54                 :            : 
      55                 :            : /* store statistics names and its offset in stats structure  */
      56                 :            : struct rte_eth_xstats_name_off {
      57                 :            :         char name[RTE_ETH_XSTATS_NAME_SIZE];
      58                 :            :         unsigned offset;
      59                 :            : };
      60                 :            : 
      61                 :            : static const struct rte_eth_xstats_name_off eth_dev_stats_strings[] = {
      62                 :            :         {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
      63                 :            :         {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
      64                 :            :         {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
      65                 :            :         {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
      66                 :            :         {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
      67                 :            :         {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
      68                 :            :         {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
      69                 :            :         {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
      70                 :            :                 rx_nombuf)},
      71                 :            : };
      72                 :            : 
      73                 :            : #define RTE_NB_STATS RTE_DIM(eth_dev_stats_strings)
      74                 :            : 
      75                 :            : static const struct rte_eth_xstats_name_off eth_dev_rxq_stats_strings[] = {
      76                 :            :         {"packets", offsetof(struct eth_queue_stats, q_ipackets)},
      77                 :            :         {"bytes", offsetof(struct eth_queue_stats, q_ibytes)},
      78                 :            : };
      79                 :            : 
      80                 :            : #define RTE_NB_RXQ_STATS RTE_DIM(eth_dev_rxq_stats_strings)
      81                 :            : 
      82                 :            : static const struct rte_eth_xstats_name_off eth_dev_txq_stats_strings[] = {
      83                 :            :         {"packets", offsetof(struct eth_queue_stats, q_opackets)},
      84                 :            :         {"bytes", offsetof(struct eth_queue_stats, q_obytes)},
      85                 :            : };
      86                 :            : #define RTE_NB_TXQ_STATS RTE_DIM(eth_dev_txq_stats_strings)
      87                 :            : 
      88                 :            : #define RTE_RX_OFFLOAD_BIT2STR(_name)   \
      89                 :            :         { RTE_ETH_RX_OFFLOAD_##_name, #_name }
      90                 :            : 
      91                 :            : static const struct {
      92                 :            :         uint64_t offload;
      93                 :            :         const char *name;
      94                 :            : } eth_dev_rx_offload_names[] = {
      95                 :            :         RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP),
      96                 :            :         RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM),
      97                 :            :         RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM),
      98                 :            :         RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM),
      99                 :            :         RTE_RX_OFFLOAD_BIT2STR(TCP_LRO),
     100                 :            :         RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP),
     101                 :            :         RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
     102                 :            :         RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP),
     103                 :            :         RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
     104                 :            :         RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
     105                 :            :         RTE_RX_OFFLOAD_BIT2STR(SCATTER),
     106                 :            :         RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
     107                 :            :         RTE_RX_OFFLOAD_BIT2STR(SECURITY),
     108                 :            :         RTE_RX_OFFLOAD_BIT2STR(KEEP_CRC),
     109                 :            :         RTE_RX_OFFLOAD_BIT2STR(SCTP_CKSUM),
     110                 :            :         RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
     111                 :            :         RTE_RX_OFFLOAD_BIT2STR(RSS_HASH),
     112                 :            :         RTE_RX_OFFLOAD_BIT2STR(BUFFER_SPLIT),
     113                 :            : };
     114                 :            : 
     115                 :            : #undef RTE_RX_OFFLOAD_BIT2STR
     116                 :            : #undef RTE_ETH_RX_OFFLOAD_BIT2STR
     117                 :            : 
     118                 :            : #define RTE_TX_OFFLOAD_BIT2STR(_name)   \
     119                 :            :         { RTE_ETH_TX_OFFLOAD_##_name, #_name }
     120                 :            : 
     121                 :            : static const struct {
     122                 :            :         uint64_t offload;
     123                 :            :         const char *name;
     124                 :            : } eth_dev_tx_offload_names[] = {
     125                 :            :         RTE_TX_OFFLOAD_BIT2STR(VLAN_INSERT),
     126                 :            :         RTE_TX_OFFLOAD_BIT2STR(IPV4_CKSUM),
     127                 :            :         RTE_TX_OFFLOAD_BIT2STR(UDP_CKSUM),
     128                 :            :         RTE_TX_OFFLOAD_BIT2STR(TCP_CKSUM),
     129                 :            :         RTE_TX_OFFLOAD_BIT2STR(SCTP_CKSUM),
     130                 :            :         RTE_TX_OFFLOAD_BIT2STR(TCP_TSO),
     131                 :            :         RTE_TX_OFFLOAD_BIT2STR(UDP_TSO),
     132                 :            :         RTE_TX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
     133                 :            :         RTE_TX_OFFLOAD_BIT2STR(QINQ_INSERT),
     134                 :            :         RTE_TX_OFFLOAD_BIT2STR(VXLAN_TNL_TSO),
     135                 :            :         RTE_TX_OFFLOAD_BIT2STR(GRE_TNL_TSO),
     136                 :            :         RTE_TX_OFFLOAD_BIT2STR(IPIP_TNL_TSO),
     137                 :            :         RTE_TX_OFFLOAD_BIT2STR(GENEVE_TNL_TSO),
     138                 :            :         RTE_TX_OFFLOAD_BIT2STR(MACSEC_INSERT),
     139                 :            :         RTE_TX_OFFLOAD_BIT2STR(MT_LOCKFREE),
     140                 :            :         RTE_TX_OFFLOAD_BIT2STR(MULTI_SEGS),
     141                 :            :         RTE_TX_OFFLOAD_BIT2STR(MBUF_FAST_FREE),
     142                 :            :         RTE_TX_OFFLOAD_BIT2STR(SECURITY),
     143                 :            :         RTE_TX_OFFLOAD_BIT2STR(UDP_TNL_TSO),
     144                 :            :         RTE_TX_OFFLOAD_BIT2STR(IP_TNL_TSO),
     145                 :            :         RTE_TX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
     146                 :            :         RTE_TX_OFFLOAD_BIT2STR(SEND_ON_TIMESTAMP),
     147                 :            : };
     148                 :            : 
     149                 :            : #undef RTE_TX_OFFLOAD_BIT2STR
     150                 :            : 
     151                 :            : static const struct {
     152                 :            :         uint64_t offload;
     153                 :            :         const char *name;
     154                 :            : } rte_eth_dev_capa_names[] = {
     155                 :            :         {RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP, "RUNTIME_RX_QUEUE_SETUP"},
     156                 :            :         {RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP, "RUNTIME_TX_QUEUE_SETUP"},
     157                 :            :         {RTE_ETH_DEV_CAPA_RXQ_SHARE, "RXQ_SHARE"},
     158                 :            :         {RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP, "FLOW_RULE_KEEP"},
     159                 :            :         {RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP, "FLOW_SHARED_OBJECT_KEEP"},
     160                 :            : };
     161                 :            : 
     162                 :            : static const struct {
     163                 :            :         enum rte_eth_hash_function algo;
     164                 :            :         const char *name;
     165                 :            : } rte_eth_dev_rss_algo_names[] = {
     166                 :            :         {RTE_ETH_HASH_FUNCTION_DEFAULT, "default"},
     167                 :            :         {RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, "simple_xor"},
     168                 :            :         {RTE_ETH_HASH_FUNCTION_TOEPLITZ, "toeplitz"},
     169                 :            :         {RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, "symmetric_toeplitz"},
     170                 :            :         {RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ_SORT, "symmetric_toeplitz_sort"},
     171                 :            : };
     172                 :            : 
     173                 :            : RTE_EXPORT_SYMBOL(rte_eth_iterator_init)
     174                 :            : int
     175                 :          0 : rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
     176                 :            : {
     177                 :            :         int ret;
     178                 :            :         struct rte_devargs devargs;
     179                 :            :         const char *bus_param_key;
     180                 :            :         char *bus_str = NULL;
     181                 :            :         char *cls_str = NULL;
     182                 :            :         int str_size;
     183                 :            : 
     184         [ #  # ]:          0 :         if (iter == NULL) {
     185                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot initialize NULL iterator");
     186                 :          0 :                 return -EINVAL;
     187                 :            :         }
     188                 :            : 
     189         [ #  # ]:          0 :         if (devargs_str == NULL) {
     190                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     191                 :            :                         "Cannot initialize iterator from NULL device description string");
     192                 :          0 :                 return -EINVAL;
     193                 :            :         }
     194                 :            : 
     195                 :            :         memset(iter, 0, sizeof(*iter));
     196                 :            :         memset(&devargs, 0, sizeof(devargs));
     197                 :            : 
     198                 :            :         /*
     199                 :            :          * The devargs string may use various syntaxes:
     200                 :            :          *   - 0000:08:00.0,representor=[1-3]
     201                 :            :          *   - pci:0000:06:00.0,representor=[0,5]
     202                 :            :          *   - class=eth,mac=00:11:22:33:44:55
     203                 :            :          *   - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z
     204                 :            :          */
     205                 :            : 
     206                 :            :         /*
     207                 :            :          * Handle pure class filter (i.e. without any bus-level argument),
     208                 :            :          * from future new syntax.
     209                 :            :          * rte_devargs_parse() is not yet supporting the new syntax,
     210                 :            :          * that's why this simple case is temporarily parsed here.
     211                 :            :          */
     212                 :            : #define iter_anybus_str "class=eth,"
     213         [ #  # ]:          0 :         if (strncmp(devargs_str, iter_anybus_str,
     214                 :            :                         strlen(iter_anybus_str)) == 0) {
     215                 :          0 :                 iter->cls_str = devargs_str + strlen(iter_anybus_str);
     216                 :          0 :                 goto end;
     217                 :            :         }
     218                 :            : 
     219                 :            :         /* Split bus, device and parameters. */
     220                 :          0 :         ret = rte_devargs_parse(&devargs, devargs_str);
     221         [ #  # ]:          0 :         if (ret != 0)
     222                 :          0 :                 goto error;
     223                 :            : 
     224                 :            :         /*
     225                 :            :          * Assume parameters of old syntax can match only at ethdev level.
     226                 :            :          * Extra parameters will be ignored, thanks to "+" prefix.
     227                 :            :          */
     228                 :          0 :         str_size = strlen(devargs.args) + 2;
     229                 :          0 :         cls_str = malloc(str_size);
     230         [ #  # ]:          0 :         if (cls_str == NULL) {
     231                 :            :                 ret = -ENOMEM;
     232                 :          0 :                 goto error;
     233                 :            :         }
     234                 :            :         ret = snprintf(cls_str, str_size, "+%s", devargs.args);
     235         [ #  # ]:          0 :         if (ret != str_size - 1) {
     236                 :            :                 ret = -EINVAL;
     237                 :          0 :                 goto error;
     238                 :            :         }
     239                 :          0 :         iter->cls_str = cls_str;
     240                 :            : 
     241                 :          0 :         iter->bus = devargs.bus;
     242         [ #  # ]:          0 :         if (iter->bus->dev_iterate == NULL) {
     243                 :            :                 ret = -ENOTSUP;
     244                 :          0 :                 goto error;
     245                 :            :         }
     246                 :            : 
     247                 :            :         /* Convert bus args to new syntax for use with new API dev_iterate. */
     248         [ #  # ]:          0 :         if ((strcmp(iter->bus->name, "vdev") == 0) ||
     249         [ #  # ]:          0 :                 (strcmp(iter->bus->name, "fslmc") == 0) ||
     250         [ #  # ]:          0 :                 (strcmp(iter->bus->name, "dpaa_bus") == 0)) {
     251                 :            :                 bus_param_key = "name";
     252         [ #  # ]:          0 :         } else if (strcmp(iter->bus->name, "pci") == 0) {
     253                 :            :                 bus_param_key = "addr";
     254                 :            :         } else {
     255                 :            :                 ret = -ENOTSUP;
     256                 :          0 :                 goto error;
     257                 :            :         }
     258                 :          0 :         str_size = strlen(bus_param_key) + strlen(devargs.name) + 2;
     259                 :          0 :         bus_str = malloc(str_size);
     260         [ #  # ]:          0 :         if (bus_str == NULL) {
     261                 :            :                 ret = -ENOMEM;
     262                 :          0 :                 goto error;
     263                 :            :         }
     264                 :            :         ret = snprintf(bus_str, str_size, "%s=%s",
     265                 :            :                         bus_param_key, devargs.name);
     266         [ #  # ]:          0 :         if (ret != str_size - 1) {
     267                 :            :                 ret = -EINVAL;
     268                 :          0 :                 goto error;
     269                 :            :         }
     270                 :          0 :         iter->bus_str = bus_str;
     271                 :            : 
     272                 :          0 : end:
     273                 :          0 :         iter->cls = rte_class_find_by_name("eth");
     274                 :          0 :         rte_devargs_reset(&devargs);
     275                 :            : 
     276                 :            :         rte_eth_trace_iterator_init(devargs_str);
     277                 :            : 
     278                 :            :         return 0;
     279                 :            : 
     280                 :          0 : error:
     281         [ #  # ]:          0 :         if (ret == -ENOTSUP)
     282                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Bus %s does not support iterating.",
     283                 :            :                                 iter->bus->name);
     284                 :          0 :         rte_devargs_reset(&devargs);
     285                 :          0 :         free(bus_str);
     286                 :          0 :         free(cls_str);
     287                 :          0 :         return ret;
     288                 :            : }
     289                 :            : 
     290                 :            : RTE_EXPORT_SYMBOL(rte_eth_iterator_next)
     291                 :            : uint16_t
     292                 :          0 : rte_eth_iterator_next(struct rte_dev_iterator *iter)
     293                 :            : {
     294         [ #  # ]:          0 :         if (iter == NULL) {
     295                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     296                 :            :                         "Cannot get next device from NULL iterator");
     297                 :          0 :                 return RTE_MAX_ETHPORTS;
     298                 :            :         }
     299                 :            : 
     300         [ #  # ]:          0 :         if (iter->cls == NULL) /* invalid ethdev iterator */
     301                 :            :                 return RTE_MAX_ETHPORTS;
     302                 :            : 
     303                 :            :         do { /* loop to try all matching rte_device */
     304                 :            :                 /* If not pure ethdev filter and */
     305         [ #  # ]:          0 :                 if (iter->bus != NULL &&
     306                 :            :                                 /* not in middle of rte_eth_dev iteration, */
     307         [ #  # ]:          0 :                                 iter->class_device == NULL) {
     308                 :            :                         /* get next rte_device to try. */
     309                 :          0 :                         iter->device = iter->bus->dev_iterate(
     310                 :          0 :                                         iter->bus, iter->device, iter->bus_str, iter);
     311         [ #  # ]:          0 :                         if (iter->device == NULL)
     312                 :            :                                 break; /* no more rte_device candidate */
     313                 :            :                 }
     314                 :            :                 /* A device is matching bus part, need to check ethdev part. */
     315                 :          0 :                 iter->class_device = iter->cls->dev_iterate(
     316                 :          0 :                                 iter->class_device, iter->cls_str, iter);
     317         [ #  # ]:          0 :                 if (iter->class_device != NULL) {
     318                 :          0 :                         uint16_t id = eth_dev_to_id(iter->class_device);
     319                 :            : 
     320                 :          0 :                         rte_eth_trace_iterator_next(iter, id);
     321                 :            : 
     322                 :          0 :                         return id; /* match */
     323                 :            :                 }
     324         [ #  # ]:          0 :         } while (iter->bus != NULL); /* need to try next rte_device */
     325                 :            : 
     326                 :            :         /* No more ethdev port to iterate. */
     327                 :          0 :         rte_eth_iterator_cleanup(iter);
     328                 :          0 :         return RTE_MAX_ETHPORTS;
     329                 :            : }
     330                 :            : 
     331                 :            : RTE_EXPORT_SYMBOL(rte_eth_iterator_cleanup)
     332                 :            : void
     333                 :          0 : rte_eth_iterator_cleanup(struct rte_dev_iterator *iter)
     334                 :            : {
     335         [ #  # ]:          0 :         if (iter == NULL) {
     336                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot do clean up from NULL iterator");
     337                 :          0 :                 return;
     338                 :            :         }
     339                 :            : 
     340         [ #  # ]:          0 :         if (iter->bus_str == NULL)
     341                 :            :                 return; /* nothing to free in pure class filter */
     342                 :            : 
     343                 :          0 :         rte_eth_trace_iterator_cleanup(iter);
     344                 :            : 
     345                 :          0 :         free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */
     346                 :          0 :         free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */
     347                 :            :         memset(iter, 0, sizeof(*iter));
     348                 :            : }
     349                 :            : 
     350                 :            : RTE_EXPORT_SYMBOL(rte_eth_find_next)
     351                 :            : uint16_t
     352                 :      12641 : rte_eth_find_next(uint16_t port_id)
     353                 :            : {
     354         [ +  + ]:     138404 :         while (port_id < RTE_MAX_ETHPORTS &&
     355         [ +  + ]:     134212 :                         rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
     356                 :     125763 :                 port_id++;
     357                 :            : 
     358         [ +  + ]:      12641 :         if (port_id >= RTE_MAX_ETHPORTS)
     359                 :            :                 return RTE_MAX_ETHPORTS;
     360                 :            : 
     361                 :       8449 :         rte_eth_trace_find_next(port_id);
     362                 :            : 
     363                 :       8449 :         return port_id;
     364                 :            : }
     365                 :            : 
     366                 :            : /*
     367                 :            :  * Macro to iterate over all valid ports for internal usage.
     368                 :            :  * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports.
     369                 :            :  */
     370                 :            : #define RTE_ETH_FOREACH_VALID_DEV(port_id) \
     371                 :            :         for (port_id = rte_eth_find_next(0); \
     372                 :            :              port_id < RTE_MAX_ETHPORTS; \
     373                 :            :              port_id = rte_eth_find_next(port_id + 1))
     374                 :            : 
     375                 :            : RTE_EXPORT_SYMBOL(rte_eth_find_next_of)
     376                 :            : uint16_t
     377                 :          0 : rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
     378                 :            : {
     379                 :          0 :         port_id = rte_eth_find_next(port_id);
     380         [ #  # ]:          0 :         while (port_id < RTE_MAX_ETHPORTS &&
     381         [ #  # ]:          0 :                         rte_eth_devices[port_id].device != parent)
     382                 :          0 :                 port_id = rte_eth_find_next(port_id + 1);
     383                 :            : 
     384                 :          0 :         rte_eth_trace_find_next_of(port_id, parent);
     385                 :            : 
     386                 :          0 :         return port_id;
     387                 :            : }
     388                 :            : 
     389                 :            : RTE_EXPORT_SYMBOL(rte_eth_find_next_sibling)
     390                 :            : uint16_t
     391                 :          0 : rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id)
     392                 :            : {
     393                 :            :         uint16_t ret;
     394                 :            : 
     395         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS);
     396                 :          0 :         ret = rte_eth_find_next_of(port_id,
     397                 :          0 :                         rte_eth_devices[ref_port_id].device);
     398                 :            : 
     399                 :          0 :         rte_eth_trace_find_next_sibling(port_id, ref_port_id, ret);
     400                 :            : 
     401                 :          0 :         return ret;
     402                 :            : }
     403                 :            : 
     404                 :            : static bool
     405                 :            : eth_dev_is_allocated(const struct rte_eth_dev *ethdev)
     406                 :            : {
     407   [ -  +  -  -  :        132 :         return ethdev->data != NULL && ethdev->data->name[0] != '\0';
             -  -  -  - ]
     408                 :            : }
     409                 :            : 
     410                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_is_valid_port)
     411                 :            : int
     412                 :       1074 : rte_eth_dev_is_valid_port(uint16_t port_id)
     413                 :            : {
     414                 :            :         int is_valid;
     415                 :            : 
     416         [ +  + ]:       1074 :         if (port_id >= RTE_MAX_ETHPORTS ||
     417         [ +  + ]:       1072 :             (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
     418                 :            :                 is_valid = 0;
     419                 :            :         else
     420                 :            :                 is_valid = 1;
     421                 :            : 
     422                 :       1074 :         rte_ethdev_trace_is_valid_port(port_id, is_valid);
     423                 :            : 
     424                 :       1074 :         return is_valid;
     425                 :            : }
     426                 :            : 
     427                 :            : static int
     428                 :            : eth_is_valid_owner_id(uint64_t owner_id)
     429                 :            :         __rte_requires_capability(rte_mcfg_ethdev_get_lock())
     430                 :            : {
     431   [ #  #  #  # ]:          0 :         if (owner_id == RTE_ETH_DEV_NO_OWNER ||
     432   [ #  #  #  #  :          0 :             eth_dev_shared_data->next_owner_id <= owner_id)
                   #  # ]
     433                 :            :                 return 0;
     434                 :            :         return 1;
     435                 :            : }
     436                 :            : 
     437                 :            : RTE_EXPORT_SYMBOL(rte_eth_find_next_owned_by)
     438                 :            : uint64_t
     439                 :      12570 : rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
     440                 :            : {
     441                 :      12570 :         port_id = rte_eth_find_next(port_id);
     442         [ +  + ]:      12570 :         while (port_id < RTE_MAX_ETHPORTS &&
     443         [ -  + ]:       8381 :                         rte_eth_devices[port_id].data->owner.id != owner_id)
     444                 :          0 :                 port_id = rte_eth_find_next(port_id + 1);
     445                 :            : 
     446                 :      12570 :         rte_eth_trace_find_next_owned_by(port_id, owner_id);
     447                 :            : 
     448                 :      12570 :         return port_id;
     449                 :            : }
     450                 :            : 
     451                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_new)
     452                 :            : int
     453                 :          0 : rte_eth_dev_owner_new(uint64_t *owner_id)
     454                 :            : {
     455                 :            :         int ret;
     456                 :            : 
     457         [ #  # ]:          0 :         if (owner_id == NULL) {
     458                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get new owner ID to NULL");
     459                 :          0 :                 return -EINVAL;
     460                 :            :         }
     461                 :            : 
     462                 :          0 :         rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
     463                 :            : 
     464         [ #  # ]:          0 :         if (eth_dev_shared_data_prepare() != NULL) {
     465                 :          0 :                 *owner_id = eth_dev_shared_data->next_owner_id++;
     466                 :          0 :                 eth_dev_shared_data->allocated_owners++;
     467                 :            :                 ret = 0;
     468                 :            :         } else {
     469                 :            :                 ret = -ENOMEM;
     470                 :            :         }
     471                 :            : 
     472                 :          0 :         rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
     473                 :            : 
     474         [ #  # ]:          0 :         rte_ethdev_trace_owner_new(*owner_id, ret);
     475                 :            : 
     476                 :          0 :         return ret;
     477                 :            : }
     478                 :            : 
     479                 :            : static int
     480                 :          0 : eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
     481                 :            :                        const struct rte_eth_dev_owner *new_owner)
     482                 :            :         __rte_requires_capability(rte_mcfg_ethdev_get_lock())
     483                 :            : {
     484                 :          0 :         struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
     485                 :            :         struct rte_eth_dev_owner *port_owner;
     486                 :            : 
     487   [ #  #  #  # ]:          0 :         if (port_id >= RTE_MAX_ETHPORTS || !eth_dev_is_allocated(ethdev)) {
     488                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port ID %"PRIu16" is not allocated",
     489                 :            :                         port_id);
     490                 :          0 :                 return -ENODEV;
     491                 :            :         }
     492                 :            : 
     493         [ #  # ]:          0 :         if (new_owner == NULL) {
     494                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     495                 :            :                         "Cannot set ethdev port %u owner from NULL owner",
     496                 :            :                         port_id);
     497                 :          0 :                 return -EINVAL;
     498                 :            :         }
     499                 :            : 
     500         [ #  # ]:          0 :         if (!eth_is_valid_owner_id(new_owner->id) &&
     501                 :            :             !eth_is_valid_owner_id(old_owner_id)) {
     502                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     503                 :            :                         "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64,
     504                 :            :                        old_owner_id, new_owner->id);
     505                 :          0 :                 return -EINVAL;
     506                 :            :         }
     507                 :            : 
     508                 :            :         port_owner = &rte_eth_devices[port_id].data->owner;
     509         [ #  # ]:          0 :         if (port_owner->id != old_owner_id) {
     510                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     511                 :            :                         "Cannot set owner to port %u already owned by %s_%016"PRIX64,
     512                 :            :                         port_id, port_owner->name, port_owner->id);
     513                 :          0 :                 return -EPERM;
     514                 :            :         }
     515                 :            : 
     516                 :            :         /* can not truncate (same structure) */
     517                 :          0 :         strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN);
     518                 :            : 
     519                 :          0 :         port_owner->id = new_owner->id;
     520                 :            : 
     521                 :          0 :         RTE_ETHDEV_LOG_LINE(DEBUG, "Port %u owner is %s_%016"PRIx64,
     522                 :            :                 port_id, new_owner->name, new_owner->id);
     523                 :            : 
     524                 :          0 :         return 0;
     525                 :            : }
     526                 :            : 
     527                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_set)
     528                 :            : int
     529                 :          0 : rte_eth_dev_owner_set(const uint16_t port_id,
     530                 :            :                       const struct rte_eth_dev_owner *owner)
     531                 :            : {
     532                 :            :         int ret;
     533                 :            : 
     534                 :          0 :         rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
     535                 :            : 
     536         [ #  # ]:          0 :         if (eth_dev_shared_data_prepare() != NULL)
     537                 :          0 :                 ret = eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner);
     538                 :            :         else
     539                 :            :                 ret = -ENOMEM;
     540                 :            : 
     541                 :          0 :         rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
     542                 :            : 
     543                 :          0 :         rte_ethdev_trace_owner_set(port_id, owner, ret);
     544                 :            : 
     545                 :          0 :         return ret;
     546                 :            : }
     547                 :            : 
     548                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_unset)
     549                 :            : int
     550                 :          0 : rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
     551                 :            : {
     552                 :          0 :         const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner)
     553                 :            :                         {.id = RTE_ETH_DEV_NO_OWNER, .name = ""};
     554                 :            :         int ret;
     555                 :            : 
     556                 :          0 :         rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
     557                 :            : 
     558         [ #  # ]:          0 :         if (eth_dev_shared_data_prepare() != NULL)
     559                 :          0 :                 ret = eth_dev_owner_set(port_id, owner_id, &new_owner);
     560                 :            :         else
     561                 :            :                 ret = -ENOMEM;
     562                 :            : 
     563                 :          0 :         rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
     564                 :            : 
     565                 :          0 :         rte_ethdev_trace_owner_unset(port_id, owner_id, ret);
     566                 :            : 
     567                 :          0 :         return ret;
     568                 :            : }
     569                 :            : 
     570                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_delete)
     571                 :            : int
     572                 :          0 : rte_eth_dev_owner_delete(const uint64_t owner_id)
     573                 :            : {
     574                 :            :         uint16_t port_id;
     575                 :            :         int ret = 0;
     576                 :            : 
     577                 :          0 :         rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
     578                 :            : 
     579         [ #  # ]:          0 :         if (eth_dev_shared_data_prepare() == NULL) {
     580                 :            :                 ret = -ENOMEM;
     581                 :            :         } else if (eth_is_valid_owner_id(owner_id)) {
     582         [ #  # ]:          0 :                 for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
     583                 :          0 :                         struct rte_eth_dev_data *data =
     584                 :          0 :                                 rte_eth_devices[port_id].data;
     585   [ #  #  #  # ]:          0 :                         if (data != NULL && data->owner.id == owner_id)
     586                 :          0 :                                 memset(&data->owner, 0,
     587                 :            :                                        sizeof(struct rte_eth_dev_owner));
     588                 :            :                 }
     589                 :          0 :                 RTE_ETHDEV_LOG_LINE(NOTICE,
     590                 :            :                         "All port owners owned by %016"PRIx64" identifier have removed",
     591                 :            :                         owner_id);
     592                 :          0 :                 eth_dev_shared_data->allocated_owners--;
     593                 :          0 :                 eth_dev_shared_data_release();
     594                 :            :         } else {
     595                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     596                 :            :                                "Invalid owner ID=%016"PRIx64,
     597                 :            :                                owner_id);
     598                 :            :                 ret = -EINVAL;
     599                 :            :         }
     600                 :            : 
     601                 :          0 :         rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
     602                 :            : 
     603                 :          0 :         rte_ethdev_trace_owner_delete(owner_id, ret);
     604                 :            : 
     605                 :          0 :         return ret;
     606                 :            : }
     607                 :            : 
     608                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_get)
     609                 :            : int
     610                 :          0 : rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
     611                 :            : {
     612                 :            :         struct rte_eth_dev *ethdev;
     613                 :            :         int ret;
     614                 :            : 
     615         [ #  # ]:          0 :         if (port_id >= RTE_MAX_ETHPORTS)
     616                 :            :                 return -ENODEV;
     617                 :            : 
     618         [ #  # ]:          0 :         ethdev = &rte_eth_devices[port_id];
     619         [ #  # ]:          0 :         if (!eth_dev_is_allocated(ethdev)) {
     620                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port ID %"PRIu16" is not allocated",
     621                 :            :                         port_id);
     622                 :          0 :                 return -ENODEV;
     623                 :            :         }
     624                 :            : 
     625         [ #  # ]:          0 :         if (owner == NULL) {
     626                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u owner to NULL",
     627                 :            :                         port_id);
     628                 :          0 :                 return -EINVAL;
     629                 :            :         }
     630                 :            : 
     631                 :          0 :         rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
     632                 :            : 
     633         [ #  # ]:          0 :         if (eth_dev_shared_data_prepare() != NULL) {
     634         [ #  # ]:          0 :                 rte_memcpy(owner, &ethdev->data->owner, sizeof(*owner));
     635                 :            :                 ret = 0;
     636                 :            :         } else {
     637                 :            :                 ret = -ENOMEM;
     638                 :            :         }
     639                 :            : 
     640                 :          0 :         rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
     641                 :            : 
     642                 :          0 :         rte_ethdev_trace_owner_get(port_id, owner, ret);
     643                 :            : 
     644                 :          0 :         return ret;
     645                 :            : }
     646                 :            : 
     647                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_socket_id)
     648                 :            : int
     649                 :        132 : rte_eth_dev_socket_id(uint16_t port_id)
     650                 :            : {
     651                 :            :         int socket_id = SOCKET_ID_ANY;
     652                 :            :         struct rte_eth_dev *ethdev;
     653                 :            : 
     654         [ -  + ]:        132 :         if (port_id >= RTE_MAX_ETHPORTS) {
     655                 :          0 :                 rte_errno = EINVAL;
     656                 :          0 :                 return socket_id;
     657                 :            :         }
     658                 :            : 
     659         [ +  - ]:        132 :         ethdev = &rte_eth_devices[port_id];
     660         [ -  + ]:        132 :         if (!eth_dev_is_allocated(ethdev)) {
     661                 :          0 :                 rte_errno = EINVAL;
     662                 :            :         } else {
     663                 :        132 :                 socket_id = rte_eth_devices[port_id].data->numa_node;
     664         [ +  + ]:        132 :                 if (socket_id == SOCKET_ID_ANY)
     665                 :          8 :                         rte_errno = 0;
     666                 :            :         }
     667                 :            : 
     668                 :        132 :         rte_ethdev_trace_socket_id(port_id, socket_id);
     669                 :            : 
     670                 :        132 :         return socket_id;
     671                 :            : }
     672                 :            : 
     673                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_sec_ctx)
     674                 :            : void *
     675                 :          0 : rte_eth_dev_get_sec_ctx(uint16_t port_id)
     676                 :            : {
     677                 :            :         void *ctx;
     678                 :            : 
     679         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
     680         [ #  # ]:          0 :         ctx = rte_eth_devices[port_id].security_ctx;
     681                 :            : 
     682                 :          0 :         rte_ethdev_trace_get_sec_ctx(port_id, ctx);
     683                 :            : 
     684                 :          0 :         return ctx;
     685                 :            : }
     686                 :            : 
     687                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_count_avail)
     688                 :            : uint16_t
     689                 :         78 : rte_eth_dev_count_avail(void)
     690                 :            : {
     691                 :            :         uint16_t p;
     692                 :            :         uint16_t count;
     693                 :            : 
     694                 :            :         count = 0;
     695                 :            : 
     696         [ +  + ]:        230 :         RTE_ETH_FOREACH_DEV(p)
     697                 :        152 :                 count++;
     698                 :            : 
     699                 :         78 :         rte_ethdev_trace_count_avail(count);
     700                 :            : 
     701                 :         78 :         return count;
     702                 :            : }
     703                 :            : 
     704                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_count_total)
     705                 :            : uint16_t
     706                 :          3 : rte_eth_dev_count_total(void)
     707                 :            : {
     708                 :            :         uint16_t port, count = 0;
     709                 :            : 
     710         [ +  + ]:          9 :         RTE_ETH_FOREACH_VALID_DEV(port)
     711                 :          6 :                 count++;
     712                 :            : 
     713                 :          3 :         rte_ethdev_trace_count_total(count);
     714                 :            : 
     715                 :          3 :         return count;
     716                 :            : }
     717                 :            : 
     718                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_name_by_port)
     719                 :            : int
     720                 :         10 : rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
     721                 :            : {
     722                 :            :         char *tmp;
     723                 :            : 
     724         [ -  + ]:         10 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
     725                 :            : 
     726         [ -  + ]:         10 :         if (name == NULL) {
     727                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u name to NULL",
     728                 :            :                         port_id);
     729                 :          0 :                 return -EINVAL;
     730                 :            :         }
     731                 :            : 
     732                 :         10 :         rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
     733                 :            :         /* shouldn't check 'rte_eth_devices[i].data',
     734                 :            :          * because it might be overwritten by VDEV PMD */
     735                 :         10 :         tmp = eth_dev_shared_data->data[port_id].name;
     736                 :         10 :         rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
     737                 :            : 
     738                 :            :         strcpy(name, tmp);
     739                 :            : 
     740                 :         10 :         rte_ethdev_trace_get_name_by_port(port_id, name);
     741                 :            : 
     742                 :         10 :         return 0;
     743                 :            : }
     744                 :            : 
     745                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_port_by_name)
     746                 :            : int
     747                 :         43 : rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
     748                 :            : {
     749                 :            :         int ret = -ENODEV;
     750                 :            :         uint16_t pid;
     751                 :            : 
     752         [ -  + ]:         43 :         if (name == NULL) {
     753                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get port ID from NULL name");
     754                 :          0 :                 return -EINVAL;
     755                 :            :         }
     756                 :            : 
     757         [ -  + ]:         43 :         if (port_id == NULL) {
     758                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     759                 :            :                         "Cannot get port ID to NULL for %s", name);
     760                 :          0 :                 return -EINVAL;
     761                 :            :         }
     762                 :            : 
     763                 :         43 :         rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
     764         [ +  - ]:         62 :         RTE_ETH_FOREACH_VALID_DEV(pid) {
     765         [ +  + ]:         62 :                 if (strcmp(name, eth_dev_shared_data->data[pid].name) != 0)
     766                 :            :                         continue;
     767                 :            : 
     768         [ -  + ]:         43 :                 *port_id = pid;
     769                 :         43 :                 rte_ethdev_trace_get_port_by_name(name, *port_id);
     770                 :            :                 ret = 0;
     771                 :         43 :                 break;
     772                 :            :         }
     773                 :         43 :         rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
     774                 :            : 
     775                 :         43 :         return ret;
     776                 :            : }
     777                 :            : 
     778                 :            : int
     779                 :        259 : eth_err(uint16_t port_id, int ret)
     780                 :            : {
     781         [ +  + ]:        259 :         if (ret == 0)
     782                 :            :                 return 0;
     783         [ -  + ]:          2 :         if (rte_eth_dev_is_removed(port_id))
     784                 :          0 :                 return -EIO;
     785                 :            :         return ret;
     786                 :            : }
     787                 :            : 
     788                 :            : static int
     789                 :          4 : eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id)
     790                 :            : {
     791                 :            :         uint16_t port_id;
     792                 :            : 
     793         [ -  + ]:          4 :         if (rx_queue_id >= dev->data->nb_rx_queues) {
     794                 :          0 :                 port_id = dev->data->port_id;
     795                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     796                 :            :                                "Invalid Rx queue_id=%u of device with port_id=%u",
     797                 :            :                                rx_queue_id, port_id);
     798                 :          0 :                 return -EINVAL;
     799                 :            :         }
     800                 :            : 
     801         [ -  + ]:          4 :         if (dev->data->rx_queues[rx_queue_id] == NULL) {
     802                 :          0 :                 port_id = dev->data->port_id;
     803                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     804                 :            :                                "Queue %u of device with port_id=%u has not been setup",
     805                 :            :                                rx_queue_id, port_id);
     806                 :          0 :                 return -EINVAL;
     807                 :            :         }
     808                 :            : 
     809                 :            :         return 0;
     810                 :            : }
     811                 :            : 
     812                 :            : static int
     813                 :          4 : eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id)
     814                 :            : {
     815                 :            :         uint16_t port_id;
     816                 :            : 
     817         [ -  + ]:          4 :         if (tx_queue_id >= dev->data->nb_tx_queues) {
     818                 :          0 :                 port_id = dev->data->port_id;
     819                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     820                 :            :                                "Invalid Tx queue_id=%u of device with port_id=%u",
     821                 :            :                                tx_queue_id, port_id);
     822                 :          0 :                 return -EINVAL;
     823                 :            :         }
     824                 :            : 
     825         [ -  + ]:          4 :         if (dev->data->tx_queues[tx_queue_id] == NULL) {
     826                 :          0 :                 port_id = dev->data->port_id;
     827                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     828                 :            :                                "Queue %u of device with port_id=%u has not been setup",
     829                 :            :                                tx_queue_id, port_id);
     830                 :          0 :                 return -EINVAL;
     831                 :            :         }
     832                 :            : 
     833                 :            :         return 0;
     834                 :            : }
     835                 :            : 
     836                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_queue_is_valid)
     837                 :            : int
     838                 :          0 : rte_eth_rx_queue_is_valid(uint16_t port_id, uint16_t queue_id)
     839                 :            : {
     840                 :            :         struct rte_eth_dev *dev;
     841                 :            : 
     842         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
     843                 :          0 :         dev = &rte_eth_devices[port_id];
     844                 :            : 
     845                 :          0 :         return eth_dev_validate_rx_queue(dev, queue_id);
     846                 :            : }
     847                 :            : 
     848                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_is_valid)
     849                 :            : int
     850                 :          0 : rte_eth_tx_queue_is_valid(uint16_t port_id, uint16_t queue_id)
     851                 :            : {
     852                 :            :         struct rte_eth_dev *dev;
     853                 :            : 
     854         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
     855                 :          0 :         dev = &rte_eth_devices[port_id];
     856                 :            : 
     857                 :          0 :         return eth_dev_validate_tx_queue(dev, queue_id);
     858                 :            : }
     859                 :            : 
     860                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_queue_start)
     861                 :            : int
     862                 :          2 : rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
     863                 :            : {
     864                 :            :         struct rte_eth_dev *dev;
     865                 :            :         int ret;
     866                 :            : 
     867         [ -  + ]:          2 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
     868                 :          2 :         dev = &rte_eth_devices[port_id];
     869                 :            : 
     870         [ -  + ]:          2 :         if (!dev->data->dev_started) {
     871                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     872                 :            :                         "Port %u must be started before start any queue",
     873                 :            :                         port_id);
     874                 :          0 :                 return -EINVAL;
     875                 :            :         }
     876                 :            : 
     877                 :          2 :         ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
     878         [ +  - ]:          2 :         if (ret != 0)
     879                 :            :                 return ret;
     880                 :            : 
     881         [ +  - ]:          2 :         if (dev->dev_ops->rx_queue_start == NULL)
     882                 :            :                 return -ENOTSUP;
     883                 :            : 
     884         [ -  + ]:          2 :         if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
     885                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
     886                 :            :                         "Can't start Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
     887                 :            :                         rx_queue_id, port_id);
     888                 :          0 :                 return -EINVAL;
     889                 :            :         }
     890                 :            : 
     891         [ -  + ]:          2 :         if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
     892                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
     893                 :            :                         "Queue %"PRIu16" of device with port_id=%"PRIu16" already started",
     894                 :            :                         rx_queue_id, port_id);
     895                 :          0 :                 return 0;
     896                 :            :         }
     897                 :            : 
     898                 :          2 :         ret = eth_err(port_id, dev->dev_ops->rx_queue_start(dev, rx_queue_id));
     899                 :            : 
     900                 :          2 :         rte_ethdev_trace_rx_queue_start(port_id, rx_queue_id, ret);
     901                 :            : 
     902                 :          2 :         return ret;
     903                 :            : }
     904                 :            : 
     905                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_queue_stop)
     906                 :            : int
     907                 :          2 : rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
     908                 :            : {
     909                 :            :         struct rte_eth_dev *dev;
     910                 :            :         int ret;
     911                 :            : 
     912         [ -  + ]:          2 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
     913                 :          2 :         dev = &rte_eth_devices[port_id];
     914                 :            : 
     915                 :          2 :         ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
     916         [ +  - ]:          2 :         if (ret != 0)
     917                 :            :                 return ret;
     918                 :            : 
     919         [ +  - ]:          2 :         if (dev->dev_ops->rx_queue_stop == NULL)
     920                 :            :                 return -ENOTSUP;
     921                 :            : 
     922         [ -  + ]:          2 :         if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
     923                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
     924                 :            :                         "Can't stop Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
     925                 :            :                         rx_queue_id, port_id);
     926                 :          0 :                 return -EINVAL;
     927                 :            :         }
     928                 :            : 
     929         [ -  + ]:          2 :         if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
     930                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
     931                 :            :                         "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped",
     932                 :            :                         rx_queue_id, port_id);
     933                 :          0 :                 return 0;
     934                 :            :         }
     935                 :            : 
     936                 :          2 :         ret = eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
     937                 :            : 
     938                 :          2 :         rte_ethdev_trace_rx_queue_stop(port_id, rx_queue_id, ret);
     939                 :            : 
     940                 :          2 :         return ret;
     941                 :            : }
     942                 :            : 
     943                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_queue_start)
     944                 :            : int
     945                 :          2 : rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
     946                 :            : {
     947                 :            :         struct rte_eth_dev *dev;
     948                 :            :         int ret;
     949                 :            : 
     950         [ -  + ]:          2 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
     951                 :          2 :         dev = &rte_eth_devices[port_id];
     952                 :            : 
     953         [ -  + ]:          2 :         if (!dev->data->dev_started) {
     954                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
     955                 :            :                         "Port %u must be started before start any queue",
     956                 :            :                         port_id);
     957                 :          0 :                 return -EINVAL;
     958                 :            :         }
     959                 :            : 
     960                 :          2 :         ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
     961         [ +  - ]:          2 :         if (ret != 0)
     962                 :            :                 return ret;
     963                 :            : 
     964         [ +  - ]:          2 :         if (dev->dev_ops->tx_queue_start == NULL)
     965                 :            :                 return -ENOTSUP;
     966                 :            : 
     967         [ -  + ]:          2 :         if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
     968                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
     969                 :            :                         "Can't start Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
     970                 :            :                         tx_queue_id, port_id);
     971                 :          0 :                 return -EINVAL;
     972                 :            :         }
     973                 :            : 
     974         [ -  + ]:          2 :         if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
     975                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
     976                 :            :                         "Queue %"PRIu16" of device with port_id=%"PRIu16" already started",
     977                 :            :                         tx_queue_id, port_id);
     978                 :          0 :                 return 0;
     979                 :            :         }
     980                 :            : 
     981                 :          2 :         ret = eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id));
     982                 :            : 
     983                 :          2 :         rte_ethdev_trace_tx_queue_start(port_id, tx_queue_id, ret);
     984                 :            : 
     985                 :          2 :         return ret;
     986                 :            : }
     987                 :            : 
     988                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_queue_stop)
     989                 :            : int
     990                 :          2 : rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
     991                 :            : {
     992                 :            :         struct rte_eth_dev *dev;
     993                 :            :         int ret;
     994                 :            : 
     995         [ -  + ]:          2 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
     996                 :          2 :         dev = &rte_eth_devices[port_id];
     997                 :            : 
     998                 :          2 :         ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
     999         [ +  - ]:          2 :         if (ret != 0)
    1000                 :            :                 return ret;
    1001                 :            : 
    1002         [ +  - ]:          2 :         if (dev->dev_ops->tx_queue_stop == NULL)
    1003                 :            :                 return -ENOTSUP;
    1004                 :            : 
    1005         [ -  + ]:          2 :         if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
    1006                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
    1007                 :            :                         "Can't stop Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
    1008                 :            :                         tx_queue_id, port_id);
    1009                 :          0 :                 return -EINVAL;
    1010                 :            :         }
    1011                 :            : 
    1012         [ -  + ]:          2 :         if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
    1013                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
    1014                 :            :                         "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped",
    1015                 :            :                         tx_queue_id, port_id);
    1016                 :          0 :                 return 0;
    1017                 :            :         }
    1018                 :            : 
    1019                 :          2 :         ret = eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
    1020                 :            : 
    1021                 :          2 :         rte_ethdev_trace_tx_queue_stop(port_id, tx_queue_id, ret);
    1022                 :            : 
    1023                 :          2 :         return ret;
    1024                 :            : }
    1025                 :            : 
    1026                 :            : RTE_EXPORT_SYMBOL(rte_eth_speed_bitflag)
    1027                 :            : uint32_t
    1028                 :          0 : rte_eth_speed_bitflag(uint32_t speed, int duplex)
    1029                 :            : {
    1030                 :            :         uint32_t ret;
    1031                 :            : 
    1032   [ #  #  #  #  :          0 :         switch (speed) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1033                 :          0 :         case RTE_ETH_SPEED_NUM_10M:
    1034         [ #  # ]:          0 :                 ret = duplex ? RTE_ETH_LINK_SPEED_10M : RTE_ETH_LINK_SPEED_10M_HD;
    1035                 :            :                 break;
    1036                 :          0 :         case RTE_ETH_SPEED_NUM_100M:
    1037         [ #  # ]:          0 :                 ret = duplex ? RTE_ETH_LINK_SPEED_100M : RTE_ETH_LINK_SPEED_100M_HD;
    1038                 :            :                 break;
    1039                 :            :         case RTE_ETH_SPEED_NUM_1G:
    1040                 :            :                 ret = RTE_ETH_LINK_SPEED_1G;
    1041                 :            :                 break;
    1042                 :          0 :         case RTE_ETH_SPEED_NUM_2_5G:
    1043                 :            :                 ret = RTE_ETH_LINK_SPEED_2_5G;
    1044                 :          0 :                 break;
    1045                 :          0 :         case RTE_ETH_SPEED_NUM_5G:
    1046                 :            :                 ret = RTE_ETH_LINK_SPEED_5G;
    1047                 :          0 :                 break;
    1048                 :          0 :         case RTE_ETH_SPEED_NUM_10G:
    1049                 :            :                 ret = RTE_ETH_LINK_SPEED_10G;
    1050                 :          0 :                 break;
    1051                 :          0 :         case RTE_ETH_SPEED_NUM_20G:
    1052                 :            :                 ret = RTE_ETH_LINK_SPEED_20G;
    1053                 :          0 :                 break;
    1054                 :          0 :         case RTE_ETH_SPEED_NUM_25G:
    1055                 :            :                 ret = RTE_ETH_LINK_SPEED_25G;
    1056                 :          0 :                 break;
    1057                 :          0 :         case RTE_ETH_SPEED_NUM_40G:
    1058                 :            :                 ret = RTE_ETH_LINK_SPEED_40G;
    1059                 :          0 :                 break;
    1060                 :          0 :         case RTE_ETH_SPEED_NUM_50G:
    1061                 :            :                 ret = RTE_ETH_LINK_SPEED_50G;
    1062                 :          0 :                 break;
    1063                 :          0 :         case RTE_ETH_SPEED_NUM_56G:
    1064                 :            :                 ret = RTE_ETH_LINK_SPEED_56G;
    1065                 :          0 :                 break;
    1066                 :          0 :         case RTE_ETH_SPEED_NUM_100G:
    1067                 :            :                 ret = RTE_ETH_LINK_SPEED_100G;
    1068                 :          0 :                 break;
    1069                 :          0 :         case RTE_ETH_SPEED_NUM_200G:
    1070                 :            :                 ret = RTE_ETH_LINK_SPEED_200G;
    1071                 :          0 :                 break;
    1072                 :          0 :         case RTE_ETH_SPEED_NUM_400G:
    1073                 :            :                 ret = RTE_ETH_LINK_SPEED_400G;
    1074                 :          0 :                 break;
    1075                 :          0 :         case RTE_ETH_SPEED_NUM_800G:
    1076                 :            :                 ret = RTE_ETH_LINK_SPEED_800G;
    1077                 :          0 :                 break;
    1078                 :          0 :         default:
    1079                 :            :                 ret = 0;
    1080                 :            :         }
    1081                 :            : 
    1082                 :          0 :         rte_eth_trace_speed_bitflag(speed, duplex, ret);
    1083                 :            : 
    1084                 :          0 :         return ret;
    1085                 :            : }
    1086                 :            : 
    1087                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_offload_name)
    1088                 :            : const char *
    1089                 :          0 : rte_eth_dev_rx_offload_name(uint64_t offload)
    1090                 :            : {
    1091                 :            :         const char *name = "UNKNOWN";
    1092                 :            :         unsigned int i;
    1093                 :            : 
    1094         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(eth_dev_rx_offload_names); ++i) {
    1095         [ #  # ]:          0 :                 if (offload == eth_dev_rx_offload_names[i].offload) {
    1096                 :          0 :                         name = eth_dev_rx_offload_names[i].name;
    1097                 :          0 :                         break;
    1098                 :            :                 }
    1099                 :            :         }
    1100                 :            : 
    1101                 :          0 :         rte_ethdev_trace_rx_offload_name(offload, name);
    1102                 :            : 
    1103                 :          0 :         return name;
    1104                 :            : }
    1105                 :            : 
    1106                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_offload_name)
    1107                 :            : const char *
    1108                 :          0 : rte_eth_dev_tx_offload_name(uint64_t offload)
    1109                 :            : {
    1110                 :            :         const char *name = "UNKNOWN";
    1111                 :            :         unsigned int i;
    1112                 :            : 
    1113         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(eth_dev_tx_offload_names); ++i) {
    1114         [ #  # ]:          0 :                 if (offload == eth_dev_tx_offload_names[i].offload) {
    1115                 :          0 :                         name = eth_dev_tx_offload_names[i].name;
    1116                 :          0 :                         break;
    1117                 :            :                 }
    1118                 :            :         }
    1119                 :            : 
    1120                 :          0 :         rte_ethdev_trace_tx_offload_name(offload, name);
    1121                 :            : 
    1122                 :          0 :         return name;
    1123                 :            : }
    1124                 :            : 
    1125                 :            : static char *
    1126                 :          0 : eth_dev_offload_names(uint64_t bitmask, char *buf, size_t size,
    1127                 :            :         const char *(*offload_name)(uint64_t))
    1128                 :            : {
    1129                 :            :         unsigned int pos = 0;
    1130                 :            :         int ret;
    1131                 :            : 
    1132                 :            :         /* There should be at least enough space to handle those cases */
    1133                 :            :         RTE_ASSERT(size >= sizeof("none") && size >= sizeof("..."));
    1134                 :            : 
    1135         [ #  # ]:          0 :         if (bitmask == 0) {
    1136                 :            :                 ret = snprintf(&buf[pos], size - pos, "none");
    1137   [ #  #  #  # ]:          0 :                 if (ret < 0 || pos + ret >= size)
    1138                 :            :                         ret = 0;
    1139                 :          0 :                 pos += ret;
    1140                 :          0 :                 goto out;
    1141                 :            :         }
    1142                 :            : 
    1143         [ #  # ]:          0 :         while (bitmask != 0) {
    1144                 :          0 :                 uint64_t offload = RTE_BIT64(rte_ctz64(bitmask));
    1145                 :          0 :                 const char *name = offload_name(offload);
    1146                 :            : 
    1147         [ #  # ]:          0 :                 ret = snprintf(&buf[pos], size - pos, "%s,", name);
    1148   [ #  #  #  # ]:          0 :                 if (ret < 0 || pos + ret >= size) {
    1149         [ #  # ]:          0 :                         if (pos + sizeof("...") >= size)
    1150                 :          0 :                                 pos = size - sizeof("...");
    1151         [ #  # ]:          0 :                         ret = snprintf(&buf[pos], size - pos, "...");
    1152   [ #  #  #  # ]:          0 :                         if (ret > 0 && pos + ret < size)
    1153                 :            :                                 pos += ret;
    1154                 :          0 :                         goto out;
    1155                 :            :                 }
    1156                 :            : 
    1157                 :            :                 pos += ret;
    1158                 :          0 :                 bitmask &= ~offload;
    1159                 :            :         }
    1160                 :            : 
    1161                 :            :         /* Eliminate trailing comma */
    1162                 :          0 :         pos--;
    1163                 :          0 : out:
    1164                 :          0 :         buf[pos] = '\0';
    1165                 :          0 :         return buf;
    1166                 :            : }
    1167                 :            : 
    1168                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_capability_name)
    1169                 :            : const char *
    1170                 :          0 : rte_eth_dev_capability_name(uint64_t capability)
    1171                 :            : {
    1172                 :            :         const char *name = "UNKNOWN";
    1173                 :            :         unsigned int i;
    1174                 :            : 
    1175         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(rte_eth_dev_capa_names); ++i) {
    1176         [ #  # ]:          0 :                 if (capability == rte_eth_dev_capa_names[i].offload) {
    1177                 :          0 :                         name = rte_eth_dev_capa_names[i].name;
    1178                 :          0 :                         break;
    1179                 :            :                 }
    1180                 :            :         }
    1181                 :            : 
    1182                 :          0 :         rte_ethdev_trace_capability_name(capability, name);
    1183                 :            : 
    1184                 :          0 :         return name;
    1185                 :            : }
    1186                 :            : 
    1187                 :            : static inline int
    1188                 :          0 : eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size,
    1189                 :            :                    uint32_t max_rx_pkt_len, uint32_t dev_info_size)
    1190                 :            : {
    1191                 :            :         int ret = 0;
    1192                 :            : 
    1193         [ #  # ]:          0 :         if (dev_info_size == 0) {
    1194         [ #  # ]:          0 :                 if (config_size != max_rx_pkt_len) {
    1195                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%d max_lro_pkt_size"
    1196                 :            :                                        " %u != %u is not allowed",
    1197                 :            :                                        port_id, config_size, max_rx_pkt_len);
    1198                 :            :                         ret = -EINVAL;
    1199                 :            :                 }
    1200         [ #  # ]:          0 :         } else if (config_size > dev_info_size) {
    1201                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
    1202                 :            :                                "> max allowed value %u", port_id, config_size,
    1203                 :            :                                dev_info_size);
    1204                 :            :                 ret = -EINVAL;
    1205         [ #  # ]:          0 :         } else if (config_size < RTE_ETHER_MIN_LEN) {
    1206                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
    1207                 :            :                                "< min allowed value %u", port_id, config_size,
    1208                 :            :                                (unsigned int)RTE_ETHER_MIN_LEN);
    1209                 :            :                 ret = -EINVAL;
    1210                 :            :         }
    1211                 :          0 :         return ret;
    1212                 :            : }
    1213                 :            : 
    1214                 :            : /*
    1215                 :            :  * Validate offloads that are requested through rte_eth_dev_configure against
    1216                 :            :  * the offloads successfully set by the Ethernet device.
    1217                 :            :  *
    1218                 :            :  * @param port_id
    1219                 :            :  *   The port identifier of the Ethernet device.
    1220                 :            :  * @param req_offloads
    1221                 :            :  *   The offloads that have been requested through `rte_eth_dev_configure`.
    1222                 :            :  * @param set_offloads
    1223                 :            :  *   The offloads successfully set by the Ethernet device.
    1224                 :            :  * @param offload_type
    1225                 :            :  *   The offload type i.e. Rx/Tx string.
    1226                 :            :  * @param offload_name
    1227                 :            :  *   The function that prints the offload name.
    1228                 :            :  * @return
    1229                 :            :  *   - (0) if validation successful.
    1230                 :            :  *   - (-EINVAL) if requested offload has been silently disabled.
    1231                 :            :  */
    1232                 :            : static int
    1233                 :         94 : eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,
    1234                 :            :                   uint64_t set_offloads, const char *offload_type,
    1235                 :            :                   const char *(*offload_name)(uint64_t))
    1236                 :            : {
    1237                 :         94 :         uint64_t offloads_diff = req_offloads ^ set_offloads;
    1238                 :            :         uint64_t offload;
    1239                 :            :         int ret = 0;
    1240                 :            : 
    1241         [ -  + ]:         94 :         while (offloads_diff != 0) {
    1242                 :            :                 /* Check if any offload is requested but not enabled. */
    1243                 :          0 :                 offload = RTE_BIT64(rte_ctz64(offloads_diff));
    1244         [ #  # ]:          0 :                 if (offload & req_offloads) {
    1245                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    1246                 :            :                                 "Port %u failed to enable %s offload %s",
    1247                 :            :                                 port_id, offload_type, offload_name(offload));
    1248                 :            :                         ret = -EINVAL;
    1249                 :            :                 }
    1250                 :            : 
    1251                 :            :                 /* Check if offload couldn't be disabled. */
    1252         [ #  # ]:          0 :                 if (offload & set_offloads) {
    1253                 :          0 :                         RTE_ETHDEV_LOG_LINE(DEBUG,
    1254                 :            :                                 "Port %u %s offload %s is not requested but enabled",
    1255                 :            :                                 port_id, offload_type, offload_name(offload));
    1256                 :            :                 }
    1257                 :            : 
    1258                 :          0 :                 offloads_diff &= ~offload;
    1259                 :            :         }
    1260                 :            : 
    1261                 :         94 :         return ret;
    1262                 :            : }
    1263                 :            : 
    1264                 :            : static uint32_t
    1265                 :            : eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
    1266                 :            : {
    1267                 :            :         uint32_t overhead_len;
    1268                 :            : 
    1269   [ -  -  -  -  :         30 :         if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu)
                   +  - ]
    1270                 :         30 :                 overhead_len = max_rx_pktlen - max_mtu;
    1271                 :            :         else
    1272                 :            :                 overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
    1273                 :            : 
    1274                 :            :         return overhead_len;
    1275                 :            : }
    1276                 :            : 
    1277                 :            : /* rte_eth_dev_info_get() should be called prior to this function */
    1278                 :            : static int
    1279                 :         52 : eth_dev_validate_mtu(uint16_t port_id, struct rte_eth_dev_info *dev_info,
    1280                 :            :                 uint16_t mtu)
    1281                 :            : {
    1282                 :            :         uint32_t overhead_len;
    1283                 :            :         uint32_t frame_size;
    1284                 :            : 
    1285         [ -  + ]:         52 :         if (mtu < dev_info->min_mtu) {
    1286                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1287                 :            :                         "MTU (%u) < device min MTU (%u) for port_id %u",
    1288                 :            :                         mtu, dev_info->min_mtu, port_id);
    1289                 :          0 :                 return -EINVAL;
    1290                 :            :         }
    1291         [ -  + ]:         52 :         if (mtu > dev_info->max_mtu) {
    1292                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1293                 :            :                         "MTU (%u) > device max MTU (%u) for port_id %u",
    1294                 :            :                         mtu, dev_info->max_mtu, port_id);
    1295                 :          0 :                 return -EINVAL;
    1296                 :            :         }
    1297                 :            : 
    1298         [ +  + ]:         52 :         overhead_len = eth_dev_get_overhead_len(dev_info->max_rx_pktlen,
    1299                 :            :                         dev_info->max_mtu);
    1300                 :         52 :         frame_size = mtu + overhead_len;
    1301         [ -  + ]:         52 :         if (frame_size < RTE_ETHER_MIN_LEN) {
    1302                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1303                 :            :                         "Frame size (%u) < min frame size (%u) for port_id %u",
    1304                 :            :                         frame_size, RTE_ETHER_MIN_LEN, port_id);
    1305                 :          0 :                 return -EINVAL;
    1306                 :            :         }
    1307                 :            : 
    1308         [ -  + ]:         52 :         if (frame_size > dev_info->max_rx_pktlen) {
    1309                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1310                 :            :                         "Frame size (%u) > device max frame size (%u) for port_id %u",
    1311                 :            :                         frame_size, dev_info->max_rx_pktlen, port_id);
    1312                 :          0 :                 return -EINVAL;
    1313                 :            :         }
    1314                 :            : 
    1315                 :            :         return 0;
    1316                 :            : }
    1317                 :            : 
    1318                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_configure)
    1319                 :            : int
    1320                 :         47 : rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
    1321                 :            :                       const struct rte_eth_conf *dev_conf)
    1322                 :            : {
    1323                 :            :         enum rte_eth_hash_function algorithm;
    1324                 :            :         struct rte_eth_dev *dev;
    1325                 :            :         struct rte_eth_dev_info dev_info;
    1326                 :            :         struct rte_eth_conf orig_conf;
    1327                 :            :         int diag;
    1328                 :            :         int ret;
    1329                 :            :         uint16_t old_mtu;
    1330                 :            : 
    1331         [ -  + ]:         47 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1332                 :         47 :         dev = &rte_eth_devices[port_id];
    1333                 :            : 
    1334         [ -  + ]:         47 :         if (dev_conf == NULL) {
    1335                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1336                 :            :                         "Cannot configure ethdev port %u from NULL config",
    1337                 :            :                         port_id);
    1338                 :          0 :                 return -EINVAL;
    1339                 :            :         }
    1340                 :            : 
    1341         [ +  - ]:         47 :         if (dev->dev_ops->dev_configure == NULL)
    1342                 :            :                 return -ENOTSUP;
    1343                 :            : 
    1344         [ -  + ]:         47 :         if (dev->data->dev_started) {
    1345                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1346                 :            :                         "Port %u must be stopped to allow configuration",
    1347                 :            :                         port_id);
    1348                 :          0 :                 return -EBUSY;
    1349                 :            :         }
    1350                 :            : 
    1351                 :            :         /*
    1352                 :            :          * Ensure that "dev_configured" is always 0 each time prepare to do
    1353                 :            :          * dev_configure() to avoid any non-anticipated behaviour.
    1354                 :            :          * And set to 1 when dev_configure() is executed successfully.
    1355                 :            :          */
    1356                 :         47 :         dev->data->dev_configured = 0;
    1357                 :            : 
    1358                 :            :          /* Store original config, as rollback required on failure */
    1359         [ +  - ]:         47 :         memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
    1360                 :            : 
    1361                 :            :         /*
    1362                 :            :          * Copy the dev_conf parameter into the dev structure.
    1363                 :            :          * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
    1364                 :            :          */
    1365         [ +  - ]:         47 :         if (dev_conf != &dev->data->dev_conf)
    1366                 :            :                 memcpy(&dev->data->dev_conf, dev_conf,
    1367                 :            :                        sizeof(dev->data->dev_conf));
    1368                 :            : 
    1369                 :            :         /* Backup mtu for rollback */
    1370                 :         47 :         old_mtu = dev->data->mtu;
    1371                 :            : 
    1372                 :            :         /* fields must be zero to reserve them for future ABI changes */
    1373         [ +  - ]:         47 :         if (dev_conf->rxmode.reserved_64s[0] != 0 ||
    1374         [ +  - ]:         47 :             dev_conf->rxmode.reserved_64s[1] != 0 ||
    1375         [ +  - ]:         47 :             dev_conf->rxmode.reserved_ptrs[0] != NULL ||
    1376         [ -  + ]:         47 :             dev_conf->rxmode.reserved_ptrs[1] != NULL) {
    1377                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rxmode reserved fields not zero");
    1378                 :            :                 ret = -EINVAL;
    1379                 :          0 :                 goto rollback;
    1380                 :            :         }
    1381                 :            : 
    1382         [ +  - ]:         47 :         if (dev_conf->txmode.reserved_64s[0] != 0 ||
    1383         [ +  - ]:         47 :             dev_conf->txmode.reserved_64s[1] != 0 ||
    1384         [ +  - ]:         47 :             dev_conf->txmode.reserved_ptrs[0] != NULL ||
    1385         [ -  + ]:         47 :             dev_conf->txmode.reserved_ptrs[1] != NULL) {
    1386                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "txmode reserved fields not zero");
    1387                 :            :                 ret = -EINVAL;
    1388                 :          0 :                 goto rollback;
    1389                 :            :         }
    1390                 :            : 
    1391                 :         47 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    1392         [ -  + ]:         47 :         if (ret != 0)
    1393                 :          0 :                 goto rollback;
    1394                 :            : 
    1395                 :            :         /* If number of queues specified by application for both Rx and Tx is
    1396                 :            :          * zero, use driver preferred values. This cannot be done individually
    1397                 :            :          * as it is valid for either Tx or Rx (but not both) to be zero.
    1398                 :            :          * If driver does not provide any preferred valued, fall back on
    1399                 :            :          * EAL defaults.
    1400                 :            :          */
    1401         [ -  + ]:         47 :         if (nb_rx_q == 0 && nb_tx_q == 0) {
    1402                 :          0 :                 nb_rx_q = dev_info.default_rxportconf.nb_queues;
    1403                 :            :                 if (nb_rx_q == 0)
    1404                 :            :                         nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES;
    1405                 :          0 :                 nb_tx_q = dev_info.default_txportconf.nb_queues;
    1406                 :            :                 if (nb_tx_q == 0)
    1407                 :            :                         nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES;
    1408                 :            :         }
    1409                 :            : 
    1410         [ -  + ]:         47 :         if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
    1411                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1412                 :            :                         "Number of Rx queues requested (%u) is greater than max supported(%d)",
    1413                 :            :                         nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
    1414                 :            :                 ret = -EINVAL;
    1415                 :          0 :                 goto rollback;
    1416                 :            :         }
    1417                 :            : 
    1418         [ -  + ]:         47 :         if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
    1419                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1420                 :            :                         "Number of Tx queues requested (%u) is greater than max supported(%d)",
    1421                 :            :                         nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
    1422                 :            :                 ret = -EINVAL;
    1423                 :          0 :                 goto rollback;
    1424                 :            :         }
    1425                 :            : 
    1426                 :            :         /*
    1427                 :            :          * Check that the numbers of Rx and Tx queues are not greater
    1428                 :            :          * than the maximum number of Rx and Tx queues supported by the
    1429                 :            :          * configured device.
    1430                 :            :          */
    1431         [ -  + ]:         47 :         if (nb_rx_q > dev_info.max_rx_queues) {
    1432                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u nb_rx_queues=%u > %u",
    1433                 :            :                         port_id, nb_rx_q, dev_info.max_rx_queues);
    1434                 :            :                 ret = -EINVAL;
    1435                 :          0 :                 goto rollback;
    1436                 :            :         }
    1437                 :            : 
    1438         [ -  + ]:         47 :         if (nb_tx_q > dev_info.max_tx_queues) {
    1439                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u nb_tx_queues=%u > %u",
    1440                 :            :                         port_id, nb_tx_q, dev_info.max_tx_queues);
    1441                 :            :                 ret = -EINVAL;
    1442                 :          0 :                 goto rollback;
    1443                 :            :         }
    1444                 :            : 
    1445                 :            :         /* Check that the device supports requested interrupts */
    1446         [ +  + ]:         47 :         if ((dev_conf->intr_conf.lsc == 1) &&
    1447         [ -  + ]:          1 :                         (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
    1448                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Driver %s does not support lsc",
    1449                 :            :                         dev->device->driver->name);
    1450                 :            :                 ret = -EINVAL;
    1451                 :          0 :                 goto rollback;
    1452                 :            :         }
    1453         [ -  + ]:         47 :         if ((dev_conf->intr_conf.rmv == 1) &&
    1454         [ #  # ]:          0 :                         (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
    1455                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Driver %s does not support rmv",
    1456                 :            :                         dev->device->driver->name);
    1457                 :            :                 ret = -EINVAL;
    1458                 :          0 :                 goto rollback;
    1459                 :            :         }
    1460                 :            : 
    1461         [ +  - ]:         47 :         if (dev_conf->rxmode.mtu == 0)
    1462                 :         47 :                 dev->data->dev_conf.rxmode.mtu =
    1463         [ +  - ]:         47 :                         (dev_info.max_mtu == 0) ? RTE_ETHER_MTU :
    1464                 :         47 :                         RTE_MIN(dev_info.max_mtu, RTE_ETHER_MTU);
    1465                 :            : 
    1466                 :         47 :         ret = eth_dev_validate_mtu(port_id, &dev_info,
    1467                 :         47 :                         dev->data->dev_conf.rxmode.mtu);
    1468         [ -  + ]:         47 :         if (ret != 0)
    1469                 :          0 :                 goto rollback;
    1470                 :            : 
    1471                 :         47 :         dev->data->mtu = dev->data->dev_conf.rxmode.mtu;
    1472                 :            : 
    1473                 :            :         /*
    1474                 :            :          * If LRO is enabled, check that the maximum aggregated packet
    1475                 :            :          * size is supported by the configured device.
    1476                 :            :          */
    1477         [ -  + ]:         47 :         if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) {
    1478                 :            :                 uint32_t max_rx_pktlen;
    1479                 :            :                 uint32_t overhead_len;
    1480                 :            : 
    1481                 :          0 :                 overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
    1482         [ #  # ]:          0 :                                 dev_info.max_mtu);
    1483                 :          0 :                 max_rx_pktlen = dev->data->dev_conf.rxmode.mtu + overhead_len;
    1484         [ #  # ]:          0 :                 if (dev_conf->rxmode.max_lro_pkt_size == 0)
    1485                 :          0 :                         dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen;
    1486                 :          0 :                 ret = eth_dev_check_lro_pkt_size(port_id,
    1487                 :            :                                 dev->data->dev_conf.rxmode.max_lro_pkt_size,
    1488                 :            :                                 max_rx_pktlen,
    1489                 :            :                                 dev_info.max_lro_pkt_size);
    1490         [ #  # ]:          0 :                 if (ret != 0)
    1491                 :          0 :                         goto rollback;
    1492                 :            :         }
    1493                 :            : 
    1494                 :            :         /* Any requested offloading must be within its device capabilities */
    1495         [ -  + ]:         47 :         if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) !=
    1496                 :            :              dev_conf->rxmode.offloads) {
    1497                 :            :                 char buffer[512];
    1498                 :            : 
    1499                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support Rx offloads %s",
    1500                 :            :                         port_id, eth_dev_offload_names(
    1501                 :            :                         dev_conf->rxmode.offloads & ~dev_info.rx_offload_capa,
    1502                 :            :                         buffer, sizeof(buffer), rte_eth_dev_rx_offload_name));
    1503                 :          0 :                 RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u was requested Rx offloads %s",
    1504                 :            :                         port_id, eth_dev_offload_names(dev_conf->rxmode.offloads,
    1505                 :            :                         buffer, sizeof(buffer), rte_eth_dev_rx_offload_name));
    1506                 :          0 :                 RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u supports Rx offloads %s",
    1507                 :            :                         port_id, eth_dev_offload_names(dev_info.rx_offload_capa,
    1508                 :            :                         buffer, sizeof(buffer), rte_eth_dev_rx_offload_name));
    1509                 :            : 
    1510                 :            :                 ret = -EINVAL;
    1511                 :          0 :                 goto rollback;
    1512                 :            :         }
    1513         [ -  + ]:         47 :         if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) !=
    1514                 :            :              dev_conf->txmode.offloads) {
    1515                 :            :                 char buffer[512];
    1516                 :            : 
    1517                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support Tx offloads %s",
    1518                 :            :                         port_id, eth_dev_offload_names(
    1519                 :            :                         dev_conf->txmode.offloads & ~dev_info.tx_offload_capa,
    1520                 :            :                         buffer, sizeof(buffer), rte_eth_dev_tx_offload_name));
    1521                 :          0 :                 RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u was requested Tx offloads %s",
    1522                 :            :                         port_id, eth_dev_offload_names(dev_conf->txmode.offloads,
    1523                 :            :                         buffer, sizeof(buffer), rte_eth_dev_tx_offload_name));
    1524                 :          0 :                 RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u supports Tx offloads %s",
    1525                 :            :                         port_id, eth_dev_offload_names(dev_info.tx_offload_capa,
    1526                 :            :                         buffer, sizeof(buffer), rte_eth_dev_tx_offload_name));
    1527                 :            :                 ret = -EINVAL;
    1528                 :          0 :                 goto rollback;
    1529                 :            :         }
    1530                 :            : 
    1531                 :         94 :         dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
    1532         [ -  + ]:         47 :                 rte_eth_rss_hf_refine(dev_conf->rx_adv_conf.rss_conf.rss_hf);
    1533                 :            : 
    1534                 :            :         /* Check that device supports requested rss hash functions. */
    1535                 :         47 :         if ((dev_info.flow_type_rss_offloads |
    1536         [ -  + ]:         47 :              dev_conf->rx_adv_conf.rss_conf.rss_hf) !=
    1537                 :            :             dev_info.flow_type_rss_offloads) {
    1538                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1539                 :            :                         "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64,
    1540                 :            :                         port_id, dev_conf->rx_adv_conf.rss_conf.rss_hf,
    1541                 :            :                         dev_info.flow_type_rss_offloads);
    1542                 :            :                 ret = -EINVAL;
    1543                 :          0 :                 goto rollback;
    1544                 :            :         }
    1545                 :            : 
    1546                 :            :         /* Check if Rx RSS distribution is disabled but RSS hash is enabled. */
    1547         [ +  - ]:         47 :         if (((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) == 0) &&
    1548         [ -  + ]:         47 :             (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH)) {
    1549                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1550                 :            :                         "Ethdev port_id=%u config invalid Rx mq_mode without RSS but %s offload is requested",
    1551                 :            :                         port_id,
    1552                 :            :                         rte_eth_dev_rx_offload_name(RTE_ETH_RX_OFFLOAD_RSS_HASH));
    1553                 :            :                 ret = -EINVAL;
    1554                 :          0 :                 goto rollback;
    1555                 :            :         }
    1556                 :            : 
    1557         [ -  + ]:         47 :         if (dev_conf->rx_adv_conf.rss_conf.rss_key != NULL &&
    1558         [ #  # ]:          0 :             dev_conf->rx_adv_conf.rss_conf.rss_key_len != dev_info.hash_key_size) {
    1559                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1560                 :            :                         "Ethdev port_id=%u invalid RSS key len: %u, valid value: %u",
    1561                 :            :                         port_id, dev_conf->rx_adv_conf.rss_conf.rss_key_len,
    1562                 :            :                         dev_info.hash_key_size);
    1563                 :            :                 ret = -EINVAL;
    1564                 :          0 :                 goto rollback;
    1565                 :            :         }
    1566                 :            : 
    1567                 :         47 :         algorithm = dev_conf->rx_adv_conf.rss_conf.algorithm;
    1568         [ +  - ]:         47 :         if ((size_t)algorithm >= CHAR_BIT * sizeof(dev_info.rss_algo_capa) ||
    1569         [ -  + ]:         47 :             (dev_info.rss_algo_capa & RTE_ETH_HASH_ALGO_TO_CAPA(algorithm)) == 0) {
    1570                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1571                 :            :                         "Ethdev port_id=%u configured RSS hash algorithm (%u)"
    1572                 :            :                         "is not in the algorithm capability (0x%" PRIx32 ")",
    1573                 :            :                         port_id, algorithm, dev_info.rss_algo_capa);
    1574                 :            :                 ret = -EINVAL;
    1575                 :          0 :                 goto rollback;
    1576                 :            :         }
    1577                 :            : 
    1578         [ +  - ]:         47 :         if (dev_info.max_vmdq_pools == 0) {
    1579         [ -  + ]:         47 :                 if ((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0) {
    1580                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support VMDq rx mode",
    1581                 :            :                                 port_id);
    1582                 :            :                         ret = -EINVAL;
    1583                 :          0 :                         goto rollback;
    1584                 :            :                 }
    1585         [ -  + ]:         47 :                 if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_DCB ||
    1586                 :            :                                 dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_ONLY) {
    1587                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support VMDq tx mode",
    1588                 :            :                                 port_id);
    1589                 :            :                         ret = -EINVAL;
    1590                 :          0 :                         goto rollback;
    1591                 :            :                 }
    1592                 :            :         }
    1593                 :            : 
    1594                 :            :         /*
    1595                 :            :          * Setup new number of Rx/Tx queues and reconfigure device.
    1596                 :            :          */
    1597                 :         47 :         diag = eth_dev_rx_queue_config(dev, nb_rx_q);
    1598         [ -  + ]:         47 :         if (diag != 0) {
    1599                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1600                 :            :                         "Port%u eth_dev_rx_queue_config = %d",
    1601                 :            :                         port_id, diag);
    1602                 :            :                 ret = diag;
    1603                 :          0 :                 goto rollback;
    1604                 :            :         }
    1605                 :            : 
    1606                 :         47 :         diag = eth_dev_tx_queue_config(dev, nb_tx_q);
    1607         [ -  + ]:         47 :         if (diag != 0) {
    1608                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1609                 :            :                         "Port%u eth_dev_tx_queue_config = %d",
    1610                 :            :                         port_id, diag);
    1611                 :          0 :                 eth_dev_rx_queue_config(dev, 0);
    1612                 :            :                 ret = diag;
    1613                 :          0 :                 goto rollback;
    1614                 :            :         }
    1615                 :            : 
    1616                 :         47 :         diag = dev->dev_ops->dev_configure(dev);
    1617         [ -  + ]:         47 :         if (diag != 0) {
    1618                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port%u dev_configure = %d",
    1619                 :            :                         port_id, diag);
    1620                 :          0 :                 ret = eth_err(port_id, diag);
    1621                 :          0 :                 goto reset_queues;
    1622                 :            :         }
    1623                 :            : 
    1624                 :            :         /* Initialize Rx profiling if enabled at compilation time. */
    1625                 :         47 :         diag = __rte_eth_dev_profile_init(port_id, dev);
    1626         [ -  + ]:         47 :         if (diag != 0) {
    1627                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port%u __rte_eth_dev_profile_init = %d",
    1628                 :            :                         port_id, diag);
    1629                 :          0 :                 ret = eth_err(port_id, diag);
    1630                 :          0 :                 goto reset_queues;
    1631                 :            :         }
    1632                 :            : 
    1633                 :            :         /* Validate Rx offloads. */
    1634                 :         47 :         diag = eth_dev_validate_offloads(port_id,
    1635                 :         47 :                         dev_conf->rxmode.offloads,
    1636                 :         47 :                         dev->data->dev_conf.rxmode.offloads, "Rx",
    1637                 :            :                         rte_eth_dev_rx_offload_name);
    1638         [ -  + ]:         47 :         if (diag != 0) {
    1639                 :            :                 ret = diag;
    1640                 :          0 :                 goto reset_queues;
    1641                 :            :         }
    1642                 :            : 
    1643                 :            :         /* Validate Tx offloads. */
    1644                 :         47 :         diag = eth_dev_validate_offloads(port_id,
    1645                 :         47 :                         dev_conf->txmode.offloads,
    1646                 :         47 :                         dev->data->dev_conf.txmode.offloads, "Tx",
    1647                 :            :                         rte_eth_dev_tx_offload_name);
    1648         [ -  + ]:         47 :         if (diag != 0) {
    1649                 :            :                 ret = diag;
    1650                 :          0 :                 goto reset_queues;
    1651                 :            :         }
    1652                 :            : 
    1653         [ -  + ]:         47 :         dev->data->dev_configured = 1;
    1654                 :         47 :         rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
    1655                 :         47 :         return 0;
    1656                 :          0 : reset_queues:
    1657                 :          0 :         eth_dev_rx_queue_config(dev, 0);
    1658                 :          0 :         eth_dev_tx_queue_config(dev, 0);
    1659                 :          0 : rollback:
    1660         [ #  # ]:          0 :         memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
    1661         [ #  # ]:          0 :         if (old_mtu != dev->data->mtu)
    1662                 :          0 :                 dev->data->mtu = old_mtu;
    1663                 :            : 
    1664                 :          0 :         rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
    1665                 :          0 :         return ret;
    1666                 :            : }
    1667                 :            : 
    1668                 :            : static void
    1669                 :         42 : eth_dev_mac_restore(struct rte_eth_dev *dev,
    1670                 :            :                         struct rte_eth_dev_info *dev_info)
    1671                 :            : {
    1672                 :            :         struct rte_ether_addr *addr;
    1673                 :            :         uint16_t i;
    1674                 :            :         uint32_t pool;
    1675                 :            :         uint64_t pool_mask;
    1676                 :            : 
    1677                 :            :         /* replay MAC address configuration including default MAC */
    1678                 :         42 :         addr = &dev->data->mac_addrs[0];
    1679         [ +  + ]:         42 :         if (dev->dev_ops->mac_addr_set != NULL)
    1680                 :          6 :                 dev->dev_ops->mac_addr_set(dev, addr);
    1681         [ +  + ]:         36 :         else if (dev->dev_ops->mac_addr_add != NULL)
    1682                 :         10 :                 dev->dev_ops->mac_addr_add(dev, addr, 0, 0);
    1683                 :            : 
    1684         [ +  + ]:         42 :         if (dev->dev_ops->mac_addr_add != NULL) {
    1685                 :         14 :                 bool vmdq = (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0;
    1686                 :            : 
    1687         [ +  + ]:         74 :                 for (i = 1; i < dev_info->max_mac_addrs; i++) {
    1688         [ +  - ]:         60 :                         addr = &dev->data->mac_addrs[i];
    1689                 :            : 
    1690                 :            :                         /* skip zero address */
    1691         [ +  - ]:         60 :                         if (rte_is_zero_ether_addr(addr))
    1692                 :         60 :                                 continue;
    1693                 :            : 
    1694         [ #  # ]:          0 :                         if (!vmdq) {
    1695                 :          0 :                                 dev->dev_ops->mac_addr_add(dev, addr, i, 0);
    1696                 :            :                         } else {
    1697                 :            :                                 pool = 0;
    1698                 :          0 :                                 pool_mask = dev->data->mac_pool_sel[i];
    1699                 :            : 
    1700                 :            :                                 do {
    1701         [ #  # ]:          0 :                                         if (pool_mask & UINT64_C(1))
    1702                 :          0 :                                                 dev->dev_ops->mac_addr_add(dev, addr, i, pool);
    1703                 :          0 :                                         pool_mask >>= 1;
    1704                 :          0 :                                         pool++;
    1705         [ #  # ]:          0 :                                 } while (pool_mask);
    1706                 :            :                         }
    1707                 :            :                 }
    1708                 :            :         }
    1709                 :         42 : }
    1710                 :            : 
    1711                 :            : static int
    1712                 :         42 : eth_dev_promiscuous_restore(struct rte_eth_dev *dev, uint16_t port_id)
    1713                 :            : {
    1714                 :            :         int ret;
    1715                 :            : 
    1716                 :            :         /* replay promiscuous configuration */
    1717                 :            :         /*
    1718                 :            :          * use callbacks directly since we don't need port_id check and
    1719                 :            :          * would like to bypass the same value set
    1720                 :            :          */
    1721         [ +  + ]:         42 :         if (rte_eth_promiscuous_get(port_id) == 1 &&
    1722         [ +  + ]:         36 :             dev->dev_ops->promiscuous_enable != NULL) {
    1723                 :         10 :                 ret = eth_err(port_id, dev->dev_ops->promiscuous_enable(dev));
    1724         [ -  + ]:         10 :                 if (ret != 0 && ret != -ENOTSUP) {
    1725                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    1726                 :            :                                 "Failed to enable promiscuous mode for device (port %u): %s",
    1727                 :            :                                 port_id, rte_strerror(-ret));
    1728                 :          0 :                         return ret;
    1729                 :            :                 }
    1730         [ +  + ]:         32 :         } else if (rte_eth_promiscuous_get(port_id) == 0 &&
    1731         [ +  - ]:          6 :                    dev->dev_ops->promiscuous_disable != NULL) {
    1732                 :          6 :                 ret = eth_err(port_id, dev->dev_ops->promiscuous_disable(dev));
    1733         [ -  + ]:          6 :                 if (ret != 0 && ret != -ENOTSUP) {
    1734                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    1735                 :            :                                 "Failed to disable promiscuous mode for device (port %u): %s",
    1736                 :            :                                 port_id, rte_strerror(-ret));
    1737                 :          0 :                         return ret;
    1738                 :            :                 }
    1739                 :            :         }
    1740                 :            : 
    1741                 :            :         return 0;
    1742                 :            : }
    1743                 :            : 
    1744                 :            : static int
    1745                 :         42 : eth_dev_allmulticast_restore(struct rte_eth_dev *dev, uint16_t port_id)
    1746                 :            : {
    1747                 :            :         int ret;
    1748                 :            : 
    1749                 :            :         /* replay all multicast configuration */
    1750                 :            :         /*
    1751                 :            :          * use callbacks directly since we don't need port_id check and
    1752                 :            :          * would like to bypass the same value set
    1753                 :            :          */
    1754         [ +  + ]:         42 :         if (rte_eth_allmulticast_get(port_id) == 1 &&
    1755         [ +  + ]:         36 :             dev->dev_ops->allmulticast_enable != NULL) {
    1756                 :         10 :                 ret = eth_err(port_id, dev->dev_ops->allmulticast_enable(dev));
    1757         [ -  + ]:         10 :                 if (ret != 0 && ret != -ENOTSUP) {
    1758                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    1759                 :            :                                 "Failed to enable allmulticast mode for device (port %u): %s",
    1760                 :            :                                 port_id, rte_strerror(-ret));
    1761                 :          0 :                         return ret;
    1762                 :            :                 }
    1763         [ +  + ]:         32 :         } else if (rte_eth_allmulticast_get(port_id) == 0 &&
    1764         [ +  + ]:          6 :                    dev->dev_ops->allmulticast_disable != NULL) {
    1765                 :          4 :                 ret = eth_err(port_id, dev->dev_ops->allmulticast_disable(dev));
    1766         [ -  + ]:          4 :                 if (ret != 0 && ret != -ENOTSUP) {
    1767                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    1768                 :            :                                 "Failed to disable allmulticast mode for device (port %u): %s",
    1769                 :            :                                 port_id, rte_strerror(-ret));
    1770                 :          0 :                         return ret;
    1771                 :            :                 }
    1772                 :            :         }
    1773                 :            : 
    1774                 :            :         return 0;
    1775                 :            : }
    1776                 :            : 
    1777                 :            : static int
    1778                 :         42 : eth_dev_config_restore(struct rte_eth_dev *dev,
    1779                 :            :                 struct rte_eth_dev_info *dev_info,
    1780                 :            :                 uint64_t restore_flags,
    1781                 :            :                 uint16_t port_id)
    1782                 :            : {
    1783                 :            :         int ret;
    1784                 :            : 
    1785         [ +  - ]:         42 :         if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR) &&
    1786         [ +  - ]:         42 :             (restore_flags & RTE_ETH_RESTORE_MAC_ADDR))
    1787                 :         42 :                 eth_dev_mac_restore(dev, dev_info);
    1788                 :            : 
    1789         [ +  - ]:         42 :         if (restore_flags & RTE_ETH_RESTORE_PROMISC) {
    1790                 :         42 :                 ret = eth_dev_promiscuous_restore(dev, port_id);
    1791         [ +  - ]:         42 :                 if (ret != 0)
    1792                 :            :                         return ret;
    1793                 :            :         }
    1794                 :            : 
    1795         [ +  - ]:         42 :         if (restore_flags & RTE_ETH_RESTORE_ALLMULTI) {
    1796                 :         42 :                 ret = eth_dev_allmulticast_restore(dev, port_id);
    1797         [ -  + ]:         42 :                 if (ret != 0)
    1798                 :          0 :                         return ret;
    1799                 :            :         }
    1800                 :            : 
    1801                 :            :         return 0;
    1802                 :            : }
    1803                 :            : 
    1804                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_start)
    1805                 :            : int
    1806                 :         42 : rte_eth_dev_start(uint16_t port_id)
    1807                 :            : {
    1808                 :            :         struct rte_eth_dev *dev;
    1809                 :            :         struct rte_eth_dev_info dev_info;
    1810                 :            :         uint64_t restore_flags;
    1811                 :            :         int diag;
    1812                 :            :         int ret, ret_stop;
    1813                 :            : 
    1814         [ -  + ]:         42 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1815                 :         42 :         dev = &rte_eth_devices[port_id];
    1816                 :            : 
    1817         [ +  - ]:         42 :         if (dev->dev_ops->dev_start == NULL)
    1818                 :            :                 return -ENOTSUP;
    1819                 :            : 
    1820         [ -  + ]:         42 :         if (dev->data->dev_configured == 0) {
    1821                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
    1822                 :            :                         "Device with port_id=%"PRIu16" is not configured.",
    1823                 :            :                         port_id);
    1824                 :          0 :                 return -EINVAL;
    1825                 :            :         }
    1826                 :            : 
    1827         [ -  + ]:         42 :         if (dev->data->dev_started != 0) {
    1828                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
    1829                 :            :                         "Device with port_id=%"PRIu16" already started",
    1830                 :            :                         port_id);
    1831                 :          0 :                 return 0;
    1832                 :            :         }
    1833                 :            : 
    1834                 :         42 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    1835         [ +  - ]:         42 :         if (ret != 0)
    1836                 :            :                 return ret;
    1837                 :            : 
    1838                 :         42 :         restore_flags = rte_eth_get_restore_flags(dev, RTE_ETH_START);
    1839                 :            : 
    1840                 :            :         /* Lets restore MAC now if device does not support live change */
    1841         [ -  + ]:         42 :         if ((*dev_info.dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR) &&
    1842         [ #  # ]:          0 :             (restore_flags & RTE_ETH_RESTORE_MAC_ADDR))
    1843                 :          0 :                 eth_dev_mac_restore(dev, &dev_info);
    1844                 :            : 
    1845                 :         42 :         diag = dev->dev_ops->dev_start(dev);
    1846         [ +  - ]:         42 :         if (diag == 0)
    1847                 :         42 :                 dev->data->dev_started = 1;
    1848                 :            :         else
    1849                 :          0 :                 return eth_err(port_id, diag);
    1850                 :            : 
    1851                 :         42 :         ret = eth_dev_config_restore(dev, &dev_info, restore_flags, port_id);
    1852         [ -  + ]:         42 :         if (ret != 0) {
    1853                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1854                 :            :                         "Error during restoring configuration for device (port %u): %s",
    1855                 :            :                         port_id, rte_strerror(-ret));
    1856                 :          0 :                 ret_stop = rte_eth_dev_stop(port_id);
    1857         [ #  # ]:          0 :                 if (ret_stop != 0) {
    1858                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    1859                 :            :                                 "Failed to stop device (port %u): %s",
    1860                 :            :                                 port_id, rte_strerror(-ret_stop));
    1861                 :            :                 }
    1862                 :            : 
    1863                 :          0 :                 return ret;
    1864                 :            :         }
    1865                 :            : 
    1866         [ +  + ]:         42 :         if (dev->data->dev_conf.intr_conf.lsc == 0) {
    1867         [ +  - ]:         40 :                 if (dev->dev_ops->link_update == NULL)
    1868                 :            :                         return -ENOTSUP;
    1869                 :         40 :                 dev->dev_ops->link_update(dev, 0);
    1870                 :            :         }
    1871                 :            : 
    1872                 :            :         /* expose selection of PMD fast-path functions */
    1873                 :         42 :         eth_dev_fp_ops_setup(rte_eth_fp_ops + port_id, dev);
    1874                 :            : 
    1875                 :         42 :         rte_ethdev_trace_start(port_id);
    1876                 :         42 :         return 0;
    1877                 :            : }
    1878                 :            : 
    1879                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_stop)
    1880                 :            : int
    1881                 :         42 : rte_eth_dev_stop(uint16_t port_id)
    1882                 :            : {
    1883                 :            :         struct rte_eth_dev *dev;
    1884                 :            :         int ret;
    1885                 :            : 
    1886         [ -  + ]:         42 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1887                 :         42 :         dev = &rte_eth_devices[port_id];
    1888                 :            : 
    1889         [ +  - ]:         42 :         if (dev->dev_ops->dev_stop == NULL)
    1890                 :            :                 return -ENOTSUP;
    1891                 :            : 
    1892         [ -  + ]:         42 :         if (dev->data->dev_started == 0) {
    1893                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
    1894                 :            :                         "Device with port_id=%"PRIu16" already stopped",
    1895                 :            :                         port_id);
    1896                 :          0 :                 return 0;
    1897                 :            :         }
    1898                 :            : 
    1899                 :            :         /* point fast-path functions to dummy ones */
    1900                 :         42 :         eth_dev_fp_ops_reset(rte_eth_fp_ops + port_id);
    1901                 :            : 
    1902                 :         42 :         ret = dev->dev_ops->dev_stop(dev);
    1903         [ +  - ]:         42 :         if (ret == 0)
    1904                 :         42 :                 dev->data->dev_started = 0;
    1905                 :         42 :         rte_ethdev_trace_stop(port_id, ret);
    1906                 :            : 
    1907                 :         42 :         return ret;
    1908                 :            : }
    1909                 :            : 
    1910                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_link_up)
    1911                 :            : int
    1912                 :          1 : rte_eth_dev_set_link_up(uint16_t port_id)
    1913                 :            : {
    1914                 :            :         struct rte_eth_dev *dev;
    1915                 :            :         int ret;
    1916                 :            : 
    1917         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1918                 :          1 :         dev = &rte_eth_devices[port_id];
    1919                 :            : 
    1920         [ +  - ]:          1 :         if (dev->dev_ops->dev_set_link_up == NULL)
    1921                 :            :                 return -ENOTSUP;
    1922                 :          1 :         ret = eth_err(port_id, dev->dev_ops->dev_set_link_up(dev));
    1923                 :            : 
    1924                 :          1 :         rte_ethdev_trace_set_link_up(port_id, ret);
    1925                 :            : 
    1926                 :          1 :         return ret;
    1927                 :            : }
    1928                 :            : 
    1929                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_link_down)
    1930                 :            : int
    1931                 :          1 : rte_eth_dev_set_link_down(uint16_t port_id)
    1932                 :            : {
    1933                 :            :         struct rte_eth_dev *dev;
    1934                 :            :         int ret;
    1935                 :            : 
    1936         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1937                 :          1 :         dev = &rte_eth_devices[port_id];
    1938                 :            : 
    1939         [ +  - ]:          1 :         if (dev->dev_ops->dev_set_link_down == NULL)
    1940                 :            :                 return -ENOTSUP;
    1941                 :          1 :         ret = eth_err(port_id, dev->dev_ops->dev_set_link_down(dev));
    1942                 :            : 
    1943                 :          1 :         rte_ethdev_trace_set_link_down(port_id, ret);
    1944                 :            : 
    1945                 :          1 :         return ret;
    1946                 :            : }
    1947                 :            : 
    1948                 :            : RTE_EXPORT_SYMBOL(rte_eth_speed_lanes_get)
    1949                 :            : int
    1950                 :          0 : rte_eth_speed_lanes_get(uint16_t port_id, uint32_t *lane)
    1951                 :            : {
    1952                 :            :         struct rte_eth_dev *dev;
    1953                 :            : 
    1954         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1955                 :          0 :         dev = &rte_eth_devices[port_id];
    1956                 :            : 
    1957         [ #  # ]:          0 :         if (dev->dev_ops->speed_lanes_get == NULL)
    1958                 :            :                 return -ENOTSUP;
    1959                 :          0 :         return eth_err(port_id, dev->dev_ops->speed_lanes_get(dev, lane));
    1960                 :            : }
    1961                 :            : 
    1962                 :            : RTE_EXPORT_SYMBOL(rte_eth_speed_lanes_get_capability)
    1963                 :            : int
    1964                 :          0 : rte_eth_speed_lanes_get_capability(uint16_t port_id,
    1965                 :            :                                    struct rte_eth_speed_lanes_capa *speed_lanes_capa,
    1966                 :            :                                    unsigned int num)
    1967                 :            : {
    1968                 :            :         struct rte_eth_dev *dev;
    1969                 :            :         int ret;
    1970                 :            : 
    1971         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1972                 :          0 :         dev = &rte_eth_devices[port_id];
    1973                 :            : 
    1974         [ #  # ]:          0 :         if (dev->dev_ops->speed_lanes_get_capa == NULL)
    1975                 :            :                 return -ENOTSUP;
    1976                 :            : 
    1977         [ #  # ]:          0 :         if (speed_lanes_capa == NULL && num > 0) {
    1978                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    1979                 :            :                                     "Cannot get ethdev port %u speed lanes capability to NULL when array size is non zero",
    1980                 :            :                                     port_id);
    1981                 :          0 :                 return -EINVAL;
    1982                 :            :         }
    1983                 :            : 
    1984                 :          0 :         ret = dev->dev_ops->speed_lanes_get_capa(dev, speed_lanes_capa, num);
    1985                 :            : 
    1986                 :          0 :         return ret;
    1987                 :            : }
    1988                 :            : 
    1989                 :            : RTE_EXPORT_SYMBOL(rte_eth_speed_lanes_set)
    1990                 :            : int
    1991                 :          0 : rte_eth_speed_lanes_set(uint16_t port_id, uint32_t speed_lanes_capa)
    1992                 :            : {
    1993                 :            :         struct rte_eth_dev *dev;
    1994                 :            : 
    1995         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    1996                 :          0 :         dev = &rte_eth_devices[port_id];
    1997                 :            : 
    1998         [ #  # ]:          0 :         if (dev->dev_ops->speed_lanes_set == NULL)
    1999                 :            :                 return -ENOTSUP;
    2000                 :          0 :         return eth_err(port_id, dev->dev_ops->speed_lanes_set(dev, speed_lanes_capa));
    2001                 :            : }
    2002                 :            : 
    2003                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_close)
    2004                 :            : int
    2005                 :          9 : rte_eth_dev_close(uint16_t port_id)
    2006                 :            : {
    2007                 :            :         struct rte_eth_dev *dev;
    2008                 :            :         int firsterr, binerr;
    2009                 :            :         int *lasterr = &firsterr;
    2010                 :            : 
    2011         [ -  + ]:          9 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    2012                 :          9 :         dev = &rte_eth_devices[port_id];
    2013                 :            : 
    2014                 :            :         /*
    2015                 :            :          * Secondary process needs to close device to release process private
    2016                 :            :          * resources. But secondary process should not be obliged to wait
    2017                 :            :          * for device stop before closing ethdev.
    2018                 :            :          */
    2019         [ +  - ]:          9 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
    2020         [ -  + ]:          9 :                         dev->data->dev_started) {
    2021                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot close started device (port %u)",
    2022                 :            :                                port_id);
    2023                 :          0 :                 return -EINVAL;
    2024                 :            :         }
    2025                 :            : 
    2026         [ +  - ]:          9 :         if (dev->dev_ops->dev_close == NULL)
    2027                 :            :                 return -ENOTSUP;
    2028                 :          9 :         *lasterr = dev->dev_ops->dev_close(dev);
    2029         [ -  + ]:          9 :         if (*lasterr != 0)
    2030                 :            :                 lasterr = &binerr;
    2031                 :            : 
    2032                 :          9 :         rte_ethdev_trace_close(port_id);
    2033                 :          9 :         *lasterr = rte_eth_dev_release_port(dev);
    2034                 :            : 
    2035                 :          9 :         return firsterr;
    2036                 :            : }
    2037                 :            : 
    2038                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_reset)
    2039                 :            : int
    2040                 :          0 : rte_eth_dev_reset(uint16_t port_id)
    2041                 :            : {
    2042                 :            :         struct rte_eth_dev *dev;
    2043                 :            :         int ret;
    2044                 :            : 
    2045         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    2046                 :          0 :         dev = &rte_eth_devices[port_id];
    2047                 :            : 
    2048         [ #  # ]:          0 :         if (dev->dev_ops->dev_reset == NULL)
    2049                 :            :                 return -ENOTSUP;
    2050                 :            : 
    2051                 :          0 :         ret = rte_eth_dev_stop(port_id);
    2052         [ #  # ]:          0 :         if (ret != 0) {
    2053                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2054                 :            :                         "Failed to stop device (port %u) before reset: %s - ignore",
    2055                 :            :                         port_id, rte_strerror(-ret));
    2056                 :            :         }
    2057                 :          0 :         ret = eth_err(port_id, dev->dev_ops->dev_reset(dev));
    2058                 :            : 
    2059                 :          0 :         rte_ethdev_trace_reset(port_id, ret);
    2060                 :            : 
    2061                 :          0 :         return ret;
    2062                 :            : }
    2063                 :            : 
    2064                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_is_removed)
    2065                 :            : int
    2066                 :          2 : rte_eth_dev_is_removed(uint16_t port_id)
    2067                 :            : {
    2068                 :            :         struct rte_eth_dev *dev;
    2069                 :            :         int ret;
    2070                 :            : 
    2071         [ -  + ]:          2 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
    2072                 :          2 :         dev = &rte_eth_devices[port_id];
    2073                 :            : 
    2074         [ +  - ]:          2 :         if (dev->state == RTE_ETH_DEV_REMOVED)
    2075                 :            :                 return 1;
    2076                 :            : 
    2077         [ -  + ]:          2 :         if (dev->dev_ops->is_removed == NULL)
    2078                 :            :                 return 0;
    2079                 :            : 
    2080                 :          0 :         ret = dev->dev_ops->is_removed(dev);
    2081         [ #  # ]:          0 :         if (ret != 0)
    2082                 :            :                 /* Device is physically removed. */
    2083                 :          0 :                 dev->state = RTE_ETH_DEV_REMOVED;
    2084                 :            : 
    2085                 :          0 :         rte_ethdev_trace_is_removed(port_id, ret);
    2086                 :            : 
    2087                 :          0 :         return ret;
    2088                 :            : }
    2089                 :            : 
    2090                 :            : static int
    2091                 :         79 : rte_eth_check_rx_mempool(struct rte_mempool *mp, uint16_t offset,
    2092                 :            :                          uint16_t min_length)
    2093                 :            : {
    2094                 :            :         uint16_t data_room_size;
    2095                 :            : 
    2096                 :            :         /*
    2097                 :            :          * Check the size of the mbuf data buffer, this value
    2098                 :            :          * must be provided in the private data of the memory pool.
    2099                 :            :          * First check that the memory pool(s) has a valid private data.
    2100                 :            :          */
    2101         [ -  + ]:         79 :         if (mp->private_data_size <
    2102                 :            :                         sizeof(struct rte_pktmbuf_pool_private)) {
    2103                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "%s private_data_size %u < %u",
    2104                 :            :                         mp->name, mp->private_data_size,
    2105                 :            :                         (unsigned int)
    2106                 :            :                         sizeof(struct rte_pktmbuf_pool_private));
    2107                 :          0 :                 return -ENOSPC;
    2108                 :            :         }
    2109                 :            :         data_room_size = rte_pktmbuf_data_room_size(mp);
    2110         [ -  + ]:         79 :         if (data_room_size < offset + min_length) {
    2111                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2112                 :            :                                "%s mbuf_data_room_size %u < %u (%u + %u)",
    2113                 :            :                                mp->name, data_room_size,
    2114                 :            :                                offset + min_length, offset, min_length);
    2115                 :          0 :                 return -EINVAL;
    2116                 :            :         }
    2117                 :            :         return 0;
    2118                 :            : }
    2119                 :            : 
    2120                 :            : static int
    2121                 :          0 : eth_dev_buffer_split_get_supported_hdrs_helper(uint16_t port_id, uint32_t **ptypes)
    2122                 :            : {
    2123                 :            :         int cnt;
    2124                 :            : 
    2125                 :          0 :         cnt = rte_eth_buffer_split_get_supported_hdr_ptypes(port_id, NULL, 0);
    2126         [ #  # ]:          0 :         if (cnt <= 0)
    2127                 :            :                 return cnt;
    2128                 :            : 
    2129                 :          0 :         *ptypes = malloc(sizeof(uint32_t) * cnt);
    2130         [ #  # ]:          0 :         if (*ptypes == NULL)
    2131                 :            :                 return -ENOMEM;
    2132                 :            : 
    2133                 :          0 :         cnt = rte_eth_buffer_split_get_supported_hdr_ptypes(port_id, *ptypes, cnt);
    2134         [ #  # ]:          0 :         if (cnt <= 0) {
    2135                 :          0 :                 free(*ptypes);
    2136                 :          0 :                 *ptypes = NULL;
    2137                 :            :         }
    2138                 :            :         return cnt;
    2139                 :            : }
    2140                 :            : 
    2141                 :            : static int
    2142                 :          0 : rte_eth_rx_queue_check_split(uint16_t port_id,
    2143                 :            :                         const struct rte_eth_rxseg_split *rx_seg,
    2144                 :            :                         uint16_t n_seg, uint32_t *mbp_buf_size,
    2145                 :            :                         const struct rte_eth_dev_info *dev_info)
    2146                 :            : {
    2147                 :            :         const struct rte_eth_rxseg_capa *seg_capa = &dev_info->rx_seg_capa;
    2148                 :            :         struct rte_mempool *mp_first = NULL;
    2149                 :            :         uint32_t offset_mask;
    2150                 :            :         uint16_t seg_idx;
    2151                 :            :         int ret = 0;
    2152                 :            :         int ptype_cnt;
    2153                 :            :         uint32_t *ptypes;
    2154                 :            :         uint32_t prev_proto_hdrs = RTE_PTYPE_UNKNOWN;
    2155                 :            :         int i;
    2156                 :            : 
    2157         [ #  # ]:          0 :         if (n_seg > seg_capa->max_nseg) {
    2158                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2159                 :            :                                "Requested Rx segments %u exceed supported %u",
    2160                 :            :                                n_seg, seg_capa->max_nseg);
    2161                 :          0 :                 return -EINVAL;
    2162                 :            :         }
    2163                 :            :         /*
    2164                 :            :          * Check the sizes and offsets against buffer sizes
    2165                 :            :          * for each segment specified in extended configuration.
    2166                 :            :          */
    2167                 :          0 :         offset_mask = RTE_BIT32(seg_capa->offset_align_log2) - 1;
    2168                 :            : 
    2169                 :          0 :         ptypes = NULL;
    2170                 :          0 :         ptype_cnt = eth_dev_buffer_split_get_supported_hdrs_helper(port_id, &ptypes);
    2171                 :            : 
    2172         [ #  # ]:          0 :         for (seg_idx = 0; seg_idx < n_seg; seg_idx++) {
    2173                 :          0 :                 struct rte_mempool *mpl = rx_seg[seg_idx].mp;
    2174                 :          0 :                 uint32_t length = rx_seg[seg_idx].length;
    2175                 :          0 :                 uint32_t offset = rx_seg[seg_idx].offset;
    2176                 :          0 :                 uint32_t proto_hdr = rx_seg[seg_idx].proto_hdr;
    2177                 :            : 
    2178         [ #  # ]:          0 :                 if (mpl == NULL) { /* discarded segment */
    2179         [ #  # ]:          0 :                         if (seg_capa->selective_rx == 0) { /* not supported */
    2180                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR, "null mempool pointer");
    2181                 :            :                                 ret = -EINVAL;
    2182                 :          0 :                                 goto out;
    2183                 :            :                         }
    2184                 :          0 :                         continue; /* next checks are not relevant if no mempool */
    2185                 :            :                 }
    2186         [ #  # ]:          0 :                 if (mp_first == NULL)
    2187                 :            :                         mp_first = mpl;
    2188   [ #  #  #  # ]:          0 :                 if (mp_first != mpl && seg_capa->multi_pools == 0) {
    2189                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Receiving to multiple pools is not supported");
    2190                 :            :                         ret = -ENOTSUP;
    2191                 :          0 :                         goto out;
    2192                 :            :                 }
    2193         [ #  # ]:          0 :                 if (offset != 0) {
    2194         [ #  # ]:          0 :                         if (seg_capa->offset_allowed == 0) {
    2195                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR, "Rx segmentation with offset is not supported");
    2196                 :            :                                 ret = -ENOTSUP;
    2197                 :          0 :                                 goto out;
    2198                 :            :                         }
    2199         [ #  # ]:          0 :                         if (offset & offset_mask) {
    2200                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR, "Rx segmentation invalid offset alignment %u, %u",
    2201                 :            :                                                offset,
    2202                 :            :                                                seg_capa->offset_align_log2);
    2203                 :            :                                 ret = -EINVAL;
    2204                 :          0 :                                 goto out;
    2205                 :            :                         }
    2206                 :            :                 }
    2207                 :            : 
    2208   [ #  #  #  # ]:          0 :                 offset += seg_idx != 0 ? 0 : RTE_PKTMBUF_HEADROOM;
    2209                 :          0 :                 *mbp_buf_size = rte_pktmbuf_data_room_size(mpl);
    2210         [ #  # ]:          0 :                 if (proto_hdr != 0) {
    2211                 :            :                         /* Split based on protocol headers. */
    2212         [ #  # ]:          0 :                         if (length != 0) {
    2213                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR,
    2214                 :            :                                         "Do not set length split and protocol split within a segment"
    2215                 :            :                                         );
    2216                 :            :                                 ret = -EINVAL;
    2217                 :          0 :                                 goto out;
    2218                 :            :                         }
    2219         [ #  # ]:          0 :                         if ((proto_hdr & prev_proto_hdrs) != 0) {
    2220                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR,
    2221                 :            :                                         "Repeat with previous protocol headers or proto-split after length-based split"
    2222                 :            :                                         );
    2223                 :            :                                 ret = -EINVAL;
    2224                 :          0 :                                 goto out;
    2225                 :            :                         }
    2226         [ #  # ]:          0 :                         if (ptype_cnt <= 0) {
    2227                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR,
    2228                 :            :                                         "Port %u failed to get supported buffer split header protocols",
    2229                 :            :                                         port_id);
    2230                 :            :                                 ret = -ENOTSUP;
    2231                 :          0 :                                 goto out;
    2232                 :            :                         }
    2233         [ #  # ]:          0 :                         for (i = 0; i < ptype_cnt; i++) {
    2234         [ #  # ]:          0 :                                 if ((prev_proto_hdrs | proto_hdr) == ptypes[i])
    2235                 :            :                                         break;
    2236                 :            :                         }
    2237         [ #  # ]:          0 :                         if (i == ptype_cnt) {
    2238                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR,
    2239                 :            :                                         "Requested Rx split header protocols 0x%x is not supported.",
    2240                 :            :                                         proto_hdr);
    2241                 :            :                                 ret = -EINVAL;
    2242                 :          0 :                                 goto out;
    2243                 :            :                         }
    2244                 :          0 :                         prev_proto_hdrs |= proto_hdr;
    2245                 :            :                 } else {
    2246                 :            :                         /* Split at fixed length. */
    2247         [ #  # ]:          0 :                         length = length != 0 ? length : *mbp_buf_size;
    2248                 :            :                         prev_proto_hdrs = RTE_PTYPE_ALL_MASK;
    2249                 :            :                 }
    2250                 :            : 
    2251                 :          0 :                 ret = rte_eth_check_rx_mempool(mpl, offset, length);
    2252         [ #  # ]:          0 :                 if (ret != 0)
    2253                 :          0 :                         goto out;
    2254                 :            :         }
    2255         [ #  # ]:          0 :         if (mp_first == NULL) {
    2256                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "At least one Rx segment must have a mempool");
    2257                 :            :                 ret = -EINVAL;
    2258                 :          0 :                 goto out;
    2259                 :            :         }
    2260                 :          0 : out:
    2261                 :          0 :         free(ptypes);
    2262                 :          0 :         return ret;
    2263                 :            : }
    2264                 :            : 
    2265                 :            : static int
    2266                 :          0 : rte_eth_rx_queue_check_mempools(struct rte_mempool **rx_mempools,
    2267                 :            :                                uint16_t n_mempools, uint32_t *min_buf_size,
    2268                 :            :                                const struct rte_eth_dev_info *dev_info)
    2269                 :            : {
    2270                 :            :         uint16_t pool_idx;
    2271                 :            :         int ret;
    2272                 :            : 
    2273         [ #  # ]:          0 :         if (n_mempools > dev_info->max_rx_mempools) {
    2274                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2275                 :            :                                "Too many Rx mempools %u vs maximum %u",
    2276                 :            :                                n_mempools, dev_info->max_rx_mempools);
    2277                 :          0 :                 return -EINVAL;
    2278                 :            :         }
    2279                 :            : 
    2280         [ #  # ]:          0 :         for (pool_idx = 0; pool_idx < n_mempools; pool_idx++) {
    2281                 :          0 :                 struct rte_mempool *mp = rx_mempools[pool_idx];
    2282                 :            : 
    2283         [ #  # ]:          0 :                 if (mp == NULL) {
    2284                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "null Rx mempool pointer");
    2285                 :          0 :                         return -EINVAL;
    2286                 :            :                 }
    2287                 :            : 
    2288                 :          0 :                 ret = rte_eth_check_rx_mempool(mp, RTE_PKTMBUF_HEADROOM,
    2289                 :          0 :                                                dev_info->min_rx_bufsize);
    2290         [ #  # ]:          0 :                 if (ret != 0)
    2291                 :          0 :                         return ret;
    2292                 :            : 
    2293         [ #  # ]:          0 :                 *min_buf_size = RTE_MIN(*min_buf_size,
    2294                 :            :                                         rte_pktmbuf_data_room_size(mp));
    2295                 :            :         }
    2296                 :            : 
    2297                 :            :         return 0;
    2298                 :            : }
    2299                 :            : 
    2300                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_queue_setup)
    2301                 :            : int
    2302                 :         81 : rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
    2303                 :            :                        uint16_t nb_rx_desc, unsigned int socket_id,
    2304                 :            :                        const struct rte_eth_rxconf *rx_conf,
    2305                 :            :                        struct rte_mempool *mp)
    2306                 :            : {
    2307                 :            :         int ret;
    2308                 :            :         uint64_t rx_offloads;
    2309                 :         81 :         uint32_t mbp_buf_size = UINT32_MAX;
    2310                 :            :         struct rte_eth_dev *dev;
    2311                 :            :         struct rte_eth_dev_info dev_info;
    2312                 :            :         struct rte_eth_rxconf local_conf;
    2313                 :            :         uint32_t buf_data_size;
    2314                 :            : 
    2315         [ -  + ]:         81 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    2316                 :         81 :         dev = &rte_eth_devices[port_id];
    2317                 :            : 
    2318         [ +  + ]:         81 :         if (rx_queue_id >= dev->data->nb_rx_queues) {
    2319                 :          1 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", rx_queue_id);
    2320                 :          1 :                 return -EINVAL;
    2321                 :            :         }
    2322                 :            : 
    2323         [ +  - ]:         80 :         if (dev->dev_ops->rx_queue_setup == NULL)
    2324                 :            :                 return -ENOTSUP;
    2325                 :            : 
    2326         [ +  + ]:         80 :         if (rx_conf != NULL &&
    2327         [ +  - ]:          4 :            (rx_conf->reserved_64s[0] != 0 ||
    2328         [ +  - ]:          4 :             rx_conf->reserved_64s[1] != 0 ||
    2329         [ +  - ]:          4 :             rx_conf->reserved_ptrs[0] != NULL ||
    2330         [ -  + ]:          4 :             rx_conf->reserved_ptrs[1] != NULL)) {
    2331                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rx conf reserved fields not zero");
    2332                 :          0 :                 return -EINVAL;
    2333                 :            :         }
    2334                 :            : 
    2335                 :         80 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    2336         [ +  - ]:         80 :         if (ret != 0)
    2337                 :            :                 return ret;
    2338                 :            : 
    2339                 :         80 :         rx_offloads = dev->data->dev_conf.rxmode.offloads;
    2340         [ +  + ]:         80 :         if (rx_conf != NULL)
    2341                 :          4 :                 rx_offloads |= rx_conf->offloads;
    2342                 :            : 
    2343                 :            :         /* Deferred start requires that device supports queue start */
    2344   [ +  +  -  + ]:         80 :         if (rx_conf != NULL && rx_conf->rx_deferred_start &&
    2345         [ #  # ]:          0 :             dev->dev_ops->rx_queue_start == NULL) {
    2346                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2347                 :            :                             "Deferred start requested, but driver does not support Rx queue start");
    2348                 :          0 :                 return -ENOTSUP;
    2349                 :            :         }
    2350                 :            : 
    2351                 :            :         /* Ensure that we have one and only one source of Rx buffers */
    2352                 :        240 :         if ((mp != NULL) +
    2353   [ +  +  +  -  :        160 :             (rx_conf != NULL && rx_conf->rx_nseg > 0) +
                   +  + ]
    2354   [ +  +  +  - ]:         80 :             (rx_conf != NULL && rx_conf->rx_nmempool > 0) != 1) {
    2355                 :          1 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2356                 :            :                                "Ambiguous Rx mempools configuration");
    2357                 :          1 :                 return -EINVAL;
    2358                 :            :         }
    2359                 :            : 
    2360         [ +  - ]:         79 :         if (mp != NULL) {
    2361                 :            :                 /* Single pool configuration check. */
    2362                 :         79 :                 ret = rte_eth_check_rx_mempool(mp, RTE_PKTMBUF_HEADROOM,
    2363                 :         79 :                                                dev_info.min_rx_bufsize);
    2364         [ +  - ]:         79 :                 if (ret != 0)
    2365                 :            :                         return ret;
    2366                 :            : 
    2367                 :         79 :                 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
    2368                 :         79 :                 buf_data_size = mbp_buf_size - RTE_PKTMBUF_HEADROOM;
    2369         [ -  + ]:         79 :                 if (buf_data_size > dev_info.max_rx_bufsize)
    2370                 :          0 :                         RTE_ETHDEV_LOG_LINE(DEBUG,
    2371                 :            :                                 "For port_id=%u, the mbuf data buffer size (%u) is bigger than "
    2372                 :            :                                 "max buffer size (%u) device can utilize, so mbuf size can be reduced.",
    2373                 :            :                                 port_id, buf_data_size, dev_info.max_rx_bufsize);
    2374   [ #  #  #  # ]:          0 :         } else if (rx_conf != NULL && rx_conf->rx_nseg > 0) {
    2375                 :            :                 const struct rte_eth_rxseg_split *rx_seg;
    2376                 :            :                 uint16_t n_seg;
    2377                 :            : 
    2378                 :            :                 /* Extended multi-segment configuration check. */
    2379         [ #  # ]:          0 :                 if (rx_conf->rx_seg == NULL) {
    2380                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    2381                 :            :                                        "Memory pool is null and no multi-segment configuration provided");
    2382                 :          0 :                         return -EINVAL;
    2383                 :            :                 }
    2384                 :            : 
    2385                 :            :                 rx_seg = (const struct rte_eth_rxseg_split *)rx_conf->rx_seg;
    2386                 :            :                 n_seg = rx_conf->rx_nseg;
    2387                 :            : 
    2388         [ #  # ]:          0 :                 if (rx_offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
    2389                 :          0 :                         ret = rte_eth_rx_queue_check_split(port_id, rx_seg, n_seg,
    2390                 :            :                                                            &mbp_buf_size,
    2391                 :            :                                                            &dev_info);
    2392         [ #  # ]:          0 :                         if (ret != 0)
    2393                 :            :                                 return ret;
    2394                 :            :                 } else {
    2395                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "No Rx segmentation offload configured");
    2396                 :          0 :                         return -EINVAL;
    2397                 :            :                 }
    2398   [ #  #  #  # ]:          0 :         } else if (rx_conf != NULL && rx_conf->rx_nmempool > 0) {
    2399                 :            :                 /* Extended multi-pool configuration check. */
    2400         [ #  # ]:          0 :                 if (rx_conf->rx_mempools == NULL) {
    2401                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Memory pools array is null");
    2402                 :          0 :                         return -EINVAL;
    2403                 :            :                 }
    2404                 :            : 
    2405                 :          0 :                 ret = rte_eth_rx_queue_check_mempools(rx_conf->rx_mempools,
    2406                 :            :                                                      rx_conf->rx_nmempool,
    2407                 :            :                                                      &mbp_buf_size,
    2408                 :            :                                                      &dev_info);
    2409         [ #  # ]:          0 :                 if (ret != 0)
    2410                 :            :                         return ret;
    2411                 :            :         } else {
    2412                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Missing Rx mempool configuration");
    2413                 :          0 :                 return -EINVAL;
    2414                 :            :         }
    2415                 :            : 
    2416                 :            :         /* Use default specified by driver, if nb_rx_desc is zero */
    2417         [ -  + ]:         79 :         if (nb_rx_desc == 0) {
    2418                 :          0 :                 nb_rx_desc = dev_info.default_rxportconf.ring_size;
    2419                 :            :                 /* If driver default is also zero, fall back on EAL default */
    2420         [ #  # ]:          0 :                 if (nb_rx_desc == 0)
    2421                 :            :                         nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
    2422                 :            :         }
    2423                 :            : 
    2424         [ +  - ]:         79 :         if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
    2425         [ +  - ]:         79 :                         nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
    2426         [ -  + ]:         79 :                         nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
    2427                 :            : 
    2428                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2429                 :            :                         "Invalid value for nb_rx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu",
    2430                 :            :                         nb_rx_desc, dev_info.rx_desc_lim.nb_max,
    2431                 :            :                         dev_info.rx_desc_lim.nb_min,
    2432                 :            :                         dev_info.rx_desc_lim.nb_align);
    2433                 :          0 :                 return -EINVAL;
    2434                 :            :         }
    2435                 :            : 
    2436         [ -  + ]:         79 :         if (dev->data->dev_started &&
    2437         [ #  # ]:          0 :                 !(dev_info.dev_capa &
    2438                 :            :                         RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP))
    2439                 :            :                 return -EBUSY;
    2440                 :            : 
    2441         [ -  + ]:         79 :         if (dev->data->dev_started &&
    2442         [ #  # ]:          0 :                 (dev->data->rx_queue_state[rx_queue_id] !=
    2443                 :            :                         RTE_ETH_QUEUE_STATE_STOPPED))
    2444                 :            :                 return -EBUSY;
    2445                 :            : 
    2446                 :         79 :         eth_dev_rxq_release(dev, rx_queue_id);
    2447                 :            : 
    2448         [ +  + ]:         79 :         if (rx_conf == NULL)
    2449                 :            :                 rx_conf = &dev_info.default_rxconf;
    2450                 :            : 
    2451                 :         79 :         local_conf = *rx_conf;
    2452                 :            : 
    2453                 :            :         /*
    2454                 :            :          * If an offloading has already been enabled in
    2455                 :            :          * rte_eth_dev_configure(), it has been enabled on all queues,
    2456                 :            :          * so there is no need to enable it in this queue again.
    2457                 :            :          * The local_conf.offloads input to underlying PMD only carries
    2458                 :            :          * those offloadings which are only enabled on this queue and
    2459                 :            :          * not enabled on all queues.
    2460                 :            :          */
    2461                 :         79 :         local_conf.offloads &= ~dev->data->dev_conf.rxmode.offloads;
    2462                 :            : 
    2463                 :            :         /*
    2464                 :            :          * New added offloadings for this queue are those not enabled in
    2465                 :            :          * rte_eth_dev_configure() and they must be per-queue type.
    2466                 :            :          * A pure per-port offloading can't be enabled on a queue while
    2467                 :            :          * disabled on another queue. A pure per-port offloading can't
    2468                 :            :          * be enabled for any queue as new added one if it hasn't been
    2469                 :            :          * enabled in rte_eth_dev_configure().
    2470                 :            :          */
    2471         [ -  + ]:         79 :         if ((local_conf.offloads & dev_info.rx_queue_offload_capa) !=
    2472                 :            :              local_conf.offloads) {
    2473                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2474                 :            :                         "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
    2475                 :            :                         "within per-queue offload capabilities 0x%"PRIx64" in %s()",
    2476                 :            :                         port_id, rx_queue_id, local_conf.offloads,
    2477                 :            :                         dev_info.rx_queue_offload_capa,
    2478                 :            :                         __func__);
    2479                 :          0 :                 return -EINVAL;
    2480                 :            :         }
    2481                 :            : 
    2482         [ -  + ]:         79 :         if (local_conf.share_group > 0 &&
    2483         [ #  # ]:          0 :             (dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) == 0) {
    2484                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2485                 :            :                         "Ethdev port_id=%d rx_queue_id=%d, enabled share_group=%hu while device doesn't support Rx queue share",
    2486                 :            :                         port_id, rx_queue_id, local_conf.share_group);
    2487                 :          0 :                 return -EINVAL;
    2488                 :            :         }
    2489                 :            : 
    2490                 :            :         /*
    2491                 :            :          * If LRO is enabled, check that the maximum aggregated packet
    2492                 :            :          * size is supported by the configured device.
    2493                 :            :          */
    2494                 :            :         /* Get the real Ethernet overhead length */
    2495         [ -  + ]:         79 :         if (local_conf.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) {
    2496                 :            :                 uint32_t overhead_len;
    2497                 :            :                 uint32_t max_rx_pktlen;
    2498                 :            : 
    2499                 :          0 :                 overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
    2500         [ #  # ]:          0 :                                 dev_info.max_mtu);
    2501                 :          0 :                 max_rx_pktlen = dev->data->mtu + overhead_len;
    2502         [ #  # ]:          0 :                 if (dev->data->dev_conf.rxmode.max_lro_pkt_size == 0)
    2503                 :          0 :                         dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen;
    2504                 :          0 :                 ret = eth_dev_check_lro_pkt_size(port_id,
    2505                 :            :                                 dev->data->dev_conf.rxmode.max_lro_pkt_size,
    2506                 :            :                                 max_rx_pktlen,
    2507                 :            :                                 dev_info.max_lro_pkt_size);
    2508         [ #  # ]:          0 :                 if (ret != 0)
    2509                 :            :                         return ret;
    2510                 :            :         }
    2511                 :            : 
    2512                 :         79 :         ret = dev->dev_ops->rx_queue_setup(dev, rx_queue_id, nb_rx_desc,
    2513                 :            :                                            socket_id, &local_conf, mp);
    2514         [ +  + ]:         79 :         if (!ret) {
    2515         [ +  + ]:         78 :                 if (!dev->data->min_rx_buf_size ||
    2516         [ -  + ]:         37 :                     dev->data->min_rx_buf_size > mbp_buf_size)
    2517                 :         41 :                         dev->data->min_rx_buf_size = mbp_buf_size;
    2518                 :            :         }
    2519                 :            : 
    2520                 :         79 :         rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp,
    2521                 :            :                 rx_conf, ret);
    2522                 :         79 :         return eth_err(port_id, ret);
    2523                 :            : }
    2524                 :            : 
    2525                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_hairpin_queue_setup)
    2526                 :            : int
    2527                 :          0 : rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
    2528                 :            :                                uint16_t nb_rx_desc,
    2529                 :            :                                const struct rte_eth_hairpin_conf *conf)
    2530                 :            : {
    2531                 :            :         int ret;
    2532                 :            :         struct rte_eth_dev *dev;
    2533                 :            :         struct rte_eth_hairpin_cap cap;
    2534                 :            :         int i;
    2535                 :            :         int count;
    2536                 :            : 
    2537         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    2538                 :          0 :         dev = &rte_eth_devices[port_id];
    2539                 :            : 
    2540         [ #  # ]:          0 :         if (rx_queue_id >= dev->data->nb_rx_queues) {
    2541                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", rx_queue_id);
    2542                 :          0 :                 return -EINVAL;
    2543                 :            :         }
    2544                 :            : 
    2545         [ #  # ]:          0 :         if (conf == NULL) {
    2546                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2547                 :            :                         "Cannot setup ethdev port %u Rx hairpin queue from NULL config",
    2548                 :            :                         port_id);
    2549                 :          0 :                 return -EINVAL;
    2550                 :            :         }
    2551                 :            : 
    2552         [ #  # ]:          0 :         if (conf->reserved != 0) {
    2553                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2554                 :            :                                "Rx hairpin reserved field not zero");
    2555                 :          0 :                 return -EINVAL;
    2556                 :            :         }
    2557                 :            : 
    2558                 :          0 :         ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
    2559         [ #  # ]:          0 :         if (ret != 0)
    2560                 :            :                 return ret;
    2561         [ #  # ]:          0 :         if (dev->dev_ops->rx_hairpin_queue_setup == NULL)
    2562                 :            :                 return -ENOTSUP;
    2563                 :            :         /* if nb_rx_desc is zero use max number of desc from the driver. */
    2564         [ #  # ]:          0 :         if (nb_rx_desc == 0)
    2565                 :          0 :                 nb_rx_desc = cap.max_nb_desc;
    2566         [ #  # ]:          0 :         if (nb_rx_desc > cap.max_nb_desc) {
    2567                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2568                 :            :                         "Invalid value for nb_rx_desc(=%hu), should be: <= %hu",
    2569                 :            :                         nb_rx_desc, cap.max_nb_desc);
    2570                 :          0 :                 return -EINVAL;
    2571                 :            :         }
    2572         [ #  # ]:          0 :         if (conf->peer_count > cap.max_rx_2_tx) {
    2573                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2574                 :            :                         "Invalid value for number of peers for Rx queue(=%u), should be: <= %hu",
    2575                 :            :                         conf->peer_count, cap.max_rx_2_tx);
    2576                 :          0 :                 return -EINVAL;
    2577                 :            :         }
    2578   [ #  #  #  # ]:          0 :         if (conf->use_locked_device_memory && !cap.rx_cap.locked_device_memory) {
    2579                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2580                 :            :                         "Attempt to use locked device memory for Rx queue, which is not supported");
    2581                 :          0 :                 return -EINVAL;
    2582                 :            :         }
    2583   [ #  #  #  # ]:          0 :         if (conf->use_rte_memory && !cap.rx_cap.rte_memory) {
    2584                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2585                 :            :                         "Attempt to use DPDK memory for Rx queue, which is not supported");
    2586                 :          0 :                 return -EINVAL;
    2587                 :            :         }
    2588         [ #  # ]:          0 :         if (conf->use_locked_device_memory && conf->use_rte_memory) {
    2589                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2590                 :            :                         "Attempt to use mutually exclusive memory settings for Rx queue");
    2591                 :          0 :                 return -EINVAL;
    2592                 :            :         }
    2593                 :          0 :         if (conf->force_memory &&
    2594         [ #  # ]:          0 :             !conf->use_locked_device_memory &&
    2595                 :            :             !conf->use_rte_memory) {
    2596                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2597                 :            :                         "Attempt to force Rx queue memory settings, but none is set");
    2598                 :          0 :                 return -EINVAL;
    2599                 :            :         }
    2600         [ #  # ]:          0 :         if (conf->peer_count == 0) {
    2601                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2602                 :            :                         "Invalid value for number of peers for Rx queue(=%u), should be: > 0",
    2603                 :            :                         conf->peer_count);
    2604                 :          0 :                 return -EINVAL;
    2605                 :            :         }
    2606         [ #  # ]:          0 :         for (i = 0, count = 0; i < dev->data->nb_rx_queues &&
    2607         [ #  # ]:          0 :              cap.max_nb_queues != UINT16_MAX; i++) {
    2608   [ #  #  #  # ]:          0 :                 if (i == rx_queue_id || rte_eth_dev_is_rx_hairpin_queue(dev, i))
    2609                 :          0 :                         count++;
    2610                 :            :         }
    2611         [ #  # ]:          0 :         if (count > cap.max_nb_queues) {
    2612                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "To many Rx hairpin queues max is %d",
    2613                 :            :                 cap.max_nb_queues);
    2614                 :          0 :                 return -EINVAL;
    2615                 :            :         }
    2616         [ #  # ]:          0 :         if (dev->data->dev_started)
    2617                 :            :                 return -EBUSY;
    2618                 :          0 :         eth_dev_rxq_release(dev, rx_queue_id);
    2619                 :          0 :         ret = dev->dev_ops->rx_hairpin_queue_setup(dev, rx_queue_id, nb_rx_desc, conf);
    2620         [ #  # ]:          0 :         if (ret == 0)
    2621                 :          0 :                 dev->data->rx_queue_state[rx_queue_id] =
    2622                 :            :                         RTE_ETH_QUEUE_STATE_HAIRPIN;
    2623                 :          0 :         ret = eth_err(port_id, ret);
    2624                 :            : 
    2625                 :          0 :         rte_eth_trace_rx_hairpin_queue_setup(port_id, rx_queue_id, nb_rx_desc,
    2626                 :            :                                              conf, ret);
    2627                 :            : 
    2628                 :          0 :         return ret;
    2629                 :            : }
    2630                 :            : 
    2631                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_setup)
    2632                 :            : int
    2633                 :         80 : rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
    2634                 :            :                        uint16_t nb_tx_desc, unsigned int socket_id,
    2635                 :            :                        const struct rte_eth_txconf *tx_conf)
    2636                 :            : {
    2637                 :            :         struct rte_eth_dev *dev;
    2638                 :            :         struct rte_eth_dev_info dev_info;
    2639                 :            :         struct rte_eth_txconf local_conf;
    2640                 :            :         int ret;
    2641                 :            : 
    2642         [ -  + ]:         80 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    2643                 :         80 :         dev = &rte_eth_devices[port_id];
    2644                 :            : 
    2645         [ -  + ]:         80 :         if (tx_queue_id >= dev->data->nb_tx_queues) {
    2646                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
    2647                 :          0 :                 return -EINVAL;
    2648                 :            :         }
    2649                 :            : 
    2650         [ +  - ]:         80 :         if (dev->dev_ops->tx_queue_setup == NULL)
    2651                 :            :                 return -ENOTSUP;
    2652                 :            : 
    2653         [ +  + ]:         80 :         if (tx_conf != NULL &&
    2654         [ +  - ]:          4 :            (tx_conf->reserved_64s[0] != 0 ||
    2655         [ +  - ]:          4 :             tx_conf->reserved_64s[1] != 0 ||
    2656         [ +  - ]:          4 :             tx_conf->reserved_ptrs[0] != NULL ||
    2657         [ -  + ]:          4 :             tx_conf->reserved_ptrs[1] != NULL)) {
    2658                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Tx conf reserved fields not zero");
    2659                 :          0 :                 return -EINVAL;
    2660                 :            :         }
    2661                 :            : 
    2662                 :            :         /* Deferred start requires that device supports queue start */
    2663   [ +  +  -  + ]:         80 :         if (tx_conf != NULL && tx_conf->tx_deferred_start &&
    2664         [ #  # ]:          0 :             dev->dev_ops->tx_queue_start == NULL) {
    2665                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2666                 :            :                             "Deferred start requested, but driver does not support Tx queue start");
    2667                 :          0 :                 return -ENOTSUP;
    2668                 :            :         }
    2669                 :            : 
    2670                 :         80 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    2671         [ +  - ]:         80 :         if (ret != 0)
    2672                 :            :                 return ret;
    2673                 :            : 
    2674                 :            :         /* Use default specified by driver, if nb_tx_desc is zero */
    2675         [ -  + ]:         80 :         if (nb_tx_desc == 0) {
    2676                 :          0 :                 nb_tx_desc = dev_info.default_txportconf.ring_size;
    2677                 :            :                 /* If driver default is zero, fall back on EAL default */
    2678         [ #  # ]:          0 :                 if (nb_tx_desc == 0)
    2679                 :            :                         nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
    2680                 :            :         }
    2681         [ +  - ]:         80 :         if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
    2682         [ +  - ]:         80 :             nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
    2683         [ -  + ]:         80 :             nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
    2684                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2685                 :            :                         "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu",
    2686                 :            :                         nb_tx_desc, dev_info.tx_desc_lim.nb_max,
    2687                 :            :                         dev_info.tx_desc_lim.nb_min,
    2688                 :            :                         dev_info.tx_desc_lim.nb_align);
    2689                 :          0 :                 return -EINVAL;
    2690                 :            :         }
    2691                 :            : 
    2692         [ -  + ]:         80 :         if (dev->data->dev_started &&
    2693         [ #  # ]:          0 :                 !(dev_info.dev_capa &
    2694                 :            :                         RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP))
    2695                 :            :                 return -EBUSY;
    2696                 :            : 
    2697         [ -  + ]:         80 :         if (dev->data->dev_started &&
    2698         [ #  # ]:          0 :                 (dev->data->tx_queue_state[tx_queue_id] !=
    2699                 :            :                         RTE_ETH_QUEUE_STATE_STOPPED))
    2700                 :            :                 return -EBUSY;
    2701                 :            : 
    2702                 :         80 :         eth_dev_txq_release(dev, tx_queue_id);
    2703                 :            : 
    2704         [ +  + ]:         80 :         if (tx_conf == NULL)
    2705                 :            :                 tx_conf = &dev_info.default_txconf;
    2706                 :            : 
    2707                 :         80 :         local_conf = *tx_conf;
    2708                 :            : 
    2709                 :            :         /*
    2710                 :            :          * If an offloading has already been enabled in
    2711                 :            :          * rte_eth_dev_configure(), it has been enabled on all queues,
    2712                 :            :          * so there is no need to enable it in this queue again.
    2713                 :            :          * The local_conf.offloads input to underlying PMD only carries
    2714                 :            :          * those offloadings which are only enabled on this queue and
    2715                 :            :          * not enabled on all queues.
    2716                 :            :          */
    2717                 :         80 :         local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads;
    2718                 :            : 
    2719                 :            :         /*
    2720                 :            :          * New added offloadings for this queue are those not enabled in
    2721                 :            :          * rte_eth_dev_configure() and they must be per-queue type.
    2722                 :            :          * A pure per-port offloading can't be enabled on a queue while
    2723                 :            :          * disabled on another queue. A pure per-port offloading can't
    2724                 :            :          * be enabled for any queue as new added one if it hasn't been
    2725                 :            :          * enabled in rte_eth_dev_configure().
    2726                 :            :          */
    2727         [ -  + ]:         80 :         if ((local_conf.offloads & dev_info.tx_queue_offload_capa) !=
    2728                 :            :              local_conf.offloads) {
    2729                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2730                 :            :                         "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
    2731                 :            :                         "within per-queue offload capabilities 0x%"PRIx64" in %s()",
    2732                 :            :                         port_id, tx_queue_id, local_conf.offloads,
    2733                 :            :                         dev_info.tx_queue_offload_capa,
    2734                 :            :                         __func__);
    2735                 :          0 :                 return -EINVAL;
    2736                 :            :         }
    2737                 :            : 
    2738         [ -  + ]:         80 :         rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf);
    2739                 :         80 :         return eth_err(port_id, dev->dev_ops->tx_queue_setup(dev,
    2740                 :            :                        tx_queue_id, nb_tx_desc, socket_id, &local_conf));
    2741                 :            : }
    2742                 :            : 
    2743                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_hairpin_queue_setup)
    2744                 :            : int
    2745                 :          0 : rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
    2746                 :            :                                uint16_t nb_tx_desc,
    2747                 :            :                                const struct rte_eth_hairpin_conf *conf)
    2748                 :            : {
    2749                 :            :         struct rte_eth_dev *dev;
    2750                 :            :         struct rte_eth_hairpin_cap cap;
    2751                 :            :         int i;
    2752                 :            :         int count;
    2753                 :            :         int ret;
    2754                 :            : 
    2755         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    2756                 :          0 :         dev = &rte_eth_devices[port_id];
    2757                 :            : 
    2758         [ #  # ]:          0 :         if (tx_queue_id >= dev->data->nb_tx_queues) {
    2759                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
    2760                 :          0 :                 return -EINVAL;
    2761                 :            :         }
    2762                 :            : 
    2763         [ #  # ]:          0 :         if (conf == NULL) {
    2764                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2765                 :            :                         "Cannot setup ethdev port %u Tx hairpin queue from NULL config",
    2766                 :            :                         port_id);
    2767                 :          0 :                 return -EINVAL;
    2768                 :            :         }
    2769                 :            : 
    2770                 :          0 :         ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
    2771         [ #  # ]:          0 :         if (ret != 0)
    2772                 :            :                 return ret;
    2773         [ #  # ]:          0 :         if (dev->dev_ops->tx_hairpin_queue_setup == NULL)
    2774                 :            :                 return -ENOTSUP;
    2775                 :            :         /* if nb_rx_desc is zero use max number of desc from the driver. */
    2776         [ #  # ]:          0 :         if (nb_tx_desc == 0)
    2777                 :          0 :                 nb_tx_desc = cap.max_nb_desc;
    2778         [ #  # ]:          0 :         if (nb_tx_desc > cap.max_nb_desc) {
    2779                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2780                 :            :                         "Invalid value for nb_tx_desc(=%hu), should be: <= %hu",
    2781                 :            :                         nb_tx_desc, cap.max_nb_desc);
    2782                 :          0 :                 return -EINVAL;
    2783                 :            :         }
    2784         [ #  # ]:          0 :         if (conf->peer_count > cap.max_tx_2_rx) {
    2785                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2786                 :            :                         "Invalid value for number of peers for Tx queue(=%u), should be: <= %hu",
    2787                 :            :                         conf->peer_count, cap.max_tx_2_rx);
    2788                 :          0 :                 return -EINVAL;
    2789                 :            :         }
    2790   [ #  #  #  # ]:          0 :         if (conf->use_locked_device_memory && !cap.tx_cap.locked_device_memory) {
    2791                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2792                 :            :                         "Attempt to use locked device memory for Tx queue, which is not supported");
    2793                 :          0 :                 return -EINVAL;
    2794                 :            :         }
    2795   [ #  #  #  # ]:          0 :         if (conf->use_rte_memory && !cap.tx_cap.rte_memory) {
    2796                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2797                 :            :                         "Attempt to use DPDK memory for Tx queue, which is not supported");
    2798                 :          0 :                 return -EINVAL;
    2799                 :            :         }
    2800         [ #  # ]:          0 :         if (conf->use_locked_device_memory && conf->use_rte_memory) {
    2801                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2802                 :            :                         "Attempt to use mutually exclusive memory settings for Tx queue");
    2803                 :          0 :                 return -EINVAL;
    2804                 :            :         }
    2805                 :          0 :         if (conf->force_memory &&
    2806         [ #  # ]:          0 :             !conf->use_locked_device_memory &&
    2807                 :            :             !conf->use_rte_memory) {
    2808                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2809                 :            :                         "Attempt to force Tx queue memory settings, but none is set");
    2810                 :          0 :                 return -EINVAL;
    2811                 :            :         }
    2812         [ #  # ]:          0 :         if (conf->peer_count == 0) {
    2813                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2814                 :            :                         "Invalid value for number of peers for Tx queue(=%u), should be: > 0",
    2815                 :            :                         conf->peer_count);
    2816                 :          0 :                 return -EINVAL;
    2817                 :            :         }
    2818         [ #  # ]:          0 :         for (i = 0, count = 0; i < dev->data->nb_tx_queues &&
    2819         [ #  # ]:          0 :              cap.max_nb_queues != UINT16_MAX; i++) {
    2820   [ #  #  #  # ]:          0 :                 if (i == tx_queue_id || rte_eth_dev_is_tx_hairpin_queue(dev, i))
    2821                 :          0 :                         count++;
    2822                 :            :         }
    2823         [ #  # ]:          0 :         if (count > cap.max_nb_queues) {
    2824                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "To many Tx hairpin queues max is %d",
    2825                 :            :                 cap.max_nb_queues);
    2826                 :          0 :                 return -EINVAL;
    2827                 :            :         }
    2828         [ #  # ]:          0 :         if (dev->data->dev_started)
    2829                 :            :                 return -EBUSY;
    2830                 :          0 :         eth_dev_txq_release(dev, tx_queue_id);
    2831                 :          0 :         ret = dev->dev_ops->tx_hairpin_queue_setup(dev, tx_queue_id, nb_tx_desc, conf);
    2832         [ #  # ]:          0 :         if (ret == 0)
    2833                 :          0 :                 dev->data->tx_queue_state[tx_queue_id] =
    2834                 :            :                         RTE_ETH_QUEUE_STATE_HAIRPIN;
    2835                 :          0 :         ret = eth_err(port_id, ret);
    2836                 :            : 
    2837                 :          0 :         rte_eth_trace_tx_hairpin_queue_setup(port_id, tx_queue_id, nb_tx_desc,
    2838                 :            :                                              conf, ret);
    2839                 :            : 
    2840                 :          0 :         return ret;
    2841                 :            : }
    2842                 :            : 
    2843                 :            : RTE_EXPORT_SYMBOL(rte_eth_hairpin_bind)
    2844                 :            : int
    2845                 :          0 : rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port)
    2846                 :            : {
    2847                 :            :         struct rte_eth_dev *dev;
    2848                 :            :         int ret;
    2849                 :            : 
    2850         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
    2851                 :          0 :         dev = &rte_eth_devices[tx_port];
    2852                 :            : 
    2853         [ #  # ]:          0 :         if (dev->data->dev_started == 0) {
    2854                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Tx port %d is not started", tx_port);
    2855                 :          0 :                 return -EBUSY;
    2856                 :            :         }
    2857                 :            : 
    2858         [ #  # ]:          0 :         if (dev->dev_ops->hairpin_bind == NULL)
    2859                 :            :                 return -ENOTSUP;
    2860                 :          0 :         ret = dev->dev_ops->hairpin_bind(dev, rx_port);
    2861         [ #  # ]:          0 :         if (ret != 0)
    2862                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Failed to bind hairpin Tx %d"
    2863                 :            :                                " to Rx %d (%d - all ports)",
    2864                 :            :                                tx_port, rx_port, RTE_MAX_ETHPORTS);
    2865                 :            : 
    2866                 :          0 :         rte_eth_trace_hairpin_bind(tx_port, rx_port, ret);
    2867                 :            : 
    2868                 :          0 :         return ret;
    2869                 :            : }
    2870                 :            : 
    2871                 :            : RTE_EXPORT_SYMBOL(rte_eth_hairpin_unbind)
    2872                 :            : int
    2873                 :          0 : rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port)
    2874                 :            : {
    2875                 :            :         struct rte_eth_dev *dev;
    2876                 :            :         int ret;
    2877                 :            : 
    2878         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
    2879                 :          0 :         dev = &rte_eth_devices[tx_port];
    2880                 :            : 
    2881         [ #  # ]:          0 :         if (dev->data->dev_started == 0) {
    2882                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Tx port %d is already stopped", tx_port);
    2883                 :          0 :                 return -EBUSY;
    2884                 :            :         }
    2885                 :            : 
    2886         [ #  # ]:          0 :         if (dev->dev_ops->hairpin_unbind == NULL)
    2887                 :            :                 return -ENOTSUP;
    2888                 :          0 :         ret = dev->dev_ops->hairpin_unbind(dev, rx_port);
    2889         [ #  # ]:          0 :         if (ret != 0)
    2890                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Failed to unbind hairpin Tx %d"
    2891                 :            :                                " from Rx %d (%d - all ports)",
    2892                 :            :                                tx_port, rx_port, RTE_MAX_ETHPORTS);
    2893                 :            : 
    2894                 :          0 :         rte_eth_trace_hairpin_unbind(tx_port, rx_port, ret);
    2895                 :            : 
    2896                 :          0 :         return ret;
    2897                 :            : }
    2898                 :            : 
    2899                 :            : RTE_EXPORT_SYMBOL(rte_eth_hairpin_get_peer_ports)
    2900                 :            : int
    2901                 :          0 : rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports,
    2902                 :            :                                size_t len, uint32_t direction)
    2903                 :            : {
    2904                 :            :         struct rte_eth_dev *dev;
    2905                 :            :         int ret;
    2906                 :            : 
    2907         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    2908                 :          0 :         dev = &rte_eth_devices[port_id];
    2909                 :            : 
    2910         [ #  # ]:          0 :         if (peer_ports == NULL) {
    2911                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2912                 :            :                         "Cannot get ethdev port %u hairpin peer ports to NULL",
    2913                 :            :                         port_id);
    2914                 :          0 :                 return -EINVAL;
    2915                 :            :         }
    2916                 :            : 
    2917         [ #  # ]:          0 :         if (len == 0) {
    2918                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2919                 :            :                         "Cannot get ethdev port %u hairpin peer ports to array with zero size",
    2920                 :            :                         port_id);
    2921                 :          0 :                 return -EINVAL;
    2922                 :            :         }
    2923                 :            : 
    2924         [ #  # ]:          0 :         if (dev->dev_ops->hairpin_get_peer_ports == NULL)
    2925                 :            :                 return -ENOTSUP;
    2926                 :            : 
    2927                 :          0 :         ret = dev->dev_ops->hairpin_get_peer_ports(dev, peer_ports, len, direction);
    2928         [ #  # ]:          0 :         if (ret < 0)
    2929         [ #  # ]:          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Failed to get %d hairpin peer %s ports",
    2930                 :            :                                port_id, direction ? "Rx" : "Tx");
    2931                 :            : 
    2932                 :          0 :         rte_eth_trace_hairpin_get_peer_ports(port_id, peer_ports, len,
    2933                 :            :                                              direction, ret);
    2934                 :            : 
    2935                 :          0 :         return ret;
    2936                 :            : }
    2937                 :            : 
    2938                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_drop_callback)
    2939                 :            : void
    2940                 :          0 : rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
    2941                 :            :                 void *userdata __rte_unused)
    2942                 :            : {
    2943                 :          0 :         rte_pktmbuf_free_bulk(pkts, unsent);
    2944                 :            : 
    2945                 :            :         rte_eth_trace_tx_buffer_drop_callback((void **)pkts, unsent);
    2946                 :          0 : }
    2947                 :            : 
    2948                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_count_callback)
    2949                 :            : void
    2950                 :          0 : rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
    2951                 :            :                 void *userdata)
    2952                 :            : {
    2953                 :            :         uint64_t *count = userdata;
    2954                 :            : 
    2955                 :          0 :         rte_pktmbuf_free_bulk(pkts, unsent);
    2956                 :          0 :         *count += unsent;
    2957                 :            : 
    2958                 :            :         rte_eth_trace_tx_buffer_count_callback((void **)pkts, unsent, *count);
    2959                 :          0 : }
    2960                 :            : 
    2961                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_set_err_callback)
    2962                 :            : int
    2963                 :        108 : rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
    2964                 :            :                 buffer_tx_error_fn cbfn, void *userdata)
    2965                 :            : {
    2966         [ -  + ]:        108 :         if (buffer == NULL) {
    2967                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    2968                 :            :                         "Cannot set Tx buffer error callback to NULL buffer");
    2969                 :          0 :                 return -EINVAL;
    2970                 :            :         }
    2971                 :            : 
    2972                 :        108 :         buffer->error_callback = cbfn;
    2973         [ -  + ]:        108 :         buffer->error_userdata = userdata;
    2974                 :            : 
    2975                 :            :         rte_eth_trace_tx_buffer_set_err_callback(buffer);
    2976                 :            : 
    2977                 :            :         return 0;
    2978                 :            : }
    2979                 :            : 
    2980                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_init)
    2981                 :            : int
    2982                 :         54 : rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
    2983                 :            : {
    2984                 :            :         int ret = 0;
    2985                 :            : 
    2986         [ -  + ]:         54 :         if (buffer == NULL) {
    2987                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot initialize NULL buffer");
    2988                 :          0 :                 return -EINVAL;
    2989                 :            :         }
    2990                 :            : 
    2991                 :         54 :         buffer->size = size;
    2992         [ +  - ]:         54 :         if (buffer->error_callback == NULL) {
    2993                 :         54 :                 ret = rte_eth_tx_buffer_set_err_callback(
    2994                 :            :                         buffer, rte_eth_tx_buffer_drop_callback, NULL);
    2995                 :            :         }
    2996                 :            : 
    2997                 :         54 :         rte_eth_trace_tx_buffer_init(buffer, size, ret);
    2998                 :            : 
    2999                 :         54 :         return ret;
    3000                 :            : }
    3001                 :            : 
    3002                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_done_cleanup)
    3003                 :            : int
    3004                 :          0 : rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
    3005                 :            : {
    3006                 :            :         struct rte_eth_dev *dev;
    3007                 :            :         int ret;
    3008                 :            : 
    3009         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3010                 :            :         dev = &rte_eth_devices[port_id];
    3011                 :            : 
    3012                 :            : #ifdef RTE_ETHDEV_DEBUG_TX
    3013                 :            :         ret = eth_dev_validate_tx_queue(dev, queue_id);
    3014                 :            :         if (ret != 0)
    3015                 :            :                 return ret;
    3016                 :            : #endif
    3017                 :            : 
    3018         [ #  # ]:          0 :         if (dev->dev_ops->tx_done_cleanup == NULL)
    3019                 :            :                 return -ENOTSUP;
    3020                 :            : 
    3021                 :            :         /* Call driver to free pending mbufs. */
    3022                 :          0 :         ret = dev->dev_ops->tx_done_cleanup(dev->data->tx_queues[queue_id], free_cnt);
    3023                 :          0 :         ret = eth_err(port_id, ret);
    3024                 :            : 
    3025                 :          0 :         rte_eth_trace_tx_done_cleanup(port_id, queue_id, free_cnt, ret);
    3026                 :            : 
    3027                 :          0 :         return ret;
    3028                 :            : }
    3029                 :            : 
    3030                 :            : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_enable)
    3031                 :            : int
    3032                 :          6 : rte_eth_promiscuous_enable(uint16_t port_id)
    3033                 :            : {
    3034                 :            :         struct rte_eth_dev *dev;
    3035                 :            :         int diag = 0;
    3036                 :            : 
    3037         [ -  + ]:          6 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3038                 :          6 :         dev = &rte_eth_devices[port_id];
    3039                 :            : 
    3040         [ +  + ]:          6 :         if (dev->data->promiscuous == 1)
    3041                 :            :                 return 0;
    3042                 :            : 
    3043         [ +  - ]:          4 :         if (dev->dev_ops->promiscuous_enable == NULL)
    3044                 :            :                 return -ENOTSUP;
    3045                 :            : 
    3046                 :          4 :         diag = dev->dev_ops->promiscuous_enable(dev);
    3047         [ +  - ]:          4 :         if (diag == 0)
    3048                 :          4 :                 dev->data->promiscuous = 1;
    3049                 :            : 
    3050                 :          4 :         diag = eth_err(port_id, diag);
    3051                 :            : 
    3052         [ -  + ]:          4 :         rte_eth_trace_promiscuous_enable(port_id, dev->data->promiscuous,
    3053                 :            :                                          diag);
    3054                 :            : 
    3055                 :          4 :         return diag;
    3056                 :            : }
    3057                 :            : 
    3058                 :            : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_disable)
    3059                 :            : int
    3060                 :          4 : rte_eth_promiscuous_disable(uint16_t port_id)
    3061                 :            : {
    3062                 :            :         struct rte_eth_dev *dev;
    3063                 :            :         int diag = 0;
    3064                 :            : 
    3065         [ -  + ]:          4 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3066                 :          4 :         dev = &rte_eth_devices[port_id];
    3067                 :            : 
    3068         [ +  + ]:          4 :         if (dev->data->promiscuous == 0)
    3069                 :            :                 return 0;
    3070                 :            : 
    3071         [ +  - ]:          3 :         if (dev->dev_ops->promiscuous_disable == NULL)
    3072                 :            :                 return -ENOTSUP;
    3073                 :            : 
    3074                 :          3 :         diag = dev->dev_ops->promiscuous_disable(dev);
    3075         [ +  - ]:          3 :         if (diag == 0)
    3076                 :          3 :                 dev->data->promiscuous = 0;
    3077                 :            : 
    3078                 :          3 :         diag = eth_err(port_id, diag);
    3079                 :            : 
    3080         [ -  + ]:          3 :         rte_eth_trace_promiscuous_disable(port_id, dev->data->promiscuous,
    3081                 :            :                                           diag);
    3082                 :            : 
    3083                 :          3 :         return diag;
    3084                 :            : }
    3085                 :            : 
    3086                 :            : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_get)
    3087                 :            : int
    3088                 :         79 : rte_eth_promiscuous_get(uint16_t port_id)
    3089                 :            : {
    3090                 :            :         struct rte_eth_dev *dev;
    3091                 :            : 
    3092         [ -  + ]:         79 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3093                 :            :         dev = &rte_eth_devices[port_id];
    3094                 :            : 
    3095         [ -  + ]:         79 :         rte_eth_trace_promiscuous_get(port_id, dev->data->promiscuous);
    3096                 :            : 
    3097                 :         79 :         return dev->data->promiscuous;
    3098                 :            : }
    3099                 :            : 
    3100                 :            : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_enable)
    3101                 :            : int
    3102                 :          2 : rte_eth_allmulticast_enable(uint16_t port_id)
    3103                 :            : {
    3104                 :            :         struct rte_eth_dev *dev;
    3105                 :            :         int diag;
    3106                 :            : 
    3107         [ -  + ]:          2 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3108                 :          2 :         dev = &rte_eth_devices[port_id];
    3109                 :            : 
    3110         [ +  - ]:          2 :         if (dev->data->all_multicast == 1)
    3111                 :            :                 return 0;
    3112                 :            : 
    3113         [ +  - ]:          2 :         if (dev->dev_ops->allmulticast_enable == NULL)
    3114                 :            :                 return -ENOTSUP;
    3115                 :          2 :         diag = dev->dev_ops->allmulticast_enable(dev);
    3116         [ +  - ]:          2 :         if (diag == 0)
    3117                 :          2 :                 dev->data->all_multicast = 1;
    3118                 :            : 
    3119                 :          2 :         diag = eth_err(port_id, diag);
    3120                 :            : 
    3121         [ -  + ]:          2 :         rte_eth_trace_allmulticast_enable(port_id, dev->data->all_multicast,
    3122                 :            :                                           diag);
    3123                 :            : 
    3124                 :          2 :         return diag;
    3125                 :            : }
    3126                 :            : 
    3127                 :            : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_disable)
    3128                 :            : int
    3129                 :          3 : rte_eth_allmulticast_disable(uint16_t port_id)
    3130                 :            : {
    3131                 :            :         struct rte_eth_dev *dev;
    3132                 :            :         int diag;
    3133                 :            : 
    3134         [ -  + ]:          3 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3135                 :          3 :         dev = &rte_eth_devices[port_id];
    3136                 :            : 
    3137         [ +  + ]:          3 :         if (dev->data->all_multicast == 0)
    3138                 :            :                 return 0;
    3139                 :            : 
    3140         [ +  - ]:          2 :         if (dev->dev_ops->allmulticast_disable == NULL)
    3141                 :            :                 return -ENOTSUP;
    3142                 :            : 
    3143                 :          2 :         diag = dev->dev_ops->allmulticast_disable(dev);
    3144         [ +  - ]:          2 :         if (diag == 0)
    3145                 :          2 :                 dev->data->all_multicast = 0;
    3146                 :            : 
    3147                 :          2 :         diag = eth_err(port_id, diag);
    3148                 :            : 
    3149         [ -  + ]:          2 :         rte_eth_trace_allmulticast_disable(port_id, dev->data->all_multicast,
    3150                 :            :                                            diag);
    3151                 :            : 
    3152                 :          2 :         return diag;
    3153                 :            : }
    3154                 :            : 
    3155                 :            : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_get)
    3156                 :            : int
    3157                 :         77 : rte_eth_allmulticast_get(uint16_t port_id)
    3158                 :            : {
    3159                 :            :         struct rte_eth_dev *dev;
    3160                 :            : 
    3161         [ -  + ]:         77 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3162                 :            :         dev = &rte_eth_devices[port_id];
    3163                 :            : 
    3164         [ -  + ]:         77 :         rte_eth_trace_allmulticast_get(port_id, dev->data->all_multicast);
    3165                 :            : 
    3166                 :         77 :         return dev->data->all_multicast;
    3167                 :            : }
    3168                 :            : 
    3169                 :            : RTE_EXPORT_SYMBOL(rte_eth_link_get)
    3170                 :            : int
    3171                 :         11 : rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
    3172                 :            : {
    3173                 :            :         struct rte_eth_dev *dev;
    3174                 :            : 
    3175         [ -  + ]:         11 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3176                 :         11 :         dev = &rte_eth_devices[port_id];
    3177                 :            : 
    3178         [ -  + ]:         11 :         if (eth_link == NULL) {
    3179                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u link to NULL",
    3180                 :            :                         port_id);
    3181                 :          0 :                 return -EINVAL;
    3182                 :            :         }
    3183                 :            : 
    3184   [ -  +  -  - ]:         11 :         if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
    3185                 :          0 :                 rte_eth_linkstatus_get(dev, eth_link);
    3186                 :            :         else {
    3187         [ +  - ]:         11 :                 if (dev->dev_ops->link_update == NULL)
    3188                 :            :                         return -ENOTSUP;
    3189                 :         11 :                 dev->dev_ops->link_update(dev, 1);
    3190                 :         11 :                 *eth_link = dev->data->dev_link;
    3191                 :            :         }
    3192                 :            : 
    3193                 :            :         rte_eth_trace_link_get(port_id, eth_link);
    3194                 :            : 
    3195                 :            :         return 0;
    3196                 :            : }
    3197                 :            : 
    3198                 :            : RTE_EXPORT_SYMBOL(rte_eth_link_get_nowait)
    3199                 :            : int
    3200                 :         13 : rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
    3201                 :            : {
    3202                 :            :         struct rte_eth_dev *dev;
    3203                 :            : 
    3204         [ -  + ]:         13 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3205                 :         13 :         dev = &rte_eth_devices[port_id];
    3206                 :            : 
    3207         [ -  + ]:         13 :         if (eth_link == NULL) {
    3208                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u link to NULL",
    3209                 :            :                         port_id);
    3210                 :          0 :                 return -EINVAL;
    3211                 :            :         }
    3212                 :            : 
    3213   [ +  +  +  - ]:         13 :         if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
    3214                 :          3 :                 rte_eth_linkstatus_get(dev, eth_link);
    3215                 :            :         else {
    3216         [ +  - ]:         10 :                 if (dev->dev_ops->link_update == NULL)
    3217                 :            :                         return -ENOTSUP;
    3218                 :         10 :                 dev->dev_ops->link_update(dev, 0);
    3219                 :         10 :                 *eth_link = dev->data->dev_link;
    3220                 :            :         }
    3221                 :            : 
    3222                 :         13 :         rte_eth_trace_link_get_nowait(port_id, eth_link);
    3223                 :            : 
    3224                 :         13 :         return 0;
    3225                 :            : }
    3226                 :            : 
    3227                 :            : RTE_EXPORT_SYMBOL(rte_eth_link_speed_to_str)
    3228                 :            : const char *
    3229                 :         24 : rte_eth_link_speed_to_str(uint32_t link_speed)
    3230                 :            : {
    3231                 :            :         const char *ret;
    3232                 :            : 
    3233   [ +  +  +  +  :         24 :         switch (link_speed) {
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  + ]
    3234                 :            :         case RTE_ETH_SPEED_NUM_NONE:
    3235                 :            :                 ret = "None";
    3236                 :            :                 break;
    3237                 :          2 :         case RTE_ETH_SPEED_NUM_10M:
    3238                 :            :                 ret = "10 Mbps";
    3239                 :          2 :                 break;
    3240                 :          1 :         case RTE_ETH_SPEED_NUM_100M:
    3241                 :            :                 ret = "100 Mbps";
    3242                 :          1 :                 break;
    3243                 :          1 :         case RTE_ETH_SPEED_NUM_1G:
    3244                 :            :                 ret = "1 Gbps";
    3245                 :          1 :                 break;
    3246                 :          2 :         case RTE_ETH_SPEED_NUM_2_5G:
    3247                 :            :                 ret = "2.5 Gbps";
    3248                 :          2 :                 break;
    3249                 :          1 :         case RTE_ETH_SPEED_NUM_5G:
    3250                 :            :                 ret = "5 Gbps";
    3251                 :          1 :                 break;
    3252                 :          1 :         case RTE_ETH_SPEED_NUM_10G:
    3253                 :            :                 ret = "10 Gbps";
    3254                 :          1 :                 break;
    3255                 :          1 :         case RTE_ETH_SPEED_NUM_20G:
    3256                 :            :                 ret = "20 Gbps";
    3257                 :          1 :                 break;
    3258                 :          1 :         case RTE_ETH_SPEED_NUM_25G:
    3259                 :            :                 ret = "25 Gbps";
    3260                 :          1 :                 break;
    3261                 :          1 :         case RTE_ETH_SPEED_NUM_40G:
    3262                 :            :                 ret = "40 Gbps";
    3263                 :          1 :                 break;
    3264                 :          1 :         case RTE_ETH_SPEED_NUM_50G:
    3265                 :            :                 ret = "50 Gbps";
    3266                 :          1 :                 break;
    3267                 :          1 :         case RTE_ETH_SPEED_NUM_56G:
    3268                 :            :                 ret = "56 Gbps";
    3269                 :          1 :                 break;
    3270                 :          1 :         case RTE_ETH_SPEED_NUM_100G:
    3271                 :            :                 ret = "100 Gbps";
    3272                 :          1 :                 break;
    3273                 :          1 :         case RTE_ETH_SPEED_NUM_200G:
    3274                 :            :                 ret = "200 Gbps";
    3275                 :          1 :                 break;
    3276                 :          1 :         case RTE_ETH_SPEED_NUM_400G:
    3277                 :            :                 ret = "400 Gbps";
    3278                 :          1 :                 break;
    3279                 :          2 :         case RTE_ETH_SPEED_NUM_800G:
    3280                 :            :                 ret = "800 Gbps";
    3281                 :          2 :                 break;
    3282                 :          2 :         case RTE_ETH_SPEED_NUM_UNKNOWN:
    3283                 :            :                 ret = "Unknown";
    3284                 :          2 :                 break;
    3285                 :          2 :         default:
    3286                 :            :                 ret = "Invalid";
    3287                 :            :         }
    3288                 :            : 
    3289                 :            :         rte_eth_trace_link_speed_to_str(link_speed, ret);
    3290                 :            : 
    3291                 :         24 :         return ret;
    3292                 :            : }
    3293                 :            : 
    3294                 :            : RTE_EXPORT_SYMBOL(rte_eth_link_to_str)
    3295                 :            : int
    3296                 :          7 : rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link)
    3297                 :            : {
    3298                 :            :         int ret;
    3299                 :            : 
    3300         [ -  + ]:          7 :         if (str == NULL) {
    3301                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot convert link to NULL string");
    3302                 :          0 :                 return -EINVAL;
    3303                 :            :         }
    3304                 :            : 
    3305         [ -  + ]:          7 :         if (len == 0) {
    3306                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    3307                 :            :                         "Cannot convert link to string with zero size");
    3308                 :          0 :                 return -EINVAL;
    3309                 :            :         }
    3310                 :            : 
    3311         [ -  + ]:          7 :         if (eth_link == NULL) {
    3312                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot convert to string from NULL link");
    3313                 :          0 :                 return -EINVAL;
    3314                 :            :         }
    3315                 :            : 
    3316         [ +  + ]:          7 :         if (eth_link->link_status == RTE_ETH_LINK_DOWN)
    3317                 :            :                 ret = snprintf(str, len, "Link down");
    3318                 :            :         else
    3319                 :         24 :                 ret = snprintf(str, len, "Link up at %s %s %s %s",
    3320                 :          6 :                         rte_eth_link_speed_to_str(eth_link->link_speed),
    3321         [ +  + ]:          6 :                         (eth_link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
    3322                 :            :                         "FDX" : "HDX",
    3323         [ +  + ]:          6 :                         (eth_link->link_autoneg == RTE_ETH_LINK_AUTONEG) ?
    3324                 :            :                         "Autoneg" : "Fixed",
    3325                 :          6 :                         rte_eth_link_connector_to_str(eth_link->link_connector));
    3326                 :            : 
    3327                 :          7 :         rte_eth_trace_link_to_str(len, eth_link, str, ret);
    3328                 :            : 
    3329                 :          7 :         return ret;
    3330                 :            : }
    3331                 :            : 
    3332                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_link_connector_to_str, 25.11)
    3333                 :            : const char *
    3334                 :          6 : rte_eth_link_connector_to_str(enum rte_eth_link_connector link_connector)
    3335                 :            : {
    3336                 :            :         static const char * const link_connector_str[] = {
    3337                 :            :                 [RTE_ETH_LINK_CONNECTOR_NONE] = "None",
    3338                 :            :                 [RTE_ETH_LINK_CONNECTOR_TP] = "Twisted Pair",
    3339                 :            :                 [RTE_ETH_LINK_CONNECTOR_AUI] = "Attachment Unit Interface",
    3340                 :            :                 [RTE_ETH_LINK_CONNECTOR_MII] = "Media Independent Interface",
    3341                 :            :                 [RTE_ETH_LINK_CONNECTOR_FIBER] = "Fiber",
    3342                 :            :                 [RTE_ETH_LINK_CONNECTOR_BNC] = "BNC",
    3343                 :            :                 [RTE_ETH_LINK_CONNECTOR_DAC] = "Direct Attach Copper",
    3344                 :            :                 [RTE_ETH_LINK_CONNECTOR_SGMII] = "SGMII",
    3345                 :            :                 [RTE_ETH_LINK_CONNECTOR_QSGMII] = "QSGMII",
    3346                 :            :                 [RTE_ETH_LINK_CONNECTOR_XFI] = "XFI",
    3347                 :            :                 [RTE_ETH_LINK_CONNECTOR_SFI] = "SFI",
    3348                 :            :                 [RTE_ETH_LINK_CONNECTOR_XLAUI] = "XLAUI",
    3349                 :            :                 [RTE_ETH_LINK_CONNECTOR_GAUI] = "GAUI",
    3350                 :            :                 [RTE_ETH_LINK_CONNECTOR_XAUI] = "XAUI",
    3351                 :            :                 [RTE_ETH_LINK_CONNECTOR_CAUI] = "CAUI",
    3352                 :            :                 [RTE_ETH_LINK_CONNECTOR_LAUI] = "LAUI",
    3353                 :            :                 [RTE_ETH_LINK_CONNECTOR_SFP] = "SFP",
    3354                 :            :                 [RTE_ETH_LINK_CONNECTOR_SFP_DD] = "SFP-DD",
    3355                 :            :                 [RTE_ETH_LINK_CONNECTOR_SFP_PLUS] = "SFP+",
    3356                 :            :                 [RTE_ETH_LINK_CONNECTOR_SFP28] = "SFP28",
    3357                 :            :                 [RTE_ETH_LINK_CONNECTOR_QSFP] = "QSFP",
    3358                 :            :                 [RTE_ETH_LINK_CONNECTOR_QSFP_PLUS] = "QSFP+",
    3359                 :            :                 [RTE_ETH_LINK_CONNECTOR_QSFP28] = "QSFP28",
    3360                 :            :                 [RTE_ETH_LINK_CONNECTOR_QSFP56] = "QSFP56",
    3361                 :            :                 [RTE_ETH_LINK_CONNECTOR_QSFP_DD] = "QSFP-DD",
    3362                 :            :                 [RTE_ETH_LINK_CONNECTOR_OTHER] = "Other",
    3363                 :            :         };
    3364                 :            :         const char *str = NULL;
    3365                 :            : 
    3366         [ +  - ]:          6 :         if (link_connector < ((enum rte_eth_link_connector)RTE_DIM(link_connector_str)))
    3367                 :          6 :                 str = link_connector_str[link_connector];
    3368                 :            : 
    3369                 :          6 :         return str;
    3370                 :            : }
    3371                 :            : 
    3372                 :            : RTE_EXPORT_SYMBOL(rte_eth_stats_get)
    3373                 :            : int
    3374                 :         41 : rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
    3375                 :            : {
    3376                 :         41 :         int ret = eth_stats_qstats_get(port_id, stats, NULL);
    3377                 :            : 
    3378                 :            :         rte_eth_trace_stats_get(port_id, stats, ret);
    3379                 :         41 :         return ret;
    3380                 :            : }
    3381                 :            : 
    3382                 :            : RTE_EXPORT_SYMBOL(rte_eth_stats_reset)
    3383                 :            : int
    3384                 :         15 : rte_eth_stats_reset(uint16_t port_id)
    3385                 :            : {
    3386                 :            :         struct rte_eth_dev *dev;
    3387                 :            :         int ret;
    3388                 :            : 
    3389         [ -  + ]:         15 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3390                 :         15 :         dev = &rte_eth_devices[port_id];
    3391                 :            : 
    3392         [ +  - ]:         15 :         if (dev->dev_ops->stats_reset == NULL)
    3393                 :            :                 return -ENOTSUP;
    3394                 :         15 :         ret = dev->dev_ops->stats_reset(dev);
    3395         [ -  + ]:         15 :         if (ret != 0)
    3396                 :          0 :                 return eth_err(port_id, ret);
    3397                 :            : 
    3398         [ -  + ]:         15 :         dev->data->rx_mbuf_alloc_failed = 0;
    3399                 :            : 
    3400                 :         15 :         rte_eth_trace_stats_reset(port_id);
    3401                 :            : 
    3402                 :         15 :         return 0;
    3403                 :            : }
    3404                 :            : 
    3405                 :            : static inline int
    3406                 :            : eth_dev_get_xstats_basic_count(struct rte_eth_dev *dev)
    3407                 :            : {
    3408                 :            :         uint16_t nb_rxqs, nb_txqs;
    3409                 :            :         int count;
    3410                 :            : 
    3411                 :          6 :         nb_rxqs = dev->data->nb_rx_queues;
    3412                 :          6 :         nb_txqs = dev->data->nb_tx_queues;
    3413                 :            : 
    3414                 :            :         count = RTE_NB_STATS;
    3415         [ +  - ]:          3 :         if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) {
    3416                 :          6 :                 count += nb_rxqs * RTE_NB_RXQ_STATS;
    3417                 :          6 :                 count += nb_txqs * RTE_NB_TXQ_STATS;
    3418                 :            :         }
    3419                 :            : 
    3420                 :            :         return count;
    3421                 :            : }
    3422                 :            : 
    3423                 :            : static int
    3424                 :          3 : eth_dev_get_xstats_count(uint16_t port_id)
    3425                 :            : {
    3426                 :            :         struct rte_eth_dev *dev;
    3427                 :            :         int count;
    3428                 :            : 
    3429         [ -  + ]:          3 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3430                 :          3 :         dev = &rte_eth_devices[port_id];
    3431         [ -  + ]:          3 :         if (dev->dev_ops->xstats_get_names != NULL) {
    3432                 :          0 :                 count = dev->dev_ops->xstats_get_names(dev, NULL, 0);
    3433         [ #  # ]:          0 :                 if (count < 0)
    3434                 :          0 :                         return eth_err(port_id, count);
    3435                 :            :         } else
    3436                 :            :                 count = 0;
    3437                 :            : 
    3438                 :            : 
    3439                 :          3 :         count += eth_dev_get_xstats_basic_count(dev);
    3440                 :            : 
    3441                 :          3 :         return count;
    3442                 :            : }
    3443                 :            : 
    3444                 :            : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_id_by_name)
    3445                 :            : int
    3446                 :          0 : rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
    3447                 :            :                 uint64_t *id)
    3448                 :            : {
    3449                 :            :         int cnt_xstats, idx_xstat, rc;
    3450                 :            :         struct rte_eth_xstat_name *xstats_names;
    3451                 :            : 
    3452         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3453                 :            : 
    3454         [ #  # ]:          0 :         if (xstat_name == NULL) {
    3455                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    3456                 :            :                         "Cannot get ethdev port %u xstats ID from NULL xstat name",
    3457                 :            :                         port_id);
    3458                 :          0 :                 return -ENOMEM;
    3459                 :            :         }
    3460                 :            : 
    3461         [ #  # ]:          0 :         if (id == NULL) {
    3462                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    3463                 :            :                         "Cannot get ethdev port %u xstats ID to NULL",
    3464                 :            :                         port_id);
    3465                 :          0 :                 return -ENOMEM;
    3466                 :            :         }
    3467                 :            : 
    3468                 :            :         /* Get count */
    3469                 :          0 :         cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
    3470         [ #  # ]:          0 :         if (cnt_xstats  < 0) {
    3471                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get count of xstats");
    3472                 :          0 :                 return -ENODEV;
    3473                 :            :         }
    3474                 :            : 
    3475                 :            :         /* Get id-name lookup table */
    3476                 :          0 :         xstats_names = calloc(cnt_xstats, sizeof(xstats_names[0]));
    3477         [ #  # ]:          0 :         if (xstats_names == NULL) {
    3478                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
    3479                 :          0 :                 return -ENOMEM;
    3480                 :            :         }
    3481                 :            : 
    3482         [ #  # ]:          0 :         if (cnt_xstats != rte_eth_xstats_get_names_by_id(
    3483                 :            :                         port_id, xstats_names, cnt_xstats, NULL)) {
    3484                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get xstats lookup");
    3485                 :          0 :                 free(xstats_names);
    3486                 :          0 :                 return -1;
    3487                 :            :         }
    3488                 :            : 
    3489                 :            :         rc = -EINVAL;
    3490         [ #  # ]:          0 :         for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
    3491         [ #  # ]:          0 :                 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
    3492         [ #  # ]:          0 :                         *id = idx_xstat;
    3493                 :            : 
    3494                 :          0 :                         rte_eth_trace_xstats_get_id_by_name(port_id,
    3495                 :            :                                                             xstat_name, *id);
    3496                 :            :                         rc = 0;
    3497                 :          0 :                         break;
    3498                 :            :                 };
    3499                 :            :         }
    3500                 :            : 
    3501                 :          0 :         free(xstats_names);
    3502                 :          0 :         return rc;
    3503                 :            : }
    3504                 :            : 
    3505                 :            : /* retrieve basic stats names */
    3506                 :            : static int
    3507                 :          2 : eth_basic_stats_get_names(struct rte_eth_dev *dev,
    3508                 :            :         struct rte_eth_xstat_name *xstats_names)
    3509                 :            : {
    3510                 :            :         int cnt_used_entries = 0;
    3511                 :            :         uint32_t idx, id_queue;
    3512                 :            :         uint16_t num_q;
    3513                 :            : 
    3514         [ +  + ]:         18 :         for (idx = 0; idx < RTE_NB_STATS; idx++) {
    3515         [ -  + ]:         16 :                 if (strlcpy(xstats_names[cnt_used_entries].name, eth_dev_stats_strings[idx].name,
    3516                 :            :                                 sizeof(xstats_names[0].name)) >= sizeof(xstats_names[0].name))
    3517                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "statistic name '%s' will be truncated",
    3518                 :            :                                 xstats_names[cnt_used_entries].name);
    3519                 :         16 :                 cnt_used_entries++;
    3520                 :            :         }
    3521                 :            : 
    3522         [ +  - ]:          2 :         if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0)
    3523                 :            :                 return cnt_used_entries;
    3524                 :            : 
    3525                 :          2 :         num_q = dev->data->nb_rx_queues;
    3526         [ +  + ]:          6 :         for (id_queue = 0; id_queue < num_q; id_queue++) {
    3527         [ +  + ]:         12 :                 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
    3528                 :            :                         unsigned int cc;
    3529                 :            : 
    3530                 :          8 :                         cc = snprintf(xstats_names[cnt_used_entries].name,
    3531                 :            :                                 sizeof(xstats_names[0].name), "rx_q%u_%s", id_queue,
    3532         [ -  + ]:          8 :                                 eth_dev_rxq_stats_strings[idx].name);
    3533                 :            : 
    3534                 :            :                         /* could only happen if a long string was added */
    3535         [ -  + ]:          8 :                         if (cc >= sizeof(xstats_names[0].name))
    3536                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR, "truncated rxq stat string '%s'",
    3537                 :            :                                         eth_dev_rxq_stats_strings[idx].name);
    3538                 :          8 :                         cnt_used_entries++;
    3539                 :            :                 }
    3540                 :            : 
    3541                 :            :         }
    3542                 :          2 :         num_q = dev->data->nb_tx_queues;
    3543         [ +  + ]:          8 :         for (id_queue = 0; id_queue < num_q; id_queue++) {
    3544         [ +  + ]:         18 :                 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
    3545                 :            :                         unsigned int cc;
    3546                 :            : 
    3547                 :         12 :                         cc = snprintf(xstats_names[cnt_used_entries].name,
    3548                 :            :                                 sizeof(xstats_names[0].name), "tx_q%u_%s", id_queue,
    3549         [ -  + ]:         12 :                                 eth_dev_txq_stats_strings[idx].name);
    3550         [ -  + ]:         12 :                         if (cc >= sizeof(xstats_names[0].name))
    3551                 :          0 :                                 RTE_ETHDEV_LOG_LINE(ERR, "truncated txq stat string '%s'",
    3552                 :            :                                         eth_dev_txq_stats_strings[idx].name);
    3553                 :         12 :                         cnt_used_entries++;
    3554                 :            :                 }
    3555                 :            :         }
    3556                 :            :         return cnt_used_entries;
    3557                 :            : }
    3558                 :            : 
    3559                 :            : static int
    3560                 :          0 : eth_xstats_get_by_name_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
    3561                 :            :         struct rte_eth_xstat_name *xstats_names, uint32_t size,
    3562                 :            :         uint32_t basic_count)
    3563                 :            : {
    3564                 :            :         int32_t rc;
    3565                 :            :         uint32_t i, k, m, n;
    3566                 :            :         uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
    3567                 :            : 
    3568                 :            :         m = 0;
    3569         [ #  # ]:          0 :         for (n = 0; n != size; n += k) {
    3570                 :            : 
    3571                 :          0 :                 k = RTE_MIN(size - n, RTE_DIM(ids_copy));
    3572                 :            : 
    3573                 :            :                 /*
    3574                 :            :                  * Convert ids to xstats ids that PMD knows.
    3575                 :            :                  * ids known by user are basic + extended stats.
    3576                 :            :                  */
    3577         [ #  # ]:          0 :                 for (i = 0; i < k; i++)
    3578                 :          0 :                         ids_copy[i] = ids[n + i] - basic_count;
    3579                 :            : 
    3580                 :          0 :                 rc = dev->dev_ops->xstats_get_names_by_id(dev, ids_copy, xstats_names + m, k);
    3581         [ #  # ]:          0 :                 if (rc < 0)
    3582                 :          0 :                         return rc;
    3583                 :          0 :                 m += rc;
    3584                 :            :         }
    3585                 :            : 
    3586                 :          0 :         return m;
    3587                 :            : }
    3588                 :            : 
    3589                 :            : 
    3590                 :            : /* retrieve ethdev extended statistics names */
    3591                 :            : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names_by_id)
    3592                 :            : int
    3593                 :          0 : rte_eth_xstats_get_names_by_id(uint16_t port_id,
    3594                 :            :         struct rte_eth_xstat_name *xstats_names, unsigned int size,
    3595                 :            :         uint64_t *ids)
    3596                 :            : {
    3597                 :            :         struct rte_eth_xstat_name *xstats_names_copy;
    3598                 :            :         unsigned int expected_entries;
    3599                 :            :         unsigned int nb_basic_stats;
    3600                 :            :         unsigned int basic_count;
    3601                 :            :         struct rte_eth_dev *dev;
    3602                 :            :         unsigned int i;
    3603                 :            :         int ret;
    3604                 :            : 
    3605         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3606         [ #  # ]:          0 :         dev = &rte_eth_devices[port_id];
    3607                 :            : 
    3608                 :          0 :         basic_count = eth_dev_get_xstats_basic_count(dev);
    3609                 :          0 :         ret = eth_dev_get_xstats_count(port_id);
    3610         [ #  # ]:          0 :         if (ret < 0)
    3611                 :            :                 return ret;
    3612                 :          0 :         expected_entries = (unsigned int)ret;
    3613                 :            : 
    3614                 :            :         /* Return max number of stats if no ids given */
    3615         [ #  # ]:          0 :         if (!ids) {
    3616         [ #  # ]:          0 :                 if (!xstats_names)
    3617                 :            :                         return expected_entries;
    3618         [ #  # ]:          0 :                 else if (xstats_names && size < expected_entries)
    3619                 :            :                         return expected_entries;
    3620                 :            :         }
    3621                 :            : 
    3622         [ #  # ]:          0 :         if (ids && !xstats_names)
    3623                 :            :                 return -EINVAL;
    3624                 :            : 
    3625                 :            :         nb_basic_stats = 0;
    3626         [ #  # ]:          0 :         if (ids != NULL) {
    3627         [ #  # ]:          0 :                 for (i = 0; i < size; i++)
    3628                 :          0 :                         nb_basic_stats += (ids[i] < basic_count);
    3629                 :            :         }
    3630                 :            : 
    3631                 :            :         /* no basic stats requested, devops function provided */
    3632   [ #  #  #  # ]:          0 :         if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
    3633         [ #  # ]:          0 :                         dev->dev_ops->xstats_get_names_by_id != NULL)
    3634                 :          0 :                 return eth_xstats_get_by_name_by_id(dev, ids, xstats_names,
    3635                 :            :                                 size, basic_count);
    3636                 :            : 
    3637                 :            :         /* Retrieve all stats */
    3638         [ #  # ]:          0 :         if (!ids) {
    3639                 :          0 :                 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
    3640                 :            :                                 expected_entries);
    3641         [ #  # ]:          0 :                 if (num_stats < 0 || num_stats > (int)expected_entries)
    3642                 :            :                         return num_stats;
    3643                 :            :                 else
    3644                 :          0 :                         return expected_entries;
    3645                 :            :         }
    3646                 :            : 
    3647                 :          0 :         xstats_names_copy = calloc(expected_entries,
    3648                 :            :                 sizeof(struct rte_eth_xstat_name));
    3649                 :            : 
    3650         [ #  # ]:          0 :         if (!xstats_names_copy) {
    3651                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
    3652                 :          0 :                 return -ENOMEM;
    3653                 :            :         }
    3654                 :            : 
    3655                 :            :         /* Fill xstats_names_copy structure */
    3656         [ #  # ]:          0 :         if (ids && nb_basic_stats == size) {
    3657                 :          0 :                 eth_basic_stats_get_names(dev, xstats_names_copy);
    3658                 :            :         } else {
    3659                 :          0 :                 ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
    3660                 :            :                         expected_entries);
    3661         [ #  # ]:          0 :                 if (ret < 0) {
    3662                 :          0 :                         free(xstats_names_copy);
    3663                 :          0 :                         return ret;
    3664                 :            :                 }
    3665                 :            :         }
    3666                 :            : 
    3667                 :            :         /* Filter stats */
    3668         [ #  # ]:          0 :         for (i = 0; i < size; i++) {
    3669         [ #  # ]:          0 :                 if (ids[i] >= expected_entries) {
    3670                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
    3671                 :          0 :                         free(xstats_names_copy);
    3672                 :          0 :                         return -1;
    3673                 :            :                 }
    3674         [ #  # ]:          0 :                 xstats_names[i] = xstats_names_copy[ids[i]];
    3675                 :            : 
    3676                 :          0 :                 rte_eth_trace_xstats_get_names_by_id(port_id, &xstats_names[i],
    3677                 :            :                                                      ids[i]);
    3678                 :            :         }
    3679                 :            : 
    3680                 :          0 :         free(xstats_names_copy);
    3681                 :          0 :         return size;
    3682                 :            : }
    3683                 :            : 
    3684                 :            : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names)
    3685                 :            : int
    3686                 :          3 : rte_eth_xstats_get_names(uint16_t port_id,
    3687                 :            :         struct rte_eth_xstat_name *xstats_names,
    3688                 :            :         unsigned int size)
    3689                 :            : {
    3690                 :            :         struct rte_eth_dev *dev;
    3691                 :            :         int cnt_used_entries;
    3692                 :            :         int cnt_expected_entries;
    3693                 :            :         int cnt_driver_entries;
    3694                 :            :         int i;
    3695                 :            : 
    3696                 :          3 :         cnt_expected_entries = eth_dev_get_xstats_count(port_id);
    3697         [ +  + ]:          3 :         if (xstats_names == NULL || cnt_expected_entries < 0 ||
    3698         [ +  - ]:          2 :                         (int)size < cnt_expected_entries)
    3699                 :            :                 return cnt_expected_entries;
    3700                 :            : 
    3701                 :            :         /* port_id checked in eth_dev_get_xstats_count() */
    3702                 :          2 :         dev = &rte_eth_devices[port_id];
    3703                 :            : 
    3704                 :          2 :         cnt_used_entries = eth_basic_stats_get_names(dev, xstats_names);
    3705                 :            : 
    3706         [ -  + ]:          2 :         if (dev->dev_ops->xstats_get_names != NULL) {
    3707                 :            :                 /* If there are any driver-specific xstats, append them
    3708                 :            :                  * to end of list.
    3709                 :            :                  */
    3710                 :          0 :                 cnt_driver_entries = dev->dev_ops->xstats_get_names(
    3711                 :            :                         dev,
    3712                 :          0 :                         xstats_names + cnt_used_entries,
    3713                 :            :                         size - cnt_used_entries);
    3714         [ #  # ]:          0 :                 if (cnt_driver_entries < 0)
    3715                 :          0 :                         return eth_err(port_id, cnt_driver_entries);
    3716                 :          0 :                 cnt_used_entries += cnt_driver_entries;
    3717                 :            :         }
    3718                 :            : 
    3719         [ +  + ]:         38 :         for (i = 0; i < cnt_used_entries; i++)
    3720         [ -  + ]:         36 :                 rte_eth_trace_xstats_get_names(port_id, i, &xstats_names[i],
    3721                 :            :                                                size, cnt_used_entries);
    3722                 :            : 
    3723                 :            :         return cnt_used_entries;
    3724                 :            : }
    3725                 :            : 
    3726                 :            : 
    3727                 :            : static int
    3728                 :          2 : eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
    3729                 :            : {
    3730                 :            :         struct rte_eth_dev *dev;
    3731                 :            :         struct rte_eth_stats eth_stats;
    3732                 :            :         struct eth_queue_stats *queue_stats = NULL;
    3733                 :            :         unsigned int count = 0, i, q;
    3734                 :            :         uint16_t nb_rxqs, nb_txqs, nb_q;
    3735                 :            :         uint64_t *stats_ptr;
    3736                 :            :         int ret;
    3737                 :            : 
    3738                 :          2 :         dev = &rte_eth_devices[port_id];
    3739                 :            : 
    3740         [ +  - ]:          2 :         if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) {
    3741                 :          2 :                 nb_rxqs = dev->data->nb_rx_queues;
    3742                 :          2 :                 nb_txqs = dev->data->nb_tx_queues;
    3743                 :            :         } else {
    3744                 :            :                 nb_rxqs = 0;
    3745                 :            :                 nb_txqs = 0;
    3746                 :            :         }
    3747                 :            : 
    3748                 :          2 :         nb_q = RTE_MAX(nb_rxqs, nb_txqs);
    3749         [ +  - ]:          2 :         if (nb_q > 0) {
    3750                 :          2 :                 queue_stats = calloc(nb_q, sizeof(*queue_stats));
    3751         [ +  - ]:          2 :                 if (queue_stats == NULL)
    3752                 :            :                         return -ENOMEM;
    3753                 :            :         }
    3754                 :            : 
    3755                 :          2 :         ret = eth_stats_qstats_get(port_id, &eth_stats, queue_stats);
    3756         [ -  + ]:          2 :         if (ret < 0)
    3757                 :          0 :                 goto out;
    3758                 :            : 
    3759                 :            :         /* global stats */
    3760         [ +  + ]:         18 :         for (i = 0; i < RTE_NB_STATS; i++) {
    3761                 :         16 :                 stats_ptr = RTE_PTR_ADD(&eth_stats,
    3762                 :            :                                         eth_dev_stats_strings[i].offset);
    3763                 :         16 :                 xstats[count++].value = *stats_ptr;
    3764                 :            :         }
    3765                 :            : 
    3766                 :            :         /* per-rxq stats */
    3767         [ +  + ]:          6 :         for (q = 0; q < nb_rxqs; q++) {
    3768         [ +  + ]:         12 :                 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
    3769                 :          8 :                         stats_ptr = RTE_PTR_ADD(&queue_stats[q],
    3770                 :            :                                         eth_dev_rxq_stats_strings[i].offset);
    3771                 :          8 :                         xstats[count++].value = *stats_ptr;
    3772                 :            :                 }
    3773                 :            :         }
    3774                 :            : 
    3775                 :            :         /* per-txq stats */
    3776         [ +  + ]:          8 :         for (q = 0; q < nb_txqs; q++) {
    3777         [ +  + ]:         18 :                 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
    3778                 :         12 :                         stats_ptr = RTE_PTR_ADD(&queue_stats[q],
    3779                 :            :                                         eth_dev_txq_stats_strings[i].offset);
    3780                 :         12 :                         xstats[count++].value = *stats_ptr;
    3781                 :            :                 }
    3782                 :            :         }
    3783                 :          2 :         ret = count;
    3784                 :          2 : out:
    3785                 :          2 :         free(queue_stats);
    3786                 :          2 :         return ret;
    3787                 :            : }
    3788                 :            : 
    3789                 :            : static int
    3790                 :          0 : eth_xtats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
    3791                 :            :         uint64_t *values, uint32_t size, uint32_t basic_count)
    3792                 :            : {
    3793                 :            :         int32_t rc;
    3794                 :            :         uint32_t i, k, m, n;
    3795                 :            :         uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
    3796                 :            : 
    3797                 :            :         m = 0;
    3798         [ #  # ]:          0 :         for (n = 0; n != size; n += k) {
    3799                 :            : 
    3800                 :          0 :                 k = RTE_MIN(size - n, RTE_DIM(ids_copy));
    3801                 :            : 
    3802                 :            :                 /*
    3803                 :            :                  * Convert ids to xstats ids that PMD knows.
    3804                 :            :                  * ids known by user are basic + extended stats.
    3805                 :            :                  */
    3806         [ #  # ]:          0 :                 for (i = 0; i < k; i++)
    3807                 :          0 :                         ids_copy[i] = ids[n + i] - basic_count;
    3808                 :            : 
    3809                 :          0 :                 rc = dev->dev_ops->xstats_get_by_id(dev, ids_copy, values + m, k);
    3810         [ #  # ]:          0 :                 if (rc < 0)
    3811                 :          0 :                         return rc;
    3812                 :          0 :                 m += rc;
    3813                 :            :         }
    3814                 :            : 
    3815                 :          0 :         return m;
    3816                 :            : }
    3817                 :            : 
    3818                 :            : /* retrieve ethdev extended statistics */
    3819                 :            : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_by_id)
    3820                 :            : int
    3821                 :          0 : rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
    3822                 :            :                          uint64_t *values, unsigned int size)
    3823                 :            : {
    3824                 :            :         unsigned int nb_basic_stats;
    3825                 :            :         unsigned int num_xstats_filled;
    3826                 :            :         unsigned int basic_count;
    3827                 :            :         uint16_t expected_entries;
    3828                 :            :         struct rte_eth_dev *dev;
    3829                 :            :         struct rte_eth_xstat *xstats;
    3830                 :            :         unsigned int i;
    3831                 :            :         int ret;
    3832                 :            : 
    3833         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3834                 :          0 :         dev = &rte_eth_devices[port_id];
    3835                 :            : 
    3836                 :          0 :         ret = eth_dev_get_xstats_count(port_id);
    3837         [ #  # ]:          0 :         if (ret < 0)
    3838                 :            :                 return ret;
    3839         [ #  # ]:          0 :         expected_entries = (uint16_t)ret;
    3840                 :          0 :         basic_count = eth_dev_get_xstats_basic_count(dev);
    3841                 :            : 
    3842                 :            :         /* Return max number of stats if no ids given */
    3843         [ #  # ]:          0 :         if (!ids) {
    3844         [ #  # ]:          0 :                 if (!values)
    3845                 :          0 :                         return expected_entries;
    3846         [ #  # ]:          0 :                 else if (values && size < expected_entries)
    3847                 :            :                         return expected_entries;
    3848                 :            :         }
    3849                 :            : 
    3850         [ #  # ]:          0 :         if (ids && !values)
    3851                 :            :                 return -EINVAL;
    3852                 :            : 
    3853                 :            :         nb_basic_stats = 0;
    3854         [ #  # ]:          0 :         if (ids != NULL) {
    3855         [ #  # ]:          0 :                 for (i = 0; i < size; i++)
    3856                 :          0 :                         nb_basic_stats += (ids[i] < basic_count);
    3857                 :            :         }
    3858                 :            : 
    3859                 :            :         /* no basic stats requested, devops function provided */
    3860   [ #  #  #  # ]:          0 :         if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
    3861         [ #  # ]:          0 :                         dev->dev_ops->xstats_get_by_id != NULL)
    3862                 :          0 :                 return eth_xtats_get_by_id(dev, ids, values, size, basic_count);
    3863                 :            : 
    3864                 :          0 :         xstats = calloc(expected_entries, sizeof(xstats[0]));
    3865         [ #  # ]:          0 :         if (xstats == NULL) {
    3866                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
    3867                 :          0 :                 return -ENOMEM;
    3868                 :            :         }
    3869                 :            : 
    3870                 :            :         /* Fill the xstats structure */
    3871         [ #  # ]:          0 :         if (ids && nb_basic_stats == size)
    3872                 :          0 :                 ret = eth_basic_stats_get(port_id, xstats);
    3873                 :            :         else
    3874                 :          0 :                 ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
    3875                 :            : 
    3876         [ #  # ]:          0 :         if (ret < 0) {
    3877                 :          0 :                 free(xstats);
    3878                 :          0 :                 return ret;
    3879                 :            :         }
    3880                 :          0 :         num_xstats_filled = (unsigned int)ret;
    3881                 :            : 
    3882                 :            :         /* Return all stats */
    3883         [ #  # ]:          0 :         if (!ids) {
    3884         [ #  # ]:          0 :                 for (i = 0; i < num_xstats_filled; i++)
    3885                 :          0 :                         values[i] = xstats[i].value;
    3886                 :            : 
    3887                 :          0 :                 free(xstats);
    3888                 :          0 :                 return expected_entries;
    3889                 :            :         }
    3890                 :            : 
    3891                 :            :         /* Filter stats */
    3892         [ #  # ]:          0 :         for (i = 0; i < size; i++) {
    3893         [ #  # ]:          0 :                 if (ids[i] >= expected_entries) {
    3894                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
    3895                 :          0 :                         break;
    3896                 :            :                 }
    3897                 :          0 :                 values[i] = xstats[ids[i]].value;
    3898                 :            :         }
    3899                 :            : 
    3900                 :          0 :         rte_eth_trace_xstats_get_by_id(port_id, ids, values, size);
    3901                 :            : 
    3902                 :          0 :         free(xstats);
    3903         [ #  # ]:          0 :         return (i == size) ? (int32_t)size : -1;
    3904                 :            : }
    3905                 :            : 
    3906                 :            : RTE_EXPORT_SYMBOL(rte_eth_xstats_get)
    3907                 :            : int
    3908                 :          3 : rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
    3909                 :            :         unsigned int n)
    3910                 :            : {
    3911                 :            :         struct rte_eth_dev *dev;
    3912                 :            :         unsigned int count, i;
    3913                 :            :         signed int xcount = 0;
    3914                 :            :         int ret;
    3915                 :            : 
    3916         [ -  + ]:          3 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3917         [ +  - ]:          3 :         if (xstats == NULL && n > 0)
    3918                 :            :                 return -EINVAL;
    3919         [ +  - ]:          3 :         dev = &rte_eth_devices[port_id];
    3920                 :            : 
    3921                 :          3 :         count = eth_dev_get_xstats_basic_count(dev);
    3922                 :            : 
    3923                 :            :         /* implemented by the driver */
    3924         [ -  + ]:          3 :         if (dev->dev_ops->xstats_get != NULL) {
    3925                 :            :                 /* Retrieve the xstats from the driver at the end of the
    3926                 :            :                  * xstats struct.
    3927                 :            :                  */
    3928   [ #  #  #  # ]:          0 :                 xcount = dev->dev_ops->xstats_get(dev,
    3929                 :          0 :                                      (n > count) ? xstats + count : NULL,
    3930                 :            :                                      (n > count) ? n - count : 0);
    3931                 :            : 
    3932         [ #  # ]:          0 :                 if (xcount < 0)
    3933                 :          0 :                         return eth_err(port_id, xcount);
    3934                 :            :         }
    3935                 :            : 
    3936   [ +  +  -  + ]:          3 :         if (n < count + xcount || xstats == NULL)
    3937                 :          1 :                 return count + xcount;
    3938                 :            : 
    3939                 :            :         /* now fill the xstats structure */
    3940                 :          2 :         ret = eth_basic_stats_get(port_id, xstats);
    3941         [ +  - ]:          2 :         if (ret < 0)
    3942                 :            :                 return ret;
    3943                 :          2 :         count = ret;
    3944                 :            : 
    3945         [ +  + ]:         38 :         for (i = 0; i < count; i++)
    3946                 :         36 :                 xstats[i].id = i;
    3947                 :            :         /* add an offset to driver-specific stats */
    3948         [ -  + ]:          2 :         for ( ; i < count + xcount; i++)
    3949                 :          0 :                 xstats[i].id += count;
    3950                 :            : 
    3951         [ +  + ]:         38 :         for (i = 0; i < n; i++)
    3952         [ -  + ]:         36 :                 rte_eth_trace_xstats_get(port_id, xstats[i]);
    3953                 :            : 
    3954                 :          2 :         return count + xcount;
    3955                 :            : }
    3956                 :            : 
    3957                 :            : /* reset ethdev extended statistics */
    3958                 :            : RTE_EXPORT_SYMBOL(rte_eth_xstats_reset)
    3959                 :            : int
    3960                 :          0 : rte_eth_xstats_reset(uint16_t port_id)
    3961                 :            : {
    3962                 :            :         struct rte_eth_dev *dev;
    3963                 :            : 
    3964         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3965                 :          0 :         dev = &rte_eth_devices[port_id];
    3966                 :            : 
    3967                 :            :         /* implemented by the driver */
    3968         [ #  # ]:          0 :         if (dev->dev_ops->xstats_reset != NULL) {
    3969                 :          0 :                 int ret = eth_err(port_id, dev->dev_ops->xstats_reset(dev));
    3970                 :            : 
    3971                 :          0 :                 rte_eth_trace_xstats_reset(port_id, ret);
    3972                 :            : 
    3973                 :          0 :                 return ret;
    3974                 :            :         }
    3975                 :            : 
    3976                 :            :         /* fallback to default */
    3977                 :          0 :         return rte_eth_stats_reset(port_id);
    3978                 :            : }
    3979                 :            : 
    3980                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_set_counter, 25.03)
    3981                 :            : int
    3982                 :          0 : rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off)
    3983                 :            : {
    3984                 :            :         struct rte_eth_dev *dev;
    3985                 :            :         unsigned int basic_count;
    3986                 :            : 
    3987         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    3988                 :            : 
    3989         [ #  # ]:          0 :         dev = &rte_eth_devices[port_id];
    3990                 :            :         basic_count = eth_dev_get_xstats_basic_count(dev);
    3991         [ #  # ]:          0 :         if (id < basic_count)
    3992                 :            :                 return -EINVAL;
    3993                 :            : 
    3994         [ #  # ]:          0 :         if (on_off == 1) {
    3995         [ #  # ]:          0 :                 if (rte_eth_xstats_query_state(port_id, id) == 1)
    3996                 :            :                         return -EEXIST;
    3997         [ #  # ]:          0 :                 if (dev->dev_ops->xstats_enable != NULL)
    3998                 :          0 :                         return dev->dev_ops->xstats_enable(dev, id - basic_count);
    3999                 :            :         } else {
    4000         [ #  # ]:          0 :                 if (rte_eth_xstats_query_state(port_id, id) == 0)
    4001                 :            :                         return 0;
    4002         [ #  # ]:          0 :                 if (dev->dev_ops->xstats_disable != NULL)
    4003                 :          0 :                         return dev->dev_ops->xstats_disable(dev, id - basic_count);
    4004                 :            :         }
    4005                 :            : 
    4006                 :            :         return -ENOTSUP;
    4007                 :            : }
    4008                 :            : 
    4009                 :            : 
    4010                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_query_state, 25.03)
    4011                 :            : int
    4012                 :          0 : rte_eth_xstats_query_state(uint16_t port_id, uint64_t id)
    4013                 :            : {
    4014                 :            :         struct rte_eth_dev *dev;
    4015                 :            :         unsigned int basic_count;
    4016                 :            : 
    4017         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4018                 :            : 
    4019         [ #  # ]:          0 :         dev = &rte_eth_devices[port_id];
    4020                 :            :         basic_count = eth_dev_get_xstats_basic_count(dev);
    4021         [ #  # ]:          0 :         if (id < basic_count)
    4022                 :            :                 return -ENOTSUP;
    4023                 :            : 
    4024                 :            :         /* implemented by the driver */
    4025         [ #  # ]:          0 :         if (dev->dev_ops->xstats_query_state != NULL)
    4026                 :          0 :                 return dev->dev_ops->xstats_query_state(dev, id - basic_count);
    4027                 :            : 
    4028                 :            :         return -ENOTSUP;
    4029                 :            : }
    4030                 :            : 
    4031                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_fw_version_get)
    4032                 :            : int
    4033                 :          1 : rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
    4034                 :            : {
    4035                 :            :         struct rte_eth_dev *dev;
    4036                 :            :         int ret;
    4037                 :            : 
    4038         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4039                 :          1 :         dev = &rte_eth_devices[port_id];
    4040                 :            : 
    4041         [ -  + ]:          1 :         if (fw_version == NULL && fw_size > 0) {
    4042                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4043                 :            :                         "Cannot get ethdev port %u FW version to NULL when string size is non zero",
    4044                 :            :                         port_id);
    4045                 :          0 :                 return -EINVAL;
    4046                 :            :         }
    4047                 :            : 
    4048         [ -  + ]:          1 :         if (dev->dev_ops->fw_version_get == NULL)
    4049                 :            :                 return -ENOTSUP;
    4050                 :          0 :         ret = eth_err(port_id, dev->dev_ops->fw_version_get(dev, fw_version, fw_size));
    4051                 :            : 
    4052                 :          0 :         rte_ethdev_trace_fw_version_get(port_id, fw_version, fw_size, ret);
    4053                 :            : 
    4054                 :          0 :         return ret;
    4055                 :            : }
    4056                 :            : 
    4057                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_info_get)
    4058                 :            : int
    4059                 :        287 : rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
    4060                 :            : {
    4061                 :            :         struct rte_eth_dev *dev;
    4062                 :            :         const struct rte_eth_desc_lim lim = {
    4063                 :            :                 .nb_max = UINT16_MAX,
    4064                 :            :                 .nb_min = 0,
    4065                 :            :                 .nb_align = 1,
    4066                 :            :                 .nb_seg_max = UINT16_MAX,
    4067                 :            :                 .nb_mtu_seg_max = UINT16_MAX,
    4068                 :            :         };
    4069                 :            :         int diag;
    4070                 :            : 
    4071         [ -  + ]:        287 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4072                 :        287 :         dev = &rte_eth_devices[port_id];
    4073                 :            : 
    4074         [ -  + ]:        287 :         if (dev_info == NULL) {
    4075                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u info to NULL",
    4076                 :            :                         port_id);
    4077                 :          0 :                 return -EINVAL;
    4078                 :            :         }
    4079                 :            : 
    4080                 :            :         /*
    4081                 :            :          * Init dev_info before port_id check since caller does not have
    4082                 :            :          * return status and does not know if get is successful or not.
    4083                 :            :          */
    4084                 :            :         memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
    4085                 :        287 :         dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
    4086                 :            : 
    4087                 :        287 :         dev_info->rx_desc_lim = lim;
    4088                 :        287 :         dev_info->tx_desc_lim = lim;
    4089                 :        287 :         dev_info->device = dev->device;
    4090                 :        287 :         dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN -
    4091                 :            :                 RTE_ETHER_CRC_LEN;
    4092                 :        287 :         dev_info->max_mtu = UINT16_MAX;
    4093                 :        287 :         dev_info->rss_algo_capa = RTE_ETH_HASH_ALGO_CAPA_MASK(DEFAULT);
    4094                 :        287 :         dev_info->max_rx_bufsize = UINT32_MAX;
    4095                 :            : 
    4096         [ +  - ]:        287 :         if (dev->dev_ops->dev_infos_get == NULL)
    4097                 :            :                 return -ENOTSUP;
    4098                 :        287 :         diag = dev->dev_ops->dev_infos_get(dev, dev_info);
    4099         [ -  + ]:        287 :         if (diag != 0) {
    4100                 :            :                 /* Cleanup already filled in device information */
    4101                 :            :                 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
    4102                 :          0 :                 return eth_err(port_id, diag);
    4103                 :            :         }
    4104                 :            : 
    4105                 :            :         /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */
    4106                 :        287 :         dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues,
    4107                 :            :                         RTE_MAX_QUEUES_PER_PORT);
    4108                 :        287 :         dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues,
    4109                 :            :                         RTE_MAX_QUEUES_PER_PORT);
    4110                 :            : 
    4111                 :        287 :         dev_info->driver_name = dev->device->driver->name;
    4112                 :        287 :         dev_info->nb_rx_queues = dev->data->nb_rx_queues;
    4113                 :        287 :         dev_info->nb_tx_queues = dev->data->nb_tx_queues;
    4114                 :            : 
    4115         [ -  + ]:        287 :         dev_info->dev_flags = &dev->data->dev_flags;
    4116                 :            : 
    4117                 :        287 :         rte_ethdev_trace_info_get(port_id, dev_info);
    4118                 :            : 
    4119                 :        287 :         return 0;
    4120                 :            : }
    4121                 :            : 
    4122                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_conf_get)
    4123                 :            : int
    4124                 :          1 : rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf)
    4125                 :            : {
    4126                 :            :         struct rte_eth_dev *dev;
    4127                 :            : 
    4128         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4129                 :            :         dev = &rte_eth_devices[port_id];
    4130                 :            : 
    4131         [ -  + ]:          1 :         if (dev_conf == NULL) {
    4132                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4133                 :            :                         "Cannot get ethdev port %u configuration to NULL",
    4134                 :            :                         port_id);
    4135                 :          0 :                 return -EINVAL;
    4136                 :            :         }
    4137                 :            : 
    4138         [ -  + ]:          1 :         memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf));
    4139                 :            : 
    4140                 :          1 :         rte_ethdev_trace_conf_get(port_id, dev_conf);
    4141                 :            : 
    4142                 :          1 :         return 0;
    4143                 :            : }
    4144                 :            : 
    4145                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_supported_ptypes)
    4146                 :            : int
    4147                 :          0 : rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
    4148                 :            :                                  uint32_t *ptypes, int num)
    4149                 :            : {
    4150                 :            :         size_t i;
    4151                 :            :         int j;
    4152                 :            :         struct rte_eth_dev *dev;
    4153                 :            :         const uint32_t *all_ptypes;
    4154                 :          0 :         size_t no_of_elements = 0;
    4155                 :            : 
    4156         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4157                 :          0 :         dev = &rte_eth_devices[port_id];
    4158                 :            : 
    4159         [ #  # ]:          0 :         if (ptypes == NULL && num > 0) {
    4160                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4161                 :            :                         "Cannot get ethdev port %u supported packet types to NULL when array size is non zero",
    4162                 :            :                         port_id);
    4163                 :          0 :                 return -EINVAL;
    4164                 :            :         }
    4165                 :            : 
    4166         [ #  # ]:          0 :         if (dev->dev_ops->dev_supported_ptypes_get == NULL)
    4167                 :            :                 return 0;
    4168                 :          0 :         all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
    4169                 :            : 
    4170         [ #  # ]:          0 :         if (!all_ptypes)
    4171                 :            :                 return 0;
    4172                 :            : 
    4173         [ #  # ]:          0 :         for (i = 0, j = 0; i < no_of_elements; ++i)
    4174         [ #  # ]:          0 :                 if (all_ptypes[i] & ptype_mask) {
    4175         [ #  # ]:          0 :                         if (j < num) {
    4176         [ #  # ]:          0 :                                 ptypes[j] = all_ptypes[i];
    4177                 :            : 
    4178                 :          0 :                                 rte_ethdev_trace_get_supported_ptypes(port_id,
    4179                 :            :                                                 j, num, ptypes[j]);
    4180                 :            :                         }
    4181                 :          0 :                         j++;
    4182                 :            :                 }
    4183                 :            : 
    4184                 :            :         return j;
    4185                 :            : }
    4186                 :            : 
    4187                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_ptypes)
    4188                 :            : int
    4189                 :          0 : rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
    4190                 :            :                                  uint32_t *set_ptypes, unsigned int num)
    4191                 :            : {
    4192                 :          0 :         const uint32_t valid_ptype_masks[] = {
    4193                 :            :                 RTE_PTYPE_L2_MASK,
    4194                 :            :                 RTE_PTYPE_L3_MASK,
    4195                 :            :                 RTE_PTYPE_L4_MASK,
    4196                 :            :                 RTE_PTYPE_TUNNEL_MASK,
    4197                 :            :                 RTE_PTYPE_INNER_L2_MASK,
    4198                 :            :                 RTE_PTYPE_INNER_L3_MASK,
    4199                 :            :                 RTE_PTYPE_INNER_L4_MASK,
    4200                 :            :         };
    4201                 :            :         const uint32_t *all_ptypes;
    4202                 :            :         struct rte_eth_dev *dev;
    4203                 :            :         uint32_t unused_mask;
    4204                 :            :         size_t i;
    4205                 :            :         unsigned int j;
    4206                 :            :         int ret;
    4207                 :          0 :         size_t no_of_elements = 0;
    4208                 :            : 
    4209         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4210                 :          0 :         dev = &rte_eth_devices[port_id];
    4211                 :            : 
    4212         [ #  # ]:          0 :         if (num > 0 && set_ptypes == NULL) {
    4213                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4214                 :            :                         "Cannot get ethdev port %u set packet types to NULL when array size is non zero",
    4215                 :            :                         port_id);
    4216                 :          0 :                 return -EINVAL;
    4217                 :            :         }
    4218                 :            : 
    4219         [ #  # ]:          0 :         if (dev->dev_ops->dev_supported_ptypes_get == NULL ||
    4220         [ #  # ]:          0 :             dev->dev_ops->dev_ptypes_set == NULL) {
    4221                 :            :                 ret = 0;
    4222                 :          0 :                 goto ptype_unknown;
    4223                 :            :         }
    4224                 :            : 
    4225         [ #  # ]:          0 :         if (ptype_mask == 0) {
    4226                 :          0 :                 ret = dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
    4227                 :          0 :                 goto ptype_unknown;
    4228                 :            :         }
    4229                 :            : 
    4230                 :            :         unused_mask = ptype_mask;
    4231         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) {
    4232                 :          0 :                 uint32_t mask = ptype_mask & valid_ptype_masks[i];
    4233   [ #  #  #  # ]:          0 :                 if (mask && mask != valid_ptype_masks[i]) {
    4234                 :            :                         ret = -EINVAL;
    4235                 :          0 :                         goto ptype_unknown;
    4236                 :            :                 }
    4237                 :          0 :                 unused_mask &= ~valid_ptype_masks[i];
    4238                 :            :         }
    4239                 :            : 
    4240         [ #  # ]:          0 :         if (unused_mask) {
    4241                 :            :                 ret = -EINVAL;
    4242                 :          0 :                 goto ptype_unknown;
    4243                 :            :         }
    4244                 :            : 
    4245                 :          0 :         all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
    4246         [ #  # ]:          0 :         if (all_ptypes == NULL) {
    4247                 :            :                 ret = 0;
    4248                 :          0 :                 goto ptype_unknown;
    4249                 :            :         }
    4250                 :            : 
    4251                 :            :         /*
    4252                 :            :          * Accommodate as many set_ptypes as possible. If the supplied
    4253                 :            :          * set_ptypes array is insufficient fill it partially.
    4254                 :            :          */
    4255         [ #  # ]:          0 :         for (i = 0, j = 0; set_ptypes != NULL &&
    4256         [ #  # ]:          0 :                                 (i < no_of_elements); ++i) {
    4257         [ #  # ]:          0 :                 if (ptype_mask & all_ptypes[i]) {
    4258         [ #  # ]:          0 :                         if (j < num - 1) {
    4259                 :          0 :                                 set_ptypes[j] = all_ptypes[i];
    4260                 :            : 
    4261         [ #  # ]:          0 :                                 rte_ethdev_trace_set_ptypes(port_id, j, num,
    4262                 :            :                                                 set_ptypes[j]);
    4263                 :            : 
    4264                 :          0 :                                 j++;
    4265                 :          0 :                                 continue;
    4266                 :            :                         }
    4267                 :            :                         break;
    4268                 :            :                 }
    4269                 :            :         }
    4270                 :            : 
    4271         [ #  # ]:          0 :         if (set_ptypes != NULL && j < num)
    4272                 :          0 :                 set_ptypes[j] = RTE_PTYPE_UNKNOWN;
    4273                 :            : 
    4274                 :          0 :         return dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
    4275                 :            : 
    4276                 :          0 : ptype_unknown:
    4277         [ #  # ]:          0 :         if (num > 0)
    4278                 :          0 :                 set_ptypes[0] = RTE_PTYPE_UNKNOWN;
    4279                 :            : 
    4280                 :            :         return ret;
    4281                 :            : }
    4282                 :            : 
    4283                 :            : RTE_EXPORT_SYMBOL(rte_eth_macaddrs_get)
    4284                 :            : int
    4285                 :          0 : rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma,
    4286                 :            :         unsigned int num)
    4287                 :            : {
    4288                 :            :         int32_t ret;
    4289                 :            :         struct rte_eth_dev *dev;
    4290                 :            :         struct rte_eth_dev_info dev_info;
    4291                 :            : 
    4292         [ #  # ]:          0 :         if (ma == NULL) {
    4293                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "%s: invalid parameters", __func__);
    4294                 :          0 :                 return -EINVAL;
    4295                 :            :         }
    4296                 :            : 
    4297                 :            :         /* will check for us that port_id is a valid one */
    4298                 :          0 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    4299         [ #  # ]:          0 :         if (ret != 0)
    4300                 :            :                 return ret;
    4301                 :            : 
    4302                 :            :         dev = &rte_eth_devices[port_id];
    4303                 :          0 :         num = RTE_MIN(dev_info.max_mac_addrs, num);
    4304         [ #  # ]:          0 :         memcpy(ma, dev->data->mac_addrs, num * sizeof(ma[0]));
    4305                 :            : 
    4306                 :          0 :         rte_eth_trace_macaddrs_get(port_id, num);
    4307                 :            : 
    4308                 :          0 :         return num;
    4309                 :            : }
    4310                 :            : 
    4311                 :            : RTE_EXPORT_SYMBOL(rte_eth_macaddr_get)
    4312                 :            : int
    4313                 :         12 : rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
    4314                 :            : {
    4315                 :            :         struct rte_eth_dev *dev;
    4316                 :            : 
    4317         [ -  + ]:         12 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4318                 :            :         dev = &rte_eth_devices[port_id];
    4319                 :            : 
    4320         [ -  + ]:         12 :         if (mac_addr == NULL) {
    4321                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4322                 :            :                         "Cannot get ethdev port %u MAC address to NULL",
    4323                 :            :                         port_id);
    4324                 :          0 :                 return -EINVAL;
    4325                 :            :         }
    4326                 :            : 
    4327                 :         12 :         rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
    4328                 :            : 
    4329                 :            :         rte_eth_trace_macaddr_get(port_id, mac_addr);
    4330                 :            : 
    4331                 :         12 :         return 0;
    4332                 :            : }
    4333                 :            : 
    4334                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_mtu)
    4335                 :            : int
    4336                 :          3 : rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
    4337                 :            : {
    4338                 :            :         struct rte_eth_dev *dev;
    4339                 :            : 
    4340         [ -  + ]:          3 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4341                 :            :         dev = &rte_eth_devices[port_id];
    4342                 :            : 
    4343         [ -  + ]:          3 :         if (mtu == NULL) {
    4344                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u MTU to NULL",
    4345                 :            :                         port_id);
    4346                 :          0 :                 return -EINVAL;
    4347                 :            :         }
    4348                 :            : 
    4349                 :          3 :         *mtu = dev->data->mtu;
    4350                 :            : 
    4351                 :            :         rte_ethdev_trace_get_mtu(port_id, *mtu);
    4352                 :            : 
    4353                 :          3 :         return 0;
    4354                 :            : }
    4355                 :            : 
    4356                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mtu)
    4357                 :            : int
    4358                 :          5 : rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
    4359                 :            : {
    4360                 :            :         int ret;
    4361                 :            :         struct rte_eth_dev_info dev_info;
    4362                 :            :         struct rte_eth_dev *dev;
    4363                 :            : 
    4364         [ -  + ]:          5 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4365                 :          5 :         dev = &rte_eth_devices[port_id];
    4366         [ +  - ]:          5 :         if (dev->dev_ops->mtu_set == NULL)
    4367                 :            :                 return -ENOTSUP;
    4368                 :            : 
    4369                 :            :         /*
    4370                 :            :          * Check if the device supports dev_infos_get, if it does not
    4371                 :            :          * skip min_mtu/max_mtu validation here as this requires values
    4372                 :            :          * that are populated within the call to rte_eth_dev_info_get()
    4373                 :            :          * which relies on dev->dev_ops->dev_infos_get.
    4374                 :            :          */
    4375         [ +  - ]:          5 :         if (dev->dev_ops->dev_infos_get != NULL) {
    4376                 :          5 :                 ret = rte_eth_dev_info_get(port_id, &dev_info);
    4377         [ +  - ]:          5 :                 if (ret != 0)
    4378                 :            :                         return ret;
    4379                 :            : 
    4380                 :          5 :                 ret = eth_dev_validate_mtu(port_id, &dev_info, mtu);
    4381         [ +  - ]:          5 :                 if (ret != 0)
    4382                 :            :                         return ret;
    4383                 :            :         }
    4384                 :            : 
    4385         [ -  + ]:          5 :         if (dev->data->dev_configured == 0) {
    4386                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4387                 :            :                         "Port %u must be configured before MTU set",
    4388                 :            :                         port_id);
    4389                 :          0 :                 return -EINVAL;
    4390                 :            :         }
    4391                 :            : 
    4392                 :          5 :         ret = dev->dev_ops->mtu_set(dev, mtu);
    4393         [ +  + ]:          5 :         if (ret == 0)
    4394                 :          4 :                 dev->data->mtu = mtu;
    4395                 :            : 
    4396                 :          5 :         ret = eth_err(port_id, ret);
    4397                 :            : 
    4398                 :          5 :         rte_ethdev_trace_set_mtu(port_id, mtu, ret);
    4399                 :            : 
    4400                 :          5 :         return ret;
    4401                 :            : }
    4402                 :            : 
    4403                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_vlan_filter)
    4404                 :            : int
    4405                 :          0 : rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
    4406                 :            : {
    4407                 :            :         struct rte_eth_dev *dev;
    4408                 :            :         int ret;
    4409                 :            : 
    4410         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4411                 :          0 :         dev = &rte_eth_devices[port_id];
    4412                 :            : 
    4413         [ #  # ]:          0 :         if (!(dev->data->dev_conf.rxmode.offloads &
    4414                 :            :               RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) {
    4415                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port %u: VLAN-filtering disabled",
    4416                 :            :                         port_id);
    4417                 :          0 :                 return -ENOSYS;
    4418                 :            :         }
    4419                 :            : 
    4420         [ #  # ]:          0 :         if (vlan_id > 4095) {
    4421                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port_id=%u invalid vlan_id=%u > 4095",
    4422                 :            :                         port_id, vlan_id);
    4423                 :          0 :                 return -EINVAL;
    4424                 :            :         }
    4425         [ #  # ]:          0 :         if (dev->dev_ops->vlan_filter_set == NULL)
    4426                 :            :                 return -ENOTSUP;
    4427                 :            : 
    4428                 :          0 :         ret = dev->dev_ops->vlan_filter_set(dev, vlan_id, on);
    4429         [ #  # ]:          0 :         if (ret == 0) {
    4430                 :            :                 struct rte_vlan_filter_conf *vfc;
    4431                 :            :                 int vidx;
    4432                 :            :                 int vbit;
    4433                 :            : 
    4434                 :          0 :                 vfc = &dev->data->vlan_filter_conf;
    4435                 :          0 :                 vidx = vlan_id / 64;
    4436                 :          0 :                 vbit = vlan_id % 64;
    4437                 :            : 
    4438         [ #  # ]:          0 :                 if (on)
    4439                 :          0 :                         vfc->ids[vidx] |= RTE_BIT64(vbit);
    4440                 :            :                 else
    4441                 :          0 :                         vfc->ids[vidx] &= ~RTE_BIT64(vbit);
    4442                 :            :         }
    4443                 :            : 
    4444                 :          0 :         ret = eth_err(port_id, ret);
    4445                 :            : 
    4446                 :          0 :         rte_ethdev_trace_vlan_filter(port_id, vlan_id, on, ret);
    4447                 :            : 
    4448                 :          0 :         return ret;
    4449                 :            : }
    4450                 :            : 
    4451                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_strip_on_queue)
    4452                 :            : int
    4453                 :          0 : rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
    4454                 :            :                                     int on)
    4455                 :            : {
    4456                 :            :         struct rte_eth_dev *dev;
    4457                 :            : 
    4458         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4459                 :          0 :         dev = &rte_eth_devices[port_id];
    4460                 :            : 
    4461         [ #  # ]:          0 :         if (rx_queue_id >= dev->data->nb_rx_queues) {
    4462                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid rx_queue_id=%u", rx_queue_id);
    4463                 :          0 :                 return -EINVAL;
    4464                 :            :         }
    4465                 :            : 
    4466         [ #  # ]:          0 :         if (dev->dev_ops->vlan_strip_queue_set == NULL)
    4467                 :            :                 return -ENOTSUP;
    4468                 :          0 :         dev->dev_ops->vlan_strip_queue_set(dev, rx_queue_id, on);
    4469                 :            : 
    4470                 :          0 :         rte_ethdev_trace_set_vlan_strip_on_queue(port_id, rx_queue_id, on);
    4471                 :            : 
    4472                 :          0 :         return 0;
    4473                 :            : }
    4474                 :            : 
    4475                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_ether_type)
    4476                 :            : int
    4477                 :          0 : rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
    4478                 :            :                                 enum rte_vlan_type vlan_type,
    4479                 :            :                                 uint16_t tpid)
    4480                 :            : {
    4481                 :            :         struct rte_eth_dev *dev;
    4482                 :            :         int ret;
    4483                 :            : 
    4484         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4485                 :          0 :         dev = &rte_eth_devices[port_id];
    4486                 :            : 
    4487         [ #  # ]:          0 :         if (dev->dev_ops->vlan_tpid_set == NULL)
    4488                 :            :                 return -ENOTSUP;
    4489                 :          0 :         ret = eth_err(port_id, dev->dev_ops->vlan_tpid_set(dev, vlan_type, tpid));
    4490                 :            : 
    4491                 :          0 :         rte_ethdev_trace_set_vlan_ether_type(port_id, vlan_type, tpid, ret);
    4492                 :            : 
    4493                 :          0 :         return ret;
    4494                 :            : }
    4495                 :            : 
    4496                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_offload)
    4497                 :            : int
    4498                 :          0 : rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
    4499                 :            : {
    4500                 :            :         struct rte_eth_dev_info dev_info;
    4501                 :            :         struct rte_eth_dev *dev;
    4502                 :            :         int ret = 0;
    4503                 :            :         int mask = 0;
    4504                 :            :         int cur, org = 0;
    4505                 :            :         uint64_t orig_offloads;
    4506                 :            :         uint64_t dev_offloads;
    4507                 :            :         uint64_t new_offloads;
    4508                 :            : 
    4509         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4510                 :          0 :         dev = &rte_eth_devices[port_id];
    4511                 :            : 
    4512                 :            :         /* save original values in case of failure */
    4513                 :          0 :         orig_offloads = dev->data->dev_conf.rxmode.offloads;
    4514                 :            :         dev_offloads = orig_offloads;
    4515                 :            : 
    4516                 :            :         /* check which option changed by application */
    4517                 :          0 :         cur = !!(offload_mask & RTE_ETH_VLAN_STRIP_OFFLOAD);
    4518                 :          0 :         org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
    4519         [ #  # ]:          0 :         if (cur != org) {
    4520         [ #  # ]:          0 :                 if (cur)
    4521                 :          0 :                         dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    4522                 :            :                 else
    4523                 :          0 :                         dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    4524                 :            :                 mask |= RTE_ETH_VLAN_STRIP_MASK;
    4525                 :            :         }
    4526                 :            : 
    4527                 :          0 :         cur = !!(offload_mask & RTE_ETH_VLAN_FILTER_OFFLOAD);
    4528                 :          0 :         org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER);
    4529         [ #  # ]:          0 :         if (cur != org) {
    4530         [ #  # ]:          0 :                 if (cur)
    4531                 :          0 :                         dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
    4532                 :            :                 else
    4533                 :          0 :                         dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
    4534                 :          0 :                 mask |= RTE_ETH_VLAN_FILTER_MASK;
    4535                 :            :         }
    4536                 :            : 
    4537                 :          0 :         cur = !!(offload_mask & RTE_ETH_VLAN_EXTEND_OFFLOAD);
    4538                 :          0 :         org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
    4539         [ #  # ]:          0 :         if (cur != org) {
    4540         [ #  # ]:          0 :                 if (cur)
    4541                 :          0 :                         dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
    4542                 :            :                 else
    4543                 :          0 :                         dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
    4544                 :          0 :                 mask |= RTE_ETH_VLAN_EXTEND_MASK;
    4545                 :            :         }
    4546                 :            : 
    4547                 :          0 :         cur = !!(offload_mask & RTE_ETH_QINQ_STRIP_OFFLOAD);
    4548                 :          0 :         org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP);
    4549         [ #  # ]:          0 :         if (cur != org) {
    4550         [ #  # ]:          0 :                 if (cur)
    4551                 :          0 :                         dev_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
    4552                 :            :                 else
    4553                 :          0 :                         dev_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
    4554                 :          0 :                 mask |= RTE_ETH_QINQ_STRIP_MASK;
    4555                 :            :         }
    4556                 :            : 
    4557                 :            :         /*no change*/
    4558         [ #  # ]:          0 :         if (mask == 0)
    4559                 :            :                 return ret;
    4560                 :            : 
    4561                 :          0 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    4562         [ #  # ]:          0 :         if (ret != 0)
    4563                 :            :                 return ret;
    4564                 :            : 
    4565                 :            :         /* Rx VLAN offloading must be within its device capabilities */
    4566         [ #  # ]:          0 :         if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) {
    4567                 :          0 :                 new_offloads = dev_offloads & ~orig_offloads;
    4568                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4569                 :            :                         "Ethdev port_id=%u requested new added VLAN offloads "
    4570                 :            :                         "0x%" PRIx64 " must be within Rx offloads capabilities "
    4571                 :            :                         "0x%" PRIx64 " in %s()",
    4572                 :            :                         port_id, new_offloads, dev_info.rx_offload_capa,
    4573                 :            :                         __func__);
    4574                 :          0 :                 return -EINVAL;
    4575                 :            :         }
    4576                 :            : 
    4577         [ #  # ]:          0 :         if (dev->dev_ops->vlan_offload_set == NULL)
    4578                 :            :                 return -ENOTSUP;
    4579                 :          0 :         dev->data->dev_conf.rxmode.offloads = dev_offloads;
    4580                 :          0 :         ret = dev->dev_ops->vlan_offload_set(dev, mask);
    4581         [ #  # ]:          0 :         if (ret) {
    4582                 :            :                 /* hit an error restore  original values */
    4583                 :          0 :                 dev->data->dev_conf.rxmode.offloads = orig_offloads;
    4584                 :            :         }
    4585                 :            : 
    4586                 :          0 :         ret = eth_err(port_id, ret);
    4587                 :            : 
    4588                 :          0 :         rte_ethdev_trace_set_vlan_offload(port_id, offload_mask, ret);
    4589                 :            : 
    4590                 :          0 :         return ret;
    4591                 :            : }
    4592                 :            : 
    4593                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_vlan_offload)
    4594                 :            : int
    4595                 :          1 : rte_eth_dev_get_vlan_offload(uint16_t port_id)
    4596                 :            : {
    4597                 :            :         struct rte_eth_dev *dev;
    4598                 :            :         uint64_t *dev_offloads;
    4599                 :            :         int ret = 0;
    4600                 :            : 
    4601         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4602                 :            :         dev = &rte_eth_devices[port_id];
    4603                 :          1 :         dev_offloads = &dev->data->dev_conf.rxmode.offloads;
    4604                 :            : 
    4605         [ -  + ]:          1 :         if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
    4606                 :            :                 ret |= RTE_ETH_VLAN_STRIP_OFFLOAD;
    4607                 :            : 
    4608         [ -  + ]:          1 :         if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
    4609                 :          0 :                 ret |= RTE_ETH_VLAN_FILTER_OFFLOAD;
    4610                 :            : 
    4611         [ -  + ]:          1 :         if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
    4612                 :          0 :                 ret |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
    4613                 :            : 
    4614         [ -  + ]:          1 :         if (*dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
    4615                 :          0 :                 ret |= RTE_ETH_QINQ_STRIP_OFFLOAD;
    4616                 :            : 
    4617                 :          1 :         rte_ethdev_trace_get_vlan_offload(port_id, ret);
    4618                 :            : 
    4619                 :          1 :         return ret;
    4620                 :            : }
    4621                 :            : 
    4622                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_pvid)
    4623                 :            : int
    4624                 :          0 : rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
    4625                 :            : {
    4626                 :            :         struct rte_eth_dev *dev;
    4627                 :            :         int ret;
    4628                 :            : 
    4629         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4630                 :          0 :         dev = &rte_eth_devices[port_id];
    4631                 :            : 
    4632         [ #  # ]:          0 :         if (dev->dev_ops->vlan_pvid_set == NULL)
    4633                 :            :                 return -ENOTSUP;
    4634                 :          0 :         ret = eth_err(port_id, dev->dev_ops->vlan_pvid_set(dev, pvid, on));
    4635                 :            : 
    4636                 :          0 :         rte_ethdev_trace_set_vlan_pvid(port_id, pvid, on, ret);
    4637                 :            : 
    4638                 :          0 :         return ret;
    4639                 :            : }
    4640                 :            : 
    4641                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_get)
    4642                 :            : int
    4643                 :          1 : rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
    4644                 :            : {
    4645                 :            :         struct rte_eth_dev *dev;
    4646                 :            :         int ret;
    4647                 :            : 
    4648         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4649                 :          1 :         dev = &rte_eth_devices[port_id];
    4650                 :            : 
    4651         [ -  + ]:          1 :         if (fc_conf == NULL) {
    4652                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4653                 :            :                         "Cannot get ethdev port %u flow control config to NULL",
    4654                 :            :                         port_id);
    4655                 :          0 :                 return -EINVAL;
    4656                 :            :         }
    4657                 :            : 
    4658         [ -  + ]:          1 :         if (dev->dev_ops->flow_ctrl_get == NULL)
    4659                 :            :                 return -ENOTSUP;
    4660                 :            :         memset(fc_conf, 0, sizeof(*fc_conf));
    4661                 :          0 :         ret = eth_err(port_id, dev->dev_ops->flow_ctrl_get(dev, fc_conf));
    4662                 :            : 
    4663                 :          0 :         rte_ethdev_trace_flow_ctrl_get(port_id, fc_conf, ret);
    4664                 :            : 
    4665                 :          0 :         return ret;
    4666                 :            : }
    4667                 :            : 
    4668                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_set)
    4669                 :            : int
    4670                 :          0 : rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
    4671                 :            : {
    4672                 :            :         struct rte_eth_dev *dev;
    4673                 :            :         int ret;
    4674                 :            : 
    4675         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4676                 :          0 :         dev = &rte_eth_devices[port_id];
    4677                 :            : 
    4678         [ #  # ]:          0 :         if (fc_conf == NULL) {
    4679                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4680                 :            :                         "Cannot set ethdev port %u flow control from NULL config",
    4681                 :            :                         port_id);
    4682                 :          0 :                 return -EINVAL;
    4683                 :            :         }
    4684                 :            : 
    4685         [ #  # ]:          0 :         if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
    4686                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid send_xon, only 0/1 allowed");
    4687                 :          0 :                 return -EINVAL;
    4688                 :            :         }
    4689                 :            : 
    4690         [ #  # ]:          0 :         if (dev->dev_ops->flow_ctrl_set == NULL)
    4691                 :            :                 return -ENOTSUP;
    4692                 :          0 :         ret = eth_err(port_id, dev->dev_ops->flow_ctrl_set(dev, fc_conf));
    4693                 :            : 
    4694                 :          0 :         rte_ethdev_trace_flow_ctrl_set(port_id, fc_conf, ret);
    4695                 :            : 
    4696                 :          0 :         return ret;
    4697                 :            : }
    4698                 :            : 
    4699                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_priority_flow_ctrl_set)
    4700                 :            : int
    4701                 :          0 : rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
    4702                 :            :                                    struct rte_eth_pfc_conf *pfc_conf)
    4703                 :            : {
    4704                 :            :         struct rte_eth_dev *dev;
    4705                 :            :         int ret;
    4706                 :            : 
    4707         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4708                 :          0 :         dev = &rte_eth_devices[port_id];
    4709                 :            : 
    4710         [ #  # ]:          0 :         if (pfc_conf == NULL) {
    4711                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4712                 :            :                         "Cannot set ethdev port %u priority flow control from NULL config",
    4713                 :            :                         port_id);
    4714                 :          0 :                 return -EINVAL;
    4715                 :            :         }
    4716                 :            : 
    4717         [ #  # ]:          0 :         if (pfc_conf->priority > (RTE_ETH_DCB_NUM_USER_PRIORITIES - 1)) {
    4718                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid priority, only 0-7 allowed");
    4719                 :          0 :                 return -EINVAL;
    4720                 :            :         }
    4721                 :            : 
    4722                 :            :         /* High water, low water validation are device specific */
    4723         [ #  # ]:          0 :         if  (dev->dev_ops->priority_flow_ctrl_set == NULL)
    4724                 :            :                 return -ENOTSUP;
    4725                 :          0 :         ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_set(dev, pfc_conf));
    4726                 :            : 
    4727                 :          0 :         rte_ethdev_trace_priority_flow_ctrl_set(port_id, pfc_conf, ret);
    4728                 :            : 
    4729                 :          0 :         return ret;
    4730                 :            : }
    4731                 :            : 
    4732                 :            : static int
    4733                 :          0 : validate_rx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
    4734                 :            :                 struct rte_eth_pfc_queue_conf *pfc_queue_conf)
    4735                 :            : {
    4736         [ #  # ]:          0 :         if ((pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) ||
    4737                 :            :                         (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
    4738         [ #  # ]:          0 :                 if (pfc_queue_conf->rx_pause.tx_qid >= dev_info->nb_tx_queues) {
    4739                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    4740                 :            :                                 "PFC Tx queue not in range for Rx pause requested:%d configured:%d",
    4741                 :            :                                 pfc_queue_conf->rx_pause.tx_qid,
    4742                 :            :                                 dev_info->nb_tx_queues);
    4743                 :          0 :                         return -EINVAL;
    4744                 :            :                 }
    4745                 :            : 
    4746         [ #  # ]:          0 :                 if (pfc_queue_conf->rx_pause.tc >= tc_max) {
    4747                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    4748                 :            :                                 "PFC TC not in range for Rx pause requested:%d max:%d",
    4749                 :            :                                 pfc_queue_conf->rx_pause.tc, tc_max);
    4750                 :          0 :                         return -EINVAL;
    4751                 :            :                 }
    4752                 :            :         }
    4753                 :            : 
    4754                 :            :         return 0;
    4755                 :            : }
    4756                 :            : 
    4757                 :            : static int
    4758                 :          0 : validate_tx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
    4759                 :            :                 struct rte_eth_pfc_queue_conf *pfc_queue_conf)
    4760                 :            : {
    4761         [ #  # ]:          0 :         if ((pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) ||
    4762                 :            :                         (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
    4763         [ #  # ]:          0 :                 if (pfc_queue_conf->tx_pause.rx_qid >= dev_info->nb_rx_queues) {
    4764                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    4765                 :            :                                 "PFC Rx queue not in range for Tx pause requested:%d configured:%d",
    4766                 :            :                                 pfc_queue_conf->tx_pause.rx_qid,
    4767                 :            :                                 dev_info->nb_rx_queues);
    4768                 :          0 :                         return -EINVAL;
    4769                 :            :                 }
    4770                 :            : 
    4771         [ #  # ]:          0 :                 if (pfc_queue_conf->tx_pause.tc >= tc_max) {
    4772                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    4773                 :            :                                 "PFC TC not in range for Tx pause requested:%d max:%d",
    4774                 :            :                                 pfc_queue_conf->tx_pause.tc, tc_max);
    4775                 :          0 :                         return -EINVAL;
    4776                 :            :                 }
    4777                 :            :         }
    4778                 :            : 
    4779                 :            :         return 0;
    4780                 :            : }
    4781                 :            : 
    4782                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_info_get)
    4783                 :            : int
    4784                 :          0 : rte_eth_dev_priority_flow_ctrl_queue_info_get(uint16_t port_id,
    4785                 :            :                 struct rte_eth_pfc_queue_info *pfc_queue_info)
    4786                 :            : {
    4787                 :            :         struct rte_eth_dev *dev;
    4788                 :            :         int ret;
    4789                 :            : 
    4790         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4791                 :          0 :         dev = &rte_eth_devices[port_id];
    4792                 :            : 
    4793         [ #  # ]:          0 :         if (pfc_queue_info == NULL) {
    4794                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "PFC info param is NULL for port (%u)",
    4795                 :            :                         port_id);
    4796                 :          0 :                 return -EINVAL;
    4797                 :            :         }
    4798                 :            : 
    4799         [ #  # ]:          0 :         if (dev->dev_ops->priority_flow_ctrl_queue_info_get == NULL)
    4800                 :            :                 return -ENOTSUP;
    4801                 :          0 :         ret = eth_err(port_id,
    4802                 :            :                       dev->dev_ops->priority_flow_ctrl_queue_info_get(dev, pfc_queue_info));
    4803                 :            : 
    4804                 :          0 :         rte_ethdev_trace_priority_flow_ctrl_queue_info_get(port_id,
    4805                 :            :                                                 pfc_queue_info, ret);
    4806                 :            : 
    4807                 :          0 :         return ret;
    4808                 :            : }
    4809                 :            : 
    4810                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_configure)
    4811                 :            : int
    4812                 :          0 : rte_eth_dev_priority_flow_ctrl_queue_configure(uint16_t port_id,
    4813                 :            :                 struct rte_eth_pfc_queue_conf *pfc_queue_conf)
    4814                 :            : {
    4815                 :            :         struct rte_eth_pfc_queue_info pfc_info;
    4816                 :            :         struct rte_eth_dev_info dev_info;
    4817                 :            :         struct rte_eth_dev *dev;
    4818                 :            :         int ret;
    4819                 :            : 
    4820         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4821                 :          0 :         dev = &rte_eth_devices[port_id];
    4822                 :            : 
    4823         [ #  # ]:          0 :         if (pfc_queue_conf == NULL) {
    4824                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "PFC parameters are NULL for port (%u)",
    4825                 :            :                         port_id);
    4826                 :          0 :                 return -EINVAL;
    4827                 :            :         }
    4828                 :            : 
    4829                 :          0 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    4830         [ #  # ]:          0 :         if (ret != 0)
    4831                 :            :                 return ret;
    4832                 :            : 
    4833                 :          0 :         ret = rte_eth_dev_priority_flow_ctrl_queue_info_get(port_id, &pfc_info);
    4834         [ #  # ]:          0 :         if (ret != 0)
    4835                 :            :                 return ret;
    4836                 :            : 
    4837         [ #  # ]:          0 :         if (pfc_info.tc_max == 0) {
    4838                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port %u does not support PFC TC values",
    4839                 :            :                         port_id);
    4840                 :          0 :                 return -ENOTSUP;
    4841                 :            :         }
    4842                 :            : 
    4843                 :            :         /* Check requested mode supported or not */
    4844         [ #  # ]:          0 :         if (pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE &&
    4845         [ #  # ]:          0 :                         pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) {
    4846                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "PFC Tx pause unsupported for port (%d)",
    4847                 :            :                         port_id);
    4848                 :          0 :                 return -EINVAL;
    4849                 :            :         }
    4850                 :            : 
    4851         [ #  # ]:          0 :         if (pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE &&
    4852         [ #  # ]:          0 :                         pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) {
    4853                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "PFC Rx pause unsupported for port (%d)",
    4854                 :            :                         port_id);
    4855                 :          0 :                 return -EINVAL;
    4856                 :            :         }
    4857                 :            : 
    4858                 :            :         /* Validate Rx pause parameters */
    4859         [ #  # ]:          0 :         if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
    4860                 :            :                         pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE) {
    4861                 :          0 :                 ret = validate_rx_pause_config(&dev_info, pfc_info.tc_max,
    4862                 :            :                                 pfc_queue_conf);
    4863         [ #  # ]:          0 :                 if (ret != 0)
    4864                 :            :                         return ret;
    4865                 :            :         }
    4866                 :            : 
    4867                 :            :         /* Validate Tx pause parameters */
    4868         [ #  # ]:          0 :         if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
    4869                 :            :                         pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE) {
    4870                 :          0 :                 ret = validate_tx_pause_config(&dev_info, pfc_info.tc_max,
    4871                 :            :                                 pfc_queue_conf);
    4872         [ #  # ]:          0 :                 if (ret != 0)
    4873                 :            :                         return ret;
    4874                 :            :         }
    4875                 :            : 
    4876         [ #  # ]:          0 :         if (dev->dev_ops->priority_flow_ctrl_queue_config == NULL)
    4877                 :            :                 return -ENOTSUP;
    4878                 :          0 :         ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_queue_config(dev, pfc_queue_conf));
    4879                 :            : 
    4880                 :          0 :         rte_ethdev_trace_priority_flow_ctrl_queue_configure(port_id,
    4881                 :            :                                                 pfc_queue_conf, ret);
    4882                 :            : 
    4883                 :          0 :         return ret;
    4884                 :            : }
    4885                 :            : 
    4886                 :            : static int
    4887                 :            : eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
    4888                 :            :                         uint16_t reta_size)
    4889                 :            : {
    4890                 :            :         uint16_t i, num;
    4891                 :            : 
    4892                 :          0 :         num = (reta_size + RTE_ETH_RETA_GROUP_SIZE - 1) / RTE_ETH_RETA_GROUP_SIZE;
    4893   [ #  #  #  # ]:          0 :         for (i = 0; i < num; i++) {
    4894   [ #  #  #  # ]:          0 :                 if (reta_conf[i].mask)
    4895                 :            :                         return 0;
    4896                 :            :         }
    4897                 :            : 
    4898                 :            :         return -EINVAL;
    4899                 :            : }
    4900                 :            : 
    4901                 :            : static int
    4902                 :          0 : eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
    4903                 :            :                          uint16_t reta_size,
    4904                 :            :                          uint16_t max_rxq)
    4905                 :            : {
    4906                 :            :         uint16_t i, idx, shift;
    4907                 :            : 
    4908         [ #  # ]:          0 :         if (max_rxq == 0) {
    4909                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "No receive queue is available");
    4910                 :          0 :                 return -EINVAL;
    4911                 :            :         }
    4912                 :            : 
    4913         [ #  # ]:          0 :         for (i = 0; i < reta_size; i++) {
    4914                 :          0 :                 idx = i / RTE_ETH_RETA_GROUP_SIZE;
    4915                 :          0 :                 shift = i % RTE_ETH_RETA_GROUP_SIZE;
    4916         [ #  # ]:          0 :                 if ((reta_conf[idx].mask & RTE_BIT64(shift)) &&
    4917         [ #  # ]:          0 :                         (reta_conf[idx].reta[shift] >= max_rxq)) {
    4918                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    4919                 :            :                                 "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u",
    4920                 :            :                                 idx, shift,
    4921                 :            :                                 reta_conf[idx].reta[shift], max_rxq);
    4922                 :          0 :                         return -EINVAL;
    4923                 :            :                 }
    4924                 :            :         }
    4925                 :            : 
    4926                 :            :         return 0;
    4927                 :            : }
    4928                 :            : 
    4929                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_update)
    4930                 :            : int
    4931                 :          0 : rte_eth_dev_rss_reta_update(uint16_t port_id,
    4932                 :            :                             struct rte_eth_rss_reta_entry64 *reta_conf,
    4933                 :            :                             uint16_t reta_size)
    4934                 :            : {
    4935                 :            :         enum rte_eth_rx_mq_mode mq_mode;
    4936                 :            :         struct rte_eth_dev *dev;
    4937                 :            :         int ret;
    4938                 :            : 
    4939         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4940                 :          0 :         dev = &rte_eth_devices[port_id];
    4941                 :            : 
    4942         [ #  # ]:          0 :         if (reta_conf == NULL) {
    4943                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4944                 :            :                         "Cannot update ethdev port %u RSS RETA to NULL",
    4945                 :            :                         port_id);
    4946                 :          0 :                 return -EINVAL;
    4947                 :            :         }
    4948                 :            : 
    4949         [ #  # ]:          0 :         if (reta_size == 0) {
    4950                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4951                 :            :                         "Cannot update ethdev port %u RSS RETA with zero size",
    4952                 :            :                         port_id);
    4953                 :          0 :                 return -EINVAL;
    4954                 :            :         }
    4955                 :            : 
    4956                 :            :         /* Check mask bits */
    4957                 :          0 :         ret = eth_check_reta_mask(reta_conf, reta_size);
    4958         [ #  # ]:          0 :         if (ret < 0)
    4959                 :            :                 return ret;
    4960                 :            : 
    4961                 :            :         /* Check entry value */
    4962                 :          0 :         ret = eth_check_reta_entry(reta_conf, reta_size,
    4963                 :          0 :                                 dev->data->nb_rx_queues);
    4964         [ #  # ]:          0 :         if (ret < 0)
    4965                 :            :                 return ret;
    4966                 :            : 
    4967                 :          0 :         mq_mode = dev->data->dev_conf.rxmode.mq_mode;
    4968         [ #  # ]:          0 :         if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
    4969                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
    4970                 :          0 :                 return -ENOTSUP;
    4971                 :            :         }
    4972                 :            : 
    4973         [ #  # ]:          0 :         if (dev->dev_ops->reta_update == NULL)
    4974                 :            :                 return -ENOTSUP;
    4975                 :          0 :         ret = eth_err(port_id, dev->dev_ops->reta_update(dev, reta_conf, reta_size));
    4976                 :            : 
    4977                 :          0 :         rte_ethdev_trace_rss_reta_update(port_id, reta_conf, reta_size, ret);
    4978                 :            : 
    4979                 :          0 :         return ret;
    4980                 :            : }
    4981                 :            : 
    4982                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_query)
    4983                 :            : int
    4984                 :          0 : rte_eth_dev_rss_reta_query(uint16_t port_id,
    4985                 :            :                            struct rte_eth_rss_reta_entry64 *reta_conf,
    4986                 :            :                            uint16_t reta_size)
    4987                 :            : {
    4988                 :            :         struct rte_eth_dev *dev;
    4989                 :            :         int ret;
    4990                 :            : 
    4991         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    4992                 :          0 :         dev = &rte_eth_devices[port_id];
    4993                 :            : 
    4994         [ #  # ]:          0 :         if (reta_conf == NULL) {
    4995                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    4996                 :            :                         "Cannot query ethdev port %u RSS RETA from NULL config",
    4997                 :            :                         port_id);
    4998                 :          0 :                 return -EINVAL;
    4999                 :            :         }
    5000                 :            : 
    5001                 :            :         /* Check mask bits */
    5002                 :          0 :         ret = eth_check_reta_mask(reta_conf, reta_size);
    5003         [ #  # ]:          0 :         if (ret < 0)
    5004                 :            :                 return ret;
    5005                 :            : 
    5006         [ #  # ]:          0 :         if (dev->dev_ops->reta_query == NULL)
    5007                 :            :                 return -ENOTSUP;
    5008                 :          0 :         ret = eth_err(port_id, dev->dev_ops->reta_query(dev, reta_conf, reta_size));
    5009                 :            : 
    5010                 :          0 :         rte_ethdev_trace_rss_reta_query(port_id, reta_conf, reta_size, ret);
    5011                 :            : 
    5012                 :          0 :         return ret;
    5013                 :            : }
    5014                 :            : 
    5015                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_update)
    5016                 :            : int
    5017                 :          0 : rte_eth_dev_rss_hash_update(uint16_t port_id,
    5018                 :            :                             struct rte_eth_rss_conf *rss_conf)
    5019                 :            : {
    5020                 :            :         struct rte_eth_dev *dev;
    5021                 :          0 :         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
    5022                 :            :         enum rte_eth_rx_mq_mode mq_mode;
    5023                 :            :         int ret;
    5024                 :            : 
    5025         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5026                 :          0 :         dev = &rte_eth_devices[port_id];
    5027                 :            : 
    5028         [ #  # ]:          0 :         if (rss_conf == NULL) {
    5029                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5030                 :            :                         "Cannot update ethdev port %u RSS hash from NULL config",
    5031                 :            :                         port_id);
    5032                 :          0 :                 return -EINVAL;
    5033                 :            :         }
    5034                 :            : 
    5035                 :          0 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    5036         [ #  # ]:          0 :         if (ret != 0)
    5037                 :            :                 return ret;
    5038                 :            : 
    5039         [ #  # ]:          0 :         rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
    5040         [ #  # ]:          0 :         if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
    5041                 :            :             dev_info.flow_type_rss_offloads) {
    5042                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5043                 :            :                         "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64,
    5044                 :            :                         port_id, rss_conf->rss_hf,
    5045                 :            :                         dev_info.flow_type_rss_offloads);
    5046                 :          0 :                 return -EINVAL;
    5047                 :            :         }
    5048                 :            : 
    5049                 :          0 :         mq_mode = dev->data->dev_conf.rxmode.mq_mode;
    5050         [ #  # ]:          0 :         if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
    5051                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
    5052                 :          0 :                 return -ENOTSUP;
    5053                 :            :         }
    5054                 :            : 
    5055         [ #  # ]:          0 :         if (rss_conf->rss_key != NULL &&
    5056         [ #  # ]:          0 :             rss_conf->rss_key_len != dev_info.hash_key_size) {
    5057                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5058                 :            :                         "Ethdev port_id=%u invalid RSS key len: %u, valid value: %u",
    5059                 :            :                         port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
    5060                 :          0 :                 return -EINVAL;
    5061                 :            :         }
    5062                 :            : 
    5063         [ #  # ]:          0 :         if ((size_t)rss_conf->algorithm >= CHAR_BIT * sizeof(dev_info.rss_algo_capa) ||
    5064                 :          0 :             (dev_info.rss_algo_capa &
    5065         [ #  # ]:          0 :              RTE_ETH_HASH_ALGO_TO_CAPA(rss_conf->algorithm)) == 0) {
    5066                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5067                 :            :                         "Ethdev port_id=%u configured RSS hash algorithm (%u)"
    5068                 :            :                         "is not in the algorithm capability (0x%" PRIx32 ")",
    5069                 :            :                         port_id, rss_conf->algorithm, dev_info.rss_algo_capa);
    5070                 :          0 :                 return -EINVAL;
    5071                 :            :         }
    5072                 :            : 
    5073         [ #  # ]:          0 :         if (dev->dev_ops->rss_hash_update == NULL)
    5074                 :            :                 return -ENOTSUP;
    5075                 :          0 :         ret = eth_err(port_id, dev->dev_ops->rss_hash_update(dev, rss_conf));
    5076                 :            : 
    5077                 :          0 :         rte_ethdev_trace_rss_hash_update(port_id, rss_conf, ret);
    5078                 :            : 
    5079                 :          0 :         return ret;
    5080                 :            : }
    5081                 :            : 
    5082                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_conf_get)
    5083                 :            : int
    5084                 :          1 : rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
    5085                 :            :                               struct rte_eth_rss_conf *rss_conf)
    5086                 :            : {
    5087                 :          1 :         struct rte_eth_dev_info dev_info = { 0 };
    5088                 :            :         struct rte_eth_dev *dev;
    5089                 :            :         int ret;
    5090                 :            : 
    5091         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5092                 :          1 :         dev = &rte_eth_devices[port_id];
    5093                 :            : 
    5094         [ -  + ]:          1 :         if (rss_conf == NULL) {
    5095                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5096                 :            :                         "Cannot get ethdev port %u RSS hash config to NULL",
    5097                 :            :                         port_id);
    5098                 :          0 :                 return -EINVAL;
    5099                 :            :         }
    5100                 :            : 
    5101                 :          1 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    5102         [ +  - ]:          1 :         if (ret != 0)
    5103                 :            :                 return ret;
    5104                 :            : 
    5105         [ +  - ]:          1 :         if (rss_conf->rss_key != NULL &&
    5106         [ -  + ]:          1 :             rss_conf->rss_key_len < dev_info.hash_key_size) {
    5107                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5108                 :            :                         "Ethdev port_id=%u invalid RSS key len: %u, should not be less than: %u",
    5109                 :            :                         port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
    5110                 :          0 :                 return -EINVAL;
    5111                 :            :         }
    5112                 :            : 
    5113                 :          1 :         rss_conf->algorithm = RTE_ETH_HASH_FUNCTION_DEFAULT;
    5114                 :            : 
    5115         [ +  - ]:          1 :         if (dev->dev_ops->rss_hash_conf_get == NULL)
    5116                 :            :                 return -ENOTSUP;
    5117                 :          1 :         ret = eth_err(port_id, dev->dev_ops->rss_hash_conf_get(dev, rss_conf));
    5118                 :            : 
    5119                 :          1 :         rte_ethdev_trace_rss_hash_conf_get(port_id, rss_conf, ret);
    5120                 :            : 
    5121                 :          1 :         return ret;
    5122                 :            : }
    5123                 :            : 
    5124                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_algo_name)
    5125                 :            : const char *
    5126                 :          1 : rte_eth_dev_rss_algo_name(enum rte_eth_hash_function rss_algo)
    5127                 :            : {
    5128                 :            :         const char *name = "Unknown function";
    5129                 :            :         unsigned int i;
    5130                 :            : 
    5131         [ +  - ]:          1 :         for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
    5132         [ +  - ]:          1 :                 if (rss_algo == rte_eth_dev_rss_algo_names[i].algo)
    5133                 :          1 :                         return rte_eth_dev_rss_algo_names[i].name;
    5134                 :            :         }
    5135                 :            : 
    5136                 :            :         return name;
    5137                 :            : }
    5138                 :            : 
    5139                 :            : RTE_EXPORT_SYMBOL(rte_eth_find_rss_algo)
    5140                 :            : int
    5141                 :          0 : rte_eth_find_rss_algo(const char *name, uint32_t *algo)
    5142                 :            : {
    5143                 :            :         unsigned int i;
    5144                 :            : 
    5145         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
    5146         [ #  # ]:          0 :                 if (strcmp(name, rte_eth_dev_rss_algo_names[i].name) == 0) {
    5147                 :          0 :                         *algo = rte_eth_dev_rss_algo_names[i].algo;
    5148                 :          0 :                         return 0;
    5149                 :            :                 }
    5150                 :            :         }
    5151                 :            : 
    5152                 :            :         return -EINVAL;
    5153                 :            : }
    5154                 :            : 
    5155                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_add)
    5156                 :            : int
    5157                 :          0 : rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
    5158                 :            :                                 struct rte_eth_udp_tunnel *udp_tunnel)
    5159                 :            : {
    5160                 :            :         struct rte_eth_dev *dev;
    5161                 :            :         int ret;
    5162                 :            : 
    5163         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5164                 :          0 :         dev = &rte_eth_devices[port_id];
    5165                 :            : 
    5166         [ #  # ]:          0 :         if (udp_tunnel == NULL) {
    5167                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5168                 :            :                         "Cannot add ethdev port %u UDP tunnel port from NULL UDP tunnel",
    5169                 :            :                         port_id);
    5170                 :          0 :                 return -EINVAL;
    5171                 :            :         }
    5172                 :            : 
    5173         [ #  # ]:          0 :         if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
    5174                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
    5175                 :          0 :                 return -EINVAL;
    5176                 :            :         }
    5177                 :            : 
    5178         [ #  # ]:          0 :         if (dev->dev_ops->udp_tunnel_port_add == NULL)
    5179                 :            :                 return -ENOTSUP;
    5180                 :          0 :         ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_add(dev, udp_tunnel));
    5181                 :            : 
    5182                 :          0 :         rte_ethdev_trace_udp_tunnel_port_add(port_id, udp_tunnel, ret);
    5183                 :            : 
    5184                 :          0 :         return ret;
    5185                 :            : }
    5186                 :            : 
    5187                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_delete)
    5188                 :            : int
    5189                 :          0 : rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
    5190                 :            :                                    struct rte_eth_udp_tunnel *udp_tunnel)
    5191                 :            : {
    5192                 :            :         struct rte_eth_dev *dev;
    5193                 :            :         int ret;
    5194                 :            : 
    5195         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5196                 :          0 :         dev = &rte_eth_devices[port_id];
    5197                 :            : 
    5198         [ #  # ]:          0 :         if (udp_tunnel == NULL) {
    5199                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5200                 :            :                         "Cannot delete ethdev port %u UDP tunnel port from NULL UDP tunnel",
    5201                 :            :                         port_id);
    5202                 :          0 :                 return -EINVAL;
    5203                 :            :         }
    5204                 :            : 
    5205         [ #  # ]:          0 :         if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
    5206                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
    5207                 :          0 :                 return -EINVAL;
    5208                 :            :         }
    5209                 :            : 
    5210         [ #  # ]:          0 :         if (dev->dev_ops->udp_tunnel_port_del == NULL)
    5211                 :            :                 return -ENOTSUP;
    5212                 :          0 :         ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_del(dev, udp_tunnel));
    5213                 :            : 
    5214                 :          0 :         rte_ethdev_trace_udp_tunnel_port_delete(port_id, udp_tunnel, ret);
    5215                 :            : 
    5216                 :          0 :         return ret;
    5217                 :            : }
    5218                 :            : 
    5219                 :            : RTE_EXPORT_SYMBOL(rte_eth_led_on)
    5220                 :            : int
    5221                 :          0 : rte_eth_led_on(uint16_t port_id)
    5222                 :            : {
    5223                 :            :         struct rte_eth_dev *dev;
    5224                 :            :         int ret;
    5225                 :            : 
    5226         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5227                 :          0 :         dev = &rte_eth_devices[port_id];
    5228                 :            : 
    5229         [ #  # ]:          0 :         if (dev->dev_ops->dev_led_on == NULL)
    5230                 :            :                 return -ENOTSUP;
    5231                 :          0 :         ret = eth_err(port_id, dev->dev_ops->dev_led_on(dev));
    5232                 :            : 
    5233                 :          0 :         rte_eth_trace_led_on(port_id, ret);
    5234                 :            : 
    5235                 :          0 :         return ret;
    5236                 :            : }
    5237                 :            : 
    5238                 :            : RTE_EXPORT_SYMBOL(rte_eth_led_off)
    5239                 :            : int
    5240                 :          0 : rte_eth_led_off(uint16_t port_id)
    5241                 :            : {
    5242                 :            :         struct rte_eth_dev *dev;
    5243                 :            :         int ret;
    5244                 :            : 
    5245         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5246                 :          0 :         dev = &rte_eth_devices[port_id];
    5247                 :            : 
    5248         [ #  # ]:          0 :         if (dev->dev_ops->dev_led_off == NULL)
    5249                 :            :                 return -ENOTSUP;
    5250                 :          0 :         ret = eth_err(port_id, dev->dev_ops->dev_led_off(dev));
    5251                 :            : 
    5252                 :          0 :         rte_eth_trace_led_off(port_id, ret);
    5253                 :            : 
    5254                 :          0 :         return ret;
    5255                 :            : }
    5256                 :            : 
    5257                 :            : RTE_EXPORT_SYMBOL(rte_eth_fec_get_capability)
    5258                 :            : int
    5259                 :          0 : rte_eth_fec_get_capability(uint16_t port_id,
    5260                 :            :                            struct rte_eth_fec_capa *speed_fec_capa,
    5261                 :            :                            unsigned int num)
    5262                 :            : {
    5263                 :            :         struct rte_eth_dev *dev;
    5264                 :            :         int ret;
    5265                 :            : 
    5266         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5267                 :          0 :         dev = &rte_eth_devices[port_id];
    5268                 :            : 
    5269         [ #  # ]:          0 :         if (speed_fec_capa == NULL && num > 0) {
    5270                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5271                 :            :                         "Cannot get ethdev port %u FEC capability to NULL when array size is non zero",
    5272                 :            :                         port_id);
    5273                 :          0 :                 return -EINVAL;
    5274                 :            :         }
    5275                 :            : 
    5276         [ #  # ]:          0 :         if (dev->dev_ops->fec_get_capability == NULL)
    5277                 :            :                 return -ENOTSUP;
    5278                 :          0 :         ret = dev->dev_ops->fec_get_capability(dev, speed_fec_capa, num);
    5279                 :            : 
    5280                 :          0 :         rte_eth_trace_fec_get_capability(port_id, speed_fec_capa, num, ret);
    5281                 :            : 
    5282                 :          0 :         return ret;
    5283                 :            : }
    5284                 :            : 
    5285                 :            : RTE_EXPORT_SYMBOL(rte_eth_fec_get)
    5286                 :            : int
    5287                 :          1 : rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa)
    5288                 :            : {
    5289                 :            :         struct rte_eth_dev *dev;
    5290                 :            :         int ret;
    5291                 :            : 
    5292         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5293                 :          1 :         dev = &rte_eth_devices[port_id];
    5294                 :            : 
    5295         [ -  + ]:          1 :         if (fec_capa == NULL) {
    5296                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5297                 :            :                         "Cannot get ethdev port %u current FEC mode to NULL",
    5298                 :            :                         port_id);
    5299                 :          0 :                 return -EINVAL;
    5300                 :            :         }
    5301                 :            : 
    5302         [ -  + ]:          1 :         if (dev->dev_ops->fec_get == NULL)
    5303                 :            :                 return -ENOTSUP;
    5304                 :          0 :         ret = eth_err(port_id, dev->dev_ops->fec_get(dev, fec_capa));
    5305                 :            : 
    5306                 :          0 :         rte_eth_trace_fec_get(port_id, fec_capa, ret);
    5307                 :            : 
    5308                 :          0 :         return ret;
    5309                 :            : }
    5310                 :            : 
    5311                 :            : RTE_EXPORT_SYMBOL(rte_eth_fec_set)
    5312                 :            : int
    5313                 :          0 : rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
    5314                 :            : {
    5315                 :            :         struct rte_eth_dev *dev;
    5316                 :            :         int ret;
    5317                 :            : 
    5318         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5319                 :          0 :         dev = &rte_eth_devices[port_id];
    5320                 :            : 
    5321         [ #  # ]:          0 :         if (fec_capa == 0) {
    5322                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "At least one FEC mode should be specified");
    5323                 :          0 :                 return -EINVAL;
    5324                 :            :         }
    5325                 :            : 
    5326         [ #  # ]:          0 :         if (dev->dev_ops->fec_set == NULL)
    5327                 :            :                 return -ENOTSUP;
    5328                 :          0 :         ret = eth_err(port_id, dev->dev_ops->fec_set(dev, fec_capa));
    5329                 :            : 
    5330                 :          0 :         rte_eth_trace_fec_set(port_id, fec_capa, ret);
    5331                 :            : 
    5332                 :          0 :         return ret;
    5333                 :            : }
    5334                 :            : 
    5335                 :            : /*
    5336                 :            :  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
    5337                 :            :  * an empty spot.
    5338                 :            :  */
    5339                 :            : static int
    5340                 :          4 : eth_dev_get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
    5341                 :            : {
    5342                 :            :         struct rte_eth_dev_info dev_info;
    5343                 :          4 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
    5344                 :            :         unsigned i;
    5345                 :            :         int ret;
    5346                 :            : 
    5347                 :          4 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    5348         [ +  - ]:          4 :         if (ret != 0)
    5349                 :            :                 return -1;
    5350                 :            : 
    5351         [ +  + ]:         23 :         for (i = 0; i < dev_info.max_mac_addrs; i++)
    5352         [ +  + ]:         21 :                 if (memcmp(addr, &dev->data->mac_addrs[i],
    5353                 :            :                                 RTE_ETHER_ADDR_LEN) == 0)
    5354                 :          2 :                         return i;
    5355                 :            : 
    5356                 :            :         return -1;
    5357                 :            : }
    5358                 :            : 
    5359                 :            : static const struct rte_ether_addr null_mac_addr;
    5360                 :            : 
    5361                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_add)
    5362                 :            : int
    5363                 :          1 : rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
    5364                 :            :                         uint32_t pool)
    5365                 :            : {
    5366                 :            :         struct rte_eth_dev *dev;
    5367                 :            :         uint64_t pool_mask;
    5368                 :            :         bool vmdq;
    5369                 :            :         int index;
    5370                 :            :         int ret;
    5371                 :            : 
    5372         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5373                 :          1 :         dev = &rte_eth_devices[port_id];
    5374                 :            : 
    5375         [ -  + ]:          1 :         if (addr == NULL) {
    5376                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5377                 :            :                         "Cannot add ethdev port %u MAC address from NULL address",
    5378                 :            :                         port_id);
    5379                 :          0 :                 return -EINVAL;
    5380                 :            :         }
    5381                 :            : 
    5382         [ +  - ]:          1 :         if (dev->dev_ops->mac_addr_add == NULL)
    5383                 :            :                 return -ENOTSUP;
    5384                 :            : 
    5385         [ -  + ]:          1 :         if (rte_is_zero_ether_addr(addr)) {
    5386                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
    5387                 :            :                         port_id);
    5388                 :          0 :                 return -EINVAL;
    5389                 :            :         }
    5390         [ -  + ]:          1 :         if (pool >= RTE_ETH_64_POOLS) {
    5391                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Pool ID must be 0-%d", RTE_ETH_64_POOLS - 1);
    5392                 :          0 :                 return -EINVAL;
    5393                 :            :         }
    5394                 :          1 :         vmdq = (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0;
    5395         [ -  + ]:          1 :         if (!vmdq && pool != 0) {
    5396                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port %u: VMDq is not configured (pool %d)",
    5397                 :            :                         port_id, pool);
    5398                 :          0 :                 return -EINVAL;
    5399                 :            :         }
    5400                 :            : 
    5401                 :          1 :         index = eth_dev_get_mac_addr_index(port_id, addr);
    5402         [ +  - ]:          1 :         if (index < 0) {
    5403                 :          1 :                 index = eth_dev_get_mac_addr_index(port_id, &null_mac_addr);
    5404         [ -  + ]:          1 :                 if (index < 0) {
    5405                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
    5406                 :            :                                 port_id);
    5407                 :          0 :                         return -ENOSPC;
    5408                 :            :                 }
    5409                 :            :         } else {
    5410         [ #  # ]:          0 :                 if (!vmdq)
    5411                 :            :                         return 0;
    5412                 :            : 
    5413                 :          0 :                 pool_mask = dev->data->mac_pool_sel[index];
    5414                 :            : 
    5415                 :            :                 /* Check if both MAC address and pool is already there, and do nothing */
    5416         [ #  # ]:          0 :                 if (pool_mask & RTE_BIT64(pool))
    5417                 :            :                         return 0;
    5418                 :            :         }
    5419                 :            : 
    5420                 :            :         /* Update NIC */
    5421                 :          1 :         ret = dev->dev_ops->mac_addr_add(dev, addr, index, pool);
    5422                 :            : 
    5423         [ +  - ]:          1 :         if (ret == 0) {
    5424                 :            :                 /* Update address in NIC data structure */
    5425         [ -  + ]:          1 :                 rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
    5426                 :            : 
    5427         [ -  + ]:          1 :                 if (vmdq) {
    5428                 :            :                         /* Update pool bitmap in NIC data structure */
    5429                 :          0 :                         dev->data->mac_pool_sel[index] |= RTE_BIT64(pool);
    5430                 :            :                 }
    5431                 :            :         }
    5432                 :            : 
    5433                 :          1 :         ret = eth_err(port_id, ret);
    5434                 :            : 
    5435                 :          1 :         rte_ethdev_trace_mac_addr_add(port_id, addr, pool, ret);
    5436                 :            : 
    5437                 :          1 :         return ret;
    5438                 :            : }
    5439                 :            : 
    5440                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_remove)
    5441                 :            : int
    5442                 :          1 : rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
    5443                 :            : {
    5444                 :            :         struct rte_eth_dev *dev;
    5445                 :            :         int index;
    5446                 :            : 
    5447         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5448                 :          1 :         dev = &rte_eth_devices[port_id];
    5449                 :            : 
    5450         [ -  + ]:          1 :         if (addr == NULL) {
    5451                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5452                 :            :                         "Cannot remove ethdev port %u MAC address from NULL address",
    5453                 :            :                         port_id);
    5454                 :          0 :                 return -EINVAL;
    5455                 :            :         }
    5456                 :            : 
    5457         [ +  - ]:          1 :         if (dev->dev_ops->mac_addr_remove == NULL)
    5458                 :            :                 return -ENOTSUP;
    5459                 :            : 
    5460                 :          1 :         index = eth_dev_get_mac_addr_index(port_id, addr);
    5461         [ -  + ]:          1 :         if (index == 0) {
    5462                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5463                 :            :                         "Port %u: Cannot remove default MAC address",
    5464                 :            :                         port_id);
    5465                 :          0 :                 return -EADDRINUSE;
    5466         [ +  - ]:          1 :         } else if (index < 0)
    5467                 :            :                 return 0;  /* Do nothing if address wasn't found */
    5468                 :            : 
    5469                 :            :         /* Update NIC */
    5470                 :          1 :         dev->dev_ops->mac_addr_remove(dev, index);
    5471                 :            : 
    5472                 :            :         /* Update address in NIC data structure */
    5473         [ -  + ]:          1 :         rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
    5474                 :            : 
    5475         [ -  + ]:          1 :         if ((dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0) {
    5476                 :            :                 /* reset pool bitmap */
    5477                 :          0 :                 dev->data->mac_pool_sel[index] = 0;
    5478                 :            :         }
    5479                 :            : 
    5480                 :          1 :         rte_ethdev_trace_mac_addr_remove(port_id, addr);
    5481                 :            : 
    5482                 :          1 :         return 0;
    5483                 :            : }
    5484                 :            : 
    5485                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_default_mac_addr_set)
    5486                 :            : int
    5487                 :          1 : rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
    5488                 :            : {
    5489                 :            :         struct rte_eth_dev *dev;
    5490                 :            :         int index;
    5491                 :            :         int ret;
    5492                 :            : 
    5493         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5494                 :          1 :         dev = &rte_eth_devices[port_id];
    5495                 :            : 
    5496         [ -  + ]:          1 :         if (addr == NULL) {
    5497                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5498                 :            :                         "Cannot set ethdev port %u default MAC address from NULL address",
    5499                 :            :                         port_id);
    5500                 :          0 :                 return -EINVAL;
    5501                 :            :         }
    5502                 :            : 
    5503                 :            :         if (!rte_is_valid_assigned_ether_addr(addr))
    5504                 :            :                 return -EINVAL;
    5505                 :            : 
    5506         [ +  - ]:          1 :         if (dev->dev_ops->mac_addr_set == NULL)
    5507                 :            :                 return -ENOTSUP;
    5508                 :            : 
    5509                 :            :         /* Keep address unique in dev->data->mac_addrs[]. */
    5510                 :          1 :         index = eth_dev_get_mac_addr_index(port_id, addr);
    5511         [ -  + ]:          1 :         if (index > 0) {
    5512                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5513                 :            :                         "New default address for port %u was already in the address list. Please remove it first.",
    5514                 :            :                         port_id);
    5515                 :          0 :                 return -EEXIST;
    5516                 :            :         }
    5517                 :            : 
    5518                 :          1 :         ret = dev->dev_ops->mac_addr_set(dev, addr);
    5519         [ +  - ]:          1 :         if (ret < 0)
    5520                 :            :                 return ret;
    5521                 :            : 
    5522                 :            :         /* Update default address in NIC data structure */
    5523         [ -  + ]:          1 :         rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
    5524                 :            : 
    5525                 :          1 :         rte_ethdev_trace_default_mac_addr_set(port_id, addr);
    5526                 :            : 
    5527                 :          1 :         return 0;
    5528                 :            : }
    5529                 :            : 
    5530                 :            : 
    5531                 :            : /*
    5532                 :            :  * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
    5533                 :            :  * an empty spot.
    5534                 :            :  */
    5535                 :            : static int
    5536                 :          0 : eth_dev_get_hash_mac_addr_index(uint16_t port_id,
    5537                 :            :                 const struct rte_ether_addr *addr)
    5538                 :            : {
    5539                 :            :         struct rte_eth_dev_info dev_info;
    5540                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
    5541                 :            :         unsigned i;
    5542                 :            :         int ret;
    5543                 :            : 
    5544                 :          0 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    5545         [ #  # ]:          0 :         if (ret != 0)
    5546                 :            :                 return -1;
    5547                 :            : 
    5548         [ #  # ]:          0 :         if (!dev->data->hash_mac_addrs)
    5549                 :            :                 return -1;
    5550                 :            : 
    5551         [ #  # ]:          0 :         for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
    5552         [ #  # ]:          0 :                 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
    5553                 :            :                         RTE_ETHER_ADDR_LEN) == 0)
    5554                 :          0 :                         return i;
    5555                 :            : 
    5556                 :            :         return -1;
    5557                 :            : }
    5558                 :            : 
    5559                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_hash_table_set)
    5560                 :            : int
    5561                 :          0 : rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
    5562                 :            :                                 uint8_t on)
    5563                 :            : {
    5564                 :            :         int index;
    5565                 :            :         int ret;
    5566                 :            :         struct rte_eth_dev *dev;
    5567                 :            : 
    5568         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5569                 :          0 :         dev = &rte_eth_devices[port_id];
    5570                 :            : 
    5571         [ #  # ]:          0 :         if (addr == NULL) {
    5572                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5573                 :            :                         "Cannot set ethdev port %u unicast hash table from NULL address",
    5574                 :            :                         port_id);
    5575                 :          0 :                 return -EINVAL;
    5576                 :            :         }
    5577                 :            : 
    5578         [ #  # ]:          0 :         if (rte_is_zero_ether_addr(addr)) {
    5579                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
    5580                 :            :                         port_id);
    5581                 :          0 :                 return -EINVAL;
    5582                 :            :         }
    5583                 :            : 
    5584                 :          0 :         index = eth_dev_get_hash_mac_addr_index(port_id, addr);
    5585                 :            :         /* Check if it's already there, and do nothing */
    5586         [ #  # ]:          0 :         if ((index >= 0) && on)
    5587                 :            :                 return 0;
    5588                 :            : 
    5589         [ #  # ]:          0 :         if (index < 0) {
    5590         [ #  # ]:          0 :                 if (!on) {
    5591                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    5592                 :            :                                 "Port %u: the MAC address was not set in UTA",
    5593                 :            :                                 port_id);
    5594                 :          0 :                         return -EINVAL;
    5595                 :            :                 }
    5596                 :            : 
    5597                 :          0 :                 index = eth_dev_get_hash_mac_addr_index(port_id, &null_mac_addr);
    5598         [ #  # ]:          0 :                 if (index < 0) {
    5599                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
    5600                 :            :                                 port_id);
    5601                 :          0 :                         return -ENOSPC;
    5602                 :            :                 }
    5603                 :            :         }
    5604                 :            : 
    5605         [ #  # ]:          0 :         if (dev->dev_ops->uc_hash_table_set == NULL)
    5606                 :            :                 return -ENOTSUP;
    5607                 :          0 :         ret = dev->dev_ops->uc_hash_table_set(dev, addr, on);
    5608         [ #  # ]:          0 :         if (ret == 0) {
    5609                 :            :                 /* Update address in NIC data structure */
    5610         [ #  # ]:          0 :                 if (on)
    5611                 :          0 :                         rte_ether_addr_copy(addr,
    5612                 :          0 :                                         &dev->data->hash_mac_addrs[index]);
    5613                 :            :                 else
    5614                 :          0 :                         rte_ether_addr_copy(&null_mac_addr,
    5615                 :          0 :                                         &dev->data->hash_mac_addrs[index]);
    5616                 :            :         }
    5617                 :            : 
    5618                 :          0 :         ret = eth_err(port_id, ret);
    5619                 :            : 
    5620                 :          0 :         rte_ethdev_trace_uc_hash_table_set(port_id, on, ret);
    5621                 :            : 
    5622                 :          0 :         return ret;
    5623                 :            : }
    5624                 :            : 
    5625                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_all_hash_table_set)
    5626                 :            : int
    5627                 :          0 : rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
    5628                 :            : {
    5629                 :            :         struct rte_eth_dev *dev;
    5630                 :            :         int ret;
    5631                 :            : 
    5632         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5633                 :          0 :         dev = &rte_eth_devices[port_id];
    5634                 :            : 
    5635         [ #  # ]:          0 :         if (dev->dev_ops->uc_all_hash_table_set == NULL)
    5636                 :            :                 return -ENOTSUP;
    5637                 :          0 :         ret = eth_err(port_id, dev->dev_ops->uc_all_hash_table_set(dev, on));
    5638                 :            : 
    5639                 :          0 :         rte_ethdev_trace_uc_all_hash_table_set(port_id, on, ret);
    5640                 :            : 
    5641                 :          0 :         return ret;
    5642                 :            : }
    5643                 :            : 
    5644                 :            : RTE_EXPORT_SYMBOL(rte_eth_set_queue_rate_limit)
    5645                 :          0 : int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
    5646                 :            :                                         uint32_t tx_rate)
    5647                 :            : {
    5648                 :            :         struct rte_eth_dev *dev;
    5649                 :            :         struct rte_eth_dev_info dev_info;
    5650                 :            :         struct rte_eth_link link;
    5651                 :            :         int ret;
    5652                 :            : 
    5653         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5654                 :          0 :         dev = &rte_eth_devices[port_id];
    5655                 :            : 
    5656                 :          0 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    5657         [ #  # ]:          0 :         if (ret != 0)
    5658                 :            :                 return ret;
    5659                 :            : 
    5660                 :          0 :         link = dev->data->dev_link;
    5661                 :            : 
    5662         [ #  # ]:          0 :         if (queue_idx > dev_info.max_tx_queues) {
    5663                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5664                 :            :                         "Set queue rate limit:port %u: invalid queue ID=%u",
    5665                 :            :                         port_id, queue_idx);
    5666                 :          0 :                 return -EINVAL;
    5667                 :            :         }
    5668                 :            : 
    5669         [ #  # ]:          0 :         if (tx_rate > link.link_speed) {
    5670                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5671                 :            :                         "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d",
    5672                 :            :                         tx_rate, link.link_speed);
    5673                 :          0 :                 return -EINVAL;
    5674                 :            :         }
    5675                 :            : 
    5676         [ #  # ]:          0 :         if (dev->dev_ops->set_queue_rate_limit == NULL)
    5677                 :            :                 return -ENOTSUP;
    5678                 :          0 :         ret = eth_err(port_id, dev->dev_ops->set_queue_rate_limit(dev, queue_idx, tx_rate));
    5679                 :            : 
    5680         [ #  # ]:          0 :         rte_eth_trace_set_queue_rate_limit(port_id, queue_idx, tx_rate, ret);
    5681                 :            : 
    5682                 :          0 :         return ret;
    5683                 :            : }
    5684                 :            : 
    5685                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_get_queue_rate_limit, 26.07)
    5686                 :          0 : int rte_eth_get_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
    5687                 :            :                 uint32_t *tx_rate)
    5688                 :            : {
    5689                 :            :         struct rte_eth_dev *dev;
    5690                 :            :         int ret;
    5691                 :            : 
    5692         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5693                 :          0 :         dev = &rte_eth_devices[port_id];
    5694                 :            : 
    5695         [ #  # ]:          0 :         if (tx_rate == NULL) {
    5696                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5697                 :            :                         "Get queue rate limit:port %u: NULL tx_rate pointer",
    5698                 :            :                         port_id);
    5699                 :          0 :                 return -EINVAL;
    5700                 :            :         }
    5701                 :            : 
    5702         [ #  # ]:          0 :         if (queue_idx >= dev->data->nb_tx_queues) {
    5703                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5704                 :            :                         "Get queue rate limit:port %u: invalid queue ID=%u",
    5705                 :            :                         port_id, queue_idx);
    5706                 :          0 :                 return -EINVAL;
    5707                 :            :         }
    5708                 :            : 
    5709         [ #  # ]:          0 :         if (dev->dev_ops->get_queue_rate_limit == NULL)
    5710                 :            :                 return -ENOTSUP;
    5711                 :          0 :         ret = eth_err(port_id,
    5712                 :            :                       dev->dev_ops->get_queue_rate_limit(dev, queue_idx,
    5713                 :            :                                                          tx_rate));
    5714                 :            : 
    5715                 :          0 :         rte_eth_trace_get_queue_rate_limit(port_id, queue_idx, ret);
    5716                 :            : 
    5717                 :          0 :         return ret;
    5718                 :            : }
    5719                 :            : 
    5720                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_avail_thresh_set)
    5721                 :          0 : int rte_eth_rx_avail_thresh_set(uint16_t port_id, uint16_t queue_id,
    5722                 :            :                                uint8_t avail_thresh)
    5723                 :            : {
    5724                 :            :         struct rte_eth_dev *dev;
    5725                 :            :         int ret;
    5726                 :            : 
    5727         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5728                 :          0 :         dev = &rte_eth_devices[port_id];
    5729                 :            : 
    5730         [ #  # ]:          0 :         if (queue_id > dev->data->nb_rx_queues) {
    5731                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5732                 :            :                         "Set queue avail thresh: port %u: invalid queue ID=%u.",
    5733                 :            :                         port_id, queue_id);
    5734                 :          0 :                 return -EINVAL;
    5735                 :            :         }
    5736                 :            : 
    5737         [ #  # ]:          0 :         if (avail_thresh > 99) {
    5738                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5739                 :            :                         "Set queue avail thresh: port %u: threshold should be <= 99.",
    5740                 :            :                         port_id);
    5741                 :          0 :                 return -EINVAL;
    5742                 :            :         }
    5743         [ #  # ]:          0 :         if (dev->dev_ops->rx_queue_avail_thresh_set == NULL)
    5744                 :            :                 return -ENOTSUP;
    5745                 :          0 :         ret = eth_err(port_id,
    5746                 :            :                       dev->dev_ops->rx_queue_avail_thresh_set(dev, queue_id, avail_thresh));
    5747                 :            : 
    5748                 :          0 :         rte_eth_trace_rx_avail_thresh_set(port_id, queue_id, avail_thresh, ret);
    5749                 :            : 
    5750                 :          0 :         return ret;
    5751                 :            : }
    5752                 :            : 
    5753                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_avail_thresh_query)
    5754                 :          0 : int rte_eth_rx_avail_thresh_query(uint16_t port_id, uint16_t *queue_id,
    5755                 :            :                                  uint8_t *avail_thresh)
    5756                 :            : {
    5757                 :            :         struct rte_eth_dev *dev;
    5758                 :            :         int ret;
    5759                 :            : 
    5760         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5761                 :          0 :         dev = &rte_eth_devices[port_id];
    5762                 :            : 
    5763         [ #  # ]:          0 :         if (queue_id == NULL)
    5764                 :            :                 return -EINVAL;
    5765         [ #  # ]:          0 :         if (*queue_id >= dev->data->nb_rx_queues)
    5766                 :          0 :                 *queue_id = 0;
    5767                 :            : 
    5768         [ #  # ]:          0 :         if (dev->dev_ops->rx_queue_avail_thresh_query == NULL)
    5769                 :            :                 return -ENOTSUP;
    5770                 :          0 :         ret = eth_err(port_id,
    5771                 :            :                       dev->dev_ops->rx_queue_avail_thresh_query(dev, queue_id, avail_thresh));
    5772                 :            : 
    5773         [ #  # ]:          0 :         rte_eth_trace_rx_avail_thresh_query(port_id, *queue_id, ret);
    5774                 :            : 
    5775                 :          0 :         return ret;
    5776                 :            : }
    5777                 :            : 
    5778                 :        302 : RTE_INIT(eth_dev_init_fp_ops)
    5779                 :            : {
    5780                 :            :         uint32_t i;
    5781                 :            : 
    5782         [ +  + ]:       9966 :         for (i = 0; i != RTE_DIM(rte_eth_fp_ops); i++)
    5783                 :       9664 :                 eth_dev_fp_ops_reset(rte_eth_fp_ops + i);
    5784                 :        302 : }
    5785                 :            : 
    5786                 :        302 : RTE_INIT(eth_dev_init_cb_lists)
    5787                 :            : {
    5788                 :            :         uint16_t i;
    5789                 :            : 
    5790         [ +  + ]:       9966 :         for (i = 0; i < RTE_MAX_ETHPORTS; i++)
    5791                 :       9664 :                 TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
    5792                 :        302 : }
    5793                 :            : 
    5794                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_register)
    5795                 :            : int
    5796                 :          1 : rte_eth_dev_callback_register(uint16_t port_id,
    5797                 :            :                         enum rte_eth_event_type event,
    5798                 :            :                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
    5799                 :            : {
    5800                 :            :         struct rte_eth_dev *dev;
    5801                 :            :         struct rte_eth_dev_callback *user_cb;
    5802                 :            :         uint16_t next_port;
    5803                 :            :         uint16_t last_port;
    5804                 :            : 
    5805         [ -  + ]:          1 :         if (cb_fn == NULL) {
    5806                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5807                 :            :                         "Cannot register ethdev port %u callback from NULL",
    5808                 :            :                         port_id);
    5809                 :          0 :                 return -EINVAL;
    5810                 :            :         }
    5811                 :            : 
    5812   [ -  +  -  - ]:          1 :         if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
    5813                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
    5814                 :          0 :                 return -EINVAL;
    5815                 :            :         }
    5816                 :            : 
    5817         [ +  - ]:          1 :         if (port_id == RTE_ETH_ALL) {
    5818                 :            :                 next_port = 0;
    5819                 :            :                 last_port = RTE_MAX_ETHPORTS - 1;
    5820                 :            :         } else {
    5821                 :            :                 next_port = last_port = port_id;
    5822                 :            :         }
    5823                 :            : 
    5824                 :            :         rte_spinlock_lock(&eth_dev_cb_lock);
    5825                 :            : 
    5826                 :            :         do {
    5827                 :          1 :                 dev = &rte_eth_devices[next_port];
    5828                 :            : 
    5829         [ -  + ]:          1 :                 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
    5830         [ #  # ]:          0 :                         if (user_cb->cb_fn == cb_fn &&
    5831         [ #  # ]:          0 :                                 user_cb->cb_arg == cb_arg &&
    5832         [ #  # ]:          0 :                                 user_cb->event == event) {
    5833                 :            :                                 break;
    5834                 :            :                         }
    5835                 :            :                 }
    5836                 :            : 
    5837                 :            :                 /* create a new callback. */
    5838         [ +  - ]:          1 :                 if (user_cb == NULL) {
    5839                 :          1 :                         user_cb = rte_zmalloc("INTR_USER_CALLBACK",
    5840                 :            :                                 sizeof(struct rte_eth_dev_callback), 0);
    5841         [ +  - ]:          1 :                         if (user_cb != NULL) {
    5842                 :          1 :                                 user_cb->cb_fn = cb_fn;
    5843                 :          1 :                                 user_cb->cb_arg = cb_arg;
    5844                 :          1 :                                 user_cb->event = event;
    5845                 :          1 :                                 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
    5846                 :            :                                                   user_cb, next);
    5847                 :            :                         } else {
    5848                 :            :                                 rte_spinlock_unlock(&eth_dev_cb_lock);
    5849                 :          0 :                                 rte_eth_dev_callback_unregister(port_id, event,
    5850                 :            :                                                                 cb_fn, cb_arg);
    5851                 :          0 :                                 return -ENOMEM;
    5852                 :            :                         }
    5853                 :            : 
    5854                 :            :                 }
    5855         [ -  + ]:          1 :         } while (++next_port <= last_port);
    5856                 :            : 
    5857                 :            :         rte_spinlock_unlock(&eth_dev_cb_lock);
    5858                 :            : 
    5859                 :          1 :         rte_ethdev_trace_callback_register(port_id, event, cb_fn, cb_arg);
    5860                 :            : 
    5861                 :          1 :         return 0;
    5862                 :            : }
    5863                 :            : 
    5864                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_unregister)
    5865                 :            : int
    5866                 :          1 : rte_eth_dev_callback_unregister(uint16_t port_id,
    5867                 :            :                         enum rte_eth_event_type event,
    5868                 :            :                         rte_eth_dev_cb_fn cb_fn, void *cb_arg)
    5869                 :            : {
    5870                 :            :         int ret;
    5871                 :            :         struct rte_eth_dev *dev;
    5872                 :            :         struct rte_eth_dev_callback *cb, *next;
    5873                 :            :         uint16_t next_port;
    5874                 :            :         uint16_t last_port;
    5875                 :            : 
    5876         [ -  + ]:          1 :         if (cb_fn == NULL) {
    5877                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    5878                 :            :                         "Cannot unregister ethdev port %u callback from NULL",
    5879                 :            :                         port_id);
    5880                 :          0 :                 return -EINVAL;
    5881                 :            :         }
    5882                 :            : 
    5883   [ -  +  -  - ]:          1 :         if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
    5884                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
    5885                 :          0 :                 return -EINVAL;
    5886                 :            :         }
    5887                 :            : 
    5888         [ +  - ]:          1 :         if (port_id == RTE_ETH_ALL) {
    5889                 :            :                 next_port = 0;
    5890                 :            :                 last_port = RTE_MAX_ETHPORTS - 1;
    5891                 :            :         } else {
    5892                 :            :                 next_port = last_port = port_id;
    5893                 :            :         }
    5894                 :            : 
    5895                 :            :         rte_spinlock_lock(&eth_dev_cb_lock);
    5896                 :            : 
    5897                 :            :         do {
    5898                 :          1 :                 dev = &rte_eth_devices[next_port];
    5899                 :            :                 ret = 0;
    5900         [ +  + ]:          2 :                 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
    5901                 :            :                      cb = next) {
    5902                 :            : 
    5903                 :          1 :                         next = TAILQ_NEXT(cb, next);
    5904                 :            : 
    5905   [ +  -  +  -  :          1 :                         if (cb->cb_fn != cb_fn || cb->event != event ||
                   +  - ]
    5906         [ -  + ]:          1 :                             (cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
    5907                 :          0 :                                 continue;
    5908                 :            : 
    5909                 :            :                         /*
    5910                 :            :                          * if this callback is not executing right now,
    5911                 :            :                          * then remove it.
    5912                 :            :                          */
    5913         [ +  - ]:          1 :                         if (cb->active == 0) {
    5914         [ -  + ]:          1 :                                 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
    5915                 :          1 :                                 rte_free(cb);
    5916                 :            :                         } else {
    5917                 :            :                                 ret = -EAGAIN;
    5918                 :            :                         }
    5919                 :            :                 }
    5920         [ -  + ]:          1 :         } while (++next_port <= last_port);
    5921                 :            : 
    5922                 :            :         rte_spinlock_unlock(&eth_dev_cb_lock);
    5923                 :            : 
    5924                 :          1 :         rte_ethdev_trace_callback_unregister(port_id, event, cb_fn, cb_arg,
    5925                 :            :                                              ret);
    5926                 :            : 
    5927                 :          1 :         return ret;
    5928                 :            : }
    5929                 :            : 
    5930                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl)
    5931                 :            : int
    5932                 :          0 : rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
    5933                 :            : {
    5934                 :            :         uint32_t vec;
    5935                 :            :         struct rte_eth_dev *dev;
    5936                 :            :         struct rte_intr_handle *intr_handle;
    5937                 :            :         uint16_t qid;
    5938                 :            :         int rc;
    5939                 :            : 
    5940         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    5941                 :            :         dev = &rte_eth_devices[port_id];
    5942                 :            : 
    5943         [ #  # ]:          0 :         if (!dev->intr_handle) {
    5944                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
    5945                 :          0 :                 return -ENOTSUP;
    5946                 :            :         }
    5947                 :            : 
    5948                 :            :         intr_handle = dev->intr_handle;
    5949         [ #  # ]:          0 :         if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
    5950                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
    5951                 :          0 :                 return -EPERM;
    5952                 :            :         }
    5953                 :            : 
    5954         [ #  # ]:          0 :         for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
    5955                 :          0 :                 vec = rte_intr_vec_list_index_get(intr_handle, qid);
    5956                 :          0 :                 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
    5957                 :            : 
    5958                 :          0 :                 rte_ethdev_trace_rx_intr_ctl(port_id, qid, epfd, op, data, rc);
    5959                 :            : 
    5960         [ #  # ]:          0 :                 if (rc && rc != -EEXIST) {
    5961                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR,
    5962                 :            :                                 "p %u q %u Rx ctl error op %d epfd %d vec %u",
    5963                 :            :                                 port_id, qid, op, epfd, vec);
    5964                 :            :                 }
    5965                 :            :         }
    5966                 :            : 
    5967                 :            :         return 0;
    5968                 :            : }
    5969                 :            : 
    5970                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q_get_fd)
    5971                 :            : int
    5972                 :          0 : rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
    5973                 :            : {
    5974                 :            :         struct rte_intr_handle *intr_handle;
    5975                 :            :         struct rte_eth_dev *dev;
    5976                 :            :         unsigned int efd_idx;
    5977                 :            :         uint32_t vec;
    5978                 :            :         int fd;
    5979                 :            : 
    5980         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
    5981                 :            :         dev = &rte_eth_devices[port_id];
    5982                 :            : 
    5983         [ #  # ]:          0 :         if (queue_id >= dev->data->nb_rx_queues) {
    5984                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
    5985                 :          0 :                 return -1;
    5986                 :            :         }
    5987                 :            : 
    5988         [ #  # ]:          0 :         if (!dev->intr_handle) {
    5989                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
    5990                 :          0 :                 return -1;
    5991                 :            :         }
    5992                 :            : 
    5993                 :            :         intr_handle = dev->intr_handle;
    5994         [ #  # ]:          0 :         if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
    5995                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
    5996                 :          0 :                 return -1;
    5997                 :            :         }
    5998                 :            : 
    5999                 :          0 :         vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
    6000                 :            :         efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
    6001         [ #  # ]:          0 :                 (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
    6002                 :          0 :         fd = rte_intr_efds_index_get(intr_handle, efd_idx);
    6003                 :            : 
    6004                 :          0 :         rte_ethdev_trace_rx_intr_ctl_q_get_fd(port_id, queue_id, fd);
    6005                 :            : 
    6006                 :          0 :         return fd;
    6007                 :            : }
    6008                 :            : 
    6009                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q)
    6010                 :            : int
    6011                 :          0 : rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
    6012                 :            :                           int epfd, int op, void *data)
    6013                 :            : {
    6014                 :            :         uint32_t vec;
    6015                 :            :         struct rte_eth_dev *dev;
    6016                 :            :         struct rte_intr_handle *intr_handle;
    6017                 :            :         int rc;
    6018                 :            : 
    6019         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6020                 :            :         dev = &rte_eth_devices[port_id];
    6021                 :            : 
    6022         [ #  # ]:          0 :         if (queue_id >= dev->data->nb_rx_queues) {
    6023                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
    6024                 :          0 :                 return -EINVAL;
    6025                 :            :         }
    6026                 :            : 
    6027         [ #  # ]:          0 :         if (!dev->intr_handle) {
    6028                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
    6029                 :          0 :                 return -ENOTSUP;
    6030                 :            :         }
    6031                 :            : 
    6032                 :            :         intr_handle = dev->intr_handle;
    6033         [ #  # ]:          0 :         if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
    6034                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
    6035                 :          0 :                 return -EPERM;
    6036                 :            :         }
    6037                 :            : 
    6038                 :          0 :         vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
    6039                 :          0 :         rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
    6040                 :            : 
    6041                 :          0 :         rte_ethdev_trace_rx_intr_ctl_q(port_id, queue_id, epfd, op, data, rc);
    6042                 :            : 
    6043         [ #  # ]:          0 :         if (rc && rc != -EEXIST) {
    6044                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6045                 :            :                         "p %u q %u Rx ctl error op %d epfd %d vec %u",
    6046                 :            :                         port_id, queue_id, op, epfd, vec);
    6047                 :          0 :                 return rc;
    6048                 :            :         }
    6049                 :            : 
    6050                 :            :         return 0;
    6051                 :            : }
    6052                 :            : 
    6053                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_enable)
    6054                 :            : int
    6055                 :          0 : rte_eth_dev_rx_intr_enable(uint16_t port_id,
    6056                 :            :                            uint16_t queue_id)
    6057                 :            : {
    6058                 :            :         struct rte_eth_dev *dev;
    6059                 :            :         int ret;
    6060                 :            : 
    6061         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6062                 :          0 :         dev = &rte_eth_devices[port_id];
    6063                 :            : 
    6064                 :          0 :         ret = eth_dev_validate_rx_queue(dev, queue_id);
    6065         [ #  # ]:          0 :         if (ret != 0)
    6066                 :            :                 return ret;
    6067                 :            : 
    6068         [ #  # ]:          0 :         if (dev->dev_ops->rx_queue_intr_enable == NULL)
    6069                 :            :                 return -ENOTSUP;
    6070                 :          0 :         ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_enable(dev, queue_id));
    6071                 :            : 
    6072                 :            :         rte_ethdev_trace_rx_intr_enable(port_id, queue_id, ret);
    6073                 :            : 
    6074                 :          0 :         return ret;
    6075                 :            : }
    6076                 :            : 
    6077                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_disable)
    6078                 :            : int
    6079                 :          0 : rte_eth_dev_rx_intr_disable(uint16_t port_id,
    6080                 :            :                             uint16_t queue_id)
    6081                 :            : {
    6082                 :            :         struct rte_eth_dev *dev;
    6083                 :            :         int ret;
    6084                 :            : 
    6085         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6086                 :          0 :         dev = &rte_eth_devices[port_id];
    6087                 :            : 
    6088                 :          0 :         ret = eth_dev_validate_rx_queue(dev, queue_id);
    6089         [ #  # ]:          0 :         if (ret != 0)
    6090                 :            :                 return ret;
    6091                 :            : 
    6092         [ #  # ]:          0 :         if (dev->dev_ops->rx_queue_intr_disable == NULL)
    6093                 :            :                 return -ENOTSUP;
    6094                 :          0 :         ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_disable(dev, queue_id));
    6095                 :            : 
    6096                 :            :         rte_ethdev_trace_rx_intr_disable(port_id, queue_id, ret);
    6097                 :            : 
    6098                 :          0 :         return ret;
    6099                 :            : }
    6100                 :            : 
    6101                 :            : 
    6102                 :            : RTE_EXPORT_SYMBOL(rte_eth_add_rx_callback)
    6103                 :            : const struct rte_eth_rxtx_callback *
    6104                 :          0 : rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
    6105                 :            :                 rte_rx_callback_fn fn, void *user_param)
    6106                 :            : {
    6107                 :            : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
    6108                 :            :         rte_errno = ENOTSUP;
    6109                 :            :         return NULL;
    6110                 :            : #endif
    6111                 :            :         struct rte_eth_dev *dev;
    6112                 :            : 
    6113                 :            :         /* check input parameters */
    6114   [ #  #  #  # ]:          0 :         if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
    6115         [ #  # ]:          0 :                     queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
    6116                 :          0 :                 rte_errno = EINVAL;
    6117                 :          0 :                 return NULL;
    6118                 :            :         }
    6119                 :          0 :         dev = &rte_eth_devices[port_id];
    6120         [ #  # ]:          0 :         if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
    6121                 :          0 :                 rte_errno = EINVAL;
    6122                 :          0 :                 return NULL;
    6123                 :            :         }
    6124                 :          0 :         struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
    6125                 :            : 
    6126         [ #  # ]:          0 :         if (cb == NULL) {
    6127                 :          0 :                 rte_errno = ENOMEM;
    6128                 :          0 :                 return NULL;
    6129                 :            :         }
    6130                 :            : 
    6131                 :          0 :         cb->fn.rx = fn;
    6132                 :          0 :         cb->param = user_param;
    6133                 :            : 
    6134                 :            :         rte_spinlock_lock(&eth_dev_rx_cb_lock);
    6135                 :            :         /* Add the callbacks in fifo order. */
    6136                 :          0 :         struct rte_eth_rxtx_callback *tail =
    6137                 :            :                 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
    6138                 :            : 
    6139         [ #  # ]:          0 :         if (!tail) {
    6140                 :            :                 /* Stores to cb->fn and cb->param should complete before
    6141                 :            :                  * cb is visible to data plane.
    6142                 :            :                  */
    6143                 :          0 :                 rte_atomic_store_explicit(
    6144                 :            :                         &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
    6145                 :            :                         cb, rte_memory_order_release);
    6146                 :            : 
    6147                 :            :         } else {
    6148         [ #  # ]:          0 :                 while (tail->next)
    6149                 :            :                         tail = tail->next;
    6150                 :            :                 /* Stores to cb->fn and cb->param should complete before
    6151                 :            :                  * cb is visible to data plane.
    6152                 :            :                  */
    6153                 :          0 :                 rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
    6154                 :            :         }
    6155                 :            :         rte_spinlock_unlock(&eth_dev_rx_cb_lock);
    6156                 :            : 
    6157                 :          0 :         rte_eth_trace_add_rx_callback(port_id, queue_id, fn, user_param, cb);
    6158                 :            : 
    6159                 :          0 :         return cb;
    6160                 :            : }
    6161                 :            : 
    6162                 :            : RTE_EXPORT_SYMBOL(rte_eth_add_first_rx_callback)
    6163                 :            : const struct rte_eth_rxtx_callback *
    6164                 :          1 : rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
    6165                 :            :                 rte_rx_callback_fn fn, void *user_param)
    6166                 :            : {
    6167                 :            : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
    6168                 :            :         rte_errno = ENOTSUP;
    6169                 :            :         return NULL;
    6170                 :            : #endif
    6171                 :            :         /* check input parameters */
    6172   [ +  -  +  - ]:          1 :         if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
    6173         [ -  + ]:          1 :                 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
    6174                 :          0 :                 rte_errno = EINVAL;
    6175                 :          0 :                 return NULL;
    6176                 :            :         }
    6177                 :            : 
    6178                 :          1 :         struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
    6179                 :            : 
    6180         [ -  + ]:          1 :         if (cb == NULL) {
    6181                 :          0 :                 rte_errno = ENOMEM;
    6182                 :          0 :                 return NULL;
    6183                 :            :         }
    6184                 :            : 
    6185                 :          1 :         cb->fn.rx = fn;
    6186                 :          1 :         cb->param = user_param;
    6187                 :            : 
    6188                 :            :         rte_spinlock_lock(&eth_dev_rx_cb_lock);
    6189                 :            :         /* Add the callbacks at first position */
    6190                 :          1 :         cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
    6191                 :            :         /* Stores to cb->fn, cb->param and cb->next should complete before
    6192                 :            :          * cb is visible to data plane threads.
    6193                 :            :          */
    6194                 :          1 :         rte_atomic_store_explicit(
    6195                 :            :                 &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
    6196                 :            :                 cb, rte_memory_order_release);
    6197                 :            :         rte_spinlock_unlock(&eth_dev_rx_cb_lock);
    6198                 :            : 
    6199                 :          1 :         rte_eth_trace_add_first_rx_callback(port_id, queue_id, fn, user_param,
    6200                 :            :                                             cb);
    6201                 :            : 
    6202                 :          1 :         return cb;
    6203                 :            : }
    6204                 :            : 
    6205                 :            : RTE_EXPORT_SYMBOL(rte_eth_add_tx_callback)
    6206                 :            : const struct rte_eth_rxtx_callback *
    6207                 :          1 : rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
    6208                 :            :                 rte_tx_callback_fn fn, void *user_param)
    6209                 :            : {
    6210                 :            : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
    6211                 :            :         rte_errno = ENOTSUP;
    6212                 :            :         return NULL;
    6213                 :            : #endif
    6214                 :            :         struct rte_eth_dev *dev;
    6215                 :            : 
    6216                 :            :         /* check input parameters */
    6217   [ +  -  +  - ]:          1 :         if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
    6218         [ -  + ]:          1 :                     queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
    6219                 :          0 :                 rte_errno = EINVAL;
    6220                 :          0 :                 return NULL;
    6221                 :            :         }
    6222                 :            : 
    6223                 :          1 :         dev = &rte_eth_devices[port_id];
    6224         [ -  + ]:          1 :         if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
    6225                 :          0 :                 rte_errno = EINVAL;
    6226                 :          0 :                 return NULL;
    6227                 :            :         }
    6228                 :            : 
    6229                 :          1 :         struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
    6230                 :            : 
    6231         [ -  + ]:          1 :         if (cb == NULL) {
    6232                 :          0 :                 rte_errno = ENOMEM;
    6233                 :          0 :                 return NULL;
    6234                 :            :         }
    6235                 :            : 
    6236                 :          1 :         cb->fn.tx = fn;
    6237                 :          1 :         cb->param = user_param;
    6238                 :            : 
    6239                 :            :         rte_spinlock_lock(&eth_dev_tx_cb_lock);
    6240                 :            :         /* Add the callbacks in fifo order. */
    6241                 :          1 :         struct rte_eth_rxtx_callback *tail =
    6242                 :            :                 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
    6243                 :            : 
    6244         [ +  - ]:          1 :         if (!tail) {
    6245                 :            :                 /* Stores to cb->fn and cb->param should complete before
    6246                 :            :                  * cb is visible to data plane.
    6247                 :            :                  */
    6248                 :          1 :                 rte_atomic_store_explicit(
    6249                 :            :                         &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id],
    6250                 :            :                         cb, rte_memory_order_release);
    6251                 :            : 
    6252                 :            :         } else {
    6253         [ #  # ]:          0 :                 while (tail->next)
    6254                 :            :                         tail = tail->next;
    6255                 :            :                 /* Stores to cb->fn and cb->param should complete before
    6256                 :            :                  * cb is visible to data plane.
    6257                 :            :                  */
    6258                 :          0 :                 rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
    6259                 :            :         }
    6260                 :            :         rte_spinlock_unlock(&eth_dev_tx_cb_lock);
    6261                 :            : 
    6262                 :          1 :         rte_eth_trace_add_tx_callback(port_id, queue_id, fn, user_param, cb);
    6263                 :            : 
    6264                 :          1 :         return cb;
    6265                 :            : }
    6266                 :            : 
    6267                 :            : RTE_EXPORT_SYMBOL(rte_eth_remove_rx_callback)
    6268                 :            : int
    6269                 :          1 : rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
    6270                 :            :                 const struct rte_eth_rxtx_callback *user_cb)
    6271                 :            : {
    6272                 :            : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
    6273                 :            :         return -ENOTSUP;
    6274                 :            : #endif
    6275                 :            :         /* Check input parameters. */
    6276         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6277         [ +  - ]:          1 :         if (user_cb == NULL ||
    6278         [ +  - ]:          1 :                         queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
    6279                 :            :                 return -EINVAL;
    6280                 :            : 
    6281                 :            :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
    6282                 :            :         struct rte_eth_rxtx_callback *cb;
    6283                 :            :         RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
    6284                 :            :         int ret = -EINVAL;
    6285                 :            : 
    6286                 :            :         rte_spinlock_lock(&eth_dev_rx_cb_lock);
    6287                 :          1 :         prev_cb = &dev->post_rx_burst_cbs[queue_id];
    6288         [ +  - ]:          1 :         for (; *prev_cb != NULL; prev_cb = &cb->next) {
    6289                 :            :                 cb = *prev_cb;
    6290         [ +  - ]:          1 :                 if (cb == user_cb) {
    6291                 :            :                         /* Remove the user cb from the callback list. */
    6292                 :          1 :                         rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
    6293                 :            :                         ret = 0;
    6294                 :          1 :                         break;
    6295                 :            :                 }
    6296                 :            :         }
    6297                 :            :         rte_spinlock_unlock(&eth_dev_rx_cb_lock);
    6298                 :            : 
    6299                 :          1 :         rte_eth_trace_remove_rx_callback(port_id, queue_id, user_cb, ret);
    6300                 :            : 
    6301                 :          1 :         return ret;
    6302                 :            : }
    6303                 :            : 
    6304                 :            : RTE_EXPORT_SYMBOL(rte_eth_remove_tx_callback)
    6305                 :            : int
    6306                 :          1 : rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
    6307                 :            :                 const struct rte_eth_rxtx_callback *user_cb)
    6308                 :            : {
    6309                 :            : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
    6310                 :            :         return -ENOTSUP;
    6311                 :            : #endif
    6312                 :            :         /* Check input parameters. */
    6313         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6314         [ +  - ]:          1 :         if (user_cb == NULL ||
    6315         [ +  - ]:          1 :                         queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
    6316                 :            :                 return -EINVAL;
    6317                 :            : 
    6318                 :            :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
    6319                 :            :         int ret = -EINVAL;
    6320                 :            :         struct rte_eth_rxtx_callback *cb;
    6321                 :            :         RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
    6322                 :            : 
    6323                 :            :         rte_spinlock_lock(&eth_dev_tx_cb_lock);
    6324                 :          1 :         prev_cb = &dev->pre_tx_burst_cbs[queue_id];
    6325         [ +  - ]:          1 :         for (; *prev_cb != NULL; prev_cb = &cb->next) {
    6326                 :            :                 cb = *prev_cb;
    6327         [ +  - ]:          1 :                 if (cb == user_cb) {
    6328                 :            :                         /* Remove the user cb from the callback list. */
    6329                 :          1 :                         rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
    6330                 :            :                         ret = 0;
    6331                 :          1 :                         break;
    6332                 :            :                 }
    6333                 :            :         }
    6334                 :            :         rte_spinlock_unlock(&eth_dev_tx_cb_lock);
    6335                 :            : 
    6336                 :          1 :         rte_eth_trace_remove_tx_callback(port_id, queue_id, user_cb, ret);
    6337                 :            : 
    6338                 :          1 :         return ret;
    6339                 :            : }
    6340                 :            : 
    6341                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_queue_info_get)
    6342                 :            : int
    6343                 :          1 : rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
    6344                 :            :         struct rte_eth_rxq_info *qinfo)
    6345                 :            : {
    6346                 :            :         struct rte_eth_dev *dev;
    6347                 :            : 
    6348         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6349                 :          1 :         dev = &rte_eth_devices[port_id];
    6350                 :            : 
    6351         [ -  + ]:          1 :         if (queue_id >= dev->data->nb_rx_queues) {
    6352                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
    6353                 :          0 :                 return -EINVAL;
    6354                 :            :         }
    6355                 :            : 
    6356         [ -  + ]:          1 :         if (qinfo == NULL) {
    6357                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Rx queue %u info to NULL",
    6358                 :            :                         port_id, queue_id);
    6359                 :          0 :                 return -EINVAL;
    6360                 :            :         }
    6361                 :            : 
    6362         [ -  + ]:          1 :         if (dev->data->rx_queues == NULL ||
    6363         [ #  # ]:          0 :                         dev->data->rx_queues[queue_id] == NULL) {
    6364                 :          1 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6365                 :            :                                "Rx queue %"PRIu16" of device with port_id=%"
    6366                 :            :                                PRIu16" has not been setup",
    6367                 :            :                                queue_id, port_id);
    6368                 :          1 :                 return -EINVAL;
    6369                 :            :         }
    6370                 :            : 
    6371         [ #  # ]:          0 :         if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
    6372                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
    6373                 :            :                         "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16,
    6374                 :            :                         queue_id, port_id);
    6375                 :          0 :                 return -EINVAL;
    6376                 :            :         }
    6377                 :            : 
    6378         [ #  # ]:          0 :         if (dev->dev_ops->rxq_info_get == NULL)
    6379                 :            :                 return -ENOTSUP;
    6380                 :            : 
    6381                 :            :         memset(qinfo, 0, sizeof(*qinfo));
    6382                 :          0 :         dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
    6383         [ #  # ]:          0 :         qinfo->queue_state = dev->data->rx_queue_state[queue_id];
    6384                 :            : 
    6385                 :          0 :         rte_eth_trace_rx_queue_info_get(port_id, queue_id, qinfo);
    6386                 :            : 
    6387                 :          0 :         return 0;
    6388                 :            : }
    6389                 :            : 
    6390                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_info_get)
    6391                 :            : int
    6392                 :          1 : rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
    6393                 :            :         struct rte_eth_txq_info *qinfo)
    6394                 :            : {
    6395                 :            :         struct rte_eth_dev *dev;
    6396                 :            : 
    6397         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6398                 :          1 :         dev = &rte_eth_devices[port_id];
    6399                 :            : 
    6400         [ -  + ]:          1 :         if (queue_id >= dev->data->nb_tx_queues) {
    6401                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
    6402                 :          0 :                 return -EINVAL;
    6403                 :            :         }
    6404                 :            : 
    6405         [ -  + ]:          1 :         if (qinfo == NULL) {
    6406                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Tx queue %u info to NULL",
    6407                 :            :                         port_id, queue_id);
    6408                 :          0 :                 return -EINVAL;
    6409                 :            :         }
    6410                 :            : 
    6411         [ -  + ]:          1 :         if (dev->data->tx_queues == NULL ||
    6412         [ #  # ]:          0 :                         dev->data->tx_queues[queue_id] == NULL) {
    6413                 :          1 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6414                 :            :                                "Tx queue %"PRIu16" of device with port_id=%"
    6415                 :            :                                PRIu16" has not been setup",
    6416                 :            :                                queue_id, port_id);
    6417                 :          1 :                 return -EINVAL;
    6418                 :            :         }
    6419                 :            : 
    6420         [ #  # ]:          0 :         if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
    6421                 :          0 :                 RTE_ETHDEV_LOG_LINE(INFO,
    6422                 :            :                         "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16,
    6423                 :            :                         queue_id, port_id);
    6424                 :          0 :                 return -EINVAL;
    6425                 :            :         }
    6426                 :            : 
    6427         [ #  # ]:          0 :         if (dev->dev_ops->txq_info_get == NULL)
    6428                 :            :                 return -ENOTSUP;
    6429                 :            : 
    6430                 :            :         memset(qinfo, 0, sizeof(*qinfo));
    6431                 :          0 :         dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
    6432         [ #  # ]:          0 :         qinfo->queue_state = dev->data->tx_queue_state[queue_id];
    6433                 :            : 
    6434                 :          0 :         rte_eth_trace_tx_queue_info_get(port_id, queue_id, qinfo);
    6435                 :            : 
    6436                 :          0 :         return 0;
    6437                 :            : }
    6438                 :            : 
    6439                 :            : RTE_EXPORT_SYMBOL(rte_eth_recycle_rx_queue_info_get)
    6440                 :            : int
    6441                 :          0 : rte_eth_recycle_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
    6442                 :            :                 struct rte_eth_recycle_rxq_info *recycle_rxq_info)
    6443                 :            : {
    6444                 :            :         struct rte_eth_dev *dev;
    6445                 :            :         int ret;
    6446                 :            : 
    6447         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6448                 :          0 :         dev = &rte_eth_devices[port_id];
    6449                 :            : 
    6450                 :          0 :         ret = eth_dev_validate_rx_queue(dev, queue_id);
    6451         [ #  # ]:          0 :         if (unlikely(ret != 0))
    6452                 :            :                 return ret;
    6453                 :            : 
    6454         [ #  # ]:          0 :         if (dev->dev_ops->recycle_rxq_info_get == NULL)
    6455                 :            :                 return -ENOTSUP;
    6456                 :            : 
    6457                 :          0 :         dev->dev_ops->recycle_rxq_info_get(dev, queue_id, recycle_rxq_info);
    6458                 :            : 
    6459                 :          0 :         return 0;
    6460                 :            : }
    6461                 :            : 
    6462                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_burst_mode_get)
    6463                 :            : int
    6464                 :          0 : rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
    6465                 :            :                           struct rte_eth_burst_mode *mode)
    6466                 :            : {
    6467                 :            :         struct rte_eth_dev *dev;
    6468                 :            :         int ret;
    6469                 :            : 
    6470         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6471                 :          0 :         dev = &rte_eth_devices[port_id];
    6472                 :            : 
    6473         [ #  # ]:          0 :         if (queue_id >= dev->data->nb_rx_queues) {
    6474                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
    6475                 :          0 :                 return -EINVAL;
    6476                 :            :         }
    6477                 :            : 
    6478         [ #  # ]:          0 :         if (mode == NULL) {
    6479                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6480                 :            :                         "Cannot get ethdev port %u Rx queue %u burst mode to NULL",
    6481                 :            :                         port_id, queue_id);
    6482                 :          0 :                 return -EINVAL;
    6483                 :            :         }
    6484                 :            : 
    6485         [ #  # ]:          0 :         if (dev->dev_ops->rx_burst_mode_get == NULL)
    6486                 :            :                 return -ENOTSUP;
    6487                 :            :         memset(mode, 0, sizeof(*mode));
    6488                 :          0 :         ret = eth_err(port_id,
    6489                 :          0 :                       dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode));
    6490                 :            : 
    6491                 :          0 :         rte_eth_trace_rx_burst_mode_get(port_id, queue_id, mode, ret);
    6492                 :            : 
    6493                 :          0 :         return ret;
    6494                 :            : }
    6495                 :            : 
    6496                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_burst_mode_get)
    6497                 :            : int
    6498                 :          0 : rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
    6499                 :            :                           struct rte_eth_burst_mode *mode)
    6500                 :            : {
    6501                 :            :         struct rte_eth_dev *dev;
    6502                 :            :         int ret;
    6503                 :            : 
    6504         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6505                 :          0 :         dev = &rte_eth_devices[port_id];
    6506                 :            : 
    6507         [ #  # ]:          0 :         if (queue_id >= dev->data->nb_tx_queues) {
    6508                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
    6509                 :          0 :                 return -EINVAL;
    6510                 :            :         }
    6511                 :            : 
    6512         [ #  # ]:          0 :         if (mode == NULL) {
    6513                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6514                 :            :                         "Cannot get ethdev port %u Tx queue %u burst mode to NULL",
    6515                 :            :                         port_id, queue_id);
    6516                 :          0 :                 return -EINVAL;
    6517                 :            :         }
    6518                 :            : 
    6519         [ #  # ]:          0 :         if (dev->dev_ops->tx_burst_mode_get == NULL)
    6520                 :            :                 return -ENOTSUP;
    6521                 :            :         memset(mode, 0, sizeof(*mode));
    6522                 :          0 :         ret = eth_err(port_id,
    6523                 :          0 :                       dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
    6524                 :            : 
    6525                 :          0 :         rte_eth_trace_tx_burst_mode_get(port_id, queue_id, mode, ret);
    6526                 :            : 
    6527                 :          0 :         return ret;
    6528                 :            : }
    6529                 :            : 
    6530                 :            : RTE_EXPORT_SYMBOL(rte_eth_get_monitor_addr)
    6531                 :            : int
    6532                 :          0 : rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
    6533                 :            :                 struct rte_power_monitor_cond *pmc)
    6534                 :            : {
    6535                 :            :         struct rte_eth_dev *dev;
    6536                 :            :         int ret;
    6537                 :            : 
    6538         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6539                 :            :         dev = &rte_eth_devices[port_id];
    6540                 :            : 
    6541         [ #  # ]:          0 :         if (queue_id >= dev->data->nb_rx_queues) {
    6542                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
    6543                 :          0 :                 return -EINVAL;
    6544                 :            :         }
    6545                 :            : 
    6546         [ #  # ]:          0 :         if (pmc == NULL) {
    6547                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6548                 :            :                         "Cannot get ethdev port %u Rx queue %u power monitor condition to NULL",
    6549                 :            :                         port_id, queue_id);
    6550                 :          0 :                 return -EINVAL;
    6551                 :            :         }
    6552                 :            : 
    6553         [ #  # ]:          0 :         if (dev->dev_ops->get_monitor_addr == NULL)
    6554                 :            :                 return -ENOTSUP;
    6555                 :          0 :         ret = eth_err(port_id,
    6556                 :          0 :                 dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id], pmc));
    6557                 :            : 
    6558                 :          0 :         rte_eth_trace_get_monitor_addr(port_id, queue_id, pmc, ret);
    6559                 :            : 
    6560                 :          0 :         return ret;
    6561                 :            : }
    6562                 :            : 
    6563                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mc_addr_list)
    6564                 :            : int
    6565                 :          2 : rte_eth_dev_set_mc_addr_list(uint16_t port_id,
    6566                 :            :                              struct rte_ether_addr *mc_addr_set,
    6567                 :            :                              uint32_t nb_mc_addr)
    6568                 :            : {
    6569                 :            :         struct rte_eth_dev *dev;
    6570                 :            :         int ret;
    6571                 :            : 
    6572         [ -  + ]:          2 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6573                 :          2 :         dev = &rte_eth_devices[port_id];
    6574                 :            : 
    6575         [ +  - ]:          2 :         if (dev->dev_ops->set_mc_addr_list == NULL)
    6576                 :            :                 return -ENOTSUP;
    6577                 :          2 :         ret = eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
    6578                 :            :                                                 mc_addr_set, nb_mc_addr));
    6579                 :            : 
    6580                 :          2 :         rte_ethdev_trace_set_mc_addr_list(port_id, mc_addr_set, nb_mc_addr,
    6581                 :            :                                           ret);
    6582                 :            : 
    6583                 :          2 :         return ret;
    6584                 :            : }
    6585                 :            : 
    6586                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_enable)
    6587                 :            : int
    6588                 :          0 : rte_eth_timesync_enable(uint16_t port_id)
    6589                 :            : {
    6590                 :            :         struct rte_eth_dev *dev;
    6591                 :            :         int ret;
    6592                 :            : 
    6593         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6594                 :          0 :         dev = &rte_eth_devices[port_id];
    6595                 :            : 
    6596         [ #  # ]:          0 :         if (dev->dev_ops->timesync_enable == NULL)
    6597                 :            :                 return -ENOTSUP;
    6598                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_enable(dev));
    6599                 :            : 
    6600                 :          0 :         rte_eth_trace_timesync_enable(port_id, ret);
    6601                 :            : 
    6602                 :          0 :         return ret;
    6603                 :            : }
    6604                 :            : 
    6605                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_disable)
    6606                 :            : int
    6607                 :          0 : rte_eth_timesync_disable(uint16_t port_id)
    6608                 :            : {
    6609                 :            :         struct rte_eth_dev *dev;
    6610                 :            :         int ret;
    6611                 :            : 
    6612         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6613                 :          0 :         dev = &rte_eth_devices[port_id];
    6614                 :            : 
    6615         [ #  # ]:          0 :         if (dev->dev_ops->timesync_disable == NULL)
    6616                 :            :                 return -ENOTSUP;
    6617                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_disable(dev));
    6618                 :            : 
    6619                 :          0 :         rte_eth_trace_timesync_disable(port_id, ret);
    6620                 :            : 
    6621                 :          0 :         return ret;
    6622                 :            : }
    6623                 :            : 
    6624                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_rx_timestamp)
    6625                 :            : int
    6626                 :          0 : rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
    6627                 :            :                                    uint32_t flags)
    6628                 :            : {
    6629                 :            :         struct rte_eth_dev *dev;
    6630                 :            :         int ret;
    6631                 :            : 
    6632         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6633                 :          0 :         dev = &rte_eth_devices[port_id];
    6634                 :            : 
    6635         [ #  # ]:          0 :         if (timestamp == NULL) {
    6636                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6637                 :            :                         "Cannot read ethdev port %u Rx timestamp to NULL",
    6638                 :            :                         port_id);
    6639                 :          0 :                 return -EINVAL;
    6640                 :            :         }
    6641                 :            : 
    6642         [ #  # ]:          0 :         if (dev->dev_ops->timesync_read_rx_timestamp == NULL)
    6643                 :            :                 return -ENOTSUP;
    6644                 :            : 
    6645                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_read_rx_timestamp(dev, timestamp, flags));
    6646                 :            : 
    6647                 :            :         rte_eth_trace_timesync_read_rx_timestamp(port_id, timestamp, flags,
    6648                 :            :                                                  ret);
    6649                 :            : 
    6650                 :          0 :         return ret;
    6651                 :            : }
    6652                 :            : 
    6653                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_tx_timestamp)
    6654                 :            : int
    6655                 :          0 : rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
    6656                 :            :                                    struct timespec *timestamp)
    6657                 :            : {
    6658                 :            :         struct rte_eth_dev *dev;
    6659                 :            :         int ret;
    6660                 :            : 
    6661         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6662                 :          0 :         dev = &rte_eth_devices[port_id];
    6663                 :            : 
    6664         [ #  # ]:          0 :         if (timestamp == NULL) {
    6665                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6666                 :            :                         "Cannot read ethdev port %u Tx timestamp to NULL",
    6667                 :            :                         port_id);
    6668                 :          0 :                 return -EINVAL;
    6669                 :            :         }
    6670                 :            : 
    6671         [ #  # ]:          0 :         if (dev->dev_ops->timesync_read_tx_timestamp == NULL)
    6672                 :            :                 return -ENOTSUP;
    6673                 :            : 
    6674                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_read_tx_timestamp(dev, timestamp));
    6675                 :            : 
    6676                 :            :         rte_eth_trace_timesync_read_tx_timestamp(port_id, timestamp, ret);
    6677                 :            : 
    6678                 :          0 :         return ret;
    6679                 :            : 
    6680                 :            : }
    6681                 :            : 
    6682                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_adjust_time)
    6683                 :            : int
    6684                 :          0 : rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
    6685                 :            : {
    6686                 :            :         struct rte_eth_dev *dev;
    6687                 :            :         int ret;
    6688                 :            : 
    6689         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6690                 :          0 :         dev = &rte_eth_devices[port_id];
    6691                 :            : 
    6692         [ #  # ]:          0 :         if (dev->dev_ops->timesync_adjust_time == NULL)
    6693                 :            :                 return -ENOTSUP;
    6694                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_adjust_time(dev, delta));
    6695                 :            : 
    6696                 :            :         rte_eth_trace_timesync_adjust_time(port_id, delta, ret);
    6697                 :            : 
    6698                 :          0 :         return ret;
    6699                 :            : }
    6700                 :            : 
    6701                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_adjust_freq)
    6702                 :            : int
    6703                 :          0 : rte_eth_timesync_adjust_freq(uint16_t port_id, int64_t ppm)
    6704                 :            : {
    6705                 :            :         struct rte_eth_dev *dev;
    6706                 :            :         int ret;
    6707                 :            : 
    6708         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6709                 :          0 :         dev = &rte_eth_devices[port_id];
    6710                 :            : 
    6711         [ #  # ]:          0 :         if (dev->dev_ops->timesync_adjust_freq == NULL)
    6712                 :            :                 return -ENOTSUP;
    6713                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_adjust_freq(dev, ppm));
    6714                 :            : 
    6715                 :            :         rte_eth_trace_timesync_adjust_freq(port_id, ppm, ret);
    6716                 :            : 
    6717                 :          0 :         return ret;
    6718                 :            : }
    6719                 :            : 
    6720                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_time)
    6721                 :            : int
    6722                 :          0 : rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
    6723                 :            : {
    6724                 :            :         struct rte_eth_dev *dev;
    6725                 :            :         int ret;
    6726                 :            : 
    6727         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6728                 :          0 :         dev = &rte_eth_devices[port_id];
    6729                 :            : 
    6730         [ #  # ]:          0 :         if (timestamp == NULL) {
    6731                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6732                 :            :                         "Cannot read ethdev port %u timesync time to NULL",
    6733                 :            :                         port_id);
    6734                 :          0 :                 return -EINVAL;
    6735                 :            :         }
    6736                 :            : 
    6737         [ #  # ]:          0 :         if (dev->dev_ops->timesync_read_time == NULL)
    6738                 :            :                 return -ENOTSUP;
    6739                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_read_time(dev, timestamp));
    6740                 :            : 
    6741                 :            :         rte_eth_trace_timesync_read_time(port_id, timestamp, ret);
    6742                 :            : 
    6743                 :          0 :         return ret;
    6744                 :            : }
    6745                 :            : 
    6746                 :            : RTE_EXPORT_SYMBOL(rte_eth_timesync_write_time)
    6747                 :            : int
    6748                 :          0 : rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
    6749                 :            : {
    6750                 :            :         struct rte_eth_dev *dev;
    6751                 :            :         int ret;
    6752                 :            : 
    6753         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6754                 :          0 :         dev = &rte_eth_devices[port_id];
    6755                 :            : 
    6756         [ #  # ]:          0 :         if (timestamp == NULL) {
    6757                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6758                 :            :                         "Cannot write ethdev port %u timesync from NULL time",
    6759                 :            :                         port_id);
    6760                 :          0 :                 return -EINVAL;
    6761                 :            :         }
    6762                 :            : 
    6763         [ #  # ]:          0 :         if (dev->dev_ops->timesync_write_time == NULL)
    6764                 :            :                 return -ENOTSUP;
    6765                 :          0 :         ret = eth_err(port_id, dev->dev_ops->timesync_write_time(dev, timestamp));
    6766                 :            : 
    6767                 :          0 :         rte_eth_trace_timesync_write_time(port_id, timestamp, ret);
    6768                 :            : 
    6769                 :          0 :         return ret;
    6770                 :            : }
    6771                 :            : 
    6772                 :            : RTE_EXPORT_SYMBOL(rte_eth_read_clock)
    6773                 :            : int
    6774                 :          0 : rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
    6775                 :            : {
    6776                 :            :         struct rte_eth_dev *dev;
    6777                 :            :         int ret;
    6778                 :            : 
    6779         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6780                 :          0 :         dev = &rte_eth_devices[port_id];
    6781                 :            : 
    6782         [ #  # ]:          0 :         if (clock == NULL) {
    6783                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot read ethdev port %u clock to NULL",
    6784                 :            :                         port_id);
    6785                 :          0 :                 return -EINVAL;
    6786                 :            :         }
    6787                 :            : 
    6788         [ #  # ]:          0 :         if (dev->dev_ops->read_clock == NULL)
    6789                 :            :                 return -ENOTSUP;
    6790                 :          0 :         ret = eth_err(port_id, dev->dev_ops->read_clock(dev, clock));
    6791                 :            : 
    6792                 :          0 :         rte_eth_trace_read_clock(port_id, clock, ret);
    6793                 :            : 
    6794                 :          0 :         return ret;
    6795                 :            : }
    6796                 :            : 
    6797                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_reg_info)
    6798                 :            : int
    6799                 :          0 : rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
    6800                 :            : {
    6801                 :          0 :         struct rte_dev_reg_info reg_info = { 0 };
    6802                 :            :         int ret;
    6803                 :            : 
    6804         [ #  # ]:          0 :         if (info == NULL) {
    6805                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6806                 :            :                         "Cannot get ethdev port %u register info to NULL",
    6807                 :            :                         port_id);
    6808                 :          0 :                 return -EINVAL;
    6809                 :            :         }
    6810                 :            : 
    6811                 :          0 :         reg_info.length = info->length;
    6812                 :          0 :         reg_info.width = info->width;
    6813                 :          0 :         reg_info.offset = info->offset;
    6814                 :          0 :         reg_info.data = info->data;
    6815                 :            : 
    6816                 :          0 :         ret = rte_eth_dev_get_reg_info_ext(port_id, &reg_info);
    6817         [ #  # ]:          0 :         if (ret != 0)
    6818                 :            :                 return ret;
    6819                 :            : 
    6820                 :          0 :         info->length = reg_info.length;
    6821                 :          0 :         info->width = reg_info.width;
    6822                 :          0 :         info->version = reg_info.version;
    6823                 :          0 :         info->offset = reg_info.offset;
    6824                 :            : 
    6825                 :          0 :         return 0;
    6826                 :            : }
    6827                 :            : 
    6828                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_reg_info_ext)
    6829                 :            : int
    6830                 :          1 : rte_eth_dev_get_reg_info_ext(uint16_t port_id, struct rte_dev_reg_info *info)
    6831                 :            : {
    6832                 :            :         struct rte_eth_dev *dev;
    6833                 :            :         uint32_t i;
    6834                 :            :         int ret;
    6835                 :            : 
    6836         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6837                 :          1 :         dev = &rte_eth_devices[port_id];
    6838                 :            : 
    6839         [ -  + ]:          1 :         if (info == NULL) {
    6840                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6841                 :            :                         "Cannot get ethdev port %u register info to NULL",
    6842                 :            :                         port_id);
    6843                 :          0 :                 return -EINVAL;
    6844                 :            :         }
    6845                 :            : 
    6846   [ -  +  -  - ]:          1 :         if (info->names != NULL && info->length != 0)
    6847                 :          0 :                 memset(info->names, 0, sizeof(struct rte_eth_reg_name) * info->length);
    6848                 :            : 
    6849         [ -  + ]:          1 :         if (dev->dev_ops->get_reg == NULL)
    6850                 :            :                 return -ENOTSUP;
    6851                 :          0 :         ret = eth_err(port_id, dev->dev_ops->get_reg(dev, info));
    6852                 :            : 
    6853                 :          0 :         rte_ethdev_trace_get_reg_info(port_id, info, ret);
    6854                 :            : 
    6855                 :            :         /* Report the default names if drivers not report. */
    6856   [ #  #  #  #  :          0 :         if (ret == 0 && info->names != NULL && strlen(info->names[0].name) == 0) {
                   #  # ]
    6857         [ #  # ]:          0 :                 for (i = 0; i < info->length; i++)
    6858                 :          0 :                         snprintf(info->names[i].name, RTE_ETH_REG_NAME_SIZE,
    6859                 :          0 :                                 "index_%u", info->offset + i);
    6860                 :            :         }
    6861                 :            :         return ret;
    6862                 :            : }
    6863                 :            : 
    6864                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom_length)
    6865                 :            : int
    6866                 :          0 : rte_eth_dev_get_eeprom_length(uint16_t port_id)
    6867                 :            : {
    6868                 :            :         struct rte_eth_dev *dev;
    6869                 :            :         int ret;
    6870                 :            : 
    6871         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6872                 :          0 :         dev = &rte_eth_devices[port_id];
    6873                 :            : 
    6874         [ #  # ]:          0 :         if (dev->dev_ops->get_eeprom_length == NULL)
    6875                 :            :                 return -ENOTSUP;
    6876                 :          0 :         ret = eth_err(port_id, dev->dev_ops->get_eeprom_length(dev));
    6877                 :            : 
    6878                 :          0 :         rte_ethdev_trace_get_eeprom_length(port_id, ret);
    6879                 :            : 
    6880                 :          0 :         return ret;
    6881                 :            : }
    6882                 :            : 
    6883                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom)
    6884                 :            : int
    6885                 :          0 : rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
    6886                 :            : {
    6887                 :            :         struct rte_eth_dev *dev;
    6888                 :            :         int ret;
    6889                 :            : 
    6890         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6891                 :          0 :         dev = &rte_eth_devices[port_id];
    6892                 :            : 
    6893         [ #  # ]:          0 :         if (info == NULL) {
    6894                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6895                 :            :                         "Cannot get ethdev port %u EEPROM info to NULL",
    6896                 :            :                         port_id);
    6897                 :          0 :                 return -EINVAL;
    6898                 :            :         }
    6899                 :            : 
    6900         [ #  # ]:          0 :         if (dev->dev_ops->get_eeprom == NULL)
    6901                 :            :                 return -ENOTSUP;
    6902                 :          0 :         ret = eth_err(port_id, dev->dev_ops->get_eeprom(dev, info));
    6903                 :            : 
    6904                 :          0 :         rte_ethdev_trace_get_eeprom(port_id, info, ret);
    6905                 :            : 
    6906                 :          0 :         return ret;
    6907                 :            : }
    6908                 :            : 
    6909                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_set_eeprom)
    6910                 :            : int
    6911                 :          0 : rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
    6912                 :            : {
    6913                 :            :         struct rte_eth_dev *dev;
    6914                 :            :         int ret;
    6915                 :            : 
    6916         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6917                 :          0 :         dev = &rte_eth_devices[port_id];
    6918                 :            : 
    6919         [ #  # ]:          0 :         if (info == NULL) {
    6920                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6921                 :            :                         "Cannot set ethdev port %u EEPROM from NULL info",
    6922                 :            :                         port_id);
    6923                 :          0 :                 return -EINVAL;
    6924                 :            :         }
    6925                 :            : 
    6926         [ #  # ]:          0 :         if (dev->dev_ops->set_eeprom == NULL)
    6927                 :            :                 return -ENOTSUP;
    6928                 :          0 :         ret = eth_err(port_id, dev->dev_ops->set_eeprom(dev, info));
    6929                 :            : 
    6930                 :          0 :         rte_ethdev_trace_set_eeprom(port_id, info, ret);
    6931                 :            : 
    6932                 :          0 :         return ret;
    6933                 :            : }
    6934                 :            : 
    6935                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_module_info)
    6936                 :            : int
    6937                 :          1 : rte_eth_dev_get_module_info(uint16_t port_id,
    6938                 :            :                             struct rte_eth_dev_module_info *modinfo)
    6939                 :            : {
    6940                 :            :         struct rte_eth_dev *dev;
    6941                 :            :         int ret;
    6942                 :            : 
    6943         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6944                 :          1 :         dev = &rte_eth_devices[port_id];
    6945                 :            : 
    6946         [ -  + ]:          1 :         if (modinfo == NULL) {
    6947                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6948                 :            :                         "Cannot get ethdev port %u EEPROM module info to NULL",
    6949                 :            :                         port_id);
    6950                 :          0 :                 return -EINVAL;
    6951                 :            :         }
    6952                 :            : 
    6953         [ -  + ]:          1 :         if (dev->dev_ops->get_module_info == NULL)
    6954                 :            :                 return -ENOTSUP;
    6955                 :          0 :         ret = dev->dev_ops->get_module_info(dev, modinfo);
    6956                 :            : 
    6957                 :          0 :         rte_ethdev_trace_get_module_info(port_id, modinfo, ret);
    6958                 :            : 
    6959                 :          0 :         return ret;
    6960                 :            : }
    6961                 :            : 
    6962                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_module_eeprom)
    6963                 :            : int
    6964                 :          0 : rte_eth_dev_get_module_eeprom(uint16_t port_id,
    6965                 :            :                               struct rte_dev_eeprom_info *info)
    6966                 :            : {
    6967                 :            :         struct rte_eth_dev *dev;
    6968                 :            :         int ret;
    6969                 :            : 
    6970         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    6971                 :          0 :         dev = &rte_eth_devices[port_id];
    6972                 :            : 
    6973         [ #  # ]:          0 :         if (info == NULL) {
    6974                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6975                 :            :                         "Cannot get ethdev port %u module EEPROM info to NULL",
    6976                 :            :                         port_id);
    6977                 :          0 :                 return -EINVAL;
    6978                 :            :         }
    6979                 :            : 
    6980         [ #  # ]:          0 :         if (info->data == NULL) {
    6981                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6982                 :            :                         "Cannot get ethdev port %u module EEPROM data to NULL",
    6983                 :            :                         port_id);
    6984                 :          0 :                 return -EINVAL;
    6985                 :            :         }
    6986                 :            : 
    6987         [ #  # ]:          0 :         if (info->length == 0) {
    6988                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    6989                 :            :                         "Cannot get ethdev port %u module EEPROM to data with zero size",
    6990                 :            :                         port_id);
    6991                 :          0 :                 return -EINVAL;
    6992                 :            :         }
    6993                 :            : 
    6994         [ #  # ]:          0 :         if (dev->dev_ops->get_module_eeprom == NULL)
    6995                 :            :                 return -ENOTSUP;
    6996                 :          0 :         ret = dev->dev_ops->get_module_eeprom(dev, info);
    6997                 :            : 
    6998                 :          0 :         rte_ethdev_trace_get_module_eeprom(port_id, info, ret);
    6999                 :            : 
    7000                 :          0 :         return ret;
    7001                 :            : }
    7002                 :            : 
    7003                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_get_dcb_info)
    7004                 :            : int
    7005                 :          1 : rte_eth_dev_get_dcb_info(uint16_t port_id,
    7006                 :            :                              struct rte_eth_dcb_info *dcb_info)
    7007                 :            : {
    7008                 :            :         struct rte_eth_dev *dev;
    7009                 :            :         int ret;
    7010                 :            : 
    7011         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7012                 :          1 :         dev = &rte_eth_devices[port_id];
    7013                 :            : 
    7014         [ -  + ]:          1 :         if (dcb_info == NULL) {
    7015                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7016                 :            :                         "Cannot get ethdev port %u DCB info to NULL",
    7017                 :            :                         port_id);
    7018                 :          0 :                 return -EINVAL;
    7019                 :            :         }
    7020                 :            : 
    7021                 :            :         memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
    7022                 :            : 
    7023         [ -  + ]:          1 :         if (dev->dev_ops->get_dcb_info == NULL)
    7024                 :            :                 return -ENOTSUP;
    7025                 :          0 :         ret = eth_err(port_id, dev->dev_ops->get_dcb_info(dev, dcb_info));
    7026                 :            : 
    7027                 :          0 :         rte_ethdev_trace_get_dcb_info(port_id, dcb_info, ret);
    7028                 :            : 
    7029                 :          0 :         return ret;
    7030                 :            : }
    7031                 :            : 
    7032                 :            : static void
    7033                 :            : eth_dev_adjust_nb_desc(uint16_t *nb_desc,
    7034                 :            :                 const struct rte_eth_desc_lim *desc_lim)
    7035                 :            : {
    7036                 :            :         /* Upcast to uint32 to avoid potential overflow with RTE_ALIGN_CEIL(). */
    7037                 :          0 :         uint32_t nb_desc_32 = (uint32_t)*nb_desc;
    7038                 :            : 
    7039   [ #  #  #  # ]:          0 :         if (desc_lim->nb_align != 0)
    7040                 :          0 :                 nb_desc_32 = RTE_ALIGN_CEIL(nb_desc_32, desc_lim->nb_align);
    7041                 :            : 
    7042   [ #  #  #  # ]:          0 :         if (desc_lim->nb_max != 0)
    7043                 :          0 :                 nb_desc_32 = RTE_MIN(nb_desc_32, desc_lim->nb_max);
    7044                 :            : 
    7045                 :          0 :         nb_desc_32 = RTE_MAX(nb_desc_32, desc_lim->nb_min);
    7046                 :            : 
    7047                 :            :         /* Assign clipped u32 back to u16. */
    7048                 :          0 :         *nb_desc = (uint16_t)nb_desc_32;
    7049                 :          0 : }
    7050                 :            : 
    7051                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_adjust_nb_rx_tx_desc)
    7052                 :            : int
    7053                 :          0 : rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
    7054                 :            :                                  uint16_t *nb_rx_desc,
    7055                 :            :                                  uint16_t *nb_tx_desc)
    7056                 :            : {
    7057                 :            :         struct rte_eth_dev_info dev_info;
    7058                 :            :         int ret;
    7059                 :            : 
    7060         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7061                 :            : 
    7062                 :          0 :         ret = rte_eth_dev_info_get(port_id, &dev_info);
    7063         [ #  # ]:          0 :         if (ret != 0)
    7064                 :            :                 return ret;
    7065                 :            : 
    7066         [ #  # ]:          0 :         if (nb_rx_desc != NULL)
    7067                 :            :                 eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
    7068                 :            : 
    7069         [ #  # ]:          0 :         if (nb_tx_desc != NULL)
    7070                 :            :                 eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
    7071                 :            : 
    7072                 :          0 :         rte_ethdev_trace_adjust_nb_rx_tx_desc(port_id);
    7073                 :            : 
    7074                 :          0 :         return 0;
    7075                 :            : }
    7076                 :            : 
    7077                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_hairpin_capability_get)
    7078                 :            : int
    7079                 :          0 : rte_eth_dev_hairpin_capability_get(uint16_t port_id,
    7080                 :            :                                    struct rte_eth_hairpin_cap *cap)
    7081                 :            : {
    7082                 :            :         struct rte_eth_dev *dev;
    7083                 :            :         int ret;
    7084                 :            : 
    7085         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7086                 :          0 :         dev = &rte_eth_devices[port_id];
    7087                 :            : 
    7088         [ #  # ]:          0 :         if (cap == NULL) {
    7089                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7090                 :            :                         "Cannot get ethdev port %u hairpin capability to NULL",
    7091                 :            :                         port_id);
    7092                 :          0 :                 return -EINVAL;
    7093                 :            :         }
    7094                 :            : 
    7095         [ #  # ]:          0 :         if (dev->dev_ops->hairpin_cap_get == NULL)
    7096                 :            :                 return -ENOTSUP;
    7097                 :            :         memset(cap, 0, sizeof(*cap));
    7098                 :          0 :         ret = eth_err(port_id, dev->dev_ops->hairpin_cap_get(dev, cap));
    7099                 :            : 
    7100                 :          0 :         rte_ethdev_trace_hairpin_capability_get(port_id, cap, ret);
    7101                 :            : 
    7102                 :          0 :         return ret;
    7103                 :            : }
    7104                 :            : 
    7105                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_pool_ops_supported)
    7106                 :            : int
    7107                 :          0 : rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
    7108                 :            : {
    7109                 :            :         struct rte_eth_dev *dev;
    7110                 :            :         int ret;
    7111                 :            : 
    7112         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7113                 :          0 :         dev = &rte_eth_devices[port_id];
    7114                 :            : 
    7115         [ #  # ]:          0 :         if (pool == NULL) {
    7116                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7117                 :            :                         "Cannot test ethdev port %u mempool operation from NULL pool",
    7118                 :            :                         port_id);
    7119                 :          0 :                 return -EINVAL;
    7120                 :            :         }
    7121                 :            : 
    7122         [ #  # ]:          0 :         if (dev->dev_ops->pool_ops_supported == NULL)
    7123                 :            :                 return 1; /* all pools are supported */
    7124                 :            : 
    7125                 :          0 :         ret = dev->dev_ops->pool_ops_supported(dev, pool);
    7126                 :            : 
    7127                 :          0 :         rte_ethdev_trace_pool_ops_supported(port_id, pool, ret);
    7128                 :            : 
    7129                 :          0 :         return ret;
    7130                 :            : }
    7131                 :            : 
    7132                 :            : RTE_EXPORT_SYMBOL(rte_eth_representor_info_get)
    7133                 :            : int
    7134                 :          0 : rte_eth_representor_info_get(uint16_t port_id,
    7135                 :            :                              struct rte_eth_representor_info *info)
    7136                 :            : {
    7137                 :            :         struct rte_eth_dev *dev;
    7138                 :            :         int ret;
    7139                 :            : 
    7140         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7141                 :          0 :         dev = &rte_eth_devices[port_id];
    7142                 :            : 
    7143         [ #  # ]:          0 :         if (dev->dev_ops->representor_info_get == NULL)
    7144                 :            :                 return -ENOTSUP;
    7145                 :          0 :         ret = eth_err(port_id, dev->dev_ops->representor_info_get(dev, info));
    7146                 :            : 
    7147                 :          0 :         rte_eth_trace_representor_info_get(port_id, info, ret);
    7148                 :            : 
    7149                 :          0 :         return ret;
    7150                 :            : }
    7151                 :            : 
    7152                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_metadata_negotiate)
    7153                 :            : int
    7154                 :          0 : rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features)
    7155                 :            : {
    7156                 :            :         struct rte_eth_dev *dev;
    7157                 :            :         int ret;
    7158                 :            : 
    7159         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7160                 :          0 :         dev = &rte_eth_devices[port_id];
    7161                 :            : 
    7162         [ #  # ]:          0 :         if (dev->data->dev_configured != 0) {
    7163                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7164                 :            :                         "The port (ID=%"PRIu16") is already configured",
    7165                 :            :                         port_id);
    7166                 :          0 :                 return -EBUSY;
    7167                 :            :         }
    7168                 :            : 
    7169         [ #  # ]:          0 :         if (features == NULL) {
    7170                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid features (NULL)");
    7171                 :          0 :                 return -EINVAL;
    7172                 :            :         }
    7173                 :            : 
    7174   [ #  #  #  # ]:          0 :         if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
    7175                 :          0 :                         rte_flow_restore_info_dynflag_register() < 0)
    7176                 :          0 :                 *features &= ~RTE_ETH_RX_METADATA_TUNNEL_ID;
    7177                 :            : 
    7178         [ #  # ]:          0 :         if (dev->dev_ops->rx_metadata_negotiate == NULL)
    7179                 :            :                 return -ENOTSUP;
    7180                 :          0 :         ret = eth_err(port_id,
    7181                 :            :                       dev->dev_ops->rx_metadata_negotiate(dev, features));
    7182                 :            : 
    7183         [ #  # ]:          0 :         rte_eth_trace_rx_metadata_negotiate(port_id, *features, ret);
    7184                 :            : 
    7185                 :          0 :         return ret;
    7186                 :            : }
    7187                 :            : 
    7188                 :            : RTE_EXPORT_SYMBOL(rte_eth_ip_reassembly_capability_get)
    7189                 :            : int
    7190                 :          0 : rte_eth_ip_reassembly_capability_get(uint16_t port_id,
    7191                 :            :                 struct rte_eth_ip_reassembly_params *reassembly_capa)
    7192                 :            : {
    7193                 :            :         struct rte_eth_dev *dev;
    7194                 :            :         int ret;
    7195                 :            : 
    7196         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7197                 :          0 :         dev = &rte_eth_devices[port_id];
    7198                 :            : 
    7199         [ #  # ]:          0 :         if (dev->data->dev_configured == 0) {
    7200                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7201                 :            :                         "port_id=%u is not configured, cannot get IP reassembly capability",
    7202                 :            :                         port_id);
    7203                 :          0 :                 return -EINVAL;
    7204                 :            :         }
    7205                 :            : 
    7206         [ #  # ]:          0 :         if (reassembly_capa == NULL) {
    7207                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly capability to NULL");
    7208                 :          0 :                 return -EINVAL;
    7209                 :            :         }
    7210                 :            : 
    7211         [ #  # ]:          0 :         if (dev->dev_ops->ip_reassembly_capability_get == NULL)
    7212                 :            :                 return -ENOTSUP;
    7213                 :            :         memset(reassembly_capa, 0, sizeof(struct rte_eth_ip_reassembly_params));
    7214                 :            : 
    7215                 :          0 :         ret = eth_err(port_id,
    7216                 :          0 :                       dev->dev_ops->ip_reassembly_capability_get(dev, reassembly_capa));
    7217                 :            : 
    7218                 :          0 :         rte_eth_trace_ip_reassembly_capability_get(port_id, reassembly_capa,
    7219                 :            :                                                    ret);
    7220                 :            : 
    7221                 :          0 :         return ret;
    7222                 :            : }
    7223                 :            : 
    7224                 :            : RTE_EXPORT_SYMBOL(rte_eth_ip_reassembly_conf_get)
    7225                 :            : int
    7226                 :          0 : rte_eth_ip_reassembly_conf_get(uint16_t port_id,
    7227                 :            :                 struct rte_eth_ip_reassembly_params *conf)
    7228                 :            : {
    7229                 :            :         struct rte_eth_dev *dev;
    7230                 :            :         int ret;
    7231                 :            : 
    7232         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7233                 :          0 :         dev = &rte_eth_devices[port_id];
    7234                 :            : 
    7235         [ #  # ]:          0 :         if (dev->data->dev_configured == 0) {
    7236                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7237                 :            :                         "port_id=%u is not configured, cannot get IP reassembly configuration",
    7238                 :            :                         port_id);
    7239                 :          0 :                 return -EINVAL;
    7240                 :            :         }
    7241                 :            : 
    7242         [ #  # ]:          0 :         if (conf == NULL) {
    7243                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly info to NULL");
    7244                 :          0 :                 return -EINVAL;
    7245                 :            :         }
    7246                 :            : 
    7247         [ #  # ]:          0 :         if (dev->dev_ops->ip_reassembly_conf_get == NULL)
    7248                 :            :                 return -ENOTSUP;
    7249                 :            :         memset(conf, 0, sizeof(struct rte_eth_ip_reassembly_params));
    7250                 :          0 :         ret = eth_err(port_id,
    7251                 :          0 :                       dev->dev_ops->ip_reassembly_conf_get(dev, conf));
    7252                 :            : 
    7253                 :          0 :         rte_eth_trace_ip_reassembly_conf_get(port_id, conf, ret);
    7254                 :            : 
    7255                 :          0 :         return ret;
    7256                 :            : }
    7257                 :            : 
    7258                 :            : RTE_EXPORT_SYMBOL(rte_eth_ip_reassembly_conf_set)
    7259                 :            : int
    7260                 :          0 : rte_eth_ip_reassembly_conf_set(uint16_t port_id,
    7261                 :            :                 const struct rte_eth_ip_reassembly_params *conf)
    7262                 :            : {
    7263                 :            :         struct rte_eth_dev *dev;
    7264                 :            :         int ret;
    7265                 :            : 
    7266         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7267                 :          0 :         dev = &rte_eth_devices[port_id];
    7268                 :            : 
    7269         [ #  # ]:          0 :         if (dev->data->dev_configured == 0) {
    7270                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7271                 :            :                         "port_id=%u is not configured, cannot set IP reassembly configuration",
    7272                 :            :                         port_id);
    7273                 :          0 :                 return -EINVAL;
    7274                 :            :         }
    7275                 :            : 
    7276         [ #  # ]:          0 :         if (dev->data->dev_started != 0) {
    7277                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7278                 :            :                         "port_id=%u is started, cannot configure IP reassembly params.",
    7279                 :            :                         port_id);
    7280                 :          0 :                 return -EINVAL;
    7281                 :            :         }
    7282                 :            : 
    7283         [ #  # ]:          0 :         if (conf == NULL) {
    7284                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7285                 :            :                                 "Invalid IP reassembly configuration (NULL)");
    7286                 :          0 :                 return -EINVAL;
    7287                 :            :         }
    7288                 :            : 
    7289         [ #  # ]:          0 :         if (dev->dev_ops->ip_reassembly_conf_set == NULL)
    7290                 :            :                 return -ENOTSUP;
    7291                 :          0 :         ret = eth_err(port_id,
    7292                 :            :                       dev->dev_ops->ip_reassembly_conf_set(dev, conf));
    7293                 :            : 
    7294                 :          0 :         rte_eth_trace_ip_reassembly_conf_set(port_id, conf, ret);
    7295                 :            : 
    7296                 :          0 :         return ret;
    7297                 :            : }
    7298                 :            : 
    7299                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_priv_dump)
    7300                 :            : int
    7301                 :          1 : rte_eth_dev_priv_dump(uint16_t port_id, FILE *file)
    7302                 :            : {
    7303                 :            :         struct rte_eth_dev *dev;
    7304                 :            : 
    7305         [ -  + ]:          1 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7306                 :          1 :         dev = &rte_eth_devices[port_id];
    7307                 :            : 
    7308         [ -  + ]:          1 :         if (file == NULL) {
    7309                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
    7310                 :          0 :                 return -EINVAL;
    7311                 :            :         }
    7312                 :            : 
    7313         [ -  + ]:          1 :         if (dev->dev_ops->eth_dev_priv_dump == NULL)
    7314                 :            :                 return -ENOTSUP;
    7315                 :          0 :         return eth_err(port_id, dev->dev_ops->eth_dev_priv_dump(dev, file));
    7316                 :            : }
    7317                 :            : 
    7318                 :            : RTE_EXPORT_SYMBOL(rte_eth_rx_descriptor_dump)
    7319                 :            : int
    7320                 :          0 : rte_eth_rx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
    7321                 :            :                            uint16_t offset, uint16_t num, FILE *file)
    7322                 :            : {
    7323                 :            :         struct rte_eth_dev *dev;
    7324                 :            : 
    7325         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7326                 :          0 :         dev = &rte_eth_devices[port_id];
    7327                 :            : 
    7328         [ #  # ]:          0 :         if (queue_id >= dev->data->nb_rx_queues) {
    7329                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
    7330                 :          0 :                 return -EINVAL;
    7331                 :            :         }
    7332                 :            : 
    7333         [ #  # ]:          0 :         if (file == NULL) {
    7334                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
    7335                 :          0 :                 return -EINVAL;
    7336                 :            :         }
    7337                 :            : 
    7338         [ #  # ]:          0 :         if (dev->dev_ops->eth_rx_descriptor_dump == NULL)
    7339                 :            :                 return -ENOTSUP;
    7340                 :            : 
    7341                 :          0 :         return eth_err(port_id,
    7342                 :            :                        dev->dev_ops->eth_rx_descriptor_dump(dev, queue_id, offset, num, file));
    7343                 :            : }
    7344                 :            : 
    7345                 :            : RTE_EXPORT_SYMBOL(rte_eth_tx_descriptor_dump)
    7346                 :            : int
    7347                 :          0 : rte_eth_tx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
    7348                 :            :                            uint16_t offset, uint16_t num, FILE *file)
    7349                 :            : {
    7350                 :            :         struct rte_eth_dev *dev;
    7351                 :            : 
    7352         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7353                 :          0 :         dev = &rte_eth_devices[port_id];
    7354                 :            : 
    7355         [ #  # ]:          0 :         if (queue_id >= dev->data->nb_tx_queues) {
    7356                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
    7357                 :          0 :                 return -EINVAL;
    7358                 :            :         }
    7359                 :            : 
    7360         [ #  # ]:          0 :         if (file == NULL) {
    7361                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
    7362                 :          0 :                 return -EINVAL;
    7363                 :            :         }
    7364                 :            : 
    7365         [ #  # ]:          0 :         if (dev->dev_ops->eth_tx_descriptor_dump == NULL)
    7366                 :            :                 return -ENOTSUP;
    7367                 :            : 
    7368                 :          0 :         return eth_err(port_id,
    7369                 :            :                        dev->dev_ops->eth_tx_descriptor_dump(dev, queue_id, offset, num, file));
    7370                 :            : }
    7371                 :            : 
    7372                 :            : RTE_EXPORT_SYMBOL(rte_eth_buffer_split_get_supported_hdr_ptypes)
    7373                 :            : int
    7374                 :          0 : rte_eth_buffer_split_get_supported_hdr_ptypes(uint16_t port_id, uint32_t *ptypes, int num)
    7375                 :            : {
    7376                 :            :         size_t i;
    7377                 :            :         int j;
    7378                 :            :         struct rte_eth_dev *dev;
    7379                 :            :         const uint32_t *all_types;
    7380                 :          0 :         size_t no_of_elements = 0;
    7381                 :            : 
    7382         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7383                 :          0 :         dev = &rte_eth_devices[port_id];
    7384                 :            : 
    7385         [ #  # ]:          0 :         if (ptypes == NULL && num > 0) {
    7386                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7387                 :            :                         "Cannot get ethdev port %u supported header protocol types to NULL when array size is non zero",
    7388                 :            :                         port_id);
    7389                 :          0 :                 return -EINVAL;
    7390                 :            :         }
    7391                 :            : 
    7392         [ #  # ]:          0 :         if (dev->dev_ops->buffer_split_supported_hdr_ptypes_get == NULL)
    7393                 :            :                 return -ENOTSUP;
    7394                 :          0 :         all_types = dev->dev_ops->buffer_split_supported_hdr_ptypes_get(dev, &no_of_elements);
    7395                 :            : 
    7396         [ #  # ]:          0 :         if (all_types == NULL)
    7397                 :            :                 return 0;
    7398                 :            : 
    7399         [ #  # ]:          0 :         for (i = 0, j = 0; i < no_of_elements; ++i) {
    7400         [ #  # ]:          0 :                 if (j < num) {
    7401         [ #  # ]:          0 :                         ptypes[j] = all_types[i];
    7402                 :            : 
    7403                 :          0 :                         rte_eth_trace_buffer_split_get_supported_hdr_ptypes(
    7404                 :            :                                                         port_id, j, ptypes[j]);
    7405                 :            :                 }
    7406                 :          0 :                 j++;
    7407                 :            :         }
    7408                 :            : 
    7409                 :            :         return j;
    7410                 :            : }
    7411                 :            : 
    7412                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_count_aggr_ports)
    7413                 :          0 : int rte_eth_dev_count_aggr_ports(uint16_t port_id)
    7414                 :            : {
    7415                 :            :         struct rte_eth_dev *dev;
    7416                 :            :         int ret;
    7417                 :            : 
    7418         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7419                 :          0 :         dev = &rte_eth_devices[port_id];
    7420                 :            : 
    7421         [ #  # ]:          0 :         if (dev->dev_ops->count_aggr_ports == NULL)
    7422                 :            :                 return 0;
    7423                 :          0 :         ret = eth_err(port_id, dev->dev_ops->count_aggr_ports(dev));
    7424                 :            : 
    7425                 :          0 :         rte_eth_trace_count_aggr_ports(port_id, ret);
    7426                 :            : 
    7427                 :          0 :         return ret;
    7428                 :            : }
    7429                 :            : 
    7430                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_map_aggr_tx_affinity)
    7431                 :          0 : int rte_eth_dev_map_aggr_tx_affinity(uint16_t port_id, uint16_t tx_queue_id,
    7432                 :            :                                      uint8_t affinity)
    7433                 :            : {
    7434                 :            :         struct rte_eth_dev *dev;
    7435                 :            :         int aggr_ports;
    7436                 :            :         int ret;
    7437                 :            : 
    7438         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
    7439                 :          0 :         dev = &rte_eth_devices[port_id];
    7440                 :            : 
    7441         [ #  # ]:          0 :         if (tx_queue_id >= dev->data->nb_tx_queues) {
    7442                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
    7443                 :          0 :                 return -EINVAL;
    7444                 :            :         }
    7445                 :            : 
    7446         [ #  # ]:          0 :         if (dev->dev_ops->map_aggr_tx_affinity == NULL)
    7447                 :            :                 return -ENOTSUP;
    7448                 :            : 
    7449         [ #  # ]:          0 :         if (dev->data->dev_configured == 0) {
    7450                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7451                 :            :                         "Port %u must be configured before Tx affinity mapping",
    7452                 :            :                         port_id);
    7453                 :          0 :                 return -EINVAL;
    7454                 :            :         }
    7455                 :            : 
    7456         [ #  # ]:          0 :         if (dev->data->dev_started) {
    7457                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7458                 :            :                         "Port %u must be stopped to allow configuration",
    7459                 :            :                         port_id);
    7460                 :          0 :                 return -EBUSY;
    7461                 :            :         }
    7462                 :            : 
    7463                 :          0 :         aggr_ports = rte_eth_dev_count_aggr_ports(port_id);
    7464         [ #  # ]:          0 :         if (aggr_ports == 0) {
    7465                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7466                 :            :                         "Port %u has no aggregated port",
    7467                 :            :                         port_id);
    7468                 :          0 :                 return -ENOTSUP;
    7469                 :            :         }
    7470                 :            : 
    7471         [ #  # ]:          0 :         if (affinity > aggr_ports) {
    7472                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR,
    7473                 :            :                         "Port %u map invalid affinity %u exceeds the maximum number %u",
    7474                 :            :                         port_id, affinity, aggr_ports);
    7475                 :          0 :                 return -EINVAL;
    7476                 :            :         }
    7477                 :            : 
    7478                 :          0 :         ret = eth_err(port_id,
    7479                 :          0 :                       dev->dev_ops->map_aggr_tx_affinity(dev, tx_queue_id, affinity));
    7480                 :            : 
    7481                 :          0 :         rte_eth_trace_map_aggr_tx_affinity(port_id, tx_queue_id, affinity, ret);
    7482                 :            : 
    7483                 :          0 :         return ret;
    7484                 :            : }
    7485                 :            : 
    7486                 :            : RTE_EXPORT_SYMBOL(rte_eth_dev_logtype)
    7487         [ -  + ]:        302 : RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);

Generated by: LCOV version 1.14