LCOV - code coverage report
Current view: top level - drivers/bus/fslmc - fslmc_bus.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 47 221 21.3 %
Date: 2026-07-01 18:02:41 Functions: 7 17 41.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 158 14.6 %

           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_bus rte_fslmc_bus;
      31                 :            : static int fslmc_bus_device_count[DPAA2_DEVTYPE_MAX];
      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 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                 :            : 
      51         [ #  # ]:          0 :         RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
      52                 :          0 :                 rte_bus_remove_device(&rte_fslmc_bus, &dev->device);
      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                 :            : 
      88   [ #  #  #  # ]:          0 :         RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
      89                 :            :                 comp = compare_dpaa2_devname(newdev, dev);
      90                 :            :                 if (comp < 0) {
      91                 :          0 :                         rte_bus_insert_device(&rte_fslmc_bus, &dev->device, &newdev->device);
      92                 :            :                         inserted = 1;
      93                 :            :                         break;
      94                 :            :                 }
      95                 :            :         }
      96                 :            : 
      97                 :            :         if (!inserted)
      98                 :          0 :                 rte_bus_add_device(&rte_fslmc_bus, &newdev->device);
      99                 :          0 : }
     100                 :            : 
     101                 :            : static void
     102                 :          0 : dump_device_list(void)
     103                 :            : {
     104                 :            :         struct rte_dpaa2_device *dev;
     105                 :            : 
     106                 :            :         /* Only if the log level has been set to Debugging, print list */
     107         [ #  # ]:          0 :         if (rte_log_can_log(dpaa2_logtype_bus, RTE_LOG_DEBUG)) {
     108                 :          0 :                 DPAA2_BUS_LOG(DEBUG, "List of devices scanned on bus:");
     109         [ #  # ]:          0 :                 RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
     110                 :          0 :                         DPAA2_BUS_LOG(DEBUG, "\t\t%s", dev->device.name);
     111                 :            :                 }
     112                 :            :         }
     113                 :          0 : }
     114                 :            : 
     115                 :            : static int
     116                 :          0 : scan_one_fslmc_device(char *dev_name)
     117                 :            : {
     118                 :            :         char *dup_dev_name, *t_ptr;
     119                 :            :         struct rte_dpaa2_device *dev = NULL;
     120                 :            :         int ret = -1;
     121                 :            : 
     122         [ #  # ]:          0 :         if (!dev_name)
     123                 :            :                 return ret;
     124                 :            : 
     125                 :            :         /* Creating a temporary copy to perform cut-parse over string */
     126                 :          0 :         dup_dev_name = strdup(dev_name);
     127         [ #  # ]:          0 :         if (!dup_dev_name) {
     128                 :          0 :                 DPAA2_BUS_ERR("Unable to allocate device name memory");
     129                 :          0 :                 return -ENOMEM;
     130                 :            :         }
     131                 :            : 
     132                 :            :         /* For all other devices, we allocate rte_dpaa2_device.
     133                 :            :          * For those devices where there is no driver, probe would release
     134                 :            :          * the memory associated with the rte_dpaa2_device after necessary
     135                 :            :          * initialization.
     136                 :            :          */
     137                 :          0 :         dev = calloc(1, sizeof(struct rte_dpaa2_device));
     138         [ #  # ]:          0 :         if (!dev) {
     139                 :          0 :                 DPAA2_BUS_ERR("Unable to allocate device object");
     140                 :          0 :                 free(dup_dev_name);
     141                 :          0 :                 return -ENOMEM;
     142                 :            :         }
     143                 :            : 
     144                 :          0 :         dev->device.numa_node = SOCKET_ID_ANY;
     145                 :            : 
     146                 :            :         /* Allocate interrupt instance */
     147                 :          0 :         dev->intr_handle =
     148                 :          0 :                 rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
     149         [ #  # ]:          0 :         if (dev->intr_handle == NULL) {
     150                 :          0 :                 DPAA2_BUS_ERR("Failed to allocate intr handle");
     151                 :            :                 ret = -ENOMEM;
     152                 :          0 :                 goto cleanup;
     153                 :            :         }
     154                 :            : 
     155                 :            :         /* Parse the device name and ID */
     156                 :          0 :         t_ptr = strtok(dup_dev_name, ".");
     157         [ #  # ]:          0 :         if (!t_ptr) {
     158                 :          0 :                 DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
     159                 :            :                 ret = -EINVAL;
     160                 :          0 :                 goto cleanup;
     161                 :            :         }
     162         [ #  # ]:          0 :         if (!strncmp("dpni", t_ptr, 4))
     163                 :          0 :                 dev->dev_type = DPAA2_ETH;
     164         [ #  # ]:          0 :         else if (!strncmp("dpseci", t_ptr, 6))
     165                 :          0 :                 dev->dev_type = DPAA2_CRYPTO;
     166         [ #  # ]:          0 :         else if (!strncmp("dpcon", t_ptr, 5))
     167                 :          0 :                 dev->dev_type = DPAA2_CON;
     168         [ #  # ]:          0 :         else if (!strncmp("dpbp", t_ptr, 4))
     169                 :          0 :                 dev->dev_type = DPAA2_BPOOL;
     170         [ #  # ]:          0 :         else if (!strncmp("dpio", t_ptr, 4))
     171                 :          0 :                 dev->dev_type = DPAA2_IO;
     172         [ #  # ]:          0 :         else if (!strncmp("dpci", t_ptr, 4))
     173                 :          0 :                 dev->dev_type = DPAA2_CI;
     174         [ #  # ]:          0 :         else if (!strncmp("dpmcp", t_ptr, 5))
     175                 :          0 :                 dev->dev_type = DPAA2_MPORTAL;
     176         [ #  # ]:          0 :         else if (!strncmp("dpdmai", t_ptr, 6))
     177                 :          0 :                 dev->dev_type = DPAA2_QDMA;
     178         [ #  # ]:          0 :         else if (!strncmp("dpdmux", t_ptr, 6))
     179                 :          0 :                 dev->dev_type = DPAA2_MUX;
     180         [ #  # ]:          0 :         else if (!strncmp("dprtc", t_ptr, 5))
     181                 :          0 :                 dev->dev_type = DPAA2_DPRTC;
     182         [ #  # ]:          0 :         else if (!strncmp("dprc", t_ptr, 4))
     183                 :          0 :                 dev->dev_type = DPAA2_DPRC;
     184                 :            :         else
     185                 :          0 :                 dev->dev_type = DPAA2_UNKNOWN;
     186                 :            : 
     187                 :          0 :         t_ptr = strtok(NULL, ".");
     188         [ #  # ]:          0 :         if (!t_ptr) {
     189                 :          0 :                 DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
     190                 :            :                 ret = 0;
     191                 :          0 :                 goto cleanup;
     192                 :            :         }
     193                 :            : 
     194                 :          0 :         sscanf(t_ptr, "%hu", &dev->object_id);
     195                 :          0 :         dev->device.name = strdup(dev_name);
     196         [ #  # ]:          0 :         if (!dev->device.name) {
     197                 :          0 :                 DPAA2_BUS_ERR("Unable to clone device name. Out of memory");
     198                 :            :                 ret = -ENOMEM;
     199                 :          0 :                 goto cleanup;
     200                 :            :         }
     201                 :          0 :         dev->device.devargs = rte_bus_find_devargs(&rte_fslmc_bus, dev_name);
     202                 :            : 
     203                 :            :         /* Update the device found into the device_count table */
     204                 :          0 :         fslmc_bus_device_count[dev->dev_type]++;
     205                 :            : 
     206                 :            :         /* Add device in the fslmc device list */
     207                 :          0 :         insert_in_device_list(dev);
     208                 :            : 
     209                 :            :         /* Don't need the duplicated device filesystem entry anymore */
     210                 :          0 :         free(dup_dev_name);
     211                 :            : 
     212                 :          0 :         return 0;
     213                 :          0 : cleanup:
     214                 :          0 :         free(dup_dev_name);
     215                 :            :         if (dev) {
     216                 :          0 :                 rte_intr_instance_free(dev->intr_handle);
     217                 :          0 :                 free(dev);
     218                 :            :         }
     219                 :          0 :         return ret;
     220                 :            : }
     221                 :            : 
     222                 :            : static int
     223                 :         42 : rte_fslmc_parse(const char *name, void *addr)
     224                 :            : {
     225                 :            :         uint16_t dev_id;
     226                 :            :         const char *t_ptr;
     227                 :            :         const char *sep;
     228                 :            :         uint8_t sep_exists = 0;
     229                 :            :         int ret = -1;
     230                 :            : 
     231                 :            :         /* There are multiple ways this can be called, with bus:dev, name=dev
     232                 :            :          * or just dev. In all cases, the 'addr' is actually a string.
     233                 :            :          */
     234                 :         42 :         sep = strchr(name, ':');
     235         [ +  + ]:         42 :         if (!sep) {
     236                 :            :                 /* check for '=' */
     237                 :         20 :                 sep = strchr(name, '=');
     238         [ +  + ]:         20 :                 if (!sep)
     239                 :            :                         sep_exists = 0;
     240                 :            :                 else
     241                 :            :                         sep_exists = 1;
     242                 :            :         } else
     243                 :            :                 sep_exists = 1;
     244                 :            : 
     245                 :            :         /* Check if starting part if either of 'fslmc:' or 'name=', separator
     246                 :            :          * exists.
     247                 :            :          */
     248                 :            :         if (sep_exists) {
     249                 :            :                 /* If either of "fslmc" or "name" are starting part */
     250         [ +  - ]:         24 :                 if (!strncmp(name, rte_fslmc_bus.name, strlen(rte_fslmc_bus.name)) ||
     251         [ -  + ]:         24 :                    (!strncmp(name, "name", strlen("name")))) {
     252                 :          0 :                         goto jump_out;
     253                 :            :                 } else {
     254                 :         24 :                         DPAA2_BUS_DEBUG("Invalid device for matching (%s).",
     255                 :            :                                         name);
     256                 :            :                         ret = -EINVAL;
     257                 :         24 :                         goto err_out;
     258                 :            :                 }
     259                 :            :         } else
     260                 :            :                 sep = name;
     261                 :            : 
     262                 :         18 : jump_out:
     263                 :            :         /* Validate device name */
     264         [ +  - ]:         18 :         if (strncmp("dpni", sep, 4) &&
     265         [ +  - ]:         18 :             strncmp("dpseci", sep, 6) &&
     266         [ +  - ]:         18 :             strncmp("dpcon", sep, 5) &&
     267         [ +  - ]:         18 :             strncmp("dpbp", sep, 4) &&
     268         [ +  - ]:         18 :             strncmp("dpio", sep, 4) &&
     269         [ +  - ]:         18 :             strncmp("dpci", sep, 4) &&
     270         [ +  - ]:         18 :             strncmp("dpmcp", sep, 5) &&
     271         [ +  - ]:         18 :             strncmp("dpdmai", sep, 6) &&
     272         [ +  - ]:         18 :             strncmp("dpdmux", sep, 6)) {
     273                 :         18 :                 DPAA2_BUS_DEBUG("Unknown or unsupported device (%s)", sep);
     274                 :            :                 ret = -EINVAL;
     275                 :         18 :                 goto err_out;
     276                 :            :         }
     277                 :            : 
     278                 :          0 :         t_ptr = strchr(sep, '.');
     279   [ #  #  #  # ]:          0 :         if (!t_ptr || sscanf(t_ptr + 1, "%hu", &dev_id) != 1) {
     280                 :          0 :                 DPAA2_BUS_ERR("Missing device id in device name (%s)", sep);
     281                 :            :                 ret = -EINVAL;
     282                 :          0 :                 goto err_out;
     283                 :            :         }
     284                 :            : 
     285         [ #  # ]:          0 :         if (addr)
     286                 :            :                 strcpy(addr, sep);
     287                 :            : 
     288                 :            :         ret = 0;
     289                 :         42 : err_out:
     290                 :         42 :         return ret;
     291                 :            : }
     292                 :            : 
     293                 :            : static int
     294                 :          0 : fslmc_dev_compare(const char *name1, const char *name2)
     295                 :            : {
     296                 :            :         char devname1[32], devname2[32];
     297                 :            : 
     298   [ #  #  #  # ]:          0 :         if (rte_fslmc_parse(name1, devname1) != 0 ||
     299                 :          0 :                         rte_fslmc_parse(name2, devname2) != 0)
     300                 :          0 :                 return 1;
     301                 :            : 
     302                 :          0 :         return strncmp(devname1, devname2, sizeof(devname1));
     303                 :            : }
     304                 :            : 
     305                 :            : static int
     306                 :        225 : rte_fslmc_scan(void)
     307                 :            : {
     308                 :            :         int ret;
     309                 :            :         char fslmc_dirpath[PATH_MAX];
     310                 :            :         DIR *dir;
     311                 :            :         struct dirent *entry;
     312                 :            :         static int process_once;
     313                 :            :         int groupid;
     314                 :            :         char *group_name;
     315                 :            : 
     316         [ -  + ]:        225 :         if (process_once) {
     317                 :            :                 struct rte_dpaa2_device *dev;
     318                 :            : 
     319                 :          0 :                 DPAA2_BUS_DEBUG("Fslmc bus already scanned. Not rescanning");
     320         [ #  # ]:          0 :                 RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
     321                 :          0 :                         dev->device.devargs = rte_bus_find_devargs(&rte_fslmc_bus,
     322                 :            :                                 dev->device.name);
     323                 :            :                 }
     324                 :            :                 return 0;
     325                 :            :         }
     326                 :            : 
     327                 :            :         /* Now we only support single group per process.*/
     328                 :        225 :         group_name = getenv("DPRC");
     329         [ +  - ]:        225 :         if (!group_name) {
     330                 :        225 :                 DPAA2_BUS_DEBUG("DPAA2: DPRC not available");
     331                 :            :                 ret = -EINVAL;
     332                 :        225 :                 goto scan_fail;
     333                 :            :         }
     334                 :            : 
     335                 :          0 :         ret = fslmc_get_container_group(group_name, &groupid);
     336         [ #  # ]:          0 :         if (ret != 0)
     337                 :          0 :                 goto scan_fail;
     338                 :            : 
     339                 :            :         /* Scan devices on the group */
     340                 :            :         sprintf(fslmc_dirpath, "%s/%s", SYSFS_FSL_MC_DEVICES, group_name);
     341                 :          0 :         dir = opendir(fslmc_dirpath);
     342         [ #  # ]:          0 :         if (!dir) {
     343                 :          0 :                 DPAA2_BUS_ERR("Unable to open VFIO group directory");
     344                 :          0 :                 goto scan_fail;
     345                 :            :         }
     346                 :            : 
     347                 :            :         /* Scan the DPRC container object */
     348                 :          0 :         ret = scan_one_fslmc_device(group_name);
     349         [ #  # ]:          0 :         if (ret != 0) {
     350                 :            :                 /* Error in parsing directory - exit gracefully */
     351                 :          0 :                 goto scan_fail_cleanup;
     352                 :            :         }
     353                 :            : 
     354         [ #  # ]:          0 :         while ((entry = readdir(dir)) != NULL) {
     355   [ #  #  #  # ]:          0 :                 if (entry->d_name[0] == '.' || entry->d_type != DT_DIR)
     356                 :          0 :                         continue;
     357                 :            : 
     358                 :          0 :                 ret = scan_one_fslmc_device(entry->d_name);
     359         [ #  # ]:          0 :                 if (ret != 0) {
     360                 :            :                         /* Error in parsing directory - exit gracefully */
     361                 :          0 :                         goto scan_fail_cleanup;
     362                 :            :                 }
     363                 :            :         }
     364                 :            : 
     365                 :          0 :         closedir(dir);
     366                 :            : 
     367                 :          0 :         DPAA2_BUS_INFO("FSLMC Bus scan completed");
     368                 :            :         /* If debugging is enabled, device list is dumped to log output */
     369                 :          0 :         dump_device_list();
     370                 :            : 
     371                 :            :         /* Bus initialization - only if devices were found */
     372         [ #  # ]:          0 :         if (!TAILQ_EMPTY(&rte_fslmc_bus.device_list)) {
     373                 :            :                 static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = {
     374                 :            :                         .name = DPAA2_SEQN_DYNFIELD_NAME,
     375                 :            :                         .size = sizeof(dpaa2_seqn_t),
     376                 :            :                         .align = alignof(dpaa2_seqn_t),
     377                 :            :                 };
     378                 :            : 
     379                 :          0 :                 dpaa2_seqn_dynfield_offset =
     380                 :          0 :                         rte_mbuf_dynfield_register(&dpaa2_seqn_dynfield_desc);
     381         [ #  # ]:          0 :                 if (dpaa2_seqn_dynfield_offset < 0) {
     382                 :          0 :                         DPAA2_BUS_ERR("Failed to register mbuf field for dpaa sequence number");
     383                 :          0 :                         return 0;
     384                 :            :                 }
     385                 :            : 
     386                 :          0 :                 ret = fslmc_vfio_setup_group();
     387         [ #  # ]:          0 :                 if (ret) {
     388                 :          0 :                         DPAA2_BUS_ERR("Unable to setup VFIO %d", ret);
     389                 :          0 :                         return 0;
     390                 :            :                 }
     391                 :            : 
     392                 :            :                 /* Map existing segments as well as, in case of hotpluggable memory,
     393                 :            :                  * install callback handler.
     394                 :            :                  */
     395         [ #  # ]:          0 :                 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
     396                 :          0 :                         ret = fslmc_vfio_dmamap();
     397         [ #  # ]:          0 :                         if (ret) {
     398                 :          0 :                                 DPAA2_BUS_ERR("Unable to DMA map existing VAs: (%d)", ret);
     399                 :          0 :                                 DPAA2_BUS_ERR("FSLMC VFIO Mapping failed");
     400                 :          0 :                                 return 0;
     401                 :            :                         }
     402                 :            :                 }
     403                 :            : 
     404                 :          0 :                 ret = fslmc_vfio_process_group();
     405         [ #  # ]:          0 :                 if (ret) {
     406                 :          0 :                         DPAA2_BUS_ERR("Unable to setup devices %d", ret);
     407                 :          0 :                         return 0;
     408                 :            :                 }
     409                 :            :         }
     410                 :            : 
     411                 :          0 :         process_once = 1;
     412                 :            : 
     413                 :          0 :         return 0;
     414                 :            : 
     415                 :          0 : scan_fail_cleanup:
     416                 :          0 :         closedir(dir);
     417                 :            : 
     418                 :            :         /* Remove all devices in the list */
     419                 :          0 :         cleanup_fslmc_device_list();
     420                 :        225 : scan_fail:
     421                 :        225 :         DPAA2_BUS_DEBUG("FSLMC Bus Not Available. Skipping (%d)", ret);
     422                 :            :         /* Irrespective of failure, scan only return success */
     423                 :        225 :         return 0;
     424                 :            : }
     425                 :            : 
     426                 :            : static bool
     427                 :          0 : fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev)
     428                 :            : {
     429                 :            :         const struct rte_dpaa2_driver *dpaa2_drv = RTE_BUS_DRIVER(drv, *dpaa2_drv);
     430                 :            :         const struct rte_dpaa2_device *dpaa2_dev = RTE_BUS_DEVICE(dev, *dpaa2_dev);
     431                 :            : 
     432         [ #  # ]:          0 :         if (dpaa2_drv->drv_type == dpaa2_dev->dev_type)
     433                 :          0 :                 return true;
     434                 :            : 
     435                 :            :         return false;
     436                 :            : }
     437                 :            : 
     438                 :            : static int
     439                 :        294 : rte_fslmc_close(struct rte_bus *bus __rte_unused)
     440                 :            : {
     441                 :            :         int ret = 0;
     442                 :            : 
     443                 :        294 :         ret = fslmc_vfio_close_group();
     444         [ +  - ]:        294 :         if (ret)
     445                 :        294 :                 DPAA2_BUS_INFO("Unable to close devices %d", ret);
     446                 :            : 
     447                 :        294 :         return 0;
     448                 :            : }
     449                 :            : 
     450                 :            : /*register a fslmc bus based dpaa2 driver */
     451                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_register)
     452                 :            : void
     453                 :        903 : rte_fslmc_driver_register(struct rte_dpaa2_driver *driver)
     454                 :            : {
     455         [ -  + ]:        903 :         RTE_VERIFY(driver);
     456         [ -  + ]:        903 :         RTE_VERIFY(driver->probe != NULL);
     457                 :            : 
     458                 :        903 :         rte_bus_add_driver(&rte_fslmc_bus, &driver->driver);
     459                 :        903 : }
     460                 :            : 
     461                 :            : /*un-register a fslmc bus based dpaa2 driver */
     462                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_unregister)
     463                 :            : void
     464                 :          0 : rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver)
     465                 :            : {
     466                 :          0 :         rte_bus_remove_driver(&rte_fslmc_bus, &driver->driver);
     467                 :          0 : }
     468                 :            : 
     469                 :            : /*
     470                 :            :  * All device has iova as va
     471                 :            :  */
     472                 :            : static inline int
     473                 :            : fslmc_all_device_support_iova(void)
     474                 :            : {
     475                 :            :         struct rte_dpaa2_device *dev;
     476                 :            :         struct rte_dpaa2_driver *drv;
     477                 :            : 
     478         [ #  # ]:          0 :         RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
     479   [ #  #  #  # ]:          0 :                 RTE_BUS_FOREACH_DRV(drv, &rte_fslmc_bus) {
     480                 :          0 :                         if (!fslmc_bus_match(&drv->driver, &dev->device))
     481                 :          0 :                                 continue;
     482                 :            :                         /* if the driver is not supporting IOVA */
     483         [ #  # ]:          0 :                         if (!(drv->drv_flags & RTE_DPAA2_DRV_IOVA_AS_VA))
     484                 :            :                                 return 0;
     485                 :            :                 }
     486                 :            :         }
     487                 :            :         return 1;
     488                 :            : }
     489                 :            : 
     490                 :            : /*
     491                 :            :  * Get iommu class of DPAA2 devices on the bus.
     492                 :            :  */
     493                 :            : static enum rte_iova_mode
     494                 :        225 : rte_dpaa2_get_iommu_class(void)
     495                 :            : {
     496         [ +  - ]:        225 :         if (rte_eal_iova_mode() == RTE_IOVA_PA)
     497                 :            :                 return RTE_IOVA_PA;
     498                 :            : 
     499         [ -  + ]:        225 :         if (TAILQ_EMPTY(&rte_fslmc_bus.device_list))
     500                 :            :                 return RTE_IOVA_DC;
     501                 :            : 
     502                 :            :         /* check if all devices on the bus support Virtual addressing or not */
     503   [ #  #  #  # ]:          0 :         if (fslmc_all_device_support_iova() != 0 && rte_vfio_noiommu_is_enabled() == 0)
     504                 :          0 :                 return RTE_IOVA_VA;
     505                 :            : 
     506                 :            :         return RTE_IOVA_PA;
     507                 :            : }
     508                 :            : 
     509                 :            : static int
     510                 :          0 : fslmc_bus_probe_device(struct rte_driver *driver, struct rte_device *rte_dev)
     511                 :            : {
     512                 :            :         struct rte_dpaa2_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
     513                 :            :         struct rte_dpaa2_driver *drv = RTE_BUS_DRIVER(driver, *drv);
     514                 :            :         int ret = 0;
     515                 :            : 
     516         [ #  # ]:          0 :         if (dev->device.devargs &&
     517         [ #  # ]:          0 :             dev->device.devargs->policy == RTE_DEV_BLOCKED) {
     518                 :          0 :                 DPAA2_BUS_DEBUG("%s Blocked, skipping",
     519                 :            :                               dev->device.name);
     520                 :          0 :                 return 0;
     521                 :            :         }
     522                 :            : 
     523                 :            :         /* FIXME: probe_device should allocate intr_handle */
     524                 :          0 :         ret = drv->probe(drv, dev);
     525         [ #  # ]:          0 :         if (ret != 0) {
     526                 :          0 :                 DPAA2_BUS_ERR("Unable to probe");
     527                 :            :         } else {
     528                 :          0 :                 DPAA2_BUS_INFO("%s Plugged",  dev->device.name);
     529                 :            :         }
     530                 :            : 
     531                 :            :         return ret;
     532                 :            : }
     533                 :            : 
     534                 :            : static int
     535                 :          0 : fslmc_bus_unplug_device(struct rte_device *rte_dev)
     536                 :            : {
     537                 :            :         struct rte_dpaa2_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
     538                 :          0 :         const struct rte_dpaa2_driver *drv = RTE_BUS_DRIVER(rte_dev->driver, *drv);
     539                 :            : 
     540         [ #  # ]:          0 :         if (drv->remove != NULL) {
     541                 :          0 :                 int ret = drv->remove(dev);
     542         [ #  # ]:          0 :                 if (ret != 0)
     543                 :            :                         return ret;
     544                 :            :                 /* FIXME: unplug_device should free intr_handle */
     545                 :          0 :                 DPAA2_BUS_INFO("%s Un-Plugged",  dev->device.name);
     546                 :          0 :                 return 0;
     547                 :            :         }
     548                 :            : 
     549                 :            :         return -ENODEV;
     550                 :            : }
     551                 :            : 
     552                 :            : struct rte_bus rte_fslmc_bus = {
     553                 :            :         .scan = rte_fslmc_scan,
     554                 :            :         .probe = rte_bus_generic_probe,
     555                 :            :         .cleanup = rte_fslmc_close,
     556                 :            :         .parse = rte_fslmc_parse,
     557                 :            :         .dev_compare = fslmc_dev_compare,
     558                 :            :         .find_device = rte_bus_generic_find_device,
     559                 :            :         .get_iommu_class = rte_dpaa2_get_iommu_class,
     560                 :            :         .match = fslmc_bus_match,
     561                 :            :         .probe_device = fslmc_bus_probe_device,
     562                 :            :         .unplug_device = fslmc_bus_unplug_device,
     563                 :            :         .dev_iterate = rte_bus_generic_dev_iterate,
     564                 :            : };
     565                 :            : 
     566                 :        301 : RTE_REGISTER_BUS(fslmc, rte_fslmc_bus);
     567         [ -  + ]:        301 : RTE_LOG_REGISTER_DEFAULT(dpaa2_logtype_bus, NOTICE);

Generated by: LCOV version 1.14