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