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 : : * QinQ always places the outer tag in the ctx desc, inner in the data desc.
1011 : : */
1012 : 0 : return ci_xmit_pkts(tx_queue, tx_pkts, nb_pkts, CI_TAG_IN_DATA_DESC, CI_TAG_IN_CTX_DESC,
1013 : : get_context_desc, NULL, NULL);
1014 : : }
1015 : :
1016 : : static uint16_t
1017 : 0 : i40e_xmit_pkts_simple(void *tx_queue,
1018 : : struct rte_mbuf **tx_pkts,
1019 : : uint16_t nb_pkts)
1020 : : {
1021 [ # # ]: 0 : return ci_xmit_pkts_simple(tx_queue, tx_pkts, nb_pkts);
1022 : : }
1023 : :
1024 : : #ifndef RTE_ARCH_X86
1025 : : static uint16_t
1026 : : i40e_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
1027 : : uint16_t nb_pkts)
1028 : : {
1029 : : uint16_t nb_tx = 0;
1030 : : struct ci_tx_queue *txq = (struct ci_tx_queue *)tx_queue;
1031 : :
1032 : : while (nb_pkts) {
1033 : : uint16_t ret, num;
1034 : :
1035 : : /* cross rs_thresh boundary is not allowed */
1036 : : num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_rs_thresh);
1037 : : ret = i40e_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
1038 : : num);
1039 : : nb_tx += ret;
1040 : : nb_pkts -= ret;
1041 : : if (ret < num)
1042 : : break;
1043 : : }
1044 : :
1045 : : return nb_tx;
1046 : : }
1047 : : #endif
1048 : :
1049 : : static const struct ci_tx_path_info i40e_tx_path_infos[] = {
1050 : : [I40E_TX_DEFAULT] = {
1051 : : .pkt_burst = i40e_xmit_pkts,
1052 : : .info = "Scalar",
1053 : : .features = {
1054 : : .tx_offloads = I40E_TX_SCALAR_OFFLOADS,
1055 : : },
1056 : : .pkt_prep = i40e_prep_pkts,
1057 : : },
1058 : : [I40E_TX_SCALAR_SIMPLE] = {
1059 : : .pkt_burst = i40e_xmit_pkts_simple,
1060 : : .info = "Scalar Simple",
1061 : : .features = {
1062 : : .tx_offloads = I40E_TX_SCALAR_OFFLOADS,
1063 : : .simple_tx = true
1064 : : },
1065 : : .pkt_prep = i40e_simple_prep_pkts,
1066 : : },
1067 : : #ifdef RTE_ARCH_X86
1068 : : [I40E_TX_AVX2] = {
1069 : : .pkt_burst = i40e_xmit_pkts_vec_avx2,
1070 : : .info = "Vector AVX2",
1071 : : .features = {
1072 : : .tx_offloads = I40E_TX_VECTOR_OFFLOADS,
1073 : : .simd_width = RTE_VECT_SIMD_256,
1074 : : },
1075 : : .pkt_prep = i40e_simple_prep_pkts,
1076 : : },
1077 : : #ifdef CC_AVX512_SUPPORT
1078 : : [I40E_TX_AVX512] = {
1079 : : .pkt_burst = i40e_xmit_pkts_vec_avx512,
1080 : : .info = "Vector AVX512",
1081 : : .features = {
1082 : : .tx_offloads = I40E_TX_VECTOR_OFFLOADS,
1083 : : .simd_width = RTE_VECT_SIMD_512,
1084 : : },
1085 : : .pkt_prep = i40e_simple_prep_pkts,
1086 : : },
1087 : : #endif
1088 : : #elif defined(RTE_ARCH_ARM)
1089 : : [I40E_TX_NEON] = {
1090 : : .pkt_burst = i40e_xmit_pkts_vec,
1091 : : .info = "Vector Neon",
1092 : : .features = {
1093 : : .tx_offloads = I40E_TX_VECTOR_OFFLOADS,
1094 : : .simd_width = RTE_VECT_SIMD_128,
1095 : : },
1096 : : .pkt_prep = i40e_simple_prep_pkts,
1097 : : },
1098 : : #elif defined(RTE_ARCH_PPC_64)
1099 : : [I40E_TX_ALTIVEC] = {
1100 : : .pkt_burst = i40e_xmit_pkts_vec,
1101 : : .info = "Vector AltiVec",
1102 : : .features = {
1103 : : .tx_offloads = I40E_TX_VECTOR_OFFLOADS,
1104 : : .simd_width = RTE_VECT_SIMD_128,
1105 : : },
1106 : : .pkt_prep = i40e_simple_prep_pkts,
1107 : : },
1108 : : #endif
1109 : : };
1110 : :
1111 : : /* Tx mbuf check */
1112 : : static uint16_t
1113 : 0 : i40e_xmit_pkts_check(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1114 : : {
1115 : : struct ci_tx_queue *txq = tx_queue;
1116 : : uint16_t idx;
1117 : : uint64_t ol_flags;
1118 : : struct rte_mbuf *mb;
1119 : : bool pkt_error = false;
1120 : 0 : const char *reason = NULL;
1121 : : uint16_t good_pkts = nb_pkts;
1122 : 0 : struct i40e_adapter *adapter = txq->i40e_vsi->adapter;
1123 : 0 : enum i40e_tx_func_type tx_func_type = adapter->tx_func_type;
1124 : :
1125 [ # # ]: 0 : for (idx = 0; idx < nb_pkts; idx++) {
1126 : 0 : mb = tx_pkts[idx];
1127 : 0 : ol_flags = mb->ol_flags;
1128 : :
1129 [ # # # # ]: 0 : if ((adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_MBUF) &&
1130 : 0 : (rte_mbuf_check(mb, 1, &reason) != 0)) {
1131 : : PMD_TX_LOG(ERR, "INVALID mbuf: %s", reason);
1132 : : pkt_error = true;
1133 : : break;
1134 : : }
1135 : :
1136 [ # # ]: 0 : if ((adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_SIZE) &&
1137 [ # # # # ]: 0 : (mb->data_len > mb->pkt_len ||
1138 : 0 : mb->data_len < I40E_TX_MIN_PKT_LEN ||
1139 [ # # ]: 0 : mb->data_len > adapter->max_pkt_len)) {
1140 : : PMD_TX_LOG(ERR, "INVALID mbuf: data_len (%u) is out of range, reasonable range (%d - %u)",
1141 : : mb->data_len, I40E_TX_MIN_PKT_LEN, adapter->max_pkt_len);
1142 : : pkt_error = true;
1143 : : break;
1144 : : }
1145 : :
1146 [ # # ]: 0 : if (adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_SEGMENT) {
1147 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
1148 : : /**
1149 : : * No TSO case: nb->segs, pkt_len to not exceed
1150 : : * the limites.
1151 : : */
1152 [ # # ]: 0 : if (mb->nb_segs > I40E_TX_MAX_MTU_SEG) {
1153 : : PMD_TX_LOG(ERR, "INVALID mbuf: nb_segs (%d) exceeds HW limit, maximum allowed value is %d",
1154 : : mb->nb_segs, I40E_TX_MAX_MTU_SEG);
1155 : : pkt_error = true;
1156 : : break;
1157 : : }
1158 [ # # ]: 0 : if (mb->pkt_len > I40E_FRAME_SIZE_MAX) {
1159 : : PMD_TX_LOG(ERR, "INVALID mbuf: pkt_len (%d) exceeds HW limit, maximum allowed value is %d",
1160 : : mb->nb_segs, I40E_FRAME_SIZE_MAX);
1161 : : pkt_error = true;
1162 : : break;
1163 : : }
1164 : : } else if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
1165 : : /** TSO case: tso_segsz, nb_segs, pkt_len not exceed
1166 : : * the limits.
1167 : : */
1168 [ # # ]: 0 : if (mb->tso_segsz < I40E_MIN_TSO_MSS ||
1169 : : mb->tso_segsz > I40E_MAX_TSO_MSS) {
1170 : : /**
1171 : : * MSS outside the range are considered malicious
1172 : : */
1173 : : PMD_TX_LOG(ERR, "INVALID mbuf: tso_segsz (%u) is out of range, reasonable range (%d - %u)",
1174 : : mb->tso_segsz, I40E_MIN_TSO_MSS, I40E_MAX_TSO_MSS);
1175 : : pkt_error = true;
1176 : : break;
1177 : : }
1178 [ # # ]: 0 : if (mb->nb_segs > ((struct ci_tx_queue *)tx_queue)->nb_tx_desc) {
1179 : : PMD_TX_LOG(ERR, "INVALID mbuf: nb_segs out of ring length");
1180 : : pkt_error = true;
1181 : : break;
1182 : : }
1183 [ # # ]: 0 : if (mb->pkt_len > I40E_TSO_FRAME_SIZE_MAX) {
1184 : : PMD_TX_LOG(ERR, "INVALID mbuf: pkt_len (%d) exceeds HW limit, maximum allowed value is %d",
1185 : : mb->nb_segs, I40E_TSO_FRAME_SIZE_MAX);
1186 : : pkt_error = true;
1187 : : break;
1188 : : }
1189 : : }
1190 : : }
1191 : :
1192 [ # # ]: 0 : if (adapter->mbuf_check & I40E_MBUF_CHECK_F_TX_OFFLOAD) {
1193 [ # # ]: 0 : if (ol_flags & I40E_TX_OFFLOAD_NOTSUP_MASK) {
1194 : : PMD_TX_LOG(ERR, "INVALID mbuf: TX offload is not supported");
1195 : : pkt_error = true;
1196 : : break;
1197 : : }
1198 : :
1199 [ # # ]: 0 : if (rte_validate_tx_offload(mb) != 0) {
1200 : : PMD_TX_LOG(ERR, "INVALID mbuf: TX offload setup error");
1201 : : pkt_error = true;
1202 : : break;
1203 : : }
1204 : : }
1205 : : }
1206 : :
1207 [ # # ]: 0 : if (pkt_error) {
1208 : 0 : txq->mbuf_errors++;
1209 : : good_pkts = idx;
1210 [ # # ]: 0 : if (good_pkts == 0)
1211 : : return 0;
1212 : : }
1213 : :
1214 : 0 : return i40e_tx_path_infos[tx_func_type].pkt_burst(tx_queue, tx_pkts, good_pkts);
1215 : : }
1216 : :
1217 : : /*********************************************************************
1218 : : *
1219 : : * TX simple prep functions
1220 : : *
1221 : : **********************************************************************/
1222 : : uint16_t
1223 : 0 : i40e_simple_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1224 : : uint16_t nb_pkts)
1225 : : {
1226 : : int i;
1227 : : uint64_t ol_flags;
1228 : : struct rte_mbuf *m;
1229 : :
1230 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1231 : 0 : m = tx_pkts[i];
1232 : 0 : ol_flags = m->ol_flags;
1233 : :
1234 [ # # ]: 0 : if (m->nb_segs != 1) {
1235 : 0 : rte_errno = EINVAL;
1236 : 0 : return i;
1237 : : }
1238 : :
1239 [ # # ]: 0 : if (ol_flags & I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK) {
1240 : 0 : rte_errno = ENOTSUP;
1241 : 0 : return i;
1242 : : }
1243 : :
1244 : : /* check the size of packet */
1245 [ # # ]: 0 : if (m->pkt_len < I40E_TX_MIN_PKT_LEN ||
1246 : : m->pkt_len > I40E_FRAME_SIZE_MAX) {
1247 : 0 : rte_errno = EINVAL;
1248 : 0 : return i;
1249 : : }
1250 : : }
1251 : 0 : return i;
1252 : : }
1253 : :
1254 : : /*********************************************************************
1255 : : *
1256 : : * TX prep functions
1257 : : *
1258 : : **********************************************************************/
1259 : : uint16_t
1260 : 0 : i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1261 : : uint16_t nb_pkts)
1262 : : {
1263 : : int i, ret;
1264 : : uint64_t ol_flags;
1265 : : struct rte_mbuf *m;
1266 : :
1267 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1268 : 0 : m = tx_pkts[i];
1269 : 0 : ol_flags = m->ol_flags;
1270 : :
1271 : : /* Check for m->nb_segs to not exceed the limits. */
1272 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
1273 [ # # ]: 0 : if (m->nb_segs > I40E_TX_MAX_MTU_SEG ||
1274 [ # # ]: 0 : m->pkt_len > I40E_FRAME_SIZE_MAX) {
1275 : 0 : rte_errno = EINVAL;
1276 : 0 : return i;
1277 : : }
1278 [ # # ]: 0 : } else if (m->nb_segs > I40E_TX_MAX_SEG ||
1279 [ # # # # ]: 0 : m->tso_segsz < I40E_MIN_TSO_MSS ||
1280 : 0 : m->tso_segsz > I40E_MAX_TSO_MSS ||
1281 [ # # ]: 0 : m->pkt_len > I40E_TSO_FRAME_SIZE_MAX) {
1282 : : /* MSS outside the range (256B - 9674B) are considered
1283 : : * malicious
1284 : : */
1285 : 0 : rte_errno = EINVAL;
1286 : 0 : return i;
1287 : : }
1288 : :
1289 [ # # ]: 0 : if (ol_flags & I40E_TX_OFFLOAD_NOTSUP_MASK) {
1290 : 0 : rte_errno = ENOTSUP;
1291 : 0 : return i;
1292 : : }
1293 : :
1294 : : /* check the size of packet */
1295 [ # # ]: 0 : if (m->pkt_len < I40E_TX_MIN_PKT_LEN) {
1296 : 0 : rte_errno = EINVAL;
1297 : 0 : return i;
1298 : : }
1299 : :
1300 : : #ifdef RTE_ETHDEV_DEBUG_TX
1301 : : ret = rte_validate_tx_offload(m);
1302 : : if (ret != 0) {
1303 : : rte_errno = -ret;
1304 : : return i;
1305 : : }
1306 : : #endif
1307 : : ret = rte_net_intel_cksum_prepare(m);
1308 [ # # ]: 0 : if (ret != 0) {
1309 : 0 : rte_errno = -ret;
1310 : 0 : return i;
1311 : : }
1312 : : }
1313 : 0 : return i;
1314 : : }
1315 : :
1316 : : /*
1317 : : * Find the VSI the queue belongs to. 'queue_idx' is the queue index
1318 : : * application used, which assume having sequential ones. But from driver's
1319 : : * perspective, it's different. For example, q0 belongs to FDIR VSI, q1-q64
1320 : : * to MAIN VSI, , q65-96 to SRIOV VSIs, q97-128 to VMDQ VSIs. For application
1321 : : * running on host, q1-64 and q97-128 can be used, total 96 queues. They can
1322 : : * use queue_idx from 0 to 95 to access queues, while real queue would be
1323 : : * different. This function will do a queue mapping to find VSI the queue
1324 : : * belongs to.
1325 : : */
1326 : : static struct i40e_vsi*
1327 : 0 : i40e_pf_get_vsi_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1328 : : {
1329 : : /* the queue in MAIN VSI range */
1330 [ # # ]: 0 : if (queue_idx < pf->main_vsi->nb_qps)
1331 : : return pf->main_vsi;
1332 : :
1333 : 0 : queue_idx -= pf->main_vsi->nb_qps;
1334 : :
1335 : : /* queue_idx is greater than VMDQ VSIs range */
1336 [ # # ]: 0 : if (queue_idx > pf->nb_cfg_vmdq_vsi * pf->vmdq_nb_qps - 1) {
1337 : 0 : PMD_INIT_LOG(ERR, "queue_idx out of range. VMDQ configured?");
1338 : 0 : return NULL;
1339 : : }
1340 : :
1341 : 0 : return pf->vmdq[queue_idx / pf->vmdq_nb_qps].vsi;
1342 : : }
1343 : :
1344 : : static uint16_t
1345 : 0 : i40e_get_queue_offset_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1346 : : {
1347 : : /* the queue in MAIN VSI range */
1348 [ # # ]: 0 : if (queue_idx < pf->main_vsi->nb_qps)
1349 : : return queue_idx;
1350 : :
1351 : : /* It's VMDQ queues */
1352 : 0 : queue_idx -= pf->main_vsi->nb_qps;
1353 : :
1354 [ # # ]: 0 : if (pf->nb_cfg_vmdq_vsi)
1355 : 0 : return queue_idx % pf->vmdq_nb_qps;
1356 : : else {
1357 : 0 : PMD_INIT_LOG(ERR, "Fail to get queue offset");
1358 : 0 : return (uint16_t)(-1);
1359 : : }
1360 : : }
1361 : :
1362 : : int
1363 : 0 : i40e_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1364 : : {
1365 : : struct ci_rx_queue *rxq;
1366 : : int err;
1367 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1368 : :
1369 : 0 : PMD_INIT_FUNC_TRACE();
1370 : :
1371 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
1372 [ # # # # ]: 0 : if (!rxq || !rxq->q_set) {
1373 : 0 : PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1374 : : rx_queue_id);
1375 : 0 : return -EINVAL;
1376 : : }
1377 : :
1378 [ # # ]: 0 : if (rxq->rx_deferred_start)
1379 : 0 : PMD_DRV_LOG(WARNING, "RX queue %u is deferred start",
1380 : : rx_queue_id);
1381 : :
1382 : 0 : err = i40e_alloc_rx_queue_mbufs(rxq);
1383 [ # # ]: 0 : if (err) {
1384 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1385 : 0 : return err;
1386 : : }
1387 : :
1388 : : /* Init the RX tail register. */
1389 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1390 : :
1391 : 0 : err = i40e_switch_rx_queue(hw, rxq->reg_idx, TRUE);
1392 [ # # ]: 0 : if (err) {
1393 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1394 : : rx_queue_id);
1395 : :
1396 : 0 : i40e_rx_queue_release_mbufs(rxq);
1397 : 0 : i40e_reset_rx_queue(rxq);
1398 : 0 : return err;
1399 : : }
1400 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1401 : :
1402 : 0 : return 0;
1403 : : }
1404 : :
1405 : : int
1406 : 0 : i40e_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1407 : : {
1408 : : struct ci_rx_queue *rxq;
1409 : : int err;
1410 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1411 : :
1412 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
1413 [ # # # # ]: 0 : if (!rxq || !rxq->q_set) {
1414 : 0 : PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1415 : : rx_queue_id);
1416 : 0 : return -EINVAL;
1417 : : }
1418 : :
1419 : : /*
1420 : : * rx_queue_id is queue id application refers to, while
1421 : : * rxq->reg_idx is the real queue index.
1422 : : */
1423 : 0 : err = i40e_switch_rx_queue(hw, rxq->reg_idx, FALSE);
1424 [ # # ]: 0 : if (err) {
1425 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1426 : : rx_queue_id);
1427 : 0 : return err;
1428 : : }
1429 : 0 : i40e_rx_queue_release_mbufs(rxq);
1430 : 0 : i40e_reset_rx_queue(rxq);
1431 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1432 : :
1433 : 0 : return 0;
1434 : : }
1435 : :
1436 : : int
1437 : 0 : i40e_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1438 : : {
1439 : : int err;
1440 : : struct ci_tx_queue *txq;
1441 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1442 : : const struct i40e_adapter *ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1443 : :
1444 : 0 : PMD_INIT_FUNC_TRACE();
1445 : :
1446 : 0 : txq = dev->data->tx_queues[tx_queue_id];
1447 [ # # # # ]: 0 : if (!txq || !txq->q_set) {
1448 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1449 : : tx_queue_id);
1450 : 0 : return -EINVAL;
1451 : : }
1452 : :
1453 [ # # ]: 0 : if (txq->tx_deferred_start)
1454 : 0 : PMD_DRV_LOG(WARNING, "TX queue %u is deferred start",
1455 : : tx_queue_id);
1456 : :
1457 : 0 : txq->use_vec_entry = ad->tx_vec_allowed || ad->tx_simple_allowed;
1458 : :
1459 : : /*
1460 : : * tx_queue_id is queue id application refers to, while
1461 : : * rxq->reg_idx is the real queue index.
1462 : : */
1463 : 0 : err = i40e_switch_tx_queue(hw, txq->reg_idx, TRUE);
1464 [ # # ]: 0 : if (err) {
1465 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1466 : : tx_queue_id);
1467 : 0 : return err;
1468 : : }
1469 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1470 : :
1471 : 0 : return 0;
1472 : : }
1473 : :
1474 : : int
1475 : 0 : i40e_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1476 : : {
1477 : : struct ci_tx_queue *txq;
1478 : : int err;
1479 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1480 : :
1481 : 0 : txq = dev->data->tx_queues[tx_queue_id];
1482 [ # # # # ]: 0 : if (!txq || !txq->q_set) {
1483 : 0 : PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1484 : : tx_queue_id);
1485 : 0 : return -EINVAL;
1486 : : }
1487 : :
1488 : : /*
1489 : : * tx_queue_id is queue id application refers to, while
1490 : : * txq->reg_idx is the real queue index.
1491 : : */
1492 : 0 : err = i40e_switch_tx_queue(hw, txq->reg_idx, FALSE);
1493 [ # # ]: 0 : if (err) {
1494 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1495 : : tx_queue_id);
1496 : 0 : return err;
1497 : : }
1498 : :
1499 : 0 : ci_txq_release_all_mbufs(txq, false);
1500 : 0 : i40e_reset_tx_queue(txq);
1501 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1502 : :
1503 : 0 : return 0;
1504 : : }
1505 : :
1506 : : const uint32_t *
1507 : 0 : i40e_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
1508 : : {
1509 : 0 : const struct i40e_adapter *ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1510 : :
1511 : : static const uint32_t ptypes[] = {
1512 : : /* refers to i40e_rxd_pkt_type_mapping() */
1513 : : RTE_PTYPE_L2_ETHER,
1514 : : RTE_PTYPE_L2_ETHER_TIMESYNC,
1515 : : RTE_PTYPE_L2_ETHER_LLDP,
1516 : : RTE_PTYPE_L2_ETHER_ARP,
1517 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1518 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
1519 : : RTE_PTYPE_L4_FRAG,
1520 : : RTE_PTYPE_L4_ICMP,
1521 : : RTE_PTYPE_L4_NONFRAG,
1522 : : RTE_PTYPE_L4_SCTP,
1523 : : RTE_PTYPE_L4_TCP,
1524 : : RTE_PTYPE_L4_UDP,
1525 : : RTE_PTYPE_TUNNEL_GRENAT,
1526 : : RTE_PTYPE_TUNNEL_IP,
1527 : : RTE_PTYPE_INNER_L2_ETHER,
1528 : : RTE_PTYPE_INNER_L2_ETHER_VLAN,
1529 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
1530 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
1531 : : RTE_PTYPE_INNER_L4_FRAG,
1532 : : RTE_PTYPE_INNER_L4_ICMP,
1533 : : RTE_PTYPE_INNER_L4_NONFRAG,
1534 : : RTE_PTYPE_INNER_L4_SCTP,
1535 : : RTE_PTYPE_INNER_L4_TCP,
1536 : : RTE_PTYPE_INNER_L4_UDP,
1537 : : };
1538 : :
1539 [ # # ]: 0 : if (ad->rx_func_type == I40E_RX_DEFAULT ||
1540 [ # # ]: 0 : ad->rx_func_type == I40E_RX_BULK_ALLOC ||
1541 [ # # ]: 0 : ad->rx_func_type == I40E_RX_SCATTERED ||
1542 [ # # ]: 0 : ad->rx_func_type == I40E_RX_NEON_SCATTERED ||
1543 [ # # ]: 0 : ad->rx_func_type == I40E_RX_NEON ||
1544 [ # # ]: 0 : ad->rx_func_type == I40E_RX_ALTIVEC_SCATTERED ||
1545 [ # # ]: 0 : ad->rx_func_type == I40E_RX_ALTIVEC ||
1546 [ # # ]: 0 : ad->rx_func_type == I40E_RX_AVX512_SCATTERED ||
1547 [ # # ]: 0 : ad->rx_func_type == I40E_RX_AVX512 ||
1548 [ # # ]: 0 : ad->rx_func_type == I40E_RX_AVX2_SCATTERED ||
1549 : : ad->rx_func_type == I40E_RX_AVX2) {
1550 : 0 : *no_of_elements = RTE_DIM(ptypes);
1551 : 0 : return ptypes;
1552 : : }
1553 : : return NULL;
1554 : : }
1555 : :
1556 : : static int
1557 : : i40e_dev_first_queue(uint16_t idx, void **queues, int num)
1558 : : {
1559 : : uint16_t i;
1560 : :
1561 [ # # # # ]: 0 : for (i = 0; i < num; i++) {
1562 [ # # # # : 0 : if (i != idx && queues[i])
# # # # ]
1563 : : return 0;
1564 : : }
1565 : :
1566 : : return 1;
1567 : : }
1568 : :
1569 : : static int
1570 : 0 : i40e_dev_rx_queue_setup_runtime(struct rte_eth_dev *dev,
1571 : : struct ci_rx_queue *rxq)
1572 : : {
1573 : 0 : struct i40e_adapter *ad =
1574 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1575 : : int use_def_burst_func =
1576 : 0 : check_rx_burst_bulk_alloc_preconditions(rxq);
1577 : 0 : uint16_t buf_size =
1578 [ # # ]: 0 : (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
1579 : : RTE_PKTMBUF_HEADROOM);
1580 : : int use_scattered_rx =
1581 : 0 : (rxq->max_pkt_len > buf_size);
1582 : :
1583 [ # # ]: 0 : if (i40e_rx_queue_init(rxq) != I40E_SUCCESS) {
1584 : 0 : PMD_DRV_LOG(ERR,
1585 : : "Failed to do RX queue initialization");
1586 : 0 : return -EINVAL;
1587 : : }
1588 : :
1589 [ # # ]: 0 : if (i40e_dev_first_queue(rxq->queue_id,
1590 : : dev->data->rx_queues,
1591 : 0 : dev->data->nb_rx_queues)) {
1592 : : /**
1593 : : * If it is the first queue to setup,
1594 : : * set all flags to default and call
1595 : : * i40e_set_rx_function.
1596 : : */
1597 : 0 : ad->rx_bulk_alloc_allowed = true;
1598 : 0 : ad->rx_vec_allowed = true;
1599 : 0 : dev->data->scattered_rx = use_scattered_rx;
1600 [ # # ]: 0 : if (use_def_burst_func)
1601 : 0 : ad->rx_bulk_alloc_allowed = false;
1602 : 0 : i40e_set_rx_function(dev);
1603 : :
1604 [ # # # # ]: 0 : if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
1605 : 0 : PMD_DRV_LOG(ERR, "Failed vector rx setup.");
1606 : 0 : return -EINVAL;
1607 : : }
1608 : :
1609 : 0 : return 0;
1610 [ # # # # ]: 0 : } else if (ad->rx_vec_allowed && !rte_is_power_of_2(rxq->nb_rx_desc)) {
1611 : 0 : PMD_DRV_LOG(ERR, "Vector mode is allowed, but descriptor"
1612 : : " number %d of queue %d isn't power of 2",
1613 : : rxq->nb_rx_desc, rxq->queue_id);
1614 : 0 : return -EINVAL;
1615 : : }
1616 : :
1617 : : /* check bulk alloc conflict */
1618 [ # # # # ]: 0 : if (ad->rx_bulk_alloc_allowed && use_def_burst_func) {
1619 : 0 : PMD_DRV_LOG(ERR, "Can't use default burst.");
1620 : 0 : return -EINVAL;
1621 : : }
1622 : : /* check scattered conflict */
1623 [ # # # # ]: 0 : if (!dev->data->scattered_rx && use_scattered_rx) {
1624 : 0 : PMD_DRV_LOG(ERR, "Scattered rx is required.");
1625 : 0 : return -EINVAL;
1626 : : }
1627 : : /* check vector conflict */
1628 [ # # # # ]: 0 : if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
1629 : 0 : PMD_DRV_LOG(ERR, "Failed vector rx setup.");
1630 : 0 : return -EINVAL;
1631 : : }
1632 : :
1633 : : return 0;
1634 : : }
1635 : :
1636 : : int
1637 : 0 : i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
1638 : : uint16_t queue_idx,
1639 : : uint16_t nb_desc,
1640 : : unsigned int socket_id,
1641 : : const struct rte_eth_rxconf *rx_conf,
1642 : : struct rte_mempool *mp)
1643 : : {
1644 : 0 : struct i40e_adapter *ad =
1645 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1646 : : struct i40e_vsi *vsi;
1647 : : struct i40e_pf *pf = NULL;
1648 : : struct ci_rx_queue *rxq;
1649 : : const struct rte_memzone *rz;
1650 : : uint32_t ring_size;
1651 : : uint16_t len, i;
1652 : : uint16_t reg_idx, base, bsf, tc_mapping;
1653 : : int q_offset, use_def_burst_func = 1;
1654 : : uint64_t offloads;
1655 : :
1656 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1657 : :
1658 : 0 : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1659 : 0 : vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
1660 [ # # ]: 0 : if (!vsi)
1661 : : return -EINVAL;
1662 : 0 : q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
1663 : : if (q_offset < 0)
1664 : : return -EINVAL;
1665 : 0 : reg_idx = vsi->base_queue + q_offset;
1666 : :
1667 [ # # ]: 0 : if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
1668 [ # # ]: 0 : (nb_desc > I40E_MAX_RING_DESC) ||
1669 : : (nb_desc < I40E_MIN_RING_DESC)) {
1670 : 0 : PMD_DRV_LOG(ERR, "Number (%u) of receive descriptors is "
1671 : : "invalid", nb_desc);
1672 : 0 : return -EINVAL;
1673 : : }
1674 : :
1675 : : /* Check that ring size is > 2 * rx_free_thresh */
1676 [ # # ]: 0 : if (nb_desc <= 2 * rx_conf->rx_free_thresh) {
1677 : 0 : PMD_DRV_LOG(ERR, "rx ring size (%u) must be > 2 * rx_free_thresh (%u)",
1678 : : nb_desc, rx_conf->rx_free_thresh);
1679 [ # # ]: 0 : if (nb_desc == I40E_MIN_RING_DESC)
1680 : 0 : PMD_DRV_LOG(ERR, "To use the minimum ring size (%u), reduce rx_free_thresh to a lower value (recommended %u)",
1681 : : I40E_MIN_RING_DESC, I40E_MIN_RING_DESC / 4);
1682 : 0 : return -EINVAL;
1683 : : }
1684 : :
1685 : : /* Free memory if needed */
1686 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx]) {
1687 : 0 : i40e_rx_queue_release(dev->data->rx_queues[queue_idx]);
1688 : 0 : dev->data->rx_queues[queue_idx] = NULL;
1689 : : }
1690 : :
1691 : : /* Allocate the rx queue data structure */
1692 : 0 : rxq = rte_zmalloc_socket("i40e rx queue",
1693 : : sizeof(struct ci_rx_queue),
1694 : : RTE_CACHE_LINE_SIZE,
1695 : : socket_id);
1696 [ # # ]: 0 : if (!rxq) {
1697 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
1698 : : "rx queue data structure");
1699 : 0 : return -ENOMEM;
1700 : : }
1701 : 0 : rxq->mp = mp;
1702 : 0 : rxq->nb_rx_desc = nb_desc;
1703 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1704 : 0 : rxq->queue_id = queue_idx;
1705 : 0 : rxq->reg_idx = reg_idx;
1706 : 0 : rxq->port_id = dev->data->port_id;
1707 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1708 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
1709 : : else
1710 : 0 : rxq->crc_len = 0;
1711 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
1712 : 0 : rxq->i40e_vsi = vsi;
1713 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
1714 : 0 : rxq->offloads = offloads;
1715 : :
1716 : : /* Allocate the maximum number of RX ring hardware descriptor. */
1717 : : len = I40E_MAX_RING_DESC;
1718 : :
1719 : : /**
1720 : : * Allocating a little more memory because vectorized/bulk_alloc Rx
1721 : : * functions doesn't check boundaries each time.
1722 : : */
1723 : : len += I40E_RX_MAX_BURST;
1724 : :
1725 : : ring_size = RTE_ALIGN(len * sizeof(union ci_rx_desc),
1726 : : I40E_DMA_MEM_ALIGN);
1727 : :
1728 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
1729 : : ring_size, I40E_RING_BASE_ALIGN, socket_id);
1730 [ # # ]: 0 : if (!rz) {
1731 : 0 : i40e_rx_queue_release(rxq);
1732 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX");
1733 : 0 : return -ENOMEM;
1734 : : }
1735 : :
1736 : 0 : rxq->mz = rz;
1737 : : /* Zero all the descriptors in the ring. */
1738 : 0 : memset(rz->addr, 0, ring_size);
1739 : :
1740 : 0 : rxq->rx_ring_phys_addr = rz->iova;
1741 : 0 : rxq->rx_ring = (union ci_rx_desc *)rz->addr;
1742 : :
1743 : 0 : len = (uint16_t)(nb_desc + I40E_RX_MAX_BURST);
1744 : :
1745 : : /* Allocate the software ring. */
1746 : 0 : rxq->sw_ring =
1747 : 0 : rte_zmalloc_socket("i40e rx sw ring",
1748 : : sizeof(struct ci_rx_entry) * len,
1749 : : RTE_CACHE_LINE_SIZE,
1750 : : socket_id);
1751 [ # # ]: 0 : if (!rxq->sw_ring) {
1752 : 0 : i40e_rx_queue_release(rxq);
1753 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for SW ring");
1754 : 0 : return -ENOMEM;
1755 : : }
1756 : :
1757 : 0 : i40e_reset_rx_queue(rxq);
1758 : 0 : rxq->q_set = TRUE;
1759 : :
1760 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1761 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
1762 : 0 : continue;
1763 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
1764 : 0 : base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
1765 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
1766 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
1767 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
1768 : :
1769 [ # # # # ]: 0 : if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
1770 : 0 : rxq->dcb_tc = i;
1771 : : }
1772 : :
1773 [ # # ]: 0 : if (dev->data->dev_started) {
1774 [ # # ]: 0 : if (i40e_dev_rx_queue_setup_runtime(dev, rxq)) {
1775 : 0 : i40e_rx_queue_release(rxq);
1776 : 0 : return -EINVAL;
1777 : : }
1778 : : } else {
1779 : : use_def_burst_func =
1780 : 0 : check_rx_burst_bulk_alloc_preconditions(rxq);
1781 [ # # ]: 0 : if (!use_def_burst_func) {
1782 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1783 : 0 : PMD_INIT_LOG(DEBUG,
1784 : : "Rx Burst Bulk Alloc Preconditions are "
1785 : : "satisfied. Rx Burst Bulk Alloc function will be "
1786 : : "used on port=%d, queue=%d.",
1787 : : rxq->port_id, rxq->queue_id);
1788 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
1789 : : } else {
1790 : 0 : PMD_INIT_LOG(DEBUG,
1791 : : "Rx Burst Bulk Alloc Preconditions are "
1792 : : "not satisfied, Scattered Rx is requested, "
1793 : : "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
1794 : : "not enabled on port=%d, queue=%d.",
1795 : : rxq->port_id, rxq->queue_id);
1796 : 0 : ad->rx_bulk_alloc_allowed = false;
1797 : : }
1798 : : }
1799 : :
1800 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1801 : 0 : return 0;
1802 : : }
1803 : :
1804 : : void
1805 : 0 : i40e_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1806 : : {
1807 : 0 : i40e_rx_queue_release(dev->data->rx_queues[qid]);
1808 : 0 : }
1809 : :
1810 : : void
1811 : 0 : i40e_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1812 : : {
1813 : 0 : i40e_tx_queue_release(dev->data->tx_queues[qid]);
1814 : 0 : }
1815 : :
1816 : : void
1817 : 0 : i40e_rx_queue_release(void *rxq)
1818 : : {
1819 : : struct ci_rx_queue *q = (struct ci_rx_queue *)rxq;
1820 : :
1821 [ # # ]: 0 : if (!q) {
1822 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
1823 : 0 : return;
1824 : : }
1825 : :
1826 : 0 : i40e_rx_queue_release_mbufs(q);
1827 : 0 : rte_free(q->sw_ring);
1828 : 0 : rte_memzone_free(q->mz);
1829 : 0 : rte_free(q);
1830 : : }
1831 : :
1832 : : int
1833 : 0 : i40e_dev_rx_queue_count(void *rx_queue)
1834 : : {
1835 : : #define I40E_RXQ_SCAN_INTERVAL 4
1836 : : volatile union ci_rx_desc *rxdp;
1837 : : struct ci_rx_queue *rxq;
1838 : : uint16_t desc = 0;
1839 : :
1840 : : rxq = rx_queue;
1841 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail]);
1842 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
1843 : 0 : ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
1844 [ # # ]: 0 : I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
1845 : : (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
1846 : : /**
1847 : : * Check the DD bit of a rx descriptor of each 4 in a group,
1848 : : * to avoid checking too frequently and downgrading performance
1849 : : * too much.
1850 : : */
1851 : 0 : desc += I40E_RXQ_SCAN_INTERVAL;
1852 : 0 : rxdp += I40E_RXQ_SCAN_INTERVAL;
1853 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
1854 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
1855 : 0 : desc - rxq->nb_rx_desc]);
1856 : : }
1857 : :
1858 : 0 : return desc;
1859 : : }
1860 : :
1861 : : int
1862 : 0 : i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
1863 : : {
1864 : : struct ci_rx_queue *rxq = rx_queue;
1865 : : volatile uint64_t *status;
1866 : : uint64_t mask;
1867 : : uint32_t desc;
1868 : :
1869 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
1870 : : return -EINVAL;
1871 : :
1872 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
1873 : : return RTE_ETH_RX_DESC_UNAVAIL;
1874 : :
1875 : 0 : desc = rxq->rx_tail + offset;
1876 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
1877 : 0 : desc -= rxq->nb_rx_desc;
1878 : :
1879 : 0 : status = &rxq->rx_ring[desc].wb.qword1.status_error_len;
1880 : : mask = rte_le_to_cpu_64((1ULL << I40E_RX_DESC_STATUS_DD_SHIFT)
1881 : : << I40E_RXD_QW1_STATUS_SHIFT);
1882 [ # # ]: 0 : if (*status & mask)
1883 : 0 : return RTE_ETH_RX_DESC_DONE;
1884 : :
1885 : : return RTE_ETH_RX_DESC_AVAIL;
1886 : : }
1887 : :
1888 : : int
1889 : 0 : i40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
1890 : : {
1891 : : struct ci_tx_queue *txq = tx_queue;
1892 : : volatile uint64_t *status;
1893 : : uint64_t mask, expect;
1894 : : uint32_t desc;
1895 : :
1896 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
1897 : : return -EINVAL;
1898 : :
1899 : 0 : desc = txq->tx_tail + offset;
1900 : : /* go to next desc that has the RS bit */
1901 : 0 : desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
1902 : : txq->tx_rs_thresh;
1903 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
1904 : 0 : desc -= txq->nb_tx_desc;
1905 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
1906 : 0 : desc -= txq->nb_tx_desc;
1907 : : }
1908 : :
1909 : 0 : status = &txq->ci_tx_ring[desc].cmd_type_offset_bsz;
1910 : : mask = rte_le_to_cpu_64(CI_TXD_QW1_DTYPE_M);
1911 : : expect = rte_cpu_to_le_64(
1912 : : CI_TX_DESC_DTYPE_DESC_DONE << CI_TXD_QW1_DTYPE_S);
1913 [ # # ]: 0 : if ((*status & mask) == expect)
1914 : 0 : return RTE_ETH_TX_DESC_DONE;
1915 : :
1916 : : return RTE_ETH_TX_DESC_FULL;
1917 : : }
1918 : :
1919 : : static int
1920 : 0 : i40e_dev_tx_queue_setup_runtime(struct rte_eth_dev *dev,
1921 : : struct ci_tx_queue *txq)
1922 : : {
1923 : 0 : struct i40e_adapter *ad =
1924 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1925 : :
1926 [ # # ]: 0 : if (i40e_tx_queue_init(txq) != I40E_SUCCESS) {
1927 : 0 : PMD_DRV_LOG(ERR,
1928 : : "Failed to do TX queue initialization");
1929 : 0 : return -EINVAL;
1930 : : }
1931 : :
1932 [ # # ]: 0 : if (i40e_dev_first_queue(txq->queue_id,
1933 : : dev->data->tx_queues,
1934 : 0 : dev->data->nb_tx_queues)) {
1935 : : /**
1936 : : * If it is the first queue to setup,
1937 : : * set all flags and call
1938 : : * i40e_set_tx_function.
1939 : : */
1940 : 0 : i40e_set_tx_function_flag(dev, txq);
1941 : 0 : i40e_set_tx_function(dev);
1942 : 0 : return 0;
1943 : : }
1944 : :
1945 : : /* check vector conflict */
1946 [ # # ]: 0 : if (ad->tx_vec_allowed) {
1947 [ # # ]: 0 : if (txq->tx_rs_thresh > I40E_TX_MAX_FREE_BUF_SZ) {
1948 : 0 : PMD_DRV_LOG(ERR, "Failed vector tx setup.");
1949 : 0 : return -EINVAL;
1950 : : }
1951 : : }
1952 : : /* check simple tx conflict */
1953 [ # # ]: 0 : if (ad->tx_simple_allowed) {
1954 [ # # ]: 0 : if ((txq->offloads & ~RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) != 0 ||
1955 [ # # ]: 0 : txq->tx_rs_thresh < I40E_TX_MAX_BURST) {
1956 : 0 : PMD_DRV_LOG(ERR, "No-simple tx is required.");
1957 : 0 : return -EINVAL;
1958 : : }
1959 : : }
1960 : :
1961 : : return 0;
1962 : : }
1963 : :
1964 : : int
1965 : 0 : i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
1966 : : uint16_t queue_idx,
1967 : : uint16_t nb_desc,
1968 : : unsigned int socket_id,
1969 : : const struct rte_eth_txconf *tx_conf)
1970 : : {
1971 : : struct i40e_vsi *vsi;
1972 : : struct i40e_pf *pf = NULL;
1973 : : struct ci_tx_queue *txq;
1974 : : const struct rte_memzone *tz;
1975 : : uint32_t ring_size;
1976 : : uint16_t tx_rs_thresh, tx_free_thresh;
1977 : : uint16_t reg_idx, i, base, bsf, tc_mapping;
1978 : : int q_offset;
1979 : : uint64_t offloads;
1980 : :
1981 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
1982 : :
1983 : 0 : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1984 : 0 : vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
1985 [ # # ]: 0 : if (!vsi)
1986 : : return -EINVAL;
1987 : :
1988 : : /* Check if QinQ TX offload requires VLAN extend mode */
1989 [ # # ]: 0 : if ((offloads & RTE_ETH_TX_OFFLOAD_QINQ_INSERT) &&
1990 [ # # ]: 0 : !(dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)) {
1991 : 0 : PMD_DRV_LOG(WARNING, "Port %u: QinQ TX offload is enabled but VLAN extend mode is not set. ",
1992 : : dev->data->port_id);
1993 : 0 : PMD_DRV_LOG(WARNING, "Double VLAN insertion may not work correctly without RTE_ETH_RX_OFFLOAD_VLAN_EXTEND set in Rx configuration.");
1994 : : }
1995 : :
1996 : 0 : q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
1997 : : if (q_offset < 0)
1998 : : return -EINVAL;
1999 : 0 : reg_idx = vsi->base_queue + q_offset;
2000 : :
2001 [ # # ]: 0 : if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
2002 [ # # ]: 0 : (nb_desc > I40E_MAX_RING_DESC) ||
2003 : : (nb_desc < I40E_MIN_RING_DESC)) {
2004 : 0 : PMD_DRV_LOG(ERR, "Number (%u) of transmit descriptors is "
2005 : : "invalid", nb_desc);
2006 : 0 : return -EINVAL;
2007 : : }
2008 : :
2009 : : /**
2010 : : * The following two parameters control the setting of the RS bit on
2011 : : * transmit descriptors. TX descriptors will have their RS bit set
2012 : : * after txq->tx_rs_thresh descriptors have been used. The TX
2013 : : * descriptor ring will be cleaned after txq->tx_free_thresh
2014 : : * descriptors are used or if the number of descriptors required to
2015 : : * transmit a packet is greater than the number of free TX descriptors.
2016 : : *
2017 : : * The following constraints must be satisfied:
2018 : : * - tx_rs_thresh must be greater than 0.
2019 : : * - tx_rs_thresh must be less than the size of the ring minus 2.
2020 : : * - tx_rs_thresh must be less than or equal to tx_free_thresh.
2021 : : * - tx_rs_thresh must be a divisor of the ring size.
2022 : : * - tx_free_thresh must be greater than 0.
2023 : : * - tx_free_thresh must be less than the size of the ring minus 3.
2024 : : * - tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
2025 : : *
2026 : : * One descriptor in the TX ring is used as a sentinel to avoid a H/W
2027 : : * race condition, hence the maximum threshold constraints. When set
2028 : : * to zero use default values.
2029 : : */
2030 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2031 : : tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2032 : : /* force tx_rs_thresh to adapt an aggressive tx_free_thresh */
2033 [ # # ]: 0 : tx_rs_thresh = (DEFAULT_TX_RS_THRESH + tx_free_thresh > nb_desc) ?
2034 : : nb_desc - tx_free_thresh : DEFAULT_TX_RS_THRESH;
2035 [ # # ]: 0 : if (tx_conf->tx_rs_thresh > 0)
2036 : : tx_rs_thresh = tx_conf->tx_rs_thresh;
2037 [ # # ]: 0 : if (tx_rs_thresh + tx_free_thresh > nb_desc) {
2038 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
2039 : : "exceed nb_desc. (tx_rs_thresh=%u "
2040 : : "tx_free_thresh=%u nb_desc=%u port=%d queue=%d)",
2041 : : (unsigned int)tx_rs_thresh,
2042 : : (unsigned int)tx_free_thresh,
2043 : : (unsigned int)nb_desc,
2044 : : (int)dev->data->port_id,
2045 : : (int)queue_idx);
2046 : 0 : return I40E_ERR_PARAM;
2047 : : }
2048 [ # # ]: 0 : if (tx_rs_thresh >= (nb_desc - 2)) {
2049 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
2050 : : "number of TX descriptors minus 2. "
2051 : : "(tx_rs_thresh=%u port=%d queue=%d)",
2052 : : (unsigned int)tx_rs_thresh,
2053 : : (int)dev->data->port_id,
2054 : : (int)queue_idx);
2055 : 0 : return I40E_ERR_PARAM;
2056 : : }
2057 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
2058 : 0 : PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
2059 : : "number of TX descriptors minus 3. "
2060 : : "(tx_free_thresh=%u port=%d queue=%d)",
2061 : : (unsigned int)tx_free_thresh,
2062 : : (int)dev->data->port_id,
2063 : : (int)queue_idx);
2064 : 0 : return I40E_ERR_PARAM;
2065 : : }
2066 [ # # ]: 0 : if (tx_rs_thresh > tx_free_thresh) {
2067 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or "
2068 : : "equal to tx_free_thresh. (tx_free_thresh=%u"
2069 : : " tx_rs_thresh=%u port=%d queue=%d)",
2070 : : (unsigned int)tx_free_thresh,
2071 : : (unsigned int)tx_rs_thresh,
2072 : : (int)dev->data->port_id,
2073 : : (int)queue_idx);
2074 : 0 : return I40E_ERR_PARAM;
2075 : : }
2076 [ # # ]: 0 : if ((nb_desc % tx_rs_thresh) != 0) {
2077 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
2078 : : "number of TX descriptors. (tx_rs_thresh=%u"
2079 : : " port=%d queue=%d)",
2080 : : (unsigned int)tx_rs_thresh,
2081 : : (int)dev->data->port_id,
2082 : : (int)queue_idx);
2083 : 0 : return I40E_ERR_PARAM;
2084 : : }
2085 [ # # ]: 0 : if (!rte_is_power_of_2(tx_rs_thresh)) {
2086 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be a power of 2. (tx_rs_thresh=%u port=%d queue=%d)",
2087 : : (unsigned int)tx_rs_thresh,
2088 : : (int)dev->data->port_id,
2089 : : (int)queue_idx);
2090 : 0 : return I40E_ERR_PARAM;
2091 : : }
2092 [ # # # # ]: 0 : if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
2093 : 0 : PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
2094 : : "tx_rs_thresh is greater than 1. "
2095 : : "(tx_rs_thresh=%u port=%d queue=%d)",
2096 : : (unsigned int)tx_rs_thresh,
2097 : : (int)dev->data->port_id,
2098 : : (int)queue_idx);
2099 : 0 : return I40E_ERR_PARAM;
2100 : : }
2101 : :
2102 : : /* Free memory if needed. */
2103 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx]) {
2104 : 0 : i40e_tx_queue_release(dev->data->tx_queues[queue_idx]);
2105 : 0 : dev->data->tx_queues[queue_idx] = NULL;
2106 : : }
2107 : :
2108 : : /* Allocate the TX queue data structure. */
2109 : 0 : txq = rte_zmalloc_socket("i40e tx queue",
2110 : : sizeof(struct ci_tx_queue),
2111 : : RTE_CACHE_LINE_SIZE,
2112 : : socket_id);
2113 [ # # ]: 0 : if (!txq) {
2114 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2115 : : "tx queue structure");
2116 : 0 : return -ENOMEM;
2117 : : }
2118 : :
2119 : : /* Allocate TX hardware ring descriptors. */
2120 : : ring_size = sizeof(struct ci_tx_desc) * I40E_MAX_RING_DESC;
2121 : : ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2122 : 0 : tz = rte_eth_dma_zone_reserve(dev, "ci_tx_ring", queue_idx,
2123 : : ring_size, I40E_RING_BASE_ALIGN, socket_id);
2124 [ # # ]: 0 : if (!tz) {
2125 : 0 : i40e_tx_queue_release(txq);
2126 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX");
2127 : 0 : return -ENOMEM;
2128 : : }
2129 : :
2130 : 0 : txq->mz = tz;
2131 : 0 : txq->nb_tx_desc = nb_desc;
2132 [ # # ]: 0 : txq->tx_rs_thresh = tx_rs_thresh;
2133 : 0 : txq->log2_rs_thresh = rte_log2_u32(tx_rs_thresh);
2134 : 0 : txq->tx_free_thresh = tx_free_thresh;
2135 : 0 : txq->queue_id = queue_idx;
2136 : 0 : txq->reg_idx = reg_idx;
2137 : 0 : txq->port_id = dev->data->port_id;
2138 : 0 : txq->fast_free_mp = offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ?
2139 [ # # ]: 0 : (void *)UINTPTR_MAX : NULL;
2140 : 0 : txq->offloads = offloads;
2141 : 0 : txq->i40e_vsi = vsi;
2142 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
2143 : :
2144 : 0 : txq->tx_ring_dma = tz->iova;
2145 : 0 : txq->ci_tx_ring = (struct ci_tx_desc *)tz->addr;
2146 : :
2147 : : /* Allocate software ring */
2148 : 0 : txq->sw_ring =
2149 : 0 : rte_zmalloc_socket("i40e tx sw ring",
2150 : : sizeof(struct ci_tx_entry) * nb_desc,
2151 : : RTE_CACHE_LINE_SIZE,
2152 : : socket_id);
2153 [ # # ]: 0 : if (!txq->sw_ring) {
2154 : 0 : i40e_tx_queue_release(txq);
2155 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring");
2156 : 0 : return -ENOMEM;
2157 : : }
2158 : :
2159 : : /* Allocate RS last_id tracking array */
2160 : 0 : uint16_t num_rs_buckets = nb_desc / tx_rs_thresh;
2161 : 0 : txq->rs_last_id = rte_zmalloc_socket(NULL, sizeof(txq->rs_last_id[0]) * num_rs_buckets,
2162 : : RTE_CACHE_LINE_SIZE, socket_id);
2163 [ # # ]: 0 : if (txq->rs_last_id == NULL) {
2164 : 0 : i40e_tx_queue_release(txq);
2165 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for RS last_id array");
2166 : 0 : return -ENOMEM;
2167 : : }
2168 : :
2169 : 0 : i40e_reset_tx_queue(txq);
2170 : 0 : txq->q_set = TRUE;
2171 : :
2172 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2173 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
2174 : 0 : continue;
2175 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2176 : 0 : base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2177 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2178 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2179 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2180 : :
2181 [ # # # # ]: 0 : if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2182 : 0 : txq->dcb_tc = i;
2183 : : }
2184 : :
2185 [ # # ]: 0 : if (dev->data->dev_started) {
2186 [ # # ]: 0 : if (i40e_dev_tx_queue_setup_runtime(dev, txq)) {
2187 : 0 : i40e_tx_queue_release(txq);
2188 : 0 : return -EINVAL;
2189 : : }
2190 : : } else {
2191 : : /**
2192 : : * Use a simple TX queue without offloads or
2193 : : * multi segs if possible
2194 : : */
2195 : 0 : i40e_set_tx_function_flag(dev, txq);
2196 : : }
2197 : 0 : dev->data->tx_queues[queue_idx] = txq;
2198 : :
2199 : 0 : return 0;
2200 : : }
2201 : :
2202 : : void
2203 : 0 : i40e_tx_queue_release(void *txq)
2204 : : {
2205 : : struct ci_tx_queue *q = (struct ci_tx_queue *)txq;
2206 : :
2207 [ # # ]: 0 : if (!q) {
2208 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL");
2209 : 0 : return;
2210 : : }
2211 : :
2212 : 0 : ci_txq_release_all_mbufs(q, false);
2213 : 0 : rte_free(q->sw_ring);
2214 : 0 : rte_free(q->rs_last_id);
2215 : 0 : rte_memzone_free(q->mz);
2216 : 0 : rte_free(q);
2217 : : }
2218 : :
2219 : : const struct rte_memzone *
2220 : 0 : i40e_memzone_reserve(const char *name, uint32_t len, int socket_id)
2221 : : {
2222 : : const struct rte_memzone *mz;
2223 : :
2224 : 0 : mz = rte_memzone_lookup(name);
2225 [ # # ]: 0 : if (mz)
2226 : : return mz;
2227 : :
2228 : 0 : mz = rte_memzone_reserve_aligned(name, len, socket_id,
2229 : : RTE_MEMZONE_IOVA_CONTIG, I40E_RING_BASE_ALIGN);
2230 : 0 : return mz;
2231 : : }
2232 : :
2233 : : void
2234 : 0 : i40e_rx_queue_release_mbufs(struct ci_rx_queue *rxq)
2235 : : {
2236 : : uint16_t i;
2237 : :
2238 : : /* Vector driver has a different way of releasing mbufs. */
2239 [ # # ]: 0 : if (rxq->vector_rx) {
2240 : 0 : i40e_rx_queue_release_mbufs_vec(rxq);
2241 : 0 : return;
2242 : : }
2243 : :
2244 [ # # ]: 0 : if (!rxq->sw_ring) {
2245 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to sw_ring is NULL");
2246 : 0 : return;
2247 : : }
2248 : :
2249 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2250 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf) {
2251 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2252 : 0 : rxq->sw_ring[i].mbuf = NULL;
2253 : : }
2254 : : }
2255 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2256 [ # # ]: 0 : if (rxq->rx_nb_avail == 0)
2257 : : return;
2258 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; i++) {
2259 : : struct rte_mbuf *mbuf;
2260 : :
2261 [ # # ]: 0 : mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
2262 : : rte_pktmbuf_free_seg(mbuf);
2263 : : }
2264 : 0 : rxq->rx_nb_avail = 0;
2265 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2266 : : }
2267 : :
2268 : : void
2269 : 0 : i40e_reset_rx_queue(struct ci_rx_queue *rxq)
2270 : : {
2271 : : unsigned i;
2272 : : uint16_t len;
2273 : :
2274 [ # # ]: 0 : if (!rxq) {
2275 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2276 : 0 : return;
2277 : : }
2278 : :
2279 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2280 [ # # ]: 0 : if (check_rx_burst_bulk_alloc_preconditions(rxq) == 0)
2281 : 0 : len = (uint16_t)(rxq->nb_rx_desc + I40E_RX_MAX_BURST);
2282 : : else
2283 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2284 : 0 : len = rxq->nb_rx_desc;
2285 : :
2286 [ # # ]: 0 : for (i = 0; i < len * sizeof(union ci_rx_desc); i++)
2287 : 0 : ((volatile char *)rxq->rx_ring)[i] = 0;
2288 : :
2289 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2290 [ # # ]: 0 : for (i = 0; i < I40E_RX_MAX_BURST; ++i)
2291 : 0 : rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
2292 : :
2293 : : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2294 : 0 : rxq->rx_nb_avail = 0;
2295 : 0 : rxq->rx_next_avail = 0;
2296 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2297 : : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2298 : 0 : rxq->rx_tail = 0;
2299 : 0 : rxq->nb_rx_hold = 0;
2300 : :
2301 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
2302 : :
2303 : 0 : rxq->pkt_first_seg = NULL;
2304 : 0 : rxq->pkt_last_seg = NULL;
2305 : :
2306 : 0 : rxq->rxrearm_start = 0;
2307 : 0 : rxq->rxrearm_nb = 0;
2308 : : }
2309 : :
2310 : : static int
2311 : 0 : i40e_tx_done_cleanup_full(struct ci_tx_queue *txq,
2312 : : uint32_t free_cnt)
2313 : : {
2314 : 0 : struct ci_tx_entry *swr_ring = txq->sw_ring;
2315 : : uint16_t i, tx_last, tx_id;
2316 : : uint16_t nb_tx_free_last;
2317 : : uint16_t nb_tx_to_clean;
2318 : : uint32_t pkt_cnt;
2319 : :
2320 : : /* Start free mbuf from the next of tx_tail */
2321 : 0 : tx_last = txq->tx_tail;
2322 : 0 : tx_id = swr_ring[tx_last].next_id;
2323 : :
2324 [ # # ]: 0 : if (txq->nb_tx_free == 0 && ci_tx_xmit_cleanup(txq))
2325 : : return 0;
2326 : :
2327 : 0 : nb_tx_to_clean = txq->nb_tx_free;
2328 : : nb_tx_free_last = txq->nb_tx_free;
2329 [ # # ]: 0 : if (!free_cnt)
2330 : 0 : free_cnt = txq->nb_tx_desc;
2331 : :
2332 : : /* Loop through swr_ring to count the amount of
2333 : : * freeable mubfs and packets.
2334 : : */
2335 [ # # ]: 0 : for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2336 : 0 : for (i = 0; i < nb_tx_to_clean &&
2337 [ # # # # ]: 0 : pkt_cnt < free_cnt &&
2338 : 0 : tx_id != tx_last; i++) {
2339 [ # # ]: 0 : if (swr_ring[tx_id].mbuf != NULL) {
2340 : : /*
2341 : : * last segment in the packet,
2342 : : * increment packet count
2343 : : */
2344 [ # # ]: 0 : pkt_cnt += (swr_ring[tx_id].mbuf->next == NULL) ? 1 : 0;
2345 : : rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2346 : 0 : swr_ring[tx_id].mbuf = NULL;
2347 : : }
2348 : :
2349 : 0 : tx_id = swr_ring[tx_id].next_id;
2350 : : }
2351 : :
2352 : 0 : if (txq->tx_rs_thresh > txq->nb_tx_desc -
2353 [ # # # # ]: 0 : txq->nb_tx_free || tx_id == tx_last)
2354 : : break;
2355 : :
2356 [ # # ]: 0 : if (pkt_cnt < free_cnt) {
2357 : : if (ci_tx_xmit_cleanup(txq))
2358 : : break;
2359 : :
2360 : 0 : nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2361 : : nb_tx_free_last = txq->nb_tx_free;
2362 : : }
2363 : : }
2364 : :
2365 : 0 : return (int)pkt_cnt;
2366 : : }
2367 : :
2368 : : static int
2369 : 0 : i40e_tx_done_cleanup_simple(struct ci_tx_queue *txq,
2370 : : uint32_t free_cnt)
2371 : : {
2372 : : int i, n, cnt;
2373 : :
2374 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2375 : 0 : free_cnt = txq->nb_tx_desc;
2376 : :
2377 : 0 : cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
2378 : :
2379 [ # # ]: 0 : for (i = 0; i < cnt; i += n) {
2380 [ # # ]: 0 : if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
2381 : : break;
2382 : :
2383 : : n = ci_tx_free_bufs_simple(txq);
2384 : :
2385 [ # # ]: 0 : if (n == 0)
2386 : : break;
2387 : : }
2388 : :
2389 : 0 : return i;
2390 : : }
2391 : :
2392 : : static int
2393 : : i40e_tx_done_cleanup_vec(struct ci_tx_queue *txq __rte_unused,
2394 : : uint32_t free_cnt __rte_unused)
2395 : : {
2396 : : return -ENOTSUP;
2397 : : }
2398 : : int
2399 : 0 : i40e_tx_done_cleanup(void *txq, uint32_t free_cnt)
2400 : : {
2401 : : struct ci_tx_queue *q = (struct ci_tx_queue *)txq;
2402 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
2403 : 0 : struct i40e_adapter *ad =
2404 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2405 : :
2406 [ # # ]: 0 : if (ad->tx_simple_allowed) {
2407 [ # # ]: 0 : if (ad->tx_vec_allowed)
2408 : : return i40e_tx_done_cleanup_vec(q, free_cnt);
2409 : : else
2410 : 0 : return i40e_tx_done_cleanup_simple(q, free_cnt);
2411 : : } else {
2412 : 0 : return i40e_tx_done_cleanup_full(q, free_cnt);
2413 : : }
2414 : : }
2415 : :
2416 : : void
2417 : 0 : i40e_reset_tx_queue(struct ci_tx_queue *txq)
2418 : : {
2419 : : struct ci_tx_entry *txe;
2420 : : uint16_t i, prev, size;
2421 : :
2422 [ # # ]: 0 : if (!txq) {
2423 : 0 : PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
2424 : 0 : return;
2425 : : }
2426 : :
2427 : 0 : txe = txq->sw_ring;
2428 : 0 : size = sizeof(struct ci_tx_desc) * txq->nb_tx_desc;
2429 [ # # ]: 0 : for (i = 0; i < size; i++)
2430 : 0 : ((volatile char *)txq->ci_tx_ring)[i] = 0;
2431 : :
2432 : 0 : prev = (uint16_t)(txq->nb_tx_desc - 1);
2433 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2434 : 0 : volatile struct ci_tx_desc *txd = &txq->ci_tx_ring[i];
2435 : :
2436 : 0 : txd->cmd_type_offset_bsz =
2437 : : rte_cpu_to_le_64(CI_TX_DESC_DTYPE_DESC_DONE);
2438 : 0 : txe[i].mbuf = NULL;
2439 : 0 : txe[prev].next_id = i;
2440 : : prev = i;
2441 : : }
2442 : :
2443 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
2444 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
2445 : :
2446 : 0 : txq->tx_tail = 0;
2447 : :
2448 : 0 : txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2449 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2450 : : }
2451 : :
2452 : : /* Init the TX queue in hardware */
2453 : : int
2454 : 0 : i40e_tx_queue_init(struct ci_tx_queue *txq)
2455 : : {
2456 : : enum i40e_status_code err = I40E_SUCCESS;
2457 : 0 : struct i40e_vsi *vsi = txq->i40e_vsi;
2458 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2459 [ # # ]: 0 : uint16_t pf_q = txq->reg_idx;
2460 : : struct i40e_hmc_obj_txq tx_ctx;
2461 : : uint32_t qtx_ctl;
2462 : :
2463 : : /* clear the context structure first */
2464 : : memset(&tx_ctx, 0, sizeof(tx_ctx));
2465 : 0 : tx_ctx.new_context = 1;
2466 : 0 : tx_ctx.base = txq->tx_ring_dma / I40E_QUEUE_BASE_ADDR_UNIT;
2467 : 0 : tx_ctx.qlen = txq->nb_tx_desc;
2468 : :
2469 : : #ifdef RTE_LIBRTE_IEEE1588
2470 : : tx_ctx.timesync_ena = 1;
2471 : : #endif
2472 : 0 : tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[txq->dcb_tc]);
2473 [ # # ]: 0 : if (vsi->type == I40E_VSI_FDIR)
2474 : 0 : tx_ctx.fd_ena = TRUE;
2475 : :
2476 : 0 : err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2477 [ # # ]: 0 : if (err != I40E_SUCCESS) {
2478 : 0 : PMD_DRV_LOG(ERR, "Failure of clean lan tx queue context");
2479 : 0 : return err;
2480 : : }
2481 : :
2482 : 0 : err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2483 [ # # ]: 0 : if (err != I40E_SUCCESS) {
2484 : 0 : PMD_DRV_LOG(ERR, "Failure of set lan tx queue context");
2485 : 0 : return err;
2486 : : }
2487 : :
2488 : : /* Now associate this queue with this PCI function */
2489 : : qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
2490 : 0 : qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2491 : : I40E_QTX_CTL_PF_INDX_MASK);
2492 : 0 : I40E_WRITE_REG(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2493 : 0 : I40E_WRITE_FLUSH(hw);
2494 : :
2495 : 0 : txq->qtx_tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2496 : :
2497 : 0 : return err;
2498 : : }
2499 : :
2500 : : int
2501 : 0 : i40e_alloc_rx_queue_mbufs(struct ci_rx_queue *rxq)
2502 : : {
2503 : 0 : struct ci_rx_entry *rxe = rxq->sw_ring;
2504 : : uint64_t dma_addr;
2505 : : uint16_t i;
2506 : :
2507 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2508 : : volatile union ci_rx_desc *rxd;
2509 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
2510 : :
2511 [ # # ]: 0 : if (unlikely(!mbuf)) {
2512 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
2513 : 0 : return -ENOMEM;
2514 : : }
2515 : :
2516 : : rte_mbuf_refcnt_set(mbuf, 1);
2517 : 0 : mbuf->next = NULL;
2518 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
2519 : 0 : mbuf->nb_segs = 1;
2520 : 0 : mbuf->port = rxq->port_id;
2521 : :
2522 : : dma_addr =
2523 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
2524 : :
2525 : 0 : rxd = &rxq->rx_ring[i];
2526 : 0 : rxd->read.pkt_addr = dma_addr;
2527 : 0 : rxd->read.hdr_addr = 0;
2528 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
2529 : 0 : rxd->read.rsvd1 = 0;
2530 : 0 : rxd->read.rsvd2 = 0;
2531 : : #endif /* RTE_NET_INTEL_USE_16BYTE_DESC */
2532 : :
2533 : 0 : rxe[i].mbuf = mbuf;
2534 : : }
2535 : :
2536 : : return 0;
2537 : : }
2538 : :
2539 : : /*
2540 : : * Calculate the buffer length, and check the jumbo frame
2541 : : * and maximum packet length.
2542 : : */
2543 : : static int
2544 : 0 : i40e_rx_queue_config(struct ci_rx_queue *rxq)
2545 : : {
2546 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->i40e_vsi);
2547 : : struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->i40e_vsi);
2548 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
2549 : : uint16_t buf_size;
2550 : :
2551 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
2552 : : RTE_PKTMBUF_HEADROOM);
2553 : :
2554 [ # # ]: 0 : switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
2555 : : I40E_FLAG_HEADER_SPLIT_ENABLED)) {
2556 : 0 : case I40E_FLAG_HEADER_SPLIT_ENABLED: /* Not supported */
2557 : 0 : rxq->rx_hdr_len = RTE_ALIGN(I40E_RXBUF_SZ_1024,
2558 : : (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
2559 : 0 : rxq->rx_buf_len = RTE_ALIGN(I40E_RXBUF_SZ_2048,
2560 : : (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2561 : 0 : rxq->hs_mode = i40e_header_split_enabled;
2562 : 0 : break;
2563 : 0 : case I40E_FLAG_HEADER_SPLIT_DISABLED:
2564 : : default:
2565 : 0 : rxq->rx_hdr_len = 0;
2566 : 0 : rxq->rx_buf_len = RTE_ALIGN_FLOOR(buf_size,
2567 : : (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2568 : 0 : rxq->rx_buf_len = RTE_MIN(rxq->rx_buf_len,
2569 : : I40E_RX_MAX_DATA_BUF_SIZE);
2570 : 0 : rxq->hs_mode = i40e_header_split_none;
2571 : 0 : break;
2572 : : }
2573 : :
2574 : 0 : rxq->max_pkt_len =
2575 : 0 : RTE_MIN(hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len,
2576 : : data->mtu + I40E_ETH_OVERHEAD);
2577 [ # # ]: 0 : if (rxq->max_pkt_len < RTE_ETHER_MIN_LEN ||
2578 : : rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
2579 : 0 : PMD_DRV_LOG(ERR, "maximum packet length must be "
2580 : : "larger than %u and smaller than %u",
2581 : : (uint32_t)RTE_ETHER_MIN_LEN,
2582 : : (uint32_t)I40E_FRAME_SIZE_MAX);
2583 : 0 : return I40E_ERR_CONFIG;
2584 : : }
2585 : :
2586 : : return 0;
2587 : : }
2588 : :
2589 : : /* Init the RX queue in hardware */
2590 : : int
2591 : 0 : i40e_rx_queue_init(struct ci_rx_queue *rxq)
2592 : : {
2593 : : int err = I40E_SUCCESS;
2594 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->i40e_vsi);
2595 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(rxq->i40e_vsi);
2596 : 0 : uint16_t pf_q = rxq->reg_idx;
2597 : : uint16_t buf_size;
2598 : : struct i40e_hmc_obj_rxq rx_ctx;
2599 : :
2600 : 0 : err = i40e_rx_queue_config(rxq);
2601 [ # # ]: 0 : if (err < 0) {
2602 : 0 : PMD_DRV_LOG(ERR, "Failed to config RX queue");
2603 : 0 : return err;
2604 : : }
2605 : :
2606 : : /* Clear the context structure first */
2607 : : memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
2608 : 0 : rx_ctx.dbuff = rxq->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2609 : 0 : rx_ctx.hbuff = rxq->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2610 : :
2611 : 0 : rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2612 : 0 : rx_ctx.qlen = rxq->nb_rx_desc;
2613 : : #ifndef RTE_NET_INTEL_USE_16BYTE_DESC
2614 : 0 : rx_ctx.dsize = 1;
2615 : : #endif
2616 : 0 : rx_ctx.dtype = rxq->hs_mode;
2617 [ # # ]: 0 : if (rxq->hs_mode)
2618 : 0 : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
2619 : : else
2620 : : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
2621 : 0 : rx_ctx.rxmax = rxq->max_pkt_len;
2622 : 0 : rx_ctx.tphrdesc_ena = 1;
2623 : 0 : rx_ctx.tphwdesc_ena = 1;
2624 : 0 : rx_ctx.tphdata_ena = 1;
2625 : 0 : rx_ctx.tphhead_ena = 1;
2626 : 0 : rx_ctx.lrxqthresh = 2;
2627 : 0 : rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
2628 : 0 : rx_ctx.l2tsel = 1;
2629 : : /* showiv indicates if inner VLAN is stripped inside of tunnel
2630 : : * packet. When set it to 1, vlan information is stripped from
2631 : : * the inner header, but the hardware does not put it in the
2632 : : * descriptor. So set it zero by default.
2633 : : */
2634 : : rx_ctx.showiv = 0;
2635 : 0 : rx_ctx.prefena = 1;
2636 : :
2637 : 0 : err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2638 [ # # ]: 0 : if (err != I40E_SUCCESS) {
2639 : 0 : PMD_DRV_LOG(ERR, "Failed to clear LAN RX queue context");
2640 : 0 : return err;
2641 : : }
2642 : 0 : err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2643 [ # # ]: 0 : if (err != I40E_SUCCESS) {
2644 : 0 : PMD_DRV_LOG(ERR, "Failed to set LAN RX queue context");
2645 : 0 : return err;
2646 : : }
2647 : :
2648 : 0 : rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2649 : :
2650 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
2651 : : RTE_PKTMBUF_HEADROOM);
2652 : :
2653 : : /* Check if scattered RX needs to be used. */
2654 [ # # ]: 0 : if (rxq->max_pkt_len > buf_size)
2655 : 0 : dev_data->scattered_rx = 1;
2656 : :
2657 : : /* Init the RX tail register. */
2658 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
2659 : :
2660 : 0 : return 0;
2661 : : }
2662 : :
2663 : : void
2664 : 0 : i40e_dev_clear_queues(struct rte_eth_dev *dev)
2665 : : {
2666 : : uint16_t i;
2667 : :
2668 : 0 : PMD_INIT_FUNC_TRACE();
2669 : :
2670 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2671 [ # # ]: 0 : if (!dev->data->tx_queues[i])
2672 : 0 : continue;
2673 : 0 : ci_txq_release_all_mbufs(dev->data->tx_queues[i], false);
2674 : 0 : i40e_reset_tx_queue(dev->data->tx_queues[i]);
2675 : : }
2676 : :
2677 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2678 [ # # ]: 0 : if (!dev->data->rx_queues[i])
2679 : 0 : continue;
2680 : 0 : i40e_rx_queue_release_mbufs(dev->data->rx_queues[i]);
2681 : 0 : i40e_reset_rx_queue(dev->data->rx_queues[i]);
2682 : : }
2683 : 0 : }
2684 : :
2685 : : void
2686 : 0 : i40e_dev_free_queues(struct rte_eth_dev *dev)
2687 : : {
2688 : : uint16_t i;
2689 : :
2690 : 0 : PMD_INIT_FUNC_TRACE();
2691 : :
2692 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2693 [ # # ]: 0 : if (!dev->data->rx_queues[i])
2694 : 0 : continue;
2695 : 0 : i40e_rx_queue_release(dev->data->rx_queues[i]);
2696 : 0 : dev->data->rx_queues[i] = NULL;
2697 : : }
2698 : :
2699 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2700 [ # # ]: 0 : if (!dev->data->tx_queues[i])
2701 : 0 : continue;
2702 : 0 : i40e_tx_queue_release(dev->data->tx_queues[i]);
2703 : 0 : dev->data->tx_queues[i] = NULL;
2704 : : }
2705 : 0 : }
2706 : :
2707 : : enum i40e_status_code
2708 : 0 : i40e_fdir_setup_tx_resources(struct i40e_pf *pf)
2709 : : {
2710 : : struct ci_tx_queue *txq;
2711 : : const struct rte_memzone *tz = NULL;
2712 : : struct rte_eth_dev *dev;
2713 : : uint32_t ring_size;
2714 : :
2715 [ # # ]: 0 : if (!pf) {
2716 : 0 : PMD_DRV_LOG(ERR, "PF is not available");
2717 : 0 : return I40E_ERR_BAD_PTR;
2718 : : }
2719 : :
2720 : 0 : dev = &rte_eth_devices[pf->dev_data->port_id];
2721 : :
2722 : : /* Allocate the TX queue data structure. */
2723 : 0 : txq = rte_zmalloc_socket("i40e fdir tx queue",
2724 : : sizeof(struct ci_tx_queue),
2725 : : RTE_CACHE_LINE_SIZE,
2726 : : SOCKET_ID_ANY);
2727 [ # # ]: 0 : if (!txq) {
2728 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2729 : : "tx queue structure.");
2730 : 0 : return I40E_ERR_NO_MEMORY;
2731 : : }
2732 : :
2733 : : /* Allocate TX hardware ring descriptors. */
2734 : : ring_size = sizeof(struct ci_tx_desc) * I40E_FDIR_NUM_TX_DESC;
2735 : : ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2736 : :
2737 : 0 : tz = rte_eth_dma_zone_reserve(dev, "fdir_tx_ring",
2738 : : I40E_FDIR_QUEUE_ID, ring_size,
2739 : : I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
2740 [ # # ]: 0 : if (!tz) {
2741 : 0 : i40e_tx_queue_release(txq);
2742 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX.");
2743 : 0 : return I40E_ERR_NO_MEMORY;
2744 : : }
2745 : :
2746 : 0 : txq->mz = tz;
2747 : 0 : txq->nb_tx_desc = I40E_FDIR_NUM_TX_DESC;
2748 : 0 : txq->queue_id = I40E_FDIR_QUEUE_ID;
2749 : 0 : txq->reg_idx = pf->fdir.fdir_vsi->base_queue;
2750 : 0 : txq->i40e_vsi = pf->fdir.fdir_vsi;
2751 : :
2752 : 0 : txq->tx_ring_dma = tz->iova;
2753 : 0 : txq->ci_tx_ring = (struct ci_tx_desc *)tz->addr;
2754 : :
2755 : : /*
2756 : : * don't need to allocate software ring and reset for the fdir
2757 : : * program queue just set the queue has been configured.
2758 : : */
2759 : 0 : txq->q_set = TRUE;
2760 : 0 : pf->fdir.txq = txq;
2761 : 0 : pf->fdir.txq_available_buf_count = I40E_FDIR_PRG_PKT_CNT;
2762 : :
2763 : 0 : return I40E_SUCCESS;
2764 : : }
2765 : :
2766 : : enum i40e_status_code
2767 : 0 : i40e_fdir_setup_rx_resources(struct i40e_pf *pf)
2768 : : {
2769 : : struct ci_rx_queue *rxq;
2770 : : const struct rte_memzone *rz = NULL;
2771 : : uint32_t ring_size;
2772 : : struct rte_eth_dev *dev;
2773 : :
2774 [ # # ]: 0 : if (!pf) {
2775 : 0 : PMD_DRV_LOG(ERR, "PF is not available");
2776 : 0 : return I40E_ERR_BAD_PTR;
2777 : : }
2778 : :
2779 : 0 : dev = &rte_eth_devices[pf->dev_data->port_id];
2780 : :
2781 : : /* Allocate the RX queue data structure. */
2782 : 0 : rxq = rte_zmalloc_socket("i40e fdir rx queue",
2783 : : sizeof(struct ci_rx_queue),
2784 : : RTE_CACHE_LINE_SIZE,
2785 : : SOCKET_ID_ANY);
2786 [ # # ]: 0 : if (!rxq) {
2787 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2788 : : "rx queue structure.");
2789 : 0 : return I40E_ERR_NO_MEMORY;
2790 : : }
2791 : :
2792 : : /* Allocate RX hardware ring descriptors. */
2793 : : ring_size = sizeof(union ci_rx_desc) * I40E_FDIR_NUM_RX_DESC;
2794 : : ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2795 : :
2796 : 0 : rz = rte_eth_dma_zone_reserve(dev, "fdir_rx_ring",
2797 : : I40E_FDIR_QUEUE_ID, ring_size,
2798 : : I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
2799 [ # # ]: 0 : if (!rz) {
2800 : 0 : i40e_rx_queue_release(rxq);
2801 : 0 : PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX.");
2802 : 0 : return I40E_ERR_NO_MEMORY;
2803 : : }
2804 : :
2805 : 0 : rxq->mz = rz;
2806 : 0 : rxq->nb_rx_desc = I40E_FDIR_NUM_RX_DESC;
2807 : 0 : rxq->queue_id = I40E_FDIR_QUEUE_ID;
2808 : 0 : rxq->reg_idx = pf->fdir.fdir_vsi->base_queue;
2809 : 0 : rxq->i40e_vsi = pf->fdir.fdir_vsi;
2810 : :
2811 : 0 : rxq->rx_ring_phys_addr = rz->iova;
2812 : 0 : memset(rz->addr, 0, I40E_FDIR_NUM_RX_DESC * sizeof(union ci_rx_desc));
2813 : 0 : rxq->rx_ring = (union ci_rx_desc *)rz->addr;
2814 : :
2815 : : /*
2816 : : * Don't need to allocate software ring and reset for the fdir
2817 : : * rx queue, just set the queue has been configured.
2818 : : */
2819 : 0 : rxq->q_set = TRUE;
2820 : 0 : pf->fdir.rxq = rxq;
2821 : :
2822 : 0 : return I40E_SUCCESS;
2823 : : }
2824 : :
2825 : : void
2826 : 0 : i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2827 : : struct rte_eth_rxq_info *qinfo)
2828 : : {
2829 : : struct ci_rx_queue *rxq;
2830 : :
2831 : 0 : rxq = dev->data->rx_queues[queue_id];
2832 : :
2833 : 0 : qinfo->mp = rxq->mp;
2834 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
2835 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
2836 : :
2837 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2838 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
2839 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
2840 : 0 : qinfo->conf.offloads = rxq->offloads;
2841 : 0 : }
2842 : :
2843 : : void
2844 : 0 : i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2845 : : struct rte_eth_txq_info *qinfo)
2846 : : {
2847 : : struct ci_tx_queue *txq;
2848 : :
2849 : 0 : txq = dev->data->tx_queues[queue_id];
2850 : :
2851 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
2852 : :
2853 : 0 : qinfo->conf.tx_thresh.pthresh = I40E_DEFAULT_TX_PTHRESH;
2854 : 0 : qinfo->conf.tx_thresh.hthresh = I40E_DEFAULT_TX_HTHRESH;
2855 : 0 : qinfo->conf.tx_thresh.wthresh = I40E_DEFAULT_TX_WTHRESH;
2856 : :
2857 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
2858 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
2859 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
2860 : 0 : qinfo->conf.offloads = txq->offloads;
2861 : 0 : }
2862 : :
2863 : : void
2864 : 0 : i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2865 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
2866 : : {
2867 : : struct ci_rx_queue *rxq;
2868 : 0 : struct i40e_adapter *ad =
2869 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2870 : :
2871 : 0 : rxq = dev->data->rx_queues[queue_id];
2872 : :
2873 : 0 : recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring;
2874 : 0 : recycle_rxq_info->mp = rxq->mp;
2875 : 0 : recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;
2876 : 0 : recycle_rxq_info->receive_tail = &rxq->rx_tail;
2877 : :
2878 [ # # ]: 0 : if (ad->rx_vec_allowed) {
2879 : 0 : recycle_rxq_info->refill_requirement = I40E_VPMD_RXQ_REARM_THRESH;
2880 : 0 : recycle_rxq_info->refill_head = &rxq->rxrearm_start;
2881 : : } else {
2882 : 0 : recycle_rxq_info->refill_requirement = rxq->rx_free_thresh;
2883 : 0 : recycle_rxq_info->refill_head = &rxq->rx_free_trigger;
2884 : : }
2885 : 0 : }
2886 : :
2887 : : static const struct ci_rx_path_info i40e_rx_path_infos[] = {
2888 : : [I40E_RX_DEFAULT] = {
2889 : : .pkt_burst = i40e_recv_pkts,
2890 : : .info = "Scalar",
2891 : : .features = {
2892 : : .rx_offloads = I40E_RX_SCALAR_OFFLOADS
2893 : : }
2894 : : },
2895 : : [I40E_RX_SCATTERED] = {
2896 : : .pkt_burst = i40e_recv_scattered_pkts,
2897 : : .info = "Scalar Scattered",
2898 : : .features = {
2899 : : .rx_offloads = I40E_RX_SCALAR_OFFLOADS,
2900 : : .scattered = true
2901 : : }
2902 : : },
2903 : : [I40E_RX_BULK_ALLOC] = {
2904 : : .pkt_burst = i40e_recv_pkts_bulk_alloc,
2905 : : .info = "Scalar Bulk Alloc",
2906 : : .features = {
2907 : : .rx_offloads = I40E_RX_SCALAR_OFFLOADS,
2908 : : .bulk_alloc = true
2909 : : }
2910 : : },
2911 : : #ifdef RTE_ARCH_X86
2912 : : [I40E_RX_AVX2] = {
2913 : : .pkt_burst = i40e_recv_pkts_vec_avx2,
2914 : : .info = "Vector AVX2",
2915 : : .features = {
2916 : : .rx_offloads = I40E_RX_VECTOR_OFFLOADS,
2917 : : .simd_width = RTE_VECT_SIMD_256,
2918 : : .bulk_alloc = true
2919 : : }
2920 : : },
2921 : : [I40E_RX_AVX2_SCATTERED] = {
2922 : : .pkt_burst = i40e_recv_scattered_pkts_vec_avx2,
2923 : : .info = "Vector AVX2 Scattered",
2924 : : .features = {
2925 : : .rx_offloads = I40E_RX_VECTOR_OFFLOADS,
2926 : : .simd_width = RTE_VECT_SIMD_256,
2927 : : .scattered = true,
2928 : : .bulk_alloc = true
2929 : : }
2930 : : },
2931 : : #ifdef CC_AVX512_SUPPORT
2932 : : [I40E_RX_AVX512] = {
2933 : : .pkt_burst = i40e_recv_pkts_vec_avx512,
2934 : : .info = "Vector AVX512",
2935 : : .features = {
2936 : : .rx_offloads = I40E_RX_VECTOR_OFFLOADS,
2937 : : .simd_width = RTE_VECT_SIMD_512,
2938 : : .bulk_alloc = true
2939 : : }
2940 : : },
2941 : : [I40E_RX_AVX512_SCATTERED] = {
2942 : : .pkt_burst = i40e_recv_scattered_pkts_vec_avx512,
2943 : : .info = "Vector AVX512 Scattered",
2944 : : .features = {
2945 : : .rx_offloads = I40E_RX_VECTOR_OFFLOADS,
2946 : : .simd_width = RTE_VECT_SIMD_512,
2947 : : .scattered = true,
2948 : : .bulk_alloc = true
2949 : : }
2950 : : },
2951 : : #endif
2952 : : #elif defined(RTE_ARCH_ARM64)
2953 : : [I40E_RX_NEON] = {
2954 : : .pkt_burst = i40e_recv_pkts_vec,
2955 : : .info = "Vector Neon",
2956 : : .features = {
2957 : : .rx_offloads = I40E_RX_SCALAR_OFFLOADS,
2958 : : .simd_width = RTE_VECT_SIMD_128,
2959 : : .bulk_alloc = true
2960 : : }
2961 : : },
2962 : : [I40E_RX_NEON_SCATTERED] = {
2963 : : .pkt_burst = i40e_recv_scattered_pkts_vec,
2964 : : .info = "Vector Neon Scattered",
2965 : : .features = {
2966 : : .rx_offloads = I40E_RX_SCALAR_OFFLOADS,
2967 : : .simd_width = RTE_VECT_SIMD_128,
2968 : : .scattered = true,
2969 : : .bulk_alloc = true
2970 : : }
2971 : : },
2972 : : #elif defined(RTE_ARCH_PPC_64)
2973 : : [I40E_RX_ALTIVEC] = {
2974 : : .pkt_burst = i40e_recv_pkts_vec,
2975 : : .info = "Vector AltiVec",
2976 : : .features = {
2977 : : .rx_offloads = I40E_RX_SCALAR_OFFLOADS,
2978 : : .simd_width = RTE_VECT_SIMD_128,
2979 : : .bulk_alloc = true
2980 : : }
2981 : : },
2982 : : [I40E_RX_ALTIVEC_SCATTERED] = {
2983 : : .pkt_burst = i40e_recv_scattered_pkts_vec,
2984 : : .info = "Vector AltiVec Scattered",
2985 : : .features = {
2986 : : .rx_offloads = I40E_RX_SCALAR_OFFLOADS,
2987 : : .simd_width = RTE_VECT_SIMD_128,
2988 : : .scattered = true,
2989 : : .bulk_alloc = true
2990 : : }
2991 : : },
2992 : : #endif
2993 : : };
2994 : :
2995 : : void __rte_cold
2996 : 0 : i40e_set_rx_function(struct rte_eth_dev *dev)
2997 : : {
2998 : 0 : struct i40e_adapter *ad =
2999 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3000 : 0 : struct ci_rx_path_features req_features = {
3001 : 0 : .rx_offloads = dev->data->dev_conf.rxmode.offloads,
3002 : : .simd_width = RTE_VECT_SIMD_DISABLED,
3003 : : };
3004 : : uint16_t i;
3005 : 0 : enum rte_vect_max_simd rx_simd_width = i40e_get_max_simd_bitwidth();
3006 : :
3007 : : /* If the device has started the function has already been selected. */
3008 [ # # ]: 0 : if (dev->data->dev_started)
3009 : 0 : goto out;
3010 : :
3011 : : /* In order to allow Vector Rx there are a few configuration
3012 : : * conditions to be met and Rx Bulk Allocation should be allowed.
3013 : : */
3014 : :
3015 [ # # # # ]: 0 : if (i40e_rx_vec_dev_conf_condition_check(dev) || !ad->rx_bulk_alloc_allowed) {
3016 : 0 : PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet"
3017 : : " Vector Rx preconditions",
3018 : : dev->data->port_id);
3019 : :
3020 : : rx_simd_width = RTE_VECT_SIMD_DISABLED;
3021 : : }
3022 : :
3023 : 0 : req_features.simd_width = rx_simd_width;
3024 [ # # ]: 0 : if (dev->data->scattered_rx)
3025 : 0 : req_features.scattered = true;
3026 [ # # ]: 0 : if (ad->rx_bulk_alloc_allowed)
3027 : 0 : req_features.bulk_alloc = true;
3028 : :
3029 : 0 : ad->rx_func_type = ci_rx_path_select(&req_features,
3030 : : &i40e_rx_path_infos[0],
3031 : : RTE_DIM(i40e_rx_path_infos),
3032 : : I40E_RX_DEFAULT);
3033 [ # # ]: 0 : if (i40e_rx_path_infos[ad->rx_func_type].features.simd_width >= RTE_VECT_SIMD_128) {
3034 : : /* Vector function selected. Prepare the rxq accordingly. */
3035 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
3036 [ # # ]: 0 : if (dev->data->rx_queues[i])
3037 : 0 : i40e_rxq_vec_setup(dev->data->rx_queues[i]);
3038 : 0 : ad->rx_vec_allowed = true;
3039 : : }
3040 : :
3041 [ # # ]: 0 : if (i40e_rx_path_infos[ad->rx_func_type].features.simd_width >= RTE_VECT_SIMD_128 &&
3042 : : i40e_rx_path_infos[ad->rx_func_type].features.simd_width <
3043 : : RTE_VECT_SIMD_512)
3044 : 0 : dev->recycle_rx_descriptors_refill = i40e_recycle_rx_descriptors_refill_vec;
3045 : :
3046 : 0 : out:
3047 : 0 : dev->rx_pkt_burst = i40e_rx_path_infos[ad->rx_func_type].pkt_burst;
3048 : 0 : PMD_DRV_LOG(DEBUG, "Using %s (port %d).",
3049 : : i40e_rx_path_infos[ad->rx_func_type].info, dev->data->port_id);
3050 : 0 : }
3051 : :
3052 : : int
3053 : 0 : i40e_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3054 : : struct rte_eth_burst_mode *mode)
3055 : : {
3056 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
3057 : : int ret = -EINVAL;
3058 : : unsigned int i;
3059 : :
3060 [ # # ]: 0 : for (i = 0; i < RTE_DIM(i40e_rx_path_infos); ++i) {
3061 [ # # ]: 0 : if (pkt_burst == i40e_rx_path_infos[i].pkt_burst) {
3062 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
3063 : 0 : i40e_rx_path_infos[i].info);
3064 : : ret = 0;
3065 : 0 : break;
3066 : : }
3067 : : }
3068 : :
3069 : 0 : return ret;
3070 : : }
3071 : :
3072 : : void __rte_cold
3073 : 0 : i40e_set_tx_function_flag(struct rte_eth_dev *dev, struct ci_tx_queue *txq)
3074 : : {
3075 : 0 : struct i40e_adapter *ad =
3076 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3077 : :
3078 : : /* Use a simple Tx queue if possible (only fast free is allowed) */
3079 : 0 : ad->tx_simple_allowed =
3080 : 0 : (txq->offloads ==
3081 [ # # ]: 0 : (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) &&
3082 [ # # ]: 0 : txq->tx_rs_thresh >= I40E_TX_MAX_BURST);
3083 [ # # ]: 0 : ad->tx_vec_allowed = (ad->tx_simple_allowed &&
3084 [ # # ]: 0 : txq->tx_rs_thresh <= I40E_TX_MAX_FREE_BUF_SZ);
3085 : :
3086 [ # # ]: 0 : if (ad->tx_vec_allowed)
3087 : 0 : PMD_INIT_LOG(DEBUG, "Vector Tx can be enabled on Tx queue %u.",
3088 : : txq->queue_id);
3089 [ # # ]: 0 : else if (ad->tx_simple_allowed)
3090 : 0 : PMD_INIT_LOG(DEBUG, "Simple Tx can be enabled on Tx queue %u.",
3091 : : txq->queue_id);
3092 : : else
3093 : 0 : PMD_INIT_LOG(DEBUG,
3094 : : "Neither simple nor vector Tx enabled on Tx queue %u",
3095 : : txq->queue_id);
3096 : 0 : }
3097 : :
3098 : : void __rte_cold
3099 : 0 : i40e_set_tx_function(struct rte_eth_dev *dev)
3100 : : {
3101 : 0 : struct i40e_adapter *ad =
3102 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3103 : 0 : uint64_t mbuf_check = ad->mbuf_check;
3104 : 0 : struct ci_tx_path_features req_features = {
3105 : 0 : .tx_offloads = dev->data->dev_conf.txmode.offloads,
3106 : : .simd_width = RTE_VECT_SIMD_DISABLED,
3107 : 0 : .simple_tx = ad->tx_simple_allowed
3108 : : };
3109 : :
3110 : : /* If the device has started the function has already been selected. */
3111 [ # # ]: 0 : if (dev->data->dev_started)
3112 : 0 : goto out;
3113 : :
3114 [ # # ]: 0 : if (ad->tx_vec_allowed) {
3115 : : #ifdef RTE_ARCH_X86
3116 : 0 : req_features.simd_width = i40e_get_max_simd_bitwidth();
3117 : : #else
3118 : : req_features.simd_width = rte_vect_get_max_simd_bitwidth();
3119 : : #endif
3120 : : }
3121 : :
3122 : 0 : ad->tx_func_type = ci_tx_path_select(&req_features, &i40e_tx_path_infos[0],
3123 : : RTE_DIM(i40e_tx_path_infos), I40E_TX_DEFAULT, false);
3124 : :
3125 : 0 : out:
3126 [ # # ]: 0 : dev->tx_pkt_burst = mbuf_check ? i40e_xmit_pkts_check :
3127 : 0 : i40e_tx_path_infos[ad->tx_func_type].pkt_burst;
3128 : 0 : dev->tx_pkt_prepare = i40e_tx_path_infos[ad->tx_func_type].pkt_prep;
3129 : :
3130 : 0 : PMD_DRV_LOG(DEBUG, "Using %s (port %d).",
3131 : : i40e_tx_path_infos[ad->tx_func_type].info, dev->data->port_id);
3132 : :
3133 [ # # ]: 0 : if (ad->tx_func_type == I40E_TX_SCALAR_SIMPLE ||
3134 [ # # ]: 0 : ad->tx_func_type == I40E_TX_NEON ||
3135 [ # # ]: 0 : ad->tx_func_type == I40E_TX_ALTIVEC ||
3136 : : ad->tx_func_type == I40E_TX_AVX2)
3137 : 0 : dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;
3138 : :
3139 : 0 : ad->tx_vec_allowed =
3140 : 0 : (i40e_tx_path_infos[ad->tx_func_type].features.simd_width >= RTE_VECT_SIMD_128);
3141 : :
3142 : 0 : }
3143 : :
3144 : : int
3145 : 0 : i40e_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3146 : : struct rte_eth_burst_mode *mode)
3147 : : {
3148 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
3149 : : int ret = -EINVAL;
3150 : : unsigned int i;
3151 : :
3152 [ # # ]: 0 : for (i = 0; i < RTE_DIM(i40e_tx_path_infos); ++i) {
3153 [ # # ]: 0 : if (pkt_burst == i40e_tx_path_infos[i].pkt_burst) {
3154 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
3155 : 0 : i40e_tx_path_infos[i].info);
3156 : : ret = 0;
3157 : 0 : break;
3158 : : }
3159 : : }
3160 : :
3161 : 0 : return ret;
3162 : : }
3163 : :
3164 : : void __rte_cold
3165 : 0 : i40e_set_default_ptype_table(struct rte_eth_dev *dev)
3166 : : {
3167 : 0 : struct i40e_adapter *ad =
3168 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3169 : : int i;
3170 : :
3171 [ # # ]: 0 : for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
3172 : 0 : ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
3173 : 0 : }
3174 : :
3175 : : void __rte_cold
3176 : 0 : i40e_set_default_pctype_table(struct rte_eth_dev *dev)
3177 : : {
3178 : 0 : struct i40e_adapter *ad =
3179 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3180 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3181 : : int i;
3182 : :
3183 [ # # ]: 0 : for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
3184 : 0 : ad->pctypes_tbl[i] = 0ULL;
3185 : 0 : ad->flow_types_mask = 0ULL;
3186 : 0 : ad->pctypes_mask = 0ULL;
3187 : :
3188 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_IPV4] =
3189 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
3190 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV4] =
3191 : : (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4);
3192 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
3193 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP);
3194 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
3195 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
3196 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
3197 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP);
3198 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
3199 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
3200 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV6] =
3201 : : (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6);
3202 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
3203 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP);
3204 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
3205 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
3206 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
3207 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP);
3208 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
3209 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
3210 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_L2_PAYLOAD] =
3211 : : (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD);
3212 : :
3213 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 ||
3214 : : hw->mac.type == I40E_MAC_X722_VF) {
3215 : : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3216 : : (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP);
3217 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3218 : : (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
3219 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] |=
3220 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
3221 : : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3222 : : (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP);
3223 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3224 : : (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
3225 : 0 : ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] |=
3226 : : (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
3227 : : }
3228 : :
3229 [ # # ]: 0 : for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
3230 [ # # ]: 0 : if (ad->pctypes_tbl[i])
3231 : 0 : ad->flow_types_mask |= (1ULL << i);
3232 : 0 : ad->pctypes_mask |= ad->pctypes_tbl[i];
3233 : : }
3234 : 0 : }
3235 : :
3236 : : #ifdef RTE_ARCH_X86
3237 : : enum rte_vect_max_simd
3238 : 0 : i40e_get_max_simd_bitwidth(void)
3239 : : {
3240 : 0 : return ci_get_x86_max_simd_bitwidth();
3241 : : }
3242 : :
3243 : : #else
3244 : : uint16_t
3245 : : i40e_recv_pkts_vec_avx2(void __rte_unused *rx_queue,
3246 : : struct rte_mbuf __rte_unused **rx_pkts,
3247 : : uint16_t __rte_unused nb_pkts)
3248 : : {
3249 : : return 0;
3250 : : }
3251 : :
3252 : : uint16_t
3253 : : i40e_recv_scattered_pkts_vec_avx2(void __rte_unused *rx_queue,
3254 : : struct rte_mbuf __rte_unused **rx_pkts,
3255 : : uint16_t __rte_unused nb_pkts)
3256 : : {
3257 : : return 0;
3258 : : }
3259 : :
3260 : : uint16_t
3261 : : i40e_xmit_pkts_vec_avx2(void __rte_unused * tx_queue,
3262 : : struct rte_mbuf __rte_unused **tx_pkts,
3263 : : uint16_t __rte_unused nb_pkts)
3264 : : {
3265 : : return 0;
3266 : : }
3267 : : #endif /* ifndef RTE_ARCH_X86 */
|