1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
16 #include <rte_byteorder.h>
17 #include <rte_common.h>
18 #include <rte_cycles.h>
20 #include <rte_debug.h>
21 #include <rte_ethdev.h>
22 #include <ethdev_driver.h>
23 #include <rte_security_driver.h>
24 #include <rte_memzone.h>
25 #include <rte_atomic.h>
26 #include <rte_mempool.h>
27 #include <rte_malloc.h>
29 #include <rte_ether.h>
30 #include <rte_prefetch.h>
34 #include <rte_string_fns.h>
35 #include <rte_errno.h>
39 #include "txgbe_logs.h"
40 #include "base/txgbe.h"
41 #include "txgbe_ethdev.h"
42 #include "txgbe_rxtx.h"
44 #ifdef RTE_LIBRTE_IEEE1588
45 #define TXGBE_TX_IEEE1588_TMST PKT_TX_IEEE1588_TMST
47 #define TXGBE_TX_IEEE1588_TMST 0
50 /* Bit Mask to indicate what bits required for building TX context */
51 static const u64 TXGBE_TX_OFFLOAD_MASK = (PKT_TX_IP_CKSUM |
60 PKT_TX_OUTER_IP_CKSUM |
61 PKT_TX_OUTER_UDP_CKSUM |
62 #ifdef RTE_LIB_SECURITY
65 TXGBE_TX_IEEE1588_TMST);
67 #define TXGBE_TX_OFFLOAD_NOTSUP_MASK \
68 (PKT_TX_OFFLOAD_MASK ^ TXGBE_TX_OFFLOAD_MASK)
71 * Prefetch a cache line into all cache levels.
73 #define rte_txgbe_prefetch(p) rte_prefetch0(p)
76 txgbe_is_vf(struct rte_eth_dev *dev)
78 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
80 switch (hw->mac.type) {
81 case txgbe_mac_raptor_vf:
88 /*********************************************************************
92 **********************************************************************/
95 * Check for descriptors with their DD bit set and free mbufs.
96 * Return the total number of buffers freed.
98 static __rte_always_inline int
99 txgbe_tx_free_bufs(struct txgbe_tx_queue *txq)
101 struct txgbe_tx_entry *txep;
104 struct rte_mbuf *m, *free[RTE_TXGBE_TX_MAX_FREE_BUF_SZ];
106 /* check DD bit on threshold descriptor */
107 status = txq->tx_ring[txq->tx_next_dd].dw3;
108 if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
109 if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
110 txgbe_set32_masked(txq->tdc_reg_addr,
111 TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
116 * first buffer to free from S/W ring is at index
117 * tx_next_dd - (tx_free_thresh-1)
119 txep = &txq->sw_ring[txq->tx_next_dd - (txq->tx_free_thresh - 1)];
120 for (i = 0; i < txq->tx_free_thresh; ++i, ++txep) {
121 /* free buffers one at a time */
122 m = rte_pktmbuf_prefree_seg(txep->mbuf);
125 if (unlikely(m == NULL))
128 if (nb_free >= RTE_TXGBE_TX_MAX_FREE_BUF_SZ ||
129 (nb_free > 0 && m->pool != free[0]->pool)) {
130 rte_mempool_put_bulk(free[0]->pool,
131 (void **)free, nb_free);
139 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
141 /* buffers were freed, update counters */
142 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_free_thresh);
143 txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_free_thresh);
144 if (txq->tx_next_dd >= txq->nb_tx_desc)
145 txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
147 return txq->tx_free_thresh;
150 /* Populate 4 descriptors with data from 4 mbufs */
152 tx4(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
154 uint64_t buf_dma_addr;
158 for (i = 0; i < 4; ++i, ++txdp, ++pkts) {
159 buf_dma_addr = rte_mbuf_data_iova(*pkts);
160 pkt_len = (*pkts)->data_len;
162 /* write data to descriptor */
163 txdp->qw0 = rte_cpu_to_le_64(buf_dma_addr);
164 txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
165 TXGBE_TXD_DATLEN(pkt_len));
166 txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
168 rte_prefetch0(&(*pkts)->pool);
172 /* Populate 1 descriptor with data from 1 mbuf */
174 tx1(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
176 uint64_t buf_dma_addr;
179 buf_dma_addr = rte_mbuf_data_iova(*pkts);
180 pkt_len = (*pkts)->data_len;
182 /* write data to descriptor */
183 txdp->qw0 = cpu_to_le64(buf_dma_addr);
184 txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
185 TXGBE_TXD_DATLEN(pkt_len));
186 txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
188 rte_prefetch0(&(*pkts)->pool);
192 * Fill H/W descriptor ring with mbuf data.
193 * Copy mbuf pointers to the S/W ring.
196 txgbe_tx_fill_hw_ring(struct txgbe_tx_queue *txq, struct rte_mbuf **pkts,
199 volatile struct txgbe_tx_desc *txdp = &txq->tx_ring[txq->tx_tail];
200 struct txgbe_tx_entry *txep = &txq->sw_ring[txq->tx_tail];
201 const int N_PER_LOOP = 4;
202 const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
203 int mainpart, leftover;
207 * Process most of the packets in chunks of N pkts. Any
208 * leftover packets will get processed one at a time.
210 mainpart = (nb_pkts & ((uint32_t)~N_PER_LOOP_MASK));
211 leftover = (nb_pkts & ((uint32_t)N_PER_LOOP_MASK));
212 for (i = 0; i < mainpart; i += N_PER_LOOP) {
213 /* Copy N mbuf pointers to the S/W ring */
214 for (j = 0; j < N_PER_LOOP; ++j)
215 (txep + i + j)->mbuf = *(pkts + i + j);
216 tx4(txdp + i, pkts + i);
219 if (unlikely(leftover > 0)) {
220 for (i = 0; i < leftover; ++i) {
221 (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
222 tx1(txdp + mainpart + i, pkts + mainpart + i);
227 static inline uint16_t
228 tx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
231 struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
235 * Begin scanning the H/W ring for done descriptors when the
236 * number of available descriptors drops below tx_free_thresh. For
237 * each done descriptor, free the associated buffer.
239 if (txq->nb_tx_free < txq->tx_free_thresh)
240 txgbe_tx_free_bufs(txq);
242 /* Only use descriptors that are available */
243 nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
244 if (unlikely(nb_pkts == 0))
247 /* Use exactly nb_pkts descriptors */
248 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
251 * At this point, we know there are enough descriptors in the
252 * ring to transmit all the packets. This assumes that each
253 * mbuf contains a single segment, and that no new offloads
254 * are expected, which would require a new context descriptor.
258 * See if we're going to wrap-around. If so, handle the top
259 * of the descriptor ring first, then do the bottom. If not,
260 * the processing looks just like the "bottom" part anyway...
262 if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
263 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
264 txgbe_tx_fill_hw_ring(txq, tx_pkts, n);
268 /* Fill H/W descriptor ring with mbuf data */
269 txgbe_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
270 txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
273 * Check for wrap-around. This would only happen if we used
274 * up to the last descriptor in the ring, no more, no less.
276 if (txq->tx_tail >= txq->nb_tx_desc)
279 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
280 (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
281 (uint16_t)txq->tx_tail, (uint16_t)nb_pkts);
283 /* update tail pointer */
285 txgbe_set32_relaxed(txq->tdt_reg_addr, txq->tx_tail);
291 txgbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
296 /* Try to transmit at least chunks of TX_MAX_BURST pkts */
297 if (likely(nb_pkts <= RTE_PMD_TXGBE_TX_MAX_BURST))
298 return tx_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
300 /* transmit more than the max burst, in chunks of TX_MAX_BURST */
305 n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_TX_MAX_BURST);
306 ret = tx_xmit_pkts(tx_queue, &tx_pkts[nb_tx], n);
307 nb_tx = (uint16_t)(nb_tx + ret);
308 nb_pkts = (uint16_t)(nb_pkts - ret);
317 txgbe_set_xmit_ctx(struct txgbe_tx_queue *txq,
318 volatile struct txgbe_tx_ctx_desc *ctx_txd,
319 uint64_t ol_flags, union txgbe_tx_offload tx_offload,
320 __rte_unused uint64_t *mdata)
322 union txgbe_tx_offload tx_offload_mask;
323 uint32_t type_tucmd_mlhl;
324 uint32_t mss_l4len_idx;
326 uint32_t vlan_macip_lens;
327 uint32_t tunnel_seed;
329 ctx_idx = txq->ctx_curr;
330 tx_offload_mask.data[0] = 0;
331 tx_offload_mask.data[1] = 0;
333 /* Specify which HW CTX to upload. */
334 mss_l4len_idx = TXGBE_TXD_IDX(ctx_idx);
335 type_tucmd_mlhl = TXGBE_TXD_CTXT;
337 tx_offload_mask.ptid |= ~0;
338 type_tucmd_mlhl |= TXGBE_TXD_PTID(tx_offload.ptid);
340 /* check if TCP segmentation required for this packet */
341 if (ol_flags & PKT_TX_TCP_SEG) {
342 tx_offload_mask.l2_len |= ~0;
343 tx_offload_mask.l3_len |= ~0;
344 tx_offload_mask.l4_len |= ~0;
345 tx_offload_mask.tso_segsz |= ~0;
346 mss_l4len_idx |= TXGBE_TXD_MSS(tx_offload.tso_segsz);
347 mss_l4len_idx |= TXGBE_TXD_L4LEN(tx_offload.l4_len);
348 } else { /* no TSO, check if hardware checksum is needed */
349 if (ol_flags & PKT_TX_IP_CKSUM) {
350 tx_offload_mask.l2_len |= ~0;
351 tx_offload_mask.l3_len |= ~0;
354 switch (ol_flags & PKT_TX_L4_MASK) {
355 case PKT_TX_UDP_CKSUM:
357 TXGBE_TXD_L4LEN(sizeof(struct rte_udp_hdr));
358 tx_offload_mask.l2_len |= ~0;
359 tx_offload_mask.l3_len |= ~0;
361 case PKT_TX_TCP_CKSUM:
363 TXGBE_TXD_L4LEN(sizeof(struct rte_tcp_hdr));
364 tx_offload_mask.l2_len |= ~0;
365 tx_offload_mask.l3_len |= ~0;
367 case PKT_TX_SCTP_CKSUM:
369 TXGBE_TXD_L4LEN(sizeof(struct rte_sctp_hdr));
370 tx_offload_mask.l2_len |= ~0;
371 tx_offload_mask.l3_len |= ~0;
378 vlan_macip_lens = TXGBE_TXD_IPLEN(tx_offload.l3_len >> 1);
380 if (ol_flags & PKT_TX_TUNNEL_MASK) {
381 tx_offload_mask.outer_tun_len |= ~0;
382 tx_offload_mask.outer_l2_len |= ~0;
383 tx_offload_mask.outer_l3_len |= ~0;
384 tx_offload_mask.l2_len |= ~0;
385 tunnel_seed = TXGBE_TXD_ETUNLEN(tx_offload.outer_tun_len >> 1);
386 tunnel_seed |= TXGBE_TXD_EIPLEN(tx_offload.outer_l3_len >> 2);
388 switch (ol_flags & PKT_TX_TUNNEL_MASK) {
389 case PKT_TX_TUNNEL_IPIP:
390 /* for non UDP / GRE tunneling, set to 0b */
392 case PKT_TX_TUNNEL_VXLAN:
393 case PKT_TX_TUNNEL_VXLAN_GPE:
394 case PKT_TX_TUNNEL_GENEVE:
395 tunnel_seed |= TXGBE_TXD_ETYPE_UDP;
397 case PKT_TX_TUNNEL_GRE:
398 tunnel_seed |= TXGBE_TXD_ETYPE_GRE;
401 PMD_TX_LOG(ERR, "Tunnel type not supported");
404 vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.outer_l2_len);
407 vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.l2_len);
410 if (ol_flags & PKT_TX_VLAN_PKT) {
411 tx_offload_mask.vlan_tci |= ~0;
412 vlan_macip_lens |= TXGBE_TXD_VLAN(tx_offload.vlan_tci);
415 #ifdef RTE_LIB_SECURITY
416 if (ol_flags & PKT_TX_SEC_OFFLOAD) {
417 union txgbe_crypto_tx_desc_md *md =
418 (union txgbe_crypto_tx_desc_md *)mdata;
419 tunnel_seed |= TXGBE_TXD_IPSEC_SAIDX(md->sa_idx);
420 type_tucmd_mlhl |= md->enc ?
421 (TXGBE_TXD_IPSEC_ESP | TXGBE_TXD_IPSEC_ESPENC) : 0;
422 type_tucmd_mlhl |= TXGBE_TXD_IPSEC_ESPLEN(md->pad_len);
423 tx_offload_mask.sa_idx |= ~0;
424 tx_offload_mask.sec_pad_len |= ~0;
428 txq->ctx_cache[ctx_idx].flags = ol_flags;
429 txq->ctx_cache[ctx_idx].tx_offload.data[0] =
430 tx_offload_mask.data[0] & tx_offload.data[0];
431 txq->ctx_cache[ctx_idx].tx_offload.data[1] =
432 tx_offload_mask.data[1] & tx_offload.data[1];
433 txq->ctx_cache[ctx_idx].tx_offload_mask = tx_offload_mask;
435 ctx_txd->dw0 = rte_cpu_to_le_32(vlan_macip_lens);
436 ctx_txd->dw1 = rte_cpu_to_le_32(tunnel_seed);
437 ctx_txd->dw2 = rte_cpu_to_le_32(type_tucmd_mlhl);
438 ctx_txd->dw3 = rte_cpu_to_le_32(mss_l4len_idx);
442 * Check which hardware context can be used. Use the existing match
443 * or create a new context descriptor.
445 static inline uint32_t
446 what_ctx_update(struct txgbe_tx_queue *txq, uint64_t flags,
447 union txgbe_tx_offload tx_offload)
449 /* If match with the current used context */
450 if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
451 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
452 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
453 & tx_offload.data[0])) &&
454 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
455 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
456 & tx_offload.data[1]))))
457 return txq->ctx_curr;
459 /* What if match with the next context */
461 if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
462 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
463 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
464 & tx_offload.data[0])) &&
465 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
466 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
467 & tx_offload.data[1]))))
468 return txq->ctx_curr;
470 /* Mismatch, use the previous context */
471 return TXGBE_CTX_NUM;
474 static inline uint32_t
475 tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
479 if ((ol_flags & PKT_TX_L4_MASK) != PKT_TX_L4_NO_CKSUM) {
481 tmp |= TXGBE_TXD_L4CS;
483 if (ol_flags & PKT_TX_IP_CKSUM) {
485 tmp |= TXGBE_TXD_IPCS;
487 if (ol_flags & PKT_TX_OUTER_IP_CKSUM) {
489 tmp |= TXGBE_TXD_EIPCS;
491 if (ol_flags & PKT_TX_TCP_SEG) {
493 /* implies IPv4 cksum */
494 if (ol_flags & PKT_TX_IPV4)
495 tmp |= TXGBE_TXD_IPCS;
496 tmp |= TXGBE_TXD_L4CS;
498 if (ol_flags & PKT_TX_VLAN_PKT)
504 static inline uint32_t
505 tx_desc_ol_flags_to_cmdtype(uint64_t ol_flags)
507 uint32_t cmdtype = 0;
509 if (ol_flags & PKT_TX_VLAN_PKT)
510 cmdtype |= TXGBE_TXD_VLE;
511 if (ol_flags & PKT_TX_TCP_SEG)
512 cmdtype |= TXGBE_TXD_TSE;
513 if (ol_flags & PKT_TX_MACSEC)
514 cmdtype |= TXGBE_TXD_LINKSEC;
518 static inline uint8_t
519 tx_desc_ol_flags_to_ptid(uint64_t oflags, uint32_t ptype)
524 return txgbe_encode_ptype(ptype);
526 /* Only support flags in TXGBE_TX_OFFLOAD_MASK */
527 tun = !!(oflags & PKT_TX_TUNNEL_MASK);
530 ptype = RTE_PTYPE_L2_ETHER;
531 if (oflags & PKT_TX_VLAN)
532 ptype |= RTE_PTYPE_L2_ETHER_VLAN;
535 if (oflags & (PKT_TX_OUTER_IPV4 | PKT_TX_OUTER_IP_CKSUM))
536 ptype |= RTE_PTYPE_L3_IPV4;
537 else if (oflags & (PKT_TX_OUTER_IPV6))
538 ptype |= RTE_PTYPE_L3_IPV6;
540 if (oflags & (PKT_TX_IPV4 | PKT_TX_IP_CKSUM))
541 ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV4 : RTE_PTYPE_L3_IPV4);
542 else if (oflags & (PKT_TX_IPV6))
543 ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV6 : RTE_PTYPE_L3_IPV6);
546 switch (oflags & (PKT_TX_L4_MASK)) {
547 case PKT_TX_TCP_CKSUM:
548 ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
550 case PKT_TX_UDP_CKSUM:
551 ptype |= (tun ? RTE_PTYPE_INNER_L4_UDP : RTE_PTYPE_L4_UDP);
553 case PKT_TX_SCTP_CKSUM:
554 ptype |= (tun ? RTE_PTYPE_INNER_L4_SCTP : RTE_PTYPE_L4_SCTP);
558 if (oflags & PKT_TX_TCP_SEG)
559 ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
562 switch (oflags & PKT_TX_TUNNEL_MASK) {
563 case PKT_TX_TUNNEL_VXLAN:
564 ptype |= RTE_PTYPE_L2_ETHER |
566 RTE_PTYPE_TUNNEL_VXLAN;
567 ptype |= RTE_PTYPE_INNER_L2_ETHER;
569 case PKT_TX_TUNNEL_GRE:
570 ptype |= RTE_PTYPE_L2_ETHER |
572 RTE_PTYPE_TUNNEL_GRE;
573 ptype |= RTE_PTYPE_INNER_L2_ETHER;
575 case PKT_TX_TUNNEL_GENEVE:
576 ptype |= RTE_PTYPE_L2_ETHER |
578 RTE_PTYPE_TUNNEL_GENEVE;
579 ptype |= RTE_PTYPE_INNER_L2_ETHER;
581 case PKT_TX_TUNNEL_VXLAN_GPE:
582 ptype |= RTE_PTYPE_L2_ETHER |
584 RTE_PTYPE_TUNNEL_VXLAN_GPE;
586 case PKT_TX_TUNNEL_IPIP:
587 case PKT_TX_TUNNEL_IP:
588 ptype |= RTE_PTYPE_L2_ETHER |
594 return txgbe_encode_ptype(ptype);
597 #ifndef DEFAULT_TX_FREE_THRESH
598 #define DEFAULT_TX_FREE_THRESH 32
601 /* Reset transmit descriptors after they have been used */
603 txgbe_xmit_cleanup(struct txgbe_tx_queue *txq)
605 struct txgbe_tx_entry *sw_ring = txq->sw_ring;
606 volatile struct txgbe_tx_desc *txr = txq->tx_ring;
607 uint16_t last_desc_cleaned = txq->last_desc_cleaned;
608 uint16_t nb_tx_desc = txq->nb_tx_desc;
609 uint16_t desc_to_clean_to;
610 uint16_t nb_tx_to_clean;
613 /* Determine the last descriptor needing to be cleaned */
614 desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_free_thresh);
615 if (desc_to_clean_to >= nb_tx_desc)
616 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
618 /* Check to make sure the last descriptor to clean is done */
619 desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
620 status = txr[desc_to_clean_to].dw3;
621 if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
622 PMD_TX_FREE_LOG(DEBUG,
623 "TX descriptor %4u is not done"
624 "(port=%d queue=%d)",
626 txq->port_id, txq->queue_id);
627 if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
628 txgbe_set32_masked(txq->tdc_reg_addr,
629 TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
630 /* Failed to clean any descriptors, better luck next time */
634 /* Figure out how many descriptors will be cleaned */
635 if (last_desc_cleaned > desc_to_clean_to)
636 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
639 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
642 PMD_TX_FREE_LOG(DEBUG,
643 "Cleaning %4u TX descriptors: %4u to %4u "
644 "(port=%d queue=%d)",
645 nb_tx_to_clean, last_desc_cleaned, desc_to_clean_to,
646 txq->port_id, txq->queue_id);
649 * The last descriptor to clean is done, so that means all the
650 * descriptors from the last descriptor that was cleaned
651 * up to the last descriptor with the RS bit set
652 * are done. Only reset the threshold descriptor.
654 txr[desc_to_clean_to].dw3 = 0;
656 /* Update the txq to reflect the last descriptor that was cleaned */
657 txq->last_desc_cleaned = desc_to_clean_to;
658 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
664 static inline uint8_t
665 txgbe_get_tun_len(struct rte_mbuf *mbuf)
667 struct txgbe_genevehdr genevehdr;
668 const struct txgbe_genevehdr *gh;
671 switch (mbuf->ol_flags & PKT_TX_TUNNEL_MASK) {
672 case PKT_TX_TUNNEL_IPIP:
675 case PKT_TX_TUNNEL_VXLAN:
676 case PKT_TX_TUNNEL_VXLAN_GPE:
677 tun_len = sizeof(struct txgbe_udphdr)
678 + sizeof(struct txgbe_vxlanhdr);
680 case PKT_TX_TUNNEL_GRE:
681 tun_len = sizeof(struct txgbe_nvgrehdr);
683 case PKT_TX_TUNNEL_GENEVE:
684 gh = rte_pktmbuf_read(mbuf,
685 mbuf->outer_l2_len + mbuf->outer_l3_len,
686 sizeof(genevehdr), &genevehdr);
687 tun_len = sizeof(struct txgbe_udphdr)
688 + sizeof(struct txgbe_genevehdr)
689 + (gh->opt_len << 2);
699 txgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
702 struct txgbe_tx_queue *txq;
703 struct txgbe_tx_entry *sw_ring;
704 struct txgbe_tx_entry *txe, *txn;
705 volatile struct txgbe_tx_desc *txr;
706 volatile struct txgbe_tx_desc *txd;
707 struct rte_mbuf *tx_pkt;
708 struct rte_mbuf *m_seg;
709 uint64_t buf_dma_addr;
710 uint32_t olinfo_status;
711 uint32_t cmd_type_len;
722 union txgbe_tx_offload tx_offload;
723 #ifdef RTE_LIB_SECURITY
727 tx_offload.data[0] = 0;
728 tx_offload.data[1] = 0;
730 sw_ring = txq->sw_ring;
732 tx_id = txq->tx_tail;
733 txe = &sw_ring[tx_id];
735 /* Determine if the descriptor ring needs to be cleaned. */
736 if (txq->nb_tx_free < txq->tx_free_thresh)
737 txgbe_xmit_cleanup(txq);
739 rte_prefetch0(&txe->mbuf->pool);
742 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
745 pkt_len = tx_pkt->pkt_len;
748 * Determine how many (if any) context descriptors
749 * are needed for offload functionality.
751 ol_flags = tx_pkt->ol_flags;
752 #ifdef RTE_LIB_SECURITY
753 use_ipsec = txq->using_ipsec && (ol_flags & PKT_TX_SEC_OFFLOAD);
756 /* If hardware offload required */
757 tx_ol_req = ol_flags & TXGBE_TX_OFFLOAD_MASK;
759 tx_offload.ptid = tx_desc_ol_flags_to_ptid(tx_ol_req,
760 tx_pkt->packet_type);
761 tx_offload.l2_len = tx_pkt->l2_len;
762 tx_offload.l3_len = tx_pkt->l3_len;
763 tx_offload.l4_len = tx_pkt->l4_len;
764 tx_offload.vlan_tci = tx_pkt->vlan_tci;
765 tx_offload.tso_segsz = tx_pkt->tso_segsz;
766 tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
767 tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
768 tx_offload.outer_tun_len = txgbe_get_tun_len(tx_pkt);
770 #ifdef RTE_LIB_SECURITY
772 union txgbe_crypto_tx_desc_md *ipsec_mdata =
773 (union txgbe_crypto_tx_desc_md *)
774 rte_security_dynfield(tx_pkt);
775 tx_offload.sa_idx = ipsec_mdata->sa_idx;
776 tx_offload.sec_pad_len = ipsec_mdata->pad_len;
780 /* If new context need be built or reuse the exist ctx*/
781 ctx = what_ctx_update(txq, tx_ol_req, tx_offload);
782 /* Only allocate context descriptor if required */
783 new_ctx = (ctx == TXGBE_CTX_NUM);
788 * Keep track of how many descriptors are used this loop
789 * This will always be the number of segments + the number of
790 * Context descriptors required to transmit the packet
792 nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
795 * The number of descriptors that must be allocated for a
796 * packet is the number of segments of that packet, plus 1
797 * Context Descriptor for the hardware offload, if any.
798 * Determine the last TX descriptor to allocate in the TX ring
799 * for the packet, starting from the current position (tx_id)
802 tx_last = (uint16_t)(tx_id + nb_used - 1);
805 if (tx_last >= txq->nb_tx_desc)
806 tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
808 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
809 " tx_first=%u tx_last=%u",
810 (uint16_t)txq->port_id,
811 (uint16_t)txq->queue_id,
817 * Make sure there are enough TX descriptors available to
818 * transmit the entire packet.
819 * nb_used better be less than or equal to txq->tx_free_thresh
821 if (nb_used > txq->nb_tx_free) {
822 PMD_TX_FREE_LOG(DEBUG,
823 "Not enough free TX descriptors "
824 "nb_used=%4u nb_free=%4u "
825 "(port=%d queue=%d)",
826 nb_used, txq->nb_tx_free,
827 txq->port_id, txq->queue_id);
829 if (txgbe_xmit_cleanup(txq) != 0) {
830 /* Could not clean any descriptors */
836 /* nb_used better be <= txq->tx_free_thresh */
837 if (unlikely(nb_used > txq->tx_free_thresh)) {
838 PMD_TX_FREE_LOG(DEBUG,
839 "The number of descriptors needed to "
840 "transmit the packet exceeds the "
841 "RS bit threshold. This will impact "
843 "nb_used=%4u nb_free=%4u "
844 "tx_free_thresh=%4u. "
845 "(port=%d queue=%d)",
846 nb_used, txq->nb_tx_free,
848 txq->port_id, txq->queue_id);
850 * Loop here until there are enough TX
851 * descriptors or until the ring cannot be
854 while (nb_used > txq->nb_tx_free) {
855 if (txgbe_xmit_cleanup(txq) != 0) {
857 * Could not clean any
869 * By now there are enough free TX descriptors to transmit
874 * Set common flags of all TX Data Descriptors.
876 * The following bits must be set in all Data Descriptors:
877 * - TXGBE_TXD_DTYP_DATA
878 * - TXGBE_TXD_DCMD_DEXT
880 * The following bits must be set in the first Data Descriptor
881 * and are ignored in the other ones:
882 * - TXGBE_TXD_DCMD_IFCS
883 * - TXGBE_TXD_MAC_1588
884 * - TXGBE_TXD_DCMD_VLE
886 * The following bits must only be set in the last Data
888 * - TXGBE_TXD_CMD_EOP
890 * The following bits can be set in any Data Descriptor, but
891 * are only set in the last Data Descriptor:
894 cmd_type_len = TXGBE_TXD_FCS;
896 #ifdef RTE_LIBRTE_IEEE1588
897 if (ol_flags & PKT_TX_IEEE1588_TMST)
898 cmd_type_len |= TXGBE_TXD_1588;
903 if (ol_flags & PKT_TX_TCP_SEG) {
904 /* when TSO is on, paylen in descriptor is the
905 * not the packet len but the tcp payload len
907 pkt_len -= (tx_offload.l2_len +
908 tx_offload.l3_len + tx_offload.l4_len);
910 (tx_pkt->ol_flags & PKT_TX_TUNNEL_MASK)
911 ? tx_offload.outer_l2_len +
912 tx_offload.outer_l3_len : 0;
916 * Setup the TX Advanced Context Descriptor if required
919 volatile struct txgbe_tx_ctx_desc *ctx_txd;
921 ctx_txd = (volatile struct txgbe_tx_ctx_desc *)
924 txn = &sw_ring[txe->next_id];
925 rte_prefetch0(&txn->mbuf->pool);
927 if (txe->mbuf != NULL) {
928 rte_pktmbuf_free_seg(txe->mbuf);
932 txgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
934 rte_security_dynfield(tx_pkt));
936 txe->last_id = tx_last;
937 tx_id = txe->next_id;
942 * Setup the TX Advanced Data Descriptor,
943 * This path will go through
944 * whatever new/reuse the context descriptor
946 cmd_type_len |= tx_desc_ol_flags_to_cmdtype(ol_flags);
948 tx_desc_cksum_flags_to_olinfo(ol_flags);
949 olinfo_status |= TXGBE_TXD_IDX(ctx);
952 olinfo_status |= TXGBE_TXD_PAYLEN(pkt_len);
953 #ifdef RTE_LIB_SECURITY
955 olinfo_status |= TXGBE_TXD_IPSEC;
961 txn = &sw_ring[txe->next_id];
962 rte_prefetch0(&txn->mbuf->pool);
964 if (txe->mbuf != NULL)
965 rte_pktmbuf_free_seg(txe->mbuf);
969 * Set up Transmit Data Descriptor.
971 slen = m_seg->data_len;
972 buf_dma_addr = rte_mbuf_data_iova(m_seg);
973 txd->qw0 = rte_cpu_to_le_64(buf_dma_addr);
974 txd->dw2 = rte_cpu_to_le_32(cmd_type_len | slen);
975 txd->dw3 = rte_cpu_to_le_32(olinfo_status);
976 txe->last_id = tx_last;
977 tx_id = txe->next_id;
980 } while (m_seg != NULL);
983 * The last packet data descriptor needs End Of Packet (EOP)
985 cmd_type_len |= TXGBE_TXD_EOP;
986 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
988 txd->dw2 |= rte_cpu_to_le_32(cmd_type_len);
996 * Set the Transmit Descriptor Tail (TDT)
998 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
999 (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
1000 (uint16_t)tx_id, (uint16_t)nb_tx);
1001 txgbe_set32_relaxed(txq->tdt_reg_addr, tx_id);
1002 txq->tx_tail = tx_id;
1007 /*********************************************************************
1011 **********************************************************************/
1013 txgbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1018 struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
1020 for (i = 0; i < nb_pkts; i++) {
1022 ol_flags = m->ol_flags;
1025 * Check if packet meets requirements for number of segments
1027 * NOTE: for txgbe it's always (40 - WTHRESH) for both TSO and
1031 if (m->nb_segs > TXGBE_TX_MAX_SEG - txq->wthresh) {
1032 rte_errno = -EINVAL;
1036 if (ol_flags & TXGBE_TX_OFFLOAD_NOTSUP_MASK) {
1037 rte_errno = -ENOTSUP;
1041 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1042 ret = rte_validate_tx_offload(m);
1048 ret = rte_net_intel_cksum_prepare(m);
1058 /*********************************************************************
1062 **********************************************************************/
1063 /* @note: fix txgbe_dev_supported_ptypes_get() if any change here. */
1064 static inline uint32_t
1065 txgbe_rxd_pkt_info_to_pkt_type(uint32_t pkt_info, uint16_t ptid_mask)
1067 uint16_t ptid = TXGBE_RXD_PTID(pkt_info);
1071 return txgbe_decode_ptype(ptid);
1074 static inline uint64_t
1075 txgbe_rxd_pkt_info_to_pkt_flags(uint32_t pkt_info)
1077 static uint64_t ip_rss_types_map[16] __rte_cache_aligned = {
1078 0, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH,
1079 0, PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH,
1080 PKT_RX_RSS_HASH, 0, 0, 0,
1081 0, 0, 0, PKT_RX_FDIR,
1083 #ifdef RTE_LIBRTE_IEEE1588
1084 static uint64_t ip_pkt_etqf_map[8] = {
1085 0, 0, 0, PKT_RX_IEEE1588_PTP,
1088 int etfid = txgbe_etflt_id(TXGBE_RXD_PTID(pkt_info));
1089 if (likely(-1 != etfid))
1090 return ip_pkt_etqf_map[etfid] |
1091 ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1093 return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1095 return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1099 static inline uint64_t
1100 rx_desc_status_to_pkt_flags(uint32_t rx_status, uint64_t vlan_flags)
1105 * Check if VLAN present only.
1106 * Do not check whether L3/L4 rx checksum done by NIC or not,
1107 * That can be found from rte_eth_rxmode.offloads flag
1109 pkt_flags = (rx_status & TXGBE_RXD_STAT_VLAN &&
1110 vlan_flags & PKT_RX_VLAN_STRIPPED)
1113 #ifdef RTE_LIBRTE_IEEE1588
1114 if (rx_status & TXGBE_RXD_STAT_1588)
1115 pkt_flags = pkt_flags | PKT_RX_IEEE1588_TMST;
1120 static inline uint64_t
1121 rx_desc_error_to_pkt_flags(uint32_t rx_status)
1123 uint64_t pkt_flags = 0;
1125 /* checksum offload can't be disabled */
1126 if (rx_status & TXGBE_RXD_STAT_IPCS) {
1127 pkt_flags |= (rx_status & TXGBE_RXD_ERR_IPCS
1128 ? PKT_RX_IP_CKSUM_BAD : PKT_RX_IP_CKSUM_GOOD);
1131 if (rx_status & TXGBE_RXD_STAT_L4CS) {
1132 pkt_flags |= (rx_status & TXGBE_RXD_ERR_L4CS
1133 ? PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD);
1136 if (rx_status & TXGBE_RXD_STAT_EIPCS &&
1137 rx_status & TXGBE_RXD_ERR_EIPCS) {
1138 pkt_flags |= PKT_RX_OUTER_IP_CKSUM_BAD;
1141 #ifdef RTE_LIB_SECURITY
1142 if (rx_status & TXGBE_RXD_STAT_SECP) {
1143 pkt_flags |= PKT_RX_SEC_OFFLOAD;
1144 if (rx_status & TXGBE_RXD_ERR_SECERR)
1145 pkt_flags |= PKT_RX_SEC_OFFLOAD_FAILED;
1153 * LOOK_AHEAD defines how many desc statuses to check beyond the
1154 * current descriptor.
1155 * It must be a pound define for optimal performance.
1156 * Do not change the value of LOOK_AHEAD, as the txgbe_rx_scan_hw_ring
1157 * function only works with LOOK_AHEAD=8.
1159 #define LOOK_AHEAD 8
1160 #if (LOOK_AHEAD != 8)
1161 #error "PMD TXGBE: LOOK_AHEAD must be 8\n"
1164 txgbe_rx_scan_hw_ring(struct txgbe_rx_queue *rxq)
1166 volatile struct txgbe_rx_desc *rxdp;
1167 struct txgbe_rx_entry *rxep;
1168 struct rte_mbuf *mb;
1172 uint32_t s[LOOK_AHEAD];
1173 uint32_t pkt_info[LOOK_AHEAD];
1174 int i, j, nb_rx = 0;
1177 /* get references to current descriptor and S/W ring entry */
1178 rxdp = &rxq->rx_ring[rxq->rx_tail];
1179 rxep = &rxq->sw_ring[rxq->rx_tail];
1181 status = rxdp->qw1.lo.status;
1182 /* check to make sure there is at least 1 packet to receive */
1183 if (!(status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
1187 * Scan LOOK_AHEAD descriptors at a time to determine which descriptors
1188 * reference packets that are ready to be received.
1190 for (i = 0; i < RTE_PMD_TXGBE_RX_MAX_BURST;
1191 i += LOOK_AHEAD, rxdp += LOOK_AHEAD, rxep += LOOK_AHEAD) {
1192 /* Read desc statuses backwards to avoid race condition */
1193 for (j = 0; j < LOOK_AHEAD; j++)
1194 s[j] = rte_le_to_cpu_32(rxdp[j].qw1.lo.status);
1196 rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1198 /* Compute how many status bits were set */
1199 for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
1200 (s[nb_dd] & TXGBE_RXD_STAT_DD); nb_dd++)
1203 for (j = 0; j < nb_dd; j++)
1204 pkt_info[j] = rte_le_to_cpu_32(rxdp[j].qw0.dw0);
1208 /* Translate descriptor info to mbuf format */
1209 for (j = 0; j < nb_dd; ++j) {
1211 pkt_len = rte_le_to_cpu_16(rxdp[j].qw1.hi.len) -
1213 mb->data_len = pkt_len;
1214 mb->pkt_len = pkt_len;
1215 mb->vlan_tci = rte_le_to_cpu_16(rxdp[j].qw1.hi.tag);
1217 /* convert descriptor fields to rte mbuf flags */
1218 pkt_flags = rx_desc_status_to_pkt_flags(s[j],
1220 pkt_flags |= rx_desc_error_to_pkt_flags(s[j]);
1222 txgbe_rxd_pkt_info_to_pkt_flags(pkt_info[j]);
1223 mb->ol_flags = pkt_flags;
1225 txgbe_rxd_pkt_info_to_pkt_type(pkt_info[j],
1226 rxq->pkt_type_mask);
1228 if (likely(pkt_flags & PKT_RX_RSS_HASH))
1230 rte_le_to_cpu_32(rxdp[j].qw0.dw1);
1231 else if (pkt_flags & PKT_RX_FDIR) {
1232 mb->hash.fdir.hash =
1233 rte_le_to_cpu_16(rxdp[j].qw0.hi.csum) &
1234 TXGBE_ATR_HASH_MASK;
1236 rte_le_to_cpu_16(rxdp[j].qw0.hi.ipid);
1240 /* Move mbuf pointers from the S/W ring to the stage */
1241 for (j = 0; j < LOOK_AHEAD; ++j)
1242 rxq->rx_stage[i + j] = rxep[j].mbuf;
1244 /* stop if all requested packets could not be received */
1245 if (nb_dd != LOOK_AHEAD)
1249 /* clear software ring entries so we can cleanup correctly */
1250 for (i = 0; i < nb_rx; ++i)
1251 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
1257 txgbe_rx_alloc_bufs(struct txgbe_rx_queue *rxq, bool reset_mbuf)
1259 volatile struct txgbe_rx_desc *rxdp;
1260 struct txgbe_rx_entry *rxep;
1261 struct rte_mbuf *mb;
1266 /* allocate buffers in bulk directly into the S/W ring */
1267 alloc_idx = rxq->rx_free_trigger - (rxq->rx_free_thresh - 1);
1268 rxep = &rxq->sw_ring[alloc_idx];
1269 diag = rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
1270 rxq->rx_free_thresh);
1271 if (unlikely(diag != 0))
1274 rxdp = &rxq->rx_ring[alloc_idx];
1275 for (i = 0; i < rxq->rx_free_thresh; ++i) {
1276 /* populate the static rte mbuf fields */
1279 mb->port = rxq->port_id;
1281 rte_mbuf_refcnt_set(mb, 1);
1282 mb->data_off = RTE_PKTMBUF_HEADROOM;
1284 /* populate the descriptors */
1285 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
1286 TXGBE_RXD_HDRADDR(&rxdp[i], 0);
1287 TXGBE_RXD_PKTADDR(&rxdp[i], dma_addr);
1290 /* update state of internal queue structure */
1291 rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh;
1292 if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
1293 rxq->rx_free_trigger = rxq->rx_free_thresh - 1;
1299 static inline uint16_t
1300 txgbe_rx_fill_from_stage(struct txgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
1303 struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
1306 /* how many packets are ready to return? */
1307 nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
1309 /* copy mbuf pointers to the application's packet list */
1310 for (i = 0; i < nb_pkts; ++i)
1311 rx_pkts[i] = stage[i];
1313 /* update internal queue state */
1314 rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
1315 rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
1320 static inline uint16_t
1321 txgbe_rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1324 struct txgbe_rx_queue *rxq = (struct txgbe_rx_queue *)rx_queue;
1325 struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1328 /* Any previously recv'd pkts will be returned from the Rx stage */
1329 if (rxq->rx_nb_avail)
1330 return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1332 /* Scan the H/W ring for packets to receive */
1333 nb_rx = (uint16_t)txgbe_rx_scan_hw_ring(rxq);
1335 /* update internal queue state */
1336 rxq->rx_next_avail = 0;
1337 rxq->rx_nb_avail = nb_rx;
1338 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
1340 /* if required, allocate new buffers to replenish descriptors */
1341 if (rxq->rx_tail > rxq->rx_free_trigger) {
1342 uint16_t cur_free_trigger = rxq->rx_free_trigger;
1344 if (txgbe_rx_alloc_bufs(rxq, true) != 0) {
1347 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1348 "queue_id=%u", (uint16_t)rxq->port_id,
1349 (uint16_t)rxq->queue_id);
1351 dev->data->rx_mbuf_alloc_failed +=
1352 rxq->rx_free_thresh;
1355 * Need to rewind any previous receives if we cannot
1356 * allocate new buffers to replenish the old ones.
1358 rxq->rx_nb_avail = 0;
1359 rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
1360 for (i = 0, j = rxq->rx_tail; i < nb_rx; ++i, ++j)
1361 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
1366 /* update tail pointer */
1368 txgbe_set32_relaxed(rxq->rdt_reg_addr, cur_free_trigger);
1371 if (rxq->rx_tail >= rxq->nb_rx_desc)
1374 /* received any packets this loop? */
1375 if (rxq->rx_nb_avail)
1376 return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1381 /* split requests into chunks of size RTE_PMD_TXGBE_RX_MAX_BURST */
1383 txgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1388 if (unlikely(nb_pkts == 0))
1391 if (likely(nb_pkts <= RTE_PMD_TXGBE_RX_MAX_BURST))
1392 return txgbe_rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
1394 /* request is relatively large, chunk it up */
1399 n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_RX_MAX_BURST);
1400 ret = txgbe_rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
1401 nb_rx = (uint16_t)(nb_rx + ret);
1402 nb_pkts = (uint16_t)(nb_pkts - ret);
1411 txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1414 struct txgbe_rx_queue *rxq;
1415 volatile struct txgbe_rx_desc *rx_ring;
1416 volatile struct txgbe_rx_desc *rxdp;
1417 struct txgbe_rx_entry *sw_ring;
1418 struct txgbe_rx_entry *rxe;
1419 struct rte_mbuf *rxm;
1420 struct rte_mbuf *nmb;
1421 struct txgbe_rx_desc rxd;
1434 rx_id = rxq->rx_tail;
1435 rx_ring = rxq->rx_ring;
1436 sw_ring = rxq->sw_ring;
1437 struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1438 while (nb_rx < nb_pkts) {
1440 * The order of operations here is important as the DD status
1441 * bit must not be read after any other descriptor fields.
1442 * rx_ring and rxdp are pointing to volatile data so the order
1443 * of accesses cannot be reordered by the compiler. If they were
1444 * not volatile, they could be reordered which could lead to
1445 * using invalid descriptor fields when read from rxd.
1447 rxdp = &rx_ring[rx_id];
1448 staterr = rxdp->qw1.lo.status;
1449 if (!(staterr & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
1456 * If the TXGBE_RXD_STAT_EOP flag is not set, the RX packet
1457 * is likely to be invalid and to be dropped by the various
1458 * validation checks performed by the network stack.
1460 * Allocate a new mbuf to replenish the RX ring descriptor.
1461 * If the allocation fails:
1462 * - arrange for that RX descriptor to be the first one
1463 * being parsed the next time the receive function is
1464 * invoked [on the same queue].
1466 * - Stop parsing the RX ring and return immediately.
1468 * This policy do not drop the packet received in the RX
1469 * descriptor for which the allocation of a new mbuf failed.
1470 * Thus, it allows that packet to be later retrieved if
1471 * mbuf have been freed in the mean time.
1472 * As a side effect, holding RX descriptors instead of
1473 * systematically giving them back to the NIC may lead to
1474 * RX ring exhaustion situations.
1475 * However, the NIC can gracefully prevent such situations
1476 * to happen by sending specific "back-pressure" flow control
1477 * frames to its peer(s).
1479 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1480 "ext_err_stat=0x%08x pkt_len=%u",
1481 (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1482 (uint16_t)rx_id, (uint32_t)staterr,
1483 (uint16_t)rte_le_to_cpu_16(rxd.qw1.hi.len));
1485 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1487 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1488 "queue_id=%u", (uint16_t)rxq->port_id,
1489 (uint16_t)rxq->queue_id);
1490 dev->data->rx_mbuf_alloc_failed++;
1495 rxe = &sw_ring[rx_id];
1497 if (rx_id == rxq->nb_rx_desc)
1500 /* Prefetch next mbuf while processing current one. */
1501 rte_txgbe_prefetch(sw_ring[rx_id].mbuf);
1504 * When next RX descriptor is on a cache-line boundary,
1505 * prefetch the next 4 RX descriptors and the next 8 pointers
1508 if ((rx_id & 0x3) == 0) {
1509 rte_txgbe_prefetch(&rx_ring[rx_id]);
1510 rte_txgbe_prefetch(&sw_ring[rx_id]);
1515 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1516 TXGBE_RXD_HDRADDR(rxdp, 0);
1517 TXGBE_RXD_PKTADDR(rxdp, dma_addr);
1520 * Initialize the returned mbuf.
1521 * 1) setup generic mbuf fields:
1522 * - number of segments,
1525 * - RX port identifier.
1526 * 2) integrate hardware offload data, if any:
1527 * - RSS flag & hash,
1528 * - IP checksum flag,
1529 * - VLAN TCI, if any,
1532 pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.qw1.hi.len) -
1534 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1535 rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
1538 rxm->pkt_len = pkt_len;
1539 rxm->data_len = pkt_len;
1540 rxm->port = rxq->port_id;
1542 pkt_info = rte_le_to_cpu_32(rxd.qw0.dw0);
1543 /* Only valid if PKT_RX_VLAN set in pkt_flags */
1544 rxm->vlan_tci = rte_le_to_cpu_16(rxd.qw1.hi.tag);
1546 pkt_flags = rx_desc_status_to_pkt_flags(staterr,
1548 pkt_flags |= rx_desc_error_to_pkt_flags(staterr);
1549 pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1550 rxm->ol_flags = pkt_flags;
1551 rxm->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1552 rxq->pkt_type_mask);
1554 if (likely(pkt_flags & PKT_RX_RSS_HASH)) {
1555 rxm->hash.rss = rte_le_to_cpu_32(rxd.qw0.dw1);
1556 } else if (pkt_flags & PKT_RX_FDIR) {
1557 rxm->hash.fdir.hash =
1558 rte_le_to_cpu_16(rxd.qw0.hi.csum) &
1559 TXGBE_ATR_HASH_MASK;
1560 rxm->hash.fdir.id = rte_le_to_cpu_16(rxd.qw0.hi.ipid);
1563 * Store the mbuf address into the next entry of the array
1564 * of returned packets.
1566 rx_pkts[nb_rx++] = rxm;
1568 rxq->rx_tail = rx_id;
1571 * If the number of free RX descriptors is greater than the RX free
1572 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1574 * Update the RDT with the value of the last processed RX descriptor
1575 * minus 1, to guarantee that the RDT register is never equal to the
1576 * RDH register, which creates a "full" ring situation from the
1577 * hardware point of view...
1579 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
1580 if (nb_hold > rxq->rx_free_thresh) {
1581 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1582 "nb_hold=%u nb_rx=%u",
1583 (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1584 (uint16_t)rx_id, (uint16_t)nb_hold,
1586 rx_id = (uint16_t)((rx_id == 0) ?
1587 (rxq->nb_rx_desc - 1) : (rx_id - 1));
1588 txgbe_set32(rxq->rdt_reg_addr, rx_id);
1591 rxq->nb_rx_hold = nb_hold;
1596 * txgbe_fill_cluster_head_buf - fill the first mbuf of the returned packet
1598 * Fill the following info in the HEAD buffer of the Rx cluster:
1599 * - RX port identifier
1600 * - hardware offload data, if any:
1602 * - IP checksum flag
1603 * - VLAN TCI, if any
1605 * @head HEAD of the packet cluster
1606 * @desc HW descriptor to get data from
1607 * @rxq Pointer to the Rx queue
1610 txgbe_fill_cluster_head_buf(struct rte_mbuf *head, struct txgbe_rx_desc *desc,
1611 struct txgbe_rx_queue *rxq, uint32_t staterr)
1616 head->port = rxq->port_id;
1618 /* The vlan_tci field is only valid when PKT_RX_VLAN is
1619 * set in the pkt_flags field.
1621 head->vlan_tci = rte_le_to_cpu_16(desc->qw1.hi.tag);
1622 pkt_info = rte_le_to_cpu_32(desc->qw0.dw0);
1623 pkt_flags = rx_desc_status_to_pkt_flags(staterr, rxq->vlan_flags);
1624 pkt_flags |= rx_desc_error_to_pkt_flags(staterr);
1625 pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1626 head->ol_flags = pkt_flags;
1627 head->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1628 rxq->pkt_type_mask);
1630 if (likely(pkt_flags & PKT_RX_RSS_HASH)) {
1631 head->hash.rss = rte_le_to_cpu_32(desc->qw0.dw1);
1632 } else if (pkt_flags & PKT_RX_FDIR) {
1633 head->hash.fdir.hash = rte_le_to_cpu_16(desc->qw0.hi.csum)
1634 & TXGBE_ATR_HASH_MASK;
1635 head->hash.fdir.id = rte_le_to_cpu_16(desc->qw0.hi.ipid);
1640 * txgbe_recv_pkts_lro - receive handler for and LRO case.
1642 * @rx_queue Rx queue handle
1643 * @rx_pkts table of received packets
1644 * @nb_pkts size of rx_pkts table
1645 * @bulk_alloc if TRUE bulk allocation is used for a HW ring refilling
1647 * Handles the Rx HW ring completions when RSC feature is configured. Uses an
1648 * additional ring of txgbe_rsc_entry's that will hold the relevant RSC info.
1650 * We use the same logic as in Linux and in FreeBSD txgbe drivers:
1651 * 1) When non-EOP RSC completion arrives:
1652 * a) Update the HEAD of the current RSC aggregation cluster with the new
1653 * segment's data length.
1654 * b) Set the "next" pointer of the current segment to point to the segment
1655 * at the NEXTP index.
1656 * c) Pass the HEAD of RSC aggregation cluster on to the next NEXTP entry
1657 * in the sw_rsc_ring.
1658 * 2) When EOP arrives we just update the cluster's total length and offload
1659 * flags and deliver the cluster up to the upper layers. In our case - put it
1660 * in the rx_pkts table.
1662 * Returns the number of received packets/clusters (according to the "bulk
1663 * receive" interface).
1665 static inline uint16_t
1666 txgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts,
1669 struct txgbe_rx_queue *rxq = rx_queue;
1670 struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1671 volatile struct txgbe_rx_desc *rx_ring = rxq->rx_ring;
1672 struct txgbe_rx_entry *sw_ring = rxq->sw_ring;
1673 struct txgbe_scattered_rx_entry *sw_sc_ring = rxq->sw_sc_ring;
1674 uint16_t rx_id = rxq->rx_tail;
1676 uint16_t nb_hold = rxq->nb_rx_hold;
1677 uint16_t prev_id = rxq->rx_tail;
1679 while (nb_rx < nb_pkts) {
1681 struct txgbe_rx_entry *rxe;
1682 struct txgbe_scattered_rx_entry *sc_entry;
1683 struct txgbe_scattered_rx_entry *next_sc_entry = NULL;
1684 struct txgbe_rx_entry *next_rxe = NULL;
1685 struct rte_mbuf *first_seg;
1686 struct rte_mbuf *rxm;
1687 struct rte_mbuf *nmb = NULL;
1688 struct txgbe_rx_desc rxd;
1691 volatile struct txgbe_rx_desc *rxdp;
1696 * The code in this whole file uses the volatile pointer to
1697 * ensure the read ordering of the status and the rest of the
1698 * descriptor fields (on the compiler level only!!!). This is so
1699 * UGLY - why not to just use the compiler barrier instead? DPDK
1700 * even has the rte_compiler_barrier() for that.
1702 * But most importantly this is just wrong because this doesn't
1703 * ensure memory ordering in a general case at all. For
1704 * instance, DPDK is supposed to work on Power CPUs where
1705 * compiler barrier may just not be enough!
1707 * I tried to write only this function properly to have a
1708 * starting point (as a part of an LRO/RSC series) but the
1709 * compiler cursed at me when I tried to cast away the
1710 * "volatile" from rx_ring (yes, it's volatile too!!!). So, I'm
1711 * keeping it the way it is for now.
1713 * The code in this file is broken in so many other places and
1714 * will just not work on a big endian CPU anyway therefore the
1715 * lines below will have to be revisited together with the rest
1719 * - Get rid of "volatile" and let the compiler do its job.
1720 * - Use the proper memory barrier (rte_rmb()) to ensure the
1721 * memory ordering below.
1723 rxdp = &rx_ring[rx_id];
1724 staterr = rte_le_to_cpu_32(rxdp->qw1.lo.status);
1726 if (!(staterr & TXGBE_RXD_STAT_DD))
1731 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1732 "staterr=0x%x data_len=%u",
1733 rxq->port_id, rxq->queue_id, rx_id, staterr,
1734 rte_le_to_cpu_16(rxd.qw1.hi.len));
1737 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1739 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed "
1740 "port_id=%u queue_id=%u",
1741 rxq->port_id, rxq->queue_id);
1743 dev->data->rx_mbuf_alloc_failed++;
1746 } else if (nb_hold > rxq->rx_free_thresh) {
1747 uint16_t next_rdt = rxq->rx_free_trigger;
1749 if (!txgbe_rx_alloc_bufs(rxq, false)) {
1751 txgbe_set32_relaxed(rxq->rdt_reg_addr,
1753 nb_hold -= rxq->rx_free_thresh;
1755 PMD_RX_LOG(DEBUG, "RX bulk alloc failed "
1756 "port_id=%u queue_id=%u",
1757 rxq->port_id, rxq->queue_id);
1759 dev->data->rx_mbuf_alloc_failed++;
1765 rxe = &sw_ring[rx_id];
1766 eop = staterr & TXGBE_RXD_STAT_EOP;
1768 next_id = rx_id + 1;
1769 if (next_id == rxq->nb_rx_desc)
1772 /* Prefetch next mbuf while processing current one. */
1773 rte_txgbe_prefetch(sw_ring[next_id].mbuf);
1776 * When next RX descriptor is on a cache-line boundary,
1777 * prefetch the next 4 RX descriptors and the next 4 pointers
1780 if ((next_id & 0x3) == 0) {
1781 rte_txgbe_prefetch(&rx_ring[next_id]);
1782 rte_txgbe_prefetch(&sw_ring[next_id]);
1789 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1791 * Update RX descriptor with the physical address of the
1792 * new data buffer of the new allocated mbuf.
1796 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1797 TXGBE_RXD_HDRADDR(rxdp, 0);
1798 TXGBE_RXD_PKTADDR(rxdp, dma);
1804 * Set data length & data buffer address of mbuf.
1806 data_len = rte_le_to_cpu_16(rxd.qw1.hi.len);
1807 rxm->data_len = data_len;
1812 * Get next descriptor index:
1813 * - For RSC it's in the NEXTP field.
1814 * - For a scattered packet - it's just a following
1817 if (TXGBE_RXD_RSCCNT(rxd.qw0.dw0))
1818 nextp_id = TXGBE_RXD_NEXTP(staterr);
1822 next_sc_entry = &sw_sc_ring[nextp_id];
1823 next_rxe = &sw_ring[nextp_id];
1824 rte_txgbe_prefetch(next_rxe);
1827 sc_entry = &sw_sc_ring[rx_id];
1828 first_seg = sc_entry->fbuf;
1829 sc_entry->fbuf = NULL;
1832 * If this is the first buffer of the received packet,
1833 * set the pointer to the first mbuf of the packet and
1834 * initialize its context.
1835 * Otherwise, update the total length and the number of segments
1836 * of the current scattered packet, and update the pointer to
1837 * the last mbuf of the current packet.
1839 if (first_seg == NULL) {
1841 first_seg->pkt_len = data_len;
1842 first_seg->nb_segs = 1;
1844 first_seg->pkt_len += data_len;
1845 first_seg->nb_segs++;
1852 * If this is not the last buffer of the received packet, update
1853 * the pointer to the first mbuf at the NEXTP entry in the
1854 * sw_sc_ring and continue to parse the RX ring.
1856 if (!eop && next_rxe) {
1857 rxm->next = next_rxe->mbuf;
1858 next_sc_entry->fbuf = first_seg;
1862 /* Initialize the first mbuf of the returned packet */
1863 txgbe_fill_cluster_head_buf(first_seg, &rxd, rxq, staterr);
1866 * Deal with the case, when HW CRC srip is disabled.
1867 * That can't happen when LRO is enabled, but still could
1868 * happen for scattered RX mode.
1870 first_seg->pkt_len -= rxq->crc_len;
1871 if (unlikely(rxm->data_len <= rxq->crc_len)) {
1872 struct rte_mbuf *lp;
1874 for (lp = first_seg; lp->next != rxm; lp = lp->next)
1877 first_seg->nb_segs--;
1878 lp->data_len -= rxq->crc_len - rxm->data_len;
1880 rte_pktmbuf_free_seg(rxm);
1882 rxm->data_len -= rxq->crc_len;
1885 /* Prefetch data of first segment, if configured to do so. */
1886 rte_packet_prefetch((char *)first_seg->buf_addr +
1887 first_seg->data_off);
1890 * Store the mbuf address into the next entry of the array
1891 * of returned packets.
1893 rx_pkts[nb_rx++] = first_seg;
1897 * Record index of the next RX descriptor to probe.
1899 rxq->rx_tail = rx_id;
1902 * If the number of free RX descriptors is greater than the RX free
1903 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1905 * Update the RDT with the value of the last processed RX descriptor
1906 * minus 1, to guarantee that the RDT register is never equal to the
1907 * RDH register, which creates a "full" ring situation from the
1908 * hardware point of view...
1910 if (!bulk_alloc && nb_hold > rxq->rx_free_thresh) {
1911 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1912 "nb_hold=%u nb_rx=%u",
1913 rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
1916 txgbe_set32_relaxed(rxq->rdt_reg_addr, prev_id);
1920 rxq->nb_rx_hold = nb_hold;
1925 txgbe_recv_pkts_lro_single_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1928 return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, false);
1932 txgbe_recv_pkts_lro_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1935 return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, true);
1939 txgbe_get_rx_queue_offloads(struct rte_eth_dev *dev __rte_unused)
1941 return DEV_RX_OFFLOAD_VLAN_STRIP;
1945 txgbe_get_rx_port_offloads(struct rte_eth_dev *dev)
1948 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1949 struct rte_eth_dev_sriov *sriov = &RTE_ETH_DEV_SRIOV(dev);
1951 offloads = DEV_RX_OFFLOAD_IPV4_CKSUM |
1952 DEV_RX_OFFLOAD_UDP_CKSUM |
1953 DEV_RX_OFFLOAD_TCP_CKSUM |
1954 DEV_RX_OFFLOAD_KEEP_CRC |
1955 DEV_RX_OFFLOAD_JUMBO_FRAME |
1956 DEV_RX_OFFLOAD_VLAN_FILTER |
1957 DEV_RX_OFFLOAD_RSS_HASH |
1958 DEV_RX_OFFLOAD_SCATTER;
1960 if (!txgbe_is_vf(dev))
1961 offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1962 DEV_RX_OFFLOAD_QINQ_STRIP |
1963 DEV_RX_OFFLOAD_VLAN_EXTEND);
1966 * RSC is only supported by PF devices in a non-SR-IOV
1969 if (hw->mac.type == txgbe_mac_raptor && !sriov->active)
1970 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
1972 if (hw->mac.type == txgbe_mac_raptor)
1973 offloads |= DEV_RX_OFFLOAD_MACSEC_STRIP;
1975 offloads |= DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
1977 #ifdef RTE_LIB_SECURITY
1978 if (dev->security_ctx)
1979 offloads |= DEV_RX_OFFLOAD_SECURITY;
1985 static void __rte_cold
1986 txgbe_tx_queue_release_mbufs(struct txgbe_tx_queue *txq)
1990 if (txq->sw_ring != NULL) {
1991 for (i = 0; i < txq->nb_tx_desc; i++) {
1992 if (txq->sw_ring[i].mbuf != NULL) {
1993 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1994 txq->sw_ring[i].mbuf = NULL;
2001 txgbe_tx_done_cleanup_full(struct txgbe_tx_queue *txq, uint32_t free_cnt)
2003 struct txgbe_tx_entry *swr_ring = txq->sw_ring;
2004 uint16_t i, tx_last, tx_id;
2005 uint16_t nb_tx_free_last;
2006 uint16_t nb_tx_to_clean;
2009 /* Start free mbuf from the next of tx_tail */
2010 tx_last = txq->tx_tail;
2011 tx_id = swr_ring[tx_last].next_id;
2013 if (txq->nb_tx_free == 0 && txgbe_xmit_cleanup(txq))
2016 nb_tx_to_clean = txq->nb_tx_free;
2017 nb_tx_free_last = txq->nb_tx_free;
2019 free_cnt = txq->nb_tx_desc;
2021 /* Loop through swr_ring to count the amount of
2022 * freeable mubfs and packets.
2024 for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2025 for (i = 0; i < nb_tx_to_clean &&
2026 pkt_cnt < free_cnt &&
2027 tx_id != tx_last; i++) {
2028 if (swr_ring[tx_id].mbuf != NULL) {
2029 rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2030 swr_ring[tx_id].mbuf = NULL;
2033 * last segment in the packet,
2034 * increment packet count
2036 pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
2039 tx_id = swr_ring[tx_id].next_id;
2042 if (pkt_cnt < free_cnt) {
2043 if (txgbe_xmit_cleanup(txq))
2046 nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2047 nb_tx_free_last = txq->nb_tx_free;
2051 return (int)pkt_cnt;
2055 txgbe_tx_done_cleanup_simple(struct txgbe_tx_queue *txq,
2060 if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2061 free_cnt = txq->nb_tx_desc;
2063 cnt = free_cnt - free_cnt % txq->tx_free_thresh;
2065 for (i = 0; i < cnt; i += n) {
2066 if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_free_thresh)
2069 n = txgbe_tx_free_bufs(txq);
2079 txgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt)
2081 struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
2082 if (txq->offloads == 0 &&
2083 #ifdef RTE_LIB_SECURITY
2084 !(txq->using_ipsec) &&
2086 txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST)
2087 return txgbe_tx_done_cleanup_simple(txq, free_cnt);
2089 return txgbe_tx_done_cleanup_full(txq, free_cnt);
2092 static void __rte_cold
2093 txgbe_tx_free_swring(struct txgbe_tx_queue *txq)
2096 txq->sw_ring != NULL)
2097 rte_free(txq->sw_ring);
2100 static void __rte_cold
2101 txgbe_tx_queue_release(struct txgbe_tx_queue *txq)
2103 if (txq != NULL && txq->ops != NULL) {
2104 txq->ops->release_mbufs(txq);
2105 txq->ops->free_swring(txq);
2111 txgbe_dev_tx_queue_release(void *txq)
2113 txgbe_tx_queue_release(txq);
2116 /* (Re)set dynamic txgbe_tx_queue fields to defaults */
2117 static void __rte_cold
2118 txgbe_reset_tx_queue(struct txgbe_tx_queue *txq)
2120 static const struct txgbe_tx_desc zeroed_desc = {0};
2121 struct txgbe_tx_entry *txe = txq->sw_ring;
2124 /* Zero out HW ring memory */
2125 for (i = 0; i < txq->nb_tx_desc; i++)
2126 txq->tx_ring[i] = zeroed_desc;
2128 /* Initialize SW ring entries */
2129 prev = (uint16_t)(txq->nb_tx_desc - 1);
2130 for (i = 0; i < txq->nb_tx_desc; i++) {
2131 volatile struct txgbe_tx_desc *txd = &txq->tx_ring[i];
2133 txd->dw3 = rte_cpu_to_le_32(TXGBE_TXD_DD);
2136 txe[prev].next_id = i;
2140 txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
2144 * Always allow 1 descriptor to be un-allocated to avoid
2145 * a H/W race condition
2147 txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2148 txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2150 memset((void *)&txq->ctx_cache, 0,
2151 TXGBE_CTX_NUM * sizeof(struct txgbe_ctx_info));
2154 static const struct txgbe_txq_ops def_txq_ops = {
2155 .release_mbufs = txgbe_tx_queue_release_mbufs,
2156 .free_swring = txgbe_tx_free_swring,
2157 .reset = txgbe_reset_tx_queue,
2160 /* Takes an ethdev and a queue and sets up the tx function to be used based on
2161 * the queue parameters. Used in tx_queue_setup by primary process and then
2162 * in dev_init by secondary process when attaching to an existing ethdev.
2165 txgbe_set_tx_function(struct rte_eth_dev *dev, struct txgbe_tx_queue *txq)
2167 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
2168 if (txq->offloads == 0 &&
2169 #ifdef RTE_LIB_SECURITY
2170 !(txq->using_ipsec) &&
2172 txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST) {
2173 PMD_INIT_LOG(DEBUG, "Using simple tx code path");
2174 dev->tx_pkt_burst = txgbe_xmit_pkts_simple;
2175 dev->tx_pkt_prepare = NULL;
2177 PMD_INIT_LOG(DEBUG, "Using full-featured tx code path");
2179 " - offloads = 0x%" PRIx64,
2182 " - tx_free_thresh = %lu [RTE_PMD_TXGBE_TX_MAX_BURST=%lu]",
2183 (unsigned long)txq->tx_free_thresh,
2184 (unsigned long)RTE_PMD_TXGBE_TX_MAX_BURST);
2185 dev->tx_pkt_burst = txgbe_xmit_pkts;
2186 dev->tx_pkt_prepare = txgbe_prep_pkts;
2191 txgbe_get_tx_queue_offloads(struct rte_eth_dev *dev)
2199 txgbe_get_tx_port_offloads(struct rte_eth_dev *dev)
2201 uint64_t tx_offload_capa;
2204 DEV_TX_OFFLOAD_VLAN_INSERT |
2205 DEV_TX_OFFLOAD_IPV4_CKSUM |
2206 DEV_TX_OFFLOAD_UDP_CKSUM |
2207 DEV_TX_OFFLOAD_TCP_CKSUM |
2208 DEV_TX_OFFLOAD_SCTP_CKSUM |
2209 DEV_TX_OFFLOAD_TCP_TSO |
2210 DEV_TX_OFFLOAD_UDP_TSO |
2211 DEV_TX_OFFLOAD_UDP_TNL_TSO |
2212 DEV_TX_OFFLOAD_IP_TNL_TSO |
2213 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
2214 DEV_TX_OFFLOAD_GRE_TNL_TSO |
2215 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
2216 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
2217 DEV_TX_OFFLOAD_MULTI_SEGS;
2219 if (!txgbe_is_vf(dev))
2220 tx_offload_capa |= DEV_TX_OFFLOAD_QINQ_INSERT;
2222 tx_offload_capa |= DEV_TX_OFFLOAD_MACSEC_INSERT;
2224 tx_offload_capa |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
2225 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
2227 #ifdef RTE_LIB_SECURITY
2228 if (dev->security_ctx)
2229 tx_offload_capa |= DEV_TX_OFFLOAD_SECURITY;
2231 return tx_offload_capa;
2235 txgbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
2238 unsigned int socket_id,
2239 const struct rte_eth_txconf *tx_conf)
2241 const struct rte_memzone *tz;
2242 struct txgbe_tx_queue *txq;
2243 struct txgbe_hw *hw;
2244 uint16_t tx_free_thresh;
2247 PMD_INIT_FUNC_TRACE();
2248 hw = TXGBE_DEV_HW(dev);
2250 offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2253 * Validate number of transmit descriptors.
2254 * It must not exceed hardware maximum, and must be multiple
2257 if (nb_desc % TXGBE_TXD_ALIGN != 0 ||
2258 nb_desc > TXGBE_RING_DESC_MAX ||
2259 nb_desc < TXGBE_RING_DESC_MIN) {
2264 * The TX descriptor ring will be cleaned after txq->tx_free_thresh
2265 * descriptors are used or if the number of descriptors required
2266 * to transmit a packet is greater than the number of free TX
2268 * One descriptor in the TX ring is used as a sentinel to avoid a
2269 * H/W race condition, hence the maximum threshold constraints.
2270 * When set to zero use default values.
2272 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2273 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2274 if (tx_free_thresh >= (nb_desc - 3)) {
2275 PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the number of "
2276 "TX descriptors minus 3. (tx_free_thresh=%u "
2277 "port=%d queue=%d)",
2278 (unsigned int)tx_free_thresh,
2279 (int)dev->data->port_id, (int)queue_idx);
2283 if ((nb_desc % tx_free_thresh) != 0) {
2284 PMD_INIT_LOG(ERR, "tx_free_thresh must be a divisor of the "
2285 "number of TX descriptors. (tx_free_thresh=%u "
2286 "port=%d queue=%d)", (unsigned int)tx_free_thresh,
2287 (int)dev->data->port_id, (int)queue_idx);
2291 /* Free memory prior to re-allocation if needed... */
2292 if (dev->data->tx_queues[queue_idx] != NULL) {
2293 txgbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
2294 dev->data->tx_queues[queue_idx] = NULL;
2297 /* First allocate the tx queue data structure */
2298 txq = rte_zmalloc_socket("ethdev TX queue",
2299 sizeof(struct txgbe_tx_queue),
2300 RTE_CACHE_LINE_SIZE, socket_id);
2305 * Allocate TX ring hardware descriptors. A memzone large enough to
2306 * handle the maximum ring size is allocated in order to allow for
2307 * resizing in later calls to the queue setup function.
2309 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
2310 sizeof(struct txgbe_tx_desc) * TXGBE_RING_DESC_MAX,
2311 TXGBE_ALIGN, socket_id);
2313 txgbe_tx_queue_release(txq);
2317 txq->nb_tx_desc = nb_desc;
2318 txq->tx_free_thresh = tx_free_thresh;
2319 txq->pthresh = tx_conf->tx_thresh.pthresh;
2320 txq->hthresh = tx_conf->tx_thresh.hthresh;
2321 txq->wthresh = tx_conf->tx_thresh.wthresh;
2322 txq->queue_id = queue_idx;
2323 txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2324 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2325 txq->port_id = dev->data->port_id;
2326 txq->offloads = offloads;
2327 txq->ops = &def_txq_ops;
2328 txq->tx_deferred_start = tx_conf->tx_deferred_start;
2329 #ifdef RTE_LIB_SECURITY
2330 txq->using_ipsec = !!(dev->data->dev_conf.txmode.offloads &
2331 DEV_TX_OFFLOAD_SECURITY);
2334 /* Modification to set tail pointer for virtual function
2335 * if vf is detected.
2337 if (hw->mac.type == txgbe_mac_raptor_vf) {
2338 txq->tdt_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXWP(queue_idx));
2339 txq->tdc_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXCFG(queue_idx));
2341 txq->tdt_reg_addr = TXGBE_REG_ADDR(hw,
2342 TXGBE_TXWP(txq->reg_idx));
2343 txq->tdc_reg_addr = TXGBE_REG_ADDR(hw,
2344 TXGBE_TXCFG(txq->reg_idx));
2347 txq->tx_ring_phys_addr = TMZ_PADDR(tz);
2348 txq->tx_ring = (struct txgbe_tx_desc *)TMZ_VADDR(tz);
2350 /* Allocate software ring */
2351 txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
2352 sizeof(struct txgbe_tx_entry) * nb_desc,
2353 RTE_CACHE_LINE_SIZE, socket_id);
2354 if (txq->sw_ring == NULL) {
2355 txgbe_tx_queue_release(txq);
2358 PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
2359 txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
2361 /* set up scalar TX function as appropriate */
2362 txgbe_set_tx_function(dev, txq);
2364 txq->ops->reset(txq);
2366 dev->data->tx_queues[queue_idx] = txq;
2372 * txgbe_free_sc_cluster - free the not-yet-completed scattered cluster
2374 * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
2375 * in the sw_rsc_ring is not set to NULL but rather points to the next
2376 * mbuf of this RSC aggregation (that has not been completed yet and still
2377 * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
2378 * will just free first "nb_segs" segments of the cluster explicitly by calling
2379 * an rte_pktmbuf_free_seg().
2381 * @m scattered cluster head
2383 static void __rte_cold
2384 txgbe_free_sc_cluster(struct rte_mbuf *m)
2386 uint16_t i, nb_segs = m->nb_segs;
2387 struct rte_mbuf *next_seg;
2389 for (i = 0; i < nb_segs; i++) {
2391 rte_pktmbuf_free_seg(m);
2396 static void __rte_cold
2397 txgbe_rx_queue_release_mbufs(struct txgbe_rx_queue *rxq)
2401 if (rxq->sw_ring != NULL) {
2402 for (i = 0; i < rxq->nb_rx_desc; i++) {
2403 if (rxq->sw_ring[i].mbuf != NULL) {
2404 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2405 rxq->sw_ring[i].mbuf = NULL;
2408 if (rxq->rx_nb_avail) {
2409 for (i = 0; i < rxq->rx_nb_avail; ++i) {
2410 struct rte_mbuf *mb;
2412 mb = rxq->rx_stage[rxq->rx_next_avail + i];
2413 rte_pktmbuf_free_seg(mb);
2415 rxq->rx_nb_avail = 0;
2419 if (rxq->sw_sc_ring)
2420 for (i = 0; i < rxq->nb_rx_desc; i++)
2421 if (rxq->sw_sc_ring[i].fbuf) {
2422 txgbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
2423 rxq->sw_sc_ring[i].fbuf = NULL;
2427 static void __rte_cold
2428 txgbe_rx_queue_release(struct txgbe_rx_queue *rxq)
2431 txgbe_rx_queue_release_mbufs(rxq);
2432 rte_free(rxq->sw_ring);
2433 rte_free(rxq->sw_sc_ring);
2439 txgbe_dev_rx_queue_release(void *rxq)
2441 txgbe_rx_queue_release(rxq);
2445 * Check if Rx Burst Bulk Alloc function can be used.
2447 * 0: the preconditions are satisfied and the bulk allocation function
2449 * -EINVAL: the preconditions are NOT satisfied and the default Rx burst
2450 * function must be used.
2452 static inline int __rte_cold
2453 check_rx_burst_bulk_alloc_preconditions(struct txgbe_rx_queue *rxq)
2458 * Make sure the following pre-conditions are satisfied:
2459 * rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST
2460 * rxq->rx_free_thresh < rxq->nb_rx_desc
2461 * (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
2462 * Scattered packets are not supported. This should be checked
2463 * outside of this function.
2465 if (!(rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST)) {
2466 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2467 "rxq->rx_free_thresh=%d, "
2468 "RTE_PMD_TXGBE_RX_MAX_BURST=%d",
2469 rxq->rx_free_thresh, RTE_PMD_TXGBE_RX_MAX_BURST);
2471 } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
2472 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2473 "rxq->rx_free_thresh=%d, "
2474 "rxq->nb_rx_desc=%d",
2475 rxq->rx_free_thresh, rxq->nb_rx_desc);
2477 } else if (!((rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)) {
2478 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2479 "rxq->nb_rx_desc=%d, "
2480 "rxq->rx_free_thresh=%d",
2481 rxq->nb_rx_desc, rxq->rx_free_thresh);
2488 /* Reset dynamic txgbe_rx_queue fields back to defaults */
2489 static void __rte_cold
2490 txgbe_reset_rx_queue(struct txgbe_adapter *adapter, struct txgbe_rx_queue *rxq)
2492 static const struct txgbe_rx_desc zeroed_desc = {
2493 {{0}, {0} }, {{0}, {0} } };
2495 uint16_t len = rxq->nb_rx_desc;
2498 * By default, the Rx queue setup function allocates enough memory for
2499 * TXGBE_RING_DESC_MAX. The Rx Burst bulk allocation function requires
2500 * extra memory at the end of the descriptor ring to be zero'd out.
2502 if (adapter->rx_bulk_alloc_allowed)
2503 /* zero out extra memory */
2504 len += RTE_PMD_TXGBE_RX_MAX_BURST;
2507 * Zero out HW ring memory. Zero out extra memory at the end of
2508 * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
2509 * reads extra memory as zeros.
2511 for (i = 0; i < len; i++)
2512 rxq->rx_ring[i] = zeroed_desc;
2515 * initialize extra software ring entries. Space for these extra
2516 * entries is always allocated
2518 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2519 for (i = rxq->nb_rx_desc; i < len; ++i)
2520 rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
2522 rxq->rx_nb_avail = 0;
2523 rxq->rx_next_avail = 0;
2524 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2526 rxq->nb_rx_hold = 0;
2527 rxq->pkt_first_seg = NULL;
2528 rxq->pkt_last_seg = NULL;
2532 txgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
2535 unsigned int socket_id,
2536 const struct rte_eth_rxconf *rx_conf,
2537 struct rte_mempool *mp)
2539 const struct rte_memzone *rz;
2540 struct txgbe_rx_queue *rxq;
2541 struct txgbe_hw *hw;
2543 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
2546 PMD_INIT_FUNC_TRACE();
2547 hw = TXGBE_DEV_HW(dev);
2549 offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
2552 * Validate number of receive descriptors.
2553 * It must not exceed hardware maximum, and must be multiple
2556 if (nb_desc % TXGBE_RXD_ALIGN != 0 ||
2557 nb_desc > TXGBE_RING_DESC_MAX ||
2558 nb_desc < TXGBE_RING_DESC_MIN) {
2562 /* Free memory prior to re-allocation if needed... */
2563 if (dev->data->rx_queues[queue_idx] != NULL) {
2564 txgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
2565 dev->data->rx_queues[queue_idx] = NULL;
2568 /* First allocate the rx queue data structure */
2569 rxq = rte_zmalloc_socket("ethdev RX queue",
2570 sizeof(struct txgbe_rx_queue),
2571 RTE_CACHE_LINE_SIZE, socket_id);
2575 rxq->nb_rx_desc = nb_desc;
2576 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
2577 rxq->queue_id = queue_idx;
2578 rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2579 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2580 rxq->port_id = dev->data->port_id;
2581 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)
2582 rxq->crc_len = RTE_ETHER_CRC_LEN;
2585 rxq->drop_en = rx_conf->rx_drop_en;
2586 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
2587 rxq->offloads = offloads;
2590 * The packet type in RX descriptor is different for different NICs.
2591 * So set different masks for different NICs.
2593 rxq->pkt_type_mask = TXGBE_PTID_MASK;
2596 * Allocate RX ring hardware descriptors. A memzone large enough to
2597 * handle the maximum ring size is allocated in order to allow for
2598 * resizing in later calls to the queue setup function.
2600 rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
2601 RX_RING_SZ, TXGBE_ALIGN, socket_id);
2603 txgbe_rx_queue_release(rxq);
2608 * Zero init all the descriptors in the ring.
2610 memset(rz->addr, 0, RX_RING_SZ);
2613 * Modified to setup VFRDT for Virtual Function
2615 if (hw->mac.type == txgbe_mac_raptor_vf) {
2617 TXGBE_REG_ADDR(hw, TXGBE_RXWP(queue_idx));
2619 TXGBE_REG_ADDR(hw, TXGBE_RXRP(queue_idx));
2622 TXGBE_REG_ADDR(hw, TXGBE_RXWP(rxq->reg_idx));
2624 TXGBE_REG_ADDR(hw, TXGBE_RXRP(rxq->reg_idx));
2627 rxq->rx_ring_phys_addr = TMZ_PADDR(rz);
2628 rxq->rx_ring = (struct txgbe_rx_desc *)TMZ_VADDR(rz);
2631 * Certain constraints must be met in order to use the bulk buffer
2632 * allocation Rx burst function. If any of Rx queues doesn't meet them
2633 * the feature should be disabled for the whole port.
2635 if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
2636 PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Rx Bulk Alloc "
2637 "preconditions - canceling the feature for "
2638 "the whole port[%d]",
2639 rxq->queue_id, rxq->port_id);
2640 adapter->rx_bulk_alloc_allowed = false;
2644 * Allocate software ring. Allow for space at the end of the
2645 * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
2646 * function does not access an invalid memory region.
2649 if (adapter->rx_bulk_alloc_allowed)
2650 len += RTE_PMD_TXGBE_RX_MAX_BURST;
2652 rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
2653 sizeof(struct txgbe_rx_entry) * len,
2654 RTE_CACHE_LINE_SIZE, socket_id);
2655 if (!rxq->sw_ring) {
2656 txgbe_rx_queue_release(rxq);
2661 * Always allocate even if it's not going to be needed in order to
2662 * simplify the code.
2664 * This ring is used in LRO and Scattered Rx cases and Scattered Rx may
2665 * be requested in txgbe_dev_rx_init(), which is called later from
2669 rte_zmalloc_socket("rxq->sw_sc_ring",
2670 sizeof(struct txgbe_scattered_rx_entry) * len,
2671 RTE_CACHE_LINE_SIZE, socket_id);
2672 if (!rxq->sw_sc_ring) {
2673 txgbe_rx_queue_release(rxq);
2677 PMD_INIT_LOG(DEBUG, "sw_ring=%p sw_sc_ring=%p hw_ring=%p "
2678 "dma_addr=0x%" PRIx64,
2679 rxq->sw_ring, rxq->sw_sc_ring, rxq->rx_ring,
2680 rxq->rx_ring_phys_addr);
2682 dev->data->rx_queues[queue_idx] = rxq;
2684 txgbe_reset_rx_queue(adapter, rxq);
2690 txgbe_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
2692 #define TXGBE_RXQ_SCAN_INTERVAL 4
2693 volatile struct txgbe_rx_desc *rxdp;
2694 struct txgbe_rx_queue *rxq;
2697 rxq = dev->data->rx_queues[rx_queue_id];
2698 rxdp = &rxq->rx_ring[rxq->rx_tail];
2700 while ((desc < rxq->nb_rx_desc) &&
2701 (rxdp->qw1.lo.status &
2702 rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))) {
2703 desc += TXGBE_RXQ_SCAN_INTERVAL;
2704 rxdp += TXGBE_RXQ_SCAN_INTERVAL;
2705 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
2706 rxdp = &(rxq->rx_ring[rxq->rx_tail +
2707 desc - rxq->nb_rx_desc]);
2714 txgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
2716 struct txgbe_rx_queue *rxq = rx_queue;
2717 volatile uint32_t *status;
2718 uint32_t nb_hold, desc;
2720 if (unlikely(offset >= rxq->nb_rx_desc))
2723 nb_hold = rxq->nb_rx_hold;
2724 if (offset >= rxq->nb_rx_desc - nb_hold)
2725 return RTE_ETH_RX_DESC_UNAVAIL;
2727 desc = rxq->rx_tail + offset;
2728 if (desc >= rxq->nb_rx_desc)
2729 desc -= rxq->nb_rx_desc;
2731 status = &rxq->rx_ring[desc].qw1.lo.status;
2732 if (*status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))
2733 return RTE_ETH_RX_DESC_DONE;
2735 return RTE_ETH_RX_DESC_AVAIL;
2739 txgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
2741 struct txgbe_tx_queue *txq = tx_queue;
2742 volatile uint32_t *status;
2745 if (unlikely(offset >= txq->nb_tx_desc))
2748 desc = txq->tx_tail + offset;
2749 if (desc >= txq->nb_tx_desc) {
2750 desc -= txq->nb_tx_desc;
2751 if (desc >= txq->nb_tx_desc)
2752 desc -= txq->nb_tx_desc;
2755 status = &txq->tx_ring[desc].dw3;
2756 if (*status & rte_cpu_to_le_32(TXGBE_TXD_DD))
2757 return RTE_ETH_TX_DESC_DONE;
2759 return RTE_ETH_TX_DESC_FULL;
2763 txgbe_dev_clear_queues(struct rte_eth_dev *dev)
2766 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
2768 PMD_INIT_FUNC_TRACE();
2770 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2771 struct txgbe_tx_queue *txq = dev->data->tx_queues[i];
2774 txq->ops->release_mbufs(txq);
2775 txq->ops->reset(txq);
2779 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2780 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
2783 txgbe_rx_queue_release_mbufs(rxq);
2784 txgbe_reset_rx_queue(adapter, rxq);
2790 txgbe_dev_free_queues(struct rte_eth_dev *dev)
2794 PMD_INIT_FUNC_TRACE();
2796 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2797 txgbe_dev_rx_queue_release(dev->data->rx_queues[i]);
2798 dev->data->rx_queues[i] = NULL;
2800 dev->data->nb_rx_queues = 0;
2802 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2803 txgbe_dev_tx_queue_release(dev->data->tx_queues[i]);
2804 dev->data->tx_queues[i] = NULL;
2806 dev->data->nb_tx_queues = 0;
2810 * Receive Side Scaling (RSS)
2813 * The source and destination IP addresses of the IP header and the source
2814 * and destination ports of TCP/UDP headers, if any, of received packets are
2815 * hashed against a configurable random key to compute a 32-bit RSS hash result.
2816 * The seven (7) LSBs of the 32-bit hash result are used as an index into a
2817 * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
2818 * RSS output index which is used as the RX queue index where to store the
2820 * The following output is supplied in the RX write-back descriptor:
2821 * - 32-bit result of the Microsoft RSS hash function,
2822 * - 4-bit RSS type field.
2826 * Used as the default key.
2828 static uint8_t rss_intel_key[40] = {
2829 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
2830 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
2831 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
2832 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
2833 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
2837 txgbe_rss_disable(struct rte_eth_dev *dev)
2839 struct txgbe_hw *hw;
2841 hw = TXGBE_DEV_HW(dev);
2842 if (hw->mac.type == txgbe_mac_raptor_vf)
2843 wr32m(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_RSSENA, 0);
2845 wr32m(hw, TXGBE_RACTL, TXGBE_RACTL_RSSENA, 0);
2849 txgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
2850 struct rte_eth_rss_conf *rss_conf)
2852 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2859 if (!txgbe_rss_update_sp(hw->mac.type)) {
2860 PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
2865 hash_key = rss_conf->rss_key;
2867 /* Fill in RSS hash key */
2868 for (i = 0; i < 10; i++) {
2869 rss_key = LS32(hash_key[(i * 4) + 0], 0, 0xFF);
2870 rss_key |= LS32(hash_key[(i * 4) + 1], 8, 0xFF);
2871 rss_key |= LS32(hash_key[(i * 4) + 2], 16, 0xFF);
2872 rss_key |= LS32(hash_key[(i * 4) + 3], 24, 0xFF);
2873 wr32at(hw, TXGBE_REG_RSSKEY, i, rss_key);
2877 /* Set configured hashing protocols */
2878 rss_hf = rss_conf->rss_hf & TXGBE_RSS_OFFLOAD_ALL;
2879 if (hw->mac.type == txgbe_mac_raptor_vf) {
2880 mrqc = rd32(hw, TXGBE_VFPLCFG);
2881 mrqc &= ~TXGBE_VFPLCFG_RSSMASK;
2882 if (rss_hf & ETH_RSS_IPV4)
2883 mrqc |= TXGBE_VFPLCFG_RSSIPV4;
2884 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
2885 mrqc |= TXGBE_VFPLCFG_RSSIPV4TCP;
2886 if (rss_hf & ETH_RSS_IPV6 ||
2887 rss_hf & ETH_RSS_IPV6_EX)
2888 mrqc |= TXGBE_VFPLCFG_RSSIPV6;
2889 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP ||
2890 rss_hf & ETH_RSS_IPV6_TCP_EX)
2891 mrqc |= TXGBE_VFPLCFG_RSSIPV6TCP;
2892 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
2893 mrqc |= TXGBE_VFPLCFG_RSSIPV4UDP;
2894 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP ||
2895 rss_hf & ETH_RSS_IPV6_UDP_EX)
2896 mrqc |= TXGBE_VFPLCFG_RSSIPV6UDP;
2899 mrqc |= TXGBE_VFPLCFG_RSSENA;
2901 mrqc &= ~TXGBE_VFPLCFG_RSSENA;
2903 if (dev->data->nb_rx_queues > 3)
2904 mrqc |= TXGBE_VFPLCFG_RSSHASH(2);
2905 else if (dev->data->nb_rx_queues > 1)
2906 mrqc |= TXGBE_VFPLCFG_RSSHASH(1);
2908 wr32(hw, TXGBE_VFPLCFG, mrqc);
2910 mrqc = rd32(hw, TXGBE_RACTL);
2911 mrqc &= ~TXGBE_RACTL_RSSMASK;
2912 if (rss_hf & ETH_RSS_IPV4)
2913 mrqc |= TXGBE_RACTL_RSSIPV4;
2914 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
2915 mrqc |= TXGBE_RACTL_RSSIPV4TCP;
2916 if (rss_hf & ETH_RSS_IPV6 ||
2917 rss_hf & ETH_RSS_IPV6_EX)
2918 mrqc |= TXGBE_RACTL_RSSIPV6;
2919 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP ||
2920 rss_hf & ETH_RSS_IPV6_TCP_EX)
2921 mrqc |= TXGBE_RACTL_RSSIPV6TCP;
2922 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
2923 mrqc |= TXGBE_RACTL_RSSIPV4UDP;
2924 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP ||
2925 rss_hf & ETH_RSS_IPV6_UDP_EX)
2926 mrqc |= TXGBE_RACTL_RSSIPV6UDP;
2929 mrqc |= TXGBE_RACTL_RSSENA;
2931 mrqc &= ~TXGBE_RACTL_RSSENA;
2933 wr32(hw, TXGBE_RACTL, mrqc);
2940 txgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
2941 struct rte_eth_rss_conf *rss_conf)
2943 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2950 hash_key = rss_conf->rss_key;
2952 /* Return RSS hash key */
2953 for (i = 0; i < 10; i++) {
2954 rss_key = rd32at(hw, TXGBE_REG_RSSKEY, i);
2955 hash_key[(i * 4) + 0] = RS32(rss_key, 0, 0xFF);
2956 hash_key[(i * 4) + 1] = RS32(rss_key, 8, 0xFF);
2957 hash_key[(i * 4) + 2] = RS32(rss_key, 16, 0xFF);
2958 hash_key[(i * 4) + 3] = RS32(rss_key, 24, 0xFF);
2963 if (hw->mac.type == txgbe_mac_raptor_vf) {
2964 mrqc = rd32(hw, TXGBE_VFPLCFG);
2965 if (mrqc & TXGBE_VFPLCFG_RSSIPV4)
2966 rss_hf |= ETH_RSS_IPV4;
2967 if (mrqc & TXGBE_VFPLCFG_RSSIPV4TCP)
2968 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
2969 if (mrqc & TXGBE_VFPLCFG_RSSIPV6)
2970 rss_hf |= ETH_RSS_IPV6 |
2972 if (mrqc & TXGBE_VFPLCFG_RSSIPV6TCP)
2973 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP |
2974 ETH_RSS_IPV6_TCP_EX;
2975 if (mrqc & TXGBE_VFPLCFG_RSSIPV4UDP)
2976 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
2977 if (mrqc & TXGBE_VFPLCFG_RSSIPV6UDP)
2978 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP |
2979 ETH_RSS_IPV6_UDP_EX;
2980 if (!(mrqc & TXGBE_VFPLCFG_RSSENA))
2983 mrqc = rd32(hw, TXGBE_RACTL);
2984 if (mrqc & TXGBE_RACTL_RSSIPV4)
2985 rss_hf |= ETH_RSS_IPV4;
2986 if (mrqc & TXGBE_RACTL_RSSIPV4TCP)
2987 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
2988 if (mrqc & TXGBE_RACTL_RSSIPV6)
2989 rss_hf |= ETH_RSS_IPV6 |
2991 if (mrqc & TXGBE_RACTL_RSSIPV6TCP)
2992 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP |
2993 ETH_RSS_IPV6_TCP_EX;
2994 if (mrqc & TXGBE_RACTL_RSSIPV4UDP)
2995 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
2996 if (mrqc & TXGBE_RACTL_RSSIPV6UDP)
2997 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP |
2998 ETH_RSS_IPV6_UDP_EX;
2999 if (!(mrqc & TXGBE_RACTL_RSSENA))
3003 rss_hf &= TXGBE_RSS_OFFLOAD_ALL;
3005 rss_conf->rss_hf = rss_hf;
3010 txgbe_rss_configure(struct rte_eth_dev *dev)
3012 struct rte_eth_rss_conf rss_conf;
3013 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
3014 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3019 PMD_INIT_FUNC_TRACE();
3022 * Fill in redirection table
3023 * The byte-swap is needed because NIC registers are in
3024 * little-endian order.
3026 if (adapter->rss_reta_updated == 0) {
3028 for (i = 0, j = 0; i < ETH_RSS_RETA_SIZE_128; i++, j++) {
3029 if (j == dev->data->nb_rx_queues)
3031 reta = (reta >> 8) | LS32(j, 24, 0xFF);
3033 wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
3037 * Configure the RSS key and the RSS protocols used to compute
3038 * the RSS hash of input packets.
3040 rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
3041 if (rss_conf.rss_key == NULL)
3042 rss_conf.rss_key = rss_intel_key; /* Default hash key */
3043 txgbe_dev_rss_hash_update(dev, &rss_conf);
3046 #define NUM_VFTA_REGISTERS 128
3047 #define NIC_RX_BUFFER_SIZE 0x200
3050 txgbe_vmdq_dcb_configure(struct rte_eth_dev *dev)
3052 struct rte_eth_vmdq_dcb_conf *cfg;
3053 struct txgbe_hw *hw;
3054 enum rte_eth_nb_pools num_pools;
3055 uint32_t mrqc, vt_ctl, queue_mapping, vlanctrl;
3057 uint8_t nb_tcs; /* number of traffic classes */
3060 PMD_INIT_FUNC_TRACE();
3061 hw = TXGBE_DEV_HW(dev);
3062 cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3063 num_pools = cfg->nb_queue_pools;
3064 /* Check we have a valid number of pools */
3065 if (num_pools != ETH_16_POOLS && num_pools != ETH_32_POOLS) {
3066 txgbe_rss_disable(dev);
3069 /* 16 pools -> 8 traffic classes, 32 pools -> 4 traffic classes */
3070 nb_tcs = (uint8_t)(ETH_VMDQ_DCB_NUM_QUEUES / (int)num_pools);
3073 * split rx buffer up into sections, each for 1 traffic class
3075 pbsize = (uint16_t)(NIC_RX_BUFFER_SIZE / nb_tcs);
3076 for (i = 0; i < nb_tcs; i++) {
3077 uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
3079 rxpbsize &= (~(0x3FF << 10));
3080 /* clear 10 bits. */
3081 rxpbsize |= (pbsize << 10); /* set value */
3082 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3084 /* zero alloc all unused TCs */
3085 for (i = nb_tcs; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3086 uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
3088 rxpbsize &= (~(0x3FF << 10));
3089 /* clear 10 bits. */
3090 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3093 if (num_pools == ETH_16_POOLS) {
3094 mrqc = TXGBE_PORTCTL_NUMTC_8;
3095 mrqc |= TXGBE_PORTCTL_NUMVT_16;
3097 mrqc = TXGBE_PORTCTL_NUMTC_4;
3098 mrqc |= TXGBE_PORTCTL_NUMVT_32;
3100 wr32m(hw, TXGBE_PORTCTL,
3101 TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK, mrqc);
3103 vt_ctl = TXGBE_POOLCTL_RPLEN;
3104 if (cfg->enable_default_pool)
3105 vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
3107 vt_ctl |= TXGBE_POOLCTL_DEFDSA;
3109 wr32(hw, TXGBE_POOLCTL, vt_ctl);
3112 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
3114 * mapping is done with 3 bits per priority,
3115 * so shift by i*3 each time
3117 queue_mapping |= ((cfg->dcb_tc[i] & 0x07) << (i * 3));
3119 wr32(hw, TXGBE_RPUP2TC, queue_mapping);
3121 wr32(hw, TXGBE_ARBRXCTL, TXGBE_ARBRXCTL_RRM);
3123 /* enable vlan filtering and allow all vlan tags through */
3124 vlanctrl = rd32(hw, TXGBE_VLANCTL);
3125 vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3126 wr32(hw, TXGBE_VLANCTL, vlanctrl);
3128 /* enable all vlan filters */
3129 for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3130 wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
3132 wr32(hw, TXGBE_POOLRXENA(0),
3133 num_pools == ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3135 wr32(hw, TXGBE_ETHADDRIDX, 0);
3136 wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
3137 wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
3139 /* set up filters for vlan tags as configured */
3140 for (i = 0; i < cfg->nb_pool_maps; i++) {
3141 /* set vlan id in VF register and set the valid bit */
3142 wr32(hw, TXGBE_PSRVLANIDX, i);
3143 wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
3144 (cfg->pool_map[i].vlan_id & 0xFFF)));
3146 wr32(hw, TXGBE_PSRVLANPLM(0), cfg->pool_map[i].pools);
3151 * txgbe_dcb_config_tx_hw_config - Configure general DCB TX parameters
3152 * @dev: pointer to eth_dev structure
3153 * @dcb_config: pointer to txgbe_dcb_config structure
3156 txgbe_dcb_tx_hw_config(struct rte_eth_dev *dev,
3157 struct txgbe_dcb_config *dcb_config)
3160 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3162 PMD_INIT_FUNC_TRACE();
3164 /* Disable the Tx desc arbiter */
3165 reg = rd32(hw, TXGBE_ARBTXCTL);
3166 reg |= TXGBE_ARBTXCTL_DIA;
3167 wr32(hw, TXGBE_ARBTXCTL, reg);
3169 /* Enable DCB for Tx with 8 TCs */
3170 reg = rd32(hw, TXGBE_PORTCTL);
3171 reg &= TXGBE_PORTCTL_NUMTC_MASK;
3172 reg |= TXGBE_PORTCTL_DCB;
3173 if (dcb_config->num_tcs.pg_tcs == 8)
3174 reg |= TXGBE_PORTCTL_NUMTC_8;
3176 reg |= TXGBE_PORTCTL_NUMTC_4;
3178 wr32(hw, TXGBE_PORTCTL, reg);
3180 /* Enable the Tx desc arbiter */
3181 reg = rd32(hw, TXGBE_ARBTXCTL);
3182 reg &= ~TXGBE_ARBTXCTL_DIA;
3183 wr32(hw, TXGBE_ARBTXCTL, reg);
3187 * txgbe_vmdq_dcb_hw_tx_config - Configure general VMDQ+DCB TX parameters
3188 * @dev: pointer to rte_eth_dev structure
3189 * @dcb_config: pointer to txgbe_dcb_config structure
3192 txgbe_vmdq_dcb_hw_tx_config(struct rte_eth_dev *dev,
3193 struct txgbe_dcb_config *dcb_config)
3195 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3196 &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3197 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3199 PMD_INIT_FUNC_TRACE();
3200 /*PF VF Transmit Enable*/
3201 wr32(hw, TXGBE_POOLTXENA(0),
3202 vmdq_tx_conf->nb_queue_pools ==
3203 ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3205 /*Configure general DCB TX parameters*/
3206 txgbe_dcb_tx_hw_config(dev, dcb_config);
3210 txgbe_vmdq_dcb_rx_config(struct rte_eth_dev *dev,
3211 struct txgbe_dcb_config *dcb_config)
3213 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
3214 &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3215 struct txgbe_dcb_tc_config *tc;
3218 /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
3219 if (vmdq_rx_conf->nb_queue_pools == ETH_16_POOLS) {
3220 dcb_config->num_tcs.pg_tcs = ETH_8_TCS;
3221 dcb_config->num_tcs.pfc_tcs = ETH_8_TCS;
3223 dcb_config->num_tcs.pg_tcs = ETH_4_TCS;
3224 dcb_config->num_tcs.pfc_tcs = ETH_4_TCS;
3227 /* Initialize User Priority to Traffic Class mapping */
3228 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3229 tc = &dcb_config->tc_config[j];
3230 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3233 /* User Priority to Traffic Class mapping */
3234 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3235 j = vmdq_rx_conf->dcb_tc[i];
3236 tc = &dcb_config->tc_config[j];
3237 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3243 txgbe_dcb_vt_tx_config(struct rte_eth_dev *dev,
3244 struct txgbe_dcb_config *dcb_config)
3246 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3247 &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3248 struct txgbe_dcb_tc_config *tc;
3251 /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
3252 if (vmdq_tx_conf->nb_queue_pools == ETH_16_POOLS) {
3253 dcb_config->num_tcs.pg_tcs = ETH_8_TCS;
3254 dcb_config->num_tcs.pfc_tcs = ETH_8_TCS;
3256 dcb_config->num_tcs.pg_tcs = ETH_4_TCS;
3257 dcb_config->num_tcs.pfc_tcs = ETH_4_TCS;
3260 /* Initialize User Priority to Traffic Class mapping */
3261 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3262 tc = &dcb_config->tc_config[j];
3263 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3266 /* User Priority to Traffic Class mapping */
3267 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3268 j = vmdq_tx_conf->dcb_tc[i];
3269 tc = &dcb_config->tc_config[j];
3270 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3276 txgbe_dcb_rx_config(struct rte_eth_dev *dev,
3277 struct txgbe_dcb_config *dcb_config)
3279 struct rte_eth_dcb_rx_conf *rx_conf =
3280 &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
3281 struct txgbe_dcb_tc_config *tc;
3284 dcb_config->num_tcs.pg_tcs = (uint8_t)rx_conf->nb_tcs;
3285 dcb_config->num_tcs.pfc_tcs = (uint8_t)rx_conf->nb_tcs;
3287 /* Initialize User Priority to Traffic Class mapping */
3288 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3289 tc = &dcb_config->tc_config[j];
3290 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3293 /* User Priority to Traffic Class mapping */
3294 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3295 j = rx_conf->dcb_tc[i];
3296 tc = &dcb_config->tc_config[j];
3297 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3303 txgbe_dcb_tx_config(struct rte_eth_dev *dev,
3304 struct txgbe_dcb_config *dcb_config)
3306 struct rte_eth_dcb_tx_conf *tx_conf =
3307 &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
3308 struct txgbe_dcb_tc_config *tc;
3311 dcb_config->num_tcs.pg_tcs = (uint8_t)tx_conf->nb_tcs;
3312 dcb_config->num_tcs.pfc_tcs = (uint8_t)tx_conf->nb_tcs;
3314 /* Initialize User Priority to Traffic Class mapping */
3315 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3316 tc = &dcb_config->tc_config[j];
3317 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3320 /* User Priority to Traffic Class mapping */
3321 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3322 j = tx_conf->dcb_tc[i];
3323 tc = &dcb_config->tc_config[j];
3324 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3330 * txgbe_dcb_rx_hw_config - Configure general DCB RX HW parameters
3331 * @dev: pointer to eth_dev structure
3332 * @dcb_config: pointer to txgbe_dcb_config structure
3335 txgbe_dcb_rx_hw_config(struct rte_eth_dev *dev,
3336 struct txgbe_dcb_config *dcb_config)
3342 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3344 PMD_INIT_FUNC_TRACE();
3346 * Disable the arbiter before changing parameters
3347 * (always enable recycle mode; WSP)
3349 reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP | TXGBE_ARBRXCTL_DIA;
3350 wr32(hw, TXGBE_ARBRXCTL, reg);
3352 reg = rd32(hw, TXGBE_PORTCTL);
3353 reg &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
3354 if (dcb_config->num_tcs.pg_tcs == 4) {
3355 reg |= TXGBE_PORTCTL_NUMTC_4;
3356 if (dcb_config->vt_mode)
3357 reg |= TXGBE_PORTCTL_NUMVT_32;
3359 wr32(hw, TXGBE_POOLCTL, 0);
3362 if (dcb_config->num_tcs.pg_tcs == 8) {
3363 reg |= TXGBE_PORTCTL_NUMTC_8;
3364 if (dcb_config->vt_mode)
3365 reg |= TXGBE_PORTCTL_NUMVT_16;
3367 wr32(hw, TXGBE_POOLCTL, 0);
3370 wr32(hw, TXGBE_PORTCTL, reg);
3372 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
3373 /* Disable drop for all queues in VMDQ mode*/
3374 for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
3375 u32 val = 1 << (q % 32);
3376 wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3379 /* Enable drop for all queues in SRIOV mode */
3380 for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
3381 u32 val = 1 << (q % 32);
3382 wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3386 /* VLNCTL: enable vlan filtering and allow all vlan tags through */
3387 vlanctrl = rd32(hw, TXGBE_VLANCTL);
3388 vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3389 wr32(hw, TXGBE_VLANCTL, vlanctrl);
3391 /* VLANTBL - enable all vlan filters */
3392 for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3393 wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
3396 * Configure Rx packet plane (recycle mode; WSP) and
3399 reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP;
3400 wr32(hw, TXGBE_ARBRXCTL, reg);
3404 txgbe_dcb_hw_arbite_rx_config(struct txgbe_hw *hw, uint16_t *refill,
3405 uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
3407 txgbe_dcb_config_rx_arbiter_raptor(hw, refill, max, bwg_id,
3412 txgbe_dcb_hw_arbite_tx_config(struct txgbe_hw *hw, uint16_t *refill,
3413 uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
3415 switch (hw->mac.type) {
3416 case txgbe_mac_raptor:
3417 txgbe_dcb_config_tx_desc_arbiter_raptor(hw, refill,
3419 txgbe_dcb_config_tx_data_arbiter_raptor(hw, refill,
3420 max, bwg_id, tsa, map);
3427 #define DCB_RX_CONFIG 1
3428 #define DCB_TX_CONFIG 1
3429 #define DCB_TX_PB 1024
3431 * txgbe_dcb_hw_configure - Enable DCB and configure
3432 * general DCB in VT mode and non-VT mode parameters
3433 * @dev: pointer to rte_eth_dev structure
3434 * @dcb_config: pointer to txgbe_dcb_config structure
3437 txgbe_dcb_hw_configure(struct rte_eth_dev *dev,
3438 struct txgbe_dcb_config *dcb_config)
3441 uint8_t i, pfc_en, nb_tcs;
3442 uint16_t pbsize, rx_buffer_size;
3443 uint8_t config_dcb_rx = 0;
3444 uint8_t config_dcb_tx = 0;
3445 uint8_t tsa[TXGBE_DCB_TC_MAX] = {0};
3446 uint8_t bwgid[TXGBE_DCB_TC_MAX] = {0};
3447 uint16_t refill[TXGBE_DCB_TC_MAX] = {0};
3448 uint16_t max[TXGBE_DCB_TC_MAX] = {0};
3449 uint8_t map[TXGBE_DCB_TC_MAX] = {0};
3450 struct txgbe_dcb_tc_config *tc;
3451 uint32_t max_frame = dev->data->mtu +
3452 RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
3453 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3454 struct txgbe_bw_conf *bw_conf = TXGBE_DEV_BW_CONF(dev);
3456 switch (dev->data->dev_conf.rxmode.mq_mode) {
3457 case ETH_MQ_RX_VMDQ_DCB:
3458 dcb_config->vt_mode = true;
3459 config_dcb_rx = DCB_RX_CONFIG;
3461 * get dcb and VT rx configuration parameters
3464 txgbe_vmdq_dcb_rx_config(dev, dcb_config);
3465 /*Configure general VMDQ and DCB RX parameters*/
3466 txgbe_vmdq_dcb_configure(dev);
3469 case ETH_MQ_RX_DCB_RSS:
3470 dcb_config->vt_mode = false;
3471 config_dcb_rx = DCB_RX_CONFIG;
3472 /* Get dcb TX configuration parameters from rte_eth_conf */
3473 txgbe_dcb_rx_config(dev, dcb_config);
3474 /*Configure general DCB RX parameters*/
3475 txgbe_dcb_rx_hw_config(dev, dcb_config);
3478 PMD_INIT_LOG(ERR, "Incorrect DCB RX mode configuration");
3481 switch (dev->data->dev_conf.txmode.mq_mode) {
3482 case ETH_MQ_TX_VMDQ_DCB:
3483 dcb_config->vt_mode = true;
3484 config_dcb_tx = DCB_TX_CONFIG;
3485 /* get DCB and VT TX configuration parameters
3488 txgbe_dcb_vt_tx_config(dev, dcb_config);
3489 /* Configure general VMDQ and DCB TX parameters */
3490 txgbe_vmdq_dcb_hw_tx_config(dev, dcb_config);
3494 dcb_config->vt_mode = false;
3495 config_dcb_tx = DCB_TX_CONFIG;
3496 /* get DCB TX configuration parameters from rte_eth_conf */
3497 txgbe_dcb_tx_config(dev, dcb_config);
3498 /* Configure general DCB TX parameters */
3499 txgbe_dcb_tx_hw_config(dev, dcb_config);
3502 PMD_INIT_LOG(ERR, "Incorrect DCB TX mode configuration");
3506 nb_tcs = dcb_config->num_tcs.pfc_tcs;
3508 txgbe_dcb_unpack_map_cee(dcb_config, TXGBE_DCB_RX_CONFIG, map);
3509 if (nb_tcs == ETH_4_TCS) {
3510 /* Avoid un-configured priority mapping to TC0 */
3512 uint8_t mask = 0xFF;
3514 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES - 4; i++)
3515 mask = (uint8_t)(mask & (~(1 << map[i])));
3516 for (i = 0; mask && (i < TXGBE_DCB_TC_MAX); i++) {
3517 if ((mask & 0x1) && j < ETH_DCB_NUM_USER_PRIORITIES)
3521 /* Re-configure 4 TCs BW */
3522 for (i = 0; i < nb_tcs; i++) {
3523 tc = &dcb_config->tc_config[i];
3524 if (bw_conf->tc_num != nb_tcs)
3525 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
3526 (uint8_t)(100 / nb_tcs);
3527 tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
3528 (uint8_t)(100 / nb_tcs);
3530 for (; i < TXGBE_DCB_TC_MAX; i++) {
3531 tc = &dcb_config->tc_config[i];
3532 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent = 0;
3533 tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent = 0;
3536 /* Re-configure 8 TCs BW */
3537 for (i = 0; i < nb_tcs; i++) {
3538 tc = &dcb_config->tc_config[i];
3539 if (bw_conf->tc_num != nb_tcs)
3540 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
3541 (uint8_t)(100 / nb_tcs + (i & 1));
3542 tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
3543 (uint8_t)(100 / nb_tcs + (i & 1));
3547 rx_buffer_size = NIC_RX_BUFFER_SIZE;
3549 if (config_dcb_rx) {
3550 /* Set RX buffer size */
3551 pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
3552 uint32_t rxpbsize = pbsize << 10;
3554 for (i = 0; i < nb_tcs; i++)
3555 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3557 /* zero alloc all unused TCs */
3558 for (; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
3559 wr32(hw, TXGBE_PBRXSIZE(i), 0);
3561 if (config_dcb_tx) {
3562 /* Only support an equally distributed
3563 * Tx packet buffer strategy.
3565 uint32_t txpktsize = TXGBE_PBTXSIZE_MAX / nb_tcs;
3566 uint32_t txpbthresh = (txpktsize / DCB_TX_PB) -
3567 TXGBE_TXPKT_SIZE_MAX;
3569 for (i = 0; i < nb_tcs; i++) {
3570 wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
3571 wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
3573 /* Clear unused TCs, if any, to zero buffer size*/
3574 for (; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3575 wr32(hw, TXGBE_PBTXSIZE(i), 0);
3576 wr32(hw, TXGBE_PBTXDMATH(i), 0);
3580 /*Calculates traffic class credits*/
3581 txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
3582 TXGBE_DCB_TX_CONFIG);
3583 txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
3584 TXGBE_DCB_RX_CONFIG);
3586 if (config_dcb_rx) {
3587 /* Unpack CEE standard containers */
3588 txgbe_dcb_unpack_refill_cee(dcb_config,
3589 TXGBE_DCB_RX_CONFIG, refill);
3590 txgbe_dcb_unpack_max_cee(dcb_config, max);
3591 txgbe_dcb_unpack_bwgid_cee(dcb_config,
3592 TXGBE_DCB_RX_CONFIG, bwgid);
3593 txgbe_dcb_unpack_tsa_cee(dcb_config,
3594 TXGBE_DCB_RX_CONFIG, tsa);
3595 /* Configure PG(ETS) RX */
3596 txgbe_dcb_hw_arbite_rx_config(hw, refill, max, bwgid, tsa, map);
3599 if (config_dcb_tx) {
3600 /* Unpack CEE standard containers */
3601 txgbe_dcb_unpack_refill_cee(dcb_config,
3602 TXGBE_DCB_TX_CONFIG, refill);
3603 txgbe_dcb_unpack_max_cee(dcb_config, max);
3604 txgbe_dcb_unpack_bwgid_cee(dcb_config,
3605 TXGBE_DCB_TX_CONFIG, bwgid);
3606 txgbe_dcb_unpack_tsa_cee(dcb_config,
3607 TXGBE_DCB_TX_CONFIG, tsa);
3608 /* Configure PG(ETS) TX */
3609 txgbe_dcb_hw_arbite_tx_config(hw, refill, max, bwgid, tsa, map);
3612 /* Configure queue statistics registers */
3613 txgbe_dcb_config_tc_stats_raptor(hw, dcb_config);
3615 /* Check if the PFC is supported */
3616 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
3617 pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
3618 for (i = 0; i < nb_tcs; i++) {
3619 /* If the TC count is 8,
3620 * and the default high_water is 48,
3621 * the low_water is 16 as default.
3623 hw->fc.high_water[i] = (pbsize * 3) / 4;
3624 hw->fc.low_water[i] = pbsize / 4;
3625 /* Enable pfc for this TC */
3626 tc = &dcb_config->tc_config[i];
3627 tc->pfc = txgbe_dcb_pfc_enabled;
3629 txgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
3630 if (dcb_config->num_tcs.pfc_tcs == ETH_4_TCS)
3632 ret = txgbe_dcb_config_pfc(hw, pfc_en, map);
3638 void txgbe_configure_pb(struct rte_eth_dev *dev)
3640 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3641 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3644 int tc = dev_conf->rx_adv_conf.dcb_rx_conf.nb_tcs;
3646 /* Reserve 256KB(/512KB) rx buffer for fdir */
3649 hw->mac.setup_pba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
3652 void txgbe_configure_port(struct rte_eth_dev *dev)
3654 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3656 uint16_t tpids[8] = {RTE_ETHER_TYPE_VLAN, RTE_ETHER_TYPE_QINQ,
3661 PMD_INIT_FUNC_TRACE();
3663 /* default outer vlan tpid */
3664 wr32(hw, TXGBE_EXTAG,
3665 TXGBE_EXTAG_ETAG(RTE_ETHER_TYPE_ETAG) |
3666 TXGBE_EXTAG_VLAN(RTE_ETHER_TYPE_QINQ));
3668 /* default inner vlan tpid */
3669 wr32m(hw, TXGBE_VLANCTL,
3670 TXGBE_VLANCTL_TPID_MASK,
3671 TXGBE_VLANCTL_TPID(RTE_ETHER_TYPE_VLAN));
3672 wr32m(hw, TXGBE_DMATXCTRL,
3673 TXGBE_DMATXCTRL_TPID_MASK,
3674 TXGBE_DMATXCTRL_TPID(RTE_ETHER_TYPE_VLAN));
3676 /* default vlan tpid filters */
3677 for (i = 0; i < 8; i++) {
3678 wr32m(hw, TXGBE_TAGTPID(i / 2),
3679 (i % 2 ? TXGBE_TAGTPID_MSB_MASK
3680 : TXGBE_TAGTPID_LSB_MASK),
3681 (i % 2 ? TXGBE_TAGTPID_MSB(tpids[i])
3682 : TXGBE_TAGTPID_LSB(tpids[i])));
3685 /* default vxlan port */
3686 wr32(hw, TXGBE_VXLANPORT, 4789);
3690 * txgbe_configure_dcb - Configure DCB Hardware
3691 * @dev: pointer to rte_eth_dev
3693 void txgbe_configure_dcb(struct rte_eth_dev *dev)
3695 struct txgbe_dcb_config *dcb_cfg = TXGBE_DEV_DCB_CONFIG(dev);
3696 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3698 PMD_INIT_FUNC_TRACE();
3700 /* check support mq_mode for DCB */
3701 if (dev_conf->rxmode.mq_mode != ETH_MQ_RX_VMDQ_DCB &&
3702 dev_conf->rxmode.mq_mode != ETH_MQ_RX_DCB &&
3703 dev_conf->rxmode.mq_mode != ETH_MQ_RX_DCB_RSS)
3706 if (dev->data->nb_rx_queues > ETH_DCB_NUM_QUEUES)
3709 /** Configure DCB hardware **/
3710 txgbe_dcb_hw_configure(dev, dcb_cfg);
3714 * VMDq only support for 10 GbE NIC.
3717 txgbe_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
3719 struct rte_eth_vmdq_rx_conf *cfg;
3720 struct txgbe_hw *hw;
3721 enum rte_eth_nb_pools num_pools;
3722 uint32_t mrqc, vt_ctl, vlanctrl;
3726 PMD_INIT_FUNC_TRACE();
3727 hw = TXGBE_DEV_HW(dev);
3728 cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
3729 num_pools = cfg->nb_queue_pools;
3731 txgbe_rss_disable(dev);
3734 mrqc = TXGBE_PORTCTL_NUMVT_64;
3735 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mrqc);
3737 /* turn on virtualisation and set the default pool */
3738 vt_ctl = TXGBE_POOLCTL_RPLEN;
3739 if (cfg->enable_default_pool)
3740 vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
3742 vt_ctl |= TXGBE_POOLCTL_DEFDSA;
3744 wr32(hw, TXGBE_POOLCTL, vt_ctl);
3746 for (i = 0; i < (int)num_pools; i++) {
3747 vmolr = txgbe_convert_vm_rx_mask_to_val(cfg->rx_mode, vmolr);
3748 wr32(hw, TXGBE_POOLETHCTL(i), vmolr);
3751 /* enable vlan filtering and allow all vlan tags through */
3752 vlanctrl = rd32(hw, TXGBE_VLANCTL);
3753 vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3754 wr32(hw, TXGBE_VLANCTL, vlanctrl);
3756 /* enable all vlan filters */
3757 for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3758 wr32(hw, TXGBE_VLANTBL(i), UINT32_MAX);
3760 /* pool enabling for receive - 64 */
3761 wr32(hw, TXGBE_POOLRXENA(0), UINT32_MAX);
3762 if (num_pools == ETH_64_POOLS)
3763 wr32(hw, TXGBE_POOLRXENA(1), UINT32_MAX);
3766 * allow pools to read specific mac addresses
3767 * In this case, all pools should be able to read from mac addr 0
3769 wr32(hw, TXGBE_ETHADDRIDX, 0);
3770 wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
3771 wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
3773 /* set up filters for vlan tags as configured */
3774 for (i = 0; i < cfg->nb_pool_maps; i++) {
3775 /* set vlan id in VF register and set the valid bit */
3776 wr32(hw, TXGBE_PSRVLANIDX, i);
3777 wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
3778 TXGBE_PSRVLAN_VID(cfg->pool_map[i].vlan_id)));
3780 * Put the allowed pools in VFB reg. As we only have 16 or 64
3781 * pools, we only need to use the first half of the register
3784 if (((cfg->pool_map[i].pools >> 32) & UINT32_MAX) == 0)
3785 wr32(hw, TXGBE_PSRVLANPLM(0),
3786 (cfg->pool_map[i].pools & UINT32_MAX));
3788 wr32(hw, TXGBE_PSRVLANPLM(1),
3789 ((cfg->pool_map[i].pools >> 32) & UINT32_MAX));
3792 /* Tx General Switch Control Enables VMDQ loopback */
3793 if (cfg->enable_loop_back) {
3794 wr32(hw, TXGBE_PSRCTL, TXGBE_PSRCTL_LBENA);
3795 for (i = 0; i < 64; i++)
3796 wr32m(hw, TXGBE_POOLETHCTL(i),
3797 TXGBE_POOLETHCTL_LLB, TXGBE_POOLETHCTL_LLB);
3804 * txgbe_vmdq_tx_hw_configure - Configure general VMDq TX parameters
3805 * @hw: pointer to hardware structure
3808 txgbe_vmdq_tx_hw_configure(struct txgbe_hw *hw)
3813 PMD_INIT_FUNC_TRACE();
3814 /*PF VF Transmit Enable*/
3815 wr32(hw, TXGBE_POOLTXENA(0), UINT32_MAX);
3816 wr32(hw, TXGBE_POOLTXENA(1), UINT32_MAX);
3818 /* Disable the Tx desc arbiter */
3819 reg = rd32(hw, TXGBE_ARBTXCTL);
3820 reg |= TXGBE_ARBTXCTL_DIA;
3821 wr32(hw, TXGBE_ARBTXCTL, reg);
3823 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK,
3824 TXGBE_PORTCTL_NUMVT_64);
3826 /* Disable drop for all queues */
3827 for (q = 0; q < 128; q++) {
3828 u32 val = 1 << (q % 32);
3829 wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3832 /* Enable the Tx desc arbiter */
3833 reg = rd32(hw, TXGBE_ARBTXCTL);
3834 reg &= ~TXGBE_ARBTXCTL_DIA;
3835 wr32(hw, TXGBE_ARBTXCTL, reg);
3840 static int __rte_cold
3841 txgbe_alloc_rx_queue_mbufs(struct txgbe_rx_queue *rxq)
3843 struct txgbe_rx_entry *rxe = rxq->sw_ring;
3847 /* Initialize software ring entries */
3848 for (i = 0; i < rxq->nb_rx_desc; i++) {
3849 volatile struct txgbe_rx_desc *rxd;
3850 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
3853 PMD_INIT_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
3854 (unsigned int)rxq->queue_id);
3858 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
3859 mbuf->port = rxq->port_id;
3862 rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
3863 rxd = &rxq->rx_ring[i];
3864 TXGBE_RXD_HDRADDR(rxd, 0);
3865 TXGBE_RXD_PKTADDR(rxd, dma_addr);
3873 txgbe_config_vf_rss(struct rte_eth_dev *dev)
3875 struct txgbe_hw *hw;
3878 txgbe_rss_configure(dev);
3880 hw = TXGBE_DEV_HW(dev);
3883 mrqc = rd32(hw, TXGBE_PORTCTL);
3884 mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
3885 switch (RTE_ETH_DEV_SRIOV(dev).active) {
3887 mrqc |= TXGBE_PORTCTL_NUMVT_64;
3891 mrqc |= TXGBE_PORTCTL_NUMVT_32;
3895 PMD_INIT_LOG(ERR, "Invalid pool number in IOV mode with VMDQ RSS");
3899 wr32(hw, TXGBE_PORTCTL, mrqc);
3905 txgbe_config_vf_default(struct rte_eth_dev *dev)
3907 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3910 mrqc = rd32(hw, TXGBE_PORTCTL);
3911 mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
3912 switch (RTE_ETH_DEV_SRIOV(dev).active) {
3914 mrqc |= TXGBE_PORTCTL_NUMVT_64;
3918 mrqc |= TXGBE_PORTCTL_NUMVT_32;
3922 mrqc |= TXGBE_PORTCTL_NUMVT_16;
3926 "invalid pool number in IOV mode");
3930 wr32(hw, TXGBE_PORTCTL, mrqc);
3936 txgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
3938 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
3940 * SRIOV inactive scheme
3941 * any DCB/RSS w/o VMDq multi-queue setting
3943 switch (dev->data->dev_conf.rxmode.mq_mode) {
3945 case ETH_MQ_RX_DCB_RSS:
3946 case ETH_MQ_RX_VMDQ_RSS:
3947 txgbe_rss_configure(dev);
3950 case ETH_MQ_RX_VMDQ_DCB:
3951 txgbe_vmdq_dcb_configure(dev);
3954 case ETH_MQ_RX_VMDQ_ONLY:
3955 txgbe_vmdq_rx_hw_configure(dev);
3958 case ETH_MQ_RX_NONE:
3960 /* if mq_mode is none, disable rss mode.*/
3961 txgbe_rss_disable(dev);
3965 /* SRIOV active scheme
3966 * Support RSS together with SRIOV.
3968 switch (dev->data->dev_conf.rxmode.mq_mode) {
3970 case ETH_MQ_RX_VMDQ_RSS:
3971 txgbe_config_vf_rss(dev);
3973 case ETH_MQ_RX_VMDQ_DCB:
3975 /* In SRIOV, the configuration is the same as VMDq case */
3976 txgbe_vmdq_dcb_configure(dev);
3978 /* DCB/RSS together with SRIOV is not supported */
3979 case ETH_MQ_RX_VMDQ_DCB_RSS:
3980 case ETH_MQ_RX_DCB_RSS:
3982 "Could not support DCB/RSS with VMDq & SRIOV");
3985 txgbe_config_vf_default(dev);
3994 txgbe_dev_mq_tx_configure(struct rte_eth_dev *dev)
3996 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4000 /* disable arbiter */
4001 rttdcs = rd32(hw, TXGBE_ARBTXCTL);
4002 rttdcs |= TXGBE_ARBTXCTL_DIA;
4003 wr32(hw, TXGBE_ARBTXCTL, rttdcs);
4005 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4007 * SRIOV inactive scheme
4008 * any DCB w/o VMDq multi-queue setting
4010 if (dev->data->dev_conf.txmode.mq_mode == ETH_MQ_TX_VMDQ_ONLY)
4011 txgbe_vmdq_tx_hw_configure(hw);
4013 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, 0);
4015 switch (RTE_ETH_DEV_SRIOV(dev).active) {
4017 * SRIOV active scheme
4018 * FIXME if support DCB together with VMDq & SRIOV
4021 mtqc = TXGBE_PORTCTL_NUMVT_64;
4024 mtqc = TXGBE_PORTCTL_NUMVT_32;
4027 mtqc = TXGBE_PORTCTL_NUMVT_16;
4031 PMD_INIT_LOG(ERR, "invalid pool number in IOV mode");
4033 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mtqc);
4036 /* re-enable arbiter */
4037 rttdcs &= ~TXGBE_ARBTXCTL_DIA;
4038 wr32(hw, TXGBE_ARBTXCTL, rttdcs);
4044 * txgbe_get_rscctl_maxdesc
4046 * @pool Memory pool of the Rx queue
4048 static inline uint32_t
4049 txgbe_get_rscctl_maxdesc(struct rte_mempool *pool)
4051 struct rte_pktmbuf_pool_private *mp_priv = rte_mempool_get_priv(pool);
4054 RTE_IPV4_MAX_PKT_LEN /
4055 (mp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
4058 return TXGBE_RXCFG_RSCMAX_16;
4059 else if (maxdesc >= 8)
4060 return TXGBE_RXCFG_RSCMAX_8;
4061 else if (maxdesc >= 4)
4062 return TXGBE_RXCFG_RSCMAX_4;
4064 return TXGBE_RXCFG_RSCMAX_1;
4068 * txgbe_set_rsc - configure RSC related port HW registers
4070 * Configures the port's RSC related registers.
4074 * Returns 0 in case of success or a non-zero error code
4077 txgbe_set_rsc(struct rte_eth_dev *dev)
4079 struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4080 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4081 struct rte_eth_dev_info dev_info = { 0 };
4082 bool rsc_capable = false;
4088 dev->dev_ops->dev_infos_get(dev, &dev_info);
4089 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO)
4092 if (!rsc_capable && (rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO)) {
4093 PMD_INIT_LOG(CRIT, "LRO is requested on HW that doesn't "
4098 /* RSC global configuration */
4100 if ((rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC) &&
4101 (rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO)) {
4102 PMD_INIT_LOG(CRIT, "LRO can't be enabled when HW CRC "
4107 rfctl = rd32(hw, TXGBE_PSRCTL);
4108 if (rsc_capable && (rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO))
4109 rfctl &= ~TXGBE_PSRCTL_RSCDIA;
4111 rfctl |= TXGBE_PSRCTL_RSCDIA;
4112 wr32(hw, TXGBE_PSRCTL, rfctl);
4114 /* If LRO hasn't been requested - we are done here. */
4115 if (!(rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO))
4118 /* Set PSRCTL.RSCACK bit */
4119 rdrxctl = rd32(hw, TXGBE_PSRCTL);
4120 rdrxctl |= TXGBE_PSRCTL_RSCACK;
4121 wr32(hw, TXGBE_PSRCTL, rdrxctl);
4123 /* Per-queue RSC configuration */
4124 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4125 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
4127 rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4129 rd32(hw, TXGBE_POOLRSS(rxq->reg_idx));
4131 rd32(hw, TXGBE_ITR(rxq->reg_idx));
4134 * txgbe PMD doesn't support header-split at the moment.
4136 srrctl &= ~TXGBE_RXCFG_HDRLEN_MASK;
4137 srrctl |= TXGBE_RXCFG_HDRLEN(128);
4140 * TODO: Consider setting the Receive Descriptor Minimum
4141 * Threshold Size for an RSC case. This is not an obviously
4142 * beneficiary option but the one worth considering...
4145 srrctl |= TXGBE_RXCFG_RSCENA;
4146 srrctl &= ~TXGBE_RXCFG_RSCMAX_MASK;
4147 srrctl |= txgbe_get_rscctl_maxdesc(rxq->mb_pool);
4148 psrtype |= TXGBE_POOLRSS_L4HDR;
4151 * RSC: Set ITR interval corresponding to 2K ints/s.
4153 * Full-sized RSC aggregations for a 10Gb/s link will
4154 * arrive at about 20K aggregation/s rate.
4156 * 2K inst/s rate will make only 10% of the
4157 * aggregations to be closed due to the interrupt timer
4158 * expiration for a streaming at wire-speed case.
4160 * For a sparse streaming case this setting will yield
4161 * at most 500us latency for a single RSC aggregation.
4163 eitr &= ~TXGBE_ITR_IVAL_MASK;
4164 eitr |= TXGBE_ITR_IVAL_10G(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT);
4165 eitr |= TXGBE_ITR_WRDSA;
4167 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
4168 wr32(hw, TXGBE_POOLRSS(rxq->reg_idx), psrtype);
4169 wr32(hw, TXGBE_ITR(rxq->reg_idx), eitr);
4172 * RSC requires the mapping of the queue to the
4175 txgbe_set_ivar_map(hw, 0, rxq->reg_idx, i);
4180 PMD_INIT_LOG(DEBUG, "enabling LRO mode");
4186 txgbe_set_rx_function(struct rte_eth_dev *dev)
4189 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
4192 * Initialize the appropriate LRO callback.
4194 * If all queues satisfy the bulk allocation preconditions
4195 * (adapter->rx_bulk_alloc_allowed is TRUE) then we may use
4196 * bulk allocation. Otherwise use a single allocation version.
4198 if (dev->data->lro) {
4199 if (adapter->rx_bulk_alloc_allowed) {
4200 PMD_INIT_LOG(DEBUG, "LRO is requested. Using a bulk "
4201 "allocation version");
4202 dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
4204 PMD_INIT_LOG(DEBUG, "LRO is requested. Using a single "
4205 "allocation version");
4206 dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
4208 } else if (dev->data->scattered_rx) {
4210 * Set the non-LRO scattered callback: there are bulk and
4211 * single allocation versions.
4213 if (adapter->rx_bulk_alloc_allowed) {
4214 PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
4215 "allocation callback (port=%d).",
4216 dev->data->port_id);
4217 dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
4219 PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
4220 "single allocation) "
4221 "Scattered Rx callback "
4223 dev->data->port_id);
4225 dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
4228 * Below we set "simple" callbacks according to port/queues parameters.
4229 * If parameters allow we are going to choose between the following
4232 * - Single buffer allocation (the simplest one)
4234 } else if (adapter->rx_bulk_alloc_allowed) {
4235 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
4236 "satisfied. Rx Burst Bulk Alloc function "
4237 "will be used on port=%d.",
4238 dev->data->port_id);
4240 dev->rx_pkt_burst = txgbe_recv_pkts_bulk_alloc;
4242 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
4243 "satisfied, or Scattered Rx is requested "
4245 dev->data->port_id);
4247 dev->rx_pkt_burst = txgbe_recv_pkts;
4250 #ifdef RTE_LIB_SECURITY
4251 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4252 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
4254 rxq->using_ipsec = !!(dev->data->dev_conf.rxmode.offloads &
4255 DEV_RX_OFFLOAD_SECURITY);
4261 * Initializes Receive Unit.
4264 txgbe_dev_rx_init(struct rte_eth_dev *dev)
4266 struct txgbe_hw *hw;
4267 struct txgbe_rx_queue *rxq;
4276 struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4279 PMD_INIT_FUNC_TRACE();
4280 hw = TXGBE_DEV_HW(dev);
4283 * Make sure receives are disabled while setting
4284 * up the RX context (registers, descriptor rings, etc.).
4286 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
4287 wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
4289 /* Enable receipt of broadcasted frames */
4290 fctrl = rd32(hw, TXGBE_PSRCTL);
4291 fctrl |= TXGBE_PSRCTL_BCA;
4292 wr32(hw, TXGBE_PSRCTL, fctrl);
4295 * Configure CRC stripping, if any.
4297 hlreg0 = rd32(hw, TXGBE_SECRXCTL);
4298 if (rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC)
4299 hlreg0 &= ~TXGBE_SECRXCTL_CRCSTRIP;
4301 hlreg0 |= TXGBE_SECRXCTL_CRCSTRIP;
4302 wr32(hw, TXGBE_SECRXCTL, hlreg0);
4305 * Configure jumbo frame support, if any.
4307 if (rx_conf->offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
4308 wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
4309 TXGBE_FRMSZ_MAX(rx_conf->max_rx_pkt_len));
4311 wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
4312 TXGBE_FRMSZ_MAX(TXGBE_FRAME_SIZE_DFT));
4316 * If loopback mode is configured, set LPBK bit.
4318 hlreg0 = rd32(hw, TXGBE_PSRCTL);
4319 if (hw->mac.type == txgbe_mac_raptor &&
4320 dev->data->dev_conf.lpbk_mode)
4321 hlreg0 |= TXGBE_PSRCTL_LBENA;
4323 hlreg0 &= ~TXGBE_PSRCTL_LBENA;
4325 wr32(hw, TXGBE_PSRCTL, hlreg0);
4328 * Assume no header split and no VLAN strip support
4329 * on any Rx queue first .
4331 rx_conf->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4333 /* Setup RX queues */
4334 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4335 rxq = dev->data->rx_queues[i];
4338 * Reset crc_len in case it was changed after queue setup by a
4339 * call to configure.
4341 if (rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC)
4342 rxq->crc_len = RTE_ETHER_CRC_LEN;
4346 /* Setup the Base and Length of the Rx Descriptor Rings */
4347 bus_addr = rxq->rx_ring_phys_addr;
4348 wr32(hw, TXGBE_RXBAL(rxq->reg_idx),
4349 (uint32_t)(bus_addr & BIT_MASK32));
4350 wr32(hw, TXGBE_RXBAH(rxq->reg_idx),
4351 (uint32_t)(bus_addr >> 32));
4352 wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
4353 wr32(hw, TXGBE_RXWP(rxq->reg_idx), 0);
4355 srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
4357 /* Set if packets are dropped when no descriptors available */
4359 srrctl |= TXGBE_RXCFG_DROP;
4362 * Configure the RX buffer size in the PKTLEN field of
4363 * the RXCFG register of the queue.
4364 * The value is in 1 KB resolution. Valid values can be from
4367 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
4368 RTE_PKTMBUF_HEADROOM);
4369 buf_size = ROUND_UP(buf_size, 0x1 << 10);
4370 srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
4372 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
4374 /* It adds dual VLAN length for supporting dual VLAN */
4375 if (dev->data->dev_conf.rxmode.max_rx_pkt_len +
4376 2 * TXGBE_VLAN_TAG_SIZE > buf_size)
4377 dev->data->scattered_rx = 1;
4378 if (rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
4379 rx_conf->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4382 if (rx_conf->offloads & DEV_RX_OFFLOAD_SCATTER)
4383 dev->data->scattered_rx = 1;
4386 * Device configured with multiple RX queues.
4388 txgbe_dev_mq_rx_configure(dev);
4391 * Setup the Checksum Register.
4392 * Disable Full-Packet Checksum which is mutually exclusive with RSS.
4393 * Enable IP/L4 checksum computation by hardware if requested to do so.
4395 rxcsum = rd32(hw, TXGBE_PSRCTL);
4396 rxcsum |= TXGBE_PSRCTL_PCSD;
4397 if (rx_conf->offloads & DEV_RX_OFFLOAD_CHECKSUM)
4398 rxcsum |= TXGBE_PSRCTL_L4CSUM;
4400 rxcsum &= ~TXGBE_PSRCTL_L4CSUM;
4402 wr32(hw, TXGBE_PSRCTL, rxcsum);
4404 if (hw->mac.type == txgbe_mac_raptor) {
4405 rdrxctl = rd32(hw, TXGBE_SECRXCTL);
4406 if (rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC)
4407 rdrxctl &= ~TXGBE_SECRXCTL_CRCSTRIP;
4409 rdrxctl |= TXGBE_SECRXCTL_CRCSTRIP;
4410 wr32(hw, TXGBE_SECRXCTL, rdrxctl);
4413 rc = txgbe_set_rsc(dev);
4417 txgbe_set_rx_function(dev);
4423 * Initializes Transmit Unit.
4426 txgbe_dev_tx_init(struct rte_eth_dev *dev)
4428 struct txgbe_hw *hw;
4429 struct txgbe_tx_queue *txq;
4433 PMD_INIT_FUNC_TRACE();
4434 hw = TXGBE_DEV_HW(dev);
4436 /* Setup the Base and Length of the Tx Descriptor Rings */
4437 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4438 txq = dev->data->tx_queues[i];
4440 bus_addr = txq->tx_ring_phys_addr;
4441 wr32(hw, TXGBE_TXBAL(txq->reg_idx),
4442 (uint32_t)(bus_addr & BIT_MASK32));
4443 wr32(hw, TXGBE_TXBAH(txq->reg_idx),
4444 (uint32_t)(bus_addr >> 32));
4445 wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_BUFLEN_MASK,
4446 TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
4447 /* Setup the HW Tx Head and TX Tail descriptor pointers */
4448 wr32(hw, TXGBE_TXRP(txq->reg_idx), 0);
4449 wr32(hw, TXGBE_TXWP(txq->reg_idx), 0);
4452 /* Device configured with multiple TX queues. */
4453 txgbe_dev_mq_tx_configure(dev);
4457 * Set up link loopback mode Tx->Rx.
4459 static inline void __rte_cold
4460 txgbe_setup_loopback_link_raptor(struct txgbe_hw *hw)
4462 PMD_INIT_FUNC_TRACE();
4464 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_LB, TXGBE_MACRXCFG_LB);
4470 * Start Transmit and Receive Units.
4473 txgbe_dev_rxtx_start(struct rte_eth_dev *dev)
4475 struct txgbe_hw *hw;
4476 struct txgbe_tx_queue *txq;
4477 struct txgbe_rx_queue *rxq;
4483 PMD_INIT_FUNC_TRACE();
4484 hw = TXGBE_DEV_HW(dev);
4486 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4487 txq = dev->data->tx_queues[i];
4488 /* Setup Transmit Threshold Registers */
4489 wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
4490 TXGBE_TXCFG_HTHRESH_MASK |
4491 TXGBE_TXCFG_WTHRESH_MASK,
4492 TXGBE_TXCFG_HTHRESH(txq->hthresh) |
4493 TXGBE_TXCFG_WTHRESH(txq->wthresh));
4496 dmatxctl = rd32(hw, TXGBE_DMATXCTRL);
4497 dmatxctl |= TXGBE_DMATXCTRL_ENA;
4498 wr32(hw, TXGBE_DMATXCTRL, dmatxctl);
4500 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4501 txq = dev->data->tx_queues[i];
4502 if (!txq->tx_deferred_start) {
4503 ret = txgbe_dev_tx_queue_start(dev, i);
4509 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4510 rxq = dev->data->rx_queues[i];
4511 if (!rxq->rx_deferred_start) {
4512 ret = txgbe_dev_rx_queue_start(dev, i);
4518 /* Enable Receive engine */
4519 rxctrl = rd32(hw, TXGBE_PBRXCTL);
4520 rxctrl |= TXGBE_PBRXCTL_ENA;
4521 hw->mac.enable_rx_dma(hw, rxctrl);
4523 /* If loopback mode is enabled, set up the link accordingly */
4524 if (hw->mac.type == txgbe_mac_raptor &&
4525 dev->data->dev_conf.lpbk_mode)
4526 txgbe_setup_loopback_link_raptor(hw);
4528 #ifdef RTE_LIB_SECURITY
4529 if ((dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SECURITY) ||
4530 (dev->data->dev_conf.txmode.offloads & DEV_TX_OFFLOAD_SECURITY)) {
4531 ret = txgbe_crypto_enable_ipsec(dev);
4534 "txgbe_crypto_enable_ipsec fails with %d.",
4545 txgbe_dev_save_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
4547 u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
4548 *(reg++) = rd32(hw, TXGBE_RXBAL(rx_queue_id));
4549 *(reg++) = rd32(hw, TXGBE_RXBAH(rx_queue_id));
4550 *(reg++) = rd32(hw, TXGBE_RXCFG(rx_queue_id));
4554 txgbe_dev_store_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
4556 u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
4557 wr32(hw, TXGBE_RXBAL(rx_queue_id), *(reg++));
4558 wr32(hw, TXGBE_RXBAH(rx_queue_id), *(reg++));
4559 wr32(hw, TXGBE_RXCFG(rx_queue_id), *(reg++) & ~TXGBE_RXCFG_ENA);
4563 txgbe_dev_save_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
4565 u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
4566 *(reg++) = rd32(hw, TXGBE_TXBAL(tx_queue_id));
4567 *(reg++) = rd32(hw, TXGBE_TXBAH(tx_queue_id));
4568 *(reg++) = rd32(hw, TXGBE_TXCFG(tx_queue_id));
4572 txgbe_dev_store_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
4574 u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
4575 wr32(hw, TXGBE_TXBAL(tx_queue_id), *(reg++));
4576 wr32(hw, TXGBE_TXBAH(tx_queue_id), *(reg++));
4577 wr32(hw, TXGBE_TXCFG(tx_queue_id), *(reg++) & ~TXGBE_TXCFG_ENA);
4581 * Start Receive Units for specified queue.
4584 txgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4586 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4587 struct txgbe_rx_queue *rxq;
4591 PMD_INIT_FUNC_TRACE();
4593 rxq = dev->data->rx_queues[rx_queue_id];
4595 /* Allocate buffers for descriptor rings */
4596 if (txgbe_alloc_rx_queue_mbufs(rxq) != 0) {
4597 PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
4601 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4602 rxdctl |= TXGBE_RXCFG_ENA;
4603 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), rxdctl);
4605 /* Wait until RX Enable ready */
4606 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4609 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4610 } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
4612 PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
4614 wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
4615 wr32(hw, TXGBE_RXWP(rxq->reg_idx), rxq->nb_rx_desc - 1);
4616 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4622 * Stop Receive Units for specified queue.
4625 txgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4627 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4628 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
4629 struct txgbe_rx_queue *rxq;
4633 PMD_INIT_FUNC_TRACE();
4635 rxq = dev->data->rx_queues[rx_queue_id];
4637 txgbe_dev_save_rx_queue(hw, rxq->reg_idx);
4638 wr32m(hw, TXGBE_RXCFG(rxq->reg_idx), TXGBE_RXCFG_ENA, 0);
4640 /* Wait until RX Enable bit clear */
4641 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4644 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4645 } while (--poll_ms && (rxdctl & TXGBE_RXCFG_ENA));
4647 PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
4649 rte_delay_us(RTE_TXGBE_WAIT_100_US);
4650 txgbe_dev_store_rx_queue(hw, rxq->reg_idx);
4652 txgbe_rx_queue_release_mbufs(rxq);
4653 txgbe_reset_rx_queue(adapter, rxq);
4654 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4660 * Start Transmit Units for specified queue.
4663 txgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4665 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4666 struct txgbe_tx_queue *txq;
4670 PMD_INIT_FUNC_TRACE();
4672 txq = dev->data->tx_queues[tx_queue_id];
4673 wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
4675 /* Wait until TX Enable ready */
4676 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4679 txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
4680 } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
4682 PMD_INIT_LOG(ERR, "Could not enable "
4683 "Tx Queue %d", tx_queue_id);
4686 wr32(hw, TXGBE_TXWP(txq->reg_idx), txq->tx_tail);
4687 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4693 * Stop Transmit Units for specified queue.
4696 txgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4698 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4699 struct txgbe_tx_queue *txq;
4701 uint32_t txtdh, txtdt;
4704 PMD_INIT_FUNC_TRACE();
4706 txq = dev->data->tx_queues[tx_queue_id];
4708 /* Wait until TX queue is empty */
4709 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4711 rte_delay_us(RTE_TXGBE_WAIT_100_US);
4712 txtdh = rd32(hw, TXGBE_TXRP(txq->reg_idx));
4713 txtdt = rd32(hw, TXGBE_TXWP(txq->reg_idx));
4714 } while (--poll_ms && (txtdh != txtdt));
4717 "Tx Queue %d is not empty when stopping.",
4720 txgbe_dev_save_tx_queue(hw, txq->reg_idx);
4721 wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, 0);
4723 /* Wait until TX Enable bit clear */
4724 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4727 txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
4728 } while (--poll_ms && (txdctl & TXGBE_TXCFG_ENA));
4730 PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
4733 rte_delay_us(RTE_TXGBE_WAIT_100_US);
4734 txgbe_dev_store_tx_queue(hw, txq->reg_idx);
4736 if (txq->ops != NULL) {
4737 txq->ops->release_mbufs(txq);
4738 txq->ops->reset(txq);
4740 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4746 txgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4747 struct rte_eth_rxq_info *qinfo)
4749 struct txgbe_rx_queue *rxq;
4751 rxq = dev->data->rx_queues[queue_id];
4753 qinfo->mp = rxq->mb_pool;
4754 qinfo->scattered_rx = dev->data->scattered_rx;
4755 qinfo->nb_desc = rxq->nb_rx_desc;
4757 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
4758 qinfo->conf.rx_drop_en = rxq->drop_en;
4759 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
4760 qinfo->conf.offloads = rxq->offloads;
4764 txgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4765 struct rte_eth_txq_info *qinfo)
4767 struct txgbe_tx_queue *txq;
4769 txq = dev->data->tx_queues[queue_id];
4771 qinfo->nb_desc = txq->nb_tx_desc;
4773 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
4774 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
4775 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
4777 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
4778 qinfo->conf.offloads = txq->offloads;
4779 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
4783 * [VF] Initializes Receive Unit.
4786 txgbevf_dev_rx_init(struct rte_eth_dev *dev)
4788 struct txgbe_hw *hw;
4789 struct txgbe_rx_queue *rxq;
4790 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4792 uint32_t srrctl, psrtype;
4797 PMD_INIT_FUNC_TRACE();
4798 hw = TXGBE_DEV_HW(dev);
4800 if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
4801 PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
4802 "it should be power of 2");
4806 if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
4807 PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
4808 "it should be equal to or less than %d",
4809 hw->mac.max_rx_queues);
4814 * When the VF driver issues a TXGBE_VF_RESET request, the PF driver
4815 * disables the VF receipt of packets if the PF MTU is > 1500.
4816 * This is done to deal with limitations that imposes
4817 * the PF and all VFs to share the same MTU.
4818 * Then, the PF driver enables again the VF receipt of packet when
4819 * the VF driver issues a TXGBE_VF_SET_LPE request.
4820 * In the meantime, the VF device cannot be used, even if the VF driver
4821 * and the Guest VM network stack are ready to accept packets with a
4822 * size up to the PF MTU.
4823 * As a work-around to this PF behaviour, force the call to
4824 * txgbevf_rlpml_set_vf even if jumbo frames are not used. This way,
4825 * VF packets received can work in all cases.
4827 if (txgbevf_rlpml_set_vf(hw,
4828 (uint16_t)dev->data->dev_conf.rxmode.max_rx_pkt_len)) {
4829 PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
4830 dev->data->dev_conf.rxmode.max_rx_pkt_len);
4835 * Assume no header split and no VLAN strip support
4836 * on any Rx queue first .
4838 rxmode->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4840 /* Set PSR type for VF RSS according to max Rx queue */
4841 psrtype = TXGBE_VFPLCFG_PSRL4HDR |
4842 TXGBE_VFPLCFG_PSRL4HDR |
4843 TXGBE_VFPLCFG_PSRL2HDR |
4844 TXGBE_VFPLCFG_PSRTUNHDR |
4845 TXGBE_VFPLCFG_PSRTUNMAC;
4846 wr32(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_PSR(psrtype));
4848 /* Setup RX queues */
4849 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4850 rxq = dev->data->rx_queues[i];
4852 /* Allocate buffers for descriptor rings */
4853 ret = txgbe_alloc_rx_queue_mbufs(rxq);
4857 /* Setup the Base and Length of the Rx Descriptor Rings */
4858 bus_addr = rxq->rx_ring_phys_addr;
4860 wr32(hw, TXGBE_RXBAL(i),
4861 (uint32_t)(bus_addr & BIT_MASK32));
4862 wr32(hw, TXGBE_RXBAH(i),
4863 (uint32_t)(bus_addr >> 32));
4864 wr32(hw, TXGBE_RXRP(i), 0);
4865 wr32(hw, TXGBE_RXWP(i), 0);
4867 /* Configure the RXCFG register */
4868 srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
4870 /* Set if packets are dropped when no descriptors available */
4872 srrctl |= TXGBE_RXCFG_DROP;
4875 * Configure the RX buffer size in the PKTLEN field of
4876 * the RXCFG register of the queue.
4877 * The value is in 1 KB resolution. Valid values can be from
4880 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
4881 RTE_PKTMBUF_HEADROOM);
4882 buf_size = ROUND_UP(buf_size, 1 << 10);
4883 srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
4886 * VF modification to write virtual function RXCFG register
4888 wr32(hw, TXGBE_RXCFG(i), srrctl);
4890 if (rxmode->offloads & DEV_RX_OFFLOAD_SCATTER ||
4891 /* It adds dual VLAN length for supporting dual VLAN */
4892 (rxmode->max_rx_pkt_len +
4893 2 * TXGBE_VLAN_TAG_SIZE) > buf_size) {
4894 if (!dev->data->scattered_rx)
4895 PMD_INIT_LOG(DEBUG, "forcing scatter mode");
4896 dev->data->scattered_rx = 1;
4899 if (rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
4900 rxmode->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4904 * Device configured with multiple RX queues.
4906 txgbe_dev_mq_rx_configure(dev);
4908 txgbe_set_rx_function(dev);
4914 * [VF] Initializes Transmit Unit.
4917 txgbevf_dev_tx_init(struct rte_eth_dev *dev)
4919 struct txgbe_hw *hw;
4920 struct txgbe_tx_queue *txq;
4924 PMD_INIT_FUNC_TRACE();
4925 hw = TXGBE_DEV_HW(dev);
4927 /* Setup the Base and Length of the Tx Descriptor Rings */
4928 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4929 txq = dev->data->tx_queues[i];
4930 bus_addr = txq->tx_ring_phys_addr;
4931 wr32(hw, TXGBE_TXBAL(i),
4932 (uint32_t)(bus_addr & BIT_MASK32));
4933 wr32(hw, TXGBE_TXBAH(i),
4934 (uint32_t)(bus_addr >> 32));
4935 wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_BUFLEN_MASK,
4936 TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
4937 /* Setup the HW Tx Head and TX Tail descriptor pointers */
4938 wr32(hw, TXGBE_TXRP(i), 0);
4939 wr32(hw, TXGBE_TXWP(i), 0);
4944 * [VF] Start Transmit and Receive Units.
4947 txgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
4949 struct txgbe_hw *hw;
4950 struct txgbe_tx_queue *txq;
4951 struct txgbe_rx_queue *rxq;
4957 PMD_INIT_FUNC_TRACE();
4958 hw = TXGBE_DEV_HW(dev);
4960 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4961 txq = dev->data->tx_queues[i];
4962 /* Setup Transmit Threshold Registers */
4963 wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
4964 TXGBE_TXCFG_HTHRESH_MASK |
4965 TXGBE_TXCFG_WTHRESH_MASK,
4966 TXGBE_TXCFG_HTHRESH(txq->hthresh) |
4967 TXGBE_TXCFG_WTHRESH(txq->wthresh));
4970 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4971 wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
4974 /* Wait until TX Enable ready */
4977 txdctl = rd32(hw, TXGBE_TXCFG(i));
4978 } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
4980 PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
4982 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4983 rxq = dev->data->rx_queues[i];
4985 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, TXGBE_RXCFG_ENA);
4987 /* Wait until RX Enable ready */
4991 rxdctl = rd32(hw, TXGBE_RXCFG(i));
4992 } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
4994 PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
4996 wr32(hw, TXGBE_RXWP(i), rxq->nb_rx_desc - 1);
5001 txgbe_rss_conf_init(struct txgbe_rte_flow_rss_conf *out,
5002 const struct rte_flow_action_rss *in)
5004 if (in->key_len > RTE_DIM(out->key) ||
5005 in->queue_num > RTE_DIM(out->queue))
5007 out->conf = (struct rte_flow_action_rss){
5011 .key_len = in->key_len,
5012 .queue_num = in->queue_num,
5013 .key = memcpy(out->key, in->key, in->key_len),
5014 .queue = memcpy(out->queue, in->queue,
5015 sizeof(*in->queue) * in->queue_num),
5021 txgbe_action_rss_same(const struct rte_flow_action_rss *comp,
5022 const struct rte_flow_action_rss *with)
5024 return (comp->func == with->func &&
5025 comp->level == with->level &&
5026 comp->types == with->types &&
5027 comp->key_len == with->key_len &&
5028 comp->queue_num == with->queue_num &&
5029 !memcmp(comp->key, with->key, with->key_len) &&
5030 !memcmp(comp->queue, with->queue,
5031 sizeof(*with->queue) * with->queue_num));
5035 txgbe_config_rss_filter(struct rte_eth_dev *dev,
5036 struct txgbe_rte_flow_rss_conf *conf, bool add)
5038 struct txgbe_hw *hw;
5042 struct rte_eth_rss_conf rss_conf = {
5043 .rss_key = conf->conf.key_len ?
5044 (void *)(uintptr_t)conf->conf.key : NULL,
5045 .rss_key_len = conf->conf.key_len,
5046 .rss_hf = conf->conf.types,
5048 struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
5050 PMD_INIT_FUNC_TRACE();
5051 hw = TXGBE_DEV_HW(dev);
5054 if (txgbe_action_rss_same(&filter_info->rss_info.conf,
5056 txgbe_rss_disable(dev);
5057 memset(&filter_info->rss_info, 0,
5058 sizeof(struct txgbe_rte_flow_rss_conf));
5064 if (filter_info->rss_info.conf.queue_num)
5066 /* Fill in redirection table
5067 * The byte-swap is needed because NIC registers are in
5068 * little-endian order.
5071 for (i = 0, j = 0; i < ETH_RSS_RETA_SIZE_128; i++, j++) {
5072 if (j == conf->conf.queue_num)
5074 reta = (reta >> 8) | LS32(conf->conf.queue[j], 24, 0xFF);
5076 wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
5079 /* Configure the RSS key and the RSS protocols used to compute
5080 * the RSS hash of input packets.
5082 if ((rss_conf.rss_hf & TXGBE_RSS_OFFLOAD_ALL) == 0) {
5083 txgbe_rss_disable(dev);
5086 if (rss_conf.rss_key == NULL)
5087 rss_conf.rss_key = rss_intel_key; /* Default hash key */
5088 txgbe_dev_rss_hash_update(dev, &rss_conf);
5090 if (txgbe_rss_conf_init(&filter_info->rss_info, &conf->conf))