LCOV - code coverage report
Current view: top level - drivers/net/ark - ark_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 402 0.5 %
Date: 2025-03-01 20:23:48 Functions: 2 25 8.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 170 0.6 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2015-2018 Atomic Rules LLC
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <unistd.h>
       6                 :            : #include <sys/stat.h>
       7                 :            : #include <dlfcn.h>
       8                 :            : 
       9                 :            : #include <bus_pci_driver.h>
      10                 :            : #include <ethdev_pci.h>
      11                 :            : #include <rte_kvargs.h>
      12                 :            : 
      13                 :            : #include "ark_global.h"
      14                 :            : #include "ark_logs.h"
      15                 :            : #include "ark_ethdev_tx.h"
      16                 :            : #include "ark_ethdev_rx.h"
      17                 :            : #include "ark_mpu.h"
      18                 :            : #include "ark_ddm.h"
      19                 :            : #include "ark_udm.h"
      20                 :            : #include "ark_pktdir.h"
      21                 :            : #include "ark_pktgen.h"
      22                 :            : #include "ark_pktchkr.h"
      23                 :            : 
      24                 :            : /*  Internal prototypes */
      25                 :            : static int eth_ark_check_args(struct ark_adapter *ark, const char *params);
      26                 :            : static int eth_ark_dev_init(struct rte_eth_dev *dev);
      27                 :            : static int ark_config_device(struct rte_eth_dev *dev);
      28                 :            : static int eth_ark_dev_uninit(struct rte_eth_dev *eth_dev);
      29                 :            : static int eth_ark_dev_configure(struct rte_eth_dev *dev);
      30                 :            : static int eth_ark_dev_start(struct rte_eth_dev *dev);
      31                 :            : static int eth_ark_dev_stop(struct rte_eth_dev *dev);
      32                 :            : static int eth_ark_dev_close(struct rte_eth_dev *dev);
      33                 :            : static int eth_ark_dev_info_get(struct rte_eth_dev *dev,
      34                 :            :                                 struct rte_eth_dev_info *dev_info);
      35                 :            : static int eth_ark_dev_link_update(struct rte_eth_dev *dev,
      36                 :            :                                    int wait_to_complete);
      37                 :            : static int eth_ark_dev_set_link_up(struct rte_eth_dev *dev);
      38                 :            : static int eth_ark_dev_set_link_down(struct rte_eth_dev *dev);
      39                 :            : static int eth_ark_dev_stats_get(struct rte_eth_dev *dev,
      40                 :            :                                   struct rte_eth_stats *stats);
      41                 :            : static int eth_ark_dev_stats_reset(struct rte_eth_dev *dev);
      42                 :            : static int eth_ark_set_default_mac_addr(struct rte_eth_dev *dev,
      43                 :            :                                          struct rte_ether_addr *mac_addr);
      44                 :            : static int eth_ark_macaddr_add(struct rte_eth_dev *dev,
      45                 :            :                                struct rte_ether_addr *mac_addr,
      46                 :            :                                uint32_t index,
      47                 :            :                                uint32_t pool);
      48                 :            : static void eth_ark_macaddr_remove(struct rte_eth_dev *dev,
      49                 :            :                                    uint32_t index);
      50                 :            : static int  eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size);
      51                 :            : 
      52                 :            : /*
      53                 :            :  * The packet generator is a functional block used to generate packet
      54                 :            :  * patterns for testing.  It is not intended for nominal use.
      55                 :            :  */
      56                 :            : #define ARK_PKTGEN_ARG "Pkt_gen"
      57                 :            : 
      58                 :            : /*
      59                 :            :  * The packet checker is a functional block used to verify packet
      60                 :            :  * patterns for testing.  It is not intended for nominal use.
      61                 :            :  */
      62                 :            : #define ARK_PKTCHKR_ARG "Pkt_chkr"
      63                 :            : 
      64                 :            : /*
      65                 :            :  * The packet director is used to select the internal ingress and
      66                 :            :  * egress packets paths during testing.  It is not intended for
      67                 :            :  * nominal use.
      68                 :            :  */
      69                 :            : #define ARK_PKTDIR_ARG "Pkt_dir"
      70                 :            : 
      71                 :            : /* Devinfo configurations */
      72                 :            : #define ARK_RX_MAX_QUEUE (4096 * 4)
      73                 :            : #define ARK_RX_MIN_QUEUE (512)
      74                 :            : #define ARK_RX_MAX_PKT_LEN ((16 * 1024) - 128)
      75                 :            : #define ARK_RX_MIN_BUFSIZE (1024)
      76                 :            : 
      77                 :            : #define ARK_TX_MAX_QUEUE (4096 * 4)
      78                 :            : #define ARK_TX_MIN_QUEUE (256)
      79                 :            : 
      80                 :            : static const char * const valid_arguments[] = {
      81                 :            :         ARK_PKTGEN_ARG,
      82                 :            :         ARK_PKTCHKR_ARG,
      83                 :            :         ARK_PKTDIR_ARG,
      84                 :            :         NULL
      85                 :            : };
      86                 :            : 
      87                 :            : #define AR_VENDOR_ID 0x1d6c
      88                 :            : static const struct rte_pci_id pci_id_ark_map[] = {
      89                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x100d)},
      90                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x100e)},
      91                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x100f)},
      92                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1010)},
      93                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1017)},
      94                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1018)},
      95                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1019)},
      96                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101a)},
      97                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101b)},
      98                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101c)},
      99                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101e)},
     100                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101f)},
     101                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1022)},
     102                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1024)},
     103                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1025)},
     104                 :            :         {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1026)},
     105                 :            :         {.vendor_id = 0, /* sentinel */ },
     106                 :            : };
     107                 :            : 
     108                 :            : /*
     109                 :            :  * This structure is used to statically define the capabilities
     110                 :            :  * of supported devices.
     111                 :            :  * Capabilities:
     112                 :            :  *    isvf -- defined for function id that are virtual
     113                 :            :  */
     114                 :            : struct ark_caps {
     115                 :            :         bool isvf;
     116                 :            : };
     117                 :            : struct ark_dev_caps {
     118                 :            :         uint32_t  device_id;
     119                 :            :         struct ark_caps  caps;
     120                 :            : };
     121                 :            : #define SET_DEV_CAPS(id, vf)                    \
     122                 :            :         {id, {.isvf = vf} }
     123                 :            : 
     124                 :            : static const struct ark_dev_caps
     125                 :            : ark_device_caps[] = {
     126                 :            :                      SET_DEV_CAPS(0x100d, false),
     127                 :            :                      SET_DEV_CAPS(0x100e, false),
     128                 :            :                      SET_DEV_CAPS(0x100f, false),
     129                 :            :                      SET_DEV_CAPS(0x1010, false),
     130                 :            :                      SET_DEV_CAPS(0x1017, false),
     131                 :            :                      SET_DEV_CAPS(0x1018, false),
     132                 :            :                      SET_DEV_CAPS(0x1019, false),
     133                 :            :                      SET_DEV_CAPS(0x101a, false),
     134                 :            :                      SET_DEV_CAPS(0x101b, false),
     135                 :            :                      SET_DEV_CAPS(0x101c, true),
     136                 :            :                      SET_DEV_CAPS(0x101e, false),
     137                 :            :                      SET_DEV_CAPS(0x101f, false),
     138                 :            :                      {.device_id = 0,}
     139                 :            : };
     140                 :            : 
     141                 :            : static int
     142                 :          0 : eth_ark_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
     143                 :            :                 struct rte_pci_device *pci_dev)
     144                 :            : {
     145                 :            :         struct rte_eth_dev *eth_dev;
     146                 :            :         int ret;
     147                 :            : 
     148                 :          0 :         eth_dev = rte_eth_dev_pci_allocate(pci_dev, sizeof(struct ark_adapter));
     149                 :            : 
     150         [ #  # ]:          0 :         if (eth_dev == NULL)
     151                 :            :                 return -ENOMEM;
     152                 :            : 
     153                 :          0 :         ret = eth_ark_dev_init(eth_dev);
     154         [ #  # ]:          0 :         if (ret)
     155                 :          0 :                 rte_eth_dev_release_port(eth_dev);
     156                 :            : 
     157                 :            :         return ret;
     158                 :            : }
     159                 :            : 
     160                 :            : static int
     161                 :          0 : eth_ark_pci_remove(struct rte_pci_device *pci_dev)
     162                 :            : {
     163                 :          0 :         return rte_eth_dev_pci_generic_remove(pci_dev, eth_ark_dev_uninit);
     164                 :            : }
     165                 :            : 
     166                 :            : static struct rte_pci_driver rte_ark_pmd = {
     167                 :            :         .id_table = pci_id_ark_map,
     168                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
     169                 :            :         .probe = eth_ark_pci_probe,
     170                 :            :         .remove = eth_ark_pci_remove,
     171                 :            : };
     172                 :            : 
     173                 :            : static const struct eth_dev_ops ark_eth_dev_ops = {
     174                 :            :         .dev_configure = eth_ark_dev_configure,
     175                 :            :         .dev_start = eth_ark_dev_start,
     176                 :            :         .dev_stop = eth_ark_dev_stop,
     177                 :            :         .dev_close = eth_ark_dev_close,
     178                 :            : 
     179                 :            :         .dev_infos_get = eth_ark_dev_info_get,
     180                 :            : 
     181                 :            :         .rx_queue_setup = eth_ark_dev_rx_queue_setup,
     182                 :            :         .tx_queue_setup = eth_ark_tx_queue_setup,
     183                 :            : 
     184                 :            :         .link_update = eth_ark_dev_link_update,
     185                 :            :         .dev_set_link_up = eth_ark_dev_set_link_up,
     186                 :            :         .dev_set_link_down = eth_ark_dev_set_link_down,
     187                 :            : 
     188                 :            :         .rx_queue_start = eth_ark_rx_start_queue,
     189                 :            :         .rx_queue_stop = eth_ark_rx_stop_queue,
     190                 :            : 
     191                 :            :         .tx_queue_start = eth_ark_tx_queue_start,
     192                 :            :         .tx_queue_stop = eth_ark_tx_queue_stop,
     193                 :            : 
     194                 :            :         .stats_get = eth_ark_dev_stats_get,
     195                 :            :         .stats_reset = eth_ark_dev_stats_reset,
     196                 :            : 
     197                 :            :         .mac_addr_add = eth_ark_macaddr_add,
     198                 :            :         .mac_addr_remove = eth_ark_macaddr_remove,
     199                 :            :         .mac_addr_set = eth_ark_set_default_mac_addr,
     200                 :            : 
     201                 :            :         .mtu_set = eth_ark_set_mtu,
     202                 :            : };
     203                 :            : 
     204                 :            : static int
     205                 :          0 : check_for_ext(struct ark_adapter *ark)
     206                 :            : {
     207                 :            :         int found = 0;
     208                 :            : 
     209                 :            :         /* Get the env */
     210                 :          0 :         const char *dllpath = getenv("ARK_EXT_PATH");
     211                 :            : 
     212         [ #  # ]:          0 :         if (dllpath == NULL) {
     213                 :          0 :                 ARK_PMD_LOG(DEBUG, "EXT NO dll path specified\n");
     214                 :          0 :                 return 0;
     215                 :            :         }
     216                 :          0 :         ARK_PMD_LOG(NOTICE, "EXT found dll path at %s\n", dllpath);
     217                 :            : 
     218                 :            :         /* Open and load the .so */
     219                 :          0 :         ark->d_handle = dlopen(dllpath, RTLD_LOCAL | RTLD_LAZY);
     220         [ #  # ]:          0 :         if (ark->d_handle == NULL) {
     221                 :          0 :                 ARK_PMD_LOG(ERR, "Could not load user extension %s\n",
     222                 :            :                             dllpath);
     223                 :          0 :                 return -1;
     224                 :            :         }
     225                 :          0 :         ARK_PMD_LOG(DEBUG, "SUCCESS: loaded user extension %s\n",
     226                 :            :                             dllpath);
     227                 :            : 
     228                 :            :         /* Get the entry points */
     229                 :          0 :         ark->user_ext.dev_init =
     230                 :          0 :                 (void *(*)(struct rte_eth_dev *, void *, int))
     231                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_init");
     232                 :          0 :         ARK_PMD_LOG(DEBUG, "device ext init pointer = %p\n",
     233                 :            :                       ark->user_ext.dev_init);
     234                 :          0 :         ark->user_ext.dev_get_port_count =
     235                 :          0 :                 (int (*)(struct rte_eth_dev *, void *))
     236                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_get_port_count");
     237                 :          0 :         ark->user_ext.dev_uninit =
     238                 :          0 :                 (void (*)(struct rte_eth_dev *, void *))
     239                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_uninit");
     240                 :          0 :         ark->user_ext.dev_configure =
     241                 :          0 :                 (int (*)(struct rte_eth_dev *, void *))
     242                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_configure");
     243                 :          0 :         ark->user_ext.dev_start =
     244                 :          0 :                 (int (*)(struct rte_eth_dev *, void *))
     245                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_start");
     246                 :          0 :         ark->user_ext.dev_stop =
     247                 :          0 :                 (void (*)(struct rte_eth_dev *, void *))
     248                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_stop");
     249                 :          0 :         ark->user_ext.dev_close =
     250                 :          0 :                 (void (*)(struct rte_eth_dev *, void *))
     251                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_close");
     252                 :          0 :         ark->user_ext.link_update =
     253                 :          0 :                 (int (*)(struct rte_eth_dev *, int, void *))
     254                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_link_update");
     255                 :          0 :         ark->user_ext.dev_set_link_up =
     256                 :          0 :                 (int (*)(struct rte_eth_dev *, void *))
     257                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_set_link_up");
     258                 :          0 :         ark->user_ext.dev_set_link_down =
     259                 :          0 :                 (int (*)(struct rte_eth_dev *, void *))
     260                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_dev_set_link_down");
     261                 :          0 :         ark->user_ext.stats_get =
     262                 :          0 :                 (int (*)(struct rte_eth_dev *, struct rte_eth_stats *,
     263                 :            :                           void *))
     264                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_stats_get");
     265                 :          0 :         ark->user_ext.stats_reset =
     266                 :          0 :                 (void (*)(struct rte_eth_dev *, void *))
     267                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_stats_reset");
     268                 :          0 :         ark->user_ext.mac_addr_add =
     269                 :          0 :                 (void (*)(struct rte_eth_dev *, struct rte_ether_addr *,
     270                 :            :                         uint32_t, uint32_t, void *))
     271                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_mac_addr_add");
     272                 :          0 :         ark->user_ext.mac_addr_remove =
     273                 :          0 :                 (void (*)(struct rte_eth_dev *, uint32_t, void *))
     274                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_mac_addr_remove");
     275                 :          0 :         ark->user_ext.mac_addr_set =
     276                 :          0 :                 (void (*)(struct rte_eth_dev *, struct rte_ether_addr *,
     277                 :            :                           void *))
     278                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_mac_addr_set");
     279                 :          0 :         ark->user_ext.set_mtu =
     280                 :          0 :                 (int (*)(struct rte_eth_dev *, uint16_t,
     281                 :            :                           void *))
     282                 :          0 :                 dlsym(ark->d_handle, "rte_pmd_ark_set_mtu");
     283                 :          0 :         ark->user_ext.rx_user_meta_hook =
     284                 :          0 :                 (rx_user_meta_hook_fn)dlsym(ark->d_handle,
     285                 :            :                                             "rte_pmd_ark_rx_user_meta_hook");
     286                 :          0 :         ark->user_ext.tx_user_meta_hook =
     287                 :          0 :                 (tx_user_meta_hook_fn)dlsym(ark->d_handle,
     288                 :            :                                             "rte_pmd_ark_tx_user_meta_hook");
     289                 :            : 
     290                 :          0 :         return found;
     291                 :            : }
     292                 :            : 
     293                 :            : static int
     294                 :          0 : eth_ark_dev_init(struct rte_eth_dev *dev)
     295                 :            : {
     296                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     297                 :            :         struct rte_pci_device *pci_dev;
     298                 :            :         int ret;
     299                 :            :         int port_count = 1;
     300                 :            :         int p;
     301                 :            :         uint16_t num_queues;
     302                 :            : 
     303                 :          0 :         ark->eth_dev = dev;
     304                 :            : 
     305                 :          0 :         ARK_PMD_LOG(DEBUG, "\n");
     306                 :            : 
     307                 :            :         /* Check to see if there is an extension that we need to load */
     308                 :          0 :         ret = check_for_ext(ark);
     309         [ #  # ]:          0 :         if (ret)
     310                 :            :                 return ret;
     311                 :            : 
     312                 :          0 :         pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     313                 :          0 :         rte_eth_copy_pci_info(dev, pci_dev);
     314                 :          0 :         dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
     315                 :            : 
     316                 :            :         p = 0;
     317         [ #  # ]:          0 :         while (ark_device_caps[p].device_id != 0) {
     318         [ #  # ]:          0 :                 if (pci_dev->id.device_id == ark_device_caps[p].device_id) {
     319                 :          0 :                         ark->isvf = ark_device_caps[p].caps.isvf;
     320                 :          0 :                         break;
     321                 :            :                 }
     322                 :          0 :                 p++;
     323                 :            :         }
     324                 :            : 
     325                 :            :         /* Use dummy function until setup */
     326                 :          0 :         dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
     327                 :          0 :         dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
     328                 :            : 
     329                 :          0 :         ark->bar0 = (uint8_t *)pci_dev->mem_resource[0].addr;
     330                 :          0 :         ark->a_bar = (uint8_t *)pci_dev->mem_resource[2].addr;
     331                 :            : 
     332                 :          0 :         ark->sysctrl.v  = (void *)&ark->bar0[ARK_SYSCTRL_BASE];
     333                 :          0 :         ark->mpurx.v  = (void *)&ark->bar0[ARK_MPU_RX_BASE];
     334                 :          0 :         ark->udm.v  = (void *)&ark->bar0[ARK_UDM_BASE];
     335                 :          0 :         ark->mputx.v  = (void *)&ark->bar0[ARK_MPU_TX_BASE];
     336                 :          0 :         ark->ddm.v  = (void *)&ark->bar0[ARK_DDM_BASE];
     337                 :          0 :         ark->cmac.v  = (void *)&ark->bar0[ARK_CMAC_BASE];
     338                 :          0 :         ark->external.v  = (void *)&ark->bar0[ARK_EXTERNAL_BASE];
     339                 :          0 :         ark->pktdir.v  = (void *)&ark->bar0[ARK_PKTDIR_BASE];
     340                 :          0 :         ark->pktgen.v  = (void *)&ark->bar0[ARK_PKTGEN_BASE];
     341                 :          0 :         ark->pktchkr.v  = (void *)&ark->bar0[ARK_PKTCHKR_BASE];
     342                 :            : 
     343                 :          0 :         ark->started = 0;
     344                 :          0 :         ark->pkt_dir_v = ARK_PKT_DIR_INIT_VAL;
     345                 :            : 
     346         [ #  # ]:          0 :         ARK_PMD_LOG(INFO, "Sys Ctrl Const = 0x%x  HW Commit_ID: %08x\n",
     347                 :            :                       ark->sysctrl.t32[4],
     348                 :            :                       rte_be_to_cpu_32(ark->sysctrl.t32[0x20 / 4]));
     349         [ #  # ]:          0 :         ARK_PMD_LOG(NOTICE, "Arkville HW Commit_ID: %08x\n",
     350                 :            :                     rte_be_to_cpu_32(ark->sysctrl.t32[0x20 / 4]));
     351                 :            : 
     352                 :            :         /* If HW sanity test fails, return an error */
     353         [ #  # ]:          0 :         if (ark->sysctrl.t32[4] != 0xcafef00d) {
     354                 :          0 :                 ARK_PMD_LOG(ERR,
     355                 :            :                             "HW Sanity test has failed, expected constant"
     356                 :            :                             " 0x%x, read 0x%x (%s)\n",
     357                 :            :                             0xcafef00d,
     358                 :            :                             ark->sysctrl.t32[4], __func__);
     359                 :          0 :                 return -1;
     360                 :            :         }
     361                 :            : 
     362                 :          0 :         ARK_PMD_LOG(DEBUG,
     363                 :            :                     "HW Sanity test has PASSED, expected constant"
     364                 :            :                     " 0x%x, read 0x%x (%s)\n",
     365                 :            :                     0xcafef00d, ark->sysctrl.t32[4], __func__);
     366                 :            : 
     367                 :            :         /* We are a single function multi-port device. */
     368                 :          0 :         ret = ark_config_device(dev);
     369         [ #  # ]:          0 :         if (ret)
     370                 :            :                 return -1;
     371                 :            : 
     372                 :          0 :         dev->dev_ops = &ark_eth_dev_ops;
     373                 :          0 :         dev->rx_queue_count = eth_ark_dev_rx_queue_count;
     374                 :            : 
     375                 :          0 :         dev->data->mac_addrs = rte_zmalloc("ark", RTE_ETHER_ADDR_LEN, 0);
     376         [ #  # ]:          0 :         if (!dev->data->mac_addrs) {
     377                 :          0 :                 ARK_PMD_LOG(ERR,
     378                 :            :                             "Failed to allocated memory for storing mac address"
     379                 :            :                             );
     380                 :            :         }
     381                 :            : 
     382         [ #  # ]:          0 :         if (ark->user_ext.dev_init) {
     383                 :          0 :                 ark->user_data[dev->data->port_id] =
     384                 :          0 :                         ark->user_ext.dev_init(dev, ark->a_bar, 0);
     385         [ #  # ]:          0 :                 if (!ark->user_data[dev->data->port_id]) {
     386                 :          0 :                         ARK_PMD_LOG(WARNING,
     387                 :            :                                     "Failed to initialize PMD extension!"
     388                 :            :                                     " continuing without it\n");
     389                 :          0 :                         memset(&ark->user_ext, 0, sizeof(struct ark_user_ext));
     390                 :          0 :                         dlclose(ark->d_handle);
     391                 :            :                 }
     392                 :            :         }
     393                 :            : 
     394         [ #  # ]:          0 :         if (pci_dev->device.devargs)
     395                 :          0 :                 ret = eth_ark_check_args(ark, pci_dev->device.devargs->args);
     396                 :            :         else
     397                 :          0 :                 ARK_PMD_LOG(INFO, "No Device args found\n");
     398                 :            : 
     399         [ #  # ]:          0 :         if (ret)
     400                 :          0 :                 goto error;
     401                 :            :         /*
     402                 :            :          * We will create additional devices based on the number of requested
     403                 :            :          * ports
     404                 :            :          */
     405         [ #  # ]:          0 :         if (ark->user_ext.dev_get_port_count)
     406                 :            :                 port_count =
     407                 :          0 :                         ark->user_ext.dev_get_port_count(dev,
     408                 :          0 :                                  ark->user_data[dev->data->port_id]);
     409                 :          0 :         ark->num_ports = port_count;
     410                 :          0 :         num_queues = ark_api_num_queues_per_port(ark->mpurx.v, port_count);
     411                 :            : 
     412         [ #  # ]:          0 :         for (p = 0; p < port_count; p++) {
     413                 :            :                 struct rte_eth_dev *eth_dev;
     414                 :            :                 char name[RTE_ETH_NAME_MAX_LEN];
     415                 :            : 
     416                 :          0 :                 snprintf(name, sizeof(name), "arketh%d",
     417         [ #  # ]:          0 :                          dev->data->port_id + p);
     418                 :            : 
     419         [ #  # ]:          0 :                 if (p == 0) {
     420                 :            :                         /* First port is already allocated by DPDK */
     421                 :          0 :                         eth_dev = ark->eth_dev;
     422                 :          0 :                         rte_eth_dev_probing_finish(eth_dev);
     423                 :          0 :                         continue;
     424                 :            :                 }
     425                 :            : 
     426                 :            :                 /* reserve an ethdev entry */
     427                 :          0 :                 eth_dev = rte_eth_dev_allocate(name);
     428         [ #  # ]:          0 :                 if (!eth_dev) {
     429                 :          0 :                         ARK_PMD_LOG(ERR,
     430                 :            :                                     "Could not allocate eth_dev for port %d\n",
     431                 :            :                                     p);
     432                 :          0 :                         goto error;
     433                 :            :                 }
     434                 :            : 
     435                 :          0 :                 eth_dev->device = &pci_dev->device;
     436                 :            :                 /* Device requires new dev_private data */
     437                 :          0 :                 eth_dev->data->dev_private =
     438                 :          0 :                         rte_zmalloc_socket(name,
     439                 :            :                                            sizeof(struct ark_adapter),
     440                 :            :                                            RTE_CACHE_LINE_SIZE,
     441                 :          0 :                                            rte_socket_id());
     442                 :            : 
     443                 :          0 :                 memcpy(eth_dev->data->dev_private, ark,
     444                 :            :                        sizeof(struct ark_adapter));
     445                 :          0 :                 ark = eth_dev->data->dev_private;
     446                 :          0 :                 ark->qbase = p * num_queues;
     447                 :            : 
     448                 :          0 :                 eth_dev->dev_ops = ark->eth_dev->dev_ops;
     449                 :          0 :                 eth_dev->tx_pkt_burst = ark->eth_dev->tx_pkt_burst;
     450                 :          0 :                 eth_dev->rx_pkt_burst = ark->eth_dev->rx_pkt_burst;
     451                 :            : 
     452                 :          0 :                 rte_eth_copy_pci_info(eth_dev, pci_dev);
     453                 :          0 :                 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
     454                 :            : 
     455                 :          0 :                 eth_dev->data->mac_addrs = rte_zmalloc(name,
     456                 :            :                                                 RTE_ETHER_ADDR_LEN, 0);
     457         [ #  # ]:          0 :                 if (!eth_dev->data->mac_addrs) {
     458                 :          0 :                         ARK_PMD_LOG(ERR,
     459                 :            :                                     "Memory allocation for MAC failed!"
     460                 :            :                                     " Exiting.\n");
     461                 :          0 :                         goto error;
     462                 :            :                 }
     463                 :            : 
     464         [ #  # ]:          0 :                 if (ark->user_ext.dev_init) {
     465                 :          0 :                         ark->user_data[eth_dev->data->port_id] =
     466                 :          0 :                                 ark->user_ext.dev_init(dev, ark->a_bar, p);
     467                 :            :                 }
     468                 :            : 
     469                 :          0 :                 rte_eth_dev_probing_finish(eth_dev);
     470                 :            :         }
     471                 :            : 
     472                 :            :         return ret;
     473                 :            : 
     474                 :          0 : error:
     475                 :          0 :         rte_free(dev->data->mac_addrs);
     476                 :          0 :         dev->data->mac_addrs = NULL;
     477                 :          0 :         return -1;
     478                 :            : }
     479                 :            : 
     480                 :            : /*
     481                 :            :  *Initial device configuration when device is opened
     482                 :            :  * setup the DDM, and UDM
     483                 :            :  * Called once per PCIE device
     484                 :            :  */
     485                 :            : static int
     486                 :          0 : ark_config_device(struct rte_eth_dev *dev)
     487                 :            : {
     488                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     489                 :            :         uint16_t num_q, i;
     490                 :            :         struct ark_mpu_t *mpu;
     491                 :            : 
     492                 :            :         /*
     493                 :            :          * Make sure that the packet director, generator and checker are in a
     494                 :            :          * known state
     495                 :            :          */
     496         [ #  # ]:          0 :         if (!ark->isvf) {
     497                 :          0 :                 ark->start_pg = 0;
     498                 :          0 :                 ark->pg_running = 0;
     499                 :          0 :                 ark->pg = ark_pktgen_init(ark->pktgen.v, 0, 1);
     500         [ #  # ]:          0 :                 if (ark->pg == NULL)
     501                 :            :                         return -1;
     502                 :          0 :                 ark_pktgen_reset(ark->pg);
     503                 :          0 :                 ark->pc = ark_pktchkr_init(ark->pktchkr.v, 0, 1);
     504         [ #  # ]:          0 :                 if (ark->pc == NULL)
     505                 :            :                         return -1;
     506                 :          0 :                 ark_pktchkr_stop(ark->pc);
     507                 :          0 :                 ark->pd = ark_pktdir_init(ark->pktdir.v);
     508         [ #  # ]:          0 :                 if (ark->pd == NULL)
     509                 :            :                         return -1;
     510                 :            :         }
     511                 :            :         /* Verify HW */
     512         [ #  # ]:          0 :         if (ark_udm_verify(ark->udm.v))
     513                 :            :                 return -1;
     514         [ #  # ]:          0 :         if (ark_ddm_verify(ark->ddm.v))
     515                 :            :                 return -1;
     516                 :            : 
     517                 :            :         /* MPU reset */
     518                 :          0 :         mpu = ark->mpurx.v;
     519                 :          0 :         num_q = ark_api_num_queues(mpu);
     520                 :          0 :         ark->rx_queues = num_q;
     521                 :            :         for (i = 0; i < num_q; i++) {
     522                 :            :                 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
     523                 :            :         }
     524                 :            : 
     525                 :          0 :         mpu = ark->mputx.v;
     526                 :          0 :         num_q = ark_api_num_queues(mpu);
     527                 :          0 :         ark->tx_queues = num_q;
     528                 :          0 :         for (i = 0; i < num_q; i++) {
     529                 :            :                 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
     530                 :            :         }
     531                 :            : 
     532                 :            :         return 0;
     533                 :            : }
     534                 :            : 
     535                 :            : static int
     536                 :          0 : eth_ark_dev_uninit(struct rte_eth_dev *dev)
     537                 :            : {
     538                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     539                 :            : 
     540         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     541                 :            :                 return 0;
     542                 :            : 
     543         [ #  # ]:          0 :         if (ark->user_ext.dev_uninit)
     544                 :          0 :                 ark->user_ext.dev_uninit(dev,
     545                 :          0 :                          ark->user_data[dev->data->port_id]);
     546                 :            : 
     547         [ #  # ]:          0 :         if (!ark->isvf) {
     548                 :          0 :                 ark_pktgen_uninit(ark->pg);
     549                 :          0 :                 ark_pktchkr_uninit(ark->pc);
     550                 :            :         }
     551                 :            : 
     552                 :            :         return 0;
     553                 :            : }
     554                 :            : 
     555                 :            : static int
     556                 :          0 : eth_ark_dev_configure(struct rte_eth_dev *dev)
     557                 :            : {
     558                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     559                 :            : 
     560                 :            :         eth_ark_dev_set_link_up(dev);
     561         [ #  # ]:          0 :         if (ark->user_ext.dev_configure)
     562                 :          0 :                 return ark->user_ext.dev_configure(dev,
     563                 :          0 :                            ark->user_data[dev->data->port_id]);
     564                 :            :         return 0;
     565                 :            : }
     566                 :            : 
     567                 :            : static int
     568                 :          0 : eth_ark_dev_start(struct rte_eth_dev *dev)
     569                 :            : {
     570                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     571                 :            :         int i;
     572                 :            : 
     573                 :            :         /* RX Side */
     574         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     575                 :          0 :                 eth_ark_rx_start_queue(dev, i);
     576                 :            : 
     577                 :            :         /* TX Side */
     578         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
     579                 :          0 :                 eth_ark_tx_queue_start(dev, i);
     580                 :            : 
     581                 :          0 :         ark->started = 1;
     582                 :            :         /* set xmit and receive function */
     583                 :          0 :         dev->rx_pkt_burst = &eth_ark_recv_pkts;
     584                 :          0 :         dev->tx_pkt_burst = &eth_ark_xmit_pkts;
     585                 :            : 
     586   [ #  #  #  # ]:          0 :         if (!ark->isvf && ark->start_pg)
     587                 :          0 :                 ark_pktchkr_run(ark->pc);
     588                 :            : 
     589   [ #  #  #  #  :          0 :         if (!ark->isvf && ark->start_pg && !ark->pg_running) {
                   #  # ]
     590                 :            :                 rte_thread_t thread;
     591                 :            : 
     592                 :            :                 /* Delay packet generator start allow the hardware to be ready
     593                 :            :                  * This is only used for sanity checking with internal generator
     594                 :            :                  */
     595                 :            :                 char tname[RTE_THREAD_INTERNAL_NAME_SIZE];
     596                 :          0 :                 snprintf(tname, sizeof(tname), "ark-pg%d", dev->data->port_id);
     597                 :            : 
     598         [ #  # ]:          0 :                 if (rte_thread_create_internal_control(&thread, tname,
     599                 :            :                                         ark_pktgen_delay_start, ark->pg)) {
     600                 :          0 :                         ARK_PMD_LOG(ERR, "Could not create pktgen "
     601                 :            :                                     "starter thread\n");
     602                 :          0 :                         return -1;
     603                 :            :                 }
     604                 :          0 :                 ark->pg_running = 1;
     605                 :            :         }
     606                 :            : 
     607         [ #  # ]:          0 :         if (ark->user_ext.dev_start)
     608                 :          0 :                 ark->user_ext.dev_start(dev,
     609                 :          0 :                         ark->user_data[dev->data->port_id]);
     610                 :            : 
     611                 :            :         return 0;
     612                 :            : }
     613                 :            : 
     614                 :            : static int
     615                 :          0 : eth_ark_dev_stop(struct rte_eth_dev *dev)
     616                 :            : {
     617                 :            :         uint16_t i;
     618                 :            :         int status;
     619                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     620                 :            : 
     621         [ #  # ]:          0 :         if (ark->started == 0)
     622                 :            :                 return 0;
     623                 :          0 :         ark->started = 0;
     624                 :          0 :         dev->data->dev_started = 0;
     625                 :            : 
     626                 :            :         /* Stop the extension first */
     627         [ #  # ]:          0 :         if (ark->user_ext.dev_stop)
     628                 :          0 :                 ark->user_ext.dev_stop(dev,
     629                 :          0 :                        ark->user_data[dev->data->port_id]);
     630                 :            : 
     631                 :            :         /* Stop the packet generator */
     632   [ #  #  #  #  :          0 :         if (!ark->isvf && ark->start_pg && ark->pg_running) {
                   #  # ]
     633                 :          0 :                 ark_pktgen_pause(ark->pg);
     634                 :          0 :                 ark->pg_running = 0;
     635                 :            :         }
     636                 :            : 
     637                 :          0 :         dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
     638                 :          0 :         dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
     639                 :            : 
     640                 :            :         /* Stop RX Side */
     641         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     642                 :          0 :                 eth_ark_rx_stop_queue(dev, i);
     643                 :            : 
     644                 :            :         /* STOP TX Side */
     645         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
     646                 :          0 :                 status = eth_ark_tx_queue_stop(dev, i);
     647         [ #  # ]:          0 :                 if (status != 0) {
     648                 :          0 :                         uint16_t port = dev->data->port_id;
     649                 :          0 :                         ARK_PMD_LOG(ERR,
     650                 :            :                                     "tx_queue stop anomaly"
     651                 :            :                                     " port %u, queue %u\n",
     652                 :            :                                     port, i);
     653                 :            :                 }
     654                 :            :         }
     655                 :            : 
     656                 :          0 :         ark_udm_dump_stats(ark->udm.v, "Post stop");
     657                 :            : 
     658         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     659                 :          0 :                 eth_ark_rx_dump_queue(dev, i, __func__);
     660                 :            : 
     661                 :            :         /* Stop the packet checker if it is running */
     662   [ #  #  #  # ]:          0 :         if (!ark->isvf && ark->start_pg) {
     663                 :          0 :                 ark_pktchkr_dump_stats(ark->pc);
     664                 :          0 :                 ark_pktchkr_stop(ark->pc);
     665                 :            :         }
     666                 :            : 
     667                 :            :         return 0;
     668                 :            : }
     669                 :            : 
     670                 :            : static int
     671                 :          0 : eth_ark_dev_close(struct rte_eth_dev *dev)
     672                 :            : {
     673                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     674                 :            :         uint16_t i;
     675                 :            : 
     676         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     677                 :            :                 return 0;
     678                 :            : 
     679         [ #  # ]:          0 :         if (ark->user_ext.dev_close)
     680                 :          0 :                 ark->user_ext.dev_close(dev,
     681                 :          0 :                  ark->user_data[dev->data->port_id]);
     682                 :            : 
     683                 :          0 :         eth_ark_dev_stop(dev);
     684                 :            : 
     685                 :            :         /*
     686                 :            :          * This should only be called once for the device during shutdown
     687                 :            :          */
     688                 :            :         /* return to power-on state */
     689         [ #  # ]:          0 :         if (ark->pd)
     690                 :          0 :                 ark_pktdir_setup(ark->pd, ARK_PKT_DIR_INIT_VAL);
     691                 :            : 
     692         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
     693                 :          0 :                 eth_ark_tx_queue_release(dev->data->tx_queues[i]);
     694                 :          0 :                 dev->data->tx_queues[i] = 0;
     695                 :            :         }
     696                 :            : 
     697         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
     698                 :          0 :                 eth_ark_dev_rx_queue_release(dev->data->rx_queues[i]);
     699                 :          0 :                 dev->data->rx_queues[i] = 0;
     700                 :            :         }
     701                 :            : 
     702                 :            :         return 0;
     703                 :            : }
     704                 :            : 
     705                 :            : static int
     706                 :          0 : eth_ark_dev_info_get(struct rte_eth_dev *dev,
     707                 :            :                      struct rte_eth_dev_info *dev_info)
     708                 :            : {
     709                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     710                 :          0 :         struct ark_mpu_t *tx_mpu = RTE_PTR_ADD(ark->bar0, ARK_MPU_TX_BASE);
     711                 :          0 :         struct ark_mpu_t *rx_mpu = RTE_PTR_ADD(ark->bar0, ARK_MPU_RX_BASE);
     712                 :          0 :         uint16_t ports = ark->num_ports;
     713                 :            : 
     714                 :          0 :         dev_info->max_rx_pktlen = ARK_RX_MAX_PKT_LEN;
     715                 :          0 :         dev_info->min_rx_bufsize = ARK_RX_MIN_BUFSIZE;
     716                 :            : 
     717                 :          0 :         dev_info->max_rx_queues = ark_api_num_queues_per_port(rx_mpu, ports);
     718                 :          0 :         dev_info->max_tx_queues = ark_api_num_queues_per_port(tx_mpu, ports);
     719                 :            : 
     720                 :          0 :         dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
     721                 :            :                 .nb_max = ARK_RX_MAX_QUEUE,
     722                 :            :                 .nb_min = ARK_RX_MIN_QUEUE,
     723                 :            :                 .nb_align = ARK_RX_MIN_QUEUE}; /* power of 2 */
     724                 :            : 
     725                 :          0 :         dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
     726                 :            :                 .nb_max = ARK_TX_MAX_QUEUE,
     727                 :            :                 .nb_min = ARK_TX_MIN_QUEUE,
     728                 :            :                 .nb_align = ARK_TX_MIN_QUEUE}; /* power of 2 */
     729                 :            : 
     730                 :            :         /* ARK PMD supports all line rates, how do we indicate that here ?? */
     731                 :          0 :         dev_info->speed_capa = (RTE_ETH_LINK_SPEED_1G |
     732                 :            :                                 RTE_ETH_LINK_SPEED_10G |
     733                 :            :                                 RTE_ETH_LINK_SPEED_25G |
     734                 :            :                                 RTE_ETH_LINK_SPEED_40G |
     735                 :            :                                 RTE_ETH_LINK_SPEED_50G |
     736                 :            :                                 RTE_ETH_LINK_SPEED_100G);
     737                 :            : 
     738                 :          0 :         dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_TIMESTAMP;
     739                 :            : 
     740                 :          0 :         return 0;
     741                 :            : }
     742                 :            : 
     743                 :            : static int
     744                 :          0 : eth_ark_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
     745                 :            : {
     746                 :          0 :         ARK_PMD_LOG(DEBUG, "link status = %d\n",
     747                 :            :                         dev->data->dev_link.link_status);
     748                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     749                 :            : 
     750         [ #  # ]:          0 :         if (ark->user_ext.link_update) {
     751                 :          0 :                 return ark->user_ext.link_update
     752                 :            :                         (dev, wait_to_complete,
     753                 :          0 :                          ark->user_data[dev->data->port_id]);
     754                 :            :         }
     755                 :            :         return 0;
     756                 :            : }
     757                 :            : 
     758                 :            : static int
     759                 :          0 : eth_ark_dev_set_link_up(struct rte_eth_dev *dev)
     760                 :            : {
     761                 :          0 :         dev->data->dev_link.link_status = 1;
     762                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     763                 :            : 
     764   [ #  #  #  # ]:          0 :         if (ark->user_ext.dev_set_link_up)
     765                 :          0 :                 return ark->user_ext.dev_set_link_up(dev,
     766                 :          0 :                              ark->user_data[dev->data->port_id]);
     767                 :            :         return 0;
     768                 :            : }
     769                 :            : 
     770                 :            : static int
     771                 :          0 : eth_ark_dev_set_link_down(struct rte_eth_dev *dev)
     772                 :            : {
     773                 :          0 :         dev->data->dev_link.link_status = 0;
     774                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     775                 :            : 
     776         [ #  # ]:          0 :         if (ark->user_ext.dev_set_link_down)
     777                 :          0 :                 return ark->user_ext.dev_set_link_down(dev,
     778                 :          0 :                        ark->user_data[dev->data->port_id]);
     779                 :            :         return 0;
     780                 :            : }
     781                 :            : 
     782                 :            : static int
     783                 :          0 : eth_ark_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
     784                 :            : {
     785                 :            :         uint16_t i;
     786                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     787                 :            : 
     788                 :          0 :         stats->ipackets = 0;
     789                 :          0 :         stats->ibytes = 0;
     790                 :          0 :         stats->opackets = 0;
     791                 :          0 :         stats->obytes = 0;
     792                 :          0 :         stats->imissed = 0;
     793                 :          0 :         stats->oerrors = 0;
     794                 :            : 
     795         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
     796                 :          0 :                 eth_tx_queue_stats_get(dev->data->tx_queues[i], stats);
     797         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     798                 :          0 :                 eth_rx_queue_stats_get(dev->data->rx_queues[i], stats);
     799         [ #  # ]:          0 :         if (ark->user_ext.stats_get)
     800                 :          0 :                 return ark->user_ext.stats_get(dev, stats,
     801                 :          0 :                         ark->user_data[dev->data->port_id]);
     802                 :            :         return 0;
     803                 :            : }
     804                 :            : 
     805                 :            : static int
     806                 :          0 : eth_ark_dev_stats_reset(struct rte_eth_dev *dev)
     807                 :            : {
     808                 :            :         uint16_t i;
     809                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     810                 :            : 
     811         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
     812                 :          0 :                 eth_tx_queue_stats_reset(dev->data->tx_queues[i]);
     813         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     814                 :          0 :                 eth_rx_queue_stats_reset(dev->data->rx_queues[i]);
     815         [ #  # ]:          0 :         if (ark->user_ext.stats_reset)
     816                 :          0 :                 ark->user_ext.stats_reset(dev,
     817                 :          0 :                           ark->user_data[dev->data->port_id]);
     818                 :            : 
     819                 :          0 :         return 0;
     820                 :            : }
     821                 :            : 
     822                 :            : static int
     823                 :          0 : eth_ark_macaddr_add(struct rte_eth_dev *dev,
     824                 :            :                     struct rte_ether_addr *mac_addr,
     825                 :            :                     uint32_t index,
     826                 :            :                     uint32_t pool)
     827                 :            : {
     828                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     829                 :            : 
     830         [ #  # ]:          0 :         if (ark->user_ext.mac_addr_add) {
     831                 :          0 :                 ark->user_ext.mac_addr_add(dev,
     832                 :            :                                            mac_addr,
     833                 :            :                                            index,
     834                 :            :                                            pool,
     835                 :          0 :                            ark->user_data[dev->data->port_id]);
     836                 :          0 :                 return 0;
     837                 :            :         }
     838                 :            :         return -ENOTSUP;
     839                 :            : }
     840                 :            : 
     841                 :            : static void
     842                 :          0 : eth_ark_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
     843                 :            : {
     844                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     845                 :            : 
     846         [ #  # ]:          0 :         if (ark->user_ext.mac_addr_remove)
     847                 :          0 :                 ark->user_ext.mac_addr_remove(dev, index,
     848                 :          0 :                               ark->user_data[dev->data->port_id]);
     849                 :          0 : }
     850                 :            : 
     851                 :            : static int
     852                 :          0 : eth_ark_set_default_mac_addr(struct rte_eth_dev *dev,
     853                 :            :                              struct rte_ether_addr *mac_addr)
     854                 :            : {
     855                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     856                 :            : 
     857         [ #  # ]:          0 :         if (ark->user_ext.mac_addr_set) {
     858                 :          0 :                 ark->user_ext.mac_addr_set(dev, mac_addr,
     859                 :          0 :                            ark->user_data[dev->data->port_id]);
     860                 :          0 :                 return 0;
     861                 :            :         }
     862                 :            :         return -ENOTSUP;
     863                 :            : }
     864                 :            : 
     865                 :            : static int
     866                 :          0 : eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t  size)
     867                 :            : {
     868                 :          0 :         struct ark_adapter *ark = dev->data->dev_private;
     869                 :            : 
     870         [ #  # ]:          0 :         if (ark->user_ext.set_mtu)
     871                 :          0 :                 return ark->user_ext.set_mtu(dev, size,
     872                 :          0 :                              ark->user_data[dev->data->port_id]);
     873                 :            : 
     874                 :            :         return -ENOTSUP;
     875                 :            : }
     876                 :            : 
     877                 :            : static inline int
     878                 :          0 : process_pktdir_arg(const char *key, const char *value,
     879                 :            :                    void *extra_args)
     880                 :            : {
     881                 :          0 :         ARK_PMD_LOG(DEBUG, "key = %s, value = %s\n",
     882                 :            :                     key, value);
     883                 :            :         struct ark_adapter *ark =
     884                 :            :                 (struct ark_adapter *)extra_args;
     885                 :            : 
     886                 :          0 :         ark->pkt_dir_v = strtol(value, NULL, 16);
     887                 :          0 :         ARK_PMD_LOG(DEBUG, "pkt_dir_v = 0x%x\n", ark->pkt_dir_v);
     888                 :          0 :         return 0;
     889                 :            : }
     890                 :            : 
     891                 :            : static inline int
     892                 :          0 : process_file_args(const char *key, const char *value, void *extra_args)
     893                 :            : {
     894                 :          0 :         ARK_PMD_LOG(DEBUG, "key = %s, value = %s\n",
     895                 :            :                     key, value);
     896                 :            :         char *args = (char *)extra_args;
     897                 :            : 
     898                 :            :         /* Open the configuration file */
     899                 :          0 :         FILE *file = fopen(value, "r");
     900                 :            :         char line[ARK_MAX_ARG_LEN];
     901                 :            :         int  size = 0;
     902                 :            :         int first = 1;
     903                 :            : 
     904         [ #  # ]:          0 :         if (file == NULL) {
     905                 :          0 :                 ARK_PMD_LOG(ERR, "Unable to open "
     906                 :            :                             "config file %s\n", value);
     907                 :          0 :                 return -1;
     908                 :            :         }
     909                 :            : 
     910         [ #  # ]:          0 :         while (fgets(line, sizeof(line), file)) {
     911                 :          0 :                 size += strlen(line);
     912         [ #  # ]:          0 :                 if (size >= ARK_MAX_ARG_LEN) {
     913                 :          0 :                         ARK_PMD_LOG(ERR, "Unable to parse file %s args, "
     914                 :            :                                     "parameter list is too long\n", value);
     915                 :          0 :                         fclose(file);
     916                 :          0 :                         return -1;
     917                 :            :                 }
     918         [ #  # ]:          0 :                 if (first) {
     919                 :            :                         strncpy(args, line, ARK_MAX_ARG_LEN);
     920                 :            :                         first = 0;
     921                 :            :                 } else {
     922                 :            :                         strncat(args, line, ARK_MAX_ARG_LEN);
     923                 :            :                 }
     924                 :            :         }
     925                 :          0 :         ARK_PMD_LOG(DEBUG, "file = %s\n", args);
     926                 :          0 :         fclose(file);
     927                 :          0 :         return 0;
     928                 :            : }
     929                 :            : 
     930                 :            : static int
     931                 :          0 : eth_ark_check_args(struct ark_adapter *ark, const char *params)
     932                 :            : {
     933                 :            :         struct rte_kvargs *kvlist;
     934                 :            :         unsigned int k_idx;
     935                 :            :         struct rte_kvargs_pair *pair = NULL;
     936                 :            :         int ret = -1;
     937                 :            : 
     938                 :          0 :         kvlist = rte_kvargs_parse(params, valid_arguments);
     939         [ #  # ]:          0 :         if (kvlist == NULL)
     940                 :            :                 return 0;
     941                 :            : 
     942                 :          0 :         ark->pkt_gen_args[0] = 0;
     943                 :          0 :         ark->pkt_chkr_args[0] = 0;
     944                 :            : 
     945         [ #  # ]:          0 :         for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
     946                 :            :                 pair = &kvlist->pairs[k_idx];
     947                 :          0 :                 ARK_PMD_LOG(DEBUG, "**** Arg passed to PMD = %s:%s\n",
     948                 :            :                              pair->key,
     949                 :            :                              pair->value);
     950                 :            :         }
     951                 :            : 
     952         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist,
     953                 :            :                                ARK_PKTDIR_ARG,
     954                 :            :                                &process_pktdir_arg,
     955                 :            :                                ark) != 0) {
     956                 :          0 :                 ARK_PMD_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTDIR_ARG);
     957                 :          0 :                 goto free_kvlist;
     958                 :            :         }
     959                 :            : 
     960         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist,
     961                 :            :                                ARK_PKTGEN_ARG,
     962                 :            :                                &process_file_args,
     963                 :          0 :                                ark->pkt_gen_args) != 0) {
     964                 :          0 :                 ARK_PMD_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTGEN_ARG);
     965                 :          0 :                 goto free_kvlist;
     966                 :            :         }
     967                 :            : 
     968         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist,
     969                 :            :                                ARK_PKTCHKR_ARG,
     970                 :            :                                &process_file_args,
     971                 :          0 :                                ark->pkt_chkr_args) != 0) {
     972                 :          0 :                 ARK_PMD_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTCHKR_ARG);
     973                 :          0 :                 goto free_kvlist;
     974                 :            :         }
     975                 :            : 
     976         [ #  # ]:          0 :         if (ark->isvf) {
     977                 :            :                 ret = 0;
     978                 :          0 :                 goto free_kvlist;
     979                 :            :         }
     980                 :          0 :         ARK_PMD_LOG(INFO, "packet director set to 0x%x\n", ark->pkt_dir_v);
     981                 :            :         /* Setup the packet director */
     982                 :          0 :         ark_pktdir_setup(ark->pd, ark->pkt_dir_v);
     983                 :            : 
     984                 :            :         /* Setup the packet generator */
     985         [ #  # ]:          0 :         if (ark->pkt_gen_args[0]) {
     986                 :          0 :                 ARK_PMD_LOG(DEBUG, "Setting up the packet generator\n");
     987                 :          0 :                 ark_pktgen_parse(ark->pkt_gen_args);
     988                 :          0 :                 ark_pktgen_reset(ark->pg);
     989                 :          0 :                 ark_pktgen_setup(ark->pg);
     990                 :          0 :                 ark->start_pg = 1;
     991                 :            :         }
     992                 :            : 
     993                 :            :         /* Setup the packet checker */
     994         [ #  # ]:          0 :         if (ark->pkt_chkr_args[0]) {
     995                 :          0 :                 ark_pktchkr_parse(ark->pkt_chkr_args);
     996                 :          0 :                 ark_pktchkr_setup(ark->pc);
     997                 :            :         }
     998                 :            : 
     999                 :            :         ret = 0;
    1000                 :            : 
    1001                 :          0 : free_kvlist:
    1002                 :          0 :         rte_kvargs_free(kvlist);
    1003                 :            : 
    1004                 :          0 :         return ret;
    1005                 :            : }
    1006                 :            : 
    1007                 :        252 : RTE_PMD_REGISTER_PCI(net_ark, rte_ark_pmd);
    1008                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_ark, "* igb_uio | uio_pci_generic ");
    1009                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_ark, pci_id_ark_map);
    1010                 :            : RTE_PMD_REGISTER_PARAM_STRING(net_ark,
    1011                 :            :                               ARK_PKTGEN_ARG "=<filename> "
    1012                 :            :                               ARK_PKTCHKR_ARG "=<filename> "
    1013                 :            :                               ARK_PKTDIR_ARG "=<bitmap>");
    1014         [ -  + ]:        252 : RTE_LOG_REGISTER_DEFAULT(ark_logtype, NOTICE);

Generated by: LCOV version 1.14