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