xref: /dpdk/lib/compressdev/rte_compressdev.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2017-2018 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_COMPRESSDEV_H_
699a2dd95SBruce Richardson #define _RTE_COMPRESSDEV_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file rte_compressdev.h
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * RTE Compression Device APIs.
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * Defines comp device APIs for the provisioning of compression operations.
1499a2dd95SBruce Richardson  */
1599a2dd95SBruce Richardson 
16*719834a6SMattias Rönnblom #include "rte_comp.h"
17*719834a6SMattias Rönnblom 
1899a2dd95SBruce Richardson #ifdef __cplusplus
1999a2dd95SBruce Richardson extern "C" {
2099a2dd95SBruce Richardson #endif
2199a2dd95SBruce Richardson 
2299a2dd95SBruce Richardson /**
2399a2dd95SBruce Richardson  * Parameter log base 2 range description.
2499a2dd95SBruce Richardson  * Final value will be 2^value.
2599a2dd95SBruce Richardson  */
2699a2dd95SBruce Richardson struct rte_param_log2_range {
2799a2dd95SBruce Richardson 	uint8_t min;	/**< Minimum log2 value */
2899a2dd95SBruce Richardson 	uint8_t max;	/**< Maximum log2 value */
2999a2dd95SBruce Richardson 	uint8_t increment;
3099a2dd95SBruce Richardson 	/**< If a range of sizes are supported,
3199a2dd95SBruce Richardson 	 * this parameter is used to indicate
3299a2dd95SBruce Richardson 	 * increments in base 2 log byte value
3399a2dd95SBruce Richardson 	 * that are supported between the minimum and maximum
3499a2dd95SBruce Richardson 	 */
3599a2dd95SBruce Richardson };
3699a2dd95SBruce Richardson 
3799a2dd95SBruce Richardson /** Structure used to capture a capability of a comp device */
3899a2dd95SBruce Richardson struct rte_compressdev_capabilities {
3999a2dd95SBruce Richardson 	enum rte_comp_algorithm algo;
4099a2dd95SBruce Richardson 	/* Compression algorithm */
4199a2dd95SBruce Richardson 	uint64_t comp_feature_flags;
4299a2dd95SBruce Richardson 	/**< Bitmask of flags for compression service features */
4399a2dd95SBruce Richardson 	struct rte_param_log2_range window_size;
4499a2dd95SBruce Richardson 	/**< Window size range in base two log byte values */
4599a2dd95SBruce Richardson };
4699a2dd95SBruce Richardson 
4799a2dd95SBruce Richardson /** Macro used at end of comp PMD list */
4899a2dd95SBruce Richardson #define RTE_COMP_END_OF_CAPABILITIES_LIST() \
4999a2dd95SBruce Richardson 	{ RTE_COMP_ALGO_UNSPECIFIED }
5099a2dd95SBruce Richardson 
5199a2dd95SBruce Richardson const struct rte_compressdev_capabilities *
5299a2dd95SBruce Richardson rte_compressdev_capability_get(uint8_t dev_id,
5399a2dd95SBruce Richardson 			enum rte_comp_algorithm algo);
5499a2dd95SBruce Richardson 
5599a2dd95SBruce Richardson /**
5699a2dd95SBruce Richardson  * compression device supported feature flags
5799a2dd95SBruce Richardson  *
5899a2dd95SBruce Richardson  * @note New features flags should be added to the end of the list
5999a2dd95SBruce Richardson  *
6099a2dd95SBruce Richardson  * Keep these flags synchronised with rte_compressdev_get_feature_name()
6199a2dd95SBruce Richardson  */
6299a2dd95SBruce Richardson #define	RTE_COMPDEV_FF_HW_ACCELERATED		(1ULL << 0)
6399a2dd95SBruce Richardson /**< Operations are off-loaded to an external hardware accelerator */
6499a2dd95SBruce Richardson #define	RTE_COMPDEV_FF_CPU_SSE			(1ULL << 1)
6599a2dd95SBruce Richardson /**< Utilises CPU SIMD SSE instructions */
6699a2dd95SBruce Richardson #define	RTE_COMPDEV_FF_CPU_AVX			(1ULL << 2)
6799a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX instructions */
6899a2dd95SBruce Richardson #define	RTE_COMPDEV_FF_CPU_AVX2			(1ULL << 3)
6999a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX2 instructions */
7099a2dd95SBruce Richardson #define	RTE_COMPDEV_FF_CPU_AVX512		(1ULL << 4)
7199a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX512 instructions */
7299a2dd95SBruce Richardson #define	RTE_COMPDEV_FF_CPU_NEON			(1ULL << 5)
7399a2dd95SBruce Richardson /**< Utilises CPU NEON instructions */
7499a2dd95SBruce Richardson #define RTE_COMPDEV_FF_OP_DONE_IN_DEQUEUE	(1ULL << 6)
7599a2dd95SBruce Richardson /**< A PMD should set this if the bulk of the
7699a2dd95SBruce Richardson  * processing is done during the dequeue. It should leave it
7799a2dd95SBruce Richardson  * cleared if the processing is done during the enqueue (default).
7899a2dd95SBruce Richardson  * Applications can use this as a hint for tuning.
7999a2dd95SBruce Richardson  */
8099a2dd95SBruce Richardson 
8199a2dd95SBruce Richardson /**
8299a2dd95SBruce Richardson  * Get the name of a compress device feature flag.
8399a2dd95SBruce Richardson  *
8499a2dd95SBruce Richardson  * @param flag
8599a2dd95SBruce Richardson  *   The mask describing the flag
8699a2dd95SBruce Richardson  *
8799a2dd95SBruce Richardson  * @return
8899a2dd95SBruce Richardson  *   The name of this flag, or NULL if it's not a valid feature flag.
8999a2dd95SBruce Richardson  */
9099a2dd95SBruce Richardson const char *
9199a2dd95SBruce Richardson rte_compressdev_get_feature_name(uint64_t flag);
9299a2dd95SBruce Richardson 
9399a2dd95SBruce Richardson /**  comp device information */
9499a2dd95SBruce Richardson struct rte_compressdev_info {
9599a2dd95SBruce Richardson 	const char *driver_name;		/**< Driver name. */
9699a2dd95SBruce Richardson 	uint64_t feature_flags;			/**< Feature flags */
9799a2dd95SBruce Richardson 	const struct rte_compressdev_capabilities *capabilities;
9899a2dd95SBruce Richardson 	/**< Array of devices supported capabilities */
9999a2dd95SBruce Richardson 	uint16_t max_nb_queue_pairs;
10099a2dd95SBruce Richardson 	/**< Maximum number of queues pairs supported by device.
10199a2dd95SBruce Richardson 	 * (If 0, there is no limit in maximum number of queue pairs)
10299a2dd95SBruce Richardson 	 */
10399a2dd95SBruce Richardson };
10499a2dd95SBruce Richardson 
10599a2dd95SBruce Richardson /** comp device statistics */
10699a2dd95SBruce Richardson struct rte_compressdev_stats {
10799a2dd95SBruce Richardson 	uint64_t enqueued_count;
10899a2dd95SBruce Richardson 	/**< Count of all operations enqueued */
10999a2dd95SBruce Richardson 	uint64_t dequeued_count;
11099a2dd95SBruce Richardson 	/**< Count of all operations dequeued */
11199a2dd95SBruce Richardson 
11299a2dd95SBruce Richardson 	uint64_t enqueue_err_count;
11399a2dd95SBruce Richardson 	/**< Total error count on operations enqueued */
11499a2dd95SBruce Richardson 	uint64_t dequeue_err_count;
11599a2dd95SBruce Richardson 	/**< Total error count on operations dequeued */
11699a2dd95SBruce Richardson };
11799a2dd95SBruce Richardson 
11899a2dd95SBruce Richardson 
11999a2dd95SBruce Richardson /**
12099a2dd95SBruce Richardson  * Get the device identifier for the named compress device.
12199a2dd95SBruce Richardson  *
12299a2dd95SBruce Richardson  * @param name
12399a2dd95SBruce Richardson  *   Device name to select the device structure
12499a2dd95SBruce Richardson  * @return
12599a2dd95SBruce Richardson  *   - Returns compress device identifier on success.
12699a2dd95SBruce Richardson  *   - Return -1 on failure to find named compress device.
12799a2dd95SBruce Richardson  */
12899a2dd95SBruce Richardson int
12999a2dd95SBruce Richardson rte_compressdev_get_dev_id(const char *name);
13099a2dd95SBruce Richardson 
13199a2dd95SBruce Richardson /**
13299a2dd95SBruce Richardson  * Get the compress device name given a device identifier.
13399a2dd95SBruce Richardson  *
13499a2dd95SBruce Richardson  * @param dev_id
13599a2dd95SBruce Richardson  *   Compress device identifier
13699a2dd95SBruce Richardson  * @return
13799a2dd95SBruce Richardson  *   - Returns compress device name.
13899a2dd95SBruce Richardson  *   - Returns NULL if compress device is not present.
13999a2dd95SBruce Richardson  */
14099a2dd95SBruce Richardson const char *
14199a2dd95SBruce Richardson rte_compressdev_name_get(uint8_t dev_id);
14299a2dd95SBruce Richardson 
14399a2dd95SBruce Richardson /**
14499a2dd95SBruce Richardson  * Get the total number of compress devices that have been successfully
14599a2dd95SBruce Richardson  * initialised.
14699a2dd95SBruce Richardson  *
14799a2dd95SBruce Richardson  * @return
14899a2dd95SBruce Richardson  *   - The total number of usable compress devices.
14999a2dd95SBruce Richardson  */
15099a2dd95SBruce Richardson uint8_t
15199a2dd95SBruce Richardson rte_compressdev_count(void);
15299a2dd95SBruce Richardson 
15399a2dd95SBruce Richardson /**
15499a2dd95SBruce Richardson  * Get number and identifiers of attached comp devices that
15599a2dd95SBruce Richardson  * use the same compress driver.
15699a2dd95SBruce Richardson  *
15799a2dd95SBruce Richardson  * @param driver_name
15899a2dd95SBruce Richardson  *   Driver name
15999a2dd95SBruce Richardson  * @param devices
16099a2dd95SBruce Richardson  *   Output devices identifiers
16199a2dd95SBruce Richardson  * @param nb_devices
16299a2dd95SBruce Richardson  *   Maximal number of devices
16399a2dd95SBruce Richardson  *
16499a2dd95SBruce Richardson  * @return
16599a2dd95SBruce Richardson  *   Returns number of attached compress devices.
16699a2dd95SBruce Richardson  */
16799a2dd95SBruce Richardson uint8_t
16899a2dd95SBruce Richardson rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
16999a2dd95SBruce Richardson 		uint8_t nb_devices);
17099a2dd95SBruce Richardson 
17199a2dd95SBruce Richardson /*
17299a2dd95SBruce Richardson  * Return the NUMA socket to which a device is connected.
17399a2dd95SBruce Richardson  *
17499a2dd95SBruce Richardson  * @param dev_id
17599a2dd95SBruce Richardson  *   Compress device identifier
17699a2dd95SBruce Richardson  * @return
17799a2dd95SBruce Richardson  *   The NUMA socket id to which the device is connected or
17899a2dd95SBruce Richardson  *   a default of zero if the socket could not be determined.
17999a2dd95SBruce Richardson  *   -1 if returned is the dev_id value is out of range.
18099a2dd95SBruce Richardson  */
18199a2dd95SBruce Richardson int
18299a2dd95SBruce Richardson rte_compressdev_socket_id(uint8_t dev_id);
18399a2dd95SBruce Richardson 
18499a2dd95SBruce Richardson /** Compress device configuration structure */
18599a2dd95SBruce Richardson struct rte_compressdev_config {
18699a2dd95SBruce Richardson 	int socket_id;
18799a2dd95SBruce Richardson 	/**< Socket on which to allocate resources */
18899a2dd95SBruce Richardson 	uint16_t nb_queue_pairs;
18999a2dd95SBruce Richardson 	/**< Total number of queue pairs to configure on a device */
19099a2dd95SBruce Richardson 	uint16_t max_nb_priv_xforms;
19199a2dd95SBruce Richardson 	/**< Max number of private_xforms which will be created on the device */
19299a2dd95SBruce Richardson 	uint16_t max_nb_streams;
19399a2dd95SBruce Richardson 	/**< Max number of streams which will be created on the device */
19499a2dd95SBruce Richardson };
19599a2dd95SBruce Richardson 
19699a2dd95SBruce Richardson /**
19799a2dd95SBruce Richardson  * Configure a device.
19899a2dd95SBruce Richardson  *
19999a2dd95SBruce Richardson  * This function must be invoked first before any other function in the
20099a2dd95SBruce Richardson  * API. This function can also be re-invoked when a device is in the
20199a2dd95SBruce Richardson  * stopped state.
20299a2dd95SBruce Richardson  *
20399a2dd95SBruce Richardson  * @param dev_id
20499a2dd95SBruce Richardson  *   Compress device identifier
20599a2dd95SBruce Richardson  * @param config
20699a2dd95SBruce Richardson  *   The compress device configuration
20799a2dd95SBruce Richardson  * @return
20899a2dd95SBruce Richardson  *   - 0: Success, device configured.
20999a2dd95SBruce Richardson  *   - <0: Error code returned by the driver configuration function.
21099a2dd95SBruce Richardson  */
21199a2dd95SBruce Richardson int
21299a2dd95SBruce Richardson rte_compressdev_configure(uint8_t dev_id,
21399a2dd95SBruce Richardson 			struct rte_compressdev_config *config);
21499a2dd95SBruce Richardson 
21599a2dd95SBruce Richardson /**
21699a2dd95SBruce Richardson  * Start a device.
21799a2dd95SBruce Richardson  *
21899a2dd95SBruce Richardson  * The device start step is called after configuring the device and setting up
21999a2dd95SBruce Richardson  * its queue pairs.
22099a2dd95SBruce Richardson  * On success, data-path functions exported by the API (enqueue/dequeue, etc)
22199a2dd95SBruce Richardson  * can be invoked.
22299a2dd95SBruce Richardson  *
22399a2dd95SBruce Richardson  * @param dev_id
22499a2dd95SBruce Richardson  *   Compress device identifier
22599a2dd95SBruce Richardson  * @return
22699a2dd95SBruce Richardson  *   - 0: Success, device started.
22799a2dd95SBruce Richardson  *   - <0: Error code of the driver device start function.
22899a2dd95SBruce Richardson  */
22999a2dd95SBruce Richardson int
23099a2dd95SBruce Richardson rte_compressdev_start(uint8_t dev_id);
23199a2dd95SBruce Richardson 
23299a2dd95SBruce Richardson /**
23399a2dd95SBruce Richardson  * Stop a device. The device can be restarted with a call to
23499a2dd95SBruce Richardson  * rte_compressdev_start()
23599a2dd95SBruce Richardson  *
23699a2dd95SBruce Richardson  * @param dev_id
23799a2dd95SBruce Richardson  *   Compress device identifier
23899a2dd95SBruce Richardson  */
23999a2dd95SBruce Richardson void
24099a2dd95SBruce Richardson rte_compressdev_stop(uint8_t dev_id);
24199a2dd95SBruce Richardson 
24299a2dd95SBruce Richardson /**
24399a2dd95SBruce Richardson  * Close an device.
24499a2dd95SBruce Richardson  * The memory allocated in the device gets freed.
24599a2dd95SBruce Richardson  * After calling this function, in order to use
24699a2dd95SBruce Richardson  * the device again, it is required to
24799a2dd95SBruce Richardson  * configure the device again.
24899a2dd95SBruce Richardson  *
24999a2dd95SBruce Richardson  * @param dev_id
25099a2dd95SBruce Richardson  *   Compress device identifier
25199a2dd95SBruce Richardson  *
25299a2dd95SBruce Richardson  * @return
25399a2dd95SBruce Richardson  *  - 0 on successfully closing device
25499a2dd95SBruce Richardson  *  - <0 on failure to close device
25599a2dd95SBruce Richardson  */
25699a2dd95SBruce Richardson int
25799a2dd95SBruce Richardson rte_compressdev_close(uint8_t dev_id);
25899a2dd95SBruce Richardson 
25999a2dd95SBruce Richardson /**
26099a2dd95SBruce Richardson  * Allocate and set up a receive queue pair for a device.
26199a2dd95SBruce Richardson  * This should only be called when the device is stopped.
26299a2dd95SBruce Richardson  *
26399a2dd95SBruce Richardson  *
26499a2dd95SBruce Richardson  * @param dev_id
26599a2dd95SBruce Richardson  *   Compress device identifier
26699a2dd95SBruce Richardson  * @param queue_pair_id
26799a2dd95SBruce Richardson  *   The index of the queue pairs to set up. The
26899a2dd95SBruce Richardson  *   value must be in the range [0, nb_queue_pair - 1]
26999a2dd95SBruce Richardson  *   previously supplied to rte_compressdev_configure()
27099a2dd95SBruce Richardson  * @param max_inflight_ops
27199a2dd95SBruce Richardson  *   Max number of ops which the qp will have to
27299a2dd95SBruce Richardson  *   accommodate simultaneously
27399a2dd95SBruce Richardson  * @param socket_id
27499a2dd95SBruce Richardson  *   The *socket_id* argument is the socket identifier
27599a2dd95SBruce Richardson  *   in case of NUMA. The value can be *SOCKET_ID_ANY*
27699a2dd95SBruce Richardson  *   if there is no NUMA constraint for the DMA memory
27799a2dd95SBruce Richardson  *   allocated for the receive queue pair
27899a2dd95SBruce Richardson  * @return
27999a2dd95SBruce Richardson  *   - 0: Success, queue pair correctly set up.
28099a2dd95SBruce Richardson  *   - <0: Queue pair configuration failed
28199a2dd95SBruce Richardson  */
28299a2dd95SBruce Richardson int
28399a2dd95SBruce Richardson rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
28499a2dd95SBruce Richardson 		uint32_t max_inflight_ops, int socket_id);
28599a2dd95SBruce Richardson 
28699a2dd95SBruce Richardson /**
28799a2dd95SBruce Richardson  * Get the number of queue pairs on a specific comp device
28899a2dd95SBruce Richardson  *
28999a2dd95SBruce Richardson  * @param dev_id
29099a2dd95SBruce Richardson  *   Compress device identifier
29199a2dd95SBruce Richardson  * @return
29299a2dd95SBruce Richardson  *   - The number of configured queue pairs.
29399a2dd95SBruce Richardson  */
29499a2dd95SBruce Richardson uint16_t
29599a2dd95SBruce Richardson rte_compressdev_queue_pair_count(uint8_t dev_id);
29699a2dd95SBruce Richardson 
29799a2dd95SBruce Richardson 
29899a2dd95SBruce Richardson /**
29999a2dd95SBruce Richardson  * Retrieve the general I/O statistics of a device.
30099a2dd95SBruce Richardson  *
30199a2dd95SBruce Richardson  * @param dev_id
30299a2dd95SBruce Richardson  *   The identifier of the device
30399a2dd95SBruce Richardson  * @param stats
30499a2dd95SBruce Richardson  *   A pointer to a structure of type
30599a2dd95SBruce Richardson  *   *rte_compressdev_stats* to be filled with the
30699a2dd95SBruce Richardson  *   values of device counters
30799a2dd95SBruce Richardson  * @return
30899a2dd95SBruce Richardson  *   - Zero if successful.
30999a2dd95SBruce Richardson  *   - Non-zero otherwise.
31099a2dd95SBruce Richardson  */
31199a2dd95SBruce Richardson int
31299a2dd95SBruce Richardson rte_compressdev_stats_get(uint8_t dev_id, struct rte_compressdev_stats *stats);
31399a2dd95SBruce Richardson 
31499a2dd95SBruce Richardson /**
31599a2dd95SBruce Richardson  * Reset the general I/O statistics of a device.
31699a2dd95SBruce Richardson  *
31799a2dd95SBruce Richardson  * @param dev_id
31899a2dd95SBruce Richardson  *   The identifier of the device.
31999a2dd95SBruce Richardson  */
32099a2dd95SBruce Richardson void
32199a2dd95SBruce Richardson rte_compressdev_stats_reset(uint8_t dev_id);
32299a2dd95SBruce Richardson 
32399a2dd95SBruce Richardson /**
32499a2dd95SBruce Richardson  * Retrieve the contextual information of a device.
32599a2dd95SBruce Richardson  *
32699a2dd95SBruce Richardson  * @param dev_id
32799a2dd95SBruce Richardson  *   Compress device identifier
32899a2dd95SBruce Richardson  * @param dev_info
32999a2dd95SBruce Richardson  *   A pointer to a structure of type *rte_compressdev_info*
33099a2dd95SBruce Richardson  *   to be filled with the contextual information of the device
33199a2dd95SBruce Richardson  *
33299a2dd95SBruce Richardson  * @note The capabilities field of dev_info is set to point to the first
33399a2dd95SBruce Richardson  * element of an array of struct rte_compressdev_capabilities.
33499a2dd95SBruce Richardson  * The element after the last valid element has it's op field set to
33533b84a2eSMichael Baum  * RTE_COMP_ALGO_UNSPECIFIED.
33699a2dd95SBruce Richardson  */
33799a2dd95SBruce Richardson void
33899a2dd95SBruce Richardson rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info);
33999a2dd95SBruce Richardson 
34099a2dd95SBruce Richardson /**
34199a2dd95SBruce Richardson  *
34299a2dd95SBruce Richardson  * Dequeue a burst of processed compression operations from a queue on the comp
34399a2dd95SBruce Richardson  * device. The dequeued operation are stored in *rte_comp_op* structures
34499a2dd95SBruce Richardson  * whose pointers are supplied in the *ops* array.
34599a2dd95SBruce Richardson  *
34699a2dd95SBruce Richardson  * The rte_compressdev_dequeue_burst() function returns the number of ops
34799a2dd95SBruce Richardson  * actually dequeued, which is the number of *rte_comp_op* data structures
34899a2dd95SBruce Richardson  * effectively supplied into the *ops* array.
34999a2dd95SBruce Richardson  *
35099a2dd95SBruce Richardson  * A return value equal to *nb_ops* indicates that the queue contained
35199a2dd95SBruce Richardson  * at least *nb_ops* operations, and this is likely to signify that other
35299a2dd95SBruce Richardson  * processed operations remain in the devices output queue. Applications
35399a2dd95SBruce Richardson  * implementing a "retrieve as many processed operations as possible" policy
35499a2dd95SBruce Richardson  * can check this specific case and keep invoking the
35599a2dd95SBruce Richardson  * rte_compressdev_dequeue_burst() function until a value less than
35699a2dd95SBruce Richardson  * *nb_ops* is returned.
35799a2dd95SBruce Richardson  *
35899a2dd95SBruce Richardson  * The rte_compressdev_dequeue_burst() function does not provide any error
35999a2dd95SBruce Richardson  * notification to avoid the corresponding overhead.
36099a2dd95SBruce Richardson  *
36199a2dd95SBruce Richardson  * @note: operation ordering is not maintained within the queue pair.
36299a2dd95SBruce Richardson  *
36399a2dd95SBruce Richardson  * @note: In case op status = OUT_OF_SPACE_TERMINATED, op.consumed=0 and the
36499a2dd95SBruce Richardson  * op must be resubmitted with the same input data and a larger output buffer.
36599a2dd95SBruce Richardson  * op.produced is usually 0, but in decompression cases a PMD may return > 0
36699a2dd95SBruce Richardson  * and the application may find it useful to inspect that data.
36799a2dd95SBruce Richardson  * This status is only returned on STATELESS ops.
36899a2dd95SBruce Richardson  *
36999a2dd95SBruce Richardson  * @note: In case op status = OUT_OF_SPACE_RECOVERABLE, op.produced can be used
37099a2dd95SBruce Richardson  * and next op in stream should continue on from op.consumed+1 with a fresh
37199a2dd95SBruce Richardson  * output buffer.
37299a2dd95SBruce Richardson  * Consumed=0, produced=0 is an unusual but allowed case. There may be useful
37399a2dd95SBruce Richardson  * state/history stored in the PMD, even though no output was produced yet.
37499a2dd95SBruce Richardson  *
37599a2dd95SBruce Richardson  *
37699a2dd95SBruce Richardson  * @param dev_id
37799a2dd95SBruce Richardson  *   Compress device identifier
37899a2dd95SBruce Richardson  * @param qp_id
37999a2dd95SBruce Richardson  *   The index of the queue pair from which to retrieve
38099a2dd95SBruce Richardson  *   processed operations. The value must be in the range
38199a2dd95SBruce Richardson  *   [0, nb_queue_pair - 1] previously supplied to
38299a2dd95SBruce Richardson  *   rte_compressdev_configure()
38399a2dd95SBruce Richardson  * @param ops
38499a2dd95SBruce Richardson  *   The address of an array of pointers to
38599a2dd95SBruce Richardson  *   *rte_comp_op* structures that must be
38699a2dd95SBruce Richardson  *   large enough to store *nb_ops* pointers in it
38799a2dd95SBruce Richardson  * @param nb_ops
38899a2dd95SBruce Richardson  *   The maximum number of operations to dequeue
38999a2dd95SBruce Richardson  * @return
39099a2dd95SBruce Richardson  *   - The number of operations actually dequeued, which is the number
39199a2dd95SBruce Richardson  *   of pointers to *rte_comp_op* structures effectively supplied to the
39299a2dd95SBruce Richardson  *   *ops* array.
39399a2dd95SBruce Richardson  */
39499a2dd95SBruce Richardson uint16_t
39599a2dd95SBruce Richardson rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
39699a2dd95SBruce Richardson 		struct rte_comp_op **ops, uint16_t nb_ops);
39799a2dd95SBruce Richardson 
39899a2dd95SBruce Richardson /**
39999a2dd95SBruce Richardson  * Enqueue a burst of operations for processing on a compression device.
40099a2dd95SBruce Richardson  *
40199a2dd95SBruce Richardson  * The rte_compressdev_enqueue_burst() function is invoked to place
40299a2dd95SBruce Richardson  * comp operations on the queue *qp_id* of the device designated by
40399a2dd95SBruce Richardson  * its *dev_id*.
40499a2dd95SBruce Richardson  *
40599a2dd95SBruce Richardson  * The *nb_ops* parameter is the number of operations to process which are
40699a2dd95SBruce Richardson  * supplied in the *ops* array of *rte_comp_op* structures.
40799a2dd95SBruce Richardson  *
40899a2dd95SBruce Richardson  * The rte_compressdev_enqueue_burst() function returns the number of
40999a2dd95SBruce Richardson  * operations it actually enqueued for processing. A return value equal to
41099a2dd95SBruce Richardson  * *nb_ops* means that all packets have been enqueued.
41199a2dd95SBruce Richardson  *
41299a2dd95SBruce Richardson  * @note All compression operations are Out-of-place (OOP) operations,
41399a2dd95SBruce Richardson  * as the size of the output data is different to the size of the input data.
41499a2dd95SBruce Richardson  *
41599a2dd95SBruce Richardson  * @note The rte_comp_op contains both input and output parameters and is the
41699a2dd95SBruce Richardson  * vehicle for the application to pass data into and out of the PMD. While an
41799a2dd95SBruce Richardson  * op is inflight, i.e. once it has been enqueued, the private_xform or stream
41899a2dd95SBruce Richardson  * attached to it and any mbufs or memory referenced by it should not be altered
41999a2dd95SBruce Richardson  * or freed by the application. The PMD may use or change some of this data at
42099a2dd95SBruce Richardson  * any time until it has been returned in a dequeue operation.
42199a2dd95SBruce Richardson  *
42299a2dd95SBruce Richardson  * @note The flush flag only applies to operations which return SUCCESS.
42399a2dd95SBruce Richardson  * In OUT_OF_SPACE cases whether STATEFUL or STATELESS, data in dest buffer
42499a2dd95SBruce Richardson  * is as if flush flag was FLUSH_NONE.
42599a2dd95SBruce Richardson  * @note flush flag only applies in compression direction. It has no meaning
42699a2dd95SBruce Richardson  * for decompression.
42799a2dd95SBruce Richardson  * @note: operation ordering is not maintained within the queue pair.
42899a2dd95SBruce Richardson  *
42999a2dd95SBruce Richardson  * @param dev_id
43099a2dd95SBruce Richardson  *   Compress device identifier
43199a2dd95SBruce Richardson  * @param qp_id
43299a2dd95SBruce Richardson  *   The index of the queue pair on which operations
43399a2dd95SBruce Richardson  *   are to be enqueued for processing. The value
43499a2dd95SBruce Richardson  *   must be in the range [0, nb_queue_pairs - 1]
43599a2dd95SBruce Richardson  *   previously supplied to *rte_compressdev_configure*
43699a2dd95SBruce Richardson  * @param ops
43799a2dd95SBruce Richardson  *   The address of an array of *nb_ops* pointers
43899a2dd95SBruce Richardson  *   to *rte_comp_op* structures which contain
43999a2dd95SBruce Richardson  *   the operations to be processed
44099a2dd95SBruce Richardson  * @param nb_ops
44199a2dd95SBruce Richardson  *   The number of operations to process
44299a2dd95SBruce Richardson  * @return
44399a2dd95SBruce Richardson  *   The number of operations actually enqueued on the device. The return
44499a2dd95SBruce Richardson  *   value can be less than the value of the *nb_ops* parameter when the
44599a2dd95SBruce Richardson  *   comp devices queue is full or if invalid parameters are specified in
44699a2dd95SBruce Richardson  *   a *rte_comp_op*.
44799a2dd95SBruce Richardson  */
44899a2dd95SBruce Richardson uint16_t
44999a2dd95SBruce Richardson rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
45099a2dd95SBruce Richardson 		struct rte_comp_op **ops, uint16_t nb_ops);
45199a2dd95SBruce Richardson 
45299a2dd95SBruce Richardson /**
45399a2dd95SBruce Richardson  * This should alloc a stream from the device's mempool and initialise it.
45499a2dd95SBruce Richardson  * The application should call this API when setting up for the stateful
45599a2dd95SBruce Richardson  * processing of a set of data on a device. The API can be called multiple
45699a2dd95SBruce Richardson  * times to set up a stream for each data set. The handle returned is only for
45799a2dd95SBruce Richardson  * use with ops of op_type STATEFUL and must be passed to the PMD
45899a2dd95SBruce Richardson  * with every op in the data stream
45999a2dd95SBruce Richardson  *
46099a2dd95SBruce Richardson  * @param dev_id
46199a2dd95SBruce Richardson  *   Compress device identifier
46299a2dd95SBruce Richardson  * @param xform
46399a2dd95SBruce Richardson  *   xform data
46499a2dd95SBruce Richardson  * @param stream
46599a2dd95SBruce Richardson  *   Pointer to where PMD's private stream handle should be stored
46699a2dd95SBruce Richardson  *
46799a2dd95SBruce Richardson  * @return
46899a2dd95SBruce Richardson  *  - 0 if successful and valid stream handle
46999a2dd95SBruce Richardson  *  - <0 in error cases
47099a2dd95SBruce Richardson  *  - Returns -EINVAL if input parameters are invalid.
47199a2dd95SBruce Richardson  *  - Returns -ENOTSUP if comp device does not support STATEFUL operations.
47299a2dd95SBruce Richardson  *  - Returns -ENOTSUP if comp device does not support the comp transform.
47399a2dd95SBruce Richardson  *  - Returns -ENOMEM if the private stream could not be allocated.
47499a2dd95SBruce Richardson  */
47599a2dd95SBruce Richardson int
47699a2dd95SBruce Richardson rte_compressdev_stream_create(uint8_t dev_id,
47799a2dd95SBruce Richardson 		const struct rte_comp_xform *xform,
47899a2dd95SBruce Richardson 		void **stream);
47999a2dd95SBruce Richardson 
48099a2dd95SBruce Richardson /**
48199a2dd95SBruce Richardson  * This should clear the stream and return it to the device's mempool.
48299a2dd95SBruce Richardson  *
48399a2dd95SBruce Richardson  * @param dev_id
48499a2dd95SBruce Richardson  *   Compress device identifier
48599a2dd95SBruce Richardson  *
48699a2dd95SBruce Richardson  * @param stream
48799a2dd95SBruce Richardson  *   PMD's private stream data
48899a2dd95SBruce Richardson  *
48999a2dd95SBruce Richardson  * @return
49099a2dd95SBruce Richardson  *  - 0 if successful
49199a2dd95SBruce Richardson  *  - <0 in error cases
49299a2dd95SBruce Richardson  *  - Returns -EINVAL if input parameters are invalid.
49399a2dd95SBruce Richardson  *  - Returns -ENOTSUP if comp device does not support STATEFUL operations.
49499a2dd95SBruce Richardson  *  - Returns -EBUSY if can't free stream as there are inflight operations
49599a2dd95SBruce Richardson  */
49699a2dd95SBruce Richardson int
49799a2dd95SBruce Richardson rte_compressdev_stream_free(uint8_t dev_id, void *stream);
49899a2dd95SBruce Richardson 
49999a2dd95SBruce Richardson /**
50099a2dd95SBruce Richardson  * This should alloc a private_xform from the device's mempool and initialise
50199a2dd95SBruce Richardson  * it. The application should call this API when setting up for stateless
50299a2dd95SBruce Richardson  * processing on a device. If it returns non-shareable, then the appl cannot
50399a2dd95SBruce Richardson  * share this handle with multiple in-flight ops and should call this API again
50499a2dd95SBruce Richardson  * to get a separate handle for every in-flight op.
50599a2dd95SBruce Richardson  * The handle returned is only valid for use with ops of op_type STATELESS.
50699a2dd95SBruce Richardson  *
50799a2dd95SBruce Richardson  * @param dev_id
50899a2dd95SBruce Richardson  *   Compress device identifier
50999a2dd95SBruce Richardson  * @param xform
51099a2dd95SBruce Richardson  *   xform data
51199a2dd95SBruce Richardson  * @param private_xform
51299a2dd95SBruce Richardson  *   Pointer to where PMD's private_xform handle should be stored
51399a2dd95SBruce Richardson  *
51499a2dd95SBruce Richardson  * @return
51599a2dd95SBruce Richardson  *  - if successful returns 0
51699a2dd95SBruce Richardson  *    and valid private_xform handle
51799a2dd95SBruce Richardson  *  - <0 in error cases
51899a2dd95SBruce Richardson  *  - Returns -EINVAL if input parameters are invalid.
51999a2dd95SBruce Richardson  *  - Returns -ENOTSUP if comp device does not support the comp transform.
52099a2dd95SBruce Richardson  *  - Returns -ENOMEM if the private_xform could not be allocated.
52199a2dd95SBruce Richardson  */
52299a2dd95SBruce Richardson int
52399a2dd95SBruce Richardson rte_compressdev_private_xform_create(uint8_t dev_id,
52499a2dd95SBruce Richardson 		const struct rte_comp_xform *xform,
52599a2dd95SBruce Richardson 		void **private_xform);
52699a2dd95SBruce Richardson 
52799a2dd95SBruce Richardson /**
52899a2dd95SBruce Richardson  * This should clear the private_xform and return it to the device's mempool.
52999a2dd95SBruce Richardson  * It is the application's responsibility to ensure that private_xform data
53099a2dd95SBruce Richardson  * is not cleared while there are still in-flight operations using it.
53199a2dd95SBruce Richardson  *
53299a2dd95SBruce Richardson  * @param dev_id
53399a2dd95SBruce Richardson  *   Compress device identifier
53499a2dd95SBruce Richardson  *
53599a2dd95SBruce Richardson  * @param private_xform
53699a2dd95SBruce Richardson  *   PMD's private_xform data
53799a2dd95SBruce Richardson  *
53899a2dd95SBruce Richardson  * @return
53999a2dd95SBruce Richardson  *  - 0 if successful
54099a2dd95SBruce Richardson  *  - <0 in error cases
54199a2dd95SBruce Richardson  *  - Returns -EINVAL if input parameters are invalid.
54299a2dd95SBruce Richardson  */
54399a2dd95SBruce Richardson int
54499a2dd95SBruce Richardson rte_compressdev_private_xform_free(uint8_t dev_id, void *private_xform);
54599a2dd95SBruce Richardson 
54699a2dd95SBruce Richardson #ifdef __cplusplus
54799a2dd95SBruce Richardson }
54899a2dd95SBruce Richardson #endif
54999a2dd95SBruce Richardson 
55099a2dd95SBruce Richardson #endif /* _RTE_COMPRESSDEV_H_ */
551