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.
6 #ifndef _RTE_AVP_COMMON_H_
7 #define _RTE_AVP_COMMON_H_
14 #include <rte_common.h>
15 #include <rte_config.h>
16 #include <rte_memory.h>
17 #include <rte_ether.h>
18 #include <rte_atomic.h>
26 * AVP name is part of network device name.
28 #define RTE_AVP_NAMESIZE 32
31 * AVP alias is a user-defined value used for lookups from secondary
32 * processes. Typically, this is a UUID.
34 #define RTE_AVP_ALIASSIZE 128
40 RTE_AVP_REQ_UNKNOWN = 0,
41 RTE_AVP_REQ_CHANGE_MTU,
42 RTE_AVP_REQ_CFG_NETWORK_IF,
43 RTE_AVP_REQ_CFG_DEVICE,
44 RTE_AVP_REQ_SHUTDOWN_DEVICE,
48 /**@{ AVP device driver types */
49 #define RTE_AVP_DRIVER_TYPE_UNKNOWN 0
50 #define RTE_AVP_DRIVER_TYPE_DPDK 1
51 #define RTE_AVP_DRIVER_TYPE_KERNEL 2
52 #define RTE_AVP_DRIVER_TYPE_QEMU 3
55 /**@{ AVP device operational modes */
56 #define RTE_AVP_MODE_HOST 0 /**< AVP interface created in host */
57 #define RTE_AVP_MODE_GUEST 1 /**< AVP interface created for export to guest */
58 #define RTE_AVP_MODE_TRACE 2 /**< AVP interface created for packet tracing */
62 * Structure for AVP queue configuration query request/result
64 struct rte_avp_device_config {
65 uint64_t device_id; /**< Unique system identifier */
66 uint32_t driver_type; /**< Device Driver type */
67 uint32_t driver_version; /**< Device Driver version */
68 uint32_t features; /**< Negotiated features */
69 uint16_t num_tx_queues; /**< Number of active transmit queues */
70 uint16_t num_rx_queues; /**< Number of active receive queues */
71 uint8_t if_up; /**< 1: interface up, 0: interface down */
72 } __attribute__ ((__packed__));
75 * Structure for AVP request.
77 struct rte_avp_request {
78 uint32_t req_id; /**< Request id */
81 uint32_t new_mtu; /**< New MTU */
82 uint8_t if_up; /**< 1: interface up, 0: interface down */
83 struct rte_avp_device_config config; /**< Queue configuration */
85 int32_t result; /**< Result for processing request */
86 } __attribute__ ((__packed__));
89 * FIFO struct mapped in a shared memory. It describes a circular buffer FIFO
90 * Write and read should wrap around. FIFO is empty when write == read
91 * Writing should never overwrite the read position
94 volatile unsigned int write; /**< Next position to be written*/
95 volatile unsigned int read; /**< Next position to be read */
96 unsigned int len; /**< Circular buffer length */
97 unsigned int elem_size; /**< Pointer size - for 32/64 bit OS */
98 void *volatile buffer[]; /**< The buffer contains mbuf pointers */
103 * AVP packet buffer header used to define the exchange of packet data.
105 struct rte_avp_desc {
107 void *pkt_mbuf; /**< Reference to packet mbuf */
109 uint16_t ol_flags; /**< Offload features. */
110 void *next; /**< Reference to next buffer in chain */
111 void *data; /**< Start address of data in segment buffer. */
112 uint16_t data_len; /**< Amount of data in segment buffer. */
113 uint8_t nb_segs; /**< Number of segments */
115 uint16_t pkt_len; /**< Total pkt len: sum of all segment data_len. */
117 uint16_t vlan_tci; /**< VLAN Tag Control Identifier (CPU order). */
119 } __attribute__ ((__aligned__(RTE_CACHE_LINE_SIZE), __packed__));
122 /**{ AVP device features */
123 #define RTE_AVP_FEATURE_VLAN_OFFLOAD (1 << 0) /**< Emulated HW VLAN offload */
127 /**@{ Offload feature flags */
128 #define RTE_AVP_TX_VLAN_PKT 0x0001 /**< TX packet is a 802.1q VLAN packet. */
129 #define RTE_AVP_RX_VLAN_PKT 0x0800 /**< RX packet is a 802.1q VLAN packet. */
133 /**@{ AVP PCI identifiers */
134 #define RTE_AVP_PCI_VENDOR_ID 0x1af4
135 #define RTE_AVP_PCI_DEVICE_ID 0x1110
138 /**@{ AVP PCI subsystem identifiers */
139 #define RTE_AVP_PCI_SUB_VENDOR_ID RTE_AVP_PCI_VENDOR_ID
140 #define RTE_AVP_PCI_SUB_DEVICE_ID 0x1104
143 /**@{ AVP PCI BAR definitions */
144 #define RTE_AVP_PCI_MMIO_BAR 0
145 #define RTE_AVP_PCI_MSIX_BAR 1
146 #define RTE_AVP_PCI_MEMORY_BAR 2
147 #define RTE_AVP_PCI_MEMMAP_BAR 4
148 #define RTE_AVP_PCI_DEVICE_BAR 5
149 #define RTE_AVP_PCI_MAX_BAR 6
152 /**@{ AVP PCI BAR name definitions */
153 #define RTE_AVP_MMIO_BAR_NAME "avp-mmio"
154 #define RTE_AVP_MSIX_BAR_NAME "avp-msix"
155 #define RTE_AVP_MEMORY_BAR_NAME "avp-memory"
156 #define RTE_AVP_MEMMAP_BAR_NAME "avp-memmap"
157 #define RTE_AVP_DEVICE_BAR_NAME "avp-device"
160 /**@{ AVP PCI MSI-X vectors */
161 #define RTE_AVP_MIGRATION_MSIX_VECTOR 0 /**< Migration interrupts */
162 #define RTE_AVP_MAX_MSIX_VECTORS 1
165 /**@} AVP Migration status/ack register values */
166 #define RTE_AVP_MIGRATION_NONE 0 /**< Migration never executed */
167 #define RTE_AVP_MIGRATION_DETACHED 1 /**< Device attached during migration */
168 #define RTE_AVP_MIGRATION_ATTACHED 2 /**< Device reattached during migration */
169 #define RTE_AVP_MIGRATION_ERROR 3 /**< Device failed to attach/detach */
172 /**@} AVP MMIO Register Offsets */
173 #define RTE_AVP_REGISTER_BASE 0
174 #define RTE_AVP_INTERRUPT_MASK_OFFSET (RTE_AVP_REGISTER_BASE + 0)
175 #define RTE_AVP_INTERRUPT_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 4)
176 #define RTE_AVP_MIGRATION_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 8)
177 #define RTE_AVP_MIGRATION_ACK_OFFSET (RTE_AVP_REGISTER_BASE + 12)
180 /**@} AVP Interrupt Status Mask */
181 #define RTE_AVP_MIGRATION_INTERRUPT_MASK (1 << 1)
182 #define RTE_AVP_APP_INTERRUPTS_MASK 0xFFFFFFFF
183 #define RTE_AVP_NO_INTERRUPTS_MASK 0
187 * Maximum number of memory regions to export
189 #define RTE_AVP_MAX_MAPS 2048
192 * Description of a single memory region
194 struct rte_avp_memmap {
196 rte_iova_t phys_addr;
201 * AVP memory mapping validation marker
203 #define RTE_AVP_MEMMAP_MAGIC 0x20131969
205 /**@{ AVP memory map versions */
206 #define RTE_AVP_MEMMAP_VERSION_1 1
207 #define RTE_AVP_MEMMAP_VERSION RTE_AVP_MEMMAP_VERSION_1
211 * Defines a list of memory regions exported from the host to the guest
213 struct rte_avp_memmap_info {
214 uint32_t magic; /**< Memory validation marker */
215 uint32_t version; /**< Data format version */
217 struct rte_avp_memmap maps[RTE_AVP_MAX_MAPS];
221 * AVP device memory validation marker
223 #define RTE_AVP_DEVICE_MAGIC 0x20131975
225 /**@{ AVP device map versions
226 * WARNING: do not change the format or names of these variables. They are
227 * automatically parsed from the build system to generate the SDK package
230 #define RTE_AVP_RELEASE_VERSION_1 1
231 #define RTE_AVP_RELEASE_VERSION RTE_AVP_RELEASE_VERSION_1
232 #define RTE_AVP_MAJOR_VERSION_0 0
233 #define RTE_AVP_MAJOR_VERSION_1 1
234 #define RTE_AVP_MAJOR_VERSION_2 2
235 #define RTE_AVP_MAJOR_VERSION RTE_AVP_MAJOR_VERSION_2
236 #define RTE_AVP_MINOR_VERSION_0 0
237 #define RTE_AVP_MINOR_VERSION_1 1
238 #define RTE_AVP_MINOR_VERSION_13 13
239 #define RTE_AVP_MINOR_VERSION RTE_AVP_MINOR_VERSION_13
244 * Generates a 32-bit version number from the specified version number
247 #define RTE_AVP_MAKE_VERSION(_release, _major, _minor) \
248 ((((_release) & 0xffff) << 16) | (((_major) & 0xff) << 8) | ((_minor) & 0xff))
252 * Represents the current version of the AVP host driver
253 * WARNING: in the current development branch the host and guest driver
254 * version should always be the same. When patching guest features back to
255 * GA releases the host version number should not be updated unless there was
256 * an actual change made to the host driver.
258 #define RTE_AVP_CURRENT_HOST_VERSION \
259 RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \
260 RTE_AVP_MAJOR_VERSION_0, \
261 RTE_AVP_MINOR_VERSION_1)
265 * Represents the current version of the AVP guest drivers
267 #define RTE_AVP_CURRENT_GUEST_VERSION \
268 RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \
269 RTE_AVP_MAJOR_VERSION_2, \
270 RTE_AVP_MINOR_VERSION_13)
273 * Access AVP device version values
275 #define RTE_AVP_GET_RELEASE_VERSION(_version) (((_version) >> 16) & 0xffff)
276 #define RTE_AVP_GET_MAJOR_VERSION(_version) (((_version) >> 8) & 0xff)
277 #define RTE_AVP_GET_MINOR_VERSION(_version) ((_version) & 0xff)
282 * Remove the minor version number so that only the release and major versions
283 * are used for comparisons.
285 #define RTE_AVP_STRIP_MINOR_VERSION(_version) ((_version) >> 8)
289 * Defines the number of mbuf pools supported per device (1 per socket)
291 #define RTE_AVP_MAX_MEMPOOLS 8
294 * Defines address translation parameters for each support mbuf pool
296 struct rte_avp_mempool_info {
298 rte_iova_t phys_addr;
303 * Struct used to create a AVP device. Passed to the kernel in IOCTL call or
304 * via inter-VM shared memory when used in a guest.
306 struct rte_avp_device_info {
307 uint32_t magic; /**< Memory validation marker */
308 uint32_t version; /**< Data format version */
310 char ifname[RTE_AVP_NAMESIZE]; /**< Network device name for AVP */
314 rte_iova_t alloc_phys;
315 rte_iova_t free_phys;
317 uint32_t features; /**< Supported feature bitmap */
318 uint8_t min_rx_queues; /**< Minimum supported receive/free queues */
319 uint8_t num_rx_queues; /**< Recommended number of receive/free queues */
320 uint8_t max_rx_queues; /**< Maximum supported receive/free queues */
321 uint8_t min_tx_queues; /**< Minimum supported transmit/alloc queues */
322 uint8_t num_tx_queues;
323 /**< Recommended number of transmit/alloc queues */
324 uint8_t max_tx_queues; /**< Maximum supported transmit/alloc queues */
326 uint32_t tx_size; /**< Size of each transmit queue */
327 uint32_t rx_size; /**< Size of each receive queue */
328 uint32_t alloc_size; /**< Size of each alloc queue */
329 uint32_t free_size; /**< Size of each free queue */
331 /* Used by Ethtool */
333 rte_iova_t resp_phys;
334 rte_iova_t sync_phys;
337 /* mbuf mempool (used when a single memory area is supported) */
339 rte_iova_t mbuf_phys;
342 struct rte_avp_mempool_info pool[RTE_AVP_MAX_MEMPOOLS];
346 char ethaddr[ETH_ALEN];
348 char ethaddr[ETHER_ADDR_LEN];
351 uint8_t mode; /**< device mode, i.e guest, host, trace */
354 unsigned int mbuf_size;
357 * unique id to differentiate between two instantiations of the same
358 * AVP device (i.e., the guest needs to know if the device has been
359 * deleted and recreated).
363 uint32_t max_rx_pkt_len; /**< Maximum receive unit size */
366 #define RTE_AVP_MAX_QUEUES 8 /**< Maximum number of queues per device */
368 /** Maximum number of chained mbufs in a packet */
369 #define RTE_AVP_MAX_MBUF_SEGMENTS 5
371 #define RTE_AVP_DEVICE "avp"
373 #define RTE_AVP_IOCTL_TEST _IOWR(0, 1, int)
374 #define RTE_AVP_IOCTL_CREATE _IOWR(0, 2, struct rte_avp_device_info)
375 #define RTE_AVP_IOCTL_RELEASE _IOWR(0, 3, struct rte_avp_device_info)
376 #define RTE_AVP_IOCTL_QUERY _IOWR(0, 4, struct rte_avp_device_config)
382 #endif /* _RTE_AVP_COMMON_H_ */