Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation.
3 : : * Copyright 2014 6WIND S.A.
4 : : */
5 : :
6 : : #include <sys/queue.h>
7 : :
8 : : #include <stdio.h>
9 : : #include <stdlib.h>
10 : : #include <string.h>
11 : : #include <errno.h>
12 : : #include <stdint.h>
13 : : #include <stdarg.h>
14 : : #include <unistd.h>
15 : : #include <inttypes.h>
16 : :
17 : : #include <rte_byteorder.h>
18 : : #include <rte_common.h>
19 : : #include <rte_cycles.h>
20 : : #include <rte_log.h>
21 : : #include <rte_debug.h>
22 : : #include <rte_interrupts.h>
23 : : #include <rte_pci.h>
24 : : #include <rte_memory.h>
25 : : #include <rte_memzone.h>
26 : : #include <rte_launch.h>
27 : : #include <rte_eal.h>
28 : : #include <rte_per_lcore.h>
29 : : #include <rte_lcore.h>
30 : : #include <rte_branch_prediction.h>
31 : : #include <rte_mempool.h>
32 : : #include <rte_malloc.h>
33 : : #include <rte_mbuf.h>
34 : : #include <rte_ether.h>
35 : : #include <ethdev_driver.h>
36 : : #include <rte_security_driver.h>
37 : : #include <rte_prefetch.h>
38 : : #include <rte_udp.h>
39 : : #include <rte_tcp.h>
40 : : #include <rte_sctp.h>
41 : : #include <rte_string_fns.h>
42 : : #include <rte_errno.h>
43 : : #include <rte_ip.h>
44 : : #include <rte_net.h>
45 : : #include <rte_vect.h>
46 : :
47 : : #include "ixgbe_logs.h"
48 : : #include "base/ixgbe_api.h"
49 : : #include "base/ixgbe_vf.h"
50 : : #include "ixgbe_ethdev.h"
51 : : #include "base/ixgbe_dcb.h"
52 : : #include "base/ixgbe_common.h"
53 : : #include "ixgbe_rxtx.h"
54 : :
55 : : #ifdef RTE_LIBRTE_IEEE1588
56 : : #define IXGBE_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
57 : : #else
58 : : #define IXGBE_TX_IEEE1588_TMST 0
59 : : #endif
60 : : /* Bit Mask to indicate what bits required for building TX context */
61 : : #define IXGBE_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_IPV6 | \
62 : : RTE_MBUF_F_TX_OUTER_IPV4 | \
63 : : RTE_MBUF_F_TX_IPV6 | \
64 : : RTE_MBUF_F_TX_IPV4 | \
65 : : RTE_MBUF_F_TX_VLAN | \
66 : : RTE_MBUF_F_TX_IP_CKSUM | \
67 : : RTE_MBUF_F_TX_L4_MASK | \
68 : : RTE_MBUF_F_TX_TCP_SEG | \
69 : : RTE_MBUF_F_TX_MACSEC | \
70 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
71 : : RTE_MBUF_F_TX_SEC_OFFLOAD | \
72 : : IXGBE_TX_IEEE1588_TMST)
73 : :
74 : : #define IXGBE_TX_OFFLOAD_NOTSUP_MASK \
75 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IXGBE_TX_OFFLOAD_MASK)
76 : :
77 : : #if 1
78 : : #define RTE_PMD_USE_PREFETCH
79 : : #endif
80 : :
81 : : #ifdef RTE_PMD_USE_PREFETCH
82 : : /*
83 : : * Prefetch a cache line into all cache levels.
84 : : */
85 : : #define rte_ixgbe_prefetch(p) rte_prefetch0(p)
86 : : #else
87 : : #define rte_ixgbe_prefetch(p) do {} while (0)
88 : : #endif
89 : :
90 : : /*********************************************************************
91 : : *
92 : : * TX functions
93 : : *
94 : : **********************************************************************/
95 : :
96 : : /*
97 : : * Check for descriptors with their DD bit set and free mbufs.
98 : : * Return the total number of buffers freed.
99 : : */
100 : : static __rte_always_inline int
101 : : ixgbe_tx_free_bufs(struct ci_tx_queue *txq)
102 : : {
103 : : struct ci_tx_entry *txep;
104 : : uint32_t status;
105 : : int i, nb_free = 0;
106 : : struct rte_mbuf *m, *free[RTE_IXGBE_TX_MAX_FREE_BUF_SZ];
107 : :
108 : : /* check DD bit on threshold descriptor */
109 : 0 : status = txq->ixgbe_tx_ring[txq->tx_next_dd].wb.status;
110 [ # # # # ]: 0 : if (!(status & rte_cpu_to_le_32(IXGBE_ADVTXD_STAT_DD)))
111 : : return 0;
112 : :
113 : : /*
114 : : * first buffer to free from S/W ring is at index
115 : : * tx_next_dd - (tx_rs_thresh-1)
116 : : */
117 : 0 : txep = &(txq->sw_ring[txq->tx_next_dd - (txq->tx_rs_thresh - 1)]);
118 : :
119 [ # # # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
120 : : /* free buffers one at a time */
121 : 0 : m = rte_pktmbuf_prefree_seg(txep->mbuf);
122 : 0 : txep->mbuf = NULL;
123 : :
124 [ # # # # ]: 0 : if (unlikely(m == NULL))
125 : 0 : continue;
126 : :
127 [ # # # # : 0 : if (nb_free >= RTE_IXGBE_TX_MAX_FREE_BUF_SZ ||
# # # # ]
128 [ # # # # ]: 0 : (nb_free > 0 && m->pool != free[0]->pool)) {
129 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool,
130 : : (void **)free, nb_free);
131 : : nb_free = 0;
132 : : }
133 : :
134 : 0 : free[nb_free++] = m;
135 : : }
136 : :
137 [ # # # # ]: 0 : if (nb_free > 0)
138 [ # # # # ]: 0 : rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
139 : :
140 : : /* buffers were freed, update counters */
141 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
142 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
143 [ # # # # ]: 0 : if (txq->tx_next_dd >= txq->nb_tx_desc)
144 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
145 : :
146 : 0 : return txq->tx_rs_thresh;
147 : : }
148 : :
149 : : /* Populate 4 descriptors with data from 4 mbufs */
150 : : static inline void
151 : : tx4(volatile union ixgbe_adv_tx_desc *txdp, struct rte_mbuf **pkts)
152 : : {
153 : : uint64_t buf_dma_addr;
154 : : uint32_t pkt_len;
155 : : int i;
156 : :
157 [ # # ]: 0 : for (i = 0; i < 4; ++i, ++txdp, ++pkts) {
158 : 0 : buf_dma_addr = rte_mbuf_data_iova(*pkts);
159 : 0 : pkt_len = (*pkts)->data_len;
160 : :
161 : : /* write data to descriptor */
162 : 0 : txdp->read.buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
163 : :
164 : 0 : txdp->read.cmd_type_len =
165 : 0 : rte_cpu_to_le_32((uint32_t)DCMD_DTYP_FLAGS | pkt_len);
166 : :
167 : 0 : txdp->read.olinfo_status =
168 : 0 : rte_cpu_to_le_32(pkt_len << IXGBE_ADVTXD_PAYLEN_SHIFT);
169 : :
170 : 0 : rte_prefetch0(&(*pkts)->pool);
171 : : }
172 : : }
173 : :
174 : : /* Populate 1 descriptor with data from 1 mbuf */
175 : : static inline void
176 : : tx1(volatile union ixgbe_adv_tx_desc *txdp, struct rte_mbuf **pkts)
177 : : {
178 : : uint64_t buf_dma_addr;
179 : : uint32_t pkt_len;
180 : :
181 : : buf_dma_addr = rte_mbuf_data_iova(*pkts);
182 : 0 : pkt_len = (*pkts)->data_len;
183 : :
184 : : /* write data to descriptor */
185 : 0 : txdp->read.buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
186 : 0 : txdp->read.cmd_type_len =
187 : 0 : rte_cpu_to_le_32((uint32_t)DCMD_DTYP_FLAGS | pkt_len);
188 : 0 : txdp->read.olinfo_status =
189 : 0 : rte_cpu_to_le_32(pkt_len << IXGBE_ADVTXD_PAYLEN_SHIFT);
190 : 0 : rte_prefetch0(&(*pkts)->pool);
191 : : }
192 : :
193 : : /*
194 : : * Fill H/W descriptor ring with mbuf data.
195 : : * Copy mbuf pointers to the S/W ring.
196 : : */
197 : : static inline void
198 : 0 : ixgbe_tx_fill_hw_ring(struct ci_tx_queue *txq, struct rte_mbuf **pkts,
199 : : uint16_t nb_pkts)
200 : : {
201 : 0 : volatile union ixgbe_adv_tx_desc *txdp = &txq->ixgbe_tx_ring[txq->tx_tail];
202 : 0 : struct ci_tx_entry *txep = &txq->sw_ring[txq->tx_tail];
203 : : const int N_PER_LOOP = 4;
204 : : const int N_PER_LOOP_MASK = N_PER_LOOP-1;
205 : : int mainpart, leftover;
206 : : int i, j;
207 : :
208 : : /*
209 : : * Process most of the packets in chunks of N pkts. Any
210 : : * leftover packets will get processed one at a time.
211 : : */
212 : 0 : mainpart = (nb_pkts & ((uint32_t) ~N_PER_LOOP_MASK));
213 : 0 : leftover = (nb_pkts & ((uint32_t) N_PER_LOOP_MASK));
214 [ # # ]: 0 : for (i = 0; i < mainpart; i += N_PER_LOOP) {
215 : : /* Copy N mbuf pointers to the S/W ring */
216 [ # # ]: 0 : for (j = 0; j < N_PER_LOOP; ++j) {
217 : 0 : (txep + i + j)->mbuf = *(pkts + i + j);
218 : : }
219 : 0 : tx4(txdp + i, pkts + i);
220 : : }
221 : :
222 [ # # ]: 0 : if (unlikely(leftover > 0)) {
223 [ # # ]: 0 : for (i = 0; i < leftover; ++i) {
224 : 0 : (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
225 : 0 : tx1(txdp + mainpart + i, pkts + mainpart + i);
226 : : }
227 : : }
228 : 0 : }
229 : :
230 : : static inline uint16_t
231 : 0 : tx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
232 : : uint16_t nb_pkts)
233 : : {
234 : : struct ci_tx_queue *txq = (struct ci_tx_queue *)tx_queue;
235 : 0 : volatile union ixgbe_adv_tx_desc *tx_r = txq->ixgbe_tx_ring;
236 : : uint16_t n = 0;
237 : :
238 : : /*
239 : : * Begin scanning the H/W ring for done descriptors when the
240 : : * number of available descriptors drops below tx_free_thresh. For
241 : : * each done descriptor, free the associated buffer.
242 : : */
243 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
244 : : ixgbe_tx_free_bufs(txq);
245 : :
246 : : /* Only use descriptors that are available */
247 : 0 : nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
248 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
249 : : return 0;
250 : :
251 : : /* Use exactly nb_pkts descriptors */
252 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
253 : :
254 : : /*
255 : : * At this point, we know there are enough descriptors in the
256 : : * ring to transmit all the packets. This assumes that each
257 : : * mbuf contains a single segment, and that no new offloads
258 : : * are expected, which would require a new context descriptor.
259 : : */
260 : :
261 : : /*
262 : : * See if we're going to wrap-around. If so, handle the top
263 : : * of the descriptor ring first, then do the bottom. If not,
264 : : * the processing looks just like the "bottom" part anyway...
265 : : */
266 [ # # ]: 0 : if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
267 : 0 : n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
268 : 0 : ixgbe_tx_fill_hw_ring(txq, tx_pkts, n);
269 : :
270 : : /*
271 : : * We know that the last descriptor in the ring will need to
272 : : * have its RS bit set because tx_rs_thresh has to be
273 : : * a divisor of the ring size
274 : : */
275 : 0 : tx_r[txq->tx_next_rs].read.cmd_type_len |=
276 : : rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
277 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
278 : :
279 : 0 : txq->tx_tail = 0;
280 : : }
281 : :
282 : : /* Fill H/W descriptor ring with mbuf data */
283 : 0 : ixgbe_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
284 : 0 : txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
285 : :
286 : : /*
287 : : * Determine if RS bit should be set
288 : : * This is what we actually want:
289 : : * if ((txq->tx_tail - 1) >= txq->tx_next_rs)
290 : : * but instead of subtracting 1 and doing >=, we can just do
291 : : * greater than without subtracting.
292 : : */
293 [ # # ]: 0 : if (txq->tx_tail > txq->tx_next_rs) {
294 : 0 : tx_r[txq->tx_next_rs].read.cmd_type_len |=
295 : : rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
296 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_next_rs +
297 : 0 : txq->tx_rs_thresh);
298 [ # # ]: 0 : if (txq->tx_next_rs >= txq->nb_tx_desc)
299 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
300 : : }
301 : :
302 : : /*
303 : : * Check for wrap-around. This would only happen if we used
304 : : * up to the last descriptor in the ring, no more, no less.
305 : : */
306 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
307 : 0 : txq->tx_tail = 0;
308 : :
309 : : /* update tail pointer */
310 : : rte_wmb();
311 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(txq->qtx_tail, txq->tx_tail);
312 : :
313 : : return nb_pkts;
314 : : }
315 : :
316 : : uint16_t
317 : 0 : ixgbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
318 : : uint16_t nb_pkts)
319 : : {
320 : : uint16_t nb_tx;
321 : :
322 : : /* Try to transmit at least chunks of TX_MAX_BURST pkts */
323 [ # # ]: 0 : if (likely(nb_pkts <= RTE_PMD_IXGBE_TX_MAX_BURST))
324 : 0 : return tx_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
325 : :
326 : : /* transmit more than the max burst, in chunks of TX_MAX_BURST */
327 : : nb_tx = 0;
328 [ # # ]: 0 : while (nb_pkts) {
329 : : uint16_t ret, n;
330 : :
331 : 0 : n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_IXGBE_TX_MAX_BURST);
332 : 0 : ret = tx_xmit_pkts(tx_queue, &(tx_pkts[nb_tx]), n);
333 : 0 : nb_tx = (uint16_t)(nb_tx + ret);
334 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
335 [ # # ]: 0 : if (ret < n)
336 : : break;
337 : : }
338 : :
339 : : return nb_tx;
340 : : }
341 : :
342 : : static uint16_t
343 : 0 : ixgbe_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
344 : : uint16_t nb_pkts)
345 : : {
346 : : uint16_t nb_tx = 0;
347 : : struct ci_tx_queue *txq = (struct ci_tx_queue *)tx_queue;
348 : :
349 [ # # ]: 0 : while (nb_pkts) {
350 : : uint16_t ret, num;
351 : :
352 : 0 : num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_rs_thresh);
353 : 0 : ret = ixgbe_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
354 : : num);
355 : 0 : nb_tx += ret;
356 : 0 : nb_pkts -= ret;
357 [ # # ]: 0 : if (ret < num)
358 : : break;
359 : : }
360 : :
361 : 0 : return nb_tx;
362 : : }
363 : :
364 : : static inline void
365 : 0 : ixgbe_set_xmit_ctx(struct ci_tx_queue *txq,
366 : : volatile struct ixgbe_adv_tx_context_desc *ctx_txd,
367 : : uint64_t ol_flags, union ixgbe_tx_offload tx_offload,
368 : : __rte_unused uint64_t *mdata)
369 : : {
370 : : uint32_t type_tucmd_mlhl;
371 : : uint32_t mss_l4len_idx = 0;
372 : : uint32_t ctx_idx;
373 : : uint32_t vlan_macip_lens;
374 : : union ixgbe_tx_offload tx_offload_mask;
375 : : uint32_t seqnum_seed = 0;
376 : :
377 : 0 : ctx_idx = txq->ctx_curr;
378 : 0 : tx_offload_mask.data[0] = 0;
379 : 0 : tx_offload_mask.data[1] = 0;
380 : : type_tucmd_mlhl = 0;
381 : :
382 : : /* Specify which HW CTX to upload. */
383 : 0 : mss_l4len_idx |= (ctx_idx << IXGBE_ADVTXD_IDX_SHIFT);
384 : :
385 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
386 : 0 : tx_offload_mask.vlan_tci |= ~0;
387 : :
388 : : /* check if TCP segmentation required for this packet */
389 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
390 : : /* implies IP cksum in IPv4 */
391 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
392 : : type_tucmd_mlhl = IXGBE_ADVTXD_TUCMD_IPV4 |
393 : : IXGBE_ADVTXD_TUCMD_L4T_TCP |
394 : : IXGBE_ADVTXD_DTYP_CTXT | IXGBE_ADVTXD_DCMD_DEXT;
395 : : else
396 : : type_tucmd_mlhl = IXGBE_ADVTXD_TUCMD_IPV6 |
397 : : IXGBE_ADVTXD_TUCMD_L4T_TCP |
398 : : IXGBE_ADVTXD_DTYP_CTXT | IXGBE_ADVTXD_DCMD_DEXT;
399 : :
400 : 0 : tx_offload_mask.l2_len |= ~0;
401 : 0 : tx_offload_mask.l3_len |= ~0;
402 : 0 : tx_offload_mask.l4_len |= ~0;
403 : 0 : tx_offload_mask.tso_segsz |= ~0;
404 : 0 : mss_l4len_idx |= tx_offload.tso_segsz << IXGBE_ADVTXD_MSS_SHIFT;
405 : 0 : mss_l4len_idx |= tx_offload.l4_len << IXGBE_ADVTXD_L4LEN_SHIFT;
406 : : } else { /* no TSO, check if hardware checksum is needed */
407 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
408 : : type_tucmd_mlhl = IXGBE_ADVTXD_TUCMD_IPV4;
409 : 0 : tx_offload_mask.l2_len |= ~0;
410 : 0 : tx_offload_mask.l3_len |= ~0;
411 : : }
412 : :
413 [ # # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
414 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
415 : 0 : type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_UDP |
416 : : IXGBE_ADVTXD_DTYP_CTXT | IXGBE_ADVTXD_DCMD_DEXT;
417 : 0 : mss_l4len_idx |= sizeof(struct rte_udp_hdr)
418 : : << IXGBE_ADVTXD_L4LEN_SHIFT;
419 : 0 : tx_offload_mask.l2_len |= ~0;
420 : 0 : tx_offload_mask.l3_len |= ~0;
421 : 0 : break;
422 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM:
423 : 0 : type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP |
424 : : IXGBE_ADVTXD_DTYP_CTXT | IXGBE_ADVTXD_DCMD_DEXT;
425 : 0 : mss_l4len_idx |= sizeof(struct rte_tcp_hdr)
426 : : << IXGBE_ADVTXD_L4LEN_SHIFT;
427 : 0 : tx_offload_mask.l2_len |= ~0;
428 : 0 : tx_offload_mask.l3_len |= ~0;
429 : 0 : break;
430 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
431 : 0 : type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_SCTP |
432 : : IXGBE_ADVTXD_DTYP_CTXT | IXGBE_ADVTXD_DCMD_DEXT;
433 : 0 : mss_l4len_idx |= sizeof(struct rte_sctp_hdr)
434 : : << IXGBE_ADVTXD_L4LEN_SHIFT;
435 : 0 : tx_offload_mask.l2_len |= ~0;
436 : 0 : tx_offload_mask.l3_len |= ~0;
437 : 0 : break;
438 : 0 : default:
439 : 0 : type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_RSV |
440 : : IXGBE_ADVTXD_DTYP_CTXT | IXGBE_ADVTXD_DCMD_DEXT;
441 : 0 : break;
442 : : }
443 : : }
444 : :
445 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
446 : 0 : tx_offload_mask.outer_l2_len |= ~0;
447 : 0 : tx_offload_mask.outer_l3_len |= ~0;
448 : 0 : tx_offload_mask.l2_len |= ~0;
449 : 0 : seqnum_seed |= tx_offload.outer_l3_len
450 : 0 : << IXGBE_ADVTXD_OUTER_IPLEN;
451 : 0 : seqnum_seed |= tx_offload.l2_len
452 : 0 : << IXGBE_ADVTXD_TUNNEL_LEN;
453 : : }
454 : : #ifdef RTE_LIB_SECURITY
455 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD) {
456 : : union ixgbe_crypto_tx_desc_md *md =
457 : : (union ixgbe_crypto_tx_desc_md *)mdata;
458 : 0 : seqnum_seed |=
459 : 0 : (IXGBE_ADVTXD_IPSEC_SA_INDEX_MASK & md->sa_idx);
460 : 0 : type_tucmd_mlhl |= md->enc ?
461 : : (IXGBE_ADVTXD_TUCMD_IPSEC_TYPE_ESP |
462 [ # # ]: 0 : IXGBE_ADVTXD_TUCMD_IPSEC_ENCRYPT_EN) : 0;
463 : 0 : type_tucmd_mlhl |=
464 : 0 : (md->pad_len & IXGBE_ADVTXD_IPSEC_ESP_LEN_MASK);
465 : 0 : tx_offload_mask.sa_idx |= ~0;
466 : 0 : tx_offload_mask.sec_pad_len |= ~0;
467 : : }
468 : : #endif
469 : :
470 : 0 : txq->ctx_cache[ctx_idx].flags = ol_flags;
471 : 0 : txq->ctx_cache[ctx_idx].tx_offload.data[0] =
472 : 0 : tx_offload_mask.data[0] & tx_offload.data[0];
473 : 0 : txq->ctx_cache[ctx_idx].tx_offload.data[1] =
474 : 0 : tx_offload_mask.data[1] & tx_offload.data[1];
475 : 0 : txq->ctx_cache[ctx_idx].tx_offload_mask = tx_offload_mask;
476 : :
477 : 0 : ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
478 : 0 : vlan_macip_lens = tx_offload.l3_len;
479 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM)
480 : 0 : vlan_macip_lens |= (tx_offload.outer_l2_len <<
481 : : IXGBE_ADVTXD_MACLEN_SHIFT);
482 : : else
483 : 0 : vlan_macip_lens |= (tx_offload.l2_len <<
484 : : IXGBE_ADVTXD_MACLEN_SHIFT);
485 : 0 : vlan_macip_lens |= ((uint32_t)tx_offload.vlan_tci << IXGBE_ADVTXD_VLAN_SHIFT);
486 : 0 : ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
487 : 0 : ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(mss_l4len_idx);
488 : 0 : ctx_txd->seqnum_seed = seqnum_seed;
489 : 0 : }
490 : :
491 : : /*
492 : : * Check which hardware context can be used. Use the existing match
493 : : * or create a new context descriptor.
494 : : */
495 : : static inline uint32_t
496 : 0 : what_advctx_update(struct ci_tx_queue *txq, uint64_t flags,
497 : : union ixgbe_tx_offload tx_offload)
498 : : {
499 : : /* If match with the current used context */
500 [ # # # # : 0 : if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
# # ]
501 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
502 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
503 : : & tx_offload.data[0])) &&
504 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
505 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
506 : : & tx_offload.data[1]))))
507 : : return txq->ctx_curr;
508 : :
509 : : /* What if match with the next context */
510 : 0 : txq->ctx_curr ^= 1;
511 [ # # # # : 0 : if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
# # ]
512 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
513 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
514 : : & tx_offload.data[0])) &&
515 : : (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
516 : : (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
517 : : & tx_offload.data[1]))))
518 : 0 : return txq->ctx_curr;
519 : :
520 : : /* Mismatch, use the previous context */
521 : : return IXGBE_CTX_NUM;
522 : : }
523 : :
524 : : static inline uint32_t
525 : : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
526 : : {
527 : : uint32_t tmp = 0;
528 : :
529 : 0 : if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM)
530 : : tmp |= IXGBE_ADVTXD_POPTS_TXSM;
531 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
532 : 0 : tmp |= IXGBE_ADVTXD_POPTS_IXSM;
533 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
534 : 0 : tmp |= IXGBE_ADVTXD_POPTS_TXSM;
535 : : return tmp;
536 : : }
537 : :
538 : : static inline uint32_t
539 : : tx_desc_ol_flags_to_cmdtype(uint64_t ol_flags)
540 : : {
541 : : uint32_t cmdtype = 0;
542 : :
543 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_VLAN)
544 : : cmdtype |= IXGBE_ADVTXD_DCMD_VLE;
545 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
546 : 0 : cmdtype |= IXGBE_ADVTXD_DCMD_TSE;
547 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM)
548 : 0 : cmdtype |= (1 << IXGBE_ADVTXD_OUTERIPCS_SHIFT);
549 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_MACSEC)
550 : 0 : cmdtype |= IXGBE_ADVTXD_MAC_LINKSEC;
551 : : return cmdtype;
552 : : }
553 : :
554 : : /* Default RS bit threshold values */
555 : : #ifndef DEFAULT_TX_RS_THRESH
556 : : #define DEFAULT_TX_RS_THRESH 32
557 : : #endif
558 : : #ifndef DEFAULT_TX_FREE_THRESH
559 : : #define DEFAULT_TX_FREE_THRESH 32
560 : : #endif
561 : :
562 : : /* Reset transmit descriptors after they have been used */
563 : : static inline int
564 : 0 : ixgbe_xmit_cleanup(struct ci_tx_queue *txq)
565 : : {
566 : 0 : struct ci_tx_entry *sw_ring = txq->sw_ring;
567 : 0 : volatile union ixgbe_adv_tx_desc *txr = txq->ixgbe_tx_ring;
568 : 0 : uint16_t last_desc_cleaned = txq->last_desc_cleaned;
569 : 0 : uint16_t nb_tx_desc = txq->nb_tx_desc;
570 : : uint16_t desc_to_clean_to;
571 : : uint16_t nb_tx_to_clean;
572 : : uint32_t status;
573 : :
574 : : /* Determine the last descriptor needing to be cleaned */
575 : 0 : desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
576 [ # # ]: 0 : if (desc_to_clean_to >= nb_tx_desc)
577 : 0 : desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
578 : :
579 : : /* Check to make sure the last descriptor to clean is done */
580 : 0 : desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
581 : 0 : status = txr[desc_to_clean_to].wb.status;
582 [ # # ]: 0 : if (!(status & rte_cpu_to_le_32(IXGBE_TXD_STAT_DD))) {
583 : : PMD_TX_LOG(DEBUG,
584 : : "TX descriptor %4u is not done"
585 : : "(port=%d queue=%d)",
586 : : desc_to_clean_to,
587 : : txq->port_id, txq->queue_id);
588 : : /* Failed to clean any descriptors, better luck next time */
589 : : return -(1);
590 : : }
591 : :
592 : : /* Figure out how many descriptors will be cleaned */
593 [ # # ]: 0 : if (last_desc_cleaned > desc_to_clean_to)
594 : 0 : nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
595 : : desc_to_clean_to);
596 : : else
597 : 0 : nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
598 : : last_desc_cleaned);
599 : :
600 : : PMD_TX_LOG(DEBUG,
601 : : "Cleaning %4u TX descriptors: %4u to %4u "
602 : : "(port=%d queue=%d)",
603 : : nb_tx_to_clean, last_desc_cleaned, desc_to_clean_to,
604 : : txq->port_id, txq->queue_id);
605 : :
606 : : /*
607 : : * The last descriptor to clean is done, so that means all the
608 : : * descriptors from the last descriptor that was cleaned
609 : : * up to the last descriptor with the RS bit set
610 : : * are done. Only reset the threshold descriptor.
611 : : */
612 : 0 : txr[desc_to_clean_to].wb.status = 0;
613 : :
614 : : /* Update the txq to reflect the last descriptor that was cleaned */
615 : 0 : txq->last_desc_cleaned = desc_to_clean_to;
616 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
617 : :
618 : : /* No Error */
619 : 0 : return 0;
620 : : }
621 : :
622 : : uint16_t
623 : 0 : ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
624 : : uint16_t nb_pkts)
625 : : {
626 : : struct ci_tx_queue *txq;
627 : : struct ci_tx_entry *sw_ring;
628 : : struct ci_tx_entry *txe, *txn;
629 : : volatile union ixgbe_adv_tx_desc *txr;
630 : : volatile union ixgbe_adv_tx_desc *txd, *txp;
631 : : struct rte_mbuf *tx_pkt;
632 : : struct rte_mbuf *m_seg;
633 : : uint64_t buf_dma_addr;
634 : : uint32_t olinfo_status;
635 : : uint32_t cmd_type_len;
636 : : uint32_t pkt_len;
637 : : uint16_t slen;
638 : : uint64_t ol_flags;
639 : : uint16_t tx_id;
640 : : uint16_t tx_last;
641 : : uint16_t nb_tx;
642 : : uint16_t nb_used;
643 : : uint64_t tx_ol_req;
644 : : uint32_t ctx = 0;
645 : : uint32_t new_ctx;
646 : : union ixgbe_tx_offload tx_offload;
647 : : #ifdef RTE_LIB_SECURITY
648 : : uint8_t use_ipsec;
649 : : #endif
650 : :
651 : 0 : tx_offload.data[0] = 0;
652 : 0 : tx_offload.data[1] = 0;
653 : : txq = tx_queue;
654 : 0 : sw_ring = txq->sw_ring;
655 : 0 : txr = txq->ixgbe_tx_ring;
656 : 0 : tx_id = txq->tx_tail;
657 : 0 : txe = &sw_ring[tx_id];
658 : : txp = NULL;
659 : :
660 : : /* Determine if the descriptor ring needs to be cleaned. */
661 [ # # ]: 0 : if (txq->nb_tx_free < txq->tx_free_thresh)
662 : 0 : ixgbe_xmit_cleanup(txq);
663 : :
664 : 0 : rte_prefetch0(&txe->mbuf->pool);
665 : :
666 : : /* TX loop */
667 [ # # ]: 0 : for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
668 : : new_ctx = 0;
669 : 0 : tx_pkt = *tx_pkts++;
670 : 0 : pkt_len = tx_pkt->pkt_len;
671 : :
672 : : /*
673 : : * Determine how many (if any) context descriptors
674 : : * are needed for offload functionality.
675 : : */
676 : 0 : ol_flags = tx_pkt->ol_flags;
677 : : #ifdef RTE_LIB_SECURITY
678 [ # # # # ]: 0 : use_ipsec = txq->using_ipsec && (ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD);
679 : : #endif
680 : :
681 : : /* If hardware offload required */
682 : 0 : tx_ol_req = ol_flags & IXGBE_TX_OFFLOAD_MASK;
683 [ # # ]: 0 : if (tx_ol_req) {
684 : 0 : tx_offload.l2_len = tx_pkt->l2_len;
685 : 0 : tx_offload.l3_len = tx_pkt->l3_len;
686 : 0 : tx_offload.l4_len = tx_pkt->l4_len;
687 : 0 : tx_offload.vlan_tci = tx_pkt->vlan_tci;
688 : 0 : tx_offload.tso_segsz = tx_pkt->tso_segsz;
689 : 0 : tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
690 : 0 : tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
691 : : #ifdef RTE_LIB_SECURITY
692 [ # # ]: 0 : if (use_ipsec) {
693 : : union ixgbe_crypto_tx_desc_md *ipsec_mdata =
694 : : (union ixgbe_crypto_tx_desc_md *)
695 : : rte_security_dynfield(tx_pkt);
696 : 0 : tx_offload.sa_idx = ipsec_mdata->sa_idx;
697 : 0 : tx_offload.sec_pad_len = ipsec_mdata->pad_len;
698 : : }
699 : : #endif
700 : :
701 : : /* If new context need be built or reuse the exist ctx. */
702 : 0 : ctx = what_advctx_update(txq, tx_ol_req,
703 : : tx_offload);
704 : : /* Only allocate context descriptor if required*/
705 : 0 : new_ctx = (ctx == IXGBE_CTX_NUM);
706 : 0 : ctx = txq->ctx_curr;
707 : : }
708 : :
709 : : /*
710 : : * Keep track of how many descriptors are used this loop
711 : : * This will always be the number of segments + the number of
712 : : * Context descriptors required to transmit the packet
713 : : */
714 : 0 : nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
715 : :
716 [ # # ]: 0 : if (txp != NULL &&
717 [ # # ]: 0 : nb_used + txq->nb_tx_used >= txq->tx_rs_thresh)
718 : : /* set RS on the previous packet in the burst */
719 : 0 : txp->read.cmd_type_len |=
720 : : rte_cpu_to_le_32(IXGBE_TXD_CMD_RS);
721 : :
722 : : /*
723 : : * The number of descriptors that must be allocated for a
724 : : * packet is the number of segments of that packet, plus 1
725 : : * Context Descriptor for the hardware offload, if any.
726 : : * Determine the last TX descriptor to allocate in the TX ring
727 : : * for the packet, starting from the current position (tx_id)
728 : : * in the ring.
729 : : */
730 : 0 : tx_last = (uint16_t) (tx_id + nb_used - 1);
731 : :
732 : : /* Circular ring */
733 [ # # ]: 0 : if (tx_last >= txq->nb_tx_desc)
734 : 0 : tx_last = (uint16_t) (tx_last - txq->nb_tx_desc);
735 : :
736 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
737 : : " tx_first=%u tx_last=%u",
738 : : (unsigned) txq->port_id,
739 : : (unsigned) txq->queue_id,
740 : : (unsigned) pkt_len,
741 : : (unsigned) tx_id,
742 : : (unsigned) tx_last);
743 : :
744 : : /*
745 : : * Make sure there are enough TX descriptors available to
746 : : * transmit the entire packet.
747 : : * nb_used better be less than or equal to txq->tx_rs_thresh
748 : : */
749 [ # # ]: 0 : if (nb_used > txq->nb_tx_free) {
750 : : PMD_TX_LOG(DEBUG,
751 : : "Not enough free TX descriptors "
752 : : "nb_used=%4u nb_free=%4u "
753 : : "(port=%d queue=%d)",
754 : : nb_used, txq->nb_tx_free,
755 : : txq->port_id, txq->queue_id);
756 : :
757 [ # # ]: 0 : if (ixgbe_xmit_cleanup(txq) != 0) {
758 : : /* Could not clean any descriptors */
759 [ # # ]: 0 : if (nb_tx == 0)
760 : : return 0;
761 : 0 : goto end_of_tx;
762 : : }
763 : :
764 : : /* nb_used better be <= txq->tx_rs_thresh */
765 [ # # ]: 0 : if (unlikely(nb_used > txq->tx_rs_thresh)) {
766 : : PMD_TX_LOG(DEBUG,
767 : : "The number of descriptors needed to "
768 : : "transmit the packet exceeds the "
769 : : "RS bit threshold. This will impact "
770 : : "performance."
771 : : "nb_used=%4u nb_free=%4u "
772 : : "tx_rs_thresh=%4u. "
773 : : "(port=%d queue=%d)",
774 : : nb_used, txq->nb_tx_free,
775 : : txq->tx_rs_thresh,
776 : : txq->port_id, txq->queue_id);
777 : : /*
778 : : * Loop here until there are enough TX
779 : : * descriptors or until the ring cannot be
780 : : * cleaned.
781 : : */
782 [ # # ]: 0 : while (nb_used > txq->nb_tx_free) {
783 [ # # ]: 0 : if (ixgbe_xmit_cleanup(txq) != 0) {
784 : : /*
785 : : * Could not clean any
786 : : * descriptors
787 : : */
788 [ # # ]: 0 : if (nb_tx == 0)
789 : : return 0;
790 : 0 : goto end_of_tx;
791 : : }
792 : : }
793 : : }
794 : : }
795 : :
796 : : /*
797 : : * By now there are enough free TX descriptors to transmit
798 : : * the packet.
799 : : */
800 : :
801 : : /*
802 : : * Set common flags of all TX Data Descriptors.
803 : : *
804 : : * The following bits must be set in all Data Descriptors:
805 : : * - IXGBE_ADVTXD_DTYP_DATA
806 : : * - IXGBE_ADVTXD_DCMD_DEXT
807 : : *
808 : : * The following bits must be set in the first Data Descriptor
809 : : * and are ignored in the other ones:
810 : : * - IXGBE_ADVTXD_DCMD_IFCS
811 : : * - IXGBE_ADVTXD_MAC_1588
812 : : * - IXGBE_ADVTXD_DCMD_VLE
813 : : *
814 : : * The following bits must only be set in the last Data
815 : : * Descriptor:
816 : : * - IXGBE_TXD_CMD_EOP
817 : : *
818 : : * The following bits can be set in any Data Descriptor, but
819 : : * are only set in the last Data Descriptor:
820 : : * - IXGBE_TXD_CMD_RS
821 : : */
822 : : cmd_type_len = IXGBE_ADVTXD_DTYP_DATA |
823 : : IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
824 : :
825 : : #ifdef RTE_LIBRTE_IEEE1588
826 : : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
827 : : cmd_type_len |= IXGBE_ADVTXD_MAC_1588;
828 : : #endif
829 : :
830 : : olinfo_status = 0;
831 [ # # ]: 0 : if (tx_ol_req) {
832 : :
833 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
834 : : /* when TSO is on, paylen in descriptor is the
835 : : * not the packet len but the tcp payload len */
836 : 0 : pkt_len -= (tx_offload.l2_len +
837 : 0 : tx_offload.l3_len + tx_offload.l4_len);
838 : : }
839 : :
840 : : /*
841 : : * Setup the TX Advanced Context Descriptor if required
842 : : */
843 [ # # ]: 0 : if (new_ctx) {
844 : : volatile struct ixgbe_adv_tx_context_desc *
845 : : ctx_txd;
846 : :
847 : 0 : ctx_txd = (volatile struct
848 : : ixgbe_adv_tx_context_desc *)
849 : 0 : &txr[tx_id];
850 : :
851 : 0 : txn = &sw_ring[txe->next_id];
852 : 0 : rte_prefetch0(&txn->mbuf->pool);
853 : :
854 [ # # ]: 0 : if (txe->mbuf != NULL) {
855 : : rte_pktmbuf_free_seg(txe->mbuf);
856 : 0 : txe->mbuf = NULL;
857 : : }
858 : :
859 : 0 : ixgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
860 : : tx_offload,
861 : : rte_security_dynfield(tx_pkt));
862 : :
863 : 0 : txe->last_id = tx_last;
864 : 0 : tx_id = txe->next_id;
865 : : txe = txn;
866 : : }
867 : :
868 : : /*
869 : : * Setup the TX Advanced Data Descriptor,
870 : : * This path will go through
871 : : * whatever new/reuse the context descriptor
872 : : */
873 [ # # ]: 0 : cmd_type_len |= tx_desc_ol_flags_to_cmdtype(ol_flags);
874 : : olinfo_status |= tx_desc_cksum_flags_to_olinfo(ol_flags);
875 : 0 : olinfo_status |= ctx << IXGBE_ADVTXD_IDX_SHIFT;
876 : : }
877 : :
878 : 0 : olinfo_status |= (pkt_len << IXGBE_ADVTXD_PAYLEN_SHIFT);
879 : : #ifdef RTE_LIB_SECURITY
880 [ # # ]: 0 : if (use_ipsec)
881 : 0 : olinfo_status |= IXGBE_ADVTXD_POPTS_IPSEC;
882 : : #endif
883 : :
884 : : m_seg = tx_pkt;
885 : : do {
886 : 0 : txd = &txr[tx_id];
887 : 0 : txn = &sw_ring[txe->next_id];
888 : 0 : rte_prefetch0(&txn->mbuf->pool);
889 : :
890 [ # # ]: 0 : if (txe->mbuf != NULL)
891 : : rte_pktmbuf_free_seg(txe->mbuf);
892 : 0 : txe->mbuf = m_seg;
893 : :
894 : : /*
895 : : * Set up Transmit Data Descriptor.
896 : : */
897 [ # # ]: 0 : slen = m_seg->data_len;
898 : : buf_dma_addr = rte_mbuf_data_iova(m_seg);
899 : 0 : txd->read.buffer_addr =
900 : : rte_cpu_to_le_64(buf_dma_addr);
901 : 0 : txd->read.cmd_type_len =
902 : 0 : rte_cpu_to_le_32(cmd_type_len | slen);
903 : 0 : txd->read.olinfo_status =
904 : : rte_cpu_to_le_32(olinfo_status);
905 : 0 : txe->last_id = tx_last;
906 : 0 : tx_id = txe->next_id;
907 : : txe = txn;
908 : 0 : m_seg = m_seg->next;
909 [ # # ]: 0 : } while (m_seg != NULL);
910 : :
911 : : /*
912 : : * The last packet data descriptor needs End Of Packet (EOP)
913 : : */
914 : 0 : cmd_type_len |= IXGBE_TXD_CMD_EOP;
915 : 0 : txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
916 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
917 : :
918 : : /* Set RS bit only on threshold packets' last descriptor */
919 [ # # ]: 0 : if (txq->nb_tx_used >= txq->tx_rs_thresh) {
920 : : PMD_TX_LOG(DEBUG,
921 : : "Setting RS bit on TXD id="
922 : : "%4u (port=%d queue=%d)",
923 : : tx_last, txq->port_id, txq->queue_id);
924 : :
925 : 0 : cmd_type_len |= IXGBE_TXD_CMD_RS;
926 : :
927 : : /* Update txq RS bit counters */
928 : 0 : txq->nb_tx_used = 0;
929 : : txp = NULL;
930 : : } else
931 : : txp = txd;
932 : :
933 : 0 : txd->read.cmd_type_len |= rte_cpu_to_le_32(cmd_type_len);
934 : : }
935 : :
936 : 0 : end_of_tx:
937 : : /* set RS on last packet in the burst */
938 [ # # ]: 0 : if (txp != NULL)
939 : 0 : txp->read.cmd_type_len |= rte_cpu_to_le_32(IXGBE_TXD_CMD_RS);
940 : :
941 : : rte_wmb();
942 : :
943 : : /*
944 : : * Set the Transmit Descriptor Tail (TDT)
945 : : */
946 : : PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
947 : : (unsigned) txq->port_id, (unsigned) txq->queue_id,
948 : : (unsigned) tx_id, (unsigned) nb_tx);
949 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(txq->qtx_tail, tx_id);
950 : 0 : txq->tx_tail = tx_id;
951 : :
952 : 0 : return nb_tx;
953 : : }
954 : :
955 : : /*********************************************************************
956 : : *
957 : : * TX prep functions
958 : : *
959 : : **********************************************************************/
960 : : uint16_t
961 : 0 : ixgbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
962 : : {
963 : : int i, ret;
964 : : uint64_t ol_flags;
965 : : struct rte_mbuf *m;
966 : : struct ci_tx_queue *txq = (struct ci_tx_queue *)tx_queue;
967 : :
968 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
969 : 0 : m = tx_pkts[i];
970 : 0 : ol_flags = m->ol_flags;
971 : :
972 : : /**
973 : : * Check if packet meets requirements for number of segments
974 : : *
975 : : * NOTE: for ixgbe it's always (40 - WTHRESH) for both TSO and
976 : : * non-TSO
977 : : */
978 : :
979 [ # # ]: 0 : if (m->nb_segs > IXGBE_TX_MAX_SEG - txq->wthresh) {
980 : 0 : rte_errno = EINVAL;
981 : 0 : return i;
982 : : }
983 : :
984 [ # # ]: 0 : if (ol_flags & IXGBE_TX_OFFLOAD_NOTSUP_MASK) {
985 : 0 : rte_errno = ENOTSUP;
986 : 0 : return i;
987 : : }
988 : :
989 : : /* check the size of packet */
990 [ # # ]: 0 : if (m->pkt_len < IXGBE_TX_MIN_PKT_LEN) {
991 : 0 : rte_errno = EINVAL;
992 : 0 : return i;
993 : : }
994 : :
995 : : #ifdef RTE_ETHDEV_DEBUG_TX
996 : : ret = rte_validate_tx_offload(m);
997 : : if (ret != 0) {
998 : : rte_errno = -ret;
999 : : return i;
1000 : : }
1001 : : #endif
1002 : : ret = rte_net_intel_cksum_prepare(m);
1003 [ # # ]: 0 : if (ret != 0) {
1004 : 0 : rte_errno = -ret;
1005 : 0 : return i;
1006 : : }
1007 : : }
1008 : :
1009 : 0 : return i;
1010 : : }
1011 : :
1012 : : /*********************************************************************
1013 : : *
1014 : : * RX functions
1015 : : *
1016 : : **********************************************************************/
1017 : :
1018 : : #define IXGBE_PACKET_TYPE_ETHER 0X00
1019 : : #define IXGBE_PACKET_TYPE_IPV4 0X01
1020 : : #define IXGBE_PACKET_TYPE_IPV4_TCP 0X11
1021 : : #define IXGBE_PACKET_TYPE_IPV4_UDP 0X21
1022 : : #define IXGBE_PACKET_TYPE_IPV4_SCTP 0X41
1023 : : #define IXGBE_PACKET_TYPE_IPV4_EXT 0X03
1024 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_TCP 0X13
1025 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_UDP 0X23
1026 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_SCTP 0X43
1027 : : #define IXGBE_PACKET_TYPE_IPV6 0X04
1028 : : #define IXGBE_PACKET_TYPE_IPV6_TCP 0X14
1029 : : #define IXGBE_PACKET_TYPE_IPV6_UDP 0X24
1030 : : #define IXGBE_PACKET_TYPE_IPV6_SCTP 0X44
1031 : : #define IXGBE_PACKET_TYPE_IPV6_EXT 0X0C
1032 : : #define IXGBE_PACKET_TYPE_IPV6_EXT_TCP 0X1C
1033 : : #define IXGBE_PACKET_TYPE_IPV6_EXT_UDP 0X2C
1034 : : #define IXGBE_PACKET_TYPE_IPV6_EXT_SCTP 0X4C
1035 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6 0X05
1036 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6_TCP 0X15
1037 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6_UDP 0X25
1038 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6_SCTP 0X45
1039 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6 0X07
1040 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_TCP 0X17
1041 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_UDP 0X27
1042 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_SCTP 0X47
1043 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6_EXT 0X0D
1044 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6_EXT_TCP 0X1D
1045 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6_EXT_UDP 0X2D
1046 : : #define IXGBE_PACKET_TYPE_IPV4_IPV6_EXT_SCTP 0X4D
1047 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT 0X0F
1048 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT_TCP 0X1F
1049 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT_UDP 0X2F
1050 : : #define IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT_SCTP 0X4F
1051 : :
1052 : : #define IXGBE_PACKET_TYPE_NVGRE 0X00
1053 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4 0X01
1054 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_TCP 0X11
1055 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_UDP 0X21
1056 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_SCTP 0X41
1057 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT 0X03
1058 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT_TCP 0X13
1059 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT_UDP 0X23
1060 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT_SCTP 0X43
1061 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6 0X04
1062 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6_TCP 0X14
1063 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6_UDP 0X24
1064 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6_SCTP 0X44
1065 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT 0X0C
1066 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT_TCP 0X1C
1067 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT_UDP 0X2C
1068 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT_SCTP 0X4C
1069 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6 0X05
1070 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_TCP 0X15
1071 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_UDP 0X25
1072 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_EXT 0X0D
1073 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_EXT_TCP 0X1D
1074 : : #define IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_EXT_UDP 0X2D
1075 : :
1076 : : #define IXGBE_PACKET_TYPE_VXLAN 0X80
1077 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4 0X81
1078 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_TCP 0x91
1079 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_UDP 0xA1
1080 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_SCTP 0xC1
1081 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT 0x83
1082 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT_TCP 0X93
1083 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT_UDP 0XA3
1084 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT_SCTP 0XC3
1085 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6 0X84
1086 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6_TCP 0X94
1087 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6_UDP 0XA4
1088 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6_SCTP 0XC4
1089 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT 0X8C
1090 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT_TCP 0X9C
1091 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT_UDP 0XAC
1092 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT_SCTP 0XCC
1093 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6 0X85
1094 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_TCP 0X95
1095 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_UDP 0XA5
1096 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_EXT 0X8D
1097 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_EXT_TCP 0X9D
1098 : : #define IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_EXT_UDP 0XAD
1099 : :
1100 : : /**
1101 : : * Use 2 different table for normal packet and tunnel packet
1102 : : * to save the space.
1103 : : */
1104 : : const alignas(RTE_CACHE_LINE_SIZE) uint32_t
1105 : : ptype_table[IXGBE_PACKET_TYPE_MAX] = {
1106 : : [IXGBE_PACKET_TYPE_ETHER] = RTE_PTYPE_L2_ETHER,
1107 : : [IXGBE_PACKET_TYPE_IPV4] = RTE_PTYPE_L2_ETHER |
1108 : : RTE_PTYPE_L3_IPV4,
1109 : : [IXGBE_PACKET_TYPE_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
1110 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
1111 : : [IXGBE_PACKET_TYPE_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
1112 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
1113 : : [IXGBE_PACKET_TYPE_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
1114 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP,
1115 : : [IXGBE_PACKET_TYPE_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
1116 : : RTE_PTYPE_L3_IPV4_EXT,
1117 : : [IXGBE_PACKET_TYPE_IPV4_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1118 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_TCP,
1119 : : [IXGBE_PACKET_TYPE_IPV4_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1120 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_UDP,
1121 : : [IXGBE_PACKET_TYPE_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
1122 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_SCTP,
1123 : : [IXGBE_PACKET_TYPE_IPV6] = RTE_PTYPE_L2_ETHER |
1124 : : RTE_PTYPE_L3_IPV6,
1125 : : [IXGBE_PACKET_TYPE_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
1126 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
1127 : : [IXGBE_PACKET_TYPE_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
1128 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
1129 : : [IXGBE_PACKET_TYPE_IPV6_SCTP] = RTE_PTYPE_L2_ETHER |
1130 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_SCTP,
1131 : : [IXGBE_PACKET_TYPE_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
1132 : : RTE_PTYPE_L3_IPV6_EXT,
1133 : : [IXGBE_PACKET_TYPE_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1134 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP,
1135 : : [IXGBE_PACKET_TYPE_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1136 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP,
1137 : : [IXGBE_PACKET_TYPE_IPV6_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
1138 : : RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_SCTP,
1139 : : [IXGBE_PACKET_TYPE_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
1140 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1141 : : RTE_PTYPE_INNER_L3_IPV6,
1142 : : [IXGBE_PACKET_TYPE_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
1143 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1144 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
1145 : : [IXGBE_PACKET_TYPE_IPV4_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
1146 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1147 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
1148 : : [IXGBE_PACKET_TYPE_IPV4_IPV6_SCTP] = RTE_PTYPE_L2_ETHER |
1149 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1150 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_SCTP,
1151 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6] = RTE_PTYPE_L2_ETHER |
1152 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1153 : : RTE_PTYPE_INNER_L3_IPV6,
1154 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
1155 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1156 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
1157 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
1158 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1159 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
1160 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_SCTP] = RTE_PTYPE_L2_ETHER |
1161 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1162 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_SCTP,
1163 : : [IXGBE_PACKET_TYPE_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
1164 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1165 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
1166 : : [IXGBE_PACKET_TYPE_IPV4_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1167 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1168 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
1169 : : [IXGBE_PACKET_TYPE_IPV4_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1170 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1171 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
1172 : : [IXGBE_PACKET_TYPE_IPV4_IPV6_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
1173 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
1174 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_SCTP,
1175 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
1176 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1177 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
1178 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1179 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1180 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
1181 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1182 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1183 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
1184 : : [IXGBE_PACKET_TYPE_IPV4_EXT_IPV6_EXT_SCTP] =
1185 : : RTE_PTYPE_L2_ETHER |
1186 : : RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_TUNNEL_IP |
1187 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_SCTP,
1188 : : };
1189 : :
1190 : : const alignas(RTE_CACHE_LINE_SIZE) uint32_t
1191 : : ptype_table_tn[IXGBE_PACKET_TYPE_TN_MAX] = {
1192 : : [IXGBE_PACKET_TYPE_NVGRE] = RTE_PTYPE_L2_ETHER |
1193 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1194 : : RTE_PTYPE_INNER_L2_ETHER,
1195 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4] = RTE_PTYPE_L2_ETHER |
1196 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1197 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4,
1198 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
1199 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1200 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4_EXT,
1201 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6] = RTE_PTYPE_L2_ETHER |
1202 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1203 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6,
1204 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
1205 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1206 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4,
1207 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
1208 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1209 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6_EXT,
1210 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
1211 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1212 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4,
1213 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
1214 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1215 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4 |
1216 : : RTE_PTYPE_INNER_L4_TCP,
1217 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
1218 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1219 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6 |
1220 : : RTE_PTYPE_INNER_L4_TCP,
1221 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
1222 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1223 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4,
1224 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1225 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1226 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6_EXT |
1227 : : RTE_PTYPE_INNER_L4_TCP,
1228 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_EXT_TCP] =
1229 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
1230 : : RTE_PTYPE_TUNNEL_GRE | RTE_PTYPE_INNER_L2_ETHER |
1231 : : RTE_PTYPE_INNER_L3_IPV4,
1232 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
1233 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1234 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4 |
1235 : : RTE_PTYPE_INNER_L4_UDP,
1236 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
1237 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1238 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6 |
1239 : : RTE_PTYPE_INNER_L4_UDP,
1240 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6_SCTP] = RTE_PTYPE_L2_ETHER |
1241 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1242 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6 |
1243 : : RTE_PTYPE_INNER_L4_SCTP,
1244 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
1245 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1246 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4,
1247 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1248 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1249 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6_EXT |
1250 : : RTE_PTYPE_INNER_L4_UDP,
1251 : : [IXGBE_PACKET_TYPE_NVGRE_IPV6_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
1252 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1253 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV6_EXT |
1254 : : RTE_PTYPE_INNER_L4_SCTP,
1255 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_IPV6_EXT_UDP] =
1256 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
1257 : : RTE_PTYPE_TUNNEL_GRE | RTE_PTYPE_INNER_L2_ETHER |
1258 : : RTE_PTYPE_INNER_L3_IPV4,
1259 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
1260 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1261 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4 |
1262 : : RTE_PTYPE_INNER_L4_SCTP,
1263 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
1264 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1265 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4_EXT |
1266 : : RTE_PTYPE_INNER_L4_SCTP,
1267 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1268 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1269 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4_EXT |
1270 : : RTE_PTYPE_INNER_L4_TCP,
1271 : : [IXGBE_PACKET_TYPE_NVGRE_IPV4_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1272 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_TUNNEL_GRE |
1273 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4_EXT |
1274 : : RTE_PTYPE_INNER_L4_UDP,
1275 : :
1276 : : [IXGBE_PACKET_TYPE_VXLAN] = RTE_PTYPE_L2_ETHER |
1277 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1278 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER,
1279 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4] = RTE_PTYPE_L2_ETHER |
1280 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1281 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1282 : : RTE_PTYPE_INNER_L3_IPV4,
1283 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
1284 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1285 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1286 : : RTE_PTYPE_INNER_L3_IPV4_EXT,
1287 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6] = RTE_PTYPE_L2_ETHER |
1288 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1289 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1290 : : RTE_PTYPE_INNER_L3_IPV6,
1291 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
1292 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1293 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1294 : : RTE_PTYPE_INNER_L3_IPV4,
1295 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
1296 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1297 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1298 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
1299 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
1300 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1301 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1302 : : RTE_PTYPE_INNER_L3_IPV4,
1303 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
1304 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1305 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1306 : : RTE_PTYPE_INNER_L3_IPV4 | RTE_PTYPE_INNER_L4_TCP,
1307 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
1308 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1309 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1310 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
1311 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
1312 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1313 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1314 : : RTE_PTYPE_INNER_L3_IPV4,
1315 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1316 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1317 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1318 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
1319 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_EXT_TCP] =
1320 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
1321 : : RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN |
1322 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4,
1323 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
1324 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1325 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1326 : : RTE_PTYPE_INNER_L3_IPV4 | RTE_PTYPE_INNER_L4_UDP,
1327 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
1328 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1329 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1330 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
1331 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6_SCTP] = RTE_PTYPE_L2_ETHER |
1332 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1333 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1334 : : RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_SCTP,
1335 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
1336 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1337 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1338 : : RTE_PTYPE_INNER_L3_IPV4,
1339 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1340 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1341 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1342 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
1343 : : [IXGBE_PACKET_TYPE_VXLAN_IPV6_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
1344 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1345 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1346 : : RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_SCTP,
1347 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_IPV6_EXT_UDP] =
1348 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
1349 : : RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN |
1350 : : RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L3_IPV4,
1351 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
1352 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1353 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1354 : : RTE_PTYPE_INNER_L3_IPV4 | RTE_PTYPE_INNER_L4_SCTP,
1355 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
1356 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1357 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1358 : : RTE_PTYPE_INNER_L3_IPV4_EXT | RTE_PTYPE_INNER_L4_SCTP,
1359 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT_TCP] = RTE_PTYPE_L2_ETHER |
1360 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1361 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1362 : : RTE_PTYPE_INNER_L3_IPV4_EXT | RTE_PTYPE_INNER_L4_TCP,
1363 : : [IXGBE_PACKET_TYPE_VXLAN_IPV4_EXT_UDP] = RTE_PTYPE_L2_ETHER |
1364 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP |
1365 : : RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_INNER_L2_ETHER |
1366 : : RTE_PTYPE_INNER_L3_IPV4_EXT | RTE_PTYPE_INNER_L4_UDP,
1367 : : };
1368 : :
1369 : : static int
1370 : 0 : ixgbe_monitor_callback(const uint64_t value,
1371 : : const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
1372 : : {
1373 : : const uint64_t m = rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD);
1374 : : /*
1375 : : * we expect the DD bit to be set to 1 if this descriptor was already
1376 : : * written to.
1377 : : */
1378 [ # # ]: 0 : return (value & m) == m ? -1 : 0;
1379 : : }
1380 : :
1381 : : int
1382 : 0 : ixgbe_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
1383 : : {
1384 : : volatile union ixgbe_adv_rx_desc *rxdp;
1385 : : struct ixgbe_rx_queue *rxq = rx_queue;
1386 : : uint16_t desc;
1387 : :
1388 : 0 : desc = rxq->rx_tail;
1389 : 0 : rxdp = &rxq->rx_ring[desc];
1390 : : /* watch for changes in status bit */
1391 : 0 : pmc->addr = &rxdp->wb.upper.status_error;
1392 : :
1393 : : /* comparison callback */
1394 : 0 : pmc->fn = ixgbe_monitor_callback;
1395 : :
1396 : : /* the registers are 32-bit */
1397 : 0 : pmc->size = sizeof(uint32_t);
1398 : :
1399 : 0 : return 0;
1400 : : }
1401 : :
1402 : : /* @note: fix ixgbe_dev_supported_ptypes_get() if any change here. */
1403 : : static inline uint32_t
1404 : : ixgbe_rxd_pkt_info_to_pkt_type(uint32_t pkt_info, uint16_t ptype_mask)
1405 : : {
1406 : :
1407 : 0 : if (unlikely(pkt_info & IXGBE_RXDADV_PKTTYPE_ETQF))
1408 : : return RTE_PTYPE_UNKNOWN;
1409 : :
1410 : 0 : pkt_info = (pkt_info >> IXGBE_PACKET_TYPE_SHIFT) & ptype_mask;
1411 : :
1412 : : /* For tunnel packet */
1413 [ # # # # : 0 : if (pkt_info & IXGBE_PACKET_TYPE_TUNNEL_BIT) {
# # ]
1414 : : /* Remove the tunnel bit to save the space. */
1415 : 0 : pkt_info &= IXGBE_PACKET_TYPE_MASK_TUNNEL;
1416 : 0 : return ptype_table_tn[pkt_info];
1417 : : }
1418 : :
1419 : : /**
1420 : : * For x550, if it's not tunnel,
1421 : : * tunnel type bit should be set to 0.
1422 : : * Reuse 82599's mask.
1423 : : */
1424 : 0 : pkt_info &= IXGBE_PACKET_TYPE_MASK_82599;
1425 : :
1426 : 0 : return ptype_table[pkt_info];
1427 : : }
1428 : :
1429 : : static inline uint64_t
1430 : : ixgbe_rxd_pkt_info_to_pkt_flags(uint16_t pkt_info)
1431 : : {
1432 : : static alignas(RTE_CACHE_LINE_SIZE) uint64_t ip_rss_types_map[16] = {
1433 : : 0, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH,
1434 : : 0, RTE_MBUF_F_RX_RSS_HASH, 0, RTE_MBUF_F_RX_RSS_HASH,
1435 : : RTE_MBUF_F_RX_RSS_HASH, 0, 0, 0,
1436 : : 0, 0, 0, RTE_MBUF_F_RX_FDIR,
1437 : : };
1438 : : #ifdef RTE_LIBRTE_IEEE1588
1439 : : static uint64_t ip_pkt_etqf_map[8] = {
1440 : : 0, 0, 0, RTE_MBUF_F_RX_IEEE1588_PTP,
1441 : : 0, 0, 0, 0,
1442 : : };
1443 : :
1444 : : if (likely(pkt_info & IXGBE_RXDADV_PKTTYPE_ETQF))
1445 : : return ip_pkt_etqf_map[(pkt_info >> 4) & 0X07] |
1446 : : ip_rss_types_map[pkt_info & 0XF];
1447 : : else
1448 : : return ip_rss_types_map[pkt_info & 0XF];
1449 : : #else
1450 : 0 : return ip_rss_types_map[pkt_info & 0XF];
1451 : : #endif
1452 : : }
1453 : :
1454 : : static inline uint64_t
1455 : : rx_desc_status_to_pkt_flags(uint32_t rx_status, uint64_t vlan_flags)
1456 : : {
1457 : : uint64_t pkt_flags;
1458 : :
1459 : : /*
1460 : : * Check if VLAN present only.
1461 : : * Do not check whether L3/L4 rx checksum done by NIC or not,
1462 : : * That can be found from rte_eth_rxmode.offloads flag
1463 : : */
1464 : 0 : pkt_flags = (rx_status & IXGBE_RXD_STAT_VP) ? vlan_flags : 0;
1465 : :
1466 : : #ifdef RTE_LIBRTE_IEEE1588
1467 : : if (rx_status & IXGBE_RXD_STAT_TMST)
1468 : : pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
1469 : : #endif
1470 : : return pkt_flags;
1471 : : }
1472 : :
1473 : : static inline uint64_t
1474 : 0 : rx_desc_error_to_pkt_flags(uint32_t rx_status, uint16_t pkt_info,
1475 : : uint8_t rx_udp_csum_zero_err)
1476 : : {
1477 : : uint64_t pkt_flags;
1478 : :
1479 : : /*
1480 : : * Bit 31: IPE, IPv4 checksum error
1481 : : * Bit 30: L4I, L4I integrity error
1482 : : */
1483 : : static uint64_t error_to_pkt_flags_map[4] = {
1484 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
1485 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
1486 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
1487 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD
1488 : : };
1489 : 0 : pkt_flags = error_to_pkt_flags_map[(rx_status >>
1490 : 0 : IXGBE_RXDADV_ERR_CKSUM_BIT) & IXGBE_RXDADV_ERR_CKSUM_MSK];
1491 : :
1492 : : /* Mask out the bad UDP checksum error if the hardware has UDP zero
1493 : : * checksum error issue, so that the software application will then
1494 : : * have to recompute the checksum itself if needed.
1495 : : */
1496 [ # # # # ]: 0 : if ((rx_status & IXGBE_RXDADV_ERR_TCPE) &&
1497 [ # # ]: 0 : (pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1498 : : rx_udp_csum_zero_err)
1499 : 0 : pkt_flags &= ~RTE_MBUF_F_RX_L4_CKSUM_BAD;
1500 : :
1501 [ # # ]: 0 : if ((rx_status & IXGBE_RXD_STAT_OUTERIPCS) &&
1502 : : (rx_status & IXGBE_RXDADV_ERR_OUTERIPER)) {
1503 : 0 : pkt_flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
1504 : : }
1505 : :
1506 : : #ifdef RTE_LIB_SECURITY
1507 [ # # ]: 0 : if (rx_status & IXGBE_RXD_STAT_SECP) {
1508 : 0 : pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD;
1509 [ # # ]: 0 : if (rx_status & IXGBE_RXDADV_LNKSEC_ERROR_BAD_SIG)
1510 : 0 : pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED;
1511 : : }
1512 : : #endif
1513 : :
1514 : 0 : return pkt_flags;
1515 : : }
1516 : :
1517 : : /*
1518 : : * LOOK_AHEAD defines how many desc statuses to check beyond the
1519 : : * current descriptor.
1520 : : * It must be a pound define for optimal performance.
1521 : : * Do not change the value of LOOK_AHEAD, as the ixgbe_rx_scan_hw_ring
1522 : : * function only works with LOOK_AHEAD=8.
1523 : : */
1524 : : #define LOOK_AHEAD 8
1525 : : #if (LOOK_AHEAD != 8)
1526 : : #error "PMD IXGBE: LOOK_AHEAD must be 8\n"
1527 : : #endif
1528 : : static inline int
1529 : 0 : ixgbe_rx_scan_hw_ring(struct ixgbe_rx_queue *rxq)
1530 : : {
1531 : : volatile union ixgbe_adv_rx_desc *rxdp;
1532 : : struct ixgbe_rx_entry *rxep;
1533 : : struct rte_mbuf *mb;
1534 : : uint16_t pkt_len;
1535 : : uint64_t pkt_flags;
1536 : : int nb_dd;
1537 : : uint32_t s[LOOK_AHEAD];
1538 : : uint32_t pkt_info[LOOK_AHEAD];
1539 : : int i, j, nb_rx = 0;
1540 : : uint32_t status;
1541 : 0 : uint64_t vlan_flags = rxq->vlan_flags;
1542 : :
1543 : : /* get references to current descriptor and S/W ring entry */
1544 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
1545 : 0 : rxep = &rxq->sw_ring[rxq->rx_tail];
1546 : :
1547 : 0 : status = rxdp->wb.upper.status_error;
1548 : : /* check to make sure there is at least 1 packet to receive */
1549 [ # # ]: 0 : if (!(status & rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
1550 : : return 0;
1551 : :
1552 : : /*
1553 : : * Scan LOOK_AHEAD descriptors at a time to determine which descriptors
1554 : : * reference packets that are ready to be received.
1555 : : */
1556 [ # # ]: 0 : for (i = 0; i < RTE_PMD_IXGBE_RX_MAX_BURST;
1557 : 0 : i += LOOK_AHEAD, rxdp += LOOK_AHEAD, rxep += LOOK_AHEAD) {
1558 : : /* Read desc statuses backwards to avoid race condition */
1559 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; j++)
1560 : 0 : s[j] = rte_le_to_cpu_32(rxdp[j].wb.upper.status_error);
1561 : :
1562 : 0 : rte_smp_rmb();
1563 : :
1564 : : /* Compute how many status bits were set */
1565 [ # # ]: 0 : for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
1566 [ # # ]: 0 : (s[nb_dd] & IXGBE_RXDADV_STAT_DD); nb_dd++)
1567 : : ;
1568 : :
1569 [ # # ]: 0 : for (j = 0; j < nb_dd; j++)
1570 : 0 : pkt_info[j] = rte_le_to_cpu_32(rxdp[j].wb.lower.
1571 : : lo_dword.data);
1572 : :
1573 : 0 : nb_rx += nb_dd;
1574 : :
1575 : : /* Translate descriptor info to mbuf format */
1576 [ # # ]: 0 : for (j = 0; j < nb_dd; ++j) {
1577 : 0 : mb = rxep[j].mbuf;
1578 : 0 : pkt_len = rte_le_to_cpu_16(rxdp[j].wb.upper.length) -
1579 : 0 : rxq->crc_len;
1580 : 0 : mb->data_len = pkt_len;
1581 : 0 : mb->pkt_len = pkt_len;
1582 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxdp[j].wb.upper.vlan);
1583 : :
1584 : : /* convert descriptor fields to rte mbuf flags */
1585 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(s[j],
1586 : : vlan_flags);
1587 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(s[j],
1588 : 0 : (uint16_t)pkt_info[j],
1589 : 0 : rxq->rx_udp_csum_zero_err);
1590 : 0 : pkt_flags |= ixgbe_rxd_pkt_info_to_pkt_flags
1591 : : ((uint16_t)pkt_info[j]);
1592 : 0 : mb->ol_flags = pkt_flags;
1593 : 0 : mb->packet_type =
1594 : : ixgbe_rxd_pkt_info_to_pkt_type
1595 [ # # ]: 0 : (pkt_info[j], rxq->pkt_type_mask);
1596 : :
1597 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1598 : 0 : mb->hash.rss = rte_le_to_cpu_32(
1599 : : rxdp[j].wb.lower.hi_dword.rss);
1600 [ # # ]: 0 : else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
1601 : 0 : mb->hash.fdir.hash = rte_le_to_cpu_16(
1602 : 0 : rxdp[j].wb.lower.hi_dword.csum_ip.csum) &
1603 : : IXGBE_ATR_HASH_MASK;
1604 : 0 : mb->hash.fdir.id = rte_le_to_cpu_16(
1605 : : rxdp[j].wb.lower.hi_dword.csum_ip.ip_id);
1606 : : }
1607 : : }
1608 : :
1609 : : /* Move mbuf pointers from the S/W ring to the stage */
1610 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; ++j) {
1611 : 0 : rxq->rx_stage[i + j] = rxep[j].mbuf;
1612 : : }
1613 : :
1614 : : /* stop if all requested packets could not be received */
1615 [ # # ]: 0 : if (nb_dd != LOOK_AHEAD)
1616 : : break;
1617 : : }
1618 : :
1619 : : /* clear software ring entries so we can cleanup correctly */
1620 [ # # ]: 0 : for (i = 0; i < nb_rx; ++i) {
1621 : 0 : rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
1622 : : }
1623 : :
1624 : :
1625 : : return nb_rx;
1626 : : }
1627 : :
1628 : : static inline int
1629 : 0 : ixgbe_rx_alloc_bufs(struct ixgbe_rx_queue *rxq, bool reset_mbuf)
1630 : : {
1631 : : volatile union ixgbe_adv_rx_desc *rxdp;
1632 : : struct ixgbe_rx_entry *rxep;
1633 : : struct rte_mbuf *mb;
1634 : : uint16_t alloc_idx;
1635 : : __le64 dma_addr;
1636 : : int diag, i;
1637 : :
1638 : : /* allocate buffers in bulk directly into the S/W ring */
1639 : 0 : alloc_idx = rxq->rx_free_trigger - (rxq->rx_free_thresh - 1);
1640 : 0 : rxep = &rxq->sw_ring[alloc_idx];
1641 [ # # ]: 0 : diag = rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
1642 : : rxq->rx_free_thresh);
1643 [ # # ]: 0 : if (unlikely(diag != 0))
1644 : : return -ENOMEM;
1645 : :
1646 : 0 : rxdp = &rxq->rx_ring[alloc_idx];
1647 [ # # ]: 0 : for (i = 0; i < rxq->rx_free_thresh; ++i) {
1648 : : /* populate the static rte mbuf fields */
1649 : 0 : mb = rxep[i].mbuf;
1650 [ # # ]: 0 : if (reset_mbuf) {
1651 : 0 : mb->port = rxq->port_id;
1652 : : }
1653 : :
1654 : : rte_mbuf_refcnt_set(mb, 1);
1655 : 0 : mb->data_off = RTE_PKTMBUF_HEADROOM;
1656 : :
1657 : : /* populate the descriptors */
1658 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
1659 : 0 : rxdp[i].read.hdr_addr = 0;
1660 : 0 : rxdp[i].read.pkt_addr = dma_addr;
1661 : : }
1662 : :
1663 : : /* update state of internal queue structure */
1664 : 0 : rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh;
1665 [ # # ]: 0 : if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
1666 : 0 : rxq->rx_free_trigger = rxq->rx_free_thresh - 1;
1667 : :
1668 : : /* no errors */
1669 : : return 0;
1670 : : }
1671 : :
1672 : : static inline uint16_t
1673 : : ixgbe_rx_fill_from_stage(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
1674 : : uint16_t nb_pkts)
1675 : : {
1676 : 0 : struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
1677 : : int i;
1678 : :
1679 : : /* how many packets are ready to return? */
1680 : 0 : nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
1681 : :
1682 : : /* copy mbuf pointers to the application's packet list */
1683 [ # # # # ]: 0 : for (i = 0; i < nb_pkts; ++i)
1684 : 0 : rx_pkts[i] = stage[i];
1685 : :
1686 : : /* update internal queue state */
1687 : 0 : rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
1688 : 0 : rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
1689 : :
1690 : : return nb_pkts;
1691 : : }
1692 : :
1693 : : static inline uint16_t
1694 : 0 : rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1695 : : uint16_t nb_pkts)
1696 : : {
1697 : : struct ixgbe_rx_queue *rxq = (struct ixgbe_rx_queue *)rx_queue;
1698 : : uint16_t nb_rx = 0;
1699 : :
1700 : : /* Any previously recv'd pkts will be returned from the Rx stage */
1701 [ # # ]: 0 : if (rxq->rx_nb_avail)
1702 : 0 : return ixgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1703 : :
1704 : : /* Scan the H/W ring for packets to receive */
1705 : 0 : nb_rx = (uint16_t)ixgbe_rx_scan_hw_ring(rxq);
1706 : :
1707 : : /* update internal queue state */
1708 : 0 : rxq->rx_next_avail = 0;
1709 : 0 : rxq->rx_nb_avail = nb_rx;
1710 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
1711 : :
1712 : : /* if required, allocate new buffers to replenish descriptors */
1713 [ # # ]: 0 : if (rxq->rx_tail > rxq->rx_free_trigger) {
1714 : : uint16_t cur_free_trigger = rxq->rx_free_trigger;
1715 : :
1716 [ # # ]: 0 : if (ixgbe_rx_alloc_bufs(rxq, true) != 0) {
1717 : : int i, j;
1718 : :
1719 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1720 : : "queue_id=%u", (unsigned) rxq->port_id,
1721 : : (unsigned) rxq->queue_id);
1722 : :
1723 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
1724 : 0 : rxq->rx_free_thresh;
1725 : :
1726 : : /*
1727 : : * Need to rewind any previous receives if we cannot
1728 : : * allocate new buffers to replenish the old ones.
1729 : : */
1730 : 0 : rxq->rx_nb_avail = 0;
1731 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
1732 [ # # ]: 0 : for (i = 0, j = rxq->rx_tail; i < nb_rx; ++i, ++j)
1733 : 0 : rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
1734 : :
1735 : : return 0;
1736 : : }
1737 : :
1738 : : /* update tail pointer */
1739 : : rte_wmb();
1740 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(rxq->rdt_reg_addr,
1741 : : cur_free_trigger);
1742 : : }
1743 : :
1744 [ # # ]: 0 : if (rxq->rx_tail >= rxq->nb_rx_desc)
1745 : 0 : rxq->rx_tail = 0;
1746 : :
1747 : : /* received any packets this loop? */
1748 [ # # ]: 0 : if (rxq->rx_nb_avail)
1749 : 0 : return ixgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1750 : :
1751 : : return 0;
1752 : : }
1753 : :
1754 : : /* split requests into chunks of size RTE_PMD_IXGBE_RX_MAX_BURST */
1755 : : uint16_t
1756 : 0 : ixgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1757 : : uint16_t nb_pkts)
1758 : : {
1759 : : uint16_t nb_rx;
1760 : :
1761 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
1762 : : return 0;
1763 : :
1764 [ # # ]: 0 : if (likely(nb_pkts <= RTE_PMD_IXGBE_RX_MAX_BURST))
1765 : 0 : return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
1766 : :
1767 : : /* request is relatively large, chunk it up */
1768 : : nb_rx = 0;
1769 [ # # ]: 0 : while (nb_pkts) {
1770 : : uint16_t ret, n;
1771 : :
1772 : 0 : n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_IXGBE_RX_MAX_BURST);
1773 : 0 : ret = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
1774 : 0 : nb_rx = (uint16_t)(nb_rx + ret);
1775 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
1776 [ # # ]: 0 : if (ret < n)
1777 : : break;
1778 : : }
1779 : :
1780 : : return nb_rx;
1781 : : }
1782 : :
1783 : : uint16_t
1784 : 0 : ixgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1785 : : uint16_t nb_pkts)
1786 : : {
1787 : : struct ixgbe_rx_queue *rxq;
1788 : : volatile union ixgbe_adv_rx_desc *rx_ring;
1789 : : volatile union ixgbe_adv_rx_desc *rxdp;
1790 : : struct ixgbe_rx_entry *sw_ring;
1791 : : struct ixgbe_rx_entry *rxe;
1792 : : struct rte_mbuf *rxm;
1793 : : struct rte_mbuf *nmb;
1794 : : union ixgbe_adv_rx_desc rxd;
1795 : : uint64_t dma_addr;
1796 : : uint32_t staterr;
1797 : : uint32_t pkt_info;
1798 : : uint16_t pkt_len;
1799 : : uint16_t rx_id;
1800 : : uint16_t nb_rx;
1801 : : uint16_t nb_hold;
1802 : : uint64_t pkt_flags;
1803 : : uint64_t vlan_flags;
1804 : :
1805 : : nb_rx = 0;
1806 : : nb_hold = 0;
1807 : : rxq = rx_queue;
1808 : 0 : rx_id = rxq->rx_tail;
1809 : 0 : rx_ring = rxq->rx_ring;
1810 : 0 : sw_ring = rxq->sw_ring;
1811 : 0 : vlan_flags = rxq->vlan_flags;
1812 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1813 : : /*
1814 : : * The order of operations here is important as the DD status
1815 : : * bit must not be read after any other descriptor fields.
1816 : : * rx_ring and rxdp are pointing to volatile data so the order
1817 : : * of accesses cannot be reordered by the compiler. If they were
1818 : : * not volatile, they could be reordered which could lead to
1819 : : * using invalid descriptor fields when read from rxd.
1820 : : *
1821 : : * Meanwhile, to prevent the CPU from executing out of order, we
1822 : : * need to use a proper memory barrier to ensure the memory
1823 : : * ordering below.
1824 : : */
1825 : 0 : rxdp = &rx_ring[rx_id];
1826 : 0 : staterr = rxdp->wb.upper.status_error;
1827 [ # # ]: 0 : if (!(staterr & rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
1828 : : break;
1829 : :
1830 : : /*
1831 : : * Use acquire fence to ensure that status_error which includes
1832 : : * DD bit is loaded before loading of other descriptor words.
1833 : : */
1834 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1835 : :
1836 : 0 : rxd = *rxdp;
1837 : :
1838 : : /*
1839 : : * End of packet.
1840 : : *
1841 : : * If the IXGBE_RXDADV_STAT_EOP flag is not set, the RX packet
1842 : : * is likely to be invalid and to be dropped by the various
1843 : : * validation checks performed by the network stack.
1844 : : *
1845 : : * Allocate a new mbuf to replenish the RX ring descriptor.
1846 : : * If the allocation fails:
1847 : : * - arrange for that RX descriptor to be the first one
1848 : : * being parsed the next time the receive function is
1849 : : * invoked [on the same queue].
1850 : : *
1851 : : * - Stop parsing the RX ring and return immediately.
1852 : : *
1853 : : * This policy do not drop the packet received in the RX
1854 : : * descriptor for which the allocation of a new mbuf failed.
1855 : : * Thus, it allows that packet to be later retrieved if
1856 : : * mbuf have been freed in the mean time.
1857 : : * As a side effect, holding RX descriptors instead of
1858 : : * systematically giving them back to the NIC may lead to
1859 : : * RX ring exhaustion situations.
1860 : : * However, the NIC can gracefully prevent such situations
1861 : : * to happen by sending specific "back-pressure" flow control
1862 : : * frames to its peer(s).
1863 : : */
1864 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1865 : : "ext_err_stat=0x%08x pkt_len=%u",
1866 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1867 : : (unsigned) rx_id, (unsigned) staterr,
1868 : : (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
1869 : :
1870 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1871 [ # # ]: 0 : if (nmb == NULL) {
1872 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1873 : : "queue_id=%u", (unsigned) rxq->port_id,
1874 : : (unsigned) rxq->queue_id);
1875 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
1876 : 0 : break;
1877 : : }
1878 : :
1879 : 0 : nb_hold++;
1880 : 0 : rxe = &sw_ring[rx_id];
1881 : 0 : rx_id++;
1882 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
1883 : : rx_id = 0;
1884 : :
1885 : : /* Prefetch next mbuf while processing current one. */
1886 : 0 : rte_ixgbe_prefetch(sw_ring[rx_id].mbuf);
1887 : :
1888 : : /*
1889 : : * When next RX descriptor is on a cache-line boundary,
1890 : : * prefetch the next 4 RX descriptors and the next 8 pointers
1891 : : * to mbufs.
1892 : : */
1893 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
1894 : 0 : rte_ixgbe_prefetch(&rx_ring[rx_id]);
1895 : : rte_ixgbe_prefetch(&sw_ring[rx_id]);
1896 : : }
1897 : :
1898 : 0 : rxm = rxe->mbuf;
1899 : 0 : rxe->mbuf = nmb;
1900 : : dma_addr =
1901 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1902 : 0 : rxdp->read.hdr_addr = 0;
1903 : 0 : rxdp->read.pkt_addr = dma_addr;
1904 : :
1905 : : /*
1906 : : * Initialize the returned mbuf.
1907 : : * 1) setup generic mbuf fields:
1908 : : * - number of segments,
1909 : : * - next segment,
1910 : : * - packet length,
1911 : : * - RX port identifier.
1912 : : * 2) integrate hardware offload data, if any:
1913 : : * - RSS flag & hash,
1914 : : * - IP checksum flag,
1915 : : * - VLAN TCI, if any,
1916 : : * - error flags.
1917 : : */
1918 : 0 : pkt_len = (uint16_t) (rte_le_to_cpu_16(rxd.wb.upper.length) -
1919 : 0 : rxq->crc_len);
1920 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1921 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
1922 : 0 : rxm->nb_segs = 1;
1923 : 0 : rxm->next = NULL;
1924 : 0 : rxm->pkt_len = pkt_len;
1925 : 0 : rxm->data_len = pkt_len;
1926 : 0 : rxm->port = rxq->port_id;
1927 : :
1928 : : pkt_info = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
1929 : : /* Only valid if RTE_MBUF_F_RX_VLAN set in pkt_flags */
1930 [ # # ]: 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd.wb.upper.vlan);
1931 : :
1932 : : pkt_flags = rx_desc_status_to_pkt_flags(staterr, vlan_flags);
1933 : 0 : pkt_flags = pkt_flags |
1934 : 0 : rx_desc_error_to_pkt_flags(staterr, (uint16_t)pkt_info,
1935 : 0 : rxq->rx_udp_csum_zero_err);
1936 : 0 : pkt_flags = pkt_flags |
1937 : : ixgbe_rxd_pkt_info_to_pkt_flags((uint16_t)pkt_info);
1938 : 0 : rxm->ol_flags = pkt_flags;
1939 : 0 : rxm->packet_type =
1940 : : ixgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1941 [ # # ]: 0 : rxq->pkt_type_mask);
1942 : :
1943 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1944 : 0 : rxm->hash.rss = rte_le_to_cpu_32(
1945 : : rxd.wb.lower.hi_dword.rss);
1946 [ # # ]: 0 : else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
1947 : 0 : rxm->hash.fdir.hash = rte_le_to_cpu_16(
1948 : 0 : rxd.wb.lower.hi_dword.csum_ip.csum) &
1949 : : IXGBE_ATR_HASH_MASK;
1950 : 0 : rxm->hash.fdir.id = rte_le_to_cpu_16(
1951 : : rxd.wb.lower.hi_dword.csum_ip.ip_id);
1952 : : }
1953 : : /*
1954 : : * Store the mbuf address into the next entry of the array
1955 : : * of returned packets.
1956 : : */
1957 : 0 : rx_pkts[nb_rx++] = rxm;
1958 : : }
1959 : 0 : rxq->rx_tail = rx_id;
1960 : :
1961 : : /*
1962 : : * If the number of free RX descriptors is greater than the RX free
1963 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1964 : : * register.
1965 : : * Update the RDT with the value of the last processed RX descriptor
1966 : : * minus 1, to guarantee that the RDT register is never equal to the
1967 : : * RDH register, which creates a "full" ring situation from the
1968 : : * hardware point of view...
1969 : : */
1970 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
1971 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1972 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1973 : : "nb_hold=%u nb_rx=%u",
1974 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1975 : : (unsigned) rx_id, (unsigned) nb_hold,
1976 : : (unsigned) nb_rx);
1977 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
1978 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1979 : 0 : IXGBE_PCI_REG_WC_WRITE(rxq->rdt_reg_addr, rx_id);
1980 : : nb_hold = 0;
1981 : : }
1982 : 0 : rxq->nb_rx_hold = nb_hold;
1983 : 0 : return nb_rx;
1984 : : }
1985 : :
1986 : : /**
1987 : : * Detect an RSC descriptor.
1988 : : */
1989 : : static inline uint32_t
1990 : : ixgbe_rsc_count(union ixgbe_adv_rx_desc *rx)
1991 : : {
1992 : 0 : return (rte_le_to_cpu_32(rx->wb.lower.lo_dword.data) &
1993 : 0 : IXGBE_RXDADV_RSCCNT_MASK) >> IXGBE_RXDADV_RSCCNT_SHIFT;
1994 : : }
1995 : :
1996 : : /**
1997 : : * ixgbe_fill_cluster_head_buf - fill the first mbuf of the returned packet
1998 : : *
1999 : : * Fill the following info in the HEAD buffer of the Rx cluster:
2000 : : * - RX port identifier
2001 : : * - hardware offload data, if any:
2002 : : * - RSS flag & hash
2003 : : * - IP checksum flag
2004 : : * - VLAN TCI, if any
2005 : : * - error flags
2006 : : * @head HEAD of the packet cluster
2007 : : * @desc HW descriptor to get data from
2008 : : * @rxq Pointer to the Rx queue
2009 : : */
2010 : : static inline void
2011 : 0 : ixgbe_fill_cluster_head_buf(
2012 : : struct rte_mbuf *head,
2013 : : union ixgbe_adv_rx_desc *desc,
2014 : : struct ixgbe_rx_queue *rxq,
2015 : : uint32_t staterr)
2016 : : {
2017 : : uint32_t pkt_info;
2018 : : uint64_t pkt_flags;
2019 : :
2020 : 0 : head->port = rxq->port_id;
2021 : :
2022 : : /* The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
2023 : : * set in the pkt_flags field.
2024 : : */
2025 : 0 : head->vlan_tci = rte_le_to_cpu_16(desc->wb.upper.vlan);
2026 : 0 : pkt_info = rte_le_to_cpu_32(desc->wb.lower.lo_dword.data);
2027 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(staterr, rxq->vlan_flags);
2028 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(staterr, (uint16_t)pkt_info,
2029 : 0 : rxq->rx_udp_csum_zero_err);
2030 : 0 : pkt_flags |= ixgbe_rxd_pkt_info_to_pkt_flags((uint16_t)pkt_info);
2031 : 0 : head->ol_flags = pkt_flags;
2032 : 0 : head->packet_type =
2033 [ # # ]: 0 : ixgbe_rxd_pkt_info_to_pkt_type(pkt_info, rxq->pkt_type_mask);
2034 : :
2035 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
2036 : 0 : head->hash.rss = rte_le_to_cpu_32(desc->wb.lower.hi_dword.rss);
2037 [ # # ]: 0 : else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
2038 : 0 : head->hash.fdir.hash =
2039 : 0 : rte_le_to_cpu_16(desc->wb.lower.hi_dword.csum_ip.csum)
2040 : 0 : & IXGBE_ATR_HASH_MASK;
2041 : 0 : head->hash.fdir.id =
2042 : 0 : rte_le_to_cpu_16(desc->wb.lower.hi_dword.csum_ip.ip_id);
2043 : : }
2044 : 0 : }
2045 : :
2046 : : /**
2047 : : * ixgbe_recv_pkts_lro - receive handler for and LRO case.
2048 : : *
2049 : : * @rx_queue Rx queue handle
2050 : : * @rx_pkts table of received packets
2051 : : * @nb_pkts size of rx_pkts table
2052 : : * @bulk_alloc if TRUE bulk allocation is used for a HW ring refilling
2053 : : *
2054 : : * Handles the Rx HW ring completions when RSC feature is configured. Uses an
2055 : : * additional ring of ixgbe_rsc_entry's that will hold the relevant RSC info.
2056 : : *
2057 : : * We use the same logic as in Linux and in FreeBSD ixgbe drivers:
2058 : : * 1) When non-EOP RSC completion arrives:
2059 : : * a) Update the HEAD of the current RSC aggregation cluster with the new
2060 : : * segment's data length.
2061 : : * b) Set the "next" pointer of the current segment to point to the segment
2062 : : * at the NEXTP index.
2063 : : * c) Pass the HEAD of RSC aggregation cluster on to the next NEXTP entry
2064 : : * in the sw_rsc_ring.
2065 : : * 2) When EOP arrives we just update the cluster's total length and offload
2066 : : * flags and deliver the cluster up to the upper layers. In our case - put it
2067 : : * in the rx_pkts table.
2068 : : *
2069 : : * Returns the number of received packets/clusters (according to the "bulk
2070 : : * receive" interface).
2071 : : */
2072 : : static inline uint16_t
2073 : 0 : ixgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts,
2074 : : bool bulk_alloc)
2075 : : {
2076 : : struct ixgbe_rx_queue *rxq = rx_queue;
2077 : 0 : volatile union ixgbe_adv_rx_desc *rx_ring = rxq->rx_ring;
2078 : 0 : struct ixgbe_rx_entry *sw_ring = rxq->sw_ring;
2079 : 0 : struct ixgbe_scattered_rx_entry *sw_sc_ring = rxq->sw_sc_ring;
2080 : 0 : uint16_t rx_id = rxq->rx_tail;
2081 : : uint16_t nb_rx = 0;
2082 : 0 : uint16_t nb_hold = rxq->nb_rx_hold;
2083 : : uint16_t prev_id = rxq->rx_tail;
2084 : :
2085 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2086 : : bool eop;
2087 : : struct ixgbe_rx_entry *rxe;
2088 : : struct ixgbe_scattered_rx_entry *sc_entry;
2089 : : struct ixgbe_scattered_rx_entry *next_sc_entry = NULL;
2090 : : struct ixgbe_rx_entry *next_rxe = NULL;
2091 : : struct rte_mbuf *first_seg;
2092 : : struct rte_mbuf *rxm;
2093 : : struct rte_mbuf *nmb = NULL;
2094 : : union ixgbe_adv_rx_desc rxd;
2095 : : uint16_t data_len;
2096 : : uint16_t next_id;
2097 : : volatile union ixgbe_adv_rx_desc *rxdp;
2098 : : uint32_t staterr;
2099 : :
2100 : 0 : next_desc:
2101 : : /*
2102 : : * "Volatile" only prevents caching of the variable marked
2103 : : * volatile. Most important, "volatile" cannot prevent the CPU
2104 : : * from executing out of order. So, it is necessary to use a
2105 : : * proper memory barrier to ensure the memory ordering below.
2106 : : */
2107 : 0 : rxdp = &rx_ring[rx_id];
2108 : 0 : staterr = rte_le_to_cpu_32(rxdp->wb.upper.status_error);
2109 : :
2110 [ # # ]: 0 : if (!(staterr & IXGBE_RXDADV_STAT_DD))
2111 : : break;
2112 : :
2113 : : /*
2114 : : * Use acquire fence to ensure that status_error which includes
2115 : : * DD bit is loaded before loading of other descriptor words.
2116 : : */
2117 : : rte_atomic_thread_fence(rte_memory_order_acquire);
2118 : :
2119 : 0 : rxd = *rxdp;
2120 : :
2121 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
2122 : : "staterr=0x%x data_len=%u",
2123 : : rxq->port_id, rxq->queue_id, rx_id, staterr,
2124 : : rte_le_to_cpu_16(rxd.wb.upper.length));
2125 : :
2126 [ # # ]: 0 : if (!bulk_alloc) {
2127 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
2128 [ # # ]: 0 : if (nmb == NULL) {
2129 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed "
2130 : : "port_id=%u queue_id=%u",
2131 : : rxq->port_id, rxq->queue_id);
2132 : :
2133 : 0 : rte_eth_devices[rxq->port_id].data->
2134 : 0 : rx_mbuf_alloc_failed++;
2135 : 0 : break;
2136 : : }
2137 [ # # ]: 0 : } else if (nb_hold > rxq->rx_free_thresh) {
2138 : 0 : uint16_t next_rdt = rxq->rx_free_trigger;
2139 : :
2140 [ # # ]: 0 : if (!ixgbe_rx_alloc_bufs(rxq, false)) {
2141 : : rte_wmb();
2142 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(
2143 : : rxq->rdt_reg_addr,
2144 : : next_rdt);
2145 : 0 : nb_hold -= rxq->rx_free_thresh;
2146 : : } else {
2147 : : PMD_RX_LOG(DEBUG, "RX bulk alloc failed "
2148 : : "port_id=%u queue_id=%u",
2149 : : rxq->port_id, rxq->queue_id);
2150 : :
2151 : 0 : rte_eth_devices[rxq->port_id].data->
2152 : 0 : rx_mbuf_alloc_failed++;
2153 : 0 : break;
2154 : : }
2155 : : }
2156 : :
2157 : 0 : nb_hold++;
2158 : 0 : rxe = &sw_ring[rx_id];
2159 : 0 : eop = staterr & IXGBE_RXDADV_STAT_EOP;
2160 : :
2161 : 0 : next_id = rx_id + 1;
2162 [ # # ]: 0 : if (next_id == rxq->nb_rx_desc)
2163 : : next_id = 0;
2164 : :
2165 : : /* Prefetch next mbuf while processing current one. */
2166 : 0 : rte_ixgbe_prefetch(sw_ring[next_id].mbuf);
2167 : :
2168 : : /*
2169 : : * When next RX descriptor is on a cache-line boundary,
2170 : : * prefetch the next 4 RX descriptors and the next 4 pointers
2171 : : * to mbufs.
2172 : : */
2173 [ # # ]: 0 : if ((next_id & 0x3) == 0) {
2174 : 0 : rte_ixgbe_prefetch(&rx_ring[next_id]);
2175 : : rte_ixgbe_prefetch(&sw_ring[next_id]);
2176 : : }
2177 : :
2178 : 0 : rxm = rxe->mbuf;
2179 : :
2180 [ # # ]: 0 : if (!bulk_alloc) {
2181 : : __le64 dma =
2182 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
2183 : : /*
2184 : : * Update RX descriptor with the physical address of the
2185 : : * new data buffer of the new allocated mbuf.
2186 : : */
2187 : 0 : rxe->mbuf = nmb;
2188 : :
2189 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2190 : 0 : rxdp->read.hdr_addr = 0;
2191 : 0 : rxdp->read.pkt_addr = dma;
2192 : : } else
2193 : 0 : rxe->mbuf = NULL;
2194 : :
2195 : : /*
2196 : : * Set data length & data buffer address of mbuf.
2197 : : */
2198 : 0 : data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
2199 : 0 : rxm->data_len = data_len;
2200 : :
2201 [ # # ]: 0 : if (!eop) {
2202 : : uint16_t nextp_id;
2203 : : /*
2204 : : * Get next descriptor index:
2205 : : * - For RSC it's in the NEXTP field.
2206 : : * - For a scattered packet - it's just a following
2207 : : * descriptor.
2208 : : */
2209 [ # # ]: 0 : if (ixgbe_rsc_count(&rxd))
2210 : 0 : nextp_id =
2211 : 0 : (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
2212 : : IXGBE_RXDADV_NEXTP_SHIFT;
2213 : : else
2214 : : nextp_id = next_id;
2215 : :
2216 : 0 : next_sc_entry = &sw_sc_ring[nextp_id];
2217 : 0 : next_rxe = &sw_ring[nextp_id];
2218 : : rte_ixgbe_prefetch(next_rxe);
2219 : : }
2220 : :
2221 : 0 : sc_entry = &sw_sc_ring[rx_id];
2222 : 0 : first_seg = sc_entry->fbuf;
2223 : 0 : sc_entry->fbuf = NULL;
2224 : :
2225 : : /*
2226 : : * If this is the first buffer of the received packet,
2227 : : * set the pointer to the first mbuf of the packet and
2228 : : * initialize its context.
2229 : : * Otherwise, update the total length and the number of segments
2230 : : * of the current scattered packet, and update the pointer to
2231 : : * the last mbuf of the current packet.
2232 : : */
2233 [ # # ]: 0 : if (first_seg == NULL) {
2234 : : first_seg = rxm;
2235 : 0 : first_seg->pkt_len = data_len;
2236 : 0 : first_seg->nb_segs = 1;
2237 : : } else {
2238 : 0 : first_seg->pkt_len += data_len;
2239 : 0 : first_seg->nb_segs++;
2240 : : }
2241 : :
2242 : : prev_id = rx_id;
2243 : : rx_id = next_id;
2244 : :
2245 : : /*
2246 : : * If this is not the last buffer of the received packet, update
2247 : : * the pointer to the first mbuf at the NEXTP entry in the
2248 : : * sw_sc_ring and continue to parse the RX ring.
2249 : : */
2250 [ # # ]: 0 : if (!eop && next_rxe) {
2251 : 0 : rxm->next = next_rxe->mbuf;
2252 : 0 : next_sc_entry->fbuf = first_seg;
2253 : 0 : goto next_desc;
2254 : : }
2255 : :
2256 : : /* Initialize the first mbuf of the returned packet */
2257 : 0 : ixgbe_fill_cluster_head_buf(first_seg, &rxd, rxq, staterr);
2258 : :
2259 : : /*
2260 : : * Deal with the case, when HW CRC srip is disabled.
2261 : : * That can't happen when LRO is enabled, but still could
2262 : : * happen for scattered RX mode.
2263 : : */
2264 : 0 : first_seg->pkt_len -= rxq->crc_len;
2265 [ # # ]: 0 : if (unlikely(rxm->data_len <= rxq->crc_len)) {
2266 : : struct rte_mbuf *lp;
2267 : :
2268 [ # # ]: 0 : for (lp = first_seg; lp->next != rxm; lp = lp->next)
2269 : : ;
2270 : :
2271 : 0 : first_seg->nb_segs--;
2272 : 0 : lp->data_len -= rxq->crc_len - rxm->data_len;
2273 [ # # ]: 0 : lp->next = NULL;
2274 : : rte_pktmbuf_free_seg(rxm);
2275 : : } else
2276 : 0 : rxm->data_len -= rxq->crc_len;
2277 : :
2278 : : /* Prefetch data of first segment, if configured to do so. */
2279 : 0 : rte_packet_prefetch((char *)first_seg->buf_addr +
2280 : : first_seg->data_off);
2281 : :
2282 : : /*
2283 : : * Store the mbuf address into the next entry of the array
2284 : : * of returned packets.
2285 : : */
2286 : 0 : rx_pkts[nb_rx++] = first_seg;
2287 : : }
2288 : :
2289 : : /*
2290 : : * Record index of the next RX descriptor to probe.
2291 : : */
2292 : 0 : rxq->rx_tail = rx_id;
2293 : :
2294 : : /*
2295 : : * If the number of free RX descriptors is greater than the RX free
2296 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
2297 : : * register.
2298 : : * Update the RDT with the value of the last processed RX descriptor
2299 : : * minus 1, to guarantee that the RDT register is never equal to the
2300 : : * RDH register, which creates a "full" ring situation from the
2301 : : * hardware point of view...
2302 : : */
2303 [ # # # # ]: 0 : if (!bulk_alloc && nb_hold > rxq->rx_free_thresh) {
2304 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
2305 : : "nb_hold=%u nb_rx=%u",
2306 : : rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
2307 : :
2308 : : rte_wmb();
2309 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(rxq->rdt_reg_addr, prev_id);
2310 : : nb_hold = 0;
2311 : : }
2312 : :
2313 : 0 : rxq->nb_rx_hold = nb_hold;
2314 : 0 : return nb_rx;
2315 : : }
2316 : :
2317 : : uint16_t
2318 : 0 : ixgbe_recv_pkts_lro_single_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
2319 : : uint16_t nb_pkts)
2320 : : {
2321 : 0 : return ixgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, false);
2322 : : }
2323 : :
2324 : : uint16_t
2325 : 0 : ixgbe_recv_pkts_lro_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
2326 : : uint16_t nb_pkts)
2327 : : {
2328 : 0 : return ixgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, true);
2329 : : }
2330 : :
2331 : : /*********************************************************************
2332 : : *
2333 : : * Queue management functions
2334 : : *
2335 : : **********************************************************************/
2336 : :
2337 : : static int
2338 : 0 : ixgbe_tx_done_cleanup_full(struct ci_tx_queue *txq, uint32_t free_cnt)
2339 : : {
2340 : 0 : struct ci_tx_entry *swr_ring = txq->sw_ring;
2341 : : uint16_t i, tx_last, tx_id;
2342 : : uint16_t nb_tx_free_last;
2343 : : uint16_t nb_tx_to_clean;
2344 : : uint32_t pkt_cnt;
2345 : :
2346 : : /* Start free mbuf from the next of tx_tail */
2347 : 0 : tx_last = txq->tx_tail;
2348 : 0 : tx_id = swr_ring[tx_last].next_id;
2349 : :
2350 [ # # # # ]: 0 : if (txq->nb_tx_free == 0 && ixgbe_xmit_cleanup(txq))
2351 : : return 0;
2352 : :
2353 : 0 : nb_tx_to_clean = txq->nb_tx_free;
2354 : : nb_tx_free_last = txq->nb_tx_free;
2355 [ # # ]: 0 : if (!free_cnt)
2356 : 0 : free_cnt = txq->nb_tx_desc;
2357 : :
2358 : : /* Loop through swr_ring to count the amount of
2359 : : * freeable mubfs and packets.
2360 : : */
2361 [ # # ]: 0 : for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2362 : 0 : for (i = 0; i < nb_tx_to_clean &&
2363 [ # # # # ]: 0 : pkt_cnt < free_cnt &&
2364 : 0 : tx_id != tx_last; i++) {
2365 [ # # ]: 0 : if (swr_ring[tx_id].mbuf != NULL) {
2366 : : rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2367 : 0 : swr_ring[tx_id].mbuf = NULL;
2368 : :
2369 : : /*
2370 : : * last segment in the packet,
2371 : : * increment packet count
2372 : : */
2373 : 0 : pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
2374 : : }
2375 : :
2376 : 0 : tx_id = swr_ring[tx_id].next_id;
2377 : : }
2378 : :
2379 : 0 : if (txq->tx_rs_thresh > txq->nb_tx_desc -
2380 [ # # # # ]: 0 : txq->nb_tx_free || tx_id == tx_last)
2381 : : break;
2382 : :
2383 [ # # ]: 0 : if (pkt_cnt < free_cnt) {
2384 [ # # ]: 0 : if (ixgbe_xmit_cleanup(txq))
2385 : : break;
2386 : :
2387 : 0 : nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2388 : : nb_tx_free_last = txq->nb_tx_free;
2389 : : }
2390 : : }
2391 : :
2392 : 0 : return (int)pkt_cnt;
2393 : : }
2394 : :
2395 : : static int
2396 : 0 : ixgbe_tx_done_cleanup_simple(struct ci_tx_queue *txq,
2397 : : uint32_t free_cnt)
2398 : : {
2399 : : int i, n, cnt;
2400 : :
2401 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2402 : 0 : free_cnt = txq->nb_tx_desc;
2403 : :
2404 : 0 : cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
2405 : :
2406 [ # # ]: 0 : for (i = 0; i < cnt; i += n) {
2407 [ # # ]: 0 : if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
2408 : : break;
2409 : :
2410 : : n = ixgbe_tx_free_bufs(txq);
2411 : :
2412 [ # # ]: 0 : if (n == 0)
2413 : : break;
2414 : : }
2415 : :
2416 : 0 : return i;
2417 : : }
2418 : :
2419 : : static int
2420 : : ixgbe_tx_done_cleanup_vec(struct ci_tx_queue *txq __rte_unused,
2421 : : uint32_t free_cnt __rte_unused)
2422 : : {
2423 : : return -ENOTSUP;
2424 : : }
2425 : :
2426 : : int
2427 : 0 : ixgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt)
2428 : : {
2429 : : struct ci_tx_queue *txq = (struct ci_tx_queue *)tx_queue;
2430 [ # # ]: 0 : if (txq->offloads == 0 &&
2431 : : #ifdef RTE_LIB_SECURITY
2432 [ # # ]: 0 : !(txq->using_ipsec) &&
2433 : : #endif
2434 [ # # ]: 0 : txq->tx_rs_thresh >= RTE_PMD_IXGBE_TX_MAX_BURST) {
2435 [ # # # # ]: 0 : if (txq->tx_rs_thresh <= RTE_IXGBE_TX_MAX_FREE_BUF_SZ &&
2436 [ # # ]: 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128 &&
2437 : 0 : (rte_eal_process_type() != RTE_PROC_PRIMARY ||
2438 [ # # ]: 0 : txq->sw_ring_vec != NULL)) {
2439 : : return ixgbe_tx_done_cleanup_vec(txq, free_cnt);
2440 : : } else {
2441 : 0 : return ixgbe_tx_done_cleanup_simple(txq, free_cnt);
2442 : : }
2443 : : }
2444 : :
2445 : 0 : return ixgbe_tx_done_cleanup_full(txq, free_cnt);
2446 : : }
2447 : :
2448 : : static void __rte_cold
2449 : 0 : ixgbe_tx_free_swring(struct ci_tx_queue *txq)
2450 : : {
2451 [ # # ]: 0 : if (txq != NULL &&
2452 [ # # ]: 0 : txq->sw_ring != NULL)
2453 : 0 : rte_free(txq->sw_ring);
2454 : 0 : }
2455 : :
2456 : : static void __rte_cold
2457 : 0 : ixgbe_tx_queue_release(struct ci_tx_queue *txq)
2458 : : {
2459 [ # # # # ]: 0 : if (txq != NULL && txq->ops != NULL) {
2460 : 0 : ci_txq_release_all_mbufs(txq, false);
2461 : 0 : txq->ops->free_swring(txq);
2462 : 0 : rte_memzone_free(txq->mz);
2463 : 0 : rte_free(txq);
2464 : : }
2465 : 0 : }
2466 : :
2467 : : void __rte_cold
2468 : 0 : ixgbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2469 : : {
2470 : 0 : ixgbe_tx_queue_release(dev->data->tx_queues[qid]);
2471 : 0 : }
2472 : :
2473 : : /* (Re)set dynamic ixgbe_tx_queue fields to defaults */
2474 : : static void __rte_cold
2475 : 0 : ixgbe_reset_tx_queue(struct ci_tx_queue *txq)
2476 : : {
2477 : : static const union ixgbe_adv_tx_desc zeroed_desc = {{0}};
2478 : 0 : struct ci_tx_entry *txe = txq->sw_ring;
2479 : : uint16_t prev, i;
2480 : :
2481 : : /* Zero out HW ring memory */
2482 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2483 : 0 : txq->ixgbe_tx_ring[i] = zeroed_desc;
2484 : : }
2485 : :
2486 : : /* Initialize SW ring entries */
2487 : 0 : prev = (uint16_t) (txq->nb_tx_desc - 1);
2488 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2489 : 0 : volatile union ixgbe_adv_tx_desc *txd = &txq->ixgbe_tx_ring[i];
2490 : :
2491 : 0 : txd->wb.status = rte_cpu_to_le_32(IXGBE_TXD_STAT_DD);
2492 : 0 : txe[i].mbuf = NULL;
2493 : 0 : txe[i].last_id = i;
2494 : 0 : txe[prev].next_id = i;
2495 : : prev = i;
2496 : : }
2497 : :
2498 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
2499 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
2500 : :
2501 : 0 : txq->tx_tail = 0;
2502 : 0 : txq->nb_tx_used = 0;
2503 : : /*
2504 : : * Always allow 1 descriptor to be un-allocated to avoid
2505 : : * a H/W race condition
2506 : : */
2507 : 0 : txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2508 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2509 : 0 : txq->ctx_curr = 0;
2510 : 0 : memset(txq->ctx_cache, 0, IXGBE_CTX_NUM * sizeof(struct ixgbe_advctx_info));
2511 : 0 : }
2512 : :
2513 : : static const struct ixgbe_txq_ops def_txq_ops = {
2514 : : .free_swring = ixgbe_tx_free_swring,
2515 : : .reset = ixgbe_reset_tx_queue,
2516 : : };
2517 : :
2518 : : /* Takes an ethdev and a queue and sets up the tx function to be used based on
2519 : : * the queue parameters. Used in tx_queue_setup by primary process and then
2520 : : * in dev_init by secondary process when attaching to an existing ethdev.
2521 : : */
2522 : : void __rte_cold
2523 : 0 : ixgbe_set_tx_function(struct rte_eth_dev *dev, struct ci_tx_queue *txq)
2524 : : {
2525 : : /* Use a simple Tx queue (no offloads, no multi segs) if possible */
2526 [ # # ]: 0 : if ((txq->offloads == 0) &&
2527 : : #ifdef RTE_LIB_SECURITY
2528 [ # # ]: 0 : !(txq->using_ipsec) &&
2529 : : #endif
2530 [ # # ]: 0 : (txq->tx_rs_thresh >= RTE_PMD_IXGBE_TX_MAX_BURST)) {
2531 : 0 : PMD_INIT_LOG(DEBUG, "Using simple tx code path");
2532 : 0 : dev->tx_pkt_prepare = NULL;
2533 [ # # # # ]: 0 : if (txq->tx_rs_thresh <= RTE_IXGBE_TX_MAX_FREE_BUF_SZ &&
2534 [ # # ]: 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128 &&
2535 [ # # ]: 0 : (rte_eal_process_type() != RTE_PROC_PRIMARY ||
2536 : 0 : ixgbe_txq_vec_setup(txq) == 0)) {
2537 : 0 : PMD_INIT_LOG(DEBUG, "Vector tx enabled.");
2538 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
2539 : 0 : dev->recycle_tx_mbufs_reuse = ixgbe_recycle_tx_mbufs_reuse_vec;
2540 : : #endif
2541 : 0 : dev->tx_pkt_burst = ixgbe_xmit_pkts_vec;
2542 : : } else
2543 : 0 : dev->tx_pkt_burst = ixgbe_xmit_pkts_simple;
2544 : : } else {
2545 : 0 : PMD_INIT_LOG(DEBUG, "Using full-featured tx code path");
2546 : 0 : PMD_INIT_LOG(DEBUG,
2547 : : " - offloads = 0x%" PRIx64,
2548 : : txq->offloads);
2549 : 0 : PMD_INIT_LOG(DEBUG,
2550 : : " - tx_rs_thresh = %lu " "[RTE_PMD_IXGBE_TX_MAX_BURST=%lu]",
2551 : : (unsigned long)txq->tx_rs_thresh,
2552 : : (unsigned long)RTE_PMD_IXGBE_TX_MAX_BURST);
2553 : 0 : dev->tx_pkt_burst = ixgbe_xmit_pkts;
2554 : 0 : dev->tx_pkt_prepare = ixgbe_prep_pkts;
2555 : : }
2556 : 0 : }
2557 : :
2558 : : uint64_t
2559 : 0 : ixgbe_get_tx_queue_offloads(struct rte_eth_dev *dev)
2560 : : {
2561 : : RTE_SET_USED(dev);
2562 : :
2563 : 0 : return 0;
2564 : : }
2565 : :
2566 : : uint64_t
2567 : 0 : ixgbe_get_tx_port_offloads(struct rte_eth_dev *dev)
2568 : : {
2569 : : uint64_t tx_offload_capa;
2570 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2571 : :
2572 : : tx_offload_capa =
2573 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
2574 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
2575 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
2576 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
2577 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
2578 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
2579 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
2580 : :
2581 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
2582 : : hw->mac.type == ixgbe_mac_X540)
2583 : : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
2584 : :
2585 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
2586 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
2587 : : hw->mac.type == ixgbe_mac_X550EM_a)
2588 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
2589 : :
2590 : : #ifdef RTE_LIB_SECURITY
2591 [ # # ]: 0 : if (dev->security_ctx)
2592 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
2593 : : #endif
2594 : 0 : return tx_offload_capa;
2595 : : }
2596 : :
2597 : : int __rte_cold
2598 : 0 : ixgbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
2599 : : uint16_t queue_idx,
2600 : : uint16_t nb_desc,
2601 : : unsigned int socket_id,
2602 : : const struct rte_eth_txconf *tx_conf)
2603 : : {
2604 : : const struct rte_memzone *tz;
2605 : : struct ci_tx_queue *txq;
2606 : : struct ixgbe_hw *hw;
2607 : : uint16_t tx_rs_thresh, tx_free_thresh;
2608 : : uint64_t offloads;
2609 : :
2610 : 0 : PMD_INIT_FUNC_TRACE();
2611 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2612 : :
2613 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2614 : :
2615 : : /*
2616 : : * Validate number of transmit descriptors.
2617 : : * It must not exceed hardware maximum, and must be multiple
2618 : : * of IXGBE_ALIGN.
2619 : : */
2620 [ # # ]: 0 : if (nb_desc % IXGBE_TXD_ALIGN != 0 ||
2621 [ # # ]: 0 : (nb_desc > IXGBE_MAX_RING_DESC) ||
2622 : : (nb_desc < IXGBE_MIN_RING_DESC)) {
2623 : : return -EINVAL;
2624 : : }
2625 : :
2626 : : /*
2627 : : * The following two parameters control the setting of the RS bit on
2628 : : * transmit descriptors.
2629 : : * TX descriptors will have their RS bit set after txq->tx_rs_thresh
2630 : : * descriptors have been used.
2631 : : * The TX descriptor ring will be cleaned after txq->tx_free_thresh
2632 : : * descriptors are used or if the number of descriptors required
2633 : : * to transmit a packet is greater than the number of free TX
2634 : : * descriptors.
2635 : : * The following constraints must be satisfied:
2636 : : * tx_rs_thresh must be greater than 0.
2637 : : * tx_rs_thresh must be less than the size of the ring minus 2.
2638 : : * tx_rs_thresh must be less than or equal to tx_free_thresh.
2639 : : * tx_rs_thresh must be a divisor of the ring size.
2640 : : * tx_free_thresh must be greater than 0.
2641 : : * tx_free_thresh must be less than the size of the ring minus 3.
2642 : : * tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
2643 : : * One descriptor in the TX ring is used as a sentinel to avoid a
2644 : : * H/W race condition, hence the maximum threshold constraints.
2645 : : * When set to zero use default values.
2646 : : */
2647 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2648 : : tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2649 : : /* force tx_rs_thresh to adapt an aggressive tx_free_thresh */
2650 [ # # ]: 0 : tx_rs_thresh = (DEFAULT_TX_RS_THRESH + tx_free_thresh > nb_desc) ?
2651 : : nb_desc - tx_free_thresh : DEFAULT_TX_RS_THRESH;
2652 [ # # ]: 0 : if (tx_conf->tx_rs_thresh > 0)
2653 : : tx_rs_thresh = tx_conf->tx_rs_thresh;
2654 [ # # ]: 0 : if (tx_rs_thresh + tx_free_thresh > nb_desc) {
2655 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
2656 : : "exceed nb_desc. (tx_rs_thresh=%u "
2657 : : "tx_free_thresh=%u nb_desc=%u port = %d queue=%d)",
2658 : : (unsigned int)tx_rs_thresh,
2659 : : (unsigned int)tx_free_thresh,
2660 : : (unsigned int)nb_desc,
2661 : : (int)dev->data->port_id,
2662 : : (int)queue_idx);
2663 : 0 : return -(EINVAL);
2664 : : }
2665 [ # # ]: 0 : if (tx_rs_thresh >= (nb_desc - 2)) {
2666 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the number "
2667 : : "of TX descriptors minus 2. (tx_rs_thresh=%u "
2668 : : "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
2669 : : (int)dev->data->port_id, (int)queue_idx);
2670 : 0 : return -(EINVAL);
2671 : : }
2672 [ # # ]: 0 : if (tx_rs_thresh > DEFAULT_TX_RS_THRESH) {
2673 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less or equal than %u. "
2674 : : "(tx_rs_thresh=%u port=%d queue=%d)",
2675 : : DEFAULT_TX_RS_THRESH, (unsigned int)tx_rs_thresh,
2676 : : (int)dev->data->port_id, (int)queue_idx);
2677 : 0 : return -(EINVAL);
2678 : : }
2679 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
2680 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
2681 : : "tx_free_thresh must be less than the number of "
2682 : : "TX descriptors minus 3. (tx_free_thresh=%u "
2683 : : "port=%d queue=%d)",
2684 : : (unsigned int)tx_free_thresh,
2685 : : (int)dev->data->port_id, (int)queue_idx);
2686 : 0 : return -(EINVAL);
2687 : : }
2688 [ # # ]: 0 : if (tx_rs_thresh > tx_free_thresh) {
2689 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or equal to "
2690 : : "tx_free_thresh. (tx_free_thresh=%u "
2691 : : "tx_rs_thresh=%u port=%d queue=%d)",
2692 : : (unsigned int)tx_free_thresh,
2693 : : (unsigned int)tx_rs_thresh,
2694 : : (int)dev->data->port_id,
2695 : : (int)queue_idx);
2696 : 0 : return -(EINVAL);
2697 : : }
2698 [ # # ]: 0 : if ((nb_desc % tx_rs_thresh) != 0) {
2699 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
2700 : : "number of TX descriptors. (tx_rs_thresh=%u "
2701 : : "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
2702 : : (int)dev->data->port_id, (int)queue_idx);
2703 : 0 : return -(EINVAL);
2704 : : }
2705 : :
2706 : : /*
2707 : : * If rs_bit_thresh is greater than 1, then TX WTHRESH should be
2708 : : * set to 0. If WTHRESH is greater than zero, the RS bit is ignored
2709 : : * by the NIC and all descriptors are written back after the NIC
2710 : : * accumulates WTHRESH descriptors.
2711 : : */
2712 [ # # # # ]: 0 : if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
2713 : 0 : PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
2714 : : "tx_rs_thresh is greater than 1. (tx_rs_thresh=%u "
2715 : : "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
2716 : : (int)dev->data->port_id, (int)queue_idx);
2717 : 0 : return -(EINVAL);
2718 : : }
2719 : :
2720 : : /* Free memory prior to re-allocation if needed... */
2721 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
2722 : 0 : ixgbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
2723 : 0 : dev->data->tx_queues[queue_idx] = NULL;
2724 : : }
2725 : :
2726 : : /* First allocate the tx queue data structure */
2727 : 0 : txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct ci_tx_queue) +
2728 : : sizeof(struct ixgbe_advctx_info) * IXGBE_CTX_NUM,
2729 : : RTE_CACHE_LINE_SIZE, socket_id);
2730 [ # # ]: 0 : if (txq == NULL)
2731 : : return -ENOMEM;
2732 : 0 : txq->ctx_cache = RTE_PTR_ADD(txq, sizeof(struct ci_tx_queue));
2733 : :
2734 : : /*
2735 : : * Allocate TX ring hardware descriptors. A memzone large enough to
2736 : : * handle the maximum ring size is allocated in order to allow for
2737 : : * resizing in later calls to the queue setup function.
2738 : : */
2739 : 0 : tz = rte_eth_dma_zone_reserve(dev, "ixgbe_tx_ring", queue_idx,
2740 : : sizeof(union ixgbe_adv_tx_desc) * IXGBE_MAX_RING_DESC,
2741 : : IXGBE_ALIGN, socket_id);
2742 [ # # ]: 0 : if (tz == NULL) {
2743 : 0 : ixgbe_tx_queue_release(txq);
2744 : 0 : return -ENOMEM;
2745 : : }
2746 : :
2747 : 0 : txq->mz = tz;
2748 : 0 : txq->nb_tx_desc = nb_desc;
2749 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
2750 : 0 : txq->tx_free_thresh = tx_free_thresh;
2751 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
2752 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
2753 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
2754 : 0 : txq->queue_id = queue_idx;
2755 [ # # ]: 0 : txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2756 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2757 : 0 : txq->port_id = dev->data->port_id;
2758 : 0 : txq->offloads = offloads;
2759 : 0 : txq->ops = &def_txq_ops;
2760 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
2761 : : #ifdef RTE_LIB_SECURITY
2762 : 0 : txq->using_ipsec = !!(dev->data->dev_conf.txmode.offloads &
2763 : : RTE_ETH_TX_OFFLOAD_SECURITY);
2764 : : #endif
2765 : :
2766 : : /*
2767 : : * Modification to set VFTDT for virtual function if vf is detected
2768 : : */
2769 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599_vf ||
2770 [ # # ]: 0 : hw->mac.type == ixgbe_mac_E610_vf ||
2771 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540_vf ||
2772 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550_vf ||
2773 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x_vf ||
2774 : : hw->mac.type == ixgbe_mac_X550EM_a_vf)
2775 : 0 : txq->qtx_tail = IXGBE_PCI_REG_ADDR(hw, IXGBE_VFTDT(queue_idx));
2776 : : else
2777 : 0 : txq->qtx_tail = IXGBE_PCI_REG_ADDR(hw, IXGBE_TDT(txq->reg_idx));
2778 : :
2779 : 0 : txq->tx_ring_dma = tz->iova;
2780 : 0 : txq->ixgbe_tx_ring = (union ixgbe_adv_tx_desc *)tz->addr;
2781 : :
2782 : : /* Allocate software ring */
2783 : 0 : txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
2784 : : sizeof(struct ci_tx_entry) * nb_desc,
2785 : : RTE_CACHE_LINE_SIZE, socket_id);
2786 [ # # ]: 0 : if (txq->sw_ring == NULL) {
2787 : 0 : ixgbe_tx_queue_release(txq);
2788 : 0 : return -ENOMEM;
2789 : : }
2790 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
2791 : : txq->sw_ring, txq->ixgbe_tx_ring, txq->tx_ring_dma);
2792 : :
2793 : : /* set up vector or scalar TX function as appropriate */
2794 : 0 : ixgbe_set_tx_function(dev, txq);
2795 : :
2796 : 0 : txq->ops->reset(txq);
2797 : :
2798 : 0 : dev->data->tx_queues[queue_idx] = txq;
2799 : :
2800 : :
2801 : 0 : return 0;
2802 : : }
2803 : :
2804 : : /**
2805 : : * ixgbe_free_sc_cluster - free the not-yet-completed scattered cluster
2806 : : *
2807 : : * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
2808 : : * in the sw_rsc_ring is not set to NULL but rather points to the next
2809 : : * mbuf of this RSC aggregation (that has not been completed yet and still
2810 : : * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
2811 : : * will just free first "nb_segs" segments of the cluster explicitly by calling
2812 : : * an rte_pktmbuf_free_seg().
2813 : : *
2814 : : * @m scattered cluster head
2815 : : */
2816 : : static void __rte_cold
2817 : 0 : ixgbe_free_sc_cluster(struct rte_mbuf *m)
2818 : : {
2819 : 0 : uint16_t i, nb_segs = m->nb_segs;
2820 : : struct rte_mbuf *next_seg;
2821 : :
2822 [ # # ]: 0 : for (i = 0; i < nb_segs; i++) {
2823 : 0 : next_seg = m->next;
2824 : : rte_pktmbuf_free_seg(m);
2825 : : m = next_seg;
2826 : : }
2827 : 0 : }
2828 : :
2829 : : static void __rte_cold
2830 : 0 : ixgbe_rx_queue_release_mbufs(struct ixgbe_rx_queue *rxq)
2831 : : {
2832 : : unsigned i;
2833 : :
2834 : : /* SSE Vector driver has a different way of releasing mbufs. */
2835 [ # # ]: 0 : if (rxq->rx_using_sse) {
2836 : 0 : ixgbe_rx_queue_release_mbufs_vec(rxq);
2837 : 0 : return;
2838 : : }
2839 : :
2840 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
2841 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2842 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
2843 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2844 : 0 : rxq->sw_ring[i].mbuf = NULL;
2845 : : }
2846 : : }
2847 [ # # ]: 0 : if (rxq->rx_nb_avail) {
2848 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; ++i) {
2849 : : struct rte_mbuf *mb;
2850 : :
2851 [ # # ]: 0 : mb = rxq->rx_stage[rxq->rx_next_avail + i];
2852 : : rte_pktmbuf_free_seg(mb);
2853 : : }
2854 : 0 : rxq->rx_nb_avail = 0;
2855 : : }
2856 : : }
2857 : :
2858 [ # # ]: 0 : if (rxq->sw_sc_ring)
2859 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++)
2860 [ # # ]: 0 : if (rxq->sw_sc_ring[i].fbuf) {
2861 : 0 : ixgbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
2862 : 0 : rxq->sw_sc_ring[i].fbuf = NULL;
2863 : : }
2864 : : }
2865 : :
2866 : : static void __rte_cold
2867 : 0 : ixgbe_rx_queue_release(struct ixgbe_rx_queue *rxq)
2868 : : {
2869 [ # # ]: 0 : if (rxq != NULL) {
2870 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
2871 : 0 : rte_free(rxq->sw_ring);
2872 : 0 : rte_free(rxq->sw_sc_ring);
2873 : 0 : rte_memzone_free(rxq->mz);
2874 : 0 : rte_free(rxq);
2875 : : }
2876 : 0 : }
2877 : :
2878 : : void __rte_cold
2879 : 0 : ixgbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2880 : : {
2881 : 0 : ixgbe_rx_queue_release(dev->data->rx_queues[qid]);
2882 : 0 : }
2883 : :
2884 : : /*
2885 : : * Check if Rx Burst Bulk Alloc function can be used.
2886 : : * Return
2887 : : * 0: the preconditions are satisfied and the bulk allocation function
2888 : : * can be used.
2889 : : * -EINVAL: the preconditions are NOT satisfied and the default Rx burst
2890 : : * function must be used.
2891 : : */
2892 : : static inline int __rte_cold
2893 : 0 : check_rx_burst_bulk_alloc_preconditions(struct ixgbe_rx_queue *rxq)
2894 : : {
2895 : : int ret = 0;
2896 : :
2897 : : /*
2898 : : * Make sure the following pre-conditions are satisfied:
2899 : : * rxq->rx_free_thresh >= RTE_PMD_IXGBE_RX_MAX_BURST
2900 : : * rxq->rx_free_thresh < rxq->nb_rx_desc
2901 : : * (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
2902 : : * Scattered packets are not supported. This should be checked
2903 : : * outside of this function.
2904 : : */
2905 [ # # ]: 0 : if (!(rxq->rx_free_thresh >= RTE_PMD_IXGBE_RX_MAX_BURST)) {
2906 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2907 : : "rxq->rx_free_thresh=%d, "
2908 : : "RTE_PMD_IXGBE_RX_MAX_BURST=%d",
2909 : : rxq->rx_free_thresh, RTE_PMD_IXGBE_RX_MAX_BURST);
2910 : : ret = -EINVAL;
2911 [ # # ]: 0 : } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
2912 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2913 : : "rxq->rx_free_thresh=%d, "
2914 : : "rxq->nb_rx_desc=%d",
2915 : : rxq->rx_free_thresh, rxq->nb_rx_desc);
2916 : : ret = -EINVAL;
2917 [ # # ]: 0 : } else if (!((rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)) {
2918 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2919 : : "rxq->nb_rx_desc=%d, "
2920 : : "rxq->rx_free_thresh=%d",
2921 : : rxq->nb_rx_desc, rxq->rx_free_thresh);
2922 : : ret = -EINVAL;
2923 : : }
2924 : :
2925 : 0 : return ret;
2926 : : }
2927 : :
2928 : : /* Reset dynamic ixgbe_rx_queue fields back to defaults */
2929 : : static void __rte_cold
2930 : 0 : ixgbe_reset_rx_queue(struct ixgbe_adapter *adapter, struct ixgbe_rx_queue *rxq)
2931 : : {
2932 : : static const union ixgbe_adv_rx_desc zeroed_desc = {{0}};
2933 : : unsigned i;
2934 : 0 : uint16_t len = rxq->nb_rx_desc;
2935 : :
2936 : : /*
2937 : : * By default, the Rx queue setup function allocates enough memory for
2938 : : * IXGBE_MAX_RING_DESC. The Rx Burst bulk allocation function requires
2939 : : * extra memory at the end of the descriptor ring to be zero'd out.
2940 : : */
2941 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
2942 : : /* zero out extra memory */
2943 : 0 : len += RTE_PMD_IXGBE_RX_MAX_BURST;
2944 : :
2945 : : /*
2946 : : * Zero out HW ring memory. Zero out extra memory at the end of
2947 : : * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
2948 : : * reads extra memory as zeros.
2949 : : */
2950 [ # # ]: 0 : for (i = 0; i < len; i++) {
2951 : 0 : rxq->rx_ring[i] = zeroed_desc;
2952 : : }
2953 : :
2954 : : /*
2955 : : * initialize extra software ring entries. Space for these extra
2956 : : * entries is always allocated
2957 : : */
2958 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2959 [ # # ]: 0 : for (i = rxq->nb_rx_desc; i < len; ++i) {
2960 : 0 : rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
2961 : : }
2962 : :
2963 : 0 : rxq->rx_nb_avail = 0;
2964 : 0 : rxq->rx_next_avail = 0;
2965 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2966 : 0 : rxq->rx_tail = 0;
2967 : 0 : rxq->nb_rx_hold = 0;
2968 : :
2969 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
2970 : :
2971 : 0 : rxq->pkt_first_seg = NULL;
2972 : 0 : rxq->pkt_last_seg = NULL;
2973 : :
2974 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
2975 : 0 : rxq->rxrearm_start = 0;
2976 : 0 : rxq->rxrearm_nb = 0;
2977 : : #endif
2978 : 0 : }
2979 : :
2980 : : static int
2981 : : ixgbe_is_vf(struct rte_eth_dev *dev)
2982 : : {
2983 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2984 : :
2985 [ # # ]: 0 : switch (hw->mac.type) {
2986 : : case ixgbe_mac_82599_vf:
2987 : : case ixgbe_mac_X540_vf:
2988 : : case ixgbe_mac_X550_vf:
2989 : : case ixgbe_mac_X550EM_x_vf:
2990 : : case ixgbe_mac_X550EM_a_vf:
2991 : : case ixgbe_mac_E610_vf:
2992 : : return 1;
2993 : : default:
2994 : : return 0;
2995 : : }
2996 : : }
2997 : :
2998 : : uint64_t
2999 : 0 : ixgbe_get_rx_queue_offloads(struct rte_eth_dev *dev)
3000 : : {
3001 : : uint64_t offloads = 0;
3002 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3003 : :
3004 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB)
3005 : : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3006 : :
3007 : 0 : return offloads;
3008 : : }
3009 : :
3010 : : uint64_t
3011 : 0 : ixgbe_get_rx_port_offloads(struct rte_eth_dev *dev)
3012 : : {
3013 : : uint64_t offloads;
3014 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3015 : :
3016 : : offloads = RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3017 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3018 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3019 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3020 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3021 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3022 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3023 : :
3024 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
3025 : : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3026 : :
3027 : : if (ixgbe_is_vf(dev) == 0)
3028 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
3029 : :
3030 : : /*
3031 : : * RSC is only supported by 82599 and x540 PF devices in a non-SR-IOV
3032 : : * mode.
3033 : : */
3034 [ # # ]: 0 : if ((hw->mac.type == ixgbe_mac_82599EB ||
3035 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540 ||
3036 : 0 : hw->mac.type == ixgbe_mac_X550) &&
3037 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active)
3038 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
3039 : :
3040 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
3041 : : hw->mac.type == ixgbe_mac_X540)
3042 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
3043 : :
3044 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
3045 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
3046 : : hw->mac.type == ixgbe_mac_X550EM_a)
3047 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM;
3048 : :
3049 : : #ifdef RTE_LIB_SECURITY
3050 [ # # ]: 0 : if (dev->security_ctx)
3051 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_SECURITY;
3052 : : #endif
3053 : :
3054 : 0 : return offloads;
3055 : : }
3056 : :
3057 : : int __rte_cold
3058 : 0 : ixgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
3059 : : uint16_t queue_idx,
3060 : : uint16_t nb_desc,
3061 : : unsigned int socket_id,
3062 : : const struct rte_eth_rxconf *rx_conf,
3063 : : struct rte_mempool *mp)
3064 : : {
3065 : : const struct rte_memzone *rz;
3066 : : struct ixgbe_rx_queue *rxq;
3067 : : struct ixgbe_hw *hw;
3068 : : uint16_t len;
3069 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
3070 : : uint64_t offloads;
3071 : :
3072 : 0 : PMD_INIT_FUNC_TRACE();
3073 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3074 : :
3075 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
3076 : :
3077 : : /*
3078 : : * Validate number of receive descriptors.
3079 : : * It must not exceed hardware maximum, and must be multiple
3080 : : * of IXGBE_ALIGN.
3081 : : */
3082 [ # # ]: 0 : if (nb_desc % IXGBE_RXD_ALIGN != 0 ||
3083 [ # # ]: 0 : (nb_desc > IXGBE_MAX_RING_DESC) ||
3084 : : (nb_desc < IXGBE_MIN_RING_DESC)) {
3085 : : return -EINVAL;
3086 : : }
3087 : :
3088 : : /* Free memory prior to re-allocation if needed... */
3089 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
3090 : 0 : ixgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
3091 : 0 : dev->data->rx_queues[queue_idx] = NULL;
3092 : : }
3093 : :
3094 : : /* First allocate the rx queue data structure */
3095 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct ixgbe_rx_queue),
3096 : : RTE_CACHE_LINE_SIZE, socket_id);
3097 [ # # ]: 0 : if (rxq == NULL)
3098 : : return -ENOMEM;
3099 : 0 : rxq->mb_pool = mp;
3100 : 0 : rxq->nb_rx_desc = nb_desc;
3101 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
3102 : 0 : rxq->queue_id = queue_idx;
3103 [ # # ]: 0 : rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
3104 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
3105 : 0 : rxq->port_id = dev->data->port_id;
3106 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
3107 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
3108 : : else
3109 : 0 : rxq->crc_len = 0;
3110 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
3111 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
3112 : 0 : rxq->offloads = offloads;
3113 : :
3114 : : /*
3115 : : * The packet type in RX descriptor is different for different NICs.
3116 : : * Some bits are used for x550 but reserved for other NICS.
3117 : : * So set different masks for different NICs.
3118 : : */
3119 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
3120 : : hw->mac.type == ixgbe_mac_X550EM_x ||
3121 : : hw->mac.type == ixgbe_mac_X550EM_a ||
3122 : : hw->mac.type == ixgbe_mac_X550_vf ||
3123 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x_vf ||
3124 : : hw->mac.type == ixgbe_mac_X550EM_a_vf)
3125 : 0 : rxq->pkt_type_mask = IXGBE_PACKET_TYPE_MASK_X550;
3126 : : else
3127 : 0 : rxq->pkt_type_mask = IXGBE_PACKET_TYPE_MASK_82599;
3128 : :
3129 : : /*
3130 : : * 82599 errata, UDP frames with a 0 checksum can be marked as checksum
3131 : : * errors.
3132 : : */
3133 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB)
3134 : 0 : rxq->rx_udp_csum_zero_err = 1;
3135 : :
3136 : : /*
3137 : : * Allocate RX ring hardware descriptors. A memzone large enough to
3138 : : * handle the maximum ring size is allocated in order to allow for
3139 : : * resizing in later calls to the queue setup function.
3140 : : */
3141 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
3142 : : RX_RING_SZ, IXGBE_ALIGN, socket_id);
3143 [ # # ]: 0 : if (rz == NULL) {
3144 : 0 : ixgbe_rx_queue_release(rxq);
3145 : 0 : return -ENOMEM;
3146 : : }
3147 : :
3148 : 0 : rxq->mz = rz;
3149 : : /*
3150 : : * Zero init all the descriptors in the ring.
3151 : : */
3152 [ # # ]: 0 : memset(rz->addr, 0, RX_RING_SZ);
3153 : :
3154 : : /*
3155 : : * Modified to setup VFRDT for Virtual Function
3156 : : */
3157 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599_vf ||
3158 [ # # ]: 0 : hw->mac.type == ixgbe_mac_E610_vf ||
3159 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540_vf ||
3160 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550_vf ||
3161 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x_vf ||
3162 : : hw->mac.type == ixgbe_mac_X550EM_a_vf) {
3163 : 0 : rxq->rdt_reg_addr =
3164 : 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_VFRDT(queue_idx));
3165 : 0 : rxq->rdh_reg_addr =
3166 : 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_VFRDH(queue_idx));
3167 : : } else {
3168 : 0 : rxq->rdt_reg_addr =
3169 [ # # ]: 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_RDT(rxq->reg_idx));
3170 : 0 : rxq->rdh_reg_addr =
3171 [ # # ]: 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_RDH(rxq->reg_idx));
3172 : : }
3173 : :
3174 : 0 : rxq->rx_ring_phys_addr = rz->iova;
3175 : 0 : rxq->rx_ring = (union ixgbe_adv_rx_desc *) rz->addr;
3176 : :
3177 : : /*
3178 : : * Certain constraints must be met in order to use the bulk buffer
3179 : : * allocation Rx burst function. If any of Rx queues doesn't meet them
3180 : : * the feature should be disabled for the whole port.
3181 : : */
3182 [ # # ]: 0 : if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
3183 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Rx Bulk Alloc "
3184 : : "preconditions - canceling the feature for "
3185 : : "the whole port[%d]",
3186 : : rxq->queue_id, rxq->port_id);
3187 : 0 : adapter->rx_bulk_alloc_allowed = false;
3188 : : }
3189 : :
3190 : : /*
3191 : : * Allocate software ring. Allow for space at the end of the
3192 : : * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
3193 : : * function does not access an invalid memory region.
3194 : : */
3195 : : len = nb_desc;
3196 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
3197 : 0 : len += RTE_PMD_IXGBE_RX_MAX_BURST;
3198 : :
3199 : 0 : rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
3200 : : sizeof(struct ixgbe_rx_entry) * len,
3201 : : RTE_CACHE_LINE_SIZE, socket_id);
3202 [ # # ]: 0 : if (!rxq->sw_ring) {
3203 : 0 : ixgbe_rx_queue_release(rxq);
3204 : 0 : return -ENOMEM;
3205 : : }
3206 : :
3207 : : /*
3208 : : * Always allocate even if it's not going to be needed in order to
3209 : : * simplify the code.
3210 : : *
3211 : : * This ring is used in LRO and Scattered Rx cases and Scattered Rx may
3212 : : * be requested in ixgbe_dev_rx_init(), which is called later from
3213 : : * dev_start() flow.
3214 : : */
3215 : 0 : rxq->sw_sc_ring =
3216 : 0 : rte_zmalloc_socket("rxq->sw_sc_ring",
3217 : : sizeof(struct ixgbe_scattered_rx_entry) * len,
3218 : : RTE_CACHE_LINE_SIZE, socket_id);
3219 [ # # ]: 0 : if (!rxq->sw_sc_ring) {
3220 : 0 : ixgbe_rx_queue_release(rxq);
3221 : 0 : return -ENOMEM;
3222 : : }
3223 : :
3224 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p sw_sc_ring=%p hw_ring=%p "
3225 : : "dma_addr=0x%"PRIx64,
3226 : : rxq->sw_ring, rxq->sw_sc_ring, rxq->rx_ring,
3227 : : rxq->rx_ring_phys_addr);
3228 : :
3229 [ # # ]: 0 : if (!rte_is_power_of_2(nb_desc)) {
3230 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
3231 : : "preconditions - canceling the feature for "
3232 : : "the whole port[%d]",
3233 : : rxq->queue_id, rxq->port_id);
3234 : 0 : adapter->rx_vec_allowed = false;
3235 : : } else
3236 : 0 : ixgbe_rxq_vec_setup(rxq);
3237 : :
3238 : 0 : dev->data->rx_queues[queue_idx] = rxq;
3239 : :
3240 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
3241 : :
3242 : 0 : return 0;
3243 : : }
3244 : :
3245 : : uint32_t
3246 : 0 : ixgbe_dev_rx_queue_count(void *rx_queue)
3247 : : {
3248 : : #define IXGBE_RXQ_SCAN_INTERVAL 4
3249 : : volatile union ixgbe_adv_rx_desc *rxdp;
3250 : : struct ixgbe_rx_queue *rxq;
3251 : : uint32_t desc = 0;
3252 : :
3253 : : rxq = rx_queue;
3254 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail]);
3255 : :
3256 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
3257 [ # # ]: 0 : (rxdp->wb.upper.status_error &
3258 : : rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD))) {
3259 : 0 : desc += IXGBE_RXQ_SCAN_INTERVAL;
3260 : 0 : rxdp += IXGBE_RXQ_SCAN_INTERVAL;
3261 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
3262 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
3263 : 0 : desc - rxq->nb_rx_desc]);
3264 : : }
3265 : :
3266 : 0 : return desc;
3267 : : }
3268 : :
3269 : : int
3270 : 0 : ixgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
3271 : : {
3272 : : struct ixgbe_rx_queue *rxq = rx_queue;
3273 : : volatile uint32_t *status;
3274 : : uint32_t nb_hold, desc;
3275 : :
3276 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
3277 : : return -EINVAL;
3278 : :
3279 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
3280 [ # # ]: 0 : if (rxq->rx_using_sse)
3281 : 0 : nb_hold = rxq->rxrearm_nb;
3282 : : else
3283 : : #endif
3284 : 0 : nb_hold = rxq->nb_rx_hold;
3285 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - nb_hold)
3286 : : return RTE_ETH_RX_DESC_UNAVAIL;
3287 : :
3288 : 0 : desc = rxq->rx_tail + offset;
3289 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
3290 : 0 : desc -= rxq->nb_rx_desc;
3291 : :
3292 : 0 : status = &rxq->rx_ring[desc].wb.upper.status_error;
3293 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD))
3294 : 0 : return RTE_ETH_RX_DESC_DONE;
3295 : :
3296 : : return RTE_ETH_RX_DESC_AVAIL;
3297 : : }
3298 : :
3299 : : int
3300 : 0 : ixgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
3301 : : {
3302 : : struct ci_tx_queue *txq = tx_queue;
3303 : : volatile uint32_t *status;
3304 : : uint32_t desc;
3305 : :
3306 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
3307 : : return -EINVAL;
3308 : :
3309 : 0 : desc = txq->tx_tail + offset;
3310 : : /* go to next desc that has the RS bit */
3311 : 0 : desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
3312 : : txq->tx_rs_thresh;
3313 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
3314 : 0 : desc -= txq->nb_tx_desc;
3315 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
3316 : 0 : desc -= txq->nb_tx_desc;
3317 : : }
3318 : :
3319 : 0 : status = &txq->ixgbe_tx_ring[desc].wb.status;
3320 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(IXGBE_ADVTXD_STAT_DD))
3321 : 0 : return RTE_ETH_TX_DESC_DONE;
3322 : :
3323 : : return RTE_ETH_TX_DESC_FULL;
3324 : : }
3325 : :
3326 : : /*
3327 : : * Set up link loopback for X540/X550 mode Tx->Rx.
3328 : : */
3329 : : static inline void __rte_cold
3330 : 0 : ixgbe_setup_loopback_link_x540_x550(struct ixgbe_hw *hw, bool enable)
3331 : : {
3332 : : uint32_t macc;
3333 : 0 : PMD_INIT_FUNC_TRACE();
3334 : :
3335 : 0 : u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
3336 : :
3337 : 0 : hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
3338 : : IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
3339 : 0 : macc = IXGBE_READ_REG(hw, IXGBE_MACC);
3340 : :
3341 [ # # ]: 0 : if (enable) {
3342 : : /* datasheet 15.2.1: disable AUTONEG (PHY Bit 7.0.C) */
3343 : 0 : autoneg_reg |= IXGBE_MII_AUTONEG_ENABLE;
3344 : : /* datasheet 15.2.1: MACC.FLU = 1 (force link up) */
3345 : 0 : macc |= IXGBE_MACC_FLU;
3346 : : } else {
3347 : 0 : autoneg_reg &= ~IXGBE_MII_AUTONEG_ENABLE;
3348 : 0 : macc &= ~IXGBE_MACC_FLU;
3349 : : }
3350 : :
3351 : 0 : hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
3352 : : IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
3353 : :
3354 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MACC, macc);
3355 : 0 : }
3356 : :
3357 : : void __rte_cold
3358 : 0 : ixgbe_dev_clear_queues(struct rte_eth_dev *dev)
3359 : : {
3360 : : unsigned i;
3361 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
3362 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3363 : :
3364 : 0 : PMD_INIT_FUNC_TRACE();
3365 : :
3366 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3367 : 0 : struct ci_tx_queue *txq = dev->data->tx_queues[i];
3368 : :
3369 [ # # ]: 0 : if (txq != NULL) {
3370 : 0 : ci_txq_release_all_mbufs(txq, false);
3371 : 0 : txq->ops->reset(txq);
3372 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3373 : : }
3374 : : }
3375 : :
3376 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3377 : 0 : struct ixgbe_rx_queue *rxq = dev->data->rx_queues[i];
3378 : :
3379 [ # # ]: 0 : if (rxq != NULL) {
3380 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
3381 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
3382 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3383 : : }
3384 : : }
3385 : : /* If loopback mode was enabled, reconfigure the link accordingly */
3386 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
3387 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X540 ||
3388 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
3389 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
3390 : : hw->mac.type == ixgbe_mac_X550EM_a)
3391 : 0 : ixgbe_setup_loopback_link_x540_x550(hw, false);
3392 : : }
3393 : 0 : }
3394 : :
3395 : : void
3396 : 0 : ixgbe_dev_free_queues(struct rte_eth_dev *dev)
3397 : : {
3398 : : unsigned i;
3399 : :
3400 : 0 : PMD_INIT_FUNC_TRACE();
3401 : :
3402 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3403 : 0 : ixgbe_dev_rx_queue_release(dev, i);
3404 : 0 : dev->data->rx_queues[i] = NULL;
3405 : : }
3406 : 0 : dev->data->nb_rx_queues = 0;
3407 : :
3408 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3409 : 0 : ixgbe_dev_tx_queue_release(dev, i);
3410 : 0 : dev->data->tx_queues[i] = NULL;
3411 : : }
3412 : 0 : dev->data->nb_tx_queues = 0;
3413 : 0 : }
3414 : :
3415 : : /*********************************************************************
3416 : : *
3417 : : * Device RX/TX init functions
3418 : : *
3419 : : **********************************************************************/
3420 : :
3421 : : /**
3422 : : * Receive Side Scaling (RSS)
3423 : : * See section 7.1.2.8 in the following document:
3424 : : * "Intel 82599 10 GbE Controller Datasheet" - Revision 2.1 October 2009
3425 : : *
3426 : : * Principles:
3427 : : * The source and destination IP addresses of the IP header and the source
3428 : : * and destination ports of TCP/UDP headers, if any, of received packets are
3429 : : * hashed against a configurable random key to compute a 32-bit RSS hash result.
3430 : : * The seven (7) LSBs of the 32-bit hash result are used as an index into a
3431 : : * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
3432 : : * RSS output index which is used as the RX queue index where to store the
3433 : : * received packets.
3434 : : * The following output is supplied in the RX write-back descriptor:
3435 : : * - 32-bit result of the Microsoft RSS hash function,
3436 : : * - 4-bit RSS type field.
3437 : : */
3438 : :
3439 : : /*
3440 : : * RSS random key supplied in section 7.1.2.8.3 of the Intel 82599 datasheet.
3441 : : * Used as the default key.
3442 : : */
3443 : : static uint8_t rss_intel_key[40] = {
3444 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
3445 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
3446 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
3447 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
3448 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
3449 : : };
3450 : :
3451 : : /*
3452 : : * This function removes the rss configuration in the mrqe field of MRQC
3453 : : * register and tries to maintain other configurations in the field, such
3454 : : * DCB and Virtualization.
3455 : : *
3456 : : * The MRQC register supplied in section 8.2.3.7.12 of the Intel 82599
3457 : : * datasheet. From the datasheet, we know that the mrqe field is an enum. So,
3458 : : * masking the mrqe field with '~IXGBE_MRQC_RSSEN' may not completely disable
3459 : : * rss configuration. For example, the value of mrqe is equal to 0101b when DCB
3460 : : * and RSS with 4 TCs configured, however 'mrqe &= ~0x01' is equal to 0100b
3461 : : * which corresponds to DCB and RSS with 8 TCs.
3462 : : */
3463 : : static void
3464 : 0 : ixgbe_mrqc_rss_remove(struct ixgbe_hw *hw)
3465 : : {
3466 : : uint32_t mrqc;
3467 : : uint32_t mrqc_reg;
3468 : : uint32_t mrqe_val;
3469 : :
3470 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3471 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3472 : 0 : mrqe_val = mrqc & IXGBE_MRQC_MRQE_MASK;
3473 : :
3474 [ # # # # : 0 : switch (mrqe_val) {
# # ]
3475 : 0 : case IXGBE_MRQC_RSSEN:
3476 : : /* Completely disable rss */
3477 : : mrqe_val = 0;
3478 : 0 : break;
3479 : 0 : case IXGBE_MRQC_RTRSS8TCEN:
3480 : : mrqe_val = IXGBE_MRQC_RT8TCEN;
3481 : 0 : break;
3482 : 0 : case IXGBE_MRQC_RTRSS4TCEN:
3483 : : mrqe_val = IXGBE_MRQC_RT4TCEN;
3484 : 0 : break;
3485 : 0 : case IXGBE_MRQC_VMDQRSS64EN:
3486 : : mrqe_val = IXGBE_MRQC_VMDQEN;
3487 : 0 : break;
3488 : 0 : case IXGBE_MRQC_VMDQRSS32EN:
3489 : 0 : PMD_DRV_LOG(WARNING, "There is no regression for virtualization"
3490 : : " and RSS with 32 pools among the MRQE configurations"
3491 : : " after removing RSS, and left it unchanged.");
3492 : 0 : break;
3493 : : default:
3494 : : /* No rss configured, leave it as it is */
3495 : : break;
3496 : : }
3497 : 0 : mrqc = (mrqc & ~IXGBE_MRQC_MRQE_MASK) | mrqe_val;
3498 : 0 : IXGBE_WRITE_REG(hw, mrqc_reg, mrqc);
3499 : 0 : }
3500 : :
3501 : : static void
3502 : : ixgbe_rss_disable(struct rte_eth_dev *dev)
3503 : : {
3504 : : struct ixgbe_hw *hw;
3505 : :
3506 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3507 : : /* Remove the rss configuration and maintain the other configurations */
3508 : 0 : ixgbe_mrqc_rss_remove(hw);
3509 : 0 : }
3510 : :
3511 : : /*
3512 : : * This function checks whether the rss is enabled or not by comparing the mrqe
3513 : : * field with some RSS related enums and also considers the configurations for
3514 : : * DCB + RSS and Virtualization + RSS. It is necessary for getting the correct
3515 : : * rss hash configurations from the RSS Field Enable field of MRQC register
3516 : : * when both RSS and DCB/VMDQ are used.
3517 : : */
3518 : : static bool
3519 : 0 : ixgbe_rss_enabled(struct ixgbe_hw *hw)
3520 : : {
3521 : : uint32_t mrqc;
3522 : : uint32_t mrqc_reg;
3523 : : uint32_t mrqe_val;
3524 : :
3525 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3526 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3527 : 0 : mrqe_val = mrqc & IXGBE_MRQC_MRQE_MASK;
3528 : :
3529 : 0 : if (mrqe_val == IXGBE_MRQC_RSSEN ||
3530 [ # # ]: 0 : mrqe_val == IXGBE_MRQC_RTRSS8TCEN ||
3531 : 0 : mrqe_val == IXGBE_MRQC_RTRSS4TCEN ||
3532 [ # # # # ]: 0 : mrqe_val == IXGBE_MRQC_VMDQRSS64EN ||
3533 : : mrqe_val == IXGBE_MRQC_VMDQRSS32EN)
3534 : 0 : return true;
3535 : :
3536 : : return false;
3537 : : }
3538 : :
3539 : : static void
3540 : 0 : ixgbe_hw_rss_hash_set(struct ixgbe_hw *hw, struct rte_eth_rss_conf *rss_conf)
3541 : : {
3542 : : uint8_t *hash_key;
3543 : : uint32_t mrqc;
3544 : : uint32_t rss_key;
3545 : : uint64_t rss_hf;
3546 : : uint16_t i;
3547 : : uint32_t mrqc_reg;
3548 : : uint32_t rssrk_reg;
3549 : :
3550 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3551 : 0 : rssrk_reg = ixgbe_rssrk_reg_get(hw->mac.type, 0);
3552 : :
3553 : 0 : hash_key = rss_conf->rss_key;
3554 [ # # ]: 0 : if (hash_key != NULL) {
3555 : : /* Fill in RSS hash key */
3556 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3557 : 0 : rss_key = hash_key[(i * 4)];
3558 : 0 : rss_key |= hash_key[(i * 4) + 1] << 8;
3559 : 0 : rss_key |= hash_key[(i * 4) + 2] << 16;
3560 : 0 : rss_key |= hash_key[(i * 4) + 3] << 24;
3561 : 0 : IXGBE_WRITE_REG_ARRAY(hw, rssrk_reg, i, rss_key);
3562 : : }
3563 : : }
3564 : :
3565 : : /* Set configured hashing protocols in MRQC register */
3566 : 0 : rss_hf = rss_conf->rss_hf;
3567 : : mrqc = IXGBE_MRQC_RSSEN; /* Enable RSS */
3568 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
3569 : : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4;
3570 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
3571 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_TCP;
3572 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
3573 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6;
3574 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_EX)
3575 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX;
3576 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
3577 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
3578 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
3579 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP;
3580 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
3581 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3582 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
3583 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3584 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
3585 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
3586 : 0 : IXGBE_WRITE_REG(hw, mrqc_reg, mrqc);
3587 : 0 : }
3588 : :
3589 : : int
3590 : 0 : ixgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
3591 : : struct rte_eth_rss_conf *rss_conf)
3592 : : {
3593 : : struct ixgbe_hw *hw;
3594 : : uint64_t rss_hf;
3595 : :
3596 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3597 : :
3598 [ # # ]: 0 : if (!ixgbe_rss_update_sp(hw->mac.type)) {
3599 : 0 : PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
3600 : : "NIC.");
3601 : 0 : return -ENOTSUP;
3602 : : }
3603 : :
3604 : : /*
3605 : : * Excerpt from section 7.1.2.8 Receive-Side Scaling (RSS):
3606 : : * "RSS enabling cannot be done dynamically while it must be
3607 : : * preceded by a software reset"
3608 : : * Before changing anything, first check that the update RSS operation
3609 : : * does not attempt to disable RSS, if RSS was enabled at
3610 : : * initialization time, or does not attempt to enable RSS, if RSS was
3611 : : * disabled at initialization time.
3612 : : */
3613 : 0 : rss_hf = rss_conf->rss_hf & IXGBE_RSS_OFFLOAD_ALL;
3614 [ # # ]: 0 : if (!ixgbe_rss_enabled(hw)) { /* RSS disabled */
3615 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
3616 : : return -(EINVAL);
3617 : 0 : return 0; /* Nothing to do */
3618 : : }
3619 : : /* RSS enabled */
3620 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
3621 : : return -(EINVAL);
3622 : 0 : ixgbe_hw_rss_hash_set(hw, rss_conf);
3623 : 0 : return 0;
3624 : : }
3625 : :
3626 : : int
3627 : 0 : ixgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
3628 : : struct rte_eth_rss_conf *rss_conf)
3629 : : {
3630 : : struct ixgbe_hw *hw;
3631 : : uint8_t *hash_key;
3632 : : uint32_t mrqc;
3633 : : uint32_t rss_key;
3634 : : uint64_t rss_hf;
3635 : : uint16_t i;
3636 : : uint32_t mrqc_reg;
3637 : : uint32_t rssrk_reg;
3638 : :
3639 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3640 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3641 : 0 : rssrk_reg = ixgbe_rssrk_reg_get(hw->mac.type, 0);
3642 : 0 : hash_key = rss_conf->rss_key;
3643 [ # # ]: 0 : if (hash_key != NULL) {
3644 : : /* Return RSS hash key */
3645 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3646 : 0 : rss_key = IXGBE_READ_REG_ARRAY(hw, rssrk_reg, i);
3647 : 0 : hash_key[(i * 4)] = rss_key & 0x000000FF;
3648 : 0 : hash_key[(i * 4) + 1] = (rss_key >> 8) & 0x000000FF;
3649 : 0 : hash_key[(i * 4) + 2] = (rss_key >> 16) & 0x000000FF;
3650 : 0 : hash_key[(i * 4) + 3] = (rss_key >> 24) & 0x000000FF;
3651 : : }
3652 : : }
3653 : :
3654 [ # # ]: 0 : if (!ixgbe_rss_enabled(hw)) { /* RSS is disabled */
3655 : 0 : rss_conf->rss_hf = 0;
3656 : 0 : return 0;
3657 : : }
3658 : :
3659 : : /* Get RSS functions configured in MRQC register */
3660 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3661 : :
3662 : : rss_hf = 0;
3663 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4)
3664 : : rss_hf |= RTE_ETH_RSS_IPV4;
3665 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4_TCP)
3666 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
3667 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6)
3668 : 0 : rss_hf |= RTE_ETH_RSS_IPV6;
3669 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX)
3670 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_EX;
3671 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_TCP)
3672 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
3673 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP)
3674 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_TCP_EX;
3675 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4_UDP)
3676 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
3677 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_UDP)
3678 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP;
3679 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP)
3680 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_UDP_EX;
3681 : 0 : rss_conf->rss_hf = rss_hf;
3682 : 0 : return 0;
3683 : : }
3684 : :
3685 : : static void
3686 : 0 : ixgbe_rss_configure(struct rte_eth_dev *dev)
3687 : : {
3688 : : struct rte_eth_rss_conf rss_conf;
3689 : : struct ixgbe_adapter *adapter;
3690 : : struct ixgbe_hw *hw;
3691 : : uint32_t reta;
3692 : : uint16_t i;
3693 : : uint16_t j;
3694 : : uint16_t sp_reta_size;
3695 : : uint32_t reta_reg;
3696 : :
3697 : 0 : PMD_INIT_FUNC_TRACE();
3698 : 0 : adapter = dev->data->dev_private;
3699 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3700 : :
3701 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
3702 : :
3703 : : /*
3704 : : * Fill in redirection table
3705 : : * The byte-swap is needed because NIC registers are in
3706 : : * little-endian order.
3707 : : */
3708 [ # # ]: 0 : if (adapter->rss_reta_updated == 0) {
3709 : : reta = 0;
3710 [ # # ]: 0 : for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
3711 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
3712 : :
3713 [ # # ]: 0 : if (j == dev->data->nb_rx_queues)
3714 : : j = 0;
3715 : 0 : reta = (reta << 8) | j;
3716 [ # # ]: 0 : if ((i & 3) == 3)
3717 [ # # ]: 0 : IXGBE_WRITE_REG(hw, reta_reg,
3718 : : rte_bswap32(reta));
3719 : : }
3720 : : }
3721 : :
3722 : : /*
3723 : : * Configure the RSS key and the RSS protocols used to compute
3724 : : * the RSS hash of input packets.
3725 : : */
3726 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
3727 [ # # ]: 0 : if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
3728 : : ixgbe_rss_disable(dev);
3729 : 0 : return;
3730 : : }
3731 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
3732 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
3733 : 0 : ixgbe_hw_rss_hash_set(hw, &rss_conf);
3734 : : }
3735 : :
3736 : : #define NUM_VFTA_REGISTERS 128
3737 : : #define NIC_RX_BUFFER_SIZE 0x200
3738 : : #define X550_RX_BUFFER_SIZE 0x180
3739 : :
3740 : : static void
3741 : 0 : ixgbe_vmdq_dcb_configure(struct rte_eth_dev *dev)
3742 : : {
3743 : : struct rte_eth_vmdq_dcb_conf *cfg;
3744 : : struct ixgbe_hw *hw;
3745 : : enum rte_eth_nb_pools num_pools;
3746 : : uint32_t mrqc, vt_ctl, queue_mapping, vlanctrl;
3747 : : uint16_t pbsize;
3748 : : uint8_t nb_tcs; /* number of traffic classes */
3749 : : int i;
3750 : :
3751 : 0 : PMD_INIT_FUNC_TRACE();
3752 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3753 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3754 : 0 : num_pools = cfg->nb_queue_pools;
3755 : : /* Check we have a valid number of pools */
3756 [ # # ]: 0 : if (num_pools != RTE_ETH_16_POOLS && num_pools != RTE_ETH_32_POOLS) {
3757 : : ixgbe_rss_disable(dev);
3758 : 0 : return;
3759 : : }
3760 : : /* 16 pools -> 8 traffic classes, 32 pools -> 4 traffic classes */
3761 : 0 : nb_tcs = (uint8_t)(RTE_ETH_VMDQ_DCB_NUM_QUEUES / (int)num_pools);
3762 : :
3763 : : /*
3764 : : * RXPBSIZE
3765 : : * split rx buffer up into sections, each for 1 traffic class
3766 : : */
3767 [ # # ]: 0 : switch (hw->mac.type) {
3768 : 0 : case ixgbe_mac_X550:
3769 : : case ixgbe_mac_X550EM_x:
3770 : : case ixgbe_mac_X550EM_a:
3771 : 0 : pbsize = (uint16_t)(X550_RX_BUFFER_SIZE / nb_tcs);
3772 : 0 : break;
3773 : 0 : default:
3774 : 0 : pbsize = (uint16_t)(NIC_RX_BUFFER_SIZE / nb_tcs);
3775 : 0 : break;
3776 : : }
3777 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3778 : 0 : uint32_t rxpbsize = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
3779 : :
3780 : 0 : rxpbsize &= (~(0x3FF << IXGBE_RXPBSIZE_SHIFT));
3781 : : /* clear 10 bits. */
3782 : 0 : rxpbsize |= (pbsize << IXGBE_RXPBSIZE_SHIFT); /* set value */
3783 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
3784 : : }
3785 : : /* zero alloc all unused TCs */
3786 [ # # ]: 0 : for (i = nb_tcs; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3787 : 0 : uint32_t rxpbsize = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
3788 : :
3789 : 0 : rxpbsize &= (~(0x3FF << IXGBE_RXPBSIZE_SHIFT));
3790 : : /* clear 10 bits. */
3791 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
3792 : : }
3793 : :
3794 : : /* MRQC: enable vmdq and dcb */
3795 : : mrqc = (num_pools == RTE_ETH_16_POOLS) ?
3796 [ # # ]: 0 : IXGBE_MRQC_VMDQRT8TCEN : IXGBE_MRQC_VMDQRT4TCEN;
3797 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3798 : :
3799 : : /* PFVTCTL: turn on virtualisation and set the default pool */
3800 : : vt_ctl = IXGBE_VT_CTL_VT_ENABLE | IXGBE_VT_CTL_REPLEN;
3801 [ # # ]: 0 : if (cfg->enable_default_pool) {
3802 : 0 : vt_ctl |= (cfg->default_pool << IXGBE_VT_CTL_POOL_SHIFT);
3803 : : } else {
3804 : : vt_ctl |= IXGBE_VT_CTL_DIS_DEFPL;
3805 : : }
3806 : :
3807 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vt_ctl);
3808 : :
3809 : : /* RTRUP2TC: mapping user priorities to traffic classes (TCs) */
3810 : : queue_mapping = 0;
3811 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
3812 : : /*
3813 : : * mapping is done with 3 bits per priority,
3814 : : * so shift by i*3 each time
3815 : : */
3816 : 0 : queue_mapping |= ((cfg->dcb_tc[i] & 0x07) << (i * 3));
3817 : :
3818 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, queue_mapping);
3819 : :
3820 : : /* RTRPCS: DCB related */
3821 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, IXGBE_RMCS_RRM);
3822 : :
3823 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
3824 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3825 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
3826 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
3827 : :
3828 : : /* VFTA - enable all vlan filters */
3829 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++) {
3830 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
3831 : : }
3832 : :
3833 : : /* VFRE: pool enabling for receive - 16 or 32 */
3834 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(0),
3835 : : num_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3836 : :
3837 : : /*
3838 : : * MPSAR - allow pools to read specific mac addresses
3839 : : * In this case, all pools should be able to read from mac addr 0
3840 : : */
3841 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(0), 0xFFFFFFFF);
3842 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(0), 0xFFFFFFFF);
3843 : :
3844 : : /* PFVLVF, PFVLVFB: set up filters for vlan tags as configured */
3845 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
3846 : : /* set vlan id in VF register and set the valid bit */
3847 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), (IXGBE_VLVF_VIEN |
3848 : : (cfg->pool_map[i].vlan_id & 0xFFF)));
3849 : : /*
3850 : : * Put the allowed pools in VFB reg. As we only have 16 or 32
3851 : : * pools, we only need to use the first half of the register
3852 : : * i.e. bits 0-31
3853 : : */
3854 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB(i*2), cfg->pool_map[i].pools);
3855 : : }
3856 : : }
3857 : :
3858 : : /**
3859 : : * ixgbe_dcb_config_tx_hw_config - Configure general DCB TX parameters
3860 : : * @dev: pointer to eth_dev structure
3861 : : * @dcb_config: pointer to ixgbe_dcb_config structure
3862 : : */
3863 : : static void
3864 : 0 : ixgbe_dcb_tx_hw_config(struct rte_eth_dev *dev,
3865 : : struct ixgbe_dcb_config *dcb_config)
3866 : : {
3867 : : uint32_t reg;
3868 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3869 : :
3870 : 0 : PMD_INIT_FUNC_TRACE();
3871 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
3872 : : /* Disable the Tx desc arbiter so that MTQC can be changed */
3873 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3874 : 0 : reg |= IXGBE_RTTDCS_ARBDIS;
3875 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
3876 : :
3877 : : /* Enable DCB for Tx with 8 TCs */
3878 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8) {
3879 : : reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3880 : : } else {
3881 : : reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3882 : : }
3883 [ # # ]: 0 : if (dcb_config->vt_mode)
3884 : 0 : reg |= IXGBE_MTQC_VT_ENA;
3885 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
3886 : :
3887 : : /* Enable the Tx desc arbiter */
3888 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3889 : 0 : reg &= ~IXGBE_RTTDCS_ARBDIS;
3890 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
3891 : :
3892 : : /* Enable Security TX Buffer IFG for DCB */
3893 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3894 : 0 : reg |= IXGBE_SECTX_DCB;
3895 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
3896 : : }
3897 : 0 : }
3898 : :
3899 : : /**
3900 : : * ixgbe_vmdq_dcb_hw_tx_config - Configure general VMDQ+DCB TX parameters
3901 : : * @dev: pointer to rte_eth_dev structure
3902 : : * @dcb_config: pointer to ixgbe_dcb_config structure
3903 : : */
3904 : : static void
3905 : 0 : ixgbe_vmdq_dcb_hw_tx_config(struct rte_eth_dev *dev,
3906 : : struct ixgbe_dcb_config *dcb_config)
3907 : : {
3908 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3909 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3910 : : struct ixgbe_hw *hw =
3911 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3912 : :
3913 : 0 : PMD_INIT_FUNC_TRACE();
3914 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB)
3915 : : /*PF VF Transmit Enable*/
3916 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(0),
3917 : : vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3918 : :
3919 : : /*Configure general DCB TX parameters*/
3920 : 0 : ixgbe_dcb_tx_hw_config(dev, dcb_config);
3921 : 0 : }
3922 : :
3923 : : static void
3924 : 0 : ixgbe_vmdq_dcb_rx_config(struct rte_eth_dev *dev,
3925 : : struct ixgbe_dcb_config *dcb_config)
3926 : : {
3927 : : struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
3928 : 0 : &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3929 : : struct ixgbe_dcb_tc_config *tc;
3930 : : uint8_t i, j;
3931 : :
3932 : : /* convert rte_eth_conf.rx_adv_conf to struct ixgbe_dcb_config */
3933 [ # # ]: 0 : if (vmdq_rx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
3934 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
3935 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
3936 : : } else {
3937 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
3938 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
3939 : : }
3940 : :
3941 : : /* Initialize User Priority to Traffic Class mapping */
3942 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
3943 : 0 : tc = &dcb_config->tc_config[j];
3944 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3945 : : }
3946 : :
3947 : : /* User Priority to Traffic Class mapping */
3948 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3949 : 0 : j = vmdq_rx_conf->dcb_tc[i];
3950 : 0 : tc = &dcb_config->tc_config[j];
3951 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3952 : 0 : (uint8_t)(1 << i);
3953 : : }
3954 : 0 : }
3955 : :
3956 : : static void
3957 : 0 : ixgbe_dcb_vt_tx_config(struct rte_eth_dev *dev,
3958 : : struct ixgbe_dcb_config *dcb_config)
3959 : : {
3960 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3961 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3962 : : struct ixgbe_dcb_tc_config *tc;
3963 : : uint8_t i, j;
3964 : :
3965 : : /* convert rte_eth_conf.rx_adv_conf to struct ixgbe_dcb_config */
3966 [ # # ]: 0 : if (vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
3967 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
3968 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
3969 : : } else {
3970 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
3971 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
3972 : : }
3973 : :
3974 : : /* Initialize User Priority to Traffic Class mapping */
3975 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
3976 : 0 : tc = &dcb_config->tc_config[j];
3977 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3978 : : }
3979 : :
3980 : : /* User Priority to Traffic Class mapping */
3981 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3982 : 0 : j = vmdq_tx_conf->dcb_tc[i];
3983 : 0 : tc = &dcb_config->tc_config[j];
3984 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3985 : 0 : (uint8_t)(1 << i);
3986 : : }
3987 : 0 : }
3988 : :
3989 : : static void
3990 : : ixgbe_dcb_rx_config(struct rte_eth_dev *dev,
3991 : : struct ixgbe_dcb_config *dcb_config)
3992 : : {
3993 : : struct rte_eth_dcb_rx_conf *rx_conf =
3994 : : &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
3995 : : struct ixgbe_dcb_tc_config *tc;
3996 : : uint8_t i, j;
3997 : :
3998 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)rx_conf->nb_tcs;
3999 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)rx_conf->nb_tcs;
4000 : :
4001 : : /* Initialize User Priority to Traffic Class mapping */
4002 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4003 : 0 : tc = &dcb_config->tc_config[j];
4004 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
4005 : : }
4006 : :
4007 : : /* User Priority to Traffic Class mapping */
4008 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4009 : 0 : j = rx_conf->dcb_tc[i];
4010 : 0 : tc = &dcb_config->tc_config[j];
4011 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
4012 : 0 : (uint8_t)(1 << i);
4013 : : }
4014 : : }
4015 : :
4016 : : static void
4017 : : ixgbe_dcb_tx_config(struct rte_eth_dev *dev,
4018 : : struct ixgbe_dcb_config *dcb_config)
4019 : : {
4020 : : struct rte_eth_dcb_tx_conf *tx_conf =
4021 : : &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
4022 : : struct ixgbe_dcb_tc_config *tc;
4023 : : uint8_t i, j;
4024 : :
4025 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)tx_conf->nb_tcs;
4026 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)tx_conf->nb_tcs;
4027 : :
4028 : : /* Initialize User Priority to Traffic Class mapping */
4029 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4030 : 0 : tc = &dcb_config->tc_config[j];
4031 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
4032 : : }
4033 : :
4034 : : /* User Priority to Traffic Class mapping */
4035 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4036 : 0 : j = tx_conf->dcb_tc[i];
4037 : 0 : tc = &dcb_config->tc_config[j];
4038 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
4039 : 0 : (uint8_t)(1 << i);
4040 : : }
4041 : : }
4042 : :
4043 : : /**
4044 : : * ixgbe_dcb_rx_hw_config - Configure general DCB RX HW parameters
4045 : : * @dev: pointer to eth_dev structure
4046 : : * @dcb_config: pointer to ixgbe_dcb_config structure
4047 : : */
4048 : : static void
4049 : 0 : ixgbe_dcb_rx_hw_config(struct rte_eth_dev *dev,
4050 : : struct ixgbe_dcb_config *dcb_config)
4051 : : {
4052 : : uint32_t reg;
4053 : : uint32_t vlanctrl;
4054 : : uint8_t i;
4055 : : uint32_t q;
4056 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4057 : :
4058 : 0 : PMD_INIT_FUNC_TRACE();
4059 : : /*
4060 : : * Disable the arbiter before changing parameters
4061 : : * (always enable recycle mode; WSP)
4062 : : */
4063 : : reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS;
4064 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
4065 : :
4066 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
4067 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
4068 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 4) {
4069 [ # # ]: 0 : if (dcb_config->vt_mode)
4070 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4071 : : IXGBE_MRQC_VMDQRT4TCEN;
4072 : : else {
4073 : : /* no matter the mode is DCB or DCB_RSS, just
4074 : : * set the MRQE to RSSXTCEN. RSS is controlled
4075 : : * by RSS_FIELD
4076 : : */
4077 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, 0);
4078 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4079 : : IXGBE_MRQC_RTRSS4TCEN;
4080 : : }
4081 : : }
4082 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8) {
4083 [ # # ]: 0 : if (dcb_config->vt_mode)
4084 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4085 : : IXGBE_MRQC_VMDQRT8TCEN;
4086 : : else {
4087 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, 0);
4088 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4089 : : IXGBE_MRQC_RTRSS8TCEN;
4090 : : }
4091 : : }
4092 : :
4093 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, reg);
4094 : :
4095 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4096 : : /* Disable drop for all queues in VMDQ mode*/
4097 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4098 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4099 : : (IXGBE_QDE_WRITE |
4100 : : (q << IXGBE_QDE_IDX_SHIFT)));
4101 : : } else {
4102 : : /* Enable drop for all queues in SRIOV mode */
4103 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4104 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4105 : : (IXGBE_QDE_WRITE |
4106 : : (q << IXGBE_QDE_IDX_SHIFT) |
4107 : : IXGBE_QDE_ENABLE));
4108 : : }
4109 : : }
4110 : :
4111 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
4112 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4113 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
4114 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
4115 : :
4116 : : /* VFTA - enable all vlan filters */
4117 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++) {
4118 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
4119 : : }
4120 : :
4121 : : /*
4122 : : * Configure Rx packet plane (recycle mode; WSP) and
4123 : : * enable arbiter
4124 : : */
4125 : : reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
4126 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
4127 : 0 : }
4128 : :
4129 : : static void
4130 : 0 : ixgbe_dcb_hw_arbite_rx_config(struct ixgbe_hw *hw, uint16_t *refill,
4131 : : uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
4132 : : {
4133 [ # # # ]: 0 : switch (hw->mac.type) {
4134 : 0 : case ixgbe_mac_82598EB:
4135 : 0 : ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, tsa);
4136 : 0 : break;
4137 : 0 : case ixgbe_mac_82599EB:
4138 : : case ixgbe_mac_X540:
4139 : : case ixgbe_mac_X550:
4140 : : case ixgbe_mac_X550EM_x:
4141 : : case ixgbe_mac_X550EM_a:
4142 : 0 : ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
4143 : : tsa, map);
4144 : 0 : break;
4145 : : default:
4146 : : break;
4147 : : }
4148 : 0 : }
4149 : :
4150 : : static void
4151 : 0 : ixgbe_dcb_hw_arbite_tx_config(struct ixgbe_hw *hw, uint16_t *refill, uint16_t *max,
4152 : : uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
4153 : : {
4154 [ # # # ]: 0 : switch (hw->mac.type) {
4155 : 0 : case ixgbe_mac_82598EB:
4156 : 0 : ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, bwg_id, tsa);
4157 : 0 : ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, bwg_id, tsa);
4158 : 0 : break;
4159 : 0 : case ixgbe_mac_82599EB:
4160 : : case ixgbe_mac_X540:
4161 : : case ixgbe_mac_X550:
4162 : : case ixgbe_mac_X550EM_x:
4163 : : case ixgbe_mac_X550EM_a:
4164 : 0 : ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, bwg_id, tsa);
4165 : 0 : ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id, tsa, map);
4166 : 0 : break;
4167 : : default:
4168 : : break;
4169 : : }
4170 : 0 : }
4171 : :
4172 : : #define DCB_RX_CONFIG 1
4173 : : #define DCB_TX_CONFIG 1
4174 : : #define DCB_TX_PB 1024
4175 : : /**
4176 : : * ixgbe_dcb_hw_configure - Enable DCB and configure
4177 : : * general DCB in VT mode and non-VT mode parameters
4178 : : * @dev: pointer to rte_eth_dev structure
4179 : : * @dcb_config: pointer to ixgbe_dcb_config structure
4180 : : */
4181 : : static int
4182 : 0 : ixgbe_dcb_hw_configure(struct rte_eth_dev *dev,
4183 : : struct ixgbe_dcb_config *dcb_config)
4184 : : {
4185 : : int ret = 0;
4186 : : uint8_t i, pfc_en, nb_tcs;
4187 : : uint16_t pbsize, rx_buffer_size;
4188 : : uint8_t config_dcb_rx = 0;
4189 : : uint8_t config_dcb_tx = 0;
4190 : 0 : uint8_t tsa[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4191 : 0 : uint8_t bwgid[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4192 : 0 : uint16_t refill[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4193 : 0 : uint16_t max[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4194 : 0 : uint8_t map[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4195 : : struct ixgbe_dcb_tc_config *tc;
4196 : 0 : uint32_t max_frame = dev->data->mtu + RTE_ETHER_HDR_LEN +
4197 : : RTE_ETHER_CRC_LEN;
4198 : 0 : struct ixgbe_hw *hw =
4199 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4200 : : struct ixgbe_bw_conf *bw_conf =
4201 : : IXGBE_DEV_PRIVATE_TO_BW_CONF(dev->data->dev_private);
4202 : :
4203 [ # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4204 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4205 : 0 : dcb_config->vt_mode = true;
4206 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
4207 : : config_dcb_rx = DCB_RX_CONFIG;
4208 : : /*
4209 : : *get dcb and VT rx configuration parameters
4210 : : *from rte_eth_conf
4211 : : */
4212 : 0 : ixgbe_vmdq_dcb_rx_config(dev, dcb_config);
4213 : : /*Configure general VMDQ and DCB RX parameters*/
4214 : 0 : ixgbe_vmdq_dcb_configure(dev);
4215 : : }
4216 : : break;
4217 : 0 : case RTE_ETH_MQ_RX_DCB:
4218 : : case RTE_ETH_MQ_RX_DCB_RSS:
4219 : 0 : dcb_config->vt_mode = false;
4220 : : config_dcb_rx = DCB_RX_CONFIG;
4221 : : /* Get dcb TX configuration parameters from rte_eth_conf */
4222 : : ixgbe_dcb_rx_config(dev, dcb_config);
4223 : : /*Configure general DCB RX parameters*/
4224 : 0 : ixgbe_dcb_rx_hw_config(dev, dcb_config);
4225 : 0 : break;
4226 : 0 : default:
4227 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB RX mode configuration");
4228 : 0 : break;
4229 : : }
4230 [ # # # ]: 0 : switch (dev->data->dev_conf.txmode.mq_mode) {
4231 : 0 : case RTE_ETH_MQ_TX_VMDQ_DCB:
4232 : 0 : dcb_config->vt_mode = true;
4233 : : config_dcb_tx = DCB_TX_CONFIG;
4234 : : /* get DCB and VT TX configuration parameters
4235 : : * from rte_eth_conf
4236 : : */
4237 : 0 : ixgbe_dcb_vt_tx_config(dev, dcb_config);
4238 : : /*Configure general VMDQ and DCB TX parameters*/
4239 : 0 : ixgbe_vmdq_dcb_hw_tx_config(dev, dcb_config);
4240 : 0 : break;
4241 : :
4242 : 0 : case RTE_ETH_MQ_TX_DCB:
4243 : 0 : dcb_config->vt_mode = false;
4244 : : config_dcb_tx = DCB_TX_CONFIG;
4245 : : /*get DCB TX configuration parameters from rte_eth_conf*/
4246 : : ixgbe_dcb_tx_config(dev, dcb_config);
4247 : : /*Configure general DCB TX parameters*/
4248 : 0 : ixgbe_dcb_tx_hw_config(dev, dcb_config);
4249 : 0 : break;
4250 : 0 : default:
4251 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB TX mode configuration");
4252 : 0 : break;
4253 : : }
4254 : :
4255 : 0 : nb_tcs = dcb_config->num_tcs.pfc_tcs;
4256 : : /* Unpack map */
4257 : 0 : ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
4258 [ # # ]: 0 : if (nb_tcs == RTE_ETH_4_TCS) {
4259 : : /* Avoid un-configured priority mapping to TC0 */
4260 : : uint8_t j = 4;
4261 : : uint8_t mask = 0xFF;
4262 : :
4263 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES - 4; i++)
4264 : 0 : mask = (uint8_t)(mask & (~(1 << map[i])));
4265 [ # # ]: 0 : for (i = 0; mask && (i < IXGBE_DCB_MAX_TRAFFIC_CLASS); i++) {
4266 [ # # # # ]: 0 : if ((mask & 0x1) && j < RTE_ETH_DCB_NUM_USER_PRIORITIES)
4267 : 0 : map[j++] = i;
4268 : 0 : mask >>= 1;
4269 : : }
4270 : : /* Re-configure 4 TCs BW */
4271 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4272 : 0 : tc = &dcb_config->tc_config[i];
4273 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
4274 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
4275 : : (uint8_t)(100 / nb_tcs);
4276 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
4277 : : (uint8_t)(100 / nb_tcs);
4278 : : }
4279 [ # # ]: 0 : for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
4280 : 0 : tc = &dcb_config->tc_config[i];
4281 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = 0;
4282 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent = 0;
4283 : : }
4284 : : } else {
4285 : : /* Re-configure 8 TCs BW */
4286 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4287 : 0 : tc = &dcb_config->tc_config[i];
4288 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
4289 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
4290 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
4291 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
4292 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
4293 : : }
4294 : : }
4295 : :
4296 [ # # ]: 0 : switch (hw->mac.type) {
4297 : : case ixgbe_mac_X550:
4298 : : case ixgbe_mac_X550EM_x:
4299 : : case ixgbe_mac_X550EM_a:
4300 : : rx_buffer_size = X550_RX_BUFFER_SIZE;
4301 : : break;
4302 : 0 : default:
4303 : : rx_buffer_size = NIC_RX_BUFFER_SIZE;
4304 : 0 : break;
4305 : : }
4306 : :
4307 [ # # ]: 0 : if (config_dcb_rx) {
4308 : : /* Set RX buffer size */
4309 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
4310 : 0 : uint32_t rxpbsize = pbsize << IXGBE_RXPBSIZE_SHIFT;
4311 : :
4312 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4313 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
4314 : : }
4315 : : /* zero alloc all unused TCs */
4316 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
4317 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
4318 : : }
4319 [ # # ]: 0 : if (config_dcb_tx) {
4320 : : /* Only support an equally distributed
4321 : : * Tx packet buffer strategy.
4322 : : */
4323 : 0 : uint32_t txpktsize = IXGBE_TXPBSIZE_MAX / nb_tcs;
4324 : 0 : uint32_t txpbthresh = (txpktsize / DCB_TX_PB) - IXGBE_TXPKT_SIZE_MAX;
4325 : :
4326 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4327 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
4328 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
4329 : : }
4330 : : /* Clear unused TCs, if any, to zero buffer size*/
4331 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4332 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
4333 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
4334 : : }
4335 : : }
4336 : :
4337 : : /*Calculates traffic class credits*/
4338 : 0 : ixgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
4339 : : IXGBE_DCB_TX_CONFIG);
4340 : 0 : ixgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
4341 : : IXGBE_DCB_RX_CONFIG);
4342 : :
4343 [ # # ]: 0 : if (config_dcb_rx) {
4344 : : /* Unpack CEE standard containers */
4345 : 0 : ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_RX_CONFIG, refill);
4346 : 0 : ixgbe_dcb_unpack_max_cee(dcb_config, max);
4347 : 0 : ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_RX_CONFIG, bwgid);
4348 : 0 : ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_RX_CONFIG, tsa);
4349 : : /* Configure PG(ETS) RX */
4350 : 0 : ixgbe_dcb_hw_arbite_rx_config(hw, refill, max, bwgid, tsa, map);
4351 : : }
4352 : :
4353 [ # # ]: 0 : if (config_dcb_tx) {
4354 : : /* Unpack CEE standard containers */
4355 : 0 : ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_TX_CONFIG, refill);
4356 : 0 : ixgbe_dcb_unpack_max_cee(dcb_config, max);
4357 : 0 : ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_TX_CONFIG, bwgid);
4358 : 0 : ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_TX_CONFIG, tsa);
4359 : : /* Configure PG(ETS) TX */
4360 : 0 : ixgbe_dcb_hw_arbite_tx_config(hw, refill, max, bwgid, tsa, map);
4361 : : }
4362 : :
4363 : : /*Configure queue statistics registers*/
4364 : 0 : ixgbe_dcb_config_tc_stats_82599(hw, dcb_config);
4365 : :
4366 : : /* Check if the PFC is supported */
4367 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
4368 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
4369 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4370 : : /*
4371 : : * If the TC count is 8,and the default high_water is 48,
4372 : : * the low_water is 16 as default.
4373 : : */
4374 : 0 : hw->fc.high_water[i] = (pbsize * 3) / 4;
4375 : 0 : hw->fc.low_water[i] = pbsize / 4;
4376 : : /* Enable pfc for this TC */
4377 : : tc = &dcb_config->tc_config[i];
4378 : 0 : tc->pfc = ixgbe_dcb_pfc_enabled;
4379 : : }
4380 : 0 : ixgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
4381 [ # # ]: 0 : if (dcb_config->num_tcs.pfc_tcs == RTE_ETH_4_TCS)
4382 : 0 : pfc_en &= 0x0F;
4383 : 0 : ret = ixgbe_dcb_config_pfc(hw, pfc_en, map);
4384 : : }
4385 : :
4386 : 0 : return ret;
4387 : : }
4388 : :
4389 : : /**
4390 : : * ixgbe_configure_dcb - Configure DCB Hardware
4391 : : * @dev: pointer to rte_eth_dev
4392 : : */
4393 : 0 : void ixgbe_configure_dcb(struct rte_eth_dev *dev)
4394 : : {
4395 : 0 : struct ixgbe_dcb_config *dcb_cfg =
4396 : 0 : IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
4397 : : struct rte_eth_conf *dev_conf = &(dev->data->dev_conf);
4398 : :
4399 : 0 : PMD_INIT_FUNC_TRACE();
4400 : :
4401 : : /* check support mq_mode for DCB */
4402 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_VMDQ_DCB &&
4403 [ # # ]: 0 : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB &&
4404 : : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB_RSS)
4405 : : return;
4406 : :
4407 [ # # ]: 0 : if (dev->data->nb_rx_queues > RTE_ETH_DCB_NUM_QUEUES)
4408 : : return;
4409 : :
4410 : : /** Configure DCB hardware **/
4411 : 0 : ixgbe_dcb_hw_configure(dev, dcb_cfg);
4412 : : }
4413 : :
4414 : : /*
4415 : : * VMDq only support for 10 GbE NIC.
4416 : : */
4417 : : static void
4418 : 0 : ixgbe_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
4419 : : {
4420 : : struct rte_eth_vmdq_rx_conf *cfg;
4421 : : struct ixgbe_hw *hw;
4422 : : enum rte_eth_nb_pools num_pools;
4423 : : uint32_t mrqc, vt_ctl, vlanctrl;
4424 : : uint32_t vmolr = 0;
4425 : : int i;
4426 : :
4427 : 0 : PMD_INIT_FUNC_TRACE();
4428 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4429 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
4430 : 0 : num_pools = cfg->nb_queue_pools;
4431 : :
4432 : : ixgbe_rss_disable(dev);
4433 : :
4434 : : /* MRQC: enable vmdq */
4435 : : mrqc = IXGBE_MRQC_VMDQEN;
4436 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4437 : :
4438 : : /* PFVTCTL: turn on virtualisation and set the default pool */
4439 : : vt_ctl = IXGBE_VT_CTL_VT_ENABLE | IXGBE_VT_CTL_REPLEN;
4440 [ # # ]: 0 : if (cfg->enable_default_pool)
4441 : 0 : vt_ctl |= (cfg->default_pool << IXGBE_VT_CTL_POOL_SHIFT);
4442 : : else
4443 : : vt_ctl |= IXGBE_VT_CTL_DIS_DEFPL;
4444 : :
4445 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vt_ctl);
4446 : :
4447 [ # # ]: 0 : for (i = 0; i < (int)num_pools; i++) {
4448 : 0 : vmolr = ixgbe_convert_vm_rx_mask_to_val(cfg->rx_mode, vmolr);
4449 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(i), vmolr);
4450 : : }
4451 : :
4452 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
4453 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4454 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
4455 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
4456 : :
4457 : : /* VFTA - enable all vlan filters */
4458 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++)
4459 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), UINT32_MAX);
4460 : :
4461 : : /* VFRE: pool enabling for receive - 64 */
4462 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), UINT32_MAX);
4463 [ # # ]: 0 : if (num_pools == RTE_ETH_64_POOLS)
4464 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), UINT32_MAX);
4465 : :
4466 : : /*
4467 : : * MPSAR - allow pools to read specific mac addresses
4468 : : * In this case, all pools should be able to read from mac addr 0
4469 : : */
4470 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(0), UINT32_MAX);
4471 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(0), UINT32_MAX);
4472 : :
4473 : : /* PFVLVF, PFVLVFB: set up filters for vlan tags as configured */
4474 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
4475 : : /* set vlan id in VF register and set the valid bit */
4476 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), (IXGBE_VLVF_VIEN |
4477 : : (cfg->pool_map[i].vlan_id & IXGBE_RXD_VLAN_ID_MASK)));
4478 : : /*
4479 : : * Put the allowed pools in VFB reg. As we only have 16 or 64
4480 : : * pools, we only need to use the first half of the register
4481 : : * i.e. bits 0-31
4482 : : */
4483 [ # # ]: 0 : if (((cfg->pool_map[i].pools >> 32) & UINT32_MAX) == 0)
4484 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB(i * 2),
4485 : : (cfg->pool_map[i].pools & UINT32_MAX));
4486 : : else
4487 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB((i * 2 + 1)),
4488 : : ((cfg->pool_map[i].pools >> 32) & UINT32_MAX));
4489 : :
4490 : : }
4491 : :
4492 : : /* PFDMA Tx General Switch Control Enables VMDQ loopback */
4493 [ # # ]: 0 : if (cfg->enable_loop_back) {
4494 : 0 : IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
4495 [ # # ]: 0 : for (i = 0; i < RTE_IXGBE_VMTXSW_REGISTER_COUNT; i++)
4496 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMTXSW(i), UINT32_MAX);
4497 : : }
4498 : :
4499 : 0 : IXGBE_WRITE_FLUSH(hw);
4500 : 0 : }
4501 : :
4502 : : /*
4503 : : * ixgbe_dcb_config_tx_hw_config - Configure general VMDq TX parameters
4504 : : * @hw: pointer to hardware structure
4505 : : */
4506 : : static void
4507 : 0 : ixgbe_vmdq_tx_hw_configure(struct ixgbe_hw *hw)
4508 : : {
4509 : : uint32_t reg;
4510 : : uint32_t q;
4511 : :
4512 : 0 : PMD_INIT_FUNC_TRACE();
4513 : : /*PF VF Transmit Enable*/
4514 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), UINT32_MAX);
4515 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), UINT32_MAX);
4516 : :
4517 : : /* Disable the Tx desc arbiter so that MTQC can be changed */
4518 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4519 : 0 : reg |= IXGBE_RTTDCS_ARBDIS;
4520 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
4521 : :
4522 : : reg = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF;
4523 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
4524 : :
4525 : : /* Disable drop for all queues */
4526 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4527 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4528 : : (IXGBE_QDE_WRITE | (q << IXGBE_QDE_IDX_SHIFT)));
4529 : :
4530 : : /* Enable the Tx desc arbiter */
4531 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4532 : 0 : reg &= ~IXGBE_RTTDCS_ARBDIS;
4533 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
4534 : :
4535 : 0 : IXGBE_WRITE_FLUSH(hw);
4536 : 0 : }
4537 : :
4538 : : static int __rte_cold
4539 : 0 : ixgbe_alloc_rx_queue_mbufs(struct ixgbe_rx_queue *rxq)
4540 : : {
4541 : 0 : struct ixgbe_rx_entry *rxe = rxq->sw_ring;
4542 : : uint64_t dma_addr;
4543 : : unsigned int i;
4544 : :
4545 : : /* Initialize software ring entries */
4546 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
4547 : : volatile union ixgbe_adv_rx_desc *rxd;
4548 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
4549 : :
4550 [ # # ]: 0 : if (mbuf == NULL) {
4551 : 0 : PMD_INIT_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
4552 : : (unsigned) rxq->queue_id);
4553 : 0 : return -ENOMEM;
4554 : : }
4555 : :
4556 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
4557 : 0 : mbuf->port = rxq->port_id;
4558 : :
4559 : : dma_addr =
4560 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
4561 : 0 : rxd = &rxq->rx_ring[i];
4562 : 0 : rxd->read.hdr_addr = 0;
4563 : 0 : rxd->read.pkt_addr = dma_addr;
4564 : 0 : rxe[i].mbuf = mbuf;
4565 : : }
4566 : :
4567 : : return 0;
4568 : : }
4569 : :
4570 : : static int
4571 : 0 : ixgbe_config_vf_rss(struct rte_eth_dev *dev)
4572 : : {
4573 : : struct ixgbe_hw *hw;
4574 : : uint32_t mrqc;
4575 : :
4576 : 0 : ixgbe_rss_configure(dev);
4577 : :
4578 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4579 : :
4580 : : /* MRQC: enable VF RSS */
4581 : 0 : mrqc = IXGBE_READ_REG(hw, IXGBE_MRQC);
4582 : 0 : mrqc &= ~IXGBE_MRQC_MRQE_MASK;
4583 [ # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4584 : 0 : case RTE_ETH_64_POOLS:
4585 : 0 : mrqc |= IXGBE_MRQC_VMDQRSS64EN;
4586 : 0 : break;
4587 : :
4588 : 0 : case RTE_ETH_32_POOLS:
4589 : 0 : mrqc |= IXGBE_MRQC_VMDQRSS32EN;
4590 : 0 : break;
4591 : :
4592 : 0 : default:
4593 : 0 : PMD_INIT_LOG(ERR, "Invalid pool number in IOV mode with VMDQ RSS");
4594 : 0 : return -EINVAL;
4595 : : }
4596 : :
4597 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4598 : :
4599 : 0 : return 0;
4600 : : }
4601 : :
4602 : : static int
4603 : 0 : ixgbe_config_vf_default(struct rte_eth_dev *dev)
4604 : : {
4605 : : struct ixgbe_hw *hw =
4606 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4607 : :
4608 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4609 : 0 : case RTE_ETH_64_POOLS:
4610 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4611 : : IXGBE_MRQC_VMDQEN);
4612 : : break;
4613 : :
4614 : 0 : case RTE_ETH_32_POOLS:
4615 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4616 : : IXGBE_MRQC_VMDQRT4TCEN);
4617 : : break;
4618 : :
4619 : 0 : case RTE_ETH_16_POOLS:
4620 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4621 : : IXGBE_MRQC_VMDQRT8TCEN);
4622 : : break;
4623 : 0 : default:
4624 : 0 : PMD_INIT_LOG(ERR,
4625 : : "invalid pool number in IOV mode");
4626 : 0 : break;
4627 : : }
4628 : 0 : return 0;
4629 : : }
4630 : :
4631 : : static int
4632 : 0 : ixgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
4633 : : {
4634 : : struct ixgbe_hw *hw =
4635 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4636 : :
4637 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
4638 : : return 0;
4639 : :
4640 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4641 : : /*
4642 : : * SRIOV inactive scheme
4643 : : * any DCB/RSS w/o VMDq multi-queue setting
4644 : : */
4645 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4646 : 0 : case RTE_ETH_MQ_RX_RSS:
4647 : : case RTE_ETH_MQ_RX_DCB_RSS:
4648 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4649 : 0 : ixgbe_rss_configure(dev);
4650 : 0 : break;
4651 : :
4652 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4653 : 0 : ixgbe_vmdq_dcb_configure(dev);
4654 : 0 : break;
4655 : :
4656 : 0 : case RTE_ETH_MQ_RX_VMDQ_ONLY:
4657 : 0 : ixgbe_vmdq_rx_hw_configure(dev);
4658 : 0 : break;
4659 : :
4660 : : case RTE_ETH_MQ_RX_NONE:
4661 : : default:
4662 : : /* if mq_mode is none, disable rss mode.*/
4663 : : ixgbe_rss_disable(dev);
4664 : : break;
4665 : : }
4666 : : } else {
4667 : : /* SRIOV active scheme
4668 : : * Support RSS together with SRIOV.
4669 : : */
4670 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4671 : 0 : case RTE_ETH_MQ_RX_RSS:
4672 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4673 : 0 : ixgbe_config_vf_rss(dev);
4674 : 0 : break;
4675 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4676 : : case RTE_ETH_MQ_RX_DCB:
4677 : : /* In SRIOV, the configuration is the same as VMDq case */
4678 : 0 : ixgbe_vmdq_dcb_configure(dev);
4679 : 0 : break;
4680 : : /* DCB/RSS together with SRIOV is not supported */
4681 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB_RSS:
4682 : : case RTE_ETH_MQ_RX_DCB_RSS:
4683 : 0 : PMD_INIT_LOG(ERR,
4684 : : "Could not support DCB/RSS with VMDq & SRIOV");
4685 : 0 : return -1;
4686 : 0 : default:
4687 : 0 : ixgbe_config_vf_default(dev);
4688 : 0 : break;
4689 : : }
4690 : : }
4691 : :
4692 : : return 0;
4693 : : }
4694 : :
4695 : : static int
4696 : 0 : ixgbe_dev_mq_tx_configure(struct rte_eth_dev *dev)
4697 : : {
4698 : 0 : struct ixgbe_hw *hw =
4699 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4700 : : uint32_t mtqc;
4701 : : uint32_t rttdcs;
4702 : :
4703 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
4704 : : return 0;
4705 : :
4706 : : /* disable arbiter before setting MTQC */
4707 : 0 : rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4708 : 0 : rttdcs |= IXGBE_RTTDCS_ARBDIS;
4709 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
4710 : :
4711 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4712 : : /*
4713 : : * SRIOV inactive scheme
4714 : : * any DCB w/o VMDq multi-queue setting
4715 : : */
4716 [ # # ]: 0 : if (dev->data->dev_conf.txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_ONLY)
4717 : 0 : ixgbe_vmdq_tx_hw_configure(hw);
4718 : : else {
4719 : : mtqc = IXGBE_MTQC_64Q_1PB;
4720 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
4721 : : }
4722 : : } else {
4723 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4724 : :
4725 : : /*
4726 : : * SRIOV active scheme
4727 : : * FIXME if support DCB together with VMDq & SRIOV
4728 : : */
4729 : : case RTE_ETH_64_POOLS:
4730 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF;
4731 : : break;
4732 : 0 : case RTE_ETH_32_POOLS:
4733 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_32VF;
4734 : 0 : break;
4735 : 0 : case RTE_ETH_16_POOLS:
4736 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_RT_ENA |
4737 : : IXGBE_MTQC_8TC_8TQ;
4738 : 0 : break;
4739 : 0 : default:
4740 : : mtqc = IXGBE_MTQC_64Q_1PB;
4741 : 0 : PMD_INIT_LOG(ERR, "invalid pool number in IOV mode");
4742 : : }
4743 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
4744 : : }
4745 : :
4746 : : /* re-enable arbiter */
4747 : : rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
4748 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
4749 : :
4750 : 0 : return 0;
4751 : : }
4752 : :
4753 : : /**
4754 : : * ixgbe_get_rscctl_maxdesc - Calculate the RSCCTL[n].MAXDESC for PF
4755 : : *
4756 : : * Return the RSCCTL[n].MAXDESC for 82599 and x540 PF devices according to the
4757 : : * spec rev. 3.0 chapter 8.2.3.8.13.
4758 : : *
4759 : : * @pool Memory pool of the Rx queue
4760 : : */
4761 : : static inline uint32_t
4762 : : ixgbe_get_rscctl_maxdesc(struct rte_mempool *pool)
4763 : : {
4764 : : struct rte_pktmbuf_pool_private *mp_priv = rte_mempool_get_priv(pool);
4765 : :
4766 : : /* MAXDESC * SRRCTL.BSIZEPKT must not exceed 64 KB minus one */
4767 : 0 : uint16_t maxdesc =
4768 : 0 : RTE_IPV4_MAX_PKT_LEN /
4769 : 0 : (mp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
4770 : :
4771 [ # # ]: 0 : if (maxdesc >= 16)
4772 : : return IXGBE_RSCCTL_MAXDESC_16;
4773 [ # # ]: 0 : else if (maxdesc >= 8)
4774 : : return IXGBE_RSCCTL_MAXDESC_8;
4775 [ # # ]: 0 : else if (maxdesc >= 4)
4776 : : return IXGBE_RSCCTL_MAXDESC_4;
4777 : : else
4778 : 0 : return IXGBE_RSCCTL_MAXDESC_1;
4779 : : }
4780 : :
4781 : : /**
4782 : : * ixgbe_set_ivar - Setup the correct IVAR register for a particular MSIX
4783 : : * interrupt
4784 : : *
4785 : : * (Taken from FreeBSD tree)
4786 : : * (yes this is all very magic and confusing :)
4787 : : *
4788 : : * @dev port handle
4789 : : * @entry the register array entry
4790 : : * @vector the MSIX vector for this queue
4791 : : * @type RX/TX/MISC
4792 : : */
4793 : : static void
4794 : 0 : ixgbe_set_ivar(struct rte_eth_dev *dev, u8 entry, u8 vector, s8 type)
4795 : : {
4796 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4797 : : u32 ivar, index;
4798 : :
4799 : 0 : vector |= IXGBE_IVAR_ALLOC_VAL;
4800 : :
4801 [ # # # ]: 0 : switch (hw->mac.type) {
4802 : :
4803 : 0 : case ixgbe_mac_82598EB:
4804 [ # # ]: 0 : if (type == -1)
4805 : : entry = IXGBE_IVAR_OTHER_CAUSES_INDEX;
4806 : : else
4807 : 0 : entry += (type * 64);
4808 : 0 : index = (entry >> 2) & 0x1F;
4809 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
4810 : 0 : ivar &= ~(0xFF << (8 * (entry & 0x3)));
4811 : 0 : ivar |= (vector << (8 * (entry & 0x3)));
4812 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
4813 : : break;
4814 : :
4815 : 0 : case ixgbe_mac_82599EB:
4816 : : case ixgbe_mac_X540:
4817 [ # # ]: 0 : if (type == -1) { /* MISC IVAR */
4818 : 0 : index = (entry & 1) * 8;
4819 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4820 : 0 : ivar &= ~(0xFF << index);
4821 : 0 : ivar |= (vector << index);
4822 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar);
4823 : : } else { /* RX/TX IVARS */
4824 : 0 : index = (16 * (entry & 1)) + (8 * type);
4825 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1));
4826 : 0 : ivar &= ~(0xFF << index);
4827 : 0 : ivar |= (vector << index);
4828 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar);
4829 : : }
4830 : :
4831 : : break;
4832 : :
4833 : : default:
4834 : : break;
4835 : : }
4836 : 0 : }
4837 : :
4838 : : void __rte_cold
4839 : 0 : ixgbe_set_rx_function(struct rte_eth_dev *dev)
4840 : : {
4841 : : uint16_t i, rx_using_sse;
4842 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
4843 : :
4844 : : /*
4845 : : * In order to allow Vector Rx there are a few configuration
4846 : : * conditions to be met and Rx Bulk Allocation should be allowed.
4847 : : */
4848 [ # # ]: 0 : if (ixgbe_rx_vec_dev_conf_condition_check(dev) ||
4849 [ # # # # ]: 0 : !adapter->rx_bulk_alloc_allowed ||
4850 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
4851 : 0 : PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet Vector Rx "
4852 : : "preconditions",
4853 : : dev->data->port_id);
4854 : :
4855 : 0 : adapter->rx_vec_allowed = false;
4856 : : }
4857 : :
4858 : : /*
4859 : : * Initialize the appropriate LRO callback.
4860 : : *
4861 : : * If all queues satisfy the bulk allocation preconditions
4862 : : * (hw->rx_bulk_alloc_allowed is TRUE) then we may use bulk allocation.
4863 : : * Otherwise use a single allocation version.
4864 : : */
4865 [ # # ]: 0 : if (dev->data->lro) {
4866 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed) {
4867 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a bulk "
4868 : : "allocation version");
4869 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_bulk_alloc;
4870 : : } else {
4871 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a single "
4872 : : "allocation version");
4873 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_single_alloc;
4874 : : }
4875 [ # # ]: 0 : } else if (dev->data->scattered_rx) {
4876 : : /*
4877 : : * Set the non-LRO scattered callback: there are Vector and
4878 : : * single allocation versions.
4879 : : */
4880 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
4881 : 0 : PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx "
4882 : : "callback (port=%d).",
4883 : : dev->data->port_id);
4884 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
4885 : 0 : dev->recycle_rx_descriptors_refill =
4886 : : ixgbe_recycle_rx_descriptors_refill_vec;
4887 : : #endif
4888 : 0 : dev->rx_pkt_burst = ixgbe_recv_scattered_pkts_vec;
4889 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
4890 : 0 : PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
4891 : : "allocation callback (port=%d).",
4892 : : dev->data->port_id);
4893 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_bulk_alloc;
4894 : : } else {
4895 : 0 : PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
4896 : : "single allocation) "
4897 : : "Scattered Rx callback "
4898 : : "(port=%d).",
4899 : : dev->data->port_id);
4900 : :
4901 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_single_alloc;
4902 : : }
4903 : : /*
4904 : : * Below we set "simple" callbacks according to port/queues parameters.
4905 : : * If parameters allow we are going to choose between the following
4906 : : * callbacks:
4907 : : * - Vector
4908 : : * - Bulk Allocation
4909 : : * - Single buffer allocation (the simplest one)
4910 : : */
4911 [ # # ]: 0 : } else if (adapter->rx_vec_allowed) {
4912 : 0 : PMD_INIT_LOG(DEBUG, "Vector rx enabled, please make sure RX "
4913 : : "burst size no less than %d (port=%d).",
4914 : : RTE_IXGBE_DESCS_PER_LOOP,
4915 : : dev->data->port_id);
4916 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
4917 : 0 : dev->recycle_rx_descriptors_refill = ixgbe_recycle_rx_descriptors_refill_vec;
4918 : : #endif
4919 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_vec;
4920 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
4921 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
4922 : : "satisfied. Rx Burst Bulk Alloc function "
4923 : : "will be used on port=%d.",
4924 : : dev->data->port_id);
4925 : :
4926 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_bulk_alloc;
4927 : : } else {
4928 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
4929 : : "satisfied, or Scattered Rx is requested "
4930 : : "(port=%d).",
4931 : : dev->data->port_id);
4932 : :
4933 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts;
4934 : : }
4935 : :
4936 : : /* Propagate information about RX function choice through all queues. */
4937 : :
4938 : : rx_using_sse =
4939 [ # # # # ]: 0 : (dev->rx_pkt_burst == ixgbe_recv_scattered_pkts_vec ||
4940 : : dev->rx_pkt_burst == ixgbe_recv_pkts_vec);
4941 : :
4942 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
4943 : 0 : struct ixgbe_rx_queue *rxq = dev->data->rx_queues[i];
4944 : :
4945 : 0 : rxq->rx_using_sse = rx_using_sse;
4946 : : #ifdef RTE_LIB_SECURITY
4947 : 0 : rxq->using_ipsec = !!(dev->data->dev_conf.rxmode.offloads &
4948 : : RTE_ETH_RX_OFFLOAD_SECURITY);
4949 : : #endif
4950 : : }
4951 : 0 : }
4952 : :
4953 : : /**
4954 : : * ixgbe_set_rsc - configure RSC related port HW registers
4955 : : *
4956 : : * Configures the port's RSC related registers according to the 4.6.7.2 chapter
4957 : : * of 82599 Spec (x540 configuration is virtually the same).
4958 : : *
4959 : : * @dev port handle
4960 : : *
4961 : : * Returns 0 in case of success or a non-zero error code
4962 : : */
4963 : : static int
4964 : 0 : ixgbe_set_rsc(struct rte_eth_dev *dev)
4965 : : {
4966 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4967 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4968 : 0 : struct rte_eth_dev_info dev_info = { 0 };
4969 : : bool rsc_capable = false;
4970 : : uint16_t i;
4971 : : uint32_t rdrxctl;
4972 : : uint32_t rfctl;
4973 : :
4974 : : /* Sanity check */
4975 : 0 : dev->dev_ops->dev_infos_get(dev, &dev_info);
4976 [ # # ]: 0 : if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO)
4977 : : rsc_capable = true;
4978 : :
4979 [ # # ]: 0 : if (!rsc_capable && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
4980 : 0 : PMD_INIT_LOG(CRIT, "LRO is requested on HW that doesn't "
4981 : : "support it");
4982 : 0 : return -EINVAL;
4983 : : }
4984 : :
4985 : : /* RSC global configuration (chapter 4.6.7.2.1 of 82599 Spec) */
4986 : :
4987 [ # # ]: 0 : if ((rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) &&
4988 : : (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
4989 : : /*
4990 : : * According to chapter of 4.6.7.2.1 of the Spec Rev.
4991 : : * 3.0 RSC configuration requires HW CRC stripping being
4992 : : * enabled. If user requested both HW CRC stripping off
4993 : : * and RSC on - return an error.
4994 : : */
4995 : 0 : PMD_INIT_LOG(CRIT, "LRO can't be enabled when HW CRC "
4996 : : "is disabled");
4997 : 0 : return -EINVAL;
4998 : : }
4999 : :
5000 : : /* RFCTL configuration */
5001 : 0 : rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
5002 [ # # # # ]: 0 : if ((rsc_capable) && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
5003 : 0 : rfctl &= ~IXGBE_RFCTL_RSC_DIS;
5004 : : else
5005 : 0 : rfctl |= IXGBE_RFCTL_RSC_DIS;
5006 : : /* disable NFS filtering */
5007 : 0 : rfctl |= IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS;
5008 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
5009 : :
5010 : : /* If LRO hasn't been requested - we are done here. */
5011 [ # # ]: 0 : if (!(rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
5012 : : return 0;
5013 : :
5014 : : /* Set RDRXCTL.RSCACKC bit */
5015 : 0 : rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
5016 : 0 : rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
5017 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
5018 : :
5019 : : /* Per-queue RSC configuration (chapter 4.6.7.2.2 of 82599 Spec) */
5020 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5021 : 0 : struct ixgbe_rx_queue *rxq = dev->data->rx_queues[i];
5022 : : uint32_t srrctl =
5023 [ # # # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_SRRCTL(rxq->reg_idx));
5024 : : uint32_t rscctl =
5025 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxq->reg_idx));
5026 : : uint32_t psrtype =
5027 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_PSRTYPE(rxq->reg_idx));
5028 : : uint32_t eitr =
5029 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_EITR(rxq->reg_idx));
5030 : :
5031 : : /*
5032 : : * ixgbe PMD doesn't support header-split at the moment.
5033 : : *
5034 : : * Following the 4.6.7.2.1 chapter of the 82599/x540
5035 : : * Spec if RSC is enabled the SRRCTL[n].BSIZEHEADER
5036 : : * should be configured even if header split is not
5037 : : * enabled. We will configure it 128 bytes following the
5038 : : * recommendation in the spec.
5039 : : */
5040 : 0 : srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
5041 : 0 : srrctl |= (128 << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
5042 : : IXGBE_SRRCTL_BSIZEHDR_MASK;
5043 : :
5044 : : /*
5045 : : * TODO: Consider setting the Receive Descriptor Minimum
5046 : : * Threshold Size for an RSC case. This is not an obviously
5047 : : * beneficiary option but the one worth considering...
5048 : : */
5049 : :
5050 : 0 : rscctl |= IXGBE_RSCCTL_RSCEN;
5051 [ # # ]: 0 : rscctl |= ixgbe_get_rscctl_maxdesc(rxq->mb_pool);
5052 : 0 : psrtype |= IXGBE_PSRTYPE_TCPHDR;
5053 : :
5054 : : /*
5055 : : * RSC: Set ITR interval corresponding to 2K ints/s.
5056 : : *
5057 : : * Full-sized RSC aggregations for a 10Gb/s link will
5058 : : * arrive at about 20K aggregation/s rate.
5059 : : *
5060 : : * 2K inst/s rate will make only 10% of the
5061 : : * aggregations to be closed due to the interrupt timer
5062 : : * expiration for a streaming at wire-speed case.
5063 : : *
5064 : : * For a sparse streaming case this setting will yield
5065 : : * at most 500us latency for a single RSC aggregation.
5066 : : */
5067 : 0 : eitr &= ~IXGBE_EITR_ITR_INT_MASK;
5068 : : eitr |= IXGBE_EITR_INTERVAL_US(IXGBE_QUEUE_ITR_INTERVAL_DEFAULT);
5069 : 0 : eitr |= IXGBE_EITR_CNT_WDIS;
5070 : :
5071 [ # # # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxq->reg_idx), srrctl);
5072 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(rxq->reg_idx), rscctl);
5073 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(rxq->reg_idx), psrtype);
5074 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_EITR(rxq->reg_idx), eitr);
5075 : :
5076 : : /*
5077 : : * RSC requires the mapping of the queue to the
5078 : : * interrupt vector.
5079 : : */
5080 : 0 : ixgbe_set_ivar(dev, rxq->reg_idx, i, 0);
5081 : : }
5082 : :
5083 : 0 : dev->data->lro = 1;
5084 : :
5085 : 0 : PMD_INIT_LOG(DEBUG, "enabling LRO mode");
5086 : :
5087 : 0 : return 0;
5088 : : }
5089 : :
5090 : : /*
5091 : : * Initializes Receive Unit.
5092 : : */
5093 : : int __rte_cold
5094 : 0 : ixgbe_dev_rx_init(struct rte_eth_dev *dev)
5095 : : {
5096 : : struct ixgbe_hw *hw;
5097 : : struct ixgbe_rx_queue *rxq;
5098 : : uint64_t bus_addr;
5099 : : uint32_t rxctrl;
5100 : : uint32_t fctrl;
5101 : : uint32_t hlreg0;
5102 : : uint32_t maxfrs;
5103 : : uint32_t srrctl;
5104 : : uint32_t rdrxctl;
5105 : : uint32_t rxcsum;
5106 : : uint16_t buf_size;
5107 : : uint16_t i;
5108 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
5109 : 0 : uint32_t frame_size = dev->data->mtu + IXGBE_ETH_OVERHEAD;
5110 : : int rc;
5111 : :
5112 : 0 : PMD_INIT_FUNC_TRACE();
5113 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5114 : :
5115 : : /*
5116 : : * Make sure receives are disabled while setting
5117 : : * up the RX context (registers, descriptor rings, etc.).
5118 : : */
5119 : 0 : rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5120 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
5121 : :
5122 : : /* Enable receipt of broadcasted frames */
5123 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5124 : : fctrl |= IXGBE_FCTRL_BAM;
5125 : : fctrl |= IXGBE_FCTRL_DPF;
5126 : 0 : fctrl |= IXGBE_FCTRL_PMCF;
5127 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5128 : :
5129 : : /*
5130 : : * Configure CRC stripping, if any.
5131 : : */
5132 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
5133 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5134 : 0 : hlreg0 &= ~IXGBE_HLREG0_RXCRCSTRP;
5135 : : else
5136 : 0 : hlreg0 |= IXGBE_HLREG0_RXCRCSTRP;
5137 : :
5138 : : /*
5139 : : * Configure jumbo frame support, if any.
5140 : : */
5141 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU) {
5142 : 0 : hlreg0 |= IXGBE_HLREG0_JUMBOEN;
5143 : 0 : maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
5144 : 0 : maxfrs &= 0x0000FFFF;
5145 : 0 : maxfrs |= (frame_size << 16);
5146 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
5147 : : } else
5148 : 0 : hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
5149 : :
5150 : : /*
5151 : : * If loopback mode is configured, set LPBK bit.
5152 : : */
5153 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
5154 : 0 : rc = ixgbe_check_supported_loopback_mode(dev);
5155 [ # # ]: 0 : if (rc < 0) {
5156 : 0 : PMD_INIT_LOG(ERR, "Unsupported loopback mode");
5157 : 0 : return rc;
5158 : : }
5159 : 0 : hlreg0 |= IXGBE_HLREG0_LPBK;
5160 : : } else {
5161 : 0 : hlreg0 &= ~IXGBE_HLREG0_LPBK;
5162 : : }
5163 : :
5164 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
5165 : :
5166 : : /*
5167 : : * Assume no header split and no VLAN strip support
5168 : : * on any Rx queue first .
5169 : : */
5170 : 0 : rx_conf->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5171 : : /* Setup RX queues */
5172 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5173 : 0 : rxq = dev->data->rx_queues[i];
5174 : :
5175 : : /*
5176 : : * Reset crc_len in case it was changed after queue setup by a
5177 : : * call to configure.
5178 : : */
5179 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5180 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
5181 : : else
5182 : 0 : rxq->crc_len = 0;
5183 : :
5184 : : /* Setup the Base and Length of the Rx Descriptor Rings */
5185 : 0 : bus_addr = rxq->rx_ring_phys_addr;
5186 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDBAL(rxq->reg_idx),
5187 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5188 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDBAH(rxq->reg_idx),
5189 : : (uint32_t)(bus_addr >> 32));
5190 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDLEN(rxq->reg_idx),
5191 : : rxq->nb_rx_desc * sizeof(union ixgbe_adv_rx_desc));
5192 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDH(rxq->reg_idx), 0);
5193 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDT(rxq->reg_idx), 0);
5194 : :
5195 : : /* Configure the SRRCTL register */
5196 : : srrctl = IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
5197 : :
5198 : : /* Set if packets are dropped when no descriptors available */
5199 [ # # ]: 0 : if (rxq->drop_en)
5200 : : srrctl |= IXGBE_SRRCTL_DROP_EN;
5201 : :
5202 : : /*
5203 : : * Configure the RX buffer size in the BSIZEPACKET field of
5204 : : * the SRRCTL register of the queue.
5205 : : * The value is in 1 KB resolution. Valid values can be from
5206 : : * 1 KB to 16 KB.
5207 : : */
5208 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
5209 : : RTE_PKTMBUF_HEADROOM);
5210 : 0 : srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
5211 : : IXGBE_SRRCTL_BSIZEPKT_MASK);
5212 : :
5213 [ # # # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxq->reg_idx), srrctl);
5214 : :
5215 : 0 : buf_size = (uint16_t) ((srrctl & IXGBE_SRRCTL_BSIZEPKT_MASK) <<
5216 : : IXGBE_SRRCTL_BSIZEPKT_SHIFT);
5217 : :
5218 : : /* It adds dual VLAN length for supporting dual VLAN */
5219 [ # # ]: 0 : if (frame_size + 2 * RTE_VLAN_HLEN > buf_size)
5220 : 0 : dev->data->scattered_rx = 1;
5221 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5222 : 0 : rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5223 : : }
5224 : :
5225 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
5226 : 0 : dev->data->scattered_rx = 1;
5227 : :
5228 : : /*
5229 : : * Device configured with multiple RX queues.
5230 : : */
5231 : 0 : ixgbe_dev_mq_rx_configure(dev);
5232 : :
5233 : : /*
5234 : : * Setup the Checksum Register.
5235 : : * Disable Full-Packet Checksum which is mutually exclusive with RSS.
5236 : : * Enable IP/L4 checksum computation by hardware if requested to do so.
5237 : : */
5238 : 0 : rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
5239 : : rxcsum |= IXGBE_RXCSUM_PCSD;
5240 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
5241 : 0 : rxcsum |= IXGBE_RXCSUM_IPPCSE;
5242 : : else
5243 : 0 : rxcsum &= ~IXGBE_RXCSUM_IPPCSE;
5244 : :
5245 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
5246 : :
5247 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
5248 : : hw->mac.type == ixgbe_mac_X540) {
5249 : 0 : rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
5250 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5251 : 0 : rdrxctl &= ~IXGBE_RDRXCTL_CRCSTRIP;
5252 : : else
5253 : 0 : rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
5254 : 0 : rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
5255 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
5256 : : }
5257 : :
5258 : 0 : rc = ixgbe_set_rsc(dev);
5259 [ # # ]: 0 : if (rc)
5260 : : return rc;
5261 : :
5262 : 0 : ixgbe_set_rx_function(dev);
5263 : :
5264 : 0 : return 0;
5265 : : }
5266 : :
5267 : : /*
5268 : : * Initializes Transmit Unit.
5269 : : */
5270 : : void __rte_cold
5271 : 0 : ixgbe_dev_tx_init(struct rte_eth_dev *dev)
5272 : : {
5273 : : struct ixgbe_hw *hw;
5274 : : struct ci_tx_queue *txq;
5275 : : uint64_t bus_addr;
5276 : : uint32_t hlreg0;
5277 : : uint32_t txctrl;
5278 : : uint16_t i;
5279 : :
5280 : 0 : PMD_INIT_FUNC_TRACE();
5281 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5282 : :
5283 : : /* Enable TX CRC (checksum offload requirement) and hw padding
5284 : : * (TSO requirement)
5285 : : */
5286 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
5287 : 0 : hlreg0 |= (IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_TXPADEN);
5288 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
5289 : :
5290 : : /* Setup the Base and Length of the Tx Descriptor Rings */
5291 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5292 : 0 : txq = dev->data->tx_queues[i];
5293 : :
5294 : 0 : bus_addr = txq->tx_ring_dma;
5295 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDBAL(txq->reg_idx),
5296 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5297 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDBAH(txq->reg_idx),
5298 : : (uint32_t)(bus_addr >> 32));
5299 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDLEN(txq->reg_idx),
5300 : : txq->nb_tx_desc * sizeof(union ixgbe_adv_tx_desc));
5301 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
5302 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDH(txq->reg_idx), 0);
5303 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDT(txq->reg_idx), 0);
5304 : :
5305 : : /*
5306 : : * Disable Tx Head Writeback RO bit, since this hoses
5307 : : * bookkeeping if things aren't delivered in order.
5308 : : */
5309 [ # # ]: 0 : switch (hw->mac.type) {
5310 : 0 : case ixgbe_mac_82598EB:
5311 : 0 : txctrl = IXGBE_READ_REG(hw,
5312 : : IXGBE_DCA_TXCTRL(txq->reg_idx));
5313 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5314 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(txq->reg_idx),
5315 : : txctrl);
5316 : : break;
5317 : :
5318 : 0 : case ixgbe_mac_82599EB:
5319 : : case ixgbe_mac_X540:
5320 : : case ixgbe_mac_X550:
5321 : : case ixgbe_mac_X550EM_x:
5322 : : case ixgbe_mac_X550EM_a:
5323 : : default:
5324 : 0 : txctrl = IXGBE_READ_REG(hw,
5325 : : IXGBE_DCA_TXCTRL_82599(txq->reg_idx));
5326 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5327 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(txq->reg_idx),
5328 : : txctrl);
5329 : : break;
5330 : : }
5331 : : }
5332 : :
5333 : : /* Device configured with multiple TX queues. */
5334 : 0 : ixgbe_dev_mq_tx_configure(dev);
5335 : 0 : }
5336 : :
5337 : : /*
5338 : : * Check if requested loopback mode is supported
5339 : : */
5340 : : int
5341 : 0 : ixgbe_check_supported_loopback_mode(struct rte_eth_dev *dev)
5342 : : {
5343 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5344 : :
5345 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_TX_RX)
5346 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
5347 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540 ||
5348 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
5349 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
5350 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
5351 : : hw->mac.type == ixgbe_mac_E610)
5352 : 0 : return 0;
5353 : :
5354 : : return -ENOTSUP;
5355 : : }
5356 : :
5357 : : /*
5358 : : * Set up link for 82599 loopback mode Tx->Rx.
5359 : : */
5360 : : static inline void __rte_cold
5361 : 0 : ixgbe_setup_loopback_link_82599(struct ixgbe_hw *hw)
5362 : : {
5363 : 0 : PMD_INIT_FUNC_TRACE();
5364 : :
5365 [ # # ]: 0 : if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
5366 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM) !=
5367 : : IXGBE_SUCCESS) {
5368 : 0 : PMD_INIT_LOG(ERR, "Could not enable loopback mode");
5369 : : /* ignore error */
5370 : 0 : return;
5371 : : }
5372 : : }
5373 : :
5374 : : /* Restart link */
5375 : 0 : IXGBE_WRITE_REG(hw,
5376 : : IXGBE_AUTOC,
5377 : : IXGBE_AUTOC_LMS_10G_LINK_NO_AN | IXGBE_AUTOC_FLU);
5378 : 0 : ixgbe_reset_pipeline_82599(hw);
5379 : :
5380 : 0 : hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
5381 : 0 : msec_delay(50);
5382 : : }
5383 : :
5384 : :
5385 : : /*
5386 : : * Start Transmit and Receive Units.
5387 : : */
5388 : : int __rte_cold
5389 : 0 : ixgbe_dev_rxtx_start(struct rte_eth_dev *dev)
5390 : : {
5391 : : struct ixgbe_hw *hw;
5392 : : struct ci_tx_queue *txq;
5393 : : struct ixgbe_rx_queue *rxq;
5394 : : uint32_t txdctl;
5395 : : uint32_t dmatxctl;
5396 : : uint32_t rxctrl;
5397 : : uint16_t i;
5398 : : int ret = 0;
5399 : :
5400 : 0 : PMD_INIT_FUNC_TRACE();
5401 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5402 : :
5403 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5404 : 0 : txq = dev->data->tx_queues[i];
5405 : : /* Setup Transmit Threshold Registers */
5406 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5407 : 0 : txdctl |= txq->pthresh & 0x7F;
5408 : 0 : txdctl |= ((txq->hthresh & 0x7F) << 8);
5409 : 0 : txdctl |= ((txq->wthresh & 0x7F) << 16);
5410 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5411 : : }
5412 : :
5413 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
5414 : 0 : dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
5415 : 0 : dmatxctl |= IXGBE_DMATXCTL_TE;
5416 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
5417 : : }
5418 : :
5419 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5420 : 0 : txq = dev->data->tx_queues[i];
5421 [ # # ]: 0 : if (!txq->tx_deferred_start) {
5422 : 0 : ret = ixgbe_dev_tx_queue_start(dev, i);
5423 [ # # ]: 0 : if (ret < 0)
5424 : 0 : return ret;
5425 : : }
5426 : : }
5427 : :
5428 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5429 : 0 : rxq = dev->data->rx_queues[i];
5430 [ # # ]: 0 : if (!rxq->rx_deferred_start) {
5431 : 0 : ret = ixgbe_dev_rx_queue_start(dev, i);
5432 [ # # ]: 0 : if (ret < 0)
5433 : 0 : return ret;
5434 : : }
5435 : : }
5436 : :
5437 : : /* Enable Receive engine */
5438 : 0 : rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5439 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
5440 : 0 : rxctrl |= IXGBE_RXCTRL_DMBYPS;
5441 : 0 : rxctrl |= IXGBE_RXCTRL_RXEN;
5442 : 0 : hw->mac.ops.enable_rx_dma(hw, rxctrl);
5443 : :
5444 : : /* If loopback mode is enabled, set up the link accordingly */
5445 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
5446 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB)
5447 : 0 : ixgbe_setup_loopback_link_82599(hw);
5448 [ # # ]: 0 : else if (hw->mac.type == ixgbe_mac_X540 ||
5449 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
5450 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
5451 : : hw->mac.type == ixgbe_mac_X550EM_a)
5452 : 0 : ixgbe_setup_loopback_link_x540_x550(hw, true);
5453 : : }
5454 : :
5455 : : #ifdef RTE_LIB_SECURITY
5456 [ # # ]: 0 : if ((dev->data->dev_conf.rxmode.offloads &
5457 : 0 : RTE_ETH_RX_OFFLOAD_SECURITY) ||
5458 [ # # ]: 0 : (dev->data->dev_conf.txmode.offloads &
5459 : : RTE_ETH_TX_OFFLOAD_SECURITY)) {
5460 : 0 : ret = ixgbe_crypto_enable_ipsec(dev);
5461 [ # # ]: 0 : if (ret != 0) {
5462 : 0 : PMD_DRV_LOG(ERR,
5463 : : "ixgbe_crypto_enable_ipsec fails with %d.",
5464 : : ret);
5465 : 0 : return ret;
5466 : : }
5467 : : }
5468 : : #endif
5469 : :
5470 : : return 0;
5471 : : }
5472 : :
5473 : : /*
5474 : : * Start Receive Units for specified queue.
5475 : : */
5476 : : int __rte_cold
5477 : 0 : ixgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
5478 : : {
5479 : : struct ixgbe_hw *hw;
5480 : : struct ixgbe_rx_queue *rxq;
5481 : : uint32_t rxdctl;
5482 : : int poll_ms;
5483 : :
5484 : 0 : PMD_INIT_FUNC_TRACE();
5485 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5486 : :
5487 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
5488 : :
5489 : : /* Allocate buffers for descriptor rings */
5490 [ # # ]: 0 : if (ixgbe_alloc_rx_queue_mbufs(rxq) != 0) {
5491 : 0 : PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
5492 : : rx_queue_id);
5493 : 0 : return -1;
5494 : : }
5495 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5496 : 0 : rxdctl |= IXGBE_RXDCTL_ENABLE;
5497 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), rxdctl);
5498 : :
5499 : : /* Wait until RX Enable ready */
5500 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5501 : : do {
5502 : : rte_delay_ms(1);
5503 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5504 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & IXGBE_RXDCTL_ENABLE));
5505 [ # # ]: 0 : if (!poll_ms)
5506 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
5507 : : rte_wmb();
5508 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDH(rxq->reg_idx), 0);
5509 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
5510 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
5511 : :
5512 : 0 : return 0;
5513 : : }
5514 : :
5515 : : /*
5516 : : * Stop Receive Units for specified queue.
5517 : : */
5518 : : int __rte_cold
5519 : 0 : ixgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
5520 : : {
5521 : : struct ixgbe_hw *hw;
5522 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5523 : : struct ixgbe_rx_queue *rxq;
5524 : : uint32_t rxdctl;
5525 : : int poll_ms;
5526 : :
5527 : 0 : PMD_INIT_FUNC_TRACE();
5528 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5529 : :
5530 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
5531 : :
5532 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5533 : 0 : rxdctl &= ~IXGBE_RXDCTL_ENABLE;
5534 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), rxdctl);
5535 : :
5536 : : /* Wait until RX Enable bit clear */
5537 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5538 : : do {
5539 : : rte_delay_ms(1);
5540 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5541 [ # # # # ]: 0 : } while (--poll_ms && (rxdctl & IXGBE_RXDCTL_ENABLE));
5542 [ # # ]: 0 : if (!poll_ms)
5543 : 0 : PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
5544 : :
5545 : 0 : rte_delay_us(RTE_IXGBE_WAIT_100_US);
5546 : :
5547 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
5548 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
5549 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5550 : :
5551 : 0 : return 0;
5552 : : }
5553 : :
5554 : :
5555 : : /*
5556 : : * Start Transmit Units for specified queue.
5557 : : */
5558 : : int __rte_cold
5559 : 0 : ixgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5560 : : {
5561 : : struct ixgbe_hw *hw;
5562 : : struct ci_tx_queue *txq;
5563 : : uint32_t txdctl;
5564 : : int poll_ms;
5565 : :
5566 : 0 : PMD_INIT_FUNC_TRACE();
5567 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5568 : :
5569 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5570 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDH(txq->reg_idx), 0);
5571 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5572 : 0 : txdctl |= IXGBE_TXDCTL_ENABLE;
5573 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5574 : :
5575 : : /* Wait until TX Enable ready */
5576 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5577 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5578 : : do {
5579 : : rte_delay_ms(1);
5580 : 0 : txdctl = IXGBE_READ_REG(hw,
5581 : : IXGBE_TXDCTL(txq->reg_idx));
5582 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & IXGBE_TXDCTL_ENABLE));
5583 [ # # ]: 0 : if (!poll_ms)
5584 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d",
5585 : : tx_queue_id);
5586 : : }
5587 : : rte_wmb();
5588 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDT(txq->reg_idx), 0);
5589 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
5590 : :
5591 : 0 : return 0;
5592 : : }
5593 : :
5594 : : /*
5595 : : * Stop Transmit Units for specified queue.
5596 : : */
5597 : : int __rte_cold
5598 : 0 : ixgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5599 : : {
5600 : : struct ixgbe_hw *hw;
5601 : : struct ci_tx_queue *txq;
5602 : : uint32_t txdctl;
5603 : : uint32_t txtdh, txtdt;
5604 : : int poll_ms;
5605 : :
5606 : 0 : PMD_INIT_FUNC_TRACE();
5607 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5608 : :
5609 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5610 : :
5611 : : /* Wait until TX queue is empty */
5612 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5613 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5614 : : do {
5615 : 0 : rte_delay_us(RTE_IXGBE_WAIT_100_US);
5616 : 0 : txtdh = IXGBE_READ_REG(hw,
5617 : : IXGBE_TDH(txq->reg_idx));
5618 : 0 : txtdt = IXGBE_READ_REG(hw,
5619 : : IXGBE_TDT(txq->reg_idx));
5620 [ # # # # ]: 0 : } while (--poll_ms && (txtdh != txtdt));
5621 [ # # ]: 0 : if (!poll_ms)
5622 : 0 : PMD_INIT_LOG(ERR,
5623 : : "Tx Queue %d is not empty when stopping.",
5624 : : tx_queue_id);
5625 : : }
5626 : :
5627 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5628 : 0 : txdctl &= ~IXGBE_TXDCTL_ENABLE;
5629 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5630 : :
5631 : : /* Wait until TX Enable bit clear */
5632 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5633 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5634 : : do {
5635 : : rte_delay_ms(1);
5636 : 0 : txdctl = IXGBE_READ_REG(hw,
5637 : : IXGBE_TXDCTL(txq->reg_idx));
5638 [ # # # # ]: 0 : } while (--poll_ms && (txdctl & IXGBE_TXDCTL_ENABLE));
5639 [ # # ]: 0 : if (!poll_ms)
5640 : 0 : PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
5641 : : tx_queue_id);
5642 : : }
5643 : :
5644 [ # # ]: 0 : if (txq->ops != NULL) {
5645 : 0 : ci_txq_release_all_mbufs(txq, false);
5646 : 0 : txq->ops->reset(txq);
5647 : : }
5648 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5649 : :
5650 : 0 : return 0;
5651 : : }
5652 : :
5653 : : void
5654 : 0 : ixgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5655 : : struct rte_eth_rxq_info *qinfo)
5656 : : {
5657 : : struct ixgbe_rx_queue *rxq;
5658 : :
5659 : 0 : rxq = dev->data->rx_queues[queue_id];
5660 : :
5661 : 0 : qinfo->mp = rxq->mb_pool;
5662 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
5663 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
5664 : :
5665 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
5666 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
5667 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
5668 : 0 : qinfo->conf.offloads = rxq->offloads;
5669 : 0 : }
5670 : :
5671 : : void
5672 : 0 : ixgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5673 : : struct rte_eth_txq_info *qinfo)
5674 : : {
5675 : : struct ci_tx_queue *txq;
5676 : :
5677 : 0 : txq = dev->data->tx_queues[queue_id];
5678 : :
5679 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
5680 : :
5681 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
5682 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
5683 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
5684 : :
5685 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
5686 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
5687 : 0 : qinfo->conf.offloads = txq->offloads;
5688 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
5689 : 0 : }
5690 : :
5691 : : void
5692 : 0 : ixgbe_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5693 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
5694 : : {
5695 : : struct ixgbe_rx_queue *rxq;
5696 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5697 : :
5698 : 0 : rxq = dev->data->rx_queues[queue_id];
5699 : :
5700 : 0 : recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring;
5701 : 0 : recycle_rxq_info->mp = rxq->mb_pool;
5702 : 0 : recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;
5703 : 0 : recycle_rxq_info->receive_tail = &rxq->rx_tail;
5704 : :
5705 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
5706 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
5707 : 0 : recycle_rxq_info->refill_requirement = RTE_IXGBE_RXQ_REARM_THRESH;
5708 : 0 : recycle_rxq_info->refill_head = &rxq->rxrearm_start;
5709 : : #endif
5710 : : } else {
5711 : 0 : recycle_rxq_info->refill_requirement = rxq->rx_free_thresh;
5712 : 0 : recycle_rxq_info->refill_head = &rxq->rx_free_trigger;
5713 : : }
5714 : 0 : }
5715 : :
5716 : : /*
5717 : : * [VF] Initializes Receive Unit.
5718 : : */
5719 : : int __rte_cold
5720 : 0 : ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
5721 : : {
5722 : : struct ixgbe_hw *hw;
5723 : : struct ixgbe_rx_queue *rxq;
5724 : 0 : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
5725 : 0 : uint32_t frame_size = dev->data->mtu + IXGBE_ETH_OVERHEAD;
5726 : : uint64_t bus_addr;
5727 : : uint32_t srrctl, psrtype = 0;
5728 : : uint16_t buf_size;
5729 : : uint16_t i;
5730 : : int ret;
5731 : :
5732 : 0 : PMD_INIT_FUNC_TRACE();
5733 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5734 : :
5735 [ # # ]: 0 : if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
5736 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5737 : : "it should be power of 2");
5738 : 0 : return -1;
5739 : : }
5740 : :
5741 [ # # ]: 0 : if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
5742 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5743 : : "it should be equal to or less than %d",
5744 : : hw->mac.max_rx_queues);
5745 : 0 : return -1;
5746 : : }
5747 : :
5748 : : /*
5749 : : * When the VF driver issues a IXGBE_VF_RESET request, the PF driver
5750 : : * disables the VF receipt of packets if the PF MTU is > 1500.
5751 : : * This is done to deal with 82599 limitations that imposes
5752 : : * the PF and all VFs to share the same MTU.
5753 : : * Then, the PF driver enables again the VF receipt of packet when
5754 : : * the VF driver issues a IXGBE_VF_SET_LPE request.
5755 : : * In the meantime, the VF device cannot be used, even if the VF driver
5756 : : * and the Guest VM network stack are ready to accept packets with a
5757 : : * size up to the PF MTU.
5758 : : * As a work-around to this PF behaviour, force the call to
5759 : : * ixgbevf_rlpml_set_vf even if jumbo frames are not used. This way,
5760 : : * VF packets received can work in all cases.
5761 : : */
5762 [ # # ]: 0 : if (ixgbevf_rlpml_set_vf(hw, frame_size) != 0)
5763 : 0 : PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
5764 : : frame_size);
5765 : :
5766 : : /*
5767 : : * Assume no header split and no VLAN strip support
5768 : : * on any Rx queue first .
5769 : : */
5770 : 0 : rxmode->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5771 : : /* Setup RX queues */
5772 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5773 : 0 : rxq = dev->data->rx_queues[i];
5774 : :
5775 : : /* Allocate buffers for descriptor rings */
5776 : 0 : ret = ixgbe_alloc_rx_queue_mbufs(rxq);
5777 [ # # ]: 0 : if (ret)
5778 : 0 : return ret;
5779 : :
5780 : : /* Setup the Base and Length of the Rx Descriptor Rings */
5781 : 0 : bus_addr = rxq->rx_ring_phys_addr;
5782 : :
5783 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(i),
5784 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5785 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(i),
5786 : : (uint32_t)(bus_addr >> 32));
5787 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(i),
5788 : : rxq->nb_rx_desc * sizeof(union ixgbe_adv_rx_desc));
5789 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDH(i), 0);
5790 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), 0);
5791 : :
5792 : :
5793 : : /* Configure the SRRCTL register */
5794 : : srrctl = IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
5795 : :
5796 : : /* Set if packets are dropped when no descriptors available */
5797 [ # # ]: 0 : if (rxq->drop_en)
5798 : : srrctl |= IXGBE_SRRCTL_DROP_EN;
5799 : :
5800 : : /*
5801 : : * Configure the RX buffer size in the BSIZEPACKET field of
5802 : : * the SRRCTL register of the queue.
5803 : : * The value is in 1 KB resolution. Valid values can be from
5804 : : * 1 KB to 16 KB.
5805 : : */
5806 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
5807 : : RTE_PKTMBUF_HEADROOM);
5808 : 0 : srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
5809 : : IXGBE_SRRCTL_BSIZEPKT_MASK);
5810 : :
5811 : : /*
5812 : : * VF modification to write virtual function SRRCTL register
5813 : : */
5814 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(i), srrctl);
5815 : :
5816 : 0 : buf_size = (uint16_t) ((srrctl & IXGBE_SRRCTL_BSIZEPKT_MASK) <<
5817 : : IXGBE_SRRCTL_BSIZEPKT_SHIFT);
5818 : :
5819 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
5820 : : /* It adds dual VLAN length for supporting dual VLAN */
5821 [ # # ]: 0 : (frame_size + 2 * RTE_VLAN_HLEN) > buf_size) {
5822 [ # # ]: 0 : if (!dev->data->scattered_rx)
5823 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
5824 : 0 : dev->data->scattered_rx = 1;
5825 : : }
5826 : :
5827 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5828 : 0 : rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5829 : : }
5830 : :
5831 : : /* Set RQPL for VF RSS according to max Rx queue */
5832 : 0 : psrtype |= (dev->data->nb_rx_queues >> 1) <<
5833 : : IXGBE_PSRTYPE_RQPL_SHIFT;
5834 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
5835 : :
5836 : : /* Initialize the rss for x550_vf cards if enabled */
5837 [ # # ]: 0 : switch (hw->mac.type) {
5838 : 0 : case ixgbe_mac_X550_vf:
5839 : : case ixgbe_mac_X550EM_x_vf:
5840 : : case ixgbe_mac_X550EM_a_vf:
5841 : : case ixgbe_mac_E610_vf:
5842 [ # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
5843 : 0 : case RTE_ETH_MQ_RX_RSS:
5844 : : case RTE_ETH_MQ_RX_DCB_RSS:
5845 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
5846 : 0 : ixgbe_rss_configure(dev);
5847 : 0 : break;
5848 : : default:
5849 : : break;
5850 : : }
5851 : : break;
5852 : : default:
5853 : : break;
5854 : : }
5855 : :
5856 : 0 : ixgbe_set_rx_function(dev);
5857 : :
5858 : 0 : return 0;
5859 : : }
5860 : :
5861 : : /*
5862 : : * [VF] Initializes Transmit Unit.
5863 : : */
5864 : : void __rte_cold
5865 : 0 : ixgbevf_dev_tx_init(struct rte_eth_dev *dev)
5866 : : {
5867 : : struct ixgbe_hw *hw;
5868 : : struct ci_tx_queue *txq;
5869 : : uint64_t bus_addr;
5870 : : uint32_t txctrl;
5871 : : uint16_t i;
5872 : :
5873 : 0 : PMD_INIT_FUNC_TRACE();
5874 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5875 : :
5876 : : /* Setup the Base and Length of the Tx Descriptor Rings */
5877 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5878 : 0 : txq = dev->data->tx_queues[i];
5879 : 0 : bus_addr = txq->tx_ring_dma;
5880 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(i),
5881 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5882 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(i),
5883 : : (uint32_t)(bus_addr >> 32));
5884 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(i),
5885 : : txq->nb_tx_desc * sizeof(union ixgbe_adv_tx_desc));
5886 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
5887 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDH(i), 0);
5888 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDT(i), 0);
5889 : :
5890 : : /*
5891 : : * Disable Tx Head Writeback RO bit, since this hoses
5892 : : * bookkeeping if things aren't delivered in order.
5893 : : */
5894 : 0 : txctrl = IXGBE_READ_REG(hw,
5895 : : IXGBE_VFDCA_TXCTRL(i));
5896 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5897 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i),
5898 : : txctrl);
5899 : : }
5900 : 0 : }
5901 : :
5902 : : /*
5903 : : * [VF] Start Transmit and Receive Units.
5904 : : */
5905 : : void __rte_cold
5906 : 0 : ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
5907 : : {
5908 : : struct ixgbe_hw *hw;
5909 : : struct ci_tx_queue *txq;
5910 : : struct ixgbe_rx_queue *rxq;
5911 : : uint32_t txdctl;
5912 : : uint32_t rxdctl;
5913 : : uint16_t i;
5914 : : int poll_ms;
5915 : :
5916 : 0 : PMD_INIT_FUNC_TRACE();
5917 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5918 : :
5919 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5920 : 0 : txq = dev->data->tx_queues[i];
5921 : : /* Setup Transmit Threshold Registers */
5922 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
5923 : 0 : txdctl |= txq->pthresh & 0x7F;
5924 : 0 : txdctl |= ((txq->hthresh & 0x7F) << 8);
5925 : 0 : txdctl |= ((txq->wthresh & 0x7F) << 16);
5926 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
5927 : : }
5928 : :
5929 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5930 : :
5931 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
5932 : 0 : txdctl |= IXGBE_TXDCTL_ENABLE;
5933 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
5934 : :
5935 : : poll_ms = 10;
5936 : : /* Wait until TX Enable ready */
5937 : : do {
5938 : : rte_delay_ms(1);
5939 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
5940 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & IXGBE_TXDCTL_ENABLE));
5941 [ # # ]: 0 : if (!poll_ms)
5942 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
5943 : : else
5944 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
5945 : : }
5946 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5947 : :
5948 : 0 : rxq = dev->data->rx_queues[i];
5949 : :
5950 : 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
5951 : 0 : rxdctl |= IXGBE_RXDCTL_ENABLE;
5952 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl);
5953 : :
5954 : : /* Wait until RX Enable ready */
5955 : : poll_ms = 10;
5956 : : do {
5957 : : rte_delay_ms(1);
5958 : 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
5959 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & IXGBE_RXDCTL_ENABLE));
5960 [ # # ]: 0 : if (!poll_ms)
5961 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
5962 : : else
5963 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
5964 : : rte_wmb();
5965 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), rxq->nb_rx_desc - 1);
5966 : :
5967 : : }
5968 : 0 : }
5969 : :
5970 : : int
5971 : 0 : ixgbe_rss_conf_init(struct ixgbe_rte_flow_rss_conf *out,
5972 : : const struct rte_flow_action_rss *in)
5973 : : {
5974 [ # # ]: 0 : if (in->key_len > RTE_DIM(out->key) ||
5975 [ # # ]: 0 : in->queue_num > RTE_DIM(out->queue))
5976 : : return -EINVAL;
5977 : 0 : out->conf = (struct rte_flow_action_rss){
5978 : 0 : .func = in->func,
5979 : 0 : .level = in->level,
5980 : 0 : .types = in->types,
5981 : : .key_len = in->key_len,
5982 : : .queue_num = in->queue_num,
5983 : 0 : .key = memcpy(out->key, in->key, in->key_len),
5984 : 0 : .queue = memcpy(out->queue, in->queue,
5985 : 0 : sizeof(*in->queue) * in->queue_num),
5986 : : };
5987 : 0 : return 0;
5988 : : }
5989 : :
5990 : : int
5991 : 0 : ixgbe_action_rss_same(const struct rte_flow_action_rss *comp,
5992 : : const struct rte_flow_action_rss *with)
5993 : : {
5994 : 0 : return (comp->func == with->func &&
5995 : 0 : comp->level == with->level &&
5996 [ # # ]: 0 : comp->types == with->types &&
5997 [ # # ]: 0 : comp->key_len == with->key_len &&
5998 : 0 : comp->queue_num == with->queue_num &&
5999 [ # # # # ]: 0 : !memcmp(comp->key, with->key, with->key_len) &&
6000 : 0 : !memcmp(comp->queue, with->queue,
6001 [ # # ]: 0 : sizeof(*with->queue) * with->queue_num));
6002 : : }
6003 : :
6004 : : int
6005 : 0 : ixgbe_config_rss_filter(struct rte_eth_dev *dev,
6006 : : struct ixgbe_rte_flow_rss_conf *conf, bool add)
6007 : : {
6008 : : struct ixgbe_hw *hw;
6009 : : uint32_t reta;
6010 : : uint16_t i;
6011 : : uint16_t j;
6012 : : uint16_t sp_reta_size;
6013 : : uint32_t reta_reg;
6014 : 0 : struct rte_eth_rss_conf rss_conf = {
6015 : 0 : .rss_key = conf->conf.key_len ?
6016 [ # # ]: 0 : (void *)(uintptr_t)conf->conf.key : NULL,
6017 : : .rss_key_len = conf->conf.key_len,
6018 : 0 : .rss_hf = conf->conf.types,
6019 : : };
6020 : : struct ixgbe_filter_info *filter_info =
6021 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6022 : :
6023 : 0 : PMD_INIT_FUNC_TRACE();
6024 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6025 : :
6026 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
6027 : :
6028 [ # # ]: 0 : if (!add) {
6029 [ # # ]: 0 : if (ixgbe_action_rss_same(&filter_info->rss_info.conf,
6030 : 0 : &conf->conf)) {
6031 : : ixgbe_rss_disable(dev);
6032 : 0 : memset(&filter_info->rss_info, 0,
6033 : : sizeof(struct ixgbe_rte_flow_rss_conf));
6034 : 0 : return 0;
6035 : : }
6036 : : return -EINVAL;
6037 : : }
6038 : :
6039 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
6040 : : return -EINVAL;
6041 : : /* Fill in redirection table
6042 : : * The byte-swap is needed because NIC registers are in
6043 : : * little-endian order.
6044 : : */
6045 : : reta = 0;
6046 [ # # ]: 0 : for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
6047 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
6048 : :
6049 [ # # ]: 0 : if (j == conf->conf.queue_num)
6050 : : j = 0;
6051 : 0 : reta = (reta << 8) | conf->conf.queue[j];
6052 [ # # ]: 0 : if ((i & 3) == 3)
6053 [ # # ]: 0 : IXGBE_WRITE_REG(hw, reta_reg,
6054 : : rte_bswap32(reta));
6055 : : }
6056 : :
6057 : : /* Configure the RSS key and the RSS protocols used to compute
6058 : : * the RSS hash of input packets.
6059 : : */
6060 [ # # ]: 0 : if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
6061 : : ixgbe_rss_disable(dev);
6062 : 0 : return 0;
6063 : : }
6064 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
6065 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
6066 : 0 : ixgbe_hw_rss_hash_set(hw, &rss_conf);
6067 : :
6068 [ # # ]: 0 : if (ixgbe_rss_conf_init(&filter_info->rss_info, &conf->conf))
6069 : 0 : return -EINVAL;
6070 : :
6071 : : return 0;
6072 : : }
6073 : :
6074 : : /* Stubs needed for linkage when RTE_ARCH_PPC_64, RTE_ARCH_RISCV or
6075 : : * RTE_ARCH_LOONGARCH is set.
6076 : : */
6077 : : #if defined(RTE_ARCH_PPC_64) || defined(RTE_ARCH_RISCV) || \
6078 : : defined(RTE_ARCH_LOONGARCH)
6079 : : int
6080 : : ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
6081 : : {
6082 : : return -1;
6083 : : }
6084 : :
6085 : : uint16_t
6086 : : ixgbe_recv_pkts_vec(
6087 : : void __rte_unused *rx_queue,
6088 : : struct rte_mbuf __rte_unused **rx_pkts,
6089 : : uint16_t __rte_unused nb_pkts)
6090 : : {
6091 : : return 0;
6092 : : }
6093 : :
6094 : : uint16_t
6095 : : ixgbe_recv_scattered_pkts_vec(
6096 : : void __rte_unused *rx_queue,
6097 : : struct rte_mbuf __rte_unused **rx_pkts,
6098 : : uint16_t __rte_unused nb_pkts)
6099 : : {
6100 : : return 0;
6101 : : }
6102 : :
6103 : : int
6104 : : ixgbe_rxq_vec_setup(struct ixgbe_rx_queue __rte_unused *rxq)
6105 : : {
6106 : : return -1;
6107 : : }
6108 : :
6109 : : uint16_t
6110 : : ixgbe_xmit_fixed_burst_vec(void __rte_unused *tx_queue,
6111 : : struct rte_mbuf __rte_unused **tx_pkts,
6112 : : uint16_t __rte_unused nb_pkts)
6113 : : {
6114 : : return 0;
6115 : : }
6116 : :
6117 : : int
6118 : : ixgbe_txq_vec_setup(struct ci_tx_queue *txq __rte_unused)
6119 : : {
6120 : : return -1;
6121 : : }
6122 : :
6123 : : void
6124 : : ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue __rte_unused *rxq)
6125 : : {
6126 : : return;
6127 : : }
6128 : : #endif
|