LCOV - code coverage report
Current view: top level - drivers/bus/fslmc - fslmc_bus.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 50 279 17.9 %
Date: 2026-05-01 18:54:57 Functions: 8 19 42.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 196 12.2 %

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

Generated by: LCOV version 1.14