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