/src/openvswitch/lib/netdev-provider.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2016 Nicira, Inc. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at: |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #ifndef NETDEV_PROVIDER_H |
18 | | #define NETDEV_PROVIDER_H 1 |
19 | | |
20 | | /* Generic interface to network devices. */ |
21 | | |
22 | | #include "connectivity.h" |
23 | | #include "netdev.h" |
24 | | #include "netdev-offload.h" |
25 | | #include "openvswitch/list.h" |
26 | | #include "ovs-numa.h" |
27 | | #include "ovs-rcu.h" |
28 | | #include "packets.h" |
29 | | #include "seq.h" |
30 | | #include "openvswitch/shash.h" |
31 | | #include "smap.h" |
32 | | |
33 | | #ifdef __cplusplus |
34 | | extern "C" { |
35 | | #endif |
36 | | |
37 | | struct netdev_tnl_build_header_params; |
38 | 0 | #define NETDEV_NUMA_UNSPEC OVS_NUMA_UNSPEC |
39 | | |
40 | | enum netdev_ol_flags { |
41 | | NETDEV_TX_OFFLOAD_IPV4_CKSUM = 1 << 0, |
42 | | NETDEV_TX_OFFLOAD_TCP_CKSUM = 1 << 1, |
43 | | NETDEV_TX_OFFLOAD_UDP_CKSUM = 1 << 2, |
44 | | NETDEV_TX_OFFLOAD_SCTP_CKSUM = 1 << 3, |
45 | | NETDEV_TX_OFFLOAD_TCP_TSO = 1 << 4, |
46 | | NETDEV_TX_VXLAN_TNL_TSO = 1 << 5, |
47 | | NETDEV_TX_GENEVE_TNL_TSO = 1 << 6, |
48 | | NETDEV_TX_OFFLOAD_OUTER_IP_CKSUM = 1 << 7, |
49 | | NETDEV_TX_OFFLOAD_OUTER_UDP_CKSUM = 1 << 8, |
50 | | NETDEV_TX_GRE_TNL_TSO = 1 << 9, |
51 | | }; |
52 | | |
53 | | /* A network device (e.g. an Ethernet device). |
54 | | * |
55 | | * Network device implementations may read these members but should not modify |
56 | | * them. */ |
57 | | struct netdev { |
58 | | /* The following do not change during the lifetime of a struct netdev. */ |
59 | | char *name; /* Name of network device. */ |
60 | | const struct netdev_class *netdev_class; /* Functions to control |
61 | | this device. */ |
62 | | |
63 | | /* If this is 'true' the user did not specify a netdev_class when |
64 | | * opening this device, and therefore got assigned to the "system" class */ |
65 | | bool auto_classified; |
66 | | |
67 | | /* This bitmask of the offloading features enabled by the netdev. */ |
68 | | uint64_t ol_flags; |
69 | | |
70 | | /* If this is 'true', the user explicitly specified an MTU for this |
71 | | * netdev. Otherwise, Open vSwitch is allowed to override it. */ |
72 | | bool mtu_user_config; |
73 | | |
74 | | int ref_cnt; /* Times this devices was opened. */ |
75 | | |
76 | | /* A sequence number which indicates changes in one of 'netdev''s |
77 | | * properties. It must be nonzero so that users have a value which |
78 | | * they may use as a reset when tracking 'netdev'. |
79 | | * |
80 | | * Minimally, the sequence number is required to change whenever |
81 | | * 'netdev''s flags, features, ethernet address, or carrier changes. */ |
82 | | atomic_uint64_t change_seq; |
83 | | |
84 | | /* A netdev provider might be unable to change some of the device's |
85 | | * parameter (n_rxq, mtu) when the device is in use. In this case |
86 | | * the provider can notify the upper layer by calling |
87 | | * netdev_request_reconfigure(). The upper layer will react by stopping |
88 | | * the operations on the device and calling netdev_reconfigure() to allow |
89 | | * the configuration changes. 'last_reconfigure_seq' remembers the value |
90 | | * of 'reconfigure_seq' when the last reconfiguration happened. */ |
91 | | struct seq *reconfigure_seq; |
92 | | uint64_t last_reconfigure_seq; |
93 | | |
94 | | /* The core netdev code initializes these at netdev construction and only |
95 | | * provide read-only access to its client. Netdev implementations may |
96 | | * modify them. */ |
97 | | int n_txq; |
98 | | int n_rxq; |
99 | | struct shash_node *node; /* Pointer to element in global map. */ |
100 | | struct ovs_list saved_flags_list; /* Contains "struct netdev_saved_flags". */ |
101 | | |
102 | | /* Functions to control flow offloading. */ |
103 | | OVSRCU_TYPE(const struct netdev_flow_api *) flow_api; |
104 | | const char *dpif_type; /* Type of dpif this netdev belongs to. */ |
105 | | struct netdev_hw_info hw_info; /* Offload-capable netdev info. */ |
106 | | }; |
107 | | |
108 | | static inline void |
109 | | netdev_change_seq_changed(const struct netdev *netdev_) |
110 | 0 | { |
111 | 0 | uint64_t change_seq; |
112 | 0 | struct netdev *netdev = CONST_CAST(struct netdev *, netdev_); |
113 | 0 | seq_change(connectivity_seq_get()); |
114 | |
|
115 | 0 | atomic_read_relaxed(&netdev->change_seq, &change_seq); |
116 | 0 | change_seq++; |
117 | 0 | if (OVS_UNLIKELY(!change_seq)) { |
118 | 0 | change_seq++; |
119 | 0 | } |
120 | 0 | atomic_store_explicit(&netdev->change_seq, change_seq, |
121 | 0 | memory_order_release); |
122 | 0 | } Unexecuted instantiation: dp-packet.c:netdev_change_seq_changed Unexecuted instantiation: flow.c:netdev_change_seq_changed Unexecuted instantiation: netdev.c:netdev_change_seq_changed Unexecuted instantiation: netdev-linux.c:netdev_change_seq_changed Unexecuted instantiation: netdev-offload-tc.c:netdev_change_seq_changed Unexecuted instantiation: dp-packet-gso.c:netdev_change_seq_changed Unexecuted instantiation: dpif.c:netdev_change_seq_changed Unexecuted instantiation: netdev-offload.c:netdev_change_seq_changed Unexecuted instantiation: netdev-vport.c:netdev_change_seq_changed Unexecuted instantiation: netdev-native-tnl.c:netdev_change_seq_changed Unexecuted instantiation: dpif-netlink.c:netdev_change_seq_changed Unexecuted instantiation: dpif-netdev.c:netdev_change_seq_changed |
123 | | |
124 | | static inline void |
125 | | netdev_request_reconfigure(struct netdev *netdev) |
126 | 0 | { |
127 | 0 | seq_change(netdev->reconfigure_seq); |
128 | 0 | } Unexecuted instantiation: dp-packet.c:netdev_request_reconfigure Unexecuted instantiation: flow.c:netdev_request_reconfigure Unexecuted instantiation: netdev.c:netdev_request_reconfigure Unexecuted instantiation: netdev-linux.c:netdev_request_reconfigure Unexecuted instantiation: netdev-offload-tc.c:netdev_request_reconfigure Unexecuted instantiation: dp-packet-gso.c:netdev_request_reconfigure Unexecuted instantiation: dpif.c:netdev_request_reconfigure Unexecuted instantiation: netdev-offload.c:netdev_request_reconfigure Unexecuted instantiation: netdev-vport.c:netdev_request_reconfigure Unexecuted instantiation: netdev-native-tnl.c:netdev_request_reconfigure Unexecuted instantiation: dpif-netlink.c:netdev_request_reconfigure Unexecuted instantiation: dpif-netdev.c:netdev_request_reconfigure |
129 | | |
130 | | const char *netdev_get_type(const struct netdev *); |
131 | | const struct netdev_class *netdev_get_class(const struct netdev *); |
132 | | const char *netdev_get_name(const struct netdev *); |
133 | | struct netdev *netdev_from_name(const char *name); |
134 | | void netdev_get_devices(const struct netdev_class *, |
135 | | struct shash *device_list); |
136 | | struct netdev **netdev_get_vports(size_t *size); |
137 | | |
138 | | /* A data structure for capturing packets received by a network device. |
139 | | * |
140 | | * Network device implementations may read these members but should not modify |
141 | | * them. |
142 | | * |
143 | | * None of these members change during the lifetime of a struct netdev_rxq. */ |
144 | | struct netdev_rxq { |
145 | | struct netdev *netdev; /* Owns a reference to the netdev. */ |
146 | | int queue_id; |
147 | | }; |
148 | | |
149 | | struct netdev *netdev_rxq_get_netdev(const struct netdev_rxq *); |
150 | | |
151 | | |
152 | | /* Network device class structure, to be defined by each implementation of a |
153 | | * network device. |
154 | | * |
155 | | * These functions return 0 if successful or a positive errno value on failure, |
156 | | * except where otherwise noted. |
157 | | * |
158 | | * |
159 | | * Data Structures |
160 | | * =============== |
161 | | * |
162 | | * These functions work primarily with two different kinds of data structures: |
163 | | * |
164 | | * - "struct netdev", which represents a network device. |
165 | | * |
166 | | * - "struct netdev_rxq", which represents a handle for capturing packets |
167 | | * received on a network device |
168 | | * |
169 | | * Each of these data structures contains all of the implementation-independent |
170 | | * generic state for the respective concept, called the "base" state. None of |
171 | | * them contains any extra space for implementations to use. Instead, each |
172 | | * implementation is expected to declare its own data structure that contains |
173 | | * an instance of the generic data structure plus additional |
174 | | * implementation-specific members, called the "derived" state. The |
175 | | * implementation can use casts or (preferably) the CONTAINER_OF macro to |
176 | | * obtain access to derived state given only a pointer to the embedded generic |
177 | | * data structure. |
178 | | * |
179 | | * |
180 | | * Life Cycle |
181 | | * ========== |
182 | | * |
183 | | * Four stylized functions accompany each of these data structures: |
184 | | * |
185 | | * "alloc" "construct" "destruct" "dealloc" |
186 | | * ------------ ---------------- --------------- -------------- |
187 | | * netdev ->alloc ->construct ->destruct ->dealloc |
188 | | * netdev_rxq ->rxq_alloc ->rxq_construct ->rxq_destruct ->rxq_dealloc |
189 | | * |
190 | | * Any instance of a given data structure goes through the following life |
191 | | * cycle: |
192 | | * |
193 | | * 1. The client calls the "alloc" function to obtain raw memory. If "alloc" |
194 | | * fails, skip all the other steps. |
195 | | * |
196 | | * 2. The client initializes all of the data structure's base state. If this |
197 | | * fails, skip to step 7. |
198 | | * |
199 | | * 3. The client calls the "construct" function. The implementation |
200 | | * initializes derived state. It may refer to the already-initialized |
201 | | * base state. If "construct" fails, skip to step 6. |
202 | | * |
203 | | * 4. The data structure is now initialized and in use. |
204 | | * |
205 | | * 5. When the data structure is no longer needed, the client calls the |
206 | | * "destruct" function. The implementation uninitializes derived state. |
207 | | * The base state has not been uninitialized yet, so the implementation |
208 | | * may still refer to it. |
209 | | * |
210 | | * 6. The client uninitializes all of the data structure's base state. |
211 | | * |
212 | | * 7. The client calls the "dealloc" to free the raw memory. The |
213 | | * implementation must not refer to base or derived state in the data |
214 | | * structure, because it has already been uninitialized. |
215 | | * |
216 | | * If netdev support multi-queue IO then netdev->construct should set initialize |
217 | | * netdev->n_rxq to number of queues. |
218 | | * |
219 | | * Each "alloc" function allocates and returns a new instance of the respective |
220 | | * data structure. The "alloc" function is not given any information about the |
221 | | * use of the new data structure, so it cannot perform much initialization. |
222 | | * Its purpose is just to ensure that the new data structure has enough room |
223 | | * for base and derived state. It may return a null pointer if memory is not |
224 | | * available, in which case none of the other functions is called. |
225 | | * |
226 | | * Each "construct" function initializes derived state in its respective data |
227 | | * structure. When "construct" is called, all of the base state has already |
228 | | * been initialized, so the "construct" function may refer to it. The |
229 | | * "construct" function is allowed to fail, in which case the client calls the |
230 | | * "dealloc" function (but not the "destruct" function). |
231 | | * |
232 | | * Each "destruct" function uninitializes and frees derived state in its |
233 | | * respective data structure. When "destruct" is called, the base state has |
234 | | * not yet been uninitialized, so the "destruct" function may refer to it. The |
235 | | * "destruct" function is not allowed to fail. |
236 | | * |
237 | | * Each "dealloc" function frees raw memory that was allocated by the |
238 | | * "alloc" function. The memory's base and derived members might not have ever |
239 | | * been initialized (but if "construct" returned successfully, then it has been |
240 | | * "destruct"ed already). The "dealloc" function is not allowed to fail. |
241 | | * |
242 | | * |
243 | | * Device Change Notification |
244 | | * ========================== |
245 | | * |
246 | | * Minimally, implementations are required to report changes to netdev flags, |
247 | | * features, ethernet address or carrier through connectivity_seq. Changes to |
248 | | * other properties are allowed to cause notification through this interface, |
249 | | * although implementations should try to avoid this. connectivity_seq_get() |
250 | | * can be used to acquire a reference to the struct seq. The interface is |
251 | | * described in detail in seq.h. */ |
252 | | struct netdev_class { |
253 | | /* Type of netdevs in this class, e.g. "system", "tap", "gre", etc. |
254 | | * |
255 | | * One of the providers should supply a "system" type, since this is |
256 | | * the type assumed if no type is specified when opening a netdev. |
257 | | * The "system" type corresponds to an existing network device on |
258 | | * the system. */ |
259 | | const char *type; |
260 | | |
261 | | /* If 'true' then this netdev should be polled by PMD threads. */ |
262 | | bool is_pmd; |
263 | | |
264 | | /* ## ------------------- ## */ |
265 | | /* ## Top-Level Functions ## */ |
266 | | /* ## ------------------- ## */ |
267 | | |
268 | | /* Called when the netdev provider is registered, typically at program |
269 | | * startup. Returning an error from this function will prevent any network |
270 | | * device in this class from being opened. |
271 | | * |
272 | | * This function may be set to null if a network device class needs no |
273 | | * initialization at registration time. */ |
274 | | int (*init)(void); |
275 | | |
276 | | /* Performs periodic work needed by netdevs of this class. May be null if |
277 | | * no periodic work is necessary. |
278 | | * |
279 | | * 'netdev_class' points to the class. It is useful in case the same |
280 | | * function is used to implement different classes. */ |
281 | | void (*run)(const struct netdev_class *netdev_class); |
282 | | |
283 | | /* Arranges for poll_block() to wake up if the "run" member function needs |
284 | | * to be called. Implementations are additionally required to wake |
285 | | * whenever something changes in any of its netdevs which would cause their |
286 | | * ->change_seq() function to change its result. May be null if nothing is |
287 | | * needed here. |
288 | | * |
289 | | * 'netdev_class' points to the class. It is useful in case the same |
290 | | * function is used to implement different classes. */ |
291 | | void (*wait)(const struct netdev_class *netdev_class); |
292 | | |
293 | | /* ## ---------------- ## */ |
294 | | /* ## netdev Functions ## */ |
295 | | /* ## ---------------- ## */ |
296 | | |
297 | | /* Life-cycle functions for a netdev. See the large comment above on |
298 | | * struct netdev_class. */ |
299 | | struct netdev *(*alloc)(void); |
300 | | int (*construct)(struct netdev *); |
301 | | void (*destruct)(struct netdev *); |
302 | | void (*dealloc)(struct netdev *); |
303 | | |
304 | | /* Fetches the device 'netdev''s configuration, storing it in 'args'. |
305 | | * The caller owns 'args' and pre-initializes it to an empty smap. |
306 | | * |
307 | | * If this netdev class does not have any configuration options, this may |
308 | | * be a null pointer. */ |
309 | | int (*get_config)(const struct netdev *netdev, struct smap *args); |
310 | | |
311 | | /* Changes the device 'netdev''s configuration to 'args'. |
312 | | * |
313 | | * If this netdev class does not support configuration, this may be a null |
314 | | * pointer. |
315 | | * |
316 | | * If the return value is not zero (meaning that an error occurred), |
317 | | * the provider can allocate a string with an error message in '*errp'. |
318 | | * The caller has to call free on it. */ |
319 | | int (*set_config)(struct netdev *netdev, const struct smap *args, |
320 | | char **errp); |
321 | | |
322 | | /* Returns the tunnel configuration of 'netdev'. If 'netdev' is |
323 | | * not a tunnel, returns null. |
324 | | * |
325 | | * If this function would always return null, it may be null instead. */ |
326 | | const struct netdev_tunnel_config * |
327 | | (*get_tunnel_config)(const struct netdev *netdev); |
328 | | |
329 | | /* Build Tunnel header. Ethernet and ip header parameters are passed to |
330 | | * tunnel implementation to build entire outer header for given flow. */ |
331 | | int (*build_header)(const struct netdev *, struct ovs_action_push_tnl *data, |
332 | | const struct netdev_tnl_build_header_params *params); |
333 | | |
334 | | /* build_header() can not build entire header for all packets for given |
335 | | * flow. Push header is called for packet to build header specific to |
336 | | * a packet on actual transmit. It uses partial header build by |
337 | | * build_header() which is passed as data. */ |
338 | | void (*push_header)(const struct netdev *, |
339 | | struct dp_packet *packet, |
340 | | const struct ovs_action_push_tnl *data); |
341 | | |
342 | | /* Pop tunnel header from packet, build tunnel metadata and resize packet |
343 | | * for further processing. |
344 | | * Returns NULL in case of error or tunnel implementation queued packet for further |
345 | | * processing. */ |
346 | | struct dp_packet * (*pop_header)(struct dp_packet *packet); |
347 | | |
348 | | /* Returns the id of the numa node the 'netdev' is on. If there is no |
349 | | * such info, returns NETDEV_NUMA_UNSPEC. */ |
350 | | int (*get_numa_id)(const struct netdev *netdev); |
351 | | |
352 | | /* Configures the number of tx queues of 'netdev'. Returns 0 if successful, |
353 | | * otherwise a positive errno value. |
354 | | * |
355 | | * 'n_txq' specifies the exact number of transmission queues to create. |
356 | | * |
357 | | * The caller will call netdev_reconfigure() (if necessary) before using |
358 | | * netdev_send() on any of the newly configured queues, giving the provider |
359 | | * a chance to adjust its settings. |
360 | | * |
361 | | * On error, the tx queue configuration is unchanged. */ |
362 | | int (*set_tx_multiq)(struct netdev *netdev, unsigned int n_txq); |
363 | | |
364 | | /* Sends buffers on 'netdev'. |
365 | | * Returns 0 if successful (for every buffer), otherwise a positive errno |
366 | | * value. Returns EAGAIN without blocking if one or more packets cannot be |
367 | | * queued immediately. Returns EMSGSIZE if a partial packet was transmitted |
368 | | * or if a packet is too big or too small to transmit on the device. |
369 | | * |
370 | | * If the function returns a non-zero value, some of the packets might have |
371 | | * been sent anyway. |
372 | | * |
373 | | * The caller transfers ownership of all the packets to the network |
374 | | * device, regardless of success. |
375 | | * |
376 | | * If 'concurrent_txq' is true, the caller may perform concurrent calls |
377 | | * to netdev_send() with the same 'qid'. The netdev provider is responsible |
378 | | * for making sure that these concurrent calls do not create a race |
379 | | * condition by using locking or other synchronization if required. |
380 | | * |
381 | | * The network device is expected to maintain one or more packet |
382 | | * transmission queues, so that the caller does not ordinarily have to |
383 | | * do additional queuing of packets. 'qid' specifies the queue to use |
384 | | * and can be ignored if the implementation does not support multiple |
385 | | * queues. |
386 | | * |
387 | | * May return EOPNOTSUPP if a network device does not implement packet |
388 | | * transmission through this interface. This function may be set to null |
389 | | * if it would always return EOPNOTSUPP anyhow. (This will prevent the |
390 | | * network device from being usefully used by the netdev-based "userspace |
391 | | * datapath". It will also prevent the OVS implementation of bonding from |
392 | | * working properly over 'netdev'.) */ |
393 | | int (*send)(struct netdev *netdev, int qid, struct dp_packet_batch *batch, |
394 | | bool concurrent_txq); |
395 | | |
396 | | /* Registers with the poll loop to wake up from the next call to |
397 | | * poll_block() when the packet transmission queue for 'netdev' has |
398 | | * sufficient room to transmit a packet with netdev_send(). |
399 | | * |
400 | | * The network device is expected to maintain one or more packet |
401 | | * transmission queues, so that the caller does not ordinarily have to |
402 | | * do additional queuing of packets. 'qid' specifies the queue to use |
403 | | * and can be ignored if the implementation does not support multiple |
404 | | * queues. |
405 | | * |
406 | | * May be null if not needed, such as for a network device that does not |
407 | | * implement packet transmission through the 'send' member function. */ |
408 | | void (*send_wait)(struct netdev *netdev, int qid); |
409 | | |
410 | | /* Sets 'netdev''s Ethernet address to 'mac' */ |
411 | | int (*set_etheraddr)(struct netdev *netdev, const struct eth_addr mac); |
412 | | |
413 | | /* Retrieves 'netdev''s Ethernet address into 'mac'. |
414 | | * |
415 | | * This address will be advertised as 'netdev''s MAC address through the |
416 | | * OpenFlow protocol, among other uses. */ |
417 | | int (*get_etheraddr)(const struct netdev *netdev, struct eth_addr *mac); |
418 | | |
419 | | /* Retrieves 'netdev''s MTU into '*mtup'. |
420 | | * |
421 | | * The MTU is the maximum size of transmitted (and received) packets, in |
422 | | * bytes, not including the hardware header; thus, this is typically 1500 |
423 | | * bytes for Ethernet devices. |
424 | | * |
425 | | * If 'netdev' does not have an MTU (e.g. as some tunnels do not), then |
426 | | * this function should return EOPNOTSUPP. This function may be set to |
427 | | * null if it would always return EOPNOTSUPP. */ |
428 | | int (*get_mtu)(const struct netdev *netdev, int *mtup); |
429 | | |
430 | | /* Sets 'netdev''s MTU to 'mtu'. |
431 | | * |
432 | | * If 'netdev' does not have an MTU (e.g. as some tunnels do not), then |
433 | | * this function should return EOPNOTSUPP. This function may be set to |
434 | | * null if it would always return EOPNOTSUPP. */ |
435 | | int (*set_mtu)(struct netdev *netdev, int mtu); |
436 | | |
437 | | /* Returns the ifindex of 'netdev', if successful, as a positive number. |
438 | | * On failure, returns a negative errno value. |
439 | | * |
440 | | * The desired semantics of the ifindex value are a combination of those |
441 | | * specified by POSIX for if_nametoindex() and by SNMP for ifIndex. An |
442 | | * ifindex value should be unique within a host and remain stable at least |
443 | | * until reboot. SNMP says an ifindex "ranges between 1 and the value of |
444 | | * ifNumber" but many systems do not follow this rule anyhow. |
445 | | * |
446 | | * This function may be set to null if it would always return -EOPNOTSUPP. |
447 | | */ |
448 | | int (*get_ifindex)(const struct netdev *netdev); |
449 | | |
450 | | /* Sets 'carrier' to true if carrier is active (link light is on) on |
451 | | * 'netdev'. |
452 | | * |
453 | | * May be null if device does not provide carrier status (will be always |
454 | | * up as long as device is up). |
455 | | */ |
456 | | int (*get_carrier)(const struct netdev *netdev, bool *carrier); |
457 | | |
458 | | /* Returns the number of times 'netdev''s carrier has changed since being |
459 | | * initialized. |
460 | | * |
461 | | * If null, callers will assume the number of carrier resets is zero. */ |
462 | | long long int (*get_carrier_resets)(const struct netdev *netdev); |
463 | | |
464 | | /* Forces ->get_carrier() to poll 'netdev''s MII registers for link status |
465 | | * instead of checking 'netdev''s carrier. 'netdev''s MII registers will |
466 | | * be polled once every 'interval' milliseconds. If 'netdev' does not |
467 | | * support MII, another method may be used as a fallback. If 'interval' is |
468 | | * less than or equal to zero, reverts ->get_carrier() to its normal |
469 | | * behavior. |
470 | | * |
471 | | * Most network devices won't support this feature and will set this |
472 | | * function pointer to NULL, which is equivalent to returning EOPNOTSUPP. |
473 | | */ |
474 | | int (*set_miimon_interval)(struct netdev *netdev, long long int interval); |
475 | | |
476 | | /* Retrieves current device stats for 'netdev' into 'stats'. |
477 | | * |
478 | | * A network device that supports some statistics but not others, it should |
479 | | * set the values of the unsupported statistics to all-1-bits |
480 | | * (UINT64_MAX). */ |
481 | | int (*get_stats)(const struct netdev *netdev, struct netdev_stats *); |
482 | | |
483 | | /* Retrieves current device custom stats for 'netdev' into 'custom_stats'. |
484 | | * |
485 | | * A network device should return only available statistics (if any). |
486 | | * If there are not statistics available, empty array should be |
487 | | * returned. |
488 | | * |
489 | | * The caller initializes 'custom_stats' before calling this function. |
490 | | * The caller takes ownership over allocated array of counters inside |
491 | | * structure netdev_custom_stats. |
492 | | * */ |
493 | | int (*get_custom_stats)(const struct netdev *netdev, |
494 | | struct netdev_custom_stats *custom_stats); |
495 | | |
496 | | /* Stores the features supported by 'netdev' into each of '*current', |
497 | | * '*advertised', '*supported', and '*peer'. Each value is a bitmap of |
498 | | * NETDEV_F_* bits. |
499 | | * |
500 | | * This function may be set to null if it would always return EOPNOTSUPP. |
501 | | */ |
502 | | int (*get_features)(const struct netdev *netdev, |
503 | | enum netdev_features *current, |
504 | | enum netdev_features *advertised, |
505 | | enum netdev_features *supported, |
506 | | enum netdev_features *peer); |
507 | | |
508 | | /* Stores the current and maximum supported link speed by 'netdev' into |
509 | | * each of '*current' and '*max'. Each value represents the speed in Mbps. |
510 | | * If any of the speeds is unknown, a zero value must be stored. |
511 | | * |
512 | | * This function may be set to null if it would always return EOPNOTSUPP. |
513 | | */ |
514 | | int (*get_speed)(const struct netdev *netdev, uint32_t *current, |
515 | | uint32_t *max); |
516 | | |
517 | | /* Set the features advertised by 'netdev' to 'advertise', which is a |
518 | | * set of NETDEV_F_* bits. |
519 | | * |
520 | | * This function may be set to null for a network device that does not |
521 | | * support configuring advertisements. */ |
522 | | int (*set_advertisements)(struct netdev *netdev, |
523 | | enum netdev_features advertise); |
524 | | |
525 | | /* Returns 'netdev''s configured packet_type mode. |
526 | | * |
527 | | * This function may be set to null if it would always return |
528 | | * NETDEV_PT_LEGACY_L2. */ |
529 | | enum netdev_pt_mode (*get_pt_mode)(const struct netdev *netdev); |
530 | | |
531 | | /* Attempts to set input rate limiting (policing) policy, such that: |
532 | | * - up to 'kbits_rate' kbps of traffic is accepted, with a maximum |
533 | | * accumulative burst size of 'kbits' kb; and |
534 | | * - up to 'kpkts' kpps of traffic is accepted, with a maximum |
535 | | * accumulative burst size of 'kpkts' kilo packets. |
536 | | * |
537 | | * This function may be set to null if policing is not supported. */ |
538 | | int (*set_policing)(struct netdev *netdev, unsigned int kbits_rate, |
539 | | unsigned int kbits_burst, unsigned int kpkts_rate, |
540 | | unsigned int kpkts_burst); |
541 | | |
542 | | /* Adds to 'types' all of the forms of QoS supported by 'netdev', or leaves |
543 | | * it empty if 'netdev' does not support QoS. Any names added to 'types' |
544 | | * should be documented as valid for the "type" column in the "QoS" table |
545 | | * in vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)). |
546 | | * |
547 | | * Every network device must support disabling QoS with a type of "", but |
548 | | * this function must not add "" to 'types'. |
549 | | * |
550 | | * The caller is responsible for initializing 'types' (e.g. with |
551 | | * sset_init()) before calling this function. The caller retains ownership |
552 | | * of 'types'. |
553 | | * |
554 | | * May be NULL if 'netdev' does not support QoS at all. */ |
555 | | int (*get_qos_types)(const struct netdev *netdev, struct sset *types); |
556 | | |
557 | | /* Queries 'netdev' for its capabilities regarding the specified 'type' of |
558 | | * QoS. On success, initializes 'caps' with the QoS capabilities. |
559 | | * |
560 | | * Should return EOPNOTSUPP if 'netdev' does not support 'type'. May be |
561 | | * NULL if 'netdev' does not support QoS at all. */ |
562 | | int (*get_qos_capabilities)(const struct netdev *netdev, |
563 | | const char *type, |
564 | | struct netdev_qos_capabilities *caps); |
565 | | |
566 | | /* Queries 'netdev' about its currently configured form of QoS. If |
567 | | * successful, stores the name of the current form of QoS into '*typep' |
568 | | * and any details of configuration as string key-value pairs in |
569 | | * 'details'. |
570 | | * |
571 | | * A '*typep' of "" indicates that QoS is currently disabled on 'netdev'. |
572 | | * |
573 | | * The caller initializes 'details' before calling this function. The |
574 | | * caller takes ownership of the string key-values pairs added to |
575 | | * 'details'. |
576 | | * |
577 | | * The netdev retains ownership of '*typep'. |
578 | | * |
579 | | * '*typep' will be one of the types returned by netdev_get_qos_types() for |
580 | | * 'netdev'. The contents of 'details' should be documented as valid for |
581 | | * '*typep' in the "other_config" column in the "QoS" table in |
582 | | * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)). |
583 | | * |
584 | | * May be NULL if 'netdev' does not support QoS at all. */ |
585 | | int (*get_qos)(const struct netdev *netdev, |
586 | | const char **typep, struct smap *details); |
587 | | |
588 | | /* Attempts to reconfigure QoS on 'netdev', changing the form of QoS to |
589 | | * 'type' with details of configuration from 'details'. |
590 | | * |
591 | | * On error, the previous QoS configuration is retained. |
592 | | * |
593 | | * When this function changes the type of QoS (not just 'details'), this |
594 | | * also resets all queue configuration for 'netdev' to their defaults |
595 | | * (which depend on the specific type of QoS). Otherwise, the queue |
596 | | * configuration for 'netdev' is unchanged. |
597 | | * |
598 | | * 'type' should be "" (to disable QoS) or one of the types returned by |
599 | | * netdev_get_qos_types() for 'netdev'. The contents of 'details' should |
600 | | * be documented as valid for the given 'type' in the "other_config" column |
601 | | * in the "QoS" table in vswitchd/vswitch.xml (which is built as |
602 | | * ovs-vswitchd.conf.db(8)). |
603 | | * |
604 | | * May be NULL if 'netdev' does not support QoS at all. */ |
605 | | int (*set_qos)(struct netdev *netdev, |
606 | | const char *type, const struct smap *details); |
607 | | |
608 | | /* Queries 'netdev' for information about the queue numbered 'queue_id'. |
609 | | * If successful, adds that information as string key-value pairs to |
610 | | * 'details'. Returns 0 if successful, otherwise a positive errno value. |
611 | | * |
612 | | * Should return EINVAL if 'queue_id' is greater than or equal to the |
613 | | * number of supported queues (as reported in the 'n_queues' member of |
614 | | * struct netdev_qos_capabilities by 'get_qos_capabilities'). |
615 | | * |
616 | | * The caller initializes 'details' before calling this function. The |
617 | | * caller takes ownership of the string key-values pairs added to |
618 | | * 'details'. |
619 | | * |
620 | | * The returned contents of 'details' should be documented as valid for the |
621 | | * given 'type' in the "other_config" column in the "Queue" table in |
622 | | * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)). |
623 | | */ |
624 | | int (*get_queue)(const struct netdev *netdev, |
625 | | unsigned int queue_id, struct smap *details); |
626 | | |
627 | | /* Configures the queue numbered 'queue_id' on 'netdev' with the key-value |
628 | | * string pairs in 'details'. The contents of 'details' should be |
629 | | * documented as valid for the given 'type' in the "other_config" column in |
630 | | * the "Queue" table in vswitchd/vswitch.xml (which is built as |
631 | | * ovs-vswitchd.conf.db(8)). Returns 0 if successful, otherwise a positive |
632 | | * errno value. On failure, the given queue's configuration should be |
633 | | * unmodified. |
634 | | * |
635 | | * Should return EINVAL if 'queue_id' is greater than or equal to the |
636 | | * number of supported queues (as reported in the 'n_queues' member of |
637 | | * struct netdev_qos_capabilities by 'get_qos_capabilities'), or if |
638 | | * 'details' is invalid for the type of queue. |
639 | | * |
640 | | * This function does not modify 'details', and the caller retains |
641 | | * ownership of it. |
642 | | * |
643 | | * May be NULL if 'netdev' does not support QoS at all. */ |
644 | | int (*set_queue)(struct netdev *netdev, |
645 | | unsigned int queue_id, const struct smap *details); |
646 | | |
647 | | /* Attempts to delete the queue numbered 'queue_id' from 'netdev'. |
648 | | * |
649 | | * Should return EINVAL if 'queue_id' is greater than or equal to the |
650 | | * number of supported queues (as reported in the 'n_queues' member of |
651 | | * struct netdev_qos_capabilities by 'get_qos_capabilities'). Should |
652 | | * return EOPNOTSUPP if 'queue_id' is valid but may not be deleted (e.g. if |
653 | | * 'netdev' has a fixed set of queues with the current QoS mode). |
654 | | * |
655 | | * May be NULL if 'netdev' does not support QoS at all, or if all of its |
656 | | * QoS modes have fixed sets of queues. */ |
657 | | int (*delete_queue)(struct netdev *netdev, unsigned int queue_id); |
658 | | |
659 | | /* Obtains statistics about 'queue_id' on 'netdev'. Fills 'stats' with the |
660 | | * queue's statistics. May set individual members of 'stats' to all-1-bits |
661 | | * if the statistic is unavailable. |
662 | | * |
663 | | * May be NULL if 'netdev' does not support QoS at all. */ |
664 | | int (*get_queue_stats)(const struct netdev *netdev, unsigned int queue_id, |
665 | | struct netdev_queue_stats *stats); |
666 | | |
667 | | /* Attempts to begin dumping the queues in 'netdev'. On success, returns 0 |
668 | | * and initializes '*statep' with any data needed for iteration. On |
669 | | * failure, returns a positive errno value. |
670 | | * |
671 | | * May be NULL if 'netdev' does not support QoS at all. */ |
672 | | int (*queue_dump_start)(const struct netdev *netdev, void **statep); |
673 | | |
674 | | /* Attempts to retrieve another queue from 'netdev' for 'state', which was |
675 | | * initialized by a successful call to the 'queue_dump_start' function for |
676 | | * 'netdev'. On success, stores a queue ID into '*queue_id' and fills |
677 | | * 'details' with the configuration of the queue with that ID. Returns EOF |
678 | | * if the last queue has been dumped, or a positive errno value on error. |
679 | | * This function will not be called again once it returns nonzero once for |
680 | | * a given iteration (but the 'queue_dump_done' function will be called |
681 | | * afterward). |
682 | | * |
683 | | * The caller initializes and clears 'details' before calling this |
684 | | * function. The caller takes ownership of the string key-values pairs |
685 | | * added to 'details'. |
686 | | * |
687 | | * The returned contents of 'details' should be documented as valid for the |
688 | | * given 'type' in the "other_config" column in the "Queue" table in |
689 | | * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)). |
690 | | * |
691 | | * May be NULL if 'netdev' does not support QoS at all. */ |
692 | | int (*queue_dump_next)(const struct netdev *netdev, void *state, |
693 | | unsigned int *queue_id, struct smap *details); |
694 | | |
695 | | /* Releases resources from 'netdev' for 'state', which was initialized by a |
696 | | * successful call to the 'queue_dump_start' function for 'netdev'. |
697 | | * |
698 | | * May be NULL if 'netdev' does not support QoS at all. */ |
699 | | int (*queue_dump_done)(const struct netdev *netdev, void *state); |
700 | | |
701 | | /* Iterates over all of 'netdev''s queues, calling 'cb' with the queue's |
702 | | * ID, its statistics, and the 'aux' specified by the caller. The order of |
703 | | * iteration is unspecified, but (when successful) each queue must be |
704 | | * visited exactly once. |
705 | | * |
706 | | * 'cb' will not modify or free the statistics passed in. */ |
707 | | int (*dump_queue_stats)(const struct netdev *netdev, |
708 | | void (*cb)(unsigned int queue_id, |
709 | | struct netdev_queue_stats *, |
710 | | void *aux), |
711 | | void *aux); |
712 | | |
713 | | /* Assigns 'addr' as 'netdev''s IPv4 address and 'mask' as its netmask. If |
714 | | * 'addr' is INADDR_ANY, 'netdev''s IPv4 address is cleared. |
715 | | * |
716 | | * This function may be set to null if it would always return EOPNOTSUPP |
717 | | * anyhow. */ |
718 | | int (*set_in4)(struct netdev *netdev, struct in_addr addr, |
719 | | struct in_addr mask); |
720 | | |
721 | | /* Returns all assigned IP address to 'netdev' and returns 0. |
722 | | * API allocates array of address and masks and set it to |
723 | | * '*addr' and '*mask'. |
724 | | * Otherwise, returns a positive errno value and sets '*addr', '*mask |
725 | | * and '*n_addr' to NULL. |
726 | | * |
727 | | * The following error values have well-defined meanings: |
728 | | * |
729 | | * - EADDRNOTAVAIL: 'netdev' has no assigned IPv6 address. |
730 | | * |
731 | | * - EOPNOTSUPP: No IPv6 network stack attached to 'netdev'. |
732 | | * |
733 | | * 'addr' may be null, in which case the address itself is not reported. */ |
734 | | int (*get_addr_list)(const struct netdev *netdev, struct in6_addr **in, |
735 | | struct in6_addr **mask, int *n_in6); |
736 | | |
737 | | /* Adds 'router' as a default IP gateway for the TCP/IP stack that |
738 | | * corresponds to 'netdev'. |
739 | | * |
740 | | * This function may be set to null if it would always return EOPNOTSUPP |
741 | | * anyhow. */ |
742 | | int (*add_router)(struct netdev *netdev, struct in_addr router); |
743 | | |
744 | | /* Looks up the next hop for 'host' in the host's routing table. If |
745 | | * successful, stores the next hop gateway's address (0 if 'host' is on a |
746 | | * directly connected network) in '*next_hop' and a copy of the name of the |
747 | | * device to reach 'host' in '*netdev_name', and returns 0. The caller is |
748 | | * responsible for freeing '*netdev_name' (by calling free()). |
749 | | * |
750 | | * This function may be set to null if it would always return EOPNOTSUPP |
751 | | * anyhow. */ |
752 | | int (*get_next_hop)(const struct in_addr *host, struct in_addr *next_hop, |
753 | | char **netdev_name); |
754 | | |
755 | | /* Retrieves driver information of the device. |
756 | | * |
757 | | * Populates 'smap' with key-value pairs representing the status of the |
758 | | * device. 'smap' is a set of key-value string pairs representing netdev |
759 | | * type specific information. For more information see |
760 | | * ovs-vswitchd.conf.db(5). |
761 | | * |
762 | | * The caller is responsible for destroying 'smap' and its data. |
763 | | * |
764 | | * This function may be set to null if it would always return EOPNOTSUPP |
765 | | * anyhow. */ |
766 | | int (*get_status)(const struct netdev *netdev, struct smap *smap); |
767 | | |
768 | | /* Looks up the ARP table entry for 'ip' on 'netdev' and stores the |
769 | | * corresponding MAC address in 'mac'. A return value of ENXIO, in |
770 | | * particular, indicates that there is no ARP table entry for 'ip' on |
771 | | * 'netdev'. |
772 | | * |
773 | | * This function may be set to null if it would always return EOPNOTSUPP |
774 | | * anyhow. */ |
775 | | int (*arp_lookup)(const struct netdev *netdev, ovs_be32 ip, |
776 | | struct eth_addr *mac); |
777 | | |
778 | | /* Retrieves the current set of flags on 'netdev' into '*old_flags'. Then, |
779 | | * turns off the flags that are set to 1 in 'off' and turns on the flags |
780 | | * that are set to 1 in 'on'. (No bit will be set to 1 in both 'off' and |
781 | | * 'on'; that is, off & on == 0.) |
782 | | * |
783 | | * This function may be invoked from a signal handler. Therefore, it |
784 | | * should not do anything that is not signal-safe (such as logging). */ |
785 | | int (*update_flags)(struct netdev *netdev, enum netdev_flags off, |
786 | | enum netdev_flags on, enum netdev_flags *old_flags); |
787 | | |
788 | | /* If the provider called netdev_request_reconfigure(), the upper layer |
789 | | * will eventually call this. The provider can update the device |
790 | | * configuration knowing that the upper layer will not call rxq_recv() or |
791 | | * send() until this function returns. |
792 | | * |
793 | | * On error, the configuration is indeterminant and the device cannot be |
794 | | * used to send and receive packets until a successful configuration is |
795 | | * applied. */ |
796 | | int (*reconfigure)(struct netdev *netdev); |
797 | | /* ## -------------------- ## */ |
798 | | /* ## netdev_rxq Functions ## */ |
799 | | /* ## -------------------- ## */ |
800 | | |
801 | | /* If a particular netdev class does not support receiving packets, all these |
802 | | * function pointers must be NULL. */ |
803 | | |
804 | | /* Life-cycle functions for a netdev_rxq. See the large comment above on |
805 | | * struct netdev_class. */ |
806 | | struct netdev_rxq *(*rxq_alloc)(void); |
807 | | int (*rxq_construct)(struct netdev_rxq *); |
808 | | void (*rxq_destruct)(struct netdev_rxq *); |
809 | | void (*rxq_dealloc)(struct netdev_rxq *); |
810 | | |
811 | | /* Retrieves the current state of rx queue. 'false' means that queue won't |
812 | | * get traffic in a short term and could be not polled. |
813 | | * |
814 | | * This function may be set to null if it would always return 'true' |
815 | | * anyhow. */ |
816 | | bool (*rxq_enabled)(struct netdev_rxq *); |
817 | | |
818 | | /* Attempts to receive a batch of packets from 'rx'. In 'batch', the |
819 | | * caller supplies 'packets' as the pointer to the beginning of an array |
820 | | * of NETDEV_MAX_BURST pointers to dp_packet. If successful, the |
821 | | * implementation stores pointers to up to NETDEV_MAX_BURST dp_packets into |
822 | | * the array, transferring ownership of the packets to the caller, stores |
823 | | * the number of received packets into 'count', and returns 0. |
824 | | * |
825 | | * The implementation does not necessarily initialize any non-data members |
826 | | * of 'packets' in 'batch'. That is, the caller must initialize layer |
827 | | * pointers and metadata itself, if desired, e.g. with pkt_metadata_init() |
828 | | * and miniflow_extract(). |
829 | | * |
830 | | * Implementations should allocate buffers with DP_NETDEV_HEADROOM bytes of |
831 | | * headroom. |
832 | | * |
833 | | * If the caller provides a non-NULL qfill pointer, the implementation |
834 | | * should return the number (zero or more) of remaining packets in the |
835 | | * queue after the reception the current batch, if it supports that, |
836 | | * or -ENOTSUP otherwise. |
837 | | * |
838 | | * Returns EAGAIN immediately if no packet is ready to be received or |
839 | | * another positive errno value if an error was encountered. */ |
840 | | int (*rxq_recv)(struct netdev_rxq *rx, struct dp_packet_batch *batch, |
841 | | int *qfill); |
842 | | |
843 | | /* Registers with the poll loop to wake up from the next call to |
844 | | * poll_block() when a packet is ready to be received with |
845 | | * netdev_rxq_recv() on 'rx'. */ |
846 | | void (*rxq_wait)(struct netdev_rxq *rx); |
847 | | |
848 | | /* Discards all packets waiting to be received from 'rx'. */ |
849 | | int (*rxq_drain)(struct netdev_rxq *rx); |
850 | | |
851 | | /* Get a block_id from the netdev. |
852 | | * Returns the block_id or 0 if none exists for netdev. */ |
853 | | uint32_t (*get_block_id)(struct netdev *); |
854 | | }; |
855 | | |
856 | | int netdev_register_provider(const struct netdev_class *); |
857 | | int netdev_unregister_provider(const char *type); |
858 | | |
859 | | #if defined(__FreeBSD__) || defined(__NetBSD__) |
860 | | extern const struct netdev_class netdev_bsd_class; |
861 | | #elif defined(_WIN32) |
862 | | extern const struct netdev_class netdev_windows_class; |
863 | | #else |
864 | | extern const struct netdev_class netdev_linux_class; |
865 | | #endif |
866 | | extern const struct netdev_class netdev_internal_class; |
867 | | extern const struct netdev_class netdev_tap_class; |
868 | | |
869 | | #ifdef HAVE_AF_XDP |
870 | | extern const struct netdev_class netdev_afxdp_class; |
871 | | extern const struct netdev_class netdev_afxdp_nonpmd_class; |
872 | | #endif |
873 | | #ifdef __cplusplus |
874 | | } |
875 | | #endif |
876 | | |
877 | | #endif /* netdev.h */ |