LCOV - code coverage report
Current view: top level - drivers/bus/uacce - uacce.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 14 205 6.8 %
Date: 2026-07-01 18:02:41 Functions: 5 27 18.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 118 2.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2024 HiSilicon Limited
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <ctype.h>
       6                 :            : #include <dirent.h>
       7                 :            : #include <errno.h>
       8                 :            : #include <fcntl.h>
       9                 :            : #include <unistd.h>
      10                 :            : #include <stdlib.h>
      11                 :            : #include <string.h>
      12                 :            : #include <sys/ioctl.h>
      13                 :            : #include <sys/mman.h>
      14                 :            : #include <sys/stat.h>
      15                 :            : #include <sys/types.h>
      16                 :            : 
      17                 :            : #include <eal_export.h>
      18                 :            : #include <rte_common.h>
      19                 :            : #include <rte_devargs.h>
      20                 :            : #include <rte_eal_paging.h>
      21                 :            : #include <rte_errno.h>
      22                 :            : #include <rte_log.h>
      23                 :            : #include <rte_kvargs.h>
      24                 :            : #include <bus_driver.h>
      25                 :            : 
      26                 :            : #include "bus_uacce_driver.h"
      27                 :            : 
      28                 :            : #define UACCE_BUS_CLASS_PATH    "/sys/class/uacce"
      29                 :            : 
      30                 :            : /* Support -a uacce:device-name when start DPDK application. */
      31                 :            : #define UACCE_DEV_PREFIX        "uacce:"
      32                 :            : 
      33                 :            : /* Forward declaration of UACCE bus. */
      34                 :            : static struct rte_bus uacce_bus;
      35                 :            : 
      36                 :            : 
      37                 :            : extern int uacce_bus_logtype;
      38                 :            : #define RTE_LOGTYPE_UACCE_BUS uacce_bus_logtype
      39                 :            : #define UACCE_BUS_LOG(level, ...) \
      40                 :            :         RTE_LOG_LINE(level, UACCE_BUS, __VA_ARGS__)
      41                 :            : #define UACCE_BUS_ERR(fmt, ...) UACCE_BUS_LOG(ERR, fmt, ##__VA_ARGS__)
      42                 :            : #define UACCE_BUS_WARN(fmt, ...) UACCE_BUS_LOG(WARNING, fmt, ##__VA_ARGS__)
      43                 :            : #define UACCE_BUS_INFO(fmt, ...) UACCE_BUS_LOG(INFO, fmt, ##__VA_ARGS__)
      44                 :            : #define UACCE_BUS_DEBUG(fmt, ...) UACCE_BUS_LOG(DEBUG, fmt, ##__VA_ARGS__)
      45                 :            : 
      46                 :            : 
      47                 :            : /*
      48                 :            :  * Returns the number of bytes read (removed last newline) on success.
      49                 :            :  * Otherwise negative value is returned.
      50                 :            :  */
      51                 :            : static int
      52                 :          0 : uacce_read_attr(const char *dev_root, const char *attr, char *buf, uint32_t sz)
      53                 :            : {
      54                 :          0 :         char filename[PATH_MAX] = {0};
      55                 :            :         int ret;
      56                 :            :         int fd;
      57                 :            : 
      58                 :            :         snprintf(filename, sizeof(filename), "%s/%s", dev_root, attr);
      59                 :            :         fd = open(filename, O_RDONLY, 0);
      60         [ #  # ]:          0 :         if (fd < 0) {
      61                 :          0 :                 UACCE_BUS_ERR("failed to open %s", filename);
      62                 :          0 :                 return -EIO;
      63                 :            :         }
      64                 :            : 
      65         [ #  # ]:          0 :         ret = read(fd, buf, sz);
      66         [ #  # ]:          0 :         if (ret > 0) {
      67                 :            :                 /* Remove the last new line character. */
      68         [ #  # ]:          0 :                 if (buf[ret - 1] == '\n') {
      69                 :          0 :                         buf[ret - 1] = '\0';
      70                 :          0 :                         ret--;
      71                 :            :                 }
      72                 :            :         }
      73         [ #  # ]:          0 :         if (ret <= 0) {
      74                 :          0 :                 UACCE_BUS_ERR("failed to read %s", filename);
      75                 :            :                 ret = -EIO;
      76                 :            :         }
      77                 :            : 
      78                 :          0 :         close(fd);
      79                 :            : 
      80                 :          0 :         return ret;
      81                 :            : }
      82                 :            : 
      83                 :            : /* 0 on success. Otherwise negative value is returned. */
      84                 :            : static int
      85                 :          0 : uacce_read_attr_int(const char *dev_root, const char *attr, int *val)
      86                 :            : {
      87                 :          0 :         char buf[RTE_UACCE_ATTR_MAX_SIZE] = {0};
      88                 :          0 :         char *s = NULL;
      89                 :            :         int ret;
      90                 :            : 
      91                 :          0 :         ret = uacce_read_attr(dev_root, attr, buf, sizeof(buf) - 1);
      92         [ #  # ]:          0 :         if (ret < 0)
      93                 :            :                 return ret;
      94                 :            : 
      95                 :          0 :         *val = strtol(buf, &s, 0);
      96         [ #  # ]:          0 :         if (s[0] != '\0') {
      97                 :          0 :                 UACCE_BUS_ERR("read attr %s/%s expect an integer value", dev_root, attr);
      98                 :          0 :                 return -EINVAL;
      99                 :            :         }
     100                 :            : 
     101                 :            :         return 0;
     102                 :            : }
     103                 :            : 
     104                 :            : /* 0 on success. Otherwise negative value is returned. */
     105                 :            : static int
     106                 :          0 : uacce_read_attr_u32(const char *dev_root, const char *attr, uint32_t *val)
     107                 :            : {
     108                 :          0 :         char buf[RTE_UACCE_ATTR_MAX_SIZE] = {0};
     109                 :          0 :         char *s = NULL;
     110                 :            :         int ret;
     111                 :            : 
     112                 :          0 :         ret = uacce_read_attr(dev_root, attr, buf, sizeof(buf) - 1);
     113         [ #  # ]:          0 :         if (ret < 0)
     114                 :            :                 return ret;
     115                 :            : 
     116                 :          0 :         *val = strtoul(buf, &s, 0);
     117         [ #  # ]:          0 :         if (s[0] != '\0') {
     118                 :          0 :                 UACCE_BUS_ERR("read attr %s/%s expect an uint32 value", dev_root, attr);
     119                 :          0 :                 return -EINVAL;
     120                 :            :         }
     121                 :            : 
     122                 :            :         return 0;
     123                 :            : }
     124                 :            : 
     125                 :            : static uint32_t
     126                 :          0 : uacce_calc_api_ver(const char *api, int *offset)
     127                 :            : {
     128                 :          0 :         int len = strlen(api);
     129                 :          0 :         int end = len - 1;
     130                 :            :         unsigned long ver;
     131                 :            : 
     132   [ #  #  #  # ]:          0 :         while (end >= 0 && isdigit(api[end]))
     133                 :          0 :                 end--;
     134                 :            : 
     135   [ #  #  #  #  :          0 :         if (end <= 0 || end == len - 1 || api[end] != 'v')
                   #  # ]
     136                 :            :                 return 0;
     137                 :            : 
     138                 :          0 :         ver = strtoul(api + end + 1, NULL, 10);
     139         [ #  # ]:          0 :         if (ver > UINT32_MAX)
     140                 :            :                 return 0;
     141                 :            : 
     142         [ #  # ]:          0 :         if (offset != NULL)
     143                 :          0 :                 *offset = end + 1;
     144                 :          0 :         return (uint32_t)ver;
     145                 :            : }
     146                 :            : 
     147                 :            : static int
     148                 :          0 : uacce_read_api(struct rte_uacce_device *dev)
     149                 :            : {
     150                 :            : #define NOIOMMU_SUFFIX          "_noiommu"
     151                 :            :         size_t api_len, sub_len;
     152                 :            :         int ret;
     153                 :            : 
     154                 :          0 :         ret = uacce_read_attr(dev->dev_root, "api", dev->api, sizeof(dev->api) - 1);
     155         [ #  # ]:          0 :         if (ret < 0)
     156                 :            :                 return ret;
     157                 :            : 
     158                 :            :         /*
     159                 :            :          * If the device is in no-iommu mode, the UACCE_DEV_FLAG_NOIOMMU flag
     160                 :            :          * in its "flags" will be set, and its "api" will contain the suffix
     161                 :            :          * _noiommu. To facilitate matching with the driver, the suffix is
     162                 :            :          * removed here.
     163                 :            :          */
     164                 :          0 :         api_len = strlen(dev->api);
     165                 :            :         sub_len = strlen(NOIOMMU_SUFFIX);
     166   [ #  #  #  # ]:          0 :         if (api_len > sub_len && strcmp(dev->api + api_len - sub_len, NOIOMMU_SUFFIX) == 0)
     167                 :          0 :                 dev->api[api_len - sub_len] = 0;
     168                 :            : 
     169                 :          0 :         dev->api_ver = uacce_calc_api_ver(dev->api, NULL);
     170                 :            : 
     171                 :          0 :         return 0;
     172                 :            : }
     173                 :            : 
     174                 :            : static int
     175                 :            : uacce_read_algs(struct rte_uacce_device *dev)
     176                 :            : {
     177                 :          0 :         int ret = uacce_read_attr(dev->dev_root, "algorithms", dev->algs, sizeof(dev->algs) - 1);
     178                 :            :         if (ret < 0)
     179                 :            :                 return ret;
     180                 :            :         return 0;
     181                 :            : }
     182                 :            : 
     183                 :            : static int
     184                 :            : uacce_read_flags(struct rte_uacce_device *dev)
     185                 :            : {
     186                 :          0 :         return uacce_read_attr_u32(dev->dev_root, "flags", &dev->flags);
     187                 :            : }
     188                 :            : 
     189                 :            : static void
     190                 :          0 : uacce_read_numa_node(struct rte_uacce_device *dev)
     191                 :            : {
     192                 :          0 :         int ret = uacce_read_attr_int(dev->dev_root, "device/numa_node", &dev->numa_node);
     193         [ #  # ]:          0 :         if (ret != 0) {
     194                 :          0 :                 UACCE_BUS_WARN("read attr numa_node failed! set to default");
     195                 :          0 :                 dev->numa_node = -1;
     196                 :            :         }
     197                 :          0 : }
     198                 :            : 
     199                 :            : static int
     200                 :          0 : uacce_read_qfrt_sz(struct rte_uacce_device *dev)
     201                 :            : {
     202                 :          0 :         int ret = uacce_read_attr_u32(dev->dev_root, "region_mmio_size",
     203                 :            :                                       &dev->qfrt_sz[RTE_UACCE_QFRT_MMIO]);
     204         [ #  # ]:          0 :         if (ret != 0)
     205                 :            :                 return ret;
     206                 :          0 :         return uacce_read_attr_u32(dev->dev_root, "region_dus_size",
     207                 :            :                                    &dev->qfrt_sz[RTE_UACCE_QFRT_DUS]);
     208                 :            : }
     209                 :            : 
     210                 :            : static int
     211                 :          0 : uacce_verify(struct rte_uacce_device *dev)
     212                 :            : {
     213         [ #  # ]:          0 :         if (!(dev->flags & (UACCE_DEV_FLAG_SVA | UACCE_DEV_FLAG_NOIOMMU))) {
     214                 :          0 :                 UACCE_BUS_WARN("device %s don't support SVA or NOIOMMU, skip it!", dev->name);
     215                 :          0 :                 return 1; /* >0 will skip this device. */
     216                 :            :         }
     217                 :            : 
     218                 :            :         return 0;
     219                 :            : }
     220                 :            : 
     221                 :            : /*
     222                 :            :  * Scan one UACCE sysfs entry, and fill the devices list from it.
     223                 :            :  * It reads api/algs/flags/numa_node/region-size (please refer Linux kernel:
     224                 :            :  * Documentation/ABI/testing/sysfs-driver-uacce) and stores them for later
     225                 :            :  * device-driver matching, driver init...
     226                 :            :  */
     227                 :            : static int
     228                 :          0 : uacce_scan_one(const char *dev_name)
     229                 :            : {
     230                 :            :         struct rte_uacce_device *dev;
     231                 :            :         int ret;
     232                 :            : 
     233                 :          0 :         dev = calloc(1, sizeof(*dev));
     234         [ #  # ]:          0 :         if (!dev)
     235                 :            :                 return -ENOMEM;
     236                 :            : 
     237                 :          0 :         dev->device.name = dev->name;
     238                 :          0 :         dev->device.devargs = rte_bus_find_devargs(&uacce_bus, dev_name);
     239                 :            :         snprintf(dev->name, sizeof(dev->name), "%s", dev_name);
     240                 :          0 :         snprintf(dev->dev_root, sizeof(dev->dev_root), "%s/%s",
     241                 :            :                  UACCE_BUS_CLASS_PATH, dev_name);
     242                 :          0 :         snprintf(dev->cdev_path, sizeof(dev->cdev_path), "/dev/%s", dev_name);
     243                 :            : 
     244                 :          0 :         ret = uacce_read_api(dev);
     245         [ #  # ]:          0 :         if (ret != 0)
     246                 :          0 :                 goto err;
     247                 :            :         ret = uacce_read_algs(dev);
     248         [ #  # ]:          0 :         if (ret != 0)
     249                 :          0 :                 goto err;
     250                 :            :         ret = uacce_read_flags(dev);
     251         [ #  # ]:          0 :         if (ret != 0)
     252                 :          0 :                 goto err;
     253                 :          0 :         uacce_read_numa_node(dev);
     254                 :          0 :         ret = uacce_read_qfrt_sz(dev);
     255         [ #  # ]:          0 :         if (ret != 0)
     256                 :          0 :                 goto err;
     257                 :            : 
     258                 :          0 :         ret = uacce_verify(dev);
     259         [ #  # ]:          0 :         if (ret != 0)
     260                 :          0 :                 goto err;
     261                 :            : 
     262                 :          0 :         rte_bus_add_device(&uacce_bus, &dev->device);
     263                 :          0 :         return 0;
     264                 :            : 
     265                 :          0 : err:
     266                 :          0 :         free(dev);
     267                 :          0 :         return ret;
     268                 :            : }
     269                 :            : 
     270                 :            : static int
     271                 :        225 : uacce_scan(void)
     272                 :            : {
     273                 :            :         struct dirent *e;
     274                 :            :         DIR *dir;
     275                 :            : 
     276                 :        225 :         dir = opendir(UACCE_BUS_CLASS_PATH);
     277         [ +  - ]:        225 :         if (dir == NULL) {
     278                 :        225 :                 UACCE_BUS_LOG(INFO, "open %s failed!", UACCE_BUS_CLASS_PATH);
     279                 :        225 :                 return 0;
     280                 :            :         }
     281                 :            : 
     282         [ #  # ]:          0 :         while ((e = readdir(dir)) != NULL) {
     283         [ #  # ]:          0 :                 if (e->d_name[0] == '.')
     284                 :          0 :                         continue;
     285                 :            : 
     286         [ #  # ]:          0 :                 if (strlen(e->d_name) >= RTE_DEV_NAME_MAX_LEN) {
     287                 :          0 :                         UACCE_BUS_LOG(WARNING, "uacce device name %s too long, skip it!",
     288                 :            :                                       e->d_name);
     289                 :          0 :                         continue;
     290                 :            :                 }
     291                 :            : 
     292         [ #  # ]:          0 :                 if (rte_bus_device_is_ignored(&uacce_bus, e->d_name))
     293                 :          0 :                         continue;
     294                 :            : 
     295         [ #  # ]:          0 :                 if (uacce_scan_one(e->d_name) < 0)
     296                 :          0 :                         goto error;
     297                 :            :         }
     298                 :          0 :         closedir(dir);
     299                 :          0 :         return 0;
     300                 :            : 
     301                 :            : error:
     302                 :          0 :         closedir(dir);
     303                 :          0 :         return -1;
     304                 :            : }
     305                 :            : 
     306                 :            : static bool
     307                 :          0 : uacce_match_api(const struct rte_uacce_device *dev, bool forward_compat,
     308                 :            :                 const struct rte_uacce_id *id_table)
     309                 :            : {
     310                 :          0 :         int dev_ver_off = 0, id_ver_off = 0;
     311                 :            :         uint32_t dev_ver, id_ver;
     312                 :            : 
     313         [ #  # ]:          0 :         if (!forward_compat)
     314                 :          0 :                 return strcmp(id_table->dev_api, dev->api) == 0;
     315                 :            : 
     316                 :          0 :         dev_ver = uacce_calc_api_ver(dev->api, &dev_ver_off);
     317                 :          0 :         id_ver = uacce_calc_api_ver(id_table->dev_api, &id_ver_off);
     318         [ #  # ]:          0 :         return dev_ver > 0 && id_ver > 0 && dev_ver_off == id_ver_off &&
     319   [ #  #  #  #  :          0 :                 strncmp(id_table->dev_api, dev->api, dev_ver_off) == 0 &&
                   #  # ]
     320                 :            :                 dev_ver >= id_ver;
     321                 :            : }
     322                 :            : 
     323                 :            : static bool
     324                 :          0 : uacce_bus_match(const struct rte_driver *drv, const struct rte_device *dev)
     325                 :            : {
     326                 :            :         const struct rte_uacce_driver *dr = RTE_BUS_DRIVER(drv, *dr);
     327                 :            :         const struct rte_uacce_device *uacce_dev = RTE_BUS_DEVICE(dev, *uacce_dev);
     328                 :          0 :         bool forward_compat = !!(dr->drv_flags & RTE_UACCE_DRV_FORWARD_COMPATIBILITY_DEV);
     329                 :          0 :         bool drv_support_noiommu = !!(dr->drv_flags & RTE_UACCE_DRV_SUPPORT_NOIOMMU_MODE);
     330                 :          0 :         bool dev_in_noiommu = !!(uacce_dev->flags & UACCE_DEV_FLAG_NOIOMMU);
     331                 :            :         const struct rte_uacce_id *id_table;
     332                 :            :         const char *map;
     333                 :            :         uint32_t len;
     334                 :            : 
     335         [ #  # ]:          0 :         if (dev_in_noiommu && !drv_support_noiommu)
     336                 :            :                 return false;
     337                 :            : 
     338         [ #  # ]:          0 :         for (id_table = dr->id_table; id_table->dev_api != NULL; id_table++) {
     339         [ #  # ]:          0 :                 if (!uacce_match_api(uacce_dev, forward_compat, id_table))
     340                 :          0 :                         continue;
     341                 :            : 
     342         [ #  # ]:          0 :                 if (id_table->dev_alg == NULL)
     343                 :            :                         return true;
     344                 :            : 
     345                 :            :                 /* The dev->algs's algrothims is separated by new line, for
     346                 :            :                  * example: dev->algs could be: aaa\nbbbb\ncc, which has three
     347                 :            :                  * algorithms: aaa, bbbb and cc.
     348                 :            :                  * The id_table->dev_alg should be a single algrithm, e.g. bbbb.
     349                 :            :                  */
     350                 :          0 :                 map = strstr(uacce_dev->algs, id_table->dev_alg);
     351         [ #  # ]:          0 :                 if (map == NULL)
     352                 :          0 :                         continue;
     353   [ #  #  #  # ]:          0 :                 if (map != uacce_dev->algs && map[-1] != '\n')
     354                 :          0 :                         continue;
     355                 :          0 :                 len = strlen(id_table->dev_alg);
     356         [ #  # ]:          0 :                 if (map[len] != '\0' && map[len] != '\n')
     357                 :          0 :                         continue;
     358                 :            : 
     359                 :            :                 return true;
     360                 :            :         }
     361                 :            : 
     362                 :            :         return false;
     363                 :            : }
     364                 :            : 
     365                 :            : static int
     366                 :          0 : uacce_probe_device(struct rte_driver *drv, struct rte_device *dev)
     367                 :            : {
     368                 :            :         struct rte_uacce_device *uacce_dev = RTE_BUS_DEVICE(dev, *uacce_dev);
     369                 :            :         struct rte_uacce_driver *uacce_drv = RTE_BUS_DRIVER(drv, *uacce_drv);
     370                 :          0 :         const char *dev_name = uacce_dev->name;
     371                 :            :         int ret;
     372                 :            : 
     373                 :          0 :         UACCE_BUS_DEBUG("probe device %s using driver %s", dev_name, uacce_drv->driver.name);
     374                 :            : 
     375                 :          0 :         ret = uacce_drv->probe(uacce_drv, uacce_dev);
     376         [ #  # ]:          0 :         if (ret != 0) {
     377                 :          0 :                 UACCE_BUS_ERR("probe device %s with driver %s failed %d",
     378                 :            :                               dev_name, uacce_drv->driver.name, ret);
     379                 :            :         } else {
     380                 :          0 :                 UACCE_BUS_DEBUG("probe device %s with driver %s success",
     381                 :            :                                 dev_name, uacce_drv->driver.name);
     382                 :            :         }
     383                 :            : 
     384                 :          0 :         return ret;
     385                 :            : }
     386                 :            : 
     387                 :            : static int
     388                 :          0 : uacce_unplug_device(struct rte_device *rte_dev)
     389                 :            : {
     390                 :          0 :         const struct rte_uacce_driver *dr = RTE_BUS_DRIVER(rte_dev->driver, *dr);
     391                 :            :         struct rte_uacce_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
     392                 :            :         int ret = 0;
     393                 :            : 
     394                 :          0 :         UACCE_BUS_DEBUG("detach device %s using driver: %s", dev->device.name, dr->driver.name);
     395                 :            : 
     396         [ #  # ]:          0 :         if (dr->remove != NULL) {
     397                 :          0 :                 ret = dr->remove(dev);
     398                 :            :                 if (ret < 0)
     399                 :            :                         return ret;
     400                 :            :         }
     401                 :            : 
     402                 :            :         return 0;
     403                 :            : }
     404                 :            : 
     405                 :            : static void
     406                 :          0 : uacce_free_device(struct rte_device *dev)
     407                 :            : {
     408                 :          0 :         free(RTE_BUS_DEVICE(dev, struct rte_uacce_device));
     409                 :          0 : }
     410                 :            : 
     411                 :            : static int
     412                 :         30 : uacce_parse(const char *name, void *addr)
     413                 :            : {
     414                 :            :         const char **out = addr;
     415                 :            :         int ret;
     416                 :            : 
     417                 :         30 :         ret = strncmp(name, UACCE_DEV_PREFIX, strlen(UACCE_DEV_PREFIX));
     418                 :            : 
     419         [ -  + ]:         30 :         if (ret == 0 && addr)
     420                 :          0 :                 *out = name;
     421                 :            : 
     422                 :         30 :         return ret;
     423                 :            : }
     424                 :            : 
     425                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_avail_queues)
     426                 :            : int
     427                 :          0 : rte_uacce_avail_queues(struct rte_uacce_device *dev)
     428                 :            : {
     429                 :          0 :         int avails = 0;
     430                 :            :         int ret;
     431                 :            : 
     432                 :          0 :         ret = uacce_read_attr_int(dev->dev_root, "available_instances", &avails);
     433         [ #  # ]:          0 :         if (ret == 0)
     434                 :          0 :                 ret = avails;
     435                 :            : 
     436                 :          0 :         return ret;
     437                 :            : }
     438                 :            : 
     439                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_queue_alloc)
     440                 :            : int
     441                 :          0 : rte_uacce_queue_alloc(struct rte_uacce_device *dev, struct rte_uacce_qcontex *qctx)
     442                 :            : {
     443                 :            :         memset(qctx, 0, sizeof(*qctx));
     444                 :            : 
     445                 :          0 :         qctx->fd = open(dev->cdev_path, O_RDWR | O_CLOEXEC);
     446         [ #  # ]:          0 :         if (qctx->fd >= 0) {
     447                 :          0 :                 qctx->dev = dev;
     448                 :          0 :                 return 0;
     449                 :            :         }
     450                 :            : 
     451                 :            :         return -EIO;
     452                 :            : }
     453                 :            : 
     454                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_queue_free)
     455                 :            : void
     456                 :          0 : rte_uacce_queue_free(struct rte_uacce_qcontex *qctx)
     457                 :            : {
     458         [ #  # ]:          0 :         if (qctx->fd >= 0)
     459                 :          0 :                 close(qctx->fd);
     460                 :            :         memset(qctx, 0, sizeof(*qctx));
     461                 :          0 :         qctx->fd = -1;
     462                 :          0 : }
     463                 :            : 
     464                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_queue_start)
     465                 :            : int
     466                 :          0 : rte_uacce_queue_start(struct rte_uacce_qcontex *qctx)
     467                 :            : {
     468                 :            : #define UACCE_CMD_START_Q       _IO('W', 0)
     469                 :          0 :         return ioctl(qctx->fd, UACCE_CMD_START_Q);
     470                 :            : }
     471                 :            : 
     472                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_queue_ioctl)
     473                 :            : int
     474                 :          0 : rte_uacce_queue_ioctl(struct rte_uacce_qcontex *qctx, unsigned long cmd, void *arg)
     475                 :            : {
     476         [ #  # ]:          0 :         if (arg == NULL)
     477                 :          0 :                 return ioctl(qctx->fd, cmd);
     478                 :            : 
     479                 :          0 :         return ioctl(qctx->fd, cmd, arg);
     480                 :            : }
     481                 :            : 
     482                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_queue_mmap)
     483                 :            : void *
     484                 :          0 : rte_uacce_queue_mmap(struct rte_uacce_qcontex *qctx, enum rte_uacce_qfrt qfrt)
     485                 :            : {
     486                 :          0 :         size_t size = qctx->dev->qfrt_sz[qfrt];
     487                 :          0 :         off_t off = qfrt * getpagesize();
     488                 :            :         void *addr;
     489                 :            : 
     490   [ #  #  #  # ]:          0 :         if (size == 0 || qctx->qfrt_base[qfrt] != NULL) {
     491                 :          0 :                 UACCE_BUS_ERR("failed to mmap for %s, size is zero or already mmapped!",
     492                 :            :                               qctx->dev->name);
     493                 :          0 :                 return NULL;
     494                 :            :         }
     495                 :            : 
     496                 :          0 :         addr = rte_mem_map(NULL, size, RTE_PROT_READ | RTE_PROT_WRITE, RTE_MAP_SHARED,
     497                 :            :                            qctx->fd, off);
     498         [ #  # ]:          0 :         if (addr == NULL) {
     499                 :          0 :                 UACCE_BUS_ERR("failed to mmap for %s, qfrt %d err %s!",
     500                 :            :                               qctx->dev->name, qfrt, rte_strerror(rte_errno));
     501                 :          0 :                 return NULL;
     502                 :            :         }
     503                 :          0 :         qctx->qfrt_base[qfrt] = addr;
     504                 :            : 
     505                 :          0 :         return addr;
     506                 :            : }
     507                 :            : 
     508                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_queue_unmap)
     509                 :            : void
     510                 :          0 : rte_uacce_queue_unmap(struct rte_uacce_qcontex *qctx, enum rte_uacce_qfrt qfrt)
     511                 :            : {
     512         [ #  # ]:          0 :         if (qctx->qfrt_base[qfrt] != NULL) {
     513                 :          0 :                 rte_mem_unmap(qctx->qfrt_base[qfrt], qctx->dev->qfrt_sz[qfrt]);
     514                 :          0 :                 qctx->qfrt_base[qfrt] = NULL;
     515                 :            :         }
     516                 :          0 : }
     517                 :            : 
     518                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_register)
     519                 :            : void
     520                 :        301 : rte_uacce_register(struct rte_uacce_driver *driver)
     521                 :            : {
     522                 :        301 :         rte_bus_add_driver(&uacce_bus, &driver->driver);
     523                 :        301 : }
     524                 :            : 
     525                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_unregister)
     526                 :            : void
     527                 :          0 : rte_uacce_unregister(struct rte_uacce_driver *driver)
     528                 :            : {
     529                 :          0 :         rte_bus_remove_driver(&uacce_bus, &driver->driver);
     530                 :          0 : }
     531                 :            : 
     532                 :            : static struct rte_bus uacce_bus = {
     533                 :            :         .scan = uacce_scan,
     534                 :            :         .probe = rte_bus_generic_probe,
     535                 :            :         .free_device = uacce_free_device,
     536                 :            :         .cleanup = rte_bus_generic_cleanup,
     537                 :            :         .match = uacce_bus_match,
     538                 :            :         .probe_device = uacce_probe_device,
     539                 :            :         .unplug_device = uacce_unplug_device,
     540                 :            :         .find_device = rte_bus_generic_find_device,
     541                 :            :         .parse = uacce_parse,
     542                 :            :         .dev_iterate = rte_bus_generic_dev_iterate,
     543                 :            : };
     544                 :            : 
     545                 :        301 : RTE_REGISTER_BUS(uacce, uacce_bus);
     546         [ -  + ]:        301 : RTE_LOG_REGISTER_DEFAULT(uacce_bus_logtype, NOTICE);

Generated by: LCOV version 1.14