blob: e3421b91978e30c7c385fa3882ae9bf6858dc351 [file] [log] [blame]
Damjan Marion38c61912023-10-17 16:06:26 +00001/* SPDX-License-Identifier: Apache-2.0
2 * Copyright (c) 2023 Cisco Systems, Inc.
3 */
4
5#ifndef _VNET_DEV_H_
6#define _VNET_DEV_H_
7
8#include <vppinfra/clib.h>
9#include <vppinfra/error_bootstrap.h>
10#include <vppinfra/format.h>
11#include <vnet/vnet.h>
12#include <vnet/dev/types.h>
13
14#define VNET_DEV_DEVICE_ID_PREFIX_DELIMITER "/"
15
16#define foreach_vnet_dev_port_type \
17 _ (0, UNKNOWN) \
18 _ (1, ETHERNET)
19
20typedef char vnet_dev_device_id_t[32];
21
22typedef enum
23{
24#define _(b, n) VNET_DEV_PORT_TYPE_##n = (1U << (b)),
25 foreach_vnet_dev_port_type
26#undef _
27} vnet_dev_port_type_t;
28
29#define foreach_vnet_dev_port_caps \
30 _ (interrupt_mode) \
Damjan Marione596ca12023-11-08 19:12:27 +000031 _ (rss) \
32 _ (change_max_rx_frame_size)
Damjan Marion38c61912023-10-17 16:06:26 +000033
34typedef union
35{
36 struct
37 {
38#define _(n) u8 n : 1;
39 foreach_vnet_dev_port_caps
40#undef _
41 };
42 u8 as_number;
43} vnet_dev_port_caps_t;
44
45typedef union
46{
47 u8 eth_mac[6];
48 u8 raw[8];
49} vnet_dev_hw_addr_t;
50
51typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t;
52typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t;
53
54typedef struct vnet_dev vnet_dev_t;
55typedef struct vnet_dev_port vnet_dev_port_t;
56typedef struct vnet_dev_rx_queue vnet_dev_rx_queue_t;
57typedef struct vnet_dev_tx_queue vnet_dev_tx_queue_t;
58typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t;
59typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t;
60typedef struct vnet_dev_counter vnet_dev_counter_t;
61typedef struct vnet_dev_counter_main vnet_dev_counter_main_t;
62typedef struct vnet_dev_port_cfg_change_req vnet_dev_port_cfg_change_req_t;
63
64typedef vnet_dev_rv_t (vnet_dev_op_t) (vlib_main_t *, vnet_dev_t *);
65typedef vnet_dev_rv_t (vnet_dev_port_op_t) (vlib_main_t *, vnet_dev_port_t *);
66typedef vnet_dev_rv_t (vnet_dev_port_cfg_change_op_t) (
67 vlib_main_t *, vnet_dev_port_t *, vnet_dev_port_cfg_change_req_t *);
68typedef vnet_dev_rv_t (vnet_dev_rx_queue_op_t) (vlib_main_t *,
69 vnet_dev_rx_queue_t *);
70typedef vnet_dev_rv_t (vnet_dev_tx_queue_op_t) (vlib_main_t *,
71 vnet_dev_tx_queue_t *);
72typedef void (vnet_dev_op_no_rv_t) (vlib_main_t *, vnet_dev_t *);
73typedef void (vnet_dev_port_op_no_rv_t) (vlib_main_t *, vnet_dev_port_t *);
74typedef void (vnet_dev_rx_queue_op_no_rv_t) (vlib_main_t *,
75 vnet_dev_rx_queue_t *);
76typedef void (vnet_dev_tx_queue_op_no_rv_t) (vlib_main_t *,
77 vnet_dev_tx_queue_t *);
78
79typedef u16 vnet_dev_queue_id_t;
80typedef u16 vnet_dev_bus_index_t;
81typedef u16 vnet_dev_driver_index_t;
82
83typedef struct
84{
85 vnet_dev_rx_queue_op_t *alloc;
86 vnet_dev_rx_queue_op_t *start;
87 vnet_dev_rx_queue_op_no_rv_t *stop;
88 vnet_dev_rx_queue_op_no_rv_t *free;
89} vnet_dev_rx_queue_ops_t;
90
91typedef struct
92{
93 vnet_dev_tx_queue_op_t *alloc;
94 vnet_dev_tx_queue_op_t *start;
95 vnet_dev_tx_queue_op_no_rv_t *stop;
96 vnet_dev_tx_queue_op_no_rv_t *free;
97} vnet_dev_tx_queue_ops_t;
98
99typedef struct
100{
101 u16 data_size;
102 u16 min_size;
103 u16 max_size;
104 u16 default_size;
105 u8 multiplier;
106 u8 size_is_power_of_two : 1;
107} vnet_dev_queue_config_t;
108
109#define foreach_vnet_dev_port_cfg_type \
110 _ (PROMISC_MODE) \
Damjan Marione596ca12023-11-08 19:12:27 +0000111 _ (MAX_RX_FRAME_SIZE) \
Damjan Marion38c61912023-10-17 16:06:26 +0000112 _ (CHANGE_PRIMARY_HW_ADDR) \
113 _ (ADD_SECONDARY_HW_ADDR) \
Damjan Marionb8dd9812023-11-03 13:47:05 +0000114 _ (REMOVE_SECONDARY_HW_ADDR) \
115 _ (RXQ_INTR_MODE_ENABLE) \
116 _ (RXQ_INTR_MODE_DISABLE)
Damjan Marion38c61912023-10-17 16:06:26 +0000117
118typedef enum
119{
120 VNET_DEV_PORT_CFG_UNKNOWN,
121#define _(n) VNET_DEV_PORT_CFG_##n,
122 foreach_vnet_dev_port_cfg_type
123#undef _
124} __clib_packed vnet_dev_port_cfg_type_t;
125
126typedef struct vnet_dev_port_cfg_change_req
127{
128 vnet_dev_port_cfg_type_t type;
129 u8 validated : 1;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000130 u8 all_queues : 1;
Damjan Marion38c61912023-10-17 16:06:26 +0000131
132 union
133 {
134 u8 promisc : 1;
135 vnet_dev_hw_addr_t addr;
Damjan Marione596ca12023-11-08 19:12:27 +0000136 u16 max_rx_frame_size;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000137 vnet_dev_queue_id_t queue_id;
Damjan Marion38c61912023-10-17 16:06:26 +0000138 };
139
140} vnet_dev_port_cfg_change_req_t;
141
142typedef struct
143{
144 vnet_dev_hw_addr_t hw_addr;
145 u16 max_rx_queues;
146 u16 max_tx_queues;
Damjan Marione596ca12023-11-08 19:12:27 +0000147 u16 max_supported_rx_frame_size;
Damjan Marion38c61912023-10-17 16:06:26 +0000148 vnet_dev_port_type_t type;
149 vnet_dev_port_caps_t caps;
150} vnet_dev_port_attr_t;
151
152typedef enum
153{
154 VNET_DEV_PERIODIC_OP_TYPE_DEV = 1,
155 VNET_DEV_PERIODIC_OP_TYPE_PORT = 2,
156} __clib_packed vnet_dev_periodic_op_type_t;
157
158typedef struct
159{
160 f64 interval;
161 f64 last_run;
162 vnet_dev_periodic_op_type_t type;
163 union
164 {
165 vnet_dev_t *dev;
166 vnet_dev_port_t *port;
167 void *arg;
168 };
169 union
170 {
171 vnet_dev_op_no_rv_t *dev_op;
172 vnet_dev_port_op_no_rv_t *port_op;
173 void *op;
174 };
175} vnet_dev_periodic_op_t;
176
177typedef struct
178{
179 struct _vlib_node_fn_registration *registrations;
180 format_function_t *format_trace;
181 vlib_error_desc_t *error_counters;
182 u16 n_error_counters;
183} vnet_dev_node_t;
184
185typedef struct
186{
187 vnet_dev_op_t *alloc;
188 vnet_dev_op_t *init;
189 vnet_dev_op_no_rv_t *deinit;
190 vnet_dev_op_t *reset;
191 vnet_dev_op_no_rv_t *free;
192 u8 *(*probe) (vlib_main_t *, vnet_dev_bus_index_t, void *);
193 format_function_t *format_info;
194} vnet_dev_ops_t;
195
196typedef struct
197{
198 vnet_dev_port_op_t *alloc;
199 vnet_dev_port_op_t *init;
200 vnet_dev_port_cfg_change_op_t *config_change;
201 vnet_dev_port_cfg_change_op_t *config_change_validate;
202 vnet_dev_port_op_t *start;
203 vnet_dev_port_op_no_rv_t *stop;
204 vnet_dev_port_op_no_rv_t *deinit;
205 vnet_dev_port_op_no_rv_t *free;
206 format_function_t *format_status;
207} vnet_dev_port_ops_t;
208
209typedef union
210{
211 struct
212 {
213 u8 update_next_index : 1;
214 u8 update_feature_arc : 1;
215 u8 suspend_off : 1;
216 u8 suspend_on : 1;
217 };
218 u8 as_number;
219} vnet_dev_rx_queue_rt_req_t;
220
221typedef struct vnet_dev_rx_queue
222{
223 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
224 vnet_dev_port_t *port;
225 u16 rx_thread_index;
226 u16 index;
227 vnet_dev_counter_main_t *counter_main;
228 CLIB_CACHE_LINE_ALIGN_MARK (runtime0);
Damjan Marionb8dd9812023-11-03 13:47:05 +0000229 vnet_dev_rx_queue_t *next_on_thread;
230 u8 interrupt_mode : 1;
Damjan Marion38c61912023-10-17 16:06:26 +0000231 u8 enabled : 1;
232 u8 started : 1;
233 u8 suspended : 1;
234 vnet_dev_queue_id_t queue_id;
235 u16 size;
236 u16 next_index;
237 vnet_dev_rx_queue_rt_req_t runtime_request;
238 CLIB_CACHE_LINE_ALIGN_MARK (runtime1);
239 vlib_buffer_template_t buffer_template;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000240 CLIB_CACHE_LINE_ALIGN_MARK (driver_data);
Damjan Marion38c61912023-10-17 16:06:26 +0000241 u8 data[];
242} vnet_dev_rx_queue_t;
243
244STATIC_ASSERT_SIZEOF (vnet_dev_rx_queue_t, 3 * CLIB_CACHE_LINE_BYTES);
245
246typedef struct vnet_dev_tx_queue
247{
248 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
249 vnet_dev_port_t *port;
250 clib_bitmap_t *assigned_threads;
251 u16 index;
252 vnet_dev_counter_main_t *counter_main;
253 CLIB_CACHE_LINE_ALIGN_MARK (runtime0);
254 vnet_dev_queue_id_t queue_id;
255 u8 started : 1;
256 u8 enabled : 1;
257 u8 lock_needed : 1;
258 u8 lock;
259 u16 size;
260 CLIB_ALIGN_MARK (private_data, 16);
261 u8 data[];
262} vnet_dev_tx_queue_t;
263
264STATIC_ASSERT_SIZEOF (vnet_dev_tx_queue_t, 2 * CLIB_CACHE_LINE_BYTES);
265
266typedef struct vnet_dev_port
267{
268 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
269 vnet_dev_t *dev;
270 vnet_dev_port_id_t port_id;
271 vnet_dev_driver_index_t driver_index;
272 u8 initialized : 1;
273 u8 started : 1;
274 u8 link_up : 1;
275 u8 promisc : 1;
276 u8 interface_created : 1;
277 u8 rx_node_assigned : 1;
278 vnet_dev_counter_main_t *counter_main;
279 vnet_dev_queue_config_t rx_queue_config;
280 vnet_dev_queue_config_t tx_queue_config;
281 vnet_dev_port_attr_t attr;
Damjan Marione596ca12023-11-08 19:12:27 +0000282 u32 max_rx_frame_size;
Damjan Marion38c61912023-10-17 16:06:26 +0000283 vnet_dev_hw_addr_t primary_hw_addr;
284 vnet_dev_hw_addr_t *secondary_hw_addr;
285 u32 index;
286 u32 speed;
287 vnet_dev_rx_queue_t **rx_queues;
288 vnet_dev_tx_queue_t **tx_queues;
289 vnet_dev_port_ops_t port_ops;
290 vnet_dev_rx_queue_ops_t rx_queue_ops;
291 vnet_dev_tx_queue_ops_t tx_queue_ops;
292 vnet_dev_node_t rx_node;
293 vnet_dev_node_t tx_node;
294
295 struct
296 {
297 vnet_dev_if_name_t name;
298 u32 dev_instance;
299 u32 rx_node_index;
300 u32 current_config_index;
301 u16 rx_next_index;
302 u16 redirect_to_node_next_index;
303 u8 feature_arc_index;
304 u8 feature_arc : 1;
305 u8 redirect_to_node : 1;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000306 u8 default_is_intr_mode : 1;
Damjan Marion38c61912023-10-17 16:06:26 +0000307 u32 tx_node_index;
308 u32 hw_if_index;
309 u32 sw_if_index;
310 u16 num_rx_queues;
311 u16 num_tx_queues;
312 u16 txq_sz;
313 u16 rxq_sz;
314 } intf;
315
316 CLIB_CACHE_LINE_ALIGN_MARK (data0);
317 u8 data[];
318} vnet_dev_port_t;
319
320typedef struct vnet_dev
321{
322 vnet_dev_device_id_t device_id;
323 u16 initialized : 1;
324 u16 not_first_init : 1;
325 u16 va_dma : 1;
326 u16 process_node_quit : 1;
327 u16 process_node_periodic : 1;
328 u16 poll_stats : 1;
329 u16 bus_index;
330 u8 numa_node;
331 u16 max_rx_queues;
332 u16 max_tx_queues;
333 vnet_dev_driver_index_t driver_index;
334 u32 index;
335 u32 process_node_index;
336 u8 bus_data[32] __clib_aligned (16);
337 vnet_dev_ops_t ops;
338 vnet_dev_port_t **ports;
339 vnet_dev_periodic_op_t *periodic_ops;
340 u8 *description;
341 u8 __clib_aligned (16)
342 data[];
343} vnet_dev_t;
344
345typedef struct
346{
347 u16 vendor_id, device_id;
348 char *description;
349} vnet_dev_match_t;
350
351#define VNET_DEV_MATCH(...) \
352 (vnet_dev_match_t[]) \
353 { \
354 __VA_ARGS__, {} \
355 }
356
357typedef struct
358{
359 vnet_dev_op_t *device_open;
360 vnet_dev_op_no_rv_t *device_close;
361 vnet_dev_rv_t (*dma_mem_alloc_fn) (vlib_main_t *, vnet_dev_t *, u32, u32,
362 void **);
363 void (*dma_mem_free_fn) (vlib_main_t *, vnet_dev_t *, void *);
364 void *(*get_device_info) (vlib_main_t *, char *);
365 void (*free_device_info) (vlib_main_t *, void *);
366 format_function_t *format_device_info;
367 format_function_t *format_device_addr;
368} vnet_dev_bus_ops_t;
369
370struct vnet_dev_bus_registration
371{
372 vnet_dev_bus_registration_t *next_registration;
373 vnet_dev_driver_name_t name;
374 u16 device_data_size;
375 vnet_dev_bus_ops_t ops;
376};
377
378struct vnet_dev_driver_registration
379{
380 vnet_dev_driver_registration_t *next_registration;
381 u8 bus_master_enable : 1;
382 vnet_dev_driver_name_t name;
383 vnet_dev_bus_name_t bus;
384 u16 device_data_sz;
385 u16 runtime_temp_space_sz;
386 vnet_dev_match_t *match;
387 int priority;
388 vnet_dev_ops_t ops;
389};
390
391typedef struct
392{
393 u32 index;
394 vnet_dev_bus_registration_t *registration;
395 vnet_dev_bus_ops_t ops;
396} vnet_dev_bus_t;
397
398typedef struct
399{
400 u32 index;
401 void *dev_data;
402 vnet_dev_driver_registration_t *registration;
403 u32 dev_class_index;
404 vnet_dev_bus_index_t bus_index;
405 vnet_dev_ops_t ops;
406} vnet_dev_driver_t;
407
408typedef struct
409{
410 vnet_dev_bus_t *buses;
411 vnet_dev_driver_t *drivers;
412 vnet_dev_t **devices;
413 vnet_dev_port_t **ports_by_dev_instance;
414 vnet_dev_bus_registration_t *bus_registrations;
415 vnet_dev_driver_registration_t *driver_registrations;
416 void *runtime_temp_spaces;
417 u32 log2_runtime_temp_space_sz;
418 u32 *free_process_node_indices;
419 u32 *free_rx_node_indices;
420 uword *device_index_by_id;
421
422 u8 *startup_config;
423 u16 next_rx_queue_thread;
424 u8 eth_port_rx_feature_arc_index;
425} vnet_dev_main_t;
426
427extern vnet_dev_main_t vnet_dev_main;
428
429typedef struct
430{
431 struct
432 {
433 vnet_dev_port_attr_t attr;
434 vnet_dev_port_ops_t ops;
435 u16 data_size;
436 void *initial_data;
437 } port;
438
439 vnet_dev_node_t *rx_node;
440 vnet_dev_node_t *tx_node;
441
442 struct
443 {
444 vnet_dev_queue_config_t config;
445 vnet_dev_rx_queue_ops_t ops;
446 } rx_queue;
447
448 struct
449 {
450 vnet_dev_queue_config_t config;
451 vnet_dev_tx_queue_ops_t ops;
452 } tx_queue;
453} vnet_dev_port_add_args_t;
454
455typedef struct
456{
457 union
458 {
459 struct
460 {
461 u8 link_speed : 1;
462 u8 link_state : 1;
463 u8 link_duplex : 1;
464 };
465 u8 any;
466 } change;
467 u8 link_state : 1;
468 u8 full_duplex : 1;
469 u32 link_speed;
470} vnet_dev_port_state_changes_t;
471
472/* dev.c */
473vnet_dev_t *vnet_dev_alloc (vlib_main_t *, vnet_dev_device_id_t,
474 vnet_dev_driver_t *);
475void vnet_dev_free (vlib_main_t *, vnet_dev_t *);
476vnet_dev_rv_t vnet_dev_init (vlib_main_t *, vnet_dev_t *);
477void vnet_dev_deinit (vlib_main_t *, vnet_dev_t *);
478vnet_dev_rv_t vnet_dev_reset (vlib_main_t *, vnet_dev_t *);
479void vnet_dev_detach (vlib_main_t *, vnet_dev_t *);
480vnet_dev_rv_t vnet_dev_port_add (vlib_main_t *, vnet_dev_t *,
481 vnet_dev_port_id_t,
482 vnet_dev_port_add_args_t *);
483vnet_dev_rv_t vnet_dev_dma_mem_alloc (vlib_main_t *, vnet_dev_t *, u32, u32,
484 void **);
485void vnet_dev_dma_mem_free (vlib_main_t *, vnet_dev_t *, void *);
486vnet_dev_bus_t *vnet_dev_find_device_bus (vlib_main_t *, vnet_dev_device_id_t);
487void *vnet_dev_get_device_info (vlib_main_t *, vnet_dev_device_id_t);
488
489/* error.c */
490clib_error_t *vnet_dev_port_err (vlib_main_t *, vnet_dev_port_t *,
491 vnet_dev_rv_t, char *, ...);
492
493/* handlers.c */
494clib_error_t *vnet_dev_port_set_max_frame_size (vnet_main_t *,
495 vnet_hw_interface_t *, u32);
496u32 vnet_dev_port_eth_flag_change (vnet_main_t *, vnet_hw_interface_t *, u32);
497clib_error_t *vnet_dev_port_mac_change (vnet_hw_interface_t *, const u8 *,
498 const u8 *);
499clib_error_t *vnet_dev_add_del_mac_address (vnet_hw_interface_t *, const u8 *,
500 u8);
501int vnet_dev_flow_ops_fn (vnet_main_t *, vnet_flow_dev_op_t, u32, u32,
502 uword *);
503clib_error_t *vnet_dev_interface_set_rss_queues (vnet_main_t *,
504 vnet_hw_interface_t *,
505 clib_bitmap_t *);
506void vnet_dev_clear_hw_interface_counters (u32);
Damjan Marion38c61912023-10-17 16:06:26 +0000507void vnet_dev_set_interface_next_node (vnet_main_t *, u32, u32);
508
509/* port.c */
510vnet_dev_rv_t vnet_dev_port_start (vlib_main_t *, vnet_dev_port_t *);
511vnet_dev_rv_t vnet_dev_port_start_all_rx_queues (vlib_main_t *,
512 vnet_dev_port_t *);
513vnet_dev_rv_t vnet_dev_port_start_all_tx_queues (vlib_main_t *,
514 vnet_dev_port_t *);
515void vnet_dev_port_stop (vlib_main_t *, vnet_dev_port_t *);
516void vnet_dev_port_deinit (vlib_main_t *, vnet_dev_port_t *);
517void vnet_dev_port_free (vlib_main_t *, vnet_dev_port_t *);
518void vnet_dev_port_add_counters (vlib_main_t *, vnet_dev_port_t *,
519 vnet_dev_counter_t *, u16);
520void vnet_dev_port_free_counters (vlib_main_t *, vnet_dev_port_t *);
521void vnet_dev_port_update_tx_node_runtime (vlib_main_t *, vnet_dev_port_t *);
522void vnet_dev_port_state_change (vlib_main_t *, vnet_dev_port_t *,
523 vnet_dev_port_state_changes_t);
524void vnet_dev_port_clear_counters (vlib_main_t *, vnet_dev_port_t *);
525vnet_dev_rv_t
526vnet_dev_port_cfg_change_req_validate (vlib_main_t *, vnet_dev_port_t *,
527 vnet_dev_port_cfg_change_req_t *);
528vnet_dev_rv_t vnet_dev_port_cfg_change (vlib_main_t *, vnet_dev_port_t *,
529 vnet_dev_port_cfg_change_req_t *);
530vnet_dev_rv_t vnet_dev_port_if_create (vlib_main_t *, vnet_dev_port_t *);
531vnet_dev_rv_t vnet_dev_port_if_remove (vlib_main_t *, vnet_dev_port_t *);
532
533/* queue.c */
534vnet_dev_rv_t vnet_dev_rx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16);
535vnet_dev_rv_t vnet_dev_tx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16);
536void vnet_dev_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *);
537void vnet_dev_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *);
538void vnet_dev_rx_queue_add_counters (vlib_main_t *, vnet_dev_rx_queue_t *,
539 vnet_dev_counter_t *, u16);
540void vnet_dev_rx_queue_free_counters (vlib_main_t *, vnet_dev_rx_queue_t *);
541void vnet_dev_tx_queue_add_counters (vlib_main_t *, vnet_dev_tx_queue_t *,
542 vnet_dev_counter_t *, u16);
543void vnet_dev_tx_queue_free_counters (vlib_main_t *, vnet_dev_tx_queue_t *);
544vnet_dev_rv_t vnet_dev_rx_queue_start (vlib_main_t *, vnet_dev_rx_queue_t *);
545vnet_dev_rv_t vnet_dev_tx_queue_start (vlib_main_t *, vnet_dev_tx_queue_t *);
546void vnet_dev_rx_queue_stop (vlib_main_t *, vnet_dev_rx_queue_t *);
547void vnet_dev_tx_queue_stop (vlib_main_t *, vnet_dev_tx_queue_t *);
548
549/* process.c */
550vnet_dev_rv_t vnet_dev_process_create (vlib_main_t *, vnet_dev_t *);
551vnet_dev_rv_t vnet_dev_process_call_op (vlib_main_t *, vnet_dev_t *,
552 vnet_dev_op_t *);
553vnet_dev_rv_t vnet_dev_process_call_op_no_rv (vlib_main_t *, vnet_dev_t *,
554 vnet_dev_op_no_rv_t *);
555void vnet_dev_process_call_op_no_wait (vlib_main_t *, vnet_dev_t *,
556 vnet_dev_op_no_rv_t *);
557vnet_dev_rv_t vnet_dev_process_call_port_op (vlib_main_t *, vnet_dev_port_t *,
558 vnet_dev_port_op_t *);
559vnet_dev_rv_t vnet_dev_process_call_port_op_no_rv (vlib_main_t *vm,
560 vnet_dev_port_t *,
561 vnet_dev_port_op_no_rv_t *);
562void vnet_dev_process_call_port_op_no_wait (vlib_main_t *, vnet_dev_port_t *,
563 vnet_dev_port_op_no_rv_t *);
564vnet_dev_rv_t
565vnet_dev_process_port_cfg_change_req (vlib_main_t *, vnet_dev_port_t *,
566 vnet_dev_port_cfg_change_req_t *);
567void vnet_dev_process_quit (vlib_main_t *, vnet_dev_t *);
568void vnet_dev_poll_dev_add (vlib_main_t *, vnet_dev_t *, f64,
569 vnet_dev_op_no_rv_t *);
570void vnet_dev_poll_dev_remove (vlib_main_t *, vnet_dev_t *,
571 vnet_dev_op_no_rv_t *);
572void vnet_dev_poll_port_add (vlib_main_t *, vnet_dev_port_t *, f64,
573 vnet_dev_port_op_no_rv_t *);
574void vnet_dev_poll_port_remove (vlib_main_t *, vnet_dev_port_t *,
575 vnet_dev_port_op_no_rv_t *);
576
Damjan Marion38c61912023-10-17 16:06:26 +0000577typedef struct
578{
579 u16 thread_index;
Damjan Marion38c61912023-10-17 16:06:26 +0000580 u8 completed;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000581 u8 in_order;
582 vnet_dev_port_t *port;
Damjan Marion38c61912023-10-17 16:06:26 +0000583} vnet_dev_rt_op_t;
584
585vnet_dev_rv_t vnet_dev_rt_exec_ops (vlib_main_t *, vnet_dev_t *,
586 vnet_dev_rt_op_t *, u32);
587
588/* format.c */
589typedef struct
590{
591 u8 counters : 1;
592 u8 show_zero_counters : 1;
593 u8 debug : 1;
594} vnet_dev_format_args_t;
595
596format_function_t format_vnet_dev_addr;
597format_function_t format_vnet_dev_hw_addr;
598format_function_t format_vnet_dev_info;
599format_function_t format_vnet_dev_interface_info;
600format_function_t format_vnet_dev_interface_name;
601format_function_t format_vnet_dev_port_info;
602format_function_t format_vnet_dev_rv;
603format_function_t format_vnet_dev_rx_queue_info;
604format_function_t format_vnet_dev_tx_queue_info;
605format_function_t format_vnet_dev_flags;
606format_function_t format_vnet_dev_port_flags;
Damjan Marion6bd6c802023-11-02 18:40:32 +0000607format_function_t format_vnet_dev_log;
Damjan Marion38c61912023-10-17 16:06:26 +0000608unformat_function_t unformat_vnet_dev_flags;
609unformat_function_t unformat_vnet_dev_port_flags;
610
611typedef struct
612{
Damjan Marionb8dd9812023-11-03 13:47:05 +0000613 vnet_dev_rx_queue_t *first_rx_queue;
Damjan Marion38c61912023-10-17 16:06:26 +0000614} vnet_dev_rx_node_runtime_t;
615
616STATIC_ASSERT (sizeof (vnet_dev_rx_node_runtime_t) <=
617 VLIB_NODE_RUNTIME_DATA_SIZE,
618 "must fit into runtime data");
619
620#define foreach_vnet_dev_port_rx_next \
621 _ (ETH_INPUT, "ethernet-input") \
622 _ (DROP, "error-drop")
623
624typedef enum
625{
626#define _(n, s) VNET_DEV_ETH_RX_PORT_NEXT_##n,
627 foreach_vnet_dev_port_rx_next
628#undef _
629 VNET_DEV_ETH_RX_PORT_N_NEXTS
630} vnet_dev_eth_port_rx_next_t;
631
632extern u16 vnet_dev_default_next_index_by_port_type[];
633extern vlib_node_registration_t port_rx_eth_node;
634
635typedef vnet_interface_output_runtime_t vnet_dev_tx_node_runtime_t;
636
637STATIC_ASSERT (sizeof (vnet_dev_tx_node_runtime_t) <=
638 VLIB_NODE_RUNTIME_DATA_SIZE,
639 "must fit into runtime data");
640
641#define VNET_DEV_REGISTER_BUS(x, ...) \
642 __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x; \
643 static void __clib_constructor __vnet_dev_bus_registration_fn_##x (void) \
644 { \
645 vnet_dev_main_t *dm = &vnet_dev_main; \
646 __vnet_dev_bus_registration_##x.next_registration = \
647 dm->bus_registrations; \
648 dm->bus_registrations = &__vnet_dev_bus_registration_##x; \
649 } \
650 __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x
651
652#define VNET_DEV_REGISTER_DRIVER(x, ...) \
653 __VA_ARGS__ vnet_dev_driver_registration_t \
654 __vnet_dev_driver_registration_##x; \
655 static void __clib_constructor __vnet_dev_driver_registration_fn_##x (void) \
656 { \
657 vnet_dev_main_t *dm = &vnet_dev_main; \
658 __vnet_dev_driver_registration_##x.next_registration = \
659 dm->driver_registrations; \
660 dm->driver_registrations = &__vnet_dev_driver_registration_##x; \
661 } \
662 __VA_ARGS__ vnet_dev_driver_registration_t __vnet_dev_driver_registration_##x
663
664#define VNET_DEV_NODE_FN(node) \
665 uword CLIB_MARCH_SFX (node##_fn) (vlib_main_t *, vlib_node_runtime_t *, \
666 vlib_frame_t *); \
667 static vlib_node_fn_registration_t CLIB_MARCH_SFX ( \
668 node##_fn_registration) = { \
669 .function = &CLIB_MARCH_SFX (node##_fn), \
670 }; \
671 \
672 static void __clib_constructor CLIB_MARCH_SFX ( \
673 node##_fn_multiarch_register) (void) \
674 { \
675 extern vnet_dev_node_t node; \
676 vlib_node_fn_registration_t *r; \
677 r = &CLIB_MARCH_SFX (node##_fn_registration); \
678 r->march_variant = CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE); \
679 r->next_registration = (node).registrations; \
680 (node).registrations = r; \
681 } \
682 uword CLIB_MARCH_SFX (node##_fn)
683
684#define foreach_vnet_dev_port(p, d) pool_foreach_pointer (p, d->ports)
685#define foreach_vnet_dev_port_rx_queue(q, p) \
686 pool_foreach_pointer (q, p->rx_queues)
687#define foreach_vnet_dev_port_tx_queue(q, p) \
688 pool_foreach_pointer (q, p->tx_queues)
689
690#include <vnet/dev/dev_funcs.h>
691
692#endif /* _VNET_DEV_H_ */