1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017-2018 Intel Corporation
5 #include <rte_string_fns.h>
6 #include <rte_malloc.h>
7 #include <rte_kvargs.h>
10 #include "rte_compressdev_internal.h"
11 #include "rte_compressdev_pmd.h"
14 * Parse name from argument
17 rte_compressdev_pmd_parse_name_arg(const char *key __rte_unused,
18 const char *value, void *extra_args)
20 struct rte_compressdev_pmd_init_params *params = extra_args;
23 n = strlcpy(params->name, value, RTE_COMPRESSDEV_NAME_MAX_LEN);
24 if (n >= RTE_COMPRESSDEV_NAME_MAX_LEN)
31 * Parse unsigned integer from argument
34 rte_compressdev_pmd_parse_uint_arg(const char *key __rte_unused,
35 const char *value, void *extra_args)
41 i = strtol(value, &end, 10);
42 if (*end != 0 || errno != 0 || i < 0)
45 *((uint32_t *)extra_args) = i;
50 rte_compressdev_pmd_parse_input_args(
51 struct rte_compressdev_pmd_init_params *params,
54 struct rte_kvargs *kvlist = NULL;
61 kvlist = rte_kvargs_parse(args, compressdev_pmd_valid_params);
65 ret = rte_kvargs_process(kvlist,
66 RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG,
67 &rte_compressdev_pmd_parse_uint_arg,
72 ret = rte_kvargs_process(kvlist,
73 RTE_COMPRESSDEV_PMD_NAME_ARG,
74 &rte_compressdev_pmd_parse_name_arg,
81 rte_kvargs_free(kvlist);
85 struct rte_compressdev *
86 rte_compressdev_pmd_create(const char *name,
87 struct rte_device *device,
88 size_t private_data_size,
89 struct rte_compressdev_pmd_init_params *params)
91 struct rte_compressdev *compressdev;
93 if (params->name[0] != '\0') {
94 COMPRESSDEV_LOG(INFO, "User specified device name = %s\n",
99 COMPRESSDEV_LOG(INFO, "Creating compressdev %s\n", name);
101 COMPRESSDEV_LOG(INFO, "Init parameters - name: %s, socket id: %d",
102 name, params->socket_id);
104 /* allocate device structure */
105 compressdev = rte_compressdev_pmd_allocate(name, params->socket_id);
106 if (compressdev == NULL) {
107 COMPRESSDEV_LOG(ERR, "Failed to allocate comp device %s", name);
111 /* allocate private device structure */
112 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
113 compressdev->data->dev_private =
114 rte_zmalloc_socket("compressdev device private",
119 if (compressdev->data->dev_private == NULL) {
121 "Cannot allocate memory for compressdev"
122 " %s private data", name);
124 rte_compressdev_pmd_release_device(compressdev);
129 compressdev->device = device;
135 rte_compressdev_pmd_destroy(struct rte_compressdev *compressdev)
139 COMPRESSDEV_LOG(INFO, "Closing comp device %s",
140 compressdev->device->name);
142 /* free comp device */
143 retval = rte_compressdev_pmd_release_device(compressdev);
147 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
148 rte_free(compressdev->data->dev_private);
150 compressdev->device = NULL;
151 compressdev->data = NULL;