blob: bbf2f9dff21e02a241e35097a9cf7e84ba54a8a8 [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) \
Monendra Singh Kushwaha4af3fdf2024-02-06 14:02:43 +0530147 _ (RXQ_INTR_MODE_DISABLE) \
148 _ (ADD_RX_FLOW) \
149 _ (DEL_RX_FLOW) \
150 _ (GET_RX_FLOW_COUNTER) \
151 _ (RESET_RX_FLOW_COUNTER)
Damjan Marion38c61912023-10-17 16:06:26 +0000152
153typedef enum
154{
155 VNET_DEV_PORT_CFG_UNKNOWN,
156#define _(n) VNET_DEV_PORT_CFG_##n,
157 foreach_vnet_dev_port_cfg_type
158#undef _
159} __clib_packed vnet_dev_port_cfg_type_t;
160
161typedef struct vnet_dev_port_cfg_change_req
162{
163 vnet_dev_port_cfg_type_t type;
164 u8 validated : 1;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000165 u8 all_queues : 1;
Damjan Marion38c61912023-10-17 16:06:26 +0000166
167 union
168 {
169 u8 promisc : 1;
170 vnet_dev_hw_addr_t addr;
Damjan Marione596ca12023-11-08 19:12:27 +0000171 u16 max_rx_frame_size;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000172 vnet_dev_queue_id_t queue_id;
Monendra Singh Kushwaha4af3fdf2024-02-06 14:02:43 +0530173 struct
174 {
175 u32 flow_index;
176 uword *private_data;
177 };
Damjan Marion38c61912023-10-17 16:06:26 +0000178 };
179
180} vnet_dev_port_cfg_change_req_t;
181
182typedef struct
183{
184 vnet_dev_hw_addr_t hw_addr;
185 u16 max_rx_queues;
186 u16 max_tx_queues;
Damjan Marione596ca12023-11-08 19:12:27 +0000187 u16 max_supported_rx_frame_size;
Damjan Marion38c61912023-10-17 16:06:26 +0000188 vnet_dev_port_type_t type;
189 vnet_dev_port_caps_t caps;
Damjan Mariond1eb1b72023-12-07 16:40:02 +0100190 vnet_dev_port_rx_offloads_t rx_offloads;
191 vnet_dev_port_tx_offloads_t tx_offloads;
Damjan Marion38c61912023-10-17 16:06:26 +0000192} vnet_dev_port_attr_t;
193
194typedef enum
195{
196 VNET_DEV_PERIODIC_OP_TYPE_DEV = 1,
197 VNET_DEV_PERIODIC_OP_TYPE_PORT = 2,
198} __clib_packed vnet_dev_periodic_op_type_t;
199
200typedef struct
201{
202 f64 interval;
203 f64 last_run;
204 vnet_dev_periodic_op_type_t type;
205 union
206 {
207 vnet_dev_t *dev;
208 vnet_dev_port_t *port;
209 void *arg;
210 };
211 union
212 {
213 vnet_dev_op_no_rv_t *dev_op;
214 vnet_dev_port_op_no_rv_t *port_op;
215 void *op;
216 };
217} vnet_dev_periodic_op_t;
218
219typedef struct
220{
221 struct _vlib_node_fn_registration *registrations;
222 format_function_t *format_trace;
223 vlib_error_desc_t *error_counters;
224 u16 n_error_counters;
225} vnet_dev_node_t;
226
227typedef struct
228{
229 vnet_dev_op_t *alloc;
230 vnet_dev_op_t *init;
231 vnet_dev_op_no_rv_t *deinit;
232 vnet_dev_op_t *reset;
233 vnet_dev_op_no_rv_t *free;
234 u8 *(*probe) (vlib_main_t *, vnet_dev_bus_index_t, void *);
235 format_function_t *format_info;
236} vnet_dev_ops_t;
237
238typedef struct
239{
240 vnet_dev_port_op_t *alloc;
241 vnet_dev_port_op_t *init;
242 vnet_dev_port_cfg_change_op_t *config_change;
243 vnet_dev_port_cfg_change_op_t *config_change_validate;
244 vnet_dev_port_op_t *start;
245 vnet_dev_port_op_no_rv_t *stop;
246 vnet_dev_port_op_no_rv_t *deinit;
247 vnet_dev_port_op_no_rv_t *free;
248 format_function_t *format_status;
Monendra Singh Kushwaha4af3fdf2024-02-06 14:02:43 +0530249 format_function_t *format_flow;
Damjan Marion38c61912023-10-17 16:06:26 +0000250} vnet_dev_port_ops_t;
251
252typedef union
253{
254 struct
255 {
256 u8 update_next_index : 1;
257 u8 update_feature_arc : 1;
258 u8 suspend_off : 1;
259 u8 suspend_on : 1;
260 };
261 u8 as_number;
262} vnet_dev_rx_queue_rt_req_t;
263
264typedef struct vnet_dev_rx_queue
265{
266 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
267 vnet_dev_port_t *port;
268 u16 rx_thread_index;
269 u16 index;
270 vnet_dev_counter_main_t *counter_main;
271 CLIB_CACHE_LINE_ALIGN_MARK (runtime0);
Damjan Marionb8dd9812023-11-03 13:47:05 +0000272 vnet_dev_rx_queue_t *next_on_thread;
273 u8 interrupt_mode : 1;
Damjan Marion38c61912023-10-17 16:06:26 +0000274 u8 enabled : 1;
275 u8 started : 1;
276 u8 suspended : 1;
277 vnet_dev_queue_id_t queue_id;
278 u16 size;
279 u16 next_index;
280 vnet_dev_rx_queue_rt_req_t runtime_request;
281 CLIB_CACHE_LINE_ALIGN_MARK (runtime1);
282 vlib_buffer_template_t buffer_template;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000283 CLIB_CACHE_LINE_ALIGN_MARK (driver_data);
Damjan Marion38c61912023-10-17 16:06:26 +0000284 u8 data[];
285} vnet_dev_rx_queue_t;
286
287STATIC_ASSERT_SIZEOF (vnet_dev_rx_queue_t, 3 * CLIB_CACHE_LINE_BYTES);
288
289typedef struct vnet_dev_tx_queue
290{
291 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
292 vnet_dev_port_t *port;
293 clib_bitmap_t *assigned_threads;
294 u16 index;
295 vnet_dev_counter_main_t *counter_main;
296 CLIB_CACHE_LINE_ALIGN_MARK (runtime0);
297 vnet_dev_queue_id_t queue_id;
298 u8 started : 1;
299 u8 enabled : 1;
300 u8 lock_needed : 1;
301 u8 lock;
302 u16 size;
303 CLIB_ALIGN_MARK (private_data, 16);
304 u8 data[];
305} vnet_dev_tx_queue_t;
306
307STATIC_ASSERT_SIZEOF (vnet_dev_tx_queue_t, 2 * CLIB_CACHE_LINE_BYTES);
308
309typedef struct vnet_dev_port
310{
311 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
312 vnet_dev_t *dev;
313 vnet_dev_port_id_t port_id;
314 vnet_dev_driver_index_t driver_index;
315 u8 initialized : 1;
316 u8 started : 1;
317 u8 link_up : 1;
318 u8 promisc : 1;
319 u8 interface_created : 1;
320 u8 rx_node_assigned : 1;
321 vnet_dev_counter_main_t *counter_main;
322 vnet_dev_queue_config_t rx_queue_config;
323 vnet_dev_queue_config_t tx_queue_config;
324 vnet_dev_port_attr_t attr;
Damjan Marione596ca12023-11-08 19:12:27 +0000325 u32 max_rx_frame_size;
Damjan Marion38c61912023-10-17 16:06:26 +0000326 vnet_dev_hw_addr_t primary_hw_addr;
327 vnet_dev_hw_addr_t *secondary_hw_addr;
328 u32 index;
329 u32 speed;
330 vnet_dev_rx_queue_t **rx_queues;
331 vnet_dev_tx_queue_t **tx_queues;
332 vnet_dev_port_ops_t port_ops;
Damjan Marion69768d92023-11-13 17:33:32 +0000333 vnet_dev_arg_t *args;
Damjan Marion38c61912023-10-17 16:06:26 +0000334 vnet_dev_rx_queue_ops_t rx_queue_ops;
335 vnet_dev_tx_queue_ops_t tx_queue_ops;
336 vnet_dev_node_t rx_node;
337 vnet_dev_node_t tx_node;
338
339 struct
340 {
341 vnet_dev_if_name_t name;
342 u32 dev_instance;
343 u32 rx_node_index;
344 u32 current_config_index;
345 u16 rx_next_index;
346 u16 redirect_to_node_next_index;
347 u8 feature_arc_index;
348 u8 feature_arc : 1;
349 u8 redirect_to_node : 1;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000350 u8 default_is_intr_mode : 1;
Damjan Marion38c61912023-10-17 16:06:26 +0000351 u32 tx_node_index;
352 u32 hw_if_index;
353 u32 sw_if_index;
354 u16 num_rx_queues;
355 u16 num_tx_queues;
356 u16 txq_sz;
357 u16 rxq_sz;
358 } intf;
359
360 CLIB_CACHE_LINE_ALIGN_MARK (data0);
361 u8 data[];
362} vnet_dev_port_t;
363
364typedef struct vnet_dev
365{
366 vnet_dev_device_id_t device_id;
367 u16 initialized : 1;
368 u16 not_first_init : 1;
369 u16 va_dma : 1;
370 u16 process_node_quit : 1;
371 u16 process_node_periodic : 1;
372 u16 poll_stats : 1;
373 u16 bus_index;
374 u8 numa_node;
375 u16 max_rx_queues;
376 u16 max_tx_queues;
377 vnet_dev_driver_index_t driver_index;
378 u32 index;
379 u32 process_node_index;
380 u8 bus_data[32] __clib_aligned (16);
381 vnet_dev_ops_t ops;
382 vnet_dev_port_t **ports;
383 vnet_dev_periodic_op_t *periodic_ops;
384 u8 *description;
Damjan Marion69768d92023-11-13 17:33:32 +0000385 vnet_dev_arg_t *args;
Damjan Marion38c61912023-10-17 16:06:26 +0000386 u8 __clib_aligned (16)
387 data[];
388} vnet_dev_t;
389
390typedef struct
391{
392 u16 vendor_id, device_id;
393 char *description;
394} vnet_dev_match_t;
395
396#define VNET_DEV_MATCH(...) \
397 (vnet_dev_match_t[]) \
398 { \
399 __VA_ARGS__, {} \
400 }
401
402typedef struct
403{
404 vnet_dev_op_t *device_open;
405 vnet_dev_op_no_rv_t *device_close;
406 vnet_dev_rv_t (*dma_mem_alloc_fn) (vlib_main_t *, vnet_dev_t *, u32, u32,
407 void **);
408 void (*dma_mem_free_fn) (vlib_main_t *, vnet_dev_t *, void *);
409 void *(*get_device_info) (vlib_main_t *, char *);
410 void (*free_device_info) (vlib_main_t *, void *);
411 format_function_t *format_device_info;
412 format_function_t *format_device_addr;
413} vnet_dev_bus_ops_t;
414
415struct vnet_dev_bus_registration
416{
417 vnet_dev_bus_registration_t *next_registration;
418 vnet_dev_driver_name_t name;
419 u16 device_data_size;
420 vnet_dev_bus_ops_t ops;
421};
422
423struct vnet_dev_driver_registration
424{
425 vnet_dev_driver_registration_t *next_registration;
426 u8 bus_master_enable : 1;
427 vnet_dev_driver_name_t name;
428 vnet_dev_bus_name_t bus;
429 u16 device_data_sz;
430 u16 runtime_temp_space_sz;
431 vnet_dev_match_t *match;
432 int priority;
433 vnet_dev_ops_t ops;
Damjan Marion69768d92023-11-13 17:33:32 +0000434 vnet_dev_arg_t *args;
Damjan Marion38c61912023-10-17 16:06:26 +0000435};
436
437typedef struct
438{
439 u32 index;
440 vnet_dev_bus_registration_t *registration;
441 vnet_dev_bus_ops_t ops;
442} vnet_dev_bus_t;
443
444typedef struct
445{
446 u32 index;
447 void *dev_data;
448 vnet_dev_driver_registration_t *registration;
449 u32 dev_class_index;
450 vnet_dev_bus_index_t bus_index;
451 vnet_dev_ops_t ops;
452} vnet_dev_driver_t;
453
454typedef struct
455{
456 vnet_dev_bus_t *buses;
457 vnet_dev_driver_t *drivers;
458 vnet_dev_t **devices;
459 vnet_dev_port_t **ports_by_dev_instance;
460 vnet_dev_bus_registration_t *bus_registrations;
461 vnet_dev_driver_registration_t *driver_registrations;
462 void *runtime_temp_spaces;
463 u32 log2_runtime_temp_space_sz;
464 u32 *free_process_node_indices;
465 u32 *free_rx_node_indices;
466 uword *device_index_by_id;
467
468 u8 *startup_config;
469 u16 next_rx_queue_thread;
470 u8 eth_port_rx_feature_arc_index;
471} vnet_dev_main_t;
472
473extern vnet_dev_main_t vnet_dev_main;
474
475typedef struct
476{
477 struct
478 {
479 vnet_dev_port_attr_t attr;
480 vnet_dev_port_ops_t ops;
Damjan Marion69768d92023-11-13 17:33:32 +0000481 vnet_dev_arg_t *args;
Damjan Marion38c61912023-10-17 16:06:26 +0000482 u16 data_size;
483 void *initial_data;
484 } port;
485
486 vnet_dev_node_t *rx_node;
487 vnet_dev_node_t *tx_node;
488
489 struct
490 {
491 vnet_dev_queue_config_t config;
492 vnet_dev_rx_queue_ops_t ops;
493 } rx_queue;
494
495 struct
496 {
497 vnet_dev_queue_config_t config;
498 vnet_dev_tx_queue_ops_t ops;
499 } tx_queue;
500} vnet_dev_port_add_args_t;
501
502typedef struct
503{
504 union
505 {
506 struct
507 {
508 u8 link_speed : 1;
509 u8 link_state : 1;
510 u8 link_duplex : 1;
511 };
512 u8 any;
513 } change;
514 u8 link_state : 1;
515 u8 full_duplex : 1;
516 u32 link_speed;
517} vnet_dev_port_state_changes_t;
518
Damjan Marion69768d92023-11-13 17:33:32 +0000519/* args.c */
520vnet_dev_rv_t vnet_dev_arg_parse (vlib_main_t *, vnet_dev_t *,
521 vnet_dev_arg_t *, u8 *);
522void vnet_dev_arg_free (vnet_dev_arg_t **);
523void vnet_dev_arg_clear_value (vnet_dev_arg_t *);
524format_function_t format_vnet_dev_arg_type;
525format_function_t format_vnet_dev_arg_value;
526format_function_t format_vnet_dev_args;
527
Damjan Marion38c61912023-10-17 16:06:26 +0000528/* dev.c */
529vnet_dev_t *vnet_dev_alloc (vlib_main_t *, vnet_dev_device_id_t,
530 vnet_dev_driver_t *);
531void vnet_dev_free (vlib_main_t *, vnet_dev_t *);
532vnet_dev_rv_t vnet_dev_init (vlib_main_t *, vnet_dev_t *);
533void vnet_dev_deinit (vlib_main_t *, vnet_dev_t *);
534vnet_dev_rv_t vnet_dev_reset (vlib_main_t *, vnet_dev_t *);
535void vnet_dev_detach (vlib_main_t *, vnet_dev_t *);
536vnet_dev_rv_t vnet_dev_port_add (vlib_main_t *, vnet_dev_t *,
537 vnet_dev_port_id_t,
538 vnet_dev_port_add_args_t *);
539vnet_dev_rv_t vnet_dev_dma_mem_alloc (vlib_main_t *, vnet_dev_t *, u32, u32,
540 void **);
541void vnet_dev_dma_mem_free (vlib_main_t *, vnet_dev_t *, void *);
542vnet_dev_bus_t *vnet_dev_find_device_bus (vlib_main_t *, vnet_dev_device_id_t);
543void *vnet_dev_get_device_info (vlib_main_t *, vnet_dev_device_id_t);
544
545/* error.c */
546clib_error_t *vnet_dev_port_err (vlib_main_t *, vnet_dev_port_t *,
547 vnet_dev_rv_t, char *, ...);
Monendra Singh Kushwaha4af3fdf2024-02-06 14:02:43 +0530548int vnet_dev_flow_err (vlib_main_t *, vnet_dev_rv_t);
Damjan Marion38c61912023-10-17 16:06:26 +0000549
550/* handlers.c */
551clib_error_t *vnet_dev_port_set_max_frame_size (vnet_main_t *,
552 vnet_hw_interface_t *, u32);
553u32 vnet_dev_port_eth_flag_change (vnet_main_t *, vnet_hw_interface_t *, u32);
554clib_error_t *vnet_dev_port_mac_change (vnet_hw_interface_t *, const u8 *,
555 const u8 *);
556clib_error_t *vnet_dev_add_del_mac_address (vnet_hw_interface_t *, const u8 *,
557 u8);
558int vnet_dev_flow_ops_fn (vnet_main_t *, vnet_flow_dev_op_t, u32, u32,
559 uword *);
560clib_error_t *vnet_dev_interface_set_rss_queues (vnet_main_t *,
561 vnet_hw_interface_t *,
562 clib_bitmap_t *);
563void vnet_dev_clear_hw_interface_counters (u32);
Damjan Marion38c61912023-10-17 16:06:26 +0000564void vnet_dev_set_interface_next_node (vnet_main_t *, u32, u32);
565
566/* port.c */
567vnet_dev_rv_t vnet_dev_port_start (vlib_main_t *, vnet_dev_port_t *);
568vnet_dev_rv_t vnet_dev_port_start_all_rx_queues (vlib_main_t *,
569 vnet_dev_port_t *);
570vnet_dev_rv_t vnet_dev_port_start_all_tx_queues (vlib_main_t *,
571 vnet_dev_port_t *);
572void vnet_dev_port_stop (vlib_main_t *, vnet_dev_port_t *);
573void vnet_dev_port_deinit (vlib_main_t *, vnet_dev_port_t *);
574void vnet_dev_port_free (vlib_main_t *, vnet_dev_port_t *);
575void vnet_dev_port_add_counters (vlib_main_t *, vnet_dev_port_t *,
576 vnet_dev_counter_t *, u16);
577void vnet_dev_port_free_counters (vlib_main_t *, vnet_dev_port_t *);
578void vnet_dev_port_update_tx_node_runtime (vlib_main_t *, vnet_dev_port_t *);
579void vnet_dev_port_state_change (vlib_main_t *, vnet_dev_port_t *,
580 vnet_dev_port_state_changes_t);
581void vnet_dev_port_clear_counters (vlib_main_t *, vnet_dev_port_t *);
582vnet_dev_rv_t
583vnet_dev_port_cfg_change_req_validate (vlib_main_t *, vnet_dev_port_t *,
584 vnet_dev_port_cfg_change_req_t *);
585vnet_dev_rv_t vnet_dev_port_cfg_change (vlib_main_t *, vnet_dev_port_t *,
586 vnet_dev_port_cfg_change_req_t *);
587vnet_dev_rv_t vnet_dev_port_if_create (vlib_main_t *, vnet_dev_port_t *);
588vnet_dev_rv_t vnet_dev_port_if_remove (vlib_main_t *, vnet_dev_port_t *);
589
590/* queue.c */
591vnet_dev_rv_t vnet_dev_rx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16);
592vnet_dev_rv_t vnet_dev_tx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16);
593void vnet_dev_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *);
594void vnet_dev_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *);
595void vnet_dev_rx_queue_add_counters (vlib_main_t *, vnet_dev_rx_queue_t *,
596 vnet_dev_counter_t *, u16);
597void vnet_dev_rx_queue_free_counters (vlib_main_t *, vnet_dev_rx_queue_t *);
598void vnet_dev_tx_queue_add_counters (vlib_main_t *, vnet_dev_tx_queue_t *,
599 vnet_dev_counter_t *, u16);
600void vnet_dev_tx_queue_free_counters (vlib_main_t *, vnet_dev_tx_queue_t *);
601vnet_dev_rv_t vnet_dev_rx_queue_start (vlib_main_t *, vnet_dev_rx_queue_t *);
602vnet_dev_rv_t vnet_dev_tx_queue_start (vlib_main_t *, vnet_dev_tx_queue_t *);
603void vnet_dev_rx_queue_stop (vlib_main_t *, vnet_dev_rx_queue_t *);
604void vnet_dev_tx_queue_stop (vlib_main_t *, vnet_dev_tx_queue_t *);
605
606/* process.c */
607vnet_dev_rv_t vnet_dev_process_create (vlib_main_t *, vnet_dev_t *);
608vnet_dev_rv_t vnet_dev_process_call_op (vlib_main_t *, vnet_dev_t *,
609 vnet_dev_op_t *);
610vnet_dev_rv_t vnet_dev_process_call_op_no_rv (vlib_main_t *, vnet_dev_t *,
611 vnet_dev_op_no_rv_t *);
612void vnet_dev_process_call_op_no_wait (vlib_main_t *, vnet_dev_t *,
613 vnet_dev_op_no_rv_t *);
614vnet_dev_rv_t vnet_dev_process_call_port_op (vlib_main_t *, vnet_dev_port_t *,
615 vnet_dev_port_op_t *);
616vnet_dev_rv_t vnet_dev_process_call_port_op_no_rv (vlib_main_t *vm,
617 vnet_dev_port_t *,
618 vnet_dev_port_op_no_rv_t *);
619void vnet_dev_process_call_port_op_no_wait (vlib_main_t *, vnet_dev_port_t *,
620 vnet_dev_port_op_no_rv_t *);
621vnet_dev_rv_t
622vnet_dev_process_port_cfg_change_req (vlib_main_t *, vnet_dev_port_t *,
623 vnet_dev_port_cfg_change_req_t *);
624void vnet_dev_process_quit (vlib_main_t *, vnet_dev_t *);
625void vnet_dev_poll_dev_add (vlib_main_t *, vnet_dev_t *, f64,
626 vnet_dev_op_no_rv_t *);
627void vnet_dev_poll_dev_remove (vlib_main_t *, vnet_dev_t *,
628 vnet_dev_op_no_rv_t *);
629void vnet_dev_poll_port_add (vlib_main_t *, vnet_dev_port_t *, f64,
630 vnet_dev_port_op_no_rv_t *);
631void vnet_dev_poll_port_remove (vlib_main_t *, vnet_dev_port_t *,
632 vnet_dev_port_op_no_rv_t *);
633
Damjan Marion38c61912023-10-17 16:06:26 +0000634typedef struct
635{
636 u16 thread_index;
Damjan Marion38c61912023-10-17 16:06:26 +0000637 u8 completed;
Damjan Marionb8dd9812023-11-03 13:47:05 +0000638 u8 in_order;
639 vnet_dev_port_t *port;
Damjan Marion38c61912023-10-17 16:06:26 +0000640} vnet_dev_rt_op_t;
641
642vnet_dev_rv_t vnet_dev_rt_exec_ops (vlib_main_t *, vnet_dev_t *,
643 vnet_dev_rt_op_t *, u32);
644
645/* format.c */
646typedef struct
647{
648 u8 counters : 1;
649 u8 show_zero_counters : 1;
650 u8 debug : 1;
651} vnet_dev_format_args_t;
652
653format_function_t format_vnet_dev_addr;
Damjan Mariond1eb1b72023-12-07 16:40:02 +0100654format_function_t format_vnet_dev_flags;
Damjan Marion38c61912023-10-17 16:06:26 +0000655format_function_t format_vnet_dev_hw_addr;
656format_function_t format_vnet_dev_info;
657format_function_t format_vnet_dev_interface_info;
658format_function_t format_vnet_dev_interface_name;
Damjan Mariond1eb1b72023-12-07 16:40:02 +0100659format_function_t format_vnet_dev_log;
660format_function_t format_vnet_dev_port_caps;
661format_function_t format_vnet_dev_port_flags;
Damjan Marion38c61912023-10-17 16:06:26 +0000662format_function_t format_vnet_dev_port_info;
Damjan Mariond1eb1b72023-12-07 16:40:02 +0100663format_function_t format_vnet_dev_port_rx_offloads;
664format_function_t format_vnet_dev_port_tx_offloads;
Damjan Marion38c61912023-10-17 16:06:26 +0000665format_function_t format_vnet_dev_rv;
666format_function_t format_vnet_dev_rx_queue_info;
667format_function_t format_vnet_dev_tx_queue_info;
Monendra Singh Kushwaha4af3fdf2024-02-06 14:02:43 +0530668format_function_t format_vnet_dev_flow;
Damjan Marion38c61912023-10-17 16:06:26 +0000669unformat_function_t unformat_vnet_dev_flags;
670unformat_function_t unformat_vnet_dev_port_flags;
671
672typedef struct
673{
Damjan Marionb8dd9812023-11-03 13:47:05 +0000674 vnet_dev_rx_queue_t *first_rx_queue;
Damjan Marion38c61912023-10-17 16:06:26 +0000675} vnet_dev_rx_node_runtime_t;
676
677STATIC_ASSERT (sizeof (vnet_dev_rx_node_runtime_t) <=
678 VLIB_NODE_RUNTIME_DATA_SIZE,
679 "must fit into runtime data");
680
681#define foreach_vnet_dev_port_rx_next \
682 _ (ETH_INPUT, "ethernet-input") \
683 _ (DROP, "error-drop")
684
685typedef enum
686{
687#define _(n, s) VNET_DEV_ETH_RX_PORT_NEXT_##n,
688 foreach_vnet_dev_port_rx_next
689#undef _
690 VNET_DEV_ETH_RX_PORT_N_NEXTS
691} vnet_dev_eth_port_rx_next_t;
692
693extern u16 vnet_dev_default_next_index_by_port_type[];
694extern vlib_node_registration_t port_rx_eth_node;
695
696typedef vnet_interface_output_runtime_t vnet_dev_tx_node_runtime_t;
697
698STATIC_ASSERT (sizeof (vnet_dev_tx_node_runtime_t) <=
699 VLIB_NODE_RUNTIME_DATA_SIZE,
700 "must fit into runtime data");
701
702#define VNET_DEV_REGISTER_BUS(x, ...) \
703 __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x; \
704 static void __clib_constructor __vnet_dev_bus_registration_fn_##x (void) \
705 { \
706 vnet_dev_main_t *dm = &vnet_dev_main; \
707 __vnet_dev_bus_registration_##x.next_registration = \
708 dm->bus_registrations; \
709 dm->bus_registrations = &__vnet_dev_bus_registration_##x; \
710 } \
711 __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x
712
713#define VNET_DEV_REGISTER_DRIVER(x, ...) \
714 __VA_ARGS__ vnet_dev_driver_registration_t \
715 __vnet_dev_driver_registration_##x; \
716 static void __clib_constructor __vnet_dev_driver_registration_fn_##x (void) \
717 { \
718 vnet_dev_main_t *dm = &vnet_dev_main; \
719 __vnet_dev_driver_registration_##x.next_registration = \
720 dm->driver_registrations; \
721 dm->driver_registrations = &__vnet_dev_driver_registration_##x; \
722 } \
723 __VA_ARGS__ vnet_dev_driver_registration_t __vnet_dev_driver_registration_##x
724
725#define VNET_DEV_NODE_FN(node) \
726 uword CLIB_MARCH_SFX (node##_fn) (vlib_main_t *, vlib_node_runtime_t *, \
727 vlib_frame_t *); \
728 static vlib_node_fn_registration_t CLIB_MARCH_SFX ( \
729 node##_fn_registration) = { \
730 .function = &CLIB_MARCH_SFX (node##_fn), \
731 }; \
732 \
733 static void __clib_constructor CLIB_MARCH_SFX ( \
734 node##_fn_multiarch_register) (void) \
735 { \
736 extern vnet_dev_node_t node; \
737 vlib_node_fn_registration_t *r; \
738 r = &CLIB_MARCH_SFX (node##_fn_registration); \
739 r->march_variant = CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE); \
740 r->next_registration = (node).registrations; \
741 (node).registrations = r; \
742 } \
743 uword CLIB_MARCH_SFX (node##_fn)
744
745#define foreach_vnet_dev_port(p, d) pool_foreach_pointer (p, d->ports)
746#define foreach_vnet_dev_port_rx_queue(q, p) \
747 pool_foreach_pointer (q, p->rx_queues)
748#define foreach_vnet_dev_port_tx_queue(q, p) \
749 pool_foreach_pointer (q, p->tx_queues)
750
751#include <vnet/dev/dev_funcs.h>
752
753#endif /* _VNET_DEV_H_ */