New upstream version 18.11-rc3
[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  * Parse a device string.
71  *
72  * Verify that a bus is capable of handling the device passed
73  * in argument. Store which bus will handle the device, its name
74  * and the eventual device parameters.
75  *
76  * The syntax is:
77  *
78  *     bus:device_identifier,arg1=val1,arg2=val2
79  *
80  * where "bus:" is the bus name followed by any character separator.
81  * The bus name is optional. If no bus name is specified, each bus
82  * will attempt to recognize the device identifier. The first one
83  * to succeed will be used.
84  *
85  * Examples:
86  *
87  *     pci:0000:05.00.0,arg=val
88  *     05.00.0,arg=val
89  *     vdev:net_ring0
90  *
91  * @param da
92  *   The devargs structure holding the device information.
93  *
94  * @param dev
95  *   String describing a device.
96  *
97  * @return
98  *   - 0 on success.
99  *   - Negative errno on error.
100  */
101 __rte_experimental
102 int
103 rte_devargs_parse(struct rte_devargs *da, const char *dev);
104
105 /**
106  * Parse a device string.
107  *
108  * Verify that a bus is capable of handling the device passed
109  * in argument. Store which bus will handle the device, its name
110  * and the eventual device parameters.
111  *
112  * The device string is built with a printf-like syntax.
113  *
114  * The syntax is:
115  *
116  *     bus:device_identifier,arg1=val1,arg2=val2
117  *
118  * where "bus:" is the bus name followed by any character separator.
119  * The bus name is optional. If no bus name is specified, each bus
120  * will attempt to recognize the device identifier. The first one
121  * to succeed will be used.
122  *
123  * Examples:
124  *
125  *     pci:0000:05.00.0,arg=val
126  *     05.00.0,arg=val
127  *     vdev:net_ring0
128  *
129  * @param da
130  *   The devargs structure holding the device information.
131  * @param format
132  *   Format string describing a device.
133  *
134  * @return
135  *   - 0 on success.
136  *   - Negative errno on error.
137  */
138 __rte_experimental
139 int
140 rte_devargs_parsef(struct rte_devargs *da,
141                    const char *format, ...)
142 __attribute__((format(printf, 2, 0)));
143
144 /**
145  * Insert an rte_devargs in the global list.
146  *
147  * @param da
148  *  The devargs structure to insert.
149  *  If a devargs for the same device is already inserted,
150  *  it will be updated and returned. It means *da pointer can change.
151  *
152  * @return
153  *   - 0 on success
154  *   - Negative on error.
155  */
156 __rte_experimental
157 int
158 rte_devargs_insert(struct rte_devargs **da);
159
160 /**
161  * Add a device to the user device list
162  * See rte_devargs_parse() for details.
163  *
164  * @param devtype
165  *   The type of the device.
166  * @param devargs_str
167  *   The arguments as given by the user.
168  *
169  * @return
170  *   - 0 on success
171  *   - A negative value on error
172  */
173 __rte_experimental
174 int rte_devargs_add(enum rte_devtype devtype, const char *devargs_str);
175
176 /**
177  * Remove a device from the user device list.
178  * Its resources are freed.
179  * If the devargs cannot be found, nothing happens.
180  *
181  * @param devargs
182  *   The instance or a copy of devargs to remove.
183  *
184  * @return
185  *   0 on success.
186  *   <0 on error.
187  *   >0 if the devargs was not within the user device list.
188  */
189 __rte_experimental
190 int rte_devargs_remove(struct rte_devargs *devargs);
191
192 /**
193  * Count the number of user devices of a specified type
194  *
195  * @param devtype
196  *   The type of the devices to counted.
197  *
198  * @return
199  *   The number of devices.
200  */
201 __rte_experimental
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 __rte_experimental
212 void rte_devargs_dump(FILE *f);
213
214 /**
215  * Find next rte_devargs matching the provided bus name.
216  *
217  * @param busname
218  *   Limit the iteration to devargs related to buses
219  *   matching this name.
220  *   Will return any next rte_devargs if NULL.
221  *
222  * @param start
223  *   Starting iteration point. The iteration will start at
224  *   the first rte_devargs if NULL.
225  *
226  * @return
227  *   Next rte_devargs entry matching the requested bus,
228  *   NULL if there is none.
229  */
230 __rte_experimental
231 struct rte_devargs *
232 rte_devargs_next(const char *busname, const struct rte_devargs *start);
233
234 /**
235  * Iterate over all rte_devargs for a specific bus.
236  */
237 #define RTE_EAL_DEVARGS_FOREACH(busname, da) \
238         for (da = rte_devargs_next(busname, NULL); \
239              da != NULL; \
240              da = rte_devargs_next(busname, da)) \
241
242 #ifdef __cplusplus
243 }
244 #endif
245
246 #endif /* _RTE_DEVARGS_H_ */