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