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, "User specified device name = %s\n",
100 COMPRESSDEV_LOG(INFO, "Creating compressdev %s\n", name);
102 COMPRESSDEV_LOG(INFO, "Init parameters - name: %s, socket id: %d",
103 name, params->socket_id);
105 /* allocate device structure */
106 compressdev = rte_compressdev_pmd_allocate(name, params->socket_id);
107 if (compressdev == NULL) {
108 COMPRESSDEV_LOG(ERR, "Failed to allocate comp device %s", name);
112 /* allocate private device structure */
113 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
114 compressdev->data->dev_private =
115 rte_zmalloc_socket("compressdev device private",
120 if (compressdev->data->dev_private == NULL) {
122 "Cannot allocate memory for compressdev"
123 " %s private data", name);
125 rte_compressdev_pmd_release_device(compressdev);
130 compressdev->device = device;
135 int __rte_experimental
136 rte_compressdev_pmd_destroy(struct rte_compressdev *compressdev)
140 COMPRESSDEV_LOG(INFO, "Closing comp device %s",
141 compressdev->device->name);
143 /* free comp device */
144 retval = rte_compressdev_pmd_release_device(compressdev);
148 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
149 rte_free(compressdev->data->dev_private);
151 compressdev->device = NULL;
152 compressdev->data = NULL;