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) \ |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 31 | _ (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 Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 40 | |
| 41 | typedef 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 | |
| 52 | typedef union |
| 53 | { |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 54 | 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 | |
| 63 | typedef 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 | |
| 74 | typedef union |
| 75 | { |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 76 | u8 eth_mac[6]; |
| 77 | u8 raw[8]; |
| 78 | } vnet_dev_hw_addr_t; |
| 79 | |
| 80 | typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t; |
| 81 | typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t; |
| 82 | |
| 83 | typedef struct vnet_dev vnet_dev_t; |
| 84 | typedef struct vnet_dev_port vnet_dev_port_t; |
| 85 | typedef struct vnet_dev_rx_queue vnet_dev_rx_queue_t; |
| 86 | typedef struct vnet_dev_tx_queue vnet_dev_tx_queue_t; |
| 87 | typedef struct vnet_dev_bus_registration vnet_dev_bus_registration_t; |
| 88 | typedef struct vnet_dev_driver_registration vnet_dev_driver_registration_t; |
| 89 | typedef struct vnet_dev_counter vnet_dev_counter_t; |
| 90 | typedef struct vnet_dev_counter_main vnet_dev_counter_main_t; |
| 91 | typedef struct vnet_dev_port_cfg_change_req vnet_dev_port_cfg_change_req_t; |
| 92 | |
| 93 | typedef vnet_dev_rv_t (vnet_dev_op_t) (vlib_main_t *, vnet_dev_t *); |
| 94 | typedef vnet_dev_rv_t (vnet_dev_port_op_t) (vlib_main_t *, vnet_dev_port_t *); |
| 95 | typedef 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 *); |
| 97 | typedef vnet_dev_rv_t (vnet_dev_rx_queue_op_t) (vlib_main_t *, |
| 98 | vnet_dev_rx_queue_t *); |
| 99 | typedef vnet_dev_rv_t (vnet_dev_tx_queue_op_t) (vlib_main_t *, |
| 100 | vnet_dev_tx_queue_t *); |
| 101 | typedef void (vnet_dev_op_no_rv_t) (vlib_main_t *, vnet_dev_t *); |
| 102 | typedef void (vnet_dev_port_op_no_rv_t) (vlib_main_t *, vnet_dev_port_t *); |
| 103 | typedef void (vnet_dev_rx_queue_op_no_rv_t) (vlib_main_t *, |
| 104 | vnet_dev_rx_queue_t *); |
| 105 | typedef void (vnet_dev_tx_queue_op_no_rv_t) (vlib_main_t *, |
| 106 | vnet_dev_tx_queue_t *); |
| 107 | |
| 108 | typedef u16 vnet_dev_queue_id_t; |
| 109 | typedef u16 vnet_dev_bus_index_t; |
| 110 | typedef u16 vnet_dev_driver_index_t; |
| 111 | |
| 112 | typedef 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 Marion | 28b6dfa | 2023-12-21 15:54:14 +0100 | [diff] [blame] | 118 | format_function_t *format_info; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 119 | } vnet_dev_rx_queue_ops_t; |
| 120 | |
| 121 | typedef 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 Marion | 28b6dfa | 2023-12-21 15:54:14 +0100 | [diff] [blame] | 127 | format_function_t *format_info; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 128 | } vnet_dev_tx_queue_ops_t; |
| 129 | |
| 130 | typedef 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 Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 142 | _ (MAX_RX_FRAME_SIZE) \ |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 143 | _ (CHANGE_PRIMARY_HW_ADDR) \ |
| 144 | _ (ADD_SECONDARY_HW_ADDR) \ |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 145 | _ (REMOVE_SECONDARY_HW_ADDR) \ |
| 146 | _ (RXQ_INTR_MODE_ENABLE) \ |
| 147 | _ (RXQ_INTR_MODE_DISABLE) |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 148 | |
| 149 | typedef 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 | |
| 157 | typedef struct vnet_dev_port_cfg_change_req |
| 158 | { |
| 159 | vnet_dev_port_cfg_type_t type; |
| 160 | u8 validated : 1; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 161 | u8 all_queues : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 162 | |
| 163 | union |
| 164 | { |
| 165 | u8 promisc : 1; |
| 166 | vnet_dev_hw_addr_t addr; |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 167 | u16 max_rx_frame_size; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 168 | vnet_dev_queue_id_t queue_id; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | } vnet_dev_port_cfg_change_req_t; |
| 172 | |
| 173 | typedef struct |
| 174 | { |
| 175 | vnet_dev_hw_addr_t hw_addr; |
| 176 | u16 max_rx_queues; |
| 177 | u16 max_tx_queues; |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 178 | u16 max_supported_rx_frame_size; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 179 | vnet_dev_port_type_t type; |
| 180 | vnet_dev_port_caps_t caps; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 181 | vnet_dev_port_rx_offloads_t rx_offloads; |
| 182 | vnet_dev_port_tx_offloads_t tx_offloads; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 183 | } vnet_dev_port_attr_t; |
| 184 | |
| 185 | typedef 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 | |
| 191 | typedef 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 | |
| 210 | typedef 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 | |
| 218 | typedef 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 | |
| 229 | typedef 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 | |
| 242 | typedef 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 | |
| 254 | typedef 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 262 | vnet_dev_rx_queue_t *next_on_thread; |
| 263 | u8 interrupt_mode : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 264 | 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 273 | CLIB_CACHE_LINE_ALIGN_MARK (driver_data); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 274 | u8 data[]; |
| 275 | } vnet_dev_rx_queue_t; |
| 276 | |
| 277 | STATIC_ASSERT_SIZEOF (vnet_dev_rx_queue_t, 3 * CLIB_CACHE_LINE_BYTES); |
| 278 | |
| 279 | typedef 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 | |
| 297 | STATIC_ASSERT_SIZEOF (vnet_dev_tx_queue_t, 2 * CLIB_CACHE_LINE_BYTES); |
| 298 | |
| 299 | typedef 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 Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 315 | u32 max_rx_frame_size; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 316 | 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 323 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 324 | 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 340 | u8 default_is_intr_mode : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 341 | 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 | |
| 354 | typedef 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 375 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 376 | u8 __clib_aligned (16) |
| 377 | data[]; |
| 378 | } vnet_dev_t; |
| 379 | |
| 380 | typedef 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 | |
| 392 | typedef 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 | |
| 405 | struct 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 | |
| 413 | struct 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 424 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 425 | }; |
| 426 | |
| 427 | typedef 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 | |
| 434 | typedef 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 | |
| 444 | typedef 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 | |
| 463 | extern vnet_dev_main_t vnet_dev_main; |
| 464 | |
| 465 | typedef struct |
| 466 | { |
| 467 | struct |
| 468 | { |
| 469 | vnet_dev_port_attr_t attr; |
| 470 | vnet_dev_port_ops_t ops; |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 471 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 472 | 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 | |
| 492 | typedef 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 509 | /* args.c */ |
| 510 | vnet_dev_rv_t vnet_dev_arg_parse (vlib_main_t *, vnet_dev_t *, |
| 511 | vnet_dev_arg_t *, u8 *); |
| 512 | void vnet_dev_arg_free (vnet_dev_arg_t **); |
| 513 | void vnet_dev_arg_clear_value (vnet_dev_arg_t *); |
| 514 | format_function_t format_vnet_dev_arg_type; |
| 515 | format_function_t format_vnet_dev_arg_value; |
| 516 | format_function_t format_vnet_dev_args; |
| 517 | |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 518 | /* dev.c */ |
| 519 | vnet_dev_t *vnet_dev_alloc (vlib_main_t *, vnet_dev_device_id_t, |
| 520 | vnet_dev_driver_t *); |
| 521 | void vnet_dev_free (vlib_main_t *, vnet_dev_t *); |
| 522 | vnet_dev_rv_t vnet_dev_init (vlib_main_t *, vnet_dev_t *); |
| 523 | void vnet_dev_deinit (vlib_main_t *, vnet_dev_t *); |
| 524 | vnet_dev_rv_t vnet_dev_reset (vlib_main_t *, vnet_dev_t *); |
| 525 | void vnet_dev_detach (vlib_main_t *, vnet_dev_t *); |
| 526 | vnet_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 *); |
| 529 | vnet_dev_rv_t vnet_dev_dma_mem_alloc (vlib_main_t *, vnet_dev_t *, u32, u32, |
| 530 | void **); |
| 531 | void vnet_dev_dma_mem_free (vlib_main_t *, vnet_dev_t *, void *); |
| 532 | vnet_dev_bus_t *vnet_dev_find_device_bus (vlib_main_t *, vnet_dev_device_id_t); |
| 533 | void *vnet_dev_get_device_info (vlib_main_t *, vnet_dev_device_id_t); |
| 534 | |
| 535 | /* error.c */ |
| 536 | clib_error_t *vnet_dev_port_err (vlib_main_t *, vnet_dev_port_t *, |
| 537 | vnet_dev_rv_t, char *, ...); |
| 538 | |
| 539 | /* handlers.c */ |
| 540 | clib_error_t *vnet_dev_port_set_max_frame_size (vnet_main_t *, |
| 541 | vnet_hw_interface_t *, u32); |
| 542 | u32 vnet_dev_port_eth_flag_change (vnet_main_t *, vnet_hw_interface_t *, u32); |
| 543 | clib_error_t *vnet_dev_port_mac_change (vnet_hw_interface_t *, const u8 *, |
| 544 | const u8 *); |
| 545 | clib_error_t *vnet_dev_add_del_mac_address (vnet_hw_interface_t *, const u8 *, |
| 546 | u8); |
| 547 | int vnet_dev_flow_ops_fn (vnet_main_t *, vnet_flow_dev_op_t, u32, u32, |
| 548 | uword *); |
| 549 | clib_error_t *vnet_dev_interface_set_rss_queues (vnet_main_t *, |
| 550 | vnet_hw_interface_t *, |
| 551 | clib_bitmap_t *); |
| 552 | void vnet_dev_clear_hw_interface_counters (u32); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 553 | void vnet_dev_set_interface_next_node (vnet_main_t *, u32, u32); |
| 554 | |
| 555 | /* port.c */ |
| 556 | vnet_dev_rv_t vnet_dev_port_start (vlib_main_t *, vnet_dev_port_t *); |
| 557 | vnet_dev_rv_t vnet_dev_port_start_all_rx_queues (vlib_main_t *, |
| 558 | vnet_dev_port_t *); |
| 559 | vnet_dev_rv_t vnet_dev_port_start_all_tx_queues (vlib_main_t *, |
| 560 | vnet_dev_port_t *); |
| 561 | void vnet_dev_port_stop (vlib_main_t *, vnet_dev_port_t *); |
| 562 | void vnet_dev_port_deinit (vlib_main_t *, vnet_dev_port_t *); |
| 563 | void vnet_dev_port_free (vlib_main_t *, vnet_dev_port_t *); |
| 564 | void vnet_dev_port_add_counters (vlib_main_t *, vnet_dev_port_t *, |
| 565 | vnet_dev_counter_t *, u16); |
| 566 | void vnet_dev_port_free_counters (vlib_main_t *, vnet_dev_port_t *); |
| 567 | void vnet_dev_port_update_tx_node_runtime (vlib_main_t *, vnet_dev_port_t *); |
| 568 | void vnet_dev_port_state_change (vlib_main_t *, vnet_dev_port_t *, |
| 569 | vnet_dev_port_state_changes_t); |
| 570 | void vnet_dev_port_clear_counters (vlib_main_t *, vnet_dev_port_t *); |
| 571 | vnet_dev_rv_t |
| 572 | vnet_dev_port_cfg_change_req_validate (vlib_main_t *, vnet_dev_port_t *, |
| 573 | vnet_dev_port_cfg_change_req_t *); |
| 574 | vnet_dev_rv_t vnet_dev_port_cfg_change (vlib_main_t *, vnet_dev_port_t *, |
| 575 | vnet_dev_port_cfg_change_req_t *); |
| 576 | vnet_dev_rv_t vnet_dev_port_if_create (vlib_main_t *, vnet_dev_port_t *); |
| 577 | vnet_dev_rv_t vnet_dev_port_if_remove (vlib_main_t *, vnet_dev_port_t *); |
| 578 | |
| 579 | /* queue.c */ |
| 580 | vnet_dev_rv_t vnet_dev_rx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16); |
| 581 | vnet_dev_rv_t vnet_dev_tx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16); |
| 582 | void vnet_dev_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 583 | void vnet_dev_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 584 | void vnet_dev_rx_queue_add_counters (vlib_main_t *, vnet_dev_rx_queue_t *, |
| 585 | vnet_dev_counter_t *, u16); |
| 586 | void vnet_dev_rx_queue_free_counters (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 587 | void vnet_dev_tx_queue_add_counters (vlib_main_t *, vnet_dev_tx_queue_t *, |
| 588 | vnet_dev_counter_t *, u16); |
| 589 | void vnet_dev_tx_queue_free_counters (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 590 | vnet_dev_rv_t vnet_dev_rx_queue_start (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 591 | vnet_dev_rv_t vnet_dev_tx_queue_start (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 592 | void vnet_dev_rx_queue_stop (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 593 | void vnet_dev_tx_queue_stop (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 594 | |
| 595 | /* process.c */ |
| 596 | vnet_dev_rv_t vnet_dev_process_create (vlib_main_t *, vnet_dev_t *); |
| 597 | vnet_dev_rv_t vnet_dev_process_call_op (vlib_main_t *, vnet_dev_t *, |
| 598 | vnet_dev_op_t *); |
| 599 | vnet_dev_rv_t vnet_dev_process_call_op_no_rv (vlib_main_t *, vnet_dev_t *, |
| 600 | vnet_dev_op_no_rv_t *); |
| 601 | void vnet_dev_process_call_op_no_wait (vlib_main_t *, vnet_dev_t *, |
| 602 | vnet_dev_op_no_rv_t *); |
| 603 | vnet_dev_rv_t vnet_dev_process_call_port_op (vlib_main_t *, vnet_dev_port_t *, |
| 604 | vnet_dev_port_op_t *); |
| 605 | vnet_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 *); |
| 608 | void vnet_dev_process_call_port_op_no_wait (vlib_main_t *, vnet_dev_port_t *, |
| 609 | vnet_dev_port_op_no_rv_t *); |
| 610 | vnet_dev_rv_t |
| 611 | vnet_dev_process_port_cfg_change_req (vlib_main_t *, vnet_dev_port_t *, |
| 612 | vnet_dev_port_cfg_change_req_t *); |
| 613 | void vnet_dev_process_quit (vlib_main_t *, vnet_dev_t *); |
| 614 | void vnet_dev_poll_dev_add (vlib_main_t *, vnet_dev_t *, f64, |
| 615 | vnet_dev_op_no_rv_t *); |
| 616 | void vnet_dev_poll_dev_remove (vlib_main_t *, vnet_dev_t *, |
| 617 | vnet_dev_op_no_rv_t *); |
| 618 | void vnet_dev_poll_port_add (vlib_main_t *, vnet_dev_port_t *, f64, |
| 619 | vnet_dev_port_op_no_rv_t *); |
| 620 | void vnet_dev_poll_port_remove (vlib_main_t *, vnet_dev_port_t *, |
| 621 | vnet_dev_port_op_no_rv_t *); |
| 622 | |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 623 | typedef struct |
| 624 | { |
| 625 | u16 thread_index; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 626 | u8 completed; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 627 | u8 in_order; |
| 628 | vnet_dev_port_t *port; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 629 | } vnet_dev_rt_op_t; |
| 630 | |
| 631 | vnet_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 */ |
| 635 | typedef struct |
| 636 | { |
| 637 | u8 counters : 1; |
| 638 | u8 show_zero_counters : 1; |
| 639 | u8 debug : 1; |
| 640 | } vnet_dev_format_args_t; |
| 641 | |
| 642 | format_function_t format_vnet_dev_addr; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 643 | format_function_t format_vnet_dev_flags; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 644 | format_function_t format_vnet_dev_hw_addr; |
| 645 | format_function_t format_vnet_dev_info; |
| 646 | format_function_t format_vnet_dev_interface_info; |
| 647 | format_function_t format_vnet_dev_interface_name; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 648 | format_function_t format_vnet_dev_log; |
| 649 | format_function_t format_vnet_dev_port_caps; |
| 650 | format_function_t format_vnet_dev_port_flags; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 651 | format_function_t format_vnet_dev_port_info; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 652 | format_function_t format_vnet_dev_port_rx_offloads; |
| 653 | format_function_t format_vnet_dev_port_tx_offloads; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 654 | format_function_t format_vnet_dev_rv; |
| 655 | format_function_t format_vnet_dev_rx_queue_info; |
| 656 | format_function_t format_vnet_dev_tx_queue_info; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 657 | unformat_function_t unformat_vnet_dev_flags; |
| 658 | unformat_function_t unformat_vnet_dev_port_flags; |
| 659 | |
| 660 | typedef struct |
| 661 | { |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 662 | vnet_dev_rx_queue_t *first_rx_queue; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 663 | } vnet_dev_rx_node_runtime_t; |
| 664 | |
| 665 | STATIC_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 | |
| 673 | typedef 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 | |
| 681 | extern u16 vnet_dev_default_next_index_by_port_type[]; |
| 682 | extern vlib_node_registration_t port_rx_eth_node; |
| 683 | |
| 684 | typedef vnet_interface_output_runtime_t vnet_dev_tx_node_runtime_t; |
| 685 | |
| 686 | STATIC_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_ */ |