LCOV - code coverage report
Current view: top level - lib/compressdev - rte_compressdev_pmd.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 54 0.0 %
Date: 2025-05-01 17:49:45 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 36 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2017-2018 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdlib.h>
       6                 :            : 
       7                 :            : #include <eal_export.h>
       8                 :            : #include <rte_string_fns.h>
       9                 :            : #include <rte_malloc.h>
      10                 :            : #include <rte_kvargs.h>
      11                 :            : #include <dev_driver.h>
      12                 :            : #include <rte_eal.h>
      13                 :            : 
      14                 :            : #include "rte_compressdev_internal.h"
      15                 :            : #include "rte_compressdev_pmd.h"
      16                 :            : 
      17                 :            : /**
      18                 :            :  * Parse name from argument
      19                 :            :  */
      20                 :            : static int
      21                 :          0 : rte_compressdev_pmd_parse_name_arg(const char *key __rte_unused,
      22                 :            :                 const char *value, void *extra_args)
      23                 :            : {
      24                 :            :         struct rte_compressdev_pmd_init_params *params = extra_args;
      25                 :            :         int n;
      26                 :            : 
      27         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
      28                 :            :                 return -EINVAL;
      29                 :            : 
      30         [ #  # ]:          0 :         n = strlcpy(params->name, value, RTE_COMPRESSDEV_NAME_MAX_LEN);
      31         [ #  # ]:          0 :         if (n >= RTE_COMPRESSDEV_NAME_MAX_LEN)
      32                 :          0 :                 return -EINVAL;
      33                 :            : 
      34                 :            :         return 0;
      35                 :            : }
      36                 :            : 
      37                 :            : /**
      38                 :            :  * Parse unsigned integer from argument
      39                 :            :  */
      40                 :            : static int
      41                 :          0 : rte_compressdev_pmd_parse_uint_arg(const char *key __rte_unused,
      42                 :            :                 const char *value, void *extra_args)
      43                 :            : {
      44                 :            :         int i;
      45                 :            :         char *end;
      46                 :            : 
      47         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
      48                 :            :                 return -EINVAL;
      49                 :            : 
      50                 :          0 :         errno = 0;
      51                 :          0 :         i = strtol(value, &end, 10);
      52   [ #  #  #  #  :          0 :         if (*end != 0 || errno != 0 || i < 0)
                   #  # ]
      53                 :            :                 return -EINVAL;
      54                 :            : 
      55                 :          0 :         *((uint32_t *)extra_args) = i;
      56                 :          0 :         return 0;
      57                 :            : }
      58                 :            : 
      59                 :            : RTE_EXPORT_SYMBOL(rte_compressdev_pmd_parse_input_args)
      60                 :            : int
      61                 :          0 : rte_compressdev_pmd_parse_input_args(
      62                 :            :                 struct rte_compressdev_pmd_init_params *params,
      63                 :            :                 const char *args)
      64                 :            : {
      65                 :            :         struct rte_kvargs *kvlist = NULL;
      66                 :            :         int ret = 0;
      67                 :            : 
      68         [ #  # ]:          0 :         if (params == NULL)
      69                 :            :                 return -EINVAL;
      70                 :            : 
      71         [ #  # ]:          0 :         if (args) {
      72                 :          0 :                 kvlist = rte_kvargs_parse(args, compressdev_pmd_valid_params);
      73         [ #  # ]:          0 :                 if (kvlist == NULL)
      74                 :            :                         return -EINVAL;
      75                 :            : 
      76                 :          0 :                 ret = rte_kvargs_process(kvlist,
      77                 :            :                                 RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG,
      78                 :            :                                 &rte_compressdev_pmd_parse_uint_arg,
      79                 :          0 :                                 &params->socket_id);
      80         [ #  # ]:          0 :                 if (ret < 0)
      81                 :          0 :                         goto free_kvlist;
      82                 :            : 
      83                 :          0 :                 ret = rte_kvargs_process(kvlist,
      84                 :            :                                 RTE_COMPRESSDEV_PMD_NAME_ARG,
      85                 :            :                                 &rte_compressdev_pmd_parse_name_arg,
      86                 :            :                                 params);
      87         [ #  # ]:          0 :                 if (ret < 0)
      88                 :          0 :                         goto free_kvlist;
      89                 :            :         }
      90                 :            : 
      91                 :          0 : free_kvlist:
      92                 :          0 :         rte_kvargs_free(kvlist);
      93                 :          0 :         return ret;
      94                 :            : }
      95                 :            : 
      96                 :            : RTE_EXPORT_SYMBOL(rte_compressdev_pmd_create)
      97                 :            : struct rte_compressdev *
      98                 :          0 : rte_compressdev_pmd_create(const char *name,
      99                 :            :                 struct rte_device *device,
     100                 :            :                 size_t private_data_size,
     101                 :            :                 struct rte_compressdev_pmd_init_params *params)
     102                 :            : {
     103                 :            :         struct rte_compressdev *compressdev;
     104                 :            : 
     105         [ #  # ]:          0 :         if (params->name[0] != '\0') {
     106                 :          0 :                 COMPRESSDEV_LOG(INFO, "User specified device name = %s",
     107                 :            :                                 params->name);
     108                 :            :                 name = params->name;
     109                 :            :         }
     110                 :            : 
     111                 :          0 :         COMPRESSDEV_LOG(INFO, "Creating compressdev %s", name);
     112                 :            : 
     113                 :          0 :         COMPRESSDEV_LOG(INFO, "Init parameters - name: %s, socket id: %d",
     114                 :            :                         name, params->socket_id);
     115                 :            : 
     116                 :            :         /* allocate device structure */
     117                 :          0 :         compressdev = rte_compressdev_pmd_allocate(name, params->socket_id);
     118         [ #  # ]:          0 :         if (compressdev == NULL) {
     119                 :          0 :                 COMPRESSDEV_LOG(ERR, "Failed to allocate comp device %s", name);
     120                 :          0 :                 return NULL;
     121                 :            :         }
     122                 :            : 
     123                 :            :         /* allocate private device structure */
     124         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
     125                 :          0 :                 compressdev->data->dev_private =
     126                 :          0 :                                 rte_zmalloc_socket("compressdev device private",
     127                 :            :                                                 private_data_size,
     128                 :            :                                                 RTE_CACHE_LINE_SIZE,
     129                 :            :                                                 params->socket_id);
     130                 :            : 
     131         [ #  # ]:          0 :                 if (compressdev->data->dev_private == NULL) {
     132                 :          0 :                         COMPRESSDEV_LOG(ERR,
     133                 :            :                                         "Cannot allocate memory for compressdev"
     134                 :            :                                         " %s private data", name);
     135                 :            : 
     136                 :          0 :                         rte_compressdev_pmd_release_device(compressdev);
     137                 :          0 :                         return NULL;
     138                 :            :                 }
     139                 :            :         }
     140                 :            : 
     141                 :          0 :         compressdev->device = device;
     142                 :            : 
     143                 :          0 :         return compressdev;
     144                 :            : }
     145                 :            : 
     146                 :            : RTE_EXPORT_SYMBOL(rte_compressdev_pmd_destroy)
     147                 :            : int
     148                 :          0 : rte_compressdev_pmd_destroy(struct rte_compressdev *compressdev)
     149                 :            : {
     150                 :            :         int retval;
     151                 :            : 
     152                 :          0 :         COMPRESSDEV_LOG(INFO, "Closing comp device %s",
     153                 :            :                         compressdev->device->name);
     154                 :            : 
     155                 :            :         /* free comp device */
     156                 :          0 :         retval = rte_compressdev_pmd_release_device(compressdev);
     157         [ #  # ]:          0 :         if (retval)
     158                 :            :                 return retval;
     159                 :            : 
     160         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
     161                 :          0 :                 rte_free(compressdev->data->dev_private);
     162                 :            : 
     163                 :          0 :         compressdev->device = NULL;
     164                 :          0 :         compressdev->data = NULL;
     165                 :            : 
     166                 :          0 :         return 0;
     167                 :            : }

Generated by: LCOV version 1.14