Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 1 | /* 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 13 | #include <vnet/dev/args.h> |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 14 | |
| 15 | #define VNET_DEV_DEVICE_ID_PREFIX_DELIMITER "/" |
| 16 | |
| 17 | #define foreach_vnet_dev_port_type \ |
| 18 | _ (0, UNKNOWN) \ |
| 19 | _ (1, ETHERNET) |
| 20 | |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 21 | typedef 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 Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 30 | _ (rss) \ |
| 31 | _ (change_max_rx_frame_size) |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 32 | |
| 33 | typedef 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 | |
| 44 | typedef union |
| 45 | { |
| 46 | u8 eth_mac[6]; |
| 47 | u8 raw[8]; |
| 48 | } vnet_dev_hw_addr_t; |
| 49 | |
| 50 | typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t; |
| 51 | typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t; |
| 52 | |
| 53 | typedef struct vnet_dev vnet_dev_t; |
| 54 | typedef struct vnet_dev_port vnet_dev_port_t; |
| 55 | typedef struct vnet_dev_rx_queue vnet_dev_rx_queue_t; |
| 56 | typedef struct vnet_dev_tx_queue vnet_dev_tx_queue_t; |
| 57 | typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t; |
| 58 | typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t; |
| 59 | typedef struct vnet_dev_counter vnet_dev_counter_t; |
| 60 | typedef struct vnet_dev_counter_main vnet_dev_counter_main_t; |
| 61 | typedef struct vnet_dev_port_cfg_change_req vnet_dev_port_cfg_change_req_t; |
| 62 | |
| 63 | typedef vnet_dev_rv_t (vnet_dev_op_t) (vlib_main_t *, vnet_dev_t *); |
| 64 | typedef vnet_dev_rv_t (vnet_dev_port_op_t) (vlib_main_t *, vnet_dev_port_t *); |
| 65 | typedef 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 *); |
| 67 | typedef vnet_dev_rv_t (vnet_dev_rx_queue_op_t) (vlib_main_t *, |
| 68 | vnet_dev_rx_queue_t *); |
| 69 | typedef vnet_dev_rv_t (vnet_dev_tx_queue_op_t) (vlib_main_t *, |
| 70 | vnet_dev_tx_queue_t *); |
| 71 | typedef void (vnet_dev_op_no_rv_t) (vlib_main_t *, vnet_dev_t *); |
| 72 | typedef void (vnet_dev_port_op_no_rv_t) (vlib_main_t *, vnet_dev_port_t *); |
| 73 | typedef void (vnet_dev_rx_queue_op_no_rv_t) (vlib_main_t *, |
| 74 | vnet_dev_rx_queue_t *); |
| 75 | typedef void (vnet_dev_tx_queue_op_no_rv_t) (vlib_main_t *, |
| 76 | vnet_dev_tx_queue_t *); |
| 77 | |
| 78 | typedef u16 vnet_dev_queue_id_t; |
| 79 | typedef u16 vnet_dev_bus_index_t; |
| 80 | typedef u16 vnet_dev_driver_index_t; |
| 81 | |
| 82 | typedef 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 | |
| 90 | typedef 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 | |
| 98 | typedef 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) \ |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 110 | _ (MAX_RX_FRAME_SIZE) \ |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 111 | _ (CHANGE_PRIMARY_HW_ADDR) \ |
| 112 | _ (ADD_SECONDARY_HW_ADDR) \ |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 113 | _ (REMOVE_SECONDARY_HW_ADDR) \ |
| 114 | _ (RXQ_INTR_MODE_ENABLE) \ |
| 115 | _ (RXQ_INTR_MODE_DISABLE) |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 116 | |
| 117 | typedef 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 | |
| 125 | typedef struct vnet_dev_port_cfg_change_req |
| 126 | { |
| 127 | vnet_dev_port_cfg_type_t type; |
| 128 | u8 validated : 1; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 129 | u8 all_queues : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 130 | |
| 131 | union |
| 132 | { |
| 133 | u8 promisc : 1; |
| 134 | vnet_dev_hw_addr_t addr; |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 135 | u16 max_rx_frame_size; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 136 | vnet_dev_queue_id_t queue_id; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | } vnet_dev_port_cfg_change_req_t; |
| 140 | |
| 141 | typedef struct |
| 142 | { |
| 143 | vnet_dev_hw_addr_t hw_addr; |
| 144 | u16 max_rx_queues; |
| 145 | u16 max_tx_queues; |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 146 | u16 max_supported_rx_frame_size; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 147 | vnet_dev_port_type_t type; |
| 148 | vnet_dev_port_caps_t caps; |
| 149 | } vnet_dev_port_attr_t; |
| 150 | |
| 151 | typedef 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 | |
| 157 | typedef 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 | |
| 176 | typedef 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 | |
| 184 | typedef 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 | |
| 195 | typedef 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 | |
| 208 | typedef 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 | |
| 220 | typedef 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 228 | vnet_dev_rx_queue_t *next_on_thread; |
| 229 | u8 interrupt_mode : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 230 | 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 239 | CLIB_CACHE_LINE_ALIGN_MARK (driver_data); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 240 | u8 data[]; |
| 241 | } vnet_dev_rx_queue_t; |
| 242 | |
| 243 | STATIC_ASSERT_SIZEOF (vnet_dev_rx_queue_t, 3 * CLIB_CACHE_LINE_BYTES); |
| 244 | |
| 245 | typedef 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 | |
| 263 | STATIC_ASSERT_SIZEOF (vnet_dev_tx_queue_t, 2 * CLIB_CACHE_LINE_BYTES); |
| 264 | |
| 265 | typedef 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; |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 281 | u32 max_rx_frame_size; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 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; |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 289 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 290 | vnet_dev_rx_queue_ops_t rx_queue_ops; |
| 291 | vnet_dev_tx_queue_ops_t tx_queue_ops; |
| 292 | vnet_dev_node_t rx_node; |
| 293 | vnet_dev_node_t tx_node; |
| 294 | |
| 295 | struct |
| 296 | { |
| 297 | vnet_dev_if_name_t name; |
| 298 | u32 dev_instance; |
| 299 | u32 rx_node_index; |
| 300 | u32 current_config_index; |
| 301 | u16 rx_next_index; |
| 302 | u16 redirect_to_node_next_index; |
| 303 | u8 feature_arc_index; |
| 304 | u8 feature_arc : 1; |
| 305 | u8 redirect_to_node : 1; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 306 | u8 default_is_intr_mode : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 307 | u32 tx_node_index; |
| 308 | u32 hw_if_index; |
| 309 | u32 sw_if_index; |
| 310 | u16 num_rx_queues; |
| 311 | u16 num_tx_queues; |
| 312 | u16 txq_sz; |
| 313 | u16 rxq_sz; |
| 314 | } intf; |
| 315 | |
| 316 | CLIB_CACHE_LINE_ALIGN_MARK (data0); |
| 317 | u8 data[]; |
| 318 | } vnet_dev_port_t; |
| 319 | |
| 320 | typedef struct vnet_dev |
| 321 | { |
| 322 | vnet_dev_device_id_t device_id; |
| 323 | u16 initialized : 1; |
| 324 | u16 not_first_init : 1; |
| 325 | u16 va_dma : 1; |
| 326 | u16 process_node_quit : 1; |
| 327 | u16 process_node_periodic : 1; |
| 328 | u16 poll_stats : 1; |
| 329 | u16 bus_index; |
| 330 | u8 numa_node; |
| 331 | u16 max_rx_queues; |
| 332 | u16 max_tx_queues; |
| 333 | vnet_dev_driver_index_t driver_index; |
| 334 | u32 index; |
| 335 | u32 process_node_index; |
| 336 | u8 bus_data[32] __clib_aligned (16); |
| 337 | vnet_dev_ops_t ops; |
| 338 | vnet_dev_port_t **ports; |
| 339 | vnet_dev_periodic_op_t *periodic_ops; |
| 340 | u8 *description; |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 341 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 342 | u8 __clib_aligned (16) |
| 343 | data[]; |
| 344 | } vnet_dev_t; |
| 345 | |
| 346 | typedef struct |
| 347 | { |
| 348 | u16 vendor_id, device_id; |
| 349 | char *description; |
| 350 | } vnet_dev_match_t; |
| 351 | |
| 352 | #define VNET_DEV_MATCH(...) \ |
| 353 | (vnet_dev_match_t[]) \ |
| 354 | { \ |
| 355 | __VA_ARGS__, {} \ |
| 356 | } |
| 357 | |
| 358 | typedef struct |
| 359 | { |
| 360 | vnet_dev_op_t *device_open; |
| 361 | vnet_dev_op_no_rv_t *device_close; |
| 362 | vnet_dev_rv_t (*dma_mem_alloc_fn) (vlib_main_t *, vnet_dev_t *, u32, u32, |
| 363 | void **); |
| 364 | void (*dma_mem_free_fn) (vlib_main_t *, vnet_dev_t *, void *); |
| 365 | void *(*get_device_info) (vlib_main_t *, char *); |
| 366 | void (*free_device_info) (vlib_main_t *, void *); |
| 367 | format_function_t *format_device_info; |
| 368 | format_function_t *format_device_addr; |
| 369 | } vnet_dev_bus_ops_t; |
| 370 | |
| 371 | struct vnet_dev_bus_registration |
| 372 | { |
| 373 | vnet_dev_bus_registration_t *next_registration; |
| 374 | vnet_dev_driver_name_t name; |
| 375 | u16 device_data_size; |
| 376 | vnet_dev_bus_ops_t ops; |
| 377 | }; |
| 378 | |
| 379 | struct vnet_dev_driver_registration |
| 380 | { |
| 381 | vnet_dev_driver_registration_t *next_registration; |
| 382 | u8 bus_master_enable : 1; |
| 383 | vnet_dev_driver_name_t name; |
| 384 | vnet_dev_bus_name_t bus; |
| 385 | u16 device_data_sz; |
| 386 | u16 runtime_temp_space_sz; |
| 387 | vnet_dev_match_t *match; |
| 388 | int priority; |
| 389 | vnet_dev_ops_t ops; |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 390 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | typedef struct |
| 394 | { |
| 395 | u32 index; |
| 396 | vnet_dev_bus_registration_t *registration; |
| 397 | vnet_dev_bus_ops_t ops; |
| 398 | } vnet_dev_bus_t; |
| 399 | |
| 400 | typedef struct |
| 401 | { |
| 402 | u32 index; |
| 403 | void *dev_data; |
| 404 | vnet_dev_driver_registration_t *registration; |
| 405 | u32 dev_class_index; |
| 406 | vnet_dev_bus_index_t bus_index; |
| 407 | vnet_dev_ops_t ops; |
| 408 | } vnet_dev_driver_t; |
| 409 | |
| 410 | typedef struct |
| 411 | { |
| 412 | vnet_dev_bus_t *buses; |
| 413 | vnet_dev_driver_t *drivers; |
| 414 | vnet_dev_t **devices; |
| 415 | vnet_dev_port_t **ports_by_dev_instance; |
| 416 | vnet_dev_bus_registration_t *bus_registrations; |
| 417 | vnet_dev_driver_registration_t *driver_registrations; |
| 418 | void *runtime_temp_spaces; |
| 419 | u32 log2_runtime_temp_space_sz; |
| 420 | u32 *free_process_node_indices; |
| 421 | u32 *free_rx_node_indices; |
| 422 | uword *device_index_by_id; |
| 423 | |
| 424 | u8 *startup_config; |
| 425 | u16 next_rx_queue_thread; |
| 426 | u8 eth_port_rx_feature_arc_index; |
| 427 | } vnet_dev_main_t; |
| 428 | |
| 429 | extern vnet_dev_main_t vnet_dev_main; |
| 430 | |
| 431 | typedef struct |
| 432 | { |
| 433 | struct |
| 434 | { |
| 435 | vnet_dev_port_attr_t attr; |
| 436 | vnet_dev_port_ops_t ops; |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 437 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 438 | u16 data_size; |
| 439 | void *initial_data; |
| 440 | } port; |
| 441 | |
| 442 | vnet_dev_node_t *rx_node; |
| 443 | vnet_dev_node_t *tx_node; |
| 444 | |
| 445 | struct |
| 446 | { |
| 447 | vnet_dev_queue_config_t config; |
| 448 | vnet_dev_rx_queue_ops_t ops; |
| 449 | } rx_queue; |
| 450 | |
| 451 | struct |
| 452 | { |
| 453 | vnet_dev_queue_config_t config; |
| 454 | vnet_dev_tx_queue_ops_t ops; |
| 455 | } tx_queue; |
| 456 | } vnet_dev_port_add_args_t; |
| 457 | |
| 458 | typedef struct |
| 459 | { |
| 460 | union |
| 461 | { |
| 462 | struct |
| 463 | { |
| 464 | u8 link_speed : 1; |
| 465 | u8 link_state : 1; |
| 466 | u8 link_duplex : 1; |
| 467 | }; |
| 468 | u8 any; |
| 469 | } change; |
| 470 | u8 link_state : 1; |
| 471 | u8 full_duplex : 1; |
| 472 | u32 link_speed; |
| 473 | } vnet_dev_port_state_changes_t; |
| 474 | |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 475 | /* args.c */ |
| 476 | vnet_dev_rv_t vnet_dev_arg_parse (vlib_main_t *, vnet_dev_t *, |
| 477 | vnet_dev_arg_t *, u8 *); |
| 478 | void vnet_dev_arg_free (vnet_dev_arg_t **); |
| 479 | void vnet_dev_arg_clear_value (vnet_dev_arg_t *); |
| 480 | format_function_t format_vnet_dev_arg_type; |
| 481 | format_function_t format_vnet_dev_arg_value; |
| 482 | format_function_t format_vnet_dev_args; |
| 483 | |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 484 | /* dev.c */ |
| 485 | vnet_dev_t *vnet_dev_alloc (vlib_main_t *, vnet_dev_device_id_t, |
| 486 | vnet_dev_driver_t *); |
| 487 | void vnet_dev_free (vlib_main_t *, vnet_dev_t *); |
| 488 | vnet_dev_rv_t vnet_dev_init (vlib_main_t *, vnet_dev_t *); |
| 489 | void vnet_dev_deinit (vlib_main_t *, vnet_dev_t *); |
| 490 | vnet_dev_rv_t vnet_dev_reset (vlib_main_t *, vnet_dev_t *); |
| 491 | void vnet_dev_detach (vlib_main_t *, vnet_dev_t *); |
| 492 | vnet_dev_rv_t vnet_dev_port_add (vlib_main_t *, vnet_dev_t *, |
| 493 | vnet_dev_port_id_t, |
| 494 | vnet_dev_port_add_args_t *); |
| 495 | vnet_dev_rv_t vnet_dev_dma_mem_alloc (vlib_main_t *, vnet_dev_t *, u32, u32, |
| 496 | void **); |
| 497 | void vnet_dev_dma_mem_free (vlib_main_t *, vnet_dev_t *, void *); |
| 498 | vnet_dev_bus_t *vnet_dev_find_device_bus (vlib_main_t *, vnet_dev_device_id_t); |
| 499 | void *vnet_dev_get_device_info (vlib_main_t *, vnet_dev_device_id_t); |
| 500 | |
| 501 | /* error.c */ |
| 502 | clib_error_t *vnet_dev_port_err (vlib_main_t *, vnet_dev_port_t *, |
| 503 | vnet_dev_rv_t, char *, ...); |
| 504 | |
| 505 | /* handlers.c */ |
| 506 | clib_error_t *vnet_dev_port_set_max_frame_size (vnet_main_t *, |
| 507 | vnet_hw_interface_t *, u32); |
| 508 | u32 vnet_dev_port_eth_flag_change (vnet_main_t *, vnet_hw_interface_t *, u32); |
| 509 | clib_error_t *vnet_dev_port_mac_change (vnet_hw_interface_t *, const u8 *, |
| 510 | const u8 *); |
| 511 | clib_error_t *vnet_dev_add_del_mac_address (vnet_hw_interface_t *, const u8 *, |
| 512 | u8); |
| 513 | int vnet_dev_flow_ops_fn (vnet_main_t *, vnet_flow_dev_op_t, u32, u32, |
| 514 | uword *); |
| 515 | clib_error_t *vnet_dev_interface_set_rss_queues (vnet_main_t *, |
| 516 | vnet_hw_interface_t *, |
| 517 | clib_bitmap_t *); |
| 518 | void vnet_dev_clear_hw_interface_counters (u32); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 519 | void vnet_dev_set_interface_next_node (vnet_main_t *, u32, u32); |
| 520 | |
| 521 | /* port.c */ |
| 522 | vnet_dev_rv_t vnet_dev_port_start (vlib_main_t *, vnet_dev_port_t *); |
| 523 | vnet_dev_rv_t vnet_dev_port_start_all_rx_queues (vlib_main_t *, |
| 524 | vnet_dev_port_t *); |
| 525 | vnet_dev_rv_t vnet_dev_port_start_all_tx_queues (vlib_main_t *, |
| 526 | vnet_dev_port_t *); |
| 527 | void vnet_dev_port_stop (vlib_main_t *, vnet_dev_port_t *); |
| 528 | void vnet_dev_port_deinit (vlib_main_t *, vnet_dev_port_t *); |
| 529 | void vnet_dev_port_free (vlib_main_t *, vnet_dev_port_t *); |
| 530 | void vnet_dev_port_add_counters (vlib_main_t *, vnet_dev_port_t *, |
| 531 | vnet_dev_counter_t *, u16); |
| 532 | void vnet_dev_port_free_counters (vlib_main_t *, vnet_dev_port_t *); |
| 533 | void vnet_dev_port_update_tx_node_runtime (vlib_main_t *, vnet_dev_port_t *); |
| 534 | void vnet_dev_port_state_change (vlib_main_t *, vnet_dev_port_t *, |
| 535 | vnet_dev_port_state_changes_t); |
| 536 | void vnet_dev_port_clear_counters (vlib_main_t *, vnet_dev_port_t *); |
| 537 | vnet_dev_rv_t |
| 538 | vnet_dev_port_cfg_change_req_validate (vlib_main_t *, vnet_dev_port_t *, |
| 539 | vnet_dev_port_cfg_change_req_t *); |
| 540 | vnet_dev_rv_t vnet_dev_port_cfg_change (vlib_main_t *, vnet_dev_port_t *, |
| 541 | vnet_dev_port_cfg_change_req_t *); |
| 542 | vnet_dev_rv_t vnet_dev_port_if_create (vlib_main_t *, vnet_dev_port_t *); |
| 543 | vnet_dev_rv_t vnet_dev_port_if_remove (vlib_main_t *, vnet_dev_port_t *); |
| 544 | |
| 545 | /* queue.c */ |
| 546 | vnet_dev_rv_t vnet_dev_rx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16); |
| 547 | vnet_dev_rv_t vnet_dev_tx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16); |
| 548 | void vnet_dev_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 549 | void vnet_dev_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 550 | void vnet_dev_rx_queue_add_counters (vlib_main_t *, vnet_dev_rx_queue_t *, |
| 551 | vnet_dev_counter_t *, u16); |
| 552 | void vnet_dev_rx_queue_free_counters (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 553 | void vnet_dev_tx_queue_add_counters (vlib_main_t *, vnet_dev_tx_queue_t *, |
| 554 | vnet_dev_counter_t *, u16); |
| 555 | void vnet_dev_tx_queue_free_counters (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 556 | vnet_dev_rv_t vnet_dev_rx_queue_start (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 557 | vnet_dev_rv_t vnet_dev_tx_queue_start (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 558 | void vnet_dev_rx_queue_stop (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 559 | void vnet_dev_tx_queue_stop (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 560 | |
| 561 | /* process.c */ |
| 562 | vnet_dev_rv_t vnet_dev_process_create (vlib_main_t *, vnet_dev_t *); |
| 563 | vnet_dev_rv_t vnet_dev_process_call_op (vlib_main_t *, vnet_dev_t *, |
| 564 | vnet_dev_op_t *); |
| 565 | vnet_dev_rv_t vnet_dev_process_call_op_no_rv (vlib_main_t *, vnet_dev_t *, |
| 566 | vnet_dev_op_no_rv_t *); |
| 567 | void vnet_dev_process_call_op_no_wait (vlib_main_t *, vnet_dev_t *, |
| 568 | vnet_dev_op_no_rv_t *); |
| 569 | vnet_dev_rv_t vnet_dev_process_call_port_op (vlib_main_t *, vnet_dev_port_t *, |
| 570 | vnet_dev_port_op_t *); |
| 571 | vnet_dev_rv_t vnet_dev_process_call_port_op_no_rv (vlib_main_t *vm, |
| 572 | vnet_dev_port_t *, |
| 573 | vnet_dev_port_op_no_rv_t *); |
| 574 | void vnet_dev_process_call_port_op_no_wait (vlib_main_t *, vnet_dev_port_t *, |
| 575 | vnet_dev_port_op_no_rv_t *); |
| 576 | vnet_dev_rv_t |
| 577 | vnet_dev_process_port_cfg_change_req (vlib_main_t *, vnet_dev_port_t *, |
| 578 | vnet_dev_port_cfg_change_req_t *); |
| 579 | void vnet_dev_process_quit (vlib_main_t *, vnet_dev_t *); |
| 580 | void vnet_dev_poll_dev_add (vlib_main_t *, vnet_dev_t *, f64, |
| 581 | vnet_dev_op_no_rv_t *); |
| 582 | void vnet_dev_poll_dev_remove (vlib_main_t *, vnet_dev_t *, |
| 583 | vnet_dev_op_no_rv_t *); |
| 584 | void vnet_dev_poll_port_add (vlib_main_t *, vnet_dev_port_t *, f64, |
| 585 | vnet_dev_port_op_no_rv_t *); |
| 586 | void vnet_dev_poll_port_remove (vlib_main_t *, vnet_dev_port_t *, |
| 587 | vnet_dev_port_op_no_rv_t *); |
| 588 | |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 589 | typedef struct |
| 590 | { |
| 591 | u16 thread_index; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 592 | u8 completed; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 593 | u8 in_order; |
| 594 | vnet_dev_port_t *port; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 595 | } vnet_dev_rt_op_t; |
| 596 | |
| 597 | vnet_dev_rv_t vnet_dev_rt_exec_ops (vlib_main_t *, vnet_dev_t *, |
| 598 | vnet_dev_rt_op_t *, u32); |
| 599 | |
| 600 | /* format.c */ |
| 601 | typedef struct |
| 602 | { |
| 603 | u8 counters : 1; |
| 604 | u8 show_zero_counters : 1; |
| 605 | u8 debug : 1; |
| 606 | } vnet_dev_format_args_t; |
| 607 | |
| 608 | format_function_t format_vnet_dev_addr; |
| 609 | format_function_t format_vnet_dev_hw_addr; |
| 610 | format_function_t format_vnet_dev_info; |
| 611 | format_function_t format_vnet_dev_interface_info; |
| 612 | format_function_t format_vnet_dev_interface_name; |
| 613 | format_function_t format_vnet_dev_port_info; |
| 614 | format_function_t format_vnet_dev_rv; |
| 615 | format_function_t format_vnet_dev_rx_queue_info; |
| 616 | format_function_t format_vnet_dev_tx_queue_info; |
| 617 | format_function_t format_vnet_dev_flags; |
| 618 | format_function_t format_vnet_dev_port_flags; |
Damjan Marion | 6bd6c80 | 2023-11-02 18:40:32 +0000 | [diff] [blame] | 619 | format_function_t format_vnet_dev_log; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 620 | unformat_function_t unformat_vnet_dev_flags; |
| 621 | unformat_function_t unformat_vnet_dev_port_flags; |
| 622 | |
| 623 | typedef struct |
| 624 | { |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 625 | vnet_dev_rx_queue_t *first_rx_queue; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 626 | } vnet_dev_rx_node_runtime_t; |
| 627 | |
| 628 | STATIC_ASSERT (sizeof (vnet_dev_rx_node_runtime_t) <= |
| 629 | VLIB_NODE_RUNTIME_DATA_SIZE, |
| 630 | "must fit into runtime data"); |
| 631 | |
| 632 | #define foreach_vnet_dev_port_rx_next \ |
| 633 | _ (ETH_INPUT, "ethernet-input") \ |
| 634 | _ (DROP, "error-drop") |
| 635 | |
| 636 | typedef enum |
| 637 | { |
| 638 | #define _(n, s) VNET_DEV_ETH_RX_PORT_NEXT_##n, |
| 639 | foreach_vnet_dev_port_rx_next |
| 640 | #undef _ |
| 641 | VNET_DEV_ETH_RX_PORT_N_NEXTS |
| 642 | } vnet_dev_eth_port_rx_next_t; |
| 643 | |
| 644 | extern u16 vnet_dev_default_next_index_by_port_type[]; |
| 645 | extern vlib_node_registration_t port_rx_eth_node; |
| 646 | |
| 647 | typedef vnet_interface_output_runtime_t vnet_dev_tx_node_runtime_t; |
| 648 | |
| 649 | STATIC_ASSERT (sizeof (vnet_dev_tx_node_runtime_t) <= |
| 650 | VLIB_NODE_RUNTIME_DATA_SIZE, |
| 651 | "must fit into runtime data"); |
| 652 | |
| 653 | #define VNET_DEV_REGISTER_BUS(x, ...) \ |
| 654 | __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x; \ |
| 655 | static void __clib_constructor __vnet_dev_bus_registration_fn_##x (void) \ |
| 656 | { \ |
| 657 | vnet_dev_main_t *dm = &vnet_dev_main; \ |
| 658 | __vnet_dev_bus_registration_##x.next_registration = \ |
| 659 | dm->bus_registrations; \ |
| 660 | dm->bus_registrations = &__vnet_dev_bus_registration_##x; \ |
| 661 | } \ |
| 662 | __VA_ARGS__ vnet_dev_bus_registration_t __vnet_dev_bus_registration_##x |
| 663 | |
| 664 | #define VNET_DEV_REGISTER_DRIVER(x, ...) \ |
| 665 | __VA_ARGS__ vnet_dev_driver_registration_t \ |
| 666 | __vnet_dev_driver_registration_##x; \ |
| 667 | static void __clib_constructor __vnet_dev_driver_registration_fn_##x (void) \ |
| 668 | { \ |
| 669 | vnet_dev_main_t *dm = &vnet_dev_main; \ |
| 670 | __vnet_dev_driver_registration_##x.next_registration = \ |
| 671 | dm->driver_registrations; \ |
| 672 | dm->driver_registrations = &__vnet_dev_driver_registration_##x; \ |
| 673 | } \ |
| 674 | __VA_ARGS__ vnet_dev_driver_registration_t __vnet_dev_driver_registration_##x |
| 675 | |
| 676 | #define VNET_DEV_NODE_FN(node) \ |
| 677 | uword CLIB_MARCH_SFX (node##_fn) (vlib_main_t *, vlib_node_runtime_t *, \ |
| 678 | vlib_frame_t *); \ |
| 679 | static vlib_node_fn_registration_t CLIB_MARCH_SFX ( \ |
| 680 | node##_fn_registration) = { \ |
| 681 | .function = &CLIB_MARCH_SFX (node##_fn), \ |
| 682 | }; \ |
| 683 | \ |
| 684 | static void __clib_constructor CLIB_MARCH_SFX ( \ |
| 685 | node##_fn_multiarch_register) (void) \ |
| 686 | { \ |
| 687 | extern vnet_dev_node_t node; \ |
| 688 | vlib_node_fn_registration_t *r; \ |
| 689 | r = &CLIB_MARCH_SFX (node##_fn_registration); \ |
| 690 | r->march_variant = CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE); \ |
| 691 | r->next_registration = (node).registrations; \ |
| 692 | (node).registrations = r; \ |
| 693 | } \ |
| 694 | uword CLIB_MARCH_SFX (node##_fn) |
| 695 | |
| 696 | #define foreach_vnet_dev_port(p, d) pool_foreach_pointer (p, d->ports) |
| 697 | #define foreach_vnet_dev_port_rx_queue(q, p) \ |
| 698 | pool_foreach_pointer (q, p->rx_queues) |
| 699 | #define foreach_vnet_dev_port_tx_queue(q, p) \ |
| 700 | pool_foreach_pointer (q, p->tx_queues) |
| 701 | |
| 702 | #include <vnet/dev/dev_funcs.h> |
| 703 | |
| 704 | #endif /* _VNET_DEV_H_ */ |