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)(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_CRYPTODEV_DEBUG) || \
73 defined(RTE_LIBRTE_EVENTDEV_DEBUG)
74 #define RTE_PMD_DEBUG_TRACE(...) \
75 rte_pmd_debug_trace(__func__, __VA_ARGS__)
77 #define RTE_PMD_DEBUG_TRACE(...) (void)0
80 /* Macros for checking for restricting functions to primary instance only */
81 #define RTE_PROC_PRIMARY_OR_ERR_RET(retval) do { \
82 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83 RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
88 #define RTE_PROC_PRIMARY_OR_RET() do { \
89 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
90 RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
95 /* Macros to check for invalid function pointers */
96 #define RTE_FUNC_PTR_OR_ERR_RET(func, retval) do { \
97 if ((func) == NULL) { \
98 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
103 #define RTE_FUNC_PTR_OR_RET(func) do { \
104 if ((func) == NULL) { \
105 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
113 enum rte_kernel_driver {
114 RTE_KDRV_UNKNOWN = 0,
117 RTE_KDRV_UIO_GENERIC,
125 enum rte_dev_policy {
131 * A generic memory resource representation.
133 struct rte_mem_resource {
134 uint64_t phys_addr; /**< Physical address, 0 if not resource. */
135 uint64_t len; /**< Length of the resource. */
136 void *addr; /**< Virtual address, NULL when not mapped. */
140 * A structure describing a device driver.
143 TAILQ_ENTRY(rte_driver) next; /**< Next in list. */
144 const char *name; /**< Driver name. */
145 const char *alias; /**< Driver alias. */
149 * Internal identifier length
150 * Sufficiently large to allow for UUID or PCI address
152 #define RTE_DEV_NAME_MAX_LEN 64
155 * A structure describing a generic device.
158 TAILQ_ENTRY(rte_device) next; /**< Next device */
159 const char *name; /**< Device name */
160 const struct rte_driver *driver;/**< Associated driver */
161 int numa_node; /**< NUMA node connection */
162 struct rte_devargs *devargs; /**< Device user arguments */
166 * Attach a device to a registered driver.
169 * The device name, that refers to a pci device (or some private
170 * way of designating a vdev device). Based on this device name, eal
171 * will identify a driver capable of handling it and pass it to the
172 * driver probing function.
174 * Device arguments to be passed to the driver.
176 * 0 on success, negative on error.
178 int rte_eal_dev_attach(const char *name, const char *devargs);
181 * Detach a device from its driver.
184 * A pointer to a rte_device structure.
186 * 0 on success, negative on error.
188 int rte_eal_dev_detach(struct rte_device *dev);
192 * @b EXPERIMENTAL: this API may change without prior notice
194 * Hotplug add a given device to a specific bus.
197 * The bus name the device is added to.
199 * The device name. Based on this device name, eal will identify a driver
200 * capable of handling it and pass it to the driver probing function.
202 * Device arguments to be passed to the driver.
204 * 0 on success, negative on error.
206 int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devname,
207 const char *devargs);
211 * @b EXPERIMENTAL: this API may change without prior notice
213 * Hotplug remove a given device from a specific bus.
216 * The bus name the device is removed from.
218 * The device name being removed.
220 * 0 on success, negative on error.
222 int __rte_experimental rte_eal_hotplug_remove(const char *busname,
223 const char *devname);
226 * Device comparison function.
228 * This type of function is used to compare an rte_device with arbitrary
235 * Data to compare against. The type of this parameter is determined by
236 * the kind of comparison performed by the function.
239 * 0 if the device matches the data.
240 * !0 if the device does not match.
241 * <0 if ordering is possible and the device is lower than the data.
242 * >0 if ordering is possible and the device is greater than the data.
244 typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data);
246 #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]
248 #define RTE_PMD_EXPORT_NAME(name, idx) \
249 static const char RTE_PMD_EXPORT_NAME_ARRAY(this_pmd_name, idx) \
250 __attribute__((used)) = RTE_STR(name)
252 #define DRV_EXP_TAG(name, tag) __##name##_##tag
254 #define RTE_PMD_REGISTER_PCI_TABLE(name, table) \
255 static const char DRV_EXP_TAG(name, pci_tbl_export)[] __attribute__((used)) = \
258 #define RTE_PMD_REGISTER_PARAM_STRING(name, str) \
259 static const char DRV_EXP_TAG(name, param_string_export)[] \
260 __attribute__((used)) = str
263 * Advertise the list of kernel modules required to run this driver
265 * This string lists the kernel modules required for the devices
266 * associated to a PMD. The format of each line of the string is:
267 * "<device-pattern> <kmod-expression>".
269 * The possible formats for the device pattern are:
270 * "*" all devices supported by this driver
271 * "pci:*" all PCI devices supported by this driver
272 * "pci:v8086:d*:sv*:sd*" all PCI devices supported by this driver
273 * whose vendor id is 0x8086.
275 * The format of the kernel modules list is a parenthesed expression
276 * containing logical-and (&) and logical-or (|).
278 * The device pattern and the kmod expression are separated by a space.
281 * - "* igb_uio | uio_pci_generic | vfio"
283 #define RTE_PMD_REGISTER_KMOD_DEP(name, str) \
284 static const char DRV_EXP_TAG(name, kmod_dep_export)[] \
285 __attribute__((used)) = str
293 * @b EXPERIMENTAL: this API may change without prior notice
295 * It registers the callback for the specific device.
296 * Multiple callbacks cal be registered at the same time.
299 * The device name, that is the param name of the struct rte_device,
300 * null value means for all devices.
304 * address of parameter for callback.
307 * - On success, zero.
308 * - On failure, a negative value.
310 int __rte_experimental
311 rte_dev_event_callback_register(const char *device_name,
312 rte_dev_event_cb_fn cb_fn,
317 * @b EXPERIMENTAL: this API may change without prior notice
319 * It unregisters the callback according to the specified device.
322 * The device name, that is the param name of the struct rte_device,
323 * null value means for all devices and their callbacks.
327 * address of parameter for callback, (void *)-1 means to remove all
328 * registered which has the same callback address.
331 * - On success, return the number of callback entities removed.
332 * - On failure, a negative value.
334 int __rte_experimental
335 rte_dev_event_callback_unregister(const char *device_name,
336 rte_dev_event_cb_fn cb_fn,
341 * @b EXPERIMENTAL: this API may change without prior notice
343 * Start the device event monitoring.
346 * - On success, zero.
347 * - On failure, a negative value.
349 int __rte_experimental
350 rte_dev_event_monitor_start(void);
354 * @b EXPERIMENTAL: this API may change without prior notice
356 * Stop the device event monitoring.
359 * - On success, zero.
360 * - On failure, a negative value.
362 int __rte_experimental
363 rte_dev_event_monitor_stop(void);
365 #endif /* _RTE_DEV_H_ */