1 /* SPDX-License-Identifier: BSD-3-Clause
11 * Generic device abstraction APIs.
13 * This API allow applications to configure and use generic devices having
14 * no specific type already available in DPDK.
21 #include <rte_common.h>
22 #include <rte_memory.h>
23 #include <rte_errno.h>
25 /* Rawdevice object - essentially a void to be typecast by implementation */
26 typedef void *rte_rawdev_obj_t;
29 * Get the total number of raw devices that have been successfully
33 * The total number of usable raw devices.
36 rte_rawdev_count(void);
39 * Get the device identifier for the named raw device.
42 * Raw device name to select the raw device identifier.
45 * Returns raw device identifier on success.
46 * - <0: Failure to find named raw device.
49 rte_rawdev_get_dev_id(const char *name);
52 * Return the NUMA socket to which a device is connected.
55 * The identifier of the device.
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.
62 rte_rawdev_socket_id(uint16_t dev_id);
65 * Raw device information forward declaration
67 struct rte_rawdev_info;
70 * Retrieve the contextual information of a raw device.
73 * The identifier of the device.
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.
85 * @param dev_private_size
86 * The length of the memory space pointed to by dev_private in dev_info.
87 * This should be set to the size of the expected private structure to be
88 * returned, and may be checked by drivers to ensure the expected struct
92 * - 0: Success, driver updates the contextual information of the raw device
93 * - <0: Error code returned by the driver info get function.
97 rte_rawdev_info_get(uint16_t dev_id, struct rte_rawdev_info *dev_info,
98 size_t dev_private_size);
101 * Configure a raw device.
103 * This function must be invoked first before any other function in the
104 * API. This function can also be re-invoked when a device is in the
107 * The caller may use rte_rawdev_info_get() to get the capability of each
108 * resources available for this raw device.
111 * The identifier of the device to configure.
113 * The raw device configuration structure encapsulated into rte_rawdev_info
115 * It is assumed that the opaque object has enough information which the
116 * driver/implementation can use to configure the device. It is also assumed
117 * that once the configuration is done, a `queue_id` type field can be used
118 * to refer to some arbitrary internal representation of a queue.
119 * @param dev_private_size
120 * The length of the memory space pointed to by dev_private in dev_info.
121 * This should be set to the size of the expected private structure to be
122 * used by the driver, and may be checked by drivers to ensure the expected
123 * struct type is provided.
126 * - 0: Success, device configured.
127 * - <0: Error code returned by the driver configuration function.
130 rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf,
131 size_t dev_private_size);
135 * Retrieve the current configuration information of a raw queue designated
136 * by its *queue_id* from the raw driver for a raw device.
138 * This function intended to be used in conjunction with rte_raw_queue_setup()
139 * where caller needs to set up the queue by overriding few default values.
142 * The identifier of the device.
144 * The index of the raw queue to get the configuration information.
145 * The value must be in the range [0, nb_raw_queues - 1]
146 * previously supplied to rte_rawdev_configure().
147 * @param[out] queue_conf
148 * The pointer to the default raw queue configuration data.
149 * @param queue_conf_size
150 * The size of the structure pointed to by queue_conf
152 * - 0: Success, driver updates the default raw queue configuration data.
153 * - <0: Error code returned by the driver info get function.
155 * @see rte_raw_queue_setup()
159 rte_rawdev_queue_conf_get(uint16_t dev_id,
161 rte_rawdev_obj_t queue_conf,
162 size_t queue_conf_size);
165 * Allocate and set up a raw queue for a raw device.
168 * The identifier of the device.
170 * The index of the raw queue to setup. The value must be in the range
171 * [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure().
173 * The pointer to the configuration data to be used for the raw queue.
174 * NULL value is allowed, in which case default configuration used.
175 * @param queue_conf_size
176 * The size of the structure pointed to by queue_conf
178 * @see rte_rawdev_queue_conf_get()
181 * - 0: Success, raw queue correctly set up.
182 * - <0: raw queue configuration failed
185 rte_rawdev_queue_setup(uint16_t dev_id,
187 rte_rawdev_obj_t queue_conf,
188 size_t queue_conf_size);
191 * Release and deallocate a raw queue from a raw device.
194 * The identifier of the device.
196 * The index of the raw queue to release. The value must be in the range
197 * [0, nb_raw_queues - 1] previously supplied to rte_rawdev_configure().
199 * @see rte_rawdev_queue_conf_get()
202 * - 0: Success, raw queue released.
203 * - <0: raw queue configuration failed
206 rte_rawdev_queue_release(uint16_t dev_id, uint16_t queue_id);
209 * Get the number of raw queues on a specific raw device
212 * Raw device identifier.
214 * - The number of configured raw queues
217 rte_rawdev_queue_count(uint16_t dev_id);
220 * Start a raw device.
222 * The device start step is the last one and consists of setting the raw
223 * queues to start accepting the raws and schedules to raw ports.
225 * On success, all basic functions exported by the API (raw enqueue,
226 * raw dequeue and so on) can be invoked.
229 * Raw device identifier
231 * - 0: Success, device started.
235 rte_rawdev_start(uint16_t dev_id);
238 * Stop a raw device. The device can be restarted with a call to
242 * Raw device identifier.
245 rte_rawdev_stop(uint16_t dev_id);
248 * Close a raw device. The device cannot be restarted after this call.
251 * Raw device identifier
254 * - 0 on successfully closing device
255 * - <0 on failure to close device
256 * - (-EAGAIN) if device is busy
259 rte_rawdev_close(uint16_t dev_id);
262 * Reset a raw device.
263 * This is different from cycle of rte_rawdev_start->rte_rawdev_stop in the
264 * sense similar to hard or soft reset.
267 * Raw device identifiers
269 * 0 for successful reset,
270 * !0 for failure in resetting
273 rte_rawdev_reset(uint16_t dev_id);
275 #define RTE_RAWDEV_NAME_MAX_LEN (64)
276 /**< @internal Max length of name of raw PMD */
281 * The data structure associated with each raw device.
282 * It is a placeholder for PMD specific data, encapsulating only information
283 * related to framework.
286 /**< Socket ID where memory is allocated */
288 /**< Device ID for this instance */
290 /**< Functions exported by PMD */
291 const struct rte_rawdev_ops *dev_ops;
292 /**< Device info. supplied during device initialization */
293 struct rte_device *device;
294 /**< Driver info. supplied by probing */
295 const char *driver_name;
298 /**< Flag indicating the device is attached */
299 uint8_t attached : 1;
300 /**< Device state: STARTED(1)/STOPPED(0) */
303 /**< PMD-specific private data */
304 rte_rawdev_obj_t dev_private;
306 char name[RTE_RAWDEV_NAME_MAX_LEN];
307 } __rte_cache_aligned;
309 /** @internal The pool of rte_rawdev structures. */
310 extern struct rte_rawdev *rte_rawdevs;
313 struct rte_rawdev_info {
314 /**< Name of driver handling this device */
315 const char *driver_name;
316 /**< Device encapsulation */
317 struct rte_device *device;
318 /**< Socket ID where memory is allocated */
320 /**< PMD-specific private data */
321 rte_rawdev_obj_t dev_private;
324 struct rte_rawdev_buf {
325 /**< Opaque buffer reference */
330 * Dump internal information about *dev_id* to the FILE* provided in *f*.
333 * The identifier of the device.
336 * A pointer to a file for output
343 rte_rawdev_dump(uint16_t dev_id, FILE *f);
346 * Get an attribute value from implementation.
347 * Attribute is an opaque handle agreed upon between application and PMD.
349 * Implementations are expected to maintain an array of attribute-value pairs
350 * based on application calls. Memory management for this structure is
351 * shared responsibility of implementation and application.
354 * The identifier of the device to configure.
356 * Opaque object representing an attribute in implementation.
357 * @param attr_value [out]
358 * Opaque response to the attribute value. In case of error, this remains
359 * untouched. This is double pointer of void type.
362 * !0 Error; attr_value remains untouched in case of error.
365 rte_rawdev_get_attr(uint16_t dev_id,
366 const char *attr_name,
367 uint64_t *attr_value);
370 * Set an attribute value.
371 * Attribute is an opaque handle agreed upon between application and PMD.
374 * The identifier of the device to configure.
376 * Opaque object representing an attribute in implementation.
378 * Value of the attribute represented by attr_name
384 rte_rawdev_set_attr(uint16_t dev_id,
385 const char *attr_name,
386 const uint64_t attr_value);
389 * Enqueue a stream of buffers to the device.
391 * Rather than specifying a queue, this API passes along an opaque object
392 * to the driver implementation. That object can be a queue or any other
393 * contextual information necessary for the device to enqueue buffers.
396 * The identifier of the device to configure.
398 * Collection of buffers for enqueuing
400 * Count of buffers to enqueue
402 * Opaque context information.
404 * >=0 for buffers enqueued
406 * Whether partial enqueue is failure or success is defined between app
407 * and driver implementation.
410 rte_rawdev_enqueue_buffers(uint16_t dev_id,
411 struct rte_rawdev_buf **buffers,
413 rte_rawdev_obj_t context);
416 * Dequeue a stream of buffers from the device.
418 * Rather than specifying a queue, this API passes along an opaque object
419 * to the driver implementation. That object can be a queue or any other
420 * contextual information necessary for the device to dequeue buffers.
422 * Application should have allocated enough space to store `count` response
424 * Releasing buffers dequeued is responsibility of the application.
427 * The identifier of the device to configure.
429 * Collection of buffers dequeued
431 * Max buffers expected to be dequeued
433 * Opaque context information.
435 * >=0 for buffers dequeued
437 * Whether partial enqueue is failure or success is defined between app
438 * and driver implementation.
441 rte_rawdev_dequeue_buffers(uint16_t dev_id,
442 struct rte_rawdev_buf **buffers,
444 rte_rawdev_obj_t context);
446 /** Maximum name length for extended statistics counters */
447 #define RTE_RAW_DEV_XSTATS_NAME_SIZE 64
450 * A name-key lookup element for extended statistics.
452 * This structure is used to map between names and ID numbers
453 * for extended ethdev statistics.
455 struct rte_rawdev_xstats_name {
456 char name[RTE_RAW_DEV_XSTATS_NAME_SIZE];
460 * Retrieve names of extended statistics of a raw device.
463 * The identifier of the raw device.
464 * @param[out] xstats_names
465 * Block of memory to insert names into. Must be at least size in capacity.
466 * If set to NULL, function returns required capacity.
468 * Capacity of xstats_names (number of names).
470 * - positive value lower or equal to size: success. The return value
471 * is the number of entries filled in the stats table.
472 * - positive value higher than size: error, the given statistics table
473 * is too small. The return value corresponds to the size that should
474 * be given to succeed. The entries in the table are not valid and
475 * shall not be used by the caller.
476 * - negative value on error:
477 * -ENODEV for invalid *dev_id*
478 * -ENOTSUP if the device doesn't support this function.
481 rte_rawdev_xstats_names_get(uint16_t dev_id,
482 struct rte_rawdev_xstats_name *xstats_names,
486 * Retrieve extended statistics of a raw device.
489 * The identifier of the device.
491 * The id numbers of the stats to get. The ids can be got from the stat
492 * position in the stat list from rte_rawdev_get_xstats_names(), or
493 * by using rte_rawdev_get_xstats_by_name()
495 * The values for each stats request by ID.
497 * The number of stats requested
499 * - positive value: number of stat entries filled into the values array
500 * - negative value on error:
501 * -ENODEV for invalid *dev_id*
502 * -ENOTSUP if the device doesn't support this function.
505 rte_rawdev_xstats_get(uint16_t dev_id,
506 const unsigned int ids[],
511 * Retrieve the value of a single stat by requesting it by name.
514 * The identifier of the device
516 * The stat name to retrieve
518 * If non-NULL, the numerical id of the stat will be returned, so that further
519 * requests for the stat can be got using rte_rawdev_xstats_get, which will
520 * be faster as it doesn't need to scan a list of names for the stat.
521 * If the stat cannot be found, the id returned will be (unsigned)-1.
523 * - positive value or zero: the stat value
524 * - negative value: -EINVAL if stat not found, -ENOTSUP if not supported.
527 rte_rawdev_xstats_by_name_get(uint16_t dev_id,
532 * Reset the values of the xstats of the selected component in the device.
535 * The identifier of the device
537 * Selects specific statistics to be reset. When NULL, all statistics
538 * will be reset. If non-NULL, must point to array of at least
541 * The number of ids available from the *ids* array. Ignored when ids is NULL.
543 * - zero: successfully reset the statistics to zero
544 * - negative value: -EINVAL invalid parameters, -ENOTSUP if not supported.
547 rte_rawdev_xstats_reset(uint16_t dev_id,
548 const uint32_t ids[],
552 * Get Firmware status of the device..
553 * Returns a memory allocated by driver/implementation containing status
554 * information block. It is responsibility of caller to release the buffer.
557 * Raw device identifier
559 * Pointer to status information area. Caller is responsible for releasing
560 * the memory associated.
563 * !0 for failure, `status_info` argument state is undefined
566 rte_rawdev_firmware_status_get(uint16_t dev_id,
567 rte_rawdev_obj_t status_info);
570 * Get Firmware version of the device.
571 * Returns a memory allocated by driver/implementation containing version
572 * information block. It is responsibility of caller to release the buffer.
575 * Raw device identifier
576 * @param version_info
577 * Pointer to version information area. Caller is responsible for releasing
578 * the memory associated.
581 * !0 for failure, `version_info` argument state is undefined
584 rte_rawdev_firmware_version_get(uint16_t dev_id,
585 rte_rawdev_obj_t version_info);
588 * Load firmware on the device.
589 * TODO: In future, methods like directly flashing from file too can be
593 * Raw device identifier
594 * @param firmware_image
595 * Pointer to buffer containing image binary data
597 * 0 for successful load
598 * !0 for failure to load the provided image, or image incorrect.
601 rte_rawdev_firmware_load(uint16_t dev_id, rte_rawdev_obj_t firmware_image);
604 * Unload firmware from the device.
607 * Raw device identifiers
609 * 0 for successful Unload
610 * !0 for failure in unloading
613 rte_rawdev_firmware_unload(uint16_t dev_id);
616 * Trigger the rawdev self test.
619 * The identifier of the device
621 * - 0: Selftest successful
622 * - -ENOTSUP if the device doesn't support selftest
623 * - other values < 0 on failure.
626 rte_rawdev_selftest(uint16_t dev_id);
632 #endif /* _RTE_RAWDEV_H_ */