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>
27 __attribute__((format(printf, 2, 0)))
29 rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
35 char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
40 vsnprintf(buffer, sizeof(buffer), fmt, ap);
43 rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD, "%s: %s", func_name, buffer);
47 * Enable RTE_PMD_DEBUG_TRACE() when at least one component relying on the
48 * RTE_*_RET() macros defined below is compiled in debug mode.
50 #if defined(RTE_LIBRTE_ETHDEV_DEBUG) || \
51 defined(RTE_LIBRTE_CRYPTODEV_DEBUG) || \
52 defined(RTE_LIBRTE_EVENTDEV_DEBUG)
53 #define RTE_PMD_DEBUG_TRACE(...) \
54 rte_pmd_debug_trace(__func__, __VA_ARGS__)
56 #define RTE_PMD_DEBUG_TRACE(...) (void)0
59 /* Macros for checking for restricting functions to primary instance only */
60 #define RTE_PROC_PRIMARY_OR_ERR_RET(retval) do { \
61 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
62 RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
67 #define RTE_PROC_PRIMARY_OR_RET() do { \
68 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
69 RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
74 /* Macros to check for invalid function pointers */
75 #define RTE_FUNC_PTR_OR_ERR_RET(func, retval) do { \
76 if ((func) == NULL) { \
77 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
82 #define RTE_FUNC_PTR_OR_RET(func) do { \
83 if ((func) == NULL) { \
84 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
92 enum rte_kernel_driver {
104 enum rte_dev_policy {
110 * A generic memory resource representation.
112 struct rte_mem_resource {
113 uint64_t phys_addr; /**< Physical address, 0 if not resource. */
114 uint64_t len; /**< Length of the resource. */
115 void *addr; /**< Virtual address, NULL when not mapped. */
119 * A structure describing a device driver.
122 TAILQ_ENTRY(rte_driver) next; /**< Next in list. */
123 const char *name; /**< Driver name. */
124 const char *alias; /**< Driver alias. */
128 * Internal identifier length
129 * Sufficiently large to allow for UUID or PCI address
131 #define RTE_DEV_NAME_MAX_LEN 64
134 * A structure describing a generic device.
137 TAILQ_ENTRY(rte_device) next; /**< Next device */
138 const char *name; /**< Device name */
139 const struct rte_driver *driver;/**< Associated driver */
140 int numa_node; /**< NUMA node connection */
141 struct rte_devargs *devargs; /**< Device user arguments */
145 * Attach a device to a registered driver.
148 * The device name, that refers to a pci device (or some private
149 * way of designating a vdev device). Based on this device name, eal
150 * will identify a driver capable of handling it and pass it to the
151 * driver probing function.
153 * Device arguments to be passed to the driver.
155 * 0 on success, negative on error.
157 int rte_eal_dev_attach(const char *name, const char *devargs);
160 * Detach a device from its driver.
163 * A pointer to a rte_device structure.
165 * 0 on success, negative on error.
167 int rte_eal_dev_detach(struct rte_device *dev);
171 * @b EXPERIMENTAL: this API may change without prior notice
173 * Hotplug add a given device to a specific bus.
176 * The bus name the device is added to.
178 * The device name. Based on this device name, eal will identify a driver
179 * capable of handling it and pass it to the driver probing function.
181 * Device arguments to be passed to the driver.
183 * 0 on success, negative on error.
185 int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devname,
186 const char *devargs);
190 * @b EXPERIMENTAL: this API may change without prior notice
192 * Hotplug remove a given device from a specific bus.
195 * The bus name the device is removed from.
197 * The device name being removed.
199 * 0 on success, negative on error.
201 int __rte_experimental rte_eal_hotplug_remove(const char *busname,
202 const char *devname);
205 * Device comparison function.
207 * This type of function is used to compare an rte_device with arbitrary
214 * Data to compare against. The type of this parameter is determined by
215 * the kind of comparison performed by the function.
218 * 0 if the device matches the data.
219 * !0 if the device does not match.
220 * <0 if ordering is possible and the device is lower than the data.
221 * >0 if ordering is possible and the device is greater than the data.
223 typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data);
225 #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]
227 #define RTE_PMD_EXPORT_NAME(name, idx) \
228 static const char RTE_PMD_EXPORT_NAME_ARRAY(this_pmd_name, idx) \
229 __attribute__((used)) = RTE_STR(name)
231 #define DRV_EXP_TAG(name, tag) __##name##_##tag
233 #define RTE_PMD_REGISTER_PCI_TABLE(name, table) \
234 static const char DRV_EXP_TAG(name, pci_tbl_export)[] __attribute__((used)) = \
237 #define RTE_PMD_REGISTER_PARAM_STRING(name, str) \
238 static const char DRV_EXP_TAG(name, param_string_export)[] \
239 __attribute__((used)) = str
242 * Advertise the list of kernel modules required to run this driver
244 * This string lists the kernel modules required for the devices
245 * associated to a PMD. The format of each line of the string is:
246 * "<device-pattern> <kmod-expression>".
248 * The possible formats for the device pattern are:
249 * "*" all devices supported by this driver
250 * "pci:*" all PCI devices supported by this driver
251 * "pci:v8086:d*:sv*:sd*" all PCI devices supported by this driver
252 * whose vendor id is 0x8086.
254 * The format of the kernel modules list is a parenthesed expression
255 * containing logical-and (&) and logical-or (|).
257 * The device pattern and the kmod expression are separated by a space.
260 * - "* igb_uio | uio_pci_generic | vfio"
262 #define RTE_PMD_REGISTER_KMOD_DEP(name, str) \
263 static const char DRV_EXP_TAG(name, kmod_dep_export)[] \
264 __attribute__((used)) = str
270 #endif /* _RTE_DEV_H_ */