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) \ |
Monendra Singh Kushwaha | 4af3fdf | 2024-02-06 14:02:43 +0530 | [diff] [blame] | 147 | _ (RXQ_INTR_MODE_DISABLE) \ |
| 148 | _ (ADD_RX_FLOW) \ |
| 149 | _ (DEL_RX_FLOW) \ |
| 150 | _ (GET_RX_FLOW_COUNTER) \ |
| 151 | _ (RESET_RX_FLOW_COUNTER) |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 152 | |
| 153 | typedef 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 | |
| 161 | typedef struct vnet_dev_port_cfg_change_req |
| 162 | { |
| 163 | vnet_dev_port_cfg_type_t type; |
| 164 | u8 validated : 1; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 165 | u8 all_queues : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 166 | |
| 167 | union |
| 168 | { |
| 169 | u8 promisc : 1; |
| 170 | vnet_dev_hw_addr_t addr; |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 171 | u16 max_rx_frame_size; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 172 | vnet_dev_queue_id_t queue_id; |
Monendra Singh Kushwaha | 4af3fdf | 2024-02-06 14:02:43 +0530 | [diff] [blame] | 173 | struct |
| 174 | { |
| 175 | u32 flow_index; |
| 176 | uword *private_data; |
| 177 | }; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | } vnet_dev_port_cfg_change_req_t; |
| 181 | |
| 182 | typedef struct |
| 183 | { |
| 184 | vnet_dev_hw_addr_t hw_addr; |
| 185 | u16 max_rx_queues; |
| 186 | u16 max_tx_queues; |
Damjan Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 187 | u16 max_supported_rx_frame_size; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 188 | vnet_dev_port_type_t type; |
| 189 | vnet_dev_port_caps_t caps; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 190 | vnet_dev_port_rx_offloads_t rx_offloads; |
| 191 | vnet_dev_port_tx_offloads_t tx_offloads; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 192 | } vnet_dev_port_attr_t; |
| 193 | |
| 194 | typedef 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 | |
| 200 | typedef 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 | |
| 219 | typedef 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 | |
| 227 | typedef 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 | |
| 238 | typedef 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 Kushwaha | 4af3fdf | 2024-02-06 14:02:43 +0530 | [diff] [blame] | 249 | format_function_t *format_flow; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 250 | } vnet_dev_port_ops_t; |
| 251 | |
| 252 | typedef 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 | |
| 264 | typedef 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 272 | vnet_dev_rx_queue_t *next_on_thread; |
| 273 | u8 interrupt_mode : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 274 | 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 283 | CLIB_CACHE_LINE_ALIGN_MARK (driver_data); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 284 | u8 data[]; |
| 285 | } vnet_dev_rx_queue_t; |
| 286 | |
| 287 | STATIC_ASSERT_SIZEOF (vnet_dev_rx_queue_t, 3 * CLIB_CACHE_LINE_BYTES); |
| 288 | |
| 289 | typedef 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 | |
| 307 | STATIC_ASSERT_SIZEOF (vnet_dev_tx_queue_t, 2 * CLIB_CACHE_LINE_BYTES); |
| 308 | |
| 309 | typedef 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 Marion | e596ca1 | 2023-11-08 19:12:27 +0000 | [diff] [blame] | 325 | u32 max_rx_frame_size; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 326 | 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 333 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 334 | 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 Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 350 | u8 default_is_intr_mode : 1; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 351 | 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 | |
| 364 | typedef 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 385 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 386 | u8 __clib_aligned (16) |
| 387 | data[]; |
| 388 | } vnet_dev_t; |
| 389 | |
| 390 | typedef 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 | |
| 402 | typedef 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 | |
| 415 | struct 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 | |
| 423 | struct 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 434 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
| 437 | typedef 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 | |
| 444 | typedef 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 | |
| 454 | typedef 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 | |
| 473 | extern vnet_dev_main_t vnet_dev_main; |
| 474 | |
| 475 | typedef struct |
| 476 | { |
| 477 | struct |
| 478 | { |
| 479 | vnet_dev_port_attr_t attr; |
| 480 | vnet_dev_port_ops_t ops; |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 481 | vnet_dev_arg_t *args; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 482 | 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 | |
| 502 | typedef 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 Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 519 | /* args.c */ |
| 520 | vnet_dev_rv_t vnet_dev_arg_parse (vlib_main_t *, vnet_dev_t *, |
| 521 | vnet_dev_arg_t *, u8 *); |
| 522 | void vnet_dev_arg_free (vnet_dev_arg_t **); |
| 523 | void vnet_dev_arg_clear_value (vnet_dev_arg_t *); |
| 524 | format_function_t format_vnet_dev_arg_type; |
| 525 | format_function_t format_vnet_dev_arg_value; |
| 526 | format_function_t format_vnet_dev_args; |
| 527 | |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 528 | /* dev.c */ |
| 529 | vnet_dev_t *vnet_dev_alloc (vlib_main_t *, vnet_dev_device_id_t, |
| 530 | vnet_dev_driver_t *); |
| 531 | void vnet_dev_free (vlib_main_t *, vnet_dev_t *); |
| 532 | vnet_dev_rv_t vnet_dev_init (vlib_main_t *, vnet_dev_t *); |
| 533 | void vnet_dev_deinit (vlib_main_t *, vnet_dev_t *); |
| 534 | vnet_dev_rv_t vnet_dev_reset (vlib_main_t *, vnet_dev_t *); |
| 535 | void vnet_dev_detach (vlib_main_t *, vnet_dev_t *); |
| 536 | vnet_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 *); |
| 539 | vnet_dev_rv_t vnet_dev_dma_mem_alloc (vlib_main_t *, vnet_dev_t *, u32, u32, |
| 540 | void **); |
| 541 | void vnet_dev_dma_mem_free (vlib_main_t *, vnet_dev_t *, void *); |
| 542 | vnet_dev_bus_t *vnet_dev_find_device_bus (vlib_main_t *, vnet_dev_device_id_t); |
| 543 | void *vnet_dev_get_device_info (vlib_main_t *, vnet_dev_device_id_t); |
| 544 | |
| 545 | /* error.c */ |
| 546 | clib_error_t *vnet_dev_port_err (vlib_main_t *, vnet_dev_port_t *, |
| 547 | vnet_dev_rv_t, char *, ...); |
Monendra Singh Kushwaha | 4af3fdf | 2024-02-06 14:02:43 +0530 | [diff] [blame] | 548 | int vnet_dev_flow_err (vlib_main_t *, vnet_dev_rv_t); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 549 | |
| 550 | /* handlers.c */ |
| 551 | clib_error_t *vnet_dev_port_set_max_frame_size (vnet_main_t *, |
| 552 | vnet_hw_interface_t *, u32); |
| 553 | u32 vnet_dev_port_eth_flag_change (vnet_main_t *, vnet_hw_interface_t *, u32); |
| 554 | clib_error_t *vnet_dev_port_mac_change (vnet_hw_interface_t *, const u8 *, |
| 555 | const u8 *); |
| 556 | clib_error_t *vnet_dev_add_del_mac_address (vnet_hw_interface_t *, const u8 *, |
| 557 | u8); |
| 558 | int vnet_dev_flow_ops_fn (vnet_main_t *, vnet_flow_dev_op_t, u32, u32, |
| 559 | uword *); |
| 560 | clib_error_t *vnet_dev_interface_set_rss_queues (vnet_main_t *, |
| 561 | vnet_hw_interface_t *, |
| 562 | clib_bitmap_t *); |
| 563 | void vnet_dev_clear_hw_interface_counters (u32); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 564 | void vnet_dev_set_interface_next_node (vnet_main_t *, u32, u32); |
| 565 | |
| 566 | /* port.c */ |
| 567 | vnet_dev_rv_t vnet_dev_port_start (vlib_main_t *, vnet_dev_port_t *); |
| 568 | vnet_dev_rv_t vnet_dev_port_start_all_rx_queues (vlib_main_t *, |
| 569 | vnet_dev_port_t *); |
| 570 | vnet_dev_rv_t vnet_dev_port_start_all_tx_queues (vlib_main_t *, |
| 571 | vnet_dev_port_t *); |
| 572 | void vnet_dev_port_stop (vlib_main_t *, vnet_dev_port_t *); |
| 573 | void vnet_dev_port_deinit (vlib_main_t *, vnet_dev_port_t *); |
| 574 | void vnet_dev_port_free (vlib_main_t *, vnet_dev_port_t *); |
| 575 | void vnet_dev_port_add_counters (vlib_main_t *, vnet_dev_port_t *, |
| 576 | vnet_dev_counter_t *, u16); |
| 577 | void vnet_dev_port_free_counters (vlib_main_t *, vnet_dev_port_t *); |
| 578 | void vnet_dev_port_update_tx_node_runtime (vlib_main_t *, vnet_dev_port_t *); |
| 579 | void vnet_dev_port_state_change (vlib_main_t *, vnet_dev_port_t *, |
| 580 | vnet_dev_port_state_changes_t); |
| 581 | void vnet_dev_port_clear_counters (vlib_main_t *, vnet_dev_port_t *); |
| 582 | vnet_dev_rv_t |
| 583 | vnet_dev_port_cfg_change_req_validate (vlib_main_t *, vnet_dev_port_t *, |
| 584 | vnet_dev_port_cfg_change_req_t *); |
| 585 | vnet_dev_rv_t vnet_dev_port_cfg_change (vlib_main_t *, vnet_dev_port_t *, |
| 586 | vnet_dev_port_cfg_change_req_t *); |
| 587 | vnet_dev_rv_t vnet_dev_port_if_create (vlib_main_t *, vnet_dev_port_t *); |
| 588 | vnet_dev_rv_t vnet_dev_port_if_remove (vlib_main_t *, vnet_dev_port_t *); |
| 589 | |
| 590 | /* queue.c */ |
| 591 | vnet_dev_rv_t vnet_dev_rx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16); |
| 592 | vnet_dev_rv_t vnet_dev_tx_queue_alloc (vlib_main_t *, vnet_dev_port_t *, u16); |
| 593 | void vnet_dev_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 594 | void vnet_dev_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 595 | void vnet_dev_rx_queue_add_counters (vlib_main_t *, vnet_dev_rx_queue_t *, |
| 596 | vnet_dev_counter_t *, u16); |
| 597 | void vnet_dev_rx_queue_free_counters (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 598 | void vnet_dev_tx_queue_add_counters (vlib_main_t *, vnet_dev_tx_queue_t *, |
| 599 | vnet_dev_counter_t *, u16); |
| 600 | void vnet_dev_tx_queue_free_counters (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 601 | vnet_dev_rv_t vnet_dev_rx_queue_start (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 602 | vnet_dev_rv_t vnet_dev_tx_queue_start (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 603 | void vnet_dev_rx_queue_stop (vlib_main_t *, vnet_dev_rx_queue_t *); |
| 604 | void vnet_dev_tx_queue_stop (vlib_main_t *, vnet_dev_tx_queue_t *); |
| 605 | |
| 606 | /* process.c */ |
| 607 | vnet_dev_rv_t vnet_dev_process_create (vlib_main_t *, vnet_dev_t *); |
| 608 | vnet_dev_rv_t vnet_dev_process_call_op (vlib_main_t *, vnet_dev_t *, |
| 609 | vnet_dev_op_t *); |
| 610 | vnet_dev_rv_t vnet_dev_process_call_op_no_rv (vlib_main_t *, vnet_dev_t *, |
| 611 | vnet_dev_op_no_rv_t *); |
| 612 | void vnet_dev_process_call_op_no_wait (vlib_main_t *, vnet_dev_t *, |
| 613 | vnet_dev_op_no_rv_t *); |
| 614 | vnet_dev_rv_t vnet_dev_process_call_port_op (vlib_main_t *, vnet_dev_port_t *, |
| 615 | vnet_dev_port_op_t *); |
| 616 | vnet_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 *); |
| 619 | void vnet_dev_process_call_port_op_no_wait (vlib_main_t *, vnet_dev_port_t *, |
| 620 | vnet_dev_port_op_no_rv_t *); |
| 621 | vnet_dev_rv_t |
| 622 | vnet_dev_process_port_cfg_change_req (vlib_main_t *, vnet_dev_port_t *, |
| 623 | vnet_dev_port_cfg_change_req_t *); |
| 624 | void vnet_dev_process_quit (vlib_main_t *, vnet_dev_t *); |
| 625 | void vnet_dev_poll_dev_add (vlib_main_t *, vnet_dev_t *, f64, |
| 626 | vnet_dev_op_no_rv_t *); |
| 627 | void vnet_dev_poll_dev_remove (vlib_main_t *, vnet_dev_t *, |
| 628 | vnet_dev_op_no_rv_t *); |
| 629 | void vnet_dev_poll_port_add (vlib_main_t *, vnet_dev_port_t *, f64, |
| 630 | vnet_dev_port_op_no_rv_t *); |
| 631 | void vnet_dev_poll_port_remove (vlib_main_t *, vnet_dev_port_t *, |
| 632 | vnet_dev_port_op_no_rv_t *); |
| 633 | |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 634 | typedef struct |
| 635 | { |
| 636 | u16 thread_index; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 637 | u8 completed; |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 638 | u8 in_order; |
| 639 | vnet_dev_port_t *port; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 640 | } vnet_dev_rt_op_t; |
| 641 | |
| 642 | vnet_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 */ |
| 646 | typedef struct |
| 647 | { |
| 648 | u8 counters : 1; |
| 649 | u8 show_zero_counters : 1; |
| 650 | u8 debug : 1; |
| 651 | } vnet_dev_format_args_t; |
| 652 | |
| 653 | format_function_t format_vnet_dev_addr; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 654 | format_function_t format_vnet_dev_flags; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 655 | format_function_t format_vnet_dev_hw_addr; |
| 656 | format_function_t format_vnet_dev_info; |
| 657 | format_function_t format_vnet_dev_interface_info; |
| 658 | format_function_t format_vnet_dev_interface_name; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 659 | format_function_t format_vnet_dev_log; |
| 660 | format_function_t format_vnet_dev_port_caps; |
| 661 | format_function_t format_vnet_dev_port_flags; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 662 | format_function_t format_vnet_dev_port_info; |
Damjan Marion | d1eb1b7 | 2023-12-07 16:40:02 +0100 | [diff] [blame] | 663 | format_function_t format_vnet_dev_port_rx_offloads; |
| 664 | format_function_t format_vnet_dev_port_tx_offloads; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 665 | format_function_t format_vnet_dev_rv; |
| 666 | format_function_t format_vnet_dev_rx_queue_info; |
| 667 | format_function_t format_vnet_dev_tx_queue_info; |
Monendra Singh Kushwaha | 4af3fdf | 2024-02-06 14:02:43 +0530 | [diff] [blame] | 668 | format_function_t format_vnet_dev_flow; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 669 | unformat_function_t unformat_vnet_dev_flags; |
| 670 | unformat_function_t unformat_vnet_dev_port_flags; |
| 671 | |
| 672 | typedef struct |
| 673 | { |
Damjan Marion | b8dd981 | 2023-11-03 13:47:05 +0000 | [diff] [blame] | 674 | vnet_dev_rx_queue_t *first_rx_queue; |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 675 | } vnet_dev_rx_node_runtime_t; |
| 676 | |
| 677 | STATIC_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 | |
| 685 | typedef 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 | |
| 693 | extern u16 vnet_dev_default_next_index_by_port_type[]; |
| 694 | extern vlib_node_registration_t port_rx_eth_node; |
| 695 | |
| 696 | typedef vnet_interface_output_runtime_t vnet_dev_tx_node_runtime_t; |
| 697 | |
| 698 | STATIC_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_ */ |