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