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_X540_vf ||
2771 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550_vf ||
2772 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x_vf ||
2773 : : hw->mac.type == ixgbe_mac_X550EM_a_vf)
2774 : 0 : txq->qtx_tail = IXGBE_PCI_REG_ADDR(hw, IXGBE_VFTDT(queue_idx));
2775 : : else
2776 : 0 : txq->qtx_tail = IXGBE_PCI_REG_ADDR(hw, IXGBE_TDT(txq->reg_idx));
2777 : :
2778 : 0 : txq->tx_ring_dma = tz->iova;
2779 : 0 : txq->ixgbe_tx_ring = (union ixgbe_adv_tx_desc *)tz->addr;
2780 : :
2781 : : /* Allocate software ring */
2782 : 0 : txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
2783 : : sizeof(struct ci_tx_entry) * nb_desc,
2784 : : RTE_CACHE_LINE_SIZE, socket_id);
2785 [ # # ]: 0 : if (txq->sw_ring == NULL) {
2786 : 0 : ixgbe_tx_queue_release(txq);
2787 : 0 : return -ENOMEM;
2788 : : }
2789 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
2790 : : txq->sw_ring, txq->ixgbe_tx_ring, txq->tx_ring_dma);
2791 : :
2792 : : /* set up vector or scalar TX function as appropriate */
2793 : 0 : ixgbe_set_tx_function(dev, txq);
2794 : :
2795 : 0 : txq->ops->reset(txq);
2796 : :
2797 : 0 : dev->data->tx_queues[queue_idx] = txq;
2798 : :
2799 : :
2800 : 0 : return 0;
2801 : : }
2802 : :
2803 : : /**
2804 : : * ixgbe_free_sc_cluster - free the not-yet-completed scattered cluster
2805 : : *
2806 : : * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
2807 : : * in the sw_rsc_ring is not set to NULL but rather points to the next
2808 : : * mbuf of this RSC aggregation (that has not been completed yet and still
2809 : : * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
2810 : : * will just free first "nb_segs" segments of the cluster explicitly by calling
2811 : : * an rte_pktmbuf_free_seg().
2812 : : *
2813 : : * @m scattered cluster head
2814 : : */
2815 : : static void __rte_cold
2816 : 0 : ixgbe_free_sc_cluster(struct rte_mbuf *m)
2817 : : {
2818 : 0 : uint16_t i, nb_segs = m->nb_segs;
2819 : : struct rte_mbuf *next_seg;
2820 : :
2821 [ # # ]: 0 : for (i = 0; i < nb_segs; i++) {
2822 : 0 : next_seg = m->next;
2823 : : rte_pktmbuf_free_seg(m);
2824 : : m = next_seg;
2825 : : }
2826 : 0 : }
2827 : :
2828 : : static void __rte_cold
2829 : 0 : ixgbe_rx_queue_release_mbufs(struct ixgbe_rx_queue *rxq)
2830 : : {
2831 : : unsigned i;
2832 : :
2833 : : /* SSE Vector driver has a different way of releasing mbufs. */
2834 [ # # ]: 0 : if (rxq->rx_using_sse) {
2835 : 0 : ixgbe_rx_queue_release_mbufs_vec(rxq);
2836 : 0 : return;
2837 : : }
2838 : :
2839 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
2840 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2841 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
2842 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2843 : 0 : rxq->sw_ring[i].mbuf = NULL;
2844 : : }
2845 : : }
2846 [ # # ]: 0 : if (rxq->rx_nb_avail) {
2847 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; ++i) {
2848 : : struct rte_mbuf *mb;
2849 : :
2850 [ # # ]: 0 : mb = rxq->rx_stage[rxq->rx_next_avail + i];
2851 : : rte_pktmbuf_free_seg(mb);
2852 : : }
2853 : 0 : rxq->rx_nb_avail = 0;
2854 : : }
2855 : : }
2856 : :
2857 [ # # ]: 0 : if (rxq->sw_sc_ring)
2858 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++)
2859 [ # # ]: 0 : if (rxq->sw_sc_ring[i].fbuf) {
2860 : 0 : ixgbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
2861 : 0 : rxq->sw_sc_ring[i].fbuf = NULL;
2862 : : }
2863 : : }
2864 : :
2865 : : static void __rte_cold
2866 : 0 : ixgbe_rx_queue_release(struct ixgbe_rx_queue *rxq)
2867 : : {
2868 [ # # ]: 0 : if (rxq != NULL) {
2869 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
2870 : 0 : rte_free(rxq->sw_ring);
2871 : 0 : rte_free(rxq->sw_sc_ring);
2872 : 0 : rte_memzone_free(rxq->mz);
2873 : 0 : rte_free(rxq);
2874 : : }
2875 : 0 : }
2876 : :
2877 : : void __rte_cold
2878 : 0 : ixgbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2879 : : {
2880 : 0 : ixgbe_rx_queue_release(dev->data->rx_queues[qid]);
2881 : 0 : }
2882 : :
2883 : : /*
2884 : : * Check if Rx Burst Bulk Alloc function can be used.
2885 : : * Return
2886 : : * 0: the preconditions are satisfied and the bulk allocation function
2887 : : * can be used.
2888 : : * -EINVAL: the preconditions are NOT satisfied and the default Rx burst
2889 : : * function must be used.
2890 : : */
2891 : : static inline int __rte_cold
2892 : 0 : check_rx_burst_bulk_alloc_preconditions(struct ixgbe_rx_queue *rxq)
2893 : : {
2894 : : int ret = 0;
2895 : :
2896 : : /*
2897 : : * Make sure the following pre-conditions are satisfied:
2898 : : * rxq->rx_free_thresh >= RTE_PMD_IXGBE_RX_MAX_BURST
2899 : : * rxq->rx_free_thresh < rxq->nb_rx_desc
2900 : : * (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
2901 : : * Scattered packets are not supported. This should be checked
2902 : : * outside of this function.
2903 : : */
2904 [ # # ]: 0 : if (!(rxq->rx_free_thresh >= RTE_PMD_IXGBE_RX_MAX_BURST)) {
2905 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2906 : : "rxq->rx_free_thresh=%d, "
2907 : : "RTE_PMD_IXGBE_RX_MAX_BURST=%d",
2908 : : rxq->rx_free_thresh, RTE_PMD_IXGBE_RX_MAX_BURST);
2909 : : ret = -EINVAL;
2910 [ # # ]: 0 : } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
2911 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2912 : : "rxq->rx_free_thresh=%d, "
2913 : : "rxq->nb_rx_desc=%d",
2914 : : rxq->rx_free_thresh, rxq->nb_rx_desc);
2915 : : ret = -EINVAL;
2916 [ # # ]: 0 : } else if (!((rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)) {
2917 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2918 : : "rxq->nb_rx_desc=%d, "
2919 : : "rxq->rx_free_thresh=%d",
2920 : : rxq->nb_rx_desc, rxq->rx_free_thresh);
2921 : : ret = -EINVAL;
2922 : : }
2923 : :
2924 : 0 : return ret;
2925 : : }
2926 : :
2927 : : /* Reset dynamic ixgbe_rx_queue fields back to defaults */
2928 : : static void __rte_cold
2929 : 0 : ixgbe_reset_rx_queue(struct ixgbe_adapter *adapter, struct ixgbe_rx_queue *rxq)
2930 : : {
2931 : : static const union ixgbe_adv_rx_desc zeroed_desc = {{0}};
2932 : : unsigned i;
2933 : 0 : uint16_t len = rxq->nb_rx_desc;
2934 : :
2935 : : /*
2936 : : * By default, the Rx queue setup function allocates enough memory for
2937 : : * IXGBE_MAX_RING_DESC. The Rx Burst bulk allocation function requires
2938 : : * extra memory at the end of the descriptor ring to be zero'd out.
2939 : : */
2940 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
2941 : : /* zero out extra memory */
2942 : 0 : len += RTE_PMD_IXGBE_RX_MAX_BURST;
2943 : :
2944 : : /*
2945 : : * Zero out HW ring memory. Zero out extra memory at the end of
2946 : : * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
2947 : : * reads extra memory as zeros.
2948 : : */
2949 [ # # ]: 0 : for (i = 0; i < len; i++) {
2950 : 0 : rxq->rx_ring[i] = zeroed_desc;
2951 : : }
2952 : :
2953 : : /*
2954 : : * initialize extra software ring entries. Space for these extra
2955 : : * entries is always allocated
2956 : : */
2957 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2958 [ # # ]: 0 : for (i = rxq->nb_rx_desc; i < len; ++i) {
2959 : 0 : rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
2960 : : }
2961 : :
2962 : 0 : rxq->rx_nb_avail = 0;
2963 : 0 : rxq->rx_next_avail = 0;
2964 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2965 : 0 : rxq->rx_tail = 0;
2966 : 0 : rxq->nb_rx_hold = 0;
2967 : :
2968 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
2969 : :
2970 : 0 : rxq->pkt_first_seg = NULL;
2971 : 0 : rxq->pkt_last_seg = NULL;
2972 : :
2973 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
2974 : 0 : rxq->rxrearm_start = 0;
2975 : 0 : rxq->rxrearm_nb = 0;
2976 : : #endif
2977 : 0 : }
2978 : :
2979 : : static int
2980 : : ixgbe_is_vf(struct rte_eth_dev *dev)
2981 : : {
2982 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2983 : :
2984 [ # # ]: 0 : switch (hw->mac.type) {
2985 : : case ixgbe_mac_82599_vf:
2986 : : case ixgbe_mac_X540_vf:
2987 : : case ixgbe_mac_X550_vf:
2988 : : case ixgbe_mac_X550EM_x_vf:
2989 : : case ixgbe_mac_X550EM_a_vf:
2990 : : return 1;
2991 : : default:
2992 : : return 0;
2993 : : }
2994 : : }
2995 : :
2996 : : uint64_t
2997 : 0 : ixgbe_get_rx_queue_offloads(struct rte_eth_dev *dev)
2998 : : {
2999 : : uint64_t offloads = 0;
3000 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3001 : :
3002 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB)
3003 : : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3004 : :
3005 : 0 : return offloads;
3006 : : }
3007 : :
3008 : : uint64_t
3009 : 0 : ixgbe_get_rx_port_offloads(struct rte_eth_dev *dev)
3010 : : {
3011 : : uint64_t offloads;
3012 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3013 : :
3014 : : offloads = RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3015 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3016 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3017 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3018 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3019 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3020 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3021 : :
3022 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
3023 : : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3024 : :
3025 : : if (ixgbe_is_vf(dev) == 0)
3026 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
3027 : :
3028 : : /*
3029 : : * RSC is only supported by 82599 and x540 PF devices in a non-SR-IOV
3030 : : * mode.
3031 : : */
3032 [ # # ]: 0 : if ((hw->mac.type == ixgbe_mac_82599EB ||
3033 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540 ||
3034 : 0 : hw->mac.type == ixgbe_mac_X550) &&
3035 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active)
3036 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
3037 : :
3038 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
3039 : : hw->mac.type == ixgbe_mac_X540)
3040 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
3041 : :
3042 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
3043 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
3044 : : hw->mac.type == ixgbe_mac_X550EM_a)
3045 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM;
3046 : :
3047 : : #ifdef RTE_LIB_SECURITY
3048 [ # # ]: 0 : if (dev->security_ctx)
3049 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_SECURITY;
3050 : : #endif
3051 : :
3052 : 0 : return offloads;
3053 : : }
3054 : :
3055 : : int __rte_cold
3056 : 0 : ixgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
3057 : : uint16_t queue_idx,
3058 : : uint16_t nb_desc,
3059 : : unsigned int socket_id,
3060 : : const struct rte_eth_rxconf *rx_conf,
3061 : : struct rte_mempool *mp)
3062 : : {
3063 : : const struct rte_memzone *rz;
3064 : : struct ixgbe_rx_queue *rxq;
3065 : : struct ixgbe_hw *hw;
3066 : : uint16_t len;
3067 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
3068 : : uint64_t offloads;
3069 : :
3070 : 0 : PMD_INIT_FUNC_TRACE();
3071 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3072 : :
3073 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
3074 : :
3075 : : /*
3076 : : * Validate number of receive descriptors.
3077 : : * It must not exceed hardware maximum, and must be multiple
3078 : : * of IXGBE_ALIGN.
3079 : : */
3080 [ # # ]: 0 : if (nb_desc % IXGBE_RXD_ALIGN != 0 ||
3081 [ # # ]: 0 : (nb_desc > IXGBE_MAX_RING_DESC) ||
3082 : : (nb_desc < IXGBE_MIN_RING_DESC)) {
3083 : : return -EINVAL;
3084 : : }
3085 : :
3086 : : /* Free memory prior to re-allocation if needed... */
3087 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
3088 : 0 : ixgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
3089 : 0 : dev->data->rx_queues[queue_idx] = NULL;
3090 : : }
3091 : :
3092 : : /* First allocate the rx queue data structure */
3093 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct ixgbe_rx_queue),
3094 : : RTE_CACHE_LINE_SIZE, socket_id);
3095 [ # # ]: 0 : if (rxq == NULL)
3096 : : return -ENOMEM;
3097 : 0 : rxq->mb_pool = mp;
3098 : 0 : rxq->nb_rx_desc = nb_desc;
3099 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
3100 : 0 : rxq->queue_id = queue_idx;
3101 [ # # ]: 0 : rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
3102 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
3103 : 0 : rxq->port_id = dev->data->port_id;
3104 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
3105 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
3106 : : else
3107 : 0 : rxq->crc_len = 0;
3108 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
3109 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
3110 : 0 : rxq->offloads = offloads;
3111 : :
3112 : : /*
3113 : : * The packet type in RX descriptor is different for different NICs.
3114 : : * Some bits are used for x550 but reserved for other NICS.
3115 : : * So set different masks for different NICs.
3116 : : */
3117 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
3118 : : hw->mac.type == ixgbe_mac_X550EM_x ||
3119 : : hw->mac.type == ixgbe_mac_X550EM_a ||
3120 : : hw->mac.type == ixgbe_mac_X550_vf ||
3121 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x_vf ||
3122 : : hw->mac.type == ixgbe_mac_X550EM_a_vf)
3123 : 0 : rxq->pkt_type_mask = IXGBE_PACKET_TYPE_MASK_X550;
3124 : : else
3125 : 0 : rxq->pkt_type_mask = IXGBE_PACKET_TYPE_MASK_82599;
3126 : :
3127 : : /*
3128 : : * 82599 errata, UDP frames with a 0 checksum can be marked as checksum
3129 : : * errors.
3130 : : */
3131 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB)
3132 : 0 : rxq->rx_udp_csum_zero_err = 1;
3133 : :
3134 : : /*
3135 : : * Allocate RX ring hardware descriptors. A memzone large enough to
3136 : : * handle the maximum ring size is allocated in order to allow for
3137 : : * resizing in later calls to the queue setup function.
3138 : : */
3139 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
3140 : : RX_RING_SZ, IXGBE_ALIGN, socket_id);
3141 [ # # ]: 0 : if (rz == NULL) {
3142 : 0 : ixgbe_rx_queue_release(rxq);
3143 : 0 : return -ENOMEM;
3144 : : }
3145 : :
3146 : 0 : rxq->mz = rz;
3147 : : /*
3148 : : * Zero init all the descriptors in the ring.
3149 : : */
3150 [ # # ]: 0 : memset(rz->addr, 0, RX_RING_SZ);
3151 : :
3152 : : /*
3153 : : * Modified to setup VFRDT for Virtual Function
3154 : : */
3155 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599_vf ||
3156 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540_vf ||
3157 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550_vf ||
3158 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x_vf ||
3159 : : hw->mac.type == ixgbe_mac_X550EM_a_vf) {
3160 : 0 : rxq->rdt_reg_addr =
3161 : 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_VFRDT(queue_idx));
3162 : 0 : rxq->rdh_reg_addr =
3163 : 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_VFRDH(queue_idx));
3164 : : } else {
3165 : 0 : rxq->rdt_reg_addr =
3166 [ # # ]: 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_RDT(rxq->reg_idx));
3167 : 0 : rxq->rdh_reg_addr =
3168 [ # # ]: 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_RDH(rxq->reg_idx));
3169 : : }
3170 : :
3171 : 0 : rxq->rx_ring_phys_addr = rz->iova;
3172 : 0 : rxq->rx_ring = (union ixgbe_adv_rx_desc *) rz->addr;
3173 : :
3174 : : /*
3175 : : * Certain constraints must be met in order to use the bulk buffer
3176 : : * allocation Rx burst function. If any of Rx queues doesn't meet them
3177 : : * the feature should be disabled for the whole port.
3178 : : */
3179 [ # # ]: 0 : if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
3180 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Rx Bulk Alloc "
3181 : : "preconditions - canceling the feature for "
3182 : : "the whole port[%d]",
3183 : : rxq->queue_id, rxq->port_id);
3184 : 0 : adapter->rx_bulk_alloc_allowed = false;
3185 : : }
3186 : :
3187 : : /*
3188 : : * Allocate software ring. Allow for space at the end of the
3189 : : * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
3190 : : * function does not access an invalid memory region.
3191 : : */
3192 : : len = nb_desc;
3193 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
3194 : 0 : len += RTE_PMD_IXGBE_RX_MAX_BURST;
3195 : :
3196 : 0 : rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
3197 : : sizeof(struct ixgbe_rx_entry) * len,
3198 : : RTE_CACHE_LINE_SIZE, socket_id);
3199 [ # # ]: 0 : if (!rxq->sw_ring) {
3200 : 0 : ixgbe_rx_queue_release(rxq);
3201 : 0 : return -ENOMEM;
3202 : : }
3203 : :
3204 : : /*
3205 : : * Always allocate even if it's not going to be needed in order to
3206 : : * simplify the code.
3207 : : *
3208 : : * This ring is used in LRO and Scattered Rx cases and Scattered Rx may
3209 : : * be requested in ixgbe_dev_rx_init(), which is called later from
3210 : : * dev_start() flow.
3211 : : */
3212 : 0 : rxq->sw_sc_ring =
3213 : 0 : rte_zmalloc_socket("rxq->sw_sc_ring",
3214 : : sizeof(struct ixgbe_scattered_rx_entry) * len,
3215 : : RTE_CACHE_LINE_SIZE, socket_id);
3216 [ # # ]: 0 : if (!rxq->sw_sc_ring) {
3217 : 0 : ixgbe_rx_queue_release(rxq);
3218 : 0 : return -ENOMEM;
3219 : : }
3220 : :
3221 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p sw_sc_ring=%p hw_ring=%p "
3222 : : "dma_addr=0x%"PRIx64,
3223 : : rxq->sw_ring, rxq->sw_sc_ring, rxq->rx_ring,
3224 : : rxq->rx_ring_phys_addr);
3225 : :
3226 [ # # ]: 0 : if (!rte_is_power_of_2(nb_desc)) {
3227 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
3228 : : "preconditions - canceling the feature for "
3229 : : "the whole port[%d]",
3230 : : rxq->queue_id, rxq->port_id);
3231 : 0 : adapter->rx_vec_allowed = false;
3232 : : } else
3233 : 0 : ixgbe_rxq_vec_setup(rxq);
3234 : :
3235 : 0 : dev->data->rx_queues[queue_idx] = rxq;
3236 : :
3237 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
3238 : :
3239 : 0 : return 0;
3240 : : }
3241 : :
3242 : : uint32_t
3243 : 0 : ixgbe_dev_rx_queue_count(void *rx_queue)
3244 : : {
3245 : : #define IXGBE_RXQ_SCAN_INTERVAL 4
3246 : : volatile union ixgbe_adv_rx_desc *rxdp;
3247 : : struct ixgbe_rx_queue *rxq;
3248 : : uint32_t desc = 0;
3249 : :
3250 : : rxq = rx_queue;
3251 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail]);
3252 : :
3253 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
3254 [ # # ]: 0 : (rxdp->wb.upper.status_error &
3255 : : rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD))) {
3256 : 0 : desc += IXGBE_RXQ_SCAN_INTERVAL;
3257 : 0 : rxdp += IXGBE_RXQ_SCAN_INTERVAL;
3258 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
3259 : 0 : rxdp = &(rxq->rx_ring[rxq->rx_tail +
3260 : 0 : desc - rxq->nb_rx_desc]);
3261 : : }
3262 : :
3263 : 0 : return desc;
3264 : : }
3265 : :
3266 : : int
3267 : 0 : ixgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
3268 : : {
3269 : : struct ixgbe_rx_queue *rxq = rx_queue;
3270 : : volatile uint32_t *status;
3271 : : uint32_t nb_hold, desc;
3272 : :
3273 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
3274 : : return -EINVAL;
3275 : :
3276 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
3277 [ # # ]: 0 : if (rxq->rx_using_sse)
3278 : 0 : nb_hold = rxq->rxrearm_nb;
3279 : : else
3280 : : #endif
3281 : 0 : nb_hold = rxq->nb_rx_hold;
3282 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - nb_hold)
3283 : : return RTE_ETH_RX_DESC_UNAVAIL;
3284 : :
3285 : 0 : desc = rxq->rx_tail + offset;
3286 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
3287 : 0 : desc -= rxq->nb_rx_desc;
3288 : :
3289 : 0 : status = &rxq->rx_ring[desc].wb.upper.status_error;
3290 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD))
3291 : 0 : return RTE_ETH_RX_DESC_DONE;
3292 : :
3293 : : return RTE_ETH_RX_DESC_AVAIL;
3294 : : }
3295 : :
3296 : : int
3297 : 0 : ixgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
3298 : : {
3299 : : struct ci_tx_queue *txq = tx_queue;
3300 : : volatile uint32_t *status;
3301 : : uint32_t desc;
3302 : :
3303 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
3304 : : return -EINVAL;
3305 : :
3306 : 0 : desc = txq->tx_tail + offset;
3307 : : /* go to next desc that has the RS bit */
3308 : 0 : desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
3309 : : txq->tx_rs_thresh;
3310 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
3311 : 0 : desc -= txq->nb_tx_desc;
3312 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
3313 : 0 : desc -= txq->nb_tx_desc;
3314 : : }
3315 : :
3316 : 0 : status = &txq->ixgbe_tx_ring[desc].wb.status;
3317 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(IXGBE_ADVTXD_STAT_DD))
3318 : 0 : return RTE_ETH_TX_DESC_DONE;
3319 : :
3320 : : return RTE_ETH_TX_DESC_FULL;
3321 : : }
3322 : :
3323 : : /*
3324 : : * Set up link loopback for X540/X550 mode Tx->Rx.
3325 : : */
3326 : : static inline void __rte_cold
3327 : 0 : ixgbe_setup_loopback_link_x540_x550(struct ixgbe_hw *hw, bool enable)
3328 : : {
3329 : : uint32_t macc;
3330 : 0 : PMD_INIT_FUNC_TRACE();
3331 : :
3332 : 0 : u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
3333 : :
3334 : 0 : hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
3335 : : IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
3336 : 0 : macc = IXGBE_READ_REG(hw, IXGBE_MACC);
3337 : :
3338 [ # # ]: 0 : if (enable) {
3339 : : /* datasheet 15.2.1: disable AUTONEG (PHY Bit 7.0.C) */
3340 : 0 : autoneg_reg |= IXGBE_MII_AUTONEG_ENABLE;
3341 : : /* datasheet 15.2.1: MACC.FLU = 1 (force link up) */
3342 : 0 : macc |= IXGBE_MACC_FLU;
3343 : : } else {
3344 : 0 : autoneg_reg &= ~IXGBE_MII_AUTONEG_ENABLE;
3345 : 0 : macc &= ~IXGBE_MACC_FLU;
3346 : : }
3347 : :
3348 : 0 : hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
3349 : : IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
3350 : :
3351 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MACC, macc);
3352 : 0 : }
3353 : :
3354 : : void __rte_cold
3355 : 0 : ixgbe_dev_clear_queues(struct rte_eth_dev *dev)
3356 : : {
3357 : : unsigned i;
3358 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
3359 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3360 : :
3361 : 0 : PMD_INIT_FUNC_TRACE();
3362 : :
3363 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3364 : 0 : struct ci_tx_queue *txq = dev->data->tx_queues[i];
3365 : :
3366 [ # # ]: 0 : if (txq != NULL) {
3367 : 0 : ci_txq_release_all_mbufs(txq, false);
3368 : 0 : txq->ops->reset(txq);
3369 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3370 : : }
3371 : : }
3372 : :
3373 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3374 : 0 : struct ixgbe_rx_queue *rxq = dev->data->rx_queues[i];
3375 : :
3376 [ # # ]: 0 : if (rxq != NULL) {
3377 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
3378 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
3379 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3380 : : }
3381 : : }
3382 : : /* If loopback mode was enabled, reconfigure the link accordingly */
3383 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
3384 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X540 ||
3385 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
3386 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
3387 : : hw->mac.type == ixgbe_mac_X550EM_a)
3388 : 0 : ixgbe_setup_loopback_link_x540_x550(hw, false);
3389 : : }
3390 : 0 : }
3391 : :
3392 : : void
3393 : 0 : ixgbe_dev_free_queues(struct rte_eth_dev *dev)
3394 : : {
3395 : : unsigned i;
3396 : :
3397 : 0 : PMD_INIT_FUNC_TRACE();
3398 : :
3399 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3400 : 0 : ixgbe_dev_rx_queue_release(dev, i);
3401 : 0 : dev->data->rx_queues[i] = NULL;
3402 : : }
3403 : 0 : dev->data->nb_rx_queues = 0;
3404 : :
3405 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3406 : 0 : ixgbe_dev_tx_queue_release(dev, i);
3407 : 0 : dev->data->tx_queues[i] = NULL;
3408 : : }
3409 : 0 : dev->data->nb_tx_queues = 0;
3410 : 0 : }
3411 : :
3412 : : /*********************************************************************
3413 : : *
3414 : : * Device RX/TX init functions
3415 : : *
3416 : : **********************************************************************/
3417 : :
3418 : : /**
3419 : : * Receive Side Scaling (RSS)
3420 : : * See section 7.1.2.8 in the following document:
3421 : : * "Intel 82599 10 GbE Controller Datasheet" - Revision 2.1 October 2009
3422 : : *
3423 : : * Principles:
3424 : : * The source and destination IP addresses of the IP header and the source
3425 : : * and destination ports of TCP/UDP headers, if any, of received packets are
3426 : : * hashed against a configurable random key to compute a 32-bit RSS hash result.
3427 : : * The seven (7) LSBs of the 32-bit hash result are used as an index into a
3428 : : * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
3429 : : * RSS output index which is used as the RX queue index where to store the
3430 : : * received packets.
3431 : : * The following output is supplied in the RX write-back descriptor:
3432 : : * - 32-bit result of the Microsoft RSS hash function,
3433 : : * - 4-bit RSS type field.
3434 : : */
3435 : :
3436 : : /*
3437 : : * RSS random key supplied in section 7.1.2.8.3 of the Intel 82599 datasheet.
3438 : : * Used as the default key.
3439 : : */
3440 : : static uint8_t rss_intel_key[40] = {
3441 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
3442 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
3443 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
3444 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
3445 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
3446 : : };
3447 : :
3448 : : /*
3449 : : * This function removes the rss configuration in the mrqe field of MRQC
3450 : : * register and tries to maintain other configurations in the field, such
3451 : : * DCB and Virtualization.
3452 : : *
3453 : : * The MRQC register supplied in section 8.2.3.7.12 of the Intel 82599
3454 : : * datasheet. From the datasheet, we know that the mrqe field is an enum. So,
3455 : : * masking the mrqe field with '~IXGBE_MRQC_RSSEN' may not completely disable
3456 : : * rss configuration. For example, the value of mrqe is equal to 0101b when DCB
3457 : : * and RSS with 4 TCs configured, however 'mrqe &= ~0x01' is equal to 0100b
3458 : : * which corresponds to DCB and RSS with 8 TCs.
3459 : : */
3460 : : static void
3461 : 0 : ixgbe_mrqc_rss_remove(struct ixgbe_hw *hw)
3462 : : {
3463 : : uint32_t mrqc;
3464 : : uint32_t mrqc_reg;
3465 : : uint32_t mrqe_val;
3466 : :
3467 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3468 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3469 : 0 : mrqe_val = mrqc & IXGBE_MRQC_MRQE_MASK;
3470 : :
3471 [ # # # # : 0 : switch (mrqe_val) {
# # ]
3472 : 0 : case IXGBE_MRQC_RSSEN:
3473 : : /* Completely disable rss */
3474 : : mrqe_val = 0;
3475 : 0 : break;
3476 : 0 : case IXGBE_MRQC_RTRSS8TCEN:
3477 : : mrqe_val = IXGBE_MRQC_RT8TCEN;
3478 : 0 : break;
3479 : 0 : case IXGBE_MRQC_RTRSS4TCEN:
3480 : : mrqe_val = IXGBE_MRQC_RT4TCEN;
3481 : 0 : break;
3482 : 0 : case IXGBE_MRQC_VMDQRSS64EN:
3483 : : mrqe_val = IXGBE_MRQC_VMDQEN;
3484 : 0 : break;
3485 : 0 : case IXGBE_MRQC_VMDQRSS32EN:
3486 : 0 : PMD_DRV_LOG(WARNING, "There is no regression for virtualization"
3487 : : " and RSS with 32 pools among the MRQE configurations"
3488 : : " after removing RSS, and left it unchanged.");
3489 : 0 : break;
3490 : : default:
3491 : : /* No rss configured, leave it as it is */
3492 : : break;
3493 : : }
3494 : 0 : mrqc = (mrqc & ~IXGBE_MRQC_MRQE_MASK) | mrqe_val;
3495 : 0 : IXGBE_WRITE_REG(hw, mrqc_reg, mrqc);
3496 : 0 : }
3497 : :
3498 : : static void
3499 : : ixgbe_rss_disable(struct rte_eth_dev *dev)
3500 : : {
3501 : : struct ixgbe_hw *hw;
3502 : :
3503 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3504 : : /* Remove the rss configuration and maintain the other configurations */
3505 : 0 : ixgbe_mrqc_rss_remove(hw);
3506 : 0 : }
3507 : :
3508 : : /*
3509 : : * This function checks whether the rss is enabled or not by comparing the mrqe
3510 : : * field with some RSS related enums and also considers the configurations for
3511 : : * DCB + RSS and Virtualization + RSS. It is necessary for getting the correct
3512 : : * rss hash configurations from the RSS Field Enable field of MRQC register
3513 : : * when both RSS and DCB/VMDQ are used.
3514 : : */
3515 : : static bool
3516 : 0 : ixgbe_rss_enabled(struct ixgbe_hw *hw)
3517 : : {
3518 : : uint32_t mrqc;
3519 : : uint32_t mrqc_reg;
3520 : : uint32_t mrqe_val;
3521 : :
3522 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3523 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3524 : 0 : mrqe_val = mrqc & IXGBE_MRQC_MRQE_MASK;
3525 : :
3526 : 0 : if (mrqe_val == IXGBE_MRQC_RSSEN ||
3527 [ # # ]: 0 : mrqe_val == IXGBE_MRQC_RTRSS8TCEN ||
3528 : 0 : mrqe_val == IXGBE_MRQC_RTRSS4TCEN ||
3529 [ # # # # ]: 0 : mrqe_val == IXGBE_MRQC_VMDQRSS64EN ||
3530 : : mrqe_val == IXGBE_MRQC_VMDQRSS32EN)
3531 : 0 : return true;
3532 : :
3533 : : return false;
3534 : : }
3535 : :
3536 : : static void
3537 : 0 : ixgbe_hw_rss_hash_set(struct ixgbe_hw *hw, struct rte_eth_rss_conf *rss_conf)
3538 : : {
3539 : : uint8_t *hash_key;
3540 : : uint32_t mrqc;
3541 : : uint32_t rss_key;
3542 : : uint64_t rss_hf;
3543 : : uint16_t i;
3544 : : uint32_t mrqc_reg;
3545 : : uint32_t rssrk_reg;
3546 : :
3547 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3548 : 0 : rssrk_reg = ixgbe_rssrk_reg_get(hw->mac.type, 0);
3549 : :
3550 : 0 : hash_key = rss_conf->rss_key;
3551 [ # # ]: 0 : if (hash_key != NULL) {
3552 : : /* Fill in RSS hash key */
3553 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3554 : 0 : rss_key = hash_key[(i * 4)];
3555 : 0 : rss_key |= hash_key[(i * 4) + 1] << 8;
3556 : 0 : rss_key |= hash_key[(i * 4) + 2] << 16;
3557 : 0 : rss_key |= hash_key[(i * 4) + 3] << 24;
3558 : 0 : IXGBE_WRITE_REG_ARRAY(hw, rssrk_reg, i, rss_key);
3559 : : }
3560 : : }
3561 : :
3562 : : /* Set configured hashing protocols in MRQC register */
3563 : 0 : rss_hf = rss_conf->rss_hf;
3564 : : mrqc = IXGBE_MRQC_RSSEN; /* Enable RSS */
3565 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
3566 : : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4;
3567 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
3568 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_TCP;
3569 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
3570 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6;
3571 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_EX)
3572 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX;
3573 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
3574 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
3575 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
3576 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP;
3577 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
3578 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3579 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
3580 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3581 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
3582 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
3583 : 0 : IXGBE_WRITE_REG(hw, mrqc_reg, mrqc);
3584 : 0 : }
3585 : :
3586 : : int
3587 : 0 : ixgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
3588 : : struct rte_eth_rss_conf *rss_conf)
3589 : : {
3590 : : struct ixgbe_hw *hw;
3591 : : uint64_t rss_hf;
3592 : :
3593 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3594 : :
3595 [ # # ]: 0 : if (!ixgbe_rss_update_sp(hw->mac.type)) {
3596 : 0 : PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
3597 : : "NIC.");
3598 : 0 : return -ENOTSUP;
3599 : : }
3600 : :
3601 : : /*
3602 : : * Excerpt from section 7.1.2.8 Receive-Side Scaling (RSS):
3603 : : * "RSS enabling cannot be done dynamically while it must be
3604 : : * preceded by a software reset"
3605 : : * Before changing anything, first check that the update RSS operation
3606 : : * does not attempt to disable RSS, if RSS was enabled at
3607 : : * initialization time, or does not attempt to enable RSS, if RSS was
3608 : : * disabled at initialization time.
3609 : : */
3610 : 0 : rss_hf = rss_conf->rss_hf & IXGBE_RSS_OFFLOAD_ALL;
3611 [ # # ]: 0 : if (!ixgbe_rss_enabled(hw)) { /* RSS disabled */
3612 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
3613 : : return -(EINVAL);
3614 : 0 : return 0; /* Nothing to do */
3615 : : }
3616 : : /* RSS enabled */
3617 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
3618 : : return -(EINVAL);
3619 : 0 : ixgbe_hw_rss_hash_set(hw, rss_conf);
3620 : 0 : return 0;
3621 : : }
3622 : :
3623 : : int
3624 : 0 : ixgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
3625 : : struct rte_eth_rss_conf *rss_conf)
3626 : : {
3627 : : struct ixgbe_hw *hw;
3628 : : uint8_t *hash_key;
3629 : : uint32_t mrqc;
3630 : : uint32_t rss_key;
3631 : : uint64_t rss_hf;
3632 : : uint16_t i;
3633 : : uint32_t mrqc_reg;
3634 : : uint32_t rssrk_reg;
3635 : :
3636 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3637 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3638 : 0 : rssrk_reg = ixgbe_rssrk_reg_get(hw->mac.type, 0);
3639 : 0 : hash_key = rss_conf->rss_key;
3640 [ # # ]: 0 : if (hash_key != NULL) {
3641 : : /* Return RSS hash key */
3642 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3643 : 0 : rss_key = IXGBE_READ_REG_ARRAY(hw, rssrk_reg, i);
3644 : 0 : hash_key[(i * 4)] = rss_key & 0x000000FF;
3645 : 0 : hash_key[(i * 4) + 1] = (rss_key >> 8) & 0x000000FF;
3646 : 0 : hash_key[(i * 4) + 2] = (rss_key >> 16) & 0x000000FF;
3647 : 0 : hash_key[(i * 4) + 3] = (rss_key >> 24) & 0x000000FF;
3648 : : }
3649 : : }
3650 : :
3651 [ # # ]: 0 : if (!ixgbe_rss_enabled(hw)) { /* RSS is disabled */
3652 : 0 : rss_conf->rss_hf = 0;
3653 : 0 : return 0;
3654 : : }
3655 : :
3656 : : /* Get RSS functions configured in MRQC register */
3657 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3658 : :
3659 : : rss_hf = 0;
3660 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4)
3661 : : rss_hf |= RTE_ETH_RSS_IPV4;
3662 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4_TCP)
3663 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
3664 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6)
3665 : 0 : rss_hf |= RTE_ETH_RSS_IPV6;
3666 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX)
3667 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_EX;
3668 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_TCP)
3669 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
3670 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP)
3671 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_TCP_EX;
3672 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4_UDP)
3673 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
3674 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_UDP)
3675 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP;
3676 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP)
3677 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_UDP_EX;
3678 : 0 : rss_conf->rss_hf = rss_hf;
3679 : 0 : return 0;
3680 : : }
3681 : :
3682 : : static void
3683 : 0 : ixgbe_rss_configure(struct rte_eth_dev *dev)
3684 : : {
3685 : : struct rte_eth_rss_conf rss_conf;
3686 : : struct ixgbe_adapter *adapter;
3687 : : struct ixgbe_hw *hw;
3688 : : uint32_t reta;
3689 : : uint16_t i;
3690 : : uint16_t j;
3691 : : uint16_t sp_reta_size;
3692 : : uint32_t reta_reg;
3693 : :
3694 : 0 : PMD_INIT_FUNC_TRACE();
3695 : 0 : adapter = dev->data->dev_private;
3696 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3697 : :
3698 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
3699 : :
3700 : : /*
3701 : : * Fill in redirection table
3702 : : * The byte-swap is needed because NIC registers are in
3703 : : * little-endian order.
3704 : : */
3705 [ # # ]: 0 : if (adapter->rss_reta_updated == 0) {
3706 : : reta = 0;
3707 [ # # ]: 0 : for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
3708 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
3709 : :
3710 [ # # ]: 0 : if (j == dev->data->nb_rx_queues)
3711 : : j = 0;
3712 : 0 : reta = (reta << 8) | j;
3713 [ # # ]: 0 : if ((i & 3) == 3)
3714 [ # # ]: 0 : IXGBE_WRITE_REG(hw, reta_reg,
3715 : : rte_bswap32(reta));
3716 : : }
3717 : : }
3718 : :
3719 : : /*
3720 : : * Configure the RSS key and the RSS protocols used to compute
3721 : : * the RSS hash of input packets.
3722 : : */
3723 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
3724 [ # # ]: 0 : if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
3725 : : ixgbe_rss_disable(dev);
3726 : 0 : return;
3727 : : }
3728 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
3729 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
3730 : 0 : ixgbe_hw_rss_hash_set(hw, &rss_conf);
3731 : : }
3732 : :
3733 : : #define NUM_VFTA_REGISTERS 128
3734 : : #define NIC_RX_BUFFER_SIZE 0x200
3735 : : #define X550_RX_BUFFER_SIZE 0x180
3736 : :
3737 : : static void
3738 : 0 : ixgbe_vmdq_dcb_configure(struct rte_eth_dev *dev)
3739 : : {
3740 : : struct rte_eth_vmdq_dcb_conf *cfg;
3741 : : struct ixgbe_hw *hw;
3742 : : enum rte_eth_nb_pools num_pools;
3743 : : uint32_t mrqc, vt_ctl, queue_mapping, vlanctrl;
3744 : : uint16_t pbsize;
3745 : : uint8_t nb_tcs; /* number of traffic classes */
3746 : : int i;
3747 : :
3748 : 0 : PMD_INIT_FUNC_TRACE();
3749 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3750 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3751 : 0 : num_pools = cfg->nb_queue_pools;
3752 : : /* Check we have a valid number of pools */
3753 [ # # ]: 0 : if (num_pools != RTE_ETH_16_POOLS && num_pools != RTE_ETH_32_POOLS) {
3754 : : ixgbe_rss_disable(dev);
3755 : 0 : return;
3756 : : }
3757 : : /* 16 pools -> 8 traffic classes, 32 pools -> 4 traffic classes */
3758 : 0 : nb_tcs = (uint8_t)(RTE_ETH_VMDQ_DCB_NUM_QUEUES / (int)num_pools);
3759 : :
3760 : : /*
3761 : : * RXPBSIZE
3762 : : * split rx buffer up into sections, each for 1 traffic class
3763 : : */
3764 [ # # ]: 0 : switch (hw->mac.type) {
3765 : 0 : case ixgbe_mac_X550:
3766 : : case ixgbe_mac_X550EM_x:
3767 : : case ixgbe_mac_X550EM_a:
3768 : 0 : pbsize = (uint16_t)(X550_RX_BUFFER_SIZE / nb_tcs);
3769 : 0 : break;
3770 : 0 : default:
3771 : 0 : pbsize = (uint16_t)(NIC_RX_BUFFER_SIZE / nb_tcs);
3772 : 0 : break;
3773 : : }
3774 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3775 : 0 : uint32_t rxpbsize = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
3776 : :
3777 : 0 : rxpbsize &= (~(0x3FF << IXGBE_RXPBSIZE_SHIFT));
3778 : : /* clear 10 bits. */
3779 : 0 : rxpbsize |= (pbsize << IXGBE_RXPBSIZE_SHIFT); /* set value */
3780 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
3781 : : }
3782 : : /* zero alloc all unused TCs */
3783 [ # # ]: 0 : for (i = nb_tcs; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3784 : 0 : uint32_t rxpbsize = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
3785 : :
3786 : 0 : rxpbsize &= (~(0x3FF << IXGBE_RXPBSIZE_SHIFT));
3787 : : /* clear 10 bits. */
3788 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
3789 : : }
3790 : :
3791 : : /* MRQC: enable vmdq and dcb */
3792 : : mrqc = (num_pools == RTE_ETH_16_POOLS) ?
3793 [ # # ]: 0 : IXGBE_MRQC_VMDQRT8TCEN : IXGBE_MRQC_VMDQRT4TCEN;
3794 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3795 : :
3796 : : /* PFVTCTL: turn on virtualisation and set the default pool */
3797 : : vt_ctl = IXGBE_VT_CTL_VT_ENABLE | IXGBE_VT_CTL_REPLEN;
3798 [ # # ]: 0 : if (cfg->enable_default_pool) {
3799 : 0 : vt_ctl |= (cfg->default_pool << IXGBE_VT_CTL_POOL_SHIFT);
3800 : : } else {
3801 : : vt_ctl |= IXGBE_VT_CTL_DIS_DEFPL;
3802 : : }
3803 : :
3804 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vt_ctl);
3805 : :
3806 : : /* RTRUP2TC: mapping user priorities to traffic classes (TCs) */
3807 : : queue_mapping = 0;
3808 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
3809 : : /*
3810 : : * mapping is done with 3 bits per priority,
3811 : : * so shift by i*3 each time
3812 : : */
3813 : 0 : queue_mapping |= ((cfg->dcb_tc[i] & 0x07) << (i * 3));
3814 : :
3815 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, queue_mapping);
3816 : :
3817 : : /* RTRPCS: DCB related */
3818 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, IXGBE_RMCS_RRM);
3819 : :
3820 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
3821 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3822 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
3823 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
3824 : :
3825 : : /* VFTA - enable all vlan filters */
3826 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++) {
3827 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
3828 : : }
3829 : :
3830 : : /* VFRE: pool enabling for receive - 16 or 32 */
3831 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(0),
3832 : : num_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3833 : :
3834 : : /*
3835 : : * MPSAR - allow pools to read specific mac addresses
3836 : : * In this case, all pools should be able to read from mac addr 0
3837 : : */
3838 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(0), 0xFFFFFFFF);
3839 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(0), 0xFFFFFFFF);
3840 : :
3841 : : /* PFVLVF, PFVLVFB: set up filters for vlan tags as configured */
3842 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
3843 : : /* set vlan id in VF register and set the valid bit */
3844 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), (IXGBE_VLVF_VIEN |
3845 : : (cfg->pool_map[i].vlan_id & 0xFFF)));
3846 : : /*
3847 : : * Put the allowed pools in VFB reg. As we only have 16 or 32
3848 : : * pools, we only need to use the first half of the register
3849 : : * i.e. bits 0-31
3850 : : */
3851 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB(i*2), cfg->pool_map[i].pools);
3852 : : }
3853 : : }
3854 : :
3855 : : /**
3856 : : * ixgbe_dcb_config_tx_hw_config - Configure general DCB TX parameters
3857 : : * @dev: pointer to eth_dev structure
3858 : : * @dcb_config: pointer to ixgbe_dcb_config structure
3859 : : */
3860 : : static void
3861 : 0 : ixgbe_dcb_tx_hw_config(struct rte_eth_dev *dev,
3862 : : struct ixgbe_dcb_config *dcb_config)
3863 : : {
3864 : : uint32_t reg;
3865 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3866 : :
3867 : 0 : PMD_INIT_FUNC_TRACE();
3868 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
3869 : : /* Disable the Tx desc arbiter so that MTQC can be changed */
3870 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3871 : 0 : reg |= IXGBE_RTTDCS_ARBDIS;
3872 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
3873 : :
3874 : : /* Enable DCB for Tx with 8 TCs */
3875 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8) {
3876 : : reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3877 : : } else {
3878 : : reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3879 : : }
3880 [ # # ]: 0 : if (dcb_config->vt_mode)
3881 : 0 : reg |= IXGBE_MTQC_VT_ENA;
3882 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
3883 : :
3884 : : /* Enable the Tx desc arbiter */
3885 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3886 : 0 : reg &= ~IXGBE_RTTDCS_ARBDIS;
3887 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
3888 : :
3889 : : /* Enable Security TX Buffer IFG for DCB */
3890 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3891 : 0 : reg |= IXGBE_SECTX_DCB;
3892 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
3893 : : }
3894 : 0 : }
3895 : :
3896 : : /**
3897 : : * ixgbe_vmdq_dcb_hw_tx_config - Configure general VMDQ+DCB TX parameters
3898 : : * @dev: pointer to rte_eth_dev structure
3899 : : * @dcb_config: pointer to ixgbe_dcb_config structure
3900 : : */
3901 : : static void
3902 : 0 : ixgbe_vmdq_dcb_hw_tx_config(struct rte_eth_dev *dev,
3903 : : struct ixgbe_dcb_config *dcb_config)
3904 : : {
3905 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3906 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3907 : : struct ixgbe_hw *hw =
3908 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3909 : :
3910 : 0 : PMD_INIT_FUNC_TRACE();
3911 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB)
3912 : : /*PF VF Transmit Enable*/
3913 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(0),
3914 : : vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3915 : :
3916 : : /*Configure general DCB TX parameters*/
3917 : 0 : ixgbe_dcb_tx_hw_config(dev, dcb_config);
3918 : 0 : }
3919 : :
3920 : : static void
3921 : 0 : ixgbe_vmdq_dcb_rx_config(struct rte_eth_dev *dev,
3922 : : struct ixgbe_dcb_config *dcb_config)
3923 : : {
3924 : : struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
3925 : 0 : &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3926 : : struct ixgbe_dcb_tc_config *tc;
3927 : : uint8_t i, j;
3928 : :
3929 : : /* convert rte_eth_conf.rx_adv_conf to struct ixgbe_dcb_config */
3930 [ # # ]: 0 : if (vmdq_rx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
3931 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
3932 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
3933 : : } else {
3934 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
3935 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
3936 : : }
3937 : :
3938 : : /* Initialize User Priority to Traffic Class mapping */
3939 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
3940 : 0 : tc = &dcb_config->tc_config[j];
3941 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3942 : : }
3943 : :
3944 : : /* User Priority to Traffic Class mapping */
3945 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3946 : 0 : j = vmdq_rx_conf->dcb_tc[i];
3947 : 0 : tc = &dcb_config->tc_config[j];
3948 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3949 : 0 : (uint8_t)(1 << i);
3950 : : }
3951 : 0 : }
3952 : :
3953 : : static void
3954 : 0 : ixgbe_dcb_vt_tx_config(struct rte_eth_dev *dev,
3955 : : struct ixgbe_dcb_config *dcb_config)
3956 : : {
3957 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3958 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3959 : : struct ixgbe_dcb_tc_config *tc;
3960 : : uint8_t i, j;
3961 : :
3962 : : /* convert rte_eth_conf.rx_adv_conf to struct ixgbe_dcb_config */
3963 [ # # ]: 0 : if (vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
3964 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
3965 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
3966 : : } else {
3967 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
3968 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
3969 : : }
3970 : :
3971 : : /* Initialize User Priority to Traffic Class mapping */
3972 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
3973 : 0 : tc = &dcb_config->tc_config[j];
3974 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3975 : : }
3976 : :
3977 : : /* User Priority to Traffic Class mapping */
3978 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3979 : 0 : j = vmdq_tx_conf->dcb_tc[i];
3980 : 0 : tc = &dcb_config->tc_config[j];
3981 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3982 : 0 : (uint8_t)(1 << i);
3983 : : }
3984 : 0 : }
3985 : :
3986 : : static void
3987 : : ixgbe_dcb_rx_config(struct rte_eth_dev *dev,
3988 : : struct ixgbe_dcb_config *dcb_config)
3989 : : {
3990 : : struct rte_eth_dcb_rx_conf *rx_conf =
3991 : : &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
3992 : : struct ixgbe_dcb_tc_config *tc;
3993 : : uint8_t i, j;
3994 : :
3995 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)rx_conf->nb_tcs;
3996 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)rx_conf->nb_tcs;
3997 : :
3998 : : /* Initialize User Priority to Traffic Class mapping */
3999 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4000 : 0 : tc = &dcb_config->tc_config[j];
4001 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
4002 : : }
4003 : :
4004 : : /* User Priority to Traffic Class mapping */
4005 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4006 : 0 : j = rx_conf->dcb_tc[i];
4007 : 0 : tc = &dcb_config->tc_config[j];
4008 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
4009 : 0 : (uint8_t)(1 << i);
4010 : : }
4011 : : }
4012 : :
4013 : : static void
4014 : : ixgbe_dcb_tx_config(struct rte_eth_dev *dev,
4015 : : struct ixgbe_dcb_config *dcb_config)
4016 : : {
4017 : : struct rte_eth_dcb_tx_conf *tx_conf =
4018 : : &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
4019 : : struct ixgbe_dcb_tc_config *tc;
4020 : : uint8_t i, j;
4021 : :
4022 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)tx_conf->nb_tcs;
4023 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)tx_conf->nb_tcs;
4024 : :
4025 : : /* Initialize User Priority to Traffic Class mapping */
4026 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4027 : 0 : tc = &dcb_config->tc_config[j];
4028 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
4029 : : }
4030 : :
4031 : : /* User Priority to Traffic Class mapping */
4032 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4033 : 0 : j = tx_conf->dcb_tc[i];
4034 : 0 : tc = &dcb_config->tc_config[j];
4035 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
4036 : 0 : (uint8_t)(1 << i);
4037 : : }
4038 : : }
4039 : :
4040 : : /**
4041 : : * ixgbe_dcb_rx_hw_config - Configure general DCB RX HW parameters
4042 : : * @dev: pointer to eth_dev structure
4043 : : * @dcb_config: pointer to ixgbe_dcb_config structure
4044 : : */
4045 : : static void
4046 : 0 : ixgbe_dcb_rx_hw_config(struct rte_eth_dev *dev,
4047 : : struct ixgbe_dcb_config *dcb_config)
4048 : : {
4049 : : uint32_t reg;
4050 : : uint32_t vlanctrl;
4051 : : uint8_t i;
4052 : : uint32_t q;
4053 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4054 : :
4055 : 0 : PMD_INIT_FUNC_TRACE();
4056 : : /*
4057 : : * Disable the arbiter before changing parameters
4058 : : * (always enable recycle mode; WSP)
4059 : : */
4060 : : reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS;
4061 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
4062 : :
4063 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
4064 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
4065 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 4) {
4066 [ # # ]: 0 : if (dcb_config->vt_mode)
4067 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4068 : : IXGBE_MRQC_VMDQRT4TCEN;
4069 : : else {
4070 : : /* no matter the mode is DCB or DCB_RSS, just
4071 : : * set the MRQE to RSSXTCEN. RSS is controlled
4072 : : * by RSS_FIELD
4073 : : */
4074 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, 0);
4075 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4076 : : IXGBE_MRQC_RTRSS4TCEN;
4077 : : }
4078 : : }
4079 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8) {
4080 [ # # ]: 0 : if (dcb_config->vt_mode)
4081 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4082 : : IXGBE_MRQC_VMDQRT8TCEN;
4083 : : else {
4084 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, 0);
4085 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4086 : : IXGBE_MRQC_RTRSS8TCEN;
4087 : : }
4088 : : }
4089 : :
4090 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, reg);
4091 : :
4092 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4093 : : /* Disable drop for all queues in VMDQ mode*/
4094 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4095 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4096 : : (IXGBE_QDE_WRITE |
4097 : : (q << IXGBE_QDE_IDX_SHIFT)));
4098 : : } else {
4099 : : /* Enable drop for all queues in SRIOV mode */
4100 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4101 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4102 : : (IXGBE_QDE_WRITE |
4103 : : (q << IXGBE_QDE_IDX_SHIFT) |
4104 : : IXGBE_QDE_ENABLE));
4105 : : }
4106 : : }
4107 : :
4108 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
4109 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4110 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
4111 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
4112 : :
4113 : : /* VFTA - enable all vlan filters */
4114 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++) {
4115 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
4116 : : }
4117 : :
4118 : : /*
4119 : : * Configure Rx packet plane (recycle mode; WSP) and
4120 : : * enable arbiter
4121 : : */
4122 : : reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
4123 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
4124 : 0 : }
4125 : :
4126 : : static void
4127 : 0 : ixgbe_dcb_hw_arbite_rx_config(struct ixgbe_hw *hw, uint16_t *refill,
4128 : : uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
4129 : : {
4130 [ # # # ]: 0 : switch (hw->mac.type) {
4131 : 0 : case ixgbe_mac_82598EB:
4132 : 0 : ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, tsa);
4133 : 0 : break;
4134 : 0 : case ixgbe_mac_82599EB:
4135 : : case ixgbe_mac_X540:
4136 : : case ixgbe_mac_X550:
4137 : : case ixgbe_mac_X550EM_x:
4138 : : case ixgbe_mac_X550EM_a:
4139 : 0 : ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
4140 : : tsa, map);
4141 : 0 : break;
4142 : : default:
4143 : : break;
4144 : : }
4145 : 0 : }
4146 : :
4147 : : static void
4148 : 0 : ixgbe_dcb_hw_arbite_tx_config(struct ixgbe_hw *hw, uint16_t *refill, uint16_t *max,
4149 : : uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
4150 : : {
4151 [ # # # ]: 0 : switch (hw->mac.type) {
4152 : 0 : case ixgbe_mac_82598EB:
4153 : 0 : ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, bwg_id, tsa);
4154 : 0 : ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, bwg_id, tsa);
4155 : 0 : break;
4156 : 0 : case ixgbe_mac_82599EB:
4157 : : case ixgbe_mac_X540:
4158 : : case ixgbe_mac_X550:
4159 : : case ixgbe_mac_X550EM_x:
4160 : : case ixgbe_mac_X550EM_a:
4161 : 0 : ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, bwg_id, tsa);
4162 : 0 : ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id, tsa, map);
4163 : 0 : break;
4164 : : default:
4165 : : break;
4166 : : }
4167 : 0 : }
4168 : :
4169 : : #define DCB_RX_CONFIG 1
4170 : : #define DCB_TX_CONFIG 1
4171 : : #define DCB_TX_PB 1024
4172 : : /**
4173 : : * ixgbe_dcb_hw_configure - Enable DCB and configure
4174 : : * general DCB in VT mode and non-VT mode parameters
4175 : : * @dev: pointer to rte_eth_dev structure
4176 : : * @dcb_config: pointer to ixgbe_dcb_config structure
4177 : : */
4178 : : static int
4179 : 0 : ixgbe_dcb_hw_configure(struct rte_eth_dev *dev,
4180 : : struct ixgbe_dcb_config *dcb_config)
4181 : : {
4182 : : int ret = 0;
4183 : : uint8_t i, pfc_en, nb_tcs;
4184 : : uint16_t pbsize, rx_buffer_size;
4185 : : uint8_t config_dcb_rx = 0;
4186 : : uint8_t config_dcb_tx = 0;
4187 : 0 : uint8_t tsa[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4188 : 0 : uint8_t bwgid[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4189 : 0 : uint16_t refill[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4190 : 0 : uint16_t max[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4191 : 0 : uint8_t map[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4192 : : struct ixgbe_dcb_tc_config *tc;
4193 : 0 : uint32_t max_frame = dev->data->mtu + RTE_ETHER_HDR_LEN +
4194 : : RTE_ETHER_CRC_LEN;
4195 : 0 : struct ixgbe_hw *hw =
4196 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4197 : : struct ixgbe_bw_conf *bw_conf =
4198 : : IXGBE_DEV_PRIVATE_TO_BW_CONF(dev->data->dev_private);
4199 : :
4200 [ # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4201 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4202 : 0 : dcb_config->vt_mode = true;
4203 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
4204 : : config_dcb_rx = DCB_RX_CONFIG;
4205 : : /*
4206 : : *get dcb and VT rx configuration parameters
4207 : : *from rte_eth_conf
4208 : : */
4209 : 0 : ixgbe_vmdq_dcb_rx_config(dev, dcb_config);
4210 : : /*Configure general VMDQ and DCB RX parameters*/
4211 : 0 : ixgbe_vmdq_dcb_configure(dev);
4212 : : }
4213 : : break;
4214 : 0 : case RTE_ETH_MQ_RX_DCB:
4215 : : case RTE_ETH_MQ_RX_DCB_RSS:
4216 : 0 : dcb_config->vt_mode = false;
4217 : : config_dcb_rx = DCB_RX_CONFIG;
4218 : : /* Get dcb TX configuration parameters from rte_eth_conf */
4219 : : ixgbe_dcb_rx_config(dev, dcb_config);
4220 : : /*Configure general DCB RX parameters*/
4221 : 0 : ixgbe_dcb_rx_hw_config(dev, dcb_config);
4222 : 0 : break;
4223 : 0 : default:
4224 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB RX mode configuration");
4225 : 0 : break;
4226 : : }
4227 [ # # # ]: 0 : switch (dev->data->dev_conf.txmode.mq_mode) {
4228 : 0 : case RTE_ETH_MQ_TX_VMDQ_DCB:
4229 : 0 : dcb_config->vt_mode = true;
4230 : : config_dcb_tx = DCB_TX_CONFIG;
4231 : : /* get DCB and VT TX configuration parameters
4232 : : * from rte_eth_conf
4233 : : */
4234 : 0 : ixgbe_dcb_vt_tx_config(dev, dcb_config);
4235 : : /*Configure general VMDQ and DCB TX parameters*/
4236 : 0 : ixgbe_vmdq_dcb_hw_tx_config(dev, dcb_config);
4237 : 0 : break;
4238 : :
4239 : 0 : case RTE_ETH_MQ_TX_DCB:
4240 : 0 : dcb_config->vt_mode = false;
4241 : : config_dcb_tx = DCB_TX_CONFIG;
4242 : : /*get DCB TX configuration parameters from rte_eth_conf*/
4243 : : ixgbe_dcb_tx_config(dev, dcb_config);
4244 : : /*Configure general DCB TX parameters*/
4245 : 0 : ixgbe_dcb_tx_hw_config(dev, dcb_config);
4246 : 0 : break;
4247 : 0 : default:
4248 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB TX mode configuration");
4249 : 0 : break;
4250 : : }
4251 : :
4252 : 0 : nb_tcs = dcb_config->num_tcs.pfc_tcs;
4253 : : /* Unpack map */
4254 : 0 : ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
4255 [ # # ]: 0 : if (nb_tcs == RTE_ETH_4_TCS) {
4256 : : /* Avoid un-configured priority mapping to TC0 */
4257 : : uint8_t j = 4;
4258 : : uint8_t mask = 0xFF;
4259 : :
4260 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES - 4; i++)
4261 : 0 : mask = (uint8_t)(mask & (~(1 << map[i])));
4262 [ # # ]: 0 : for (i = 0; mask && (i < IXGBE_DCB_MAX_TRAFFIC_CLASS); i++) {
4263 [ # # # # ]: 0 : if ((mask & 0x1) && j < RTE_ETH_DCB_NUM_USER_PRIORITIES)
4264 : 0 : map[j++] = i;
4265 : 0 : mask >>= 1;
4266 : : }
4267 : : /* Re-configure 4 TCs BW */
4268 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4269 : 0 : tc = &dcb_config->tc_config[i];
4270 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
4271 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
4272 : : (uint8_t)(100 / nb_tcs);
4273 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
4274 : : (uint8_t)(100 / nb_tcs);
4275 : : }
4276 [ # # ]: 0 : for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
4277 : 0 : tc = &dcb_config->tc_config[i];
4278 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = 0;
4279 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent = 0;
4280 : : }
4281 : : } else {
4282 : : /* Re-configure 8 TCs BW */
4283 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4284 : 0 : tc = &dcb_config->tc_config[i];
4285 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
4286 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
4287 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
4288 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
4289 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
4290 : : }
4291 : : }
4292 : :
4293 [ # # ]: 0 : switch (hw->mac.type) {
4294 : : case ixgbe_mac_X550:
4295 : : case ixgbe_mac_X550EM_x:
4296 : : case ixgbe_mac_X550EM_a:
4297 : : rx_buffer_size = X550_RX_BUFFER_SIZE;
4298 : : break;
4299 : 0 : default:
4300 : : rx_buffer_size = NIC_RX_BUFFER_SIZE;
4301 : 0 : break;
4302 : : }
4303 : :
4304 [ # # ]: 0 : if (config_dcb_rx) {
4305 : : /* Set RX buffer size */
4306 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
4307 : 0 : uint32_t rxpbsize = pbsize << IXGBE_RXPBSIZE_SHIFT;
4308 : :
4309 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4310 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
4311 : : }
4312 : : /* zero alloc all unused TCs */
4313 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
4314 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
4315 : : }
4316 [ # # ]: 0 : if (config_dcb_tx) {
4317 : : /* Only support an equally distributed
4318 : : * Tx packet buffer strategy.
4319 : : */
4320 : 0 : uint32_t txpktsize = IXGBE_TXPBSIZE_MAX / nb_tcs;
4321 : 0 : uint32_t txpbthresh = (txpktsize / DCB_TX_PB) - IXGBE_TXPKT_SIZE_MAX;
4322 : :
4323 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4324 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
4325 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
4326 : : }
4327 : : /* Clear unused TCs, if any, to zero buffer size*/
4328 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4329 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
4330 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
4331 : : }
4332 : : }
4333 : :
4334 : : /*Calculates traffic class credits*/
4335 : 0 : ixgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
4336 : : IXGBE_DCB_TX_CONFIG);
4337 : 0 : ixgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
4338 : : IXGBE_DCB_RX_CONFIG);
4339 : :
4340 [ # # ]: 0 : if (config_dcb_rx) {
4341 : : /* Unpack CEE standard containers */
4342 : 0 : ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_RX_CONFIG, refill);
4343 : 0 : ixgbe_dcb_unpack_max_cee(dcb_config, max);
4344 : 0 : ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_RX_CONFIG, bwgid);
4345 : 0 : ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_RX_CONFIG, tsa);
4346 : : /* Configure PG(ETS) RX */
4347 : 0 : ixgbe_dcb_hw_arbite_rx_config(hw, refill, max, bwgid, tsa, map);
4348 : : }
4349 : :
4350 [ # # ]: 0 : if (config_dcb_tx) {
4351 : : /* Unpack CEE standard containers */
4352 : 0 : ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_TX_CONFIG, refill);
4353 : 0 : ixgbe_dcb_unpack_max_cee(dcb_config, max);
4354 : 0 : ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_TX_CONFIG, bwgid);
4355 : 0 : ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_TX_CONFIG, tsa);
4356 : : /* Configure PG(ETS) TX */
4357 : 0 : ixgbe_dcb_hw_arbite_tx_config(hw, refill, max, bwgid, tsa, map);
4358 : : }
4359 : :
4360 : : /*Configure queue statistics registers*/
4361 : 0 : ixgbe_dcb_config_tc_stats_82599(hw, dcb_config);
4362 : :
4363 : : /* Check if the PFC is supported */
4364 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
4365 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
4366 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4367 : : /*
4368 : : * If the TC count is 8,and the default high_water is 48,
4369 : : * the low_water is 16 as default.
4370 : : */
4371 : 0 : hw->fc.high_water[i] = (pbsize * 3) / 4;
4372 : 0 : hw->fc.low_water[i] = pbsize / 4;
4373 : : /* Enable pfc for this TC */
4374 : : tc = &dcb_config->tc_config[i];
4375 : 0 : tc->pfc = ixgbe_dcb_pfc_enabled;
4376 : : }
4377 : 0 : ixgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
4378 [ # # ]: 0 : if (dcb_config->num_tcs.pfc_tcs == RTE_ETH_4_TCS)
4379 : 0 : pfc_en &= 0x0F;
4380 : 0 : ret = ixgbe_dcb_config_pfc(hw, pfc_en, map);
4381 : : }
4382 : :
4383 : 0 : return ret;
4384 : : }
4385 : :
4386 : : /**
4387 : : * ixgbe_configure_dcb - Configure DCB Hardware
4388 : : * @dev: pointer to rte_eth_dev
4389 : : */
4390 : 0 : void ixgbe_configure_dcb(struct rte_eth_dev *dev)
4391 : : {
4392 : 0 : struct ixgbe_dcb_config *dcb_cfg =
4393 : 0 : IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
4394 : : struct rte_eth_conf *dev_conf = &(dev->data->dev_conf);
4395 : :
4396 : 0 : PMD_INIT_FUNC_TRACE();
4397 : :
4398 : : /* check support mq_mode for DCB */
4399 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_VMDQ_DCB &&
4400 [ # # ]: 0 : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB &&
4401 : : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB_RSS)
4402 : : return;
4403 : :
4404 [ # # ]: 0 : if (dev->data->nb_rx_queues > RTE_ETH_DCB_NUM_QUEUES)
4405 : : return;
4406 : :
4407 : : /** Configure DCB hardware **/
4408 : 0 : ixgbe_dcb_hw_configure(dev, dcb_cfg);
4409 : : }
4410 : :
4411 : : /*
4412 : : * VMDq only support for 10 GbE NIC.
4413 : : */
4414 : : static void
4415 : 0 : ixgbe_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
4416 : : {
4417 : : struct rte_eth_vmdq_rx_conf *cfg;
4418 : : struct ixgbe_hw *hw;
4419 : : enum rte_eth_nb_pools num_pools;
4420 : : uint32_t mrqc, vt_ctl, vlanctrl;
4421 : : uint32_t vmolr = 0;
4422 : : int i;
4423 : :
4424 : 0 : PMD_INIT_FUNC_TRACE();
4425 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4426 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
4427 : 0 : num_pools = cfg->nb_queue_pools;
4428 : :
4429 : : ixgbe_rss_disable(dev);
4430 : :
4431 : : /* MRQC: enable vmdq */
4432 : : mrqc = IXGBE_MRQC_VMDQEN;
4433 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4434 : :
4435 : : /* PFVTCTL: turn on virtualisation and set the default pool */
4436 : : vt_ctl = IXGBE_VT_CTL_VT_ENABLE | IXGBE_VT_CTL_REPLEN;
4437 [ # # ]: 0 : if (cfg->enable_default_pool)
4438 : 0 : vt_ctl |= (cfg->default_pool << IXGBE_VT_CTL_POOL_SHIFT);
4439 : : else
4440 : : vt_ctl |= IXGBE_VT_CTL_DIS_DEFPL;
4441 : :
4442 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vt_ctl);
4443 : :
4444 [ # # ]: 0 : for (i = 0; i < (int)num_pools; i++) {
4445 : 0 : vmolr = ixgbe_convert_vm_rx_mask_to_val(cfg->rx_mode, vmolr);
4446 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(i), vmolr);
4447 : : }
4448 : :
4449 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
4450 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4451 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
4452 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
4453 : :
4454 : : /* VFTA - enable all vlan filters */
4455 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++)
4456 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), UINT32_MAX);
4457 : :
4458 : : /* VFRE: pool enabling for receive - 64 */
4459 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), UINT32_MAX);
4460 [ # # ]: 0 : if (num_pools == RTE_ETH_64_POOLS)
4461 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), UINT32_MAX);
4462 : :
4463 : : /*
4464 : : * MPSAR - allow pools to read specific mac addresses
4465 : : * In this case, all pools should be able to read from mac addr 0
4466 : : */
4467 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(0), UINT32_MAX);
4468 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(0), UINT32_MAX);
4469 : :
4470 : : /* PFVLVF, PFVLVFB: set up filters for vlan tags as configured */
4471 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
4472 : : /* set vlan id in VF register and set the valid bit */
4473 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), (IXGBE_VLVF_VIEN |
4474 : : (cfg->pool_map[i].vlan_id & IXGBE_RXD_VLAN_ID_MASK)));
4475 : : /*
4476 : : * Put the allowed pools in VFB reg. As we only have 16 or 64
4477 : : * pools, we only need to use the first half of the register
4478 : : * i.e. bits 0-31
4479 : : */
4480 [ # # ]: 0 : if (((cfg->pool_map[i].pools >> 32) & UINT32_MAX) == 0)
4481 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB(i * 2),
4482 : : (cfg->pool_map[i].pools & UINT32_MAX));
4483 : : else
4484 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB((i * 2 + 1)),
4485 : : ((cfg->pool_map[i].pools >> 32) & UINT32_MAX));
4486 : :
4487 : : }
4488 : :
4489 : : /* PFDMA Tx General Switch Control Enables VMDQ loopback */
4490 [ # # ]: 0 : if (cfg->enable_loop_back) {
4491 : 0 : IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
4492 [ # # ]: 0 : for (i = 0; i < RTE_IXGBE_VMTXSW_REGISTER_COUNT; i++)
4493 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMTXSW(i), UINT32_MAX);
4494 : : }
4495 : :
4496 : 0 : IXGBE_WRITE_FLUSH(hw);
4497 : 0 : }
4498 : :
4499 : : /*
4500 : : * ixgbe_dcb_config_tx_hw_config - Configure general VMDq TX parameters
4501 : : * @hw: pointer to hardware structure
4502 : : */
4503 : : static void
4504 : 0 : ixgbe_vmdq_tx_hw_configure(struct ixgbe_hw *hw)
4505 : : {
4506 : : uint32_t reg;
4507 : : uint32_t q;
4508 : :
4509 : 0 : PMD_INIT_FUNC_TRACE();
4510 : : /*PF VF Transmit Enable*/
4511 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), UINT32_MAX);
4512 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), UINT32_MAX);
4513 : :
4514 : : /* Disable the Tx desc arbiter so that MTQC can be changed */
4515 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4516 : 0 : reg |= IXGBE_RTTDCS_ARBDIS;
4517 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
4518 : :
4519 : : reg = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF;
4520 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
4521 : :
4522 : : /* Disable drop for all queues */
4523 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4524 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4525 : : (IXGBE_QDE_WRITE | (q << IXGBE_QDE_IDX_SHIFT)));
4526 : :
4527 : : /* Enable the Tx desc arbiter */
4528 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4529 : 0 : reg &= ~IXGBE_RTTDCS_ARBDIS;
4530 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
4531 : :
4532 : 0 : IXGBE_WRITE_FLUSH(hw);
4533 : 0 : }
4534 : :
4535 : : static int __rte_cold
4536 : 0 : ixgbe_alloc_rx_queue_mbufs(struct ixgbe_rx_queue *rxq)
4537 : : {
4538 : 0 : struct ixgbe_rx_entry *rxe = rxq->sw_ring;
4539 : : uint64_t dma_addr;
4540 : : unsigned int i;
4541 : :
4542 : : /* Initialize software ring entries */
4543 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
4544 : : volatile union ixgbe_adv_rx_desc *rxd;
4545 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
4546 : :
4547 [ # # ]: 0 : if (mbuf == NULL) {
4548 : 0 : PMD_INIT_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
4549 : : (unsigned) rxq->queue_id);
4550 : 0 : return -ENOMEM;
4551 : : }
4552 : :
4553 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
4554 : 0 : mbuf->port = rxq->port_id;
4555 : :
4556 : : dma_addr =
4557 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
4558 : 0 : rxd = &rxq->rx_ring[i];
4559 : 0 : rxd->read.hdr_addr = 0;
4560 : 0 : rxd->read.pkt_addr = dma_addr;
4561 : 0 : rxe[i].mbuf = mbuf;
4562 : : }
4563 : :
4564 : : return 0;
4565 : : }
4566 : :
4567 : : static int
4568 : 0 : ixgbe_config_vf_rss(struct rte_eth_dev *dev)
4569 : : {
4570 : : struct ixgbe_hw *hw;
4571 : : uint32_t mrqc;
4572 : :
4573 : 0 : ixgbe_rss_configure(dev);
4574 : :
4575 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4576 : :
4577 : : /* MRQC: enable VF RSS */
4578 : 0 : mrqc = IXGBE_READ_REG(hw, IXGBE_MRQC);
4579 : 0 : mrqc &= ~IXGBE_MRQC_MRQE_MASK;
4580 [ # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4581 : 0 : case RTE_ETH_64_POOLS:
4582 : 0 : mrqc |= IXGBE_MRQC_VMDQRSS64EN;
4583 : 0 : break;
4584 : :
4585 : 0 : case RTE_ETH_32_POOLS:
4586 : 0 : mrqc |= IXGBE_MRQC_VMDQRSS32EN;
4587 : 0 : break;
4588 : :
4589 : 0 : default:
4590 : 0 : PMD_INIT_LOG(ERR, "Invalid pool number in IOV mode with VMDQ RSS");
4591 : 0 : return -EINVAL;
4592 : : }
4593 : :
4594 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4595 : :
4596 : 0 : return 0;
4597 : : }
4598 : :
4599 : : static int
4600 : 0 : ixgbe_config_vf_default(struct rte_eth_dev *dev)
4601 : : {
4602 : : struct ixgbe_hw *hw =
4603 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4604 : :
4605 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4606 : 0 : case RTE_ETH_64_POOLS:
4607 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4608 : : IXGBE_MRQC_VMDQEN);
4609 : : break;
4610 : :
4611 : 0 : case RTE_ETH_32_POOLS:
4612 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4613 : : IXGBE_MRQC_VMDQRT4TCEN);
4614 : : break;
4615 : :
4616 : 0 : case RTE_ETH_16_POOLS:
4617 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4618 : : IXGBE_MRQC_VMDQRT8TCEN);
4619 : : break;
4620 : 0 : default:
4621 : 0 : PMD_INIT_LOG(ERR,
4622 : : "invalid pool number in IOV mode");
4623 : 0 : break;
4624 : : }
4625 : 0 : return 0;
4626 : : }
4627 : :
4628 : : static int
4629 : 0 : ixgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
4630 : : {
4631 : : struct ixgbe_hw *hw =
4632 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4633 : :
4634 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
4635 : : return 0;
4636 : :
4637 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4638 : : /*
4639 : : * SRIOV inactive scheme
4640 : : * any DCB/RSS w/o VMDq multi-queue setting
4641 : : */
4642 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4643 : 0 : case RTE_ETH_MQ_RX_RSS:
4644 : : case RTE_ETH_MQ_RX_DCB_RSS:
4645 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4646 : 0 : ixgbe_rss_configure(dev);
4647 : 0 : break;
4648 : :
4649 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4650 : 0 : ixgbe_vmdq_dcb_configure(dev);
4651 : 0 : break;
4652 : :
4653 : 0 : case RTE_ETH_MQ_RX_VMDQ_ONLY:
4654 : 0 : ixgbe_vmdq_rx_hw_configure(dev);
4655 : 0 : break;
4656 : :
4657 : : case RTE_ETH_MQ_RX_NONE:
4658 : : default:
4659 : : /* if mq_mode is none, disable rss mode.*/
4660 : : ixgbe_rss_disable(dev);
4661 : : break;
4662 : : }
4663 : : } else {
4664 : : /* SRIOV active scheme
4665 : : * Support RSS together with SRIOV.
4666 : : */
4667 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4668 : 0 : case RTE_ETH_MQ_RX_RSS:
4669 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4670 : 0 : ixgbe_config_vf_rss(dev);
4671 : 0 : break;
4672 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4673 : : case RTE_ETH_MQ_RX_DCB:
4674 : : /* In SRIOV, the configuration is the same as VMDq case */
4675 : 0 : ixgbe_vmdq_dcb_configure(dev);
4676 : 0 : break;
4677 : : /* DCB/RSS together with SRIOV is not supported */
4678 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB_RSS:
4679 : : case RTE_ETH_MQ_RX_DCB_RSS:
4680 : 0 : PMD_INIT_LOG(ERR,
4681 : : "Could not support DCB/RSS with VMDq & SRIOV");
4682 : 0 : return -1;
4683 : 0 : default:
4684 : 0 : ixgbe_config_vf_default(dev);
4685 : 0 : break;
4686 : : }
4687 : : }
4688 : :
4689 : : return 0;
4690 : : }
4691 : :
4692 : : static int
4693 : 0 : ixgbe_dev_mq_tx_configure(struct rte_eth_dev *dev)
4694 : : {
4695 : 0 : struct ixgbe_hw *hw =
4696 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4697 : : uint32_t mtqc;
4698 : : uint32_t rttdcs;
4699 : :
4700 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
4701 : : return 0;
4702 : :
4703 : : /* disable arbiter before setting MTQC */
4704 : 0 : rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4705 : 0 : rttdcs |= IXGBE_RTTDCS_ARBDIS;
4706 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
4707 : :
4708 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4709 : : /*
4710 : : * SRIOV inactive scheme
4711 : : * any DCB w/o VMDq multi-queue setting
4712 : : */
4713 [ # # ]: 0 : if (dev->data->dev_conf.txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_ONLY)
4714 : 0 : ixgbe_vmdq_tx_hw_configure(hw);
4715 : : else {
4716 : : mtqc = IXGBE_MTQC_64Q_1PB;
4717 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
4718 : : }
4719 : : } else {
4720 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4721 : :
4722 : : /*
4723 : : * SRIOV active scheme
4724 : : * FIXME if support DCB together with VMDq & SRIOV
4725 : : */
4726 : : case RTE_ETH_64_POOLS:
4727 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF;
4728 : : break;
4729 : 0 : case RTE_ETH_32_POOLS:
4730 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_32VF;
4731 : 0 : break;
4732 : 0 : case RTE_ETH_16_POOLS:
4733 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_RT_ENA |
4734 : : IXGBE_MTQC_8TC_8TQ;
4735 : 0 : break;
4736 : 0 : default:
4737 : : mtqc = IXGBE_MTQC_64Q_1PB;
4738 : 0 : PMD_INIT_LOG(ERR, "invalid pool number in IOV mode");
4739 : : }
4740 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
4741 : : }
4742 : :
4743 : : /* re-enable arbiter */
4744 : : rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
4745 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
4746 : :
4747 : 0 : return 0;
4748 : : }
4749 : :
4750 : : /**
4751 : : * ixgbe_get_rscctl_maxdesc - Calculate the RSCCTL[n].MAXDESC for PF
4752 : : *
4753 : : * Return the RSCCTL[n].MAXDESC for 82599 and x540 PF devices according to the
4754 : : * spec rev. 3.0 chapter 8.2.3.8.13.
4755 : : *
4756 : : * @pool Memory pool of the Rx queue
4757 : : */
4758 : : static inline uint32_t
4759 : : ixgbe_get_rscctl_maxdesc(struct rte_mempool *pool)
4760 : : {
4761 : : struct rte_pktmbuf_pool_private *mp_priv = rte_mempool_get_priv(pool);
4762 : :
4763 : : /* MAXDESC * SRRCTL.BSIZEPKT must not exceed 64 KB minus one */
4764 : 0 : uint16_t maxdesc =
4765 : 0 : RTE_IPV4_MAX_PKT_LEN /
4766 : 0 : (mp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
4767 : :
4768 [ # # ]: 0 : if (maxdesc >= 16)
4769 : : return IXGBE_RSCCTL_MAXDESC_16;
4770 [ # # ]: 0 : else if (maxdesc >= 8)
4771 : : return IXGBE_RSCCTL_MAXDESC_8;
4772 [ # # ]: 0 : else if (maxdesc >= 4)
4773 : : return IXGBE_RSCCTL_MAXDESC_4;
4774 : : else
4775 : 0 : return IXGBE_RSCCTL_MAXDESC_1;
4776 : : }
4777 : :
4778 : : /**
4779 : : * ixgbe_set_ivar - Setup the correct IVAR register for a particular MSIX
4780 : : * interrupt
4781 : : *
4782 : : * (Taken from FreeBSD tree)
4783 : : * (yes this is all very magic and confusing :)
4784 : : *
4785 : : * @dev port handle
4786 : : * @entry the register array entry
4787 : : * @vector the MSIX vector for this queue
4788 : : * @type RX/TX/MISC
4789 : : */
4790 : : static void
4791 : 0 : ixgbe_set_ivar(struct rte_eth_dev *dev, u8 entry, u8 vector, s8 type)
4792 : : {
4793 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4794 : : u32 ivar, index;
4795 : :
4796 : 0 : vector |= IXGBE_IVAR_ALLOC_VAL;
4797 : :
4798 [ # # # ]: 0 : switch (hw->mac.type) {
4799 : :
4800 : 0 : case ixgbe_mac_82598EB:
4801 [ # # ]: 0 : if (type == -1)
4802 : : entry = IXGBE_IVAR_OTHER_CAUSES_INDEX;
4803 : : else
4804 : 0 : entry += (type * 64);
4805 : 0 : index = (entry >> 2) & 0x1F;
4806 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
4807 : 0 : ivar &= ~(0xFF << (8 * (entry & 0x3)));
4808 : 0 : ivar |= (vector << (8 * (entry & 0x3)));
4809 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
4810 : : break;
4811 : :
4812 : 0 : case ixgbe_mac_82599EB:
4813 : : case ixgbe_mac_X540:
4814 [ # # ]: 0 : if (type == -1) { /* MISC IVAR */
4815 : 0 : index = (entry & 1) * 8;
4816 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4817 : 0 : ivar &= ~(0xFF << index);
4818 : 0 : ivar |= (vector << index);
4819 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar);
4820 : : } else { /* RX/TX IVARS */
4821 : 0 : index = (16 * (entry & 1)) + (8 * type);
4822 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1));
4823 : 0 : ivar &= ~(0xFF << index);
4824 : 0 : ivar |= (vector << index);
4825 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar);
4826 : : }
4827 : :
4828 : : break;
4829 : :
4830 : : default:
4831 : : break;
4832 : : }
4833 : 0 : }
4834 : :
4835 : : void __rte_cold
4836 : 0 : ixgbe_set_rx_function(struct rte_eth_dev *dev)
4837 : : {
4838 : : uint16_t i, rx_using_sse;
4839 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
4840 : :
4841 : : /*
4842 : : * In order to allow Vector Rx there are a few configuration
4843 : : * conditions to be met and Rx Bulk Allocation should be allowed.
4844 : : */
4845 [ # # ]: 0 : if (ixgbe_rx_vec_dev_conf_condition_check(dev) ||
4846 [ # # # # ]: 0 : !adapter->rx_bulk_alloc_allowed ||
4847 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
4848 : 0 : PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet Vector Rx "
4849 : : "preconditions",
4850 : : dev->data->port_id);
4851 : :
4852 : 0 : adapter->rx_vec_allowed = false;
4853 : : }
4854 : :
4855 : : /*
4856 : : * Initialize the appropriate LRO callback.
4857 : : *
4858 : : * If all queues satisfy the bulk allocation preconditions
4859 : : * (hw->rx_bulk_alloc_allowed is TRUE) then we may use bulk allocation.
4860 : : * Otherwise use a single allocation version.
4861 : : */
4862 [ # # ]: 0 : if (dev->data->lro) {
4863 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed) {
4864 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a bulk "
4865 : : "allocation version");
4866 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_bulk_alloc;
4867 : : } else {
4868 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a single "
4869 : : "allocation version");
4870 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_single_alloc;
4871 : : }
4872 [ # # ]: 0 : } else if (dev->data->scattered_rx) {
4873 : : /*
4874 : : * Set the non-LRO scattered callback: there are Vector and
4875 : : * single allocation versions.
4876 : : */
4877 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
4878 : 0 : PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx "
4879 : : "callback (port=%d).",
4880 : : dev->data->port_id);
4881 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
4882 : 0 : dev->recycle_rx_descriptors_refill =
4883 : : ixgbe_recycle_rx_descriptors_refill_vec;
4884 : : #endif
4885 : 0 : dev->rx_pkt_burst = ixgbe_recv_scattered_pkts_vec;
4886 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
4887 : 0 : PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
4888 : : "allocation callback (port=%d).",
4889 : : dev->data->port_id);
4890 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_bulk_alloc;
4891 : : } else {
4892 : 0 : PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
4893 : : "single allocation) "
4894 : : "Scattered Rx callback "
4895 : : "(port=%d).",
4896 : : dev->data->port_id);
4897 : :
4898 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_single_alloc;
4899 : : }
4900 : : /*
4901 : : * Below we set "simple" callbacks according to port/queues parameters.
4902 : : * If parameters allow we are going to choose between the following
4903 : : * callbacks:
4904 : : * - Vector
4905 : : * - Bulk Allocation
4906 : : * - Single buffer allocation (the simplest one)
4907 : : */
4908 [ # # ]: 0 : } else if (adapter->rx_vec_allowed) {
4909 : 0 : PMD_INIT_LOG(DEBUG, "Vector rx enabled, please make sure RX "
4910 : : "burst size no less than %d (port=%d).",
4911 : : RTE_IXGBE_DESCS_PER_LOOP,
4912 : : dev->data->port_id);
4913 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
4914 : 0 : dev->recycle_rx_descriptors_refill = ixgbe_recycle_rx_descriptors_refill_vec;
4915 : : #endif
4916 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_vec;
4917 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
4918 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
4919 : : "satisfied. Rx Burst Bulk Alloc function "
4920 : : "will be used on port=%d.",
4921 : : dev->data->port_id);
4922 : :
4923 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_bulk_alloc;
4924 : : } else {
4925 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
4926 : : "satisfied, or Scattered Rx is requested "
4927 : : "(port=%d).",
4928 : : dev->data->port_id);
4929 : :
4930 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts;
4931 : : }
4932 : :
4933 : : /* Propagate information about RX function choice through all queues. */
4934 : :
4935 : : rx_using_sse =
4936 [ # # # # ]: 0 : (dev->rx_pkt_burst == ixgbe_recv_scattered_pkts_vec ||
4937 : : dev->rx_pkt_burst == ixgbe_recv_pkts_vec);
4938 : :
4939 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
4940 : 0 : struct ixgbe_rx_queue *rxq = dev->data->rx_queues[i];
4941 : :
4942 : 0 : rxq->rx_using_sse = rx_using_sse;
4943 : : #ifdef RTE_LIB_SECURITY
4944 : 0 : rxq->using_ipsec = !!(dev->data->dev_conf.rxmode.offloads &
4945 : : RTE_ETH_RX_OFFLOAD_SECURITY);
4946 : : #endif
4947 : : }
4948 : 0 : }
4949 : :
4950 : : /**
4951 : : * ixgbe_set_rsc - configure RSC related port HW registers
4952 : : *
4953 : : * Configures the port's RSC related registers according to the 4.6.7.2 chapter
4954 : : * of 82599 Spec (x540 configuration is virtually the same).
4955 : : *
4956 : : * @dev port handle
4957 : : *
4958 : : * Returns 0 in case of success or a non-zero error code
4959 : : */
4960 : : static int
4961 : 0 : ixgbe_set_rsc(struct rte_eth_dev *dev)
4962 : : {
4963 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4964 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4965 : 0 : struct rte_eth_dev_info dev_info = { 0 };
4966 : : bool rsc_capable = false;
4967 : : uint16_t i;
4968 : : uint32_t rdrxctl;
4969 : : uint32_t rfctl;
4970 : :
4971 : : /* Sanity check */
4972 : 0 : dev->dev_ops->dev_infos_get(dev, &dev_info);
4973 [ # # ]: 0 : if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO)
4974 : : rsc_capable = true;
4975 : :
4976 [ # # ]: 0 : if (!rsc_capable && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
4977 : 0 : PMD_INIT_LOG(CRIT, "LRO is requested on HW that doesn't "
4978 : : "support it");
4979 : 0 : return -EINVAL;
4980 : : }
4981 : :
4982 : : /* RSC global configuration (chapter 4.6.7.2.1 of 82599 Spec) */
4983 : :
4984 [ # # ]: 0 : if ((rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) &&
4985 : : (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
4986 : : /*
4987 : : * According to chapter of 4.6.7.2.1 of the Spec Rev.
4988 : : * 3.0 RSC configuration requires HW CRC stripping being
4989 : : * enabled. If user requested both HW CRC stripping off
4990 : : * and RSC on - return an error.
4991 : : */
4992 : 0 : PMD_INIT_LOG(CRIT, "LRO can't be enabled when HW CRC "
4993 : : "is disabled");
4994 : 0 : return -EINVAL;
4995 : : }
4996 : :
4997 : : /* RFCTL configuration */
4998 : 0 : rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4999 [ # # # # ]: 0 : if ((rsc_capable) && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
5000 : 0 : rfctl &= ~IXGBE_RFCTL_RSC_DIS;
5001 : : else
5002 : 0 : rfctl |= IXGBE_RFCTL_RSC_DIS;
5003 : : /* disable NFS filtering */
5004 : 0 : rfctl |= IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS;
5005 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
5006 : :
5007 : : /* If LRO hasn't been requested - we are done here. */
5008 [ # # ]: 0 : if (!(rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
5009 : : return 0;
5010 : :
5011 : : /* Set RDRXCTL.RSCACKC bit */
5012 : 0 : rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
5013 : 0 : rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
5014 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
5015 : :
5016 : : /* Per-queue RSC configuration (chapter 4.6.7.2.2 of 82599 Spec) */
5017 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5018 : 0 : struct ixgbe_rx_queue *rxq = dev->data->rx_queues[i];
5019 : : uint32_t srrctl =
5020 [ # # # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_SRRCTL(rxq->reg_idx));
5021 : : uint32_t rscctl =
5022 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxq->reg_idx));
5023 : : uint32_t psrtype =
5024 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_PSRTYPE(rxq->reg_idx));
5025 : : uint32_t eitr =
5026 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_EITR(rxq->reg_idx));
5027 : :
5028 : : /*
5029 : : * ixgbe PMD doesn't support header-split at the moment.
5030 : : *
5031 : : * Following the 4.6.7.2.1 chapter of the 82599/x540
5032 : : * Spec if RSC is enabled the SRRCTL[n].BSIZEHEADER
5033 : : * should be configured even if header split is not
5034 : : * enabled. We will configure it 128 bytes following the
5035 : : * recommendation in the spec.
5036 : : */
5037 : 0 : srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
5038 : 0 : srrctl |= (128 << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
5039 : : IXGBE_SRRCTL_BSIZEHDR_MASK;
5040 : :
5041 : : /*
5042 : : * TODO: Consider setting the Receive Descriptor Minimum
5043 : : * Threshold Size for an RSC case. This is not an obviously
5044 : : * beneficiary option but the one worth considering...
5045 : : */
5046 : :
5047 : 0 : rscctl |= IXGBE_RSCCTL_RSCEN;
5048 [ # # ]: 0 : rscctl |= ixgbe_get_rscctl_maxdesc(rxq->mb_pool);
5049 : 0 : psrtype |= IXGBE_PSRTYPE_TCPHDR;
5050 : :
5051 : : /*
5052 : : * RSC: Set ITR interval corresponding to 2K ints/s.
5053 : : *
5054 : : * Full-sized RSC aggregations for a 10Gb/s link will
5055 : : * arrive at about 20K aggregation/s rate.
5056 : : *
5057 : : * 2K inst/s rate will make only 10% of the
5058 : : * aggregations to be closed due to the interrupt timer
5059 : : * expiration for a streaming at wire-speed case.
5060 : : *
5061 : : * For a sparse streaming case this setting will yield
5062 : : * at most 500us latency for a single RSC aggregation.
5063 : : */
5064 : 0 : eitr &= ~IXGBE_EITR_ITR_INT_MASK;
5065 : : eitr |= IXGBE_EITR_INTERVAL_US(IXGBE_QUEUE_ITR_INTERVAL_DEFAULT);
5066 : 0 : eitr |= IXGBE_EITR_CNT_WDIS;
5067 : :
5068 [ # # # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxq->reg_idx), srrctl);
5069 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(rxq->reg_idx), rscctl);
5070 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(rxq->reg_idx), psrtype);
5071 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_EITR(rxq->reg_idx), eitr);
5072 : :
5073 : : /*
5074 : : * RSC requires the mapping of the queue to the
5075 : : * interrupt vector.
5076 : : */
5077 : 0 : ixgbe_set_ivar(dev, rxq->reg_idx, i, 0);
5078 : : }
5079 : :
5080 : 0 : dev->data->lro = 1;
5081 : :
5082 : 0 : PMD_INIT_LOG(DEBUG, "enabling LRO mode");
5083 : :
5084 : 0 : return 0;
5085 : : }
5086 : :
5087 : : /*
5088 : : * Initializes Receive Unit.
5089 : : */
5090 : : int __rte_cold
5091 : 0 : ixgbe_dev_rx_init(struct rte_eth_dev *dev)
5092 : : {
5093 : : struct ixgbe_hw *hw;
5094 : : struct ixgbe_rx_queue *rxq;
5095 : : uint64_t bus_addr;
5096 : : uint32_t rxctrl;
5097 : : uint32_t fctrl;
5098 : : uint32_t hlreg0;
5099 : : uint32_t maxfrs;
5100 : : uint32_t srrctl;
5101 : : uint32_t rdrxctl;
5102 : : uint32_t rxcsum;
5103 : : uint16_t buf_size;
5104 : : uint16_t i;
5105 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
5106 : 0 : uint32_t frame_size = dev->data->mtu + IXGBE_ETH_OVERHEAD;
5107 : : int rc;
5108 : :
5109 : 0 : PMD_INIT_FUNC_TRACE();
5110 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5111 : :
5112 : : /*
5113 : : * Make sure receives are disabled while setting
5114 : : * up the RX context (registers, descriptor rings, etc.).
5115 : : */
5116 : 0 : rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5117 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
5118 : :
5119 : : /* Enable receipt of broadcasted frames */
5120 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5121 : : fctrl |= IXGBE_FCTRL_BAM;
5122 : : fctrl |= IXGBE_FCTRL_DPF;
5123 : 0 : fctrl |= IXGBE_FCTRL_PMCF;
5124 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5125 : :
5126 : : /*
5127 : : * Configure CRC stripping, if any.
5128 : : */
5129 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
5130 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5131 : 0 : hlreg0 &= ~IXGBE_HLREG0_RXCRCSTRP;
5132 : : else
5133 : 0 : hlreg0 |= IXGBE_HLREG0_RXCRCSTRP;
5134 : :
5135 : : /*
5136 : : * Configure jumbo frame support, if any.
5137 : : */
5138 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU) {
5139 : 0 : hlreg0 |= IXGBE_HLREG0_JUMBOEN;
5140 : 0 : maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
5141 : 0 : maxfrs &= 0x0000FFFF;
5142 : 0 : maxfrs |= (frame_size << 16);
5143 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
5144 : : } else
5145 : 0 : hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
5146 : :
5147 : : /*
5148 : : * If loopback mode is configured, set LPBK bit.
5149 : : */
5150 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
5151 : 0 : rc = ixgbe_check_supported_loopback_mode(dev);
5152 [ # # ]: 0 : if (rc < 0) {
5153 : 0 : PMD_INIT_LOG(ERR, "Unsupported loopback mode");
5154 : 0 : return rc;
5155 : : }
5156 : 0 : hlreg0 |= IXGBE_HLREG0_LPBK;
5157 : : } else {
5158 : 0 : hlreg0 &= ~IXGBE_HLREG0_LPBK;
5159 : : }
5160 : :
5161 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
5162 : :
5163 : : /*
5164 : : * Assume no header split and no VLAN strip support
5165 : : * on any Rx queue first .
5166 : : */
5167 : 0 : rx_conf->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5168 : : /* Setup RX queues */
5169 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5170 : 0 : rxq = dev->data->rx_queues[i];
5171 : :
5172 : : /*
5173 : : * Reset crc_len in case it was changed after queue setup by a
5174 : : * call to configure.
5175 : : */
5176 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5177 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
5178 : : else
5179 : 0 : rxq->crc_len = 0;
5180 : :
5181 : : /* Setup the Base and Length of the Rx Descriptor Rings */
5182 : 0 : bus_addr = rxq->rx_ring_phys_addr;
5183 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDBAL(rxq->reg_idx),
5184 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5185 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDBAH(rxq->reg_idx),
5186 : : (uint32_t)(bus_addr >> 32));
5187 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDLEN(rxq->reg_idx),
5188 : : rxq->nb_rx_desc * sizeof(union ixgbe_adv_rx_desc));
5189 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDH(rxq->reg_idx), 0);
5190 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDT(rxq->reg_idx), 0);
5191 : :
5192 : : /* Configure the SRRCTL register */
5193 : : srrctl = IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
5194 : :
5195 : : /* Set if packets are dropped when no descriptors available */
5196 [ # # ]: 0 : if (rxq->drop_en)
5197 : : srrctl |= IXGBE_SRRCTL_DROP_EN;
5198 : :
5199 : : /*
5200 : : * Configure the RX buffer size in the BSIZEPACKET field of
5201 : : * the SRRCTL register of the queue.
5202 : : * The value is in 1 KB resolution. Valid values can be from
5203 : : * 1 KB to 16 KB.
5204 : : */
5205 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
5206 : : RTE_PKTMBUF_HEADROOM);
5207 : 0 : srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
5208 : : IXGBE_SRRCTL_BSIZEPKT_MASK);
5209 : :
5210 [ # # # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxq->reg_idx), srrctl);
5211 : :
5212 : 0 : buf_size = (uint16_t) ((srrctl & IXGBE_SRRCTL_BSIZEPKT_MASK) <<
5213 : : IXGBE_SRRCTL_BSIZEPKT_SHIFT);
5214 : :
5215 : : /* It adds dual VLAN length for supporting dual VLAN */
5216 [ # # ]: 0 : if (frame_size + 2 * RTE_VLAN_HLEN > buf_size)
5217 : 0 : dev->data->scattered_rx = 1;
5218 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5219 : 0 : rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5220 : : }
5221 : :
5222 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
5223 : 0 : dev->data->scattered_rx = 1;
5224 : :
5225 : : /*
5226 : : * Device configured with multiple RX queues.
5227 : : */
5228 : 0 : ixgbe_dev_mq_rx_configure(dev);
5229 : :
5230 : : /*
5231 : : * Setup the Checksum Register.
5232 : : * Disable Full-Packet Checksum which is mutually exclusive with RSS.
5233 : : * Enable IP/L4 checksum computation by hardware if requested to do so.
5234 : : */
5235 : 0 : rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
5236 : : rxcsum |= IXGBE_RXCSUM_PCSD;
5237 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
5238 : 0 : rxcsum |= IXGBE_RXCSUM_IPPCSE;
5239 : : else
5240 : 0 : rxcsum &= ~IXGBE_RXCSUM_IPPCSE;
5241 : :
5242 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
5243 : :
5244 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
5245 : : hw->mac.type == ixgbe_mac_X540) {
5246 : 0 : rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
5247 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5248 : 0 : rdrxctl &= ~IXGBE_RDRXCTL_CRCSTRIP;
5249 : : else
5250 : 0 : rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
5251 : 0 : rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
5252 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
5253 : : }
5254 : :
5255 : 0 : rc = ixgbe_set_rsc(dev);
5256 [ # # ]: 0 : if (rc)
5257 : : return rc;
5258 : :
5259 : 0 : ixgbe_set_rx_function(dev);
5260 : :
5261 : 0 : return 0;
5262 : : }
5263 : :
5264 : : /*
5265 : : * Initializes Transmit Unit.
5266 : : */
5267 : : void __rte_cold
5268 : 0 : ixgbe_dev_tx_init(struct rte_eth_dev *dev)
5269 : : {
5270 : : struct ixgbe_hw *hw;
5271 : : struct ci_tx_queue *txq;
5272 : : uint64_t bus_addr;
5273 : : uint32_t hlreg0;
5274 : : uint32_t txctrl;
5275 : : uint16_t i;
5276 : :
5277 : 0 : PMD_INIT_FUNC_TRACE();
5278 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5279 : :
5280 : : /* Enable TX CRC (checksum offload requirement) and hw padding
5281 : : * (TSO requirement)
5282 : : */
5283 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
5284 : 0 : hlreg0 |= (IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_TXPADEN);
5285 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
5286 : :
5287 : : /* Setup the Base and Length of the Tx Descriptor Rings */
5288 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5289 : 0 : txq = dev->data->tx_queues[i];
5290 : :
5291 : 0 : bus_addr = txq->tx_ring_dma;
5292 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDBAL(txq->reg_idx),
5293 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5294 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDBAH(txq->reg_idx),
5295 : : (uint32_t)(bus_addr >> 32));
5296 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDLEN(txq->reg_idx),
5297 : : txq->nb_tx_desc * sizeof(union ixgbe_adv_tx_desc));
5298 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
5299 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDH(txq->reg_idx), 0);
5300 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDT(txq->reg_idx), 0);
5301 : :
5302 : : /*
5303 : : * Disable Tx Head Writeback RO bit, since this hoses
5304 : : * bookkeeping if things aren't delivered in order.
5305 : : */
5306 [ # # ]: 0 : switch (hw->mac.type) {
5307 : 0 : case ixgbe_mac_82598EB:
5308 : 0 : txctrl = IXGBE_READ_REG(hw,
5309 : : IXGBE_DCA_TXCTRL(txq->reg_idx));
5310 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5311 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(txq->reg_idx),
5312 : : txctrl);
5313 : : break;
5314 : :
5315 : 0 : case ixgbe_mac_82599EB:
5316 : : case ixgbe_mac_X540:
5317 : : case ixgbe_mac_X550:
5318 : : case ixgbe_mac_X550EM_x:
5319 : : case ixgbe_mac_X550EM_a:
5320 : : default:
5321 : 0 : txctrl = IXGBE_READ_REG(hw,
5322 : : IXGBE_DCA_TXCTRL_82599(txq->reg_idx));
5323 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5324 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(txq->reg_idx),
5325 : : txctrl);
5326 : : break;
5327 : : }
5328 : : }
5329 : :
5330 : : /* Device configured with multiple TX queues. */
5331 : 0 : ixgbe_dev_mq_tx_configure(dev);
5332 : 0 : }
5333 : :
5334 : : /*
5335 : : * Check if requested loopback mode is supported
5336 : : */
5337 : : int
5338 : 0 : ixgbe_check_supported_loopback_mode(struct rte_eth_dev *dev)
5339 : : {
5340 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5341 : :
5342 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_TX_RX)
5343 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
5344 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540 ||
5345 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
5346 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
5347 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
5348 : : hw->mac.type == ixgbe_mac_E610)
5349 : 0 : return 0;
5350 : :
5351 : : return -ENOTSUP;
5352 : : }
5353 : :
5354 : : /*
5355 : : * Set up link for 82599 loopback mode Tx->Rx.
5356 : : */
5357 : : static inline void __rte_cold
5358 : 0 : ixgbe_setup_loopback_link_82599(struct ixgbe_hw *hw)
5359 : : {
5360 : 0 : PMD_INIT_FUNC_TRACE();
5361 : :
5362 [ # # ]: 0 : if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
5363 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM) !=
5364 : : IXGBE_SUCCESS) {
5365 : 0 : PMD_INIT_LOG(ERR, "Could not enable loopback mode");
5366 : : /* ignore error */
5367 : 0 : return;
5368 : : }
5369 : : }
5370 : :
5371 : : /* Restart link */
5372 : 0 : IXGBE_WRITE_REG(hw,
5373 : : IXGBE_AUTOC,
5374 : : IXGBE_AUTOC_LMS_10G_LINK_NO_AN | IXGBE_AUTOC_FLU);
5375 : 0 : ixgbe_reset_pipeline_82599(hw);
5376 : :
5377 : 0 : hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
5378 : 0 : msec_delay(50);
5379 : : }
5380 : :
5381 : :
5382 : : /*
5383 : : * Start Transmit and Receive Units.
5384 : : */
5385 : : int __rte_cold
5386 : 0 : ixgbe_dev_rxtx_start(struct rte_eth_dev *dev)
5387 : : {
5388 : : struct ixgbe_hw *hw;
5389 : : struct ci_tx_queue *txq;
5390 : : struct ixgbe_rx_queue *rxq;
5391 : : uint32_t txdctl;
5392 : : uint32_t dmatxctl;
5393 : : uint32_t rxctrl;
5394 : : uint16_t i;
5395 : : int ret = 0;
5396 : :
5397 : 0 : PMD_INIT_FUNC_TRACE();
5398 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5399 : :
5400 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5401 : 0 : txq = dev->data->tx_queues[i];
5402 : : /* Setup Transmit Threshold Registers */
5403 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5404 : 0 : txdctl |= txq->pthresh & 0x7F;
5405 : 0 : txdctl |= ((txq->hthresh & 0x7F) << 8);
5406 : 0 : txdctl |= ((txq->wthresh & 0x7F) << 16);
5407 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5408 : : }
5409 : :
5410 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
5411 : 0 : dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
5412 : 0 : dmatxctl |= IXGBE_DMATXCTL_TE;
5413 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
5414 : : }
5415 : :
5416 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5417 : 0 : txq = dev->data->tx_queues[i];
5418 [ # # ]: 0 : if (!txq->tx_deferred_start) {
5419 : 0 : ret = ixgbe_dev_tx_queue_start(dev, i);
5420 [ # # ]: 0 : if (ret < 0)
5421 : 0 : return ret;
5422 : : }
5423 : : }
5424 : :
5425 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5426 : 0 : rxq = dev->data->rx_queues[i];
5427 [ # # ]: 0 : if (!rxq->rx_deferred_start) {
5428 : 0 : ret = ixgbe_dev_rx_queue_start(dev, i);
5429 [ # # ]: 0 : if (ret < 0)
5430 : 0 : return ret;
5431 : : }
5432 : : }
5433 : :
5434 : : /* Enable Receive engine */
5435 : 0 : rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5436 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
5437 : 0 : rxctrl |= IXGBE_RXCTRL_DMBYPS;
5438 : 0 : rxctrl |= IXGBE_RXCTRL_RXEN;
5439 : 0 : hw->mac.ops.enable_rx_dma(hw, rxctrl);
5440 : :
5441 : : /* If loopback mode is enabled, set up the link accordingly */
5442 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
5443 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB)
5444 : 0 : ixgbe_setup_loopback_link_82599(hw);
5445 [ # # ]: 0 : else if (hw->mac.type == ixgbe_mac_X540 ||
5446 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
5447 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
5448 : : hw->mac.type == ixgbe_mac_X550EM_a)
5449 : 0 : ixgbe_setup_loopback_link_x540_x550(hw, true);
5450 : : }
5451 : :
5452 : : #ifdef RTE_LIB_SECURITY
5453 [ # # ]: 0 : if ((dev->data->dev_conf.rxmode.offloads &
5454 : 0 : RTE_ETH_RX_OFFLOAD_SECURITY) ||
5455 [ # # ]: 0 : (dev->data->dev_conf.txmode.offloads &
5456 : : RTE_ETH_TX_OFFLOAD_SECURITY)) {
5457 : 0 : ret = ixgbe_crypto_enable_ipsec(dev);
5458 [ # # ]: 0 : if (ret != 0) {
5459 : 0 : PMD_DRV_LOG(ERR,
5460 : : "ixgbe_crypto_enable_ipsec fails with %d.",
5461 : : ret);
5462 : 0 : return ret;
5463 : : }
5464 : : }
5465 : : #endif
5466 : :
5467 : : return 0;
5468 : : }
5469 : :
5470 : : /*
5471 : : * Start Receive Units for specified queue.
5472 : : */
5473 : : int __rte_cold
5474 : 0 : ixgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
5475 : : {
5476 : : struct ixgbe_hw *hw;
5477 : : struct ixgbe_rx_queue *rxq;
5478 : : uint32_t rxdctl;
5479 : : int poll_ms;
5480 : :
5481 : 0 : PMD_INIT_FUNC_TRACE();
5482 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5483 : :
5484 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
5485 : :
5486 : : /* Allocate buffers for descriptor rings */
5487 [ # # ]: 0 : if (ixgbe_alloc_rx_queue_mbufs(rxq) != 0) {
5488 : 0 : PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
5489 : : rx_queue_id);
5490 : 0 : return -1;
5491 : : }
5492 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5493 : 0 : rxdctl |= IXGBE_RXDCTL_ENABLE;
5494 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), rxdctl);
5495 : :
5496 : : /* Wait until RX Enable ready */
5497 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5498 : : do {
5499 : : rte_delay_ms(1);
5500 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5501 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & IXGBE_RXDCTL_ENABLE));
5502 [ # # ]: 0 : if (!poll_ms)
5503 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
5504 : : rte_wmb();
5505 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDH(rxq->reg_idx), 0);
5506 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
5507 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
5508 : :
5509 : 0 : return 0;
5510 : : }
5511 : :
5512 : : /*
5513 : : * Stop Receive Units for specified queue.
5514 : : */
5515 : : int __rte_cold
5516 : 0 : ixgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
5517 : : {
5518 : : struct ixgbe_hw *hw;
5519 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5520 : : struct ixgbe_rx_queue *rxq;
5521 : : uint32_t rxdctl;
5522 : : int poll_ms;
5523 : :
5524 : 0 : PMD_INIT_FUNC_TRACE();
5525 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5526 : :
5527 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
5528 : :
5529 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5530 : 0 : rxdctl &= ~IXGBE_RXDCTL_ENABLE;
5531 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), rxdctl);
5532 : :
5533 : : /* Wait until RX Enable bit clear */
5534 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5535 : : do {
5536 : : rte_delay_ms(1);
5537 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5538 [ # # # # ]: 0 : } while (--poll_ms && (rxdctl & IXGBE_RXDCTL_ENABLE));
5539 [ # # ]: 0 : if (!poll_ms)
5540 : 0 : PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
5541 : :
5542 : 0 : rte_delay_us(RTE_IXGBE_WAIT_100_US);
5543 : :
5544 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
5545 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
5546 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5547 : :
5548 : 0 : return 0;
5549 : : }
5550 : :
5551 : :
5552 : : /*
5553 : : * Start Transmit Units for specified queue.
5554 : : */
5555 : : int __rte_cold
5556 : 0 : ixgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5557 : : {
5558 : : struct ixgbe_hw *hw;
5559 : : struct ci_tx_queue *txq;
5560 : : uint32_t txdctl;
5561 : : int poll_ms;
5562 : :
5563 : 0 : PMD_INIT_FUNC_TRACE();
5564 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5565 : :
5566 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5567 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDH(txq->reg_idx), 0);
5568 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5569 : 0 : txdctl |= IXGBE_TXDCTL_ENABLE;
5570 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5571 : :
5572 : : /* Wait until TX Enable ready */
5573 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5574 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5575 : : do {
5576 : : rte_delay_ms(1);
5577 : 0 : txdctl = IXGBE_READ_REG(hw,
5578 : : IXGBE_TXDCTL(txq->reg_idx));
5579 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & IXGBE_TXDCTL_ENABLE));
5580 [ # # ]: 0 : if (!poll_ms)
5581 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d",
5582 : : tx_queue_id);
5583 : : }
5584 : : rte_wmb();
5585 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDT(txq->reg_idx), 0);
5586 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
5587 : :
5588 : 0 : return 0;
5589 : : }
5590 : :
5591 : : /*
5592 : : * Stop Transmit Units for specified queue.
5593 : : */
5594 : : int __rte_cold
5595 : 0 : ixgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5596 : : {
5597 : : struct ixgbe_hw *hw;
5598 : : struct ci_tx_queue *txq;
5599 : : uint32_t txdctl;
5600 : : uint32_t txtdh, txtdt;
5601 : : int poll_ms;
5602 : :
5603 : 0 : PMD_INIT_FUNC_TRACE();
5604 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5605 : :
5606 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5607 : :
5608 : : /* Wait until TX queue is empty */
5609 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5610 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5611 : : do {
5612 : 0 : rte_delay_us(RTE_IXGBE_WAIT_100_US);
5613 : 0 : txtdh = IXGBE_READ_REG(hw,
5614 : : IXGBE_TDH(txq->reg_idx));
5615 : 0 : txtdt = IXGBE_READ_REG(hw,
5616 : : IXGBE_TDT(txq->reg_idx));
5617 [ # # # # ]: 0 : } while (--poll_ms && (txtdh != txtdt));
5618 [ # # ]: 0 : if (!poll_ms)
5619 : 0 : PMD_INIT_LOG(ERR,
5620 : : "Tx Queue %d is not empty when stopping.",
5621 : : tx_queue_id);
5622 : : }
5623 : :
5624 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5625 : 0 : txdctl &= ~IXGBE_TXDCTL_ENABLE;
5626 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5627 : :
5628 : : /* Wait until TX Enable bit clear */
5629 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5630 : : poll_ms = RTE_IXGBE_REGISTER_POLL_WAIT_10_MS;
5631 : : do {
5632 : : rte_delay_ms(1);
5633 : 0 : txdctl = IXGBE_READ_REG(hw,
5634 : : IXGBE_TXDCTL(txq->reg_idx));
5635 [ # # # # ]: 0 : } while (--poll_ms && (txdctl & IXGBE_TXDCTL_ENABLE));
5636 [ # # ]: 0 : if (!poll_ms)
5637 : 0 : PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
5638 : : tx_queue_id);
5639 : : }
5640 : :
5641 [ # # ]: 0 : if (txq->ops != NULL) {
5642 : 0 : ci_txq_release_all_mbufs(txq, false);
5643 : 0 : txq->ops->reset(txq);
5644 : : }
5645 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5646 : :
5647 : 0 : return 0;
5648 : : }
5649 : :
5650 : : void
5651 : 0 : ixgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5652 : : struct rte_eth_rxq_info *qinfo)
5653 : : {
5654 : : struct ixgbe_rx_queue *rxq;
5655 : :
5656 : 0 : rxq = dev->data->rx_queues[queue_id];
5657 : :
5658 : 0 : qinfo->mp = rxq->mb_pool;
5659 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
5660 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
5661 : :
5662 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
5663 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
5664 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
5665 : 0 : qinfo->conf.offloads = rxq->offloads;
5666 : 0 : }
5667 : :
5668 : : void
5669 : 0 : ixgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5670 : : struct rte_eth_txq_info *qinfo)
5671 : : {
5672 : : struct ci_tx_queue *txq;
5673 : :
5674 : 0 : txq = dev->data->tx_queues[queue_id];
5675 : :
5676 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
5677 : :
5678 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
5679 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
5680 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
5681 : :
5682 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
5683 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
5684 : 0 : qinfo->conf.offloads = txq->offloads;
5685 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
5686 : 0 : }
5687 : :
5688 : : void
5689 : 0 : ixgbe_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5690 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
5691 : : {
5692 : : struct ixgbe_rx_queue *rxq;
5693 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5694 : :
5695 : 0 : rxq = dev->data->rx_queues[queue_id];
5696 : :
5697 : 0 : recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring;
5698 : 0 : recycle_rxq_info->mp = rxq->mb_pool;
5699 : 0 : recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;
5700 : 0 : recycle_rxq_info->receive_tail = &rxq->rx_tail;
5701 : :
5702 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
5703 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
5704 : 0 : recycle_rxq_info->refill_requirement = RTE_IXGBE_RXQ_REARM_THRESH;
5705 : 0 : recycle_rxq_info->refill_head = &rxq->rxrearm_start;
5706 : : #endif
5707 : : } else {
5708 : 0 : recycle_rxq_info->refill_requirement = rxq->rx_free_thresh;
5709 : 0 : recycle_rxq_info->refill_head = &rxq->rx_free_trigger;
5710 : : }
5711 : 0 : }
5712 : :
5713 : : /*
5714 : : * [VF] Initializes Receive Unit.
5715 : : */
5716 : : int __rte_cold
5717 : 0 : ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
5718 : : {
5719 : : struct ixgbe_hw *hw;
5720 : : struct ixgbe_rx_queue *rxq;
5721 : 0 : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
5722 : 0 : uint32_t frame_size = dev->data->mtu + IXGBE_ETH_OVERHEAD;
5723 : : uint64_t bus_addr;
5724 : : uint32_t srrctl, psrtype = 0;
5725 : : uint16_t buf_size;
5726 : : uint16_t i;
5727 : : int ret;
5728 : :
5729 : 0 : PMD_INIT_FUNC_TRACE();
5730 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5731 : :
5732 [ # # ]: 0 : if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
5733 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5734 : : "it should be power of 2");
5735 : 0 : return -1;
5736 : : }
5737 : :
5738 [ # # ]: 0 : if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
5739 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5740 : : "it should be equal to or less than %d",
5741 : : hw->mac.max_rx_queues);
5742 : 0 : return -1;
5743 : : }
5744 : :
5745 : : /*
5746 : : * When the VF driver issues a IXGBE_VF_RESET request, the PF driver
5747 : : * disables the VF receipt of packets if the PF MTU is > 1500.
5748 : : * This is done to deal with 82599 limitations that imposes
5749 : : * the PF and all VFs to share the same MTU.
5750 : : * Then, the PF driver enables again the VF receipt of packet when
5751 : : * the VF driver issues a IXGBE_VF_SET_LPE request.
5752 : : * In the meantime, the VF device cannot be used, even if the VF driver
5753 : : * and the Guest VM network stack are ready to accept packets with a
5754 : : * size up to the PF MTU.
5755 : : * As a work-around to this PF behaviour, force the call to
5756 : : * ixgbevf_rlpml_set_vf even if jumbo frames are not used. This way,
5757 : : * VF packets received can work in all cases.
5758 : : */
5759 [ # # ]: 0 : if (ixgbevf_rlpml_set_vf(hw, frame_size) != 0)
5760 : 0 : PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
5761 : : frame_size);
5762 : :
5763 : : /*
5764 : : * Assume no header split and no VLAN strip support
5765 : : * on any Rx queue first .
5766 : : */
5767 : 0 : rxmode->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5768 : : /* Setup RX queues */
5769 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5770 : 0 : rxq = dev->data->rx_queues[i];
5771 : :
5772 : : /* Allocate buffers for descriptor rings */
5773 : 0 : ret = ixgbe_alloc_rx_queue_mbufs(rxq);
5774 [ # # ]: 0 : if (ret)
5775 : 0 : return ret;
5776 : :
5777 : : /* Setup the Base and Length of the Rx Descriptor Rings */
5778 : 0 : bus_addr = rxq->rx_ring_phys_addr;
5779 : :
5780 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(i),
5781 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5782 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(i),
5783 : : (uint32_t)(bus_addr >> 32));
5784 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(i),
5785 : : rxq->nb_rx_desc * sizeof(union ixgbe_adv_rx_desc));
5786 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDH(i), 0);
5787 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), 0);
5788 : :
5789 : :
5790 : : /* Configure the SRRCTL register */
5791 : : srrctl = IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
5792 : :
5793 : : /* Set if packets are dropped when no descriptors available */
5794 [ # # ]: 0 : if (rxq->drop_en)
5795 : : srrctl |= IXGBE_SRRCTL_DROP_EN;
5796 : :
5797 : : /*
5798 : : * Configure the RX buffer size in the BSIZEPACKET field of
5799 : : * the SRRCTL register of the queue.
5800 : : * The value is in 1 KB resolution. Valid values can be from
5801 : : * 1 KB to 16 KB.
5802 : : */
5803 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
5804 : : RTE_PKTMBUF_HEADROOM);
5805 : 0 : srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
5806 : : IXGBE_SRRCTL_BSIZEPKT_MASK);
5807 : :
5808 : : /*
5809 : : * VF modification to write virtual function SRRCTL register
5810 : : */
5811 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(i), srrctl);
5812 : :
5813 : 0 : buf_size = (uint16_t) ((srrctl & IXGBE_SRRCTL_BSIZEPKT_MASK) <<
5814 : : IXGBE_SRRCTL_BSIZEPKT_SHIFT);
5815 : :
5816 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
5817 : : /* It adds dual VLAN length for supporting dual VLAN */
5818 [ # # ]: 0 : (frame_size + 2 * RTE_VLAN_HLEN) > buf_size) {
5819 [ # # ]: 0 : if (!dev->data->scattered_rx)
5820 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
5821 : 0 : dev->data->scattered_rx = 1;
5822 : : }
5823 : :
5824 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5825 : 0 : rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5826 : : }
5827 : :
5828 : : /* Set RQPL for VF RSS according to max Rx queue */
5829 : 0 : psrtype |= (dev->data->nb_rx_queues >> 1) <<
5830 : : IXGBE_PSRTYPE_RQPL_SHIFT;
5831 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
5832 : :
5833 : : /* Initialize the rss for x550_vf cards if enabled */
5834 [ # # ]: 0 : switch (hw->mac.type) {
5835 : 0 : case ixgbe_mac_X550_vf:
5836 : : case ixgbe_mac_X550EM_x_vf:
5837 : : case ixgbe_mac_X550EM_a_vf:
5838 [ # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
5839 : 0 : case RTE_ETH_MQ_RX_RSS:
5840 : : case RTE_ETH_MQ_RX_DCB_RSS:
5841 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
5842 : 0 : ixgbe_rss_configure(dev);
5843 : 0 : break;
5844 : : default:
5845 : : break;
5846 : : }
5847 : : break;
5848 : : default:
5849 : : break;
5850 : : }
5851 : :
5852 : 0 : ixgbe_set_rx_function(dev);
5853 : :
5854 : 0 : return 0;
5855 : : }
5856 : :
5857 : : /*
5858 : : * [VF] Initializes Transmit Unit.
5859 : : */
5860 : : void __rte_cold
5861 : 0 : ixgbevf_dev_tx_init(struct rte_eth_dev *dev)
5862 : : {
5863 : : struct ixgbe_hw *hw;
5864 : : struct ci_tx_queue *txq;
5865 : : uint64_t bus_addr;
5866 : : uint32_t txctrl;
5867 : : uint16_t i;
5868 : :
5869 : 0 : PMD_INIT_FUNC_TRACE();
5870 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5871 : :
5872 : : /* Setup the Base and Length of the Tx Descriptor Rings */
5873 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5874 : 0 : txq = dev->data->tx_queues[i];
5875 : 0 : bus_addr = txq->tx_ring_dma;
5876 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(i),
5877 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5878 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(i),
5879 : : (uint32_t)(bus_addr >> 32));
5880 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(i),
5881 : : txq->nb_tx_desc * sizeof(union ixgbe_adv_tx_desc));
5882 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
5883 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDH(i), 0);
5884 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDT(i), 0);
5885 : :
5886 : : /*
5887 : : * Disable Tx Head Writeback RO bit, since this hoses
5888 : : * bookkeeping if things aren't delivered in order.
5889 : : */
5890 : 0 : txctrl = IXGBE_READ_REG(hw,
5891 : : IXGBE_VFDCA_TXCTRL(i));
5892 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5893 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i),
5894 : : txctrl);
5895 : : }
5896 : 0 : }
5897 : :
5898 : : /*
5899 : : * [VF] Start Transmit and Receive Units.
5900 : : */
5901 : : void __rte_cold
5902 : 0 : ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
5903 : : {
5904 : : struct ixgbe_hw *hw;
5905 : : struct ci_tx_queue *txq;
5906 : : struct ixgbe_rx_queue *rxq;
5907 : : uint32_t txdctl;
5908 : : uint32_t rxdctl;
5909 : : uint16_t i;
5910 : : int poll_ms;
5911 : :
5912 : 0 : PMD_INIT_FUNC_TRACE();
5913 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5914 : :
5915 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5916 : 0 : txq = dev->data->tx_queues[i];
5917 : : /* Setup Transmit Threshold Registers */
5918 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
5919 : 0 : txdctl |= txq->pthresh & 0x7F;
5920 : 0 : txdctl |= ((txq->hthresh & 0x7F) << 8);
5921 : 0 : txdctl |= ((txq->wthresh & 0x7F) << 16);
5922 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
5923 : : }
5924 : :
5925 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5926 : :
5927 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
5928 : 0 : txdctl |= IXGBE_TXDCTL_ENABLE;
5929 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
5930 : :
5931 : : poll_ms = 10;
5932 : : /* Wait until TX Enable ready */
5933 : : do {
5934 : : rte_delay_ms(1);
5935 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
5936 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & IXGBE_TXDCTL_ENABLE));
5937 [ # # ]: 0 : if (!poll_ms)
5938 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
5939 : : else
5940 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
5941 : : }
5942 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5943 : :
5944 : 0 : rxq = dev->data->rx_queues[i];
5945 : :
5946 : 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
5947 : 0 : rxdctl |= IXGBE_RXDCTL_ENABLE;
5948 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl);
5949 : :
5950 : : /* Wait until RX Enable ready */
5951 : : poll_ms = 10;
5952 : : do {
5953 : : rte_delay_ms(1);
5954 : 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
5955 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & IXGBE_RXDCTL_ENABLE));
5956 [ # # ]: 0 : if (!poll_ms)
5957 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
5958 : : else
5959 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
5960 : : rte_wmb();
5961 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), rxq->nb_rx_desc - 1);
5962 : :
5963 : : }
5964 : 0 : }
5965 : :
5966 : : int
5967 : 0 : ixgbe_rss_conf_init(struct ixgbe_rte_flow_rss_conf *out,
5968 : : const struct rte_flow_action_rss *in)
5969 : : {
5970 [ # # ]: 0 : if (in->key_len > RTE_DIM(out->key) ||
5971 [ # # ]: 0 : in->queue_num > RTE_DIM(out->queue))
5972 : : return -EINVAL;
5973 : 0 : out->conf = (struct rte_flow_action_rss){
5974 : 0 : .func = in->func,
5975 : 0 : .level = in->level,
5976 : 0 : .types = in->types,
5977 : : .key_len = in->key_len,
5978 : : .queue_num = in->queue_num,
5979 : 0 : .key = memcpy(out->key, in->key, in->key_len),
5980 : 0 : .queue = memcpy(out->queue, in->queue,
5981 : 0 : sizeof(*in->queue) * in->queue_num),
5982 : : };
5983 : 0 : return 0;
5984 : : }
5985 : :
5986 : : int
5987 : 0 : ixgbe_action_rss_same(const struct rte_flow_action_rss *comp,
5988 : : const struct rte_flow_action_rss *with)
5989 : : {
5990 : 0 : return (comp->func == with->func &&
5991 : 0 : comp->level == with->level &&
5992 [ # # ]: 0 : comp->types == with->types &&
5993 [ # # ]: 0 : comp->key_len == with->key_len &&
5994 : 0 : comp->queue_num == with->queue_num &&
5995 [ # # # # ]: 0 : !memcmp(comp->key, with->key, with->key_len) &&
5996 : 0 : !memcmp(comp->queue, with->queue,
5997 [ # # ]: 0 : sizeof(*with->queue) * with->queue_num));
5998 : : }
5999 : :
6000 : : int
6001 : 0 : ixgbe_config_rss_filter(struct rte_eth_dev *dev,
6002 : : struct ixgbe_rte_flow_rss_conf *conf, bool add)
6003 : : {
6004 : : struct ixgbe_hw *hw;
6005 : : uint32_t reta;
6006 : : uint16_t i;
6007 : : uint16_t j;
6008 : : uint16_t sp_reta_size;
6009 : : uint32_t reta_reg;
6010 : 0 : struct rte_eth_rss_conf rss_conf = {
6011 : 0 : .rss_key = conf->conf.key_len ?
6012 [ # # ]: 0 : (void *)(uintptr_t)conf->conf.key : NULL,
6013 : : .rss_key_len = conf->conf.key_len,
6014 : 0 : .rss_hf = conf->conf.types,
6015 : : };
6016 : : struct ixgbe_filter_info *filter_info =
6017 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6018 : :
6019 : 0 : PMD_INIT_FUNC_TRACE();
6020 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6021 : :
6022 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
6023 : :
6024 [ # # ]: 0 : if (!add) {
6025 [ # # ]: 0 : if (ixgbe_action_rss_same(&filter_info->rss_info.conf,
6026 : 0 : &conf->conf)) {
6027 : : ixgbe_rss_disable(dev);
6028 : 0 : memset(&filter_info->rss_info, 0,
6029 : : sizeof(struct ixgbe_rte_flow_rss_conf));
6030 : 0 : return 0;
6031 : : }
6032 : : return -EINVAL;
6033 : : }
6034 : :
6035 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
6036 : : return -EINVAL;
6037 : : /* Fill in redirection table
6038 : : * The byte-swap is needed because NIC registers are in
6039 : : * little-endian order.
6040 : : */
6041 : : reta = 0;
6042 [ # # ]: 0 : for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
6043 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
6044 : :
6045 [ # # ]: 0 : if (j == conf->conf.queue_num)
6046 : : j = 0;
6047 : 0 : reta = (reta << 8) | conf->conf.queue[j];
6048 [ # # ]: 0 : if ((i & 3) == 3)
6049 [ # # ]: 0 : IXGBE_WRITE_REG(hw, reta_reg,
6050 : : rte_bswap32(reta));
6051 : : }
6052 : :
6053 : : /* Configure the RSS key and the RSS protocols used to compute
6054 : : * the RSS hash of input packets.
6055 : : */
6056 [ # # ]: 0 : if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
6057 : : ixgbe_rss_disable(dev);
6058 : 0 : return 0;
6059 : : }
6060 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
6061 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
6062 : 0 : ixgbe_hw_rss_hash_set(hw, &rss_conf);
6063 : :
6064 [ # # ]: 0 : if (ixgbe_rss_conf_init(&filter_info->rss_info, &conf->conf))
6065 : 0 : return -EINVAL;
6066 : :
6067 : : return 0;
6068 : : }
6069 : :
6070 : : /* Stubs needed for linkage when RTE_ARCH_PPC_64, RTE_ARCH_RISCV or
6071 : : * RTE_ARCH_LOONGARCH is set.
6072 : : */
6073 : : #if defined(RTE_ARCH_PPC_64) || defined(RTE_ARCH_RISCV) || \
6074 : : defined(RTE_ARCH_LOONGARCH)
6075 : : int
6076 : : ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
6077 : : {
6078 : : return -1;
6079 : : }
6080 : :
6081 : : uint16_t
6082 : : ixgbe_recv_pkts_vec(
6083 : : void __rte_unused *rx_queue,
6084 : : struct rte_mbuf __rte_unused **rx_pkts,
6085 : : uint16_t __rte_unused nb_pkts)
6086 : : {
6087 : : return 0;
6088 : : }
6089 : :
6090 : : uint16_t
6091 : : ixgbe_recv_scattered_pkts_vec(
6092 : : void __rte_unused *rx_queue,
6093 : : struct rte_mbuf __rte_unused **rx_pkts,
6094 : : uint16_t __rte_unused nb_pkts)
6095 : : {
6096 : : return 0;
6097 : : }
6098 : :
6099 : : int
6100 : : ixgbe_rxq_vec_setup(struct ixgbe_rx_queue __rte_unused *rxq)
6101 : : {
6102 : : return -1;
6103 : : }
6104 : :
6105 : : uint16_t
6106 : : ixgbe_xmit_fixed_burst_vec(void __rte_unused *tx_queue,
6107 : : struct rte_mbuf __rte_unused **tx_pkts,
6108 : : uint16_t __rte_unused nb_pkts)
6109 : : {
6110 : : return 0;
6111 : : }
6112 : :
6113 : : int
6114 : : ixgbe_txq_vec_setup(struct ci_tx_queue *txq __rte_unused)
6115 : : {
6116 : : return -1;
6117 : : }
6118 : :
6119 : : void
6120 : : ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue __rte_unused *rxq)
6121 : : {
6122 : : return;
6123 : : }
6124 : : #endif
|