Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <stdlib.h>
7 : : #include <string.h>
8 : : #include <errno.h>
9 : : #include <stdint.h>
10 : : #include <stdarg.h>
11 : : #include <unistd.h>
12 : : #include <inttypes.h>
13 : : #include <sys/queue.h>
14 : :
15 : : #include <rte_string_fns.h>
16 : : #include <rte_memzone.h>
17 : : #include <rte_mbuf.h>
18 : : #include <rte_malloc.h>
19 : : #include <rte_ether.h>
20 : : #include <ethdev_driver.h>
21 : : #include <rte_tcp.h>
22 : : #include <rte_sctp.h>
23 : : #include <rte_udp.h>
24 : : #include <rte_ip.h>
25 : : #include <rte_net.h>
26 : : #include <rte_vect.h>
27 : :
28 : : #include "i40e_logs.h"
29 : : #include "base/i40e_prototype.h"
30 : : #include "base/i40e_type.h"
31 : : #include "i40e_ethdev.h"
32 : : #include "i40e_rxtx.h"
33 : :
34 : : #define DEFAULT_TX_RS_THRESH 32
35 : : #define DEFAULT_TX_FREE_THRESH 32
36 : :
37 : : #define I40E_TX_MAX_BURST 32
38 : :
39 : : #define I40E_DMA_MEM_ALIGN 4096
40 : :
41 : : /* Base address of the HW descriptor ring should be 128B aligned. */
42 : : #define I40E_RING_BASE_ALIGN 128
43 : :
44 : : #define I40E_TXD_CMD (I40E_TX_DESC_CMD_EOP | I40E_TX_DESC_CMD_RS)
45 : :
46 : : #ifdef RTE_LIBRTE_IEEE1588
47 : : #define I40E_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
48 : : #else
49 : : #define I40E_TX_IEEE1588_TMST 0
50 : : #endif
51 : :
52 : : #define I40E_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_IP_CKSUM | \
53 : : RTE_MBUF_F_TX_L4_MASK | \
54 : : RTE_MBUF_F_TX_TCP_SEG | \
55 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM)
56 : :
57 : : #define I40E_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_IPV4 | \
58 : : RTE_MBUF_F_TX_OUTER_IPV6 | \
59 : : RTE_MBUF_F_TX_IPV4 | \
60 : : RTE_MBUF_F_TX_IPV6 | \
61 : : RTE_MBUF_F_TX_IP_CKSUM | \
62 : : RTE_MBUF_F_TX_L4_MASK | \
63 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
64 : : RTE_MBUF_F_TX_TCP_SEG | \
65 : : RTE_MBUF_F_TX_QINQ | \
66 : : RTE_MBUF_F_TX_VLAN | \
67 : : RTE_MBUF_F_TX_TUNNEL_MASK | \
68 : : RTE_MBUF_F_TX_OUTER_UDP_CKSUM | \
69 : : I40E_TX_IEEE1588_TMST)
70 : :
71 : : #define I40E_TX_OFFLOAD_NOTSUP_MASK \
72 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ I40E_TX_OFFLOAD_MASK)
73 : :
74 : : #define I40E_TX_OFFLOAD_SIMPLE_SUP_MASK (RTE_MBUF_F_TX_IPV4 | \
75 : : RTE_MBUF_F_TX_IPV6 | \
76 : : RTE_MBUF_F_TX_OUTER_IPV4 | \
77 : : RTE_MBUF_F_TX_OUTER_IPV6)
78 : :
79 : : #define I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK \
80 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ I40E_TX_OFFLOAD_SIMPLE_SUP_MASK)
81 : :
82 : : static int
83 : 0 : i40e_monitor_callback(const uint64_t value,
84 : : const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
85 : : {
86 : : const uint64_t m = rte_cpu_to_le_64(1 << I40E_RX_DESC_STATUS_DD_SHIFT);
87 : : /*
88 : : * we expect the DD bit to be set to 1 if this descriptor was already
89 : : * written to.
90 : : */
91 [ # # ]: 0 : return (value & m) == m ? -1 : 0;
92 : : }
93 : :
94 : : int
95 : 0 : i40e_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
96 : : {
97 : : struct i40e_rx_queue *rxq = rx_queue;
98 : : volatile union i40e_rx_desc *rxdp;
99 : : uint16_t desc;
100 : :
101 : 0 : desc = rxq->rx_tail;
102 : 0 : rxdp = &rxq->rx_ring[desc];
103 : : /* watch for changes in status bit */
104 : 0 : pmc->addr = &rxdp->wb.qword1.status_error_len;
105 : :
106 : : /* comparison callback */
107 : 0 : pmc->fn = i40e_monitor_callback;
108 : :
109 : : /* registers are 64-bit */
110 : 0 : pmc->size = sizeof(uint64_t);
111 : :
112 : 0 : return 0;
113 : : }
114 : :
115 : : static inline void
116 : : i40e_rxd_to_vlan_tci(struct rte_mbuf *mb, volatile union i40e_rx_desc *rxdp)
117 : : {
118 : 0 : if (rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
119 : : (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
120 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
121 : 0 : mb->vlan_tci =
122 : 0 : rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1);
123 : : PMD_RX_LOG(DEBUG, "Descriptor l2tag1: %u",
124 : : rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1));
125 : : } else {
126 : 0 : mb->vlan_tci = 0;
127 : : }
128 : : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
129 [ # # # # : 0 : if (rte_le_to_cpu_16(rxdp->wb.qword2.ext_status) &
# # ]
130 : : (1 << I40E_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT)) {
131 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_QINQ_STRIPPED | RTE_MBUF_F_RX_QINQ |
132 : : RTE_MBUF_F_RX_VLAN_STRIPPED | RTE_MBUF_F_RX_VLAN;
133 : 0 : mb->vlan_tci_outer = mb->vlan_tci;
134 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2);
135 : : PMD_RX_LOG(DEBUG, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
136 : : rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_1),
137 : : rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2));
138 : : } else {
139 : 0 : mb->vlan_tci_outer = 0;
140 : : }
141 : : #endif
142 : : PMD_RX_LOG(DEBUG, "Mbuf vlan_tci: %u, vlan_tci_outer: %u",
143 : : mb->vlan_tci, mb->vlan_tci_outer);
144 : : }
145 : :
146 : : /* Translate the rx descriptor status to pkt flags */
147 : : static inline uint64_t
148 : : i40e_rxd_status_to_pkt_flags(uint64_t qword)
149 : : {
150 : : uint64_t flags;
151 : :
152 : : /* Check if RSS_HASH */
153 : 0 : flags = (((qword >> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) &
154 : : I40E_RX_DESC_FLTSTAT_RSS_HASH) ==
155 [ # # # # : 0 : I40E_RX_DESC_FLTSTAT_RSS_HASH) ? RTE_MBUF_F_RX_RSS_HASH : 0;
# # ]
156 : :
157 : : /* Check if FDIR Match */
158 : 0 : flags |= (qword & (1 << I40E_RX_DESC_STATUS_FLM_SHIFT) ?
159 : 0 : RTE_MBUF_F_RX_FDIR : 0);
160 : :
161 : : return flags;
162 : : }
163 : :
164 : : static inline uint64_t
165 : : i40e_rxd_error_to_pkt_flags(uint64_t qword)
166 : : {
167 : : uint64_t flags = 0;
168 : 0 : uint64_t error_bits = (qword >> I40E_RXD_QW1_ERROR_SHIFT);
169 : :
170 : : #define I40E_RX_ERR_BITS 0x3f
171 [ # # # # : 0 : if (likely((error_bits & I40E_RX_ERR_BITS) == 0)) {
# # ]
172 : : flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD);
173 : : return flags;
174 : : }
175 : :
176 [ # # # # : 0 : if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_IPE_SHIFT)))
# # ]
177 : : flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
178 : : else
179 : : flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
180 : :
181 [ # # # # : 0 : if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_L4E_SHIFT)))
# # ]
182 : 0 : flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
183 : : else
184 : 0 : flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
185 : :
186 [ # # # # : 0 : if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_EIPE_SHIFT)))
# # ]
187 : 0 : flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
188 : :
189 : : return flags;
190 : : }
191 : :
192 : : /* Function to check and set the ieee1588 timesync index and get the
193 : : * appropriate flags.
194 : : */
195 : : #ifdef RTE_LIBRTE_IEEE1588
196 : : static inline uint64_t
197 : : i40e_get_iee15888_flags(struct rte_mbuf *mb, uint64_t qword)
198 : : {
199 : : uint64_t pkt_flags = 0;
200 : : uint16_t tsyn = (qword & (I40E_RXD_QW1_STATUS_TSYNVALID_MASK
201 : : | I40E_RXD_QW1_STATUS_TSYNINDX_MASK))
202 : : >> I40E_RX_DESC_STATUS_TSYNINDX_SHIFT;
203 : :
204 : : if ((mb->packet_type & RTE_PTYPE_L2_MASK)
205 : : == RTE_PTYPE_L2_ETHER_TIMESYNC)
206 : : pkt_flags = RTE_MBUF_F_RX_IEEE1588_PTP;
207 : : if (tsyn & 0x04) {
208 : : pkt_flags |= RTE_MBUF_F_RX_IEEE1588_TMST;
209 : : mb->timesync = tsyn & 0x03;
210 : : }
211 : :
212 : : return pkt_flags;
213 : : }
214 : : #endif
215 : :
216 : : static inline uint64_t
217 : : i40e_rxd_build_fdir(volatile union i40e_rx_desc *rxdp, struct rte_mbuf *mb)
218 : : {
219 : : uint64_t flags = 0;
220 : : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
221 : : uint16_t flexbh, flexbl;
222 : :
223 : 0 : flexbh = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
224 : 0 : I40E_RX_DESC_EXT_STATUS_FLEXBH_SHIFT) &
225 : : I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK;
226 : 0 : flexbl = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
227 : 0 : I40E_RX_DESC_EXT_STATUS_FLEXBL_SHIFT) &
228 : : I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK;
229 : :
230 : :
231 [ # # # # : 0 : if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID) {
# # ]
232 : 0 : mb->hash.fdir.hi =
233 : 0 : rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.fd_id);
234 : : flags |= RTE_MBUF_F_RX_FDIR_ID;
235 [ # # # # : 0 : } else if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX) {
# # ]
236 : 0 : mb->hash.fdir.hi =
237 : 0 : rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.flex_bytes_hi);
238 : : flags |= RTE_MBUF_F_RX_FDIR_FLX;
239 : : }
240 [ # # # # : 0 : if (flexbl == I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX) {
# # ]
241 : 0 : mb->hash.fdir.lo =
242 : 0 : rte_le_to_cpu_32(rxdp->wb.qword3.lo_dword.flex_bytes_lo);
243 : 0 : flags |= RTE_MBUF_F_RX_FDIR_FLX;
244 : : }
245 : : #else
246 : : mb->hash.fdir.hi =
247 : : rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.fd_id);
248 : : flags |= RTE_MBUF_F_RX_FDIR_ID;
249 : : #endif
250 : : return flags;
251 : : }
252 : :
253 : : static inline void
254 : 0 : i40e_parse_tunneling_params(uint64_t ol_flags,
255 : : union i40e_tx_offload tx_offload,
256 : : uint32_t *cd_tunneling)
257 : : {
258 : : /* EIPT: External (outer) IP header type */
259 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM)
260 : 0 : *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4;
261 [ # # ]: 0 : else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4)
262 : 0 : *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM;
263 [ # # ]: 0 : else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV6)
264 : 0 : *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV6;
265 : :
266 : : /* EIPLEN: External (outer) IP header length, in DWords */
267 : 0 : *cd_tunneling |= (tx_offload.outer_l3_len >> 2) <<
268 : : I40E_TXD_CTX_QW0_EXT_IPLEN_SHIFT;
269 : :
270 : : /* L4TUNT: L4 Tunneling Type */
271 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
272 : : case RTE_MBUF_F_TX_TUNNEL_IPIP:
273 : : /* for non UDP / GRE tunneling, set to 00b */
274 : : break;
275 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
276 : : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
277 : 0 : *cd_tunneling |= I40E_TXD_CTX_UDP_TUNNELING;
278 : 0 : break;
279 : 0 : case RTE_MBUF_F_TX_TUNNEL_GRE:
280 : 0 : *cd_tunneling |= I40E_TXD_CTX_GRE_TUNNELING;
281 : 0 : break;
282 : : default:
283 : : PMD_TX_LOG(ERR, "Tunnel type not supported");
284 : : return;
285 : : }
286 : :
287 : : /* L4TUNLEN: L4 Tunneling Length, in Words
288 : : *
289 : : * We depend on app to set rte_mbuf.l2_len correctly.
290 : : * For IP in GRE it should be set to the length of the GRE
291 : : * header;
292 : : * for MAC in GRE or MAC in UDP it should be set to the length
293 : : * of the GRE or UDP headers plus the inner MAC up to including
294 : : * its last Ethertype.
295 : : */
296 : 0 : *cd_tunneling |= (tx_offload.l2_len >> 1) <<
297 : : I40E_TXD_CTX_QW0_NATLEN_SHIFT;
298 : : }
299 : :
300 : : static inline void
301 : 0 : i40e_txd_enable_checksum(uint64_t ol_flags,
302 : : uint32_t *td_cmd,
303 : : uint32_t *td_offset,
304 : : union i40e_tx_offload tx_offload)
305 : : {
306 : : /* Set MACLEN */
307 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK))
308 : 0 : *td_offset |= (tx_offload.l2_len >> 1)
309 : 0 : << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
310 : :
311 : : /* Enable L3 checksum offloads */
312 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
313 : 0 : *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4_CSUM;
314 : 0 : *td_offset |= (tx_offload.l3_len >> 2)
315 : 0 : << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
316 [ # # ]: 0 : } else if (ol_flags & RTE_MBUF_F_TX_IPV4) {
317 : 0 : *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4;
318 : 0 : *td_offset |= (tx_offload.l3_len >> 2)
319 : 0 : << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
320 [ # # ]: 0 : } else if (ol_flags & RTE_MBUF_F_TX_IPV6) {
321 : 0 : *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV6;
322 : 0 : *td_offset |= (tx_offload.l3_len >> 2)
323 : 0 : << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
324 : : }
325 : :
326 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
327 : 0 : *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
328 : 0 : *td_offset |= (tx_offload.l4_len >> 2)
329 : 0 : << I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
330 : 0 : return;
331 : : }
332 : :
333 : : /* Enable L4 checksum offloads */
334 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
335 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
336 : 0 : *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
337 : 0 : *td_offset |= (sizeof(struct rte_tcp_hdr) >> 2) <<
338 : : I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
339 : 0 : break;
340 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
341 : 0 : *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_SCTP;
342 : 0 : *td_offset |= (sizeof(struct rte_sctp_hdr) >> 2) <<
343 : : I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
344 : 0 : break;
345 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
346 : 0 : *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_UDP;
347 : 0 : *td_offset |= (sizeof(struct rte_udp_hdr) >> 2) <<
348 : : I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
349 : 0 : break;
350 : : default:
351 : : break;
352 : : }
353 : : }
354 : :
355 : : /* Construct the tx flags */
356 : : static inline uint64_t
357 : : i40e_build_ctob(uint32_t td_cmd,
358 : : uint32_t td_offset,
359 : : unsigned int size,
360 : : uint32_t td_tag)
361 : : {
362 : 0 : return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
363 : : ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
364 : : ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
365 : : ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
366 : : ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
367 : : }
368 : :
369 : : static inline int
370 : 0 : i40e_xmit_cleanup(struct i40e_tx_queue *txq)
371 : : {
372 : 0 : struct i40e_tx_entry *sw_ring = txq->sw_ring;
373 : 0 : volatile struct i40e_tx_desc *txd = txq->tx_ring;
374 : 0 : uint16_t last_desc_cleaned = txq->last_desc_cleaned;
375 : 0 : uint16_t nb_tx_desc = txq->nb_tx_desc;
376 : : uint16_t desc_to_clean_to;
377 : : uint16_t nb_tx_to_clean;
378 : :
379 : 0 : desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
380 [ # # ]: 0 : if (desc_to_clean_to >= nb_tx_desc)
381 : 0 : desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
382 : :
383 : 0 : desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
384 [ # # ]: 0 : if ((txd[desc_to_clean_to].cmd_type_offset_bsz &
385 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
386 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE)) {
387 : : PMD_TX_LOG(DEBUG, "TX descriptor %4u is not done "
388 : : "(port=%d queue=%d)", desc_to_clean_to,
389 : : txq->port_id, txq->queue_id);
390 : : return -1;
391 : : }
392 : :
393 [ # # ]: 0 : if (last_desc_cleaned > desc_to_clean_to)
394 : 0 : nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
395 : : desc_to_clean_to);
396 : : else
397 : 0 : nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
398 : : last_desc_cleaned);
399 : :
400 : 0 : txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
401 : :
402 : 0 : txq->last_desc_cleaned = desc_to_clean_to;
403 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
404 : :
405 : 0 : return 0;
406 : : }
407 : :
408 : : static inline int
409 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
410 : 0 : check_rx_burst_bulk_alloc_preconditions(struct i40e_rx_queue *rxq)
411 : : #else
412 : : check_rx_burst_bulk_alloc_preconditions(__rte_unused struct i40e_rx_queue *rxq)
413 : : #endif
414 : : {
415 : : int ret = 0;
416 : :
417 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
418 [ # # ]: 0 : if (!(rxq->rx_free_thresh >= RTE_PMD_I40E_RX_MAX_BURST)) {
419 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
420 : : "rxq->rx_free_thresh=%d, "
421 : : "RTE_PMD_I40E_RX_MAX_BURST=%d",
422 : : rxq->rx_free_thresh, RTE_PMD_I40E_RX_MAX_BURST);
423 : : ret = -EINVAL;
424 [ # # ]: 0 : } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
425 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
426 : : "rxq->rx_free_thresh=%d, "
427 : : "rxq->nb_rx_desc=%d",
428 : : rxq->rx_free_thresh, rxq->nb_rx_desc);
429 : : ret = -EINVAL;
430 [ # # ]: 0 : } else if (rxq->nb_rx_desc % rxq->rx_free_thresh != 0) {
431 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
432 : : "rxq->nb_rx_desc=%d, "
433 : : "rxq->rx_free_thresh=%d",
434 : : rxq->nb_rx_desc, rxq->rx_free_thresh);
435 : : ret = -EINVAL;
436 : : }
437 : : #else
438 : : ret = -EINVAL;
439 : : #endif
440 : :
441 : 0 : return ret;
442 : : }
443 : :
444 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
445 : : #define I40E_LOOK_AHEAD 8
446 : : #if (I40E_LOOK_AHEAD != 8)
447 : : #error "PMD I40E: I40E_LOOK_AHEAD must be 8\n"
448 : : #endif
449 : : static inline int
450 : 0 : i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
451 : : {
452 : : volatile union i40e_rx_desc *rxdp;
453 : : struct i40e_rx_entry *rxep;
454 : : struct rte_mbuf *mb;
455 : : uint16_t pkt_len;
456 : : uint64_t qword1;
457 : : uint32_t rx_status;
458 : : int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
459 : : int32_t i, j, nb_rx = 0;
460 : : uint64_t pkt_flags;
461 : 0 : uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
462 : :
463 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
464 : 0 : rxep = &rxq->sw_ring[rxq->rx_tail];
465 : :
466 : 0 : qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
467 : 0 : rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
468 : : I40E_RXD_QW1_STATUS_SHIFT;
469 : :
470 : : /* Make sure there is at least 1 packet to receive */
471 [ # # ]: 0 : if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
472 : : return 0;
473 : :
474 : : /**
475 : : * Scan LOOK_AHEAD descriptors at a time to determine which
476 : : * descriptors reference packets that are ready to be received.
477 : : */
478 [ # # ]: 0 : for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; i+=I40E_LOOK_AHEAD,
479 : 0 : rxdp += I40E_LOOK_AHEAD, rxep += I40E_LOOK_AHEAD) {
480 : : /* Read desc statuses backwards to avoid race condition */
481 [ # # ]: 0 : for (j = I40E_LOOK_AHEAD - 1; j >= 0; j--) {
482 : 0 : qword1 = rte_le_to_cpu_64(\
483 : : rxdp[j].wb.qword1.status_error_len);
484 : 0 : s[j] = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
485 : : I40E_RXD_QW1_STATUS_SHIFT;
486 : : }
487 : :
488 : : /* This barrier is to order loads of different words in the descriptor */
489 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
490 : :
491 : : /* Compute how many status bits were set */
492 [ # # ]: 0 : for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
493 : 0 : var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
494 : : #ifdef RTE_ARCH_ARM
495 : : /* For Arm platforms, only compute continuous status bits */
496 : : if (var)
497 : : nb_dd += 1;
498 : : else
499 : : break;
500 : : #else
501 : 0 : nb_dd += var;
502 : : #endif
503 : : }
504 : :
505 : 0 : nb_rx += nb_dd;
506 : :
507 : : /* Translate descriptor info to mbuf parameters */
508 [ # # ]: 0 : for (j = 0; j < nb_dd; j++) {
509 : 0 : mb = rxep[j].mbuf;
510 : 0 : qword1 = rte_le_to_cpu_64(\
511 : : rxdp[j].wb.qword1.status_error_len);
512 : 0 : pkt_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
513 : 0 : I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
514 : 0 : mb->data_len = pkt_len;
515 : 0 : mb->pkt_len = pkt_len;
516 [ # # ]: 0 : mb->ol_flags = 0;
517 : : i40e_rxd_to_vlan_tci(mb, &rxdp[j]);
518 : : pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
519 : 0 : pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
520 : 0 : mb->packet_type =
521 : 0 : ptype_tbl[(uint8_t)((qword1 &
522 : 0 : I40E_RXD_QW1_PTYPE_MASK) >>
523 : : I40E_RXD_QW1_PTYPE_SHIFT)];
524 [ # # ]: 0 : if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
525 : 0 : mb->hash.rss = rte_le_to_cpu_32(\
526 : : rxdp[j].wb.qword0.hi_dword.rss);
527 [ # # ]: 0 : if (pkt_flags & RTE_MBUF_F_RX_FDIR)
528 : 0 : pkt_flags |= i40e_rxd_build_fdir(&rxdp[j], mb);
529 : :
530 : : #ifdef RTE_LIBRTE_IEEE1588
531 : : pkt_flags |= i40e_get_iee15888_flags(mb, qword1);
532 : : #endif
533 : 0 : mb->ol_flags |= pkt_flags;
534 : :
535 : : }
536 : :
537 [ # # ]: 0 : for (j = 0; j < I40E_LOOK_AHEAD; j++)
538 : 0 : rxq->rx_stage[i + j] = rxep[j].mbuf;
539 : :
540 [ # # ]: 0 : if (nb_dd != I40E_LOOK_AHEAD)
541 : : break;
542 : : }
543 : :
544 : : /* Clear software ring entries */
545 [ # # ]: 0 : for (i = 0; i < nb_rx; i++)
546 : 0 : rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
547 : :
548 : : return nb_rx;
549 : : }
550 : :
551 : : static inline uint16_t
552 : : i40e_rx_fill_from_stage(struct i40e_rx_queue *rxq,
553 : : struct rte_mbuf **rx_pkts,
554 : : uint16_t nb_pkts)
555 : : {
556 : : uint16_t i;
557 : 0 : struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
558 : :
559 : 0 : nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
560 : :
561 [ # # # # ]: 0 : for (i = 0; i < nb_pkts; i++)
562 : 0 : rx_pkts[i] = stage[i];
563 : :
564 : 0 : rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
565 : 0 : rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
566 : :
567 : : return nb_pkts;
568 : : }
569 : :
570 : : static inline int
571 : 0 : i40e_rx_alloc_bufs(struct i40e_rx_queue *rxq)
572 : : {
573 : : volatile union i40e_rx_desc *rxdp;
574 : : struct i40e_rx_entry *rxep;
575 : : struct rte_mbuf *mb;
576 : : uint16_t alloc_idx, i;
577 : : uint64_t dma_addr;
578 : : int diag;
579 : :
580 : : /* Allocate buffers in bulk */
581 : 0 : alloc_idx = (uint16_t)(rxq->rx_free_trigger -
582 : 0 : (rxq->rx_free_thresh - 1));
583 : 0 : rxep = &(rxq->sw_ring[alloc_idx]);
584 [ # # ]: 0 : diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
585 : : rxq->rx_free_thresh);
586 [ # # ]: 0 : if (unlikely(diag != 0)) {
587 : 0 : PMD_DRV_LOG(ERR, "Failed to get mbufs in bulk");
588 : 0 : return -ENOMEM;
589 : : }
590 : :
591 : 0 : rxdp = &rxq->rx_ring[alloc_idx];
592 [ # # ]: 0 : for (i = 0; i < rxq->rx_free_thresh; i++) {
593 [ # # ]: 0 : if (likely(i < (rxq->rx_free_thresh - 1)))
594 : : /* Prefetch next mbuf */
595 : 0 : rte_prefetch0(rxep[i + 1].mbuf);
596 : :
597 : 0 : mb = rxep[i].mbuf;
598 : : rte_mbuf_refcnt_set(mb, 1);
599 : 0 : mb->next = NULL;
600 : 0 : mb->data_off = RTE_PKTMBUF_HEADROOM;
601 : 0 : mb->nb_segs = 1;
602 : 0 : mb->port = rxq->port_id;
603 : : dma_addr = rte_cpu_to_le_64(\
604 : : rte_mbuf_data_iova_default(mb));
605 : 0 : rxdp[i].read.hdr_addr = 0;
606 : 0 : rxdp[i].read.pkt_addr = dma_addr;
607 : : }
608 : :
609 : : /* Update rx tail register */
610 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_free_trigger);
611 : :
612 : 0 : rxq->rx_free_trigger =
613 : 0 : (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
614 [ # # ]: 0 : if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
615 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
616 : :
617 : : return 0;
618 : : }
619 : :
620 : : static inline uint16_t
621 : 0 : rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
622 : : {
623 : : struct i40e_rx_queue *rxq = (struct i40e_rx_queue *)rx_queue;
624 : : struct rte_eth_dev *dev;
625 : : uint16_t nb_rx = 0;
626 : :
627 [ # # ]: 0 : if (!nb_pkts)
628 : : return 0;
629 : :
630 [ # # ]: 0 : if (rxq->rx_nb_avail)
631 : 0 : return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
632 : :
633 : 0 : nb_rx = (uint16_t)i40e_rx_scan_hw_ring(rxq);
634 : 0 : rxq->rx_next_avail = 0;
635 : 0 : rxq->rx_nb_avail = nb_rx;
636 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
637 : :
638 [ # # ]: 0 : if (rxq->rx_tail > rxq->rx_free_trigger) {
639 [ # # ]: 0 : if (i40e_rx_alloc_bufs(rxq) != 0) {
640 : : uint16_t i, j;
641 : :
642 : 0 : dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
643 : 0 : dev->data->rx_mbuf_alloc_failed +=
644 : 0 : rxq->rx_free_thresh;
645 : :
646 : 0 : rxq->rx_nb_avail = 0;
647 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
648 [ # # ]: 0 : for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
649 : 0 : rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
650 : :
651 : : return 0;
652 : : }
653 : : }
654 : :
655 [ # # ]: 0 : if (rxq->rx_tail >= rxq->nb_rx_desc)
656 : 0 : rxq->rx_tail = 0;
657 : :
658 [ # # ]: 0 : if (rxq->rx_nb_avail)
659 : 0 : return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
660 : :
661 : : return 0;
662 : : }
663 : :
664 : : static uint16_t
665 : 0 : i40e_recv_pkts_bulk_alloc(void *rx_queue,
666 : : struct rte_mbuf **rx_pkts,
667 : : uint16_t nb_pkts)
668 : : {
669 : : uint16_t nb_rx = 0, n, count;
670 : :
671 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
672 : : return 0;
673 : :
674 [ # # ]: 0 : if (likely(nb_pkts <= RTE_PMD_I40E_RX_MAX_BURST))
675 : 0 : return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
676 : :
677 [ # # ]: 0 : while (nb_pkts) {
678 : 0 : n = RTE_MIN(nb_pkts, RTE_PMD_I40E_RX_MAX_BURST);
679 : 0 : count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
680 : 0 : nb_rx = (uint16_t)(nb_rx + count);
681 : 0 : nb_pkts = (uint16_t)(nb_pkts - count);
682 [ # # ]: 0 : if (count < n)
683 : : break;
684 : : }
685 : :
686 : : return nb_rx;
687 : : }
688 : : #else
689 : : static uint16_t
690 : : i40e_recv_pkts_bulk_alloc(void __rte_unused *rx_queue,
691 : : struct rte_mbuf __rte_unused **rx_pkts,
692 : : uint16_t __rte_unused nb_pkts)
693 : : {
694 : : return 0;
695 : : }
696 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
697 : :
698 : : uint16_t
699 : 0 : i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
700 : : {
701 : : struct i40e_rx_queue *rxq;
702 : : volatile union i40e_rx_desc *rx_ring;
703 : : volatile union i40e_rx_desc *rxdp;
704 : : union i40e_rx_desc rxd;
705 : : struct i40e_rx_entry *sw_ring;
706 : : struct i40e_rx_entry *rxe;
707 : : struct rte_eth_dev *dev;
708 : : struct rte_mbuf *rxm;
709 : : struct rte_mbuf *nmb;
710 : : uint16_t nb_rx;
711 : : uint32_t rx_status;
712 : : uint64_t qword1;
713 : : uint16_t rx_packet_len;
714 : : uint16_t rx_id, nb_hold;
715 : : uint64_t dma_addr;
716 : : uint64_t pkt_flags;
717 : : uint32_t *ptype_tbl;
718 : :
719 : : nb_rx = 0;
720 : : nb_hold = 0;
721 : : rxq = rx_queue;
722 : 0 : rx_id = rxq->rx_tail;
723 : 0 : rx_ring = rxq->rx_ring;
724 : 0 : sw_ring = rxq->sw_ring;
725 : 0 : ptype_tbl = rxq->vsi->adapter->ptype_tbl;
726 : :
727 [ # # ]: 0 : while (nb_rx < nb_pkts) {
728 : 0 : rxdp = &rx_ring[rx_id];
729 : 0 : qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
730 : : rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
731 : 0 : >> I40E_RXD_QW1_STATUS_SHIFT;
732 : :
733 : : /* Check the DD bit first */
734 [ # # ]: 0 : if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
735 : : break;
736 : :
737 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mp);
738 [ # # ]: 0 : if (unlikely(!nmb)) {
739 : 0 : dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
740 : 0 : dev->data->rx_mbuf_alloc_failed++;
741 : 0 : break;
742 : : }
743 : :
744 : : /**
745 : : * Use acquire fence to ensure that qword1 which includes DD
746 : : * bit is loaded before loading of other descriptor words.
747 : : */
748 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
749 : :
750 : 0 : rxd = *rxdp;
751 : 0 : nb_hold++;
752 : 0 : rxe = &sw_ring[rx_id];
753 : 0 : rx_id++;
754 [ # # ]: 0 : if (unlikely(rx_id == rxq->nb_rx_desc))
755 : : rx_id = 0;
756 : :
757 : : /* Prefetch next mbuf */
758 : 0 : rte_prefetch0(sw_ring[rx_id].mbuf);
759 : :
760 : : /**
761 : : * When next RX descriptor is on a cache line boundary,
762 : : * prefetch the next 4 RX descriptors and next 8 pointers
763 : : * to mbufs.
764 : : */
765 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
766 : 0 : rte_prefetch0(&rx_ring[rx_id]);
767 : : rte_prefetch0(&sw_ring[rx_id]);
768 : : }
769 : 0 : rxm = rxe->mbuf;
770 : 0 : rxe->mbuf = nmb;
771 : : dma_addr =
772 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
773 : 0 : rxdp->read.hdr_addr = 0;
774 : 0 : rxdp->read.pkt_addr = dma_addr;
775 : :
776 : 0 : rx_packet_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
777 : 0 : I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
778 : :
779 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
780 : 0 : rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
781 : 0 : rxm->nb_segs = 1;
782 : 0 : rxm->next = NULL;
783 : 0 : rxm->pkt_len = rx_packet_len;
784 : 0 : rxm->data_len = rx_packet_len;
785 : 0 : rxm->port = rxq->port_id;
786 [ # # ]: 0 : rxm->ol_flags = 0;
787 : : i40e_rxd_to_vlan_tci(rxm, &rxd);
788 : : pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
789 : 0 : pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
790 : 0 : rxm->packet_type =
791 : 0 : ptype_tbl[(uint8_t)((qword1 &
792 : 0 : I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
793 [ # # ]: 0 : if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
794 : 0 : rxm->hash.rss =
795 : 0 : rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
796 [ # # ]: 0 : if (pkt_flags & RTE_MBUF_F_RX_FDIR)
797 : 0 : pkt_flags |= i40e_rxd_build_fdir(&rxd, rxm);
798 : :
799 : : #ifdef RTE_LIBRTE_IEEE1588
800 : : pkt_flags |= i40e_get_iee15888_flags(rxm, qword1);
801 : : #endif
802 : 0 : rxm->ol_flags |= pkt_flags;
803 : :
804 : 0 : rx_pkts[nb_rx++] = rxm;
805 : : }
806 : 0 : rxq->rx_tail = rx_id;
807 : :
808 : : /**
809 : : * If the number of free RX descriptors is greater than the RX free
810 : : * threshold of the queue, advance the receive tail register of queue.
811 : : * Update that register with the value of the last processed RX
812 : : * descriptor minus 1.
813 : : */
814 : 0 : nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
815 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
816 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
817 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
818 : 0 : I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
819 : : nb_hold = 0;
820 : : }
821 : 0 : rxq->nb_rx_hold = nb_hold;
822 : :
823 : 0 : return nb_rx;
824 : : }
825 : :
826 : : uint16_t
827 : 0 : i40e_recv_scattered_pkts(void *rx_queue,
828 : : struct rte_mbuf **rx_pkts,
829 : : uint16_t nb_pkts)
830 : : {
831 : : struct i40e_rx_queue *rxq = rx_queue;
832 : 0 : volatile union i40e_rx_desc *rx_ring = rxq->rx_ring;
833 : : volatile union i40e_rx_desc *rxdp;
834 : : union i40e_rx_desc rxd;
835 : 0 : struct i40e_rx_entry *sw_ring = rxq->sw_ring;
836 : : struct i40e_rx_entry *rxe;
837 : 0 : struct rte_mbuf *first_seg = rxq->pkt_first_seg;
838 : 0 : struct rte_mbuf *last_seg = rxq->pkt_last_seg;
839 : : struct rte_mbuf *nmb, *rxm;
840 : 0 : uint16_t rx_id = rxq->rx_tail;
841 : : uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len;
842 : : struct rte_eth_dev *dev;
843 : : uint32_t rx_status;
844 : : uint64_t qword1;
845 : : uint64_t dma_addr;
846 : : uint64_t pkt_flags;
847 : 0 : uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
848 : :
849 [ # # ]: 0 : while (nb_rx < nb_pkts) {
850 : 0 : rxdp = &rx_ring[rx_id];
851 : 0 : qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
852 : 0 : rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
853 : : I40E_RXD_QW1_STATUS_SHIFT;
854 : :
855 : : /* Check the DD bit */
856 [ # # ]: 0 : if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
857 : : break;
858 : :
859 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mp);
860 [ # # ]: 0 : if (unlikely(!nmb)) {
861 : 0 : dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
862 : 0 : dev->data->rx_mbuf_alloc_failed++;
863 : 0 : break;
864 : : }
865 : :
866 : : /**
867 : : * Use acquire fence to ensure that qword1 which includes DD
868 : : * bit is loaded before loading of other descriptor words.
869 : : */
870 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
871 : :
872 : 0 : rxd = *rxdp;
873 : 0 : nb_hold++;
874 : 0 : rxe = &sw_ring[rx_id];
875 : 0 : rx_id++;
876 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
877 : : rx_id = 0;
878 : :
879 : : /* Prefetch next mbuf */
880 : 0 : rte_prefetch0(sw_ring[rx_id].mbuf);
881 : :
882 : : /**
883 : : * When next RX descriptor is on a cache line boundary,
884 : : * prefetch the next 4 RX descriptors and next 8 pointers
885 : : * to mbufs.
886 : : */
887 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
888 : 0 : rte_prefetch0(&rx_ring[rx_id]);
889 : : rte_prefetch0(&sw_ring[rx_id]);
890 : : }
891 : :
892 : 0 : rxm = rxe->mbuf;
893 [ # # ]: 0 : rxe->mbuf = nmb;
894 : : dma_addr =
895 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
896 : :
897 : : /* Set data buffer address and data length of the mbuf */
898 : 0 : rxdp->read.hdr_addr = 0;
899 : 0 : rxdp->read.pkt_addr = dma_addr;
900 : 0 : rx_packet_len = (qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
901 : : I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
902 : 0 : rxm->data_len = rx_packet_len;
903 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
904 : :
905 : : /**
906 : : * If this is the first buffer of the received packet, set the
907 : : * pointer to the first mbuf of the packet and initialize its
908 : : * context. Otherwise, update the total length and the number
909 : : * of segments of the current scattered packet, and update the
910 : : * pointer to the last mbuf of the current packet.
911 : : */
912 [ # # ]: 0 : if (!first_seg) {
913 : : first_seg = rxm;
914 : 0 : first_seg->nb_segs = 1;
915 : 0 : first_seg->pkt_len = rx_packet_len;
916 : : } else {
917 : 0 : first_seg->pkt_len =
918 : 0 : (uint16_t)(first_seg->pkt_len +
919 : : rx_packet_len);
920 : 0 : first_seg->nb_segs++;
921 : 0 : last_seg->next = rxm;
922 : : }
923 : :
924 : : /**
925 : : * If this is not the last buffer of the received packet,
926 : : * update the pointer to the last mbuf of the current scattered
927 : : * packet and continue to parse the RX ring.
928 : : */
929 [ # # ]: 0 : if (!(rx_status & (1 << I40E_RX_DESC_STATUS_EOF_SHIFT))) {
930 : : last_seg = rxm;
931 : 0 : continue;
932 : : }
933 : :
934 : : /**
935 : : * This is the last buffer of the received packet. If the CRC
936 : : * is not stripped by the hardware:
937 : : * - Subtract the CRC length from the total packet length.
938 : : * - If the last buffer only contains the whole CRC or a part
939 : : * of it, free the mbuf associated to the last buffer. If part
940 : : * of the CRC is also contained in the previous mbuf, subtract
941 : : * the length of that CRC part from the data length of the
942 : : * previous mbuf.
943 : : */
944 : 0 : rxm->next = NULL;
945 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
946 : 0 : first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
947 [ # # ]: 0 : if (rx_packet_len <= RTE_ETHER_CRC_LEN) {
948 : : rte_pktmbuf_free_seg(rxm);
949 : 0 : first_seg->nb_segs--;
950 : 0 : last_seg->data_len =
951 : 0 : (uint16_t)(last_seg->data_len -
952 : : (RTE_ETHER_CRC_LEN - rx_packet_len));
953 : 0 : last_seg->next = NULL;
954 : : } else
955 : 0 : rxm->data_len = (uint16_t)(rx_packet_len -
956 : : RTE_ETHER_CRC_LEN);
957 : : }
958 : :
959 : 0 : first_seg->port = rxq->port_id;
960 [ # # ]: 0 : first_seg->ol_flags = 0;
961 : : i40e_rxd_to_vlan_tci(first_seg, &rxd);
962 : : pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
963 : 0 : pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
964 : 0 : first_seg->packet_type =
965 : 0 : ptype_tbl[(uint8_t)((qword1 &
966 : 0 : I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
967 [ # # ]: 0 : if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
968 : 0 : first_seg->hash.rss =
969 : 0 : rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
970 [ # # ]: 0 : if (pkt_flags & RTE_MBUF_F_RX_FDIR)
971 : 0 : pkt_flags |= i40e_rxd_build_fdir(&rxd, first_seg);
972 : :
973 : : #ifdef RTE_LIBRTE_IEEE1588
974 : : pkt_flags |= i40e_get_iee15888_flags(first_seg, qword1);
975 : : #endif
976 : 0 : first_seg->ol_flags |= pkt_flags;
977 : :
978 : : /* Prefetch data of first segment, if configured to do so. */
979 : 0 : rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
980 : : first_seg->data_off));
981 : 0 : rx_pkts[nb_rx++] = first_seg;
982 : : first_seg = NULL;
983 : : }
984 : :
985 : : /* Record index of the next RX descriptor to probe. */
986 : 0 : rxq->rx_tail = rx_id;
987 : 0 : rxq->pkt_first_seg = first_seg;
988 : 0 : rxq->pkt_last_seg = last_seg;
989 : :
990 : : /**
991 : : * If the number of free RX descriptors is greater than the RX free
992 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
993 : : * register. Update the RDT with the value of the last processed RX
994 : : * descriptor minus 1, to guarantee that the RDT register is never
995 : : * equal to the RDH register, which creates a "full" ring situation
996 : : * from the hardware point of view.
997 : : */
998 : 0 : nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
999 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1000 [ # # ]: 0 : rx_id = (uint16_t)(rx_id == 0 ?
1001 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1002 : 0 : I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
1003 : : nb_hold = 0;
1004 : : }
1005 : 0 : rxq->nb_rx_hold = nb_hold;
1006 : :
1007 : 0 : return nb_rx;
1008 : : }
1009 : :
1010 : : /* Check if the context descriptor is needed for TX offloading */
1011 : : static inline uint16_t
1012 : : i40e_calc_context_desc(uint64_t flags)
1013 : : {
1014 : : static uint64_t mask = RTE_MBUF_F_TX_OUTER_IP_CKSUM |
1015 : : RTE_MBUF_F_TX_TCP_SEG |
1016 : : RTE_MBUF_F_TX_QINQ |
1017 : : RTE_MBUF_F_TX_TUNNEL_MASK;
1018 : :
1019 : : #ifdef RTE_LIBRTE_IEEE1588
1020 : : mask |= RTE_MBUF_F_TX_IEEE1588_TMST;
1021 : : #endif
1022 : :
1023 : 0 : return (flags & mask) ? 1 : 0;
1024 : : }
1025 : :
1026 : : /* set i40e TSO context descriptor */
1027 : : static inline uint64_t
1028 : 0 : i40e_set_tso_ctx(struct rte_mbuf *mbuf, union i40e_tx_offload tx_offload)
1029 : : {
1030 : : uint64_t ctx_desc = 0;
1031 : : uint32_t cd_cmd, hdr_len, cd_tso_len;
1032 : :
1033 [ # # ]: 0 : if (!tx_offload.l4_len) {
1034 : 0 : PMD_DRV_LOG(DEBUG, "L4 length set to 0");
1035 : 0 : return ctx_desc;
1036 : : }
1037 : :
1038 : 0 : hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len;
1039 : 0 : hdr_len += (mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
1040 [ # # ]: 0 : tx_offload.outer_l2_len + tx_offload.outer_l3_len : 0;
1041 : :
1042 : : cd_cmd = I40E_TX_CTX_DESC_TSO;
1043 : 0 : cd_tso_len = mbuf->pkt_len - hdr_len;
1044 : 0 : ctx_desc |= ((uint64_t)cd_cmd << I40E_TXD_CTX_QW1_CMD_SHIFT) |
1045 : 0 : ((uint64_t)cd_tso_len <<
1046 : 0 : I40E_TXD_CTX_QW1_TSO_LEN_SHIFT) |
1047 : 0 : ((uint64_t)mbuf->tso_segsz <<
1048 : : I40E_TXD_CTX_QW1_MSS_SHIFT);
1049 : :
1050 : 0 : return ctx_desc;
1051 : : }
1052 : :
1053 : : /* HW requires that Tx buffer size ranges from 1B up to (16K-1)B. */
1054 : : #define I40E_MAX_DATA_PER_TXD \
1055 : : (I40E_TXD_QW1_TX_BUF_SZ_MASK >> I40E_TXD_QW1_TX_BUF_SZ_SHIFT)
1056 : : /* Calculate the number of TX descriptors needed for each pkt */
1057 : : static inline uint16_t
1058 : : i40e_calc_pkt_desc(struct rte_mbuf *tx_pkt)
1059 : : {
1060 : : struct rte_mbuf *txd = tx_pkt;
1061 : : uint16_t count = 0;
1062 : :
1063 [ # # ]: 0 : while (txd != NULL) {
1064 : 0 : count += DIV_ROUND_UP(txd->data_len, I40E_MAX_DATA_PER_TXD);
1065 : 0 : txd = txd->next;
1066 : : }
1067 : :
1068 : : return count;
1069 : : }
1070 : :
1071 : : uint16_t
1072 : 0 : i40e_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1073 : : {
1074 : : struct i40e_tx_queue *txq;
1075 : : struct i40e_tx_entry *sw_ring;
1076 : : struct i40e_tx_entry *txe, *txn;
1077 : : volatile struct i40e_tx_desc *txd;
1078 : : volatile struct i40e_tx_desc *txr;
1079 : : struct rte_mbuf *tx_pkt;
1080 : : struct rte_mbuf *m_seg;
1081 : : uint32_t cd_tunneling_params;
1082 : : uint16_t tx_id;
1083 : : uint16_t nb_tx;
1084 : : uint32_t td_cmd;
1085 : : uint32_t td_offset;
1086 : : uint32_t td_tag;
1087 : : uint64_t ol_flags;
1088 : : uint16_t nb_used;
1089 : : uint16_t nb_ctx;
1090 : : uint16_t tx_last;
1091 : : uint16_t slen;
1092 : : uint64_t buf_dma_addr;
1093 : 0 : union i40e_tx_offload tx_offload = {0};
1094 : :
1095 : : txq = tx_queue;
1096 : 0 : sw_ring = txq->sw_ring;
1097 : 0 : txr = txq->tx_ring;
1098 : 0 : tx_id = txq->tx_tail;
1099 : 0 : txe = &sw_ring[tx_id];
1100 : :
1101 : : /* Check if the descriptor ring needs to be cleaned. */
1102 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
1103 : 0 : (void)i40e_xmit_cleanup(txq);
1104 : :
1105 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1106 : 0 : td_cmd = 0;
1107 : : td_tag = 0;
1108 : 0 : td_offset = 0;
1109 : :
1110 : 0 : tx_pkt = *tx_pkts++;
1111 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1112 : :
1113 : 0 : ol_flags = tx_pkt->ol_flags;
1114 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
1115 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
1116 : 0 : tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
1117 : 0 : tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
1118 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
1119 : 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
1120 : :
1121 : : /* Calculate the number of context descriptors needed. */
1122 : : nb_ctx = i40e_calc_context_desc(ol_flags);
1123 : :
1124 : : /**
1125 : : * The number of descriptors that must be allocated for
1126 : : * a packet equals to the number of the segments of that
1127 : : * packet plus 1 context descriptor if needed.
1128 : : * Recalculate the needed tx descs when TSO enabled in case
1129 : : * the mbuf data size exceeds max data size that hw allows
1130 : : * per tx desc.
1131 : : */
1132 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
1133 : 0 : nb_used = (uint16_t)(i40e_calc_pkt_desc(tx_pkt) +
1134 : : nb_ctx);
1135 : : else
1136 : 0 : nb_used = (uint16_t)(tx_pkt->nb_segs + nb_ctx);
1137 : 0 : tx_last = (uint16_t)(tx_id + nb_used - 1);
1138 : :
1139 : : /* Circular ring */
1140 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
1141 : 0 : tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1142 : :
1143 [ # # ]: 0 : if (nb_used > txq->nb_tx_free) {
1144 [ # # ]: 0 : if (i40e_xmit_cleanup(txq) != 0) {
1145 [ # # ]: 0 : if (nb_tx == 0)
1146 : : return 0;
1147 : 0 : goto end_of_tx;
1148 : : }
1149 [ # # ]: 0 : if (unlikely(nb_used > txq->tx_rs_thresh)) {
1150 [ # # ]: 0 : while (nb_used > txq->nb_tx_free) {
1151 [ # # ]: 0 : if (i40e_xmit_cleanup(txq) != 0) {
1152 [ # # ]: 0 : if (nb_tx == 0)
1153 : : return 0;
1154 : 0 : goto end_of_tx;
1155 : : }
1156 : : }
1157 : : }
1158 : : }
1159 : :
1160 : : /* Descriptor based VLAN insertion */
1161 [ # # ]: 0 : if (ol_flags & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) {
1162 : 0 : td_cmd |= I40E_TX_DESC_CMD_IL2TAG1;
1163 : 0 : td_tag = tx_pkt->vlan_tci;
1164 : : }
1165 : :
1166 : : /* Always enable CRC offload insertion */
1167 : 0 : td_cmd |= I40E_TX_DESC_CMD_ICRC;
1168 : :
1169 : : /* Fill in tunneling parameters if necessary */
1170 : 0 : cd_tunneling_params = 0;
1171 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
1172 : 0 : td_offset |= (tx_offload.outer_l2_len >> 1)
1173 : 0 : << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
1174 : 0 : i40e_parse_tunneling_params(ol_flags, tx_offload,
1175 : : &cd_tunneling_params);
1176 : : }
1177 : : /* Enable checksum offloading */
1178 [ # # ]: 0 : if (ol_flags & I40E_TX_CKSUM_OFFLOAD_MASK)
1179 : 0 : i40e_txd_enable_checksum(ol_flags, &td_cmd,
1180 : : &td_offset, tx_offload);
1181 : :
1182 [ # # ]: 0 : if (nb_ctx) {
1183 : : /* Setup TX context descriptor if required */
1184 : 0 : volatile struct i40e_tx_context_desc *ctx_txd =
1185 : : (volatile struct i40e_tx_context_desc *)\
1186 : 0 : &txr[tx_id];
1187 : : uint16_t cd_l2tag2 = 0;
1188 : : uint64_t cd_type_cmd_tso_mss =
1189 : : I40E_TX_DESC_DTYPE_CONTEXT;
1190 : :
1191 : 0 : txn = &sw_ring[txe->next_id];
1192 [ # # ]: 0 : RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1193 [ # # ]: 0 : if (txe->mbuf != NULL) {
1194 : : rte_pktmbuf_free_seg(txe->mbuf);
1195 : 0 : txe->mbuf = NULL;
1196 : : }
1197 : :
1198 : : /* TSO enabled means no timestamp */
1199 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
1200 : 0 : cd_type_cmd_tso_mss |=
1201 : 0 : i40e_set_tso_ctx(tx_pkt, tx_offload);
1202 : : else {
1203 : : #ifdef RTE_LIBRTE_IEEE1588
1204 : : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
1205 : : cd_type_cmd_tso_mss |=
1206 : : ((uint64_t)I40E_TX_CTX_DESC_TSYN <<
1207 : : I40E_TXD_CTX_QW1_CMD_SHIFT);
1208 : : #endif
1209 : : }
1210 : :
1211 : 0 : ctx_txd->tunneling_params =
1212 : : rte_cpu_to_le_32(cd_tunneling_params);
1213 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_QINQ) {
1214 : 0 : cd_l2tag2 = tx_pkt->vlan_tci_outer;
1215 : 0 : cd_type_cmd_tso_mss |=
1216 : : ((uint64_t)I40E_TX_CTX_DESC_IL2TAG2 <<
1217 : : I40E_TXD_CTX_QW1_CMD_SHIFT);
1218 : : }
1219 : 0 : ctx_txd->l2tag2 = rte_cpu_to_le_16(cd_l2tag2);
1220 : 0 : ctx_txd->type_cmd_tso_mss =
1221 : : rte_cpu_to_le_64(cd_type_cmd_tso_mss);
1222 : :
1223 : : PMD_TX_LOG(DEBUG, "mbuf: %p, TCD[%u]:\n"
1224 : : "tunneling_params: %#x;\n"
1225 : : "l2tag2: %#hx;\n"
1226 : : "rsvd: %#hx;\n"
1227 : : "type_cmd_tso_mss: %#"PRIx64";\n",
1228 : : tx_pkt, tx_id,
1229 : : ctx_txd->tunneling_params,
1230 : : ctx_txd->l2tag2,
1231 : : ctx_txd->rsvd,
1232 : : ctx_txd->type_cmd_tso_mss);
1233 : :
1234 : 0 : txe->last_id = tx_last;
1235 : 0 : tx_id = txe->next_id;
1236 : : txe = txn;
1237 : : }
1238 : :
1239 : : m_seg = tx_pkt;
1240 : : do {
1241 : 0 : txd = &txr[tx_id];
1242 : 0 : txn = &sw_ring[txe->next_id];
1243 : :
1244 [ # # ]: 0 : if (txe->mbuf)
1245 : : rte_pktmbuf_free_seg(txe->mbuf);
1246 : 0 : txe->mbuf = m_seg;
1247 : :
1248 : : /* Setup TX Descriptor */
1249 : 0 : slen = m_seg->data_len;
1250 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
1251 : :
1252 [ # # ]: 0 : while ((ol_flags & RTE_MBUF_F_TX_TCP_SEG) &&
1253 [ # # ]: 0 : unlikely(slen > I40E_MAX_DATA_PER_TXD)) {
1254 : 0 : txd->buffer_addr =
1255 : : rte_cpu_to_le_64(buf_dma_addr);
1256 : 0 : txd->cmd_type_offset_bsz =
1257 : 0 : i40e_build_ctob(td_cmd,
1258 : : td_offset, I40E_MAX_DATA_PER_TXD,
1259 : : td_tag);
1260 : :
1261 : 0 : buf_dma_addr += I40E_MAX_DATA_PER_TXD;
1262 : 0 : slen -= I40E_MAX_DATA_PER_TXD;
1263 : :
1264 : 0 : txe->last_id = tx_last;
1265 : 0 : tx_id = txe->next_id;
1266 : : txe = txn;
1267 : 0 : txd = &txr[tx_id];
1268 : 0 : txn = &sw_ring[txe->next_id];
1269 : : }
1270 : : PMD_TX_LOG(DEBUG, "mbuf: %p, TDD[%u]:\n"
1271 : : "buf_dma_addr: %#"PRIx64";\n"
1272 : : "td_cmd: %#x;\n"
1273 : : "td_offset: %#x;\n"
1274 : : "td_len: %u;\n"
1275 : : "td_tag: %#x;\n",
1276 : : tx_pkt, tx_id, buf_dma_addr,
1277 : : td_cmd, td_offset, slen, td_tag);
1278 : :
1279 : 0 : txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
1280 : 0 : txd->cmd_type_offset_bsz = i40e_build_ctob(td_cmd,
1281 : : td_offset, slen, td_tag);
1282 : 0 : txe->last_id = tx_last;
1283 : 0 : tx_id = txe->next_id;
1284 : : txe = txn;
1285 : 0 : m_seg = m_seg->next;
1286 [ # # ]: 0 : } while (m_seg != NULL);
1287 : :
1288 : : /* The last packet data descriptor needs End Of Packet (EOP) */
1289 : 0 : td_cmd |= I40E_TX_DESC_CMD_EOP;
1290 : 0 : txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
1291 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
1292 : :
1293 [ # # ]: 0 : if (txq->nb_tx_used >= txq->tx_rs_thresh) {
1294 : : PMD_TX_LOG(DEBUG,
1295 : : "Setting RS bit on TXD id="
1296 : : "%4u (port=%d queue=%d)",
1297 : : tx_last, txq->port_id, txq->queue_id);
1298 : :
1299 : 0 : td_cmd |= I40E_TX_DESC_CMD_RS;
1300 : :
1301 : : /* Update txq RS bit counters */
1302 : 0 : txq->nb_tx_used = 0;
1303 : : }
1304 : :
1305 : 0 : txd->cmd_type_offset_bsz |=
1306 : 0 : rte_cpu_to_le_64(((uint64_t)td_cmd) <<
1307 : : I40E_TXD_QW1_CMD_SHIFT);
1308 : : }
1309 : :
1310 : 0 : end_of_tx:
1311 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1312 : : (unsigned) txq->port_id, (unsigned) txq->queue_id,
1313 : : (unsigned) tx_id, (unsigned) nb_tx);
1314 : :
1315 : 0 : rte_io_wmb();
1316 [ # # ]: 0 : I40E_PCI_REG_WC_WRITE_RELAXED(txq->qtx_tail, tx_id);
1317 : 0 : txq->tx_tail = tx_id;
1318 : :
1319 : 0 : return nb_tx;
1320 : : }
1321 : :
1322 : : static __rte_always_inline int
1323 : : i40e_tx_free_bufs(struct i40e_tx_queue *txq)
1324 : : {
1325 : : struct i40e_tx_entry *txep;
1326 : 0 : uint16_t tx_rs_thresh = txq->tx_rs_thresh;
1327 : : uint16_t i = 0, j = 0;
1328 : : struct rte_mbuf *free[RTE_I40E_TX_MAX_FREE_BUF_SZ];
1329 : 0 : const uint16_t k = RTE_ALIGN_FLOOR(tx_rs_thresh, RTE_I40E_TX_MAX_FREE_BUF_SZ);
1330 : 0 : const uint16_t m = tx_rs_thresh % RTE_I40E_TX_MAX_FREE_BUF_SZ;
1331 : :
1332 [ # # # # ]: 0 : if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz &
1333 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
1334 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1335 : : return 0;
1336 : :
1337 : 0 : txep = &txq->sw_ring[txq->tx_next_dd - (tx_rs_thresh - 1)];
1338 : :
1339 [ # # # # ]: 0 : for (i = 0; i < tx_rs_thresh; i++)
1340 : 0 : rte_prefetch0((txep + i)->mbuf);
1341 : :
1342 [ # # # # ]: 0 : if (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {
1343 [ # # # # ]: 0 : if (k) {
1344 [ # # # # ]: 0 : for (j = 0; j != k; j += RTE_I40E_TX_MAX_FREE_BUF_SZ) {
1345 [ # # # # ]: 0 : for (i = 0; i < RTE_I40E_TX_MAX_FREE_BUF_SZ; ++i, ++txep) {
1346 : 0 : free[i] = txep->mbuf;
1347 : 0 : txep->mbuf = NULL;
1348 : : }
1349 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool, (void **)free,
1350 : : RTE_I40E_TX_MAX_FREE_BUF_SZ);
1351 : : }
1352 : : }
1353 : :
1354 [ # # # # ]: 0 : if (m) {
1355 [ # # # # ]: 0 : for (i = 0; i < m; ++i, ++txep) {
1356 : 0 : free[i] = txep->mbuf;
1357 : 0 : txep->mbuf = NULL;
1358 : : }
1359 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool, (void **)free, m);
1360 : : }
1361 : : } else {
1362 [ # # # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
1363 : 0 : rte_pktmbuf_free_seg(txep->mbuf);
1364 : 0 : txep->mbuf = NULL;
1365 : : }
1366 : : }
1367 : :
1368 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
1369 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
1370 [ # # # # ]: 0 : if (txq->tx_next_dd >= txq->nb_tx_desc)
1371 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
1372 : :
1373 : 0 : return txq->tx_rs_thresh;
1374 : : }
1375 : :
1376 : : /* Populate 4 descriptors with data from 4 mbufs */
1377 : : static inline void
1378 : : tx4(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1379 : : {
1380 : : uint64_t dma_addr;
1381 : : uint32_t i;
1382 : :
1383 [ # # ]: 0 : for (i = 0; i < 4; i++, txdp++, pkts++) {
1384 : 0 : dma_addr = rte_mbuf_data_iova(*pkts);
1385 : 0 : txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1386 : 0 : txdp->cmd_type_offset_bsz =
1387 : : i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1388 : 0 : (*pkts)->data_len, 0);
1389 : : }
1390 : : }
1391 : :
1392 : : /* Populate 1 descriptor with data from 1 mbuf */
1393 : : static inline void
1394 : : tx1(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1395 : : {
1396 : : uint64_t dma_addr;
1397 : :
1398 : : dma_addr = rte_mbuf_data_iova(*pkts);
1399 : 0 : txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1400 : 0 : txdp->cmd_type_offset_bsz =
1401 : : i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1402 : 0 : (*pkts)->data_len, 0);
1403 : : }
1404 : :
1405 : : /* Fill hardware descriptor ring with mbuf data */
1406 : : static inline void
1407 : 0 : i40e_tx_fill_hw_ring(struct i40e_tx_queue *txq,
1408 : : struct rte_mbuf **pkts,
1409 : : uint16_t nb_pkts)
1410 : : {
1411 : 0 : volatile struct i40e_tx_desc *txdp = &(txq->tx_ring[txq->tx_tail]);
1412 : 0 : struct i40e_tx_entry *txep = &(txq->sw_ring[txq->tx_tail]);
1413 : : const int N_PER_LOOP = 4;
1414 : : const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
1415 : : int mainpart, leftover;
1416 : : int i, j;
1417 : :
1418 : 0 : mainpart = (nb_pkts & ((uint32_t) ~N_PER_LOOP_MASK));
1419 : 0 : leftover = (nb_pkts & ((uint32_t) N_PER_LOOP_MASK));
1420 [ # # ]: 0 : for (i = 0; i < mainpart; i += N_PER_LOOP) {
1421 [ # # ]: 0 : for (j = 0; j < N_PER_LOOP; ++j) {
1422 : 0 : (txep + i + j)->mbuf = *(pkts + i + j);
1423 : : }
1424 : 0 : tx4(txdp + i, pkts + i);
1425 : : }
1426 [ # # ]: 0 : if (unlikely(leftover > 0)) {
1427 [ # # ]: 0 : for (i = 0; i < leftover; ++i) {
1428 : 0 : (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
1429 : 0 : tx1(txdp + mainpart + i, pkts + mainpart + i);
1430 : : }
1431 : : }
1432 : 0 : }
1433 : :
1434 : : static inline uint16_t
1435 : 0 : tx_xmit_pkts(struct i40e_tx_queue *txq,
1436 : : struct rte_mbuf **tx_pkts,
1437 : : uint16_t nb_pkts)
1438 : : {
1439 : 0 : volatile struct i40e_tx_desc *txr = txq->tx_ring;
1440 : : uint16_t n = 0;
1441 : :
1442 : : /**
1443 : : * Begin scanning the H/W ring for done descriptors when the number
1444 : : * of available descriptors drops below tx_free_thresh. For each done
1445 : : * descriptor, free the associated buffer.
1446 : : */
1447 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
1448 : : i40e_tx_free_bufs(txq);
1449 : :
1450 : : /* Use available descriptor only */
1451 : 0 : nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
1452 [ # # ]: 0 : if (unlikely(!nb_pkts))
1453 : : return 0;
1454 : :
1455 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
1456 [ # # ]: 0 : if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
1457 : 0 : n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
1458 : 0 : i40e_tx_fill_hw_ring(txq, tx_pkts, n);
1459 : 0 : txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1460 : : rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1461 : : I40E_TXD_QW1_CMD_SHIFT);
1462 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1463 : 0 : txq->tx_tail = 0;
1464 : : }
1465 : :
1466 : : /* Fill hardware descriptor ring with mbuf data */
1467 : 0 : i40e_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
1468 : 0 : txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
1469 : :
1470 : : /* Determine if RS bit needs to be set */
1471 [ # # ]: 0 : if (txq->tx_tail > txq->tx_next_rs) {
1472 : 0 : txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1473 : : rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1474 : : I40E_TXD_QW1_CMD_SHIFT);
1475 : 0 : txq->tx_next_rs =
1476 : 0 : (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
1477 [ # # ]: 0 : if (txq->tx_next_rs >= txq->nb_tx_desc)
1478 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1479 : : }
1480 : :
1481 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
1482 : 0 : txq->tx_tail = 0;
1483 : :
1484 : : /* Update the tx tail register */
1485 : 0 : I40E_PCI_REG_WC_WRITE(txq->qtx_tail, txq->tx_tail);
1486 : :
1487 : : return nb_pkts;
1488 : : }
1489 : :
1490 : : static uint16_t
1491 : 0 : i40e_xmit_pkts_simple(void *tx_queue,
1492 : : struct rte_mbuf **tx_pkts,
1493 : : uint16_t nb_pkts)
1494 : : {
1495 : : uint16_t nb_tx = 0;
1496 : :
1497 [ # # ]: 0 : if (likely(nb_pkts <= I40E_TX_MAX_BURST))
1498 : 0 : return tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1499 : : tx_pkts, nb_pkts);
1500 : :
1501 [ # # ]: 0 : while (nb_pkts) {
1502 : 0 : uint16_t ret, num = (uint16_t)RTE_MIN(nb_pkts,
1503 : : I40E_TX_MAX_BURST);
1504 : :
1505 : 0 : ret = tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1506 : 0 : &tx_pkts[nb_tx], num);
1507 : 0 : nb_tx = (uint16_t)(nb_tx + ret);
1508 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
1509 [ # # ]: 0 : if (ret < num)
1510 : : break;
1511 : : }
1512 : :
1513 : : return nb_tx;
1514 : : }
1515 : :
1516 : : static uint16_t
1517 : 0 : i40e_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
1518 : : uint16_t nb_pkts)
1519 : : {
1520 : : uint16_t nb_tx = 0;
1521 : : struct i40e_tx_queue *txq = (struct i40e_tx_queue *)tx_queue;
1522 : :
1523 [ # # ]: 0 : while (nb_pkts) {
1524 : : uint16_t ret, num;
1525 : :
1526 : : /* cross rs_thresh boundary is not allowed */
1527 : 0 : num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_rs_thresh);
1528 : 0 : ret = i40e_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
1529 : : num);
1530 : 0 : nb_tx += ret;
1531 : 0 : nb_pkts -= ret;
1532 [ # # ]: 0 : if (ret < num)
1533 : : break;
1534 : : }
1535 : :
1536 : 0 : return nb_tx;
1537 : : }
1538 : :
1539 : : /* Tx mbuf check */
1540 : : static uint16_t
1541 : 0 : i40e_xmit_pkts_check(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1542 : : {
1543 : : struct i40e_tx_queue *txq = tx_queue;
1544 : : uint16_t idx;
1545 : : uint64_t ol_flags;
1546 : : struct rte_mbuf *mb;
1547 : : bool pkt_error = false;
1548 : 0 : const char *reason = NULL;
1549 : : uint16_t good_pkts = nb_pkts;
1550 : 0 : struct i40e_adapter *adapter = txq->vsi->adapter;
1551 : :
1552 [ # # ]: 0 : for (idx = 0; idx < nb_pkts; idx++) {
1553 : 0 : mb = tx_pkts[idx];
1554 : 0 : ol_flags = mb->ol_flags;
1555 : :
1556 [ # # # # ]: 0 : if ((adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_MBUF) &&
1557 : 0 : (rte_mbuf_check(mb, 0, &reason) != 0)) {
1558 : : PMD_TX_LOG(ERR, "INVALID mbuf: %s\n", reason);
1559 : : pkt_error = true;
1560 : : break;
1561 : : }
1562 : :
1563 [ # # ]: 0 : if ((adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_SIZE) &&
1564 [ # # # # ]: 0 : (mb->data_len > mb->pkt_len ||
1565 : 0 : mb->data_len < I40E_TX_MIN_PKT_LEN ||
1566 [ # # ]: 0 : mb->data_len > adapter->max_pkt_len)) {
1567 : : PMD_TX_LOG(ERR, "INVALID mbuf: data_len (%u) is out of range, reasonable range (%d - %u)\n",
1568 : : mb->data_len, I40E_TX_MIN_PKT_LEN, adapter->max_pkt_len);
1569 : : pkt_error = true;
1570 : : break;
1571 : : }
1572 : :
1573 [ # # ]: 0 : if (adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_SEGMENT) {
1574 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
1575 : : /**
1576 : : * No TSO case: nb->segs, pkt_len to not exceed
1577 : : * the limites.
1578 : : */
1579 [ # # ]: 0 : if (mb->nb_segs > I40E_TX_MAX_MTU_SEG) {
1580 : : PMD_TX_LOG(ERR, "INVALID mbuf: nb_segs (%d) exceeds HW limit, maximum allowed value is %d\n",
1581 : : mb->nb_segs, I40E_TX_MAX_MTU_SEG);
1582 : : pkt_error = true;
1583 : : break;
1584 : : }
1585 [ # # ]: 0 : if (mb->pkt_len > I40E_FRAME_SIZE_MAX) {
1586 : : PMD_TX_LOG(ERR, "INVALID mbuf: pkt_len (%d) exceeds HW limit, maximum allowed value is %d\n",
1587 : : mb->nb_segs, I40E_FRAME_SIZE_MAX);
1588 : : pkt_error = true;
1589 : : break;
1590 : : }
1591 : : } else if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
1592 : : /** TSO case: tso_segsz, nb_segs, pkt_len not exceed
1593 : : * the limits.
1594 : : */
1595 [ # # ]: 0 : if (mb->tso_segsz < I40E_MIN_TSO_MSS ||
1596 : : mb->tso_segsz > I40E_MAX_TSO_MSS) {
1597 : : /**
1598 : : * MSS outside the range are considered malicious
1599 : : */
1600 : : PMD_TX_LOG(ERR, "INVALID mbuf: tso_segsz (%u) is out of range, reasonable range (%d - %u)\n",
1601 : : mb->tso_segsz, I40E_MIN_TSO_MSS, I40E_MAX_TSO_MSS);
1602 : : pkt_error = true;
1603 : : break;
1604 : : }
1605 [ # # ]: 0 : if (mb->nb_segs > ((struct i40e_tx_queue *)tx_queue)->nb_tx_desc) {
1606 : : PMD_TX_LOG(ERR, "INVALID mbuf: nb_segs out of ring length\n");
1607 : : pkt_error = true;
1608 : : break;
1609 : : }
1610 [ # # ]: 0 : if (mb->pkt_len > I40E_TSO_FRAME_SIZE_MAX) {
1611 : : PMD_TX_LOG(ERR, "INVALID mbuf: pkt_len (%d) exceeds HW limit, maximum allowed value is %d\n",
1612 : : mb->nb_segs, I40E_TSO_FRAME_SIZE_MAX);
1613 : : pkt_error = true;
1614 : : break;
1615 : : }
1616 : : }
1617 : : }
1618 : :
1619 [ # # ]: 0 : if (adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_OFFLOAD) {
1620 [ # # ]: 0 : if (ol_flags & I40E_TX_OFFLOAD_NOTSUP_MASK) {
1621 : : PMD_TX_LOG(ERR, "INVALID mbuf: TX offload is not supported\n");
1622 : : pkt_error = true;
1623 : : break;
1624 : : }
1625 : :
1626 [ # # ]: 0 : if (!rte_validate_tx_offload(mb)) {
1627 : : PMD_TX_LOG(ERR, "INVALID mbuf: TX offload setup error\n");
1628 : : pkt_error = true;
1629 : : break;
1630 : : }
1631 : : }
1632 : : }
1633 : :
1634 [ # # ]: 0 : if (pkt_error) {
1635 : 0 : txq->mbuf_errors++;
1636 : : good_pkts = idx;
1637 [ # # ]: 0 : if (good_pkts == 0)
1638 : : return 0;
1639 : : }
1640 : :
1641 : 0 : return adapter->tx_pkt_burst(tx_queue, tx_pkts, good_pkts);
1642 : : }
1643 : :
1644 : : /*********************************************************************
1645 : : *
1646 : : * TX simple prep functions
1647 : : *
1648 : : **********************************************************************/
1649 : : uint16_t
1650 : 0 : i40e_simple_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1651 : : uint16_t nb_pkts)
1652 : : {
1653 : : int i;
1654 : : uint64_t ol_flags;
1655 : : struct rte_mbuf *m;
1656 : :
1657 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1658 : 0 : m = tx_pkts[i];
1659 : 0 : ol_flags = m->ol_flags;
1660 : :
1661 [ # # ]: 0 : if (m->nb_segs != 1) {
1662 : 0 : rte_errno = EINVAL;
1663 : 0 : return i;
1664 : : }
1665 : :
1666 [ # # ]: 0 : if (ol_flags & I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK) {
1667 : 0 : rte_errno = ENOTSUP;
1668 : 0 : return i;
1669 : : }
1670 : :
1671 : : /* check the size of packet */
1672 [ # # ]: 0 : if (m->pkt_len < I40E_TX_MIN_PKT_LEN ||
1673 : : m->pkt_len > I40E_FRAME_SIZE_MAX) {
1674 : 0 : rte_errno = EINVAL;
1675 : 0 : return i;
1676 : : }
1677 : : }
1678 : 0 : return i;
1679 : : }
1680 : :
1681 : : /*********************************************************************
1682 : : *
1683 : : * TX prep functions
1684 : : *
1685 : : **********************************************************************/
1686 : : uint16_t
1687 : 0 : i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1688 : : uint16_t nb_pkts)
1689 : : {
1690 : : int i, ret;
1691 : : uint64_t ol_flags;
1692 : : struct rte_mbuf *m;
1693 : :
1694 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1695 : 0 : m = tx_pkts[i];
1696 : 0 : ol_flags = m->ol_flags;
1697 : :
1698 : : /* Check for m->nb_segs to not exceed the limits. */
1699 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
1700 [ # # ]: 0 : if (m->nb_segs > I40E_TX_MAX_MTU_SEG ||
1701 [ # # ]: 0 : m->pkt_len > I40E_FRAME_SIZE_MAX) {
1702 : 0 : rte_errno = EINVAL;
1703 : 0 : return i;
1704 : : }
1705 [ # # ]: 0 : } else if (m->nb_segs > I40E_TX_MAX_SEG ||
1706 [ # # # # ]: 0 : m->tso_segsz < I40E_MIN_TSO_MSS ||
1707 : 0 : m->tso_segsz > I40E_MAX_TSO_MSS ||
1708 [ # # ]: 0 : m->pkt_len > I40E_TSO_FRAME_SIZE_MAX) {
1709 : : /* MSS outside the range (256B - 9674B) are considered
1710 : : * malicious
1711 : : */
1712 : 0 : rte_errno = EINVAL;
1713 : 0 : return i;
1714 : : }
1715 : :
1716 [ # # ]: 0 : if (ol_flags & I40E_TX_OFFLOAD_NOTSUP_MASK) {
1717 : 0 : rte_errno = ENOTSUP;
1718 : 0 : return i;
1719 : : }
1720 : :
1721 : : /* check the size of packet */
1722 [ # # ]: 0 : if (m->pkt_len < I40E_TX_MIN_PKT_LEN) {
1723 : 0 : rte_errno = EINVAL;
1724 : 0 : return i;
1725 : : }
1726 : :
1727 : : #ifdef RTE_ETHDEV_DEBUG_TX
1728 : : ret = rte_validate_tx_offload(m);
1729 : : if (ret != 0) {
1730 : : rte_errno = -ret;
1731 : : return i;
1732 : : }
1733 : : #endif
1734 : : ret = rte_net_intel_cksum_prepare(m);
1735 [ # # ]: 0 : if (ret != 0) {
1736 : 0 : rte_errno = -ret;
1737 : 0 : return i;
1738 : : }
1739 : : }
1740 : 0 : return i;
1741 : : }
1742 : :
1743 : : /*
1744 : : * Find the VSI the queue belongs to. 'queue_idx' is the queue index
1745 : : * application used, which assume having sequential ones. But from driver's
1746 : : * perspective, it's different. For example, q0 belongs to FDIR VSI, q1-q64
1747 : : * to MAIN VSI, , q65-96 to SRIOV VSIs, q97-128 to VMDQ VSIs. For application
1748 : : * running on host, q1-64 and q97-128 can be used, total 96 queues. They can
1749 : : * use queue_idx from 0 to 95 to access queues, while real queue would be
1750 : : * different. This function will do a queue mapping to find VSI the queue
1751 : : * belongs to.
1752 : : */
1753 : : static struct i40e_vsi*
1754 : 0 : i40e_pf_get_vsi_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1755 : : {
1756 : : /* the queue in MAIN VSI range */
1757 [ # # ]: 0 : if (queue_idx < pf->main_vsi->nb_qps)
1758 : : return pf->main_vsi;
1759 : :
1760 : 0 : queue_idx -= pf->main_vsi->nb_qps;
1761 : :
1762 : : /* queue_idx is greater than VMDQ VSIs range */
1763 [ # # ]: 0 : if (queue_idx > pf->nb_cfg_vmdq_vsi * pf->vmdq_nb_qps - 1) {
1764 : 0 : PMD_INIT_LOG(ERR, "queue_idx out of range. VMDQ configured?");
1765 : 0 : return NULL;
1766 : : }
1767 : :
1768 : 0 : return pf->vmdq[queue_idx / pf->vmdq_nb_qps].vsi;
1769 : : }
1770 : :
1771 : : static uint16_t
1772 : 0 : i40e_get_queue_offset_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1773 : : {
1774 : : /* the queue in MAIN VSI range */
1775 [ # # ]: 0 : if (queue_idx < pf->main_vsi->nb_qps)
1776 : : return queue_idx;
1777 : :
1778 : : /* It's VMDQ queues */
1779 : 0 : queue_idx -= pf->main_vsi->nb_qps;
1780 : :
1781 [ # # ]: 0 : if (pf->nb_cfg_vmdq_vsi)
1782 : 0 : return queue_idx % pf->vmdq_nb_qps;
1783 : : else {
1784 : 0 : PMD_INIT_LOG(ERR, "Fail to get queue offset");
1785 : 0 : return (uint16_t)(-1);
1786 : : }
1787 : : }
1788 : :
1789 : : int
1790 : 0 : i40e_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1791 : : {
1792 : : struct i40e_rx_queue *rxq;
1793 : : int err;
1794 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1795 : :
1796 : 0 : PMD_INIT_FUNC_TRACE();
1797 : :
1798 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
1799 [ # # # # ]: 0 : if (!rxq || !rxq->q_set) {
1800 : 0 : PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1801 : : rx_queue_id);
1802 : 0 : return -EINVAL;
1803 : : }
1804 : :
1805 [ # # ]: 0 : if (rxq->rx_deferred_start)
1806 : 0 : PMD_DRV_LOG(WARNING, "RX queue %u is deferred start",
1807 : : rx_queue_id);
1808 : :
1809 : 0 : err = i40e_alloc_rx_queue_mbufs(rxq);
1810 [ # # ]: 0 : if (err) {
1811 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1812 : 0 : return err;
1813 : : }
1814 : :
1815 : : /* Init the RX tail register. */
1816 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1817 : :
1818 : 0 : err = i40e_switch_rx_queue(hw, rxq->reg_idx, TRUE);
1819 [ # # ]: 0 : if (err) {
1820 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1821 : : rx_queue_id);
1822 : :
1823 : 0 : i40e_rx_queue_release_mbufs(rxq);
1824 : 0 : i40e_reset_rx_queue(rxq);
1825 : 0 : return err;
1826 : : }
1827 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1828 : :
1829 : 0 : return 0;
1830 : : }
1831 : :
1832 : : int
1833 : 0 : i40e_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1834 : : {
1835 : : struct i40e_rx_queue *rxq;
1836 : : int err;
1837 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1838 : :
1839 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
1840 [ # # # # ]: 0 : if (!rxq || !rxq->q_set) {
1841 : 0 : PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1842 : : rx_queue_id);
1843 : 0 : return -EINVAL;
1844 : : }
1845 : :
1846 : : /*
1847 : : * rx_queue_id is queue id application refers to, while
1848 : : * rxq->reg_idx is the real queue index.
1849 : : */
1850 : 0 : err = i40e_switch_rx_queue(hw, rxq->reg_idx, FALSE);
1851 [ # # ]: 0 : if (err) {
1852 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1853 : : rx_queue_id);
1854 : 0 : return err;
1855 : : }
1856 : 0 : i40e_rx_queue_release_mbufs(rxq);
1857 : 0 : i40e_reset_rx_queue(rxq);
1858 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1859 : :
1860 : 0 : return 0;
1861 : : }
1862 : :
1863 : : int
1864 : 0 : i40e_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1865 : : {
1866 : : int err;
1867 : : struct i40e_tx_queue *txq;
1868 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1869 : :
1870 : 0 : PMD_INIT_FUNC_TRACE();
1871 : :
1872 : 0 : txq = dev->data->tx_queues[tx_queue_id];
1873 [ # # # # ]: 0 : if (!txq || !txq->q_set) {
1874 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1875 : : tx_queue_id);
1876 : 0 : return -EINVAL;
1877 : : }
1878 : :
1879 [ # # ]: 0 : if (txq->tx_deferred_start)
1880 : 0 : PMD_DRV_LOG(WARNING, "TX queue %u is deferred start",
1881 : : tx_queue_id);
1882 : :
1883 : : /*
1884 : : * tx_queue_id is queue id application refers to, while
1885 : : * rxq->reg_idx is the real queue index.
1886 : : */
1887 : 0 : err = i40e_switch_tx_queue(hw, txq->reg_idx, TRUE);
1888 [ # # ]: 0 : if (err) {
1889 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1890 : : tx_queue_id);
1891 : 0 : return err;
1892 : : }
1893 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1894 : :
1895 : 0 : return 0;
1896 : : }
1897 : :
1898 : : int
1899 : 0 : i40e_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1900 : : {
1901 : : struct i40e_tx_queue *txq;
1902 : : int err;
1903 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1904 : :
1905 : 0 : txq = dev->data->tx_queues[tx_queue_id];
1906 [ # # # # ]: 0 : if (!txq || !txq->q_set) {
1907 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1908 : : tx_queue_id);
1909 : 0 : return -EINVAL;
1910 : : }
1911 : :
1912 : : /*
1913 : : * tx_queue_id is queue id application refers to, while
1914 : : * txq->reg_idx is the real queue index.
1915 : : */
1916 : 0 : err = i40e_switch_tx_queue(hw, txq->reg_idx, FALSE);
1917 [ # # ]: 0 : if (err) {
1918 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1919 : : tx_queue_id);
1920 : 0 : return err;
1921 : : }
1922 : :
1923 : 0 : i40e_tx_queue_release_mbufs(txq);
1924 : 0 : i40e_reset_tx_queue(txq);
1925 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1926 : :
1927 : 0 : return 0;
1928 : : }
1929 : :
1930 : : const uint32_t *
1931 : 0 : i40e_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
1932 : : {
1933 : : static const uint32_t ptypes[] = {
1934 : : /* refers to i40e_rxd_pkt_type_mapping() */
1935 : : RTE_PTYPE_L2_ETHER,
1936 : : RTE_PTYPE_L2_ETHER_TIMESYNC,
1937 : : RTE_PTYPE_L2_ETHER_LLDP,
1938 : : RTE_PTYPE_L2_ETHER_ARP,
1939 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1940 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
1941 : : RTE_PTYPE_L4_FRAG,
1942 : : RTE_PTYPE_L4_ICMP,
1943 : : RTE_PTYPE_L4_NONFRAG,
1944 : : RTE_PTYPE_L4_SCTP,
1945 : : RTE_PTYPE_L4_TCP,
1946 : : RTE_PTYPE_L4_UDP,
1947 : : RTE_PTYPE_TUNNEL_GRENAT,
1948 : : RTE_PTYPE_TUNNEL_IP,
1949 : : RTE_PTYPE_INNER_L2_ETHER,
1950 : : RTE_PTYPE_INNER_L2_ETHER_VLAN,
1951 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
1952 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
1953 : : RTE_PTYPE_INNER_L4_FRAG,
1954 : : RTE_PTYPE_INNER_L4_ICMP,
1955 : : RTE_PTYPE_INNER_L4_NONFRAG,
1956 : : RTE_PTYPE_INNER_L4_SCTP,
1957 : : RTE_PTYPE_INNER_L4_TCP,
1958 : : RTE_PTYPE_INNER_L4_UDP,
1959 : : };
1960 : :
1961 [ # # # # ]: 0 : if (dev->rx_pkt_burst == i40e_recv_pkts ||
1962 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1963 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_pkts_bulk_alloc ||
1964 : : #endif
1965 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_scattered_pkts ||
1966 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
1967 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_pkts_vec ||
1968 : : #ifdef CC_AVX512_SUPPORT
1969 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
1970 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
1971 : : #endif
1972 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
1973 : : dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2) {
1974 : 0 : *no_of_elements = RTE_DIM(ptypes);
1975 : 0 : return ptypes;
1976 : : }
1977 : : return NULL;
1978 : : }
1979 : :
1980 : : static int
1981 : : i40e_dev_first_queue(uint16_t idx, void **queues, int num)
1982 : : {
1983 : : uint16_t i;
1984 : :
1985 [ # # # # ]: 0 : for (i = 0; i < num; i++) {
1986 [ # # # # : 0 : if (i != idx && queues[i])
# # # # ]
1987 : : return 0;
1988 : : }
1989 : :
1990 : : return 1;
1991 : : }
1992 : :
1993 : : static int
1994 : 0 : i40e_dev_rx_queue_setup_runtime(struct rte_eth_dev *dev,
1995 : : struct i40e_rx_queue *rxq)
1996 : : {
1997 : 0 : struct i40e_adapter *ad =
1998 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1999 : : int use_def_burst_func =
2000 : 0 : check_rx_burst_bulk_alloc_preconditions(rxq);
2001 : 0 : uint16_t buf_size =
2002 [ # # ]: 0 : (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
2003 : : RTE_PKTMBUF_HEADROOM);
2004 : : int use_scattered_rx =
2005 : 0 : (rxq->max_pkt_len > buf_size);
2006 : :
2007 [ # # ]: 0 : if (i40e_rx_queue_init(rxq) != I40E_SUCCESS) {
2008 : 0 : PMD_DRV_LOG(ERR,
2009 : : "Failed to do RX queue initialization");
2010 : 0 : return -EINVAL;
2011 : : }
2012 : :
2013 [ # # ]: 0 : if (i40e_dev_first_queue(rxq->queue_id,
2014 : : dev->data->rx_queues,
2015 : 0 : dev->data->nb_rx_queues)) {
2016 : : /**
2017 : : * If it is the first queue to setup,
2018 : : * set all flags to default and call
2019 : : * i40e_set_rx_function.
2020 : : */
2021 : 0 : ad->rx_bulk_alloc_allowed = true;
2022 : 0 : ad->rx_vec_allowed = true;
2023 : 0 : dev->data->scattered_rx = use_scattered_rx;
2024 [ # # ]: 0 : if (use_def_burst_func)
2025 : 0 : ad->rx_bulk_alloc_allowed = false;
2026 : 0 : i40e_set_rx_function(dev);
2027 : :
2028 [ # # # # ]: 0 : if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
2029 : 0 : PMD_DRV_LOG(ERR, "Failed vector rx setup.");
2030 : 0 : return -EINVAL;
2031 : : }
2032 : :
2033 : 0 : return 0;
2034 [ # # # # ]: 0 : } else if (ad->rx_vec_allowed && !rte_is_power_of_2(rxq->nb_rx_desc)) {
2035 : 0 : PMD_DRV_LOG(ERR, "Vector mode is allowed, but descriptor"
2036 : : " number %d of queue %d isn't power of 2",
2037 : : rxq->nb_rx_desc, rxq->queue_id);
2038 : 0 : return -EINVAL;
2039 : : }
2040 : :
2041 : : /* check bulk alloc conflict */
2042 [ # # # # ]: 0 : if (ad->rx_bulk_alloc_allowed && use_def_burst_func) {
2043 : 0 : PMD_DRV_LOG(ERR, "Can't use default burst.");
2044 : 0 : return -EINVAL;
2045 : : }
2046 : : /* check scattered conflict */
2047 [ # # # # ]: 0 : if (!dev->data->scattered_rx && use_scattered_rx) {
2048 : 0 : PMD_DRV_LOG(ERR, "Scattered rx is required.");
2049 : 0 : return -EINVAL;
2050 : : }
2051 : : /* check vector conflict */
2052 [ # # # # ]: 0 : if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
2053 : 0 : PMD_DRV_LOG(ERR, "Failed vector rx setup.");
2054 : 0 : return -EINVAL;
2055 : : }
2056 : :
2057 : : return 0;
2058 : : }
2059 : :
2060 : : int
2061 : 0 : i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
2062 : : uint16_t queue_idx,
2063 : : uint16_t nb_desc,
2064 : : unsigned int socket_id,
2065 : : const struct rte_eth_rxconf *rx_conf,
2066 : : struct rte_mempool *mp)
2067 : : {
2068 : 0 : struct i40e_adapter *ad =
2069 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2070 : : struct i40e_vsi *vsi;
2071 : : struct i40e_pf *pf = NULL;
2072 : : struct i40e_rx_queue *rxq;
2073 : : const struct rte_memzone *rz;
2074 : : uint32_t ring_size;
2075 : : uint16_t len, i;
2076 : : uint16_t reg_idx, base, bsf, tc_mapping;
2077 : : int q_offset, use_def_burst_func = 1;
2078 : : uint64_t offloads;
2079 : :
2080 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
2081 : :
2082 : 0 : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2083 : 0 : vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
2084 [ # # ]: 0 : if (!vsi)
2085 : : return -EINVAL;
2086 : 0 : q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
2087 : : if (q_offset < 0)
2088 : : return -EINVAL;
2089 : 0 : reg_idx = vsi->base_queue + q_offset;
2090 : :
2091 [ # # ]: 0 : if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
2092 [ # # ]: 0 : (nb_desc > I40E_MAX_RING_DESC) ||
2093 : : (nb_desc < I40E_MIN_RING_DESC)) {
2094 : 0 : PMD_DRV_LOG(ERR, "Number (%u) of receive descriptors is "
2095 : : "invalid", nb_desc);
2096 : 0 : return -EINVAL;
2097 : : }
2098 : :
2099 : : /* Free memory if needed */
2100 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx]) {
2101 : 0 : i40e_rx_queue_release(dev->data->rx_queues[queue_idx]);
2102 : 0 : dev->data->rx_queues[queue_idx] = NULL;
2103 : : }
2104 : :
2105 : : /* Allocate the rx queue data structure */
2106 : 0 : rxq = rte_zmalloc_socket("i40e rx queue",
2107 : : sizeof(struct i40e_rx_queue),
2108 : : RTE_CACHE_LINE_SIZE,
2109 : : socket_id);
2110 [ # # ]: 0 : if (!rxq) {
2111 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2112 : : "rx queue data structure");
2113 : 0 : return -ENOMEM;
2114 : : }
2115 : 0 : rxq->mp = mp;
2116 : 0 : rxq->nb_rx_desc = nb_desc;
2117 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
2118 : 0 : rxq->queue_id = queue_idx;
2119 : 0 : rxq->reg_idx = reg_idx;
2120 : 0 : rxq->port_id = dev->data->port_id;
2121 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
2122 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
2123 : : else
2124 : 0 : rxq->crc_len = 0;
2125 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
2126 : 0 : rxq->vsi = vsi;
2127 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
2128 : 0 : rxq->offloads = offloads;
2129 : :
2130 : : /* Allocate the maximum number of RX ring hardware descriptor. */
2131 : : len = I40E_MAX_RING_DESC;
2132 : :
2133 : : /**
2134 : : * Allocating a little more memory because vectorized/bulk_alloc Rx
2135 : : * functions doesn't check boundaries each time.
2136 : : */
2137 : : len += RTE_PMD_I40E_RX_MAX_BURST;
2138 : :
2139 : : ring_size = RTE_ALIGN(len * sizeof(union i40e_rx_desc),
2140 : : I40E_DMA_MEM_ALIGN);
2141 : :
2142 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
2143 : : ring_size, I40E_RING_BASE_ALIGN, socket_id);
2144 [ # # ]: 0 : if (!rz) {
2145 : 0 : i40e_rx_queue_release(rxq);
2146 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX");
2147 : 0 : return -ENOMEM;
2148 : : }
2149 : :
2150 : 0 : rxq->mz = rz;
2151 : : /* Zero all the descriptors in the ring. */
2152 : 0 : memset(rz->addr, 0, ring_size);
2153 : :
2154 : 0 : rxq->rx_ring_phys_addr = rz->iova;
2155 : 0 : rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
2156 : :
2157 : 0 : len = (uint16_t)(nb_desc + RTE_PMD_I40E_RX_MAX_BURST);
2158 : :
2159 : : /* Allocate the software ring. */
2160 : 0 : rxq->sw_ring =
2161 : 0 : rte_zmalloc_socket("i40e rx sw ring",
2162 : : sizeof(struct i40e_rx_entry) * len,
2163 : : RTE_CACHE_LINE_SIZE,
2164 : : socket_id);
2165 [ # # ]: 0 : if (!rxq->sw_ring) {
2166 : 0 : i40e_rx_queue_release(rxq);
2167 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for SW ring");
2168 : 0 : return -ENOMEM;
2169 : : }
2170 : :
2171 : 0 : i40e_reset_rx_queue(rxq);
2172 : 0 : rxq->q_set = TRUE;
2173 : :
2174 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2175 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
2176 : 0 : continue;
2177 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2178 : 0 : base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2179 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2180 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2181 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2182 : :
2183 [ # # # # ]: 0 : if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2184 : 0 : rxq->dcb_tc = i;
2185 : : }
2186 : :
2187 [ # # ]: 0 : if (dev->data->dev_started) {
2188 [ # # ]: 0 : if (i40e_dev_rx_queue_setup_runtime(dev, rxq)) {
2189 : 0 : i40e_rx_queue_release(rxq);
2190 : 0 : return -EINVAL;
2191 : : }
2192 : : } else {
2193 : : use_def_burst_func =
2194 : 0 : check_rx_burst_bulk_alloc_preconditions(rxq);
2195 [ # # ]: 0 : if (!use_def_burst_func) {
2196 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2197 : 0 : PMD_INIT_LOG(DEBUG,
2198 : : "Rx Burst Bulk Alloc Preconditions are "
2199 : : "satisfied. Rx Burst Bulk Alloc function will be "
2200 : : "used on port=%d, queue=%d.",
2201 : : rxq->port_id, rxq->queue_id);
2202 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2203 : : } else {
2204 : 0 : PMD_INIT_LOG(DEBUG,
2205 : : "Rx Burst Bulk Alloc Preconditions are "
2206 : : "not satisfied, Scattered Rx is requested, "
2207 : : "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
2208 : : "not enabled on port=%d, queue=%d.",
2209 : : rxq->port_id, rxq->queue_id);
2210 : 0 : ad->rx_bulk_alloc_allowed = false;
2211 : : }
2212 : : }
2213 : :
2214 : 0 : dev->data->rx_queues[queue_idx] = rxq;
2215 : 0 : return 0;
2216 : : }
2217 : :
2218 : : void
2219 : 0 : i40e_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2220 : : {
2221 : 0 : i40e_rx_queue_release(dev->data->rx_queues[qid]);
2222 : 0 : }
2223 : :
2224 : : void
2225 : 0 : i40e_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2226 : : {
2227 : 0 : i40e_tx_queue_release(dev->data->tx_queues[qid]);
2228 : 0 : }
2229 : :
2230 : : void
2231 : 0 : i40e_rx_queue_release(void *rxq)
2232 : : {
2233 : : struct i40e_rx_queue *q = (struct i40e_rx_queue *)rxq;
2234 : :
2235 [ # # ]: 0 : if (!q) {
2236 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2237 : 0 : return;
2238 : : }
2239 : :
2240 : 0 : i40e_rx_queue_release_mbufs(q);
2241 : 0 : rte_free(q->sw_ring);
2242 : 0 : rte_memzone_free(q->mz);
2243 : 0 : rte_free(q);
2244 : : }
2245 : :
2246 : : uint32_t
2247 : 0 : i40e_dev_rx_queue_count(void *rx_queue)
2248 : : {
2249 : : #define I40E_RXQ_SCAN_INTERVAL 4
2250 : : volatile union i40e_rx_desc *rxdp;
2251 : : struct i40e_rx_queue *rxq;
2252 : : uint16_t desc = 0;
2253 : :
2254 : : rxq = rx_queue;
2255 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail]);
2256 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
2257 : 0 : ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
2258 [ # # ]: 0 : I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
2259 : : (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
2260 : : /**
2261 : : * Check the DD bit of a rx descriptor of each 4 in a group,
2262 : : * to avoid checking too frequently and downgrading performance
2263 : : * too much.
2264 : : */
2265 : 0 : desc += I40E_RXQ_SCAN_INTERVAL;
2266 : 0 : rxdp += I40E_RXQ_SCAN_INTERVAL;
2267 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
2268 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
2269 : 0 : desc - rxq->nb_rx_desc]);
2270 : : }
2271 : :
2272 : 0 : return desc;
2273 : : }
2274 : :
2275 : : int
2276 : 0 : i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
2277 : : {
2278 : : struct i40e_rx_queue *rxq = rx_queue;
2279 : : volatile uint64_t *status;
2280 : : uint64_t mask;
2281 : : uint32_t desc;
2282 : :
2283 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
2284 : : return -EINVAL;
2285 : :
2286 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
2287 : : return RTE_ETH_RX_DESC_UNAVAIL;
2288 : :
2289 : 0 : desc = rxq->rx_tail + offset;
2290 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
2291 : 0 : desc -= rxq->nb_rx_desc;
2292 : :
2293 : 0 : status = &rxq->rx_ring[desc].wb.qword1.status_error_len;
2294 : : mask = rte_le_to_cpu_64((1ULL << I40E_RX_DESC_STATUS_DD_SHIFT)
2295 : : << I40E_RXD_QW1_STATUS_SHIFT);
2296 [ # # ]: 0 : if (*status & mask)
2297 : 0 : return RTE_ETH_RX_DESC_DONE;
2298 : :
2299 : : return RTE_ETH_RX_DESC_AVAIL;
2300 : : }
2301 : :
2302 : : int
2303 : 0 : i40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
2304 : : {
2305 : : struct i40e_tx_queue *txq = tx_queue;
2306 : : volatile uint64_t *status;
2307 : : uint64_t mask, expect;
2308 : : uint32_t desc;
2309 : :
2310 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
2311 : : return -EINVAL;
2312 : :
2313 : 0 : desc = txq->tx_tail + offset;
2314 : : /* go to next desc that has the RS bit */
2315 : 0 : desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
2316 : : txq->tx_rs_thresh;
2317 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
2318 : 0 : desc -= txq->nb_tx_desc;
2319 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
2320 : 0 : desc -= txq->nb_tx_desc;
2321 : : }
2322 : :
2323 : 0 : status = &txq->tx_ring[desc].cmd_type_offset_bsz;
2324 : : mask = rte_le_to_cpu_64(I40E_TXD_QW1_DTYPE_MASK);
2325 : : expect = rte_cpu_to_le_64(
2326 : : I40E_TX_DESC_DTYPE_DESC_DONE << I40E_TXD_QW1_DTYPE_SHIFT);
2327 [ # # ]: 0 : if ((*status & mask) == expect)
2328 : 0 : return RTE_ETH_TX_DESC_DONE;
2329 : :
2330 : : return RTE_ETH_TX_DESC_FULL;
2331 : : }
2332 : :
2333 : : static int
2334 : 0 : i40e_dev_tx_queue_setup_runtime(struct rte_eth_dev *dev,
2335 : : struct i40e_tx_queue *txq)
2336 : : {
2337 : 0 : struct i40e_adapter *ad =
2338 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2339 : :
2340 [ # # ]: 0 : if (i40e_tx_queue_init(txq) != I40E_SUCCESS) {
2341 : 0 : PMD_DRV_LOG(ERR,
2342 : : "Failed to do TX queue initialization");
2343 : 0 : return -EINVAL;
2344 : : }
2345 : :
2346 [ # # ]: 0 : if (i40e_dev_first_queue(txq->queue_id,
2347 : : dev->data->tx_queues,
2348 : 0 : dev->data->nb_tx_queues)) {
2349 : : /**
2350 : : * If it is the first queue to setup,
2351 : : * set all flags and call
2352 : : * i40e_set_tx_function.
2353 : : */
2354 : 0 : i40e_set_tx_function_flag(dev, txq);
2355 : 0 : i40e_set_tx_function(dev);
2356 : 0 : return 0;
2357 : : }
2358 : :
2359 : : /* check vector conflict */
2360 [ # # ]: 0 : if (ad->tx_vec_allowed) {
2361 [ # # # # ]: 0 : if (txq->tx_rs_thresh > RTE_I40E_TX_MAX_FREE_BUF_SZ ||
2362 : 0 : i40e_txq_vec_setup(txq)) {
2363 : 0 : PMD_DRV_LOG(ERR, "Failed vector tx setup.");
2364 : 0 : return -EINVAL;
2365 : : }
2366 : : }
2367 : : /* check simple tx conflict */
2368 [ # # ]: 0 : if (ad->tx_simple_allowed) {
2369 [ # # ]: 0 : if ((txq->offloads & ~RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) != 0 ||
2370 [ # # ]: 0 : txq->tx_rs_thresh < RTE_PMD_I40E_TX_MAX_BURST) {
2371 : 0 : PMD_DRV_LOG(ERR, "No-simple tx is required.");
2372 : 0 : return -EINVAL;
2373 : : }
2374 : : }
2375 : :
2376 : : return 0;
2377 : : }
2378 : :
2379 : : int
2380 : 0 : i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
2381 : : uint16_t queue_idx,
2382 : : uint16_t nb_desc,
2383 : : unsigned int socket_id,
2384 : : const struct rte_eth_txconf *tx_conf)
2385 : : {
2386 : : struct i40e_vsi *vsi;
2387 : : struct i40e_pf *pf = NULL;
2388 : : struct i40e_tx_queue *txq;
2389 : : const struct rte_memzone *tz;
2390 : : uint32_t ring_size;
2391 : : uint16_t tx_rs_thresh, tx_free_thresh;
2392 : : uint16_t reg_idx, i, base, bsf, tc_mapping;
2393 : : int q_offset;
2394 : : uint64_t offloads;
2395 : :
2396 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2397 : :
2398 : 0 : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2399 : 0 : vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
2400 [ # # ]: 0 : if (!vsi)
2401 : : return -EINVAL;
2402 : 0 : q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
2403 : : if (q_offset < 0)
2404 : : return -EINVAL;
2405 : 0 : reg_idx = vsi->base_queue + q_offset;
2406 : :
2407 [ # # ]: 0 : if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
2408 [ # # ]: 0 : (nb_desc > I40E_MAX_RING_DESC) ||
2409 : : (nb_desc < I40E_MIN_RING_DESC)) {
2410 : 0 : PMD_DRV_LOG(ERR, "Number (%u) of transmit descriptors is "
2411 : : "invalid", nb_desc);
2412 : 0 : return -EINVAL;
2413 : : }
2414 : :
2415 : : /**
2416 : : * The following two parameters control the setting of the RS bit on
2417 : : * transmit descriptors. TX descriptors will have their RS bit set
2418 : : * after txq->tx_rs_thresh descriptors have been used. The TX
2419 : : * descriptor ring will be cleaned after txq->tx_free_thresh
2420 : : * descriptors are used or if the number of descriptors required to
2421 : : * transmit a packet is greater than the number of free TX descriptors.
2422 : : *
2423 : : * The following constraints must be satisfied:
2424 : : * - tx_rs_thresh must be greater than 0.
2425 : : * - tx_rs_thresh must be less than the size of the ring minus 2.
2426 : : * - tx_rs_thresh must be less than or equal to tx_free_thresh.
2427 : : * - tx_rs_thresh must be a divisor of the ring size.
2428 : : * - tx_free_thresh must be greater than 0.
2429 : : * - tx_free_thresh must be less than the size of the ring minus 3.
2430 : : * - tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
2431 : : *
2432 : : * One descriptor in the TX ring is used as a sentinel to avoid a H/W
2433 : : * race condition, hence the maximum threshold constraints. When set
2434 : : * to zero use default values.
2435 : : */
2436 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2437 : : tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2438 : : /* force tx_rs_thresh to adapt an aggressive tx_free_thresh */
2439 [ # # ]: 0 : tx_rs_thresh = (DEFAULT_TX_RS_THRESH + tx_free_thresh > nb_desc) ?
2440 : : nb_desc - tx_free_thresh : DEFAULT_TX_RS_THRESH;
2441 [ # # ]: 0 : if (tx_conf->tx_rs_thresh > 0)
2442 : : tx_rs_thresh = tx_conf->tx_rs_thresh;
2443 [ # # ]: 0 : if (tx_rs_thresh + tx_free_thresh > nb_desc) {
2444 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
2445 : : "exceed nb_desc. (tx_rs_thresh=%u "
2446 : : "tx_free_thresh=%u nb_desc=%u port=%d queue=%d)",
2447 : : (unsigned int)tx_rs_thresh,
2448 : : (unsigned int)tx_free_thresh,
2449 : : (unsigned int)nb_desc,
2450 : : (int)dev->data->port_id,
2451 : : (int)queue_idx);
2452 : 0 : return I40E_ERR_PARAM;
2453 : : }
2454 [ # # ]: 0 : if (tx_rs_thresh >= (nb_desc - 2)) {
2455 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
2456 : : "number of TX descriptors minus 2. "
2457 : : "(tx_rs_thresh=%u port=%d queue=%d)",
2458 : : (unsigned int)tx_rs_thresh,
2459 : : (int)dev->data->port_id,
2460 : : (int)queue_idx);
2461 : 0 : return I40E_ERR_PARAM;
2462 : : }
2463 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
2464 : 0 : PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
2465 : : "number of TX descriptors minus 3. "
2466 : : "(tx_free_thresh=%u port=%d queue=%d)",
2467 : : (unsigned int)tx_free_thresh,
2468 : : (int)dev->data->port_id,
2469 : : (int)queue_idx);
2470 : 0 : return I40E_ERR_PARAM;
2471 : : }
2472 [ # # ]: 0 : if (tx_rs_thresh > tx_free_thresh) {
2473 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or "
2474 : : "equal to tx_free_thresh. (tx_free_thresh=%u"
2475 : : " tx_rs_thresh=%u port=%d queue=%d)",
2476 : : (unsigned int)tx_free_thresh,
2477 : : (unsigned int)tx_rs_thresh,
2478 : : (int)dev->data->port_id,
2479 : : (int)queue_idx);
2480 : 0 : return I40E_ERR_PARAM;
2481 : : }
2482 [ # # ]: 0 : if ((nb_desc % tx_rs_thresh) != 0) {
2483 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
2484 : : "number of TX descriptors. (tx_rs_thresh=%u"
2485 : : " port=%d queue=%d)",
2486 : : (unsigned int)tx_rs_thresh,
2487 : : (int)dev->data->port_id,
2488 : : (int)queue_idx);
2489 : 0 : return I40E_ERR_PARAM;
2490 : : }
2491 [ # # # # ]: 0 : if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
2492 : 0 : PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
2493 : : "tx_rs_thresh is greater than 1. "
2494 : : "(tx_rs_thresh=%u port=%d queue=%d)",
2495 : : (unsigned int)tx_rs_thresh,
2496 : : (int)dev->data->port_id,
2497 : : (int)queue_idx);
2498 : 0 : return I40E_ERR_PARAM;
2499 : : }
2500 : :
2501 : : /* Free memory if needed. */
2502 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx]) {
2503 : 0 : i40e_tx_queue_release(dev->data->tx_queues[queue_idx]);
2504 : 0 : dev->data->tx_queues[queue_idx] = NULL;
2505 : : }
2506 : :
2507 : : /* Allocate the TX queue data structure. */
2508 : 0 : txq = rte_zmalloc_socket("i40e tx queue",
2509 : : sizeof(struct i40e_tx_queue),
2510 : : RTE_CACHE_LINE_SIZE,
2511 : : socket_id);
2512 [ # # ]: 0 : if (!txq) {
2513 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2514 : : "tx queue structure");
2515 : 0 : return -ENOMEM;
2516 : : }
2517 : :
2518 : : /* Allocate TX hardware ring descriptors. */
2519 : : ring_size = sizeof(struct i40e_tx_desc) * I40E_MAX_RING_DESC;
2520 : : ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2521 : 0 : tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
2522 : : ring_size, I40E_RING_BASE_ALIGN, socket_id);
2523 [ # # ]: 0 : if (!tz) {
2524 : 0 : i40e_tx_queue_release(txq);
2525 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX");
2526 : 0 : return -ENOMEM;
2527 : : }
2528 : :
2529 : 0 : txq->mz = tz;
2530 : 0 : txq->nb_tx_desc = nb_desc;
2531 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
2532 : 0 : txq->tx_free_thresh = tx_free_thresh;
2533 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
2534 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
2535 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
2536 : 0 : txq->queue_id = queue_idx;
2537 : 0 : txq->reg_idx = reg_idx;
2538 : 0 : txq->port_id = dev->data->port_id;
2539 : 0 : txq->offloads = offloads;
2540 : 0 : txq->vsi = vsi;
2541 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
2542 : :
2543 : 0 : txq->tx_ring_phys_addr = tz->iova;
2544 : 0 : txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
2545 : :
2546 : : /* Allocate software ring */
2547 : 0 : txq->sw_ring =
2548 : 0 : rte_zmalloc_socket("i40e tx sw ring",
2549 : : sizeof(struct i40e_tx_entry) * nb_desc,
2550 : : RTE_CACHE_LINE_SIZE,
2551 : : socket_id);
2552 [ # # ]: 0 : if (!txq->sw_ring) {
2553 : 0 : i40e_tx_queue_release(txq);
2554 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring");
2555 : 0 : return -ENOMEM;
2556 : : }
2557 : :
2558 : 0 : i40e_reset_tx_queue(txq);
2559 : 0 : txq->q_set = TRUE;
2560 : :
2561 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2562 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
2563 : 0 : continue;
2564 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2565 : 0 : base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2566 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2567 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2568 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2569 : :
2570 [ # # # # ]: 0 : if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2571 : 0 : txq->dcb_tc = i;
2572 : : }
2573 : :
2574 [ # # ]: 0 : if (dev->data->dev_started) {
2575 [ # # ]: 0 : if (i40e_dev_tx_queue_setup_runtime(dev, txq)) {
2576 : 0 : i40e_tx_queue_release(txq);
2577 : 0 : return -EINVAL;
2578 : : }
2579 : : } else {
2580 : : /**
2581 : : * Use a simple TX queue without offloads or
2582 : : * multi segs if possible
2583 : : */
2584 : 0 : i40e_set_tx_function_flag(dev, txq);
2585 : : }
2586 : 0 : dev->data->tx_queues[queue_idx] = txq;
2587 : :
2588 : 0 : return 0;
2589 : : }
2590 : :
2591 : : void
2592 : 0 : i40e_tx_queue_release(void *txq)
2593 : : {
2594 : : struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
2595 : :
2596 [ # # ]: 0 : if (!q) {
2597 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL");
2598 : 0 : return;
2599 : : }
2600 : :
2601 : 0 : i40e_tx_queue_release_mbufs(q);
2602 : 0 : rte_free(q->sw_ring);
2603 : 0 : rte_memzone_free(q->mz);
2604 : 0 : rte_free(q);
2605 : : }
2606 : :
2607 : : const struct rte_memzone *
2608 : 0 : i40e_memzone_reserve(const char *name, uint32_t len, int socket_id)
2609 : : {
2610 : : const struct rte_memzone *mz;
2611 : :
2612 : 0 : mz = rte_memzone_lookup(name);
2613 [ # # ]: 0 : if (mz)
2614 : : return mz;
2615 : :
2616 : 0 : mz = rte_memzone_reserve_aligned(name, len, socket_id,
2617 : : RTE_MEMZONE_IOVA_CONTIG, I40E_RING_BASE_ALIGN);
2618 : 0 : return mz;
2619 : : }
2620 : :
2621 : : void
2622 : 0 : i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
2623 : : {
2624 : : uint16_t i;
2625 : :
2626 : : /* SSE Vector driver has a different way of releasing mbufs. */
2627 [ # # ]: 0 : if (rxq->rx_using_sse) {
2628 : 0 : i40e_rx_queue_release_mbufs_vec(rxq);
2629 : 0 : return;
2630 : : }
2631 : :
2632 [ # # ]: 0 : if (!rxq->sw_ring) {
2633 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to sw_ring is NULL");
2634 : 0 : return;
2635 : : }
2636 : :
2637 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2638 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf) {
2639 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2640 : 0 : rxq->sw_ring[i].mbuf = NULL;
2641 : : }
2642 : : }
2643 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2644 [ # # ]: 0 : if (rxq->rx_nb_avail == 0)
2645 : : return;
2646 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; i++) {
2647 : : struct rte_mbuf *mbuf;
2648 : :
2649 [ # # ]: 0 : mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
2650 : : rte_pktmbuf_free_seg(mbuf);
2651 : : }
2652 : 0 : rxq->rx_nb_avail = 0;
2653 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2654 : : }
2655 : :
2656 : : void
2657 : 0 : i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
2658 : : {
2659 : : unsigned i;
2660 : : uint16_t len;
2661 : :
2662 [ # # ]: 0 : if (!rxq) {
2663 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2664 : 0 : return;
2665 : : }
2666 : :
2667 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2668 [ # # ]: 0 : if (check_rx_burst_bulk_alloc_preconditions(rxq) == 0)
2669 : 0 : len = (uint16_t)(rxq->nb_rx_desc + RTE_PMD_I40E_RX_MAX_BURST);
2670 : : else
2671 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2672 : 0 : len = rxq->nb_rx_desc;
2673 : :
2674 [ # # ]: 0 : for (i = 0; i < len * sizeof(union i40e_rx_desc); i++)
2675 : 0 : ((volatile char *)rxq->rx_ring)[i] = 0;
2676 : :
2677 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2678 [ # # ]: 0 : for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; ++i)
2679 : 0 : rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
2680 : :
2681 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2682 : 0 : rxq->rx_nb_avail = 0;
2683 : 0 : rxq->rx_next_avail = 0;
2684 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2685 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2686 : 0 : rxq->rx_tail = 0;
2687 : 0 : rxq->nb_rx_hold = 0;
2688 : :
2689 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
2690 : :
2691 : 0 : rxq->pkt_first_seg = NULL;
2692 : 0 : rxq->pkt_last_seg = NULL;
2693 : :
2694 : 0 : rxq->rxrearm_start = 0;
2695 : 0 : rxq->rxrearm_nb = 0;
2696 : : }
2697 : :
2698 : : void
2699 : 0 : i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
2700 : : {
2701 : : struct rte_eth_dev *dev;
2702 : : uint16_t i;
2703 : :
2704 [ # # # # ]: 0 : if (!txq || !txq->sw_ring) {
2705 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to txq or sw_ring is NULL");
2706 : 0 : return;
2707 : : }
2708 : :
2709 : 0 : dev = &rte_eth_devices[txq->port_id];
2710 : :
2711 : : /**
2712 : : * vPMD tx will not set sw_ring's mbuf to NULL after free,
2713 : : * so need to free remains more carefully.
2714 : : */
2715 : : #ifdef CC_AVX512_SUPPORT
2716 [ # # ]: 0 : if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx512) {
2717 : : struct i40e_vec_tx_entry *swr = (void *)txq->sw_ring;
2718 : :
2719 : 0 : i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
2720 [ # # ]: 0 : if (txq->tx_tail < i) {
2721 [ # # ]: 0 : for (; i < txq->nb_tx_desc; i++) {
2722 [ # # ]: 0 : rte_pktmbuf_free_seg(swr[i].mbuf);
2723 : 0 : swr[i].mbuf = NULL;
2724 : : }
2725 : : i = 0;
2726 : : }
2727 [ # # ]: 0 : for (; i < txq->tx_tail; i++) {
2728 [ # # ]: 0 : rte_pktmbuf_free_seg(swr[i].mbuf);
2729 : 0 : swr[i].mbuf = NULL;
2730 : : }
2731 : : return;
2732 : : }
2733 : : #endif
2734 [ # # # # ]: 0 : if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx2 ||
2735 : : dev->tx_pkt_burst == i40e_xmit_pkts_vec) {
2736 : 0 : i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
2737 [ # # ]: 0 : if (txq->tx_tail < i) {
2738 [ # # ]: 0 : for (; i < txq->nb_tx_desc; i++) {
2739 [ # # ]: 0 : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2740 : 0 : txq->sw_ring[i].mbuf = NULL;
2741 : : }
2742 : : i = 0;
2743 : : }
2744 [ # # ]: 0 : for (; i < txq->tx_tail; i++) {
2745 [ # # ]: 0 : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2746 : 0 : txq->sw_ring[i].mbuf = NULL;
2747 : : }
2748 : : } else {
2749 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2750 [ # # ]: 0 : if (txq->sw_ring[i].mbuf) {
2751 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2752 : 0 : txq->sw_ring[i].mbuf = NULL;
2753 : : }
2754 : : }
2755 : : }
2756 : : }
2757 : :
2758 : : static int
2759 : 0 : i40e_tx_done_cleanup_full(struct i40e_tx_queue *txq,
2760 : : uint32_t free_cnt)
2761 : : {
2762 : 0 : struct i40e_tx_entry *swr_ring = txq->sw_ring;
2763 : : uint16_t i, tx_last, tx_id;
2764 : : uint16_t nb_tx_free_last;
2765 : : uint16_t nb_tx_to_clean;
2766 : : uint32_t pkt_cnt;
2767 : :
2768 : : /* Start free mbuf from the next of tx_tail */
2769 : 0 : tx_last = txq->tx_tail;
2770 : 0 : tx_id = swr_ring[tx_last].next_id;
2771 : :
2772 [ # # # # ]: 0 : if (txq->nb_tx_free == 0 && i40e_xmit_cleanup(txq))
2773 : : return 0;
2774 : :
2775 : 0 : nb_tx_to_clean = txq->nb_tx_free;
2776 : : nb_tx_free_last = txq->nb_tx_free;
2777 [ # # ]: 0 : if (!free_cnt)
2778 : 0 : free_cnt = txq->nb_tx_desc;
2779 : :
2780 : : /* Loop through swr_ring to count the amount of
2781 : : * freeable mubfs and packets.
2782 : : */
2783 [ # # ]: 0 : for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2784 : 0 : for (i = 0; i < nb_tx_to_clean &&
2785 [ # # # # ]: 0 : pkt_cnt < free_cnt &&
2786 : 0 : tx_id != tx_last; i++) {
2787 [ # # ]: 0 : if (swr_ring[tx_id].mbuf != NULL) {
2788 : : rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2789 : 0 : swr_ring[tx_id].mbuf = NULL;
2790 : :
2791 : : /*
2792 : : * last segment in the packet,
2793 : : * increment packet count
2794 : : */
2795 : 0 : pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
2796 : : }
2797 : :
2798 : 0 : tx_id = swr_ring[tx_id].next_id;
2799 : : }
2800 : :
2801 : 0 : if (txq->tx_rs_thresh > txq->nb_tx_desc -
2802 [ # # # # ]: 0 : txq->nb_tx_free || tx_id == tx_last)
2803 : : break;
2804 : :
2805 [ # # ]: 0 : if (pkt_cnt < free_cnt) {
2806 [ # # ]: 0 : if (i40e_xmit_cleanup(txq))
2807 : : break;
2808 : :
2809 : 0 : nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2810 : : nb_tx_free_last = txq->nb_tx_free;
2811 : : }
2812 : : }
2813 : :
2814 : 0 : return (int)pkt_cnt;
2815 : : }
2816 : :
2817 : : static int
2818 : 0 : i40e_tx_done_cleanup_simple(struct i40e_tx_queue *txq,
2819 : : uint32_t free_cnt)
2820 : : {
2821 : : int i, n, cnt;
2822 : :
2823 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2824 : 0 : free_cnt = txq->nb_tx_desc;
2825 : :
2826 : 0 : cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
2827 : :
2828 [ # # ]: 0 : for (i = 0; i < cnt; i += n) {
2829 [ # # ]: 0 : if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
2830 : : break;
2831 : :
2832 : : n = i40e_tx_free_bufs(txq);
2833 : :
2834 [ # # ]: 0 : if (n == 0)
2835 : : break;
2836 : : }
2837 : :
2838 : 0 : return i;
2839 : : }
2840 : :
2841 : : static int
2842 : : i40e_tx_done_cleanup_vec(struct i40e_tx_queue *txq __rte_unused,
2843 : : uint32_t free_cnt __rte_unused)
2844 : : {
2845 : : return -ENOTSUP;
2846 : : }
2847 : : int
2848 : 0 : i40e_tx_done_cleanup(void *txq, uint32_t free_cnt)
2849 : : {
2850 : : struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
2851 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
2852 : 0 : struct i40e_adapter *ad =
2853 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2854 : :
2855 [ # # ]: 0 : if (ad->tx_simple_allowed) {
2856 [ # # ]: 0 : if (ad->tx_vec_allowed)
2857 : : return i40e_tx_done_cleanup_vec(q, free_cnt);
2858 : : else
2859 : 0 : return i40e_tx_done_cleanup_simple(q, free_cnt);
2860 : : } else {
2861 : 0 : return i40e_tx_done_cleanup_full(q, free_cnt);
2862 : : }
2863 : : }
2864 : :
2865 : : void
2866 : 0 : i40e_reset_tx_queue(struct i40e_tx_queue *txq)
2867 : : {
2868 : : struct i40e_tx_entry *txe;
2869 : : uint16_t i, prev, size;
2870 : :
2871 [ # # ]: 0 : if (!txq) {
2872 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
2873 : 0 : return;
2874 : : }
2875 : :
2876 : 0 : txe = txq->sw_ring;
2877 : 0 : size = sizeof(struct i40e_tx_desc) * txq->nb_tx_desc;
2878 [ # # ]: 0 : for (i = 0; i < size; i++)
2879 : 0 : ((volatile char *)txq->tx_ring)[i] = 0;
2880 : :
2881 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
2882 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2883 : 0 : volatile struct i40e_tx_desc *txd = &txq->tx_ring[i];
2884 : :
2885 : 0 : txd->cmd_type_offset_bsz =
2886 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE);
2887 : 0 : txe[i].mbuf = NULL;
2888 : 0 : txe[i].last_id = i;
2889 : 0 : txe[prev].next_id = i;
2890 : : prev = i;
2891 : : }
2892 : :
2893 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
2894 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
2895 : :
2896 : 0 : txq->tx_tail = 0;
2897 : 0 : txq->nb_tx_used = 0;
2898 : :
2899 : 0 : txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2900 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2901 : : }
2902 : :
2903 : : /* Init the TX queue in hardware */
2904 : : int
2905 : 0 : i40e_tx_queue_init(struct i40e_tx_queue *txq)
2906 : : {
2907 : : enum i40e_status_code err = I40E_SUCCESS;
2908 : 0 : struct i40e_vsi *vsi = txq->vsi;
2909 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2910 [ # # ]: 0 : uint16_t pf_q = txq->reg_idx;
2911 : : struct i40e_hmc_obj_txq tx_ctx;
2912 : : uint32_t qtx_ctl;
2913 : :
2914 : : /* clear the context structure first */
2915 : : memset(&tx_ctx, 0, sizeof(tx_ctx));
2916 : 0 : tx_ctx.new_context = 1;
2917 : 0 : tx_ctx.base = txq->tx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2918 : 0 : tx_ctx.qlen = txq->nb_tx_desc;
2919 : :
2920 : : #ifdef RTE_LIBRTE_IEEE1588
2921 : : tx_ctx.timesync_ena = 1;
2922 : : #endif
2923 : 0 : tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[txq->dcb_tc]);
2924 [ # # ]: 0 : if (vsi->type == I40E_VSI_FDIR)
2925 : 0 : tx_ctx.fd_ena = TRUE;
2926 : :
2927 : 0 : err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2928 [ # # ]: 0 : if (err != I40E_SUCCESS) {
2929 : 0 : PMD_DRV_LOG(ERR, "Failure of clean lan tx queue context");
2930 : 0 : return err;
2931 : : }
2932 : :
2933 : 0 : err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2934 [ # # ]: 0 : if (err != I40E_SUCCESS) {
2935 : 0 : PMD_DRV_LOG(ERR, "Failure of set lan tx queue context");
2936 : 0 : return err;
2937 : : }
2938 : :
2939 : : /* Now associate this queue with this PCI function */
2940 : : qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
2941 : 0 : qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2942 : : I40E_QTX_CTL_PF_INDX_MASK);
2943 : 0 : I40E_WRITE_REG(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2944 : 0 : I40E_WRITE_FLUSH(hw);
2945 : :
2946 : 0 : txq->qtx_tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2947 : :
2948 : 0 : return err;
2949 : : }
2950 : :
2951 : : int
2952 : 0 : i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue *rxq)
2953 : : {
2954 : 0 : struct i40e_rx_entry *rxe = rxq->sw_ring;
2955 : : uint64_t dma_addr;
2956 : : uint16_t i;
2957 : :
2958 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2959 : : volatile union i40e_rx_desc *rxd;
2960 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
2961 : :
2962 [ # # ]: 0 : if (unlikely(!mbuf)) {
2963 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
2964 : 0 : return -ENOMEM;
2965 : : }
2966 : :
2967 : : rte_mbuf_refcnt_set(mbuf, 1);
2968 : 0 : mbuf->next = NULL;
2969 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
2970 : 0 : mbuf->nb_segs = 1;
2971 : 0 : mbuf->port = rxq->port_id;
2972 : :
2973 : : dma_addr =
2974 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
2975 : :
2976 : 0 : rxd = &rxq->rx_ring[i];
2977 : 0 : rxd->read.pkt_addr = dma_addr;
2978 : 0 : rxd->read.hdr_addr = 0;
2979 : : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2980 : 0 : rxd->read.rsvd1 = 0;
2981 : 0 : rxd->read.rsvd2 = 0;
2982 : : #endif /* RTE_LIBRTE_I40E_16BYTE_RX_DESC */
2983 : :
2984 : 0 : rxe[i].mbuf = mbuf;
2985 : : }
2986 : :
2987 : : return 0;
2988 : : }
2989 : :
2990 : : /*
2991 : : * Calculate the buffer length, and check the jumbo frame
2992 : : * and maximum packet length.
2993 : : */
2994 : : static int
2995 : 0 : i40e_rx_queue_config(struct i40e_rx_queue *rxq)
2996 : : {
2997 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi);
2998 : : struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2999 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
3000 : : uint16_t buf_size;
3001 : :
3002 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
3003 : : RTE_PKTMBUF_HEADROOM);
3004 : :
3005 [ # # ]: 0 : switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
3006 : : I40E_FLAG_HEADER_SPLIT_ENABLED)) {
3007 : 0 : case I40E_FLAG_HEADER_SPLIT_ENABLED: /* Not supported */
3008 : 0 : rxq->rx_hdr_len = RTE_ALIGN(I40E_RXBUF_SZ_1024,
3009 : : (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
3010 : 0 : rxq->rx_buf_len = RTE_ALIGN(I40E_RXBUF_SZ_2048,
3011 : : (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
3012 : 0 : rxq->hs_mode = i40e_header_split_enabled;
3013 : 0 : break;
3014 : 0 : case I40E_FLAG_HEADER_SPLIT_DISABLED:
3015 : : default:
3016 : 0 : rxq->rx_hdr_len = 0;
3017 : 0 : rxq->rx_buf_len = RTE_ALIGN_FLOOR(buf_size,
3018 : : (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
3019 : 0 : rxq->rx_buf_len = RTE_MIN(rxq->rx_buf_len,
3020 : : I40E_RX_MAX_DATA_BUF_SIZE);
3021 : 0 : rxq->hs_mode = i40e_header_split_none;
3022 : 0 : break;
3023 : : }
3024 : :
3025 : 0 : rxq->max_pkt_len =
3026 : 0 : RTE_MIN(hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len,
3027 : : data->mtu + I40E_ETH_OVERHEAD);
3028 [ # # ]: 0 : if (rxq->max_pkt_len < RTE_ETHER_MIN_LEN ||
3029 : : rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
3030 : 0 : PMD_DRV_LOG(ERR, "maximum packet length must be "
3031 : : "larger than %u and smaller than %u",
3032 : : (uint32_t)RTE_ETHER_MIN_LEN,
3033 : : (uint32_t)I40E_FRAME_SIZE_MAX);
3034 : 0 : return I40E_ERR_CONFIG;
3035 : : }
3036 : :
3037 : : return 0;
3038 : : }
3039 : :
3040 : : /* Init the RX queue in hardware */
3041 : : int
3042 : 0 : i40e_rx_queue_init(struct i40e_rx_queue *rxq)
3043 : : {
3044 : : int err = I40E_SUCCESS;
3045 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
3046 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(rxq->vsi);
3047 : 0 : uint16_t pf_q = rxq->reg_idx;
3048 : : uint16_t buf_size;
3049 : : struct i40e_hmc_obj_rxq rx_ctx;
3050 : :
3051 : 0 : err = i40e_rx_queue_config(rxq);
3052 [ # # ]: 0 : if (err < 0) {
3053 : 0 : PMD_DRV_LOG(ERR, "Failed to config RX queue");
3054 : 0 : return err;
3055 : : }
3056 : :
3057 : : /* Clear the context structure first */
3058 : : memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
3059 : 0 : rx_ctx.dbuff = rxq->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
3060 : 0 : rx_ctx.hbuff = rxq->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
3061 : :
3062 : 0 : rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
3063 : 0 : rx_ctx.qlen = rxq->nb_rx_desc;
3064 : : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
3065 : 0 : rx_ctx.dsize = 1;
3066 : : #endif
3067 : 0 : rx_ctx.dtype = rxq->hs_mode;
3068 [ # # ]: 0 : if (rxq->hs_mode)
3069 : 0 : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
3070 : : else
3071 : : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
3072 : 0 : rx_ctx.rxmax = rxq->max_pkt_len;
3073 : 0 : rx_ctx.tphrdesc_ena = 1;
3074 : 0 : rx_ctx.tphwdesc_ena = 1;
3075 : 0 : rx_ctx.tphdata_ena = 1;
3076 : 0 : rx_ctx.tphhead_ena = 1;
3077 : 0 : rx_ctx.lrxqthresh = 2;
3078 : 0 : rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
3079 : 0 : rx_ctx.l2tsel = 1;
3080 : : /* showiv indicates if inner VLAN is stripped inside of tunnel
3081 : : * packet. When set it to 1, vlan information is stripped from
3082 : : * the inner header, but the hardware does not put it in the
3083 : : * descriptor. So set it zero by default.
3084 : : */
3085 : : rx_ctx.showiv = 0;
3086 : 0 : rx_ctx.prefena = 1;
3087 : :
3088 : 0 : err = i40e_clear_lan_rx_queue_context(hw, pf_q);
3089 [ # # ]: 0 : if (err != I40E_SUCCESS) {
3090 : 0 : PMD_DRV_LOG(ERR, "Failed to clear LAN RX queue context");
3091 : 0 : return err;
3092 : : }
3093 : 0 : err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
3094 [ # # ]: 0 : if (err != I40E_SUCCESS) {
3095 : 0 : PMD_DRV_LOG(ERR, "Failed to set LAN RX queue context");
3096 : 0 : return err;
3097 : : }
3098 : :
3099 : 0 : rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3100 : :
3101 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
3102 : : RTE_PKTMBUF_HEADROOM);
3103 : :
3104 : : /* Check if scattered RX needs to be used. */
3105 [ # # ]: 0 : if (rxq->max_pkt_len > buf_size)
3106 : 0 : dev_data->scattered_rx = 1;
3107 : :
3108 : : /* Init the RX tail register. */
3109 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
3110 : :
3111 : 0 : return 0;
3112 : : }
3113 : :
3114 : : void
3115 : 0 : i40e_dev_clear_queues(struct rte_eth_dev *dev)
3116 : : {
3117 : : uint16_t i;
3118 : :
3119 : 0 : PMD_INIT_FUNC_TRACE();
3120 : :
3121 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3122 [ # # ]: 0 : if (!dev->data->tx_queues[i])
3123 : 0 : continue;
3124 : 0 : i40e_tx_queue_release_mbufs(dev->data->tx_queues[i]);
3125 : 0 : i40e_reset_tx_queue(dev->data->tx_queues[i]);
3126 : : }
3127 : :
3128 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3129 [ # # ]: 0 : if (!dev->data->rx_queues[i])
3130 : 0 : continue;
3131 : 0 : i40e_rx_queue_release_mbufs(dev->data->rx_queues[i]);
3132 : 0 : i40e_reset_rx_queue(dev->data->rx_queues[i]);
3133 : : }
3134 : 0 : }
3135 : :
3136 : : void
3137 : 0 : i40e_dev_free_queues(struct rte_eth_dev *dev)
3138 : : {
3139 : : uint16_t i;
3140 : :
3141 : 0 : PMD_INIT_FUNC_TRACE();
3142 : :
3143 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3144 [ # # ]: 0 : if (!dev->data->rx_queues[i])
3145 : 0 : continue;
3146 : 0 : i40e_rx_queue_release(dev->data->rx_queues[i]);
3147 : 0 : dev->data->rx_queues[i] = NULL;
3148 : : }
3149 : :
3150 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3151 [ # # ]: 0 : if (!dev->data->tx_queues[i])
3152 : 0 : continue;
3153 : 0 : i40e_tx_queue_release(dev->data->tx_queues[i]);
3154 : 0 : dev->data->tx_queues[i] = NULL;
3155 : : }
3156 : 0 : }
3157 : :
3158 : : enum i40e_status_code
3159 : 0 : i40e_fdir_setup_tx_resources(struct i40e_pf *pf)
3160 : : {
3161 : : struct i40e_tx_queue *txq;
3162 : : const struct rte_memzone *tz = NULL;
3163 : : struct rte_eth_dev *dev;
3164 : : uint32_t ring_size;
3165 : :
3166 [ # # ]: 0 : if (!pf) {
3167 : 0 : PMD_DRV_LOG(ERR, "PF is not available");
3168 : 0 : return I40E_ERR_BAD_PTR;
3169 : : }
3170 : :
3171 : 0 : dev = &rte_eth_devices[pf->dev_data->port_id];
3172 : :
3173 : : /* Allocate the TX queue data structure. */
3174 : 0 : txq = rte_zmalloc_socket("i40e fdir tx queue",
3175 : : sizeof(struct i40e_tx_queue),
3176 : : RTE_CACHE_LINE_SIZE,
3177 : : SOCKET_ID_ANY);
3178 [ # # ]: 0 : if (!txq) {
3179 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3180 : : "tx queue structure.");
3181 : 0 : return I40E_ERR_NO_MEMORY;
3182 : : }
3183 : :
3184 : : /* Allocate TX hardware ring descriptors. */
3185 : : ring_size = sizeof(struct i40e_tx_desc) * I40E_FDIR_NUM_TX_DESC;
3186 : : ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
3187 : :
3188 : 0 : tz = rte_eth_dma_zone_reserve(dev, "fdir_tx_ring",
3189 : : I40E_FDIR_QUEUE_ID, ring_size,
3190 : : I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
3191 [ # # ]: 0 : if (!tz) {
3192 : 0 : i40e_tx_queue_release(txq);
3193 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX.");
3194 : 0 : return I40E_ERR_NO_MEMORY;
3195 : : }
3196 : :
3197 : 0 : txq->mz = tz;
3198 : 0 : txq->nb_tx_desc = I40E_FDIR_NUM_TX_DESC;
3199 : 0 : txq->queue_id = I40E_FDIR_QUEUE_ID;
3200 : 0 : txq->reg_idx = pf->fdir.fdir_vsi->base_queue;
3201 : 0 : txq->vsi = pf->fdir.fdir_vsi;
3202 : :
3203 : 0 : txq->tx_ring_phys_addr = tz->iova;
3204 : 0 : txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
3205 : :
3206 : : /*
3207 : : * don't need to allocate software ring and reset for the fdir
3208 : : * program queue just set the queue has been configured.
3209 : : */
3210 : 0 : txq->q_set = TRUE;
3211 : 0 : pf->fdir.txq = txq;
3212 : 0 : pf->fdir.txq_available_buf_count = I40E_FDIR_PRG_PKT_CNT;
3213 : :
3214 : 0 : return I40E_SUCCESS;
3215 : : }
3216 : :
3217 : : enum i40e_status_code
3218 : 0 : i40e_fdir_setup_rx_resources(struct i40e_pf *pf)
3219 : : {
3220 : : struct i40e_rx_queue *rxq;
3221 : : const struct rte_memzone *rz = NULL;
3222 : : uint32_t ring_size;
3223 : : struct rte_eth_dev *dev;
3224 : :
3225 [ # # ]: 0 : if (!pf) {
3226 : 0 : PMD_DRV_LOG(ERR, "PF is not available");
3227 : 0 : return I40E_ERR_BAD_PTR;
3228 : : }
3229 : :
3230 : 0 : dev = &rte_eth_devices[pf->dev_data->port_id];
3231 : :
3232 : : /* Allocate the RX queue data structure. */
3233 : 0 : rxq = rte_zmalloc_socket("i40e fdir rx queue",
3234 : : sizeof(struct i40e_rx_queue),
3235 : : RTE_CACHE_LINE_SIZE,
3236 : : SOCKET_ID_ANY);
3237 [ # # ]: 0 : if (!rxq) {
3238 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3239 : : "rx queue structure.");
3240 : 0 : return I40E_ERR_NO_MEMORY;
3241 : : }
3242 : :
3243 : : /* Allocate RX hardware ring descriptors. */
3244 : : ring_size = sizeof(union i40e_rx_desc) * I40E_FDIR_NUM_RX_DESC;
3245 : : ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
3246 : :
3247 : 0 : rz = rte_eth_dma_zone_reserve(dev, "fdir_rx_ring",
3248 : : I40E_FDIR_QUEUE_ID, ring_size,
3249 : : I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
3250 [ # # ]: 0 : if (!rz) {
3251 : 0 : i40e_rx_queue_release(rxq);
3252 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX.");
3253 : 0 : return I40E_ERR_NO_MEMORY;
3254 : : }
3255 : :
3256 : 0 : rxq->mz = rz;
3257 : 0 : rxq->nb_rx_desc = I40E_FDIR_NUM_RX_DESC;
3258 : 0 : rxq->queue_id = I40E_FDIR_QUEUE_ID;
3259 : 0 : rxq->reg_idx = pf->fdir.fdir_vsi->base_queue;
3260 : 0 : rxq->vsi = pf->fdir.fdir_vsi;
3261 : :
3262 : 0 : rxq->rx_ring_phys_addr = rz->iova;
3263 : 0 : memset(rz->addr, 0, I40E_FDIR_NUM_RX_DESC * sizeof(union i40e_rx_desc));
3264 : 0 : rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
3265 : :
3266 : : /*
3267 : : * Don't need to allocate software ring and reset for the fdir
3268 : : * rx queue, just set the queue has been configured.
3269 : : */
3270 : 0 : rxq->q_set = TRUE;
3271 : 0 : pf->fdir.rxq = rxq;
3272 : :
3273 : 0 : return I40E_SUCCESS;
3274 : : }
3275 : :
3276 : : void
3277 : 0 : i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3278 : : struct rte_eth_rxq_info *qinfo)
3279 : : {
3280 : : struct i40e_rx_queue *rxq;
3281 : :
3282 : 0 : rxq = dev->data->rx_queues[queue_id];
3283 : :
3284 : 0 : qinfo->mp = rxq->mp;
3285 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
3286 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
3287 : :
3288 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
3289 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
3290 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
3291 : 0 : qinfo->conf.offloads = rxq->offloads;
3292 : 0 : }
3293 : :
3294 : : void
3295 : 0 : i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3296 : : struct rte_eth_txq_info *qinfo)
3297 : : {
3298 : : struct i40e_tx_queue *txq;
3299 : :
3300 : 0 : txq = dev->data->tx_queues[queue_id];
3301 : :
3302 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
3303 : :
3304 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
3305 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
3306 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
3307 : :
3308 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
3309 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
3310 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
3311 : 0 : qinfo->conf.offloads = txq->offloads;
3312 : 0 : }
3313 : :
3314 : : void
3315 : 0 : i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3316 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
3317 : : {
3318 : : struct i40e_rx_queue *rxq;
3319 : 0 : struct i40e_adapter *ad =
3320 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3321 : :
3322 : 0 : rxq = dev->data->rx_queues[queue_id];
3323 : :
3324 : 0 : recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring;
3325 : 0 : recycle_rxq_info->mp = rxq->mp;
3326 : 0 : recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;
3327 : 0 : recycle_rxq_info->receive_tail = &rxq->rx_tail;
3328 : :
3329 [ # # ]: 0 : if (ad->rx_vec_allowed) {
3330 : 0 : recycle_rxq_info->refill_requirement = RTE_I40E_RXQ_REARM_THRESH;
3331 : 0 : recycle_rxq_info->refill_head = &rxq->rxrearm_start;
3332 : : } else {
3333 : 0 : recycle_rxq_info->refill_requirement = rxq->rx_free_thresh;
3334 : 0 : recycle_rxq_info->refill_head = &rxq->rx_free_trigger;
3335 : : }
3336 : 0 : }
3337 : :
3338 : : #ifdef RTE_ARCH_X86
3339 : : static inline bool
3340 : 0 : get_avx_supported(bool request_avx512)
3341 : : {
3342 [ # # ]: 0 : if (request_avx512) {
3343 [ # # # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512 &&
3344 [ # # ]: 0 : rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
3345 : 0 : rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512BW) == 1)
3346 : : #ifdef CC_AVX512_SUPPORT
3347 : 0 : return true;
3348 : : #else
3349 : : PMD_DRV_LOG(NOTICE,
3350 : : "AVX512 is not supported in build env");
3351 : : return false;
3352 : : #endif
3353 : : } else {
3354 [ # # # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
3355 [ # # ]: 0 : rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 &&
3356 : 0 : rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1)
3357 : 0 : return true;
3358 : : }
3359 : :
3360 : : return false;
3361 : : }
3362 : : #endif /* RTE_ARCH_X86 */
3363 : :
3364 : :
3365 : : void __rte_cold
3366 : 0 : i40e_set_rx_function(struct rte_eth_dev *dev)
3367 : : {
3368 : 0 : struct i40e_adapter *ad =
3369 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3370 : : uint16_t rx_using_sse, i;
3371 : : /* In order to allow Vector Rx there are a few configuration
3372 : : * conditions to be met and Rx Bulk Allocation should be allowed.
3373 : : */
3374 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3375 : : #ifdef RTE_ARCH_X86
3376 : 0 : ad->rx_use_avx512 = false;
3377 : 0 : ad->rx_use_avx2 = false;
3378 : : #endif
3379 [ # # ]: 0 : if (i40e_rx_vec_dev_conf_condition_check(dev) ||
3380 [ # # ]: 0 : !ad->rx_bulk_alloc_allowed) {
3381 : 0 : PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet"
3382 : : " Vector Rx preconditions",
3383 : : dev->data->port_id);
3384 : :
3385 : 0 : ad->rx_vec_allowed = false;
3386 : : }
3387 [ # # ]: 0 : if (ad->rx_vec_allowed) {
3388 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3389 : 0 : struct i40e_rx_queue *rxq =
3390 : 0 : dev->data->rx_queues[i];
3391 : :
3392 [ # # # # ]: 0 : if (rxq && i40e_rxq_vec_setup(rxq)) {
3393 : 0 : ad->rx_vec_allowed = false;
3394 : 0 : break;
3395 : : }
3396 : : }
3397 : : #ifdef RTE_ARCH_X86
3398 : 0 : ad->rx_use_avx512 = get_avx_supported(1);
3399 : :
3400 [ # # ]: 0 : if (!ad->rx_use_avx512)
3401 : 0 : ad->rx_use_avx2 = get_avx_supported(0);
3402 : : #endif
3403 : : }
3404 : : }
3405 : :
3406 [ # # # # ]: 0 : if (ad->rx_vec_allowed &&
3407 : 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
3408 : : #ifdef RTE_ARCH_X86
3409 [ # # ]: 0 : if (dev->data->scattered_rx) {
3410 [ # # ]: 0 : if (ad->rx_use_avx512) {
3411 : : #ifdef CC_AVX512_SUPPORT
3412 : 0 : PMD_DRV_LOG(NOTICE,
3413 : : "Using AVX512 Vector Scattered Rx (port %d).",
3414 : : dev->data->port_id);
3415 : 0 : dev->rx_pkt_burst =
3416 : : i40e_recv_scattered_pkts_vec_avx512;
3417 : : #endif
3418 : : } else {
3419 [ # # ]: 0 : PMD_INIT_LOG(DEBUG,
3420 : : "Using %sVector Scattered Rx (port %d).",
3421 : : ad->rx_use_avx2 ? "avx2 " : "",
3422 : : dev->data->port_id);
3423 : 0 : dev->rx_pkt_burst = ad->rx_use_avx2 ?
3424 [ # # ]: 0 : i40e_recv_scattered_pkts_vec_avx2 :
3425 : : i40e_recv_scattered_pkts_vec;
3426 : 0 : dev->recycle_rx_descriptors_refill =
3427 : : i40e_recycle_rx_descriptors_refill_vec;
3428 : : }
3429 : : } else {
3430 [ # # ]: 0 : if (ad->rx_use_avx512) {
3431 : : #ifdef CC_AVX512_SUPPORT
3432 : 0 : PMD_DRV_LOG(NOTICE,
3433 : : "Using AVX512 Vector Rx (port %d).",
3434 : : dev->data->port_id);
3435 : 0 : dev->rx_pkt_burst =
3436 : : i40e_recv_pkts_vec_avx512;
3437 : : #endif
3438 : : } else {
3439 [ # # ]: 0 : PMD_INIT_LOG(DEBUG,
3440 : : "Using %sVector Rx (port %d).",
3441 : : ad->rx_use_avx2 ? "avx2 " : "",
3442 : : dev->data->port_id);
3443 : 0 : dev->rx_pkt_burst = ad->rx_use_avx2 ?
3444 [ # # ]: 0 : i40e_recv_pkts_vec_avx2 :
3445 : : i40e_recv_pkts_vec;
3446 : 0 : dev->recycle_rx_descriptors_refill =
3447 : : i40e_recycle_rx_descriptors_refill_vec;
3448 : : }
3449 : : }
3450 : : #else /* RTE_ARCH_X86 */
3451 : : dev->recycle_rx_descriptors_refill = i40e_recycle_rx_descriptors_refill_vec;
3452 : : if (dev->data->scattered_rx) {
3453 : : PMD_INIT_LOG(DEBUG,
3454 : : "Using Vector Scattered Rx (port %d).",
3455 : : dev->data->port_id);
3456 : : dev->rx_pkt_burst = i40e_recv_scattered_pkts_vec;
3457 : : } else {
3458 : : PMD_INIT_LOG(DEBUG, "Using Vector Rx (port %d).",
3459 : : dev->data->port_id);
3460 : : dev->rx_pkt_burst = i40e_recv_pkts_vec;
3461 : : }
3462 : : #endif /* RTE_ARCH_X86 */
3463 [ # # # # ]: 0 : } else if (!dev->data->scattered_rx && ad->rx_bulk_alloc_allowed) {
3464 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
3465 : : "satisfied. Rx Burst Bulk Alloc function "
3466 : : "will be used on port=%d.",
3467 : : dev->data->port_id);
3468 : :
3469 : 0 : dev->rx_pkt_burst = i40e_recv_pkts_bulk_alloc;
3470 : : } else {
3471 : : /* Simple Rx Path. */
3472 : 0 : PMD_INIT_LOG(DEBUG, "Simple Rx path will be used on port=%d.",
3473 : : dev->data->port_id);
3474 : 0 : dev->rx_pkt_burst = dev->data->scattered_rx ?
3475 [ # # ]: 0 : i40e_recv_scattered_pkts :
3476 : : i40e_recv_pkts;
3477 : : }
3478 : :
3479 : : /* Propagate information about RX function choice through all queues. */
3480 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3481 : 0 : rx_using_sse =
3482 [ # # ]: 0 : (dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
3483 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_pkts_vec ||
3484 : : #ifdef CC_AVX512_SUPPORT
3485 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
3486 [ # # ]: 0 : dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
3487 : : #endif
3488 [ # # # # ]: 0 : dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
3489 : : dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2);
3490 : :
3491 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3492 : 0 : struct i40e_rx_queue *rxq = dev->data->rx_queues[i];
3493 : :
3494 [ # # ]: 0 : if (rxq)
3495 : 0 : rxq->rx_using_sse = rx_using_sse;
3496 : : }
3497 : : }
3498 : 0 : }
3499 : :
3500 : : static const struct {
3501 : : eth_rx_burst_t pkt_burst;
3502 : : const char *info;
3503 : : } i40e_rx_burst_infos[] = {
3504 : : { i40e_recv_scattered_pkts, "Scalar Scattered" },
3505 : : { i40e_recv_pkts_bulk_alloc, "Scalar Bulk Alloc" },
3506 : : { i40e_recv_pkts, "Scalar" },
3507 : : #ifdef RTE_ARCH_X86
3508 : : #ifdef CC_AVX512_SUPPORT
3509 : : { i40e_recv_scattered_pkts_vec_avx512, "Vector AVX512 Scattered" },
3510 : : { i40e_recv_pkts_vec_avx512, "Vector AVX512" },
3511 : : #endif
3512 : : { i40e_recv_scattered_pkts_vec_avx2, "Vector AVX2 Scattered" },
3513 : : { i40e_recv_pkts_vec_avx2, "Vector AVX2" },
3514 : : { i40e_recv_scattered_pkts_vec, "Vector SSE Scattered" },
3515 : : { i40e_recv_pkts_vec, "Vector SSE" },
3516 : : #elif defined(RTE_ARCH_ARM64)
3517 : : { i40e_recv_scattered_pkts_vec, "Vector Neon Scattered" },
3518 : : { i40e_recv_pkts_vec, "Vector Neon" },
3519 : : #elif defined(RTE_ARCH_PPC_64)
3520 : : { i40e_recv_scattered_pkts_vec, "Vector AltiVec Scattered" },
3521 : : { i40e_recv_pkts_vec, "Vector AltiVec" },
3522 : : #endif
3523 : : };
3524 : :
3525 : : int
3526 : 0 : i40e_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3527 : : struct rte_eth_burst_mode *mode)
3528 : : {
3529 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
3530 : : int ret = -EINVAL;
3531 : : unsigned int i;
3532 : :
3533 [ # # ]: 0 : for (i = 0; i < RTE_DIM(i40e_rx_burst_infos); ++i) {
3534 [ # # ]: 0 : if (pkt_burst == i40e_rx_burst_infos[i].pkt_burst) {
3535 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
3536 : 0 : i40e_rx_burst_infos[i].info);
3537 : : ret = 0;
3538 : 0 : break;
3539 : : }
3540 : : }
3541 : :
3542 : 0 : return ret;
3543 : : }
3544 : :
3545 : : void __rte_cold
3546 : 0 : i40e_set_tx_function_flag(struct rte_eth_dev *dev, struct i40e_tx_queue *txq)
3547 : : {
3548 : 0 : struct i40e_adapter *ad =
3549 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3550 : :
3551 : : /* Use a simple Tx queue if possible (only fast free is allowed) */
3552 : 0 : ad->tx_simple_allowed =
3553 : 0 : (txq->offloads ==
3554 [ # # ]: 0 : (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) &&
3555 [ # # ]: 0 : txq->tx_rs_thresh >= RTE_PMD_I40E_TX_MAX_BURST);
3556 [ # # ]: 0 : ad->tx_vec_allowed = (ad->tx_simple_allowed &&
3557 [ # # ]: 0 : txq->tx_rs_thresh <= RTE_I40E_TX_MAX_FREE_BUF_SZ);
3558 : :
3559 [ # # ]: 0 : if (ad->tx_vec_allowed)
3560 : 0 : PMD_INIT_LOG(DEBUG, "Vector Tx can be enabled on Tx queue %u.",
3561 : : txq->queue_id);
3562 [ # # ]: 0 : else if (ad->tx_simple_allowed)
3563 : 0 : PMD_INIT_LOG(DEBUG, "Simple Tx can be enabled on Tx queue %u.",
3564 : : txq->queue_id);
3565 : : else
3566 : 0 : PMD_INIT_LOG(DEBUG,
3567 : : "Neither simple nor vector Tx enabled on Tx queue %u\n",
3568 : : txq->queue_id);
3569 : 0 : }
3570 : :
3571 : : void __rte_cold
3572 : 0 : i40e_set_tx_function(struct rte_eth_dev *dev)
3573 : : {
3574 : 0 : struct i40e_adapter *ad =
3575 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3576 : 0 : uint64_t mbuf_check = ad->mbuf_check;
3577 : : int i;
3578 : :
3579 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3580 : : #ifdef RTE_ARCH_X86
3581 : 0 : ad->tx_use_avx2 = false;
3582 : 0 : ad->tx_use_avx512 = false;
3583 : : #endif
3584 [ # # ]: 0 : if (ad->tx_vec_allowed) {
3585 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3586 : 0 : struct i40e_tx_queue *txq =
3587 : 0 : dev->data->tx_queues[i];
3588 : :
3589 [ # # # # ]: 0 : if (txq && i40e_txq_vec_setup(txq)) {
3590 : 0 : ad->tx_vec_allowed = false;
3591 : 0 : break;
3592 : : }
3593 : : }
3594 : : #ifdef RTE_ARCH_X86
3595 : 0 : ad->tx_use_avx512 = get_avx_supported(1);
3596 : :
3597 [ # # ]: 0 : if (!ad->tx_use_avx512)
3598 : 0 : ad->tx_use_avx2 = get_avx_supported(0);
3599 : : #endif
3600 : : }
3601 : : }
3602 : :
3603 [ # # ]: 0 : if (ad->tx_simple_allowed) {
3604 [ # # # # ]: 0 : if (ad->tx_vec_allowed &&
3605 : 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
3606 : : #ifdef RTE_ARCH_X86
3607 [ # # ]: 0 : if (ad->tx_use_avx512) {
3608 : : #ifdef CC_AVX512_SUPPORT
3609 : 0 : PMD_DRV_LOG(NOTICE, "Using AVX512 Vector Tx (port %d).",
3610 : : dev->data->port_id);
3611 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts_vec_avx512;
3612 : : #endif
3613 : : } else {
3614 [ # # ]: 0 : PMD_INIT_LOG(DEBUG, "Using %sVector Tx (port %d).",
3615 : : ad->tx_use_avx2 ? "avx2 " : "",
3616 : : dev->data->port_id);
3617 : 0 : dev->tx_pkt_burst = ad->tx_use_avx2 ?
3618 [ # # ]: 0 : i40e_xmit_pkts_vec_avx2 :
3619 : : i40e_xmit_pkts_vec;
3620 : 0 : dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;
3621 : : }
3622 : : #else /* RTE_ARCH_X86 */
3623 : : PMD_INIT_LOG(DEBUG, "Using Vector Tx (port %d).",
3624 : : dev->data->port_id);
3625 : : dev->tx_pkt_burst = i40e_xmit_pkts_vec;
3626 : : dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;
3627 : : #endif /* RTE_ARCH_X86 */
3628 : : } else {
3629 : 0 : PMD_INIT_LOG(DEBUG, "Simple tx finally be used.");
3630 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts_simple;
3631 : 0 : dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;
3632 : : }
3633 : 0 : dev->tx_pkt_prepare = i40e_simple_prep_pkts;
3634 : : } else {
3635 : 0 : PMD_INIT_LOG(DEBUG, "Xmit tx finally be used.");
3636 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts;
3637 : 0 : dev->tx_pkt_prepare = i40e_prep_pkts;
3638 : : }
3639 : :
3640 [ # # ]: 0 : if (mbuf_check) {
3641 : 0 : ad->tx_pkt_burst = dev->tx_pkt_burst;
3642 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts_check;
3643 : : }
3644 : 0 : }
3645 : :
3646 : : static const struct {
3647 : : eth_tx_burst_t pkt_burst;
3648 : : const char *info;
3649 : : } i40e_tx_burst_infos[] = {
3650 : : { i40e_xmit_pkts_simple, "Scalar Simple" },
3651 : : { i40e_xmit_pkts, "Scalar" },
3652 : : #ifdef RTE_ARCH_X86
3653 : : #ifdef CC_AVX512_SUPPORT
3654 : : { i40e_xmit_pkts_vec_avx512, "Vector AVX512" },
3655 : : #endif
3656 : : { i40e_xmit_pkts_vec_avx2, "Vector AVX2" },
3657 : : { i40e_xmit_pkts_vec, "Vector SSE" },
3658 : : #elif defined(RTE_ARCH_ARM64)
3659 : : { i40e_xmit_pkts_vec, "Vector Neon" },
3660 : : #elif defined(RTE_ARCH_PPC_64)
3661 : : { i40e_xmit_pkts_vec, "Vector AltiVec" },
3662 : : #endif
3663 : : };
3664 : :
3665 : : int
3666 : 0 : i40e_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3667 : : struct rte_eth_burst_mode *mode)
3668 : : {
3669 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
3670 : : int ret = -EINVAL;
3671 : : unsigned int i;
3672 : :
3673 [ # # ]: 0 : for (i = 0; i < RTE_DIM(i40e_tx_burst_infos); ++i) {
3674 [ # # ]: 0 : if (pkt_burst == i40e_tx_burst_infos[i].pkt_burst) {
3675 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
3676 : 0 : i40e_tx_burst_infos[i].info);
3677 : : ret = 0;
3678 : 0 : break;
3679 : : }
3680 : : }
3681 : :
3682 : 0 : return ret;
3683 : : }
3684 : :
3685 : : void __rte_cold
3686 : 0 : i40e_set_default_ptype_table(struct rte_eth_dev *dev)
3687 : : {
3688 : 0 : struct i40e_adapter *ad =
3689 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3690 : : int i;
3691 : :
3692 [ # # ]: 0 : for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
3693 : 0 : ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
3694 : 0 : }
3695 : :
3696 : : void __rte_cold
3697 : 0 : i40e_set_default_pctype_table(struct rte_eth_dev *dev)
3698 : : {
3699 : 0 : struct i40e_adapter *ad =
3700 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3701 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3702 : : int i;
3703 : :
3704 [ # # ]: 0 : for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
3705 : 0 : ad->pctypes_tbl[i] = 0ULL;
3706 : 0 : ad->flow_types_mask = 0ULL;
3707 : 0 : ad->pctypes_mask = 0ULL;
3708 : :
3709 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV4] =
3710 : : (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4);
3711 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
3712 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP);
3713 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
3714 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
3715 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
3716 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP);
3717 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
3718 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
3719 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV6] =
3720 : : (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6);
3721 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
3722 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP);
3723 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
3724 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
3725 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
3726 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP);
3727 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
3728 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
3729 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_L2_PAYLOAD] =
3730 : : (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD);
3731 : :
3732 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 ||
3733 : : hw->mac.type == I40E_MAC_X722_VF) {
3734 : : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3735 : : (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP);
3736 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3737 : : (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
3738 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] |=
3739 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
3740 : : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3741 : : (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP);
3742 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3743 : : (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
3744 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] |=
3745 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
3746 : : }
3747 : :
3748 [ # # ]: 0 : for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
3749 [ # # ]: 0 : if (ad->pctypes_tbl[i])
3750 : 0 : ad->flow_types_mask |= (1ULL << i);
3751 : 0 : ad->pctypes_mask |= ad->pctypes_tbl[i];
3752 : : }
3753 : 0 : }
3754 : :
3755 : : #ifndef RTE_ARCH_X86
3756 : : uint16_t
3757 : : i40e_recv_pkts_vec_avx2(void __rte_unused *rx_queue,
3758 : : struct rte_mbuf __rte_unused **rx_pkts,
3759 : : uint16_t __rte_unused nb_pkts)
3760 : : {
3761 : : return 0;
3762 : : }
3763 : :
3764 : : uint16_t
3765 : : i40e_recv_scattered_pkts_vec_avx2(void __rte_unused *rx_queue,
3766 : : struct rte_mbuf __rte_unused **rx_pkts,
3767 : : uint16_t __rte_unused nb_pkts)
3768 : : {
3769 : : return 0;
3770 : : }
3771 : :
3772 : : uint16_t
3773 : : i40e_xmit_pkts_vec_avx2(void __rte_unused * tx_queue,
3774 : : struct rte_mbuf __rte_unused **tx_pkts,
3775 : : uint16_t __rte_unused nb_pkts)
3776 : : {
3777 : : return 0;
3778 : : }
3779 : : #endif /* ifndef RTE_ARCH_X86 */
|