New upstream version 17.11.1
[deb_dpdk.git] / lib / librte_eal / linuxapp / eal / include / exec-env / rte_kni_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) 2007-2014 Intel Corporation. All rights reserved.
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of version 2.1 of the GNU Lesser General Public License
11  *   as published by the Free Software Foundation.
12  *
13  *   This program is distributed in the hope that it will be useful, but
14  *   WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *   Lesser General Public License for more details.
17  *
18  *   You should have received a copy of the GNU Lesser General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  *   Contact Information:
23  *   Intel Corporation
24  *
25  *
26  *   BSD LICENSE
27  *
28  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
29  *   All rights reserved.
30  *
31  *   Redistribution and use in source and binary forms, with or without
32  *   modification, are permitted provided that the following conditions
33  *   are met:
34  *
35  *   * Redistributions of source code must retain the above copyright
36  *     notice, this list of conditions and the following disclaimer.
37  *   * Redistributions in binary form must reproduce the above copyright
38  *     notice, this list of conditions and the following disclaimer in
39  *     the documentation and/or other materials provided with the
40  *     distribution.
41  *   * Neither the name of Intel Corporation nor the names of its
42  *     contributors may be used to endorse or promote products derived
43  *     from this software without specific prior written permission.
44  *
45  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46  *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47  *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48  *    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
49  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  *
57  */
58
59 #ifndef _RTE_KNI_COMMON_H_
60 #define _RTE_KNI_COMMON_H_
61
62 #ifdef __KERNEL__
63 #include <linux/if.h>
64 #define RTE_STD_C11
65 #else
66 #include <rte_common.h>
67 #include <rte_config.h>
68 #endif
69
70 /**
71  * KNI name is part of memzone name.
72  */
73 #define RTE_KNI_NAMESIZE 32
74
75 #define RTE_CACHE_LINE_MIN_SIZE 64
76
77 /*
78  * Request id.
79  */
80 enum rte_kni_req_id {
81         RTE_KNI_REQ_UNKNOWN = 0,
82         RTE_KNI_REQ_CHANGE_MTU,
83         RTE_KNI_REQ_CFG_NETWORK_IF,
84         RTE_KNI_REQ_MAX,
85 };
86
87 /*
88  * Structure for KNI request.
89  */
90 struct rte_kni_request {
91         uint32_t req_id;             /**< Request id */
92         RTE_STD_C11
93         union {
94                 uint32_t new_mtu;    /**< New MTU */
95                 uint8_t if_up;       /**< 1: interface up, 0: interface down */
96         };
97         int32_t result;               /**< Result for processing request */
98 } __attribute__((__packed__));
99
100 /*
101  * Fifo struct mapped in a shared memory. It describes a circular buffer FIFO
102  * Write and read should wrap around. Fifo is empty when write == read
103  * Writing should never overwrite the read position
104  */
105 struct rte_kni_fifo {
106         volatile unsigned write;     /**< Next position to be written*/
107         volatile unsigned read;      /**< Next position to be read */
108         unsigned len;                /**< Circular buffer length */
109         unsigned elem_size;          /**< Pointer size - for 32/64 bit OS */
110         void *volatile buffer[];     /**< The buffer contains mbuf pointers */
111 };
112
113 /*
114  * The kernel image of the rte_mbuf struct, with only the relevant fields.
115  * Padding is necessary to assure the offsets of these fields
116  */
117 struct rte_kni_mbuf {
118         void *buf_addr __attribute__((__aligned__(RTE_CACHE_LINE_SIZE)));
119         uint64_t buf_physaddr;
120         uint16_t data_off;      /**< Start address of data in segment buffer. */
121         char pad1[2];
122         uint16_t nb_segs;       /**< Number of segments. */
123         char pad4[2];
124         uint64_t ol_flags;      /**< Offload features. */
125         char pad2[4];
126         uint32_t pkt_len;       /**< Total pkt len: sum of all segment data_len. */
127         uint16_t data_len;      /**< Amount of data in segment buffer. */
128
129         /* fields on second cache line */
130         char pad3[8] __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
131         void *pool;
132         void *next;
133 };
134
135 /*
136  * Struct used to create a KNI device. Passed to the kernel in IOCTL call
137  */
138
139 struct rte_kni_device_info {
140         char name[RTE_KNI_NAMESIZE];  /**< Network device name for KNI */
141
142         phys_addr_t tx_phys;
143         phys_addr_t rx_phys;
144         phys_addr_t alloc_phys;
145         phys_addr_t free_phys;
146
147         /* Used by Ethtool */
148         phys_addr_t req_phys;
149         phys_addr_t resp_phys;
150         phys_addr_t sync_phys;
151         void * sync_va;
152
153         /* mbuf mempool */
154         void * mbuf_va;
155         phys_addr_t mbuf_phys;
156
157         /* PCI info */
158         uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
159         uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
160         uint8_t bus;                  /**< Device bus */
161         uint8_t devid;                /**< Device ID */
162         uint8_t function;             /**< Device function. */
163
164         uint16_t group_id;            /**< Group ID */
165         uint32_t core_id;             /**< core ID to bind for kernel thread */
166
167         __extension__
168         uint8_t force_bind : 1;       /**< Flag for kernel thread binding */
169
170         /* mbuf size */
171         unsigned mbuf_size;
172 };
173
174 #define KNI_DEVICE "kni"
175
176 #define RTE_KNI_IOCTL_TEST    _IOWR(0, 1, int)
177 #define RTE_KNI_IOCTL_CREATE  _IOWR(0, 2, struct rte_kni_device_info)
178 #define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info)
179
180 #endif /* _RTE_KNI_COMMON_H_ */