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

Generated by: LCOV version 1.14