DPDK  19.02.0
rte_dev.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014 6WIND S.A.
3  */
4 
5 #ifndef _RTE_DEV_H_
6 #define _RTE_DEV_H_
7 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <stdio.h>
21 #include <sys/queue.h>
22 
23 #include <rte_config.h>
24 #include <rte_compat.h>
25 #include <rte_log.h>
26 
34 };
35 
36 struct rte_dev_event {
37  enum rte_dev_event_type type;
38  int subsystem;
39  char *devname;
40 };
41 
42 typedef void (*rte_dev_event_cb_fn)(const char *device_name,
43  enum rte_dev_event_type event,
44  void *cb_arg);
45 
46 __attribute__((format(printf, 2, 0)))
47 static inline void
48 rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
49 {
50  va_list ap;
51 
52  va_start(ap, fmt);
53 
54  {
55  char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
56 
57  va_end(ap);
58 
59  va_start(ap, fmt);
60  vsnprintf(buffer, sizeof(buffer), fmt, ap);
61  va_end(ap);
62 
64  func_name, buffer);
65  }
66 }
67 
68 /*
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.
71  */
72 #if defined(RTE_LIBRTE_EVENTDEV_DEBUG)
73 #define RTE_PMD_DEBUG_TRACE(...) \
74  rte_pmd_debug_trace(__func__, __VA_ARGS__)
75 #else
76 #define RTE_PMD_DEBUG_TRACE(...) (void)0
77 #endif
78 
79 /* Macros for checking for restricting functions to primary instance only */
80 #define RTE_PROC_PRIMARY_OR_ERR_RET(retval) do { \
81  if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
82  RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
83  return retval; \
84  } \
85 } while (0)
86 
87 #define RTE_PROC_PRIMARY_OR_RET() do { \
88  if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
89  RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
90  return; \
91  } \
92 } while (0)
93 
94 /* Macros to check for invalid function pointers */
95 #define RTE_FUNC_PTR_OR_ERR_RET(func, retval) do { \
96  if ((func) == NULL) { \
97  RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
98  return retval; \
99  } \
100 } while (0)
101 
102 #define RTE_FUNC_PTR_OR_RET(func) do { \
103  if ((func) == NULL) { \
104  RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
105  return; \
106  } \
107 } while (0)
108 
113  RTE_KDRV_UNKNOWN = 0,
114  RTE_KDRV_IGB_UIO,
115  RTE_KDRV_VFIO,
116  RTE_KDRV_UIO_GENERIC,
117  RTE_KDRV_NIC_UIO,
118  RTE_KDRV_NONE,
119 };
120 
125  RTE_DEV_WHITELISTED,
126  RTE_DEV_BLACKLISTED,
127 };
128 
133  uint64_t phys_addr;
134  uint64_t len;
135  void *addr;
136 };
137 
141 struct rte_driver {
142  TAILQ_ENTRY(rte_driver) next;
143  const char *name;
144  const char *alias;
145 };
146 
147 /*
148  * Internal identifier length
149  * Sufficiently large to allow for UUID or PCI address
150  */
151 #define RTE_DEV_NAME_MAX_LEN 64
152 
156 struct rte_device {
157  TAILQ_ENTRY(rte_device) next;
158  const char *name;
159  const struct rte_driver *driver;
160  const struct rte_bus *bus;
161  int numa_node;
163 };
164 
176 __rte_experimental
177 int rte_dev_is_probed(const struct rte_device *dev);
178 
195 int rte_eal_hotplug_add(const char *busname, const char *devname,
196  const char *drvargs);
197 
209 int rte_dev_probe(const char *devargs);
210 
224 int rte_eal_hotplug_remove(const char *busname, const char *devname);
225 
237 int rte_dev_remove(struct rte_device *dev);
238 
258 typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data);
259 
260 #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]
261 
262 #define RTE_PMD_EXPORT_NAME(name, idx) \
263 static const char RTE_PMD_EXPORT_NAME_ARRAY(this_pmd_name, idx) \
264 __attribute__((used)) = RTE_STR(name)
265 
266 #define DRV_EXP_TAG(name, tag) __##name##_##tag
267 
268 #define RTE_PMD_REGISTER_PCI_TABLE(name, table) \
269 static const char DRV_EXP_TAG(name, pci_tbl_export)[] __attribute__((used)) = \
270 RTE_STR(table)
271 
272 #define RTE_PMD_REGISTER_PARAM_STRING(name, str) \
273 static const char DRV_EXP_TAG(name, param_string_export)[] \
274 __attribute__((used)) = str
275 
297 #define RTE_PMD_REGISTER_KMOD_DEP(name, str) \
298 static const char DRV_EXP_TAG(name, kmod_dep_export)[] \
299 __attribute__((used)) = str
300 
307  const char *dev_str;
308  const char *bus_str;
309  const char *cls_str;
310  struct rte_bus *bus;
311  struct rte_class *cls;
312  struct rte_device *device;
313  void *class_device;
314 };
315 
344 typedef void *(*rte_dev_iterate_t)(const void *start,
345  const char *devstr,
346  const struct rte_dev_iterator *it);
347 
368 __rte_experimental
369 int
370 rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str);
371 
388 __rte_experimental
389 struct rte_device *
391 
392 #define RTE_DEV_FOREACH(dev, devstr, it) \
393  for (rte_dev_iterator_init(it, devstr), \
394  dev = rte_dev_iterator_next(it); \
395  dev != NULL; \
396  dev = rte_dev_iterator_next(it))
397 
398 #ifdef __cplusplus
399 }
400 #endif
401 
421 int __rte_experimental
422 rte_dev_event_callback_register(const char *device_name,
423  rte_dev_event_cb_fn cb_fn,
424  void *cb_arg);
425 
445 int __rte_experimental
446 rte_dev_event_callback_unregister(const char *device_name,
447  rte_dev_event_cb_fn cb_fn,
448  void *cb_arg);
449 
462 void __rte_experimental
463 rte_dev_event_callback_process(const char *device_name,
464  enum rte_dev_event_type event);
465 
476 int __rte_experimental
478 
489 int __rte_experimental
491 
502 int __rte_experimental
504 
515 int __rte_experimental
517 
518 #endif /* _RTE_DEV_H_ */