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