1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
17 #include <rte_byteorder.h>
18 #include <rte_common.h>
19 #include <rte_cycles.h>
21 #include <rte_debug.h>
22 #include <rte_ethdev.h>
23 #include <ethdev_driver.h>
24 #include <rte_security_driver.h>
25 #include <rte_memzone.h>
26 #include <rte_atomic.h>
27 #include <rte_mempool.h>
28 #include <rte_malloc.h>
30 #include <rte_ether.h>
31 #include <rte_prefetch.h>
35 #include <rte_string_fns.h>
36 #include <rte_errno.h>
40 #include "txgbe_logs.h"
41 #include "base/txgbe.h"
42 #include "txgbe_ethdev.h"
43 #include "txgbe_rxtx.h"
45 #ifdef RTE_LIBRTE_IEEE1588
46 #define TXGBE_TX_IEEE1588_TMST PKT_TX_IEEE1588_TMST
48 #define TXGBE_TX_IEEE1588_TMST 0
51 /* Bit Mask to indicate what bits required for building TX context */
52 static const u64 TXGBE_TX_OFFLOAD_MASK = (PKT_TX_IP_CKSUM |
61 PKT_TX_OUTER_IP_CKSUM |
62 PKT_TX_OUTER_UDP_CKSUM |
63 #ifdef RTE_LIB_SECURITY
66 TXGBE_TX_IEEE1588_TMST);
68 #define TXGBE_TX_OFFLOAD_NOTSUP_MASK \
69 (PKT_TX_OFFLOAD_MASK ^ TXGBE_TX_OFFLOAD_MASK)
72 * Prefetch a cache line into all cache levels.
74 #define rte_txgbe_prefetch(p) rte_prefetch0(p)
77 txgbe_is_vf(struct rte_eth_dev *dev)
79 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
81 switch (hw->mac.type) {
82 case txgbe_mac_raptor_vf:
89 /*********************************************************************
93 **********************************************************************/
96 * Check for descriptors with their DD bit set and free mbufs.
97 * Return the total number of buffers freed.
99 static __rte_always_inline int
100 txgbe_tx_free_bufs(struct txgbe_tx_queue *txq)
102 struct txgbe_tx_entry *txep;
105 struct rte_mbuf *m, *free[RTE_TXGBE_TX_MAX_FREE_BUF_SZ];
107 /* check DD bit on threshold descriptor */
108 status = txq->tx_ring[txq->tx_next_dd].dw3;
109 if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
110 if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
111 txgbe_set32_masked(txq->tdc_reg_addr,
112 TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
117 * first buffer to free from S/W ring is at index
118 * tx_next_dd - (tx_free_thresh-1)
120 txep = &txq->sw_ring[txq->tx_next_dd - (txq->tx_free_thresh - 1)];
121 for (i = 0; i < txq->tx_free_thresh; ++i, ++txep) {
122 /* free buffers one at a time */
123 m = rte_pktmbuf_prefree_seg(txep->mbuf);
126 if (unlikely(m == NULL))
129 if (nb_free >= RTE_TXGBE_TX_MAX_FREE_BUF_SZ ||
130 (nb_free > 0 && m->pool != free[0]->pool)) {
131 rte_mempool_put_bulk(free[0]->pool,
132 (void **)free, nb_free);
140 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
142 /* buffers were freed, update counters */
143 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_free_thresh);
144 txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_free_thresh);
145 if (txq->tx_next_dd >= txq->nb_tx_desc)
146 txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
148 return txq->tx_free_thresh;
151 /* Populate 4 descriptors with data from 4 mbufs */
153 tx4(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
155 uint64_t buf_dma_addr;
159 for (i = 0; i < 4; ++i, ++txdp, ++pkts) {
160 buf_dma_addr = rte_mbuf_data_iova(*pkts);
161 pkt_len = (*pkts)->data_len;
163 /* write data to descriptor */
164 txdp->qw0 = rte_cpu_to_le_64(buf_dma_addr);
165 txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
166 TXGBE_TXD_DATLEN(pkt_len));
167 txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
169 rte_prefetch0(&(*pkts)->pool);
173 /* Populate 1 descriptor with data from 1 mbuf */
175 tx1(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
177 uint64_t buf_dma_addr;
180 buf_dma_addr = rte_mbuf_data_iova(*pkts);
181 pkt_len = (*pkts)->data_len;
183 /* write data to descriptor */
184 txdp->qw0 = cpu_to_le64(buf_dma_addr);
185 txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
186 TXGBE_TXD_DATLEN(pkt_len));
187 txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
189 rte_prefetch0(&(*pkts)->pool);
193 * Fill H/W descriptor ring with mbuf data.
194 * Copy mbuf pointers to the S/W ring.
197 txgbe_tx_fill_hw_ring(struct txgbe_tx_queue *txq, struct rte_mbuf **pkts,
200 volatile struct txgbe_tx_desc *txdp = &txq->tx_ring[txq->tx_tail];
201 struct txgbe_tx_entry *txep = &txq->sw_ring[txq->tx_tail];
202 const int N_PER_LOOP = 4;
203 const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
204 int mainpart, leftover;
208 * Process most of the packets in chunks of N pkts. Any
209 * leftover packets will get processed one at a time.
211 mainpart = (nb_pkts & ((uint32_t)~N_PER_LOOP_MASK));
212 leftover = (nb_pkts & ((uint32_t)N_PER_LOOP_MASK));
213 for (i = 0; i < mainpart; i += N_PER_LOOP) {
214 /* Copy N mbuf pointers to the S/W ring */
215 for (j = 0; j < N_PER_LOOP; ++j)
216 (txep + i + j)->mbuf = *(pkts + i + j);
217 tx4(txdp + i, pkts + i);
220 if (unlikely(leftover > 0)) {
221 for (i = 0; i < leftover; ++i) {
222 (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
223 tx1(txdp + mainpart + i, pkts + mainpart + i);
228 static inline uint16_t
229 tx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
232 struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
236 * Begin scanning the H/W ring for done descriptors when the
237 * number of available descriptors drops below tx_free_thresh. For
238 * each done descriptor, free the associated buffer.
240 if (txq->nb_tx_free < txq->tx_free_thresh)
241 txgbe_tx_free_bufs(txq);
243 /* Only use descriptors that are available */
244 nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
245 if (unlikely(nb_pkts == 0))
248 /* Use exactly nb_pkts descriptors */
249 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
252 * At this point, we know there are enough descriptors in the
253 * ring to transmit all the packets. This assumes that each
254 * mbuf contains a single segment, and that no new offloads
255 * are expected, which would require a new context descriptor.
259 * See if we're going to wrap-around. If so, handle the top
260 * of the descriptor ring first, then do the bottom. If not,
261 * the processing looks just like the "bottom" part anyway...
263 if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
264 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
265 txgbe_tx_fill_hw_ring(txq, tx_pkts, n);
269 /* Fill H/W descriptor ring with mbuf data */
270 txgbe_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
271 txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
274 * Check for wrap-around. This would only happen if we used
275 * up to the last descriptor in the ring, no more, no less.
277 if (txq->tx_tail >= txq->nb_tx_desc)
280 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
281 (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
282 (uint16_t)txq->tx_tail, (uint16_t)nb_pkts);
284 /* update tail pointer */
286 txgbe_set32_relaxed(txq->tdt_reg_addr, txq->tx_tail);
292 txgbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
297 /* Try to transmit at least chunks of TX_MAX_BURST pkts */
298 if (likely(nb_pkts <= RTE_PMD_TXGBE_TX_MAX_BURST))
299 return tx_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
301 /* transmit more than the max burst, in chunks of TX_MAX_BURST */
306 n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_TX_MAX_BURST);
307 ret = tx_xmit_pkts(tx_queue, &tx_pkts[nb_tx], n);
308 nb_tx = (uint16_t)(nb_tx + ret);
309 nb_pkts = (uint16_t)(nb_pkts - ret);
318 txgbe_set_xmit_ctx(struct txgbe_tx_queue *txq,
319 volatile struct txgbe_tx_ctx_desc *ctx_txd,
320 uint64_t ol_flags, union txgbe_tx_offload tx_offload,
321 __rte_unused uint64_t *mdata)
323 union txgbe_tx_offload tx_offload_mask;
324 uint32_t type_tucmd_mlhl;
325 uint32_t mss_l4len_idx;
327 uint32_t vlan_macip_lens;
328 uint32_t tunnel_seed;
330 ctx_idx = txq->ctx_curr;
331 tx_offload_mask.data[0] = 0;
332 tx_offload_mask.data[1] = 0;
334 /* Specify which HW CTX to upload. */
335 mss_l4len_idx = TXGBE_TXD_IDX(ctx_idx);
336 type_tucmd_mlhl = TXGBE_TXD_CTXT;
338 tx_offload_mask.ptid |= ~0;
339 type_tucmd_mlhl |= TXGBE_TXD_PTID(tx_offload.ptid);
341 /* check if TCP segmentation required for this packet */
342 if (ol_flags & PKT_TX_TCP_SEG) {
343 tx_offload_mask.l2_len |= ~0;
344 tx_offload_mask.l3_len |= ~0;
345 tx_offload_mask.l4_len |= ~0;
346 tx_offload_mask.tso_segsz |= ~0;
347 mss_l4len_idx |= TXGBE_TXD_MSS(tx_offload.tso_segsz);
348 mss_l4len_idx |= TXGBE_TXD_L4LEN(tx_offload.l4_len);
349 } else { /* no TSO, check if hardware checksum is needed */
350 if (ol_flags & PKT_TX_IP_CKSUM) {
351 tx_offload_mask.l2_len |= ~0;
352 tx_offload_mask.l3_len |= ~0;
355 switch (ol_flags & PKT_TX_L4_MASK) {
356 case PKT_TX_UDP_CKSUM:
358 TXGBE_TXD_L4LEN(sizeof(struct rte_udp_hdr));
359 tx_offload_mask.l2_len |= ~0;
360 tx_offload_mask.l3_len |= ~0;
362 case PKT_TX_TCP_CKSUM:
364 TXGBE_TXD_L4LEN(sizeof(struct rte_tcp_hdr));
365 tx_offload_mask.l2_len |= ~0;
366 tx_offload_mask.l3_len |= ~0;
368 case PKT_TX_SCTP_CKSUM:
370 TXGBE_TXD_L4LEN(sizeof(struct rte_sctp_hdr));
371 tx_offload_mask.l2_len |= ~0;
372 tx_offload_mask.l3_len |= ~0;
379 vlan_macip_lens = TXGBE_TXD_IPLEN(tx_offload.l3_len >> 1);
381 if (ol_flags & PKT_TX_TUNNEL_MASK) {
382 tx_offload_mask.outer_tun_len |= ~0;
383 tx_offload_mask.outer_l2_len |= ~0;
384 tx_offload_mask.outer_l3_len |= ~0;
385 tx_offload_mask.l2_len |= ~0;
386 tunnel_seed = TXGBE_TXD_ETUNLEN(tx_offload.outer_tun_len >> 1);
387 tunnel_seed |= TXGBE_TXD_EIPLEN(tx_offload.outer_l3_len >> 2);
389 switch (ol_flags & PKT_TX_TUNNEL_MASK) {
390 case PKT_TX_TUNNEL_IPIP:
391 /* for non UDP / GRE tunneling, set to 0b */
393 case PKT_TX_TUNNEL_VXLAN:
394 case PKT_TX_TUNNEL_VXLAN_GPE:
395 case PKT_TX_TUNNEL_GENEVE:
396 tunnel_seed |= TXGBE_TXD_ETYPE_UDP;
398 case PKT_TX_TUNNEL_GRE:
399 tunnel_seed |= TXGBE_TXD_ETYPE_GRE;
402 PMD_TX_LOG(ERR, "Tunnel type not supported");
405 vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.outer_l2_len);
408 vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.l2_len);
411 if (ol_flags & PKT_TX_VLAN_PKT) {
412 tx_offload_mask.vlan_tci |= ~0;
413 vlan_macip_lens |= TXGBE_TXD_VLAN(tx_offload.vlan_tci);
416 #ifdef RTE_LIB_SECURITY
417 if (ol_flags & PKT_TX_SEC_OFFLOAD) {
418 union txgbe_crypto_tx_desc_md *md =
419 (union txgbe_crypto_tx_desc_md *)mdata;
420 tunnel_seed |= TXGBE_TXD_IPSEC_SAIDX(md->sa_idx);
421 type_tucmd_mlhl |= md->enc ?
422 (TXGBE_TXD_IPSEC_ESP | TXGBE_TXD_IPSEC_ESPENC) : 0;
423 type_tucmd_mlhl |= TXGBE_TXD_IPSEC_ESPLEN(md->pad_len);
424 tx_offload_mask.sa_idx |= ~0;
425 tx_offload_mask.sec_pad_len |= ~0;
429 txq->ctx_cache[ctx_idx].flags = ol_flags;
430 txq->ctx_cache[ctx_idx].tx_offload.data[0] =
431 tx_offload_mask.data[0] & tx_offload.data[0];
432 txq->ctx_cache[ctx_idx].tx_offload.data[1] =
433 tx_offload_mask.data[1] & tx_offload.data[1];
434 txq->ctx_cache[ctx_idx].tx_offload_mask = tx_offload_mask;
436 ctx_txd->dw0 = rte_cpu_to_le_32(vlan_macip_lens);
437 ctx_txd->dw1 = rte_cpu_to_le_32(tunnel_seed);
438 ctx_txd->dw2 = rte_cpu_to_le_32(type_tucmd_mlhl);
439 ctx_txd->dw3 = rte_cpu_to_le_32(mss_l4len_idx);
443 * Check which hardware context can be used. Use the existing match
444 * or create a new context descriptor.
446 static inline uint32_t
447 what_ctx_update(struct txgbe_tx_queue *txq, uint64_t flags,
448 union txgbe_tx_offload tx_offload)
450 /* If match with the current used context */
451 if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
452 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
453 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
454 & tx_offload.data[0])) &&
455 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
456 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
457 & tx_offload.data[1]))))
458 return txq->ctx_curr;
460 /* What if match with the next context */
462 if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
463 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
464 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
465 & tx_offload.data[0])) &&
466 (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
467 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
468 & tx_offload.data[1]))))
469 return txq->ctx_curr;
471 /* Mismatch, use the previous context */
472 return TXGBE_CTX_NUM;
475 static inline uint32_t
476 tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
480 if ((ol_flags & PKT_TX_L4_MASK) != PKT_TX_L4_NO_CKSUM) {
482 tmp |= TXGBE_TXD_L4CS;
484 if (ol_flags & PKT_TX_IP_CKSUM) {
486 tmp |= TXGBE_TXD_IPCS;
488 if (ol_flags & PKT_TX_OUTER_IP_CKSUM) {
490 tmp |= TXGBE_TXD_EIPCS;
492 if (ol_flags & PKT_TX_TCP_SEG) {
494 /* implies IPv4 cksum */
495 if (ol_flags & PKT_TX_IPV4)
496 tmp |= TXGBE_TXD_IPCS;
497 tmp |= TXGBE_TXD_L4CS;
499 if (ol_flags & PKT_TX_VLAN_PKT)
505 static inline uint32_t
506 tx_desc_ol_flags_to_cmdtype(uint64_t ol_flags)
508 uint32_t cmdtype = 0;
510 if (ol_flags & PKT_TX_VLAN_PKT)
511 cmdtype |= TXGBE_TXD_VLE;
512 if (ol_flags & PKT_TX_TCP_SEG)
513 cmdtype |= TXGBE_TXD_TSE;
514 if (ol_flags & PKT_TX_MACSEC)
515 cmdtype |= TXGBE_TXD_LINKSEC;
519 static inline uint8_t
520 tx_desc_ol_flags_to_ptid(uint64_t oflags, uint32_t ptype)
525 return txgbe_encode_ptype(ptype);
527 /* Only support flags in TXGBE_TX_OFFLOAD_MASK */
528 tun = !!(oflags & PKT_TX_TUNNEL_MASK);
531 ptype = RTE_PTYPE_L2_ETHER;
532 if (oflags & PKT_TX_VLAN)
533 ptype |= RTE_PTYPE_L2_ETHER_VLAN;
536 if (oflags & (PKT_TX_OUTER_IPV4 | PKT_TX_OUTER_IP_CKSUM))
537 ptype |= RTE_PTYPE_L3_IPV4;
538 else if (oflags & (PKT_TX_OUTER_IPV6))
539 ptype |= RTE_PTYPE_L3_IPV6;
541 if (oflags & (PKT_TX_IPV4 | PKT_TX_IP_CKSUM))
542 ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV4 : RTE_PTYPE_L3_IPV4);
543 else if (oflags & (PKT_TX_IPV6))
544 ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV6 : RTE_PTYPE_L3_IPV6);
547 switch (oflags & (PKT_TX_L4_MASK)) {
548 case PKT_TX_TCP_CKSUM:
549 ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
551 case PKT_TX_UDP_CKSUM:
552 ptype |= (tun ? RTE_PTYPE_INNER_L4_UDP : RTE_PTYPE_L4_UDP);
554 case PKT_TX_SCTP_CKSUM:
555 ptype |= (tun ? RTE_PTYPE_INNER_L4_SCTP : RTE_PTYPE_L4_SCTP);
559 if (oflags & PKT_TX_TCP_SEG)
560 ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
563 switch (oflags & PKT_TX_TUNNEL_MASK) {
564 case PKT_TX_TUNNEL_VXLAN:
565 case PKT_TX_TUNNEL_VXLAN_GPE:
566 ptype |= RTE_PTYPE_L2_ETHER |
568 RTE_PTYPE_TUNNEL_GRENAT;
570 case PKT_TX_TUNNEL_GRE:
571 ptype |= RTE_PTYPE_L2_ETHER |
573 RTE_PTYPE_TUNNEL_GRE;
574 ptype |= RTE_PTYPE_INNER_L2_ETHER;
576 case PKT_TX_TUNNEL_GENEVE:
577 ptype |= RTE_PTYPE_L2_ETHER |
579 RTE_PTYPE_TUNNEL_GENEVE;
580 ptype |= RTE_PTYPE_INNER_L2_ETHER;
582 case PKT_TX_TUNNEL_IPIP:
583 case PKT_TX_TUNNEL_IP:
584 ptype |= RTE_PTYPE_L2_ETHER |
590 return txgbe_encode_ptype(ptype);
593 #ifndef DEFAULT_TX_FREE_THRESH
594 #define DEFAULT_TX_FREE_THRESH 32
597 /* Reset transmit descriptors after they have been used */
599 txgbe_xmit_cleanup(struct txgbe_tx_queue *txq)
601 struct txgbe_tx_entry *sw_ring = txq->sw_ring;
602 volatile struct txgbe_tx_desc *txr = txq->tx_ring;
603 uint16_t last_desc_cleaned = txq->last_desc_cleaned;
604 uint16_t nb_tx_desc = txq->nb_tx_desc;
605 uint16_t desc_to_clean_to;
606 uint16_t nb_tx_to_clean;
609 /* Determine the last descriptor needing to be cleaned */
610 desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_free_thresh);
611 if (desc_to_clean_to >= nb_tx_desc)
612 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
614 /* Check to make sure the last descriptor to clean is done */
615 desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
616 status = txr[desc_to_clean_to].dw3;
617 if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
618 PMD_TX_FREE_LOG(DEBUG,
619 "TX descriptor %4u is not done"
620 "(port=%d queue=%d)",
622 txq->port_id, txq->queue_id);
623 if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
624 txgbe_set32_masked(txq->tdc_reg_addr,
625 TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
626 /* Failed to clean any descriptors, better luck next time */
630 /* Figure out how many descriptors will be cleaned */
631 if (last_desc_cleaned > desc_to_clean_to)
632 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
635 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
638 PMD_TX_FREE_LOG(DEBUG,
639 "Cleaning %4u TX descriptors: %4u to %4u "
640 "(port=%d queue=%d)",
641 nb_tx_to_clean, last_desc_cleaned, desc_to_clean_to,
642 txq->port_id, txq->queue_id);
645 * The last descriptor to clean is done, so that means all the
646 * descriptors from the last descriptor that was cleaned
647 * up to the last descriptor with the RS bit set
648 * are done. Only reset the threshold descriptor.
650 txr[desc_to_clean_to].dw3 = 0;
652 /* Update the txq to reflect the last descriptor that was cleaned */
653 txq->last_desc_cleaned = desc_to_clean_to;
654 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
660 static inline uint8_t
661 txgbe_get_tun_len(struct rte_mbuf *mbuf)
663 struct txgbe_genevehdr genevehdr;
664 const struct txgbe_genevehdr *gh;
667 switch (mbuf->ol_flags & PKT_TX_TUNNEL_MASK) {
668 case PKT_TX_TUNNEL_IPIP:
671 case PKT_TX_TUNNEL_VXLAN:
672 case PKT_TX_TUNNEL_VXLAN_GPE:
673 tun_len = sizeof(struct txgbe_udphdr)
674 + sizeof(struct txgbe_vxlanhdr);
676 case PKT_TX_TUNNEL_GRE:
677 tun_len = sizeof(struct txgbe_nvgrehdr);
679 case PKT_TX_TUNNEL_GENEVE:
680 gh = rte_pktmbuf_read(mbuf,
681 mbuf->outer_l2_len + mbuf->outer_l3_len,
682 sizeof(genevehdr), &genevehdr);
683 tun_len = sizeof(struct txgbe_udphdr)
684 + sizeof(struct txgbe_genevehdr)
685 + (gh->opt_len << 2);
694 static inline uint8_t
695 txgbe_parse_tun_ptid(struct rte_mbuf *tx_pkt)
697 uint64_t l2_none, l2_mac, l2_mac_vlan;
700 if ((tx_pkt->ol_flags & (PKT_TX_TUNNEL_VXLAN |
701 PKT_TX_TUNNEL_VXLAN_GPE)) == 0)
704 l2_none = sizeof(struct txgbe_udphdr) + sizeof(struct txgbe_vxlanhdr);
705 l2_mac = l2_none + sizeof(struct rte_ether_hdr);
706 l2_mac_vlan = l2_mac + sizeof(struct rte_vlan_hdr);
708 if (tx_pkt->l2_len == l2_none)
709 ptid = TXGBE_PTID_TUN_EIG;
710 else if (tx_pkt->l2_len == l2_mac)
711 ptid = TXGBE_PTID_TUN_EIGM;
712 else if (tx_pkt->l2_len == l2_mac_vlan)
713 ptid = TXGBE_PTID_TUN_EIGMV;
719 txgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
722 struct txgbe_tx_queue *txq;
723 struct txgbe_tx_entry *sw_ring;
724 struct txgbe_tx_entry *txe, *txn;
725 volatile struct txgbe_tx_desc *txr;
726 volatile struct txgbe_tx_desc *txd;
727 struct rte_mbuf *tx_pkt;
728 struct rte_mbuf *m_seg;
729 uint64_t buf_dma_addr;
730 uint32_t olinfo_status;
731 uint32_t cmd_type_len;
742 union txgbe_tx_offload tx_offload;
743 #ifdef RTE_LIB_SECURITY
747 tx_offload.data[0] = 0;
748 tx_offload.data[1] = 0;
750 sw_ring = txq->sw_ring;
752 tx_id = txq->tx_tail;
753 txe = &sw_ring[tx_id];
755 /* Determine if the descriptor ring needs to be cleaned. */
756 if (txq->nb_tx_free < txq->tx_free_thresh)
757 txgbe_xmit_cleanup(txq);
759 rte_prefetch0(&txe->mbuf->pool);
762 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
765 pkt_len = tx_pkt->pkt_len;
768 * Determine how many (if any) context descriptors
769 * are needed for offload functionality.
771 ol_flags = tx_pkt->ol_flags;
772 #ifdef RTE_LIB_SECURITY
773 use_ipsec = txq->using_ipsec && (ol_flags & PKT_TX_SEC_OFFLOAD);
776 /* If hardware offload required */
777 tx_ol_req = ol_flags & TXGBE_TX_OFFLOAD_MASK;
779 tx_offload.ptid = tx_desc_ol_flags_to_ptid(tx_ol_req,
780 tx_pkt->packet_type);
781 if (tx_offload.ptid & TXGBE_PTID_PKT_TUN)
782 tx_offload.ptid |= txgbe_parse_tun_ptid(tx_pkt);
783 tx_offload.l2_len = tx_pkt->l2_len;
784 tx_offload.l3_len = tx_pkt->l3_len;
785 tx_offload.l4_len = tx_pkt->l4_len;
786 tx_offload.vlan_tci = tx_pkt->vlan_tci;
787 tx_offload.tso_segsz = tx_pkt->tso_segsz;
788 tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
789 tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
790 tx_offload.outer_tun_len = txgbe_get_tun_len(tx_pkt);
792 #ifdef RTE_LIB_SECURITY
794 union txgbe_crypto_tx_desc_md *ipsec_mdata =
795 (union txgbe_crypto_tx_desc_md *)
796 rte_security_dynfield(tx_pkt);
797 tx_offload.sa_idx = ipsec_mdata->sa_idx;
798 tx_offload.sec_pad_len = ipsec_mdata->pad_len;
802 /* If new context need be built or reuse the exist ctx*/
803 ctx = what_ctx_update(txq, tx_ol_req, tx_offload);
804 /* Only allocate context descriptor if required */
805 new_ctx = (ctx == TXGBE_CTX_NUM);
810 * Keep track of how many descriptors are used this loop
811 * This will always be the number of segments + the number of
812 * Context descriptors required to transmit the packet
814 nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
817 * The number of descriptors that must be allocated for a
818 * packet is the number of segments of that packet, plus 1
819 * Context Descriptor for the hardware offload, if any.
820 * Determine the last TX descriptor to allocate in the TX ring
821 * for the packet, starting from the current position (tx_id)
824 tx_last = (uint16_t)(tx_id + nb_used - 1);
827 if (tx_last >= txq->nb_tx_desc)
828 tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
830 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
831 " tx_first=%u tx_last=%u",
832 (uint16_t)txq->port_id,
833 (uint16_t)txq->queue_id,
839 * Make sure there are enough TX descriptors available to
840 * transmit the entire packet.
841 * nb_used better be less than or equal to txq->tx_free_thresh
843 if (nb_used > txq->nb_tx_free) {
844 PMD_TX_FREE_LOG(DEBUG,
845 "Not enough free TX descriptors "
846 "nb_used=%4u nb_free=%4u "
847 "(port=%d queue=%d)",
848 nb_used, txq->nb_tx_free,
849 txq->port_id, txq->queue_id);
851 if (txgbe_xmit_cleanup(txq) != 0) {
852 /* Could not clean any descriptors */
858 /* nb_used better be <= txq->tx_free_thresh */
859 if (unlikely(nb_used > txq->tx_free_thresh)) {
860 PMD_TX_FREE_LOG(DEBUG,
861 "The number of descriptors needed to "
862 "transmit the packet exceeds the "
863 "RS bit threshold. This will impact "
865 "nb_used=%4u nb_free=%4u "
866 "tx_free_thresh=%4u. "
867 "(port=%d queue=%d)",
868 nb_used, txq->nb_tx_free,
870 txq->port_id, txq->queue_id);
872 * Loop here until there are enough TX
873 * descriptors or until the ring cannot be
876 while (nb_used > txq->nb_tx_free) {
877 if (txgbe_xmit_cleanup(txq) != 0) {
879 * Could not clean any
891 * By now there are enough free TX descriptors to transmit
896 * Set common flags of all TX Data Descriptors.
898 * The following bits must be set in all Data Descriptors:
899 * - TXGBE_TXD_DTYP_DATA
900 * - TXGBE_TXD_DCMD_DEXT
902 * The following bits must be set in the first Data Descriptor
903 * and are ignored in the other ones:
904 * - TXGBE_TXD_DCMD_IFCS
905 * - TXGBE_TXD_MAC_1588
906 * - TXGBE_TXD_DCMD_VLE
908 * The following bits must only be set in the last Data
910 * - TXGBE_TXD_CMD_EOP
912 * The following bits can be set in any Data Descriptor, but
913 * are only set in the last Data Descriptor:
916 cmd_type_len = TXGBE_TXD_FCS;
918 #ifdef RTE_LIBRTE_IEEE1588
919 if (ol_flags & PKT_TX_IEEE1588_TMST)
920 cmd_type_len |= TXGBE_TXD_1588;
925 if (ol_flags & PKT_TX_TCP_SEG) {
926 /* when TSO is on, paylen in descriptor is the
927 * not the packet len but the tcp payload len
929 pkt_len -= (tx_offload.l2_len +
930 tx_offload.l3_len + tx_offload.l4_len);
932 (tx_pkt->ol_flags & PKT_TX_TUNNEL_MASK)
933 ? tx_offload.outer_l2_len +
934 tx_offload.outer_l3_len : 0;
938 * Setup the TX Advanced Context Descriptor if required
941 volatile struct txgbe_tx_ctx_desc *ctx_txd;
943 ctx_txd = (volatile struct txgbe_tx_ctx_desc *)
946 txn = &sw_ring[txe->next_id];
947 rte_prefetch0(&txn->mbuf->pool);
949 if (txe->mbuf != NULL) {
950 rte_pktmbuf_free_seg(txe->mbuf);
954 txgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
956 rte_security_dynfield(tx_pkt));
958 txe->last_id = tx_last;
959 tx_id = txe->next_id;
964 * Setup the TX Advanced Data Descriptor,
965 * This path will go through
966 * whatever new/reuse the context descriptor
968 cmd_type_len |= tx_desc_ol_flags_to_cmdtype(ol_flags);
970 tx_desc_cksum_flags_to_olinfo(ol_flags);
971 olinfo_status |= TXGBE_TXD_IDX(ctx);
974 olinfo_status |= TXGBE_TXD_PAYLEN(pkt_len);
975 #ifdef RTE_LIB_SECURITY
977 olinfo_status |= TXGBE_TXD_IPSEC;
983 txn = &sw_ring[txe->next_id];
984 rte_prefetch0(&txn->mbuf->pool);
986 if (txe->mbuf != NULL)
987 rte_pktmbuf_free_seg(txe->mbuf);
991 * Set up Transmit Data Descriptor.
993 slen = m_seg->data_len;
994 buf_dma_addr = rte_mbuf_data_iova(m_seg);
995 txd->qw0 = rte_cpu_to_le_64(buf_dma_addr);
996 txd->dw2 = rte_cpu_to_le_32(cmd_type_len | slen);
997 txd->dw3 = rte_cpu_to_le_32(olinfo_status);
998 txe->last_id = tx_last;
999 tx_id = txe->next_id;
1001 m_seg = m_seg->next;
1002 } while (m_seg != NULL);
1005 * The last packet data descriptor needs End Of Packet (EOP)
1007 cmd_type_len |= TXGBE_TXD_EOP;
1008 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
1010 txd->dw2 |= rte_cpu_to_le_32(cmd_type_len);
1018 * Set the Transmit Descriptor Tail (TDT)
1020 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1021 (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
1022 (uint16_t)tx_id, (uint16_t)nb_tx);
1023 txgbe_set32_relaxed(txq->tdt_reg_addr, tx_id);
1024 txq->tx_tail = tx_id;
1029 /*********************************************************************
1033 **********************************************************************/
1035 txgbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1040 struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
1042 for (i = 0; i < nb_pkts; i++) {
1044 ol_flags = m->ol_flags;
1047 * Check if packet meets requirements for number of segments
1049 * NOTE: for txgbe it's always (40 - WTHRESH) for both TSO and
1053 if (m->nb_segs > TXGBE_TX_MAX_SEG - txq->wthresh) {
1054 rte_errno = -EINVAL;
1058 if (ol_flags & TXGBE_TX_OFFLOAD_NOTSUP_MASK) {
1059 rte_errno = -ENOTSUP;
1063 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1064 ret = rte_validate_tx_offload(m);
1070 ret = rte_net_intel_cksum_prepare(m);
1080 /*********************************************************************
1084 **********************************************************************/
1085 /* @note: fix txgbe_dev_supported_ptypes_get() if any change here. */
1086 static inline uint32_t
1087 txgbe_rxd_pkt_info_to_pkt_type(uint32_t pkt_info, uint16_t ptid_mask)
1089 uint16_t ptid = TXGBE_RXD_PTID(pkt_info);
1093 return txgbe_decode_ptype(ptid);
1096 static inline uint64_t
1097 txgbe_rxd_pkt_info_to_pkt_flags(uint32_t pkt_info)
1099 static uint64_t ip_rss_types_map[16] __rte_cache_aligned = {
1100 0, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH,
1101 0, PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH,
1102 PKT_RX_RSS_HASH, 0, 0, 0,
1103 0, 0, 0, PKT_RX_FDIR,
1105 #ifdef RTE_LIBRTE_IEEE1588
1106 static uint64_t ip_pkt_etqf_map[8] = {
1107 0, 0, 0, PKT_RX_IEEE1588_PTP,
1110 int etfid = txgbe_etflt_id(TXGBE_RXD_PTID(pkt_info));
1111 if (likely(-1 != etfid))
1112 return ip_pkt_etqf_map[etfid] |
1113 ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1115 return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1117 return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
1121 static inline uint64_t
1122 rx_desc_status_to_pkt_flags(uint32_t rx_status, uint64_t vlan_flags)
1127 * Check if VLAN present only.
1128 * Do not check whether L3/L4 rx checksum done by NIC or not,
1129 * That can be found from rte_eth_rxmode.offloads flag
1131 pkt_flags = (rx_status & TXGBE_RXD_STAT_VLAN &&
1132 vlan_flags & PKT_RX_VLAN_STRIPPED)
1135 #ifdef RTE_LIBRTE_IEEE1588
1136 if (rx_status & TXGBE_RXD_STAT_1588)
1137 pkt_flags = pkt_flags | PKT_RX_IEEE1588_TMST;
1142 static inline uint64_t
1143 rx_desc_error_to_pkt_flags(uint32_t rx_status)
1145 uint64_t pkt_flags = 0;
1147 /* checksum offload can't be disabled */
1148 if (rx_status & TXGBE_RXD_STAT_IPCS) {
1149 pkt_flags |= (rx_status & TXGBE_RXD_ERR_IPCS
1150 ? PKT_RX_IP_CKSUM_BAD : PKT_RX_IP_CKSUM_GOOD);
1153 if (rx_status & TXGBE_RXD_STAT_L4CS) {
1154 pkt_flags |= (rx_status & TXGBE_RXD_ERR_L4CS
1155 ? PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD);
1158 if (rx_status & TXGBE_RXD_STAT_EIPCS &&
1159 rx_status & TXGBE_RXD_ERR_EIPCS) {
1160 pkt_flags |= PKT_RX_OUTER_IP_CKSUM_BAD;
1163 #ifdef RTE_LIB_SECURITY
1164 if (rx_status & TXGBE_RXD_STAT_SECP) {
1165 pkt_flags |= PKT_RX_SEC_OFFLOAD;
1166 if (rx_status & TXGBE_RXD_ERR_SECERR)
1167 pkt_flags |= PKT_RX_SEC_OFFLOAD_FAILED;
1175 * LOOK_AHEAD defines how many desc statuses to check beyond the
1176 * current descriptor.
1177 * It must be a pound define for optimal performance.
1178 * Do not change the value of LOOK_AHEAD, as the txgbe_rx_scan_hw_ring
1179 * function only works with LOOK_AHEAD=8.
1181 #define LOOK_AHEAD 8
1182 #if (LOOK_AHEAD != 8)
1183 #error "PMD TXGBE: LOOK_AHEAD must be 8\n"
1186 txgbe_rx_scan_hw_ring(struct txgbe_rx_queue *rxq)
1188 volatile struct txgbe_rx_desc *rxdp;
1189 struct txgbe_rx_entry *rxep;
1190 struct rte_mbuf *mb;
1194 uint32_t s[LOOK_AHEAD];
1195 uint32_t pkt_info[LOOK_AHEAD];
1196 int i, j, nb_rx = 0;
1199 /* get references to current descriptor and S/W ring entry */
1200 rxdp = &rxq->rx_ring[rxq->rx_tail];
1201 rxep = &rxq->sw_ring[rxq->rx_tail];
1203 status = rxdp->qw1.lo.status;
1204 /* check to make sure there is at least 1 packet to receive */
1205 if (!(status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
1209 * Scan LOOK_AHEAD descriptors at a time to determine which descriptors
1210 * reference packets that are ready to be received.
1212 for (i = 0; i < RTE_PMD_TXGBE_RX_MAX_BURST;
1213 i += LOOK_AHEAD, rxdp += LOOK_AHEAD, rxep += LOOK_AHEAD) {
1214 /* Read desc statuses backwards to avoid race condition */
1215 for (j = 0; j < LOOK_AHEAD; j++)
1216 s[j] = rte_le_to_cpu_32(rxdp[j].qw1.lo.status);
1218 rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1220 /* Compute how many status bits were set */
1221 for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
1222 (s[nb_dd] & TXGBE_RXD_STAT_DD); nb_dd++)
1225 for (j = 0; j < nb_dd; j++)
1226 pkt_info[j] = rte_le_to_cpu_32(rxdp[j].qw0.dw0);
1230 /* Translate descriptor info to mbuf format */
1231 for (j = 0; j < nb_dd; ++j) {
1233 pkt_len = rte_le_to_cpu_16(rxdp[j].qw1.hi.len) -
1235 mb->data_len = pkt_len;
1236 mb->pkt_len = pkt_len;
1237 mb->vlan_tci = rte_le_to_cpu_16(rxdp[j].qw1.hi.tag);
1239 /* convert descriptor fields to rte mbuf flags */
1240 pkt_flags = rx_desc_status_to_pkt_flags(s[j],
1242 pkt_flags |= rx_desc_error_to_pkt_flags(s[j]);
1244 txgbe_rxd_pkt_info_to_pkt_flags(pkt_info[j]);
1245 mb->ol_flags = pkt_flags;
1247 txgbe_rxd_pkt_info_to_pkt_type(pkt_info[j],
1248 rxq->pkt_type_mask);
1250 if (likely(pkt_flags & PKT_RX_RSS_HASH))
1252 rte_le_to_cpu_32(rxdp[j].qw0.dw1);
1253 else if (pkt_flags & PKT_RX_FDIR) {
1254 mb->hash.fdir.hash =
1255 rte_le_to_cpu_16(rxdp[j].qw0.hi.csum) &
1256 TXGBE_ATR_HASH_MASK;
1258 rte_le_to_cpu_16(rxdp[j].qw0.hi.ipid);
1262 /* Move mbuf pointers from the S/W ring to the stage */
1263 for (j = 0; j < LOOK_AHEAD; ++j)
1264 rxq->rx_stage[i + j] = rxep[j].mbuf;
1266 /* stop if all requested packets could not be received */
1267 if (nb_dd != LOOK_AHEAD)
1271 /* clear software ring entries so we can cleanup correctly */
1272 for (i = 0; i < nb_rx; ++i)
1273 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
1279 txgbe_rx_alloc_bufs(struct txgbe_rx_queue *rxq, bool reset_mbuf)
1281 volatile struct txgbe_rx_desc *rxdp;
1282 struct txgbe_rx_entry *rxep;
1283 struct rte_mbuf *mb;
1288 /* allocate buffers in bulk directly into the S/W ring */
1289 alloc_idx = rxq->rx_free_trigger - (rxq->rx_free_thresh - 1);
1290 rxep = &rxq->sw_ring[alloc_idx];
1291 diag = rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
1292 rxq->rx_free_thresh);
1293 if (unlikely(diag != 0))
1296 rxdp = &rxq->rx_ring[alloc_idx];
1297 for (i = 0; i < rxq->rx_free_thresh; ++i) {
1298 /* populate the static rte mbuf fields */
1301 mb->port = rxq->port_id;
1303 rte_mbuf_refcnt_set(mb, 1);
1304 mb->data_off = RTE_PKTMBUF_HEADROOM;
1306 /* populate the descriptors */
1307 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
1308 TXGBE_RXD_HDRADDR(&rxdp[i], 0);
1309 TXGBE_RXD_PKTADDR(&rxdp[i], dma_addr);
1312 /* update state of internal queue structure */
1313 rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh;
1314 if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
1315 rxq->rx_free_trigger = rxq->rx_free_thresh - 1;
1321 static inline uint16_t
1322 txgbe_rx_fill_from_stage(struct txgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
1325 struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
1328 /* how many packets are ready to return? */
1329 nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
1331 /* copy mbuf pointers to the application's packet list */
1332 for (i = 0; i < nb_pkts; ++i)
1333 rx_pkts[i] = stage[i];
1335 /* update internal queue state */
1336 rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
1337 rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
1342 static inline uint16_t
1343 txgbe_rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1346 struct txgbe_rx_queue *rxq = (struct txgbe_rx_queue *)rx_queue;
1347 struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1350 /* Any previously recv'd pkts will be returned from the Rx stage */
1351 if (rxq->rx_nb_avail)
1352 return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1354 /* Scan the H/W ring for packets to receive */
1355 nb_rx = (uint16_t)txgbe_rx_scan_hw_ring(rxq);
1357 /* update internal queue state */
1358 rxq->rx_next_avail = 0;
1359 rxq->rx_nb_avail = nb_rx;
1360 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
1362 /* if required, allocate new buffers to replenish descriptors */
1363 if (rxq->rx_tail > rxq->rx_free_trigger) {
1364 uint16_t cur_free_trigger = rxq->rx_free_trigger;
1366 if (txgbe_rx_alloc_bufs(rxq, true) != 0) {
1369 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1370 "queue_id=%u", (uint16_t)rxq->port_id,
1371 (uint16_t)rxq->queue_id);
1373 dev->data->rx_mbuf_alloc_failed +=
1374 rxq->rx_free_thresh;
1377 * Need to rewind any previous receives if we cannot
1378 * allocate new buffers to replenish the old ones.
1380 rxq->rx_nb_avail = 0;
1381 rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
1382 for (i = 0, j = rxq->rx_tail; i < nb_rx; ++i, ++j)
1383 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
1388 /* update tail pointer */
1390 txgbe_set32_relaxed(rxq->rdt_reg_addr, cur_free_trigger);
1393 if (rxq->rx_tail >= rxq->nb_rx_desc)
1396 /* received any packets this loop? */
1397 if (rxq->rx_nb_avail)
1398 return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
1403 /* split requests into chunks of size RTE_PMD_TXGBE_RX_MAX_BURST */
1405 txgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1410 if (unlikely(nb_pkts == 0))
1413 if (likely(nb_pkts <= RTE_PMD_TXGBE_RX_MAX_BURST))
1414 return txgbe_rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
1416 /* request is relatively large, chunk it up */
1421 n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_RX_MAX_BURST);
1422 ret = txgbe_rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
1423 nb_rx = (uint16_t)(nb_rx + ret);
1424 nb_pkts = (uint16_t)(nb_pkts - ret);
1433 txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1436 struct txgbe_rx_queue *rxq;
1437 volatile struct txgbe_rx_desc *rx_ring;
1438 volatile struct txgbe_rx_desc *rxdp;
1439 struct txgbe_rx_entry *sw_ring;
1440 struct txgbe_rx_entry *rxe;
1441 struct rte_mbuf *rxm;
1442 struct rte_mbuf *nmb;
1443 struct txgbe_rx_desc rxd;
1456 rx_id = rxq->rx_tail;
1457 rx_ring = rxq->rx_ring;
1458 sw_ring = rxq->sw_ring;
1459 struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1460 while (nb_rx < nb_pkts) {
1462 * The order of operations here is important as the DD status
1463 * bit must not be read after any other descriptor fields.
1464 * rx_ring and rxdp are pointing to volatile data so the order
1465 * of accesses cannot be reordered by the compiler. If they were
1466 * not volatile, they could be reordered which could lead to
1467 * using invalid descriptor fields when read from rxd.
1469 rxdp = &rx_ring[rx_id];
1470 staterr = rxdp->qw1.lo.status;
1471 if (!(staterr & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
1478 * If the TXGBE_RXD_STAT_EOP flag is not set, the RX packet
1479 * is likely to be invalid and to be dropped by the various
1480 * validation checks performed by the network stack.
1482 * Allocate a new mbuf to replenish the RX ring descriptor.
1483 * If the allocation fails:
1484 * - arrange for that RX descriptor to be the first one
1485 * being parsed the next time the receive function is
1486 * invoked [on the same queue].
1488 * - Stop parsing the RX ring and return immediately.
1490 * This policy do not drop the packet received in the RX
1491 * descriptor for which the allocation of a new mbuf failed.
1492 * Thus, it allows that packet to be later retrieved if
1493 * mbuf have been freed in the mean time.
1494 * As a side effect, holding RX descriptors instead of
1495 * systematically giving them back to the NIC may lead to
1496 * RX ring exhaustion situations.
1497 * However, the NIC can gracefully prevent such situations
1498 * to happen by sending specific "back-pressure" flow control
1499 * frames to its peer(s).
1501 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1502 "ext_err_stat=0x%08x pkt_len=%u",
1503 (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1504 (uint16_t)rx_id, (uint32_t)staterr,
1505 (uint16_t)rte_le_to_cpu_16(rxd.qw1.hi.len));
1507 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1509 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1510 "queue_id=%u", (uint16_t)rxq->port_id,
1511 (uint16_t)rxq->queue_id);
1512 dev->data->rx_mbuf_alloc_failed++;
1517 rxe = &sw_ring[rx_id];
1519 if (rx_id == rxq->nb_rx_desc)
1522 /* Prefetch next mbuf while processing current one. */
1523 rte_txgbe_prefetch(sw_ring[rx_id].mbuf);
1526 * When next RX descriptor is on a cache-line boundary,
1527 * prefetch the next 4 RX descriptors and the next 8 pointers
1530 if ((rx_id & 0x3) == 0) {
1531 rte_txgbe_prefetch(&rx_ring[rx_id]);
1532 rte_txgbe_prefetch(&sw_ring[rx_id]);
1537 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1538 TXGBE_RXD_HDRADDR(rxdp, 0);
1539 TXGBE_RXD_PKTADDR(rxdp, dma_addr);
1542 * Initialize the returned mbuf.
1543 * 1) setup generic mbuf fields:
1544 * - number of segments,
1547 * - RX port identifier.
1548 * 2) integrate hardware offload data, if any:
1549 * - RSS flag & hash,
1550 * - IP checksum flag,
1551 * - VLAN TCI, if any,
1554 pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.qw1.hi.len) -
1556 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1557 rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
1560 rxm->pkt_len = pkt_len;
1561 rxm->data_len = pkt_len;
1562 rxm->port = rxq->port_id;
1564 pkt_info = rte_le_to_cpu_32(rxd.qw0.dw0);
1565 /* Only valid if PKT_RX_VLAN set in pkt_flags */
1566 rxm->vlan_tci = rte_le_to_cpu_16(rxd.qw1.hi.tag);
1568 pkt_flags = rx_desc_status_to_pkt_flags(staterr,
1570 pkt_flags |= rx_desc_error_to_pkt_flags(staterr);
1571 pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1572 rxm->ol_flags = pkt_flags;
1573 rxm->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1574 rxq->pkt_type_mask);
1576 if (likely(pkt_flags & PKT_RX_RSS_HASH)) {
1577 rxm->hash.rss = rte_le_to_cpu_32(rxd.qw0.dw1);
1578 } else if (pkt_flags & PKT_RX_FDIR) {
1579 rxm->hash.fdir.hash =
1580 rte_le_to_cpu_16(rxd.qw0.hi.csum) &
1581 TXGBE_ATR_HASH_MASK;
1582 rxm->hash.fdir.id = rte_le_to_cpu_16(rxd.qw0.hi.ipid);
1585 * Store the mbuf address into the next entry of the array
1586 * of returned packets.
1588 rx_pkts[nb_rx++] = rxm;
1590 rxq->rx_tail = rx_id;
1593 * If the number of free RX descriptors is greater than the RX free
1594 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1596 * Update the RDT with the value of the last processed RX descriptor
1597 * minus 1, to guarantee that the RDT register is never equal to the
1598 * RDH register, which creates a "full" ring situation from the
1599 * hardware point of view...
1601 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
1602 if (nb_hold > rxq->rx_free_thresh) {
1603 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1604 "nb_hold=%u nb_rx=%u",
1605 (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
1606 (uint16_t)rx_id, (uint16_t)nb_hold,
1608 rx_id = (uint16_t)((rx_id == 0) ?
1609 (rxq->nb_rx_desc - 1) : (rx_id - 1));
1610 txgbe_set32(rxq->rdt_reg_addr, rx_id);
1613 rxq->nb_rx_hold = nb_hold;
1618 * txgbe_fill_cluster_head_buf - fill the first mbuf of the returned packet
1620 * Fill the following info in the HEAD buffer of the Rx cluster:
1621 * - RX port identifier
1622 * - hardware offload data, if any:
1624 * - IP checksum flag
1625 * - VLAN TCI, if any
1627 * @head HEAD of the packet cluster
1628 * @desc HW descriptor to get data from
1629 * @rxq Pointer to the Rx queue
1632 txgbe_fill_cluster_head_buf(struct rte_mbuf *head, struct txgbe_rx_desc *desc,
1633 struct txgbe_rx_queue *rxq, uint32_t staterr)
1638 head->port = rxq->port_id;
1640 /* The vlan_tci field is only valid when PKT_RX_VLAN is
1641 * set in the pkt_flags field.
1643 head->vlan_tci = rte_le_to_cpu_16(desc->qw1.hi.tag);
1644 pkt_info = rte_le_to_cpu_32(desc->qw0.dw0);
1645 pkt_flags = rx_desc_status_to_pkt_flags(staterr, rxq->vlan_flags);
1646 pkt_flags |= rx_desc_error_to_pkt_flags(staterr);
1647 pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
1648 head->ol_flags = pkt_flags;
1649 head->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
1650 rxq->pkt_type_mask);
1652 if (likely(pkt_flags & PKT_RX_RSS_HASH)) {
1653 head->hash.rss = rte_le_to_cpu_32(desc->qw0.dw1);
1654 } else if (pkt_flags & PKT_RX_FDIR) {
1655 head->hash.fdir.hash = rte_le_to_cpu_16(desc->qw0.hi.csum)
1656 & TXGBE_ATR_HASH_MASK;
1657 head->hash.fdir.id = rte_le_to_cpu_16(desc->qw0.hi.ipid);
1662 * txgbe_recv_pkts_lro - receive handler for and LRO case.
1664 * @rx_queue Rx queue handle
1665 * @rx_pkts table of received packets
1666 * @nb_pkts size of rx_pkts table
1667 * @bulk_alloc if TRUE bulk allocation is used for a HW ring refilling
1669 * Handles the Rx HW ring completions when RSC feature is configured. Uses an
1670 * additional ring of txgbe_rsc_entry's that will hold the relevant RSC info.
1672 * We use the same logic as in Linux and in FreeBSD txgbe drivers:
1673 * 1) When non-EOP RSC completion arrives:
1674 * a) Update the HEAD of the current RSC aggregation cluster with the new
1675 * segment's data length.
1676 * b) Set the "next" pointer of the current segment to point to the segment
1677 * at the NEXTP index.
1678 * c) Pass the HEAD of RSC aggregation cluster on to the next NEXTP entry
1679 * in the sw_rsc_ring.
1680 * 2) When EOP arrives we just update the cluster's total length and offload
1681 * flags and deliver the cluster up to the upper layers. In our case - put it
1682 * in the rx_pkts table.
1684 * Returns the number of received packets/clusters (according to the "bulk
1685 * receive" interface).
1687 static inline uint16_t
1688 txgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts,
1691 struct txgbe_rx_queue *rxq = rx_queue;
1692 struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
1693 volatile struct txgbe_rx_desc *rx_ring = rxq->rx_ring;
1694 struct txgbe_rx_entry *sw_ring = rxq->sw_ring;
1695 struct txgbe_scattered_rx_entry *sw_sc_ring = rxq->sw_sc_ring;
1696 uint16_t rx_id = rxq->rx_tail;
1698 uint16_t nb_hold = rxq->nb_rx_hold;
1699 uint16_t prev_id = rxq->rx_tail;
1701 while (nb_rx < nb_pkts) {
1703 struct txgbe_rx_entry *rxe;
1704 struct txgbe_scattered_rx_entry *sc_entry;
1705 struct txgbe_scattered_rx_entry *next_sc_entry = NULL;
1706 struct txgbe_rx_entry *next_rxe = NULL;
1707 struct rte_mbuf *first_seg;
1708 struct rte_mbuf *rxm;
1709 struct rte_mbuf *nmb = NULL;
1710 struct txgbe_rx_desc rxd;
1713 volatile struct txgbe_rx_desc *rxdp;
1718 * The code in this whole file uses the volatile pointer to
1719 * ensure the read ordering of the status and the rest of the
1720 * descriptor fields (on the compiler level only!!!). This is so
1721 * UGLY - why not to just use the compiler barrier instead? DPDK
1722 * even has the rte_compiler_barrier() for that.
1724 * But most importantly this is just wrong because this doesn't
1725 * ensure memory ordering in a general case at all. For
1726 * instance, DPDK is supposed to work on Power CPUs where
1727 * compiler barrier may just not be enough!
1729 * I tried to write only this function properly to have a
1730 * starting point (as a part of an LRO/RSC series) but the
1731 * compiler cursed at me when I tried to cast away the
1732 * "volatile" from rx_ring (yes, it's volatile too!!!). So, I'm
1733 * keeping it the way it is for now.
1735 * The code in this file is broken in so many other places and
1736 * will just not work on a big endian CPU anyway therefore the
1737 * lines below will have to be revisited together with the rest
1741 * - Get rid of "volatile" and let the compiler do its job.
1742 * - Use the proper memory barrier (rte_rmb()) to ensure the
1743 * memory ordering below.
1745 rxdp = &rx_ring[rx_id];
1746 staterr = rte_le_to_cpu_32(rxdp->qw1.lo.status);
1748 if (!(staterr & TXGBE_RXD_STAT_DD))
1753 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
1754 "staterr=0x%x data_len=%u",
1755 rxq->port_id, rxq->queue_id, rx_id, staterr,
1756 rte_le_to_cpu_16(rxd.qw1.hi.len));
1759 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
1761 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed "
1762 "port_id=%u queue_id=%u",
1763 rxq->port_id, rxq->queue_id);
1765 dev->data->rx_mbuf_alloc_failed++;
1768 } else if (nb_hold > rxq->rx_free_thresh) {
1769 uint16_t next_rdt = rxq->rx_free_trigger;
1771 if (!txgbe_rx_alloc_bufs(rxq, false)) {
1773 txgbe_set32_relaxed(rxq->rdt_reg_addr,
1775 nb_hold -= rxq->rx_free_thresh;
1777 PMD_RX_LOG(DEBUG, "RX bulk alloc failed "
1778 "port_id=%u queue_id=%u",
1779 rxq->port_id, rxq->queue_id);
1781 dev->data->rx_mbuf_alloc_failed++;
1787 rxe = &sw_ring[rx_id];
1788 eop = staterr & TXGBE_RXD_STAT_EOP;
1790 next_id = rx_id + 1;
1791 if (next_id == rxq->nb_rx_desc)
1794 /* Prefetch next mbuf while processing current one. */
1795 rte_txgbe_prefetch(sw_ring[next_id].mbuf);
1798 * When next RX descriptor is on a cache-line boundary,
1799 * prefetch the next 4 RX descriptors and the next 4 pointers
1802 if ((next_id & 0x3) == 0) {
1803 rte_txgbe_prefetch(&rx_ring[next_id]);
1804 rte_txgbe_prefetch(&sw_ring[next_id]);
1811 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1813 * Update RX descriptor with the physical address of the
1814 * new data buffer of the new allocated mbuf.
1818 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1819 TXGBE_RXD_HDRADDR(rxdp, 0);
1820 TXGBE_RXD_PKTADDR(rxdp, dma);
1826 * Set data length & data buffer address of mbuf.
1828 data_len = rte_le_to_cpu_16(rxd.qw1.hi.len);
1829 rxm->data_len = data_len;
1834 * Get next descriptor index:
1835 * - For RSC it's in the NEXTP field.
1836 * - For a scattered packet - it's just a following
1839 if (TXGBE_RXD_RSCCNT(rxd.qw0.dw0))
1840 nextp_id = TXGBE_RXD_NEXTP(staterr);
1844 next_sc_entry = &sw_sc_ring[nextp_id];
1845 next_rxe = &sw_ring[nextp_id];
1846 rte_txgbe_prefetch(next_rxe);
1849 sc_entry = &sw_sc_ring[rx_id];
1850 first_seg = sc_entry->fbuf;
1851 sc_entry->fbuf = NULL;
1854 * If this is the first buffer of the received packet,
1855 * set the pointer to the first mbuf of the packet and
1856 * initialize its context.
1857 * Otherwise, update the total length and the number of segments
1858 * of the current scattered packet, and update the pointer to
1859 * the last mbuf of the current packet.
1861 if (first_seg == NULL) {
1863 first_seg->pkt_len = data_len;
1864 first_seg->nb_segs = 1;
1866 first_seg->pkt_len += data_len;
1867 first_seg->nb_segs++;
1874 * If this is not the last buffer of the received packet, update
1875 * the pointer to the first mbuf at the NEXTP entry in the
1876 * sw_sc_ring and continue to parse the RX ring.
1878 if (!eop && next_rxe) {
1879 rxm->next = next_rxe->mbuf;
1880 next_sc_entry->fbuf = first_seg;
1884 /* Initialize the first mbuf of the returned packet */
1885 txgbe_fill_cluster_head_buf(first_seg, &rxd, rxq, staterr);
1888 * Deal with the case, when HW CRC srip is disabled.
1889 * That can't happen when LRO is enabled, but still could
1890 * happen for scattered RX mode.
1892 first_seg->pkt_len -= rxq->crc_len;
1893 if (unlikely(rxm->data_len <= rxq->crc_len)) {
1894 struct rte_mbuf *lp;
1896 for (lp = first_seg; lp->next != rxm; lp = lp->next)
1899 first_seg->nb_segs--;
1900 lp->data_len -= rxq->crc_len - rxm->data_len;
1902 rte_pktmbuf_free_seg(rxm);
1904 rxm->data_len -= rxq->crc_len;
1907 /* Prefetch data of first segment, if configured to do so. */
1908 rte_packet_prefetch((char *)first_seg->buf_addr +
1909 first_seg->data_off);
1912 * Store the mbuf address into the next entry of the array
1913 * of returned packets.
1915 rx_pkts[nb_rx++] = first_seg;
1919 * Record index of the next RX descriptor to probe.
1921 rxq->rx_tail = rx_id;
1924 * If the number of free RX descriptors is greater than the RX free
1925 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1927 * Update the RDT with the value of the last processed RX descriptor
1928 * minus 1, to guarantee that the RDT register is never equal to the
1929 * RDH register, which creates a "full" ring situation from the
1930 * hardware point of view...
1932 if (!bulk_alloc && nb_hold > rxq->rx_free_thresh) {
1933 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1934 "nb_hold=%u nb_rx=%u",
1935 rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
1938 txgbe_set32_relaxed(rxq->rdt_reg_addr, prev_id);
1942 rxq->nb_rx_hold = nb_hold;
1947 txgbe_recv_pkts_lro_single_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1950 return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, false);
1954 txgbe_recv_pkts_lro_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
1957 return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, true);
1961 txgbe_get_rx_queue_offloads(struct rte_eth_dev *dev __rte_unused)
1963 return DEV_RX_OFFLOAD_VLAN_STRIP;
1967 txgbe_get_rx_port_offloads(struct rte_eth_dev *dev)
1970 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1971 struct rte_eth_dev_sriov *sriov = &RTE_ETH_DEV_SRIOV(dev);
1973 offloads = DEV_RX_OFFLOAD_IPV4_CKSUM |
1974 DEV_RX_OFFLOAD_UDP_CKSUM |
1975 DEV_RX_OFFLOAD_TCP_CKSUM |
1976 DEV_RX_OFFLOAD_KEEP_CRC |
1977 DEV_RX_OFFLOAD_JUMBO_FRAME |
1978 DEV_RX_OFFLOAD_VLAN_FILTER |
1979 DEV_RX_OFFLOAD_RSS_HASH |
1980 DEV_RX_OFFLOAD_SCATTER;
1982 if (!txgbe_is_vf(dev))
1983 offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1984 DEV_RX_OFFLOAD_QINQ_STRIP |
1985 DEV_RX_OFFLOAD_VLAN_EXTEND);
1988 * RSC is only supported by PF devices in a non-SR-IOV
1991 if (hw->mac.type == txgbe_mac_raptor && !sriov->active)
1992 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
1994 if (hw->mac.type == txgbe_mac_raptor)
1995 offloads |= DEV_RX_OFFLOAD_MACSEC_STRIP;
1997 offloads |= DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
1999 #ifdef RTE_LIB_SECURITY
2000 if (dev->security_ctx)
2001 offloads |= DEV_RX_OFFLOAD_SECURITY;
2007 static void __rte_cold
2008 txgbe_tx_queue_release_mbufs(struct txgbe_tx_queue *txq)
2012 if (txq->sw_ring != NULL) {
2013 for (i = 0; i < txq->nb_tx_desc; i++) {
2014 if (txq->sw_ring[i].mbuf != NULL) {
2015 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2016 txq->sw_ring[i].mbuf = NULL;
2023 txgbe_tx_done_cleanup_full(struct txgbe_tx_queue *txq, uint32_t free_cnt)
2025 struct txgbe_tx_entry *swr_ring = txq->sw_ring;
2026 uint16_t i, tx_last, tx_id;
2027 uint16_t nb_tx_free_last;
2028 uint16_t nb_tx_to_clean;
2031 /* Start free mbuf from the next of tx_tail */
2032 tx_last = txq->tx_tail;
2033 tx_id = swr_ring[tx_last].next_id;
2035 if (txq->nb_tx_free == 0 && txgbe_xmit_cleanup(txq))
2038 nb_tx_to_clean = txq->nb_tx_free;
2039 nb_tx_free_last = txq->nb_tx_free;
2041 free_cnt = txq->nb_tx_desc;
2043 /* Loop through swr_ring to count the amount of
2044 * freeable mubfs and packets.
2046 for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2047 for (i = 0; i < nb_tx_to_clean &&
2048 pkt_cnt < free_cnt &&
2049 tx_id != tx_last; i++) {
2050 if (swr_ring[tx_id].mbuf != NULL) {
2051 rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2052 swr_ring[tx_id].mbuf = NULL;
2055 * last segment in the packet,
2056 * increment packet count
2058 pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
2061 tx_id = swr_ring[tx_id].next_id;
2064 if (pkt_cnt < free_cnt) {
2065 if (txgbe_xmit_cleanup(txq))
2068 nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2069 nb_tx_free_last = txq->nb_tx_free;
2073 return (int)pkt_cnt;
2077 txgbe_tx_done_cleanup_simple(struct txgbe_tx_queue *txq,
2082 if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2083 free_cnt = txq->nb_tx_desc;
2085 cnt = free_cnt - free_cnt % txq->tx_free_thresh;
2087 for (i = 0; i < cnt; i += n) {
2088 if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_free_thresh)
2091 n = txgbe_tx_free_bufs(txq);
2101 txgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt)
2103 struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
2104 if (txq->offloads == 0 &&
2105 #ifdef RTE_LIB_SECURITY
2106 !(txq->using_ipsec) &&
2108 txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST)
2109 return txgbe_tx_done_cleanup_simple(txq, free_cnt);
2111 return txgbe_tx_done_cleanup_full(txq, free_cnt);
2114 static void __rte_cold
2115 txgbe_tx_free_swring(struct txgbe_tx_queue *txq)
2118 txq->sw_ring != NULL)
2119 rte_free(txq->sw_ring);
2122 static void __rte_cold
2123 txgbe_tx_queue_release(struct txgbe_tx_queue *txq)
2125 if (txq != NULL && txq->ops != NULL) {
2126 txq->ops->release_mbufs(txq);
2127 txq->ops->free_swring(txq);
2133 txgbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2135 txgbe_tx_queue_release(dev->data->tx_queues[qid]);
2138 /* (Re)set dynamic txgbe_tx_queue fields to defaults */
2139 static void __rte_cold
2140 txgbe_reset_tx_queue(struct txgbe_tx_queue *txq)
2142 static const struct txgbe_tx_desc zeroed_desc = {0};
2143 struct txgbe_tx_entry *txe = txq->sw_ring;
2146 /* Zero out HW ring memory */
2147 for (i = 0; i < txq->nb_tx_desc; i++)
2148 txq->tx_ring[i] = zeroed_desc;
2150 /* Initialize SW ring entries */
2151 prev = (uint16_t)(txq->nb_tx_desc - 1);
2152 for (i = 0; i < txq->nb_tx_desc; i++) {
2153 volatile struct txgbe_tx_desc *txd = &txq->tx_ring[i];
2155 txd->dw3 = rte_cpu_to_le_32(TXGBE_TXD_DD);
2158 txe[prev].next_id = i;
2162 txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
2166 * Always allow 1 descriptor to be un-allocated to avoid
2167 * a H/W race condition
2169 txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2170 txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2172 memset((void *)&txq->ctx_cache, 0,
2173 TXGBE_CTX_NUM * sizeof(struct txgbe_ctx_info));
2176 static const struct txgbe_txq_ops def_txq_ops = {
2177 .release_mbufs = txgbe_tx_queue_release_mbufs,
2178 .free_swring = txgbe_tx_free_swring,
2179 .reset = txgbe_reset_tx_queue,
2182 /* Takes an ethdev and a queue and sets up the tx function to be used based on
2183 * the queue parameters. Used in tx_queue_setup by primary process and then
2184 * in dev_init by secondary process when attaching to an existing ethdev.
2187 txgbe_set_tx_function(struct rte_eth_dev *dev, struct txgbe_tx_queue *txq)
2189 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
2190 if (txq->offloads == 0 &&
2191 #ifdef RTE_LIB_SECURITY
2192 !(txq->using_ipsec) &&
2194 txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST) {
2195 PMD_INIT_LOG(DEBUG, "Using simple tx code path");
2196 dev->tx_pkt_burst = txgbe_xmit_pkts_simple;
2197 dev->tx_pkt_prepare = NULL;
2199 PMD_INIT_LOG(DEBUG, "Using full-featured tx code path");
2201 " - offloads = 0x%" PRIx64,
2204 " - tx_free_thresh = %lu [RTE_PMD_TXGBE_TX_MAX_BURST=%lu]",
2205 (unsigned long)txq->tx_free_thresh,
2206 (unsigned long)RTE_PMD_TXGBE_TX_MAX_BURST);
2207 dev->tx_pkt_burst = txgbe_xmit_pkts;
2208 dev->tx_pkt_prepare = txgbe_prep_pkts;
2213 txgbe_get_tx_queue_offloads(struct rte_eth_dev *dev)
2221 txgbe_get_tx_port_offloads(struct rte_eth_dev *dev)
2223 uint64_t tx_offload_capa;
2226 DEV_TX_OFFLOAD_VLAN_INSERT |
2227 DEV_TX_OFFLOAD_IPV4_CKSUM |
2228 DEV_TX_OFFLOAD_UDP_CKSUM |
2229 DEV_TX_OFFLOAD_TCP_CKSUM |
2230 DEV_TX_OFFLOAD_SCTP_CKSUM |
2231 DEV_TX_OFFLOAD_TCP_TSO |
2232 DEV_TX_OFFLOAD_UDP_TSO |
2233 DEV_TX_OFFLOAD_UDP_TNL_TSO |
2234 DEV_TX_OFFLOAD_IP_TNL_TSO |
2235 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
2236 DEV_TX_OFFLOAD_GRE_TNL_TSO |
2237 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
2238 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
2239 DEV_TX_OFFLOAD_MULTI_SEGS;
2241 if (!txgbe_is_vf(dev))
2242 tx_offload_capa |= DEV_TX_OFFLOAD_QINQ_INSERT;
2244 tx_offload_capa |= DEV_TX_OFFLOAD_MACSEC_INSERT;
2246 tx_offload_capa |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
2247 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
2249 #ifdef RTE_LIB_SECURITY
2250 if (dev->security_ctx)
2251 tx_offload_capa |= DEV_TX_OFFLOAD_SECURITY;
2253 return tx_offload_capa;
2257 txgbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
2260 unsigned int socket_id,
2261 const struct rte_eth_txconf *tx_conf)
2263 const struct rte_memzone *tz;
2264 struct txgbe_tx_queue *txq;
2265 struct txgbe_hw *hw;
2266 uint16_t tx_free_thresh;
2269 PMD_INIT_FUNC_TRACE();
2270 hw = TXGBE_DEV_HW(dev);
2272 offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2275 * Validate number of transmit descriptors.
2276 * It must not exceed hardware maximum, and must be multiple
2279 if (nb_desc % TXGBE_TXD_ALIGN != 0 ||
2280 nb_desc > TXGBE_RING_DESC_MAX ||
2281 nb_desc < TXGBE_RING_DESC_MIN) {
2286 * The TX descriptor ring will be cleaned after txq->tx_free_thresh
2287 * descriptors are used or if the number of descriptors required
2288 * to transmit a packet is greater than the number of free TX
2290 * One descriptor in the TX ring is used as a sentinel to avoid a
2291 * H/W race condition, hence the maximum threshold constraints.
2292 * When set to zero use default values.
2294 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2295 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2296 if (tx_free_thresh >= (nb_desc - 3)) {
2297 PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the number of "
2298 "TX descriptors minus 3. (tx_free_thresh=%u "
2299 "port=%d queue=%d)",
2300 (unsigned int)tx_free_thresh,
2301 (int)dev->data->port_id, (int)queue_idx);
2305 if ((nb_desc % tx_free_thresh) != 0) {
2306 PMD_INIT_LOG(ERR, "tx_free_thresh must be a divisor of the "
2307 "number of TX descriptors. (tx_free_thresh=%u "
2308 "port=%d queue=%d)", (unsigned int)tx_free_thresh,
2309 (int)dev->data->port_id, (int)queue_idx);
2313 /* Free memory prior to re-allocation if needed... */
2314 if (dev->data->tx_queues[queue_idx] != NULL) {
2315 txgbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
2316 dev->data->tx_queues[queue_idx] = NULL;
2319 /* First allocate the tx queue data structure */
2320 txq = rte_zmalloc_socket("ethdev TX queue",
2321 sizeof(struct txgbe_tx_queue),
2322 RTE_CACHE_LINE_SIZE, socket_id);
2327 * Allocate TX ring hardware descriptors. A memzone large enough to
2328 * handle the maximum ring size is allocated in order to allow for
2329 * resizing in later calls to the queue setup function.
2331 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
2332 sizeof(struct txgbe_tx_desc) * TXGBE_RING_DESC_MAX,
2333 TXGBE_ALIGN, socket_id);
2335 txgbe_tx_queue_release(txq);
2339 txq->nb_tx_desc = nb_desc;
2340 txq->tx_free_thresh = tx_free_thresh;
2341 txq->pthresh = tx_conf->tx_thresh.pthresh;
2342 txq->hthresh = tx_conf->tx_thresh.hthresh;
2343 txq->wthresh = tx_conf->tx_thresh.wthresh;
2344 txq->queue_id = queue_idx;
2345 txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2346 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2347 txq->port_id = dev->data->port_id;
2348 txq->offloads = offloads;
2349 txq->ops = &def_txq_ops;
2350 txq->tx_deferred_start = tx_conf->tx_deferred_start;
2351 #ifdef RTE_LIB_SECURITY
2352 txq->using_ipsec = !!(dev->data->dev_conf.txmode.offloads &
2353 DEV_TX_OFFLOAD_SECURITY);
2356 /* Modification to set tail pointer for virtual function
2357 * if vf is detected.
2359 if (hw->mac.type == txgbe_mac_raptor_vf) {
2360 txq->tdt_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXWP(queue_idx));
2361 txq->tdc_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXCFG(queue_idx));
2363 txq->tdt_reg_addr = TXGBE_REG_ADDR(hw,
2364 TXGBE_TXWP(txq->reg_idx));
2365 txq->tdc_reg_addr = TXGBE_REG_ADDR(hw,
2366 TXGBE_TXCFG(txq->reg_idx));
2369 txq->tx_ring_phys_addr = TMZ_PADDR(tz);
2370 txq->tx_ring = (struct txgbe_tx_desc *)TMZ_VADDR(tz);
2372 /* Allocate software ring */
2373 txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
2374 sizeof(struct txgbe_tx_entry) * nb_desc,
2375 RTE_CACHE_LINE_SIZE, socket_id);
2376 if (txq->sw_ring == NULL) {
2377 txgbe_tx_queue_release(txq);
2380 PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
2381 txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
2383 /* set up scalar TX function as appropriate */
2384 txgbe_set_tx_function(dev, txq);
2386 txq->ops->reset(txq);
2388 dev->data->tx_queues[queue_idx] = txq;
2394 * txgbe_free_sc_cluster - free the not-yet-completed scattered cluster
2396 * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
2397 * in the sw_rsc_ring is not set to NULL but rather points to the next
2398 * mbuf of this RSC aggregation (that has not been completed yet and still
2399 * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
2400 * will just free first "nb_segs" segments of the cluster explicitly by calling
2401 * an rte_pktmbuf_free_seg().
2403 * @m scattered cluster head
2405 static void __rte_cold
2406 txgbe_free_sc_cluster(struct rte_mbuf *m)
2408 uint16_t i, nb_segs = m->nb_segs;
2409 struct rte_mbuf *next_seg;
2411 for (i = 0; i < nb_segs; i++) {
2413 rte_pktmbuf_free_seg(m);
2418 static void __rte_cold
2419 txgbe_rx_queue_release_mbufs(struct txgbe_rx_queue *rxq)
2423 if (rxq->sw_ring != NULL) {
2424 for (i = 0; i < rxq->nb_rx_desc; i++) {
2425 if (rxq->sw_ring[i].mbuf != NULL) {
2426 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2427 rxq->sw_ring[i].mbuf = NULL;
2430 if (rxq->rx_nb_avail) {
2431 for (i = 0; i < rxq->rx_nb_avail; ++i) {
2432 struct rte_mbuf *mb;
2434 mb = rxq->rx_stage[rxq->rx_next_avail + i];
2435 rte_pktmbuf_free_seg(mb);
2437 rxq->rx_nb_avail = 0;
2441 if (rxq->sw_sc_ring)
2442 for (i = 0; i < rxq->nb_rx_desc; i++)
2443 if (rxq->sw_sc_ring[i].fbuf) {
2444 txgbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
2445 rxq->sw_sc_ring[i].fbuf = NULL;
2449 static void __rte_cold
2450 txgbe_rx_queue_release(struct txgbe_rx_queue *rxq)
2453 txgbe_rx_queue_release_mbufs(rxq);
2454 rte_free(rxq->sw_ring);
2455 rte_free(rxq->sw_sc_ring);
2461 txgbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2463 txgbe_rx_queue_release(dev->data->rx_queues[qid]);
2467 * Check if Rx Burst Bulk Alloc function can be used.
2469 * 0: the preconditions are satisfied and the bulk allocation function
2471 * -EINVAL: the preconditions are NOT satisfied and the default Rx burst
2472 * function must be used.
2474 static inline int __rte_cold
2475 check_rx_burst_bulk_alloc_preconditions(struct txgbe_rx_queue *rxq)
2480 * Make sure the following pre-conditions are satisfied:
2481 * rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST
2482 * rxq->rx_free_thresh < rxq->nb_rx_desc
2483 * (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
2484 * Scattered packets are not supported. This should be checked
2485 * outside of this function.
2487 if (!(rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST)) {
2488 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2489 "rxq->rx_free_thresh=%d, "
2490 "RTE_PMD_TXGBE_RX_MAX_BURST=%d",
2491 rxq->rx_free_thresh, RTE_PMD_TXGBE_RX_MAX_BURST);
2493 } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
2494 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2495 "rxq->rx_free_thresh=%d, "
2496 "rxq->nb_rx_desc=%d",
2497 rxq->rx_free_thresh, rxq->nb_rx_desc);
2499 } else if (!((rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)) {
2500 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
2501 "rxq->nb_rx_desc=%d, "
2502 "rxq->rx_free_thresh=%d",
2503 rxq->nb_rx_desc, rxq->rx_free_thresh);
2510 /* Reset dynamic txgbe_rx_queue fields back to defaults */
2511 static void __rte_cold
2512 txgbe_reset_rx_queue(struct txgbe_adapter *adapter, struct txgbe_rx_queue *rxq)
2514 static const struct txgbe_rx_desc zeroed_desc = {
2515 {{0}, {0} }, {{0}, {0} } };
2517 uint16_t len = rxq->nb_rx_desc;
2520 * By default, the Rx queue setup function allocates enough memory for
2521 * TXGBE_RING_DESC_MAX. The Rx Burst bulk allocation function requires
2522 * extra memory at the end of the descriptor ring to be zero'd out.
2524 if (adapter->rx_bulk_alloc_allowed)
2525 /* zero out extra memory */
2526 len += RTE_PMD_TXGBE_RX_MAX_BURST;
2529 * Zero out HW ring memory. Zero out extra memory at the end of
2530 * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
2531 * reads extra memory as zeros.
2533 for (i = 0; i < len; i++)
2534 rxq->rx_ring[i] = zeroed_desc;
2537 * initialize extra software ring entries. Space for these extra
2538 * entries is always allocated
2540 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2541 for (i = rxq->nb_rx_desc; i < len; ++i)
2542 rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
2544 rxq->rx_nb_avail = 0;
2545 rxq->rx_next_avail = 0;
2546 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2548 rxq->nb_rx_hold = 0;
2549 rxq->pkt_first_seg = NULL;
2550 rxq->pkt_last_seg = NULL;
2554 txgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
2557 unsigned int socket_id,
2558 const struct rte_eth_rxconf *rx_conf,
2559 struct rte_mempool *mp)
2561 const struct rte_memzone *rz;
2562 struct txgbe_rx_queue *rxq;
2563 struct txgbe_hw *hw;
2565 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
2568 PMD_INIT_FUNC_TRACE();
2569 hw = TXGBE_DEV_HW(dev);
2571 offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
2574 * Validate number of receive descriptors.
2575 * It must not exceed hardware maximum, and must be multiple
2578 if (nb_desc % TXGBE_RXD_ALIGN != 0 ||
2579 nb_desc > TXGBE_RING_DESC_MAX ||
2580 nb_desc < TXGBE_RING_DESC_MIN) {
2584 /* Free memory prior to re-allocation if needed... */
2585 if (dev->data->rx_queues[queue_idx] != NULL) {
2586 txgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
2587 dev->data->rx_queues[queue_idx] = NULL;
2590 /* First allocate the rx queue data structure */
2591 rxq = rte_zmalloc_socket("ethdev RX queue",
2592 sizeof(struct txgbe_rx_queue),
2593 RTE_CACHE_LINE_SIZE, socket_id);
2597 rxq->nb_rx_desc = nb_desc;
2598 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
2599 rxq->queue_id = queue_idx;
2600 rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
2601 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
2602 rxq->port_id = dev->data->port_id;
2603 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)
2604 rxq->crc_len = RTE_ETHER_CRC_LEN;
2607 rxq->drop_en = rx_conf->rx_drop_en;
2608 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
2609 rxq->offloads = offloads;
2612 * The packet type in RX descriptor is different for different NICs.
2613 * So set different masks for different NICs.
2615 rxq->pkt_type_mask = TXGBE_PTID_MASK;
2618 * Allocate RX ring hardware descriptors. A memzone large enough to
2619 * handle the maximum ring size is allocated in order to allow for
2620 * resizing in later calls to the queue setup function.
2622 rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
2623 RX_RING_SZ, TXGBE_ALIGN, socket_id);
2625 txgbe_rx_queue_release(rxq);
2630 * Zero init all the descriptors in the ring.
2632 memset(rz->addr, 0, RX_RING_SZ);
2635 * Modified to setup VFRDT for Virtual Function
2637 if (hw->mac.type == txgbe_mac_raptor_vf) {
2639 TXGBE_REG_ADDR(hw, TXGBE_RXWP(queue_idx));
2641 TXGBE_REG_ADDR(hw, TXGBE_RXRP(queue_idx));
2644 TXGBE_REG_ADDR(hw, TXGBE_RXWP(rxq->reg_idx));
2646 TXGBE_REG_ADDR(hw, TXGBE_RXRP(rxq->reg_idx));
2649 rxq->rx_ring_phys_addr = TMZ_PADDR(rz);
2650 rxq->rx_ring = (struct txgbe_rx_desc *)TMZ_VADDR(rz);
2653 * Certain constraints must be met in order to use the bulk buffer
2654 * allocation Rx burst function. If any of Rx queues doesn't meet them
2655 * the feature should be disabled for the whole port.
2657 if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
2658 PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Rx Bulk Alloc "
2659 "preconditions - canceling the feature for "
2660 "the whole port[%d]",
2661 rxq->queue_id, rxq->port_id);
2662 adapter->rx_bulk_alloc_allowed = false;
2666 * Allocate software ring. Allow for space at the end of the
2667 * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
2668 * function does not access an invalid memory region.
2671 if (adapter->rx_bulk_alloc_allowed)
2672 len += RTE_PMD_TXGBE_RX_MAX_BURST;
2674 rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
2675 sizeof(struct txgbe_rx_entry) * len,
2676 RTE_CACHE_LINE_SIZE, socket_id);
2677 if (!rxq->sw_ring) {
2678 txgbe_rx_queue_release(rxq);
2683 * Always allocate even if it's not going to be needed in order to
2684 * simplify the code.
2686 * This ring is used in LRO and Scattered Rx cases and Scattered Rx may
2687 * be requested in txgbe_dev_rx_init(), which is called later from
2691 rte_zmalloc_socket("rxq->sw_sc_ring",
2692 sizeof(struct txgbe_scattered_rx_entry) * len,
2693 RTE_CACHE_LINE_SIZE, socket_id);
2694 if (!rxq->sw_sc_ring) {
2695 txgbe_rx_queue_release(rxq);
2699 PMD_INIT_LOG(DEBUG, "sw_ring=%p sw_sc_ring=%p hw_ring=%p "
2700 "dma_addr=0x%" PRIx64,
2701 rxq->sw_ring, rxq->sw_sc_ring, rxq->rx_ring,
2702 rxq->rx_ring_phys_addr);
2704 dev->data->rx_queues[queue_idx] = rxq;
2706 txgbe_reset_rx_queue(adapter, rxq);
2712 txgbe_dev_rx_queue_count(void *rx_queue)
2714 #define TXGBE_RXQ_SCAN_INTERVAL 4
2715 volatile struct txgbe_rx_desc *rxdp;
2716 struct txgbe_rx_queue *rxq;
2720 rxdp = &rxq->rx_ring[rxq->rx_tail];
2722 while ((desc < rxq->nb_rx_desc) &&
2723 (rxdp->qw1.lo.status &
2724 rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))) {
2725 desc += TXGBE_RXQ_SCAN_INTERVAL;
2726 rxdp += TXGBE_RXQ_SCAN_INTERVAL;
2727 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
2728 rxdp = &(rxq->rx_ring[rxq->rx_tail +
2729 desc - rxq->nb_rx_desc]);
2736 txgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
2738 struct txgbe_rx_queue *rxq = rx_queue;
2739 volatile uint32_t *status;
2740 uint32_t nb_hold, desc;
2742 if (unlikely(offset >= rxq->nb_rx_desc))
2745 nb_hold = rxq->nb_rx_hold;
2746 if (offset >= rxq->nb_rx_desc - nb_hold)
2747 return RTE_ETH_RX_DESC_UNAVAIL;
2749 desc = rxq->rx_tail + offset;
2750 if (desc >= rxq->nb_rx_desc)
2751 desc -= rxq->nb_rx_desc;
2753 status = &rxq->rx_ring[desc].qw1.lo.status;
2754 if (*status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))
2755 return RTE_ETH_RX_DESC_DONE;
2757 return RTE_ETH_RX_DESC_AVAIL;
2761 txgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
2763 struct txgbe_tx_queue *txq = tx_queue;
2764 volatile uint32_t *status;
2767 if (unlikely(offset >= txq->nb_tx_desc))
2770 desc = txq->tx_tail + offset;
2771 if (desc >= txq->nb_tx_desc) {
2772 desc -= txq->nb_tx_desc;
2773 if (desc >= txq->nb_tx_desc)
2774 desc -= txq->nb_tx_desc;
2777 status = &txq->tx_ring[desc].dw3;
2778 if (*status & rte_cpu_to_le_32(TXGBE_TXD_DD))
2779 return RTE_ETH_TX_DESC_DONE;
2781 return RTE_ETH_TX_DESC_FULL;
2785 txgbe_dev_clear_queues(struct rte_eth_dev *dev)
2788 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
2790 PMD_INIT_FUNC_TRACE();
2792 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2793 struct txgbe_tx_queue *txq = dev->data->tx_queues[i];
2796 txq->ops->release_mbufs(txq);
2797 txq->ops->reset(txq);
2801 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2802 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
2805 txgbe_rx_queue_release_mbufs(rxq);
2806 txgbe_reset_rx_queue(adapter, rxq);
2812 txgbe_dev_free_queues(struct rte_eth_dev *dev)
2816 PMD_INIT_FUNC_TRACE();
2818 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2819 txgbe_dev_rx_queue_release(dev, i);
2820 dev->data->rx_queues[i] = NULL;
2822 dev->data->nb_rx_queues = 0;
2824 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2825 txgbe_dev_tx_queue_release(dev, i);
2826 dev->data->tx_queues[i] = NULL;
2828 dev->data->nb_tx_queues = 0;
2832 * Receive Side Scaling (RSS)
2835 * The source and destination IP addresses of the IP header and the source
2836 * and destination ports of TCP/UDP headers, if any, of received packets are
2837 * hashed against a configurable random key to compute a 32-bit RSS hash result.
2838 * The seven (7) LSBs of the 32-bit hash result are used as an index into a
2839 * 128-entry redirection table (RETA). Each entry of the RETA provides a 3-bit
2840 * RSS output index which is used as the RX queue index where to store the
2842 * The following output is supplied in the RX write-back descriptor:
2843 * - 32-bit result of the Microsoft RSS hash function,
2844 * - 4-bit RSS type field.
2848 * Used as the default key.
2850 static uint8_t rss_intel_key[40] = {
2851 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
2852 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
2853 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
2854 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
2855 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
2859 txgbe_rss_disable(struct rte_eth_dev *dev)
2861 struct txgbe_hw *hw;
2863 hw = TXGBE_DEV_HW(dev);
2864 if (hw->mac.type == txgbe_mac_raptor_vf)
2865 wr32m(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_RSSENA, 0);
2867 wr32m(hw, TXGBE_RACTL, TXGBE_RACTL_RSSENA, 0);
2871 txgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
2872 struct rte_eth_rss_conf *rss_conf)
2874 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2881 if (!txgbe_rss_update_sp(hw->mac.type)) {
2882 PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
2887 hash_key = rss_conf->rss_key;
2889 /* Fill in RSS hash key */
2890 for (i = 0; i < 10; i++) {
2891 rss_key = LS32(hash_key[(i * 4) + 0], 0, 0xFF);
2892 rss_key |= LS32(hash_key[(i * 4) + 1], 8, 0xFF);
2893 rss_key |= LS32(hash_key[(i * 4) + 2], 16, 0xFF);
2894 rss_key |= LS32(hash_key[(i * 4) + 3], 24, 0xFF);
2895 wr32at(hw, TXGBE_REG_RSSKEY, i, rss_key);
2899 /* Set configured hashing protocols */
2900 rss_hf = rss_conf->rss_hf & TXGBE_RSS_OFFLOAD_ALL;
2901 if (hw->mac.type == txgbe_mac_raptor_vf) {
2902 mrqc = rd32(hw, TXGBE_VFPLCFG);
2903 mrqc &= ~TXGBE_VFPLCFG_RSSMASK;
2904 if (rss_hf & ETH_RSS_IPV4)
2905 mrqc |= TXGBE_VFPLCFG_RSSIPV4;
2906 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
2907 mrqc |= TXGBE_VFPLCFG_RSSIPV4TCP;
2908 if (rss_hf & ETH_RSS_IPV6 ||
2909 rss_hf & ETH_RSS_IPV6_EX)
2910 mrqc |= TXGBE_VFPLCFG_RSSIPV6;
2911 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP ||
2912 rss_hf & ETH_RSS_IPV6_TCP_EX)
2913 mrqc |= TXGBE_VFPLCFG_RSSIPV6TCP;
2914 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
2915 mrqc |= TXGBE_VFPLCFG_RSSIPV4UDP;
2916 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP ||
2917 rss_hf & ETH_RSS_IPV6_UDP_EX)
2918 mrqc |= TXGBE_VFPLCFG_RSSIPV6UDP;
2921 mrqc |= TXGBE_VFPLCFG_RSSENA;
2923 mrqc &= ~TXGBE_VFPLCFG_RSSENA;
2925 if (dev->data->nb_rx_queues > 3)
2926 mrqc |= TXGBE_VFPLCFG_RSSHASH(2);
2927 else if (dev->data->nb_rx_queues > 1)
2928 mrqc |= TXGBE_VFPLCFG_RSSHASH(1);
2930 wr32(hw, TXGBE_VFPLCFG, mrqc);
2932 mrqc = rd32(hw, TXGBE_RACTL);
2933 mrqc &= ~TXGBE_RACTL_RSSMASK;
2934 if (rss_hf & ETH_RSS_IPV4)
2935 mrqc |= TXGBE_RACTL_RSSIPV4;
2936 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
2937 mrqc |= TXGBE_RACTL_RSSIPV4TCP;
2938 if (rss_hf & ETH_RSS_IPV6 ||
2939 rss_hf & ETH_RSS_IPV6_EX)
2940 mrqc |= TXGBE_RACTL_RSSIPV6;
2941 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP ||
2942 rss_hf & ETH_RSS_IPV6_TCP_EX)
2943 mrqc |= TXGBE_RACTL_RSSIPV6TCP;
2944 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
2945 mrqc |= TXGBE_RACTL_RSSIPV4UDP;
2946 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP ||
2947 rss_hf & ETH_RSS_IPV6_UDP_EX)
2948 mrqc |= TXGBE_RACTL_RSSIPV6UDP;
2951 mrqc |= TXGBE_RACTL_RSSENA;
2953 mrqc &= ~TXGBE_RACTL_RSSENA;
2955 wr32(hw, TXGBE_RACTL, mrqc);
2962 txgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
2963 struct rte_eth_rss_conf *rss_conf)
2965 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2972 hash_key = rss_conf->rss_key;
2974 /* Return RSS hash key */
2975 for (i = 0; i < 10; i++) {
2976 rss_key = rd32at(hw, TXGBE_REG_RSSKEY, i);
2977 hash_key[(i * 4) + 0] = RS32(rss_key, 0, 0xFF);
2978 hash_key[(i * 4) + 1] = RS32(rss_key, 8, 0xFF);
2979 hash_key[(i * 4) + 2] = RS32(rss_key, 16, 0xFF);
2980 hash_key[(i * 4) + 3] = RS32(rss_key, 24, 0xFF);
2985 if (hw->mac.type == txgbe_mac_raptor_vf) {
2986 mrqc = rd32(hw, TXGBE_VFPLCFG);
2987 if (mrqc & TXGBE_VFPLCFG_RSSIPV4)
2988 rss_hf |= ETH_RSS_IPV4;
2989 if (mrqc & TXGBE_VFPLCFG_RSSIPV4TCP)
2990 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
2991 if (mrqc & TXGBE_VFPLCFG_RSSIPV6)
2992 rss_hf |= ETH_RSS_IPV6 |
2994 if (mrqc & TXGBE_VFPLCFG_RSSIPV6TCP)
2995 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP |
2996 ETH_RSS_IPV6_TCP_EX;
2997 if (mrqc & TXGBE_VFPLCFG_RSSIPV4UDP)
2998 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
2999 if (mrqc & TXGBE_VFPLCFG_RSSIPV6UDP)
3000 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP |
3001 ETH_RSS_IPV6_UDP_EX;
3002 if (!(mrqc & TXGBE_VFPLCFG_RSSENA))
3005 mrqc = rd32(hw, TXGBE_RACTL);
3006 if (mrqc & TXGBE_RACTL_RSSIPV4)
3007 rss_hf |= ETH_RSS_IPV4;
3008 if (mrqc & TXGBE_RACTL_RSSIPV4TCP)
3009 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
3010 if (mrqc & TXGBE_RACTL_RSSIPV6)
3011 rss_hf |= ETH_RSS_IPV6 |
3013 if (mrqc & TXGBE_RACTL_RSSIPV6TCP)
3014 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP |
3015 ETH_RSS_IPV6_TCP_EX;
3016 if (mrqc & TXGBE_RACTL_RSSIPV4UDP)
3017 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
3018 if (mrqc & TXGBE_RACTL_RSSIPV6UDP)
3019 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP |
3020 ETH_RSS_IPV6_UDP_EX;
3021 if (!(mrqc & TXGBE_RACTL_RSSENA))
3025 rss_hf &= TXGBE_RSS_OFFLOAD_ALL;
3027 rss_conf->rss_hf = rss_hf;
3032 txgbe_rss_configure(struct rte_eth_dev *dev)
3034 struct rte_eth_rss_conf rss_conf;
3035 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
3036 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3041 PMD_INIT_FUNC_TRACE();
3044 * Fill in redirection table
3045 * The byte-swap is needed because NIC registers are in
3046 * little-endian order.
3048 if (adapter->rss_reta_updated == 0) {
3050 for (i = 0, j = 0; i < ETH_RSS_RETA_SIZE_128; i++, j++) {
3051 if (j == dev->data->nb_rx_queues)
3053 reta = (reta >> 8) | LS32(j, 24, 0xFF);
3055 wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
3059 * Configure the RSS key and the RSS protocols used to compute
3060 * the RSS hash of input packets.
3062 rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
3063 if (rss_conf.rss_key == NULL)
3064 rss_conf.rss_key = rss_intel_key; /* Default hash key */
3065 txgbe_dev_rss_hash_update(dev, &rss_conf);
3068 #define NUM_VFTA_REGISTERS 128
3069 #define NIC_RX_BUFFER_SIZE 0x200
3072 txgbe_vmdq_dcb_configure(struct rte_eth_dev *dev)
3074 struct rte_eth_vmdq_dcb_conf *cfg;
3075 struct txgbe_hw *hw;
3076 enum rte_eth_nb_pools num_pools;
3077 uint32_t mrqc, vt_ctl, queue_mapping, vlanctrl;
3079 uint8_t nb_tcs; /* number of traffic classes */
3082 PMD_INIT_FUNC_TRACE();
3083 hw = TXGBE_DEV_HW(dev);
3084 cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3085 num_pools = cfg->nb_queue_pools;
3086 /* Check we have a valid number of pools */
3087 if (num_pools != ETH_16_POOLS && num_pools != ETH_32_POOLS) {
3088 txgbe_rss_disable(dev);
3091 /* 16 pools -> 8 traffic classes, 32 pools -> 4 traffic classes */
3092 nb_tcs = (uint8_t)(ETH_VMDQ_DCB_NUM_QUEUES / (int)num_pools);
3095 * split rx buffer up into sections, each for 1 traffic class
3097 pbsize = (uint16_t)(NIC_RX_BUFFER_SIZE / nb_tcs);
3098 for (i = 0; i < nb_tcs; i++) {
3099 uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
3101 rxpbsize &= (~(0x3FF << 10));
3102 /* clear 10 bits. */
3103 rxpbsize |= (pbsize << 10); /* set value */
3104 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3106 /* zero alloc all unused TCs */
3107 for (i = nb_tcs; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3108 uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
3110 rxpbsize &= (~(0x3FF << 10));
3111 /* clear 10 bits. */
3112 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3115 if (num_pools == ETH_16_POOLS) {
3116 mrqc = TXGBE_PORTCTL_NUMTC_8;
3117 mrqc |= TXGBE_PORTCTL_NUMVT_16;
3119 mrqc = TXGBE_PORTCTL_NUMTC_4;
3120 mrqc |= TXGBE_PORTCTL_NUMVT_32;
3122 wr32m(hw, TXGBE_PORTCTL,
3123 TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK, mrqc);
3125 vt_ctl = TXGBE_POOLCTL_RPLEN;
3126 if (cfg->enable_default_pool)
3127 vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
3129 vt_ctl |= TXGBE_POOLCTL_DEFDSA;
3131 wr32(hw, TXGBE_POOLCTL, vt_ctl);
3134 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
3136 * mapping is done with 3 bits per priority,
3137 * so shift by i*3 each time
3139 queue_mapping |= ((cfg->dcb_tc[i] & 0x07) << (i * 3));
3141 wr32(hw, TXGBE_RPUP2TC, queue_mapping);
3143 wr32(hw, TXGBE_ARBRXCTL, TXGBE_ARBRXCTL_RRM);
3145 /* enable vlan filtering and allow all vlan tags through */
3146 vlanctrl = rd32(hw, TXGBE_VLANCTL);
3147 vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3148 wr32(hw, TXGBE_VLANCTL, vlanctrl);
3150 /* enable all vlan filters */
3151 for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3152 wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
3154 wr32(hw, TXGBE_POOLRXENA(0),
3155 num_pools == ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3157 wr32(hw, TXGBE_ETHADDRIDX, 0);
3158 wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
3159 wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
3161 /* set up filters for vlan tags as configured */
3162 for (i = 0; i < cfg->nb_pool_maps; i++) {
3163 /* set vlan id in VF register and set the valid bit */
3164 wr32(hw, TXGBE_PSRVLANIDX, i);
3165 wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
3166 (cfg->pool_map[i].vlan_id & 0xFFF)));
3168 wr32(hw, TXGBE_PSRVLANPLM(0), cfg->pool_map[i].pools);
3173 * txgbe_dcb_config_tx_hw_config - Configure general DCB TX parameters
3174 * @dev: pointer to eth_dev structure
3175 * @dcb_config: pointer to txgbe_dcb_config structure
3178 txgbe_dcb_tx_hw_config(struct rte_eth_dev *dev,
3179 struct txgbe_dcb_config *dcb_config)
3182 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3184 PMD_INIT_FUNC_TRACE();
3186 /* Disable the Tx desc arbiter */
3187 reg = rd32(hw, TXGBE_ARBTXCTL);
3188 reg |= TXGBE_ARBTXCTL_DIA;
3189 wr32(hw, TXGBE_ARBTXCTL, reg);
3191 /* Enable DCB for Tx with 8 TCs */
3192 reg = rd32(hw, TXGBE_PORTCTL);
3193 reg &= TXGBE_PORTCTL_NUMTC_MASK;
3194 reg |= TXGBE_PORTCTL_DCB;
3195 if (dcb_config->num_tcs.pg_tcs == 8)
3196 reg |= TXGBE_PORTCTL_NUMTC_8;
3198 reg |= TXGBE_PORTCTL_NUMTC_4;
3200 wr32(hw, TXGBE_PORTCTL, reg);
3202 /* Enable the Tx desc arbiter */
3203 reg = rd32(hw, TXGBE_ARBTXCTL);
3204 reg &= ~TXGBE_ARBTXCTL_DIA;
3205 wr32(hw, TXGBE_ARBTXCTL, reg);
3209 * txgbe_vmdq_dcb_hw_tx_config - Configure general VMDQ+DCB TX parameters
3210 * @dev: pointer to rte_eth_dev structure
3211 * @dcb_config: pointer to txgbe_dcb_config structure
3214 txgbe_vmdq_dcb_hw_tx_config(struct rte_eth_dev *dev,
3215 struct txgbe_dcb_config *dcb_config)
3217 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3218 &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3219 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3221 PMD_INIT_FUNC_TRACE();
3222 /*PF VF Transmit Enable*/
3223 wr32(hw, TXGBE_POOLTXENA(0),
3224 vmdq_tx_conf->nb_queue_pools ==
3225 ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
3227 /*Configure general DCB TX parameters*/
3228 txgbe_dcb_tx_hw_config(dev, dcb_config);
3232 txgbe_vmdq_dcb_rx_config(struct rte_eth_dev *dev,
3233 struct txgbe_dcb_config *dcb_config)
3235 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
3236 &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
3237 struct txgbe_dcb_tc_config *tc;
3240 /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
3241 if (vmdq_rx_conf->nb_queue_pools == ETH_16_POOLS) {
3242 dcb_config->num_tcs.pg_tcs = ETH_8_TCS;
3243 dcb_config->num_tcs.pfc_tcs = ETH_8_TCS;
3245 dcb_config->num_tcs.pg_tcs = ETH_4_TCS;
3246 dcb_config->num_tcs.pfc_tcs = ETH_4_TCS;
3249 /* Initialize User Priority to Traffic Class mapping */
3250 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3251 tc = &dcb_config->tc_config[j];
3252 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3255 /* User Priority to Traffic Class mapping */
3256 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3257 j = vmdq_rx_conf->dcb_tc[i];
3258 tc = &dcb_config->tc_config[j];
3259 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3265 txgbe_dcb_vt_tx_config(struct rte_eth_dev *dev,
3266 struct txgbe_dcb_config *dcb_config)
3268 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3269 &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
3270 struct txgbe_dcb_tc_config *tc;
3273 /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
3274 if (vmdq_tx_conf->nb_queue_pools == ETH_16_POOLS) {
3275 dcb_config->num_tcs.pg_tcs = ETH_8_TCS;
3276 dcb_config->num_tcs.pfc_tcs = ETH_8_TCS;
3278 dcb_config->num_tcs.pg_tcs = ETH_4_TCS;
3279 dcb_config->num_tcs.pfc_tcs = ETH_4_TCS;
3282 /* Initialize User Priority to Traffic Class mapping */
3283 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3284 tc = &dcb_config->tc_config[j];
3285 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3288 /* User Priority to Traffic Class mapping */
3289 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3290 j = vmdq_tx_conf->dcb_tc[i];
3291 tc = &dcb_config->tc_config[j];
3292 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3298 txgbe_dcb_rx_config(struct rte_eth_dev *dev,
3299 struct txgbe_dcb_config *dcb_config)
3301 struct rte_eth_dcb_rx_conf *rx_conf =
3302 &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
3303 struct txgbe_dcb_tc_config *tc;
3306 dcb_config->num_tcs.pg_tcs = (uint8_t)rx_conf->nb_tcs;
3307 dcb_config->num_tcs.pfc_tcs = (uint8_t)rx_conf->nb_tcs;
3309 /* Initialize User Priority to Traffic Class mapping */
3310 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3311 tc = &dcb_config->tc_config[j];
3312 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
3315 /* User Priority to Traffic Class mapping */
3316 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3317 j = rx_conf->dcb_tc[i];
3318 tc = &dcb_config->tc_config[j];
3319 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
3325 txgbe_dcb_tx_config(struct rte_eth_dev *dev,
3326 struct txgbe_dcb_config *dcb_config)
3328 struct rte_eth_dcb_tx_conf *tx_conf =
3329 &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
3330 struct txgbe_dcb_tc_config *tc;
3333 dcb_config->num_tcs.pg_tcs = (uint8_t)tx_conf->nb_tcs;
3334 dcb_config->num_tcs.pfc_tcs = (uint8_t)tx_conf->nb_tcs;
3336 /* Initialize User Priority to Traffic Class mapping */
3337 for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
3338 tc = &dcb_config->tc_config[j];
3339 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
3342 /* User Priority to Traffic Class mapping */
3343 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3344 j = tx_conf->dcb_tc[i];
3345 tc = &dcb_config->tc_config[j];
3346 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
3352 * txgbe_dcb_rx_hw_config - Configure general DCB RX HW parameters
3353 * @dev: pointer to eth_dev structure
3354 * @dcb_config: pointer to txgbe_dcb_config structure
3357 txgbe_dcb_rx_hw_config(struct rte_eth_dev *dev,
3358 struct txgbe_dcb_config *dcb_config)
3364 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3366 PMD_INIT_FUNC_TRACE();
3368 * Disable the arbiter before changing parameters
3369 * (always enable recycle mode; WSP)
3371 reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP | TXGBE_ARBRXCTL_DIA;
3372 wr32(hw, TXGBE_ARBRXCTL, reg);
3374 reg = rd32(hw, TXGBE_PORTCTL);
3375 reg &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
3376 if (dcb_config->num_tcs.pg_tcs == 4) {
3377 reg |= TXGBE_PORTCTL_NUMTC_4;
3378 if (dcb_config->vt_mode)
3379 reg |= TXGBE_PORTCTL_NUMVT_32;
3381 wr32(hw, TXGBE_POOLCTL, 0);
3384 if (dcb_config->num_tcs.pg_tcs == 8) {
3385 reg |= TXGBE_PORTCTL_NUMTC_8;
3386 if (dcb_config->vt_mode)
3387 reg |= TXGBE_PORTCTL_NUMVT_16;
3389 wr32(hw, TXGBE_POOLCTL, 0);
3392 wr32(hw, TXGBE_PORTCTL, reg);
3394 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
3395 /* Disable drop for all queues in VMDQ mode*/
3396 for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
3397 u32 val = 1 << (q % 32);
3398 wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3401 /* Enable drop for all queues in SRIOV mode */
3402 for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
3403 u32 val = 1 << (q % 32);
3404 wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3408 /* VLNCTL: enable vlan filtering and allow all vlan tags through */
3409 vlanctrl = rd32(hw, TXGBE_VLANCTL);
3410 vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3411 wr32(hw, TXGBE_VLANCTL, vlanctrl);
3413 /* VLANTBL - enable all vlan filters */
3414 for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3415 wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
3418 * Configure Rx packet plane (recycle mode; WSP) and
3421 reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP;
3422 wr32(hw, TXGBE_ARBRXCTL, reg);
3426 txgbe_dcb_hw_arbite_rx_config(struct txgbe_hw *hw, uint16_t *refill,
3427 uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
3429 txgbe_dcb_config_rx_arbiter_raptor(hw, refill, max, bwg_id,
3434 txgbe_dcb_hw_arbite_tx_config(struct txgbe_hw *hw, uint16_t *refill,
3435 uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
3437 switch (hw->mac.type) {
3438 case txgbe_mac_raptor:
3439 txgbe_dcb_config_tx_desc_arbiter_raptor(hw, refill,
3441 txgbe_dcb_config_tx_data_arbiter_raptor(hw, refill,
3442 max, bwg_id, tsa, map);
3449 #define DCB_RX_CONFIG 1
3450 #define DCB_TX_CONFIG 1
3451 #define DCB_TX_PB 1024
3453 * txgbe_dcb_hw_configure - Enable DCB and configure
3454 * general DCB in VT mode and non-VT mode parameters
3455 * @dev: pointer to rte_eth_dev structure
3456 * @dcb_config: pointer to txgbe_dcb_config structure
3459 txgbe_dcb_hw_configure(struct rte_eth_dev *dev,
3460 struct txgbe_dcb_config *dcb_config)
3463 uint8_t i, pfc_en, nb_tcs;
3464 uint16_t pbsize, rx_buffer_size;
3465 uint8_t config_dcb_rx = 0;
3466 uint8_t config_dcb_tx = 0;
3467 uint8_t tsa[TXGBE_DCB_TC_MAX] = {0};
3468 uint8_t bwgid[TXGBE_DCB_TC_MAX] = {0};
3469 uint16_t refill[TXGBE_DCB_TC_MAX] = {0};
3470 uint16_t max[TXGBE_DCB_TC_MAX] = {0};
3471 uint8_t map[TXGBE_DCB_TC_MAX] = {0};
3472 struct txgbe_dcb_tc_config *tc;
3473 uint32_t max_frame = dev->data->mtu +
3474 RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
3475 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3476 struct txgbe_bw_conf *bw_conf = TXGBE_DEV_BW_CONF(dev);
3478 switch (dev->data->dev_conf.rxmode.mq_mode) {
3479 case ETH_MQ_RX_VMDQ_DCB:
3480 dcb_config->vt_mode = true;
3481 config_dcb_rx = DCB_RX_CONFIG;
3483 * get dcb and VT rx configuration parameters
3486 txgbe_vmdq_dcb_rx_config(dev, dcb_config);
3487 /*Configure general VMDQ and DCB RX parameters*/
3488 txgbe_vmdq_dcb_configure(dev);
3491 case ETH_MQ_RX_DCB_RSS:
3492 dcb_config->vt_mode = false;
3493 config_dcb_rx = DCB_RX_CONFIG;
3494 /* Get dcb TX configuration parameters from rte_eth_conf */
3495 txgbe_dcb_rx_config(dev, dcb_config);
3496 /*Configure general DCB RX parameters*/
3497 txgbe_dcb_rx_hw_config(dev, dcb_config);
3500 PMD_INIT_LOG(ERR, "Incorrect DCB RX mode configuration");
3503 switch (dev->data->dev_conf.txmode.mq_mode) {
3504 case ETH_MQ_TX_VMDQ_DCB:
3505 dcb_config->vt_mode = true;
3506 config_dcb_tx = DCB_TX_CONFIG;
3507 /* get DCB and VT TX configuration parameters
3510 txgbe_dcb_vt_tx_config(dev, dcb_config);
3511 /* Configure general VMDQ and DCB TX parameters */
3512 txgbe_vmdq_dcb_hw_tx_config(dev, dcb_config);
3516 dcb_config->vt_mode = false;
3517 config_dcb_tx = DCB_TX_CONFIG;
3518 /* get DCB TX configuration parameters from rte_eth_conf */
3519 txgbe_dcb_tx_config(dev, dcb_config);
3520 /* Configure general DCB TX parameters */
3521 txgbe_dcb_tx_hw_config(dev, dcb_config);
3524 PMD_INIT_LOG(ERR, "Incorrect DCB TX mode configuration");
3528 nb_tcs = dcb_config->num_tcs.pfc_tcs;
3530 txgbe_dcb_unpack_map_cee(dcb_config, TXGBE_DCB_RX_CONFIG, map);
3531 if (nb_tcs == ETH_4_TCS) {
3532 /* Avoid un-configured priority mapping to TC0 */
3534 uint8_t mask = 0xFF;
3536 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES - 4; i++)
3537 mask = (uint8_t)(mask & (~(1 << map[i])));
3538 for (i = 0; mask && (i < TXGBE_DCB_TC_MAX); i++) {
3539 if ((mask & 0x1) && j < ETH_DCB_NUM_USER_PRIORITIES)
3543 /* Re-configure 4 TCs BW */
3544 for (i = 0; i < nb_tcs; i++) {
3545 tc = &dcb_config->tc_config[i];
3546 if (bw_conf->tc_num != nb_tcs)
3547 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
3548 (uint8_t)(100 / nb_tcs);
3549 tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
3550 (uint8_t)(100 / nb_tcs);
3552 for (; i < TXGBE_DCB_TC_MAX; i++) {
3553 tc = &dcb_config->tc_config[i];
3554 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent = 0;
3555 tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent = 0;
3558 /* Re-configure 8 TCs BW */
3559 for (i = 0; i < nb_tcs; i++) {
3560 tc = &dcb_config->tc_config[i];
3561 if (bw_conf->tc_num != nb_tcs)
3562 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
3563 (uint8_t)(100 / nb_tcs + (i & 1));
3564 tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
3565 (uint8_t)(100 / nb_tcs + (i & 1));
3569 rx_buffer_size = NIC_RX_BUFFER_SIZE;
3571 if (config_dcb_rx) {
3572 /* Set RX buffer size */
3573 pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
3574 uint32_t rxpbsize = pbsize << 10;
3576 for (i = 0; i < nb_tcs; i++)
3577 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
3579 /* zero alloc all unused TCs */
3580 for (; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
3581 wr32(hw, TXGBE_PBRXSIZE(i), 0);
3583 if (config_dcb_tx) {
3584 /* Only support an equally distributed
3585 * Tx packet buffer strategy.
3587 uint32_t txpktsize = TXGBE_PBTXSIZE_MAX / nb_tcs;
3588 uint32_t txpbthresh = (txpktsize / DCB_TX_PB) -
3589 TXGBE_TXPKT_SIZE_MAX;
3591 for (i = 0; i < nb_tcs; i++) {
3592 wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
3593 wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
3595 /* Clear unused TCs, if any, to zero buffer size*/
3596 for (; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3597 wr32(hw, TXGBE_PBTXSIZE(i), 0);
3598 wr32(hw, TXGBE_PBTXDMATH(i), 0);
3602 /*Calculates traffic class credits*/
3603 txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
3604 TXGBE_DCB_TX_CONFIG);
3605 txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
3606 TXGBE_DCB_RX_CONFIG);
3608 if (config_dcb_rx) {
3609 /* Unpack CEE standard containers */
3610 txgbe_dcb_unpack_refill_cee(dcb_config,
3611 TXGBE_DCB_RX_CONFIG, refill);
3612 txgbe_dcb_unpack_max_cee(dcb_config, max);
3613 txgbe_dcb_unpack_bwgid_cee(dcb_config,
3614 TXGBE_DCB_RX_CONFIG, bwgid);
3615 txgbe_dcb_unpack_tsa_cee(dcb_config,
3616 TXGBE_DCB_RX_CONFIG, tsa);
3617 /* Configure PG(ETS) RX */
3618 txgbe_dcb_hw_arbite_rx_config(hw, refill, max, bwgid, tsa, map);
3621 if (config_dcb_tx) {
3622 /* Unpack CEE standard containers */
3623 txgbe_dcb_unpack_refill_cee(dcb_config,
3624 TXGBE_DCB_TX_CONFIG, refill);
3625 txgbe_dcb_unpack_max_cee(dcb_config, max);
3626 txgbe_dcb_unpack_bwgid_cee(dcb_config,
3627 TXGBE_DCB_TX_CONFIG, bwgid);
3628 txgbe_dcb_unpack_tsa_cee(dcb_config,
3629 TXGBE_DCB_TX_CONFIG, tsa);
3630 /* Configure PG(ETS) TX */
3631 txgbe_dcb_hw_arbite_tx_config(hw, refill, max, bwgid, tsa, map);
3634 /* Configure queue statistics registers */
3635 txgbe_dcb_config_tc_stats_raptor(hw, dcb_config);
3637 /* Check if the PFC is supported */
3638 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
3639 pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
3640 for (i = 0; i < nb_tcs; i++) {
3641 /* If the TC count is 8,
3642 * and the default high_water is 48,
3643 * the low_water is 16 as default.
3645 hw->fc.high_water[i] = (pbsize * 3) / 4;
3646 hw->fc.low_water[i] = pbsize / 4;
3647 /* Enable pfc for this TC */
3648 tc = &dcb_config->tc_config[i];
3649 tc->pfc = txgbe_dcb_pfc_enabled;
3651 txgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
3652 if (dcb_config->num_tcs.pfc_tcs == ETH_4_TCS)
3654 ret = txgbe_dcb_config_pfc(hw, pfc_en, map);
3660 void txgbe_configure_pb(struct rte_eth_dev *dev)
3662 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3663 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3666 int tc = dev_conf->rx_adv_conf.dcb_rx_conf.nb_tcs;
3668 /* Reserve 256KB(/512KB) rx buffer for fdir */
3671 hw->mac.setup_pba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
3674 void txgbe_configure_port(struct rte_eth_dev *dev)
3676 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3678 uint16_t tpids[8] = {RTE_ETHER_TYPE_VLAN, RTE_ETHER_TYPE_QINQ,
3683 PMD_INIT_FUNC_TRACE();
3685 /* default outer vlan tpid */
3686 wr32(hw, TXGBE_EXTAG,
3687 TXGBE_EXTAG_ETAG(RTE_ETHER_TYPE_ETAG) |
3688 TXGBE_EXTAG_VLAN(RTE_ETHER_TYPE_QINQ));
3690 /* default inner vlan tpid */
3691 wr32m(hw, TXGBE_VLANCTL,
3692 TXGBE_VLANCTL_TPID_MASK,
3693 TXGBE_VLANCTL_TPID(RTE_ETHER_TYPE_VLAN));
3694 wr32m(hw, TXGBE_DMATXCTRL,
3695 TXGBE_DMATXCTRL_TPID_MASK,
3696 TXGBE_DMATXCTRL_TPID(RTE_ETHER_TYPE_VLAN));
3698 /* default vlan tpid filters */
3699 for (i = 0; i < 8; i++) {
3700 wr32m(hw, TXGBE_TAGTPID(i / 2),
3701 (i % 2 ? TXGBE_TAGTPID_MSB_MASK
3702 : TXGBE_TAGTPID_LSB_MASK),
3703 (i % 2 ? TXGBE_TAGTPID_MSB(tpids[i])
3704 : TXGBE_TAGTPID_LSB(tpids[i])));
3707 /* default vxlan port */
3708 wr32(hw, TXGBE_VXLANPORT, 4789);
3712 * txgbe_configure_dcb - Configure DCB Hardware
3713 * @dev: pointer to rte_eth_dev
3715 void txgbe_configure_dcb(struct rte_eth_dev *dev)
3717 struct txgbe_dcb_config *dcb_cfg = TXGBE_DEV_DCB_CONFIG(dev);
3718 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3720 PMD_INIT_FUNC_TRACE();
3722 /* check support mq_mode for DCB */
3723 if (dev_conf->rxmode.mq_mode != ETH_MQ_RX_VMDQ_DCB &&
3724 dev_conf->rxmode.mq_mode != ETH_MQ_RX_DCB &&
3725 dev_conf->rxmode.mq_mode != ETH_MQ_RX_DCB_RSS)
3728 if (dev->data->nb_rx_queues > ETH_DCB_NUM_QUEUES)
3731 /** Configure DCB hardware **/
3732 txgbe_dcb_hw_configure(dev, dcb_cfg);
3736 * VMDq only support for 10 GbE NIC.
3739 txgbe_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
3741 struct rte_eth_vmdq_rx_conf *cfg;
3742 struct txgbe_hw *hw;
3743 enum rte_eth_nb_pools num_pools;
3744 uint32_t mrqc, vt_ctl, vlanctrl;
3748 PMD_INIT_FUNC_TRACE();
3749 hw = TXGBE_DEV_HW(dev);
3750 cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
3751 num_pools = cfg->nb_queue_pools;
3753 txgbe_rss_disable(dev);
3756 mrqc = TXGBE_PORTCTL_NUMVT_64;
3757 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mrqc);
3759 /* turn on virtualisation and set the default pool */
3760 vt_ctl = TXGBE_POOLCTL_RPLEN;
3761 if (cfg->enable_default_pool)
3762 vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
3764 vt_ctl |= TXGBE_POOLCTL_DEFDSA;
3766 wr32(hw, TXGBE_POOLCTL, vt_ctl);
3768 for (i = 0; i < (int)num_pools; i++) {
3769 vmolr = txgbe_convert_vm_rx_mask_to_val(cfg->rx_mode, vmolr);
3770 wr32(hw, TXGBE_POOLETHCTL(i), vmolr);
3773 /* enable vlan filtering and allow all vlan tags through */
3774 vlanctrl = rd32(hw, TXGBE_VLANCTL);
3775 vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
3776 wr32(hw, TXGBE_VLANCTL, vlanctrl);
3778 /* enable all vlan filters */
3779 for (i = 0; i < NUM_VFTA_REGISTERS; i++)
3780 wr32(hw, TXGBE_VLANTBL(i), UINT32_MAX);
3782 /* pool enabling for receive - 64 */
3783 wr32(hw, TXGBE_POOLRXENA(0), UINT32_MAX);
3784 if (num_pools == ETH_64_POOLS)
3785 wr32(hw, TXGBE_POOLRXENA(1), UINT32_MAX);
3788 * allow pools to read specific mac addresses
3789 * In this case, all pools should be able to read from mac addr 0
3791 wr32(hw, TXGBE_ETHADDRIDX, 0);
3792 wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
3793 wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
3795 /* set up filters for vlan tags as configured */
3796 for (i = 0; i < cfg->nb_pool_maps; i++) {
3797 /* set vlan id in VF register and set the valid bit */
3798 wr32(hw, TXGBE_PSRVLANIDX, i);
3799 wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
3800 TXGBE_PSRVLAN_VID(cfg->pool_map[i].vlan_id)));
3802 * Put the allowed pools in VFB reg. As we only have 16 or 64
3803 * pools, we only need to use the first half of the register
3806 if (((cfg->pool_map[i].pools >> 32) & UINT32_MAX) == 0)
3807 wr32(hw, TXGBE_PSRVLANPLM(0),
3808 (cfg->pool_map[i].pools & UINT32_MAX));
3810 wr32(hw, TXGBE_PSRVLANPLM(1),
3811 ((cfg->pool_map[i].pools >> 32) & UINT32_MAX));
3814 /* Tx General Switch Control Enables VMDQ loopback */
3815 if (cfg->enable_loop_back) {
3816 wr32(hw, TXGBE_PSRCTL, TXGBE_PSRCTL_LBENA);
3817 for (i = 0; i < 64; i++)
3818 wr32m(hw, TXGBE_POOLETHCTL(i),
3819 TXGBE_POOLETHCTL_LLB, TXGBE_POOLETHCTL_LLB);
3826 * txgbe_vmdq_tx_hw_configure - Configure general VMDq TX parameters
3827 * @hw: pointer to hardware structure
3830 txgbe_vmdq_tx_hw_configure(struct txgbe_hw *hw)
3835 PMD_INIT_FUNC_TRACE();
3836 /*PF VF Transmit Enable*/
3837 wr32(hw, TXGBE_POOLTXENA(0), UINT32_MAX);
3838 wr32(hw, TXGBE_POOLTXENA(1), UINT32_MAX);
3840 /* Disable the Tx desc arbiter */
3841 reg = rd32(hw, TXGBE_ARBTXCTL);
3842 reg |= TXGBE_ARBTXCTL_DIA;
3843 wr32(hw, TXGBE_ARBTXCTL, reg);
3845 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK,
3846 TXGBE_PORTCTL_NUMVT_64);
3848 /* Disable drop for all queues */
3849 for (q = 0; q < 128; q++) {
3850 u32 val = 1 << (q % 32);
3851 wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
3854 /* Enable the Tx desc arbiter */
3855 reg = rd32(hw, TXGBE_ARBTXCTL);
3856 reg &= ~TXGBE_ARBTXCTL_DIA;
3857 wr32(hw, TXGBE_ARBTXCTL, reg);
3862 static int __rte_cold
3863 txgbe_alloc_rx_queue_mbufs(struct txgbe_rx_queue *rxq)
3865 struct txgbe_rx_entry *rxe = rxq->sw_ring;
3869 /* Initialize software ring entries */
3870 for (i = 0; i < rxq->nb_rx_desc; i++) {
3871 volatile struct txgbe_rx_desc *rxd;
3872 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
3875 PMD_INIT_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
3876 (unsigned int)rxq->queue_id);
3880 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
3881 mbuf->port = rxq->port_id;
3884 rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
3885 rxd = &rxq->rx_ring[i];
3886 TXGBE_RXD_HDRADDR(rxd, 0);
3887 TXGBE_RXD_PKTADDR(rxd, dma_addr);
3895 txgbe_config_vf_rss(struct rte_eth_dev *dev)
3897 struct txgbe_hw *hw;
3900 txgbe_rss_configure(dev);
3902 hw = TXGBE_DEV_HW(dev);
3905 mrqc = rd32(hw, TXGBE_PORTCTL);
3906 mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
3907 switch (RTE_ETH_DEV_SRIOV(dev).active) {
3909 mrqc |= TXGBE_PORTCTL_NUMVT_64;
3913 mrqc |= TXGBE_PORTCTL_NUMVT_32;
3917 PMD_INIT_LOG(ERR, "Invalid pool number in IOV mode with VMDQ RSS");
3921 wr32(hw, TXGBE_PORTCTL, mrqc);
3927 txgbe_config_vf_default(struct rte_eth_dev *dev)
3929 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
3932 mrqc = rd32(hw, TXGBE_PORTCTL);
3933 mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
3934 switch (RTE_ETH_DEV_SRIOV(dev).active) {
3936 mrqc |= TXGBE_PORTCTL_NUMVT_64;
3940 mrqc |= TXGBE_PORTCTL_NUMVT_32;
3944 mrqc |= TXGBE_PORTCTL_NUMVT_16;
3948 "invalid pool number in IOV mode");
3952 wr32(hw, TXGBE_PORTCTL, mrqc);
3958 txgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
3960 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
3962 * SRIOV inactive scheme
3963 * any DCB/RSS w/o VMDq multi-queue setting
3965 switch (dev->data->dev_conf.rxmode.mq_mode) {
3967 case ETH_MQ_RX_DCB_RSS:
3968 case ETH_MQ_RX_VMDQ_RSS:
3969 txgbe_rss_configure(dev);
3972 case ETH_MQ_RX_VMDQ_DCB:
3973 txgbe_vmdq_dcb_configure(dev);
3976 case ETH_MQ_RX_VMDQ_ONLY:
3977 txgbe_vmdq_rx_hw_configure(dev);
3980 case ETH_MQ_RX_NONE:
3982 /* if mq_mode is none, disable rss mode.*/
3983 txgbe_rss_disable(dev);
3987 /* SRIOV active scheme
3988 * Support RSS together with SRIOV.
3990 switch (dev->data->dev_conf.rxmode.mq_mode) {
3992 case ETH_MQ_RX_VMDQ_RSS:
3993 txgbe_config_vf_rss(dev);
3995 case ETH_MQ_RX_VMDQ_DCB:
3997 /* In SRIOV, the configuration is the same as VMDq case */
3998 txgbe_vmdq_dcb_configure(dev);
4000 /* DCB/RSS together with SRIOV is not supported */
4001 case ETH_MQ_RX_VMDQ_DCB_RSS:
4002 case ETH_MQ_RX_DCB_RSS:
4004 "Could not support DCB/RSS with VMDq & SRIOV");
4007 txgbe_config_vf_default(dev);
4016 txgbe_dev_mq_tx_configure(struct rte_eth_dev *dev)
4018 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4022 /* disable arbiter */
4023 rttdcs = rd32(hw, TXGBE_ARBTXCTL);
4024 rttdcs |= TXGBE_ARBTXCTL_DIA;
4025 wr32(hw, TXGBE_ARBTXCTL, rttdcs);
4027 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
4029 * SRIOV inactive scheme
4030 * any DCB w/o VMDq multi-queue setting
4032 if (dev->data->dev_conf.txmode.mq_mode == ETH_MQ_TX_VMDQ_ONLY)
4033 txgbe_vmdq_tx_hw_configure(hw);
4035 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, 0);
4037 switch (RTE_ETH_DEV_SRIOV(dev).active) {
4039 * SRIOV active scheme
4040 * FIXME if support DCB together with VMDq & SRIOV
4043 mtqc = TXGBE_PORTCTL_NUMVT_64;
4046 mtqc = TXGBE_PORTCTL_NUMVT_32;
4049 mtqc = TXGBE_PORTCTL_NUMVT_16;
4053 PMD_INIT_LOG(ERR, "invalid pool number in IOV mode");
4055 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mtqc);
4058 /* re-enable arbiter */
4059 rttdcs &= ~TXGBE_ARBTXCTL_DIA;
4060 wr32(hw, TXGBE_ARBTXCTL, rttdcs);
4066 * txgbe_get_rscctl_maxdesc
4068 * @pool Memory pool of the Rx queue
4070 static inline uint32_t
4071 txgbe_get_rscctl_maxdesc(struct rte_mempool *pool)
4073 struct rte_pktmbuf_pool_private *mp_priv = rte_mempool_get_priv(pool);
4076 RTE_IPV4_MAX_PKT_LEN /
4077 (mp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
4080 return TXGBE_RXCFG_RSCMAX_16;
4081 else if (maxdesc >= 8)
4082 return TXGBE_RXCFG_RSCMAX_8;
4083 else if (maxdesc >= 4)
4084 return TXGBE_RXCFG_RSCMAX_4;
4086 return TXGBE_RXCFG_RSCMAX_1;
4090 * txgbe_set_rsc - configure RSC related port HW registers
4092 * Configures the port's RSC related registers.
4096 * Returns 0 in case of success or a non-zero error code
4099 txgbe_set_rsc(struct rte_eth_dev *dev)
4101 struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4102 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4103 struct rte_eth_dev_info dev_info = { 0 };
4104 bool rsc_capable = false;
4110 dev->dev_ops->dev_infos_get(dev, &dev_info);
4111 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO)
4114 if (!rsc_capable && (rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO)) {
4115 PMD_INIT_LOG(CRIT, "LRO is requested on HW that doesn't "
4120 /* RSC global configuration */
4122 if ((rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC) &&
4123 (rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO)) {
4124 PMD_INIT_LOG(CRIT, "LRO can't be enabled when HW CRC "
4129 rfctl = rd32(hw, TXGBE_PSRCTL);
4130 if (rsc_capable && (rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO))
4131 rfctl &= ~TXGBE_PSRCTL_RSCDIA;
4133 rfctl |= TXGBE_PSRCTL_RSCDIA;
4134 wr32(hw, TXGBE_PSRCTL, rfctl);
4136 /* If LRO hasn't been requested - we are done here. */
4137 if (!(rx_conf->offloads & DEV_RX_OFFLOAD_TCP_LRO))
4140 /* Set PSRCTL.RSCACK bit */
4141 rdrxctl = rd32(hw, TXGBE_PSRCTL);
4142 rdrxctl |= TXGBE_PSRCTL_RSCACK;
4143 wr32(hw, TXGBE_PSRCTL, rdrxctl);
4145 /* Per-queue RSC configuration */
4146 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4147 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
4149 rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4151 rd32(hw, TXGBE_POOLRSS(rxq->reg_idx));
4153 rd32(hw, TXGBE_ITR(rxq->reg_idx));
4156 * txgbe PMD doesn't support header-split at the moment.
4158 srrctl &= ~TXGBE_RXCFG_HDRLEN_MASK;
4159 srrctl |= TXGBE_RXCFG_HDRLEN(128);
4162 * TODO: Consider setting the Receive Descriptor Minimum
4163 * Threshold Size for an RSC case. This is not an obviously
4164 * beneficiary option but the one worth considering...
4167 srrctl |= TXGBE_RXCFG_RSCENA;
4168 srrctl &= ~TXGBE_RXCFG_RSCMAX_MASK;
4169 srrctl |= txgbe_get_rscctl_maxdesc(rxq->mb_pool);
4170 psrtype |= TXGBE_POOLRSS_L4HDR;
4173 * RSC: Set ITR interval corresponding to 2K ints/s.
4175 * Full-sized RSC aggregations for a 10Gb/s link will
4176 * arrive at about 20K aggregation/s rate.
4178 * 2K inst/s rate will make only 10% of the
4179 * aggregations to be closed due to the interrupt timer
4180 * expiration for a streaming at wire-speed case.
4182 * For a sparse streaming case this setting will yield
4183 * at most 500us latency for a single RSC aggregation.
4185 eitr &= ~TXGBE_ITR_IVAL_MASK;
4186 eitr |= TXGBE_ITR_IVAL_10G(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT);
4187 eitr |= TXGBE_ITR_WRDSA;
4189 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
4190 wr32(hw, TXGBE_POOLRSS(rxq->reg_idx), psrtype);
4191 wr32(hw, TXGBE_ITR(rxq->reg_idx), eitr);
4194 * RSC requires the mapping of the queue to the
4197 txgbe_set_ivar_map(hw, 0, rxq->reg_idx, i);
4202 PMD_INIT_LOG(DEBUG, "enabling LRO mode");
4208 txgbe_set_rx_function(struct rte_eth_dev *dev)
4211 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
4214 * Initialize the appropriate LRO callback.
4216 * If all queues satisfy the bulk allocation preconditions
4217 * (adapter->rx_bulk_alloc_allowed is TRUE) then we may use
4218 * bulk allocation. Otherwise use a single allocation version.
4220 if (dev->data->lro) {
4221 if (adapter->rx_bulk_alloc_allowed) {
4222 PMD_INIT_LOG(DEBUG, "LRO is requested. Using a bulk "
4223 "allocation version");
4224 dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
4226 PMD_INIT_LOG(DEBUG, "LRO is requested. Using a single "
4227 "allocation version");
4228 dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
4230 } else if (dev->data->scattered_rx) {
4232 * Set the non-LRO scattered callback: there are bulk and
4233 * single allocation versions.
4235 if (adapter->rx_bulk_alloc_allowed) {
4236 PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
4237 "allocation callback (port=%d).",
4238 dev->data->port_id);
4239 dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
4241 PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
4242 "single allocation) "
4243 "Scattered Rx callback "
4245 dev->data->port_id);
4247 dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
4250 * Below we set "simple" callbacks according to port/queues parameters.
4251 * If parameters allow we are going to choose between the following
4254 * - Single buffer allocation (the simplest one)
4256 } else if (adapter->rx_bulk_alloc_allowed) {
4257 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
4258 "satisfied. Rx Burst Bulk Alloc function "
4259 "will be used on port=%d.",
4260 dev->data->port_id);
4262 dev->rx_pkt_burst = txgbe_recv_pkts_bulk_alloc;
4264 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
4265 "satisfied, or Scattered Rx is requested "
4267 dev->data->port_id);
4269 dev->rx_pkt_burst = txgbe_recv_pkts;
4272 #ifdef RTE_LIB_SECURITY
4273 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4274 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
4276 rxq->using_ipsec = !!(dev->data->dev_conf.rxmode.offloads &
4277 DEV_RX_OFFLOAD_SECURITY);
4283 * Initializes Receive Unit.
4286 txgbe_dev_rx_init(struct rte_eth_dev *dev)
4288 struct txgbe_hw *hw;
4289 struct txgbe_rx_queue *rxq;
4298 struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
4301 PMD_INIT_FUNC_TRACE();
4302 hw = TXGBE_DEV_HW(dev);
4305 * Make sure receives are disabled while setting
4306 * up the RX context (registers, descriptor rings, etc.).
4308 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
4309 wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
4311 /* Enable receipt of broadcasted frames */
4312 fctrl = rd32(hw, TXGBE_PSRCTL);
4313 fctrl |= TXGBE_PSRCTL_BCA;
4314 wr32(hw, TXGBE_PSRCTL, fctrl);
4317 * Configure CRC stripping, if any.
4319 hlreg0 = rd32(hw, TXGBE_SECRXCTL);
4320 if (rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC)
4321 hlreg0 &= ~TXGBE_SECRXCTL_CRCSTRIP;
4323 hlreg0 |= TXGBE_SECRXCTL_CRCSTRIP;
4324 wr32(hw, TXGBE_SECRXCTL, hlreg0);
4327 * Configure jumbo frame support, if any.
4329 if (rx_conf->offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
4330 wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
4331 TXGBE_FRMSZ_MAX(rx_conf->max_rx_pkt_len));
4333 wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
4334 TXGBE_FRMSZ_MAX(TXGBE_FRAME_SIZE_DFT));
4338 * If loopback mode is configured, set LPBK bit.
4340 hlreg0 = rd32(hw, TXGBE_PSRCTL);
4341 if (hw->mac.type == txgbe_mac_raptor &&
4342 dev->data->dev_conf.lpbk_mode)
4343 hlreg0 |= TXGBE_PSRCTL_LBENA;
4345 hlreg0 &= ~TXGBE_PSRCTL_LBENA;
4347 wr32(hw, TXGBE_PSRCTL, hlreg0);
4350 * Assume no header split and no VLAN strip support
4351 * on any Rx queue first .
4353 rx_conf->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4355 /* Setup RX queues */
4356 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4357 rxq = dev->data->rx_queues[i];
4360 * Reset crc_len in case it was changed after queue setup by a
4361 * call to configure.
4363 if (rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC)
4364 rxq->crc_len = RTE_ETHER_CRC_LEN;
4368 /* Setup the Base and Length of the Rx Descriptor Rings */
4369 bus_addr = rxq->rx_ring_phys_addr;
4370 wr32(hw, TXGBE_RXBAL(rxq->reg_idx),
4371 (uint32_t)(bus_addr & BIT_MASK32));
4372 wr32(hw, TXGBE_RXBAH(rxq->reg_idx),
4373 (uint32_t)(bus_addr >> 32));
4374 wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
4375 wr32(hw, TXGBE_RXWP(rxq->reg_idx), 0);
4377 srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
4379 /* Set if packets are dropped when no descriptors available */
4381 srrctl |= TXGBE_RXCFG_DROP;
4384 * Configure the RX buffer size in the PKTLEN field of
4385 * the RXCFG register of the queue.
4386 * The value is in 1 KB resolution. Valid values can be from
4389 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
4390 RTE_PKTMBUF_HEADROOM);
4391 buf_size = ROUND_UP(buf_size, 0x1 << 10);
4392 srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
4394 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
4396 /* It adds dual VLAN length for supporting dual VLAN */
4397 if (dev->data->dev_conf.rxmode.max_rx_pkt_len +
4398 2 * TXGBE_VLAN_TAG_SIZE > buf_size)
4399 dev->data->scattered_rx = 1;
4400 if (rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
4401 rx_conf->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4404 if (rx_conf->offloads & DEV_RX_OFFLOAD_SCATTER)
4405 dev->data->scattered_rx = 1;
4408 * Device configured with multiple RX queues.
4410 txgbe_dev_mq_rx_configure(dev);
4413 * Setup the Checksum Register.
4414 * Disable Full-Packet Checksum which is mutually exclusive with RSS.
4415 * Enable IP/L4 checksum computation by hardware if requested to do so.
4417 rxcsum = rd32(hw, TXGBE_PSRCTL);
4418 rxcsum |= TXGBE_PSRCTL_PCSD;
4419 if (rx_conf->offloads & DEV_RX_OFFLOAD_CHECKSUM)
4420 rxcsum |= TXGBE_PSRCTL_L4CSUM;
4422 rxcsum &= ~TXGBE_PSRCTL_L4CSUM;
4424 wr32(hw, TXGBE_PSRCTL, rxcsum);
4426 if (hw->mac.type == txgbe_mac_raptor) {
4427 rdrxctl = rd32(hw, TXGBE_SECRXCTL);
4428 if (rx_conf->offloads & DEV_RX_OFFLOAD_KEEP_CRC)
4429 rdrxctl &= ~TXGBE_SECRXCTL_CRCSTRIP;
4431 rdrxctl |= TXGBE_SECRXCTL_CRCSTRIP;
4432 wr32(hw, TXGBE_SECRXCTL, rdrxctl);
4435 rc = txgbe_set_rsc(dev);
4439 txgbe_set_rx_function(dev);
4445 * Initializes Transmit Unit.
4448 txgbe_dev_tx_init(struct rte_eth_dev *dev)
4450 struct txgbe_hw *hw;
4451 struct txgbe_tx_queue *txq;
4455 PMD_INIT_FUNC_TRACE();
4456 hw = TXGBE_DEV_HW(dev);
4458 /* Setup the Base and Length of the Tx Descriptor Rings */
4459 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4460 txq = dev->data->tx_queues[i];
4462 bus_addr = txq->tx_ring_phys_addr;
4463 wr32(hw, TXGBE_TXBAL(txq->reg_idx),
4464 (uint32_t)(bus_addr & BIT_MASK32));
4465 wr32(hw, TXGBE_TXBAH(txq->reg_idx),
4466 (uint32_t)(bus_addr >> 32));
4467 wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_BUFLEN_MASK,
4468 TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
4469 /* Setup the HW Tx Head and TX Tail descriptor pointers */
4470 wr32(hw, TXGBE_TXRP(txq->reg_idx), 0);
4471 wr32(hw, TXGBE_TXWP(txq->reg_idx), 0);
4474 /* Device configured with multiple TX queues. */
4475 txgbe_dev_mq_tx_configure(dev);
4479 * Set up link loopback mode Tx->Rx.
4481 static inline void __rte_cold
4482 txgbe_setup_loopback_link_raptor(struct txgbe_hw *hw)
4484 PMD_INIT_FUNC_TRACE();
4486 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_LB, TXGBE_MACRXCFG_LB);
4492 * Start Transmit and Receive Units.
4495 txgbe_dev_rxtx_start(struct rte_eth_dev *dev)
4497 struct txgbe_hw *hw;
4498 struct txgbe_tx_queue *txq;
4499 struct txgbe_rx_queue *rxq;
4505 PMD_INIT_FUNC_TRACE();
4506 hw = TXGBE_DEV_HW(dev);
4508 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4509 txq = dev->data->tx_queues[i];
4510 /* Setup Transmit Threshold Registers */
4511 wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
4512 TXGBE_TXCFG_HTHRESH_MASK |
4513 TXGBE_TXCFG_WTHRESH_MASK,
4514 TXGBE_TXCFG_HTHRESH(txq->hthresh) |
4515 TXGBE_TXCFG_WTHRESH(txq->wthresh));
4518 dmatxctl = rd32(hw, TXGBE_DMATXCTRL);
4519 dmatxctl |= TXGBE_DMATXCTRL_ENA;
4520 wr32(hw, TXGBE_DMATXCTRL, dmatxctl);
4522 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4523 txq = dev->data->tx_queues[i];
4524 if (!txq->tx_deferred_start) {
4525 ret = txgbe_dev_tx_queue_start(dev, i);
4531 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4532 rxq = dev->data->rx_queues[i];
4533 if (!rxq->rx_deferred_start) {
4534 ret = txgbe_dev_rx_queue_start(dev, i);
4540 /* Enable Receive engine */
4541 rxctrl = rd32(hw, TXGBE_PBRXCTL);
4542 rxctrl |= TXGBE_PBRXCTL_ENA;
4543 hw->mac.enable_rx_dma(hw, rxctrl);
4545 /* If loopback mode is enabled, set up the link accordingly */
4546 if (hw->mac.type == txgbe_mac_raptor &&
4547 dev->data->dev_conf.lpbk_mode)
4548 txgbe_setup_loopback_link_raptor(hw);
4550 #ifdef RTE_LIB_SECURITY
4551 if ((dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SECURITY) ||
4552 (dev->data->dev_conf.txmode.offloads & DEV_TX_OFFLOAD_SECURITY)) {
4553 ret = txgbe_crypto_enable_ipsec(dev);
4556 "txgbe_crypto_enable_ipsec fails with %d.",
4567 txgbe_dev_save_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
4569 u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
4570 *(reg++) = rd32(hw, TXGBE_RXBAL(rx_queue_id));
4571 *(reg++) = rd32(hw, TXGBE_RXBAH(rx_queue_id));
4572 *(reg++) = rd32(hw, TXGBE_RXCFG(rx_queue_id));
4576 txgbe_dev_store_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
4578 u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
4579 wr32(hw, TXGBE_RXBAL(rx_queue_id), *(reg++));
4580 wr32(hw, TXGBE_RXBAH(rx_queue_id), *(reg++));
4581 wr32(hw, TXGBE_RXCFG(rx_queue_id), *(reg++) & ~TXGBE_RXCFG_ENA);
4585 txgbe_dev_save_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
4587 u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
4588 *(reg++) = rd32(hw, TXGBE_TXBAL(tx_queue_id));
4589 *(reg++) = rd32(hw, TXGBE_TXBAH(tx_queue_id));
4590 *(reg++) = rd32(hw, TXGBE_TXCFG(tx_queue_id));
4594 txgbe_dev_store_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
4596 u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
4597 wr32(hw, TXGBE_TXBAL(tx_queue_id), *(reg++));
4598 wr32(hw, TXGBE_TXBAH(tx_queue_id), *(reg++));
4599 wr32(hw, TXGBE_TXCFG(tx_queue_id), *(reg++) & ~TXGBE_TXCFG_ENA);
4603 * Start Receive Units for specified queue.
4606 txgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4608 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4609 struct txgbe_rx_queue *rxq;
4613 PMD_INIT_FUNC_TRACE();
4615 rxq = dev->data->rx_queues[rx_queue_id];
4617 /* Allocate buffers for descriptor rings */
4618 if (txgbe_alloc_rx_queue_mbufs(rxq) != 0) {
4619 PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
4623 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4624 rxdctl |= TXGBE_RXCFG_ENA;
4625 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), rxdctl);
4627 /* Wait until RX Enable ready */
4628 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4631 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4632 } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
4634 PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
4636 wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
4637 wr32(hw, TXGBE_RXWP(rxq->reg_idx), rxq->nb_rx_desc - 1);
4638 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4644 * Stop Receive Units for specified queue.
4647 txgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4649 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4650 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
4651 struct txgbe_rx_queue *rxq;
4655 PMD_INIT_FUNC_TRACE();
4657 rxq = dev->data->rx_queues[rx_queue_id];
4659 txgbe_dev_save_rx_queue(hw, rxq->reg_idx);
4660 wr32m(hw, TXGBE_RXCFG(rxq->reg_idx), TXGBE_RXCFG_ENA, 0);
4662 /* Wait until RX Enable bit clear */
4663 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4666 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
4667 } while (--poll_ms && (rxdctl & TXGBE_RXCFG_ENA));
4669 PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
4671 rte_delay_us(RTE_TXGBE_WAIT_100_US);
4672 txgbe_dev_store_rx_queue(hw, rxq->reg_idx);
4674 txgbe_rx_queue_release_mbufs(rxq);
4675 txgbe_reset_rx_queue(adapter, rxq);
4676 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4682 * Start Transmit Units for specified queue.
4685 txgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4687 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4688 struct txgbe_tx_queue *txq;
4692 PMD_INIT_FUNC_TRACE();
4694 txq = dev->data->tx_queues[tx_queue_id];
4695 wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
4697 /* Wait until TX Enable ready */
4698 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4701 txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
4702 } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
4704 PMD_INIT_LOG(ERR, "Could not enable "
4705 "Tx Queue %d", tx_queue_id);
4708 wr32(hw, TXGBE_TXWP(txq->reg_idx), txq->tx_tail);
4709 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4715 * Stop Transmit Units for specified queue.
4718 txgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4720 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
4721 struct txgbe_tx_queue *txq;
4723 uint32_t txtdh, txtdt;
4726 PMD_INIT_FUNC_TRACE();
4728 txq = dev->data->tx_queues[tx_queue_id];
4730 /* Wait until TX queue is empty */
4731 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4733 rte_delay_us(RTE_TXGBE_WAIT_100_US);
4734 txtdh = rd32(hw, TXGBE_TXRP(txq->reg_idx));
4735 txtdt = rd32(hw, TXGBE_TXWP(txq->reg_idx));
4736 } while (--poll_ms && (txtdh != txtdt));
4739 "Tx Queue %d is not empty when stopping.",
4742 txgbe_dev_save_tx_queue(hw, txq->reg_idx);
4743 wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, 0);
4745 /* Wait until TX Enable bit clear */
4746 poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
4749 txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
4750 } while (--poll_ms && (txdctl & TXGBE_TXCFG_ENA));
4752 PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
4755 rte_delay_us(RTE_TXGBE_WAIT_100_US);
4756 txgbe_dev_store_tx_queue(hw, txq->reg_idx);
4758 if (txq->ops != NULL) {
4759 txq->ops->release_mbufs(txq);
4760 txq->ops->reset(txq);
4762 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4768 txgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4769 struct rte_eth_rxq_info *qinfo)
4771 struct txgbe_rx_queue *rxq;
4773 rxq = dev->data->rx_queues[queue_id];
4775 qinfo->mp = rxq->mb_pool;
4776 qinfo->scattered_rx = dev->data->scattered_rx;
4777 qinfo->nb_desc = rxq->nb_rx_desc;
4779 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
4780 qinfo->conf.rx_drop_en = rxq->drop_en;
4781 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
4782 qinfo->conf.offloads = rxq->offloads;
4786 txgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4787 struct rte_eth_txq_info *qinfo)
4789 struct txgbe_tx_queue *txq;
4791 txq = dev->data->tx_queues[queue_id];
4793 qinfo->nb_desc = txq->nb_tx_desc;
4795 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
4796 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
4797 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
4799 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
4800 qinfo->conf.offloads = txq->offloads;
4801 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
4805 * [VF] Initializes Receive Unit.
4808 txgbevf_dev_rx_init(struct rte_eth_dev *dev)
4810 struct txgbe_hw *hw;
4811 struct txgbe_rx_queue *rxq;
4812 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4814 uint32_t srrctl, psrtype;
4819 PMD_INIT_FUNC_TRACE();
4820 hw = TXGBE_DEV_HW(dev);
4822 if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
4823 PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
4824 "it should be power of 2");
4828 if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
4829 PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
4830 "it should be equal to or less than %d",
4831 hw->mac.max_rx_queues);
4836 * When the VF driver issues a TXGBE_VF_RESET request, the PF driver
4837 * disables the VF receipt of packets if the PF MTU is > 1500.
4838 * This is done to deal with limitations that imposes
4839 * the PF and all VFs to share the same MTU.
4840 * Then, the PF driver enables again the VF receipt of packet when
4841 * the VF driver issues a TXGBE_VF_SET_LPE request.
4842 * In the meantime, the VF device cannot be used, even if the VF driver
4843 * and the Guest VM network stack are ready to accept packets with a
4844 * size up to the PF MTU.
4845 * As a work-around to this PF behaviour, force the call to
4846 * txgbevf_rlpml_set_vf even if jumbo frames are not used. This way,
4847 * VF packets received can work in all cases.
4849 if (txgbevf_rlpml_set_vf(hw,
4850 (uint16_t)dev->data->dev_conf.rxmode.max_rx_pkt_len)) {
4851 PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
4852 dev->data->dev_conf.rxmode.max_rx_pkt_len);
4857 * Assume no header split and no VLAN strip support
4858 * on any Rx queue first .
4860 rxmode->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
4862 /* Set PSR type for VF RSS according to max Rx queue */
4863 psrtype = TXGBE_VFPLCFG_PSRL4HDR |
4864 TXGBE_VFPLCFG_PSRL4HDR |
4865 TXGBE_VFPLCFG_PSRL2HDR |
4866 TXGBE_VFPLCFG_PSRTUNHDR |
4867 TXGBE_VFPLCFG_PSRTUNMAC;
4868 wr32(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_PSR(psrtype));
4870 /* Setup RX queues */
4871 for (i = 0; i < dev->data->nb_rx_queues; i++) {
4872 rxq = dev->data->rx_queues[i];
4874 /* Allocate buffers for descriptor rings */
4875 ret = txgbe_alloc_rx_queue_mbufs(rxq);
4879 /* Setup the Base and Length of the Rx Descriptor Rings */
4880 bus_addr = rxq->rx_ring_phys_addr;
4882 wr32(hw, TXGBE_RXBAL(i),
4883 (uint32_t)(bus_addr & BIT_MASK32));
4884 wr32(hw, TXGBE_RXBAH(i),
4885 (uint32_t)(bus_addr >> 32));
4886 wr32(hw, TXGBE_RXRP(i), 0);
4887 wr32(hw, TXGBE_RXWP(i), 0);
4889 /* Configure the RXCFG register */
4890 srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
4892 /* Set if packets are dropped when no descriptors available */
4894 srrctl |= TXGBE_RXCFG_DROP;
4897 * Configure the RX buffer size in the PKTLEN field of
4898 * the RXCFG register of the queue.
4899 * The value is in 1 KB resolution. Valid values can be from
4902 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
4903 RTE_PKTMBUF_HEADROOM);
4904 buf_size = ROUND_UP(buf_size, 1 << 10);
4905 srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
4908 * VF modification to write virtual function RXCFG register
4910 wr32(hw, TXGBE_RXCFG(i), srrctl);
4912 if (rxmode->offloads & DEV_RX_OFFLOAD_SCATTER ||
4913 /* It adds dual VLAN length for supporting dual VLAN */
4914 (rxmode->max_rx_pkt_len +
4915 2 * TXGBE_VLAN_TAG_SIZE) > buf_size) {
4916 if (!dev->data->scattered_rx)
4917 PMD_INIT_LOG(DEBUG, "forcing scatter mode");
4918 dev->data->scattered_rx = 1;
4921 if (rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
4922 rxmode->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
4926 * Device configured with multiple RX queues.
4928 txgbe_dev_mq_rx_configure(dev);
4930 txgbe_set_rx_function(dev);
4936 * [VF] Initializes Transmit Unit.
4939 txgbevf_dev_tx_init(struct rte_eth_dev *dev)
4941 struct txgbe_hw *hw;
4942 struct txgbe_tx_queue *txq;
4946 PMD_INIT_FUNC_TRACE();
4947 hw = TXGBE_DEV_HW(dev);
4949 /* Setup the Base and Length of the Tx Descriptor Rings */
4950 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4951 txq = dev->data->tx_queues[i];
4952 bus_addr = txq->tx_ring_phys_addr;
4953 wr32(hw, TXGBE_TXBAL(i),
4954 (uint32_t)(bus_addr & BIT_MASK32));
4955 wr32(hw, TXGBE_TXBAH(i),
4956 (uint32_t)(bus_addr >> 32));
4957 wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_BUFLEN_MASK,
4958 TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
4959 /* Setup the HW Tx Head and TX Tail descriptor pointers */
4960 wr32(hw, TXGBE_TXRP(i), 0);
4961 wr32(hw, TXGBE_TXWP(i), 0);
4966 * [VF] Start Transmit and Receive Units.
4969 txgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
4971 struct txgbe_hw *hw;
4972 struct txgbe_tx_queue *txq;
4973 struct txgbe_rx_queue *rxq;
4979 PMD_INIT_FUNC_TRACE();
4980 hw = TXGBE_DEV_HW(dev);
4982 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4983 txq = dev->data->tx_queues[i];
4984 /* Setup Transmit Threshold Registers */
4985 wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
4986 TXGBE_TXCFG_HTHRESH_MASK |
4987 TXGBE_TXCFG_WTHRESH_MASK,
4988 TXGBE_TXCFG_HTHRESH(txq->hthresh) |
4989 TXGBE_TXCFG_WTHRESH(txq->wthresh));
4992 for (i = 0; i < dev->data->nb_tx_queues; i++) {
4993 wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
4996 /* Wait until TX Enable ready */
4999 txdctl = rd32(hw, TXGBE_TXCFG(i));
5000 } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
5002 PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
5004 for (i = 0; i < dev->data->nb_rx_queues; i++) {
5005 rxq = dev->data->rx_queues[i];
5007 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, TXGBE_RXCFG_ENA);
5009 /* Wait until RX Enable ready */
5013 rxdctl = rd32(hw, TXGBE_RXCFG(i));
5014 } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
5016 PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
5018 wr32(hw, TXGBE_RXWP(i), rxq->nb_rx_desc - 1);
5023 txgbe_rss_conf_init(struct txgbe_rte_flow_rss_conf *out,
5024 const struct rte_flow_action_rss *in)
5026 if (in->key_len > RTE_DIM(out->key) ||
5027 in->queue_num > RTE_DIM(out->queue))
5029 out->conf = (struct rte_flow_action_rss){
5033 .key_len = in->key_len,
5034 .queue_num = in->queue_num,
5035 .key = memcpy(out->key, in->key, in->key_len),
5036 .queue = memcpy(out->queue, in->queue,
5037 sizeof(*in->queue) * in->queue_num),
5043 txgbe_action_rss_same(const struct rte_flow_action_rss *comp,
5044 const struct rte_flow_action_rss *with)
5046 return (comp->func == with->func &&
5047 comp->level == with->level &&
5048 comp->types == with->types &&
5049 comp->key_len == with->key_len &&
5050 comp->queue_num == with->queue_num &&
5051 !memcmp(comp->key, with->key, with->key_len) &&
5052 !memcmp(comp->queue, with->queue,
5053 sizeof(*with->queue) * with->queue_num));
5057 txgbe_config_rss_filter(struct rte_eth_dev *dev,
5058 struct txgbe_rte_flow_rss_conf *conf, bool add)
5060 struct txgbe_hw *hw;
5064 struct rte_eth_rss_conf rss_conf = {
5065 .rss_key = conf->conf.key_len ?
5066 (void *)(uintptr_t)conf->conf.key : NULL,
5067 .rss_key_len = conf->conf.key_len,
5068 .rss_hf = conf->conf.types,
5070 struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
5072 PMD_INIT_FUNC_TRACE();
5073 hw = TXGBE_DEV_HW(dev);
5076 if (txgbe_action_rss_same(&filter_info->rss_info.conf,
5078 txgbe_rss_disable(dev);
5079 memset(&filter_info->rss_info, 0,
5080 sizeof(struct txgbe_rte_flow_rss_conf));
5086 if (filter_info->rss_info.conf.queue_num)
5088 /* Fill in redirection table
5089 * The byte-swap is needed because NIC registers are in
5090 * little-endian order.
5093 for (i = 0, j = 0; i < ETH_RSS_RETA_SIZE_128; i++, j++) {
5094 if (j == conf->conf.queue_num)
5096 reta = (reta >> 8) | LS32(conf->conf.queue[j], 24, 0xFF);
5098 wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
5101 /* Configure the RSS key and the RSS protocols used to compute
5102 * the RSS hash of input packets.
5104 if ((rss_conf.rss_hf & TXGBE_RSS_OFFLOAD_ALL) == 0) {
5105 txgbe_rss_disable(dev);
5108 if (rss_conf.rss_key == NULL)
5109 rss_conf.rss_key = rss_intel_key; /* Default hash key */
5110 txgbe_dev_rss_hash_update(dev, &rss_conf);
5112 if (txgbe_rss_conf_init(&filter_info->rss_info, &conf->conf))