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