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