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