LCOV - code coverage report
Current view: top level - drivers/common/qat - qat_device.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 191 0.5 %
Date: 2026-11-01 19:11:22 Functions: 1 11 9.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 121 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018-2022 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_string_fns.h>
       6                 :            : #include <rte_devargs.h>
       7                 :            : #include <ctype.h>
       8                 :            : 
       9                 :            : #include "qat_device.h"
      10                 :            : #include "adf_transport_access_macros.h"
      11                 :            : #include "qat_sym.h"
      12                 :            : #include "qat_comp_pmd.h"
      13                 :            : #include "adf_pf2vf_msg.h"
      14                 :            : #include "qat_pf2vf.h"
      15                 :            : 
      16                 :            : #define NOT_NULL(arg, func, msg, ...)           \
      17                 :            :         do {                                    \
      18                 :            :                 if (arg == NULL) {              \
      19                 :            :                         QAT_LOG(ERR,            \
      20                 :            :                         msg, ##__VA_ARGS__);    \
      21                 :            :                         func;                   \
      22                 :            :                 }                               \
      23                 :            :         } while (0)
      24                 :            : 
      25                 :            : /* Hardware device information per generation */
      26                 :            : struct qat_gen_hw_data qat_gen_config[QAT_N_GENS];
      27                 :            : struct qat_dev_hw_spec_funcs *qat_dev_hw_spec[QAT_N_GENS];
      28                 :            : 
      29                 :            : struct qat_service qat_service[QAT_MAX_SERVICES];
      30                 :            : 
      31                 :            : /* per-process array of device data */
      32                 :            : struct qat_device_info qat_pci_devs[RTE_PMD_QAT_MAX_PCI_DEVICES];
      33                 :            : static int qat_nb_pci_devices;
      34                 :            : 
      35                 :            : /*
      36                 :            :  * The set of PCI devices this driver supports
      37                 :            :  */
      38                 :            : 
      39                 :            : static const struct rte_pci_id pci_id_qat_map[] = {
      40                 :            :                 {
      41                 :            :                         RTE_PCI_DEVICE(0x8086, 0x0443),
      42                 :            :                 },
      43                 :            :                 {
      44                 :            :                         RTE_PCI_DEVICE(0x8086, 0x37c9),
      45                 :            :                 },
      46                 :            :                 {
      47                 :            :                         RTE_PCI_DEVICE(0x8086, 0x19e3),
      48                 :            :                 },
      49                 :            :                 {
      50                 :            :                         RTE_PCI_DEVICE(0x8086, 0x6f55),
      51                 :            :                 },
      52                 :            :                 {
      53                 :            :                         RTE_PCI_DEVICE(0x8086, 0x18ef),
      54                 :            :                 },
      55                 :            :                 {
      56                 :            :                         RTE_PCI_DEVICE(0x8086, 0x18a1),
      57                 :            :                 },
      58                 :            :                 {
      59                 :            :                         RTE_PCI_DEVICE(0x8086, 0x578b),
      60                 :            :                 },
      61                 :            :                 {
      62                 :            :                         RTE_PCI_DEVICE(0x8086, 0x4941),
      63                 :            :                 },
      64                 :            :                 {
      65                 :            :                         RTE_PCI_DEVICE(0x8086, 0x4943),
      66                 :            :                 },
      67                 :            :                 {
      68                 :            :                         RTE_PCI_DEVICE(0x8086, 0x4945),
      69                 :            :                 },
      70                 :            :                 {
      71                 :            :                         RTE_PCI_DEVICE(0x8086, 0x4947),
      72                 :            :                 },
      73                 :            :                 {
      74                 :            :                         RTE_PCI_DEVICE(0x8086, 0x4949),
      75                 :            :                 },
      76                 :            :                 {
      77                 :            :                         RTE_PCI_DEVICE(0x8086, 0x1454),
      78                 :            :                 },
      79                 :            :                 {
      80                 :            :                         RTE_PCI_DEVICE(0x8086, 0x0da5),
      81                 :            :                 },
      82                 :            :                 {.device_id = 0},
      83                 :            : };
      84                 :            : 
      85                 :            : static int
      86                 :            : qat_pci_get_extra_size(enum qat_device_gen qat_dev_gen)
      87                 :            : {
      88                 :          0 :         struct qat_dev_hw_spec_funcs *ops_hw =
      89                 :            :                 qat_dev_hw_spec[qat_dev_gen];
      90         [ #  # ]:          0 :         if (ops_hw->qat_dev_get_extra_size == NULL)
      91                 :            :                 return -ENOTSUP;
      92                 :          0 :         return ops_hw->qat_dev_get_extra_size();
      93                 :            : }
      94                 :            : 
      95                 :            : static struct qat_pci_device *
      96                 :          0 : qat_pci_get_named_dev(const char *name)
      97                 :            : {
      98                 :            :         unsigned int i;
      99                 :            : 
     100         [ #  # ]:          0 :         if (name == NULL)
     101                 :            :                 return NULL;
     102                 :            : 
     103         [ #  # ]:          0 :         for (i = 0; i < RTE_PMD_QAT_MAX_PCI_DEVICES; i++) {
     104         [ #  # ]:          0 :                 if (qat_pci_devs[i].mz &&
     105                 :          0 :                                 (strcmp(((struct qat_pci_device *)
     106         [ #  # ]:          0 :                                 qat_pci_devs[i].mz->addr)->name, name)
     107                 :            :                                 == 0))
     108                 :          0 :                         return (struct qat_pci_device *)
     109                 :            :                                 qat_pci_devs[i].mz->addr;
     110                 :            :         }
     111                 :            : 
     112                 :            :         return NULL;
     113                 :            : }
     114                 :            : 
     115                 :            : static uint8_t
     116                 :            : qat_pci_find_free_device_index(void)
     117                 :            : {
     118                 :            :                 uint8_t dev_id;
     119                 :            : 
     120         [ #  # ]:          0 :                 for (dev_id = 0; dev_id < RTE_PMD_QAT_MAX_PCI_DEVICES;
     121                 :          0 :                                 dev_id++) {
     122         [ #  # ]:          0 :                         if (qat_pci_devs[dev_id].mz == NULL)
     123                 :            :                                 break;
     124                 :            :                 }
     125                 :            :                 return dev_id;
     126                 :            : }
     127                 :            : 
     128                 :            : static struct qat_pci_device *
     129                 :            : qat_get_qat_dev_from_pci_dev(struct rte_pci_device *pci_dev)
     130                 :            : {
     131                 :            :         char name[QAT_DEV_NAME_MAX_LEN];
     132                 :            : 
     133                 :          0 :         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
     134                 :            : 
     135                 :          0 :         return qat_pci_get_named_dev(name);
     136                 :            : }
     137                 :            : 
     138                 :            : static enum qat_device_gen
     139                 :          0 : pick_gen(const struct rte_pci_device *pci_dev)
     140                 :            : {
     141   [ #  #  #  #  :          0 :         switch (pci_dev->id.device_id) {
             #  #  #  #  
                      # ]
     142                 :            :         case 0x0443:
     143                 :            :                 return QAT_GEN1;
     144                 :          0 :         case 0x37c9:
     145                 :            :         case 0x19e3:
     146                 :            :         case 0x6f55:
     147                 :            :         case 0x18ef:
     148                 :          0 :                 return QAT_GEN2;
     149                 :          0 :         case 0x18a1:
     150                 :            :         case 0x578b:
     151                 :          0 :                 return QAT_GEN3;
     152                 :          0 :         case 0x4941:
     153                 :            :         case 0x4943:
     154                 :            :         case 0x4945:
     155                 :          0 :                 return QAT_GEN4;
     156                 :          0 :         case 0x4947:
     157                 :          0 :                 return QAT_GEN5;
     158                 :          0 :         case 0x4949:
     159                 :          0 :                 return QAT_GEN6;
     160                 :          0 :         case 0x1454:
     161                 :          0 :                 return QAT_GEN_LCE;
     162                 :          0 :         case 0x0da5:
     163                 :          0 :                 return QAT_VQAT;
     164                 :          0 :         default:
     165                 :          0 :                 QAT_LOG(ERR, "Invalid dev_id, can't determine generation");
     166                 :          0 :                 return QAT_N_GENS;
     167                 :            :         }
     168                 :            : }
     169                 :            : 
     170                 :            : static int
     171                 :            : wireless_slice_support(uint16_t pci_dev_id)
     172                 :            : {
     173                 :          0 :         return pci_dev_id == 0x578b ||
     174                 :          0 :                         pci_dev_id == 0x4947;
     175                 :            : }
     176                 :            : 
     177                 :            : /* This function base on the atoi function peculiarity, non integral part
     178                 :            :  * other than the equals sign is ignored. It will not work with other conversion
     179                 :            :  * functions like strt*.
     180                 :            :  */
     181                 :          0 : const char *qat_dev_cmdline_get_val(struct qat_pci_device *qat_dev,
     182                 :            :         const char *key)
     183                 :            : {
     184         [ #  # ]:          0 :         if (qat_dev->command_line == NULL)
     185                 :            :                 return NULL;
     186                 :          0 :         key = strstr(qat_dev->command_line, key);
     187                 :            :         /* At this point, a key should be validated */
     188         [ #  # ]:          0 :         return key ? strchr(key, '=') + 1 : NULL;
     189                 :            : }
     190                 :            : 
     191                 :          0 : static int cmdline_validate(const char *arg)
     192                 :            : {
     193                 :          0 :         const char *eq_sign = strchr(arg, '=');
     194                 :            :         int i, len;
     195                 :            : 
     196                 :            :         /* Check for the equal sign */
     197         [ #  # ]:          0 :         if (eq_sign == NULL) {
     198                 :          0 :                 QAT_LOG(ERR, "malformed string, no equals sign, %s", arg);
     199                 :          0 :                 return 0;
     200                 :            :         }
     201                 :            :         /* Check if an argument is not empty */
     202                 :          0 :         len = strlen(eq_sign) - 1;
     203         [ #  # ]:          0 :         if (len == 0) {
     204                 :          0 :                 QAT_LOG(ERR, "malformed string, empty argument, %s", arg);
     205                 :          0 :                 return 0;
     206                 :            :         }
     207                 :          0 :         len = eq_sign - arg;
     208         [ #  # ]:          0 :         for (i = 0; i < QAT_MAX_SERVICES + 1; i++) {
     209                 :            :                 int j = 0;
     210                 :            :                 const char *def = NULL;
     211                 :            : 
     212         [ #  # ]:          0 :                 if (!qat_cmdline_defines[i])
     213                 :          0 :                         continue;
     214         [ #  # ]:          0 :                 while ((def = qat_cmdline_defines[i][j++])) {
     215         [ #  # ]:          0 :                         if (strncmp(def, arg, len))
     216                 :          0 :                                 continue;
     217                 :          0 :                         QAT_LOG(DEBUG, "Found %s command line argument",
     218                 :            :                                 def);
     219                 :          0 :                         return 1;
     220                 :            :                 }
     221                 :            :         }
     222                 :            :         return 0;
     223                 :            : }
     224                 :            : 
     225                 :            : static int
     226                 :          0 : qat_dev_parse_command_line(struct qat_pci_device *qat_dev,
     227                 :            :         struct rte_devargs *devargs)
     228                 :            : {
     229                 :            :         int len = 0;
     230                 :            :         char *token = NULL;
     231                 :            : 
     232         [ #  # ]:          0 :         if (!devargs)
     233                 :            :                 return 0;
     234                 :            : 
     235                 :          0 :         len = strlen(devargs->drv_str);
     236         [ #  # ]:          0 :         if (len == 0)
     237                 :            :                 return 0;
     238                 :          0 :         ++len;
     239                 :            :         /* Allocate per-device command line */
     240                 :          0 :         qat_dev->command_line = rte_malloc(NULL, len, 0);
     241         [ #  # ]:          0 :         if (qat_dev->command_line == NULL) {
     242                 :          0 :                 QAT_LOG(ERR, "Cannot allocate memory for command line");
     243                 :          0 :                 return -1;
     244                 :            :         }
     245                 :          0 :         strcpy(qat_dev->command_line, devargs->drv_str);
     246                 :          0 :         token = strtok(qat_dev->command_line, ",");
     247         [ #  # ]:          0 :         while (token != NULL) {
     248         [ #  # ]:          0 :                 if (!cmdline_validate(token)) {
     249                 :          0 :                         QAT_LOG(ERR, "Incorrect command line argument: %s",
     250                 :            :                                 token);
     251                 :          0 :                         return -1;
     252                 :            :                 }
     253                 :          0 :                 token = strtok(NULL, ",");
     254                 :            :         }
     255                 :            :         /* Copy once againe the entire string, strtok already altered the contents */
     256                 :          0 :         strcpy(qat_dev->command_line, devargs->drv_str);
     257                 :          0 :         return 0;
     258                 :            : }
     259                 :            : 
     260                 :            : static struct qat_pci_device *
     261                 :          0 : qat_pci_device_allocate(struct rte_pci_device *pci_dev)
     262                 :            : {
     263                 :            :         struct qat_pci_device *qat_dev;
     264                 :            :         enum qat_device_gen qat_dev_gen;
     265                 :            :         uint8_t qat_dev_id = 0;
     266                 :            :         char name[QAT_DEV_NAME_MAX_LEN];
     267                 :          0 :         struct rte_devargs *devargs = pci_dev->device.devargs;
     268                 :            :         struct qat_dev_hw_spec_funcs *ops_hw;
     269                 :            :         struct rte_mem_resource *mem_resource;
     270                 :            :         const struct rte_memzone *qat_dev_mz;
     271                 :            :         int qat_dev_size, extra_size;
     272                 :            :         const char *cmdline = NULL;
     273                 :            : 
     274                 :          0 :         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
     275                 :          0 :         snprintf(name+strlen(name), QAT_DEV_NAME_MAX_LEN-strlen(name), "_qat");
     276                 :            : 
     277                 :          0 :         qat_dev_gen = pick_gen(pci_dev);
     278         [ #  # ]:          0 :         if (qat_dev_gen == QAT_N_GENS) {
     279                 :          0 :                 QAT_LOG(ERR, "Invalid dev_id, can't determine generation");
     280                 :          0 :                 return NULL;
     281                 :            :         }
     282                 :            : 
     283         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
     284                 :          0 :                 const struct rte_memzone *mz = rte_memzone_lookup(name);
     285                 :            : 
     286         [ #  # ]:          0 :                 if (mz == NULL) {
     287                 :          0 :                         QAT_LOG(ERR,
     288                 :            :                                 "Secondary can't find %s mz, did primary create device?",
     289                 :            :                                 name);
     290                 :          0 :                         return NULL;
     291                 :            :                 }
     292                 :          0 :                 qat_dev = mz->addr;
     293                 :          0 :                 qat_pci_devs[qat_dev->qat_dev_id].mz = mz;
     294                 :          0 :                 qat_pci_devs[qat_dev->qat_dev_id].pci_dev = pci_dev;
     295                 :          0 :                 qat_nb_pci_devices++;
     296                 :          0 :                 QAT_LOG(DEBUG, "QAT device %d found, name %s, total QATs %d",
     297                 :            :                         qat_dev->qat_dev_id, qat_dev->name, qat_nb_pci_devices);
     298                 :          0 :                 return qat_dev;
     299                 :            :         }
     300                 :            : 
     301         [ #  # ]:          0 :         if (qat_pci_get_named_dev(name) != NULL) {
     302                 :          0 :                 QAT_LOG(ERR, "QAT device with name %s already allocated!",
     303                 :            :                                 name);
     304                 :          0 :                 return NULL;
     305                 :            :         }
     306                 :            : 
     307                 :            :         qat_dev_id = qat_pci_find_free_device_index();
     308         [ #  # ]:          0 :         if (qat_dev_id == RTE_PMD_QAT_MAX_PCI_DEVICES) {
     309                 :          0 :                 QAT_LOG(ERR, "Reached maximum number of QAT devices");
     310                 :          0 :                 return NULL;
     311                 :            :         }
     312                 :            : 
     313                 :            :         extra_size = qat_pci_get_extra_size(qat_dev_gen);
     314         [ #  # ]:          0 :         if (extra_size < 0) {
     315                 :          0 :                 QAT_LOG(ERR, "QAT internal error: no pci pointer for gen %d",
     316                 :            :                         qat_dev_gen);
     317                 :          0 :                 return NULL;
     318                 :            :         }
     319                 :            : 
     320                 :          0 :         qat_dev_size = sizeof(struct qat_pci_device) + sizeof(void *) *
     321                 :          0 :                                 QAT_MAX_SERVICES + extra_size;
     322                 :          0 :         qat_dev_mz = rte_memzone_reserve(name, qat_dev_size,
     323                 :          0 :                 rte_socket_id(), 0);
     324                 :            : 
     325         [ #  # ]:          0 :         if (qat_dev_mz == NULL) {
     326                 :          0 :                 QAT_LOG(ERR, "Error when allocating memzone for QAT_%d",
     327                 :            :                         qat_dev_id);
     328                 :          0 :                 return NULL;
     329                 :            :         }
     330                 :            : 
     331         [ #  # ]:          0 :         qat_dev = qat_dev_mz->addr;
     332                 :            :         memset(qat_dev, 0, qat_dev_size);
     333                 :          0 :         qat_dev->dev_private = qat_dev + 1;
     334         [ #  # ]:          0 :         strlcpy(qat_dev->name, name, QAT_DEV_NAME_MAX_LEN);
     335                 :          0 :         qat_dev->qat_dev_id = qat_dev_id;
     336                 :          0 :         qat_dev->qat_dev_gen = qat_dev_gen;
     337                 :          0 :         qat_pci_devs[qat_dev_id].pci_dev = pci_dev;
     338                 :            : 
     339         [ #  # ]:          0 :         if (wireless_slice_support(pci_dev->id.device_id))
     340                 :          0 :                 qat_dev->options.has_wireless_slice = 1;
     341                 :            : 
     342                 :          0 :         ops_hw = qat_dev_hw_spec[qat_dev->qat_dev_gen];
     343         [ #  # ]:          0 :         NOT_NULL(ops_hw->qat_dev_get_misc_bar, goto error,
     344                 :            :                 "QAT internal error! qat_dev_get_misc_bar function not set");
     345         [ #  # ]:          0 :         if (ops_hw->qat_dev_get_misc_bar(&mem_resource, pci_dev) == 0) {
     346         [ #  # ]:          0 :                 if (mem_resource->addr == NULL) {
     347                 :          0 :                         QAT_LOG(ERR, "QAT cannot get access to VF misc bar");
     348                 :          0 :                         goto error;
     349                 :            :                 }
     350                 :          0 :                 qat_dev->misc_bar_io_addr = mem_resource->addr;
     351                 :            :         } else
     352                 :          0 :                 qat_dev->misc_bar_io_addr = NULL;
     353                 :            : 
     354                 :            :         /* Parse the command line */
     355         [ #  # ]:          0 :         if (qat_dev_parse_command_line(qat_dev, devargs))
     356                 :          0 :                 goto error;
     357                 :            : 
     358                 :            :         /* Parse the arguments */
     359                 :          0 :         cmdline = qat_dev_cmdline_get_val(qat_dev, QAT_LEGACY_CAPA);
     360         [ #  # ]:          0 :         if (cmdline)
     361                 :          0 :                 qat_dev->options.legacy_alg = atoi(cmdline);
     362                 :            : 
     363         [ #  # ]:          0 :         if (qat_read_qp_config(qat_dev)) {
     364                 :          0 :                 QAT_LOG(ERR,
     365                 :            :                         "Cannot acquire ring configuration for QAT_%d",
     366                 :            :                         qat_dev_id);
     367                 :          0 :                 goto error;
     368                 :            :         }
     369         [ #  # ]:          0 :         NOT_NULL(ops_hw->qat_dev_reset_ring_pairs, goto error,
     370                 :            :                 "QAT internal error! Reset ring pairs function not set, gen : %d",
     371                 :            :                 qat_dev_gen);
     372         [ #  # ]:          0 :         if (ops_hw->qat_dev_reset_ring_pairs(qat_dev)) {
     373                 :          0 :                 QAT_LOG(ERR,
     374                 :            :                         "Cannot reset ring pairs, does pf driver supports pf2vf comms?"
     375                 :            :                         );
     376                 :          0 :                 goto error;
     377                 :            :         }
     378         [ #  # ]:          0 :         NOT_NULL(ops_hw->qat_dev_get_slice_map, goto error,
     379                 :            :                 "QAT internal error! Read slice function not set, gen : %d",
     380                 :            :                 qat_dev_gen);
     381         [ #  # ]:          0 :         if (ops_hw->qat_dev_get_slice_map(&qat_dev->options.slice_map, pci_dev) < 0) {
     382                 :          0 :                 QAT_LOG(ERR,
     383                 :            :                         "Cannot read slice configuration");
     384                 :          0 :                 goto error;
     385                 :            :         }
     386                 :            :         rte_spinlock_init(&qat_dev->arb_csr_lock);
     387                 :            : 
     388                 :            :         /* No errors when allocating, attach memzone with
     389                 :            :          * qat_dev to list of devices
     390                 :            :          */
     391                 :          0 :         qat_pci_devs[qat_dev_id].mz = qat_dev_mz;
     392                 :          0 :         qat_nb_pci_devices++;
     393                 :            : 
     394                 :          0 :         QAT_LOG(DEBUG, "QAT device %d found, name %s, total QATs %d",
     395                 :            :                         qat_dev->qat_dev_id, qat_dev->name, qat_nb_pci_devices);
     396                 :            : 
     397                 :          0 :         return qat_dev;
     398                 :          0 : error:
     399                 :          0 :         rte_free(qat_dev->command_line);
     400                 :          0 :         rte_memzone_free(qat_dev_mz);
     401                 :          0 :         return NULL;
     402                 :            : }
     403                 :            : 
     404                 :            : static int
     405                 :          0 : qat_pci_device_release(struct rte_pci_device *pci_dev)
     406                 :            : {
     407                 :            :         struct qat_pci_device *qat_dev;
     408                 :            :         char name[QAT_DEV_NAME_MAX_LEN];
     409                 :            :         int busy = 0, i;
     410                 :            : 
     411         [ #  # ]:          0 :         if (pci_dev == NULL)
     412                 :            :                 return -EINVAL;
     413                 :            : 
     414                 :          0 :         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
     415         [ #  # ]:          0 :         snprintf(name+strlen(name), QAT_DEV_NAME_MAX_LEN-strlen(name), "_qat");
     416                 :          0 :         qat_dev = qat_pci_get_named_dev(name);
     417         [ #  # ]:          0 :         if (qat_dev != NULL) {
     418                 :            : 
     419                 :          0 :                 struct qat_device_info *inst =
     420                 :          0 :                                 &qat_pci_devs[qat_dev->qat_dev_id];
     421                 :            :                 /* Check that there are no service devs still on pci device */
     422                 :            : 
     423         [ #  # ]:          0 :                 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
     424         [ #  # ]:          0 :                         for (i = 0; i < QAT_MAX_SERVICES; i++) {
     425         [ #  # ]:          0 :                                 if (qat_dev->pmd[i] != NULL) {
     426                 :          0 :                                         QAT_LOG(DEBUG, "QAT %s device %s is busy",
     427                 :            :                                                 qat_service[i].name, name);
     428                 :            :                                         busy = 1;
     429                 :            :                                 }
     430                 :            :                         }
     431         [ #  # ]:          0 :                         if (busy)
     432                 :            :                                 return -EBUSY;
     433                 :          0 :                         rte_memzone_free(inst->mz);
     434                 :            :                 }
     435                 :            :                 memset(inst, 0, sizeof(struct qat_device_info));
     436                 :          0 :                 qat_nb_pci_devices--;
     437                 :          0 :                 QAT_LOG(DEBUG, "QAT device %s released, total QATs %d",
     438                 :            :                                         name, qat_nb_pci_devices);
     439                 :            :         }
     440                 :            :         return 0;
     441                 :            : }
     442                 :            : 
     443                 :            : static int
     444                 :          0 : qat_pci_dev_destroy(struct qat_pci_device *qat_pci_dev,
     445                 :            :                 struct rte_pci_device *pci_dev)
     446                 :            : {
     447                 :            :         int i;
     448                 :            : 
     449         [ #  # ]:          0 :         for (i = 0; i < QAT_MAX_SERVICES; i++) {
     450         [ #  # ]:          0 :                 if (!qat_service[i].dev_destroy)
     451                 :          0 :                         continue;
     452                 :          0 :                 qat_service[i].dev_destroy(qat_pci_dev);
     453                 :            :         }
     454                 :          0 :         return qat_pci_device_release(pci_dev);
     455                 :            : }
     456                 :            : 
     457                 :          0 : static int qat_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
     458                 :            :                 struct rte_pci_device *pci_dev)
     459                 :            : {
     460                 :            :         int i, ret = 0, num_pmds_created = 0;
     461                 :            :         struct qat_pci_device *qat_pci_dev;
     462                 :            : 
     463                 :          0 :         QAT_LOG(DEBUG, "Found QAT device at %02x:%02x.%x",
     464                 :            :                         pci_dev->addr.bus,
     465                 :            :                         pci_dev->addr.devid,
     466                 :            :                         pci_dev->addr.function);
     467                 :            : 
     468                 :          0 :         qat_pci_dev = qat_pci_device_allocate(pci_dev);
     469         [ #  # ]:          0 :         if (qat_pci_dev == NULL)
     470                 :            :                 return -ENODEV;
     471                 :            : 
     472         [ #  # ]:          0 :         for (i = 0; i < QAT_MAX_SERVICES; i++) {
     473         [ #  # ]:          0 :                 if (!qat_service[i].dev_create)
     474                 :          0 :                         continue;
     475                 :          0 :                 ret = qat_service[i].dev_create(qat_pci_dev);
     476         [ #  # ]:          0 :                 if (ret == 0)
     477                 :          0 :                         num_pmds_created++;
     478                 :            :                 else {
     479                 :          0 :                         QAT_LOG(WARNING, "Failed to create %s PMD on device %s",
     480                 :            :                                 qat_service[i].name,
     481                 :            :                                 qat_pci_dev->name);
     482                 :            :                 }
     483                 :            :         }
     484                 :            : 
     485         [ #  # ]:          0 :         if (num_pmds_created == 0)
     486                 :          0 :                 qat_pci_dev_destroy(qat_pci_dev, pci_dev);
     487                 :            : 
     488                 :            :         return 0;
     489                 :            : }
     490                 :            : 
     491                 :            : static int
     492                 :          0 : qat_pci_remove(struct rte_pci_device *pci_dev)
     493                 :            : {
     494                 :            :         struct qat_pci_device *qat_pci_dev;
     495                 :            : 
     496         [ #  # ]:          0 :         if (pci_dev == NULL)
     497                 :            :                 return -EINVAL;
     498                 :            : 
     499                 :            :         qat_pci_dev = qat_get_qat_dev_from_pci_dev(pci_dev);
     500         [ #  # ]:          0 :         if (qat_pci_dev == NULL)
     501                 :            :                 return 0;
     502                 :            : 
     503                 :          0 :         return qat_pci_dev_destroy(qat_pci_dev, pci_dev);
     504                 :            : }
     505                 :            : 
     506                 :            : static struct rte_pci_driver rte_qat_pmd = {
     507                 :            :         .id_table = pci_id_qat_map,
     508                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
     509                 :            :         .probe = qat_pci_probe,
     510                 :            :         .remove = qat_pci_remove
     511                 :            : };
     512                 :            : 
     513                 :        305 : RTE_PMD_REGISTER_PCI(QAT_PCI_NAME, rte_qat_pmd);
     514                 :            : RTE_PMD_REGISTER_PCI_TABLE(QAT_PCI_NAME, pci_id_qat_map);
     515                 :            : RTE_PMD_REGISTER_KMOD_DEP(QAT_PCI_NAME, "* igb_uio | uio_pci_generic | vfio-pci");

Generated by: LCOV version 1.14