LCOV - code coverage report
Current view: top level - drivers/bus/fslmc - fslmc_bus.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 50 264 18.9 %
Date: 2025-11-01 17:50:34 Functions: 8 19 42.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 186 12.4 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *
       3                 :            :  *   Copyright 2016,2018-2021 NXP
       4                 :            :  *
       5                 :            :  */
       6                 :            : 
       7                 :            : #include <string.h>
       8                 :            : #include <dirent.h>
       9                 :            : #include <stdalign.h>
      10                 :            : #include <stdbool.h>
      11                 :            : 
      12                 :            : #include <eal_export.h>
      13                 :            : #include <rte_log.h>
      14                 :            : #include <bus_driver.h>
      15                 :            : #include <rte_malloc.h>
      16                 :            : #include <rte_devargs.h>
      17                 :            : #include <rte_memcpy.h>
      18                 :            : #include <ethdev_driver.h>
      19                 :            : #include <rte_mbuf_dyn.h>
      20                 :            : #include <rte_vfio.h>
      21                 :            : 
      22                 :            : #include "private.h"
      23                 :            : #include <fslmc_vfio.h>
      24                 :            : #include "fslmc_logs.h"
      25                 :            : 
      26                 :            : #include <dpaax_iova_table.h>
      27                 :            : 
      28                 :            : #define VFIO_IOMMU_GROUP_PATH "/sys/kernel/iommu_groups"
      29                 :            : #define FSLMC_BUS_NAME  fslmc
      30                 :            : 
      31                 :            : struct rte_fslmc_bus rte_fslmc_bus;
      32                 :            : 
      33                 :            : #define DPAA2_SEQN_DYNFIELD_NAME "dpaa2_seqn_dynfield"
      34                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpaa2_seqn_dynfield_offset)
      35                 :            : int dpaa2_seqn_dynfield_offset = -1;
      36                 :            : 
      37                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_get_device_count)
      38                 :            : uint32_t
      39                 :          0 : rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type)
      40                 :            : {
      41         [ #  # ]:          0 :         if (device_type >= DPAA2_DEVTYPE_MAX)
      42                 :            :                 return 0;
      43                 :          0 :         return rte_fslmc_bus.device_count[device_type];
      44                 :            : }
      45                 :            : 
      46                 :            : static void
      47                 :          0 : cleanup_fslmc_device_list(void)
      48                 :            : {
      49                 :            :         struct rte_dpaa2_device *dev;
      50                 :            :         struct rte_dpaa2_device *t_dev;
      51                 :            : 
      52         [ #  # ]:          0 :         RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, t_dev) {
      53         [ #  # ]:          0 :                 TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
      54                 :          0 :                 rte_intr_instance_free(dev->intr_handle);
      55                 :          0 :                 free(dev);
      56                 :            :                 dev = NULL;
      57                 :            :         }
      58                 :          0 : }
      59                 :            : 
      60                 :            : static int
      61                 :            : compare_dpaa2_devname(struct rte_dpaa2_device *dev1,
      62                 :            :                       struct rte_dpaa2_device *dev2)
      63                 :            : {
      64                 :            :         int comp;
      65                 :            : 
      66                 :          0 :         if (dev1->dev_type > dev2->dev_type) {
      67                 :            :                 comp = 1;
      68         [ #  # ]:          0 :         } else if (dev1->dev_type < dev2->dev_type) {
      69                 :            :                 comp = -1;
      70                 :            :         } else {
      71                 :            :                 /* Check the ID as types match */
      72         [ #  # ]:          0 :                 if (dev1->object_id > dev2->object_id)
      73                 :            :                         comp = 1;
      74         [ #  # ]:          0 :                 else if (dev1->object_id < dev2->object_id)
      75                 :            :                         comp = -1;
      76                 :            :                 else
      77                 :            :                         comp = 0; /* Duplicate device name */
      78                 :            :         }
      79                 :            : 
      80                 :            :         return comp;
      81                 :            : }
      82                 :            : 
      83                 :            : static void
      84                 :          0 : insert_in_device_list(struct rte_dpaa2_device *newdev)
      85                 :            : {
      86                 :            :         int comp, inserted = 0;
      87                 :            :         struct rte_dpaa2_device *dev = NULL;
      88                 :            :         struct rte_dpaa2_device *tdev = NULL;
      89                 :            : 
      90   [ #  #  #  # ]:          0 :         RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, tdev) {
      91                 :            :                 comp = compare_dpaa2_devname(newdev, dev);
      92                 :            :                 if (comp < 0) {
      93                 :          0 :                         TAILQ_INSERT_BEFORE(dev, newdev, next);
      94                 :            :                         inserted = 1;
      95                 :            :                         break;
      96                 :            :                 }
      97                 :            :         }
      98                 :            : 
      99                 :            :         if (!inserted)
     100                 :          0 :                 TAILQ_INSERT_TAIL(&rte_fslmc_bus.device_list, newdev, next);
     101                 :          0 : }
     102                 :            : 
     103                 :            : static struct rte_devargs *
     104                 :          0 : fslmc_devargs_lookup(struct rte_dpaa2_device *dev)
     105                 :            : {
     106                 :            :         struct rte_devargs *devargs;
     107                 :            :         char dev_name[32];
     108                 :            : 
     109         [ #  # ]:          0 :         RTE_EAL_DEVARGS_FOREACH("fslmc", devargs) {
     110                 :          0 :                 devargs->bus->parse(devargs->name, &dev_name);
     111         [ #  # ]:          0 :                 if (strcmp(dev_name, dev->device.name) == 0) {
     112                 :          0 :                         DPAA2_BUS_INFO("**Devargs matched %s", dev_name);
     113                 :          0 :                         return devargs;
     114                 :            :                 }
     115                 :            :         }
     116                 :            :         return NULL;
     117                 :            : }
     118                 :            : 
     119                 :            : static void
     120                 :          0 : dump_device_list(void)
     121                 :            : {
     122                 :            :         struct rte_dpaa2_device *dev;
     123                 :            : 
     124                 :            :         /* Only if the log level has been set to Debugging, print list */
     125         [ #  # ]:          0 :         if (rte_log_can_log(dpaa2_logtype_bus, RTE_LOG_DEBUG)) {
     126                 :          0 :                 DPAA2_BUS_LOG(DEBUG, "List of devices scanned on bus:");
     127         [ #  # ]:          0 :                 TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
     128                 :          0 :                         DPAA2_BUS_LOG(DEBUG, "\t\t%s", dev->device.name);
     129                 :            :                 }
     130                 :            :         }
     131                 :          0 : }
     132                 :            : 
     133                 :            : static int
     134                 :          0 : scan_one_fslmc_device(char *dev_name)
     135                 :            : {
     136                 :            :         char *dup_dev_name, *t_ptr;
     137                 :            :         struct rte_dpaa2_device *dev = NULL;
     138                 :            :         int ret = -1;
     139                 :            : 
     140         [ #  # ]:          0 :         if (!dev_name)
     141                 :            :                 return ret;
     142                 :            : 
     143                 :            :         /* Creating a temporary copy to perform cut-parse over string */
     144                 :          0 :         dup_dev_name = strdup(dev_name);
     145         [ #  # ]:          0 :         if (!dup_dev_name) {
     146                 :          0 :                 DPAA2_BUS_ERR("Unable to allocate device name memory");
     147                 :          0 :                 return -ENOMEM;
     148                 :            :         }
     149                 :            : 
     150                 :            :         /* For all other devices, we allocate rte_dpaa2_device.
     151                 :            :          * For those devices where there is no driver, probe would release
     152                 :            :          * the memory associated with the rte_dpaa2_device after necessary
     153                 :            :          * initialization.
     154                 :            :          */
     155                 :          0 :         dev = calloc(1, sizeof(struct rte_dpaa2_device));
     156         [ #  # ]:          0 :         if (!dev) {
     157                 :          0 :                 DPAA2_BUS_ERR("Unable to allocate device object");
     158                 :          0 :                 free(dup_dev_name);
     159                 :          0 :                 return -ENOMEM;
     160                 :            :         }
     161                 :            : 
     162                 :          0 :         dev->device.bus = &rte_fslmc_bus.bus;
     163                 :          0 :         dev->device.numa_node = SOCKET_ID_ANY;
     164                 :            : 
     165                 :            :         /* Allocate interrupt instance */
     166                 :          0 :         dev->intr_handle =
     167                 :          0 :                 rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
     168         [ #  # ]:          0 :         if (dev->intr_handle == NULL) {
     169                 :          0 :                 DPAA2_BUS_ERR("Failed to allocate intr handle");
     170                 :            :                 ret = -ENOMEM;
     171                 :          0 :                 goto cleanup;
     172                 :            :         }
     173                 :            : 
     174                 :            :         /* Parse the device name and ID */
     175                 :          0 :         t_ptr = strtok(dup_dev_name, ".");
     176         [ #  # ]:          0 :         if (!t_ptr) {
     177                 :          0 :                 DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
     178                 :            :                 ret = -EINVAL;
     179                 :          0 :                 goto cleanup;
     180                 :            :         }
     181         [ #  # ]:          0 :         if (!strncmp("dpni", t_ptr, 4))
     182                 :          0 :                 dev->dev_type = DPAA2_ETH;
     183         [ #  # ]:          0 :         else if (!strncmp("dpseci", t_ptr, 6))
     184                 :          0 :                 dev->dev_type = DPAA2_CRYPTO;
     185         [ #  # ]:          0 :         else if (!strncmp("dpcon", t_ptr, 5))
     186                 :          0 :                 dev->dev_type = DPAA2_CON;
     187         [ #  # ]:          0 :         else if (!strncmp("dpbp", t_ptr, 4))
     188                 :          0 :                 dev->dev_type = DPAA2_BPOOL;
     189         [ #  # ]:          0 :         else if (!strncmp("dpio", t_ptr, 4))
     190                 :          0 :                 dev->dev_type = DPAA2_IO;
     191         [ #  # ]:          0 :         else if (!strncmp("dpci", t_ptr, 4))
     192                 :          0 :                 dev->dev_type = DPAA2_CI;
     193         [ #  # ]:          0 :         else if (!strncmp("dpmcp", t_ptr, 5))
     194                 :          0 :                 dev->dev_type = DPAA2_MPORTAL;
     195         [ #  # ]:          0 :         else if (!strncmp("dpdmai", t_ptr, 6))
     196                 :          0 :                 dev->dev_type = DPAA2_QDMA;
     197         [ #  # ]:          0 :         else if (!strncmp("dpdmux", t_ptr, 6))
     198                 :          0 :                 dev->dev_type = DPAA2_MUX;
     199         [ #  # ]:          0 :         else if (!strncmp("dprtc", t_ptr, 5))
     200                 :          0 :                 dev->dev_type = DPAA2_DPRTC;
     201         [ #  # ]:          0 :         else if (!strncmp("dprc", t_ptr, 4))
     202                 :          0 :                 dev->dev_type = DPAA2_DPRC;
     203                 :            :         else
     204                 :          0 :                 dev->dev_type = DPAA2_UNKNOWN;
     205                 :            : 
     206                 :          0 :         t_ptr = strtok(NULL, ".");
     207         [ #  # ]:          0 :         if (!t_ptr) {
     208                 :          0 :                 DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
     209                 :            :                 ret = 0;
     210                 :          0 :                 goto cleanup;
     211                 :            :         }
     212                 :            : 
     213                 :          0 :         sscanf(t_ptr, "%hu", &dev->object_id);
     214                 :          0 :         dev->device.name = strdup(dev_name);
     215         [ #  # ]:          0 :         if (!dev->device.name) {
     216                 :          0 :                 DPAA2_BUS_ERR("Unable to clone device name. Out of memory");
     217                 :            :                 ret = -ENOMEM;
     218                 :          0 :                 goto cleanup;
     219                 :            :         }
     220                 :          0 :         dev->device.devargs = fslmc_devargs_lookup(dev);
     221                 :            : 
     222                 :            :         /* Update the device found into the device_count table */
     223                 :          0 :         rte_fslmc_bus.device_count[dev->dev_type]++;
     224                 :            : 
     225                 :            :         /* Add device in the fslmc device list */
     226                 :          0 :         insert_in_device_list(dev);
     227                 :            : 
     228                 :            :         /* Don't need the duplicated device filesystem entry anymore */
     229                 :          0 :         free(dup_dev_name);
     230                 :            : 
     231                 :          0 :         return 0;
     232                 :          0 : cleanup:
     233                 :          0 :         free(dup_dev_name);
     234                 :            :         if (dev) {
     235                 :          0 :                 rte_intr_instance_free(dev->intr_handle);
     236                 :          0 :                 free(dev);
     237                 :            :         }
     238                 :          0 :         return ret;
     239                 :            : }
     240                 :            : 
     241                 :            : static int
     242                 :         37 : rte_fslmc_parse(const char *name, void *addr)
     243                 :            : {
     244                 :            :         uint16_t dev_id;
     245                 :            :         char *t_ptr;
     246                 :            :         const char *sep;
     247                 :            :         uint8_t sep_exists = 0;
     248                 :            :         int ret = -1;
     249                 :            : 
     250                 :            :         /* There are multiple ways this can be called, with bus:dev, name=dev
     251                 :            :          * or just dev. In all cases, the 'addr' is actually a string.
     252                 :            :          */
     253                 :         37 :         sep = strchr(name, ':');
     254         [ +  + ]:         37 :         if (!sep) {
     255                 :            :                 /* check for '=' */
     256                 :         18 :                 sep = strchr(name, '=');
     257         [ +  + ]:         18 :                 if (!sep)
     258                 :            :                         sep_exists = 0;
     259                 :            :                 else
     260                 :            :                         sep_exists = 1;
     261                 :            :         } else
     262                 :            :                 sep_exists = 1;
     263                 :            : 
     264                 :            :         /* Check if starting part if either of 'fslmc:' or 'name=', separator
     265                 :            :          * exists.
     266                 :            :          */
     267                 :            :         if (sep_exists) {
     268                 :            :                 /* If either of "fslmc" or "name" are starting part */
     269         [ +  - ]:         21 :                 if (!strncmp(name, RTE_STR(FSLMC_BUS_NAME),
     270                 :         21 :                              strlen(RTE_STR(FSLMC_BUS_NAME))) ||
     271         [ -  + ]:         21 :                    (!strncmp(name, "name", strlen("name")))) {
     272                 :          0 :                         goto jump_out;
     273                 :            :                 } else {
     274                 :         21 :                         DPAA2_BUS_DEBUG("Invalid device for matching (%s).",
     275                 :            :                                         name);
     276                 :            :                         ret = -EINVAL;
     277                 :         21 :                         goto err_out;
     278                 :            :                 }
     279                 :            :         } else
     280                 :            :                 sep = name;
     281                 :            : 
     282                 :         16 : jump_out:
     283                 :            :         /* Validate device name */
     284         [ +  - ]:         16 :         if (strncmp("dpni", sep, 4) &&
     285         [ +  - ]:         16 :             strncmp("dpseci", sep, 6) &&
     286         [ +  - ]:         16 :             strncmp("dpcon", sep, 5) &&
     287         [ +  - ]:         16 :             strncmp("dpbp", sep, 4) &&
     288         [ +  - ]:         16 :             strncmp("dpio", sep, 4) &&
     289         [ +  - ]:         16 :             strncmp("dpci", sep, 4) &&
     290         [ +  - ]:         16 :             strncmp("dpmcp", sep, 5) &&
     291         [ +  - ]:         16 :             strncmp("dpdmai", sep, 6) &&
     292         [ +  - ]:         16 :             strncmp("dpdmux", sep, 6)) {
     293                 :         16 :                 DPAA2_BUS_DEBUG("Unknown or unsupported device (%s)", sep);
     294                 :            :                 ret = -EINVAL;
     295                 :         16 :                 goto err_out;
     296                 :            :         }
     297                 :            : 
     298                 :          0 :         t_ptr = strchr(sep, '.');
     299   [ #  #  #  # ]:          0 :         if (!t_ptr || sscanf(t_ptr + 1, "%hu", &dev_id) != 1) {
     300                 :          0 :                 DPAA2_BUS_ERR("Missing device id in device name (%s)", sep);
     301                 :            :                 ret = -EINVAL;
     302                 :          0 :                 goto err_out;
     303                 :            :         }
     304                 :            : 
     305         [ #  # ]:          0 :         if (addr)
     306                 :            :                 strcpy(addr, sep);
     307                 :            : 
     308                 :            :         ret = 0;
     309                 :         37 : err_out:
     310                 :         37 :         return ret;
     311                 :            : }
     312                 :            : 
     313                 :            : static int
     314                 :        186 : rte_fslmc_scan(void)
     315                 :            : {
     316                 :            :         int ret;
     317                 :            :         char fslmc_dirpath[PATH_MAX];
     318                 :            :         DIR *dir;
     319                 :            :         struct dirent *entry;
     320                 :            :         static int process_once;
     321                 :            :         int groupid;
     322                 :            :         char *group_name;
     323                 :            : 
     324         [ -  + ]:        186 :         if (process_once) {
     325                 :          0 :                 DPAA2_BUS_DEBUG("Fslmc bus already scanned. Not rescanning");
     326                 :          0 :                 return 0;
     327                 :            :         }
     328                 :        186 :         process_once = 1;
     329                 :            : 
     330                 :            :         /* Now we only support single group per process.*/
     331                 :        186 :         group_name = getenv("DPRC");
     332         [ +  - ]:        186 :         if (!group_name) {
     333                 :        186 :                 DPAA2_BUS_DEBUG("DPAA2: DPRC not available");
     334                 :            :                 ret = -EINVAL;
     335                 :        186 :                 goto scan_fail;
     336                 :            :         }
     337                 :            : 
     338                 :          0 :         ret = fslmc_get_container_group(group_name, &groupid);
     339         [ #  # ]:          0 :         if (ret != 0)
     340                 :          0 :                 goto scan_fail;
     341                 :            : 
     342                 :            :         /* Scan devices on the group */
     343                 :            :         sprintf(fslmc_dirpath, "%s/%s", SYSFS_FSL_MC_DEVICES, group_name);
     344                 :          0 :         dir = opendir(fslmc_dirpath);
     345         [ #  # ]:          0 :         if (!dir) {
     346                 :          0 :                 DPAA2_BUS_ERR("Unable to open VFIO group directory");
     347                 :          0 :                 goto scan_fail;
     348                 :            :         }
     349                 :            : 
     350                 :            :         /* Scan the DPRC container object */
     351                 :          0 :         ret = scan_one_fslmc_device(group_name);
     352         [ #  # ]:          0 :         if (ret != 0) {
     353                 :            :                 /* Error in parsing directory - exit gracefully */
     354                 :          0 :                 goto scan_fail_cleanup;
     355                 :            :         }
     356                 :            : 
     357         [ #  # ]:          0 :         while ((entry = readdir(dir)) != NULL) {
     358   [ #  #  #  # ]:          0 :                 if (entry->d_name[0] == '.' || entry->d_type != DT_DIR)
     359                 :          0 :                         continue;
     360                 :            : 
     361                 :          0 :                 ret = scan_one_fslmc_device(entry->d_name);
     362         [ #  # ]:          0 :                 if (ret != 0) {
     363                 :            :                         /* Error in parsing directory - exit gracefully */
     364                 :          0 :                         goto scan_fail_cleanup;
     365                 :            :                 }
     366                 :            :         }
     367                 :            : 
     368                 :          0 :         closedir(dir);
     369                 :            : 
     370                 :          0 :         DPAA2_BUS_INFO("FSLMC Bus scan completed");
     371                 :            :         /* If debugging is enabled, device list is dumped to log output */
     372                 :          0 :         dump_device_list();
     373                 :            : 
     374                 :          0 :         return 0;
     375                 :            : 
     376                 :          0 : scan_fail_cleanup:
     377                 :          0 :         closedir(dir);
     378                 :            : 
     379                 :            :         /* Remove all devices in the list */
     380                 :          0 :         cleanup_fslmc_device_list();
     381                 :        186 : scan_fail:
     382                 :        186 :         DPAA2_BUS_DEBUG("FSLMC Bus Not Available. Skipping (%d)", ret);
     383                 :            :         /* Irrespective of failure, scan only return success */
     384                 :        186 :         return 0;
     385                 :            : }
     386                 :            : 
     387                 :            : static int
     388                 :            : rte_fslmc_match(struct rte_dpaa2_driver *dpaa2_drv,
     389                 :            :                 struct rte_dpaa2_device *dpaa2_dev)
     390                 :            : {
     391   [ #  #  #  # ]:          0 :         if (dpaa2_drv->drv_type == dpaa2_dev->dev_type)
     392                 :            :                 return 0;
     393                 :            : 
     394                 :            :         return 1;
     395                 :            : }
     396                 :            : 
     397                 :            : static int
     398                 :        246 : rte_fslmc_close(void)
     399                 :            : {
     400                 :            :         int ret = 0;
     401                 :            : 
     402                 :        246 :         ret = fslmc_vfio_close_group();
     403         [ +  - ]:        246 :         if (ret)
     404                 :        246 :                 DPAA2_BUS_INFO("Unable to close devices %d", ret);
     405                 :            : 
     406                 :        246 :         return 0;
     407                 :            : }
     408                 :            : 
     409                 :            : static int
     410                 :        181 : rte_fslmc_probe(void)
     411                 :            : {
     412                 :            :         int ret = 0;
     413                 :            :         int probe_all;
     414                 :            : 
     415                 :            :         struct rte_dpaa2_device *dev;
     416                 :            :         struct rte_dpaa2_driver *drv;
     417                 :            : 
     418                 :            :         static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = {
     419                 :            :                 .name = DPAA2_SEQN_DYNFIELD_NAME,
     420                 :            :                 .size = sizeof(dpaa2_seqn_t),
     421                 :            :                 .align = alignof(dpaa2_seqn_t),
     422                 :            :         };
     423                 :            : 
     424         [ -  + ]:        181 :         if (TAILQ_EMPTY(&rte_fslmc_bus.device_list))
     425                 :            :                 return 0;
     426                 :            : 
     427                 :          0 :         dpaa2_seqn_dynfield_offset =
     428                 :          0 :                 rte_mbuf_dynfield_register(&dpaa2_seqn_dynfield_desc);
     429         [ #  # ]:          0 :         if (dpaa2_seqn_dynfield_offset < 0) {
     430                 :          0 :                 DPAA2_BUS_ERR("Failed to register mbuf field for dpaa sequence number");
     431                 :          0 :                 return 0;
     432                 :            :         }
     433                 :            : 
     434                 :          0 :         ret = fslmc_vfio_setup_group();
     435         [ #  # ]:          0 :         if (ret) {
     436                 :          0 :                 DPAA2_BUS_ERR("Unable to setup VFIO %d", ret);
     437                 :          0 :                 return 0;
     438                 :            :         }
     439                 :            : 
     440                 :            :         /* Map existing segments as well as, in case of hotpluggable memory,
     441                 :            :          * install callback handler.
     442                 :            :          */
     443         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
     444                 :          0 :                 ret = fslmc_vfio_dmamap();
     445         [ #  # ]:          0 :                 if (ret) {
     446                 :          0 :                         DPAA2_BUS_ERR("Unable to DMA map existing VAs: (%d)",
     447                 :            :                                       ret);
     448                 :            :                         /* Not continuing ahead */
     449                 :          0 :                         DPAA2_BUS_ERR("FSLMC VFIO Mapping failed");
     450                 :          0 :                         return 0;
     451                 :            :                 }
     452                 :            :         }
     453                 :            : 
     454                 :          0 :         ret = fslmc_vfio_process_group();
     455         [ #  # ]:          0 :         if (ret) {
     456                 :          0 :                 DPAA2_BUS_ERR("Unable to setup devices %d", ret);
     457                 :          0 :                 return 0;
     458                 :            :         }
     459                 :            : 
     460                 :          0 :         probe_all = rte_fslmc_bus.bus.conf.scan_mode != RTE_BUS_SCAN_ALLOWLIST;
     461                 :            : 
     462         [ #  # ]:          0 :         TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
     463         [ #  # ]:          0 :                 TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
     464                 :            :                         ret = rte_fslmc_match(drv, dev);
     465                 :          0 :                         if (ret)
     466                 :          0 :                                 continue;
     467                 :            : 
     468         [ #  # ]:          0 :                         if (!drv->probe)
     469                 :          0 :                                 continue;
     470                 :            : 
     471         [ #  # ]:          0 :                         if (rte_dev_is_probed(&dev->device))
     472                 :          0 :                                 continue;
     473                 :            : 
     474         [ #  # ]:          0 :                         if (dev->device.devargs &&
     475         [ #  # ]:          0 :                             dev->device.devargs->policy == RTE_DEV_BLOCKED) {
     476                 :          0 :                                 DPAA2_BUS_LOG(DEBUG, "%s Blocked, skipping",
     477                 :            :                                               dev->device.name);
     478                 :          0 :                                 continue;
     479                 :            :                         }
     480                 :            : 
     481   [ #  #  #  # ]:          0 :                         if (probe_all ||
     482                 :          0 :                            (dev->device.devargs &&
     483         [ #  # ]:          0 :                             dev->device.devargs->policy == RTE_DEV_ALLOWED)) {
     484                 :          0 :                                 ret = drv->probe(drv, dev);
     485         [ #  # ]:          0 :                                 if (ret) {
     486                 :          0 :                                         DPAA2_BUS_ERR("Unable to probe");
     487                 :            :                                 } else {
     488                 :          0 :                                         dev->driver = drv;
     489                 :          0 :                                         dev->device.driver = &drv->driver;
     490                 :            :                                 }
     491                 :            :                         }
     492                 :            :                         break;
     493                 :            :                 }
     494                 :            :         }
     495                 :            : 
     496                 :            :         return 0;
     497                 :            : }
     498                 :            : 
     499                 :            : static struct rte_device *
     500                 :          0 : rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
     501                 :            :                       const void *data)
     502                 :            : {
     503                 :            :         const struct rte_dpaa2_device *dstart;
     504                 :            :         struct rte_dpaa2_device *dev;
     505                 :            : 
     506                 :          0 :         DPAA2_BUS_DEBUG("Finding a device named %s", (const char *)data);
     507                 :            : 
     508                 :            :         /* find_device is always called with an opaque object which should be
     509                 :            :          * passed along to the 'cmp' function iterating over all device obj
     510                 :            :          * on the bus.
     511                 :            :          */
     512                 :            : 
     513         [ #  # ]:          0 :         if (start != NULL) {
     514                 :          0 :                 dstart = RTE_DEV_TO_FSLMC_CONST(start);
     515                 :          0 :                 dev = TAILQ_NEXT(dstart, next);
     516                 :            :         } else {
     517                 :          0 :                 dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
     518                 :            :         }
     519         [ #  # ]:          0 :         while (dev != NULL) {
     520         [ #  # ]:          0 :                 if (cmp(&dev->device, data) == 0) {
     521                 :          0 :                         DPAA2_BUS_DEBUG("Found device (%s)",
     522                 :            :                                         dev->device.name);
     523                 :          0 :                         return &dev->device;
     524                 :            :                 }
     525                 :          0 :                 dev = TAILQ_NEXT(dev, next);
     526                 :            :         }
     527                 :            : 
     528                 :            :         return NULL;
     529                 :            : }
     530                 :            : 
     531                 :            : /*register a fslmc bus based dpaa2 driver */
     532                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_register)
     533                 :            : void
     534                 :        759 : rte_fslmc_driver_register(struct rte_dpaa2_driver *driver)
     535                 :            : {
     536         [ -  + ]:        759 :         RTE_VERIFY(driver);
     537                 :            : 
     538                 :        759 :         TAILQ_INSERT_TAIL(&rte_fslmc_bus.driver_list, driver, next);
     539                 :        759 : }
     540                 :            : 
     541                 :            : /*un-register a fslmc bus based dpaa2 driver */
     542                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_unregister)
     543                 :            : void
     544                 :          0 : rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver)
     545                 :            : {
     546         [ #  # ]:          0 :         TAILQ_REMOVE(&rte_fslmc_bus.driver_list, driver, next);
     547                 :          0 : }
     548                 :            : 
     549                 :            : /*
     550                 :            :  * All device has iova as va
     551                 :            :  */
     552                 :            : static inline int
     553                 :            : fslmc_all_device_support_iova(void)
     554                 :            : {
     555                 :            :         int ret = 0;
     556                 :            :         struct rte_dpaa2_device *dev;
     557                 :            :         struct rte_dpaa2_driver *drv;
     558                 :            : 
     559         [ #  # ]:          0 :         TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
     560         [ #  # ]:          0 :                 TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
     561                 :            :                         ret = rte_fslmc_match(drv, dev);
     562                 :          0 :                         if (ret)
     563                 :          0 :                                 continue;
     564                 :            :                         /* if the driver is not supporting IOVA */
     565         [ #  # ]:          0 :                         if (!(drv->drv_flags & RTE_DPAA2_DRV_IOVA_AS_VA))
     566                 :            :                                 return 0;
     567                 :            :                 }
     568                 :            :         }
     569                 :            :         return 1;
     570                 :            : }
     571                 :            : 
     572                 :            : /*
     573                 :            :  * Get iommu class of DPAA2 devices on the bus.
     574                 :            :  */
     575                 :            : static enum rte_iova_mode
     576                 :        186 : rte_dpaa2_get_iommu_class(void)
     577                 :            : {
     578         [ +  - ]:        186 :         if (rte_eal_iova_mode() == RTE_IOVA_PA)
     579                 :            :                 return RTE_IOVA_PA;
     580                 :            : 
     581         [ -  + ]:        186 :         if (TAILQ_EMPTY(&rte_fslmc_bus.device_list))
     582                 :            :                 return RTE_IOVA_DC;
     583                 :            : 
     584                 :            :         /* check if all devices on the bus support Virtual addressing or not */
     585   [ #  #  #  # ]:          0 :         if (fslmc_all_device_support_iova() != 0 && rte_vfio_noiommu_is_enabled() == 0)
     586                 :          0 :                 return RTE_IOVA_VA;
     587                 :            : 
     588                 :            :         return RTE_IOVA_PA;
     589                 :            : }
     590                 :            : 
     591                 :            : static int
     592                 :          0 : fslmc_bus_plug(struct rte_device *dev __rte_unused)
     593                 :            : {
     594                 :            :         /* No operation is performed while plugging the device */
     595                 :          0 :         return 0;
     596                 :            : }
     597                 :            : 
     598                 :            : static int
     599                 :          0 : fslmc_bus_unplug(struct rte_device *dev __rte_unused)
     600                 :            : {
     601                 :            :         /* No operation is performed while unplugging the device */
     602                 :          0 :         return 0;
     603                 :            : }
     604                 :            : 
     605                 :            : static void *
     606                 :          0 : fslmc_bus_dev_iterate(const void *start, const char *str,
     607                 :            :                       const struct rte_dev_iterator *it __rte_unused)
     608                 :            : {
     609                 :            :         const struct rte_dpaa2_device *dstart;
     610                 :            :         struct rte_dpaa2_device *dev;
     611                 :            :         char *dup, *dev_name = NULL;
     612                 :            : 
     613         [ #  # ]:          0 :         if (str == NULL) {
     614                 :          0 :                 DPAA2_BUS_DEBUG("No device string");
     615                 :          0 :                 return NULL;
     616                 :            :         }
     617                 :            : 
     618                 :            :         /* Expectation is that device would be name=device_name */
     619         [ #  # ]:          0 :         if (strncmp(str, "name=", 5) != 0) {
     620                 :          0 :                 DPAA2_BUS_DEBUG("Invalid device string (%s)", str);
     621                 :          0 :                 return NULL;
     622                 :            :         }
     623                 :            : 
     624                 :            :         /* Now that name=device_name format is available, split */
     625                 :          0 :         dup = strdup(str);
     626         [ #  # ]:          0 :         if (dup == NULL) {
     627                 :          0 :                 DPAA2_BUS_DEBUG("Dup string (%s) failed!", str);
     628                 :          0 :                 return NULL;
     629                 :            :         }
     630                 :          0 :         dev_name = dup + strlen("name=");
     631                 :            : 
     632         [ #  # ]:          0 :         if (start != NULL) {
     633                 :          0 :                 dstart = RTE_DEV_TO_FSLMC_CONST(start);
     634                 :          0 :                 dev = TAILQ_NEXT(dstart, next);
     635                 :            :         } else {
     636                 :          0 :                 dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
     637                 :            :         }
     638                 :            : 
     639         [ #  # ]:          0 :         while (dev != NULL) {
     640         [ #  # ]:          0 :                 if (strcmp(dev->device.name, dev_name) == 0) {
     641                 :          0 :                         free(dup);
     642                 :          0 :                         return &dev->device;
     643                 :            :                 }
     644                 :          0 :                 dev = TAILQ_NEXT(dev, next);
     645                 :            :         }
     646                 :            : 
     647                 :          0 :         free(dup);
     648                 :          0 :         return NULL;
     649                 :            : }
     650                 :            : 
     651                 :            : struct rte_fslmc_bus rte_fslmc_bus = {
     652                 :            :         .bus = {
     653                 :            :                 .scan = rte_fslmc_scan,
     654                 :            :                 .probe = rte_fslmc_probe,
     655                 :            :                 .cleanup = rte_fslmc_close,
     656                 :            :                 .parse = rte_fslmc_parse,
     657                 :            :                 .find_device = rte_fslmc_find_device,
     658                 :            :                 .get_iommu_class = rte_dpaa2_get_iommu_class,
     659                 :            :                 .plug = fslmc_bus_plug,
     660                 :            :                 .unplug = fslmc_bus_unplug,
     661                 :            :                 .dev_iterate = fslmc_bus_dev_iterate,
     662                 :            :         },
     663                 :            :         .device_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.device_list),
     664                 :            :         .driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
     665                 :            :         .device_count = {0},
     666                 :            : };
     667                 :            : 
     668                 :        253 : RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);
     669         [ -  + ]:        253 : RTE_LOG_REGISTER_DEFAULT(dpaa2_logtype_bus, NOTICE);

Generated by: LCOV version 1.14