199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright 2017 NXP 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _RTE_RAWDEV_H_ 699a2dd95SBruce Richardson #define _RTE_RAWDEV_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /** 999a2dd95SBruce Richardson * @file rte_rawdev.h 1099a2dd95SBruce Richardson * 1199a2dd95SBruce Richardson * Generic device abstraction APIs. 1299a2dd95SBruce Richardson * 1399a2dd95SBruce Richardson * This API allow applications to configure and use generic devices having 1499a2dd95SBruce Richardson * no specific type already available in DPDK. 1599a2dd95SBruce Richardson */ 1699a2dd95SBruce Richardson 17*719834a6SMattias Rönnblom #include <rte_common.h> 18*719834a6SMattias Rönnblom #include <rte_memory.h> 19*719834a6SMattias Rönnblom 2099a2dd95SBruce Richardson #ifdef __cplusplus 2199a2dd95SBruce Richardson extern "C" { 2299a2dd95SBruce Richardson #endif 2399a2dd95SBruce Richardson 2499a2dd95SBruce Richardson /* Rawdevice object - essentially a void to be typecast by implementation */ 2599a2dd95SBruce Richardson typedef void *rte_rawdev_obj_t; 2699a2dd95SBruce Richardson 2799a2dd95SBruce Richardson /** 2899a2dd95SBruce Richardson * Get the total number of raw devices that have been successfully 2999a2dd95SBruce Richardson * initialised. 3099a2dd95SBruce Richardson * 3199a2dd95SBruce Richardson * @return 3299a2dd95SBruce Richardson * The total number of usable raw devices. 3399a2dd95SBruce Richardson */ 3499a2dd95SBruce Richardson uint8_t 3599a2dd95SBruce Richardson rte_rawdev_count(void); 3699a2dd95SBruce Richardson 3799a2dd95SBruce Richardson /** 3899a2dd95SBruce Richardson * Get the device identifier for the named raw device. 3999a2dd95SBruce Richardson * 4099a2dd95SBruce Richardson * @param name 4199a2dd95SBruce Richardson * Raw device name to select the raw device identifier. 4299a2dd95SBruce Richardson * 4399a2dd95SBruce Richardson * @return 4499a2dd95SBruce Richardson * Returns raw device identifier on success. 4599a2dd95SBruce Richardson * - <0: Failure to find named raw device. 4699a2dd95SBruce Richardson */ 4799a2dd95SBruce Richardson uint16_t 4899a2dd95SBruce Richardson rte_rawdev_get_dev_id(const char *name); 4999a2dd95SBruce Richardson 5099a2dd95SBruce Richardson /** 5199a2dd95SBruce Richardson * Return the NUMA socket to which a device is connected. 5299a2dd95SBruce Richardson * 5399a2dd95SBruce Richardson * @param dev_id 5499a2dd95SBruce Richardson * The identifier of the device. 5599a2dd95SBruce Richardson * @return 5699a2dd95SBruce Richardson * The NUMA socket id to which the device is connected or 5799a2dd95SBruce Richardson * a default of zero if the socket could not be determined. 5899a2dd95SBruce Richardson * -(-EINVAL) dev_id value is out of range. 5999a2dd95SBruce Richardson */ 6099a2dd95SBruce Richardson int 6199a2dd95SBruce Richardson rte_rawdev_socket_id(uint16_t dev_id); 6299a2dd95SBruce Richardson 6399a2dd95SBruce Richardson /** 6499a2dd95SBruce Richardson * Raw device information forward declaration 6599a2dd95SBruce Richardson */ 6699a2dd95SBruce Richardson struct rte_rawdev_info; 6799a2dd95SBruce Richardson 6899a2dd95SBruce Richardson /** 6999a2dd95SBruce Richardson * Retrieve the contextual information of a raw device. 7099a2dd95SBruce Richardson * 7199a2dd95SBruce Richardson * @param dev_id 7299a2dd95SBruce Richardson * The identifier of the device. 7399a2dd95SBruce Richardson * 7499a2dd95SBruce Richardson * @param[out] dev_info 7599a2dd95SBruce Richardson * A pointer to a structure of type *rte_rawdev_info* to be filled with the 7699a2dd95SBruce Richardson * contextual information of the device. The dev_info->dev_private field 7799a2dd95SBruce Richardson * should point to an appropriate buffer space for holding the device- 7899a2dd95SBruce Richardson * specific info for that hardware. 7999a2dd95SBruce Richardson * If the dev_private field is set to NULL, then the device-specific info 8099a2dd95SBruce Richardson * function will not be called and only basic information about the device 8199a2dd95SBruce Richardson * will be returned. This can be used to safely query the type of a rawdev 8299a2dd95SBruce Richardson * instance without needing to know the size of the private data to return. 8399a2dd95SBruce Richardson * 8499a2dd95SBruce Richardson * @param dev_private_size 8599a2dd95SBruce Richardson * The length of the memory space pointed to by dev_private in dev_info. 8699a2dd95SBruce Richardson * This should be set to the size of the expected private structure to be 8799a2dd95SBruce Richardson * returned, and may be checked by drivers to ensure the expected struct 8899a2dd95SBruce Richardson * type is provided. 8999a2dd95SBruce Richardson * 9099a2dd95SBruce Richardson * @return 9199a2dd95SBruce Richardson * - 0: Success, driver updates the contextual information of the raw device 9299a2dd95SBruce Richardson * - <0: Error code returned by the driver info get function. 9399a2dd95SBruce Richardson */ 9499a2dd95SBruce Richardson int 9599a2dd95SBruce Richardson rte_rawdev_info_get(uint16_t dev_id, struct rte_rawdev_info *dev_info, 9699a2dd95SBruce Richardson size_t dev_private_size); 9799a2dd95SBruce Richardson 9899a2dd95SBruce Richardson /** 9999a2dd95SBruce Richardson * Configure a raw device. 10099a2dd95SBruce Richardson * 10199a2dd95SBruce Richardson * This function must be invoked first before any other function in the 10299a2dd95SBruce Richardson * API. This function can also be re-invoked when a device is in the 10399a2dd95SBruce Richardson * stopped state. 10499a2dd95SBruce Richardson * 10599a2dd95SBruce Richardson * The caller may use rte_rawdev_info_get() to get the capability of each 10699a2dd95SBruce Richardson * resources available for this raw device. 10799a2dd95SBruce Richardson * 10899a2dd95SBruce Richardson * @param dev_id 10999a2dd95SBruce Richardson * The identifier of the device to configure. 11099a2dd95SBruce Richardson * @param dev_conf 11199a2dd95SBruce Richardson * The raw device configuration structure encapsulated into rte_rawdev_info 11299a2dd95SBruce Richardson * object. 11399a2dd95SBruce Richardson * It is assumed that the opaque object has enough information which the 11499a2dd95SBruce Richardson * driver/implementation can use to configure the device. It is also assumed 11599a2dd95SBruce Richardson * that once the configuration is done, a `queue_id` type field can be used 11699a2dd95SBruce Richardson * to refer to some arbitrary internal representation of a queue. 11799a2dd95SBruce Richardson * @param dev_private_size 11899a2dd95SBruce Richardson * The length of the memory space pointed to by dev_private in dev_info. 11999a2dd95SBruce Richardson * This should be set to the size of the expected private structure to be 12099a2dd95SBruce Richardson * used by the driver, and may be checked by drivers to ensure the expected 12199a2dd95SBruce Richardson * struct type is provided. 12299a2dd95SBruce Richardson * 12399a2dd95SBruce Richardson * @return 12499a2dd95SBruce Richardson * - 0: Success, device configured. 12599a2dd95SBruce Richardson * - <0: Error code returned by the driver configuration function. 12699a2dd95SBruce Richardson */ 12799a2dd95SBruce Richardson int 12899a2dd95SBruce Richardson rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf, 12999a2dd95SBruce Richardson size_t dev_private_size); 13099a2dd95SBruce Richardson 13199a2dd95SBruce Richardson 13299a2dd95SBruce Richardson /** 13399a2dd95SBruce Richardson * Retrieve the current configuration information of a raw queue designated 13499a2dd95SBruce Richardson * by its *queue_id* from the raw driver for a raw device. 13599a2dd95SBruce Richardson * 13699a2dd95SBruce Richardson * This function intended to be used in conjunction with rte_raw_queue_setup() 13799a2dd95SBruce Richardson * where caller needs to set up the queue by overriding few default values. 13899a2dd95SBruce Richardson * 13999a2dd95SBruce Richardson * @param dev_id 14099a2dd95SBruce Richardson * The identifier of the device. 14199a2dd95SBruce Richardson * @param queue_id 14299a2dd95SBruce Richardson * The index of the raw queue to get the configuration information. 14399a2dd95SBruce Richardson * The value must be in the range [0, nb_raw_queues - 1] 14499a2dd95SBruce Richardson * previously supplied to rte_rawdev_configure(). 14599a2dd95SBruce Richardson * @param[out] queue_conf 14699a2dd95SBruce Richardson * The pointer to the default raw queue configuration data. 14799a2dd95SBruce Richardson * @param queue_conf_size 14899a2dd95SBruce Richardson * The size of the structure pointed to by queue_conf 14999a2dd95SBruce Richardson * @return 15099a2dd95SBruce Richardson * - 0: Success, driver updates the default raw queue configuration data. 15199a2dd95SBruce Richardson * - <0: Error code returned by the driver info get function. 15299a2dd95SBruce Richardson * 15399a2dd95SBruce Richardson * @see rte_raw_queue_setup() 15499a2dd95SBruce Richardson */ 15599a2dd95SBruce Richardson int 15699a2dd95SBruce Richardson rte_rawdev_queue_conf_get(uint16_t dev_id, 15799a2dd95SBruce Richardson uint16_t queue_id, 15899a2dd95SBruce Richardson rte_rawdev_obj_t queue_conf, 15999a2dd95SBruce Richardson size_t queue_conf_size); 16099a2dd95SBruce Richardson 16199a2dd95SBruce Richardson /** 16299a2dd95SBruce Richardson * Allocate and set up a raw queue for a raw device. 16399a2dd95SBruce Richardson * 16499a2dd95SBruce Richardson * @param dev_id 16599a2dd95SBruce Richardson * The identifier of the device. 16699a2dd95SBruce Richardson * @param queue_id 16799a2dd95SBruce Richardson * The index of the raw queue to setup. The value must be in the range 16899a2dd95SBruce Richardson * [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure(). 16999a2dd95SBruce Richardson * @param queue_conf 17099a2dd95SBruce Richardson * The pointer to the configuration data to be used for the raw queue. 17199a2dd95SBruce Richardson * NULL value is allowed, in which case default configuration used. 17299a2dd95SBruce Richardson * @param queue_conf_size 17399a2dd95SBruce Richardson * The size of the structure pointed to by queue_conf 17499a2dd95SBruce Richardson * 17599a2dd95SBruce Richardson * @see rte_rawdev_queue_conf_get() 17699a2dd95SBruce Richardson * 17799a2dd95SBruce Richardson * @return 17899a2dd95SBruce Richardson * - 0: Success, raw queue correctly set up. 17999a2dd95SBruce Richardson * - <0: raw queue configuration failed 18099a2dd95SBruce Richardson */ 18199a2dd95SBruce Richardson int 18299a2dd95SBruce Richardson rte_rawdev_queue_setup(uint16_t dev_id, 18399a2dd95SBruce Richardson uint16_t queue_id, 18499a2dd95SBruce Richardson rte_rawdev_obj_t queue_conf, 18599a2dd95SBruce Richardson size_t queue_conf_size); 18699a2dd95SBruce Richardson 18799a2dd95SBruce Richardson /** 18899a2dd95SBruce Richardson * Release and deallocate a raw queue from a raw device. 18999a2dd95SBruce Richardson * 19099a2dd95SBruce Richardson * @param dev_id 19199a2dd95SBruce Richardson * The identifier of the device. 19299a2dd95SBruce Richardson * @param queue_id 19399a2dd95SBruce Richardson * The index of the raw queue to release. The value must be in the range 19499a2dd95SBruce Richardson * [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure(). 19599a2dd95SBruce Richardson * 19699a2dd95SBruce Richardson * @see rte_rawdev_queue_conf_get() 19799a2dd95SBruce Richardson * 19899a2dd95SBruce Richardson * @return 19999a2dd95SBruce Richardson * - 0: Success, raw queue released. 20099a2dd95SBruce Richardson * - <0: raw queue configuration failed 20199a2dd95SBruce Richardson */ 20299a2dd95SBruce Richardson int 20399a2dd95SBruce Richardson rte_rawdev_queue_release(uint16_t dev_id, uint16_t queue_id); 20499a2dd95SBruce Richardson 20599a2dd95SBruce Richardson /** 20699a2dd95SBruce Richardson * Get the number of raw queues on a specific raw device 20799a2dd95SBruce Richardson * 20899a2dd95SBruce Richardson * @param dev_id 20999a2dd95SBruce Richardson * Raw device identifier. 21099a2dd95SBruce Richardson * @return 21199a2dd95SBruce Richardson * - The number of configured raw queues 21299a2dd95SBruce Richardson */ 21399a2dd95SBruce Richardson uint16_t 21499a2dd95SBruce Richardson rte_rawdev_queue_count(uint16_t dev_id); 21599a2dd95SBruce Richardson 21699a2dd95SBruce Richardson /** 21799a2dd95SBruce Richardson * Start a raw device. 21899a2dd95SBruce Richardson * 21999a2dd95SBruce Richardson * The device start step is the last one and consists of setting the raw 22099a2dd95SBruce Richardson * queues to start accepting the raws and schedules to raw ports. 22199a2dd95SBruce Richardson * 22299a2dd95SBruce Richardson * On success, all basic functions exported by the API (raw enqueue, 22399a2dd95SBruce Richardson * raw dequeue and so on) can be invoked. 22499a2dd95SBruce Richardson * 22599a2dd95SBruce Richardson * @param dev_id 22699a2dd95SBruce Richardson * Raw device identifier 22799a2dd95SBruce Richardson * @return 22899a2dd95SBruce Richardson * - 0: Success, device started. 22999a2dd95SBruce Richardson * < 0: Failure 23099a2dd95SBruce Richardson */ 23199a2dd95SBruce Richardson int 23299a2dd95SBruce Richardson rte_rawdev_start(uint16_t dev_id); 23399a2dd95SBruce Richardson 23499a2dd95SBruce Richardson /** 23599a2dd95SBruce Richardson * Stop a raw device. The device can be restarted with a call to 23699a2dd95SBruce Richardson * rte_rawdev_start() 23799a2dd95SBruce Richardson * 23899a2dd95SBruce Richardson * @param dev_id 23999a2dd95SBruce Richardson * Raw device identifier. 24099a2dd95SBruce Richardson */ 24199a2dd95SBruce Richardson void 24299a2dd95SBruce Richardson rte_rawdev_stop(uint16_t dev_id); 24399a2dd95SBruce Richardson 24499a2dd95SBruce Richardson /** 24599a2dd95SBruce Richardson * Close a raw device. The device cannot be restarted after this call. 24699a2dd95SBruce Richardson * 24799a2dd95SBruce Richardson * @param dev_id 24899a2dd95SBruce Richardson * Raw device identifier 24999a2dd95SBruce Richardson * 25099a2dd95SBruce Richardson * @return 25199a2dd95SBruce Richardson * - 0 on successfully closing device 25299a2dd95SBruce Richardson * - <0 on failure to close device 25399a2dd95SBruce Richardson * - (-EAGAIN) if device is busy 25499a2dd95SBruce Richardson */ 25599a2dd95SBruce Richardson int 25699a2dd95SBruce Richardson rte_rawdev_close(uint16_t dev_id); 25799a2dd95SBruce Richardson 25899a2dd95SBruce Richardson /** 25999a2dd95SBruce Richardson * Reset a raw device. 26099a2dd95SBruce Richardson * This is different from cycle of rte_rawdev_start->rte_rawdev_stop in the 26199a2dd95SBruce Richardson * sense similar to hard or soft reset. 26299a2dd95SBruce Richardson * 26399a2dd95SBruce Richardson * @param dev_id 26499a2dd95SBruce Richardson * Raw device identifiers 26599a2dd95SBruce Richardson * @return 26699a2dd95SBruce Richardson * 0 for successful reset, 26799a2dd95SBruce Richardson * !0 for failure in resetting 26899a2dd95SBruce Richardson */ 26999a2dd95SBruce Richardson int 27099a2dd95SBruce Richardson rte_rawdev_reset(uint16_t dev_id); 27199a2dd95SBruce Richardson 27299a2dd95SBruce Richardson #define RTE_RAWDEV_NAME_MAX_LEN (64) 27399a2dd95SBruce Richardson /**< @internal Max length of name of raw PMD */ 27499a2dd95SBruce Richardson 27599a2dd95SBruce Richardson 27699a2dd95SBruce Richardson 27799a2dd95SBruce Richardson /** @internal 27899a2dd95SBruce Richardson * The data structure associated with each raw device. 27999a2dd95SBruce Richardson * It is a placeholder for PMD specific data, encapsulating only information 28099a2dd95SBruce Richardson * related to framework. 28199a2dd95SBruce Richardson */ 282c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_rawdev { 28399a2dd95SBruce Richardson /**< Socket ID where memory is allocated */ 28499a2dd95SBruce Richardson int socket_id; 28599a2dd95SBruce Richardson /**< Device ID for this instance */ 28699a2dd95SBruce Richardson uint16_t dev_id; 28799a2dd95SBruce Richardson /**< Functions exported by PMD */ 28899a2dd95SBruce Richardson const struct rte_rawdev_ops *dev_ops; 28999a2dd95SBruce Richardson /**< Device info. supplied during device initialization */ 29099a2dd95SBruce Richardson struct rte_device *device; 29199a2dd95SBruce Richardson /**< Driver info. supplied by probing */ 29299a2dd95SBruce Richardson const char *driver_name; 29399a2dd95SBruce Richardson 29499a2dd95SBruce Richardson /**< Flag indicating the device is attached */ 29599a2dd95SBruce Richardson uint8_t attached : 1; 29699a2dd95SBruce Richardson /**< Device state: STARTED(1)/STOPPED(0) */ 29799a2dd95SBruce Richardson uint8_t started : 1; 29899a2dd95SBruce Richardson 29999a2dd95SBruce Richardson /**< PMD-specific private data */ 30099a2dd95SBruce Richardson rte_rawdev_obj_t dev_private; 30199a2dd95SBruce Richardson /**< Device name */ 30299a2dd95SBruce Richardson char name[RTE_RAWDEV_NAME_MAX_LEN]; 303c6552d9aSTyler Retzlaff }; 30499a2dd95SBruce Richardson 30599a2dd95SBruce Richardson /** @internal The pool of rte_rawdev structures. */ 30699a2dd95SBruce Richardson extern struct rte_rawdev *rte_rawdevs; 30799a2dd95SBruce Richardson 30899a2dd95SBruce Richardson 30999a2dd95SBruce Richardson struct rte_rawdev_info { 31099a2dd95SBruce Richardson /**< Name of driver handling this device */ 31199a2dd95SBruce Richardson const char *driver_name; 31299a2dd95SBruce Richardson /**< Device encapsulation */ 31399a2dd95SBruce Richardson struct rte_device *device; 31499a2dd95SBruce Richardson /**< Socket ID where memory is allocated */ 31599a2dd95SBruce Richardson int socket_id; 31699a2dd95SBruce Richardson /**< PMD-specific private data */ 31799a2dd95SBruce Richardson rte_rawdev_obj_t dev_private; 31899a2dd95SBruce Richardson }; 31999a2dd95SBruce Richardson 32099a2dd95SBruce Richardson struct rte_rawdev_buf { 32199a2dd95SBruce Richardson /**< Opaque buffer reference */ 32299a2dd95SBruce Richardson void *buf_addr; 32399a2dd95SBruce Richardson }; 32499a2dd95SBruce Richardson 32599a2dd95SBruce Richardson /** 32699a2dd95SBruce Richardson * Dump internal information about *dev_id* to the FILE* provided in *f*. 32799a2dd95SBruce Richardson * 32899a2dd95SBruce Richardson * @param dev_id 32999a2dd95SBruce Richardson * The identifier of the device. 33099a2dd95SBruce Richardson * 33199a2dd95SBruce Richardson * @param f 33299a2dd95SBruce Richardson * A pointer to a file for output 33399a2dd95SBruce Richardson * 33499a2dd95SBruce Richardson * @return 33599a2dd95SBruce Richardson * - 0: on success 33699a2dd95SBruce Richardson * - <0: on failure. 33799a2dd95SBruce Richardson */ 33899a2dd95SBruce Richardson int 33999a2dd95SBruce Richardson rte_rawdev_dump(uint16_t dev_id, FILE *f); 34099a2dd95SBruce Richardson 34199a2dd95SBruce Richardson /** 34299a2dd95SBruce Richardson * Get an attribute value from implementation. 34399a2dd95SBruce Richardson * Attribute is an opaque handle agreed upon between application and PMD. 34499a2dd95SBruce Richardson * 34599a2dd95SBruce Richardson * Implementations are expected to maintain an array of attribute-value pairs 34699a2dd95SBruce Richardson * based on application calls. Memory management for this structure is 34799a2dd95SBruce Richardson * shared responsibility of implementation and application. 34899a2dd95SBruce Richardson * 34999a2dd95SBruce Richardson * @param dev_id 35099a2dd95SBruce Richardson * The identifier of the device to configure. 35199a2dd95SBruce Richardson * @param attr_name 35299a2dd95SBruce Richardson * Opaque object representing an attribute in implementation. 35399a2dd95SBruce Richardson * @param attr_value [out] 35499a2dd95SBruce Richardson * Opaque response to the attribute value. In case of error, this remains 35599a2dd95SBruce Richardson * untouched. This is double pointer of void type. 35699a2dd95SBruce Richardson * @return 35799a2dd95SBruce Richardson * 0 for success 35899a2dd95SBruce Richardson * !0 Error; attr_value remains untouched in case of error. 35999a2dd95SBruce Richardson */ 36099a2dd95SBruce Richardson int 36199a2dd95SBruce Richardson rte_rawdev_get_attr(uint16_t dev_id, 36299a2dd95SBruce Richardson const char *attr_name, 36399a2dd95SBruce Richardson uint64_t *attr_value); 36499a2dd95SBruce Richardson 36599a2dd95SBruce Richardson /** 36699a2dd95SBruce Richardson * Set an attribute value. 36799a2dd95SBruce Richardson * Attribute is an opaque handle agreed upon between application and PMD. 36899a2dd95SBruce Richardson * 36999a2dd95SBruce Richardson * @param dev_id 37099a2dd95SBruce Richardson * The identifier of the device to configure. 37199a2dd95SBruce Richardson * @param attr_name 37299a2dd95SBruce Richardson * Opaque object representing an attribute in implementation. 37399a2dd95SBruce Richardson * @param attr_value 37499a2dd95SBruce Richardson * Value of the attribute represented by attr_name 37599a2dd95SBruce Richardson * @return 37699a2dd95SBruce Richardson * 0 for success 37799a2dd95SBruce Richardson * !0 Error 37899a2dd95SBruce Richardson */ 37999a2dd95SBruce Richardson int 38099a2dd95SBruce Richardson rte_rawdev_set_attr(uint16_t dev_id, 38199a2dd95SBruce Richardson const char *attr_name, 38299a2dd95SBruce Richardson const uint64_t attr_value); 38399a2dd95SBruce Richardson 38499a2dd95SBruce Richardson /** 38599a2dd95SBruce Richardson * Enqueue a stream of buffers to the device. 38699a2dd95SBruce Richardson * 38799a2dd95SBruce Richardson * Rather than specifying a queue, this API passes along an opaque object 38899a2dd95SBruce Richardson * to the driver implementation. That object can be a queue or any other 38999a2dd95SBruce Richardson * contextual information necessary for the device to enqueue buffers. 39099a2dd95SBruce Richardson * 39199a2dd95SBruce Richardson * @param dev_id 39299a2dd95SBruce Richardson * The identifier of the device to configure. 39399a2dd95SBruce Richardson * @param buffers 39499a2dd95SBruce Richardson * Collection of buffers for enqueuing 39599a2dd95SBruce Richardson * @param count 39699a2dd95SBruce Richardson * Count of buffers to enqueue 39799a2dd95SBruce Richardson * @param context 39899a2dd95SBruce Richardson * Opaque context information. 39999a2dd95SBruce Richardson * @return 40099a2dd95SBruce Richardson * >=0 for buffers enqueued 40199a2dd95SBruce Richardson * !0 for failure. 40299a2dd95SBruce Richardson * Whether partial enqueue is failure or success is defined between app 40399a2dd95SBruce Richardson * and driver implementation. 40499a2dd95SBruce Richardson */ 40599a2dd95SBruce Richardson int 40699a2dd95SBruce Richardson rte_rawdev_enqueue_buffers(uint16_t dev_id, 40799a2dd95SBruce Richardson struct rte_rawdev_buf **buffers, 40899a2dd95SBruce Richardson unsigned int count, 40999a2dd95SBruce Richardson rte_rawdev_obj_t context); 41099a2dd95SBruce Richardson 41199a2dd95SBruce Richardson /** 41299a2dd95SBruce Richardson * Dequeue a stream of buffers from the device. 41399a2dd95SBruce Richardson * 41499a2dd95SBruce Richardson * Rather than specifying a queue, this API passes along an opaque object 41599a2dd95SBruce Richardson * to the driver implementation. That object can be a queue or any other 41699a2dd95SBruce Richardson * contextual information necessary for the device to dequeue buffers. 41799a2dd95SBruce Richardson * 41899a2dd95SBruce Richardson * Application should have allocated enough space to store `count` response 41999a2dd95SBruce Richardson * buffers. 42099a2dd95SBruce Richardson * Releasing buffers dequeued is responsibility of the application. 42199a2dd95SBruce Richardson * 42299a2dd95SBruce Richardson * @param dev_id 42399a2dd95SBruce Richardson * The identifier of the device to configure. 42499a2dd95SBruce Richardson * @param buffers 42599a2dd95SBruce Richardson * Collection of buffers dequeued 42699a2dd95SBruce Richardson * @param count 42799a2dd95SBruce Richardson * Max buffers expected to be dequeued 42899a2dd95SBruce Richardson * @param context 42999a2dd95SBruce Richardson * Opaque context information. 43099a2dd95SBruce Richardson * @return 43199a2dd95SBruce Richardson * >=0 for buffers dequeued 43299a2dd95SBruce Richardson * !0 for failure. 43399a2dd95SBruce Richardson * Whether partial enqueue is failure or success is defined between app 43499a2dd95SBruce Richardson * and driver implementation. 43599a2dd95SBruce Richardson */ 43699a2dd95SBruce Richardson int 43799a2dd95SBruce Richardson rte_rawdev_dequeue_buffers(uint16_t dev_id, 43899a2dd95SBruce Richardson struct rte_rawdev_buf **buffers, 43999a2dd95SBruce Richardson unsigned int count, 44099a2dd95SBruce Richardson rte_rawdev_obj_t context); 44199a2dd95SBruce Richardson 44299a2dd95SBruce Richardson /** Maximum name length for extended statistics counters */ 44399a2dd95SBruce Richardson #define RTE_RAW_DEV_XSTATS_NAME_SIZE 64 44499a2dd95SBruce Richardson 44599a2dd95SBruce Richardson /** 44699a2dd95SBruce Richardson * A name-key lookup element for extended statistics. 44799a2dd95SBruce Richardson * 44899a2dd95SBruce Richardson * This structure is used to map between names and ID numbers 44999a2dd95SBruce Richardson * for extended ethdev statistics. 45099a2dd95SBruce Richardson */ 45199a2dd95SBruce Richardson struct rte_rawdev_xstats_name { 45299a2dd95SBruce Richardson char name[RTE_RAW_DEV_XSTATS_NAME_SIZE]; 45399a2dd95SBruce Richardson }; 45499a2dd95SBruce Richardson 45599a2dd95SBruce Richardson /** 45699a2dd95SBruce Richardson * Retrieve names of extended statistics of a raw device. 45799a2dd95SBruce Richardson * 45899a2dd95SBruce Richardson * @param dev_id 45999a2dd95SBruce Richardson * The identifier of the raw device. 46099a2dd95SBruce Richardson * @param[out] xstats_names 46199a2dd95SBruce Richardson * Block of memory to insert names into. Must be at least size in capacity. 46299a2dd95SBruce Richardson * If set to NULL, function returns required capacity. 46399a2dd95SBruce Richardson * @param size 46499a2dd95SBruce Richardson * Capacity of xstats_names (number of names). 46599a2dd95SBruce Richardson * @return 46699a2dd95SBruce Richardson * - positive value lower or equal to size: success. The return value 46799a2dd95SBruce Richardson * is the number of entries filled in the stats table. 46899a2dd95SBruce Richardson * - positive value higher than size: error, the given statistics table 46999a2dd95SBruce Richardson * is too small. The return value corresponds to the size that should 47099a2dd95SBruce Richardson * be given to succeed. The entries in the table are not valid and 47199a2dd95SBruce Richardson * shall not be used by the caller. 47299a2dd95SBruce Richardson * - negative value on error: 47399a2dd95SBruce Richardson * -ENODEV for invalid *dev_id* 47499a2dd95SBruce Richardson * -ENOTSUP if the device doesn't support this function. 47599a2dd95SBruce Richardson */ 47699a2dd95SBruce Richardson int 47799a2dd95SBruce Richardson rte_rawdev_xstats_names_get(uint16_t dev_id, 47899a2dd95SBruce Richardson struct rte_rawdev_xstats_name *xstats_names, 47999a2dd95SBruce Richardson unsigned int size); 48099a2dd95SBruce Richardson 48199a2dd95SBruce Richardson /** 48299a2dd95SBruce Richardson * Retrieve extended statistics of a raw device. 48399a2dd95SBruce Richardson * 48499a2dd95SBruce Richardson * @param dev_id 48599a2dd95SBruce Richardson * The identifier of the device. 48699a2dd95SBruce Richardson * @param ids 48799a2dd95SBruce Richardson * The id numbers of the stats to get. The ids can be got from the stat 48899a2dd95SBruce Richardson * position in the stat list from rte_rawdev_get_xstats_names(), or 48999a2dd95SBruce Richardson * by using rte_rawdev_get_xstats_by_name() 49099a2dd95SBruce Richardson * @param[out] values 49199a2dd95SBruce Richardson * The values for each stats request by ID. 49299a2dd95SBruce Richardson * @param n 49399a2dd95SBruce Richardson * The number of stats requested 49499a2dd95SBruce Richardson * @return 49599a2dd95SBruce Richardson * - positive value: number of stat entries filled into the values array 49699a2dd95SBruce Richardson * - negative value on error: 49799a2dd95SBruce Richardson * -ENODEV for invalid *dev_id* 49899a2dd95SBruce Richardson * -ENOTSUP if the device doesn't support this function. 49999a2dd95SBruce Richardson */ 50099a2dd95SBruce Richardson int 50199a2dd95SBruce Richardson rte_rawdev_xstats_get(uint16_t dev_id, 50299a2dd95SBruce Richardson const unsigned int ids[], 50399a2dd95SBruce Richardson uint64_t values[], 50499a2dd95SBruce Richardson unsigned int n); 50599a2dd95SBruce Richardson 50699a2dd95SBruce Richardson /** 50799a2dd95SBruce Richardson * Retrieve the value of a single stat by requesting it by name. 50899a2dd95SBruce Richardson * 50999a2dd95SBruce Richardson * @param dev_id 51099a2dd95SBruce Richardson * The identifier of the device 51199a2dd95SBruce Richardson * @param name 51299a2dd95SBruce Richardson * The stat name to retrieve 51399a2dd95SBruce Richardson * @param[out] id 51499a2dd95SBruce Richardson * If non-NULL, the numerical id of the stat will be returned, so that further 51599a2dd95SBruce Richardson * requests for the stat can be got using rte_rawdev_xstats_get, which will 51699a2dd95SBruce Richardson * be faster as it doesn't need to scan a list of names for the stat. 51799a2dd95SBruce Richardson * If the stat cannot be found, the id returned will be (unsigned)-1. 51899a2dd95SBruce Richardson * @return 51999a2dd95SBruce Richardson * - positive value or zero: the stat value 52099a2dd95SBruce Richardson * - negative value: -EINVAL if stat not found, -ENOTSUP if not supported. 52199a2dd95SBruce Richardson */ 52299a2dd95SBruce Richardson uint64_t 52399a2dd95SBruce Richardson rte_rawdev_xstats_by_name_get(uint16_t dev_id, 52499a2dd95SBruce Richardson const char *name, 52599a2dd95SBruce Richardson unsigned int *id); 52699a2dd95SBruce Richardson 52799a2dd95SBruce Richardson /** 52899a2dd95SBruce Richardson * Reset the values of the xstats of the selected component in the device. 52999a2dd95SBruce Richardson * 53099a2dd95SBruce Richardson * @param dev_id 53199a2dd95SBruce Richardson * The identifier of the device 53299a2dd95SBruce Richardson * @param ids 53399a2dd95SBruce Richardson * Selects specific statistics to be reset. When NULL, all statistics 53499a2dd95SBruce Richardson * will be reset. If non-NULL, must point to array of at least 53599a2dd95SBruce Richardson * *nb_ids* size. 53699a2dd95SBruce Richardson * @param nb_ids 53799a2dd95SBruce Richardson * The number of ids available from the *ids* array. Ignored when ids is NULL. 53899a2dd95SBruce Richardson * @return 53999a2dd95SBruce Richardson * - zero: successfully reset the statistics to zero 54099a2dd95SBruce Richardson * - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported. 54199a2dd95SBruce Richardson */ 54299a2dd95SBruce Richardson int 54399a2dd95SBruce Richardson rte_rawdev_xstats_reset(uint16_t dev_id, 54499a2dd95SBruce Richardson const uint32_t ids[], 54599a2dd95SBruce Richardson uint32_t nb_ids); 54699a2dd95SBruce Richardson 54799a2dd95SBruce Richardson /** 54899a2dd95SBruce Richardson * Get Firmware status of the device.. 54999a2dd95SBruce Richardson * Returns a memory allocated by driver/implementation containing status 55099a2dd95SBruce Richardson * information block. It is responsibility of caller to release the buffer. 55199a2dd95SBruce Richardson * 55299a2dd95SBruce Richardson * @param dev_id 55399a2dd95SBruce Richardson * Raw device identifier 55499a2dd95SBruce Richardson * @param status_info 55599a2dd95SBruce Richardson * Pointer to status information area. Caller is responsible for releasing 55699a2dd95SBruce Richardson * the memory associated. 55799a2dd95SBruce Richardson * @return 55899a2dd95SBruce Richardson * 0 for success, 55999a2dd95SBruce Richardson * !0 for failure, `status_info` argument state is undefined 56099a2dd95SBruce Richardson */ 56199a2dd95SBruce Richardson int 56299a2dd95SBruce Richardson rte_rawdev_firmware_status_get(uint16_t dev_id, 56399a2dd95SBruce Richardson rte_rawdev_obj_t status_info); 56499a2dd95SBruce Richardson 56599a2dd95SBruce Richardson /** 56699a2dd95SBruce Richardson * Get Firmware version of the device. 56799a2dd95SBruce Richardson * Returns a memory allocated by driver/implementation containing version 56899a2dd95SBruce Richardson * information block. It is responsibility of caller to release the buffer. 56999a2dd95SBruce Richardson * 57099a2dd95SBruce Richardson * @param dev_id 57199a2dd95SBruce Richardson * Raw device identifier 57299a2dd95SBruce Richardson * @param version_info 57399a2dd95SBruce Richardson * Pointer to version information area. Caller is responsible for releasing 57499a2dd95SBruce Richardson * the memory associated. 57599a2dd95SBruce Richardson * @return 57699a2dd95SBruce Richardson * 0 for success, 57799a2dd95SBruce Richardson * !0 for failure, `version_info` argument state is undefined 57899a2dd95SBruce Richardson */ 57999a2dd95SBruce Richardson int 58099a2dd95SBruce Richardson rte_rawdev_firmware_version_get(uint16_t dev_id, 58199a2dd95SBruce Richardson rte_rawdev_obj_t version_info); 58299a2dd95SBruce Richardson 58399a2dd95SBruce Richardson /** 58499a2dd95SBruce Richardson * Load firmware on the device. 58599a2dd95SBruce Richardson * TODO: In future, methods like directly flashing from file too can be 58699a2dd95SBruce Richardson * supported. 58799a2dd95SBruce Richardson * 58899a2dd95SBruce Richardson * @param dev_id 58999a2dd95SBruce Richardson * Raw device identifier 59099a2dd95SBruce Richardson * @param firmware_image 59199a2dd95SBruce Richardson * Pointer to buffer containing image binary data 59299a2dd95SBruce Richardson * @return 59399a2dd95SBruce Richardson * 0 for successful load 59499a2dd95SBruce Richardson * !0 for failure to load the provided image, or image incorrect. 59599a2dd95SBruce Richardson */ 59699a2dd95SBruce Richardson int 59799a2dd95SBruce Richardson rte_rawdev_firmware_load(uint16_t dev_id, rte_rawdev_obj_t firmware_image); 59899a2dd95SBruce Richardson 59999a2dd95SBruce Richardson /** 60099a2dd95SBruce Richardson * Unload firmware from the device. 60199a2dd95SBruce Richardson * 60299a2dd95SBruce Richardson * @param dev_id 60399a2dd95SBruce Richardson * Raw device identifiers 60499a2dd95SBruce Richardson * @return 60599a2dd95SBruce Richardson * 0 for successful Unload 60699a2dd95SBruce Richardson * !0 for failure in unloading 60799a2dd95SBruce Richardson */ 60899a2dd95SBruce Richardson int 60999a2dd95SBruce Richardson rte_rawdev_firmware_unload(uint16_t dev_id); 61099a2dd95SBruce Richardson 61199a2dd95SBruce Richardson /** 61299a2dd95SBruce Richardson * Trigger the rawdev self test. 61399a2dd95SBruce Richardson * 61499a2dd95SBruce Richardson * @param dev_id 61599a2dd95SBruce Richardson * The identifier of the device 61699a2dd95SBruce Richardson * @return 61799a2dd95SBruce Richardson * - 0: Selftest successful 61899a2dd95SBruce Richardson * - -ENOTSUP if the device doesn't support selftest 61999a2dd95SBruce Richardson * - other values < 0 on failure. 62099a2dd95SBruce Richardson */ 62199a2dd95SBruce Richardson int 62299a2dd95SBruce Richardson rte_rawdev_selftest(uint16_t dev_id); 62399a2dd95SBruce Richardson 62499a2dd95SBruce Richardson #ifdef __cplusplus 62599a2dd95SBruce Richardson } 62699a2dd95SBruce Richardson #endif 62799a2dd95SBruce Richardson 62899a2dd95SBruce Richardson #endif /* _RTE_RAWDEV_H_ */ 629