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_PMD_H_ 699a2dd95SBruce Richardson #define _RTE_COMPRESSDEV_PMD_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /** @file 999a2dd95SBruce Richardson * RTE comp PMD APIs 1099a2dd95SBruce Richardson * 1199a2dd95SBruce Richardson * @note 1299a2dd95SBruce Richardson * These APIs are for comp PMDs only and user applications should not call 1399a2dd95SBruce Richardson * them directly. 1499a2dd95SBruce Richardson */ 1599a2dd95SBruce Richardson 1699a2dd95SBruce Richardson #include <string.h> 1799a2dd95SBruce Richardson 181acb7f54SDavid Marchand #include <dev_driver.h> 1999a2dd95SBruce Richardson 2099a2dd95SBruce Richardson #include "rte_compressdev.h" 2199a2dd95SBruce Richardson #include "rte_compressdev_internal.h" 2299a2dd95SBruce Richardson 23*719834a6SMattias Rönnblom #ifdef __cplusplus 24*719834a6SMattias Rönnblom extern "C" { 25*719834a6SMattias Rönnblom #endif 26*719834a6SMattias Rönnblom 2799a2dd95SBruce Richardson #define RTE_COMPRESSDEV_PMD_NAME_ARG ("name") 2899a2dd95SBruce Richardson #define RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG ("socket_id") 2999a2dd95SBruce Richardson 3099a2dd95SBruce Richardson static const char * const compressdev_pmd_valid_params[] = { 3199a2dd95SBruce Richardson RTE_COMPRESSDEV_PMD_NAME_ARG, 3299a2dd95SBruce Richardson RTE_COMPRESSDEV_PMD_SOCKET_ID_ARG 3399a2dd95SBruce Richardson }; 3499a2dd95SBruce Richardson 3599a2dd95SBruce Richardson /** 3699a2dd95SBruce Richardson * @internal 3799a2dd95SBruce Richardson * Initialisation parameters for comp devices 3899a2dd95SBruce Richardson */ 3999a2dd95SBruce Richardson struct rte_compressdev_pmd_init_params { 4099a2dd95SBruce Richardson char name[RTE_COMPRESSDEV_NAME_MAX_LEN]; 4199a2dd95SBruce Richardson int socket_id; 4299a2dd95SBruce Richardson }; 4399a2dd95SBruce Richardson 4499a2dd95SBruce Richardson /** Global structure used for maintaining state of allocated comp devices */ 4599a2dd95SBruce Richardson struct rte_compressdev_global { 4699a2dd95SBruce Richardson struct rte_compressdev *devs; /**< Device information array */ 4799a2dd95SBruce Richardson struct rte_compressdev_data *data[RTE_COMPRESS_MAX_DEVS]; 4899a2dd95SBruce Richardson /**< Device private data */ 4999a2dd95SBruce Richardson uint8_t nb_devs; /**< Number of devices found */ 5099a2dd95SBruce Richardson uint8_t max_devs; /**< Max number of devices */ 5199a2dd95SBruce Richardson }; 5299a2dd95SBruce Richardson 5399a2dd95SBruce Richardson /** 5499a2dd95SBruce Richardson * Get the rte_compressdev structure device pointer for the named device. 5599a2dd95SBruce Richardson * 5699a2dd95SBruce Richardson * @param name 5799a2dd95SBruce Richardson * Compress device name 5899a2dd95SBruce Richardson * @return 5999a2dd95SBruce Richardson * - The rte_compressdev structure pointer for the given device identifier. 6099a2dd95SBruce Richardson */ 6199a2dd95SBruce Richardson struct rte_compressdev * 6299a2dd95SBruce Richardson rte_compressdev_pmd_get_named_dev(const char *name); 6399a2dd95SBruce Richardson 6499a2dd95SBruce Richardson /** 65b53d106dSSean Morrissey * Definitions of all functions exported by a driver through 6699a2dd95SBruce Richardson * the generic structure of type *comp_dev_ops* supplied in the 6799a2dd95SBruce Richardson * *rte_compressdev* structure associated with a device. 6899a2dd95SBruce Richardson */ 6999a2dd95SBruce Richardson 7099a2dd95SBruce Richardson /** 7199a2dd95SBruce Richardson * Function used to configure device. 7299a2dd95SBruce Richardson * 7399a2dd95SBruce Richardson * @param dev 7499a2dd95SBruce Richardson * Compress device 7599a2dd95SBruce Richardson * @param config 7699a2dd95SBruce Richardson * Compress device configurations 7799a2dd95SBruce Richardson * @return 7899a2dd95SBruce Richardson * Returns 0 on success 7999a2dd95SBruce Richardson */ 8099a2dd95SBruce Richardson typedef int (*compressdev_configure_t)(struct rte_compressdev *dev, 8199a2dd95SBruce Richardson struct rte_compressdev_config *config); 8299a2dd95SBruce Richardson 8399a2dd95SBruce Richardson /** 8499a2dd95SBruce Richardson * Function used to start a configured device. 8599a2dd95SBruce Richardson * 8699a2dd95SBruce Richardson * @param dev 8799a2dd95SBruce Richardson * Compress device 8899a2dd95SBruce Richardson * @return 8999a2dd95SBruce Richardson * Returns 0 on success 9099a2dd95SBruce Richardson */ 9199a2dd95SBruce Richardson typedef int (*compressdev_start_t)(struct rte_compressdev *dev); 9299a2dd95SBruce Richardson 9399a2dd95SBruce Richardson /** 9499a2dd95SBruce Richardson * Function used to stop a configured device. 9599a2dd95SBruce Richardson * 9699a2dd95SBruce Richardson * @param dev 9799a2dd95SBruce Richardson * Compress device 9899a2dd95SBruce Richardson */ 9999a2dd95SBruce Richardson typedef void (*compressdev_stop_t)(struct rte_compressdev *dev); 10099a2dd95SBruce Richardson 10199a2dd95SBruce Richardson /** 10299a2dd95SBruce Richardson * Function used to close a configured device. 10399a2dd95SBruce Richardson * 10499a2dd95SBruce Richardson * @param dev 10599a2dd95SBruce Richardson * Compress device 10699a2dd95SBruce Richardson * @return 10799a2dd95SBruce Richardson * - 0 on success. 10899a2dd95SBruce Richardson * - EAGAIN if can't close as device is busy 10999a2dd95SBruce Richardson */ 11099a2dd95SBruce Richardson typedef int (*compressdev_close_t)(struct rte_compressdev *dev); 11199a2dd95SBruce Richardson 11299a2dd95SBruce Richardson 11399a2dd95SBruce Richardson /** 11499a2dd95SBruce Richardson * Function used to get statistics of a device. 11599a2dd95SBruce Richardson * 11699a2dd95SBruce Richardson * @param dev 11799a2dd95SBruce Richardson * Compress device 11899a2dd95SBruce Richardson * @param stats 11999a2dd95SBruce Richardson * Compress device stats to populate 12099a2dd95SBruce Richardson */ 12199a2dd95SBruce Richardson typedef void (*compressdev_stats_get_t)(struct rte_compressdev *dev, 12299a2dd95SBruce Richardson struct rte_compressdev_stats *stats); 12399a2dd95SBruce Richardson 12499a2dd95SBruce Richardson 12599a2dd95SBruce Richardson /** 12699a2dd95SBruce Richardson * Function used to reset statistics of a device. 12799a2dd95SBruce Richardson * 12899a2dd95SBruce Richardson * @param dev 12999a2dd95SBruce Richardson * Compress device 13099a2dd95SBruce Richardson */ 13199a2dd95SBruce Richardson typedef void (*compressdev_stats_reset_t)(struct rte_compressdev *dev); 13299a2dd95SBruce Richardson 13399a2dd95SBruce Richardson 13499a2dd95SBruce Richardson /** 13599a2dd95SBruce Richardson * Function used to get specific information of a device. 13699a2dd95SBruce Richardson * 13799a2dd95SBruce Richardson * @param dev 13899a2dd95SBruce Richardson * Compress device 13999a2dd95SBruce Richardson * @param dev_info 14099a2dd95SBruce Richardson * Compress device information to populate 14199a2dd95SBruce Richardson */ 14299a2dd95SBruce Richardson typedef void (*compressdev_info_get_t)(struct rte_compressdev *dev, 14399a2dd95SBruce Richardson struct rte_compressdev_info *dev_info); 14499a2dd95SBruce Richardson 14599a2dd95SBruce Richardson /** 14699a2dd95SBruce Richardson * Setup a queue pair for a device. 14799a2dd95SBruce Richardson * 14899a2dd95SBruce Richardson * @param dev 14999a2dd95SBruce Richardson * Compress device 15099a2dd95SBruce Richardson * @param qp_id 15199a2dd95SBruce Richardson * Queue pair identifier 15299a2dd95SBruce Richardson * @param max_inflight_ops 15399a2dd95SBruce Richardson * Max inflight ops which qp must accommodate 15499a2dd95SBruce Richardson * @param socket_id 15599a2dd95SBruce Richardson * Socket identifier 15699a2dd95SBruce Richardson * @return 15799a2dd95SBruce Richardson * Returns 0 on success. 15899a2dd95SBruce Richardson */ 15999a2dd95SBruce Richardson typedef int (*compressdev_queue_pair_setup_t)(struct rte_compressdev *dev, 16099a2dd95SBruce Richardson uint16_t qp_id, uint32_t max_inflight_ops, int socket_id); 16199a2dd95SBruce Richardson 16299a2dd95SBruce Richardson /** 16399a2dd95SBruce Richardson * Release memory resources allocated by given queue pair. 16499a2dd95SBruce Richardson * 16599a2dd95SBruce Richardson * @param dev 16699a2dd95SBruce Richardson * Compress device 16799a2dd95SBruce Richardson * @param qp_id 16899a2dd95SBruce Richardson * Queue pair identifier 16999a2dd95SBruce Richardson * @return 17099a2dd95SBruce Richardson * - 0 on success. 17199a2dd95SBruce Richardson * - EAGAIN if can't close as device is busy 17299a2dd95SBruce Richardson */ 17399a2dd95SBruce Richardson typedef int (*compressdev_queue_pair_release_t)(struct rte_compressdev *dev, 17499a2dd95SBruce Richardson uint16_t qp_id); 17599a2dd95SBruce Richardson 17699a2dd95SBruce Richardson /** 17799a2dd95SBruce Richardson * Create driver private stream data. 17899a2dd95SBruce Richardson * 17999a2dd95SBruce Richardson * @param dev 18099a2dd95SBruce Richardson * Compressdev device 18199a2dd95SBruce Richardson * @param xform 18299a2dd95SBruce Richardson * xform data 18399a2dd95SBruce Richardson * @param stream 18499a2dd95SBruce Richardson * ptr where handle of pmd's private stream data should be stored 18599a2dd95SBruce Richardson * @return 18699a2dd95SBruce Richardson * - Returns 0 if private stream structure has been created successfully. 18799a2dd95SBruce Richardson * - Returns -EINVAL if input parameters are invalid. 18899a2dd95SBruce Richardson * - Returns -ENOTSUP if comp device does not support STATEFUL operations. 18999a2dd95SBruce Richardson * - Returns -ENOTSUP if comp device does not support the comp transform. 19099a2dd95SBruce Richardson * - Returns -ENOMEM if the private stream could not be allocated. 19199a2dd95SBruce Richardson */ 19299a2dd95SBruce Richardson typedef int (*compressdev_stream_create_t)(struct rte_compressdev *dev, 19399a2dd95SBruce Richardson const struct rte_comp_xform *xform, void **stream); 19499a2dd95SBruce Richardson 19599a2dd95SBruce Richardson /** 19699a2dd95SBruce Richardson * Free driver private stream data. 19799a2dd95SBruce Richardson * 19899a2dd95SBruce Richardson * @param dev 19999a2dd95SBruce Richardson * Compressdev device 20099a2dd95SBruce Richardson * @param stream 20199a2dd95SBruce Richardson * handle of pmd's private stream data 20299a2dd95SBruce Richardson * @return 20399a2dd95SBruce Richardson * - 0 if successful 20499a2dd95SBruce Richardson * - <0 in error cases 20599a2dd95SBruce Richardson * - Returns -EINVAL if input parameters are invalid. 20699a2dd95SBruce Richardson * - Returns -ENOTSUP if comp device does not support STATEFUL operations. 20799a2dd95SBruce Richardson * - Returns -EBUSY if can't free stream as there are inflight operations 20899a2dd95SBruce Richardson */ 20999a2dd95SBruce Richardson typedef int (*compressdev_stream_free_t)(struct rte_compressdev *dev, 21099a2dd95SBruce Richardson void *stream); 21199a2dd95SBruce Richardson 21299a2dd95SBruce Richardson /** 21399a2dd95SBruce Richardson * Create driver private_xform data. 21499a2dd95SBruce Richardson * 21599a2dd95SBruce Richardson * @param dev 21699a2dd95SBruce Richardson * Compressdev device 21799a2dd95SBruce Richardson * @param xform 21899a2dd95SBruce Richardson * xform data 21999a2dd95SBruce Richardson * @param private_xform 22099a2dd95SBruce Richardson * ptr where handle of pmd's private_xform data should be stored 22199a2dd95SBruce Richardson * @return 22299a2dd95SBruce Richardson * - if successful returns 0 22399a2dd95SBruce Richardson * and valid private_xform handle 22499a2dd95SBruce Richardson * - <0 in error cases 22599a2dd95SBruce Richardson * - Returns -EINVAL if input parameters are invalid. 22699a2dd95SBruce Richardson * - Returns -ENOTSUP if comp device does not support the comp transform. 22799a2dd95SBruce Richardson * - Returns -ENOMEM if the private_xform could not be allocated. 22899a2dd95SBruce Richardson */ 22999a2dd95SBruce Richardson typedef int (*compressdev_private_xform_create_t)(struct rte_compressdev *dev, 23099a2dd95SBruce Richardson const struct rte_comp_xform *xform, void **private_xform); 23199a2dd95SBruce Richardson 23299a2dd95SBruce Richardson /** 23399a2dd95SBruce Richardson * Free driver private_xform data. 23499a2dd95SBruce Richardson * 23599a2dd95SBruce Richardson * @param dev 23699a2dd95SBruce Richardson * Compressdev device 23799a2dd95SBruce Richardson * @param private_xform 23899a2dd95SBruce Richardson * handle of pmd's private_xform data 23999a2dd95SBruce Richardson * @return 24099a2dd95SBruce Richardson * - 0 if successful 24199a2dd95SBruce Richardson * - <0 in error cases 24299a2dd95SBruce Richardson * - Returns -EINVAL if input parameters are invalid. 24399a2dd95SBruce Richardson * - Returns -EBUSY if can't free private_xform due to inflight operations 24499a2dd95SBruce Richardson */ 24599a2dd95SBruce Richardson typedef int (*compressdev_private_xform_free_t)(struct rte_compressdev *dev, 24699a2dd95SBruce Richardson void *private_xform); 24799a2dd95SBruce Richardson 24899a2dd95SBruce Richardson /** comp device operations function pointer table */ 24999a2dd95SBruce Richardson struct rte_compressdev_ops { 25099a2dd95SBruce Richardson compressdev_configure_t dev_configure; /**< Configure device. */ 25199a2dd95SBruce Richardson compressdev_start_t dev_start; /**< Start device. */ 25299a2dd95SBruce Richardson compressdev_stop_t dev_stop; /**< Stop device. */ 25399a2dd95SBruce Richardson compressdev_close_t dev_close; /**< Close device. */ 25499a2dd95SBruce Richardson 25599a2dd95SBruce Richardson compressdev_info_get_t dev_infos_get; /**< Get device info. */ 25699a2dd95SBruce Richardson 25799a2dd95SBruce Richardson compressdev_stats_get_t stats_get; 25899a2dd95SBruce Richardson /**< Get device statistics. */ 25999a2dd95SBruce Richardson compressdev_stats_reset_t stats_reset; 26099a2dd95SBruce Richardson /**< Reset device statistics. */ 26199a2dd95SBruce Richardson 26299a2dd95SBruce Richardson compressdev_queue_pair_setup_t queue_pair_setup; 26399a2dd95SBruce Richardson /**< Set up a device queue pair. */ 26499a2dd95SBruce Richardson compressdev_queue_pair_release_t queue_pair_release; 26599a2dd95SBruce Richardson /**< Release a queue pair. */ 26699a2dd95SBruce Richardson 26799a2dd95SBruce Richardson compressdev_stream_create_t stream_create; 26899a2dd95SBruce Richardson /**< Create a comp stream and initialise its private data. */ 26999a2dd95SBruce Richardson compressdev_stream_free_t stream_free; 27099a2dd95SBruce Richardson /**< Free a comp stream's private data. */ 27199a2dd95SBruce Richardson 27299a2dd95SBruce Richardson compressdev_private_xform_create_t private_xform_create; 27399a2dd95SBruce Richardson /**< Create a comp private_xform and initialise its private data. */ 27499a2dd95SBruce Richardson compressdev_private_xform_free_t private_xform_free; 27599a2dd95SBruce Richardson /**< Free a comp private_xform's data. */ 27699a2dd95SBruce Richardson }; 27799a2dd95SBruce Richardson 27899a2dd95SBruce Richardson /** 27999a2dd95SBruce Richardson * @internal 28099a2dd95SBruce Richardson * 28199a2dd95SBruce Richardson * Function for internal use by dummy drivers primarily, e.g. ring-based 28299a2dd95SBruce Richardson * driver. 28399a2dd95SBruce Richardson * Allocates a new compressdev slot for an comp device and returns the pointer 28499a2dd95SBruce Richardson * to that slot for the driver to use. 28599a2dd95SBruce Richardson * 28699a2dd95SBruce Richardson * @param name 28799a2dd95SBruce Richardson * Unique identifier name for each device 28899a2dd95SBruce Richardson * @param socket_id 28999a2dd95SBruce Richardson * Socket to allocate resources on 29099a2dd95SBruce Richardson * @return 29199a2dd95SBruce Richardson * - Slot in the rte_dev_devices array for a new device; 29299a2dd95SBruce Richardson */ 29399a2dd95SBruce Richardson struct rte_compressdev * 29499a2dd95SBruce Richardson rte_compressdev_pmd_allocate(const char *name, int socket_id); 29599a2dd95SBruce Richardson 29699a2dd95SBruce Richardson /** 29799a2dd95SBruce Richardson * @internal 29899a2dd95SBruce Richardson * 29999a2dd95SBruce Richardson * Function for internal use by dummy drivers primarily, e.g. ring-based 30099a2dd95SBruce Richardson * driver. 30199a2dd95SBruce Richardson * Release the specified compressdev device. 30299a2dd95SBruce Richardson * 30399a2dd95SBruce Richardson * @param dev 30499a2dd95SBruce Richardson * Compress device 30599a2dd95SBruce Richardson * @return 30699a2dd95SBruce Richardson * - 0 on success, negative on error 30799a2dd95SBruce Richardson */ 30899a2dd95SBruce Richardson int 30999a2dd95SBruce Richardson rte_compressdev_pmd_release_device(struct rte_compressdev *dev); 31099a2dd95SBruce Richardson 31199a2dd95SBruce Richardson 31299a2dd95SBruce Richardson /** 31399a2dd95SBruce Richardson * @internal 31499a2dd95SBruce Richardson * 31599a2dd95SBruce Richardson * PMD assist function to parse initialisation arguments for comp driver 31699a2dd95SBruce Richardson * when creating a new comp PMD device instance. 31799a2dd95SBruce Richardson * 318f8dbaebbSSean Morrissey * PMD should set default values for that PMD before calling function, 31999a2dd95SBruce Richardson * these default values will be over-written with successfully parsed values 32099a2dd95SBruce Richardson * from args string. 32199a2dd95SBruce Richardson * 32299a2dd95SBruce Richardson * @param params 32399a2dd95SBruce Richardson * Parsed PMD initialisation parameters 32499a2dd95SBruce Richardson * @param args 32599a2dd95SBruce Richardson * Input argument string to parse 32699a2dd95SBruce Richardson * @return 32799a2dd95SBruce Richardson * - 0 on success 32899a2dd95SBruce Richardson * - errno on failure 32999a2dd95SBruce Richardson */ 33099a2dd95SBruce Richardson int 33199a2dd95SBruce Richardson rte_compressdev_pmd_parse_input_args( 33299a2dd95SBruce Richardson struct rte_compressdev_pmd_init_params *params, 33399a2dd95SBruce Richardson const char *args); 33499a2dd95SBruce Richardson 33599a2dd95SBruce Richardson /** 33699a2dd95SBruce Richardson * @internal 33799a2dd95SBruce Richardson * 33899a2dd95SBruce Richardson * PMD assist function to provide boiler plate code for comp driver to create 33999a2dd95SBruce Richardson * and allocate resources for a new comp PMD device instance. 34099a2dd95SBruce Richardson * 34199a2dd95SBruce Richardson * @param name 34299a2dd95SBruce Richardson * Compress device name 34399a2dd95SBruce Richardson * @param device 34499a2dd95SBruce Richardson * Base device instance 34599a2dd95SBruce Richardson * @param params 34699a2dd95SBruce Richardson * PMD initialisation parameters 34799a2dd95SBruce Richardson * @return 34899a2dd95SBruce Richardson * - comp device instance on success 34999a2dd95SBruce Richardson * - NULL on creation failure 35099a2dd95SBruce Richardson */ 35199a2dd95SBruce Richardson struct rte_compressdev * 35299a2dd95SBruce Richardson rte_compressdev_pmd_create(const char *name, 35399a2dd95SBruce Richardson struct rte_device *device, 35499a2dd95SBruce Richardson size_t private_data_size, 35599a2dd95SBruce Richardson struct rte_compressdev_pmd_init_params *params); 35699a2dd95SBruce Richardson 35799a2dd95SBruce Richardson /** 35899a2dd95SBruce Richardson * @internal 35999a2dd95SBruce Richardson * 36099a2dd95SBruce Richardson * PMD assist function to provide boiler plate code for comp driver to 36199a2dd95SBruce Richardson * destroy and free resources associated with a comp PMD device instance. 36299a2dd95SBruce Richardson * 36399a2dd95SBruce Richardson * @param dev 36499a2dd95SBruce Richardson * Compress device 36599a2dd95SBruce Richardson * @return 36699a2dd95SBruce Richardson * - 0 on success 36799a2dd95SBruce Richardson * - errno on failure 36899a2dd95SBruce Richardson */ 36999a2dd95SBruce Richardson int 37099a2dd95SBruce Richardson rte_compressdev_pmd_destroy(struct rte_compressdev *dev); 37199a2dd95SBruce Richardson 37299a2dd95SBruce Richardson #ifdef __cplusplus 37399a2dd95SBruce Richardson } 37499a2dd95SBruce Richardson #endif 37599a2dd95SBruce Richardson 37699a2dd95SBruce Richardson #endif /* _RTE_COMPRESSDEV_PMD_H_ */ 377