1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2*99a2dd95SBruce Richardson * Copyright 2017 NXP 3*99a2dd95SBruce Richardson */ 4*99a2dd95SBruce Richardson 5*99a2dd95SBruce Richardson #ifndef _RTE_RAWDEV_H_ 6*99a2dd95SBruce Richardson #define _RTE_RAWDEV_H_ 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson /** 9*99a2dd95SBruce Richardson * @file rte_rawdev.h 10*99a2dd95SBruce Richardson * 11*99a2dd95SBruce Richardson * Generic device abstraction APIs. 12*99a2dd95SBruce Richardson * 13*99a2dd95SBruce Richardson * This API allow applications to configure and use generic devices having 14*99a2dd95SBruce Richardson * no specific type already available in DPDK. 15*99a2dd95SBruce Richardson */ 16*99a2dd95SBruce Richardson 17*99a2dd95SBruce Richardson #ifdef __cplusplus 18*99a2dd95SBruce Richardson extern "C" { 19*99a2dd95SBruce Richardson #endif 20*99a2dd95SBruce Richardson 21*99a2dd95SBruce Richardson #include <rte_common.h> 22*99a2dd95SBruce Richardson #include <rte_memory.h> 23*99a2dd95SBruce Richardson #include <rte_errno.h> 24*99a2dd95SBruce Richardson 25*99a2dd95SBruce Richardson /* Rawdevice object - essentially a void to be typecast by implementation */ 26*99a2dd95SBruce Richardson typedef void *rte_rawdev_obj_t; 27*99a2dd95SBruce Richardson 28*99a2dd95SBruce Richardson /** 29*99a2dd95SBruce Richardson * Get the total number of raw devices that have been successfully 30*99a2dd95SBruce Richardson * initialised. 31*99a2dd95SBruce Richardson * 32*99a2dd95SBruce Richardson * @return 33*99a2dd95SBruce Richardson * The total number of usable raw devices. 34*99a2dd95SBruce Richardson */ 35*99a2dd95SBruce Richardson uint8_t 36*99a2dd95SBruce Richardson rte_rawdev_count(void); 37*99a2dd95SBruce Richardson 38*99a2dd95SBruce Richardson /** 39*99a2dd95SBruce Richardson * Get the device identifier for the named raw device. 40*99a2dd95SBruce Richardson * 41*99a2dd95SBruce Richardson * @param name 42*99a2dd95SBruce Richardson * Raw device name to select the raw device identifier. 43*99a2dd95SBruce Richardson * 44*99a2dd95SBruce Richardson * @return 45*99a2dd95SBruce Richardson * Returns raw device identifier on success. 46*99a2dd95SBruce Richardson * - <0: Failure to find named raw device. 47*99a2dd95SBruce Richardson */ 48*99a2dd95SBruce Richardson uint16_t 49*99a2dd95SBruce Richardson rte_rawdev_get_dev_id(const char *name); 50*99a2dd95SBruce Richardson 51*99a2dd95SBruce Richardson /** 52*99a2dd95SBruce Richardson * Return the NUMA socket to which a device is connected. 53*99a2dd95SBruce Richardson * 54*99a2dd95SBruce Richardson * @param dev_id 55*99a2dd95SBruce Richardson * The identifier of the device. 56*99a2dd95SBruce Richardson * @return 57*99a2dd95SBruce Richardson * The NUMA socket id to which the device is connected or 58*99a2dd95SBruce Richardson * a default of zero if the socket could not be determined. 59*99a2dd95SBruce Richardson * -(-EINVAL) dev_id value is out of range. 60*99a2dd95SBruce Richardson */ 61*99a2dd95SBruce Richardson int 62*99a2dd95SBruce Richardson rte_rawdev_socket_id(uint16_t dev_id); 63*99a2dd95SBruce Richardson 64*99a2dd95SBruce Richardson /** 65*99a2dd95SBruce Richardson * Raw device information forward declaration 66*99a2dd95SBruce Richardson */ 67*99a2dd95SBruce Richardson struct rte_rawdev_info; 68*99a2dd95SBruce Richardson 69*99a2dd95SBruce Richardson /** 70*99a2dd95SBruce Richardson * Retrieve the contextual information of a raw device. 71*99a2dd95SBruce Richardson * 72*99a2dd95SBruce Richardson * @param dev_id 73*99a2dd95SBruce Richardson * The identifier of the device. 74*99a2dd95SBruce Richardson * 75*99a2dd95SBruce Richardson * @param[out] dev_info 76*99a2dd95SBruce Richardson * A pointer to a structure of type *rte_rawdev_info* to be filled with the 77*99a2dd95SBruce Richardson * contextual information of the device. The dev_info->dev_private field 78*99a2dd95SBruce Richardson * should point to an appropriate buffer space for holding the device- 79*99a2dd95SBruce Richardson * specific info for that hardware. 80*99a2dd95SBruce Richardson * If the dev_private field is set to NULL, then the device-specific info 81*99a2dd95SBruce Richardson * function will not be called and only basic information about the device 82*99a2dd95SBruce Richardson * will be returned. This can be used to safely query the type of a rawdev 83*99a2dd95SBruce Richardson * instance without needing to know the size of the private data to return. 84*99a2dd95SBruce Richardson * 85*99a2dd95SBruce Richardson * @param dev_private_size 86*99a2dd95SBruce Richardson * The length of the memory space pointed to by dev_private in dev_info. 87*99a2dd95SBruce Richardson * This should be set to the size of the expected private structure to be 88*99a2dd95SBruce Richardson * returned, and may be checked by drivers to ensure the expected struct 89*99a2dd95SBruce Richardson * type is provided. 90*99a2dd95SBruce Richardson * 91*99a2dd95SBruce Richardson * @return 92*99a2dd95SBruce Richardson * - 0: Success, driver updates the contextual information of the raw device 93*99a2dd95SBruce Richardson * - <0: Error code returned by the driver info get function. 94*99a2dd95SBruce Richardson * 95*99a2dd95SBruce Richardson */ 96*99a2dd95SBruce Richardson int 97*99a2dd95SBruce Richardson rte_rawdev_info_get(uint16_t dev_id, struct rte_rawdev_info *dev_info, 98*99a2dd95SBruce Richardson size_t dev_private_size); 99*99a2dd95SBruce Richardson 100*99a2dd95SBruce Richardson /** 101*99a2dd95SBruce Richardson * Configure a raw device. 102*99a2dd95SBruce Richardson * 103*99a2dd95SBruce Richardson * This function must be invoked first before any other function in the 104*99a2dd95SBruce Richardson * API. This function can also be re-invoked when a device is in the 105*99a2dd95SBruce Richardson * stopped state. 106*99a2dd95SBruce Richardson * 107*99a2dd95SBruce Richardson * The caller may use rte_rawdev_info_get() to get the capability of each 108*99a2dd95SBruce Richardson * resources available for this raw device. 109*99a2dd95SBruce Richardson * 110*99a2dd95SBruce Richardson * @param dev_id 111*99a2dd95SBruce Richardson * The identifier of the device to configure. 112*99a2dd95SBruce Richardson * @param dev_conf 113*99a2dd95SBruce Richardson * The raw device configuration structure encapsulated into rte_rawdev_info 114*99a2dd95SBruce Richardson * object. 115*99a2dd95SBruce Richardson * It is assumed that the opaque object has enough information which the 116*99a2dd95SBruce Richardson * driver/implementation can use to configure the device. It is also assumed 117*99a2dd95SBruce Richardson * that once the configuration is done, a `queue_id` type field can be used 118*99a2dd95SBruce Richardson * to refer to some arbitrary internal representation of a queue. 119*99a2dd95SBruce Richardson * @param dev_private_size 120*99a2dd95SBruce Richardson * The length of the memory space pointed to by dev_private in dev_info. 121*99a2dd95SBruce Richardson * This should be set to the size of the expected private structure to be 122*99a2dd95SBruce Richardson * used by the driver, and may be checked by drivers to ensure the expected 123*99a2dd95SBruce Richardson * struct type is provided. 124*99a2dd95SBruce Richardson * 125*99a2dd95SBruce Richardson * @return 126*99a2dd95SBruce Richardson * - 0: Success, device configured. 127*99a2dd95SBruce Richardson * - <0: Error code returned by the driver configuration function. 128*99a2dd95SBruce Richardson */ 129*99a2dd95SBruce Richardson int 130*99a2dd95SBruce Richardson rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf, 131*99a2dd95SBruce Richardson size_t dev_private_size); 132*99a2dd95SBruce Richardson 133*99a2dd95SBruce Richardson 134*99a2dd95SBruce Richardson /** 135*99a2dd95SBruce Richardson * Retrieve the current configuration information of a raw queue designated 136*99a2dd95SBruce Richardson * by its *queue_id* from the raw driver for a raw device. 137*99a2dd95SBruce Richardson * 138*99a2dd95SBruce Richardson * This function intended to be used in conjunction with rte_raw_queue_setup() 139*99a2dd95SBruce Richardson * where caller needs to set up the queue by overriding few default values. 140*99a2dd95SBruce Richardson * 141*99a2dd95SBruce Richardson * @param dev_id 142*99a2dd95SBruce Richardson * The identifier of the device. 143*99a2dd95SBruce Richardson * @param queue_id 144*99a2dd95SBruce Richardson * The index of the raw queue to get the configuration information. 145*99a2dd95SBruce Richardson * The value must be in the range [0, nb_raw_queues - 1] 146*99a2dd95SBruce Richardson * previously supplied to rte_rawdev_configure(). 147*99a2dd95SBruce Richardson * @param[out] queue_conf 148*99a2dd95SBruce Richardson * The pointer to the default raw queue configuration data. 149*99a2dd95SBruce Richardson * @param queue_conf_size 150*99a2dd95SBruce Richardson * The size of the structure pointed to by queue_conf 151*99a2dd95SBruce Richardson * @return 152*99a2dd95SBruce Richardson * - 0: Success, driver updates the default raw queue configuration data. 153*99a2dd95SBruce Richardson * - <0: Error code returned by the driver info get function. 154*99a2dd95SBruce Richardson * 155*99a2dd95SBruce Richardson * @see rte_raw_queue_setup() 156*99a2dd95SBruce Richardson * 157*99a2dd95SBruce Richardson */ 158*99a2dd95SBruce Richardson int 159*99a2dd95SBruce Richardson rte_rawdev_queue_conf_get(uint16_t dev_id, 160*99a2dd95SBruce Richardson uint16_t queue_id, 161*99a2dd95SBruce Richardson rte_rawdev_obj_t queue_conf, 162*99a2dd95SBruce Richardson size_t queue_conf_size); 163*99a2dd95SBruce Richardson 164*99a2dd95SBruce Richardson /** 165*99a2dd95SBruce Richardson * Allocate and set up a raw queue for a raw device. 166*99a2dd95SBruce Richardson * 167*99a2dd95SBruce Richardson * @param dev_id 168*99a2dd95SBruce Richardson * The identifier of the device. 169*99a2dd95SBruce Richardson * @param queue_id 170*99a2dd95SBruce Richardson * The index of the raw queue to setup. The value must be in the range 171*99a2dd95SBruce Richardson * [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure(). 172*99a2dd95SBruce Richardson * @param queue_conf 173*99a2dd95SBruce Richardson * The pointer to the configuration data to be used for the raw queue. 174*99a2dd95SBruce Richardson * NULL value is allowed, in which case default configuration used. 175*99a2dd95SBruce Richardson * @param queue_conf_size 176*99a2dd95SBruce Richardson * The size of the structure pointed to by queue_conf 177*99a2dd95SBruce Richardson * 178*99a2dd95SBruce Richardson * @see rte_rawdev_queue_conf_get() 179*99a2dd95SBruce Richardson * 180*99a2dd95SBruce Richardson * @return 181*99a2dd95SBruce Richardson * - 0: Success, raw queue correctly set up. 182*99a2dd95SBruce Richardson * - <0: raw queue configuration failed 183*99a2dd95SBruce Richardson */ 184*99a2dd95SBruce Richardson int 185*99a2dd95SBruce Richardson rte_rawdev_queue_setup(uint16_t dev_id, 186*99a2dd95SBruce Richardson uint16_t queue_id, 187*99a2dd95SBruce Richardson rte_rawdev_obj_t queue_conf, 188*99a2dd95SBruce Richardson size_t queue_conf_size); 189*99a2dd95SBruce Richardson 190*99a2dd95SBruce Richardson /** 191*99a2dd95SBruce Richardson * Release and deallocate a raw queue from a raw device. 192*99a2dd95SBruce Richardson * 193*99a2dd95SBruce Richardson * @param dev_id 194*99a2dd95SBruce Richardson * The identifier of the device. 195*99a2dd95SBruce Richardson * @param queue_id 196*99a2dd95SBruce Richardson * The index of the raw queue to release. The value must be in the range 197*99a2dd95SBruce Richardson * [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure(). 198*99a2dd95SBruce Richardson * 199*99a2dd95SBruce Richardson * @see rte_rawdev_queue_conf_get() 200*99a2dd95SBruce Richardson * 201*99a2dd95SBruce Richardson * @return 202*99a2dd95SBruce Richardson * - 0: Success, raw queue released. 203*99a2dd95SBruce Richardson * - <0: raw queue configuration failed 204*99a2dd95SBruce Richardson */ 205*99a2dd95SBruce Richardson int 206*99a2dd95SBruce Richardson rte_rawdev_queue_release(uint16_t dev_id, uint16_t queue_id); 207*99a2dd95SBruce Richardson 208*99a2dd95SBruce Richardson /** 209*99a2dd95SBruce Richardson * Get the number of raw queues on a specific raw device 210*99a2dd95SBruce Richardson * 211*99a2dd95SBruce Richardson * @param dev_id 212*99a2dd95SBruce Richardson * Raw device identifier. 213*99a2dd95SBruce Richardson * @return 214*99a2dd95SBruce Richardson * - The number of configured raw queues 215*99a2dd95SBruce Richardson */ 216*99a2dd95SBruce Richardson uint16_t 217*99a2dd95SBruce Richardson rte_rawdev_queue_count(uint16_t dev_id); 218*99a2dd95SBruce Richardson 219*99a2dd95SBruce Richardson /** 220*99a2dd95SBruce Richardson * Start a raw device. 221*99a2dd95SBruce Richardson * 222*99a2dd95SBruce Richardson * The device start step is the last one and consists of setting the raw 223*99a2dd95SBruce Richardson * queues to start accepting the raws and schedules to raw ports. 224*99a2dd95SBruce Richardson * 225*99a2dd95SBruce Richardson * On success, all basic functions exported by the API (raw enqueue, 226*99a2dd95SBruce Richardson * raw dequeue and so on) can be invoked. 227*99a2dd95SBruce Richardson * 228*99a2dd95SBruce Richardson * @param dev_id 229*99a2dd95SBruce Richardson * Raw device identifier 230*99a2dd95SBruce Richardson * @return 231*99a2dd95SBruce Richardson * - 0: Success, device started. 232*99a2dd95SBruce Richardson * < 0: Failure 233*99a2dd95SBruce Richardson */ 234*99a2dd95SBruce Richardson int 235*99a2dd95SBruce Richardson rte_rawdev_start(uint16_t dev_id); 236*99a2dd95SBruce Richardson 237*99a2dd95SBruce Richardson /** 238*99a2dd95SBruce Richardson * Stop a raw device. The device can be restarted with a call to 239*99a2dd95SBruce Richardson * rte_rawdev_start() 240*99a2dd95SBruce Richardson * 241*99a2dd95SBruce Richardson * @param dev_id 242*99a2dd95SBruce Richardson * Raw device identifier. 243*99a2dd95SBruce Richardson */ 244*99a2dd95SBruce Richardson void 245*99a2dd95SBruce Richardson rte_rawdev_stop(uint16_t dev_id); 246*99a2dd95SBruce Richardson 247*99a2dd95SBruce Richardson /** 248*99a2dd95SBruce Richardson * Close a raw device. The device cannot be restarted after this call. 249*99a2dd95SBruce Richardson * 250*99a2dd95SBruce Richardson * @param dev_id 251*99a2dd95SBruce Richardson * Raw device identifier 252*99a2dd95SBruce Richardson * 253*99a2dd95SBruce Richardson * @return 254*99a2dd95SBruce Richardson * - 0 on successfully closing device 255*99a2dd95SBruce Richardson * - <0 on failure to close device 256*99a2dd95SBruce Richardson * - (-EAGAIN) if device is busy 257*99a2dd95SBruce Richardson */ 258*99a2dd95SBruce Richardson int 259*99a2dd95SBruce Richardson rte_rawdev_close(uint16_t dev_id); 260*99a2dd95SBruce Richardson 261*99a2dd95SBruce Richardson /** 262*99a2dd95SBruce Richardson * Reset a raw device. 263*99a2dd95SBruce Richardson * This is different from cycle of rte_rawdev_start->rte_rawdev_stop in the 264*99a2dd95SBruce Richardson * sense similar to hard or soft reset. 265*99a2dd95SBruce Richardson * 266*99a2dd95SBruce Richardson * @param dev_id 267*99a2dd95SBruce Richardson * Raw device identifiers 268*99a2dd95SBruce Richardson * @return 269*99a2dd95SBruce Richardson * 0 for successful reset, 270*99a2dd95SBruce Richardson * !0 for failure in resetting 271*99a2dd95SBruce Richardson */ 272*99a2dd95SBruce Richardson int 273*99a2dd95SBruce Richardson rte_rawdev_reset(uint16_t dev_id); 274*99a2dd95SBruce Richardson 275*99a2dd95SBruce Richardson #define RTE_RAWDEV_NAME_MAX_LEN (64) 276*99a2dd95SBruce Richardson /**< @internal Max length of name of raw PMD */ 277*99a2dd95SBruce Richardson 278*99a2dd95SBruce Richardson 279*99a2dd95SBruce Richardson 280*99a2dd95SBruce Richardson /** @internal 281*99a2dd95SBruce Richardson * The data structure associated with each raw device. 282*99a2dd95SBruce Richardson * It is a placeholder for PMD specific data, encapsulating only information 283*99a2dd95SBruce Richardson * related to framework. 284*99a2dd95SBruce Richardson */ 285*99a2dd95SBruce Richardson struct rte_rawdev { 286*99a2dd95SBruce Richardson /**< Socket ID where memory is allocated */ 287*99a2dd95SBruce Richardson int socket_id; 288*99a2dd95SBruce Richardson /**< Device ID for this instance */ 289*99a2dd95SBruce Richardson uint16_t dev_id; 290*99a2dd95SBruce Richardson /**< Functions exported by PMD */ 291*99a2dd95SBruce Richardson const struct rte_rawdev_ops *dev_ops; 292*99a2dd95SBruce Richardson /**< Device info. supplied during device initialization */ 293*99a2dd95SBruce Richardson struct rte_device *device; 294*99a2dd95SBruce Richardson /**< Driver info. supplied by probing */ 295*99a2dd95SBruce Richardson const char *driver_name; 296*99a2dd95SBruce Richardson 297*99a2dd95SBruce Richardson RTE_STD_C11 298*99a2dd95SBruce Richardson /**< Flag indicating the device is attached */ 299*99a2dd95SBruce Richardson uint8_t attached : 1; 300*99a2dd95SBruce Richardson /**< Device state: STARTED(1)/STOPPED(0) */ 301*99a2dd95SBruce Richardson uint8_t started : 1; 302*99a2dd95SBruce Richardson 303*99a2dd95SBruce Richardson /**< PMD-specific private data */ 304*99a2dd95SBruce Richardson rte_rawdev_obj_t dev_private; 305*99a2dd95SBruce Richardson /**< Device name */ 306*99a2dd95SBruce Richardson char name[RTE_RAWDEV_NAME_MAX_LEN]; 307*99a2dd95SBruce Richardson } __rte_cache_aligned; 308*99a2dd95SBruce Richardson 309*99a2dd95SBruce Richardson /** @internal The pool of rte_rawdev structures. */ 310*99a2dd95SBruce Richardson extern struct rte_rawdev *rte_rawdevs; 311*99a2dd95SBruce Richardson 312*99a2dd95SBruce Richardson 313*99a2dd95SBruce Richardson struct rte_rawdev_info { 314*99a2dd95SBruce Richardson /**< Name of driver handling this device */ 315*99a2dd95SBruce Richardson const char *driver_name; 316*99a2dd95SBruce Richardson /**< Device encapsulation */ 317*99a2dd95SBruce Richardson struct rte_device *device; 318*99a2dd95SBruce Richardson /**< Socket ID where memory is allocated */ 319*99a2dd95SBruce Richardson int socket_id; 320*99a2dd95SBruce Richardson /**< PMD-specific private data */ 321*99a2dd95SBruce Richardson rte_rawdev_obj_t dev_private; 322*99a2dd95SBruce Richardson }; 323*99a2dd95SBruce Richardson 324*99a2dd95SBruce Richardson struct rte_rawdev_buf { 325*99a2dd95SBruce Richardson /**< Opaque buffer reference */ 326*99a2dd95SBruce Richardson void *buf_addr; 327*99a2dd95SBruce Richardson }; 328*99a2dd95SBruce Richardson 329*99a2dd95SBruce Richardson /** 330*99a2dd95SBruce Richardson * Dump internal information about *dev_id* to the FILE* provided in *f*. 331*99a2dd95SBruce Richardson * 332*99a2dd95SBruce Richardson * @param dev_id 333*99a2dd95SBruce Richardson * The identifier of the device. 334*99a2dd95SBruce Richardson * 335*99a2dd95SBruce Richardson * @param f 336*99a2dd95SBruce Richardson * A pointer to a file for output 337*99a2dd95SBruce Richardson * 338*99a2dd95SBruce Richardson * @return 339*99a2dd95SBruce Richardson * - 0: on success 340*99a2dd95SBruce Richardson * - <0: on failure. 341*99a2dd95SBruce Richardson */ 342*99a2dd95SBruce Richardson int 343*99a2dd95SBruce Richardson rte_rawdev_dump(uint16_t dev_id, FILE *f); 344*99a2dd95SBruce Richardson 345*99a2dd95SBruce Richardson /** 346*99a2dd95SBruce Richardson * Get an attribute value from implementation. 347*99a2dd95SBruce Richardson * Attribute is an opaque handle agreed upon between application and PMD. 348*99a2dd95SBruce Richardson * 349*99a2dd95SBruce Richardson * Implementations are expected to maintain an array of attribute-value pairs 350*99a2dd95SBruce Richardson * based on application calls. Memory management for this structure is 351*99a2dd95SBruce Richardson * shared responsibility of implementation and application. 352*99a2dd95SBruce Richardson * 353*99a2dd95SBruce Richardson * @param dev_id 354*99a2dd95SBruce Richardson * The identifier of the device to configure. 355*99a2dd95SBruce Richardson * @param attr_name 356*99a2dd95SBruce Richardson * Opaque object representing an attribute in implementation. 357*99a2dd95SBruce Richardson * @param attr_value [out] 358*99a2dd95SBruce Richardson * Opaque response to the attribute value. In case of error, this remains 359*99a2dd95SBruce Richardson * untouched. This is double pointer of void type. 360*99a2dd95SBruce Richardson * @return 361*99a2dd95SBruce Richardson * 0 for success 362*99a2dd95SBruce Richardson * !0 Error; attr_value remains untouched in case of error. 363*99a2dd95SBruce Richardson */ 364*99a2dd95SBruce Richardson int 365*99a2dd95SBruce Richardson rte_rawdev_get_attr(uint16_t dev_id, 366*99a2dd95SBruce Richardson const char *attr_name, 367*99a2dd95SBruce Richardson uint64_t *attr_value); 368*99a2dd95SBruce Richardson 369*99a2dd95SBruce Richardson /** 370*99a2dd95SBruce Richardson * Set an attribute value. 371*99a2dd95SBruce Richardson * Attribute is an opaque handle agreed upon between application and PMD. 372*99a2dd95SBruce Richardson * 373*99a2dd95SBruce Richardson * @param dev_id 374*99a2dd95SBruce Richardson * The identifier of the device to configure. 375*99a2dd95SBruce Richardson * @param attr_name 376*99a2dd95SBruce Richardson * Opaque object representing an attribute in implementation. 377*99a2dd95SBruce Richardson * @param attr_value 378*99a2dd95SBruce Richardson * Value of the attribute represented by attr_name 379*99a2dd95SBruce Richardson * @return 380*99a2dd95SBruce Richardson * 0 for success 381*99a2dd95SBruce Richardson * !0 Error 382*99a2dd95SBruce Richardson */ 383*99a2dd95SBruce Richardson int 384*99a2dd95SBruce Richardson rte_rawdev_set_attr(uint16_t dev_id, 385*99a2dd95SBruce Richardson const char *attr_name, 386*99a2dd95SBruce Richardson const uint64_t attr_value); 387*99a2dd95SBruce Richardson 388*99a2dd95SBruce Richardson /** 389*99a2dd95SBruce Richardson * Enqueue a stream of buffers to the device. 390*99a2dd95SBruce Richardson * 391*99a2dd95SBruce Richardson * Rather than specifying a queue, this API passes along an opaque object 392*99a2dd95SBruce Richardson * to the driver implementation. That object can be a queue or any other 393*99a2dd95SBruce Richardson * contextual information necessary for the device to enqueue buffers. 394*99a2dd95SBruce Richardson * 395*99a2dd95SBruce Richardson * @param dev_id 396*99a2dd95SBruce Richardson * The identifier of the device to configure. 397*99a2dd95SBruce Richardson * @param buffers 398*99a2dd95SBruce Richardson * Collection of buffers for enqueuing 399*99a2dd95SBruce Richardson * @param count 400*99a2dd95SBruce Richardson * Count of buffers to enqueue 401*99a2dd95SBruce Richardson * @param context 402*99a2dd95SBruce Richardson * Opaque context information. 403*99a2dd95SBruce Richardson * @return 404*99a2dd95SBruce Richardson * >=0 for buffers enqueued 405*99a2dd95SBruce Richardson * !0 for failure. 406*99a2dd95SBruce Richardson * Whether partial enqueue is failure or success is defined between app 407*99a2dd95SBruce Richardson * and driver implementation. 408*99a2dd95SBruce Richardson */ 409*99a2dd95SBruce Richardson int 410*99a2dd95SBruce Richardson rte_rawdev_enqueue_buffers(uint16_t dev_id, 411*99a2dd95SBruce Richardson struct rte_rawdev_buf **buffers, 412*99a2dd95SBruce Richardson unsigned int count, 413*99a2dd95SBruce Richardson rte_rawdev_obj_t context); 414*99a2dd95SBruce Richardson 415*99a2dd95SBruce Richardson /** 416*99a2dd95SBruce Richardson * Dequeue a stream of buffers from the device. 417*99a2dd95SBruce Richardson * 418*99a2dd95SBruce Richardson * Rather than specifying a queue, this API passes along an opaque object 419*99a2dd95SBruce Richardson * to the driver implementation. That object can be a queue or any other 420*99a2dd95SBruce Richardson * contextual information necessary for the device to dequeue buffers. 421*99a2dd95SBruce Richardson * 422*99a2dd95SBruce Richardson * Application should have allocated enough space to store `count` response 423*99a2dd95SBruce Richardson * buffers. 424*99a2dd95SBruce Richardson * Releasing buffers dequeued is responsibility of the application. 425*99a2dd95SBruce Richardson * 426*99a2dd95SBruce Richardson * @param dev_id 427*99a2dd95SBruce Richardson * The identifier of the device to configure. 428*99a2dd95SBruce Richardson * @param buffers 429*99a2dd95SBruce Richardson * Collection of buffers dequeued 430*99a2dd95SBruce Richardson * @param count 431*99a2dd95SBruce Richardson * Max buffers expected to be dequeued 432*99a2dd95SBruce Richardson * @param context 433*99a2dd95SBruce Richardson * Opaque context information. 434*99a2dd95SBruce Richardson * @return 435*99a2dd95SBruce Richardson * >=0 for buffers dequeued 436*99a2dd95SBruce Richardson * !0 for failure. 437*99a2dd95SBruce Richardson * Whether partial enqueue is failure or success is defined between app 438*99a2dd95SBruce Richardson * and driver implementation. 439*99a2dd95SBruce Richardson */ 440*99a2dd95SBruce Richardson int 441*99a2dd95SBruce Richardson rte_rawdev_dequeue_buffers(uint16_t dev_id, 442*99a2dd95SBruce Richardson struct rte_rawdev_buf **buffers, 443*99a2dd95SBruce Richardson unsigned int count, 444*99a2dd95SBruce Richardson rte_rawdev_obj_t context); 445*99a2dd95SBruce Richardson 446*99a2dd95SBruce Richardson /** Maximum name length for extended statistics counters */ 447*99a2dd95SBruce Richardson #define RTE_RAW_DEV_XSTATS_NAME_SIZE 64 448*99a2dd95SBruce Richardson 449*99a2dd95SBruce Richardson /** 450*99a2dd95SBruce Richardson * A name-key lookup element for extended statistics. 451*99a2dd95SBruce Richardson * 452*99a2dd95SBruce Richardson * This structure is used to map between names and ID numbers 453*99a2dd95SBruce Richardson * for extended ethdev statistics. 454*99a2dd95SBruce Richardson */ 455*99a2dd95SBruce Richardson struct rte_rawdev_xstats_name { 456*99a2dd95SBruce Richardson char name[RTE_RAW_DEV_XSTATS_NAME_SIZE]; 457*99a2dd95SBruce Richardson }; 458*99a2dd95SBruce Richardson 459*99a2dd95SBruce Richardson /** 460*99a2dd95SBruce Richardson * Retrieve names of extended statistics of a raw device. 461*99a2dd95SBruce Richardson * 462*99a2dd95SBruce Richardson * @param dev_id 463*99a2dd95SBruce Richardson * The identifier of the raw device. 464*99a2dd95SBruce Richardson * @param[out] xstats_names 465*99a2dd95SBruce Richardson * Block of memory to insert names into. Must be at least size in capacity. 466*99a2dd95SBruce Richardson * If set to NULL, function returns required capacity. 467*99a2dd95SBruce Richardson * @param size 468*99a2dd95SBruce Richardson * Capacity of xstats_names (number of names). 469*99a2dd95SBruce Richardson * @return 470*99a2dd95SBruce Richardson * - positive value lower or equal to size: success. The return value 471*99a2dd95SBruce Richardson * is the number of entries filled in the stats table. 472*99a2dd95SBruce Richardson * - positive value higher than size: error, the given statistics table 473*99a2dd95SBruce Richardson * is too small. The return value corresponds to the size that should 474*99a2dd95SBruce Richardson * be given to succeed. The entries in the table are not valid and 475*99a2dd95SBruce Richardson * shall not be used by the caller. 476*99a2dd95SBruce Richardson * - negative value on error: 477*99a2dd95SBruce Richardson * -ENODEV for invalid *dev_id* 478*99a2dd95SBruce Richardson * -ENOTSUP if the device doesn't support this function. 479*99a2dd95SBruce Richardson */ 480*99a2dd95SBruce Richardson int 481*99a2dd95SBruce Richardson rte_rawdev_xstats_names_get(uint16_t dev_id, 482*99a2dd95SBruce Richardson struct rte_rawdev_xstats_name *xstats_names, 483*99a2dd95SBruce Richardson unsigned int size); 484*99a2dd95SBruce Richardson 485*99a2dd95SBruce Richardson /** 486*99a2dd95SBruce Richardson * Retrieve extended statistics of a raw device. 487*99a2dd95SBruce Richardson * 488*99a2dd95SBruce Richardson * @param dev_id 489*99a2dd95SBruce Richardson * The identifier of the device. 490*99a2dd95SBruce Richardson * @param ids 491*99a2dd95SBruce Richardson * The id numbers of the stats to get. The ids can be got from the stat 492*99a2dd95SBruce Richardson * position in the stat list from rte_rawdev_get_xstats_names(), or 493*99a2dd95SBruce Richardson * by using rte_rawdev_get_xstats_by_name() 494*99a2dd95SBruce Richardson * @param[out] values 495*99a2dd95SBruce Richardson * The values for each stats request by ID. 496*99a2dd95SBruce Richardson * @param n 497*99a2dd95SBruce Richardson * The number of stats requested 498*99a2dd95SBruce Richardson * @return 499*99a2dd95SBruce Richardson * - positive value: number of stat entries filled into the values array 500*99a2dd95SBruce Richardson * - negative value on error: 501*99a2dd95SBruce Richardson * -ENODEV for invalid *dev_id* 502*99a2dd95SBruce Richardson * -ENOTSUP if the device doesn't support this function. 503*99a2dd95SBruce Richardson */ 504*99a2dd95SBruce Richardson int 505*99a2dd95SBruce Richardson rte_rawdev_xstats_get(uint16_t dev_id, 506*99a2dd95SBruce Richardson const unsigned int ids[], 507*99a2dd95SBruce Richardson uint64_t values[], 508*99a2dd95SBruce Richardson unsigned int n); 509*99a2dd95SBruce Richardson 510*99a2dd95SBruce Richardson /** 511*99a2dd95SBruce Richardson * Retrieve the value of a single stat by requesting it by name. 512*99a2dd95SBruce Richardson * 513*99a2dd95SBruce Richardson * @param dev_id 514*99a2dd95SBruce Richardson * The identifier of the device 515*99a2dd95SBruce Richardson * @param name 516*99a2dd95SBruce Richardson * The stat name to retrieve 517*99a2dd95SBruce Richardson * @param[out] id 518*99a2dd95SBruce Richardson * If non-NULL, the numerical id of the stat will be returned, so that further 519*99a2dd95SBruce Richardson * requests for the stat can be got using rte_rawdev_xstats_get, which will 520*99a2dd95SBruce Richardson * be faster as it doesn't need to scan a list of names for the stat. 521*99a2dd95SBruce Richardson * If the stat cannot be found, the id returned will be (unsigned)-1. 522*99a2dd95SBruce Richardson * @return 523*99a2dd95SBruce Richardson * - positive value or zero: the stat value 524*99a2dd95SBruce Richardson * - negative value: -EINVAL if stat not found, -ENOTSUP if not supported. 525*99a2dd95SBruce Richardson */ 526*99a2dd95SBruce Richardson uint64_t 527*99a2dd95SBruce Richardson rte_rawdev_xstats_by_name_get(uint16_t dev_id, 528*99a2dd95SBruce Richardson const char *name, 529*99a2dd95SBruce Richardson unsigned int *id); 530*99a2dd95SBruce Richardson 531*99a2dd95SBruce Richardson /** 532*99a2dd95SBruce Richardson * Reset the values of the xstats of the selected component in the device. 533*99a2dd95SBruce Richardson * 534*99a2dd95SBruce Richardson * @param dev_id 535*99a2dd95SBruce Richardson * The identifier of the device 536*99a2dd95SBruce Richardson * @param ids 537*99a2dd95SBruce Richardson * Selects specific statistics to be reset. When NULL, all statistics 538*99a2dd95SBruce Richardson * will be reset. If non-NULL, must point to array of at least 539*99a2dd95SBruce Richardson * *nb_ids* size. 540*99a2dd95SBruce Richardson * @param nb_ids 541*99a2dd95SBruce Richardson * The number of ids available from the *ids* array. Ignored when ids is NULL. 542*99a2dd95SBruce Richardson * @return 543*99a2dd95SBruce Richardson * - zero: successfully reset the statistics to zero 544*99a2dd95SBruce Richardson * - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported. 545*99a2dd95SBruce Richardson */ 546*99a2dd95SBruce Richardson int 547*99a2dd95SBruce Richardson rte_rawdev_xstats_reset(uint16_t dev_id, 548*99a2dd95SBruce Richardson const uint32_t ids[], 549*99a2dd95SBruce Richardson uint32_t nb_ids); 550*99a2dd95SBruce Richardson 551*99a2dd95SBruce Richardson /** 552*99a2dd95SBruce Richardson * Get Firmware status of the device.. 553*99a2dd95SBruce Richardson * Returns a memory allocated by driver/implementation containing status 554*99a2dd95SBruce Richardson * information block. It is responsibility of caller to release the buffer. 555*99a2dd95SBruce Richardson * 556*99a2dd95SBruce Richardson * @param dev_id 557*99a2dd95SBruce Richardson * Raw device identifier 558*99a2dd95SBruce Richardson * @param status_info 559*99a2dd95SBruce Richardson * Pointer to status information area. Caller is responsible for releasing 560*99a2dd95SBruce Richardson * the memory associated. 561*99a2dd95SBruce Richardson * @return 562*99a2dd95SBruce Richardson * 0 for success, 563*99a2dd95SBruce Richardson * !0 for failure, `status_info` argument state is undefined 564*99a2dd95SBruce Richardson */ 565*99a2dd95SBruce Richardson int 566*99a2dd95SBruce Richardson rte_rawdev_firmware_status_get(uint16_t dev_id, 567*99a2dd95SBruce Richardson rte_rawdev_obj_t status_info); 568*99a2dd95SBruce Richardson 569*99a2dd95SBruce Richardson /** 570*99a2dd95SBruce Richardson * Get Firmware version of the device. 571*99a2dd95SBruce Richardson * Returns a memory allocated by driver/implementation containing version 572*99a2dd95SBruce Richardson * information block. It is responsibility of caller to release the buffer. 573*99a2dd95SBruce Richardson * 574*99a2dd95SBruce Richardson * @param dev_id 575*99a2dd95SBruce Richardson * Raw device identifier 576*99a2dd95SBruce Richardson * @param version_info 577*99a2dd95SBruce Richardson * Pointer to version information area. Caller is responsible for releasing 578*99a2dd95SBruce Richardson * the memory associated. 579*99a2dd95SBruce Richardson * @return 580*99a2dd95SBruce Richardson * 0 for success, 581*99a2dd95SBruce Richardson * !0 for failure, `version_info` argument state is undefined 582*99a2dd95SBruce Richardson */ 583*99a2dd95SBruce Richardson int 584*99a2dd95SBruce Richardson rte_rawdev_firmware_version_get(uint16_t dev_id, 585*99a2dd95SBruce Richardson rte_rawdev_obj_t version_info); 586*99a2dd95SBruce Richardson 587*99a2dd95SBruce Richardson /** 588*99a2dd95SBruce Richardson * Load firmware on the device. 589*99a2dd95SBruce Richardson * TODO: In future, methods like directly flashing from file too can be 590*99a2dd95SBruce Richardson * supported. 591*99a2dd95SBruce Richardson * 592*99a2dd95SBruce Richardson * @param dev_id 593*99a2dd95SBruce Richardson * Raw device identifier 594*99a2dd95SBruce Richardson * @param firmware_image 595*99a2dd95SBruce Richardson * Pointer to buffer containing image binary data 596*99a2dd95SBruce Richardson * @return 597*99a2dd95SBruce Richardson * 0 for successful load 598*99a2dd95SBruce Richardson * !0 for failure to load the provided image, or image incorrect. 599*99a2dd95SBruce Richardson */ 600*99a2dd95SBruce Richardson int 601*99a2dd95SBruce Richardson rte_rawdev_firmware_load(uint16_t dev_id, rte_rawdev_obj_t firmware_image); 602*99a2dd95SBruce Richardson 603*99a2dd95SBruce Richardson /** 604*99a2dd95SBruce Richardson * Unload firmware from the device. 605*99a2dd95SBruce Richardson * 606*99a2dd95SBruce Richardson * @param dev_id 607*99a2dd95SBruce Richardson * Raw device identifiers 608*99a2dd95SBruce Richardson * @return 609*99a2dd95SBruce Richardson * 0 for successful Unload 610*99a2dd95SBruce Richardson * !0 for failure in unloading 611*99a2dd95SBruce Richardson */ 612*99a2dd95SBruce Richardson int 613*99a2dd95SBruce Richardson rte_rawdev_firmware_unload(uint16_t dev_id); 614*99a2dd95SBruce Richardson 615*99a2dd95SBruce Richardson /** 616*99a2dd95SBruce Richardson * Trigger the rawdev self test. 617*99a2dd95SBruce Richardson * 618*99a2dd95SBruce Richardson * @param dev_id 619*99a2dd95SBruce Richardson * The identifier of the device 620*99a2dd95SBruce Richardson * @return 621*99a2dd95SBruce Richardson * - 0: Selftest successful 622*99a2dd95SBruce Richardson * - -ENOTSUP if the device doesn't support selftest 623*99a2dd95SBruce Richardson * - other values < 0 on failure. 624*99a2dd95SBruce Richardson */ 625*99a2dd95SBruce Richardson int 626*99a2dd95SBruce Richardson rte_rawdev_selftest(uint16_t dev_id); 627*99a2dd95SBruce Richardson 628*99a2dd95SBruce Richardson #ifdef __cplusplus 629*99a2dd95SBruce Richardson } 630*99a2dd95SBruce Richardson #endif 631*99a2dd95SBruce Richardson 632*99a2dd95SBruce Richardson #endif /* _RTE_RAWDEV_H_ */ 633