c35828c03234f267a9321a84bb0a22a25e674d51
[dpdk.git] / drivers / net / i40e / i40e_rxtx.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _I40E_RXTX_H_
35 #define _I40E_RXTX_H_
36
37 /**
38  * 32 bits tx flags, high 16 bits for L2TAG1 (VLAN),
39  * low 16 bits for others.
40  */
41 #define I40E_TX_FLAG_L2TAG1_SHIFT 16
42 #define I40E_TX_FLAG_L2TAG1_MASK  0xffff0000
43 #define I40E_TX_FLAG_CSUM         ((uint32_t)(1 << 0))
44 #define I40E_TX_FLAG_INSERT_VLAN  ((uint32_t)(1 << 1))
45 #define I40E_TX_FLAG_TSYN         ((uint32_t)(1 << 2))
46
47 #define RTE_PMD_I40E_RX_MAX_BURST 32
48 #define RTE_PMD_I40E_TX_MAX_BURST 32
49
50 #define RTE_I40E_VPMD_RX_BURST        32
51 #define RTE_I40E_VPMD_TX_BURST        32
52 #define RTE_I40E_RXQ_REARM_THRESH      32
53 #define RTE_I40E_MAX_RX_BURST          RTE_I40E_RXQ_REARM_THRESH
54 #define RTE_I40E_TX_MAX_FREE_BUF_SZ    64
55 #define RTE_I40E_DESCS_PER_LOOP    4
56
57 #define I40E_RXBUF_SZ_1024 1024
58 #define I40E_RXBUF_SZ_2048 2048
59
60 #undef container_of
61 #define container_of(ptr, type, member) ({ \
62                 typeof(((type *)0)->member)(*__mptr) = (ptr); \
63                 (type *)((char *)__mptr - offsetof(type, member)); })
64
65 #define I40E_TD_CMD (I40E_TX_DESC_CMD_ICRC |\
66                      I40E_TX_DESC_CMD_EOP)
67
68 enum i40e_header_split_mode {
69         i40e_header_split_none = 0,
70         i40e_header_split_enabled = 1,
71         i40e_header_split_always = 2,
72         i40e_header_split_reserved
73 };
74
75 #define I40E_HEADER_SPLIT_NONE    ((uint8_t)0)
76 #define I40E_HEADER_SPLIT_L2      ((uint8_t)(1 << 0))
77 #define I40E_HEADER_SPLIT_IP      ((uint8_t)(1 << 1))
78 #define I40E_HEADER_SPLIT_UDP_TCP ((uint8_t)(1 << 2))
79 #define I40E_HEADER_SPLIT_SCTP    ((uint8_t)(1 << 3))
80 #define I40E_HEADER_SPLIT_ALL (I40E_HEADER_SPLIT_L2 | \
81                                I40E_HEADER_SPLIT_IP | \
82                                I40E_HEADER_SPLIT_UDP_TCP | \
83                                I40E_HEADER_SPLIT_SCTP)
84
85 /* HW desc structure, both 16-byte and 32-byte types are supported */
86 #ifdef RTE_LIBRTE_I40E_16BYTE_RX_DESC
87 #define i40e_rx_desc i40e_16byte_rx_desc
88 #else
89 #define i40e_rx_desc i40e_32byte_rx_desc
90 #endif
91
92 struct i40e_rx_entry {
93         struct rte_mbuf *mbuf;
94 };
95
96 /*
97  * Structure associated with each RX queue.
98  */
99 struct i40e_rx_queue {
100         struct rte_mempool *mp; /**< mbuf pool to populate RX ring */
101         volatile union i40e_rx_desc *rx_ring;/**< RX ring virtual address */
102         uint64_t rx_ring_phys_addr; /**< RX ring DMA address */
103         struct i40e_rx_entry *sw_ring; /**< address of RX soft ring */
104         uint16_t nb_rx_desc; /**< number of RX descriptors */
105         uint16_t rx_free_thresh; /**< max free RX desc to hold */
106         uint16_t rx_tail; /**< current value of tail */
107         uint16_t nb_rx_hold; /**< number of held free RX desc */
108         struct rte_mbuf *pkt_first_seg; /**< first segment of current packet */
109         struct rte_mbuf *pkt_last_seg; /**< last segment of current packet */
110 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
111         uint16_t rx_nb_avail; /**< number of staged packets ready */
112         uint16_t rx_next_avail; /**< index of next staged packets */
113         uint16_t rx_free_trigger; /**< triggers rx buffer allocation */
114         struct rte_mbuf fake_mbuf; /**< dummy mbuf */
115         struct rte_mbuf *rx_stage[RTE_PMD_I40E_RX_MAX_BURST * 2];
116 #endif
117
118         uint16_t rxrearm_nb;    /**< number of remaining to be re-armed */
119         uint16_t rxrearm_start; /**< the idx we start the re-arming from */
120         uint64_t mbuf_initializer; /**< value to init mbufs */
121
122         uint8_t port_id; /**< device port ID */
123         uint8_t crc_len; /**< 0 if CRC stripped, 4 otherwise */
124         uint16_t queue_id; /**< RX queue index */
125         uint16_t reg_idx; /**< RX queue register index */
126         uint8_t drop_en; /**< if not 0, set register bit */
127         volatile uint8_t *qrx_tail; /**< register address of tail */
128         struct i40e_vsi *vsi; /**< the VSI this queue belongs to */
129         uint16_t rx_buf_len; /* The packet buffer size */
130         uint16_t rx_hdr_len; /* The header buffer size */
131         uint16_t max_pkt_len; /* Maximum packet length */
132         uint8_t hs_mode; /* Header Split mode */
133         bool q_set; /**< indicate if rx queue has been configured */
134         bool rx_deferred_start; /**< don't start this queue in dev start */
135         uint16_t rx_using_sse; /**<flag indicate the usage of vPMD for rx */
136         uint8_t dcb_tc;         /**< Traffic class of rx queue */
137 };
138
139 struct i40e_tx_entry {
140         struct rte_mbuf *mbuf;
141         uint16_t next_id;
142         uint16_t last_id;
143 };
144
145 /*
146  * Structure associated with each TX queue.
147  */
148 struct i40e_tx_queue {
149         uint16_t nb_tx_desc; /**< number of TX descriptors */
150         uint64_t tx_ring_phys_addr; /**< TX ring DMA address */
151         volatile struct i40e_tx_desc *tx_ring; /**< TX ring virtual address */
152         struct i40e_tx_entry *sw_ring; /**< virtual address of SW ring */
153         uint16_t tx_tail; /**< current value of tail register */
154         volatile uint8_t *qtx_tail; /**< register address of tail */
155         uint16_t nb_tx_used; /**< number of TX desc used since RS bit set */
156         /**< index to last TX descriptor to have been cleaned */
157         uint16_t last_desc_cleaned;
158         /**< Total number of TX descriptors ready to be allocated. */
159         uint16_t nb_tx_free;
160         /**< Start freeing TX buffers if there are less free descriptors than
161              this value. */
162         uint16_t tx_free_thresh;
163         /** Number of TX descriptors to use before RS bit is set. */
164         uint16_t tx_rs_thresh;
165         uint8_t pthresh; /**< Prefetch threshold register. */
166         uint8_t hthresh; /**< Host threshold register. */
167         uint8_t wthresh; /**< Write-back threshold reg. */
168         uint8_t port_id; /**< Device port identifier. */
169         uint16_t queue_id; /**< TX queue index. */
170         uint16_t reg_idx;
171         uint32_t txq_flags;
172         struct i40e_vsi *vsi; /**< the VSI this queue belongs to */
173         uint16_t tx_next_dd;
174         uint16_t tx_next_rs;
175         bool q_set; /**< indicate if tx queue has been configured */
176         bool tx_deferred_start; /**< don't start this queue in dev start */
177         uint8_t dcb_tc;         /**< Traffic class of tx queue */
178 };
179
180 /** Offload features */
181 union i40e_tx_offload {
182         uint64_t data;
183         struct {
184                 uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
185                 uint64_t l3_len:9; /**< L3 (IP) Header Length. */
186                 uint64_t l4_len:8; /**< L4 Header Length. */
187                 uint64_t tso_segsz:16; /**< TCP TSO segment size */
188                 uint64_t outer_l2_len:8; /**< outer L2 Header Length */
189                 uint64_t outer_l3_len:16; /**< outer L3 Header Length */
190         };
191 };
192
193 int i40e_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
194 int i40e_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
195 int i40e_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
196 int i40e_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
197 int i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
198                             uint16_t queue_idx,
199                             uint16_t nb_desc,
200                             unsigned int socket_id,
201                             const struct rte_eth_rxconf *rx_conf,
202                             struct rte_mempool *mp);
203 int i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
204                             uint16_t queue_idx,
205                             uint16_t nb_desc,
206                             unsigned int socket_id,
207                             const struct rte_eth_txconf *tx_conf);
208 void i40e_dev_rx_queue_release(void *rxq);
209 void i40e_dev_tx_queue_release(void *txq);
210 uint16_t i40e_recv_pkts(void *rx_queue,
211                         struct rte_mbuf **rx_pkts,
212                         uint16_t nb_pkts);
213 uint16_t i40e_recv_scattered_pkts(void *rx_queue,
214                                   struct rte_mbuf **rx_pkts,
215                                   uint16_t nb_pkts);
216 uint16_t i40e_xmit_pkts(void *tx_queue,
217                         struct rte_mbuf **tx_pkts,
218                         uint16_t nb_pkts);
219 int i40e_tx_queue_init(struct i40e_tx_queue *txq);
220 int i40e_rx_queue_init(struct i40e_rx_queue *rxq);
221 void i40e_free_tx_resources(struct i40e_tx_queue *txq);
222 void i40e_free_rx_resources(struct i40e_rx_queue *rxq);
223 void i40e_dev_clear_queues(struct rte_eth_dev *dev);
224 void i40e_dev_free_queues(struct rte_eth_dev *dev);
225 void i40e_reset_rx_queue(struct i40e_rx_queue *rxq);
226 void i40e_reset_tx_queue(struct i40e_tx_queue *txq);
227 void i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq);
228 int i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue *rxq);
229 void i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq);
230
231 uint32_t i40e_dev_rx_queue_count(struct rte_eth_dev *dev,
232                                  uint16_t rx_queue_id);
233 int i40e_dev_rx_descriptor_done(void *rx_queue, uint16_t offset);
234
235 uint16_t i40e_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
236                             uint16_t nb_pkts);
237 uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue,
238                                       struct rte_mbuf **rx_pkts,
239                                       uint16_t nb_pkts);
240 int i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev);
241 int i40e_rxq_vec_setup(struct i40e_rx_queue *rxq);
242 int i40e_txq_vec_setup(struct i40e_tx_queue *txq);
243 void i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue *rxq);
244 uint16_t i40e_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
245                             uint16_t nb_pkts);
246 void i40e_set_rx_function(struct rte_eth_dev *dev);
247 void i40e_set_tx_function_flag(struct rte_eth_dev *dev,
248                                struct i40e_tx_queue *txq);
249 void i40e_set_tx_function(struct rte_eth_dev *dev);
250
251 #endif /* _I40E_RXTX_H_ */