eal: use SPDX tags in 6WIND copyrighted files
[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         /** Bus handle for the device. */
55         struct rte_bus *bus;
56         /** Name of the device. */
57         char name[RTE_DEV_NAME_MAX_LEN];
58         /** Arguments string as given by user or "" for no argument. */
59         char *args;
60 };
61
62 /** user device double-linked queue type definition */
63 TAILQ_HEAD(rte_devargs_list, rte_devargs);
64
65 /** Global list of user devices */
66 extern struct rte_devargs_list devargs_list;
67
68 /**
69  * Parse a devargs string.
70  *
71  * For PCI devices, the format of arguments string is "PCI_ADDR" or
72  * "PCI_ADDR,key=val,key2=val2,...". Examples: "08:00.1", "0000:5:00.0",
73  * "04:00.0,arg=val".
74  *
75  * For virtual devices, the format of arguments string is "DRIVER_NAME*"
76  * or "DRIVER_NAME*,key=val,key2=val2,...". Examples: "net_ring",
77  * "net_ring0", "net_pmdAnything,arg=0:arg2=1".
78  *
79  * The function parses the arguments string to get driver name and driver
80  * arguments.
81  *
82  * @param devargs_str
83  *   The arguments as given by the user.
84  * @param drvname
85  *   The pointer to the string to store parsed driver name.
86  * @param drvargs
87  *   The pointer to the string to store parsed driver arguments.
88  *
89  * @return
90  *   - 0 on success
91  *   - A negative value on error
92  */
93 int rte_eal_parse_devargs_str(const char *devargs_str,
94                                 char **drvname, char **drvargs);
95
96 /**
97  * Parse a device string.
98  *
99  * Verify that a bus is capable of handling the device passed
100  * in argument. Store which bus will handle the device, its name
101  * and the eventual device parameters.
102  *
103  * @param dev
104  *   The device declaration string.
105  * @param da
106  *   The devargs structure holding the device information.
107  *
108  * @return
109  *   - 0 on success.
110  *   - Negative errno on error.
111  */
112 int __rte_experimental
113 rte_eal_devargs_parse(const char *dev,
114                       struct rte_devargs *da);
115
116 /**
117  * Insert an rte_devargs in the global list.
118  *
119  * @param da
120  *  The devargs structure to insert.
121  *
122  * @return
123  *   - 0 on success
124  *   - Negative on error.
125  */
126 int __rte_experimental
127 rte_eal_devargs_insert(struct rte_devargs *da);
128
129 /**
130  * Add a device to the user device list
131  *
132  * For PCI devices, the format of arguments string is "PCI_ADDR" or
133  * "PCI_ADDR,key=val,key2=val2,...". Examples: "08:00.1", "0000:5:00.0",
134  * "04:00.0,arg=val".
135  *
136  * For virtual devices, the format of arguments string is "DRIVER_NAME*"
137  * or "DRIVER_NAME*,key=val,key2=val2,...". Examples: "net_ring",
138  * "net_ring0", "net_pmdAnything,arg=0:arg2=1". The validity of the
139  * driver name is not checked by this function, it is done when probing
140  * the drivers.
141  *
142  * @param devtype
143  *   The type of the device.
144  * @param devargs_str
145  *   The arguments as given by the user.
146  *
147  * @return
148  *   - 0 on success
149  *   - A negative value on error
150  */
151 int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str);
152
153 /**
154  * Remove a device from the user device list.
155  * Its resources are freed.
156  * If the devargs cannot be found, nothing happens.
157  *
158  * @param busname
159  *   bus name of the devargs to remove.
160  *
161  * @param devname
162  *   device name of the devargs to remove.
163  *
164  * @return
165  *   0 on success.
166  *   <0 on error.
167  *   >0 if the devargs was not within the user device list.
168  */
169 int __rte_experimental rte_eal_devargs_remove(const char *busname,
170                                           const char *devname);
171
172 /**
173  * Count the number of user devices of a specified type
174  *
175  * @param devtype
176  *   The type of the devices to counted.
177  *
178  * @return
179  *   The number of devices.
180  */
181 unsigned int
182 rte_eal_devargs_type_count(enum rte_devtype devtype);
183
184 /**
185  * This function dumps the list of user device and their arguments.
186  *
187  * @param f
188  *   A pointer to a file for output
189  */
190 void rte_eal_devargs_dump(FILE *f);
191
192 #ifdef __cplusplus
193 }
194 #endif
195
196 #endif /* _RTE_DEVARGS_H_ */