net/avp: add public header files
[dpdk.git] / drivers / net / avp / rte_avp_common.h
1 /*-
2  *   This file is provided under a dual BSD/LGPLv2 license.  When using or
3  *   redistributing this file, you may do so under either license.
4  *
5  *   GNU LESSER GENERAL PUBLIC LICENSE
6  *
7  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
8  *   Copyright(c) 2014-2017 Wind River Systems, Inc. All rights reserved.
9  *
10  *   This program is free software; you can redistribute it and/or modify
11  *   it under the terms of version 2.1 of the GNU Lesser General Public License
12  *   as published by the Free Software Foundation.
13  *
14  *   This program is distributed in the hope that it will be useful, but
15  *   WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *   Lesser General Public License for more details.
18  *
19  *   Contact Information:
20  *   Wind River Systems, Inc.
21  *
22  *
23  *   BSD LICENSE
24  *
25  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
26  *   Copyright(c) 2014-2017 Wind River Systems, Inc. All rights reserved.
27  *   All rights reserved.
28  *
29  *   Redistribution and use in source and binary forms, with or without
30  *   modification, are permitted provided that the following conditions
31  *   are met:
32  *
33  *   * Redistributions of source code must retain the above copyright
34  *     notice, this list of conditions and the following disclaimer.
35  *   * Redistributions in binary form must reproduce the above copyright
36  *     notice, this list of conditions and the following disclaimer in
37  *     the documentation and/or other materials provided with the
38  *     distribution.
39  *   * Neither the name of Intel Corporation nor the names of its
40  *     contributors may be used to endorse or promote products derived
41  *     from this software without specific prior written permission.
42  *
43  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44  *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45  *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46  *    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54  *
55  */
56
57 #ifndef _RTE_AVP_COMMON_H_
58 #define _RTE_AVP_COMMON_H_
59
60 #ifdef __KERNEL__
61 #include <linux/if.h>
62 #endif
63
64 /**
65  * AVP name is part of network device name.
66  */
67 #define RTE_AVP_NAMESIZE 32
68
69 /**
70  * AVP alias is a user-defined value used for lookups from secondary
71  * processes.  Typically, this is a UUID.
72  */
73 #define RTE_AVP_ALIASSIZE 128
74
75 /*
76  * Request id.
77  */
78 enum rte_avp_req_id {
79         RTE_AVP_REQ_UNKNOWN = 0,
80         RTE_AVP_REQ_CHANGE_MTU,
81         RTE_AVP_REQ_CFG_NETWORK_IF,
82         RTE_AVP_REQ_CFG_DEVICE,
83         RTE_AVP_REQ_SHUTDOWN_DEVICE,
84         RTE_AVP_REQ_MAX,
85 };
86
87 /**@{ AVP device driver types */
88 #define RTE_AVP_DRIVER_TYPE_UNKNOWN 0
89 #define RTE_AVP_DRIVER_TYPE_DPDK 1
90 #define RTE_AVP_DRIVER_TYPE_KERNEL 2
91 #define RTE_AVP_DRIVER_TYPE_QEMU 3
92 /**@} */
93
94 /**@{ AVP device operational modes */
95 #define RTE_AVP_MODE_HOST 0 /**< AVP interface created in host */
96 #define RTE_AVP_MODE_GUEST 1 /**< AVP interface created for export to guest */
97 #define RTE_AVP_MODE_TRACE 2 /**< AVP interface created for packet tracing */
98 /**@} */
99
100 /*
101  * Structure for AVP queue configuration query request/result
102  */
103 struct rte_avp_device_config {
104         uint64_t device_id;     /**< Unique system identifier */
105         uint32_t driver_type; /**< Device Driver type */
106         uint32_t driver_version; /**< Device Driver version */
107         uint32_t features; /**< Negotiated features */
108         uint16_t num_tx_queues; /**< Number of active transmit queues */
109         uint16_t num_rx_queues; /**< Number of active receive queues */
110         uint8_t if_up; /**< 1: interface up, 0: interface down */
111 } __attribute__ ((__packed__));
112
113 /*
114  * Structure for AVP request.
115  */
116 struct rte_avp_request {
117         uint32_t req_id; /**< Request id */
118         union {
119                 uint32_t new_mtu; /**< New MTU */
120                 uint8_t if_up;  /**< 1: interface up, 0: interface down */
121         struct rte_avp_device_config config; /**< Queue configuration */
122         };
123         int32_t result; /**< Result for processing request */
124 } __attribute__ ((__packed__));
125
126 /*
127  * FIFO struct mapped in a shared memory. It describes a circular buffer FIFO
128  * Write and read should wrap around. FIFO is empty when write == read
129  * Writing should never overwrite the read position
130  */
131 struct rte_avp_fifo {
132         volatile unsigned int write; /**< Next position to be written*/
133         volatile unsigned int read; /**< Next position to be read */
134         unsigned int len; /**< Circular buffer length */
135         unsigned int elem_size; /**< Pointer size - for 32/64 bit OS */
136         void *volatile buffer[0]; /**< The buffer contains mbuf pointers */
137 };
138
139
140 /*
141  * AVP packet buffer header used to define the exchange of packet data.
142  */
143 struct rte_avp_desc {
144         uint64_t pad0;
145         void *pkt_mbuf; /**< Reference to packet mbuf */
146         uint8_t pad1[14];
147         uint16_t ol_flags; /**< Offload features. */
148         void *next;     /**< Reference to next buffer in chain */
149         void *data;     /**< Start address of data in segment buffer. */
150         uint16_t data_len; /**< Amount of data in segment buffer. */
151         uint8_t nb_segs; /**< Number of segments */
152         uint8_t pad2;
153         uint16_t pkt_len; /**< Total pkt len: sum of all segment data_len. */
154         uint32_t pad3;
155         uint16_t vlan_tci; /**< VLAN Tag Control Identifier (CPU order). */
156         uint32_t pad4;
157 } __attribute__ ((__aligned__(RTE_CACHE_LINE_SIZE), __packed__));
158
159
160 /**{ AVP device features */
161 #define RTE_AVP_FEATURE_VLAN_OFFLOAD (1 << 0) /**< Emulated HW VLAN offload */
162 /**@} */
163
164
165 /**@{ Offload feature flags */
166 #define RTE_AVP_TX_VLAN_PKT 0x0001 /**< TX packet is a 802.1q VLAN packet. */
167 #define RTE_AVP_RX_VLAN_PKT 0x0800 /**< RX packet is a 802.1q VLAN packet. */
168 /**@} */
169
170
171 /**@{ AVP PCI identifiers */
172 #define RTE_AVP_PCI_VENDOR_ID   0x1af4
173 #define RTE_AVP_PCI_DEVICE_ID   0x1110
174 /**@} */
175
176 /**@{ AVP PCI subsystem identifiers */
177 #define RTE_AVP_PCI_SUB_VENDOR_ID RTE_AVP_PCI_VENDOR_ID
178 #define RTE_AVP_PCI_SUB_DEVICE_ID 0x1104
179 /**@} */
180
181 /**@{ AVP PCI BAR definitions */
182 #define RTE_AVP_PCI_MMIO_BAR   0
183 #define RTE_AVP_PCI_MSIX_BAR   1
184 #define RTE_AVP_PCI_MEMORY_BAR 2
185 #define RTE_AVP_PCI_MEMMAP_BAR 4
186 #define RTE_AVP_PCI_DEVICE_BAR 5
187 #define RTE_AVP_PCI_MAX_BAR    6
188 /**@} */
189
190 /**@{ AVP PCI BAR name definitions */
191 #define RTE_AVP_MMIO_BAR_NAME   "avp-mmio"
192 #define RTE_AVP_MSIX_BAR_NAME   "avp-msix"
193 #define RTE_AVP_MEMORY_BAR_NAME "avp-memory"
194 #define RTE_AVP_MEMMAP_BAR_NAME "avp-memmap"
195 #define RTE_AVP_DEVICE_BAR_NAME "avp-device"
196 /**@} */
197
198 /**@{ AVP PCI MSI-X vectors */
199 #define RTE_AVP_MIGRATION_MSIX_VECTOR 0 /**< Migration interrupts */
200 #define RTE_AVP_MAX_MSIX_VECTORS 1
201 /**@} */
202
203 /**@} AVP Migration status/ack register values */
204 #define RTE_AVP_MIGRATION_NONE      0 /**< Migration never executed */
205 #define RTE_AVP_MIGRATION_DETACHED  1 /**< Device attached during migration */
206 #define RTE_AVP_MIGRATION_ATTACHED  2 /**< Device reattached during migration */
207 #define RTE_AVP_MIGRATION_ERROR     3 /**< Device failed to attach/detach */
208 /**@} */
209
210 /**@} AVP MMIO Register Offsets */
211 #define RTE_AVP_REGISTER_BASE 0
212 #define RTE_AVP_INTERRUPT_MASK_OFFSET (RTE_AVP_REGISTER_BASE + 0)
213 #define RTE_AVP_INTERRUPT_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 4)
214 #define RTE_AVP_MIGRATION_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 8)
215 #define RTE_AVP_MIGRATION_ACK_OFFSET (RTE_AVP_REGISTER_BASE + 12)
216 /**@} */
217
218 /**@} AVP Interrupt Status Mask */
219 #define RTE_AVP_MIGRATION_INTERRUPT_MASK (1 << 1)
220 #define RTE_AVP_APP_INTERRUPTS_MASK      0xFFFFFFFF
221 #define RTE_AVP_NO_INTERRUPTS_MASK       0
222 /**@} */
223
224 /*
225  * Maximum number of memory regions to export
226  */
227 #define RTE_AVP_MAX_MAPS  2048
228
229 /*
230  * Description of a single memory region
231  */
232 struct rte_avp_memmap {
233         void *addr;
234         phys_addr_t phys_addr;
235         uint64_t length;
236 };
237
238 /*
239  * AVP memory mapping validation marker
240  */
241 #define RTE_AVP_MEMMAP_MAGIC 0x20131969
242
243 /**@{  AVP memory map versions */
244 #define RTE_AVP_MEMMAP_VERSION_1 1
245 #define RTE_AVP_MEMMAP_VERSION RTE_AVP_MEMMAP_VERSION_1
246 /**@} */
247
248 /*
249  * Defines a list of memory regions exported from the host to the guest
250  */
251 struct rte_avp_memmap_info {
252         uint32_t magic; /**< Memory validation marker */
253         uint32_t version; /**< Data format version */
254         uint32_t nb_maps;
255         struct rte_avp_memmap maps[RTE_AVP_MAX_MAPS];
256 };
257
258 /*
259  * AVP device memory validation marker
260  */
261 #define RTE_AVP_DEVICE_MAGIC 0x20131975
262
263 /**@{  AVP device map versions
264  * WARNING:  do not change the format or names of these variables.  They are
265  * automatically parsed from the build system to generate the SDK package
266  * name.
267  **/
268 #define RTE_AVP_RELEASE_VERSION_1 1
269 #define RTE_AVP_RELEASE_VERSION RTE_AVP_RELEASE_VERSION_1
270 #define RTE_AVP_MAJOR_VERSION_0 0
271 #define RTE_AVP_MAJOR_VERSION_1 1
272 #define RTE_AVP_MAJOR_VERSION_2 2
273 #define RTE_AVP_MAJOR_VERSION RTE_AVP_MAJOR_VERSION_2
274 #define RTE_AVP_MINOR_VERSION_0 0
275 #define RTE_AVP_MINOR_VERSION_1 1
276 #define RTE_AVP_MINOR_VERSION_13 13
277 #define RTE_AVP_MINOR_VERSION RTE_AVP_MINOR_VERSION_13
278 /**@} */
279
280
281 /**
282  * Generates a 32-bit version number from the specified version number
283  * components
284  */
285 #define RTE_AVP_MAKE_VERSION(_release, _major, _minor) \
286 ((((_release) & 0xffff) << 16) | (((_major) & 0xff) << 8) | ((_minor) & 0xff))
287
288
289 /**
290  * Represents the current version of the AVP host driver
291  * WARNING:  in the current development branch the host and guest driver
292  * version should always be the same.  When patching guest features back to
293  * GA releases the host version number should not be updated unless there was
294  * an actual change made to the host driver.
295  */
296 #define RTE_AVP_CURRENT_HOST_VERSION \
297 RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \
298                      RTE_AVP_MAJOR_VERSION_0, \
299                      RTE_AVP_MINOR_VERSION_1)
300
301
302 /**
303  * Represents the current version of the AVP guest drivers
304  */
305 #define RTE_AVP_CURRENT_GUEST_VERSION \
306 RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \
307                      RTE_AVP_MAJOR_VERSION_2, \
308                      RTE_AVP_MINOR_VERSION_13)
309
310 /**
311  * Access AVP device version values
312  */
313 #define RTE_AVP_GET_RELEASE_VERSION(_version) (((_version) >> 16) & 0xffff)
314 #define RTE_AVP_GET_MAJOR_VERSION(_version) (((_version) >> 8) & 0xff)
315 #define RTE_AVP_GET_MINOR_VERSION(_version) ((_version) & 0xff)
316 /**@}*/
317
318
319 /**
320  * Remove the minor version number so that only the release and major versions
321  * are used for comparisons.
322  */
323 #define RTE_AVP_STRIP_MINOR_VERSION(_version) ((_version) >> 8)
324
325
326 /**
327  * Defines the number of mbuf pools supported per device (1 per socket)
328  */
329 #define RTE_AVP_MAX_MEMPOOLS 8
330
331 /*
332  * Defines address translation parameters for each support mbuf pool
333  */
334 struct rte_avp_mempool_info {
335         void *addr;
336         phys_addr_t phys_addr;
337         uint64_t length;
338 };
339
340 /*
341  * Struct used to create a AVP device. Passed to the kernel in IOCTL call or
342  * via inter-VM shared memory when used in a guest.
343  */
344 struct rte_avp_device_info {
345         uint32_t magic; /**< Memory validation marker */
346         uint32_t version; /**< Data format version */
347
348         char ifname[RTE_AVP_NAMESIZE];  /**< Network device name for AVP */
349
350         phys_addr_t tx_phys;
351         phys_addr_t rx_phys;
352         phys_addr_t alloc_phys;
353         phys_addr_t free_phys;
354
355         uint32_t features; /**< Supported feature bitmap */
356         uint8_t min_rx_queues; /**< Minimum supported receive/free queues */
357         uint8_t num_rx_queues; /**< Recommended number of receive/free queues */
358         uint8_t max_rx_queues; /**< Maximum supported receive/free queues */
359         uint8_t min_tx_queues; /**< Minimum supported transmit/alloc queues */
360         uint8_t num_tx_queues;
361         /**< Recommended number of transmit/alloc queues */
362         uint8_t max_tx_queues; /**< Maximum supported transmit/alloc queues */
363
364         uint32_t tx_size; /**< Size of each transmit queue */
365         uint32_t rx_size; /**< Size of each receive queue */
366         uint32_t alloc_size; /**< Size of each alloc queue */
367         uint32_t free_size;     /**< Size of each free queue */
368
369         /* Used by Ethtool */
370         phys_addr_t req_phys;
371         phys_addr_t resp_phys;
372         phys_addr_t sync_phys;
373         void *sync_va;
374
375         /* mbuf mempool (used when a single memory area is supported) */
376         void *mbuf_va;
377         phys_addr_t mbuf_phys;
378
379         /* mbuf mempools */
380         struct rte_avp_mempool_info pool[RTE_AVP_MAX_MEMPOOLS];
381
382 #ifdef __KERNEL__
383         /* Ethernet info */
384         char ethaddr[ETH_ALEN];
385 #else
386         char ethaddr[ETHER_ADDR_LEN];
387 #endif
388
389         uint8_t mode; /**< device mode, i.e guest, host, trace */
390
391         /* mbuf size */
392         unsigned int mbuf_size;
393
394         /*
395          * unique id to differentiate between two instantiations of the same
396          * AVP device (i.e., the guest needs to know if the device has been
397          * deleted and recreated).
398          */
399         uint64_t device_id;
400
401         uint32_t max_rx_pkt_len; /**< Maximum receive unit size */
402 };
403
404 #define RTE_AVP_MAX_QUEUES 8 /**< Maximum number of queues per device */
405
406 /** Maximum number of chained mbufs in a packet */
407 #define RTE_AVP_MAX_MBUF_SEGMENTS 5
408
409 #define RTE_AVP_DEVICE "avp"
410
411 #define RTE_AVP_IOCTL_TEST    _IOWR(0, 1, int)
412 #define RTE_AVP_IOCTL_CREATE  _IOWR(0, 2, struct rte_avp_device_info)
413 #define RTE_AVP_IOCTL_RELEASE _IOWR(0, 3, struct rte_avp_device_info)
414 #define RTE_AVP_IOCTL_QUERY   _IOWR(0, 4, struct rte_avp_device_config)
415
416 #endif /* _RTE_AVP_COMMON_H_ */