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