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