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"
13 int compressdev_logtype;
16 * Parse name from argument
19 rte_compressdev_pmd_parse_name_arg(const char *key __rte_unused,
20 const char *value, void *extra_args)
22 struct rte_compressdev_pmd_init_params *params = extra_args;
25 n = strlcpy(params->name, value, RTE_COMPRESSDEV_NAME_MAX_LEN);
26 if (n >= RTE_COMPRESSDEV_NAME_MAX_LEN)
33 * Parse unsigned integer from argument
36 rte_compressdev_pmd_parse_uint_arg(const char *key __rte_unused,
37 const char *value, void *extra_args)
43 i = strtol(value, &end, 10);
44 if (*end != 0 || errno != 0 || i < 0)
47 *((uint32_t *)extra_args) = i;
52 rte_compressdev_pmd_parse_input_args(
53 struct rte_compressdev_pmd_init_params *params,
56 struct rte_kvargs *kvlist = NULL;
63 kvlist = rte_kvargs_parse(args, compressdev_pmd_valid_params);
67 ret = rte_kvargs_process(kvlist,
68 RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG,
69 &rte_compressdev_pmd_parse_uint_arg,
74 ret = rte_kvargs_process(kvlist,
75 RTE_COMPRESSDEV_PMD_NAME_ARG,
76 &rte_compressdev_pmd_parse_name_arg,
83 rte_kvargs_free(kvlist);
87 struct rte_compressdev *
88 rte_compressdev_pmd_create(const char *name,
89 struct rte_device *device,
90 size_t private_data_size,
91 struct rte_compressdev_pmd_init_params *params)
93 struct rte_compressdev *compressdev;
95 if (params->name[0] != '\0') {
96 COMPRESSDEV_LOG(INFO, "User specified device name = %s\n",
101 COMPRESSDEV_LOG(INFO, "Creating compressdev %s\n", name);
103 COMPRESSDEV_LOG(INFO, "Init parameters - name: %s, socket id: %d",
104 name, params->socket_id);
106 /* allocate device structure */
107 compressdev = rte_compressdev_pmd_allocate(name, params->socket_id);
108 if (compressdev == NULL) {
109 COMPRESSDEV_LOG(ERR, "Failed to allocate comp device %s", name);
113 /* allocate private device structure */
114 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
115 compressdev->data->dev_private =
116 rte_zmalloc_socket("compressdev device private",
121 if (compressdev->data->dev_private == NULL) {
123 "Cannot allocate memory for compressdev"
124 " %s private data", name);
126 rte_compressdev_pmd_release_device(compressdev);
131 compressdev->device = device;
137 rte_compressdev_pmd_destroy(struct rte_compressdev *compressdev)
141 COMPRESSDEV_LOG(INFO, "Closing comp device %s",
142 compressdev->device->name);
144 /* free comp device */
145 retval = rte_compressdev_pmd_release_device(compressdev);
149 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
150 rte_free(compressdev->data->dev_private);
152 compressdev->device = NULL;
153 compressdev->data = NULL;