1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014 6WIND S.A.
11 * RTE PMD Driver Registration Interface
13 * This file manages the list of device drivers.
21 #include <sys/queue.h>
23 #include <rte_config.h>
24 #include <rte_compat.h>
28 * The device event type.
30 enum rte_dev_event_type {
31 RTE_DEV_EVENT_ADD, /**< device being added */
32 RTE_DEV_EVENT_REMOVE, /**< device being removed */
33 RTE_DEV_EVENT_MAX /**< max value of this enum */
36 struct rte_dev_event {
37 enum rte_dev_event_type type; /**< device event type */
38 int subsystem; /**< subsystem id */
39 char *devname; /**< device name */
42 typedef void (*rte_dev_event_cb_fn)(const char *device_name,
43 enum rte_dev_event_type event,
46 __attribute__((format(printf, 2, 0)))
48 rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
55 char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
60 vsnprintf(buffer, sizeof(buffer), fmt, ap);
63 rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD, "%s: %s",
69 * Enable RTE_PMD_DEBUG_TRACE() when at least one component relying on the
70 * RTE_*_RET() macros defined below is compiled in debug mode.
72 #if defined(RTE_LIBRTE_EVENTDEV_DEBUG)
73 #define RTE_PMD_DEBUG_TRACE(...) \
74 rte_pmd_debug_trace(__func__, __VA_ARGS__)
76 #define RTE_PMD_DEBUG_TRACE(...) (void)0
79 /* Macros to check for invalid function pointers */
80 #define RTE_FUNC_PTR_OR_ERR_RET(func, retval) do { \
81 if ((func) == NULL) { \
82 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
87 #define RTE_FUNC_PTR_OR_RET(func) do { \
88 if ((func) == NULL) { \
89 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
97 enum rte_kernel_driver {
101 RTE_KDRV_UIO_GENERIC,
109 enum rte_dev_policy {
115 * A generic memory resource representation.
117 struct rte_mem_resource {
118 uint64_t phys_addr; /**< Physical address, 0 if not resource. */
119 uint64_t len; /**< Length of the resource. */
120 void *addr; /**< Virtual address, NULL when not mapped. */
124 * A structure describing a device driver.
127 TAILQ_ENTRY(rte_driver) next; /**< Next in list. */
128 const char *name; /**< Driver name. */
129 const char *alias; /**< Driver alias. */
133 * Internal identifier length
134 * Sufficiently large to allow for UUID or PCI address
136 #define RTE_DEV_NAME_MAX_LEN 64
139 * A structure describing a generic device.
142 TAILQ_ENTRY(rte_device) next; /**< Next device */
143 const char *name; /**< Device name */
144 const struct rte_driver *driver; /**< Driver assigned after probing */
145 const struct rte_bus *bus; /**< Bus handle assigned on scan */
146 int numa_node; /**< NUMA node connection */
147 struct rte_devargs *devargs; /**< Arguments for latest probing */
152 * @b EXPERIMENTAL: this API may change without prior notice
154 * Query status of a device.
157 * Generic device pointer.
159 * (int)true if already probed successfully, 0 otherwise.
162 int rte_dev_is_probed(const struct rte_device *dev);
165 * Hotplug add a given device to a specific bus.
167 * In multi-process, it will request other processes to add the same device.
168 * A failure, in any process, will rollback the action
171 * The bus name the device is added to.
173 * The device name. Based on this device name, eal will identify a driver
174 * capable of handling it and pass it to the driver probing function.
176 * Device arguments to be passed to the driver.
178 * 0 on success, negative on error.
180 int rte_eal_hotplug_add(const char *busname, const char *devname,
181 const char *drvargs);
184 * Add matching devices.
186 * In multi-process, it will request other processes to add the same device.
187 * A failure, in any process, will rollback the action
190 * Device arguments including bus, class and driver properties.
192 * 0 on success, negative on error.
194 int rte_dev_probe(const char *devargs);
197 * Hotplug remove a given device from a specific bus.
199 * In multi-process, it will request other processes to remove the same device.
200 * A failure, in any process, will rollback the action
203 * The bus name the device is removed from.
205 * The device name being removed.
207 * 0 on success, negative on error.
209 int rte_eal_hotplug_remove(const char *busname, const char *devname);
214 * In multi-process, it will request other processes to remove the same device.
215 * A failure, in any process, will rollback the action
218 * Data structure of the device to remove.
220 * 0 on success, negative on error.
222 int rte_dev_remove(struct rte_device *dev);
225 * Device comparison function.
227 * This type of function is used to compare an rte_device with arbitrary
234 * Data to compare against. The type of this parameter is determined by
235 * the kind of comparison performed by the function.
238 * 0 if the device matches the data.
239 * !0 if the device does not match.
240 * <0 if ordering is possible and the device is lower than the data.
241 * >0 if ordering is possible and the device is greater than the data.
243 typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data);
245 #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]
247 #define RTE_PMD_EXPORT_NAME(name, idx) \
248 static const char RTE_PMD_EXPORT_NAME_ARRAY(this_pmd_name, idx) \
249 __attribute__((used)) = RTE_STR(name)
251 #define DRV_EXP_TAG(name, tag) __##name##_##tag
253 #define RTE_PMD_REGISTER_PCI_TABLE(name, table) \
254 static const char DRV_EXP_TAG(name, pci_tbl_export)[] __attribute__((used)) = \
257 #define RTE_PMD_REGISTER_PARAM_STRING(name, str) \
258 static const char DRV_EXP_TAG(name, param_string_export)[] \
259 __attribute__((used)) = str
262 * Advertise the list of kernel modules required to run this driver
264 * This string lists the kernel modules required for the devices
265 * associated to a PMD. The format of each line of the string is:
266 * "<device-pattern> <kmod-expression>".
268 * The possible formats for the device pattern are:
269 * "*" all devices supported by this driver
270 * "pci:*" all PCI devices supported by this driver
271 * "pci:v8086:d*:sv*:sd*" all PCI devices supported by this driver
272 * whose vendor id is 0x8086.
274 * The format of the kernel modules list is a parenthesed expression
275 * containing logical-and (&) and logical-or (|).
277 * The device pattern and the kmod expression are separated by a space.
280 * - "* igb_uio | uio_pci_generic | vfio"
282 #define RTE_PMD_REGISTER_KMOD_DEP(name, str) \
283 static const char DRV_EXP_TAG(name, kmod_dep_export)[] \
284 __attribute__((used)) = str
289 * This context carries over the current iteration state.
291 struct rte_dev_iterator {
292 const char *dev_str; /**< device string. */
293 const char *bus_str; /**< bus-related part of device string. */
294 const char *cls_str; /**< class-related part of device string. */
295 struct rte_bus *bus; /**< bus handle. */
296 struct rte_class *cls; /**< class handle. */
297 struct rte_device *device; /**< current position. */
298 void *class_device; /**< additional specialized context. */
302 * Device iteration function.
304 * Find the next device matching properties passed in parameters.
305 * The function takes an additional ``start`` parameter, that is
306 * used as starting context when relevant.
308 * The function returns the current element in the iteration.
309 * This return value will potentially be used as a start parameter
310 * in subsequent calls to the function.
312 * The additional iterator parameter is only there if a specific
313 * implementation needs additional context. It must not be modified by
314 * the iteration function itself.
317 * Starting iteration context.
320 * Device description string.
326 * The address of the current element matching the device description
329 typedef void *(*rte_dev_iterate_t)(const void *start,
331 const struct rte_dev_iterator *it);
334 * Initializes a device iterator.
336 * This iterator allows accessing a list of devices matching a criteria.
337 * The device matching is made among all buses and classes currently registered,
338 * filtered by the device description given as parameter.
340 * This function will not allocate any memory. It is safe to stop the
341 * iteration at any moment and let the iterator go out of context.
344 * Device iterator handle.
347 * Device description string.
350 * 0 on successful initialization.
355 rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str);
358 * Iterates on a device iterator.
360 * Generates a new rte_device handle corresponding to the next element
361 * in the list described in comprehension by the iterator.
363 * The next object is returned, and the iterator is updated.
366 * Device iterator handle.
369 * An rte_device handle if found.
370 * NULL if an error occurred (rte_errno is set).
371 * NULL if no device could be found (rte_errno is not set).
375 rte_dev_iterator_next(struct rte_dev_iterator *it);
377 #define RTE_DEV_FOREACH(dev, devstr, it) \
378 for (rte_dev_iterator_init(it, devstr), \
379 dev = rte_dev_iterator_next(it); \
381 dev = rte_dev_iterator_next(it))
389 * @b EXPERIMENTAL: this API may change without prior notice
391 * It registers the callback for the specific device.
392 * Multiple callbacks cal be registered at the same time.
395 * The device name, that is the param name of the struct rte_device,
396 * null value means for all devices.
400 * address of parameter for callback.
403 * - On success, zero.
404 * - On failure, a negative value.
406 int __rte_experimental
407 rte_dev_event_callback_register(const char *device_name,
408 rte_dev_event_cb_fn cb_fn,
413 * @b EXPERIMENTAL: this API may change without prior notice
415 * It unregisters the callback according to the specified device.
418 * The device name, that is the param name of the struct rte_device,
419 * null value means for all devices and their callbacks.
423 * address of parameter for callback, (void *)-1 means to remove all
424 * registered which has the same callback address.
427 * - On success, return the number of callback entities removed.
428 * - On failure, a negative value.
430 int __rte_experimental
431 rte_dev_event_callback_unregister(const char *device_name,
432 rte_dev_event_cb_fn cb_fn,
437 * @b EXPERIMENTAL: this API may change without prior notice
439 * Executes all the user application registered callbacks for
440 * the specific device.
445 * the device event type.
447 void __rte_experimental
448 rte_dev_event_callback_process(const char *device_name,
449 enum rte_dev_event_type event);
453 * @b EXPERIMENTAL: this API may change without prior notice
455 * Start the device event monitoring.
458 * - On success, zero.
459 * - On failure, a negative value.
461 int __rte_experimental
462 rte_dev_event_monitor_start(void);
466 * @b EXPERIMENTAL: this API may change without prior notice
468 * Stop the device event monitoring.
471 * - On success, zero.
472 * - On failure, a negative value.
474 int __rte_experimental
475 rte_dev_event_monitor_stop(void);
479 * @b EXPERIMENTAL: this API may change without prior notice
481 * Enable hotplug handling for devices.
484 * - On success, zero.
485 * - On failure, a negative value.
487 int __rte_experimental
488 rte_dev_hotplug_handle_enable(void);
492 * @b EXPERIMENTAL: this API may change without prior notice
494 * Disable hotplug handling for devices.
497 * - On success, zero.
498 * - On failure, a negative value.
500 int __rte_experimental
501 rte_dev_hotplug_handle_disable(void);
503 #endif /* _RTE_DEV_H_ */