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