1 /* SPDX-License-Identifier: BSD-3-Clause
5 #ifndef _RTE_RAWDEV_PMD_H_
6 #define _RTE_RAWDEV_PMD_H_
12 * Driver facing APIs for a raw device. These are not to be called directly by
23 #include <rte_malloc.h>
25 #include <rte_common.h>
27 #include "rte_rawdev.h"
29 extern int librawdev_logtype;
32 #define RTE_RDEV_LOG(level, fmt, args...) \
33 rte_log(RTE_LOG_ ## level, librawdev_logtype, "%s(): " fmt "\n", \
36 #define RTE_RDEV_ERR(fmt, args...) \
37 RTE_RDEV_LOG(ERR, fmt, ## args)
38 #define RTE_RDEV_DEBUG(fmt, args...) \
39 RTE_RDEV_LOG(DEBUG, fmt, ## args)
40 #define RTE_RDEV_INFO(fmt, args...) \
41 RTE_RDEV_LOG(INFO, fmt, ## args)
44 /* Macros to check for valid device */
45 #define RTE_RAWDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
46 if (!rte_rawdev_pmd_is_valid_dev((dev_id))) { \
47 RTE_RDEV_ERR("Invalid dev_id=%d", dev_id); \
52 #define RTE_RAWDEV_VALID_DEVID_OR_RET(dev_id) do { \
53 if (!rte_rawdev_pmd_is_valid_dev((dev_id))) { \
54 RTE_RDEV_ERR("Invalid dev_id=%d", dev_id); \
59 #define RTE_RAWDEV_DETACHED (0)
60 #define RTE_RAWDEV_ATTACHED (1)
62 /* Global structure used for maintaining state of allocated raw devices.
64 * TODO: Can be expanded to <type of raw device>:<count> in future.
65 * Applications should be able to select from a number of type of raw
66 * devices which were detected or attached to this DPDK instance.
68 struct rte_rawdev_global {
69 /**< Number of devices found */
73 extern struct rte_rawdev *rte_rawdevs;
74 /** The pool of rte_rawdev structures. */
77 * Get the rte_rawdev structure device pointer for the named device.
80 * device name to select the device structure.
83 * - The rte_rawdev structure pointer for the given device ID.
85 static inline struct rte_rawdev *
86 rte_rawdev_pmd_get_named_dev(const char *name)
88 struct rte_rawdev *dev;
94 for (i = 0; i < RTE_RAWDEV_MAX_DEVS; i++) {
95 dev = &rte_rawdevs[i];
96 if ((dev->attached == RTE_RAWDEV_ATTACHED) &&
97 (strcmp(dev->name, name) == 0))
105 * Validate if the raw device index is a valid attached raw device.
111 * - If the device index is valid (1) or not (0).
113 static inline unsigned
114 rte_rawdev_pmd_is_valid_dev(uint8_t dev_id)
116 struct rte_rawdev *dev;
118 if (dev_id >= RTE_RAWDEV_MAX_DEVS)
121 dev = &rte_rawdevs[dev_id];
122 if (dev->attached != RTE_RAWDEV_ATTACHED)
129 * Definitions of all functions exported by a driver through
130 * the generic structure of type *rawdev_ops* supplied in the
131 * *rte_rawdev* structure associated with a device.
135 * Get device information of a device.
140 * Raw device information structure
141 * @param dev_private_size
142 * The size of the structure pointed to by dev_info->dev_private
145 * Returns 0 on success, negative error code on failure
147 typedef int (*rawdev_info_get_t)(struct rte_rawdev *dev,
148 rte_rawdev_obj_t dev_info,
149 size_t dev_private_size);
152 * Configure a device.
157 * Void object containing device specific configuration
159 * Size of the memory allocated for the configuration
162 * Returns 0 on success
164 typedef int (*rawdev_configure_t)(const struct rte_rawdev *dev,
165 rte_rawdev_obj_t config,
169 * Start a configured device.
175 * Returns 0 on success
177 typedef int (*rawdev_start_t)(struct rte_rawdev *dev);
180 * Stop a configured device.
185 typedef void (*rawdev_stop_t)(struct rte_rawdev *dev);
188 * Close a configured device.
195 * - (-EAGAIN) if can't close as device is busy
197 typedef int (*rawdev_close_t)(struct rte_rawdev *dev);
200 * Reset a configured device.
208 typedef int (*rawdev_reset_t)(struct rte_rawdev *dev);
211 * Retrieve the current raw queue configuration.
216 * Raw device queue index
217 * @param[out] queue_conf
218 * Raw device queue configuration structure
219 * @param queue_conf_size
220 * Size of the memory allocated for the configuration
223 * Returns 0 on success, negative errno on failure
225 typedef int (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev,
227 rte_rawdev_obj_t queue_conf,
228 size_t queue_conf_size);
231 * Setup an raw queue.
238 * Rawqueue configuration structure
239 * @param queue_conf_size
240 * Size of the memory allocated for the configuration
243 * Returns 0 on success.
245 typedef int (*rawdev_queue_setup_t)(struct rte_rawdev *dev,
247 rte_rawdev_obj_t queue_conf,
248 size_t queue_conf_size);
251 * Release resources allocated by given raw queue.
259 typedef int (*rawdev_queue_release_t)(struct rte_rawdev *dev,
263 * Get the count of number of queues configured on this device.
265 * Another way to fetch this information is to fetch the device configuration.
266 * But, that assumes that the device configuration managed by the driver has
267 * that kind of information.
269 * This function helps in getting queue count supported, independently. It
270 * can help in cases where iterator needs to be implemented.
275 * Number of queues; 0 is assumed to be a valid response.
278 typedef uint16_t (*rawdev_queue_count_t)(struct rte_rawdev *dev);
281 * Enqueue an array of raw buffers to the device.
283 * Buffer being used is opaque - it can be obtained from mempool or from
284 * any other source. Interpretation of buffer is responsibility of driver.
291 * number of buffers passed
293 * an opaque object representing context of the call; for example, an
294 * application can pass information about the queues on which enqueue needs
295 * to be done. Or, the enqueue operation might be passed reference to an
296 * object containing a callback (agreed upon between application and driver).
299 * >=0 Count of buffers successfully enqueued (0: no buffers enqueued)
300 * <0 Error count in case of error
302 typedef int (*rawdev_enqueue_bufs_t)(struct rte_rawdev *dev,
303 struct rte_rawdev_buf **buffers,
305 rte_rawdev_obj_t context);
308 * Dequeue an array of raw buffers from the device.
315 * Max buffers expected to be dequeued
317 * an opaque object representing context of the call. Based on this object,
318 * the application and driver can coordinate for dequeue operation involving
319 * agreed upon semantics. For example, queue information/id on which Dequeue
320 * needs to be performed.
322 * >0, ~0: Count of buffers returned
324 * Whether short dequeue is success or failure is decided between app and
327 typedef int (*rawdev_dequeue_bufs_t)(struct rte_rawdev *dev,
328 struct rte_rawdev_buf **buffers,
330 rte_rawdev_obj_t context);
333 * Dump internal information
338 * A pointer to a file for output
344 typedef int (*rawdev_dump_t)(struct rte_rawdev *dev, FILE *f);
347 * Get an attribute value from implementation.
348 * Attribute is an opaque handle agreed upon between application and PMD.
353 * Opaque object representing an attribute in implementation.
354 * @param attr_value [out]
355 * Opaque response to the attribute value. In case of error, this remains
356 * untouched. This is double pointer of void type.
359 * !0 Error; attr_value remains untouched in case of error.
361 typedef int (*rawdev_get_attr_t)(struct rte_rawdev *dev,
362 const char *attr_name,
363 uint64_t *attr_value);
366 * Set an attribute value.
367 * Attribute is an opaque handle agreed upon between application and PMD.
372 * Opaque object representing an attribute in implementation.
374 * Value of the attribute represented by attr_name
379 typedef int (*rawdev_set_attr_t)(struct rte_rawdev *dev,
380 const char *attr_name,
381 const uint64_t attr_value);
384 * Retrieve a set of statistics from device.
385 * Note: Being a raw device, the stats are specific to the device being
386 * implemented thus represented as xstats.
391 * The stat ids to retrieve
393 * The returned stat values
395 * The number of id values and entries in the values array
397 * The number of stat values successfully filled into the values array
399 typedef int (*rawdev_xstats_get_t)(const struct rte_rawdev *dev,
400 const unsigned int ids[], uint64_t values[], unsigned int n);
403 * Resets the statistic values in xstats for the device.
405 typedef int (*rawdev_xstats_reset_t)(struct rte_rawdev *dev,
406 const uint32_t ids[],
410 * Get names of extended stats of an raw device
414 * @param xstats_names
415 * Array of name values to be filled in
417 * Number of values in the xstats_names array
419 * When size >= the number of stats, return the number of stat values filled
421 * When size < the number of available stats, return the number of stats
422 * values, and do not fill in any data into xstats_names.
424 typedef int (*rawdev_xstats_get_names_t)(const struct rte_rawdev *dev,
425 struct rte_rawdev_xstats_name *xstats_names,
429 * Get value of one stats and optionally return its id
434 * The name of the stat to retrieve
436 * Pointer to an unsigned int where we store the stat-id.
437 * This pointer may be null if the id is not required.
439 * The value of the stat, or (uint64_t)-1 if the stat is not found.
440 * If the stat is not found, the id value will be returned as (unsigned)-1,
441 * if id pointer is non-NULL
443 typedef uint64_t (*rawdev_xstats_get_by_name_t)(const struct rte_rawdev *dev,
448 * Get firmware/device-stack status.
449 * Implementation to allocate buffer for returning information.
454 * void block containing device specific status information
457 * !0 for failure, with undefined value in `status_info`
459 typedef int (*rawdev_firmware_status_get_t)(struct rte_rawdev *dev,
460 rte_rawdev_obj_t status_info);
463 * Get firmware version information
467 * @param version_info
468 * void pointer to version information returned by device
471 * !0 for failure, with undefined value in `version_info`
473 typedef int (*rawdev_firmware_version_get_t)(struct rte_rawdev *dev,
474 rte_rawdev_obj_t version_info);
477 * Load firmware from a buffer (DMA'able)
481 * @param firmware_buf
482 * Pointer to firmware image
484 * >0, ~0: for successful load
487 * @see Application may use 'firmware_version_get` for ascertaining successful
490 typedef int (*rawdev_firmware_load_t)(struct rte_rawdev *dev,
491 rte_rawdev_obj_t firmware_buf);
499 * >0, ~0 for successful unloading
500 * <0 for failure in unloading
502 * Note: Application can use the `firmware_status_get` or
503 * `firmware_version_get` to get result of unload.
505 typedef int (*rawdev_firmware_unload_t)(struct rte_rawdev *dev);
508 * Start rawdev selftest
511 * Return 0 on success
513 typedef int (*rawdev_selftest_t)(uint16_t dev_id);
515 /** Rawdevice operations function pointer table */
516 struct rte_rawdev_ops {
517 /**< Get device info. */
518 rawdev_info_get_t dev_info_get;
519 /**< Configure device. */
520 rawdev_configure_t dev_configure;
521 /**< Start device. */
522 rawdev_start_t dev_start;
524 rawdev_stop_t dev_stop;
525 /**< Close device. */
526 rawdev_close_t dev_close;
527 /**< Reset device. */
528 rawdev_reset_t dev_reset;
530 /**< Get raw queue configuration. */
531 rawdev_queue_conf_get_t queue_def_conf;
532 /**< Set up an raw queue. */
533 rawdev_queue_setup_t queue_setup;
534 /**< Release an raw queue. */
535 rawdev_queue_release_t queue_release;
536 /**< Get the number of queues attached to the device */
537 rawdev_queue_count_t queue_count;
539 /**< Enqueue an array of raw buffers to device. */
540 rawdev_enqueue_bufs_t enqueue_bufs;
541 /**< Dequeue an array of raw buffers from device. */
542 /** TODO: Callback based enqueue and dequeue support */
543 rawdev_dequeue_bufs_t dequeue_bufs;
545 /* Dump internal information */
548 /**< Get an attribute managed by the implementation */
549 rawdev_get_attr_t attr_get;
550 /**< Set an attribute managed by the implementation */
551 rawdev_set_attr_t attr_set;
553 /**< Get extended device statistics. */
554 rawdev_xstats_get_t xstats_get;
555 /**< Get names of extended stats. */
556 rawdev_xstats_get_names_t xstats_get_names;
557 /**< Get one value by name. */
558 rawdev_xstats_get_by_name_t xstats_get_by_name;
559 /**< Reset the statistics values in xstats. */
560 rawdev_xstats_reset_t xstats_reset;
562 /**< Obtain firmware status */
563 rawdev_firmware_status_get_t firmware_status_get;
564 /**< Obtain firmware version information */
565 rawdev_firmware_version_get_t firmware_version_get;
566 /**< Load firmware */
567 rawdev_firmware_load_t firmware_load;
568 /**< Unload firmware */
569 rawdev_firmware_unload_t firmware_unload;
571 /**< Device selftest function */
572 rawdev_selftest_t dev_selftest;
576 * Allocates a new rawdev slot for an raw device and returns the pointer
577 * to that slot for the driver to use.
580 * Unique identifier name for each device
581 * @param dev_private_size
582 * Size of private data memory allocated within rte_rawdev object.
583 * Set to 0 to disable internal memory allocation and allow for
586 * Socket to allocate resources on.
588 * - Slot in the rte_dev_devices array for a new device;
591 rte_rawdev_pmd_allocate(const char *name, size_t dev_private_size,
595 * Release the specified rawdev device.
598 * The *rawdev* pointer is the address of the *rte_rawdev* structure.
600 * - 0 on success, negative on error
603 rte_rawdev_pmd_release(struct rte_rawdev *rawdev);
606 * Creates a new raw device and returns the pointer to that device.
609 * Pointer to a character array containing name of the device
610 * @param dev_private_size
611 * Size of raw PMDs private data
613 * Socket to allocate resources on.
616 * - Raw device pointer if device is successfully created.
617 * - NULL if device cannot be created.
620 rte_rawdev_pmd_init(const char *name, size_t dev_private_size,
624 * Destroy a raw device
629 * - 0 on success, negative on error
632 rte_rawdev_pmd_uninit(const char *name);
638 #endif /* _RTE_RAWDEV_PMD_H_ */