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