LCOV - code coverage report
Current view: top level - drivers/net/bonding - rte_eth_bond_args.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 99 0.0 %
Date: 2024-01-22 16:13:49 Functions: 0 12 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 80 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_devargs.h>
       6                 :            : #include <rte_pci.h>
       7                 :            : #include <bus_driver.h>
       8                 :            : #include <bus_pci_driver.h>
       9                 :            : #include <rte_kvargs.h>
      10                 :            : 
      11                 :            : #include "rte_eth_bond.h"
      12                 :            : #include "eth_bond_private.h"
      13                 :            : 
      14                 :            : const char *pmd_bond_init_valid_arguments[] = {
      15                 :            :         PMD_BOND_MEMBER_PORT_KVARG,
      16                 :            :         PMD_BOND_PRIMARY_MEMBER_KVARG,
      17                 :            :         PMD_BOND_MODE_KVARG,
      18                 :            :         PMD_BOND_XMIT_POLICY_KVARG,
      19                 :            :         PMD_BOND_SOCKET_ID_KVARG,
      20                 :            :         PMD_BOND_MAC_ADDR_KVARG,
      21                 :            :         PMD_BOND_AGG_MODE_KVARG,
      22                 :            :         RTE_DEVARGS_KEY_DRIVER,
      23                 :            :         NULL
      24                 :            : };
      25                 :            : 
      26                 :            : static inline int
      27                 :          0 : bond_pci_addr_cmp(const struct rte_device *dev, const void *_pci_addr)
      28                 :            : {
      29                 :          0 :         const struct rte_pci_device *pdev = RTE_DEV_TO_PCI_CONST(dev);
      30                 :            :         const struct rte_pci_addr *paddr = _pci_addr;
      31                 :            : 
      32                 :          0 :         return rte_pci_addr_cmp(&pdev->addr, paddr);
      33                 :            : }
      34                 :            : 
      35                 :            : static inline int
      36                 :          0 : find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
      37                 :            : {
      38                 :            :         struct rte_bus *pci_bus;
      39                 :            :         struct rte_device *dev;
      40                 :            :         unsigned i;
      41                 :            : 
      42                 :          0 :         pci_bus = rte_bus_find_by_name("pci");
      43         [ #  # ]:          0 :         if (pci_bus == NULL) {
      44                 :          0 :                 RTE_BOND_LOG(ERR, "No PCI bus found");
      45                 :          0 :                 return -1;
      46                 :            :         }
      47                 :            : 
      48                 :          0 :         dev = pci_bus->find_device(NULL, bond_pci_addr_cmp, pci_addr);
      49         [ #  # ]:          0 :         if (dev == NULL) {
      50                 :          0 :                 RTE_BOND_LOG(ERR, "unable to find PCI device");
      51                 :          0 :                 return -1;
      52                 :            :         }
      53                 :            : 
      54         [ #  # ]:          0 :         RTE_ETH_FOREACH_DEV(i)
      55         [ #  # ]:          0 :                 if (rte_eth_devices[i].device == dev)
      56                 :          0 :                         return i;
      57                 :            :         return -1;
      58                 :            : }
      59                 :            : 
      60                 :            : static inline int
      61                 :          0 : find_port_id_by_dev_name(const char *name)
      62                 :            : {
      63                 :            :         unsigned i;
      64                 :            : 
      65         [ #  # ]:          0 :         RTE_ETH_FOREACH_DEV(i) {
      66         [ #  # ]:          0 :                 if (rte_eth_devices[i].data == NULL)
      67                 :          0 :                         continue;
      68                 :            : 
      69         [ #  # ]:          0 :                 if (strcmp(rte_eth_devices[i].device->name, name) == 0)
      70                 :          0 :                         return i;
      71                 :            :         }
      72                 :            :         return -1;
      73                 :            : }
      74                 :            : 
      75                 :            : /**
      76                 :            :  * Parses a port identifier string to a port id by pci address, then by name,
      77                 :            :  * and finally port id.
      78                 :            :  */
      79                 :            : static inline int
      80                 :          0 : parse_port_id(const char *port_str)
      81                 :            : {
      82                 :            :         struct rte_pci_addr dev_addr;
      83                 :            :         int port_id;
      84                 :            : 
      85                 :            :         /* try parsing as pci address, physical devices */
      86         [ #  # ]:          0 :         if (rte_pci_addr_parse(port_str, &dev_addr) == 0) {
      87                 :          0 :                 port_id = find_port_id_by_pci_addr(&dev_addr);
      88         [ #  # ]:          0 :                 if (port_id < 0)
      89                 :            :                         return -1;
      90                 :            :         } else {
      91                 :            :                 /* try parsing as device name, virtual devices */
      92                 :          0 :                 port_id = find_port_id_by_dev_name(port_str);
      93         [ #  # ]:          0 :                 if (port_id < 0) {
      94                 :            :                         char *end;
      95                 :          0 :                         errno = 0;
      96                 :            : 
      97                 :            :                         /* try parsing as port id */
      98                 :          0 :                         port_id = strtol(port_str, &end, 10);
      99   [ #  #  #  # ]:          0 :                         if (*end != 0 || errno != 0)
     100                 :          0 :                                 return -1;
     101                 :            :                 }
     102                 :            :         }
     103                 :            : 
     104         [ #  # ]:          0 :         if (!rte_eth_dev_is_valid_port(port_id)) {
     105                 :          0 :                 RTE_BOND_LOG(ERR, "Specified port (%s) is invalid", port_str);
     106                 :          0 :                 return -1;
     107                 :            :         }
     108                 :            :         return port_id;
     109                 :            : }
     110                 :            : 
     111                 :            : int
     112                 :          0 : bond_ethdev_parse_member_port_kvarg(const char *key,
     113                 :            :                 const char *value, void *extra_args)
     114                 :            : {
     115                 :            :         struct bond_ethdev_member_ports *member_ports;
     116                 :            : 
     117         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     118                 :            :                 return -1;
     119                 :            : 
     120                 :            :         member_ports = extra_args;
     121                 :            : 
     122         [ #  # ]:          0 :         if (strcmp(key, PMD_BOND_MEMBER_PORT_KVARG) == 0) {
     123                 :          0 :                 int port_id = parse_port_id(value);
     124         [ #  # ]:          0 :                 if (port_id < 0) {
     125                 :          0 :                         RTE_BOND_LOG(ERR, "Invalid member port value (%s) specified",
     126                 :            :                                      value);
     127                 :          0 :                         return -1;
     128                 :            :                 } else
     129                 :          0 :                         member_ports->members[member_ports->member_count++] =
     130                 :            :                                         port_id;
     131                 :            :         }
     132                 :            :         return 0;
     133                 :            : }
     134                 :            : 
     135                 :            : int
     136                 :          0 : bond_ethdev_parse_member_mode_kvarg(const char *key __rte_unused,
     137                 :            :                 const char *value, void *extra_args)
     138                 :            : {
     139                 :            :         uint8_t *mode;
     140                 :            :         char *endptr;
     141                 :            : 
     142         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     143                 :            :                 return -1;
     144                 :            : 
     145                 :            :         mode = extra_args;
     146                 :            : 
     147                 :          0 :         errno = 0;
     148                 :          0 :         *mode = strtol(value, &endptr, 10);
     149   [ #  #  #  # ]:          0 :         if (*endptr != 0 || errno != 0)
     150                 :            :                 return -1;
     151                 :            : 
     152                 :            :         /* validate mode value */
     153         [ #  # ]:          0 :         switch (*mode) {
     154                 :            :         case BONDING_MODE_ROUND_ROBIN:
     155                 :            :         case BONDING_MODE_ACTIVE_BACKUP:
     156                 :            :         case BONDING_MODE_BALANCE:
     157                 :            :         case BONDING_MODE_BROADCAST:
     158                 :            :         case BONDING_MODE_8023AD:
     159                 :            :         case BONDING_MODE_TLB:
     160                 :            :         case BONDING_MODE_ALB:
     161                 :            :                 return 0;
     162                 :          0 :         default:
     163                 :          0 :                 RTE_BOND_LOG(ERR, "Invalid member mode value (%s) specified", value);
     164                 :          0 :                 return -1;
     165                 :            :         }
     166                 :            : }
     167                 :            : 
     168                 :            : int
     169                 :          0 : bond_ethdev_parse_member_agg_mode_kvarg(const char *key __rte_unused,
     170                 :            :                 const char *value, void *extra_args)
     171                 :            : {
     172                 :            :         uint8_t *agg_mode;
     173                 :            : 
     174         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     175                 :            :                 return -1;
     176                 :            : 
     177                 :            :         agg_mode = extra_args;
     178                 :            : 
     179                 :          0 :         errno = 0;
     180         [ #  # ]:          0 :         if (strncmp(value, "stable", 6) == 0)
     181                 :          0 :                 *agg_mode = AGG_STABLE;
     182                 :            : 
     183         [ #  # ]:          0 :         if (strncmp(value, "bandwidth", 9) == 0)
     184                 :          0 :                 *agg_mode = AGG_BANDWIDTH;
     185                 :            : 
     186         [ #  # ]:          0 :         if (strncmp(value, "count", 5) == 0)
     187                 :          0 :                 *agg_mode = AGG_COUNT;
     188                 :            : 
     189         [ #  # ]:          0 :         switch (*agg_mode) {
     190                 :            :         case AGG_STABLE:
     191                 :            :         case AGG_BANDWIDTH:
     192                 :            :         case AGG_COUNT:
     193                 :            :                 return 0;
     194                 :          0 :         default:
     195                 :          0 :                 RTE_BOND_LOG(ERR, "Invalid agg mode value stable/bandwidth/count");
     196                 :          0 :                 return -1;
     197                 :            :         }
     198                 :            : }
     199                 :            : 
     200                 :            : int
     201                 :          0 : bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
     202                 :            :                 const char *value, void *extra_args)
     203                 :            : {
     204                 :            :         long socket_id;
     205                 :            :         char *endptr;
     206                 :            : 
     207         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     208                 :            :                 return -1;
     209                 :            : 
     210                 :          0 :         errno = 0;
     211                 :          0 :         socket_id = strtol(value, &endptr, 10);
     212   [ #  #  #  # ]:          0 :         if (*endptr != 0 || errno != 0)
     213                 :            :                 return -1;
     214                 :            : 
     215                 :            :         /* SOCKET_ID_ANY also consider a valid socket id */
     216         [ #  # ]:          0 :         if ((int8_t)socket_id == SOCKET_ID_ANY) {
     217                 :          0 :                 *(int *)extra_args = SOCKET_ID_ANY;
     218                 :          0 :                 return 0;
     219                 :            :         }
     220                 :            : 
     221                 :            :         /* validate socket id value */
     222         [ #  # ]:          0 :         if (socket_id >= 0 && socket_id < RTE_MAX_NUMA_NODES) {
     223                 :          0 :                 *(int *)extra_args = (int)socket_id;
     224                 :          0 :                 return 0;
     225                 :            :         }
     226                 :            :         return -1;
     227                 :            : }
     228                 :            : 
     229                 :            : int
     230                 :          0 : bond_ethdev_parse_primary_member_port_id_kvarg(const char *key __rte_unused,
     231                 :            :                 const char *value, void *extra_args)
     232                 :            : {
     233                 :            :         int primary_member_port_id;
     234                 :            : 
     235         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     236                 :            :                 return -1;
     237                 :            : 
     238                 :          0 :         primary_member_port_id = parse_port_id(value);
     239         [ #  # ]:          0 :         if (primary_member_port_id < 0)
     240                 :            :                 return -1;
     241                 :            : 
     242                 :          0 :         *(uint16_t *)extra_args = (uint16_t)primary_member_port_id;
     243                 :            : 
     244                 :          0 :         return 0;
     245                 :            : }
     246                 :            : 
     247                 :            : int
     248                 :          0 : bond_ethdev_parse_balance_xmit_policy_kvarg(const char *key __rte_unused,
     249                 :            :                 const char *value, void *extra_args)
     250                 :            : {
     251                 :            :         uint8_t *xmit_policy;
     252                 :            : 
     253         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     254                 :            :                 return -1;
     255                 :            : 
     256                 :            :         xmit_policy = extra_args;
     257                 :            : 
     258         [ #  # ]:          0 :         if (strcmp(PMD_BOND_XMIT_POLICY_LAYER2_KVARG, value) == 0)
     259                 :          0 :                 *xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
     260         [ #  # ]:          0 :         else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER23_KVARG, value) == 0)
     261                 :          0 :                 *xmit_policy = BALANCE_XMIT_POLICY_LAYER23;
     262         [ #  # ]:          0 :         else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER34_KVARG, value) == 0)
     263                 :          0 :                 *xmit_policy = BALANCE_XMIT_POLICY_LAYER34;
     264                 :            :         else
     265                 :            :                 return -1;
     266                 :            : 
     267                 :            :         return 0;
     268                 :            : }
     269                 :            : 
     270                 :            : int
     271                 :          0 : bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
     272                 :            :                 const char *value, void *extra_args)
     273                 :            : {
     274         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     275                 :            :                 return -1;
     276                 :            : 
     277                 :            :         /* Parse MAC */
     278                 :          0 :         return rte_ether_unformat_addr(value, extra_args);
     279                 :            : }
     280                 :            : 
     281                 :            : int
     282                 :          0 : bond_ethdev_parse_time_ms_kvarg(const char *key __rte_unused,
     283                 :            :                 const char *value, void *extra_args)
     284                 :            : {
     285                 :            :         uint32_t time_ms;
     286                 :            :         char *endptr;
     287                 :            : 
     288         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
     289                 :            :                 return -1;
     290                 :            : 
     291                 :          0 :         errno = 0;
     292                 :          0 :         time_ms = (uint32_t)strtol(value, &endptr, 10);
     293   [ #  #  #  # ]:          0 :         if (*endptr != 0 || errno != 0)
     294                 :            :                 return -1;
     295                 :            : 
     296                 :          0 :         *(uint32_t *)extra_args = time_ms;
     297                 :            : 
     298                 :          0 :         return 0;
     299                 :            : }

Generated by: LCOV version 1.14