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