1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017-2018 Intel Corporation
5 #include <rte_malloc.h>
6 #include <rte_kvargs.h>
9 #include "rte_compressdev_internal.h"
10 #include "rte_compressdev_pmd.h"
12 int compressdev_logtype;
15 * Parse name from argument
18 rte_compressdev_pmd_parse_name_arg(const char *key __rte_unused,
19 const char *value, void *extra_args)
21 struct rte_compressdev_pmd_init_params *params = extra_args;
24 n = snprintf(params->name, RTE_COMPRESSDEV_NAME_MAX_LEN, "%s", value);
25 if (n >= RTE_COMPRESSDEV_NAME_MAX_LEN)
32 * Parse unsigned integer from argument
35 rte_compressdev_pmd_parse_uint_arg(const char *key __rte_unused,
36 const char *value, void *extra_args)
42 i = strtol(value, &end, 10);
43 if (*end != 0 || errno != 0 || i < 0)
46 *((uint32_t *)extra_args) = i;
50 int __rte_experimental
51 rte_compressdev_pmd_parse_input_args(
52 struct rte_compressdev_pmd_init_params *params,
55 struct rte_kvargs *kvlist = NULL;
62 kvlist = rte_kvargs_parse(args, compressdev_pmd_valid_params);
66 ret = rte_kvargs_process(kvlist,
67 RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG,
68 &rte_compressdev_pmd_parse_uint_arg,
73 ret = rte_kvargs_process(kvlist,
74 RTE_COMPRESSDEV_PMD_NAME_ARG,
75 &rte_compressdev_pmd_parse_name_arg,
82 rte_kvargs_free(kvlist);
86 struct rte_compressdev * __rte_experimental
87 rte_compressdev_pmd_create(const char *name,
88 struct rte_device *device,
89 size_t private_data_size,
90 struct rte_compressdev_pmd_init_params *params)
92 struct rte_compressdev *compressdev;
94 if (params->name[0] != '\0') {
95 COMPRESSDEV_LOG(INFO, "[%s] User specified device name = %s\n",
96 device->driver->name, params->name);
100 COMPRESSDEV_LOG(INFO, "[%s] - Creating compressdev %s\n",
101 device->driver->name, name);
103 COMPRESSDEV_LOG(INFO,
104 "[%s] - Init parameters - name: %s, socket id: %d",
105 device->driver->name, name,
108 /* allocate device structure */
109 compressdev = rte_compressdev_pmd_allocate(name, params->socket_id);
110 if (compressdev == NULL) {
111 COMPRESSDEV_LOG(ERR, "[%s] Failed to allocate comp device %s",
112 device->driver->name, name);
116 /* allocate private device structure */
117 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
118 compressdev->data->dev_private =
119 rte_zmalloc_socket("compressdev device private",
124 if (compressdev->data->dev_private == NULL) {
126 "[%s] Cannot allocate memory for compressdev %s private data",
127 device->driver->name, name);
129 rte_compressdev_pmd_release_device(compressdev);
134 compressdev->device = device;
139 int __rte_experimental
140 rte_compressdev_pmd_destroy(struct rte_compressdev *compressdev)
144 COMPRESSDEV_LOG(INFO, "[%s] Closing comp device %s",
145 compressdev->device->driver->name,
146 compressdev->device->name);
148 /* free comp device */
149 retval = rte_compressdev_pmd_release_device(compressdev);
153 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
154 rte_free(compressdev->data->dev_private);
156 compressdev->device = NULL;
157 compressdev->data = NULL;