DPDK  18.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 
27 __attribute__((format(printf, 2, 0)))
28 static inline void
29 rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
30 {
31  va_list ap;
32 
33  va_start(ap, fmt);
34 
35  char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
36 
37  va_end(ap);
38 
39  va_start(ap, fmt);
40  vsnprintf(buffer, sizeof(buffer), fmt, ap);
41  va_end(ap);
42 
43  rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD, "%s: %s", func_name, buffer);
44 }
45 
46 /*
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.
49  */
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__)
55 #else
56 #define RTE_PMD_DEBUG_TRACE(...) (void)0
57 #endif
58 
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"); \
63  return retval; \
64  } \
65 } while (0)
66 
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"); \
70  return; \
71  } \
72 } while (0)
73 
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"); \
78  return retval; \
79  } \
80 } while (0)
81 
82 #define RTE_FUNC_PTR_OR_RET(func) do { \
83  if ((func) == NULL) { \
84  RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
85  return; \
86  } \
87 } while (0)
88 
93  RTE_KDRV_UNKNOWN = 0,
94  RTE_KDRV_IGB_UIO,
95  RTE_KDRV_VFIO,
96  RTE_KDRV_UIO_GENERIC,
97  RTE_KDRV_NIC_UIO,
98  RTE_KDRV_NONE,
99 };
100 
105  RTE_DEV_WHITELISTED,
106  RTE_DEV_BLACKLISTED,
107 };
108 
113  uint64_t phys_addr;
114  uint64_t len;
115  void *addr;
116 };
117 
121 struct rte_driver {
122  TAILQ_ENTRY(rte_driver) next;
123  const char *name;
124  const char *alias;
125 };
126 
127 /*
128  * Internal identifier length
129  * Sufficiently large to allow for UUID or PCI address
130  */
131 #define RTE_DEV_NAME_MAX_LEN 64
132 
136 struct rte_device {
137  TAILQ_ENTRY(rte_device) next;
138  const char *name;
139  const struct rte_driver *driver;
140  int numa_node;
142 };
143 
157 int rte_eal_dev_attach(const char *name, const char *devargs);
158 
167 int rte_eal_dev_detach(struct rte_device *dev);
168 
185 int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devname,
186  const char *devargs);
187 
201 int __rte_experimental rte_eal_hotplug_remove(const char *busname,
202  const char *devname);
203 
223 typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data);
224 
225 #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]
226 
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)
230 
231 #define DRV_EXP_TAG(name, tag) __##name##_##tag
232 
233 #define RTE_PMD_REGISTER_PCI_TABLE(name, table) \
234 static const char DRV_EXP_TAG(name, pci_tbl_export)[] __attribute__((used)) = \
235 RTE_STR(table)
236 
237 #define RTE_PMD_REGISTER_PARAM_STRING(name, str) \
238 static const char DRV_EXP_TAG(name, param_string_export)[] \
239 __attribute__((used)) = str
240 
262 #define RTE_PMD_REGISTER_KMOD_DEP(name, str) \
263 static const char DRV_EXP_TAG(name, kmod_dep_export)[] \
264 __attribute__((used)) = str
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif /* _RTE_DEV_H_ */
#define RTE_LOG_ERR
Definition: rte_log.h:81
uint64_t len
Definition: rte_dev.h:114
int rte_log(uint32_t level, uint32_t logtype, const char *format,...)
int rte_eal_dev_attach(const char *name, const char *devargs)
int rte_eal_dev_detach(struct rte_device *dev)
TAILQ_ENTRY(rte_driver) next
uint64_t phys_addr
Definition: rte_dev.h:113
TAILQ_ENTRY(rte_device) next
rte_kernel_driver
Definition: rte_dev.h:92
char name[RTE_DEV_NAME_MAX_LEN]
Definition: rte_devargs.h:57
rte_dev_policy
Definition: rte_dev.h:104
int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devname, const char *devargs)
struct rte_devargs * devargs
Definition: rte_dev.h:141
int numa_node
Definition: rte_dev.h:140
#define RTE_LOGTYPE_PMD
Definition: rte_log.h:47
const char * name
Definition: rte_dev.h:123
const char * name
Definition: rte_dev.h:138
const char * alias
Definition: rte_dev.h:124
const struct rte_driver * driver
Definition: rte_dev.h:139
int(* rte_dev_cmp_t)(const struct rte_device *dev, const void *data)
Definition: rte_dev.h:223
int __rte_experimental rte_eal_hotplug_remove(const char *busname, const char *devname)