199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson * Copyright(c) 2017-2018 Intel Corporation
399a2dd95SBruce Richardson */
499a2dd95SBruce Richardson
599a2dd95SBruce Richardson #include <string.h>
699a2dd95SBruce Richardson #include <stdio.h>
799a2dd95SBruce Richardson #include <inttypes.h>
899a2dd95SBruce Richardson
999a2dd95SBruce Richardson #include <rte_string_fns.h>
1099a2dd95SBruce Richardson #include <rte_malloc.h>
1199a2dd95SBruce Richardson #include <rte_eal.h>
1299a2dd95SBruce Richardson #include <rte_memzone.h>
1399a2dd95SBruce Richardson
1499a2dd95SBruce Richardson #include "rte_compressdev.h"
1599a2dd95SBruce Richardson #include "rte_compressdev_internal.h"
1699a2dd95SBruce Richardson #include "rte_compressdev_pmd.h"
1799a2dd95SBruce Richardson
1899a2dd95SBruce Richardson #define RTE_COMPRESSDEV_DETACHED (0)
1999a2dd95SBruce Richardson #define RTE_COMPRESSDEV_ATTACHED (1)
2099a2dd95SBruce Richardson
2199a2dd95SBruce Richardson static struct rte_compressdev rte_comp_devices[RTE_COMPRESS_MAX_DEVS];
2299a2dd95SBruce Richardson
2399a2dd95SBruce Richardson static struct rte_compressdev_global compressdev_globals = {
2499a2dd95SBruce Richardson .devs = rte_comp_devices,
2599a2dd95SBruce Richardson .data = { NULL },
2699a2dd95SBruce Richardson .nb_devs = 0,
2799a2dd95SBruce Richardson .max_devs = RTE_COMPRESS_MAX_DEVS
2899a2dd95SBruce Richardson };
2999a2dd95SBruce Richardson
3099a2dd95SBruce Richardson const struct rte_compressdev_capabilities *
rte_compressdev_capability_get(uint8_t dev_id,enum rte_comp_algorithm algo)3199a2dd95SBruce Richardson rte_compressdev_capability_get(uint8_t dev_id,
3299a2dd95SBruce Richardson enum rte_comp_algorithm algo)
3399a2dd95SBruce Richardson {
3499a2dd95SBruce Richardson const struct rte_compressdev_capabilities *capability;
3599a2dd95SBruce Richardson struct rte_compressdev_info dev_info;
3699a2dd95SBruce Richardson int i = 0;
3799a2dd95SBruce Richardson
3899a2dd95SBruce Richardson if (dev_id >= compressdev_globals.nb_devs) {
3999a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%d", dev_id);
4099a2dd95SBruce Richardson return NULL;
4199a2dd95SBruce Richardson }
4299a2dd95SBruce Richardson rte_compressdev_info_get(dev_id, &dev_info);
4399a2dd95SBruce Richardson
4499a2dd95SBruce Richardson while ((capability = &dev_info.capabilities[i++])->algo !=
4599a2dd95SBruce Richardson RTE_COMP_ALGO_UNSPECIFIED){
4699a2dd95SBruce Richardson if (capability->algo == algo)
4799a2dd95SBruce Richardson return capability;
4899a2dd95SBruce Richardson }
4999a2dd95SBruce Richardson
5099a2dd95SBruce Richardson return NULL;
5199a2dd95SBruce Richardson }
5299a2dd95SBruce Richardson
5399a2dd95SBruce Richardson const char *
rte_compressdev_get_feature_name(uint64_t flag)5499a2dd95SBruce Richardson rte_compressdev_get_feature_name(uint64_t flag)
5599a2dd95SBruce Richardson {
5699a2dd95SBruce Richardson switch (flag) {
5799a2dd95SBruce Richardson case RTE_COMPDEV_FF_HW_ACCELERATED:
5899a2dd95SBruce Richardson return "HW_ACCELERATED";
5999a2dd95SBruce Richardson case RTE_COMPDEV_FF_CPU_SSE:
6099a2dd95SBruce Richardson return "CPU_SSE";
6199a2dd95SBruce Richardson case RTE_COMPDEV_FF_CPU_AVX:
6299a2dd95SBruce Richardson return "CPU_AVX";
6399a2dd95SBruce Richardson case RTE_COMPDEV_FF_CPU_AVX2:
6499a2dd95SBruce Richardson return "CPU_AVX2";
6599a2dd95SBruce Richardson case RTE_COMPDEV_FF_CPU_AVX512:
6699a2dd95SBruce Richardson return "CPU_AVX512";
6799a2dd95SBruce Richardson case RTE_COMPDEV_FF_CPU_NEON:
6899a2dd95SBruce Richardson return "CPU_NEON";
6999a2dd95SBruce Richardson case RTE_COMPDEV_FF_OP_DONE_IN_DEQUEUE:
7099a2dd95SBruce Richardson return "OP_DONE_IN_DEQ";
7199a2dd95SBruce Richardson default:
7299a2dd95SBruce Richardson return NULL;
7399a2dd95SBruce Richardson }
7499a2dd95SBruce Richardson }
7599a2dd95SBruce Richardson
7699a2dd95SBruce Richardson static struct rte_compressdev *
rte_compressdev_get_dev(uint8_t dev_id)7799a2dd95SBruce Richardson rte_compressdev_get_dev(uint8_t dev_id)
7899a2dd95SBruce Richardson {
7999a2dd95SBruce Richardson return &compressdev_globals.devs[dev_id];
8099a2dd95SBruce Richardson }
8199a2dd95SBruce Richardson
8299a2dd95SBruce Richardson struct rte_compressdev *
rte_compressdev_pmd_get_named_dev(const char * name)8399a2dd95SBruce Richardson rte_compressdev_pmd_get_named_dev(const char *name)
8499a2dd95SBruce Richardson {
8599a2dd95SBruce Richardson struct rte_compressdev *dev;
8699a2dd95SBruce Richardson unsigned int i;
8799a2dd95SBruce Richardson
8899a2dd95SBruce Richardson if (name == NULL)
8999a2dd95SBruce Richardson return NULL;
9099a2dd95SBruce Richardson
9199a2dd95SBruce Richardson for (i = 0; i < compressdev_globals.max_devs; i++) {
9299a2dd95SBruce Richardson dev = &compressdev_globals.devs[i];
9399a2dd95SBruce Richardson
9499a2dd95SBruce Richardson if ((dev->attached == RTE_COMPRESSDEV_ATTACHED) &&
9599a2dd95SBruce Richardson (strcmp(dev->data->name, name) == 0))
9699a2dd95SBruce Richardson return dev;
9799a2dd95SBruce Richardson }
9899a2dd95SBruce Richardson
9999a2dd95SBruce Richardson return NULL;
10099a2dd95SBruce Richardson }
10199a2dd95SBruce Richardson
10299a2dd95SBruce Richardson static unsigned int
rte_compressdev_is_valid_dev(uint8_t dev_id)10399a2dd95SBruce Richardson rte_compressdev_is_valid_dev(uint8_t dev_id)
10499a2dd95SBruce Richardson {
10599a2dd95SBruce Richardson struct rte_compressdev *dev = NULL;
10699a2dd95SBruce Richardson
10799a2dd95SBruce Richardson if (dev_id >= compressdev_globals.nb_devs)
10899a2dd95SBruce Richardson return 0;
10999a2dd95SBruce Richardson
11099a2dd95SBruce Richardson dev = rte_compressdev_get_dev(dev_id);
11199a2dd95SBruce Richardson if (dev->attached != RTE_COMPRESSDEV_ATTACHED)
11299a2dd95SBruce Richardson return 0;
11399a2dd95SBruce Richardson else
11499a2dd95SBruce Richardson return 1;
11599a2dd95SBruce Richardson }
11699a2dd95SBruce Richardson
11799a2dd95SBruce Richardson
11899a2dd95SBruce Richardson int
rte_compressdev_get_dev_id(const char * name)11999a2dd95SBruce Richardson rte_compressdev_get_dev_id(const char *name)
12099a2dd95SBruce Richardson {
12199a2dd95SBruce Richardson unsigned int i;
12299a2dd95SBruce Richardson
12399a2dd95SBruce Richardson if (name == NULL)
12499a2dd95SBruce Richardson return -1;
12599a2dd95SBruce Richardson
12699a2dd95SBruce Richardson for (i = 0; i < compressdev_globals.nb_devs; i++)
12799a2dd95SBruce Richardson if ((strcmp(compressdev_globals.devs[i].data->name, name)
12899a2dd95SBruce Richardson == 0) &&
12999a2dd95SBruce Richardson (compressdev_globals.devs[i].attached ==
13099a2dd95SBruce Richardson RTE_COMPRESSDEV_ATTACHED))
13199a2dd95SBruce Richardson return i;
13299a2dd95SBruce Richardson
13399a2dd95SBruce Richardson return -1;
13499a2dd95SBruce Richardson }
13599a2dd95SBruce Richardson
13699a2dd95SBruce Richardson uint8_t
rte_compressdev_count(void)13799a2dd95SBruce Richardson rte_compressdev_count(void)
13899a2dd95SBruce Richardson {
13999a2dd95SBruce Richardson return compressdev_globals.nb_devs;
14099a2dd95SBruce Richardson }
14199a2dd95SBruce Richardson
14299a2dd95SBruce Richardson uint8_t
rte_compressdev_devices_get(const char * driver_name,uint8_t * devices,uint8_t nb_devices)14399a2dd95SBruce Richardson rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
14499a2dd95SBruce Richardson uint8_t nb_devices)
14599a2dd95SBruce Richardson {
14699a2dd95SBruce Richardson uint8_t i, count = 0;
14799a2dd95SBruce Richardson struct rte_compressdev *devs = compressdev_globals.devs;
14899a2dd95SBruce Richardson uint8_t max_devs = compressdev_globals.max_devs;
14999a2dd95SBruce Richardson
15099a2dd95SBruce Richardson for (i = 0; i < max_devs && count < nb_devices; i++) {
15199a2dd95SBruce Richardson
15299a2dd95SBruce Richardson if (devs[i].attached == RTE_COMPRESSDEV_ATTACHED) {
15399a2dd95SBruce Richardson int cmp;
15499a2dd95SBruce Richardson
15599a2dd95SBruce Richardson cmp = strncmp(devs[i].device->driver->name,
15699a2dd95SBruce Richardson driver_name,
15799a2dd95SBruce Richardson strlen(driver_name));
15899a2dd95SBruce Richardson
15999a2dd95SBruce Richardson if (cmp == 0)
16099a2dd95SBruce Richardson devices[count++] = devs[i].data->dev_id;
16199a2dd95SBruce Richardson }
16299a2dd95SBruce Richardson }
16399a2dd95SBruce Richardson
16499a2dd95SBruce Richardson return count;
16599a2dd95SBruce Richardson }
16699a2dd95SBruce Richardson
16799a2dd95SBruce Richardson int
rte_compressdev_socket_id(uint8_t dev_id)16899a2dd95SBruce Richardson rte_compressdev_socket_id(uint8_t dev_id)
16999a2dd95SBruce Richardson {
17099a2dd95SBruce Richardson struct rte_compressdev *dev;
17199a2dd95SBruce Richardson
17299a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id))
17399a2dd95SBruce Richardson return -1;
17499a2dd95SBruce Richardson
17599a2dd95SBruce Richardson dev = rte_compressdev_get_dev(dev_id);
17699a2dd95SBruce Richardson
17799a2dd95SBruce Richardson return dev->data->socket_id;
17899a2dd95SBruce Richardson }
17999a2dd95SBruce Richardson
18099a2dd95SBruce Richardson static inline int
rte_compressdev_data_alloc(uint8_t dev_id,struct rte_compressdev_data ** data,int socket_id)18199a2dd95SBruce Richardson rte_compressdev_data_alloc(uint8_t dev_id, struct rte_compressdev_data **data,
18299a2dd95SBruce Richardson int socket_id)
18399a2dd95SBruce Richardson {
18499a2dd95SBruce Richardson char mz_name[RTE_COMPRESSDEV_NAME_MAX_LEN];
18599a2dd95SBruce Richardson const struct rte_memzone *mz;
18699a2dd95SBruce Richardson int n;
18799a2dd95SBruce Richardson
18899a2dd95SBruce Richardson /* generate memzone name */
18999a2dd95SBruce Richardson n = snprintf(mz_name, sizeof(mz_name),
19099a2dd95SBruce Richardson "rte_compressdev_data_%u", dev_id);
19199a2dd95SBruce Richardson if (n >= (int)sizeof(mz_name))
19299a2dd95SBruce Richardson return -EINVAL;
19399a2dd95SBruce Richardson
19499a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
19599a2dd95SBruce Richardson mz = rte_memzone_reserve(mz_name,
19699a2dd95SBruce Richardson sizeof(struct rte_compressdev_data),
19799a2dd95SBruce Richardson socket_id, 0);
19899a2dd95SBruce Richardson } else
19999a2dd95SBruce Richardson mz = rte_memzone_lookup(mz_name);
20099a2dd95SBruce Richardson
20199a2dd95SBruce Richardson if (mz == NULL)
20299a2dd95SBruce Richardson return -ENOMEM;
20399a2dd95SBruce Richardson
20499a2dd95SBruce Richardson *data = mz->addr;
20599a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY)
20699a2dd95SBruce Richardson memset(*data, 0, sizeof(struct rte_compressdev_data));
20799a2dd95SBruce Richardson
20899a2dd95SBruce Richardson return 0;
20999a2dd95SBruce Richardson }
21099a2dd95SBruce Richardson
21199a2dd95SBruce Richardson static uint8_t
rte_compressdev_find_free_device_index(void)21299a2dd95SBruce Richardson rte_compressdev_find_free_device_index(void)
21399a2dd95SBruce Richardson {
21499a2dd95SBruce Richardson uint8_t dev_id;
21599a2dd95SBruce Richardson
21699a2dd95SBruce Richardson for (dev_id = 0; dev_id < RTE_COMPRESS_MAX_DEVS; dev_id++) {
21799a2dd95SBruce Richardson if (rte_comp_devices[dev_id].attached ==
21899a2dd95SBruce Richardson RTE_COMPRESSDEV_DETACHED)
21999a2dd95SBruce Richardson return dev_id;
22099a2dd95SBruce Richardson }
22199a2dd95SBruce Richardson return RTE_COMPRESS_MAX_DEVS;
22299a2dd95SBruce Richardson }
22399a2dd95SBruce Richardson
22499a2dd95SBruce Richardson struct rte_compressdev *
rte_compressdev_pmd_allocate(const char * name,int socket_id)22599a2dd95SBruce Richardson rte_compressdev_pmd_allocate(const char *name, int socket_id)
22699a2dd95SBruce Richardson {
22799a2dd95SBruce Richardson struct rte_compressdev *compressdev;
22899a2dd95SBruce Richardson uint8_t dev_id;
22999a2dd95SBruce Richardson
23099a2dd95SBruce Richardson if (rte_compressdev_pmd_get_named_dev(name) != NULL) {
23199a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
23299a2dd95SBruce Richardson "comp device with name %s already allocated!", name);
23399a2dd95SBruce Richardson return NULL;
23499a2dd95SBruce Richardson }
23599a2dd95SBruce Richardson
23699a2dd95SBruce Richardson dev_id = rte_compressdev_find_free_device_index();
23799a2dd95SBruce Richardson if (dev_id == RTE_COMPRESS_MAX_DEVS) {
23899a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Reached maximum number of comp devices");
23999a2dd95SBruce Richardson return NULL;
24099a2dd95SBruce Richardson }
24199a2dd95SBruce Richardson compressdev = rte_compressdev_get_dev(dev_id);
24299a2dd95SBruce Richardson
24399a2dd95SBruce Richardson if (compressdev->data == NULL) {
24499a2dd95SBruce Richardson struct rte_compressdev_data *compressdev_data =
24599a2dd95SBruce Richardson compressdev_globals.data[dev_id];
24699a2dd95SBruce Richardson
24799a2dd95SBruce Richardson int retval = rte_compressdev_data_alloc(dev_id,
24899a2dd95SBruce Richardson &compressdev_data, socket_id);
24999a2dd95SBruce Richardson
25099a2dd95SBruce Richardson if (retval < 0 || compressdev_data == NULL)
25199a2dd95SBruce Richardson return NULL;
25299a2dd95SBruce Richardson
25399a2dd95SBruce Richardson compressdev->data = compressdev_data;
25499a2dd95SBruce Richardson
25599a2dd95SBruce Richardson strlcpy(compressdev->data->name, name,
25699a2dd95SBruce Richardson RTE_COMPRESSDEV_NAME_MAX_LEN);
25799a2dd95SBruce Richardson
25899a2dd95SBruce Richardson compressdev->data->dev_id = dev_id;
25999a2dd95SBruce Richardson compressdev->data->socket_id = socket_id;
26099a2dd95SBruce Richardson compressdev->data->dev_started = 0;
26199a2dd95SBruce Richardson
26299a2dd95SBruce Richardson compressdev->attached = RTE_COMPRESSDEV_ATTACHED;
26399a2dd95SBruce Richardson
26499a2dd95SBruce Richardson compressdev_globals.nb_devs++;
26599a2dd95SBruce Richardson }
26699a2dd95SBruce Richardson
26799a2dd95SBruce Richardson return compressdev;
26899a2dd95SBruce Richardson }
26999a2dd95SBruce Richardson
27099a2dd95SBruce Richardson int
rte_compressdev_pmd_release_device(struct rte_compressdev * compressdev)27199a2dd95SBruce Richardson rte_compressdev_pmd_release_device(struct rte_compressdev *compressdev)
27299a2dd95SBruce Richardson {
27399a2dd95SBruce Richardson int ret;
27499a2dd95SBruce Richardson
27599a2dd95SBruce Richardson if (compressdev == NULL)
27699a2dd95SBruce Richardson return -EINVAL;
27799a2dd95SBruce Richardson
27899a2dd95SBruce Richardson /* Close device only if device operations have been set */
27999a2dd95SBruce Richardson if (compressdev->dev_ops) {
28099a2dd95SBruce Richardson ret = rte_compressdev_close(compressdev->data->dev_id);
28199a2dd95SBruce Richardson if (ret < 0)
28299a2dd95SBruce Richardson return ret;
28399a2dd95SBruce Richardson }
28499a2dd95SBruce Richardson
28599a2dd95SBruce Richardson compressdev->attached = RTE_COMPRESSDEV_DETACHED;
28699a2dd95SBruce Richardson compressdev_globals.nb_devs--;
28799a2dd95SBruce Richardson return 0;
28899a2dd95SBruce Richardson }
28999a2dd95SBruce Richardson
29099a2dd95SBruce Richardson uint16_t
rte_compressdev_queue_pair_count(uint8_t dev_id)29199a2dd95SBruce Richardson rte_compressdev_queue_pair_count(uint8_t dev_id)
29299a2dd95SBruce Richardson {
29399a2dd95SBruce Richardson struct rte_compressdev *dev;
29499a2dd95SBruce Richardson
29599a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
29699a2dd95SBruce Richardson return dev->data->nb_queue_pairs;
29799a2dd95SBruce Richardson }
29899a2dd95SBruce Richardson
29999a2dd95SBruce Richardson static int
rte_compressdev_queue_pairs_config(struct rte_compressdev * dev,uint16_t nb_qpairs,int socket_id)30099a2dd95SBruce Richardson rte_compressdev_queue_pairs_config(struct rte_compressdev *dev,
30199a2dd95SBruce Richardson uint16_t nb_qpairs, int socket_id)
30299a2dd95SBruce Richardson {
30399a2dd95SBruce Richardson struct rte_compressdev_info dev_info;
30499a2dd95SBruce Richardson void **qp;
30599a2dd95SBruce Richardson unsigned int i;
30699a2dd95SBruce Richardson
30799a2dd95SBruce Richardson if ((dev == NULL) || (nb_qpairs < 1)) {
30899a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "invalid param: dev %p, nb_queues %u",
30999a2dd95SBruce Richardson dev, nb_qpairs);
31099a2dd95SBruce Richardson return -EINVAL;
31199a2dd95SBruce Richardson }
31299a2dd95SBruce Richardson
31399a2dd95SBruce Richardson COMPRESSDEV_LOG(DEBUG, "Setup %d queues pairs on device %u",
31499a2dd95SBruce Richardson nb_qpairs, dev->data->dev_id);
31599a2dd95SBruce Richardson
31699a2dd95SBruce Richardson memset(&dev_info, 0, sizeof(struct rte_compressdev_info));
31799a2dd95SBruce Richardson
31899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
31999a2dd95SBruce Richardson (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
32099a2dd95SBruce Richardson
32199a2dd95SBruce Richardson if ((dev_info.max_nb_queue_pairs != 0) &&
32299a2dd95SBruce Richardson (nb_qpairs > dev_info.max_nb_queue_pairs)) {
32399a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid num queue_pairs (%u) for dev %u",
32499a2dd95SBruce Richardson nb_qpairs, dev->data->dev_id);
32599a2dd95SBruce Richardson return -EINVAL;
32699a2dd95SBruce Richardson }
32799a2dd95SBruce Richardson
32899a2dd95SBruce Richardson if (dev->data->queue_pairs == NULL) { /* first time configuration */
32999a2dd95SBruce Richardson dev->data->queue_pairs = rte_zmalloc_socket(
33099a2dd95SBruce Richardson "compressdev->queue_pairs",
33199a2dd95SBruce Richardson sizeof(dev->data->queue_pairs[0]) * nb_qpairs,
33299a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE, socket_id);
33399a2dd95SBruce Richardson
33499a2dd95SBruce Richardson if (dev->data->queue_pairs == NULL) {
33599a2dd95SBruce Richardson dev->data->nb_queue_pairs = 0;
33699a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
33799a2dd95SBruce Richardson "failed to get memory for qp meta data, nb_queues %u",
33899a2dd95SBruce Richardson nb_qpairs);
33999a2dd95SBruce Richardson return -(ENOMEM);
34099a2dd95SBruce Richardson }
34199a2dd95SBruce Richardson } else { /* re-configure */
34299a2dd95SBruce Richardson int ret;
34399a2dd95SBruce Richardson uint16_t old_nb_queues = dev->data->nb_queue_pairs;
34499a2dd95SBruce Richardson
34599a2dd95SBruce Richardson qp = dev->data->queue_pairs;
34699a2dd95SBruce Richardson
34799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_release,
34899a2dd95SBruce Richardson -ENOTSUP);
34999a2dd95SBruce Richardson
35099a2dd95SBruce Richardson for (i = nb_qpairs; i < old_nb_queues; i++) {
35199a2dd95SBruce Richardson ret = (*dev->dev_ops->queue_pair_release)(dev, i);
35299a2dd95SBruce Richardson if (ret < 0)
35399a2dd95SBruce Richardson return ret;
35499a2dd95SBruce Richardson }
35599a2dd95SBruce Richardson
35699a2dd95SBruce Richardson qp = rte_realloc(qp, sizeof(qp[0]) * nb_qpairs,
35799a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE);
35899a2dd95SBruce Richardson if (qp == NULL) {
35999a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
36099a2dd95SBruce Richardson "failed to realloc qp meta data, nb_queues %u",
36199a2dd95SBruce Richardson nb_qpairs);
36299a2dd95SBruce Richardson return -(ENOMEM);
36399a2dd95SBruce Richardson }
36499a2dd95SBruce Richardson
36599a2dd95SBruce Richardson if (nb_qpairs > old_nb_queues) {
36699a2dd95SBruce Richardson uint16_t new_qs = nb_qpairs - old_nb_queues;
36799a2dd95SBruce Richardson
36899a2dd95SBruce Richardson memset(qp + old_nb_queues, 0,
36999a2dd95SBruce Richardson sizeof(qp[0]) * new_qs);
37099a2dd95SBruce Richardson }
37199a2dd95SBruce Richardson
37299a2dd95SBruce Richardson dev->data->queue_pairs = qp;
37399a2dd95SBruce Richardson
37499a2dd95SBruce Richardson }
37599a2dd95SBruce Richardson dev->data->nb_queue_pairs = nb_qpairs;
37699a2dd95SBruce Richardson return 0;
37799a2dd95SBruce Richardson }
37899a2dd95SBruce Richardson
37999a2dd95SBruce Richardson static int
rte_compressdev_queue_pairs_release(struct rte_compressdev * dev)38099a2dd95SBruce Richardson rte_compressdev_queue_pairs_release(struct rte_compressdev *dev)
38199a2dd95SBruce Richardson {
38299a2dd95SBruce Richardson uint16_t num_qps, i;
38399a2dd95SBruce Richardson int ret;
38499a2dd95SBruce Richardson
38599a2dd95SBruce Richardson if (dev == NULL) {
38699a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "invalid param: dev %p", dev);
38799a2dd95SBruce Richardson return -EINVAL;
38899a2dd95SBruce Richardson }
38999a2dd95SBruce Richardson
39099a2dd95SBruce Richardson num_qps = dev->data->nb_queue_pairs;
39199a2dd95SBruce Richardson
39299a2dd95SBruce Richardson if (num_qps == 0)
39399a2dd95SBruce Richardson return 0;
39499a2dd95SBruce Richardson
39599a2dd95SBruce Richardson COMPRESSDEV_LOG(DEBUG, "Free %d queues pairs on device %u",
39699a2dd95SBruce Richardson dev->data->nb_queue_pairs, dev->data->dev_id);
39799a2dd95SBruce Richardson
39899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_release,
39999a2dd95SBruce Richardson -ENOTSUP);
40099a2dd95SBruce Richardson
40199a2dd95SBruce Richardson for (i = 0; i < num_qps; i++) {
40299a2dd95SBruce Richardson ret = (*dev->dev_ops->queue_pair_release)(dev, i);
40399a2dd95SBruce Richardson if (ret < 0)
40499a2dd95SBruce Richardson return ret;
40599a2dd95SBruce Richardson }
40699a2dd95SBruce Richardson
40799a2dd95SBruce Richardson rte_free(dev->data->queue_pairs);
40899a2dd95SBruce Richardson dev->data->queue_pairs = NULL;
40999a2dd95SBruce Richardson dev->data->nb_queue_pairs = 0;
41099a2dd95SBruce Richardson
41199a2dd95SBruce Richardson return 0;
41299a2dd95SBruce Richardson }
41399a2dd95SBruce Richardson
41499a2dd95SBruce Richardson int
rte_compressdev_configure(uint8_t dev_id,struct rte_compressdev_config * config)41599a2dd95SBruce Richardson rte_compressdev_configure(uint8_t dev_id, struct rte_compressdev_config *config)
41699a2dd95SBruce Richardson {
41799a2dd95SBruce Richardson struct rte_compressdev *dev;
41899a2dd95SBruce Richardson int diag;
41999a2dd95SBruce Richardson
42099a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id)) {
42199a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%" PRIu8, dev_id);
42299a2dd95SBruce Richardson return -EINVAL;
42399a2dd95SBruce Richardson }
42499a2dd95SBruce Richardson
42599a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
42699a2dd95SBruce Richardson
42799a2dd95SBruce Richardson if (dev->data->dev_started) {
42899a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
42999a2dd95SBruce Richardson "device %d must be stopped to allow configuration", dev_id);
43099a2dd95SBruce Richardson return -EBUSY;
43199a2dd95SBruce Richardson }
43299a2dd95SBruce Richardson
43399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
43499a2dd95SBruce Richardson
43599a2dd95SBruce Richardson /* Setup new number of queue pairs and reconfigure device. */
43699a2dd95SBruce Richardson diag = rte_compressdev_queue_pairs_config(dev, config->nb_queue_pairs,
43799a2dd95SBruce Richardson config->socket_id);
43899a2dd95SBruce Richardson if (diag != 0) {
43999a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
44099a2dd95SBruce Richardson "dev%d rte_comp_dev_queue_pairs_config = %d",
44199a2dd95SBruce Richardson dev_id, diag);
44299a2dd95SBruce Richardson return diag;
44399a2dd95SBruce Richardson }
44499a2dd95SBruce Richardson
44599a2dd95SBruce Richardson return (*dev->dev_ops->dev_configure)(dev, config);
44699a2dd95SBruce Richardson }
44799a2dd95SBruce Richardson
44899a2dd95SBruce Richardson int
rte_compressdev_start(uint8_t dev_id)44999a2dd95SBruce Richardson rte_compressdev_start(uint8_t dev_id)
45099a2dd95SBruce Richardson {
45199a2dd95SBruce Richardson struct rte_compressdev *dev;
45299a2dd95SBruce Richardson int diag;
45399a2dd95SBruce Richardson
45499a2dd95SBruce Richardson COMPRESSDEV_LOG(DEBUG, "Start dev_id=%" PRIu8, dev_id);
45599a2dd95SBruce Richardson
45699a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id)) {
45799a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%" PRIu8, dev_id);
45899a2dd95SBruce Richardson return -EINVAL;
45999a2dd95SBruce Richardson }
46099a2dd95SBruce Richardson
46199a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
46299a2dd95SBruce Richardson
46399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
46499a2dd95SBruce Richardson
46599a2dd95SBruce Richardson if (dev->data->dev_started != 0) {
46699a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
46799a2dd95SBruce Richardson "Device with dev_id=%" PRIu8 " already started", dev_id);
46899a2dd95SBruce Richardson return 0;
46999a2dd95SBruce Richardson }
47099a2dd95SBruce Richardson
47199a2dd95SBruce Richardson diag = (*dev->dev_ops->dev_start)(dev);
47299a2dd95SBruce Richardson if (diag == 0)
47399a2dd95SBruce Richardson dev->data->dev_started = 1;
47499a2dd95SBruce Richardson else
47599a2dd95SBruce Richardson return diag;
47699a2dd95SBruce Richardson
47799a2dd95SBruce Richardson return 0;
47899a2dd95SBruce Richardson }
47999a2dd95SBruce Richardson
48099a2dd95SBruce Richardson void
rte_compressdev_stop(uint8_t dev_id)48199a2dd95SBruce Richardson rte_compressdev_stop(uint8_t dev_id)
48299a2dd95SBruce Richardson {
48399a2dd95SBruce Richardson struct rte_compressdev *dev;
48499a2dd95SBruce Richardson
48599a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id)) {
48699a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%" PRIu8, dev_id);
48799a2dd95SBruce Richardson return;
48899a2dd95SBruce Richardson }
48999a2dd95SBruce Richardson
49099a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
49199a2dd95SBruce Richardson
49299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
49399a2dd95SBruce Richardson
49499a2dd95SBruce Richardson if (dev->data->dev_started == 0) {
49599a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
49699a2dd95SBruce Richardson "Device with dev_id=%" PRIu8 " already stopped", dev_id);
49799a2dd95SBruce Richardson return;
49899a2dd95SBruce Richardson }
49999a2dd95SBruce Richardson
50099a2dd95SBruce Richardson (*dev->dev_ops->dev_stop)(dev);
50199a2dd95SBruce Richardson dev->data->dev_started = 0;
50299a2dd95SBruce Richardson }
50399a2dd95SBruce Richardson
50499a2dd95SBruce Richardson int
rte_compressdev_close(uint8_t dev_id)50599a2dd95SBruce Richardson rte_compressdev_close(uint8_t dev_id)
50699a2dd95SBruce Richardson {
50799a2dd95SBruce Richardson struct rte_compressdev *dev;
50899a2dd95SBruce Richardson int retval;
50999a2dd95SBruce Richardson
51099a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id)) {
51199a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%" PRIu8, dev_id);
51299a2dd95SBruce Richardson return -1;
51399a2dd95SBruce Richardson }
51499a2dd95SBruce Richardson
51599a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
51699a2dd95SBruce Richardson
51799a2dd95SBruce Richardson /* Device must be stopped before it can be closed */
51899a2dd95SBruce Richardson if (dev->data->dev_started == 1) {
51999a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Device %u must be stopped before closing",
52099a2dd95SBruce Richardson dev_id);
52199a2dd95SBruce Richardson return -EBUSY;
52299a2dd95SBruce Richardson }
52399a2dd95SBruce Richardson
52499a2dd95SBruce Richardson /* Free queue pairs memory */
52599a2dd95SBruce Richardson retval = rte_compressdev_queue_pairs_release(dev);
52699a2dd95SBruce Richardson
52799a2dd95SBruce Richardson if (retval < 0)
52899a2dd95SBruce Richardson return retval;
52999a2dd95SBruce Richardson
53099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
53199a2dd95SBruce Richardson retval = (*dev->dev_ops->dev_close)(dev);
53299a2dd95SBruce Richardson
53399a2dd95SBruce Richardson if (retval < 0)
53499a2dd95SBruce Richardson return retval;
53599a2dd95SBruce Richardson
53699a2dd95SBruce Richardson return 0;
53799a2dd95SBruce Richardson }
53899a2dd95SBruce Richardson
53999a2dd95SBruce Richardson int
rte_compressdev_queue_pair_setup(uint8_t dev_id,uint16_t queue_pair_id,uint32_t max_inflight_ops,int socket_id)54099a2dd95SBruce Richardson rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
54199a2dd95SBruce Richardson uint32_t max_inflight_ops, int socket_id)
54299a2dd95SBruce Richardson {
54399a2dd95SBruce Richardson struct rte_compressdev *dev;
54499a2dd95SBruce Richardson
54599a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id)) {
54699a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%" PRIu8, dev_id);
54799a2dd95SBruce Richardson return -EINVAL;
54899a2dd95SBruce Richardson }
54999a2dd95SBruce Richardson
55099a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
55199a2dd95SBruce Richardson if (queue_pair_id >= dev->data->nb_queue_pairs) {
55299a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid queue_pair_id=%d", queue_pair_id);
55399a2dd95SBruce Richardson return -EINVAL;
55499a2dd95SBruce Richardson }
55599a2dd95SBruce Richardson
55699a2dd95SBruce Richardson if (dev->data->dev_started) {
55799a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
55899a2dd95SBruce Richardson "device %d must be stopped to allow configuration", dev_id);
55999a2dd95SBruce Richardson return -EBUSY;
56099a2dd95SBruce Richardson }
56199a2dd95SBruce Richardson
56299a2dd95SBruce Richardson if (max_inflight_ops == 0) {
56399a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
56499a2dd95SBruce Richardson "Invalid maximum number of inflight operations");
56599a2dd95SBruce Richardson return -EINVAL;
56699a2dd95SBruce Richardson }
56799a2dd95SBruce Richardson
56899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_setup, -ENOTSUP);
56999a2dd95SBruce Richardson
57099a2dd95SBruce Richardson return (*dev->dev_ops->queue_pair_setup)(dev, queue_pair_id,
57199a2dd95SBruce Richardson max_inflight_ops, socket_id);
57299a2dd95SBruce Richardson }
57399a2dd95SBruce Richardson
57499a2dd95SBruce Richardson uint16_t
rte_compressdev_dequeue_burst(uint8_t dev_id,uint16_t qp_id,struct rte_comp_op ** ops,uint16_t nb_ops)57599a2dd95SBruce Richardson rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
57699a2dd95SBruce Richardson struct rte_comp_op **ops, uint16_t nb_ops)
57799a2dd95SBruce Richardson {
57899a2dd95SBruce Richardson struct rte_compressdev *dev = &rte_comp_devices[dev_id];
57999a2dd95SBruce Richardson
58099a2dd95SBruce Richardson nb_ops = (*dev->dequeue_burst)
58199a2dd95SBruce Richardson (dev->data->queue_pairs[qp_id], ops, nb_ops);
58299a2dd95SBruce Richardson
58399a2dd95SBruce Richardson return nb_ops;
58499a2dd95SBruce Richardson }
58599a2dd95SBruce Richardson
58699a2dd95SBruce Richardson uint16_t
rte_compressdev_enqueue_burst(uint8_t dev_id,uint16_t qp_id,struct rte_comp_op ** ops,uint16_t nb_ops)58799a2dd95SBruce Richardson rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
58899a2dd95SBruce Richardson struct rte_comp_op **ops, uint16_t nb_ops)
58999a2dd95SBruce Richardson {
59099a2dd95SBruce Richardson struct rte_compressdev *dev = &rte_comp_devices[dev_id];
59199a2dd95SBruce Richardson
59299a2dd95SBruce Richardson return (*dev->enqueue_burst)(
59399a2dd95SBruce Richardson dev->data->queue_pairs[qp_id], ops, nb_ops);
59499a2dd95SBruce Richardson }
59599a2dd95SBruce Richardson
59699a2dd95SBruce Richardson int
rte_compressdev_stats_get(uint8_t dev_id,struct rte_compressdev_stats * stats)59799a2dd95SBruce Richardson rte_compressdev_stats_get(uint8_t dev_id, struct rte_compressdev_stats *stats)
59899a2dd95SBruce Richardson {
59999a2dd95SBruce Richardson struct rte_compressdev *dev;
60099a2dd95SBruce Richardson
60199a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id)) {
60299a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%d", dev_id);
60399a2dd95SBruce Richardson return -ENODEV;
60499a2dd95SBruce Richardson }
60599a2dd95SBruce Richardson
60699a2dd95SBruce Richardson if (stats == NULL) {
60799a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid stats ptr");
60899a2dd95SBruce Richardson return -EINVAL;
60999a2dd95SBruce Richardson }
61099a2dd95SBruce Richardson
61199a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
61299a2dd95SBruce Richardson memset(stats, 0, sizeof(*stats));
61399a2dd95SBruce Richardson
61499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
61599a2dd95SBruce Richardson (*dev->dev_ops->stats_get)(dev, stats);
61699a2dd95SBruce Richardson return 0;
61799a2dd95SBruce Richardson }
61899a2dd95SBruce Richardson
61999a2dd95SBruce Richardson void
rte_compressdev_stats_reset(uint8_t dev_id)62099a2dd95SBruce Richardson rte_compressdev_stats_reset(uint8_t dev_id)
62199a2dd95SBruce Richardson {
62299a2dd95SBruce Richardson struct rte_compressdev *dev;
62399a2dd95SBruce Richardson
62499a2dd95SBruce Richardson if (!rte_compressdev_is_valid_dev(dev_id)) {
62599a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%" PRIu8, dev_id);
62699a2dd95SBruce Richardson return;
62799a2dd95SBruce Richardson }
62899a2dd95SBruce Richardson
62999a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
63099a2dd95SBruce Richardson
63199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
63299a2dd95SBruce Richardson (*dev->dev_ops->stats_reset)(dev);
63399a2dd95SBruce Richardson }
63499a2dd95SBruce Richardson
63599a2dd95SBruce Richardson
63699a2dd95SBruce Richardson void
rte_compressdev_info_get(uint8_t dev_id,struct rte_compressdev_info * dev_info)63799a2dd95SBruce Richardson rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info)
63899a2dd95SBruce Richardson {
63999a2dd95SBruce Richardson struct rte_compressdev *dev;
64099a2dd95SBruce Richardson
64199a2dd95SBruce Richardson if (dev_id >= compressdev_globals.nb_devs) {
64299a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR, "Invalid dev_id=%d", dev_id);
64399a2dd95SBruce Richardson return;
64499a2dd95SBruce Richardson }
64599a2dd95SBruce Richardson
64699a2dd95SBruce Richardson dev = &rte_comp_devices[dev_id];
64799a2dd95SBruce Richardson
64899a2dd95SBruce Richardson memset(dev_info, 0, sizeof(struct rte_compressdev_info));
64999a2dd95SBruce Richardson
65099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
65199a2dd95SBruce Richardson (*dev->dev_ops->dev_infos_get)(dev, dev_info);
65299a2dd95SBruce Richardson
65399a2dd95SBruce Richardson dev_info->driver_name = dev->device->driver->name;
65499a2dd95SBruce Richardson }
65599a2dd95SBruce Richardson
65699a2dd95SBruce Richardson int
rte_compressdev_private_xform_create(uint8_t dev_id,const struct rte_comp_xform * xform,void ** priv_xform)65799a2dd95SBruce Richardson rte_compressdev_private_xform_create(uint8_t dev_id,
65899a2dd95SBruce Richardson const struct rte_comp_xform *xform,
65999a2dd95SBruce Richardson void **priv_xform)
66099a2dd95SBruce Richardson {
66199a2dd95SBruce Richardson struct rte_compressdev *dev;
66299a2dd95SBruce Richardson int ret;
66399a2dd95SBruce Richardson
66499a2dd95SBruce Richardson dev = rte_compressdev_get_dev(dev_id);
66599a2dd95SBruce Richardson
66699a2dd95SBruce Richardson if (xform == NULL || priv_xform == NULL || dev == NULL)
66799a2dd95SBruce Richardson return -EINVAL;
66899a2dd95SBruce Richardson
66999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->private_xform_create, -ENOTSUP);
67099a2dd95SBruce Richardson ret = (*dev->dev_ops->private_xform_create)(dev, xform, priv_xform);
67199a2dd95SBruce Richardson if (ret < 0) {
67299a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
67399a2dd95SBruce Richardson "dev_id %d failed to create private_xform: err=%d",
67499a2dd95SBruce Richardson dev_id, ret);
67599a2dd95SBruce Richardson return ret;
67699a2dd95SBruce Richardson };
67799a2dd95SBruce Richardson
67899a2dd95SBruce Richardson return 0;
67999a2dd95SBruce Richardson }
68099a2dd95SBruce Richardson
68199a2dd95SBruce Richardson int
rte_compressdev_private_xform_free(uint8_t dev_id,void * priv_xform)68299a2dd95SBruce Richardson rte_compressdev_private_xform_free(uint8_t dev_id, void *priv_xform)
68399a2dd95SBruce Richardson {
68499a2dd95SBruce Richardson struct rte_compressdev *dev;
68599a2dd95SBruce Richardson int ret;
68699a2dd95SBruce Richardson
68799a2dd95SBruce Richardson dev = rte_compressdev_get_dev(dev_id);
68899a2dd95SBruce Richardson
68999a2dd95SBruce Richardson if (dev == NULL || priv_xform == NULL)
69099a2dd95SBruce Richardson return -EINVAL;
69199a2dd95SBruce Richardson
69299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->private_xform_free, -ENOTSUP);
69399a2dd95SBruce Richardson ret = dev->dev_ops->private_xform_free(dev, priv_xform);
69499a2dd95SBruce Richardson if (ret < 0) {
69599a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
69699a2dd95SBruce Richardson "dev_id %d failed to free private xform: err=%d",
69799a2dd95SBruce Richardson dev_id, ret);
69899a2dd95SBruce Richardson return ret;
69999a2dd95SBruce Richardson };
70099a2dd95SBruce Richardson
70199a2dd95SBruce Richardson return 0;
70299a2dd95SBruce Richardson }
70399a2dd95SBruce Richardson
70499a2dd95SBruce Richardson int
rte_compressdev_stream_create(uint8_t dev_id,const struct rte_comp_xform * xform,void ** stream)70599a2dd95SBruce Richardson rte_compressdev_stream_create(uint8_t dev_id,
70699a2dd95SBruce Richardson const struct rte_comp_xform *xform,
70799a2dd95SBruce Richardson void **stream)
70899a2dd95SBruce Richardson {
70999a2dd95SBruce Richardson struct rte_compressdev *dev;
71099a2dd95SBruce Richardson int ret;
71199a2dd95SBruce Richardson
71299a2dd95SBruce Richardson dev = rte_compressdev_get_dev(dev_id);
71399a2dd95SBruce Richardson
71499a2dd95SBruce Richardson if (xform == NULL || dev == NULL || stream == NULL)
71599a2dd95SBruce Richardson return -EINVAL;
71699a2dd95SBruce Richardson
71799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stream_create, -ENOTSUP);
71899a2dd95SBruce Richardson ret = (*dev->dev_ops->stream_create)(dev, xform, stream);
71999a2dd95SBruce Richardson if (ret < 0) {
72099a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
72199a2dd95SBruce Richardson "dev_id %d failed to create stream: err=%d",
72299a2dd95SBruce Richardson dev_id, ret);
72399a2dd95SBruce Richardson return ret;
72499a2dd95SBruce Richardson };
72599a2dd95SBruce Richardson
72699a2dd95SBruce Richardson return 0;
72799a2dd95SBruce Richardson }
72899a2dd95SBruce Richardson
72999a2dd95SBruce Richardson
73099a2dd95SBruce Richardson int
rte_compressdev_stream_free(uint8_t dev_id,void * stream)73199a2dd95SBruce Richardson rte_compressdev_stream_free(uint8_t dev_id, void *stream)
73299a2dd95SBruce Richardson {
73399a2dd95SBruce Richardson struct rte_compressdev *dev;
73499a2dd95SBruce Richardson int ret;
73599a2dd95SBruce Richardson
73699a2dd95SBruce Richardson dev = rte_compressdev_get_dev(dev_id);
73799a2dd95SBruce Richardson
73899a2dd95SBruce Richardson if (dev == NULL || stream == NULL)
73999a2dd95SBruce Richardson return -EINVAL;
74099a2dd95SBruce Richardson
74199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stream_free, -ENOTSUP);
74299a2dd95SBruce Richardson ret = dev->dev_ops->stream_free(dev, stream);
74399a2dd95SBruce Richardson if (ret < 0) {
74499a2dd95SBruce Richardson COMPRESSDEV_LOG(ERR,
74599a2dd95SBruce Richardson "dev_id %d failed to free stream: err=%d",
74699a2dd95SBruce Richardson dev_id, ret);
74799a2dd95SBruce Richardson return ret;
74899a2dd95SBruce Richardson };
74999a2dd95SBruce Richardson
75099a2dd95SBruce Richardson return 0;
75199a2dd95SBruce Richardson }
75299a2dd95SBruce Richardson
75399a2dd95SBruce Richardson const char *
rte_compressdev_name_get(uint8_t dev_id)75499a2dd95SBruce Richardson rte_compressdev_name_get(uint8_t dev_id)
75599a2dd95SBruce Richardson {
75699a2dd95SBruce Richardson struct rte_compressdev *dev = rte_compressdev_get_dev(dev_id);
75799a2dd95SBruce Richardson
75899a2dd95SBruce Richardson if (dev == NULL)
75999a2dd95SBruce Richardson return NULL;
76099a2dd95SBruce Richardson
76199a2dd95SBruce Richardson return dev->data->name;
76299a2dd95SBruce Richardson }
76399a2dd95SBruce Richardson
764*eeded204SDavid Marchand RTE_LOG_REGISTER_DEFAULT(compressdev_logtype, NOTICE);
765