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 : 0 : 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 const uint64_t ip_pkt_etqf_map[IXGBE_MAX_ETQF_FILTERS] = {
1432 : : [IXGBE_ETQF_FILTER_TIMESYNC] = RTE_MBUF_F_RX_IEEE1588_PTP,
1433 : : };
1434 : :
1435 : : if (likely(pkt_info & IXGBE_RXDADV_PKTTYPE_ETQF))
1436 : : return ip_pkt_etqf_map[(pkt_info >> 4) & 0X07] |
1437 : : ip_rss_types_map[pkt_info & 0XF];
1438 : : else
1439 : : return ip_rss_types_map[pkt_info & 0XF];
1440 : : #else
1441 : 0 : return ip_rss_types_map[pkt_info & 0XF];
1442 : : #endif
1443 : : }
1444 : :
1445 : : static inline uint64_t
1446 : : rx_desc_status_to_pkt_flags(uint32_t rx_status, uint64_t vlan_flags)
1447 : : {
1448 : : uint64_t pkt_flags;
1449 : :
1450 : : /*
1451 : : * Check if VLAN present only.
1452 : : * Do not check whether L3/L4 rx checksum done by NIC or not,
1453 : : * That can be found from rte_eth_rxmode.offloads flag
1454 : : */
1455 : 0 : pkt_flags = (rx_status & IXGBE_RXD_STAT_VP) ? vlan_flags : 0;
1456 : :
1457 : : #ifdef RTE_LIBRTE_IEEE1588
1458 : : if (rx_status & IXGBE_RXD_STAT_TMST)
1459 : : pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
1460 : : #endif
1461 : : return pkt_flags;
1462 : : }
1463 : :
1464 : : static inline uint64_t
1465 : 0 : rx_desc_error_to_pkt_flags(uint32_t rx_status, uint16_t pkt_info,
1466 : : uint8_t rx_udp_csum_zero_err)
1467 : : {
1468 : : uint64_t pkt_flags;
1469 : :
1470 : : /*
1471 : : * Bit 31: IPE, IPv4 checksum error
1472 : : * Bit 30: L4I, L4I integrity error
1473 : : */
1474 : : static uint64_t error_to_pkt_flags_map[4] = {
1475 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
1476 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
1477 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
1478 : : RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD
1479 : : };
1480 : 0 : pkt_flags = error_to_pkt_flags_map[(rx_status >>
1481 : 0 : IXGBE_RXDADV_ERR_CKSUM_BIT) & IXGBE_RXDADV_ERR_CKSUM_MSK];
1482 : :
1483 : : /* Mask out the bad UDP checksum error if the hardware has UDP zero
1484 : : * checksum error issue, so that the software application will then
1485 : : * have to recompute the checksum itself if needed.
1486 : : */
1487 [ # # # # ]: 0 : if ((rx_status & IXGBE_RXDADV_ERR_TCPE) &&
1488 [ # # ]: 0 : (pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1489 : : rx_udp_csum_zero_err)
1490 : 0 : pkt_flags &= ~RTE_MBUF_F_RX_L4_CKSUM_BAD;
1491 : :
1492 [ # # ]: 0 : if ((rx_status & IXGBE_RXD_STAT_OUTERIPCS) &&
1493 : : (rx_status & IXGBE_RXDADV_ERR_OUTERIPER)) {
1494 : 0 : pkt_flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
1495 : : }
1496 : :
1497 [ # # ]: 0 : if (rx_status & IXGBE_RXD_STAT_SECP) {
1498 : 0 : pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD;
1499 [ # # ]: 0 : if (rx_status & IXGBE_RXDADV_LNKSEC_ERROR_BAD_SIG)
1500 : 0 : pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED;
1501 : : }
1502 : :
1503 : 0 : return pkt_flags;
1504 : : }
1505 : :
1506 : : /*
1507 : : * LOOK_AHEAD defines how many desc statuses to check beyond the
1508 : : * current descriptor.
1509 : : * It must be a pound define for optimal performance.
1510 : : * Do not change the value of LOOK_AHEAD, as the ixgbe_rx_scan_hw_ring
1511 : : * function only works with LOOK_AHEAD=8.
1512 : : */
1513 : : #define LOOK_AHEAD 8
1514 : : #if (LOOK_AHEAD != 8)
1515 : : #error "PMD IXGBE: LOOK_AHEAD must be 8\n"
1516 : : #endif
1517 : : static inline int
1518 : 0 : ixgbe_rx_scan_hw_ring(struct ci_rx_queue *rxq)
1519 : : {
1520 : : volatile union ixgbe_adv_rx_desc *rxdp;
1521 : : struct ci_rx_entry *rxep;
1522 : : struct rte_mbuf *mb;
1523 : : uint16_t pkt_len;
1524 : : uint64_t pkt_flags;
1525 : : int nb_dd;
1526 : : uint32_t s[LOOK_AHEAD];
1527 : : uint32_t pkt_info[LOOK_AHEAD];
1528 : : int i, j, nb_rx = 0;
1529 : : uint32_t status;
1530 : 0 : uint64_t vlan_flags = rxq->vlan_flags;
1531 : :
1532 : : /* get references to current descriptor and S/W ring entry */
1533 : 0 : rxdp = &rxq->ixgbe_rx_ring[rxq->rx_tail];
1534 : 0 : rxep = &rxq->sw_ring[rxq->rx_tail];
1535 : :
1536 : 0 : status = rxdp->wb.upper.status_error;
1537 : : /* check to make sure there is at least 1 packet to receive */
1538 [ # # ]: 0 : if (!(status & rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
1539 : : return 0;
1540 : :
1541 : : /*
1542 : : * Scan LOOK_AHEAD descriptors at a time to determine which descriptors
1543 : : * reference packets that are ready to be received.
1544 : : */
1545 [ # # ]: 0 : for (i = 0; i < IXGBE_RX_MAX_BURST;
1546 : 0 : i += LOOK_AHEAD, rxdp += LOOK_AHEAD, rxep += LOOK_AHEAD) {
1547 : : /* Read desc statuses backwards to avoid race condition */
1548 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; j++)
1549 : 0 : s[j] = rte_le_to_cpu_32(rxdp[j].wb.upper.status_error);
1550 : :
1551 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1552 : :
1553 : : /* Compute how many status bits were set */
1554 [ # # ]: 0 : for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
1555 [ # # ]: 0 : (s[nb_dd] & IXGBE_RXDADV_STAT_DD); nb_dd++)
1556 : : ;
1557 : :
1558 [ # # ]: 0 : for (j = 0; j < nb_dd; j++)
1559 : 0 : pkt_info[j] = rte_le_to_cpu_32(rxdp[j].wb.lower.
1560 : : lo_dword.data);
1561 : :
1562 : 0 : nb_rx += nb_dd;
1563 : :
1564 : : /* Translate descriptor info to mbuf format */
1565 [ # # ]: 0 : for (j = 0; j < nb_dd; ++j) {
1566 : 0 : mb = rxep[j].mbuf;
1567 : 0 : pkt_len = rte_le_to_cpu_16(rxdp[j].wb.upper.length) -
1568 : 0 : rxq->crc_len;
1569 : 0 : mb->data_len = pkt_len;
1570 : 0 : mb->pkt_len = pkt_len;
1571 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxdp[j].wb.upper.vlan);
1572 : :
1573 : : /* convert descriptor fields to rte mbuf flags */
1574 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(s[j],
1575 : : vlan_flags);
1576 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(s[j],
1577 : 0 : (uint16_t)pkt_info[j],
1578 : 0 : rxq->rx_udp_csum_zero_err);
1579 : 0 : pkt_flags |= ixgbe_rxd_pkt_info_to_pkt_flags
1580 : : ((uint16_t)pkt_info[j]);
1581 : 0 : mb->ol_flags = pkt_flags;
1582 : 0 : mb->packet_type =
1583 : : ixgbe_rxd_pkt_info_to_pkt_type
1584 [ # # ]: 0 : (pkt_info[j], rxq->pkt_type_mask);
1585 : :
1586 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1587 : 0 : mb->hash.rss = rte_le_to_cpu_32(
1588 : : rxdp[j].wb.lower.hi_dword.rss);
1589 [ # # ]: 0 : else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
1590 : 0 : mb->hash.fdir.hash = rte_le_to_cpu_16(
1591 : 0 : rxdp[j].wb.lower.hi_dword.csum_ip.csum) &
1592 : : IXGBE_ATR_HASH_MASK;
1593 : 0 : mb->hash.fdir.id = rte_le_to_cpu_16(
1594 : : rxdp[j].wb.lower.hi_dword.csum_ip.ip_id);
1595 : : }
1596 : : }
1597 : :
1598 : : /* Move mbuf pointers from the S/W ring to the stage */
1599 [ # # ]: 0 : for (j = 0; j < LOOK_AHEAD; ++j) {
1600 : 0 : rxq->rx_stage[i + j] = rxep[j].mbuf;
1601 : : }
1602 : :
1603 : : /* stop if all requested packets could not be received */
1604 [ # # ]: 0 : if (nb_dd != LOOK_AHEAD)
1605 : : break;
1606 : : }
1607 : :
1608 : : /* clear software ring entries so we can cleanup correctly */
1609 [ # # ]: 0 : for (i = 0; i < nb_rx; ++i) {
1610 : 0 : rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
1611 : : }
1612 : :
1613 : :
1614 : : return nb_rx;
1615 : : }
1616 : :
1617 : : static inline int
1618 : 0 : ixgbe_rx_alloc_bufs(struct ci_rx_queue *rxq, bool reset_mbuf)
1619 : : {
1620 : : volatile union ixgbe_adv_rx_desc *rxdp;
1621 : : struct ci_rx_entry *rxep;
1622 : : struct rte_mbuf *mb;
1623 : : uint16_t alloc_idx;
1624 : : __le64 dma_addr;
1625 : : int diag, i;
1626 : :
1627 : : /* allocate buffers in bulk directly into the S/W ring */
1628 : 0 : alloc_idx = rxq->rx_free_trigger - (rxq->rx_free_thresh - 1);
1629 : 0 : rxep = &rxq->sw_ring[alloc_idx];
1630 [ # # ]: 0 : diag = rte_mbuf_raw_alloc_bulk(rxq->mp, (void *)rxep,
1631 : : rxq->rx_free_thresh);
1632 [ # # ]: 0 : if (unlikely(diag != 0))
1633 : : return -ENOMEM;
1634 : :
1635 : 0 : rxdp = &rxq->ixgbe_rx_ring[alloc_idx];
1636 [ # # ]: 0 : for (i = 0; i < rxq->rx_free_thresh; ++i) {
1637 : : /* populate the static rte mbuf fields */
1638 : 0 : mb = rxep[i].mbuf;
1639 [ # # ]: 0 : if (reset_mbuf) {
1640 : 0 : mb->port = rxq->port_id;
1641 : : }
1642 : :
1643 : : rte_mbuf_refcnt_set(mb, 1);
1644 : 0 : mb->data_off = RTE_PKTMBUF_HEADROOM;
1645 : :
1646 : : /* populate the descriptors */
1647 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
1648 : 0 : rxdp[i].read.hdr_addr = 0;
1649 : 0 : rxdp[i].read.pkt_addr = dma_addr;
1650 : : }
1651 : :
1652 : : /* update state of internal queue structure */
1653 : 0 : rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh;
1654 [ # # ]: 0 : if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
1655 : 0 : rxq->rx_free_trigger = rxq->rx_free_thresh - 1;
1656 : :
1657 : : /* no errors */
1658 : : return 0;
1659 : : }
1660 : :
1661 : : static inline uint16_t
1662 : : ixgbe_rx_fill_from_stage(struct ci_rx_queue *rxq, struct rte_mbuf **rx_pkts,
1663 : : uint16_t nb_pkts)
1664 : : {
1665 : 0 : struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
1666 : : int i;
1667 : :
1668 : : /* how many packets are ready to return? */
1669 : 0 : nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
1670 : :
1671 : : /* copy mbuf pointers to the application's packet list */
1672 [ # # # # ]: 0 : for (i = 0; i < nb_pkts; ++i)
1673 : 0 : rx_pkts[i] = stage[i];
1674 : :
1675 : : /* update internal queue state */
1676 : 0 : rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
1677 : 0 : rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
1678 : :
1679 : : return nb_pkts;
1680 : : }
1681 : :
1682 : : static inline uint16_t
1683 : 0 : rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1684 : : uint16_t nb_pkts)
1685 : : {
1686 : : struct ci_rx_queue *rxq = (struct ci_rx_queue *)rx_queue;
1687 : : uint16_t nb_rx = 0;
1688 : :
1689 : : /* Any previously recv'd pkts will be returned from the Rx stage */
1690 [ # # ]: 0 : if (rxq->rx_nb_avail)
1691 : 0 : return ixgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1692 : :
1693 : : /* Scan the H/W ring for packets to receive */
1694 : 0 : nb_rx = (uint16_t)ixgbe_rx_scan_hw_ring(rxq);
1695 : :
1696 : : /* update internal queue state */
1697 : 0 : rxq->rx_next_avail = 0;
1698 : 0 : rxq->rx_nb_avail = nb_rx;
1699 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
1700 : :
1701 : : /* if required, allocate new buffers to replenish descriptors */
1702 [ # # ]: 0 : if (rxq->rx_tail > rxq->rx_free_trigger) {
1703 : : uint16_t cur_free_trigger = rxq->rx_free_trigger;
1704 : :
1705 [ # # ]: 0 : if (ixgbe_rx_alloc_bufs(rxq, true) != 0) {
1706 : : int i, j;
1707 : :
1708 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1709 : : "queue_id=%u", (unsigned) rxq->port_id,
1710 : : (unsigned) rxq->queue_id);
1711 : :
1712 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
1713 : 0 : rxq->rx_free_thresh;
1714 : :
1715 : : /*
1716 : : * Need to rewind any previous receives if we cannot
1717 : : * allocate new buffers to replenish the old ones.
1718 : : */
1719 : 0 : rxq->rx_nb_avail = 0;
1720 : 0 : rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
1721 [ # # ]: 0 : for (i = 0, j = rxq->rx_tail; i < nb_rx; ++i, ++j)
1722 : 0 : rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
1723 : :
1724 : : return 0;
1725 : : }
1726 : :
1727 : : /* update tail pointer */
1728 : : rte_wmb();
1729 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(rxq->qrx_tail, cur_free_trigger);
1730 : : }
1731 : :
1732 [ # # ]: 0 : if (rxq->rx_tail >= rxq->nb_rx_desc)
1733 : 0 : rxq->rx_tail = 0;
1734 : :
1735 : : /* received any packets this loop? */
1736 [ # # ]: 0 : if (rxq->rx_nb_avail)
1737 : 0 : return ixgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1738 : :
1739 : : return 0;
1740 : : }
1741 : :
1742 : : /* split requests into chunks of size IXGBE_RX_MAX_BURST */
1743 : : uint16_t
1744 : 0 : ixgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1745 : : uint16_t nb_pkts)
1746 : : {
1747 : : uint16_t nb_rx;
1748 : :
1749 [ # # ]: 0 : if (unlikely(nb_pkts == 0))
1750 : : return 0;
1751 : :
1752 [ # # ]: 0 : if (likely(nb_pkts <= IXGBE_RX_MAX_BURST))
1753 : 0 : return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
1754 : :
1755 : : /* request is relatively large, chunk it up */
1756 : : nb_rx = 0;
1757 [ # # ]: 0 : while (nb_pkts) {
1758 : : uint16_t ret, n;
1759 : :
1760 : 0 : n = (uint16_t)RTE_MIN(nb_pkts, IXGBE_RX_MAX_BURST);
1761 : 0 : ret = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
1762 : 0 : nb_rx = (uint16_t)(nb_rx + ret);
1763 : 0 : nb_pkts = (uint16_t)(nb_pkts - ret);
1764 [ # # ]: 0 : if (ret < n)
1765 : : break;
1766 : : }
1767 : :
1768 : : return nb_rx;
1769 : : }
1770 : :
1771 : : uint16_t
1772 : 0 : ixgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1773 : : uint16_t nb_pkts)
1774 : : {
1775 : : struct ci_rx_queue *rxq;
1776 : : volatile union ixgbe_adv_rx_desc *rx_ring;
1777 : : volatile union ixgbe_adv_rx_desc *rxdp;
1778 : : struct ci_rx_entry *sw_ring;
1779 : : struct ci_rx_entry *rxe;
1780 : : struct rte_mbuf *rxm;
1781 : : struct rte_mbuf *nmb;
1782 : : union ixgbe_adv_rx_desc rxd;
1783 : : uint64_t dma_addr;
1784 : : uint32_t staterr;
1785 : : uint32_t pkt_info;
1786 : : uint16_t pkt_len;
1787 : : uint16_t rx_id;
1788 : : uint16_t nb_rx;
1789 : : uint16_t nb_hold;
1790 : : uint64_t pkt_flags;
1791 : : uint64_t vlan_flags;
1792 : :
1793 : : nb_rx = 0;
1794 : : nb_hold = 0;
1795 : : rxq = rx_queue;
1796 : 0 : rx_id = rxq->rx_tail;
1797 : 0 : rx_ring = rxq->ixgbe_rx_ring;
1798 : 0 : sw_ring = rxq->sw_ring;
1799 : 0 : vlan_flags = rxq->vlan_flags;
1800 [ # # ]: 0 : while (nb_rx < nb_pkts) {
1801 : : /*
1802 : : * The order of operations here is important as the DD status
1803 : : * bit must not be read after any other descriptor fields.
1804 : : * rx_ring and rxdp are pointing to volatile data so the order
1805 : : * of accesses cannot be reordered by the compiler. If they were
1806 : : * not volatile, they could be reordered which could lead to
1807 : : * using invalid descriptor fields when read from rxd.
1808 : : *
1809 : : * Meanwhile, to prevent the CPU from executing out of order, we
1810 : : * need to use a proper memory barrier to ensure the memory
1811 : : * ordering below.
1812 : : */
1813 : 0 : rxdp = &rx_ring[rx_id];
1814 : 0 : staterr = rxdp->wb.upper.status_error;
1815 [ # # ]: 0 : if (!(staterr & rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
1816 : : break;
1817 : :
1818 : : /*
1819 : : * Use acquire fence to ensure that status_error which includes
1820 : : * DD bit is loaded before loading of other descriptor words.
1821 : : */
1822 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1823 : :
1824 : 0 : rxd = *rxdp;
1825 : :
1826 : : /*
1827 : : * End of packet.
1828 : : *
1829 : : * If the IXGBE_RXDADV_STAT_EOP flag is not set, the RX packet
1830 : : * is likely to be invalid and to be dropped by the various
1831 : : * validation checks performed by the network stack.
1832 : : *
1833 : : * Allocate a new mbuf to replenish the RX ring descriptor.
1834 : : * If the allocation fails:
1835 : : * - arrange for that RX descriptor to be the first one
1836 : : * being parsed the next time the receive function is
1837 : : * invoked [on the same queue].
1838 : : *
1839 : : * - Stop parsing the RX ring and return immediately.
1840 : : *
1841 : : * This policy do not drop the packet received in the RX
1842 : : * descriptor for which the allocation of a new mbuf failed.
1843 : : * Thus, it allows that packet to be later retrieved if
1844 : : * mbuf have been freed in the mean time.
1845 : : * As a side effect, holding RX descriptors instead of
1846 : : * systematically giving them back to the NIC may lead to
1847 : : * RX ring exhaustion situations.
1848 : : * However, the NIC can gracefully prevent such situations
1849 : : * to happen by sending specific "back-pressure" flow control
1850 : : * frames to its peer(s).
1851 : : */
1852 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1853 : : "ext_err_stat=0x%08x pkt_len=%u",
1854 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1855 : : (unsigned) rx_id, (unsigned) staterr,
1856 : : (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
1857 : :
1858 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mp);
1859 [ # # ]: 0 : if (nmb == NULL) {
1860 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1861 : : "queue_id=%u", (unsigned) rxq->port_id,
1862 : : (unsigned) rxq->queue_id);
1863 : 0 : rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
1864 : 0 : break;
1865 : : }
1866 : :
1867 : 0 : nb_hold++;
1868 : 0 : rxe = &sw_ring[rx_id];
1869 : 0 : rx_id++;
1870 [ # # ]: 0 : if (rx_id == rxq->nb_rx_desc)
1871 : : rx_id = 0;
1872 : :
1873 : : /* Prefetch next mbuf while processing current one. */
1874 : 0 : rte_ixgbe_prefetch(sw_ring[rx_id].mbuf);
1875 : :
1876 : : /*
1877 : : * When next RX descriptor is on a cache-line boundary,
1878 : : * prefetch the next 4 RX descriptors and the next 8 pointers
1879 : : * to mbufs.
1880 : : */
1881 [ # # ]: 0 : if ((rx_id & 0x3) == 0) {
1882 : 0 : rte_ixgbe_prefetch(&rx_ring[rx_id]);
1883 : : rte_ixgbe_prefetch(&sw_ring[rx_id]);
1884 : : }
1885 : :
1886 : 0 : rxm = rxe->mbuf;
1887 : 0 : rxe->mbuf = nmb;
1888 : : dma_addr =
1889 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1890 : 0 : rxdp->read.hdr_addr = 0;
1891 : 0 : rxdp->read.pkt_addr = dma_addr;
1892 : :
1893 : : /*
1894 : : * Initialize the returned mbuf.
1895 : : * 1) setup generic mbuf fields:
1896 : : * - number of segments,
1897 : : * - next segment,
1898 : : * - packet length,
1899 : : * - RX port identifier.
1900 : : * 2) integrate hardware offload data, if any:
1901 : : * - RSS flag & hash,
1902 : : * - IP checksum flag,
1903 : : * - VLAN TCI, if any,
1904 : : * - error flags.
1905 : : */
1906 : 0 : pkt_len = (uint16_t) (rte_le_to_cpu_16(rxd.wb.upper.length) -
1907 : 0 : rxq->crc_len);
1908 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
1909 : 0 : rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
1910 : 0 : rxm->nb_segs = 1;
1911 : 0 : rxm->next = NULL;
1912 : 0 : rxm->pkt_len = pkt_len;
1913 : 0 : rxm->data_len = pkt_len;
1914 : 0 : rxm->port = rxq->port_id;
1915 : :
1916 : : pkt_info = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
1917 : : /* Only valid if RTE_MBUF_F_RX_VLAN set in pkt_flags */
1918 [ # # ]: 0 : rxm->vlan_tci = rte_le_to_cpu_16(rxd.wb.upper.vlan);
1919 : :
1920 : : pkt_flags = rx_desc_status_to_pkt_flags(staterr, vlan_flags);
1921 : 0 : pkt_flags = pkt_flags |
1922 : 0 : rx_desc_error_to_pkt_flags(staterr, (uint16_t)pkt_info,
1923 : 0 : rxq->rx_udp_csum_zero_err);
1924 : 0 : pkt_flags = pkt_flags |
1925 : : ixgbe_rxd_pkt_info_to_pkt_flags((uint16_t)pkt_info);
1926 : 0 : rxm->ol_flags = pkt_flags;
1927 : 0 : rxm->packet_type =
1928 : : ixgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1929 [ # # ]: 0 : rxq->pkt_type_mask);
1930 : :
1931 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
1932 : 0 : rxm->hash.rss = rte_le_to_cpu_32(
1933 : : rxd.wb.lower.hi_dword.rss);
1934 [ # # ]: 0 : else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
1935 : 0 : rxm->hash.fdir.hash = rte_le_to_cpu_16(
1936 : 0 : rxd.wb.lower.hi_dword.csum_ip.csum) &
1937 : : IXGBE_ATR_HASH_MASK;
1938 : 0 : rxm->hash.fdir.id = rte_le_to_cpu_16(
1939 : : rxd.wb.lower.hi_dword.csum_ip.ip_id);
1940 : : }
1941 : : /*
1942 : : * Store the mbuf address into the next entry of the array
1943 : : * of returned packets.
1944 : : */
1945 : 0 : rx_pkts[nb_rx++] = rxm;
1946 : : }
1947 : 0 : rxq->rx_tail = rx_id;
1948 : :
1949 : : /*
1950 : : * If the number of free RX descriptors is greater than the RX free
1951 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1952 : : * register.
1953 : : * Update the RDT with the value of the last processed RX descriptor
1954 : : * minus 1, to guarantee that the RDT register is never equal to the
1955 : : * RDH register, which creates a "full" ring situation from the
1956 : : * hardware point of view...
1957 : : */
1958 : 0 : nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
1959 [ # # ]: 0 : if (nb_hold > rxq->rx_free_thresh) {
1960 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1961 : : "nb_hold=%u nb_rx=%u",
1962 : : (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
1963 : : (unsigned) rx_id, (unsigned) nb_hold,
1964 : : (unsigned) nb_rx);
1965 [ # # ]: 0 : rx_id = (uint16_t) ((rx_id == 0) ?
1966 : 0 : (rxq->nb_rx_desc - 1) : (rx_id - 1));
1967 : 0 : IXGBE_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
1968 : : nb_hold = 0;
1969 : : }
1970 : 0 : rxq->nb_rx_hold = nb_hold;
1971 : 0 : return nb_rx;
1972 : : }
1973 : :
1974 : : /**
1975 : : * Detect an RSC descriptor.
1976 : : */
1977 : : static inline uint32_t
1978 : : ixgbe_rsc_count(union ixgbe_adv_rx_desc *rx)
1979 : : {
1980 : 0 : return (rte_le_to_cpu_32(rx->wb.lower.lo_dword.data) &
1981 : 0 : IXGBE_RXDADV_RSCCNT_MASK) >> IXGBE_RXDADV_RSCCNT_SHIFT;
1982 : : }
1983 : :
1984 : : /**
1985 : : * ixgbe_fill_cluster_head_buf - fill the first mbuf of the returned packet
1986 : : *
1987 : : * Fill the following info in the HEAD buffer of the Rx cluster:
1988 : : * - RX port identifier
1989 : : * - hardware offload data, if any:
1990 : : * - RSS flag & hash
1991 : : * - IP checksum flag
1992 : : * - VLAN TCI, if any
1993 : : * - error flags
1994 : : * @head HEAD of the packet cluster
1995 : : * @desc HW descriptor to get data from
1996 : : * @rxq Pointer to the Rx queue
1997 : : */
1998 : : static inline void
1999 : 0 : ixgbe_fill_cluster_head_buf(
2000 : : struct rte_mbuf *head,
2001 : : union ixgbe_adv_rx_desc *desc,
2002 : : struct ci_rx_queue *rxq,
2003 : : uint32_t staterr)
2004 : : {
2005 : : uint32_t pkt_info;
2006 : : uint64_t pkt_flags;
2007 : :
2008 : 0 : head->port = rxq->port_id;
2009 : :
2010 : : /* The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
2011 : : * set in the pkt_flags field.
2012 : : */
2013 : 0 : head->vlan_tci = rte_le_to_cpu_16(desc->wb.upper.vlan);
2014 : 0 : pkt_info = rte_le_to_cpu_32(desc->wb.lower.lo_dword.data);
2015 [ # # ]: 0 : pkt_flags = rx_desc_status_to_pkt_flags(staterr, rxq->vlan_flags);
2016 : 0 : pkt_flags |= rx_desc_error_to_pkt_flags(staterr, (uint16_t)pkt_info,
2017 : 0 : rxq->rx_udp_csum_zero_err);
2018 : 0 : pkt_flags |= ixgbe_rxd_pkt_info_to_pkt_flags((uint16_t)pkt_info);
2019 : 0 : head->ol_flags = pkt_flags;
2020 : 0 : head->packet_type =
2021 [ # # ]: 0 : ixgbe_rxd_pkt_info_to_pkt_type(pkt_info, rxq->pkt_type_mask);
2022 : :
2023 [ # # ]: 0 : if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
2024 : 0 : head->hash.rss = rte_le_to_cpu_32(desc->wb.lower.hi_dword.rss);
2025 [ # # ]: 0 : else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
2026 : 0 : head->hash.fdir.hash =
2027 : 0 : rte_le_to_cpu_16(desc->wb.lower.hi_dword.csum_ip.csum)
2028 : 0 : & IXGBE_ATR_HASH_MASK;
2029 : 0 : head->hash.fdir.id =
2030 : 0 : rte_le_to_cpu_16(desc->wb.lower.hi_dword.csum_ip.ip_id);
2031 : : }
2032 : 0 : }
2033 : :
2034 : : /**
2035 : : * ixgbe_recv_pkts_lro - receive handler for and LRO case.
2036 : : *
2037 : : * @rx_queue Rx queue handle
2038 : : * @rx_pkts table of received packets
2039 : : * @nb_pkts size of rx_pkts table
2040 : : * @bulk_alloc if TRUE bulk allocation is used for a HW ring refilling
2041 : : *
2042 : : * Handles the Rx HW ring completions when RSC feature is configured. Uses an
2043 : : * additional ring of ixgbe_rsc_entry's that will hold the relevant RSC info.
2044 : : *
2045 : : * We use the same logic as in Linux and in FreeBSD ixgbe drivers:
2046 : : * 1) When non-EOP RSC completion arrives:
2047 : : * a) Update the HEAD of the current RSC aggregation cluster with the new
2048 : : * segment's data length.
2049 : : * b) Set the "next" pointer of the current segment to point to the segment
2050 : : * at the NEXTP index.
2051 : : * c) Pass the HEAD of RSC aggregation cluster on to the next NEXTP entry
2052 : : * in the sw_rsc_ring.
2053 : : * 2) When EOP arrives we just update the cluster's total length and offload
2054 : : * flags and deliver the cluster up to the upper layers. In our case - put it
2055 : : * in the rx_pkts table.
2056 : : *
2057 : : * Returns the number of received packets/clusters (according to the "bulk
2058 : : * receive" interface).
2059 : : */
2060 : : static inline uint16_t
2061 : 0 : ixgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts,
2062 : : bool bulk_alloc)
2063 : : {
2064 : : struct ci_rx_queue *rxq = rx_queue;
2065 : 0 : volatile union ixgbe_adv_rx_desc *rx_ring = rxq->ixgbe_rx_ring;
2066 : 0 : struct ci_rx_entry *sw_ring = rxq->sw_ring;
2067 : 0 : struct ci_rx_entry_sc *sw_sc_ring = rxq->sw_sc_ring;
2068 : 0 : uint16_t rx_id = rxq->rx_tail;
2069 : : uint16_t nb_rx = 0;
2070 : 0 : uint16_t nb_hold = rxq->nb_rx_hold;
2071 : : uint16_t prev_id = rxq->rx_tail;
2072 : :
2073 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2074 : : bool eop;
2075 : : struct ci_rx_entry *rxe;
2076 : : struct ci_rx_entry_sc *sc_entry;
2077 : : struct ci_rx_entry_sc *next_sc_entry = NULL;
2078 : : struct ci_rx_entry *next_rxe = NULL;
2079 : : struct rte_mbuf *first_seg;
2080 : : struct rte_mbuf *rxm;
2081 : : struct rte_mbuf *nmb = NULL;
2082 : : union ixgbe_adv_rx_desc rxd;
2083 : : uint16_t data_len;
2084 : : uint16_t next_id;
2085 : : volatile union ixgbe_adv_rx_desc *rxdp;
2086 : : uint32_t staterr;
2087 : :
2088 : 0 : next_desc:
2089 : : /*
2090 : : * "Volatile" only prevents caching of the variable marked
2091 : : * volatile. Most important, "volatile" cannot prevent the CPU
2092 : : * from executing out of order. So, it is necessary to use a
2093 : : * proper memory barrier to ensure the memory ordering below.
2094 : : */
2095 : 0 : rxdp = &rx_ring[rx_id];
2096 : 0 : staterr = rte_le_to_cpu_32(rxdp->wb.upper.status_error);
2097 : :
2098 [ # # ]: 0 : if (!(staterr & IXGBE_RXDADV_STAT_DD))
2099 : : break;
2100 : :
2101 : : /*
2102 : : * Use acquire fence to ensure that status_error which includes
2103 : : * DD bit is loaded before loading of other descriptor words.
2104 : : */
2105 : : rte_atomic_thread_fence(rte_memory_order_acquire);
2106 : :
2107 : 0 : rxd = *rxdp;
2108 : :
2109 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
2110 : : "staterr=0x%x data_len=%u",
2111 : : rxq->port_id, rxq->queue_id, rx_id, staterr,
2112 : : rte_le_to_cpu_16(rxd.wb.upper.length));
2113 : :
2114 [ # # ]: 0 : if (!bulk_alloc) {
2115 : 0 : nmb = rte_mbuf_raw_alloc(rxq->mp);
2116 [ # # ]: 0 : if (nmb == NULL) {
2117 : : PMD_RX_LOG(DEBUG, "RX mbuf alloc failed "
2118 : : "port_id=%u queue_id=%u",
2119 : : rxq->port_id, rxq->queue_id);
2120 : :
2121 : 0 : rte_eth_devices[rxq->port_id].data->
2122 : 0 : rx_mbuf_alloc_failed++;
2123 : 0 : break;
2124 : : }
2125 [ # # ]: 0 : } else if (nb_hold > rxq->rx_free_thresh) {
2126 : 0 : uint16_t next_rdt = rxq->rx_free_trigger;
2127 : :
2128 [ # # ]: 0 : if (!ixgbe_rx_alloc_bufs(rxq, false)) {
2129 : : rte_wmb();
2130 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(
2131 : : rxq->qrx_tail,
2132 : : next_rdt);
2133 : 0 : nb_hold -= rxq->rx_free_thresh;
2134 : : } else {
2135 : : PMD_RX_LOG(DEBUG, "RX bulk alloc failed "
2136 : : "port_id=%u queue_id=%u",
2137 : : rxq->port_id, rxq->queue_id);
2138 : :
2139 : 0 : rte_eth_devices[rxq->port_id].data->
2140 : 0 : rx_mbuf_alloc_failed++;
2141 : 0 : break;
2142 : : }
2143 : : }
2144 : :
2145 : 0 : nb_hold++;
2146 : 0 : rxe = &sw_ring[rx_id];
2147 : 0 : eop = staterr & IXGBE_RXDADV_STAT_EOP;
2148 : :
2149 : 0 : next_id = rx_id + 1;
2150 [ # # ]: 0 : if (next_id == rxq->nb_rx_desc)
2151 : : next_id = 0;
2152 : :
2153 : : /* Prefetch next mbuf while processing current one. */
2154 : 0 : rte_ixgbe_prefetch(sw_ring[next_id].mbuf);
2155 : :
2156 : : /*
2157 : : * When next RX descriptor is on a cache-line boundary,
2158 : : * prefetch the next 4 RX descriptors and the next 4 pointers
2159 : : * to mbufs.
2160 : : */
2161 [ # # ]: 0 : if ((next_id & 0x3) == 0) {
2162 : 0 : rte_ixgbe_prefetch(&rx_ring[next_id]);
2163 : : rte_ixgbe_prefetch(&sw_ring[next_id]);
2164 : : }
2165 : :
2166 : 0 : rxm = rxe->mbuf;
2167 : :
2168 [ # # ]: 0 : if (!bulk_alloc) {
2169 : : __le64 dma =
2170 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
2171 : : /*
2172 : : * Update RX descriptor with the physical address of the
2173 : : * new data buffer of the new allocated mbuf.
2174 : : */
2175 : 0 : rxe->mbuf = nmb;
2176 : :
2177 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2178 : 0 : rxdp->read.hdr_addr = 0;
2179 : 0 : rxdp->read.pkt_addr = dma;
2180 : : } else
2181 : 0 : rxe->mbuf = NULL;
2182 : :
2183 : : /*
2184 : : * Set data length & data buffer address of mbuf.
2185 : : */
2186 : 0 : data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
2187 : 0 : rxm->data_len = data_len;
2188 : :
2189 [ # # ]: 0 : if (!eop) {
2190 : : uint16_t nextp_id;
2191 : : /*
2192 : : * Get next descriptor index:
2193 : : * - For RSC it's in the NEXTP field.
2194 : : * - For a scattered packet - it's just a following
2195 : : * descriptor.
2196 : : */
2197 [ # # ]: 0 : if (ixgbe_rsc_count(&rxd))
2198 : 0 : nextp_id =
2199 : 0 : (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
2200 : : IXGBE_RXDADV_NEXTP_SHIFT;
2201 : : else
2202 : : nextp_id = next_id;
2203 : :
2204 : 0 : next_sc_entry = &sw_sc_ring[nextp_id];
2205 : 0 : next_rxe = &sw_ring[nextp_id];
2206 : : rte_ixgbe_prefetch(next_rxe);
2207 : : }
2208 : :
2209 : 0 : sc_entry = &sw_sc_ring[rx_id];
2210 : 0 : first_seg = sc_entry->fbuf;
2211 : 0 : sc_entry->fbuf = NULL;
2212 : :
2213 : : /*
2214 : : * If this is the first buffer of the received packet,
2215 : : * set the pointer to the first mbuf of the packet and
2216 : : * initialize its context.
2217 : : * Otherwise, update the total length and the number of segments
2218 : : * of the current scattered packet, and update the pointer to
2219 : : * the last mbuf of the current packet.
2220 : : */
2221 [ # # ]: 0 : if (first_seg == NULL) {
2222 : : first_seg = rxm;
2223 : 0 : first_seg->pkt_len = data_len;
2224 : 0 : first_seg->nb_segs = 1;
2225 : : } else {
2226 : 0 : first_seg->pkt_len += data_len;
2227 : 0 : first_seg->nb_segs++;
2228 : : }
2229 : :
2230 : : prev_id = rx_id;
2231 : : rx_id = next_id;
2232 : :
2233 : : /*
2234 : : * If this is not the last buffer of the received packet, update
2235 : : * the pointer to the first mbuf at the NEXTP entry in the
2236 : : * sw_sc_ring and continue to parse the RX ring.
2237 : : */
2238 [ # # ]: 0 : if (!eop && next_rxe) {
2239 : 0 : rxm->next = next_rxe->mbuf;
2240 : 0 : next_sc_entry->fbuf = first_seg;
2241 : 0 : goto next_desc;
2242 : : }
2243 : :
2244 : : /* Initialize the first mbuf of the returned packet */
2245 : 0 : ixgbe_fill_cluster_head_buf(first_seg, &rxd, rxq, staterr);
2246 : :
2247 : : /*
2248 : : * Deal with the case, when HW CRC srip is disabled.
2249 : : * That can't happen when LRO is enabled, but still could
2250 : : * happen for scattered RX mode.
2251 : : */
2252 : 0 : first_seg->pkt_len -= rxq->crc_len;
2253 [ # # ]: 0 : if (unlikely(rxm->data_len <= rxq->crc_len)) {
2254 : : struct rte_mbuf *lp;
2255 : :
2256 [ # # ]: 0 : for (lp = first_seg; lp->next != rxm; lp = lp->next)
2257 : : ;
2258 : :
2259 : 0 : first_seg->nb_segs--;
2260 : 0 : lp->data_len -= rxq->crc_len - rxm->data_len;
2261 [ # # ]: 0 : lp->next = NULL;
2262 : : rte_pktmbuf_free_seg(rxm);
2263 : : } else
2264 : 0 : rxm->data_len -= rxq->crc_len;
2265 : :
2266 : : /* Prefetch data of first segment, if configured to do so. */
2267 : 0 : rte_packet_prefetch((char *)first_seg->buf_addr +
2268 : : first_seg->data_off);
2269 : :
2270 : : /*
2271 : : * Store the mbuf address into the next entry of the array
2272 : : * of returned packets.
2273 : : */
2274 : 0 : rx_pkts[nb_rx++] = first_seg;
2275 : : }
2276 : :
2277 : : /*
2278 : : * Record index of the next RX descriptor to probe.
2279 : : */
2280 : 0 : rxq->rx_tail = rx_id;
2281 : :
2282 : : /*
2283 : : * If the number of free RX descriptors is greater than the RX free
2284 : : * threshold of the queue, advance the Receive Descriptor Tail (RDT)
2285 : : * register.
2286 : : * Update the RDT with the value of the last processed RX descriptor
2287 : : * minus 1, to guarantee that the RDT register is never equal to the
2288 : : * RDH register, which creates a "full" ring situation from the
2289 : : * hardware point of view...
2290 : : */
2291 [ # # # # ]: 0 : if (!bulk_alloc && nb_hold > rxq->rx_free_thresh) {
2292 : : PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
2293 : : "nb_hold=%u nb_rx=%u",
2294 : : rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
2295 : :
2296 : : rte_wmb();
2297 [ # # ]: 0 : IXGBE_PCI_REG_WC_WRITE_RELAXED(rxq->qrx_tail, prev_id);
2298 : : nb_hold = 0;
2299 : : }
2300 : :
2301 : 0 : rxq->nb_rx_hold = nb_hold;
2302 : 0 : return nb_rx;
2303 : : }
2304 : :
2305 : : uint16_t
2306 : 0 : ixgbe_recv_pkts_lro_single_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
2307 : : uint16_t nb_pkts)
2308 : : {
2309 : 0 : return ixgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, false);
2310 : : }
2311 : :
2312 : : uint16_t
2313 : 0 : ixgbe_recv_pkts_lro_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
2314 : : uint16_t nb_pkts)
2315 : : {
2316 : 0 : return ixgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, true);
2317 : : }
2318 : :
2319 : : /*********************************************************************
2320 : : *
2321 : : * Queue management functions
2322 : : *
2323 : : **********************************************************************/
2324 : :
2325 : : int
2326 : 0 : ixgbe_write_default_ctx_desc(struct ci_tx_queue *txq, struct rte_mempool *mp, bool vec)
2327 : : {
2328 : : volatile struct ixgbe_adv_tx_context_desc *ctx_txd;
2329 : : struct rte_mbuf *dummy;
2330 : : uint32_t vlan_macip_lens, type_tucmd_mlhl;
2331 : :
2332 : : /* allocate a dummy mbuf from tx pool to make sure it can be freed later */
2333 : 0 : dummy = rte_pktmbuf_alloc(mp);
2334 [ # # ]: 0 : if (dummy == NULL) {
2335 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate dummy mbuf for VF context descriptor");
2336 : 0 : return -1;
2337 : : }
2338 : :
2339 : : /* take first buffer in the ring and make it a context descriptor */
2340 : 0 : ctx_txd = (volatile struct ixgbe_adv_tx_context_desc *)&txq->ixgbe_tx_ring[txq->tx_tail];
2341 : :
2342 : : /* populate default context descriptor for VF */
2343 : : vlan_macip_lens = RTE_ETHER_HDR_LEN << IXGBE_ADVTXD_MACLEN_SHIFT;
2344 : : type_tucmd_mlhl = IXGBE_ADVTXD_TUCMD_L4T_RSV |
2345 : : IXGBE_ADVTXD_DTYP_CTXT | IXGBE_ADVTXD_DCMD_DEXT;
2346 : 0 : ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
2347 : 0 : ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
2348 : :
2349 : : /* update SW ring */
2350 [ # # ]: 0 : if (vec) {
2351 : : struct ci_tx_entry_vec *txve;
2352 : 0 : txve = &txq->sw_ring_vec[txq->tx_tail];
2353 : 0 : txve->mbuf = dummy;
2354 : : } else {
2355 : : struct ci_tx_entry *txe;
2356 : 0 : txe = &txq->sw_ring[txq->tx_tail];
2357 : 0 : txe->mbuf = dummy;
2358 : : }
2359 : 0 : txq->nb_tx_free--;
2360 : 0 : txq->tx_tail++;
2361 : :
2362 : : /* never come back until queue reset */
2363 : 0 : txq->vf_ctx_initialized = 1;
2364 : :
2365 : 0 : return 0;
2366 : : }
2367 : :
2368 : : static int
2369 : 0 : ixgbe_tx_done_cleanup_full(struct ci_tx_queue *txq, uint32_t free_cnt)
2370 : : {
2371 : 0 : struct ci_tx_entry *swr_ring = txq->sw_ring;
2372 : : uint16_t i, tx_last, tx_id;
2373 : : uint16_t nb_tx_free_last;
2374 : : uint16_t nb_tx_to_clean;
2375 : : uint32_t pkt_cnt;
2376 : :
2377 : : /* Start free mbuf from the next of tx_tail */
2378 : 0 : tx_last = txq->tx_tail;
2379 : 0 : tx_id = swr_ring[tx_last].next_id;
2380 : :
2381 [ # # # # ]: 0 : if (txq->nb_tx_free == 0 && ixgbe_xmit_cleanup(txq))
2382 : : return 0;
2383 : :
2384 : 0 : nb_tx_to_clean = txq->nb_tx_free;
2385 : : nb_tx_free_last = txq->nb_tx_free;
2386 [ # # ]: 0 : if (!free_cnt)
2387 : 0 : free_cnt = txq->nb_tx_desc;
2388 : :
2389 : : /* Loop through swr_ring to count the amount of
2390 : : * freeable mubfs and packets.
2391 : : */
2392 [ # # ]: 0 : for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2393 : 0 : for (i = 0; i < nb_tx_to_clean &&
2394 [ # # # # ]: 0 : pkt_cnt < free_cnt &&
2395 : 0 : tx_id != tx_last; i++) {
2396 [ # # ]: 0 : if (swr_ring[tx_id].mbuf != NULL) {
2397 : : /*
2398 : : * last segment in the packet,
2399 : : * increment packet count
2400 : : */
2401 [ # # ]: 0 : pkt_cnt += swr_ring[tx_id].mbuf->next == NULL ? 1 : 0;
2402 : : rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2403 : 0 : swr_ring[tx_id].mbuf = NULL;
2404 : :
2405 : : }
2406 : :
2407 : 0 : tx_id = swr_ring[tx_id].next_id;
2408 : : }
2409 : :
2410 : 0 : if (txq->tx_rs_thresh > txq->nb_tx_desc -
2411 [ # # # # ]: 0 : txq->nb_tx_free || tx_id == tx_last)
2412 : : break;
2413 : :
2414 [ # # ]: 0 : if (pkt_cnt < free_cnt) {
2415 [ # # ]: 0 : if (ixgbe_xmit_cleanup(txq))
2416 : : break;
2417 : :
2418 : 0 : nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2419 : : nb_tx_free_last = txq->nb_tx_free;
2420 : : }
2421 : : }
2422 : :
2423 : 0 : return (int)pkt_cnt;
2424 : : }
2425 : :
2426 : : static int
2427 : 0 : ixgbe_tx_done_cleanup_simple(struct ci_tx_queue *txq,
2428 : : uint32_t free_cnt)
2429 : : {
2430 : : int i, n, cnt;
2431 : :
2432 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2433 : 0 : free_cnt = txq->nb_tx_desc;
2434 : :
2435 : 0 : cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
2436 : :
2437 [ # # ]: 0 : for (i = 0; i < cnt; i += n) {
2438 [ # # ]: 0 : if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
2439 : : break;
2440 : :
2441 : : n = ixgbe_tx_free_bufs(txq);
2442 : :
2443 [ # # ]: 0 : if (n == 0)
2444 : : break;
2445 : : }
2446 : :
2447 : 0 : return i;
2448 : : }
2449 : :
2450 : : static int
2451 : : ixgbe_tx_done_cleanup_vec(struct ci_tx_queue *txq __rte_unused,
2452 : : uint32_t free_cnt __rte_unused)
2453 : : {
2454 : : return -ENOTSUP;
2455 : : }
2456 : :
2457 : : int
2458 : 0 : ixgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt)
2459 : : {
2460 : : struct ci_tx_queue *txq = (struct ci_tx_queue *)tx_queue;
2461 [ # # ]: 0 : if (txq->offloads == 0 &&
2462 [ # # ]: 0 : !(txq->using_ipsec) &&
2463 [ # # ]: 0 : txq->tx_rs_thresh >= IXGBE_TX_MAX_BURST) {
2464 [ # # # # ]: 0 : if (txq->tx_rs_thresh <= IXGBE_TX_MAX_FREE_BUF_SZ &&
2465 [ # # ]: 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128 &&
2466 : 0 : (rte_eal_process_type() != RTE_PROC_PRIMARY ||
2467 [ # # ]: 0 : txq->sw_ring_vec != NULL)) {
2468 : : return ixgbe_tx_done_cleanup_vec(txq, free_cnt);
2469 : : } else {
2470 : 0 : return ixgbe_tx_done_cleanup_simple(txq, free_cnt);
2471 : : }
2472 : : }
2473 : :
2474 : 0 : return ixgbe_tx_done_cleanup_full(txq, free_cnt);
2475 : : }
2476 : :
2477 : : static void __rte_cold
2478 : 0 : ixgbe_tx_free_swring(struct ci_tx_queue *txq)
2479 : : {
2480 [ # # ]: 0 : if (txq != NULL &&
2481 [ # # ]: 0 : txq->sw_ring != NULL)
2482 : 0 : rte_free(txq->sw_ring);
2483 : 0 : }
2484 : :
2485 : : static void __rte_cold
2486 : 0 : ixgbe_tx_queue_release(struct ci_tx_queue *txq)
2487 : : {
2488 [ # # # # ]: 0 : if (txq != NULL && txq->ops != NULL) {
2489 : 0 : ci_txq_release_all_mbufs(txq, false);
2490 : 0 : txq->ops->free_swring(txq);
2491 : 0 : rte_free(txq->rs_last_id);
2492 : 0 : rte_memzone_free(txq->mz);
2493 : 0 : rte_free(txq);
2494 : : }
2495 : 0 : }
2496 : :
2497 : : void __rte_cold
2498 : 0 : ixgbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2499 : : {
2500 : 0 : ixgbe_tx_queue_release(dev->data->tx_queues[qid]);
2501 : 0 : }
2502 : :
2503 : : /* (Re)set dynamic ixgbe_tx_queue fields to defaults */
2504 : : static void __rte_cold
2505 : 0 : ixgbe_reset_tx_queue(struct ci_tx_queue *txq)
2506 : : {
2507 : : static const union ixgbe_adv_tx_desc zeroed_desc = {{0}};
2508 : 0 : struct ci_tx_entry *txe = txq->sw_ring;
2509 : : uint16_t prev, i;
2510 : :
2511 : : /* Zero out HW ring memory */
2512 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2513 : 0 : txq->ixgbe_tx_ring[i] = zeroed_desc;
2514 : : }
2515 : :
2516 : : /* Initialize SW ring entries */
2517 : 0 : prev = (uint16_t) (txq->nb_tx_desc - 1);
2518 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
2519 : 0 : volatile union ixgbe_adv_tx_desc *txd = &txq->ixgbe_tx_ring[i];
2520 : :
2521 : 0 : txd->wb.status = rte_cpu_to_le_32(IXGBE_TXD_STAT_DD);
2522 : 0 : txe[i].mbuf = NULL;
2523 : 0 : txe[prev].next_id = i;
2524 : : prev = i;
2525 : : }
2526 : :
2527 : 0 : txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
2528 : 0 : txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
2529 : :
2530 : 0 : txq->tx_tail = 0;
2531 : : /*
2532 : : * Always allow 1 descriptor to be un-allocated to avoid
2533 : : * a H/W race condition
2534 : : */
2535 : 0 : txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2536 : 0 : txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2537 : 0 : txq->ctx_curr = 0;
2538 : : /*
2539 : : * When doing Tx on a VF queue, we need to set CC bit and specify a
2540 : : * valid context descriptor regardless of whether we are using any
2541 : : * offloads.
2542 : : *
2543 : : * For simple/vector Tx paths, a default context descriptor will always
2544 : : * be created on Tx start, so we do not need any special handling here.
2545 : : * However, for full offload path, we will be dynamically switching
2546 : : * between two context descriptors (and create new ones when necessary)
2547 : : * based on what kind of offloads are enabled for each packet, so we
2548 : : * need to prepare the offload cache accordingly.
2549 : : *
2550 : : * In case of VF, because we might be transmitting packets with and
2551 : : * without offloads (both of which require context descriptors), we need
2552 : : * to distinguish between "packet with no offloads" and "packet with no
2553 : : * offloads but we've already created a context for it" cases. This
2554 : : * works fine on switchover from having filled offload context cache
2555 : : * previously as no-offload case won't match previously created context,
2556 : : * but to make this work in cases where no previous packets had offloads
2557 : : * (such as on Tx start), we poison the offload cache, so that
2558 : : * no-offload packet also triggers creation of new context descriptor
2559 : : * due to offload cache mismatch.
2560 : : */
2561 [ # # ]: 0 : memset(txq->ctx_cache, 0xFF, IXGBE_CTX_NUM * sizeof(struct ixgbe_advctx_info));
2562 : :
2563 : : /* for PF, we do not need to initialize the context descriptor */
2564 [ # # ]: 0 : if (!txq->is_vf)
2565 : 0 : txq->vf_ctx_initialized = 1;
2566 : 0 : }
2567 : :
2568 : : static const struct ixgbe_txq_ops def_txq_ops = {
2569 : : .free_swring = ixgbe_tx_free_swring,
2570 : : .reset = ixgbe_reset_tx_queue,
2571 : : };
2572 : :
2573 : : static const struct {
2574 : : eth_tx_burst_t pkt_burst;
2575 : : const char *info;
2576 : : } ixgbe_tx_burst_info[] = {
2577 : : { ixgbe_xmit_pkts, "Scalar"},
2578 : : { ixgbe_xmit_pkts_simple, "Scalar simple"},
2579 : : { ixgbe_vf_representor_tx_burst, "Scalar representor"},
2580 : : #ifdef IXGBE_VPMD_SUPPORTED
2581 : : #ifdef RTE_ARCH_X86
2582 : : { ixgbe_xmit_pkts_vec, "Vector SSE"},
2583 : : #elif defined(RTE_ARCH_ARM)
2584 : : { ixgbe_xmit_pkts_vec, "Vector NEON"},
2585 : : #endif
2586 : : #endif
2587 : : };
2588 : :
2589 : : int
2590 : 0 : ixgbe_tx_burst_mode_get(struct rte_eth_dev *dev,
2591 : : __rte_unused uint16_t queue_id,
2592 : : struct rte_eth_burst_mode *mode)
2593 : : {
2594 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
2595 : : size_t i;
2596 : :
2597 [ # # ]: 0 : for (i = 0; i < RTE_DIM(ixgbe_tx_burst_info); i++) {
2598 [ # # ]: 0 : if (pkt_burst == ixgbe_tx_burst_info[i].pkt_burst) {
2599 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
2600 : 0 : ixgbe_tx_burst_info[i].info);
2601 : 0 : return 0;
2602 : : }
2603 : : }
2604 : :
2605 : : return -EINVAL;
2606 : : }
2607 : :
2608 : : /* Takes an ethdev and a queue and sets up the tx function to be used based on
2609 : : * the queue parameters. Used in tx_queue_setup by primary process and then
2610 : : * in dev_init by secondary process when attaching to an existing ethdev.
2611 : : */
2612 : : void __rte_cold
2613 : 0 : ixgbe_set_tx_function(struct rte_eth_dev *dev, struct ci_tx_queue *txq)
2614 : : {
2615 : : /* Use a simple Tx queue (no offloads, no multi segs) if possible */
2616 [ # # ]: 0 : if ((txq->offloads == 0) &&
2617 [ # # ]: 0 : !(txq->using_ipsec) &&
2618 [ # # ]: 0 : (txq->tx_rs_thresh >= IXGBE_TX_MAX_BURST)) {
2619 : 0 : PMD_INIT_LOG(DEBUG, "Using simple tx code path");
2620 : 0 : dev->tx_pkt_prepare = rte_eth_tx_pkt_prepare_dummy;
2621 [ # # # # ]: 0 : if (txq->tx_rs_thresh <= IXGBE_TX_MAX_FREE_BUF_SZ &&
2622 [ # # ]: 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128 &&
2623 [ # # ]: 0 : (rte_eal_process_type() != RTE_PROC_PRIMARY ||
2624 : 0 : ixgbe_txq_vec_setup(txq) == 0)) {
2625 : 0 : PMD_INIT_LOG(DEBUG, "Vector tx enabled.");
2626 : 0 : dev->recycle_tx_mbufs_reuse = ixgbe_recycle_tx_mbufs_reuse_vec;
2627 : 0 : dev->tx_pkt_burst = ixgbe_xmit_pkts_vec;
2628 : : } else {
2629 : 0 : dev->tx_pkt_burst = ixgbe_xmit_pkts_simple;
2630 : : }
2631 : : } else {
2632 : 0 : PMD_INIT_LOG(DEBUG, "Using full-featured tx code path");
2633 : 0 : PMD_INIT_LOG(DEBUG,
2634 : : " - offloads = 0x%" PRIx64,
2635 : : txq->offloads);
2636 : 0 : PMD_INIT_LOG(DEBUG,
2637 : : " - tx_rs_thresh = %lu [IXGBE_TX_MAX_BURST=%lu]",
2638 : : (unsigned long)txq->tx_rs_thresh,
2639 : : (unsigned long)IXGBE_TX_MAX_BURST);
2640 : 0 : dev->tx_pkt_burst = ixgbe_xmit_pkts;
2641 : 0 : dev->tx_pkt_prepare = ixgbe_prep_pkts;
2642 : : }
2643 : 0 : }
2644 : :
2645 : : uint64_t
2646 : 0 : ixgbe_get_tx_queue_offloads(struct rte_eth_dev *dev)
2647 : : {
2648 : : RTE_SET_USED(dev);
2649 : :
2650 : 0 : return 0;
2651 : : }
2652 : :
2653 : : uint64_t
2654 : 0 : ixgbe_get_tx_port_offloads(struct rte_eth_dev *dev)
2655 : : {
2656 : : uint64_t tx_offload_capa;
2657 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2658 : :
2659 : : tx_offload_capa =
2660 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
2661 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
2662 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
2663 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
2664 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
2665 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
2666 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
2667 : :
2668 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
2669 : : hw->mac.type == ixgbe_mac_X540)
2670 : : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
2671 : :
2672 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
2673 : : hw->mac.type == ixgbe_mac_X550EM_x ||
2674 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
2675 : : hw->mac.type == ixgbe_mac_E610)
2676 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
2677 : :
2678 [ # # ]: 0 : if (dev->security_ctx)
2679 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
2680 : 0 : return tx_offload_capa;
2681 : : }
2682 : :
2683 : : int __rte_cold
2684 : 0 : ixgbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
2685 : : uint16_t queue_idx,
2686 : : uint16_t nb_desc,
2687 : : unsigned int socket_id,
2688 : : const struct rte_eth_txconf *tx_conf)
2689 : : {
2690 : : const struct rte_memzone *tz;
2691 : : struct ci_tx_queue *txq;
2692 : : struct ixgbe_hw *hw;
2693 : : uint16_t tx_rs_thresh, tx_free_thresh;
2694 : : uint64_t offloads;
2695 : :
2696 : 0 : PMD_INIT_FUNC_TRACE();
2697 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2698 : :
2699 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2700 : :
2701 : : /*
2702 : : * Validate number of transmit descriptors.
2703 : : * It must not exceed hardware maximum, and must be multiple
2704 : : * of IXGBE_ALIGN.
2705 : : */
2706 [ # # ]: 0 : if (nb_desc % IXGBE_TXD_ALIGN != 0 ||
2707 [ # # ]: 0 : (nb_desc > IXGBE_MAX_RING_DESC) ||
2708 : : (nb_desc < IXGBE_MIN_RING_DESC)) {
2709 : : return -EINVAL;
2710 : : }
2711 : :
2712 : : /*
2713 : : * The following two parameters control the setting of the RS bit on
2714 : : * transmit descriptors.
2715 : : * TX descriptors will have their RS bit set after txq->tx_rs_thresh
2716 : : * descriptors have been used.
2717 : : * The TX descriptor ring will be cleaned after txq->tx_free_thresh
2718 : : * descriptors are used or if the number of descriptors required
2719 : : * to transmit a packet is greater than the number of free TX
2720 : : * descriptors.
2721 : : * The following constraints must be satisfied:
2722 : : * tx_rs_thresh must be greater than 0.
2723 : : * tx_rs_thresh must be less than the size of the ring minus 2.
2724 : : * tx_rs_thresh must be less than or equal to tx_free_thresh.
2725 : : * tx_rs_thresh must be a divisor of the ring size.
2726 : : * tx_free_thresh must be greater than 0.
2727 : : * tx_free_thresh must be less than the size of the ring minus 3.
2728 : : * tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
2729 : : * One descriptor in the TX ring is used as a sentinel to avoid a
2730 : : * H/W race condition, hence the maximum threshold constraints.
2731 : : * When set to zero use default values.
2732 : : */
2733 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2734 : : tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2735 : : /* force tx_rs_thresh to adapt an aggressive tx_free_thresh */
2736 [ # # ]: 0 : tx_rs_thresh = (DEFAULT_TX_RS_THRESH + tx_free_thresh > nb_desc) ?
2737 : : nb_desc - tx_free_thresh : DEFAULT_TX_RS_THRESH;
2738 [ # # ]: 0 : if (tx_conf->tx_rs_thresh > 0)
2739 : : tx_rs_thresh = tx_conf->tx_rs_thresh;
2740 [ # # ]: 0 : if (tx_rs_thresh + tx_free_thresh > nb_desc) {
2741 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
2742 : : "exceed nb_desc. (tx_rs_thresh=%u "
2743 : : "tx_free_thresh=%u nb_desc=%u port = %d queue=%d)",
2744 : : (unsigned int)tx_rs_thresh,
2745 : : (unsigned int)tx_free_thresh,
2746 : : (unsigned int)nb_desc,
2747 : : (int)dev->data->port_id,
2748 : : (int)queue_idx);
2749 : 0 : return -(EINVAL);
2750 : : }
2751 [ # # ]: 0 : if (tx_rs_thresh >= (nb_desc - 2)) {
2752 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the number "
2753 : : "of TX descriptors minus 2. (tx_rs_thresh=%u "
2754 : : "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
2755 : : (int)dev->data->port_id, (int)queue_idx);
2756 : 0 : return -(EINVAL);
2757 : : }
2758 [ # # ]: 0 : if (tx_rs_thresh > DEFAULT_TX_RS_THRESH) {
2759 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less or equal than %u. "
2760 : : "(tx_rs_thresh=%u port=%d queue=%d)",
2761 : : DEFAULT_TX_RS_THRESH, (unsigned int)tx_rs_thresh,
2762 : : (int)dev->data->port_id, (int)queue_idx);
2763 : 0 : return -(EINVAL);
2764 : : }
2765 [ # # ]: 0 : if (tx_free_thresh >= (nb_desc - 3)) {
2766 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
2767 : : "tx_free_thresh must be less than the number of "
2768 : : "TX descriptors minus 3. (tx_free_thresh=%u "
2769 : : "port=%d queue=%d)",
2770 : : (unsigned int)tx_free_thresh,
2771 : : (int)dev->data->port_id, (int)queue_idx);
2772 : 0 : return -(EINVAL);
2773 : : }
2774 [ # # ]: 0 : if (tx_rs_thresh > tx_free_thresh) {
2775 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or equal to "
2776 : : "tx_free_thresh. (tx_free_thresh=%u "
2777 : : "tx_rs_thresh=%u port=%d queue=%d)",
2778 : : (unsigned int)tx_free_thresh,
2779 : : (unsigned int)tx_rs_thresh,
2780 : : (int)dev->data->port_id,
2781 : : (int)queue_idx);
2782 : 0 : return -(EINVAL);
2783 : : }
2784 [ # # ]: 0 : if ((nb_desc % tx_rs_thresh) != 0) {
2785 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
2786 : : "number of TX descriptors. (tx_rs_thresh=%u "
2787 : : "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
2788 : : (int)dev->data->port_id, (int)queue_idx);
2789 : 0 : return -(EINVAL);
2790 : : }
2791 [ # # ]: 0 : if (!rte_is_power_of_2(tx_rs_thresh)) {
2792 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh must be a power of 2. (tx_rs_thresh=%u port=%d queue=%d)",
2793 : : (unsigned int)tx_rs_thresh,
2794 : : (int)dev->data->port_id,
2795 : : (int)queue_idx);
2796 : 0 : return -(EINVAL);
2797 : : }
2798 : :
2799 : : /*
2800 : : * If rs_bit_thresh is greater than 1, then TX WTHRESH should be
2801 : : * set to 0. If WTHRESH is greater than zero, the RS bit is ignored
2802 : : * by the NIC and all descriptors are written back after the NIC
2803 : : * accumulates WTHRESH descriptors.
2804 : : */
2805 [ # # # # ]: 0 : if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
2806 : 0 : PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
2807 : : "tx_rs_thresh is greater than 1. (tx_rs_thresh=%u "
2808 : : "port=%d queue=%d)", (unsigned int)tx_rs_thresh,
2809 : : (int)dev->data->port_id, (int)queue_idx);
2810 : 0 : return -(EINVAL);
2811 : : }
2812 : :
2813 : : /* Free memory prior to re-allocation if needed... */
2814 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
2815 : 0 : ixgbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
2816 : 0 : dev->data->tx_queues[queue_idx] = NULL;
2817 : : }
2818 : :
2819 : : /* First allocate the tx queue data structure */
2820 : 0 : txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct ci_tx_queue) +
2821 : : sizeof(struct ixgbe_advctx_info) * IXGBE_CTX_NUM,
2822 : : RTE_CACHE_LINE_SIZE, socket_id);
2823 [ # # ]: 0 : if (txq == NULL)
2824 : : return -ENOMEM;
2825 : 0 : txq->ctx_cache = RTE_PTR_ADD(txq, sizeof(struct ci_tx_queue));
2826 : :
2827 : : /*
2828 : : * Allocate TX ring hardware descriptors. A memzone large enough to
2829 : : * handle the maximum ring size is allocated in order to allow for
2830 : : * resizing in later calls to the queue setup function.
2831 : : */
2832 : 0 : tz = rte_eth_dma_zone_reserve(dev, "ixgbe_tx_ring", queue_idx,
2833 : : sizeof(union ixgbe_adv_tx_desc) * IXGBE_MAX_RING_DESC,
2834 : : IXGBE_ALIGN, socket_id);
2835 [ # # ]: 0 : if (tz == NULL) {
2836 : 0 : ixgbe_tx_queue_release(txq);
2837 : 0 : return -ENOMEM;
2838 : : }
2839 : :
2840 : 0 : txq->mz = tz;
2841 : 0 : txq->nb_tx_desc = nb_desc;
2842 [ # # ]: 0 : txq->tx_rs_thresh = tx_rs_thresh;
2843 : 0 : txq->log2_rs_thresh = rte_log2_u32(tx_rs_thresh);
2844 : 0 : txq->tx_free_thresh = tx_free_thresh;
2845 : 0 : txq->pthresh = tx_conf->tx_thresh.pthresh;
2846 : 0 : txq->hthresh = tx_conf->tx_thresh.hthresh;
2847 : 0 : txq->wthresh = tx_conf->tx_thresh.wthresh;
2848 : 0 : txq->queue_id = queue_idx;
2849 [ # # ]: 0 : txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2850 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2851 : 0 : txq->port_id = dev->data->port_id;
2852 : 0 : txq->fast_free_mp = offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ?
2853 [ # # ]: 0 : (void *)UINTPTR_MAX : NULL;
2854 : 0 : txq->offloads = offloads;
2855 : 0 : txq->ops = &def_txq_ops;
2856 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
2857 : 0 : txq->using_ipsec = !!(dev->data->dev_conf.txmode.offloads &
2858 : : RTE_ETH_TX_OFFLOAD_SECURITY);
2859 : :
2860 : : /*
2861 : : * Modification to set VFTDT for virtual function if vf is detected
2862 : : */
2863 : : if (ixgbe_is_vf(dev)) {
2864 : : /* mark this queue as VF, because VF needs special Tx behavior */
2865 : 0 : txq->is_vf = 1;
2866 : 0 : txq->qtx_tail = IXGBE_PCI_REG_ADDR(hw, IXGBE_VFTDT(queue_idx));
2867 : : } else {
2868 : 0 : txq->qtx_tail = IXGBE_PCI_REG_ADDR(hw, IXGBE_TDT(txq->reg_idx));
2869 : : }
2870 : :
2871 : 0 : txq->tx_ring_dma = tz->iova;
2872 : 0 : txq->ixgbe_tx_ring = (union ixgbe_adv_tx_desc *)tz->addr;
2873 : :
2874 : : /* Allocate software ring */
2875 : 0 : txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
2876 : : sizeof(struct ci_tx_entry) * nb_desc,
2877 : : RTE_CACHE_LINE_SIZE, socket_id);
2878 [ # # ]: 0 : if (txq->sw_ring == NULL) {
2879 : 0 : ixgbe_tx_queue_release(txq);
2880 : 0 : return -ENOMEM;
2881 : : }
2882 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
2883 : : txq->sw_ring, txq->ixgbe_tx_ring, txq->tx_ring_dma);
2884 : :
2885 : : /* Allocate RS last_id tracking array */
2886 : 0 : uint16_t num_rs_buckets = nb_desc / tx_rs_thresh;
2887 : 0 : txq->rs_last_id = rte_zmalloc_socket(NULL, sizeof(txq->rs_last_id[0]) * num_rs_buckets,
2888 : : RTE_CACHE_LINE_SIZE, socket_id);
2889 [ # # ]: 0 : if (txq->rs_last_id == NULL) {
2890 : 0 : ixgbe_tx_queue_release(txq);
2891 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for RS last_id array");
2892 : 0 : return -ENOMEM;
2893 : : }
2894 : :
2895 : : /* set up vector or scalar TX function as appropriate */
2896 : 0 : ixgbe_set_tx_function(dev, txq);
2897 : :
2898 : 0 : txq->ops->reset(txq);
2899 : :
2900 : 0 : dev->data->tx_queues[queue_idx] = txq;
2901 : :
2902 : :
2903 : 0 : return 0;
2904 : : }
2905 : :
2906 : : /**
2907 : : * ixgbe_free_sc_cluster - free the not-yet-completed scattered cluster
2908 : : *
2909 : : * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
2910 : : * in the sw_rsc_ring is not set to NULL but rather points to the next
2911 : : * mbuf of this RSC aggregation (that has not been completed yet and still
2912 : : * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
2913 : : * will just free first "nb_segs" segments of the cluster explicitly by calling
2914 : : * an rte_pktmbuf_free_seg().
2915 : : *
2916 : : * @m scattered cluster head
2917 : : */
2918 : : static void __rte_cold
2919 : 0 : ixgbe_free_sc_cluster(struct rte_mbuf *m)
2920 : : {
2921 : 0 : uint16_t i, nb_segs = m->nb_segs;
2922 : : struct rte_mbuf *next_seg;
2923 : :
2924 [ # # ]: 0 : for (i = 0; i < nb_segs; i++) {
2925 : 0 : next_seg = m->next;
2926 : : rte_pktmbuf_free_seg(m);
2927 : : m = next_seg;
2928 : : }
2929 : 0 : }
2930 : :
2931 : : static void __rte_cold
2932 : 0 : ixgbe_rx_queue_release_mbufs_non_vec(struct ci_rx_queue *rxq)
2933 : : {
2934 : : unsigned i;
2935 : :
2936 [ # # ]: 0 : if (rxq->sw_ring != NULL) {
2937 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
2938 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
2939 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2940 : 0 : rxq->sw_ring[i].mbuf = NULL;
2941 : : }
2942 : : }
2943 [ # # ]: 0 : if (rxq->rx_nb_avail) {
2944 [ # # ]: 0 : for (i = 0; i < rxq->rx_nb_avail; ++i) {
2945 : : struct rte_mbuf *mb;
2946 : :
2947 : 0 : mb = rxq->rx_stage[rxq->rx_next_avail + i];
2948 : : rte_pktmbuf_free_seg(mb);
2949 : : }
2950 : 0 : rxq->rx_nb_avail = 0;
2951 : : }
2952 : : }
2953 : :
2954 [ # # ]: 0 : if (rxq->sw_sc_ring)
2955 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++)
2956 [ # # ]: 0 : if (rxq->sw_sc_ring[i].fbuf) {
2957 : 0 : ixgbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
2958 : 0 : rxq->sw_sc_ring[i].fbuf = NULL;
2959 : : }
2960 : 0 : }
2961 : :
2962 : : static void __rte_cold
2963 : 0 : ixgbe_rx_queue_release_mbufs(struct ci_rx_queue *rxq)
2964 : : {
2965 [ # # ]: 0 : if (rxq->vector_rx)
2966 : 0 : ixgbe_rx_queue_release_mbufs_vec(rxq);
2967 : : else
2968 : 0 : ixgbe_rx_queue_release_mbufs_non_vec(rxq);
2969 : 0 : }
2970 : :
2971 : : static void __rte_cold
2972 : 0 : ixgbe_rx_queue_release(struct ci_rx_queue *rxq)
2973 : : {
2974 [ # # ]: 0 : if (rxq != NULL) {
2975 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
2976 : 0 : rte_free(rxq->sw_ring);
2977 : 0 : rte_free(rxq->sw_sc_ring);
2978 : 0 : rte_memzone_free(rxq->mz);
2979 : 0 : rte_free(rxq);
2980 : : }
2981 : 0 : }
2982 : :
2983 : : void __rte_cold
2984 : 0 : ixgbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2985 : : {
2986 : 0 : ixgbe_rx_queue_release(dev->data->rx_queues[qid]);
2987 : 0 : }
2988 : :
2989 : : /*
2990 : : * Check if Rx Burst Bulk Alloc function can be used.
2991 : : * Return
2992 : : * 0: the preconditions are satisfied and the bulk allocation function
2993 : : * can be used.
2994 : : * -EINVAL: the preconditions are NOT satisfied and the default Rx burst
2995 : : * function must be used.
2996 : : */
2997 : : static inline int __rte_cold
2998 : 0 : check_rx_burst_bulk_alloc_preconditions(struct ci_rx_queue *rxq)
2999 : : {
3000 : : int ret = 0;
3001 : :
3002 : : /*
3003 : : * Make sure the following pre-conditions are satisfied:
3004 : : * rxq->rx_free_thresh >= IXGBE_RX_MAX_BURST
3005 : : * rxq->rx_free_thresh < rxq->nb_rx_desc
3006 : : * (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
3007 : : * Scattered packets are not supported. This should be checked
3008 : : * outside of this function.
3009 : : */
3010 [ # # ]: 0 : if (!(rxq->rx_free_thresh >= IXGBE_RX_MAX_BURST)) {
3011 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
3012 : : "rxq->rx_free_thresh=%d, "
3013 : : "IXGBE_RX_MAX_BURST=%d",
3014 : : rxq->rx_free_thresh, IXGBE_RX_MAX_BURST);
3015 : : ret = -EINVAL;
3016 [ # # ]: 0 : } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
3017 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
3018 : : "rxq->rx_free_thresh=%d, "
3019 : : "rxq->nb_rx_desc=%d",
3020 : : rxq->rx_free_thresh, rxq->nb_rx_desc);
3021 : : ret = -EINVAL;
3022 [ # # ]: 0 : } else if (!((rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)) {
3023 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
3024 : : "rxq->nb_rx_desc=%d, "
3025 : : "rxq->rx_free_thresh=%d",
3026 : : rxq->nb_rx_desc, rxq->rx_free_thresh);
3027 : : ret = -EINVAL;
3028 : : }
3029 : :
3030 : 0 : return ret;
3031 : : }
3032 : :
3033 : : /* Reset dynamic ixgbe_rx_queue fields back to defaults */
3034 : : static void __rte_cold
3035 : 0 : ixgbe_reset_rx_queue(struct ixgbe_adapter *adapter, struct ci_rx_queue *rxq)
3036 : : {
3037 : : static const union ixgbe_adv_rx_desc zeroed_desc = {{0}};
3038 : : unsigned i;
3039 : 0 : uint16_t len = rxq->nb_rx_desc;
3040 : :
3041 : : /*
3042 : : * By default, the Rx queue setup function allocates enough memory for
3043 : : * IXGBE_MAX_RING_DESC. The Rx Burst bulk allocation function requires
3044 : : * extra memory at the end of the descriptor ring to be zero'd out.
3045 : : */
3046 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
3047 : : /* zero out extra memory */
3048 : 0 : len += IXGBE_RX_MAX_BURST;
3049 : :
3050 : : /*
3051 : : * Zero out HW ring memory. Zero out extra memory at the end of
3052 : : * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
3053 : : * reads extra memory as zeros.
3054 : : */
3055 [ # # ]: 0 : for (i = 0; i < len; i++) {
3056 : 0 : rxq->ixgbe_rx_ring[i] = zeroed_desc;
3057 : : }
3058 : :
3059 : : /*
3060 : : * initialize extra software ring entries. Space for these extra
3061 : : * entries is always allocated
3062 : : */
3063 : 0 : memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
3064 [ # # ]: 0 : for (i = rxq->nb_rx_desc; i < len; ++i) {
3065 : 0 : rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
3066 : : }
3067 : :
3068 : 0 : rxq->rx_nb_avail = 0;
3069 : 0 : rxq->rx_next_avail = 0;
3070 : 0 : rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
3071 : 0 : rxq->rx_tail = 0;
3072 : 0 : rxq->nb_rx_hold = 0;
3073 : :
3074 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
3075 : :
3076 : 0 : rxq->pkt_first_seg = NULL;
3077 : 0 : rxq->pkt_last_seg = NULL;
3078 : 0 : rxq->rxrearm_start = 0;
3079 : 0 : rxq->rxrearm_nb = 0;
3080 : 0 : }
3081 : :
3082 : : static int
3083 : : ixgbe_is_vf(struct rte_eth_dev *dev)
3084 : : {
3085 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3086 : :
3087 [ # # # # : 0 : switch (hw->mac.type) {
# # ]
3088 : : case ixgbe_mac_82599_vf:
3089 : : case ixgbe_mac_X540_vf:
3090 : : case ixgbe_mac_X550_vf:
3091 : : case ixgbe_mac_X550EM_x_vf:
3092 : : case ixgbe_mac_X550EM_a_vf:
3093 : : case ixgbe_mac_E610_vf:
3094 : : return 1;
3095 : : default:
3096 : : return 0;
3097 : : }
3098 : : }
3099 : :
3100 : : uint64_t
3101 : 0 : ixgbe_get_rx_queue_offloads(struct rte_eth_dev *dev)
3102 : : {
3103 : : uint64_t offloads = 0;
3104 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3105 : :
3106 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB)
3107 : : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3108 : :
3109 : 0 : return offloads;
3110 : : }
3111 : :
3112 : : uint64_t
3113 : 0 : ixgbe_get_rx_port_offloads(struct rte_eth_dev *dev)
3114 : : {
3115 : : uint64_t offloads;
3116 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3117 : :
3118 : : offloads = RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3119 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3120 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3121 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3122 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3123 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3124 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3125 : :
3126 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
3127 : : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
3128 : :
3129 : : if (ixgbe_is_vf(dev) == 0)
3130 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
3131 : :
3132 : : /*
3133 : : * RSC is only supported by 82599 and x540 PF devices in a non-SR-IOV
3134 : : * mode.
3135 : : */
3136 [ # # ]: 0 : if ((hw->mac.type == ixgbe_mac_82599EB ||
3137 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540 ||
3138 : 0 : hw->mac.type == ixgbe_mac_X550) &&
3139 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active)
3140 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
3141 : :
3142 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
3143 : : hw->mac.type == ixgbe_mac_X540)
3144 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
3145 : :
3146 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
3147 : : hw->mac.type == ixgbe_mac_X550EM_x ||
3148 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
3149 : : hw->mac.type == ixgbe_mac_E610)
3150 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM;
3151 : :
3152 [ # # ]: 0 : if (dev->security_ctx)
3153 : 0 : offloads |= RTE_ETH_RX_OFFLOAD_SECURITY;
3154 : :
3155 : 0 : return offloads;
3156 : : }
3157 : :
3158 : : int __rte_cold
3159 : 0 : ixgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
3160 : : uint16_t queue_idx,
3161 : : uint16_t nb_desc,
3162 : : unsigned int socket_id,
3163 : : const struct rte_eth_rxconf *rx_conf,
3164 : : struct rte_mempool *mp)
3165 : : {
3166 : : const struct rte_memzone *rz;
3167 : : struct ci_rx_queue *rxq;
3168 : : struct ixgbe_hw *hw;
3169 : : uint16_t len;
3170 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
3171 : : uint64_t offloads;
3172 : :
3173 : 0 : PMD_INIT_FUNC_TRACE();
3174 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3175 : :
3176 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
3177 : :
3178 : : /*
3179 : : * Validate number of receive descriptors.
3180 : : * It must not exceed hardware maximum, and must be multiple
3181 : : * of IXGBE_ALIGN.
3182 : : */
3183 [ # # ]: 0 : if (nb_desc % IXGBE_RXD_ALIGN != 0 ||
3184 [ # # ]: 0 : (nb_desc > IXGBE_MAX_RING_DESC) ||
3185 : : (nb_desc < IXGBE_MIN_RING_DESC)) {
3186 : : return -EINVAL;
3187 : : }
3188 : :
3189 : : /* Check that ring size is > 2 * rx_free_thresh */
3190 [ # # ]: 0 : if (nb_desc <= 2 * rx_conf->rx_free_thresh) {
3191 : 0 : PMD_INIT_LOG(ERR, "rx ring size (%u) must be > 2 * rx_free_thresh (%u)",
3192 : : nb_desc, rx_conf->rx_free_thresh);
3193 [ # # ]: 0 : if (nb_desc == IXGBE_MIN_RING_DESC)
3194 : 0 : PMD_INIT_LOG(ERR, "To use the minimum ring size (%u), reduce rx_free_thresh to a lower value (recommended %u)",
3195 : : IXGBE_MIN_RING_DESC, IXGBE_MIN_RING_DESC / 4);
3196 : 0 : return -EINVAL;
3197 : : }
3198 : :
3199 : : /* Free memory prior to re-allocation if needed... */
3200 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
3201 : 0 : ixgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
3202 : 0 : dev->data->rx_queues[queue_idx] = NULL;
3203 : : }
3204 : :
3205 : : /* First allocate the rx queue data structure */
3206 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct ci_rx_queue),
3207 : : RTE_CACHE_LINE_SIZE, socket_id);
3208 [ # # ]: 0 : if (rxq == NULL)
3209 : : return -ENOMEM;
3210 : 0 : rxq->mp = mp;
3211 : 0 : rxq->nb_rx_desc = nb_desc;
3212 : 0 : rxq->rx_free_thresh = rx_conf->rx_free_thresh;
3213 : 0 : rxq->queue_id = queue_idx;
3214 [ # # ]: 0 : rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
3215 : 0 : queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
3216 : 0 : rxq->port_id = dev->data->port_id;
3217 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
3218 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
3219 : : else
3220 : 0 : rxq->crc_len = 0;
3221 : 0 : rxq->drop_en = rx_conf->rx_drop_en;
3222 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
3223 : 0 : rxq->offloads = offloads;
3224 : :
3225 : : /*
3226 : : * The packet type in RX descriptor is different for different NICs.
3227 : : * Some bits are used for x550 and E610 but reserved for other NICS.
3228 : : * So set different masks for different NICs.
3229 : : */
3230 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
3231 : : hw->mac.type == ixgbe_mac_X550EM_x ||
3232 : : hw->mac.type == ixgbe_mac_X550EM_a ||
3233 : : hw->mac.type == ixgbe_mac_X550_vf ||
3234 : : hw->mac.type == ixgbe_mac_X550EM_x_vf ||
3235 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a_vf ||
3236 : : hw->mac.type == ixgbe_mac_E610)
3237 : 0 : rxq->pkt_type_mask = IXGBE_PACKET_TYPE_MASK_X550;
3238 : : else
3239 : 0 : rxq->pkt_type_mask = IXGBE_PACKET_TYPE_MASK_82599;
3240 : :
3241 : : /*
3242 : : * 82599 errata, UDP frames with a 0 checksum can be marked as checksum
3243 : : * errors.
3244 : : */
3245 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB)
3246 : 0 : rxq->rx_udp_csum_zero_err = 1;
3247 : :
3248 : : /*
3249 : : * Allocate RX ring hardware descriptors. A memzone large enough to
3250 : : * handle the maximum ring size is allocated in order to allow for
3251 : : * resizing in later calls to the queue setup function.
3252 : : */
3253 : 0 : rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
3254 : : RX_RING_SZ, IXGBE_ALIGN, socket_id);
3255 [ # # ]: 0 : if (rz == NULL) {
3256 : 0 : ixgbe_rx_queue_release(rxq);
3257 : 0 : return -ENOMEM;
3258 : : }
3259 : :
3260 : 0 : rxq->mz = rz;
3261 : : /*
3262 : : * Zero init all the descriptors in the ring.
3263 : : */
3264 [ # # ]: 0 : memset(rz->addr, 0, RX_RING_SZ);
3265 : :
3266 : : /*
3267 : : * Modified to setup VFRDT for Virtual Function
3268 : : */
3269 : : if (ixgbe_is_vf(dev))
3270 : 0 : rxq->qrx_tail =
3271 : 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_VFRDT(queue_idx));
3272 : : else
3273 : 0 : rxq->qrx_tail =
3274 [ # # ]: 0 : IXGBE_PCI_REG_ADDR(hw, IXGBE_RDT(rxq->reg_idx));
3275 : :
3276 : 0 : rxq->rx_ring_phys_addr = rz->iova;
3277 : 0 : rxq->ixgbe_rx_ring = (union ixgbe_adv_rx_desc *)rz->addr;
3278 : :
3279 : : /*
3280 : : * Certain constraints must be met in order to use the bulk buffer
3281 : : * allocation Rx burst function. If any of Rx queues doesn't meet them
3282 : : * the feature should be disabled for the whole port.
3283 : : */
3284 [ # # ]: 0 : if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
3285 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Rx Bulk Alloc "
3286 : : "preconditions - canceling the feature for "
3287 : : "the whole port[%d]",
3288 : : rxq->queue_id, rxq->port_id);
3289 : 0 : adapter->rx_bulk_alloc_allowed = false;
3290 : : }
3291 : :
3292 : : /*
3293 : : * Allocate software ring. Allow for space at the end of the
3294 : : * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
3295 : : * function does not access an invalid memory region.
3296 : : */
3297 : : len = nb_desc;
3298 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed)
3299 : 0 : len += IXGBE_RX_MAX_BURST;
3300 : :
3301 : 0 : rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
3302 : : sizeof(struct ci_rx_entry) * len,
3303 : : RTE_CACHE_LINE_SIZE, socket_id);
3304 [ # # ]: 0 : if (!rxq->sw_ring) {
3305 : 0 : ixgbe_rx_queue_release(rxq);
3306 : 0 : return -ENOMEM;
3307 : : }
3308 : :
3309 : : /*
3310 : : * Always allocate even if it's not going to be needed in order to
3311 : : * simplify the code.
3312 : : *
3313 : : * This ring is used in LRO and Scattered Rx cases and Scattered Rx may
3314 : : * be requested in ixgbe_dev_rx_init(), which is called later from
3315 : : * dev_start() flow.
3316 : : */
3317 : 0 : rxq->sw_sc_ring =
3318 : 0 : rte_zmalloc_socket("rxq->sw_sc_ring",
3319 : : sizeof(struct ci_rx_entry_sc) * len,
3320 : : RTE_CACHE_LINE_SIZE, socket_id);
3321 [ # # ]: 0 : if (!rxq->sw_sc_ring) {
3322 : 0 : ixgbe_rx_queue_release(rxq);
3323 : 0 : return -ENOMEM;
3324 : : }
3325 : :
3326 : 0 : PMD_INIT_LOG(DEBUG, "sw_ring=%p sw_sc_ring=%p hw_ring=%p "
3327 : : "dma_addr=0x%"PRIx64,
3328 : : rxq->sw_ring, rxq->sw_sc_ring, rxq->ixgbe_rx_ring,
3329 : : rxq->rx_ring_phys_addr);
3330 : :
3331 [ # # ]: 0 : if (!rte_is_power_of_2(nb_desc)) {
3332 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
3333 : : "preconditions - canceling the feature for "
3334 : : "the whole port[%d]",
3335 : : rxq->queue_id, rxq->port_id);
3336 : 0 : adapter->rx_vec_allowed = false;
3337 : : } else
3338 : 0 : ixgbe_rxq_vec_setup(rxq);
3339 : :
3340 : 0 : dev->data->rx_queues[queue_idx] = rxq;
3341 : :
3342 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
3343 : :
3344 : 0 : return 0;
3345 : : }
3346 : :
3347 : : int
3348 : 0 : ixgbe_dev_rx_queue_count(void *rx_queue)
3349 : : {
3350 : : #define IXGBE_RXQ_SCAN_INTERVAL 4
3351 : : volatile union ixgbe_adv_rx_desc *rxdp;
3352 : : struct ci_rx_queue *rxq;
3353 : : uint32_t desc = 0;
3354 : :
3355 : : rxq = rx_queue;
3356 : 0 : rxdp = &rxq->ixgbe_rx_ring[rxq->rx_tail];
3357 : :
3358 [ # # ]: 0 : while ((desc < rxq->nb_rx_desc) &&
3359 [ # # ]: 0 : (rxdp->wb.upper.status_error &
3360 : : rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD))) {
3361 : 0 : desc += IXGBE_RXQ_SCAN_INTERVAL;
3362 : 0 : rxdp += IXGBE_RXQ_SCAN_INTERVAL;
3363 [ # # ]: 0 : if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
3364 : 0 : rxdp = &(rxq->ixgbe_rx_ring[rxq->rx_tail +
3365 : 0 : desc - rxq->nb_rx_desc]);
3366 : : }
3367 : :
3368 : 0 : return desc;
3369 : : }
3370 : :
3371 : : int
3372 : 0 : ixgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
3373 : : {
3374 : : struct ci_rx_queue *rxq = rx_queue;
3375 : : volatile uint32_t *status;
3376 : : uint32_t nb_hold, desc;
3377 : :
3378 [ # # ]: 0 : if (unlikely(offset >= rxq->nb_rx_desc))
3379 : : return -EINVAL;
3380 : :
3381 [ # # ]: 0 : if (rxq->vector_rx)
3382 : 0 : nb_hold = rxq->rxrearm_nb;
3383 : : else
3384 : 0 : nb_hold = rxq->nb_rx_hold;
3385 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - nb_hold)
3386 : : return RTE_ETH_RX_DESC_UNAVAIL;
3387 : :
3388 : 0 : desc = rxq->rx_tail + offset;
3389 [ # # ]: 0 : if (desc >= rxq->nb_rx_desc)
3390 : 0 : desc -= rxq->nb_rx_desc;
3391 : :
3392 : 0 : status = &rxq->ixgbe_rx_ring[desc].wb.upper.status_error;
3393 [ # # ]: 0 : if (*status & rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD))
3394 : 0 : return RTE_ETH_RX_DESC_DONE;
3395 : :
3396 : : return RTE_ETH_RX_DESC_AVAIL;
3397 : : }
3398 : :
3399 : : int
3400 : 0 : ixgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
3401 : : {
3402 : : struct ci_tx_queue *txq = tx_queue;
3403 : : uint32_t desc;
3404 : :
3405 [ # # ]: 0 : if (unlikely(offset >= txq->nb_tx_desc))
3406 : : return -EINVAL;
3407 : :
3408 : 0 : desc = txq->tx_tail + offset;
3409 : : /* go to next desc that has the RS bit */
3410 : 0 : desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
3411 : : txq->tx_rs_thresh;
3412 [ # # ]: 0 : if (desc >= txq->nb_tx_desc) {
3413 : 0 : desc -= txq->nb_tx_desc;
3414 [ # # ]: 0 : if (desc >= txq->nb_tx_desc)
3415 : 0 : desc -= txq->nb_tx_desc;
3416 : : }
3417 : :
3418 [ # # ]: 0 : if (ixgbe_tx_desc_done(txq, desc))
3419 : 0 : return RTE_ETH_TX_DESC_DONE;
3420 : :
3421 : : return RTE_ETH_TX_DESC_FULL;
3422 : : }
3423 : :
3424 : : /*
3425 : : * Set up link loopback for X540/X550 mode Tx->Rx.
3426 : : */
3427 : : static inline void __rte_cold
3428 : 0 : ixgbe_setup_loopback_link_x540_x550(struct ixgbe_hw *hw, bool enable)
3429 : : {
3430 : : uint32_t macc;
3431 : 0 : PMD_INIT_FUNC_TRACE();
3432 : :
3433 : 0 : u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
3434 : :
3435 : 0 : hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
3436 : : IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
3437 : 0 : macc = IXGBE_READ_REG(hw, IXGBE_MACC);
3438 : :
3439 [ # # ]: 0 : if (enable) {
3440 : : /* datasheet 15.2.1: disable AUTONEG (PHY Bit 7.0.C) */
3441 : 0 : autoneg_reg |= IXGBE_MII_AUTONEG_ENABLE;
3442 : : /* datasheet 15.2.1: MACC.FLU = 1 (force link up) */
3443 : 0 : macc |= IXGBE_MACC_FLU;
3444 : : } else {
3445 : 0 : autoneg_reg &= ~IXGBE_MII_AUTONEG_ENABLE;
3446 : 0 : macc &= ~IXGBE_MACC_FLU;
3447 : : }
3448 : :
3449 : 0 : hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
3450 : : IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
3451 : :
3452 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MACC, macc);
3453 : 0 : }
3454 : :
3455 : : void __rte_cold
3456 : 0 : ixgbe_dev_clear_queues(struct rte_eth_dev *dev)
3457 : : {
3458 : : unsigned i;
3459 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
3460 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3461 : :
3462 : 0 : PMD_INIT_FUNC_TRACE();
3463 : :
3464 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3465 : 0 : struct ci_tx_queue *txq = dev->data->tx_queues[i];
3466 : :
3467 [ # # ]: 0 : if (txq != NULL) {
3468 : 0 : ci_txq_release_all_mbufs(txq, false);
3469 : 0 : txq->ops->reset(txq);
3470 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3471 : : }
3472 : : }
3473 : :
3474 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3475 : 0 : struct ci_rx_queue *rxq = dev->data->rx_queues[i];
3476 : :
3477 [ # # ]: 0 : if (rxq != NULL) {
3478 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
3479 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
3480 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
3481 : : }
3482 : : }
3483 : : /* If loopback mode was enabled, reconfigure the link accordingly */
3484 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
3485 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X540 ||
3486 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
3487 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
3488 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
3489 : : hw->mac.type == ixgbe_mac_E610)
3490 : 0 : ixgbe_setup_loopback_link_x540_x550(hw, false);
3491 : : }
3492 : 0 : }
3493 : :
3494 : : void
3495 : 0 : ixgbe_dev_free_queues(struct rte_eth_dev *dev)
3496 : : {
3497 : : unsigned i;
3498 : :
3499 : 0 : PMD_INIT_FUNC_TRACE();
3500 : :
3501 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3502 : 0 : ixgbe_dev_rx_queue_release(dev, i);
3503 : 0 : dev->data->rx_queues[i] = NULL;
3504 : : }
3505 : 0 : dev->data->nb_rx_queues = 0;
3506 : :
3507 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
3508 : 0 : ixgbe_dev_tx_queue_release(dev, i);
3509 : 0 : dev->data->tx_queues[i] = NULL;
3510 : : }
3511 : 0 : dev->data->nb_tx_queues = 0;
3512 : 0 : }
3513 : :
3514 : : /*********************************************************************
3515 : : *
3516 : : * Device RX/TX init functions
3517 : : *
3518 : : **********************************************************************/
3519 : :
3520 : : /**
3521 : : * Receive Side Scaling (RSS)
3522 : : * See section 7.1.2.8 in the following document:
3523 : : * "Intel 82599 10 GbE Controller Datasheet" - Revision 2.1 October 2009
3524 : : *
3525 : : * Principles:
3526 : : * The source and destination IP addresses of the IP header and the source
3527 : : * and destination ports of TCP/UDP headers, if any, of received packets are
3528 : : * hashed against a configurable random key to compute a 32-bit RSS hash result.
3529 : : * The seven (7) LSBs of the 32-bit hash result are used as an index into a
3530 : : * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
3531 : : * RSS output index which is used as the RX queue index where to store the
3532 : : * received packets.
3533 : : * The following output is supplied in the RX write-back descriptor:
3534 : : * - 32-bit result of the Microsoft RSS hash function,
3535 : : * - 4-bit RSS type field.
3536 : : */
3537 : :
3538 : : /*
3539 : : * RSS random key supplied in section 7.1.2.8.3 of the Intel 82599 datasheet.
3540 : : * Used as the default key.
3541 : : */
3542 : : static uint8_t rss_intel_key[40] = {
3543 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
3544 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
3545 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
3546 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
3547 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
3548 : : };
3549 : :
3550 : : /*
3551 : : * This function removes the rss configuration in the mrqe field of MRQC
3552 : : * register and tries to maintain other configurations in the field, such
3553 : : * DCB and Virtualization.
3554 : : *
3555 : : * The MRQC register supplied in section 8.2.3.7.12 of the Intel 82599
3556 : : * datasheet. From the datasheet, we know that the mrqe field is an enum. So,
3557 : : * masking the mrqe field with '~IXGBE_MRQC_RSSEN' may not completely disable
3558 : : * rss configuration. For example, the value of mrqe is equal to 0101b when DCB
3559 : : * and RSS with 4 TCs configured, however 'mrqe &= ~0x01' is equal to 0100b
3560 : : * which corresponds to DCB and RSS with 8 TCs.
3561 : : */
3562 : : static void
3563 : 0 : ixgbe_mrqc_rss_remove(struct ixgbe_hw *hw)
3564 : : {
3565 : : uint32_t mrqc;
3566 : : uint32_t mrqc_reg;
3567 : : uint32_t mrqe_val;
3568 : :
3569 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3570 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3571 : 0 : mrqe_val = mrqc & IXGBE_MRQC_MRQE_MASK;
3572 : :
3573 [ # # # # : 0 : switch (mrqe_val) {
# # ]
3574 : 0 : case IXGBE_MRQC_RSSEN:
3575 : : /* Completely disable rss */
3576 : : mrqe_val = 0;
3577 : 0 : break;
3578 : 0 : case IXGBE_MRQC_RTRSS8TCEN:
3579 : : mrqe_val = IXGBE_MRQC_RT8TCEN;
3580 : 0 : break;
3581 : 0 : case IXGBE_MRQC_RTRSS4TCEN:
3582 : : mrqe_val = IXGBE_MRQC_RT4TCEN;
3583 : 0 : break;
3584 : 0 : case IXGBE_MRQC_VMDQRSS64EN:
3585 : : mrqe_val = IXGBE_MRQC_VMDQEN;
3586 : 0 : break;
3587 : 0 : case IXGBE_MRQC_VMDQRSS32EN:
3588 : 0 : PMD_DRV_LOG(WARNING, "There is no regression for virtualization"
3589 : : " and RSS with 32 pools among the MRQE configurations"
3590 : : " after removing RSS, and left it unchanged.");
3591 : 0 : break;
3592 : : default:
3593 : : /* No rss configured, leave it as it is */
3594 : : break;
3595 : : }
3596 : 0 : mrqc = (mrqc & ~IXGBE_MRQC_MRQE_MASK) | mrqe_val;
3597 : 0 : IXGBE_WRITE_REG(hw, mrqc_reg, mrqc);
3598 : 0 : }
3599 : :
3600 : : static void
3601 : : ixgbe_rss_disable(struct rte_eth_dev *dev)
3602 : : {
3603 : : struct ixgbe_hw *hw;
3604 : :
3605 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3606 : : /* Remove the rss configuration and maintain the other configurations */
3607 : 0 : ixgbe_mrqc_rss_remove(hw);
3608 : 0 : }
3609 : :
3610 : : /*
3611 : : * This function checks whether the rss is enabled or not by comparing the mrqe
3612 : : * field with some RSS related enums and also considers the configurations for
3613 : : * DCB + RSS and Virtualization + RSS. It is necessary for getting the correct
3614 : : * rss hash configurations from the RSS Field Enable field of MRQC register
3615 : : * when both RSS and DCB/VMDQ are used.
3616 : : */
3617 : : static bool
3618 : 0 : ixgbe_rss_enabled(struct ixgbe_hw *hw)
3619 : : {
3620 : : uint32_t mrqc;
3621 : : uint32_t mrqc_reg;
3622 : : uint32_t mrqe_val;
3623 : :
3624 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3625 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3626 : 0 : mrqe_val = mrqc & IXGBE_MRQC_MRQE_MASK;
3627 : :
3628 : 0 : if (mrqe_val == IXGBE_MRQC_RSSEN ||
3629 [ # # ]: 0 : mrqe_val == IXGBE_MRQC_RTRSS8TCEN ||
3630 : 0 : mrqe_val == IXGBE_MRQC_RTRSS4TCEN ||
3631 [ # # # # ]: 0 : mrqe_val == IXGBE_MRQC_VMDQRSS64EN ||
3632 : : mrqe_val == IXGBE_MRQC_VMDQRSS32EN)
3633 : 0 : return true;
3634 : :
3635 : : return false;
3636 : : }
3637 : :
3638 : : static void
3639 : 0 : ixgbe_hw_rss_hash_set(struct ixgbe_hw *hw, struct rte_eth_rss_conf *rss_conf)
3640 : : {
3641 : : uint8_t *hash_key;
3642 : : uint32_t mrqc;
3643 : : uint32_t rss_key;
3644 : : uint64_t rss_hf;
3645 : : uint16_t i;
3646 : : uint32_t mrqc_reg;
3647 : : uint32_t rssrk_reg;
3648 : :
3649 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3650 : 0 : rssrk_reg = ixgbe_rssrk_reg_get(hw->mac.type, 0);
3651 : :
3652 : 0 : hash_key = rss_conf->rss_key;
3653 [ # # ]: 0 : if (hash_key != NULL) {
3654 : : /* Fill in RSS hash key */
3655 [ # # ]: 0 : for (i = 0; i < 10; i++) {
3656 : 0 : rss_key = hash_key[(i * 4)];
3657 : 0 : rss_key |= hash_key[(i * 4) + 1] << 8;
3658 : 0 : rss_key |= hash_key[(i * 4) + 2] << 16;
3659 : 0 : rss_key |= hash_key[(i * 4) + 3] << 24;
3660 : 0 : IXGBE_WRITE_REG_ARRAY(hw, rssrk_reg, i, rss_key);
3661 : : }
3662 : : }
3663 : :
3664 : : /* Set configured hashing protocols in MRQC register */
3665 : 0 : rss_hf = rss_conf->rss_hf;
3666 : : mrqc = IXGBE_MRQC_RSSEN; /* Enable RSS */
3667 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
3668 : : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4;
3669 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
3670 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_TCP;
3671 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
3672 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6;
3673 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_EX)
3674 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX;
3675 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
3676 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
3677 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
3678 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP;
3679 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
3680 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3681 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
3682 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3683 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
3684 : 0 : mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
3685 : 0 : IXGBE_WRITE_REG(hw, mrqc_reg, mrqc);
3686 : 0 : }
3687 : :
3688 : : int
3689 : 0 : ixgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
3690 : : struct rte_eth_rss_conf *rss_conf)
3691 : : {
3692 : : struct ixgbe_hw *hw;
3693 : : uint64_t rss_hf;
3694 : :
3695 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3696 : :
3697 [ # # ]: 0 : if (!ixgbe_rss_update_sp(hw->mac.type)) {
3698 : 0 : PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
3699 : : "NIC.");
3700 : 0 : return -ENOTSUP;
3701 : : }
3702 : :
3703 : : /*
3704 : : * Excerpt from section 7.1.2.8 Receive-Side Scaling (RSS):
3705 : : * "RSS enabling cannot be done dynamically while it must be
3706 : : * preceded by a software reset"
3707 : : * Before changing anything, first check that the update RSS operation
3708 : : * does not attempt to disable RSS, if RSS was enabled at
3709 : : * initialization time, or does not attempt to enable RSS, if RSS was
3710 : : * disabled at initialization time.
3711 : : */
3712 : 0 : rss_hf = rss_conf->rss_hf & IXGBE_RSS_OFFLOAD_ALL;
3713 [ # # ]: 0 : if (!ixgbe_rss_enabled(hw)) { /* RSS disabled */
3714 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
3715 : : return -(EINVAL);
3716 : 0 : return 0; /* Nothing to do */
3717 : : }
3718 : : /* RSS enabled */
3719 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
3720 : : return -(EINVAL);
3721 : 0 : ixgbe_hw_rss_hash_set(hw, rss_conf);
3722 : 0 : return 0;
3723 : : }
3724 : :
3725 : : int
3726 : 0 : ixgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
3727 : : struct rte_eth_rss_conf *rss_conf)
3728 : : {
3729 : : struct ixgbe_hw *hw;
3730 : : uint8_t *hash_key;
3731 : : uint32_t mrqc;
3732 : : uint32_t rss_key;
3733 : : uint64_t rss_hf;
3734 : : uint16_t i;
3735 : : uint32_t mrqc_reg;
3736 : : uint32_t rssrk_reg;
3737 : :
3738 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3739 : 0 : mrqc_reg = ixgbe_mrqc_reg_get(hw->mac.type);
3740 : 0 : rssrk_reg = ixgbe_rssrk_reg_get(hw->mac.type, 0);
3741 : 0 : hash_key = rss_conf->rss_key;
3742 [ # # ]: 0 : if (hash_key != NULL) {
3743 : : /* Return RSS hash key */
3744 [ # # ]: 0 : for (i = 0; i < IXGBE_HKEY_MAX_INDEX; i++) {
3745 : 0 : rss_key = IXGBE_READ_REG_ARRAY(hw, rssrk_reg, i);
3746 : 0 : hash_key[(i * 4)] = rss_key & 0x000000FF;
3747 : 0 : hash_key[(i * 4) + 1] = (rss_key >> 8) & 0x000000FF;
3748 : 0 : hash_key[(i * 4) + 2] = (rss_key >> 16) & 0x000000FF;
3749 : 0 : hash_key[(i * 4) + 3] = (rss_key >> 24) & 0x000000FF;
3750 : : }
3751 : 0 : rss_conf->rss_key_len = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
3752 : : }
3753 : :
3754 [ # # ]: 0 : if (!ixgbe_rss_enabled(hw)) { /* RSS is disabled */
3755 : 0 : rss_conf->rss_hf = 0;
3756 : 0 : return 0;
3757 : : }
3758 : :
3759 : : /* Get RSS functions configured in MRQC register */
3760 : 0 : mrqc = IXGBE_READ_REG(hw, mrqc_reg);
3761 : :
3762 : : rss_hf = 0;
3763 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4)
3764 : : rss_hf |= RTE_ETH_RSS_IPV4;
3765 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4_TCP)
3766 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
3767 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6)
3768 : 0 : rss_hf |= RTE_ETH_RSS_IPV6;
3769 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX)
3770 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_EX;
3771 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_TCP)
3772 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
3773 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP)
3774 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_TCP_EX;
3775 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV4_UDP)
3776 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
3777 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_UDP)
3778 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP;
3779 [ # # ]: 0 : if (mrqc & IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP)
3780 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_UDP_EX;
3781 : 0 : rss_conf->rss_hf = rss_hf;
3782 : 0 : return 0;
3783 : : }
3784 : :
3785 : : static void
3786 : 0 : ixgbe_rss_configure(struct rte_eth_dev *dev)
3787 : : {
3788 : : struct rte_eth_rss_conf rss_conf;
3789 : : struct ixgbe_adapter *adapter;
3790 : : struct ixgbe_hw *hw;
3791 : : uint32_t reta;
3792 : : uint16_t i;
3793 : : uint16_t j;
3794 : : uint16_t sp_reta_size;
3795 : : uint32_t reta_reg;
3796 : :
3797 : 0 : PMD_INIT_FUNC_TRACE();
3798 : 0 : adapter = dev->data->dev_private;
3799 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3800 : :
3801 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
3802 : :
3803 : : /*
3804 : : * Fill in redirection table
3805 : : * The byte-swap is needed because NIC registers are in
3806 : : * little-endian order.
3807 : : */
3808 [ # # ]: 0 : if (adapter->rss_reta_updated == 0) {
3809 : : reta = 0;
3810 [ # # ]: 0 : for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
3811 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
3812 : :
3813 [ # # ]: 0 : if (j == dev->data->nb_rx_queues)
3814 : : j = 0;
3815 : 0 : reta = (reta << 8) | j;
3816 [ # # ]: 0 : if ((i & 3) == 3)
3817 [ # # ]: 0 : IXGBE_WRITE_REG(hw, reta_reg,
3818 : : rte_bswap32(reta));
3819 : : }
3820 : : }
3821 : :
3822 : : /*
3823 : : * Configure the RSS key and the RSS protocols used to compute
3824 : : * the RSS hash of input packets.
3825 : : */
3826 : 0 : rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
3827 [ # # ]: 0 : if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
3828 : : ixgbe_rss_disable(dev);
3829 : 0 : return;
3830 : : }
3831 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
3832 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
3833 : 0 : ixgbe_hw_rss_hash_set(hw, &rss_conf);
3834 : : }
3835 : :
3836 : : #define NUM_VFTA_REGISTERS 128
3837 : :
3838 : : static void
3839 : 0 : ixgbe_vmdq_dcb_configure(struct rte_eth_dev *dev)
3840 : : {
3841 : : struct rte_eth_vmdq_dcb_conf *cfg;
3842 : : struct ixgbe_hw *hw;
3843 : : enum rte_eth_nb_pools num_pools;
3844 : : uint32_t mrqc, vt_ctl, queue_mapping, vlanctrl;
3845 : : uint16_t pbsize;
3846 : : uint8_t nb_tcs; /* number of traffic classes */
3847 : : int i;
3848 : :
3849 : 0 : PMD_INIT_FUNC_TRACE();
3850 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3851 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3852 : 0 : num_pools = cfg->nb_queue_pools;
3853 : : /* Check we have a valid number of pools */
3854 [ # # ]: 0 : if (num_pools != RTE_ETH_16_POOLS && num_pools != RTE_ETH_32_POOLS) {
3855 : : ixgbe_rss_disable(dev);
3856 : 0 : return;
3857 : : }
3858 : : /* 16 pools -> 8 traffic classes, 32 pools -> 4 traffic classes */
3859 : 0 : nb_tcs = (uint8_t)(RTE_ETH_VMDQ_DCB_NUM_QUEUES / (int)num_pools);
3860 : :
3861 : : /*
3862 : : * RXPBSIZE
3863 : : * Split the MAC Rx packet buffer equally across traffic classes.
3864 : : * hw->mac.rx_pb_size is the total size in KB.
3865 : : */
3866 : 0 : pbsize = (uint16_t)(hw->mac.rx_pb_size / nb_tcs);
3867 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
3868 : 0 : uint32_t rxpbsize = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
3869 : :
3870 : 0 : rxpbsize &= (~(0x3FF << IXGBE_RXPBSIZE_SHIFT));
3871 : : /* clear 10 bits. */
3872 : 0 : rxpbsize |= (pbsize << IXGBE_RXPBSIZE_SHIFT); /* set value */
3873 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
3874 : : }
3875 : : /* zero alloc all unused TCs */
3876 [ # # ]: 0 : for (i = nb_tcs; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
3877 : 0 : uint32_t rxpbsize = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
3878 : :
3879 : 0 : rxpbsize &= (~(0x3FF << IXGBE_RXPBSIZE_SHIFT));
3880 : : /* clear 10 bits. */
3881 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
3882 : : }
3883 : :
3884 : : /* MRQC: enable vmdq and dcb */
3885 : : mrqc = (num_pools == RTE_ETH_16_POOLS) ?
3886 [ # # ]: 0 : IXGBE_MRQC_VMDQRT8TCEN : IXGBE_MRQC_VMDQRT4TCEN;
3887 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3888 : :
3889 : : /* PFVTCTL: turn on virtualisation and set the default pool */
3890 : : vt_ctl = IXGBE_VT_CTL_VT_ENABLE | IXGBE_VT_CTL_REPLEN;
3891 [ # # ]: 0 : if (cfg->enable_default_pool) {
3892 : 0 : vt_ctl |= (cfg->default_pool << IXGBE_VT_CTL_POOL_SHIFT);
3893 : : } else {
3894 : : vt_ctl |= IXGBE_VT_CTL_DIS_DEFPL;
3895 : : }
3896 : :
3897 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vt_ctl);
3898 : :
3899 : : /* RTRUP2TC: mapping user priorities to traffic classes (TCs) */
3900 : : queue_mapping = 0;
3901 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
3902 : : /*
3903 : : * mapping is done with 3 bits per priority,
3904 : : * so shift by i*3 each time
3905 : : */
3906 : 0 : queue_mapping |= ((cfg->dcb_tc[i] & 0x07) << (i * 3));
3907 : :
3908 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, queue_mapping);
3909 : :
3910 : : /* RTRPCS: DCB related */
3911 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, IXGBE_RMCS_RRM);
3912 : :
3913 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
3914 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3915 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
3916 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
3917 : :
3918 : : /* VFTA - enable all vlan filters */
3919 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++) {
3920 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
3921 : : }
3922 : :
3923 : : /* VFRE: pool enabling for receive - 16 or 32 */
3924 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(0),
3925 : : num_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3926 : :
3927 : : /*
3928 : : * MPSAR - allow pools to read specific mac addresses
3929 : : * In this case, all pools should be able to read from mac addr 0
3930 : : */
3931 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(0), 0xFFFFFFFF);
3932 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(0), 0xFFFFFFFF);
3933 : :
3934 : : /* PFVLVF, PFVLVFB: set up filters for vlan tags as configured */
3935 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
3936 : : /* set vlan id in VF register and set the valid bit */
3937 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), (IXGBE_VLVF_VIEN |
3938 : : (cfg->pool_map[i].vlan_id & 0xFFF)));
3939 : : /*
3940 : : * Put the allowed pools in VFB reg. As we only have 16 or 32
3941 : : * pools, we only need to use the first half of the register
3942 : : * i.e. bits 0-31
3943 : : */
3944 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB(i*2), cfg->pool_map[i].pools);
3945 : : }
3946 : : }
3947 : :
3948 : : /**
3949 : : * ixgbe_dcb_config_tx_hw_config - Configure general DCB TX parameters
3950 : : * @dev: pointer to eth_dev structure
3951 : : * @dcb_config: pointer to ixgbe_dcb_config structure
3952 : : */
3953 : : static void
3954 : 0 : ixgbe_dcb_tx_hw_config(struct rte_eth_dev *dev,
3955 : : struct ixgbe_dcb_config *dcb_config)
3956 : : {
3957 : : uint32_t reg;
3958 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3959 : :
3960 : 0 : PMD_INIT_FUNC_TRACE();
3961 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
3962 : : /* Disable the Tx desc arbiter so that MTQC can be changed */
3963 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3964 : 0 : reg |= IXGBE_RTTDCS_ARBDIS;
3965 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
3966 : :
3967 : : /* Enable DCB for Tx with 8 TCs */
3968 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8) {
3969 : : reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3970 : : } else {
3971 : : reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3972 : : }
3973 [ # # ]: 0 : if (dcb_config->vt_mode)
3974 : 0 : reg |= IXGBE_MTQC_VT_ENA;
3975 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
3976 : :
3977 : : /* Enable the Tx desc arbiter */
3978 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3979 : 0 : reg &= ~IXGBE_RTTDCS_ARBDIS;
3980 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
3981 : :
3982 : : /* Enable Security TX Buffer IFG for DCB */
3983 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3984 : 0 : reg |= IXGBE_SECTX_DCB;
3985 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
3986 : : }
3987 : 0 : }
3988 : :
3989 : : /**
3990 : : * ixgbe_vmdq_dcb_hw_tx_config - Configure general VMDQ+DCB TX parameters
3991 : : * @dev: pointer to rte_eth_dev structure
3992 : : * @dcb_config: pointer to ixgbe_dcb_config structure
3993 : : */
3994 : : static void
3995 : 0 : ixgbe_vmdq_dcb_hw_tx_config(struct rte_eth_dev *dev,
3996 : : struct ixgbe_dcb_config *dcb_config)
3997 : : {
3998 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3999 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
4000 : : struct ixgbe_hw *hw =
4001 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4002 : :
4003 : 0 : PMD_INIT_FUNC_TRACE();
4004 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB)
4005 : : /*PF VF Transmit Enable*/
4006 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(0),
4007 : : vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
4008 : :
4009 : : /*Configure general DCB TX parameters*/
4010 : 0 : ixgbe_dcb_tx_hw_config(dev, dcb_config);
4011 : 0 : }
4012 : :
4013 : : static void
4014 : 0 : ixgbe_vmdq_dcb_rx_config(struct rte_eth_dev *dev,
4015 : : struct ixgbe_dcb_config *dcb_config)
4016 : : {
4017 : : struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
4018 : 0 : &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
4019 : : struct ixgbe_dcb_tc_config *tc;
4020 : : uint8_t i, j;
4021 : :
4022 : : /* convert rte_eth_conf.rx_adv_conf to struct ixgbe_dcb_config */
4023 [ # # ]: 0 : if (vmdq_rx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
4024 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
4025 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
4026 : : } else {
4027 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
4028 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
4029 : : }
4030 : :
4031 : : /* Initialize User Priority to Traffic Class mapping */
4032 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4033 : 0 : tc = &dcb_config->tc_config[j];
4034 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
4035 : : }
4036 : :
4037 : : /* User Priority to Traffic Class mapping */
4038 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4039 : 0 : j = vmdq_rx_conf->dcb_tc[i];
4040 : 0 : tc = &dcb_config->tc_config[j];
4041 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
4042 : 0 : (uint8_t)(1 << i);
4043 : : }
4044 : 0 : }
4045 : :
4046 : : static void
4047 : 0 : ixgbe_dcb_vt_tx_config(struct rte_eth_dev *dev,
4048 : : struct ixgbe_dcb_config *dcb_config)
4049 : : {
4050 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
4051 : 0 : &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
4052 : : struct ixgbe_dcb_tc_config *tc;
4053 : : uint8_t i, j;
4054 : :
4055 : : /* convert rte_eth_conf.rx_adv_conf to struct ixgbe_dcb_config */
4056 [ # # ]: 0 : if (vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
4057 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
4058 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
4059 : : } else {
4060 : 0 : dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
4061 : 0 : dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
4062 : : }
4063 : :
4064 : : /* Initialize User Priority to Traffic Class mapping */
4065 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4066 : 0 : tc = &dcb_config->tc_config[j];
4067 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
4068 : : }
4069 : :
4070 : : /* User Priority to Traffic Class mapping */
4071 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4072 : 0 : j = vmdq_tx_conf->dcb_tc[i];
4073 : 0 : tc = &dcb_config->tc_config[j];
4074 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
4075 : 0 : (uint8_t)(1 << i);
4076 : : }
4077 : 0 : }
4078 : :
4079 : : static void
4080 : : ixgbe_dcb_rx_config(struct rte_eth_dev *dev,
4081 : : struct ixgbe_dcb_config *dcb_config)
4082 : : {
4083 : : struct rte_eth_dcb_rx_conf *rx_conf =
4084 : : &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
4085 : : struct ixgbe_dcb_tc_config *tc;
4086 : : uint8_t i, j;
4087 : :
4088 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)rx_conf->nb_tcs;
4089 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)rx_conf->nb_tcs;
4090 : :
4091 : : /* Initialize User Priority to Traffic Class mapping */
4092 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4093 : 0 : tc = &dcb_config->tc_config[j];
4094 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
4095 : : }
4096 : :
4097 : : /* User Priority to Traffic Class mapping */
4098 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4099 : 0 : j = rx_conf->dcb_tc[i];
4100 : 0 : tc = &dcb_config->tc_config[j];
4101 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
4102 : 0 : (uint8_t)(1 << i);
4103 : : }
4104 : : }
4105 : :
4106 : : static void
4107 : : ixgbe_dcb_tx_config(struct rte_eth_dev *dev,
4108 : : struct ixgbe_dcb_config *dcb_config)
4109 : : {
4110 : : struct rte_eth_dcb_tx_conf *tx_conf =
4111 : : &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
4112 : : struct ixgbe_dcb_tc_config *tc;
4113 : : uint8_t i, j;
4114 : :
4115 : 0 : dcb_config->num_tcs.pg_tcs = (uint8_t)tx_conf->nb_tcs;
4116 : 0 : dcb_config->num_tcs.pfc_tcs = (uint8_t)tx_conf->nb_tcs;
4117 : :
4118 : : /* Initialize User Priority to Traffic Class mapping */
4119 [ # # ]: 0 : for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
4120 : 0 : tc = &dcb_config->tc_config[j];
4121 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
4122 : : }
4123 : :
4124 : : /* User Priority to Traffic Class mapping */
4125 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4126 : 0 : j = tx_conf->dcb_tc[i];
4127 : 0 : tc = &dcb_config->tc_config[j];
4128 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
4129 : 0 : (uint8_t)(1 << i);
4130 : : }
4131 : : }
4132 : :
4133 : : /**
4134 : : * ixgbe_dcb_rx_hw_config - Configure general DCB RX HW parameters
4135 : : * @dev: pointer to eth_dev structure
4136 : : * @dcb_config: pointer to ixgbe_dcb_config structure
4137 : : */
4138 : : static void
4139 : 0 : ixgbe_dcb_rx_hw_config(struct rte_eth_dev *dev,
4140 : : struct ixgbe_dcb_config *dcb_config)
4141 : : {
4142 : : uint32_t reg;
4143 : : uint32_t vlanctrl;
4144 : : uint8_t i;
4145 : : uint32_t q;
4146 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4147 : :
4148 : 0 : PMD_INIT_FUNC_TRACE();
4149 : : /*
4150 : : * Disable the arbiter before changing parameters
4151 : : * (always enable recycle mode; WSP)
4152 : : */
4153 : : reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS;
4154 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
4155 : :
4156 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
4157 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
4158 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 4) {
4159 [ # # ]: 0 : if (dcb_config->vt_mode)
4160 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4161 : : IXGBE_MRQC_VMDQRT4TCEN;
4162 : : else {
4163 : : /* no matter the mode is DCB or DCB_RSS, just
4164 : : * set the MRQE to RSSXTCEN. RSS is controlled
4165 : : * by RSS_FIELD
4166 : : */
4167 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, 0);
4168 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4169 : : IXGBE_MRQC_RTRSS4TCEN;
4170 : : }
4171 : : }
4172 [ # # ]: 0 : if (dcb_config->num_tcs.pg_tcs == 8) {
4173 [ # # ]: 0 : if (dcb_config->vt_mode)
4174 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4175 : : IXGBE_MRQC_VMDQRT8TCEN;
4176 : : else {
4177 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, 0);
4178 : 0 : reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
4179 : : IXGBE_MRQC_RTRSS8TCEN;
4180 : : }
4181 : : }
4182 : :
4183 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, reg);
4184 : :
4185 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4186 : : /* Disable drop for all queues in VMDQ mode*/
4187 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4188 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4189 : : (IXGBE_QDE_WRITE |
4190 : : (q << IXGBE_QDE_IDX_SHIFT)));
4191 : : } else {
4192 : : /* Enable drop for all queues in SRIOV mode */
4193 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4194 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4195 : : (IXGBE_QDE_WRITE |
4196 : : (q << IXGBE_QDE_IDX_SHIFT) |
4197 : : IXGBE_QDE_ENABLE));
4198 : : }
4199 : : }
4200 : :
4201 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
4202 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4203 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
4204 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
4205 : :
4206 : : /* VFTA - enable all vlan filters */
4207 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++) {
4208 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
4209 : : }
4210 : :
4211 : : /*
4212 : : * Configure Rx packet plane (recycle mode; WSP) and
4213 : : * enable arbiter
4214 : : */
4215 : : reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
4216 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
4217 : 0 : }
4218 : :
4219 : : static void
4220 : 0 : ixgbe_dcb_hw_arbite_rx_config(struct ixgbe_hw *hw, uint16_t *refill,
4221 : : uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
4222 : : {
4223 [ # # # ]: 0 : switch (hw->mac.type) {
4224 : 0 : case ixgbe_mac_82598EB:
4225 : 0 : ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, tsa);
4226 : 0 : break;
4227 : 0 : case ixgbe_mac_82599EB:
4228 : : case ixgbe_mac_X540:
4229 : : case ixgbe_mac_X550:
4230 : : case ixgbe_mac_X550EM_x:
4231 : : case ixgbe_mac_X550EM_a:
4232 : 0 : ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
4233 : : tsa, map);
4234 : 0 : break;
4235 : : default:
4236 : : break;
4237 : : }
4238 : 0 : }
4239 : :
4240 : : static void
4241 : 0 : ixgbe_dcb_hw_arbite_tx_config(struct ixgbe_hw *hw, uint16_t *refill, uint16_t *max,
4242 : : uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
4243 : : {
4244 [ # # # ]: 0 : switch (hw->mac.type) {
4245 : 0 : case ixgbe_mac_82598EB:
4246 : 0 : ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, bwg_id, tsa);
4247 : 0 : ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, bwg_id, tsa);
4248 : 0 : break;
4249 : 0 : case ixgbe_mac_82599EB:
4250 : : case ixgbe_mac_X540:
4251 : : case ixgbe_mac_X550:
4252 : : case ixgbe_mac_X550EM_x:
4253 : : case ixgbe_mac_X550EM_a:
4254 : 0 : ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, bwg_id, tsa);
4255 : 0 : ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id, tsa, map);
4256 : 0 : break;
4257 : : default:
4258 : : break;
4259 : : }
4260 : 0 : }
4261 : :
4262 : : #define DCB_RX_CONFIG 1
4263 : : #define DCB_TX_CONFIG 1
4264 : : #define DCB_TX_PB 1024
4265 : : /**
4266 : : * ixgbe_dcb_hw_configure - Enable DCB and configure
4267 : : * general DCB in VT mode and non-VT mode parameters
4268 : : * @dev: pointer to rte_eth_dev structure
4269 : : * @dcb_config: pointer to ixgbe_dcb_config structure
4270 : : */
4271 : : static int
4272 : 0 : ixgbe_dcb_hw_configure(struct rte_eth_dev *dev,
4273 : : struct ixgbe_dcb_config *dcb_config)
4274 : : {
4275 : : int ret = 0;
4276 : : uint8_t i, pfc_en, nb_tcs;
4277 : : uint16_t pbsize, rx_buffer_size;
4278 : : uint8_t config_dcb_rx = 0;
4279 : : uint8_t config_dcb_tx = 0;
4280 : 0 : uint8_t tsa[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4281 : 0 : uint8_t bwgid[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4282 : 0 : uint16_t refill[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4283 : 0 : uint16_t max[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4284 : 0 : uint8_t map[IXGBE_DCB_MAX_TRAFFIC_CLASS] = {0};
4285 : : struct ixgbe_dcb_tc_config *tc;
4286 : 0 : uint32_t max_frame = dev->data->mtu + RTE_ETHER_HDR_LEN +
4287 : : RTE_ETHER_CRC_LEN;
4288 : 0 : struct ixgbe_hw *hw =
4289 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4290 : : struct ixgbe_bw_conf *bw_conf =
4291 : : IXGBE_DEV_PRIVATE_TO_BW_CONF(dev->data->dev_private);
4292 : :
4293 [ # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4294 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4295 : 0 : dcb_config->vt_mode = true;
4296 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
4297 : : config_dcb_rx = DCB_RX_CONFIG;
4298 : : /*
4299 : : *get dcb and VT rx configuration parameters
4300 : : *from rte_eth_conf
4301 : : */
4302 : 0 : ixgbe_vmdq_dcb_rx_config(dev, dcb_config);
4303 : : /*Configure general VMDQ and DCB RX parameters*/
4304 : 0 : ixgbe_vmdq_dcb_configure(dev);
4305 : : }
4306 : : break;
4307 : 0 : case RTE_ETH_MQ_RX_DCB:
4308 : : case RTE_ETH_MQ_RX_DCB_RSS:
4309 : 0 : dcb_config->vt_mode = false;
4310 : : config_dcb_rx = DCB_RX_CONFIG;
4311 : : /* Get dcb TX configuration parameters from rte_eth_conf */
4312 : : ixgbe_dcb_rx_config(dev, dcb_config);
4313 : : /*Configure general DCB RX parameters*/
4314 : 0 : ixgbe_dcb_rx_hw_config(dev, dcb_config);
4315 : 0 : break;
4316 : 0 : default:
4317 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB RX mode configuration");
4318 : 0 : break;
4319 : : }
4320 [ # # # ]: 0 : switch (dev->data->dev_conf.txmode.mq_mode) {
4321 : 0 : case RTE_ETH_MQ_TX_VMDQ_DCB:
4322 : 0 : dcb_config->vt_mode = true;
4323 : : config_dcb_tx = DCB_TX_CONFIG;
4324 : : /* get DCB and VT TX configuration parameters
4325 : : * from rte_eth_conf
4326 : : */
4327 : 0 : ixgbe_dcb_vt_tx_config(dev, dcb_config);
4328 : : /*Configure general VMDQ and DCB TX parameters*/
4329 : 0 : ixgbe_vmdq_dcb_hw_tx_config(dev, dcb_config);
4330 : 0 : break;
4331 : :
4332 : 0 : case RTE_ETH_MQ_TX_DCB:
4333 : 0 : dcb_config->vt_mode = false;
4334 : : config_dcb_tx = DCB_TX_CONFIG;
4335 : : /*get DCB TX configuration parameters from rte_eth_conf*/
4336 : : ixgbe_dcb_tx_config(dev, dcb_config);
4337 : : /*Configure general DCB TX parameters*/
4338 : 0 : ixgbe_dcb_tx_hw_config(dev, dcb_config);
4339 : 0 : break;
4340 : 0 : default:
4341 : 0 : PMD_INIT_LOG(ERR, "Incorrect DCB TX mode configuration");
4342 : 0 : break;
4343 : : }
4344 : :
4345 : 0 : nb_tcs = dcb_config->num_tcs.pfc_tcs;
4346 : : /* Unpack map */
4347 : 0 : ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
4348 [ # # ]: 0 : if (nb_tcs == RTE_ETH_4_TCS) {
4349 : : /* Avoid un-configured priority mapping to TC0 */
4350 : : uint8_t j = 4;
4351 : : uint8_t mask = 0xFF;
4352 : :
4353 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES - 4; i++)
4354 : 0 : mask = (uint8_t)(mask & (~(1 << map[i])));
4355 [ # # ]: 0 : for (i = 0; mask && (i < IXGBE_DCB_MAX_TRAFFIC_CLASS); i++) {
4356 [ # # # # ]: 0 : if ((mask & 0x1) && j < RTE_ETH_DCB_NUM_USER_PRIORITIES)
4357 : 0 : map[j++] = i;
4358 : 0 : mask >>= 1;
4359 : : }
4360 : : /* Re-configure 4 TCs BW */
4361 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4362 : 0 : tc = &dcb_config->tc_config[i];
4363 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
4364 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
4365 : : (uint8_t)(100 / nb_tcs);
4366 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
4367 : : (uint8_t)(100 / nb_tcs);
4368 : : }
4369 [ # # ]: 0 : for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
4370 : 0 : tc = &dcb_config->tc_config[i];
4371 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = 0;
4372 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent = 0;
4373 : : }
4374 : : } else {
4375 : : /* Re-configure 8 TCs BW */
4376 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4377 : 0 : tc = &dcb_config->tc_config[i];
4378 [ # # ]: 0 : if (bw_conf->tc_num != nb_tcs)
4379 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
4380 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
4381 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
4382 : 0 : (uint8_t)(100 / nb_tcs + (i & 1));
4383 : : }
4384 : : }
4385 : :
4386 : 0 : rx_buffer_size = (uint16_t)hw->mac.rx_pb_size;
4387 : :
4388 [ # # ]: 0 : if (config_dcb_rx) {
4389 : : /* Set RX buffer size */
4390 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
4391 : 0 : uint32_t rxpbsize = pbsize << IXGBE_RXPBSIZE_SHIFT;
4392 : :
4393 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4394 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpbsize);
4395 : : }
4396 : : /* zero alloc all unused TCs */
4397 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
4398 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
4399 : : }
4400 [ # # ]: 0 : if (config_dcb_tx) {
4401 : : /* Only support an equally distributed
4402 : : * Tx packet buffer strategy.
4403 : : */
4404 : 0 : uint32_t txpktsize = IXGBE_TXPBSIZE_MAX / nb_tcs;
4405 : 0 : uint32_t txpbthresh = (txpktsize / DCB_TX_PB) - IXGBE_TXPKT_SIZE_MAX;
4406 : :
4407 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4408 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
4409 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
4410 : : }
4411 : : /* Clear unused TCs, if any, to zero buffer size*/
4412 [ # # ]: 0 : for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
4413 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
4414 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
4415 : : }
4416 : : }
4417 : :
4418 : : /*Calculates traffic class credits*/
4419 : 0 : ixgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
4420 : : IXGBE_DCB_TX_CONFIG);
4421 : 0 : ixgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
4422 : : IXGBE_DCB_RX_CONFIG);
4423 : :
4424 [ # # ]: 0 : if (config_dcb_rx) {
4425 : : /* Unpack CEE standard containers */
4426 : 0 : ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_RX_CONFIG, refill);
4427 : 0 : ixgbe_dcb_unpack_max_cee(dcb_config, max);
4428 : 0 : ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_RX_CONFIG, bwgid);
4429 : 0 : ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_RX_CONFIG, tsa);
4430 : : /* Configure PG(ETS) RX */
4431 : 0 : ixgbe_dcb_hw_arbite_rx_config(hw, refill, max, bwgid, tsa, map);
4432 : : }
4433 : :
4434 [ # # ]: 0 : if (config_dcb_tx) {
4435 : : /* Unpack CEE standard containers */
4436 : 0 : ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_TX_CONFIG, refill);
4437 : 0 : ixgbe_dcb_unpack_max_cee(dcb_config, max);
4438 : 0 : ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_TX_CONFIG, bwgid);
4439 : 0 : ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_TX_CONFIG, tsa);
4440 : : /* Configure PG(ETS) TX */
4441 : 0 : ixgbe_dcb_hw_arbite_tx_config(hw, refill, max, bwgid, tsa, map);
4442 : : }
4443 : :
4444 : : /*Configure queue statistics registers*/
4445 : 0 : ixgbe_dcb_config_tc_stats_82599(hw, dcb_config);
4446 : :
4447 : : /* Check if the PFC is supported */
4448 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
4449 : 0 : pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
4450 [ # # ]: 0 : for (i = 0; i < nb_tcs; i++) {
4451 : : /*
4452 : : * If the TC count is 8,and the default high_water is 48,
4453 : : * the low_water is 16 as default.
4454 : : */
4455 : 0 : hw->fc.high_water[i] = (pbsize * 3) / 4;
4456 : 0 : hw->fc.low_water[i] = pbsize / 4;
4457 : : /* Enable pfc for this TC */
4458 : : tc = &dcb_config->tc_config[i];
4459 : 0 : tc->pfc = ixgbe_dcb_pfc_enabled;
4460 : : }
4461 : 0 : ixgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
4462 [ # # ]: 0 : if (dcb_config->num_tcs.pfc_tcs == RTE_ETH_4_TCS)
4463 : 0 : pfc_en &= 0x0F;
4464 : 0 : ret = ixgbe_dcb_config_pfc(hw, pfc_en, map);
4465 : : }
4466 : :
4467 : 0 : return ret;
4468 : : }
4469 : :
4470 : : /**
4471 : : * ixgbe_configure_dcb - Configure DCB Hardware
4472 : : * @dev: pointer to rte_eth_dev
4473 : : */
4474 : 0 : void ixgbe_configure_dcb(struct rte_eth_dev *dev)
4475 : : {
4476 : 0 : struct ixgbe_dcb_config *dcb_cfg =
4477 : 0 : IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
4478 : : struct rte_eth_conf *dev_conf = &(dev->data->dev_conf);
4479 : :
4480 : 0 : PMD_INIT_FUNC_TRACE();
4481 : :
4482 : : /* check support mq_mode for DCB */
4483 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_VMDQ_DCB &&
4484 [ # # ]: 0 : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB &&
4485 : : dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB_RSS)
4486 : : return;
4487 : :
4488 [ # # ]: 0 : if (dev->data->nb_rx_queues > RTE_ETH_DCB_NUM_QUEUES)
4489 : : return;
4490 : :
4491 : : /** Configure DCB hardware **/
4492 : 0 : ixgbe_dcb_hw_configure(dev, dcb_cfg);
4493 : : }
4494 : :
4495 : : /*
4496 : : * VMDq only support for 10 GbE NIC.
4497 : : */
4498 : : static void
4499 : 0 : ixgbe_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
4500 : : {
4501 : : struct rte_eth_vmdq_rx_conf *cfg;
4502 : : struct ixgbe_hw *hw;
4503 : : enum rte_eth_nb_pools num_pools;
4504 : : uint32_t mrqc, vt_ctl, vlanctrl;
4505 : : uint32_t vmolr = 0;
4506 : : int i;
4507 : :
4508 : 0 : PMD_INIT_FUNC_TRACE();
4509 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4510 : : cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
4511 : 0 : num_pools = cfg->nb_queue_pools;
4512 : :
4513 : : ixgbe_rss_disable(dev);
4514 : :
4515 : : /* MRQC: enable vmdq */
4516 : : mrqc = IXGBE_MRQC_VMDQEN;
4517 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4518 : :
4519 : : /* PFVTCTL: turn on virtualisation and set the default pool */
4520 : : vt_ctl = IXGBE_VT_CTL_VT_ENABLE | IXGBE_VT_CTL_REPLEN;
4521 [ # # ]: 0 : if (cfg->enable_default_pool)
4522 : 0 : vt_ctl |= (cfg->default_pool << IXGBE_VT_CTL_POOL_SHIFT);
4523 : : else
4524 : : vt_ctl |= IXGBE_VT_CTL_DIS_DEFPL;
4525 : :
4526 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vt_ctl);
4527 : :
4528 [ # # ]: 0 : for (i = 0; i < (int)num_pools; i++) {
4529 : 0 : vmolr = ixgbe_convert_vm_rx_mask_to_val(cfg->rx_mode, vmolr);
4530 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(i), vmolr);
4531 : : }
4532 : :
4533 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
4534 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4535 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
4536 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
4537 : :
4538 : : /* VFTA - enable all vlan filters */
4539 [ # # ]: 0 : for (i = 0; i < NUM_VFTA_REGISTERS; i++)
4540 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), UINT32_MAX);
4541 : :
4542 : : /* VFRE: pool enabling for receive - 64 */
4543 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), UINT32_MAX);
4544 [ # # ]: 0 : if (num_pools == RTE_ETH_64_POOLS)
4545 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), UINT32_MAX);
4546 : :
4547 : : /*
4548 : : * MPSAR - allow pools to read specific mac addresses
4549 : : * In this case, all pools should be able to read from mac addr 0
4550 : : */
4551 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(0), UINT32_MAX);
4552 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(0), UINT32_MAX);
4553 : :
4554 : : /* PFVLVF, PFVLVFB: set up filters for vlan tags as configured */
4555 [ # # ]: 0 : for (i = 0; i < cfg->nb_pool_maps; i++) {
4556 : : /* set vlan id in VF register and set the valid bit */
4557 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), (IXGBE_VLVF_VIEN |
4558 : : (cfg->pool_map[i].vlan_id & IXGBE_RXD_VLAN_ID_MASK)));
4559 : : /*
4560 : : * Put the allowed pools in VFB reg. As we only have 16 or 64
4561 : : * pools, we only need to use the first half of the register
4562 : : * i.e. bits 0-31
4563 : : */
4564 [ # # ]: 0 : if (((cfg->pool_map[i].pools >> 32) & UINT32_MAX) == 0)
4565 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB(i * 2),
4566 : : (cfg->pool_map[i].pools & UINT32_MAX));
4567 : : else
4568 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLVFB((i * 2 + 1)),
4569 : : ((cfg->pool_map[i].pools >> 32) & UINT32_MAX));
4570 : :
4571 : : }
4572 : :
4573 : : /* PFDMA Tx General Switch Control Enables VMDQ loopback */
4574 [ # # ]: 0 : if (cfg->enable_loop_back) {
4575 : 0 : IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
4576 [ # # ]: 0 : for (i = 0; i < IXGBE_VMTXSW_REGISTER_COUNT; i++)
4577 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMTXSW(i), UINT32_MAX);
4578 : : }
4579 : :
4580 : 0 : IXGBE_WRITE_FLUSH(hw);
4581 : 0 : }
4582 : :
4583 : : /*
4584 : : * ixgbe_dcb_config_tx_hw_config - Configure general VMDq TX parameters
4585 : : * @hw: pointer to hardware structure
4586 : : */
4587 : : static void
4588 : 0 : ixgbe_vmdq_tx_hw_configure(struct ixgbe_hw *hw)
4589 : : {
4590 : : uint32_t reg;
4591 : : uint32_t q;
4592 : :
4593 : 0 : PMD_INIT_FUNC_TRACE();
4594 : : /*PF VF Transmit Enable*/
4595 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), UINT32_MAX);
4596 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), UINT32_MAX);
4597 : :
4598 : : /* Disable the Tx desc arbiter so that MTQC can be changed */
4599 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4600 : 0 : reg |= IXGBE_RTTDCS_ARBDIS;
4601 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
4602 : :
4603 : : reg = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF;
4604 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
4605 : :
4606 : : /* Disable drop for all queues */
4607 [ # # ]: 0 : for (q = 0; q < IXGBE_MAX_RX_QUEUE_NUM; q++)
4608 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE,
4609 : : (IXGBE_QDE_WRITE | (q << IXGBE_QDE_IDX_SHIFT)));
4610 : :
4611 : : /* Enable the Tx desc arbiter */
4612 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4613 : 0 : reg &= ~IXGBE_RTTDCS_ARBDIS;
4614 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
4615 : :
4616 : 0 : IXGBE_WRITE_FLUSH(hw);
4617 : 0 : }
4618 : :
4619 : : static int __rte_cold
4620 : 0 : ixgbe_alloc_rx_queue_mbufs(struct ci_rx_queue *rxq)
4621 : : {
4622 : 0 : struct ci_rx_entry *rxe = rxq->sw_ring;
4623 : : uint64_t dma_addr;
4624 : : unsigned int i;
4625 : :
4626 : : /* Initialize software ring entries */
4627 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
4628 : : volatile union ixgbe_adv_rx_desc *rxd;
4629 : 0 : struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
4630 : :
4631 [ # # ]: 0 : if (mbuf == NULL) {
4632 : 0 : PMD_INIT_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
4633 : : (unsigned) rxq->queue_id);
4634 : 0 : return -ENOMEM;
4635 : : }
4636 : :
4637 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
4638 : 0 : mbuf->port = rxq->port_id;
4639 : :
4640 : : dma_addr =
4641 : : rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
4642 : 0 : rxd = &rxq->ixgbe_rx_ring[i];
4643 : 0 : rxd->read.hdr_addr = 0;
4644 : 0 : rxd->read.pkt_addr = dma_addr;
4645 : 0 : rxe[i].mbuf = mbuf;
4646 : : }
4647 : :
4648 : : return 0;
4649 : : }
4650 : :
4651 : : static int
4652 : 0 : ixgbe_config_vf_rss(struct rte_eth_dev *dev)
4653 : : {
4654 : : struct ixgbe_hw *hw;
4655 : : uint32_t mrqc;
4656 : :
4657 : 0 : ixgbe_rss_configure(dev);
4658 : :
4659 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4660 : :
4661 : : /* MRQC: enable VF RSS */
4662 : 0 : mrqc = IXGBE_READ_REG(hw, IXGBE_MRQC);
4663 : 0 : mrqc &= ~IXGBE_MRQC_MRQE_MASK;
4664 [ # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4665 : 0 : case RTE_ETH_64_POOLS:
4666 : 0 : mrqc |= IXGBE_MRQC_VMDQRSS64EN;
4667 : 0 : break;
4668 : :
4669 : 0 : case RTE_ETH_32_POOLS:
4670 : 0 : mrqc |= IXGBE_MRQC_VMDQRSS32EN;
4671 : 0 : break;
4672 : :
4673 : 0 : default:
4674 : 0 : PMD_INIT_LOG(ERR, "Invalid pool number in IOV mode with VMDQ RSS");
4675 : 0 : return -EINVAL;
4676 : : }
4677 : :
4678 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4679 : :
4680 : 0 : return 0;
4681 : : }
4682 : :
4683 : : static int
4684 : 0 : ixgbe_config_vf_default(struct rte_eth_dev *dev)
4685 : : {
4686 : : struct ixgbe_hw *hw =
4687 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4688 : :
4689 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4690 : 0 : case RTE_ETH_64_POOLS:
4691 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4692 : : IXGBE_MRQC_VMDQEN);
4693 : : break;
4694 : :
4695 : 0 : case RTE_ETH_32_POOLS:
4696 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4697 : : IXGBE_MRQC_VMDQRT4TCEN);
4698 : : break;
4699 : :
4700 : 0 : case RTE_ETH_16_POOLS:
4701 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MRQC,
4702 : : IXGBE_MRQC_VMDQRT8TCEN);
4703 : : break;
4704 : 0 : default:
4705 : 0 : PMD_INIT_LOG(ERR,
4706 : : "invalid pool number in IOV mode");
4707 : 0 : break;
4708 : : }
4709 : 0 : return 0;
4710 : : }
4711 : :
4712 : : static int
4713 : 0 : ixgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
4714 : : {
4715 : : struct ixgbe_hw *hw =
4716 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4717 : :
4718 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
4719 : : return 0;
4720 : :
4721 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4722 : : /*
4723 : : * SRIOV inactive scheme
4724 : : * any DCB/RSS w/o VMDq multi-queue setting
4725 : : */
4726 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4727 : 0 : case RTE_ETH_MQ_RX_RSS:
4728 : : case RTE_ETH_MQ_RX_DCB_RSS:
4729 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4730 : 0 : ixgbe_rss_configure(dev);
4731 : 0 : break;
4732 : :
4733 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4734 : 0 : ixgbe_vmdq_dcb_configure(dev);
4735 : 0 : break;
4736 : :
4737 : 0 : case RTE_ETH_MQ_RX_VMDQ_ONLY:
4738 : 0 : ixgbe_vmdq_rx_hw_configure(dev);
4739 : 0 : break;
4740 : :
4741 : : case RTE_ETH_MQ_RX_NONE:
4742 : : default:
4743 : : /* if mq_mode is none, disable rss mode.*/
4744 : : ixgbe_rss_disable(dev);
4745 : : break;
4746 : : }
4747 : : } else {
4748 : : /* SRIOV active scheme
4749 : : * Support RSS together with SRIOV.
4750 : : */
4751 [ # # # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
4752 : 0 : case RTE_ETH_MQ_RX_RSS:
4753 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
4754 : 0 : ixgbe_config_vf_rss(dev);
4755 : 0 : break;
4756 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
4757 : : case RTE_ETH_MQ_RX_DCB:
4758 : : /* In SRIOV, the configuration is the same as VMDq case */
4759 : 0 : ixgbe_vmdq_dcb_configure(dev);
4760 : 0 : break;
4761 : : /* DCB/RSS together with SRIOV is not supported */
4762 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB_RSS:
4763 : : case RTE_ETH_MQ_RX_DCB_RSS:
4764 : 0 : PMD_INIT_LOG(ERR,
4765 : : "Could not support DCB/RSS with VMDq & SRIOV");
4766 : 0 : return -1;
4767 : 0 : default:
4768 : 0 : ixgbe_config_vf_default(dev);
4769 : 0 : break;
4770 : : }
4771 : : }
4772 : :
4773 : : return 0;
4774 : : }
4775 : :
4776 : : static int
4777 : 0 : ixgbe_dev_mq_tx_configure(struct rte_eth_dev *dev)
4778 : : {
4779 : 0 : struct ixgbe_hw *hw =
4780 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4781 : : uint32_t mtqc;
4782 : : uint32_t rttdcs;
4783 : :
4784 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
4785 : : return 0;
4786 : :
4787 : : /* disable arbiter before setting MTQC */
4788 : 0 : rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
4789 : 0 : rttdcs |= IXGBE_RTTDCS_ARBDIS;
4790 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
4791 : :
4792 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4793 : : /*
4794 : : * SRIOV inactive scheme
4795 : : * any DCB w/o VMDq multi-queue setting
4796 : : */
4797 [ # # ]: 0 : if (dev->data->dev_conf.txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_ONLY)
4798 : 0 : ixgbe_vmdq_tx_hw_configure(hw);
4799 : : else {
4800 : : mtqc = IXGBE_MTQC_64Q_1PB;
4801 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
4802 : : }
4803 : : } else {
4804 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(dev).active) {
4805 : :
4806 : : /*
4807 : : * SRIOV active scheme
4808 : : * FIXME if support DCB together with VMDq & SRIOV
4809 : : */
4810 : : case RTE_ETH_64_POOLS:
4811 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF;
4812 : : break;
4813 : 0 : case RTE_ETH_32_POOLS:
4814 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_32VF;
4815 : 0 : break;
4816 : 0 : case RTE_ETH_16_POOLS:
4817 : : mtqc = IXGBE_MTQC_VT_ENA | IXGBE_MTQC_RT_ENA |
4818 : : IXGBE_MTQC_8TC_8TQ;
4819 : 0 : break;
4820 : 0 : default:
4821 : : mtqc = IXGBE_MTQC_64Q_1PB;
4822 : 0 : PMD_INIT_LOG(ERR, "invalid pool number in IOV mode");
4823 : : }
4824 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
4825 : : }
4826 : :
4827 : : /* re-enable arbiter */
4828 : : rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
4829 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
4830 : :
4831 : 0 : return 0;
4832 : : }
4833 : :
4834 : : /**
4835 : : * ixgbe_get_rscctl_maxdesc - Calculate the RSCCTL[n].MAXDESC for PF
4836 : : *
4837 : : * Return the RSCCTL[n].MAXDESC for 82599 and x540 PF devices according to the
4838 : : * spec rev. 3.0 chapter 8.2.3.8.13.
4839 : : *
4840 : : * @pool Memory pool of the Rx queue
4841 : : */
4842 : : static inline uint32_t
4843 : : ixgbe_get_rscctl_maxdesc(struct rte_mempool *pool)
4844 : : {
4845 : : struct rte_pktmbuf_pool_private *mp_priv = rte_mempool_get_priv(pool);
4846 : :
4847 : : /* MAXDESC * SRRCTL.BSIZEPKT must not exceed 64 KB minus one */
4848 : 0 : uint16_t maxdesc =
4849 : 0 : RTE_IPV4_MAX_PKT_LEN /
4850 : 0 : (mp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
4851 : :
4852 : 0 : if (maxdesc >= 16)
4853 : : return IXGBE_RSCCTL_MAXDESC_16;
4854 [ # # ]: 0 : else if (maxdesc >= 8)
4855 : : return IXGBE_RSCCTL_MAXDESC_8;
4856 [ # # ]: 0 : else if (maxdesc >= 4)
4857 : : return IXGBE_RSCCTL_MAXDESC_4;
4858 : : else
4859 : 0 : return IXGBE_RSCCTL_MAXDESC_1;
4860 : : }
4861 : :
4862 : : /**
4863 : : * ixgbe_set_ivar - Setup the correct IVAR register for a particular MSIX
4864 : : * interrupt
4865 : : *
4866 : : * (Taken from FreeBSD tree)
4867 : : * (yes this is all very magic and confusing :)
4868 : : *
4869 : : * @dev port handle
4870 : : * @entry the register array entry
4871 : : * @vector the MSIX vector for this queue
4872 : : * @type RX/TX/MISC
4873 : : */
4874 : : static void
4875 : 0 : ixgbe_set_ivar(struct rte_eth_dev *dev, u8 entry, u8 vector, s8 type)
4876 : : {
4877 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4878 : : u32 ivar, index;
4879 : :
4880 : 0 : vector |= IXGBE_IVAR_ALLOC_VAL;
4881 : :
4882 [ # # # ]: 0 : switch (hw->mac.type) {
4883 : :
4884 : 0 : case ixgbe_mac_82598EB:
4885 [ # # ]: 0 : if (type == -1)
4886 : : entry = IXGBE_IVAR_OTHER_CAUSES_INDEX;
4887 : : else
4888 : 0 : entry += (type * 64);
4889 : 0 : index = (entry >> 2) & 0x1F;
4890 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
4891 : 0 : ivar &= ~(0xFF << (8 * (entry & 0x3)));
4892 : 0 : ivar |= (vector << (8 * (entry & 0x3)));
4893 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
4894 : : break;
4895 : :
4896 : 0 : case ixgbe_mac_82599EB:
4897 : : case ixgbe_mac_X540:
4898 [ # # ]: 0 : if (type == -1) { /* MISC IVAR */
4899 : 0 : index = (entry & 1) * 8;
4900 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4901 : 0 : ivar &= ~(0xFF << index);
4902 : 0 : ivar |= (vector << index);
4903 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar);
4904 : : } else { /* RX/TX IVARS */
4905 : 0 : index = (16 * (entry & 1)) + (8 * type);
4906 : 0 : ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1));
4907 : 0 : ivar &= ~(0xFF << index);
4908 : 0 : ivar |= (vector << index);
4909 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar);
4910 : : }
4911 : :
4912 : : break;
4913 : :
4914 : : default:
4915 : : break;
4916 : : }
4917 : 0 : }
4918 : :
4919 : : static const struct {
4920 : : eth_rx_burst_t pkt_burst;
4921 : : const char *info;
4922 : : } ixgbe_rx_burst_info[] = {
4923 : : { ixgbe_recv_pkts, "Scalar"},
4924 : : { ixgbe_recv_pkts_bulk_alloc, "Scalar bulk alloc"},
4925 : : { ixgbe_recv_pkts_lro_bulk_alloc, "Scalar LRO bulk alloc"},
4926 : : { ixgbe_recv_pkts_lro_single_alloc, "Scalar LRO single alloc"},
4927 : : { ixgbe_vf_representor_rx_burst, "Scalar representor"},
4928 : : #ifdef IXGBE_VPMD_SUPPORTED
4929 : : #ifdef RTE_ARCH_X86
4930 : : { ixgbe_recv_pkts_vec, "Vector SSE"},
4931 : : { ixgbe_recv_scattered_pkts_vec, "Vector SSE scattered"},
4932 : : #elif defined(RTE_ARCH_ARM)
4933 : : { ixgbe_recv_pkts_vec, "Vector NEON"},
4934 : : { ixgbe_recv_scattered_pkts_vec, "Vector NEON scattered"},
4935 : : #endif
4936 : : #endif
4937 : : };
4938 : :
4939 : : int
4940 : 0 : ixgbe_rx_burst_mode_get(struct rte_eth_dev *dev,
4941 : : __rte_unused uint16_t queue_id,
4942 : : struct rte_eth_burst_mode *mode)
4943 : : {
4944 : 0 : eth_tx_burst_t pkt_burst = dev->rx_pkt_burst;
4945 : : size_t i;
4946 : :
4947 [ # # ]: 0 : for (i = 0; i < RTE_DIM(ixgbe_rx_burst_info); i++) {
4948 [ # # ]: 0 : if (pkt_burst == ixgbe_rx_burst_info[i].pkt_burst) {
4949 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
4950 : 0 : ixgbe_rx_burst_info[i].info);
4951 : 0 : return 0;
4952 : : }
4953 : : }
4954 : :
4955 : : return -EINVAL;
4956 : : }
4957 : :
4958 : : void __rte_cold
4959 : 0 : ixgbe_set_rx_function(struct rte_eth_dev *dev)
4960 : : {
4961 : : uint16_t i, rx_using_sse;
4962 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
4963 : :
4964 : : /*
4965 : : * In order to allow Vector Rx there are a few configuration
4966 : : * conditions to be met and Rx Bulk Allocation should be allowed.
4967 : : */
4968 [ # # ]: 0 : if (ixgbe_rx_vec_dev_conf_condition_check(dev) ||
4969 [ # # # # ]: 0 : !adapter->rx_bulk_alloc_allowed ||
4970 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
4971 : 0 : PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet Vector Rx "
4972 : : "preconditions",
4973 : : dev->data->port_id);
4974 : :
4975 : 0 : adapter->rx_vec_allowed = false;
4976 : : }
4977 : :
4978 : : /*
4979 : : * Initialize the appropriate LRO callback.
4980 : : *
4981 : : * If all queues satisfy the bulk allocation preconditions
4982 : : * (hw->rx_bulk_alloc_allowed is TRUE) then we may use bulk allocation.
4983 : : * Otherwise use a single allocation version.
4984 : : */
4985 [ # # ]: 0 : if (dev->data->lro) {
4986 [ # # ]: 0 : if (adapter->rx_bulk_alloc_allowed) {
4987 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a bulk "
4988 : : "allocation version");
4989 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_bulk_alloc;
4990 : : } else {
4991 : 0 : PMD_INIT_LOG(DEBUG, "LRO is requested. Using a single "
4992 : : "allocation version");
4993 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_single_alloc;
4994 : : }
4995 [ # # ]: 0 : } else if (dev->data->scattered_rx) {
4996 : : /*
4997 : : * Set the non-LRO scattered callback: there are Vector and
4998 : : * single allocation versions.
4999 : : */
5000 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
5001 : 0 : PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx "
5002 : : "callback (port=%d).",
5003 : : dev->data->port_id);
5004 : 0 : dev->recycle_rx_descriptors_refill =
5005 : : ixgbe_recycle_rx_descriptors_refill_vec;
5006 : 0 : dev->rx_pkt_burst = ixgbe_recv_scattered_pkts_vec;
5007 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
5008 : 0 : PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
5009 : : "allocation callback (port=%d).",
5010 : : dev->data->port_id);
5011 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_bulk_alloc;
5012 : : } else {
5013 : 0 : PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
5014 : : "single allocation) "
5015 : : "Scattered Rx callback "
5016 : : "(port=%d).",
5017 : : dev->data->port_id);
5018 : :
5019 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_lro_single_alloc;
5020 : : }
5021 : : /*
5022 : : * Below we set "simple" callbacks according to port/queues parameters.
5023 : : * If parameters allow we are going to choose between the following
5024 : : * callbacks:
5025 : : * - Vector
5026 : : * - Bulk Allocation
5027 : : * - Single buffer allocation (the simplest one)
5028 : : */
5029 [ # # ]: 0 : } else if (adapter->rx_vec_allowed) {
5030 : 0 : PMD_INIT_LOG(DEBUG, "Vector rx enabled, please make sure RX "
5031 : : "burst size no less than %d (port=%d).",
5032 : : IXGBE_VPMD_DESCS_PER_LOOP,
5033 : : dev->data->port_id);
5034 : 0 : dev->recycle_rx_descriptors_refill = ixgbe_recycle_rx_descriptors_refill_vec;
5035 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_vec;
5036 [ # # ]: 0 : } else if (adapter->rx_bulk_alloc_allowed) {
5037 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
5038 : : "satisfied. Rx Burst Bulk Alloc function "
5039 : : "will be used on port=%d.",
5040 : : dev->data->port_id);
5041 : :
5042 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts_bulk_alloc;
5043 : : } else {
5044 : 0 : PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
5045 : : "satisfied, or Scattered Rx is requested "
5046 : : "(port=%d).",
5047 : : dev->data->port_id);
5048 : :
5049 : 0 : dev->rx_pkt_burst = ixgbe_recv_pkts;
5050 : : }
5051 : :
5052 : : /* Propagate information about RX function choice through all queues. */
5053 : :
5054 : : rx_using_sse =
5055 [ # # # # ]: 0 : (dev->rx_pkt_burst == ixgbe_recv_scattered_pkts_vec ||
5056 : : dev->rx_pkt_burst == ixgbe_recv_pkts_vec);
5057 : :
5058 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5059 : 0 : struct ci_rx_queue *rxq = dev->data->rx_queues[i];
5060 : :
5061 : 0 : rxq->vector_rx = rx_using_sse;
5062 : 0 : rxq->using_ipsec = !!(dev->data->dev_conf.rxmode.offloads &
5063 : : RTE_ETH_RX_OFFLOAD_SECURITY);
5064 : : }
5065 : 0 : }
5066 : :
5067 : : /**
5068 : : * ixgbe_set_rsc - configure RSC related port HW registers
5069 : : *
5070 : : * Configures the port's RSC related registers according to the 4.6.7.2 chapter
5071 : : * of 82599 Spec (x540 configuration is virtually the same).
5072 : : *
5073 : : * @dev port handle
5074 : : *
5075 : : * Returns 0 in case of success or a non-zero error code
5076 : : */
5077 : : static int
5078 : 0 : ixgbe_set_rsc(struct rte_eth_dev *dev)
5079 : : {
5080 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
5081 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5082 : 0 : struct rte_eth_dev_info dev_info = { 0 };
5083 : : bool rsc_capable = false;
5084 : : uint16_t i;
5085 : : uint32_t rdrxctl;
5086 : : uint32_t rfctl;
5087 : :
5088 : : /* Sanity check */
5089 : 0 : dev->dev_ops->dev_infos_get(dev, &dev_info);
5090 [ # # ]: 0 : if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO)
5091 : : rsc_capable = true;
5092 : :
5093 [ # # ]: 0 : if (!rsc_capable && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
5094 : 0 : PMD_INIT_LOG(CRIT, "LRO is requested on HW that doesn't "
5095 : : "support it");
5096 : 0 : return -EINVAL;
5097 : : }
5098 : :
5099 : : /* RSC global configuration (chapter 4.6.7.2.1 of 82599 Spec) */
5100 : :
5101 [ # # ]: 0 : if ((rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) &&
5102 : : (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
5103 : : /*
5104 : : * According to chapter of 4.6.7.2.1 of the Spec Rev.
5105 : : * 3.0 RSC configuration requires HW CRC stripping being
5106 : : * enabled. If user requested both HW CRC stripping off
5107 : : * and RSC on - return an error.
5108 : : */
5109 : 0 : PMD_INIT_LOG(CRIT, "LRO can't be enabled when HW CRC "
5110 : : "is disabled");
5111 : 0 : return -EINVAL;
5112 : : }
5113 : :
5114 : : /* RFCTL configuration */
5115 : 0 : rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
5116 [ # # # # ]: 0 : if ((rsc_capable) && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
5117 : 0 : rfctl &= ~IXGBE_RFCTL_RSC_DIS;
5118 : : else
5119 : 0 : rfctl |= IXGBE_RFCTL_RSC_DIS;
5120 : : /* disable NFS filtering */
5121 : 0 : rfctl |= IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS;
5122 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
5123 : :
5124 : : /* If LRO hasn't been requested - we are done here. */
5125 [ # # ]: 0 : if (!(rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
5126 : : return 0;
5127 : :
5128 : : /* Set RDRXCTL.RSCACKC bit */
5129 : 0 : rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
5130 : 0 : rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
5131 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
5132 : :
5133 : : /* Per-queue RSC configuration (chapter 4.6.7.2.2 of 82599 Spec) */
5134 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5135 : 0 : struct ci_rx_queue *rxq = dev->data->rx_queues[i];
5136 : : uint32_t srrctl =
5137 [ # # # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_SRRCTL(rxq->reg_idx));
5138 : : uint32_t rscctl =
5139 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxq->reg_idx));
5140 : : uint32_t psrtype =
5141 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_PSRTYPE(rxq->reg_idx));
5142 : : uint32_t eitr =
5143 [ # # ]: 0 : IXGBE_READ_REG(hw, IXGBE_EITR(rxq->reg_idx));
5144 : :
5145 : : /*
5146 : : * ixgbe PMD doesn't support header-split at the moment.
5147 : : *
5148 : : * Following the 4.6.7.2.1 chapter of the 82599/x540
5149 : : * Spec if RSC is enabled the SRRCTL[n].BSIZEHEADER
5150 : : * should be configured even if header split is not
5151 : : * enabled. We will configure it 128 bytes following the
5152 : : * recommendation in the spec.
5153 : : */
5154 : 0 : srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
5155 : 0 : srrctl |= (128 << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
5156 : : IXGBE_SRRCTL_BSIZEHDR_MASK;
5157 : :
5158 : : /*
5159 : : * TODO: Consider setting the Receive Descriptor Minimum
5160 : : * Threshold Size for an RSC case. This is not an obviously
5161 : : * beneficiary option but the one worth considering...
5162 : : */
5163 : :
5164 : 0 : rscctl |= IXGBE_RSCCTL_RSCEN;
5165 [ # # ]: 0 : rscctl |= ixgbe_get_rscctl_maxdesc(rxq->mp);
5166 : 0 : psrtype |= IXGBE_PSRTYPE_TCPHDR;
5167 : :
5168 : : /*
5169 : : * RSC: Set ITR interval corresponding to 2K ints/s.
5170 : : *
5171 : : * Full-sized RSC aggregations for a 10Gb/s link will
5172 : : * arrive at about 20K aggregation/s rate.
5173 : : *
5174 : : * 2K inst/s rate will make only 10% of the
5175 : : * aggregations to be closed due to the interrupt timer
5176 : : * expiration for a streaming at wire-speed case.
5177 : : *
5178 : : * For a sparse streaming case this setting will yield
5179 : : * at most 500us latency for a single RSC aggregation.
5180 : : */
5181 : 0 : eitr &= ~IXGBE_EITR_ITR_INT_MASK;
5182 : : eitr |= IXGBE_EITR_INTERVAL_US(IXGBE_QUEUE_ITR_INTERVAL_DEFAULT);
5183 : 0 : eitr |= IXGBE_EITR_CNT_WDIS;
5184 : :
5185 [ # # # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxq->reg_idx), srrctl);
5186 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(rxq->reg_idx), rscctl);
5187 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(rxq->reg_idx), psrtype);
5188 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_EITR(rxq->reg_idx), eitr);
5189 : :
5190 : : /*
5191 : : * RSC requires the mapping of the queue to the
5192 : : * interrupt vector.
5193 : : */
5194 : 0 : ixgbe_set_ivar(dev, rxq->reg_idx, i, 0);
5195 : : }
5196 : :
5197 : 0 : dev->data->lro = 1;
5198 : :
5199 : 0 : PMD_INIT_LOG(DEBUG, "enabling LRO mode");
5200 : :
5201 : 0 : return 0;
5202 : : }
5203 : :
5204 : : /*
5205 : : * Initializes Receive Unit.
5206 : : */
5207 : : int __rte_cold
5208 : 0 : ixgbe_dev_rx_init(struct rte_eth_dev *dev)
5209 : : {
5210 : : struct ixgbe_hw *hw;
5211 : : struct ci_rx_queue *rxq;
5212 : : uint64_t bus_addr;
5213 : : uint32_t rxctrl;
5214 : : uint32_t fctrl;
5215 : : uint32_t hlreg0;
5216 : : uint32_t maxfrs;
5217 : : uint32_t srrctl;
5218 : : uint32_t rdrxctl;
5219 : : uint32_t rxcsum;
5220 : : uint16_t buf_size;
5221 : : uint16_t i;
5222 : 0 : struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
5223 : 0 : uint32_t frame_size = dev->data->mtu + IXGBE_ETH_OVERHEAD;
5224 : : int rc;
5225 : :
5226 : 0 : PMD_INIT_FUNC_TRACE();
5227 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5228 : :
5229 : : /*
5230 : : * Make sure receives are disabled while setting
5231 : : * up the RX context (registers, descriptor rings, etc.).
5232 : : */
5233 : 0 : rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5234 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
5235 : :
5236 : : /* Enable receipt of broadcasted frames */
5237 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5238 : : fctrl |= IXGBE_FCTRL_BAM;
5239 : : fctrl |= IXGBE_FCTRL_DPF;
5240 : 0 : fctrl |= IXGBE_FCTRL_PMCF;
5241 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5242 : :
5243 : : /*
5244 : : * Configure CRC stripping, if any.
5245 : : */
5246 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
5247 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5248 : 0 : hlreg0 &= ~IXGBE_HLREG0_RXCRCSTRP;
5249 : : else
5250 : 0 : hlreg0 |= IXGBE_HLREG0_RXCRCSTRP;
5251 : :
5252 : : /*
5253 : : * Configure jumbo frame support, if any.
5254 : : */
5255 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU) {
5256 : 0 : hlreg0 |= IXGBE_HLREG0_JUMBOEN;
5257 : 0 : maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
5258 : 0 : maxfrs &= 0x0000FFFF;
5259 : 0 : maxfrs |= (frame_size << 16);
5260 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
5261 : : } else
5262 : 0 : hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
5263 : :
5264 : : /*
5265 : : * If loopback mode is configured, set LPBK bit.
5266 : : */
5267 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
5268 : 0 : rc = ixgbe_check_supported_loopback_mode(dev);
5269 [ # # ]: 0 : if (rc < 0) {
5270 : 0 : PMD_INIT_LOG(ERR, "Unsupported loopback mode");
5271 : 0 : return rc;
5272 : : }
5273 : 0 : hlreg0 |= IXGBE_HLREG0_LPBK;
5274 : : } else {
5275 : 0 : hlreg0 &= ~IXGBE_HLREG0_LPBK;
5276 : : }
5277 : :
5278 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
5279 : :
5280 : : /*
5281 : : * Assume no header split and no VLAN strip support
5282 : : * on any Rx queue first .
5283 : : */
5284 : 0 : rx_conf->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5285 : : /* Setup RX queues */
5286 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5287 : 0 : rxq = dev->data->rx_queues[i];
5288 : :
5289 : : /*
5290 : : * Reset crc_len in case it was changed after queue setup by a
5291 : : * call to configure.
5292 : : */
5293 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5294 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
5295 : : else
5296 : 0 : rxq->crc_len = 0;
5297 : :
5298 : : /* Setup the Base and Length of the Rx Descriptor Rings */
5299 : 0 : bus_addr = rxq->rx_ring_phys_addr;
5300 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDBAL(rxq->reg_idx),
5301 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5302 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDBAH(rxq->reg_idx),
5303 : : (uint32_t)(bus_addr >> 32));
5304 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDLEN(rxq->reg_idx),
5305 : : rxq->nb_rx_desc * sizeof(union ixgbe_adv_rx_desc));
5306 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDH(rxq->reg_idx), 0);
5307 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDT(rxq->reg_idx), 0);
5308 : :
5309 : : /* Configure the SRRCTL register */
5310 : : srrctl = IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
5311 : :
5312 : : /* Set if packets are dropped when no descriptors available */
5313 [ # # ]: 0 : if (rxq->drop_en)
5314 : : srrctl |= IXGBE_SRRCTL_DROP_EN;
5315 : :
5316 : : /*
5317 : : * Configure the RX buffer size in the BSIZEPACKET field of
5318 : : * the SRRCTL register of the queue.
5319 : : * The value is in 1 KB resolution. Valid values can be from
5320 : : * 1 KB to 16 KB.
5321 : : */
5322 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
5323 : : RTE_PKTMBUF_HEADROOM);
5324 : 0 : srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
5325 : : IXGBE_SRRCTL_BSIZEPKT_MASK);
5326 : :
5327 [ # # # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxq->reg_idx), srrctl);
5328 : :
5329 : 0 : buf_size = (uint16_t) ((srrctl & IXGBE_SRRCTL_BSIZEPKT_MASK) <<
5330 : : IXGBE_SRRCTL_BSIZEPKT_SHIFT);
5331 : :
5332 : : /* It adds dual VLAN length for supporting dual VLAN */
5333 [ # # ]: 0 : if (frame_size + 2 * RTE_VLAN_HLEN > buf_size)
5334 : 0 : dev->data->scattered_rx = 1;
5335 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5336 : 0 : rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5337 : : }
5338 : :
5339 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
5340 : 0 : dev->data->scattered_rx = 1;
5341 : :
5342 : : /*
5343 : : * Device configured with multiple RX queues.
5344 : : */
5345 : 0 : ixgbe_dev_mq_rx_configure(dev);
5346 : :
5347 : : /*
5348 : : * Setup the Checksum Register.
5349 : : * Disable Full-Packet Checksum which is mutually exclusive with RSS.
5350 : : * Enable IP/L4 checksum computation by hardware if requested to do so.
5351 : : */
5352 : 0 : rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
5353 : : rxcsum |= IXGBE_RXCSUM_PCSD;
5354 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
5355 : 0 : rxcsum |= IXGBE_RXCSUM_IPPCSE;
5356 : : else
5357 : 0 : rxcsum &= ~IXGBE_RXCSUM_IPPCSE;
5358 : :
5359 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
5360 : :
5361 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
5362 : : hw->mac.type == ixgbe_mac_X540) {
5363 : 0 : rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
5364 [ # # ]: 0 : if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
5365 : 0 : rdrxctl &= ~IXGBE_RDRXCTL_CRCSTRIP;
5366 : : else
5367 : 0 : rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
5368 : 0 : rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
5369 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
5370 : : }
5371 : :
5372 : 0 : rc = ixgbe_set_rsc(dev);
5373 [ # # ]: 0 : if (rc)
5374 : : return rc;
5375 : :
5376 : 0 : ixgbe_set_rx_function(dev);
5377 : :
5378 : 0 : return 0;
5379 : : }
5380 : :
5381 : : /*
5382 : : * Initializes Transmit Unit.
5383 : : */
5384 : : void __rte_cold
5385 : 0 : ixgbe_dev_tx_init(struct rte_eth_dev *dev)
5386 : : {
5387 : : struct ixgbe_hw *hw;
5388 : : struct ci_tx_queue *txq;
5389 : : uint64_t bus_addr;
5390 : : uint32_t hlreg0;
5391 : : uint32_t txctrl;
5392 : : uint16_t i;
5393 : :
5394 : 0 : PMD_INIT_FUNC_TRACE();
5395 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5396 : :
5397 : : /* Enable TX CRC (checksum offload requirement) and hw padding
5398 : : * (TSO requirement)
5399 : : */
5400 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
5401 : 0 : hlreg0 |= (IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_TXPADEN);
5402 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
5403 : :
5404 : : /* Setup the Base and Length of the Tx Descriptor Rings */
5405 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5406 : 0 : txq = dev->data->tx_queues[i];
5407 : :
5408 : 0 : bus_addr = txq->tx_ring_dma;
5409 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDBAL(txq->reg_idx),
5410 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5411 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDBAH(txq->reg_idx),
5412 : : (uint32_t)(bus_addr >> 32));
5413 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDLEN(txq->reg_idx),
5414 : : txq->nb_tx_desc * sizeof(union ixgbe_adv_tx_desc));
5415 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
5416 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDH(txq->reg_idx), 0);
5417 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDT(txq->reg_idx), 0);
5418 : :
5419 : : /*
5420 : : * Disable Tx Head Writeback RO bit, since this hoses
5421 : : * bookkeeping if things aren't delivered in order.
5422 : : */
5423 [ # # ]: 0 : switch (hw->mac.type) {
5424 : 0 : case ixgbe_mac_82598EB:
5425 : 0 : txctrl = IXGBE_READ_REG(hw,
5426 : : IXGBE_DCA_TXCTRL(txq->reg_idx));
5427 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5428 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(txq->reg_idx),
5429 : : txctrl);
5430 : : break;
5431 : :
5432 : 0 : case ixgbe_mac_82599EB:
5433 : : case ixgbe_mac_X540:
5434 : : case ixgbe_mac_X550:
5435 : : case ixgbe_mac_X550EM_x:
5436 : : case ixgbe_mac_X550EM_a:
5437 : : default:
5438 : 0 : txctrl = IXGBE_READ_REG(hw,
5439 : : IXGBE_DCA_TXCTRL_82599(txq->reg_idx));
5440 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
5441 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(txq->reg_idx),
5442 : : txctrl);
5443 : : break;
5444 : : }
5445 : : }
5446 : :
5447 : : /* Device configured with multiple TX queues. */
5448 : 0 : ixgbe_dev_mq_tx_configure(dev);
5449 : 0 : }
5450 : :
5451 : : /*
5452 : : * Check if requested loopback mode is supported
5453 : : */
5454 : : int
5455 : 0 : ixgbe_check_supported_loopback_mode(struct rte_eth_dev *dev)
5456 : : {
5457 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5458 : :
5459 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_TX_RX)
5460 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB ||
5461 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X540 ||
5462 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
5463 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
5464 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_a ||
5465 : : hw->mac.type == ixgbe_mac_E610)
5466 : 0 : return 0;
5467 : :
5468 : : return -ENOTSUP;
5469 : : }
5470 : :
5471 : : /*
5472 : : * Set up link for 82599 loopback mode Tx->Rx.
5473 : : */
5474 : : static inline void __rte_cold
5475 : 0 : ixgbe_setup_loopback_link_82599(struct ixgbe_hw *hw)
5476 : : {
5477 : 0 : PMD_INIT_FUNC_TRACE();
5478 : :
5479 [ # # ]: 0 : if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
5480 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM) !=
5481 : : IXGBE_SUCCESS) {
5482 : 0 : PMD_INIT_LOG(ERR, "Could not enable loopback mode");
5483 : : /* ignore error */
5484 : 0 : return;
5485 : : }
5486 : : }
5487 : :
5488 : : /* Restart link */
5489 : 0 : IXGBE_WRITE_REG(hw,
5490 : : IXGBE_AUTOC,
5491 : : IXGBE_AUTOC_LMS_10G_LINK_NO_AN | IXGBE_AUTOC_FLU);
5492 : 0 : ixgbe_reset_pipeline_82599(hw);
5493 : :
5494 : 0 : hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
5495 : 0 : msec_delay(50);
5496 : : }
5497 : :
5498 : :
5499 : : /*
5500 : : * Start Transmit and Receive Units.
5501 : : */
5502 : : int __rte_cold
5503 : 0 : ixgbe_dev_rxtx_start(struct rte_eth_dev *dev)
5504 : : {
5505 : : struct ixgbe_hw *hw;
5506 : : struct ci_tx_queue *txq;
5507 : : struct ci_rx_queue *rxq;
5508 : : uint32_t txdctl;
5509 : : uint32_t dmatxctl;
5510 : : uint32_t rxctrl;
5511 : : uint16_t i;
5512 : : int ret = 0;
5513 : :
5514 : 0 : PMD_INIT_FUNC_TRACE();
5515 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5516 : :
5517 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5518 : 0 : txq = dev->data->tx_queues[i];
5519 : : /* Setup Transmit Threshold Registers */
5520 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5521 : 0 : txdctl |= txq->pthresh & 0x7F;
5522 : 0 : txdctl |= ((txq->hthresh & 0x7F) << 8);
5523 : 0 : txdctl |= ((txq->wthresh & 0x7F) << 16);
5524 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5525 : : }
5526 : :
5527 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
5528 : 0 : dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
5529 : 0 : dmatxctl |= IXGBE_DMATXCTL_TE;
5530 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
5531 : : }
5532 : :
5533 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5534 : 0 : txq = dev->data->tx_queues[i];
5535 [ # # ]: 0 : if (!txq->tx_deferred_start) {
5536 : 0 : ret = ixgbe_dev_tx_queue_start(dev, i);
5537 [ # # ]: 0 : if (ret < 0)
5538 : 0 : return ret;
5539 : : }
5540 : : }
5541 : :
5542 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5543 : 0 : rxq = dev->data->rx_queues[i];
5544 [ # # ]: 0 : if (!rxq->rx_deferred_start) {
5545 : 0 : ret = ixgbe_dev_rx_queue_start(dev, i);
5546 [ # # ]: 0 : if (ret < 0)
5547 : 0 : return ret;
5548 : : }
5549 : : }
5550 : :
5551 : : /* Enable Receive engine */
5552 : 0 : rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5553 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
5554 : 0 : rxctrl |= IXGBE_RXCTRL_DMBYPS;
5555 : 0 : rxctrl |= IXGBE_RXCTRL_RXEN;
5556 : 0 : hw->mac.ops.enable_rx_dma(hw, rxctrl);
5557 : :
5558 : : /* If loopback mode is enabled, set up the link accordingly */
5559 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
5560 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB)
5561 : 0 : ixgbe_setup_loopback_link_82599(hw);
5562 [ # # ]: 0 : else if (hw->mac.type == ixgbe_mac_X540 ||
5563 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
5564 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
5565 : : hw->mac.type == ixgbe_mac_X550EM_a)
5566 : 0 : ixgbe_setup_loopback_link_x540_x550(hw, true);
5567 : : }
5568 : :
5569 [ # # ]: 0 : if ((dev->data->dev_conf.rxmode.offloads &
5570 : 0 : RTE_ETH_RX_OFFLOAD_SECURITY) ||
5571 [ # # ]: 0 : (dev->data->dev_conf.txmode.offloads &
5572 : : RTE_ETH_TX_OFFLOAD_SECURITY)) {
5573 : 0 : ret = ixgbe_crypto_enable_ipsec(dev);
5574 [ # # ]: 0 : if (ret != 0) {
5575 : 0 : PMD_DRV_LOG(ERR,
5576 : : "ixgbe_crypto_enable_ipsec fails with %d.",
5577 : : ret);
5578 : 0 : return ret;
5579 : : }
5580 : : }
5581 : :
5582 : : return 0;
5583 : : }
5584 : :
5585 : : /*
5586 : : * Start Receive Units for specified queue.
5587 : : */
5588 : : int __rte_cold
5589 : 0 : ixgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
5590 : : {
5591 : : struct ixgbe_hw *hw;
5592 : : struct ci_rx_queue *rxq;
5593 : : uint32_t rxdctl;
5594 : : int poll_ms;
5595 : :
5596 : 0 : PMD_INIT_FUNC_TRACE();
5597 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5598 : :
5599 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
5600 : :
5601 : : /* Allocate buffers for descriptor rings */
5602 [ # # ]: 0 : if (ixgbe_alloc_rx_queue_mbufs(rxq) != 0) {
5603 : 0 : PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
5604 : : rx_queue_id);
5605 : 0 : return -1;
5606 : : }
5607 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5608 : 0 : rxdctl |= IXGBE_RXDCTL_ENABLE;
5609 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), rxdctl);
5610 : :
5611 : : /* Wait until RX Enable ready */
5612 : : poll_ms = IXGBE_REGISTER_POLL_WAIT_10_MS;
5613 : : do {
5614 : : rte_delay_ms(1);
5615 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5616 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & IXGBE_RXDCTL_ENABLE));
5617 [ # # ]: 0 : if (!poll_ms)
5618 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
5619 : : rte_wmb();
5620 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDH(rxq->reg_idx), 0);
5621 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
5622 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
5623 : :
5624 : 0 : return 0;
5625 : : }
5626 : :
5627 : : /*
5628 : : * Stop Receive Units for specified queue.
5629 : : */
5630 : : int __rte_cold
5631 : 0 : ixgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
5632 : : {
5633 : : struct ixgbe_hw *hw;
5634 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5635 : : struct ci_rx_queue *rxq;
5636 : : uint32_t rxdctl;
5637 : : int poll_ms;
5638 : :
5639 : 0 : PMD_INIT_FUNC_TRACE();
5640 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5641 : :
5642 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
5643 : :
5644 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5645 : 0 : rxdctl &= ~IXGBE_RXDCTL_ENABLE;
5646 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), rxdctl);
5647 : :
5648 : : /* Wait until RX Enable bit clear */
5649 : : poll_ms = IXGBE_REGISTER_POLL_WAIT_10_MS;
5650 : : do {
5651 : : rte_delay_ms(1);
5652 [ # # ]: 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
5653 [ # # # # ]: 0 : } while (--poll_ms && (rxdctl & IXGBE_RXDCTL_ENABLE));
5654 [ # # ]: 0 : if (!poll_ms)
5655 : 0 : PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
5656 : :
5657 : 0 : rte_delay_us(IXGBE_WAIT_100_US);
5658 : :
5659 : 0 : ixgbe_rx_queue_release_mbufs(rxq);
5660 : 0 : ixgbe_reset_rx_queue(adapter, rxq);
5661 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5662 : :
5663 : 0 : return 0;
5664 : : }
5665 : :
5666 : :
5667 : : /*
5668 : : * Start Transmit Units for specified queue.
5669 : : */
5670 : : int __rte_cold
5671 : 0 : ixgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5672 : : {
5673 : : struct ixgbe_hw *hw;
5674 : : struct ci_tx_queue *txq;
5675 : : uint32_t txdctl;
5676 : : int poll_ms;
5677 : :
5678 : 0 : PMD_INIT_FUNC_TRACE();
5679 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5680 : :
5681 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5682 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDH(txq->reg_idx), 0);
5683 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5684 : 0 : txdctl |= IXGBE_TXDCTL_ENABLE;
5685 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5686 : :
5687 : : /* Wait until TX Enable ready */
5688 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5689 : : poll_ms = IXGBE_REGISTER_POLL_WAIT_10_MS;
5690 : : do {
5691 : : rte_delay_ms(1);
5692 : 0 : txdctl = IXGBE_READ_REG(hw,
5693 : : IXGBE_TXDCTL(txq->reg_idx));
5694 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & IXGBE_TXDCTL_ENABLE));
5695 [ # # ]: 0 : if (!poll_ms)
5696 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d",
5697 : : tx_queue_id);
5698 : : }
5699 : : rte_wmb();
5700 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TDT(txq->reg_idx), 0);
5701 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
5702 : :
5703 : 0 : return 0;
5704 : : }
5705 : :
5706 : : /*
5707 : : * Stop Transmit Units for specified queue.
5708 : : */
5709 : : int __rte_cold
5710 : 0 : ixgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
5711 : : {
5712 : : struct ixgbe_hw *hw;
5713 : : struct ci_tx_queue *txq;
5714 : : uint32_t txdctl;
5715 : : uint32_t txtdh, txtdt;
5716 : : int poll_ms;
5717 : :
5718 : 0 : PMD_INIT_FUNC_TRACE();
5719 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5720 : :
5721 : 0 : txq = dev->data->tx_queues[tx_queue_id];
5722 : :
5723 : : /* Wait until TX queue is empty */
5724 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5725 : : poll_ms = IXGBE_REGISTER_POLL_WAIT_10_MS;
5726 : : do {
5727 : 0 : rte_delay_us(IXGBE_WAIT_100_US);
5728 : 0 : txtdh = IXGBE_READ_REG(hw,
5729 : : IXGBE_TDH(txq->reg_idx));
5730 : 0 : txtdt = IXGBE_READ_REG(hw,
5731 : : IXGBE_TDT(txq->reg_idx));
5732 [ # # # # ]: 0 : } while (--poll_ms && (txtdh != txtdt));
5733 [ # # ]: 0 : if (!poll_ms)
5734 : 0 : PMD_INIT_LOG(ERR,
5735 : : "Tx Queue %d is not empty when stopping.",
5736 : : tx_queue_id);
5737 : : }
5738 : :
5739 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txq->reg_idx));
5740 : 0 : txdctl &= ~IXGBE_TXDCTL_ENABLE;
5741 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txq->reg_idx), txdctl);
5742 : :
5743 : : /* Wait until TX Enable bit clear */
5744 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
5745 : : poll_ms = IXGBE_REGISTER_POLL_WAIT_10_MS;
5746 : : do {
5747 : : rte_delay_ms(1);
5748 : 0 : txdctl = IXGBE_READ_REG(hw,
5749 : : IXGBE_TXDCTL(txq->reg_idx));
5750 [ # # # # ]: 0 : } while (--poll_ms && (txdctl & IXGBE_TXDCTL_ENABLE));
5751 [ # # ]: 0 : if (!poll_ms)
5752 : 0 : PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
5753 : : tx_queue_id);
5754 : : }
5755 : :
5756 [ # # ]: 0 : if (txq->ops != NULL) {
5757 : 0 : ci_txq_release_all_mbufs(txq, false);
5758 : 0 : txq->ops->reset(txq);
5759 : : }
5760 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
5761 : :
5762 : 0 : return 0;
5763 : : }
5764 : :
5765 : : void
5766 : 0 : ixgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5767 : : struct rte_eth_rxq_info *qinfo)
5768 : : {
5769 : : struct ci_rx_queue *rxq;
5770 : :
5771 : 0 : rxq = dev->data->rx_queues[queue_id];
5772 : :
5773 : 0 : qinfo->mp = rxq->mp;
5774 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
5775 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
5776 : :
5777 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
5778 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
5779 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
5780 : 0 : qinfo->conf.offloads = rxq->offloads;
5781 : 0 : }
5782 : :
5783 : : void
5784 : 0 : ixgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5785 : : struct rte_eth_txq_info *qinfo)
5786 : : {
5787 : : struct ci_tx_queue *txq;
5788 : :
5789 : 0 : txq = dev->data->tx_queues[queue_id];
5790 : :
5791 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
5792 : :
5793 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
5794 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
5795 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
5796 : :
5797 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
5798 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
5799 : 0 : qinfo->conf.offloads = txq->offloads;
5800 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
5801 : 0 : }
5802 : :
5803 : : void
5804 : 0 : ixgbe_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
5805 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
5806 : : {
5807 : : struct ci_rx_queue *rxq;
5808 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5809 : :
5810 : 0 : rxq = dev->data->rx_queues[queue_id];
5811 : :
5812 : 0 : recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring;
5813 : 0 : recycle_rxq_info->mp = rxq->mp;
5814 : 0 : recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;
5815 : 0 : recycle_rxq_info->receive_tail = &rxq->rx_tail;
5816 : :
5817 [ # # ]: 0 : if (adapter->rx_vec_allowed) {
5818 : 0 : recycle_rxq_info->refill_requirement = IXGBE_VPMD_RXQ_REARM_THRESH;
5819 : 0 : recycle_rxq_info->refill_head = &rxq->rxrearm_start;
5820 : : } else {
5821 : 0 : recycle_rxq_info->refill_requirement = rxq->rx_free_thresh;
5822 : 0 : recycle_rxq_info->refill_head = &rxq->rx_free_trigger;
5823 : : }
5824 : 0 : }
5825 : :
5826 : : /*
5827 : : * [VF] Initializes Receive Unit.
5828 : : */
5829 : : int __rte_cold
5830 : 0 : ixgbevf_dev_rx_init(struct rte_eth_dev *dev)
5831 : : {
5832 : : struct ixgbe_hw *hw;
5833 : : struct ci_rx_queue *rxq;
5834 : 0 : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
5835 : 0 : uint32_t frame_size = dev->data->mtu + IXGBE_ETH_OVERHEAD;
5836 : : uint64_t bus_addr;
5837 : : uint32_t srrctl, psrtype = 0;
5838 : : uint16_t buf_size;
5839 : : uint16_t i;
5840 : : int ret;
5841 : :
5842 : 0 : PMD_INIT_FUNC_TRACE();
5843 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5844 : :
5845 [ # # ]: 0 : if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
5846 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5847 : : "it should be power of 2");
5848 : 0 : return -1;
5849 : : }
5850 : :
5851 [ # # ]: 0 : if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
5852 : 0 : PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
5853 : : "it should be equal to or less than %d",
5854 : : hw->mac.max_rx_queues);
5855 : 0 : return -1;
5856 : : }
5857 : :
5858 : : /*
5859 : : * When the VF driver issues a IXGBE_VF_RESET request, the PF driver
5860 : : * disables the VF receipt of packets if the PF MTU is > 1500.
5861 : : * This is done to deal with 82599 limitations that imposes
5862 : : * the PF and all VFs to share the same MTU.
5863 : : * Then, the PF driver enables again the VF receipt of packet when
5864 : : * the VF driver issues a IXGBE_VF_SET_LPE request.
5865 : : * In the meantime, the VF device cannot be used, even if the VF driver
5866 : : * and the Guest VM network stack are ready to accept packets with a
5867 : : * size up to the PF MTU.
5868 : : * As a work-around to this PF behaviour, force the call to
5869 : : * ixgbevf_rlpml_set_vf even if jumbo frames are not used. This way,
5870 : : * VF packets received can work in all cases.
5871 : : */
5872 [ # # ]: 0 : if (ixgbevf_rlpml_set_vf(hw, frame_size) != 0)
5873 : 0 : PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
5874 : : frame_size);
5875 : :
5876 : : /*
5877 : : * Assume no header split and no VLAN strip support
5878 : : * on any Rx queue first .
5879 : : */
5880 : 0 : rxmode->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5881 : : /* Setup RX queues */
5882 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5883 : 0 : rxq = dev->data->rx_queues[i];
5884 : :
5885 : : /* Allocate buffers for descriptor rings */
5886 : 0 : ret = ixgbe_alloc_rx_queue_mbufs(rxq);
5887 [ # # ]: 0 : if (ret)
5888 : 0 : return ret;
5889 : :
5890 : : /* Setup the Base and Length of the Rx Descriptor Rings */
5891 : 0 : bus_addr = rxq->rx_ring_phys_addr;
5892 : :
5893 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(i),
5894 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5895 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(i),
5896 : : (uint32_t)(bus_addr >> 32));
5897 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(i),
5898 : : rxq->nb_rx_desc * sizeof(union ixgbe_adv_rx_desc));
5899 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDH(i), 0);
5900 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), 0);
5901 : :
5902 : :
5903 : : /* Configure the SRRCTL register */
5904 : : srrctl = IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
5905 : :
5906 : : /* Set if packets are dropped when no descriptors available */
5907 [ # # ]: 0 : if (rxq->drop_en)
5908 : : srrctl |= IXGBE_SRRCTL_DROP_EN;
5909 : :
5910 : : /*
5911 : : * Configure the RX buffer size in the BSIZEPACKET field of
5912 : : * the SRRCTL register of the queue.
5913 : : * The value is in 1 KB resolution. Valid values can be from
5914 : : * 1 KB to 16 KB.
5915 : : */
5916 : 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
5917 : : RTE_PKTMBUF_HEADROOM);
5918 : 0 : srrctl |= ((buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) &
5919 : : IXGBE_SRRCTL_BSIZEPKT_MASK);
5920 : :
5921 : : /*
5922 : : * VF modification to write virtual function SRRCTL register
5923 : : */
5924 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(i), srrctl);
5925 : :
5926 : 0 : buf_size = (uint16_t) ((srrctl & IXGBE_SRRCTL_BSIZEPKT_MASK) <<
5927 : : IXGBE_SRRCTL_BSIZEPKT_SHIFT);
5928 : :
5929 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
5930 : : /* It adds dual VLAN length for supporting dual VLAN */
5931 [ # # ]: 0 : (frame_size + 2 * RTE_VLAN_HLEN) > buf_size) {
5932 [ # # ]: 0 : if (!dev->data->scattered_rx)
5933 : 0 : PMD_INIT_LOG(DEBUG, "forcing scatter mode");
5934 : 0 : dev->data->scattered_rx = 1;
5935 : : }
5936 : :
5937 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5938 : 0 : rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5939 : : }
5940 : :
5941 : : /* Set RQPL for VF RSS according to max Rx queue */
5942 : 0 : psrtype |= (dev->data->nb_rx_queues >> 1) <<
5943 : : IXGBE_PSRTYPE_RQPL_SHIFT;
5944 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
5945 : :
5946 : : /* Initialize the rss for x550_vf cards if enabled */
5947 [ # # ]: 0 : switch (hw->mac.type) {
5948 : 0 : case ixgbe_mac_X550_vf:
5949 : : case ixgbe_mac_X550EM_x_vf:
5950 : : case ixgbe_mac_X550EM_a_vf:
5951 : : case ixgbe_mac_E610_vf:
5952 [ # # ]: 0 : switch (dev->data->dev_conf.rxmode.mq_mode) {
5953 : 0 : case RTE_ETH_MQ_RX_RSS:
5954 : : case RTE_ETH_MQ_RX_DCB_RSS:
5955 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
5956 : 0 : ixgbe_rss_configure(dev);
5957 : 0 : break;
5958 : : default:
5959 : : break;
5960 : : }
5961 : : break;
5962 : : default:
5963 : : break;
5964 : : }
5965 : :
5966 : 0 : ixgbe_set_rx_function(dev);
5967 : :
5968 : 0 : return 0;
5969 : : }
5970 : :
5971 : : /*
5972 : : * [VF] Initializes Transmit Unit.
5973 : : */
5974 : : void __rte_cold
5975 : 0 : ixgbevf_dev_tx_init(struct rte_eth_dev *dev)
5976 : : {
5977 : : struct ixgbe_hw *hw;
5978 : : struct ci_tx_queue *txq;
5979 : : uint64_t bus_addr;
5980 : : uint32_t txctrl;
5981 : : uint16_t i;
5982 : :
5983 : 0 : PMD_INIT_FUNC_TRACE();
5984 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5985 : :
5986 : : /* Setup the Base and Length of the Tx Descriptor Rings */
5987 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
5988 : 0 : txq = dev->data->tx_queues[i];
5989 : 0 : bus_addr = txq->tx_ring_dma;
5990 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(i),
5991 : : (uint32_t)(bus_addr & 0x00000000ffffffffULL));
5992 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(i),
5993 : : (uint32_t)(bus_addr >> 32));
5994 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(i),
5995 : : txq->nb_tx_desc * sizeof(union ixgbe_adv_tx_desc));
5996 : : /* Setup the HW Tx Head and TX Tail descriptor pointers */
5997 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDH(i), 0);
5998 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTDT(i), 0);
5999 : :
6000 : : /*
6001 : : * Disable Tx Head Writeback RO bit, since this hoses
6002 : : * bookkeeping if things aren't delivered in order.
6003 : : */
6004 : 0 : txctrl = IXGBE_READ_REG(hw,
6005 : : IXGBE_VFDCA_TXCTRL(i));
6006 : 0 : txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
6007 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i),
6008 : : txctrl);
6009 : : }
6010 : 0 : }
6011 : :
6012 : : /*
6013 : : * [VF] Start Transmit and Receive Units.
6014 : : */
6015 : : void __rte_cold
6016 : 0 : ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
6017 : : {
6018 : : struct ixgbe_hw *hw;
6019 : : struct ci_tx_queue *txq;
6020 : : struct ci_rx_queue *rxq;
6021 : : uint32_t txdctl;
6022 : : uint32_t rxdctl;
6023 : : uint16_t i;
6024 : : int poll_ms;
6025 : :
6026 : 0 : PMD_INIT_FUNC_TRACE();
6027 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6028 : :
6029 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
6030 : 0 : txq = dev->data->tx_queues[i];
6031 : : /* Setup Transmit Threshold Registers */
6032 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
6033 : 0 : txdctl |= txq->pthresh & 0x7F;
6034 : 0 : txdctl |= ((txq->hthresh & 0x7F) << 8);
6035 : 0 : txdctl |= ((txq->wthresh & 0x7F) << 16);
6036 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
6037 : : }
6038 : :
6039 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
6040 : :
6041 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
6042 : 0 : txdctl |= IXGBE_TXDCTL_ENABLE;
6043 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
6044 : :
6045 : : poll_ms = 10;
6046 : : /* Wait until TX Enable ready */
6047 : : do {
6048 : : rte_delay_ms(1);
6049 : 0 : txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
6050 [ # # # # ]: 0 : } while (--poll_ms && !(txdctl & IXGBE_TXDCTL_ENABLE));
6051 [ # # ]: 0 : if (!poll_ms)
6052 : 0 : PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
6053 : : else
6054 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
6055 : : }
6056 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
6057 : :
6058 : 0 : rxq = dev->data->rx_queues[i];
6059 : :
6060 : 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
6061 : 0 : rxdctl |= IXGBE_RXDCTL_ENABLE;
6062 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl);
6063 : :
6064 : : /* Wait until RX Enable ready */
6065 : : poll_ms = 10;
6066 : : do {
6067 : : rte_delay_ms(1);
6068 : 0 : rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
6069 [ # # # # ]: 0 : } while (--poll_ms && !(rxdctl & IXGBE_RXDCTL_ENABLE));
6070 [ # # ]: 0 : if (!poll_ms)
6071 : 0 : PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
6072 : : else
6073 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
6074 : : rte_wmb();
6075 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), rxq->nb_rx_desc - 1);
6076 : :
6077 : : }
6078 : 0 : }
6079 : :
6080 : : int
6081 : 0 : ixgbe_rss_conf_init(struct ixgbe_rss_conf *out,
6082 : : const struct rte_flow_action_rss *in)
6083 : : {
6084 [ # # # # ]: 0 : if (in->key_len > RTE_DIM(out->key) || in->queue_num > RTE_DIM(out->queue))
6085 : : return -EINVAL;
6086 : :
6087 : 0 : *out = (struct ixgbe_rss_conf){
6088 : 0 : .types = in->types,
6089 : : .key_len = in->key_len,
6090 : : .queue_num = in->queue_num,
6091 : : };
6092 [ # # ]: 0 : if (in->key_len != 0)
6093 : 0 : memcpy(out->key, in->key, in->key_len);
6094 [ # # ]: 0 : if (in->queue_num != 0)
6095 : 0 : memcpy(out->queue, in->queue, sizeof(*in->queue) * in->queue_num);
6096 : :
6097 : : return 0;
6098 : : }
6099 : :
6100 : : void
6101 : 0 : ixgbe_hw_rss_filter_program(struct ixgbe_hw *hw,
6102 : : const struct ixgbe_rss_conf *conf)
6103 : : {
6104 : : uint32_t reta;
6105 : : uint16_t i;
6106 : : uint16_t j;
6107 : : uint16_t sp_reta_size;
6108 : : uint32_t reta_reg;
6109 : 0 : struct rte_eth_rss_conf rss_conf = {
6110 : 0 : .rss_key = conf->key_len ?
6111 [ # # ]: 0 : (void *)(uintptr_t)conf->key : NULL,
6112 : : .rss_key_len = conf->key_len,
6113 : 0 : .rss_hf = conf->types,
6114 : : };
6115 : :
6116 : 0 : PMD_INIT_FUNC_TRACE();
6117 : :
6118 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
6119 : :
6120 : : /* Fill in redirection table
6121 : : * The byte-swap is needed because NIC registers are in
6122 : : * little-endian order.
6123 : : */
6124 : : reta = 0;
6125 [ # # ]: 0 : for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
6126 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
6127 : :
6128 [ # # ]: 0 : if (j == conf->queue_num)
6129 : : j = 0;
6130 : 0 : reta = (reta << 8) | conf->queue[j];
6131 [ # # ]: 0 : if ((i & 3) == 3)
6132 [ # # ]: 0 : IXGBE_WRITE_REG(hw, reta_reg,
6133 : : rte_bswap32(reta));
6134 : : }
6135 : :
6136 : : /* Configure the RSS key and the RSS protocols used to compute
6137 : : * the RSS hash of input packets.
6138 : : */
6139 [ # # ]: 0 : if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
6140 : 0 : ixgbe_mrqc_rss_remove(hw);
6141 : 0 : return;
6142 : : }
6143 [ # # ]: 0 : if (rss_conf.rss_key == NULL)
6144 : 0 : rss_conf.rss_key = rss_intel_key; /* Default hash key */
6145 : 0 : ixgbe_hw_rss_hash_set(hw, &rss_conf);
6146 : : }
6147 : :
6148 : : void
6149 : 0 : ixgbe_hw_rss_filter_clear(struct ixgbe_hw *hw)
6150 : : {
6151 : 0 : ixgbe_mrqc_rss_remove(hw);
6152 : 0 : }
|