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