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