1 /* SPDX-License-Identifier: (BSD-3-Clause OR LGPL-2.1) 2 * Copyright(c) 2010-2013 Intel Corporation. 3 * Copyright(c) 2014-2017 Wind River Systems, Inc. 4 */ 5 6 #ifndef _RTE_AVP_COMMON_H_ 7 #define _RTE_AVP_COMMON_H_ 8 9 #ifdef __KERNEL__ 10 #include <linux/if.h> 11 #else 12 #include <stdint.h> 13 #include <rte_common.h> 14 #include <rte_config.h> 15 #include <rte_memory.h> 16 #include <rte_ether.h> 17 #include <rte_atomic.h> 18 #endif 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** 25 * AVP name is part of network device name. 26 */ 27 #define RTE_AVP_NAMESIZE 32 28 29 /** 30 * AVP alias is a user-defined value used for lookups from secondary 31 * processes. Typically, this is a UUID. 32 */ 33 #define RTE_AVP_ALIASSIZE 128 34 35 /* 36 * Request id. 37 */ 38 enum rte_avp_req_id { 39 RTE_AVP_REQ_UNKNOWN = 0, 40 RTE_AVP_REQ_CHANGE_MTU, 41 RTE_AVP_REQ_CFG_NETWORK_IF, 42 RTE_AVP_REQ_CFG_DEVICE, 43 RTE_AVP_REQ_SHUTDOWN_DEVICE, 44 RTE_AVP_REQ_MAX, 45 }; 46 47 /**@{ AVP device driver types */ 48 #define RTE_AVP_DRIVER_TYPE_UNKNOWN 0 49 #define RTE_AVP_DRIVER_TYPE_DPDK 1 50 #define RTE_AVP_DRIVER_TYPE_KERNEL 2 51 #define RTE_AVP_DRIVER_TYPE_QEMU 3 52 /**@} */ 53 54 /**@{ AVP device operational modes */ 55 #define RTE_AVP_MODE_HOST 0 /**< AVP interface created in host */ 56 #define RTE_AVP_MODE_GUEST 1 /**< AVP interface created for export to guest */ 57 #define RTE_AVP_MODE_TRACE 2 /**< AVP interface created for packet tracing */ 58 /**@} */ 59 60 /* 61 * Structure for AVP queue configuration query request/result 62 */ 63 struct __rte_packed_begin rte_avp_device_config { 64 uint64_t device_id; /**< Unique system identifier */ 65 uint32_t driver_type; /**< Device Driver type */ 66 uint32_t driver_version; /**< Device Driver version */ 67 uint32_t features; /**< Negotiated features */ 68 uint16_t num_tx_queues; /**< Number of active transmit queues */ 69 uint16_t num_rx_queues; /**< Number of active receive queues */ 70 uint8_t if_up; /**< 1: interface up, 0: interface down */ 71 } __rte_packed_end; 72 73 /* 74 * Structure for AVP request. 75 */ 76 struct __rte_packed_begin rte_avp_request { 77 uint32_t req_id; /**< Request id */ 78 union { 79 uint32_t new_mtu; /**< New MTU */ 80 uint8_t if_up; /**< 1: interface up, 0: interface down */ 81 struct rte_avp_device_config config; /**< Queue configuration */ 82 }; 83 int32_t result; /**< Result for processing request */ 84 } __rte_packed_end; 85 86 /* 87 * FIFO struct mapped in a shared memory. It describes a circular buffer FIFO 88 * Write and read should wrap around. FIFO is empty when write == read 89 * Writing should never overwrite the read position 90 */ 91 struct rte_avp_fifo { 92 volatile unsigned int write; /**< Next position to be written*/ 93 volatile unsigned int read; /**< Next position to be read */ 94 unsigned int len; /**< Circular buffer length */ 95 unsigned int elem_size; /**< Pointer size - for 32/64 bit OS */ 96 void *volatile buffer[]; /**< The buffer contains mbuf pointers */ 97 }; 98 99 100 /* 101 * AVP packet buffer header used to define the exchange of packet data. 102 */ 103 struct __rte_cache_aligned __rte_packed_begin rte_avp_desc { 104 uint64_t pad0; 105 void *pkt_mbuf; /**< Reference to packet mbuf */ 106 uint8_t pad1[14]; 107 uint16_t ol_flags; /**< Offload features. */ 108 void *next; /**< Reference to next buffer in chain */ 109 void *data; /**< Start address of data in segment buffer. */ 110 uint16_t data_len; /**< Amount of data in segment buffer. */ 111 uint8_t nb_segs; /**< Number of segments */ 112 uint8_t pad2; 113 uint16_t pkt_len; /**< Total pkt len: sum of all segment data_len. */ 114 uint32_t pad3; 115 uint16_t vlan_tci; /**< VLAN Tag Control Identifier (CPU order). */ 116 uint32_t pad4; 117 } __rte_packed_end; 118 119 120 /**{ AVP device features */ 121 #define RTE_AVP_FEATURE_VLAN_OFFLOAD (1 << 0) /**< Emulated HW VLAN offload */ 122 /**@} */ 123 124 125 /**@{ Offload feature flags */ 126 #define RTE_AVP_TX_VLAN_PKT 0x0001 /**< TX packet is a 802.1q VLAN packet. */ 127 #define RTE_AVP_RX_VLAN_PKT 0x0800 /**< RX packet is a 802.1q VLAN packet. */ 128 /**@} */ 129 130 131 /**@{ AVP PCI identifiers */ 132 #define RTE_AVP_PCI_VENDOR_ID 0x1af4 133 #define RTE_AVP_PCI_DEVICE_ID 0x1110 134 /**@} */ 135 136 /**@{ AVP PCI subsystem identifiers */ 137 #define RTE_AVP_PCI_SUB_VENDOR_ID RTE_AVP_PCI_VENDOR_ID 138 #define RTE_AVP_PCI_SUB_DEVICE_ID 0x1104 139 /**@} */ 140 141 /**@{ AVP PCI BAR definitions */ 142 #define RTE_AVP_PCI_MMIO_BAR 0 143 #define RTE_AVP_PCI_MSIX_BAR 1 144 #define RTE_AVP_PCI_MEMORY_BAR 2 145 #define RTE_AVP_PCI_MEMMAP_BAR 4 146 #define RTE_AVP_PCI_DEVICE_BAR 5 147 #define RTE_AVP_PCI_MAX_BAR 6 148 /**@} */ 149 150 /**@{ AVP PCI BAR name definitions */ 151 #define RTE_AVP_MMIO_BAR_NAME "avp-mmio" 152 #define RTE_AVP_MSIX_BAR_NAME "avp-msix" 153 #define RTE_AVP_MEMORY_BAR_NAME "avp-memory" 154 #define RTE_AVP_MEMMAP_BAR_NAME "avp-memmap" 155 #define RTE_AVP_DEVICE_BAR_NAME "avp-device" 156 /**@} */ 157 158 /**@{ AVP PCI MSI-X vectors */ 159 #define RTE_AVP_MIGRATION_MSIX_VECTOR 0 /**< Migration interrupts */ 160 #define RTE_AVP_MAX_MSIX_VECTORS 1 161 /**@} */ 162 163 /**@} AVP Migration status/ack register values */ 164 #define RTE_AVP_MIGRATION_NONE 0 /**< Migration never executed */ 165 #define RTE_AVP_MIGRATION_DETACHED 1 /**< Device attached during migration */ 166 #define RTE_AVP_MIGRATION_ATTACHED 2 /**< Device reattached during migration */ 167 #define RTE_AVP_MIGRATION_ERROR 3 /**< Device failed to attach/detach */ 168 /**@} */ 169 170 /**@} AVP MMIO Register Offsets */ 171 #define RTE_AVP_REGISTER_BASE 0 172 #define RTE_AVP_INTERRUPT_MASK_OFFSET (RTE_AVP_REGISTER_BASE + 0) 173 #define RTE_AVP_INTERRUPT_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 4) 174 #define RTE_AVP_MIGRATION_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 8) 175 #define RTE_AVP_MIGRATION_ACK_OFFSET (RTE_AVP_REGISTER_BASE + 12) 176 /**@} */ 177 178 /**@} AVP Interrupt Status Mask */ 179 #define RTE_AVP_MIGRATION_INTERRUPT_MASK (1 << 1) 180 #define RTE_AVP_APP_INTERRUPTS_MASK 0xFFFFFFFF 181 #define RTE_AVP_NO_INTERRUPTS_MASK 0 182 /**@} */ 183 184 /* 185 * Maximum number of memory regions to export 186 */ 187 #define RTE_AVP_MAX_MAPS 2048 188 189 /* 190 * Description of a single memory region 191 */ 192 struct rte_avp_memmap { 193 void *addr; 194 rte_iova_t phys_addr; 195 uint64_t length; 196 }; 197 198 /* 199 * AVP memory mapping validation marker 200 */ 201 #define RTE_AVP_MEMMAP_MAGIC 0x20131969 202 203 /**@{ AVP memory map versions */ 204 #define RTE_AVP_MEMMAP_VERSION_1 1 205 #define RTE_AVP_MEMMAP_VERSION RTE_AVP_MEMMAP_VERSION_1 206 /**@} */ 207 208 /* 209 * Defines a list of memory regions exported from the host to the guest 210 */ 211 struct rte_avp_memmap_info { 212 uint32_t magic; /**< Memory validation marker */ 213 uint32_t version; /**< Data format version */ 214 uint32_t nb_maps; 215 struct rte_avp_memmap maps[RTE_AVP_MAX_MAPS]; 216 }; 217 218 /* 219 * AVP device memory validation marker 220 */ 221 #define RTE_AVP_DEVICE_MAGIC 0x20131975 222 223 /**@{ AVP device map versions 224 * WARNING: do not change the format or names of these variables. They are 225 * automatically parsed from the build system to generate the SDK package 226 * name. 227 **/ 228 #define RTE_AVP_RELEASE_VERSION_1 1 229 #define RTE_AVP_RELEASE_VERSION RTE_AVP_RELEASE_VERSION_1 230 #define RTE_AVP_MAJOR_VERSION_0 0 231 #define RTE_AVP_MAJOR_VERSION_1 1 232 #define RTE_AVP_MAJOR_VERSION_2 2 233 #define RTE_AVP_MAJOR_VERSION RTE_AVP_MAJOR_VERSION_2 234 #define RTE_AVP_MINOR_VERSION_0 0 235 #define RTE_AVP_MINOR_VERSION_1 1 236 #define RTE_AVP_MINOR_VERSION_13 13 237 #define RTE_AVP_MINOR_VERSION RTE_AVP_MINOR_VERSION_13 238 /**@} */ 239 240 241 /** 242 * Generates a 32-bit version number from the specified version number 243 * components 244 */ 245 #define RTE_AVP_MAKE_VERSION(_release, _major, _minor) \ 246 ((((_release) & 0xffff) << 16) | (((_major) & 0xff) << 8) | ((_minor) & 0xff)) 247 248 249 /** 250 * Represents the current version of the AVP host driver 251 * WARNING: in the current development branch the host and guest driver 252 * version should always be the same. When patching guest features back to 253 * GA releases the host version number should not be updated unless there was 254 * an actual change made to the host driver. 255 */ 256 #define RTE_AVP_CURRENT_HOST_VERSION \ 257 RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \ 258 RTE_AVP_MAJOR_VERSION_0, \ 259 RTE_AVP_MINOR_VERSION_1) 260 261 262 /** 263 * Represents the current version of the AVP guest drivers 264 */ 265 #define RTE_AVP_CURRENT_GUEST_VERSION \ 266 RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \ 267 RTE_AVP_MAJOR_VERSION_2, \ 268 RTE_AVP_MINOR_VERSION_13) 269 270 /** 271 * Access AVP device version values 272 */ 273 #define RTE_AVP_GET_RELEASE_VERSION(_version) (((_version) >> 16) & 0xffff) 274 #define RTE_AVP_GET_MAJOR_VERSION(_version) (((_version) >> 8) & 0xff) 275 #define RTE_AVP_GET_MINOR_VERSION(_version) ((_version) & 0xff) 276 /**@}*/ 277 278 279 /** 280 * Remove the minor version number so that only the release and major versions 281 * are used for comparisons. 282 */ 283 #define RTE_AVP_STRIP_MINOR_VERSION(_version) ((_version) >> 8) 284 285 286 /** 287 * Defines the number of mbuf pools supported per device (1 per socket) 288 */ 289 #define RTE_AVP_MAX_MEMPOOLS 8 290 291 /* 292 * Defines address translation parameters for each support mbuf pool 293 */ 294 struct rte_avp_mempool_info { 295 void *addr; 296 rte_iova_t phys_addr; 297 uint64_t length; 298 }; 299 300 /* 301 * Struct used to create a AVP device. Passed to the kernel in IOCTL call or 302 * via inter-VM shared memory when used in a guest. 303 */ 304 struct rte_avp_device_info { 305 uint32_t magic; /**< Memory validation marker */ 306 uint32_t version; /**< Data format version */ 307 308 char ifname[RTE_AVP_NAMESIZE]; /**< Network device name for AVP */ 309 310 rte_iova_t tx_phys; 311 rte_iova_t rx_phys; 312 rte_iova_t alloc_phys; 313 rte_iova_t free_phys; 314 315 uint32_t features; /**< Supported feature bitmap */ 316 uint8_t min_rx_queues; /**< Minimum supported receive/free queues */ 317 uint8_t num_rx_queues; /**< Recommended number of receive/free queues */ 318 uint8_t max_rx_queues; /**< Maximum supported receive/free queues */ 319 uint8_t min_tx_queues; /**< Minimum supported transmit/alloc queues */ 320 uint8_t num_tx_queues; 321 /**< Recommended number of transmit/alloc queues */ 322 uint8_t max_tx_queues; /**< Maximum supported transmit/alloc queues */ 323 324 uint32_t tx_size; /**< Size of each transmit queue */ 325 uint32_t rx_size; /**< Size of each receive queue */ 326 uint32_t alloc_size; /**< Size of each alloc queue */ 327 uint32_t free_size; /**< Size of each free queue */ 328 329 /* Used by Ethtool */ 330 rte_iova_t req_phys; 331 rte_iova_t resp_phys; 332 rte_iova_t sync_phys; 333 void *sync_va; 334 335 /* mbuf mempool (used when a single memory area is supported) */ 336 void *mbuf_va; 337 rte_iova_t mbuf_phys; 338 339 /* mbuf mempools */ 340 struct rte_avp_mempool_info pool[RTE_AVP_MAX_MEMPOOLS]; 341 342 #ifdef __KERNEL__ 343 /* Ethernet info */ 344 char ethaddr[ETH_ALEN]; 345 #else 346 char ethaddr[RTE_ETHER_ADDR_LEN]; 347 #endif 348 349 uint8_t mode; /**< device mode, i.e guest, host, trace */ 350 351 /* mbuf size */ 352 unsigned int mbuf_size; 353 354 /* 355 * unique id to differentiate between two instantiations of the same 356 * AVP device (i.e., the guest needs to know if the device has been 357 * deleted and recreated). 358 */ 359 uint64_t device_id; 360 361 uint32_t max_rx_pkt_len; /**< Maximum receive unit size */ 362 }; 363 364 #define RTE_AVP_MAX_QUEUES 8 /**< Maximum number of queues per device */ 365 366 /** Maximum number of chained mbufs in a packet */ 367 #define RTE_AVP_MAX_MBUF_SEGMENTS 5 368 369 #define RTE_AVP_DEVICE "avp" 370 371 #define RTE_AVP_IOCTL_TEST _IOWR(0, 1, int) 372 #define RTE_AVP_IOCTL_CREATE _IOWR(0, 2, struct rte_avp_device_info) 373 #define RTE_AVP_IOCTL_RELEASE _IOWR(0, 3, struct rte_avp_device_info) 374 #define RTE_AVP_IOCTL_QUERY _IOWR(0, 4, struct rte_avp_device_config) 375 376 #ifdef __cplusplus 377 } 378 #endif 379 380 #endif /* _RTE_AVP_COMMON_H_ */ 381