New upstream version 18.08
[deb_dpdk.git] / lib / librte_eal / common / include / rte_devargs.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2014 6WIND S.A.
3  */
4
5 #ifndef _RTE_DEVARGS_H_
6 #define _RTE_DEVARGS_H_
7
8 /**
9  * @file
10  *
11  * RTE devargs: list of devices and their user arguments
12  *
13  * This file stores a list of devices and their arguments given by
14  * the user when a DPDK application is started. These devices can be PCI
15  * devices or virtual devices. These devices are stored at startup in a
16  * list of rte_devargs structures.
17  */
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #include <stdio.h>
24 #include <sys/queue.h>
25 #include <rte_compat.h>
26 #include <rte_bus.h>
27
28 /**
29  * Type of generic device
30  */
31 enum rte_devtype {
32         RTE_DEVTYPE_WHITELISTED_PCI,
33         RTE_DEVTYPE_BLACKLISTED_PCI,
34         RTE_DEVTYPE_VIRTUAL,
35 };
36
37 /**
38  * Structure that stores a device given by the user with its arguments
39  *
40  * A user device is a physical or a virtual device given by the user to
41  * the DPDK application at startup through command line arguments.
42  *
43  * The structure stores the configuration of the device, its PCI
44  * identifier if it's a PCI device or the driver name if it's a virtual
45  * device.
46  */
47 struct rte_devargs {
48         /** Next in list. */
49         TAILQ_ENTRY(rte_devargs) next;
50         /** Type of device. */
51         enum rte_devtype type;
52         /** Device policy. */
53         enum rte_dev_policy policy;
54         /** Name of the device. */
55         char name[RTE_DEV_NAME_MAX_LEN];
56         RTE_STD_C11
57         union {
58         /** Arguments string as given by user or "" for no argument. */
59                 char *args;
60                 const char *drv_str;
61         };
62         struct rte_bus *bus; /**< bus handle. */
63         struct rte_class *cls; /**< class handle. */
64         const char *bus_str; /**< bus-related part of device string. */
65         const char *cls_str; /**< class-related part of device string. */
66         const char *data; /**< Device string storage. */
67 };
68
69 /**
70  * @deprecated
71  * Parse a devargs string.
72  *
73  * For PCI devices, the format of arguments string is "PCI_ADDR" or
74  * "PCI_ADDR,key=val,key2=val2,...". Examples: "08:00.1", "0000:5:00.0",
75  * "04:00.0,arg=val".
76  *
77  * For virtual devices, the format of arguments string is "DRIVER_NAME*"
78  * or "DRIVER_NAME*,key=val,key2=val2,...". Examples: "net_ring",
79  * "net_ring0", "net_pmdAnything,arg=0:arg2=1".
80  *
81  * The function parses the arguments string to get driver name and driver
82  * arguments.
83  *
84  * @param devargs_str
85  *   The arguments as given by the user.
86  * @param drvname
87  *   The pointer to the string to store parsed driver name.
88  * @param drvargs
89  *   The pointer to the string to store parsed driver arguments.
90  *
91  * @return
92  *   - 0 on success
93  *   - A negative value on error
94  */
95 __rte_deprecated
96 int rte_eal_parse_devargs_str(const char *devargs_str,
97                                 char **drvname, char **drvargs);
98
99 /**
100  * Parse a device string.
101  *
102  * Verify that a bus is capable of handling the device passed
103  * in argument. Store which bus will handle the device, its name
104  * and the eventual device parameters.
105  *
106  * The syntax is:
107  *
108  *     bus:device_identifier,arg1=val1,arg2=val2
109  *
110  * where "bus:" is the bus name followed by any character separator.
111  * The bus name is optional. If no bus name is specified, each bus
112  * will attempt to recognize the device identifier. The first one
113  * to succeed will be used.
114  *
115  * Examples:
116  *
117  *     pci:0000:05.00.0,arg=val
118  *     05.00.0,arg=val
119  *     vdev:net_ring0
120  *
121  * @param da
122  *   The devargs structure holding the device information.
123  *
124  * @param dev
125  *   String describing a device.
126  *
127  * @return
128  *   - 0 on success.
129  *   - Negative errno on error.
130  */
131 __rte_experimental
132 int
133 rte_devargs_parse(struct rte_devargs *da, const char *dev);
134
135 /**
136  * Parse a device string.
137  *
138  * Verify that a bus is capable of handling the device passed
139  * in argument. Store which bus will handle the device, its name
140  * and the eventual device parameters.
141  *
142  * The device string is built with a printf-like syntax.
143  *
144  * The syntax is:
145  *
146  *     bus:device_identifier,arg1=val1,arg2=val2
147  *
148  * where "bus:" is the bus name followed by any character separator.
149  * The bus name is optional. If no bus name is specified, each bus
150  * will attempt to recognize the device identifier. The first one
151  * to succeed will be used.
152  *
153  * Examples:
154  *
155  *     pci:0000:05.00.0,arg=val
156  *     05.00.0,arg=val
157  *     vdev:net_ring0
158  *
159  * @param da
160  *   The devargs structure holding the device information.
161  * @param format
162  *   Format string describing a device.
163  *
164  * @return
165  *   - 0 on success.
166  *   - Negative errno on error.
167  */
168 __rte_experimental
169 int
170 rte_devargs_parsef(struct rte_devargs *da,
171                    const char *format, ...)
172 __attribute__((format(printf, 2, 0)));
173
174 /**
175  * Insert an rte_devargs in the global list.
176  *
177  * @param da
178  *  The devargs structure to insert.
179  *
180  * @return
181  *   - 0 on success
182  *   - Negative on error.
183  */
184 __rte_experimental
185 int
186 rte_devargs_insert(struct rte_devargs *da);
187
188 /**
189  * Add a device to the user device list
190  * See rte_devargs_parse() for details.
191  *
192  * @param devtype
193  *   The type of the device.
194  * @param devargs_str
195  *   The arguments as given by the user.
196  *
197  * @return
198  *   - 0 on success
199  *   - A negative value on error
200  */
201 __rte_experimental
202 int rte_devargs_add(enum rte_devtype devtype, const char *devargs_str);
203
204 /**
205  * @deprecated
206  * Add a device to the user device list
207  * See rte_devargs_parse() for details.
208  *
209  * @param devtype
210  *   The type of the device.
211  * @param devargs_str
212  *   The arguments as given by the user.
213  *
214  * @return
215  *   - 0 on success
216  *   - A negative value on error
217  */
218 __rte_deprecated
219 int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str);
220
221 /**
222  * Remove a device from the user device list.
223  * Its resources are freed.
224  * If the devargs cannot be found, nothing happens.
225  *
226  * @param busname
227  *   bus name of the devargs to remove.
228  *
229  * @param devname
230  *   device name of the devargs to remove.
231  *
232  * @return
233  *   0 on success.
234  *   <0 on error.
235  *   >0 if the devargs was not within the user device list.
236  */
237 __rte_experimental
238 int rte_devargs_remove(const char *busname,
239                        const char *devname);
240
241 /**
242  * Count the number of user devices of a specified type
243  *
244  * @param devtype
245  *   The type of the devices to counted.
246  *
247  * @return
248  *   The number of devices.
249  */
250 __rte_experimental
251 unsigned int
252 rte_devargs_type_count(enum rte_devtype devtype);
253
254 /**
255  * @deprecated
256  * Count the number of user devices of a specified type
257  *
258  * @param devtype
259  *   The type of the devices to counted.
260  *
261  * @return
262  *   The number of devices.
263  */
264 __rte_deprecated
265 unsigned int
266 rte_eal_devargs_type_count(enum rte_devtype devtype);
267
268 /**
269  * This function dumps the list of user device and their arguments.
270  *
271  * @param f
272  *   A pointer to a file for output
273  */
274 __rte_experimental
275 void rte_devargs_dump(FILE *f);
276
277 /**
278  * @deprecated
279  * This function dumps the list of user device and their arguments.
280  *
281  * @param f
282  *   A pointer to a file for output
283  */
284 __rte_deprecated
285 void rte_eal_devargs_dump(FILE *f);
286
287 /**
288  * Find next rte_devargs matching the provided bus name.
289  *
290  * @param busname
291  *   Limit the iteration to devargs related to buses
292  *   matching this name.
293  *   Will return any next rte_devargs if NULL.
294  *
295  * @param start
296  *   Starting iteration point. The iteration will start at
297  *   the first rte_devargs if NULL.
298  *
299  * @return
300  *   Next rte_devargs entry matching the requested bus,
301  *   NULL if there is none.
302  */
303 __rte_experimental
304 struct rte_devargs *
305 rte_devargs_next(const char *busname, const struct rte_devargs *start);
306
307 /**
308  * Iterate over all rte_devargs for a specific bus.
309  */
310 #define RTE_EAL_DEVARGS_FOREACH(busname, da) \
311         for (da = rte_devargs_next(busname, NULL); \
312              da != NULL; \
313              da = rte_devargs_next(busname, da)) \
314
315 #ifdef __cplusplus
316 }
317 #endif
318
319 #endif /* _RTE_DEVARGS_H_ */