eal: replace usage of blacklist/whitelist in enums
[dpdk.git] / lib / librte_eal / 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_ALLOWED,
33         RTE_DEVTYPE_BLOCKED,
34         RTE_DEVTYPE_VIRTUAL,
35 };
36
37 /* Backwards compatibility will be removed later */
38 #define RTE_DEVTYPE_WHITELISTED_PCI \
39         RTE_DEPRECATED(RTE_DEVTYPE_WHITELISTED_PCI) RTE_DEVTYPE_ALLOWED
40 #define RTE_DEVTYPE_BLACKLISTED_PCI \
41         RTE_DEPRECATED(RTE_DEVTYPE_BLACKLISTED_PCI) RTE_DEVTYPE_BLOCKED
42
43 /**
44  * Structure that stores a device given by the user with its arguments
45  *
46  * A user device is a physical or a virtual device given by the user to
47  * the DPDK application at startup through command line arguments.
48  *
49  * The structure stores the configuration of the device, its PCI
50  * identifier if it's a PCI device or the driver name if it's a virtual
51  * device.
52  */
53 struct rte_devargs {
54         /** Next in list. */
55         TAILQ_ENTRY(rte_devargs) next;
56         /** Type of device. */
57         enum rte_devtype type;
58         /** Device policy. */
59         enum rte_dev_policy policy;
60         /** Name of the device. */
61         char name[RTE_DEV_NAME_MAX_LEN];
62         RTE_STD_C11
63         union {
64         /** Arguments string as given by user or "" for no argument. */
65                 char *args;
66                 const char *drv_str;
67         };
68         struct rte_bus *bus; /**< bus handle. */
69         struct rte_class *cls; /**< class handle. */
70         const char *bus_str; /**< bus-related part of device string. */
71         const char *cls_str; /**< class-related part of device string. */
72         const char *data; /**< Device string storage. */
73 };
74
75 /**
76  * Parse a device string.
77  *
78  * Verify that a bus is capable of handling the device passed
79  * in argument. Store which bus will handle the device, its name
80  * and the eventual device parameters.
81  *
82  * The syntax is:
83  *
84  *     bus:device_identifier,arg1=val1,arg2=val2
85  *
86  * where "bus:" is the bus name followed by any character separator.
87  * The bus name is optional. If no bus name is specified, each bus
88  * will attempt to recognize the device identifier. The first one
89  * to succeed will be used.
90  *
91  * Examples:
92  *
93  *     pci:0000:05.00.0,arg=val
94  *     05.00.0,arg=val
95  *     vdev:net_ring0
96  *
97  * @param da
98  *   The devargs structure holding the device information.
99  *
100  * @param dev
101  *   String describing a device.
102  *
103  * @return
104  *   - 0 on success.
105  *   - Negative errno on error.
106  */
107 int
108 rte_devargs_parse(struct rte_devargs *da, const char *dev);
109
110 /**
111  * Parse a device string.
112  *
113  * Verify that a bus is capable of handling the device passed
114  * in argument. Store which bus will handle the device, its name
115  * and the eventual device parameters.
116  *
117  * The device string is built with a printf-like syntax.
118  *
119  * The syntax is:
120  *
121  *     bus:device_identifier,arg1=val1,arg2=val2
122  *
123  * where "bus:" is the bus name followed by any character separator.
124  * The bus name is optional. If no bus name is specified, each bus
125  * will attempt to recognize the device identifier. The first one
126  * to succeed will be used.
127  *
128  * Examples:
129  *
130  *     pci:0000:05.00.0,arg=val
131  *     05.00.0,arg=val
132  *     vdev:net_ring0
133  *
134  * @param da
135  *   The devargs structure holding the device information.
136  * @param format
137  *   Format string describing a device.
138  *
139  * @return
140  *   - 0 on success.
141  *   - Negative errno on error.
142  */
143 int
144 rte_devargs_parsef(struct rte_devargs *da,
145                    const char *format, ...)
146 __rte_format_printf(2, 0);
147
148 /**
149  * Insert an rte_devargs in the global list.
150  *
151  * @param da
152  *  The devargs structure to insert.
153  *  If a devargs for the same device is already inserted,
154  *  it will be updated and returned. It means *da pointer can change.
155  *
156  * @return
157  *   - 0 on success
158  *   - Negative on error.
159  */
160 int
161 rte_devargs_insert(struct rte_devargs **da);
162
163 /**
164  * Add a device to the user device list
165  * See rte_devargs_parse() for details.
166  *
167  * @param devtype
168  *   The type of the device.
169  * @param devargs_str
170  *   The arguments as given by the user.
171  *
172  * @return
173  *   - 0 on success
174  *   - A negative value on error
175  */
176 int rte_devargs_add(enum rte_devtype devtype, const char *devargs_str);
177
178 /**
179  * Remove a device from the user device list.
180  * Its resources are freed.
181  * If the devargs cannot be found, nothing happens.
182  *
183  * @param devargs
184  *   The instance or a copy of devargs to remove.
185  *
186  * @return
187  *   0 on success.
188  *   <0 on error.
189  *   >0 if the devargs was not within the user device list.
190  */
191 int rte_devargs_remove(struct rte_devargs *devargs);
192
193 /**
194  * Count the number of user devices of a specified type
195  *
196  * @param devtype
197  *   The type of the devices to counted.
198  *
199  * @return
200  *   The number of devices.
201  */
202 unsigned int
203 rte_devargs_type_count(enum rte_devtype devtype);
204
205 /**
206  * This function dumps the list of user device and their arguments.
207  *
208  * @param f
209  *   A pointer to a file for output
210  */
211 void rte_devargs_dump(FILE *f);
212
213 /**
214  * Find next rte_devargs matching the provided bus name.
215  *
216  * @param busname
217  *   Limit the iteration to devargs related to buses
218  *   matching this name.
219  *   Will return any next rte_devargs if NULL.
220  *
221  * @param start
222  *   Starting iteration point. The iteration will start at
223  *   the first rte_devargs if NULL.
224  *
225  * @return
226  *   Next rte_devargs entry matching the requested bus,
227  *   NULL if there is none.
228  */
229 struct rte_devargs *
230 rte_devargs_next(const char *busname, const struct rte_devargs *start);
231
232 /**
233  * Iterate over all rte_devargs for a specific bus.
234  */
235 #define RTE_EAL_DEVARGS_FOREACH(busname, da) \
236         for (da = rte_devargs_next(busname, NULL); \
237              da != NULL; \
238              da = rte_devargs_next(busname, da)) \
239
240 #ifdef __cplusplus
241 }
242 #endif
243
244 #endif /* _RTE_DEVARGS_H_ */