1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
11 #include "sfc_debug.h"
15 #include "sfc_tweak.h"
16 #include "sfc_kvargs.h"
19 * Maximum number of TX queue flush attempts in case of
20 * failure or flush timeout
22 #define SFC_TX_QFLUSH_ATTEMPTS (3)
25 * Time to wait between event queue polling attempts when waiting for TX
26 * queue flush done or flush failed events
28 #define SFC_TX_QFLUSH_POLL_WAIT_MS (1)
31 * Maximum number of event queue polling attempts when waiting for TX queue
32 * flush done or flush failed events; it defines TX queue flush attempt timeout
33 * together with SFC_TX_QFLUSH_POLL_WAIT_MS
35 #define SFC_TX_QFLUSH_POLL_ATTEMPTS (2000)
38 sfc_tx_get_dev_offload_caps(struct sfc_adapter *sa)
40 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
43 if ((sa->dp_tx->features & SFC_DP_TX_FEAT_VLAN_INSERT) &&
44 encp->enc_hw_tx_insert_vlan_enabled)
45 caps |= DEV_TX_OFFLOAD_VLAN_INSERT;
47 if (sa->dp_tx->features & SFC_DP_TX_FEAT_MULTI_SEG)
48 caps |= DEV_TX_OFFLOAD_MULTI_SEGS;
50 if ((~sa->dp_tx->features & SFC_DP_TX_FEAT_MULTI_POOL) &&
51 (~sa->dp_tx->features & SFC_DP_TX_FEAT_REFCNT))
52 caps |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
58 sfc_tx_get_queue_offload_caps(struct sfc_adapter *sa)
60 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
63 caps |= DEV_TX_OFFLOAD_IPV4_CKSUM;
64 caps |= DEV_TX_OFFLOAD_UDP_CKSUM;
65 caps |= DEV_TX_OFFLOAD_TCP_CKSUM;
67 if (encp->enc_tunnel_encapsulations_supported)
68 caps |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
71 caps |= DEV_TX_OFFLOAD_TCP_TSO;
77 sfc_tx_log_offloads(struct sfc_adapter *sa, const char *offload_group,
78 const char *verdict, uint64_t offloads)
80 unsigned long long bit;
82 while ((bit = __builtin_ffsll(offloads)) != 0) {
83 uint64_t flag = (1ULL << --bit);
85 sfc_err(sa, "Tx %s offload %s %s", offload_group,
86 rte_eth_dev_tx_offload_name(flag), verdict);
93 sfc_tx_queue_offload_mismatch(struct sfc_adapter *sa, uint64_t requested)
95 uint64_t mandatory = sa->eth_dev->data->dev_conf.txmode.offloads;
96 uint64_t supported = sfc_tx_get_dev_offload_caps(sa) |
97 sfc_tx_get_queue_offload_caps(sa);
98 uint64_t rejected = requested & ~supported;
99 uint64_t missing = (requested & mandatory) ^ mandatory;
100 boolean_t mismatch = B_FALSE;
103 sfc_tx_log_offloads(sa, "queue", "is unsupported", rejected);
108 sfc_tx_log_offloads(sa, "queue", "must be set", missing);
116 sfc_tx_qcheck_conf(struct sfc_adapter *sa, unsigned int txq_max_fill_level,
117 const struct rte_eth_txconf *tx_conf)
121 if (tx_conf->tx_rs_thresh != 0) {
122 sfc_err(sa, "RS bit in transmit descriptor is not supported");
126 if (tx_conf->tx_free_thresh > txq_max_fill_level) {
128 "TxQ free threshold too large: %u vs maximum %u",
129 tx_conf->tx_free_thresh, txq_max_fill_level);
133 if (tx_conf->tx_thresh.pthresh != 0 ||
134 tx_conf->tx_thresh.hthresh != 0 ||
135 tx_conf->tx_thresh.wthresh != 0) {
137 "prefetch/host/writeback thresholds are not supported");
140 /* We either perform both TCP and UDP offload, or no offload at all */
141 if (((tx_conf->offloads & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) !=
142 ((tx_conf->offloads & DEV_TX_OFFLOAD_UDP_CKSUM) == 0)) {
143 sfc_err(sa, "TCP and UDP offloads can't be set independently");
147 if (sfc_tx_queue_offload_mismatch(sa, tx_conf->offloads))
154 sfc_tx_qflush_done(struct sfc_txq *txq)
156 txq->state |= SFC_TXQ_FLUSHED;
157 txq->state &= ~SFC_TXQ_FLUSHING;
161 sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
162 uint16_t nb_tx_desc, unsigned int socket_id,
163 const struct rte_eth_txconf *tx_conf)
165 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
166 unsigned int txq_entries;
167 unsigned int evq_entries;
168 unsigned int txq_max_fill_level;
169 struct sfc_txq_info *txq_info;
173 struct sfc_dp_tx_qcreate_info info;
175 sfc_log_init(sa, "TxQ = %u", sw_index);
177 rc = sa->dp_tx->qsize_up_rings(nb_tx_desc, &txq_entries, &evq_entries,
178 &txq_max_fill_level);
180 goto fail_size_up_rings;
181 SFC_ASSERT(txq_entries >= EFX_TXQ_MINNDESCS);
182 SFC_ASSERT(txq_entries <= sa->txq_max_entries);
183 SFC_ASSERT(txq_entries >= nb_tx_desc);
184 SFC_ASSERT(txq_max_fill_level <= nb_tx_desc);
186 rc = sfc_tx_qcheck_conf(sa, txq_max_fill_level, tx_conf);
190 SFC_ASSERT(sw_index < sa->txq_count);
191 txq_info = &sa->txq_info[sw_index];
193 txq_info->entries = txq_entries;
195 rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_TX, sw_index,
196 evq_entries, socket_id, &evq);
201 txq = rte_zmalloc_socket("sfc-txq", sizeof(*txq), 0, socket_id);
207 txq->hw_index = sw_index;
210 (tx_conf->tx_free_thresh) ? tx_conf->tx_free_thresh :
211 SFC_TX_DEFAULT_FREE_THRESH;
212 txq->flags = tx_conf->txq_flags;
213 txq->offloads = tx_conf->offloads;
215 rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_TXQ_SIZE(txq_info->entries),
216 socket_id, &txq->mem);
220 memset(&info, 0, sizeof(info));
221 info.max_fill_level = txq_max_fill_level;
222 info.free_thresh = txq->free_thresh;
223 info.flags = tx_conf->txq_flags;
224 info.offloads = tx_conf->offloads;
225 info.txq_entries = txq_info->entries;
226 info.dma_desc_size_max = encp->enc_tx_dma_desc_size_max;
227 info.txq_hw_ring = txq->mem.esm_base;
228 info.evq_entries = evq_entries;
229 info.evq_hw_ring = evq->mem.esm_base;
230 info.hw_index = txq->hw_index;
231 info.mem_bar = sa->mem_bar.esb_base;
232 info.vi_window_shift = encp->enc_vi_window_shift;
234 rc = sa->dp_tx->qcreate(sa->eth_dev->data->port_id, sw_index,
235 &RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr,
236 socket_id, &info, &txq->dp);
238 goto fail_dp_tx_qinit;
240 evq->dp_txq = txq->dp;
242 txq->state = SFC_TXQ_INITIALIZED;
244 txq_info->deferred_start = (tx_conf->tx_deferred_start != 0);
249 sfc_dma_free(sa, &txq->mem);
252 txq_info->txq = NULL;
259 txq_info->entries = 0;
263 sfc_log_init(sa, "failed (TxQ = %u, rc = %d)", sw_index, rc);
268 sfc_tx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
270 struct sfc_txq_info *txq_info;
273 sfc_log_init(sa, "TxQ = %u", sw_index);
275 SFC_ASSERT(sw_index < sa->txq_count);
276 txq_info = &sa->txq_info[sw_index];
279 SFC_ASSERT(txq != NULL);
280 SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
282 sa->dp_tx->qdestroy(txq->dp);
285 txq_info->txq = NULL;
286 txq_info->entries = 0;
288 sfc_dma_free(sa, &txq->mem);
290 sfc_ev_qfini(txq->evq);
297 sfc_tx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
299 sfc_log_init(sa, "TxQ = %u", sw_index);
305 sfc_tx_check_mode(struct sfc_adapter *sa, const struct rte_eth_txmode *txmode)
307 uint64_t offloads_supported = sfc_tx_get_dev_offload_caps(sa) |
308 sfc_tx_get_queue_offload_caps(sa);
309 uint64_t offloads_rejected = txmode->offloads & ~offloads_supported;
312 switch (txmode->mq_mode) {
316 sfc_err(sa, "Tx multi-queue mode %u not supported",
322 * These features are claimed to be i40e-specific,
323 * but it does make sense to double-check their absence
325 if (txmode->hw_vlan_reject_tagged) {
326 sfc_err(sa, "Rejecting tagged packets not supported");
330 if (txmode->hw_vlan_reject_untagged) {
331 sfc_err(sa, "Rejecting untagged packets not supported");
335 if (txmode->hw_vlan_insert_pvid) {
336 sfc_err(sa, "Port-based VLAN insertion not supported");
340 if (offloads_rejected) {
341 sfc_tx_log_offloads(sa, "device", "is unsupported",
350 * Destroy excess queues that are no longer needed after reconfiguration
354 sfc_tx_fini_queues(struct sfc_adapter *sa, unsigned int nb_tx_queues)
358 SFC_ASSERT(nb_tx_queues <= sa->txq_count);
360 sw_index = sa->txq_count;
361 while (--sw_index >= (int)nb_tx_queues) {
362 if (sa->txq_info[sw_index].txq != NULL)
363 sfc_tx_qfini(sa, sw_index);
366 sa->txq_count = nb_tx_queues;
370 sfc_tx_configure(struct sfc_adapter *sa)
372 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
373 const struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
374 const unsigned int nb_tx_queues = sa->eth_dev->data->nb_tx_queues;
377 sfc_log_init(sa, "nb_tx_queues=%u (old %u)",
378 nb_tx_queues, sa->txq_count);
381 * The datapath implementation assumes absence of boundary
382 * limits on Tx DMA descriptors. Addition of these checks on
383 * datapath would simply make the datapath slower.
385 if (encp->enc_tx_dma_desc_boundary != 0) {
387 goto fail_tx_dma_desc_boundary;
390 rc = sfc_tx_check_mode(sa, &dev_conf->txmode);
392 goto fail_check_mode;
394 if (nb_tx_queues == sa->txq_count)
397 if (sa->txq_info == NULL) {
398 sa->txq_info = rte_calloc_socket("sfc-txqs", nb_tx_queues,
399 sizeof(sa->txq_info[0]), 0,
401 if (sa->txq_info == NULL)
402 goto fail_txqs_alloc;
404 struct sfc_txq_info *new_txq_info;
406 if (nb_tx_queues < sa->txq_count)
407 sfc_tx_fini_queues(sa, nb_tx_queues);
410 rte_realloc(sa->txq_info,
411 nb_tx_queues * sizeof(sa->txq_info[0]), 0);
412 if (new_txq_info == NULL && nb_tx_queues > 0)
413 goto fail_txqs_realloc;
415 sa->txq_info = new_txq_info;
416 if (nb_tx_queues > sa->txq_count)
417 memset(&sa->txq_info[sa->txq_count], 0,
418 (nb_tx_queues - sa->txq_count) *
419 sizeof(sa->txq_info[0]));
422 while (sa->txq_count < nb_tx_queues) {
423 rc = sfc_tx_qinit_info(sa, sa->txq_count);
425 goto fail_tx_qinit_info;
439 fail_tx_dma_desc_boundary:
440 sfc_log_init(sa, "failed (rc = %d)", rc);
445 sfc_tx_close(struct sfc_adapter *sa)
447 sfc_tx_fini_queues(sa, 0);
449 rte_free(sa->txq_info);
454 sfc_tx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
456 uint64_t offloads_supported = sfc_tx_get_dev_offload_caps(sa) |
457 sfc_tx_get_queue_offload_caps(sa);
458 struct rte_eth_dev_data *dev_data;
459 struct sfc_txq_info *txq_info;
463 unsigned int desc_index;
466 sfc_log_init(sa, "TxQ = %u", sw_index);
468 SFC_ASSERT(sw_index < sa->txq_count);
469 txq_info = &sa->txq_info[sw_index];
473 SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
477 rc = sfc_ev_qstart(evq, sfc_evq_index_by_txq_sw_index(sa, sw_index));
482 * The absence of ETH_TXQ_FLAGS_IGNORE is associated with a legacy
483 * application which expects that IPv4 checksum offload is enabled
484 * all the time as there is no legacy flag to turn off the offload.
486 if ((txq->offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ||
487 (~txq->flags & ETH_TXQ_FLAGS_IGNORE))
488 flags |= EFX_TXQ_CKSUM_IPV4;
490 if ((txq->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
491 ((~txq->flags & ETH_TXQ_FLAGS_IGNORE) &&
492 (offloads_supported & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)))
493 flags |= EFX_TXQ_CKSUM_INNER_IPV4;
495 if ((txq->offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
496 (txq->offloads & DEV_TX_OFFLOAD_UDP_CKSUM)) {
497 flags |= EFX_TXQ_CKSUM_TCPUDP;
499 if ((~txq->flags & ETH_TXQ_FLAGS_IGNORE) &&
500 (offloads_supported & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
501 flags |= EFX_TXQ_CKSUM_INNER_TCPUDP;
505 * The absence of ETH_TXQ_FLAGS_IGNORE is associated with a legacy
506 * application. In turn, the absence of ETH_TXQ_FLAGS_NOXSUMTCP is
507 * associated specifically with a legacy application which expects
508 * both TCP checksum offload and TSO to be enabled because the legacy
509 * API does not provide a dedicated mechanism to control TSO.
511 if ((txq->offloads & DEV_TX_OFFLOAD_TCP_TSO) ||
512 ((~txq->flags & ETH_TXQ_FLAGS_IGNORE) &&
513 (~txq->flags & ETH_TXQ_FLAGS_NOXSUMTCP)))
514 flags |= EFX_TXQ_FATSOV2;
516 rc = efx_tx_qcreate(sa->nic, sw_index, 0, &txq->mem,
517 txq_info->entries, 0 /* not used on EF10 */,
519 &txq->common, &desc_index);
521 if (sa->tso && (rc == ENOSPC))
522 sfc_err(sa, "ran out of TSO contexts");
524 goto fail_tx_qcreate;
527 efx_tx_qenable(txq->common);
529 txq->state |= SFC_TXQ_STARTED;
531 rc = sa->dp_tx->qstart(txq->dp, evq->read_ptr, desc_index);
536 * It seems to be used by DPDK for debug purposes only ('rte_ether')
538 dev_data = sa->eth_dev->data;
539 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STARTED;
544 txq->state = SFC_TXQ_INITIALIZED;
545 efx_tx_qdestroy(txq->common);
555 sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index)
557 struct rte_eth_dev_data *dev_data;
558 struct sfc_txq_info *txq_info;
560 unsigned int retry_count;
561 unsigned int wait_count;
564 sfc_log_init(sa, "TxQ = %u", sw_index);
566 SFC_ASSERT(sw_index < sa->txq_count);
567 txq_info = &sa->txq_info[sw_index];
571 if (txq->state == SFC_TXQ_INITIALIZED)
574 SFC_ASSERT(txq->state & SFC_TXQ_STARTED);
576 sa->dp_tx->qstop(txq->dp, &txq->evq->read_ptr);
579 * Retry TX queue flushing in case of flush failed or
580 * timeout; in the worst case it can delay for 6 seconds
582 for (retry_count = 0;
583 ((txq->state & SFC_TXQ_FLUSHED) == 0) &&
584 (retry_count < SFC_TX_QFLUSH_ATTEMPTS);
586 rc = efx_tx_qflush(txq->common);
588 txq->state |= (rc == EALREADY) ?
589 SFC_TXQ_FLUSHED : SFC_TXQ_FLUSH_FAILED;
594 * Wait for TX queue flush done or flush failed event at least
595 * SFC_TX_QFLUSH_POLL_WAIT_MS milliseconds and not more
596 * than 2 seconds (SFC_TX_QFLUSH_POLL_WAIT_MS multiplied
597 * by SFC_TX_QFLUSH_POLL_ATTEMPTS)
601 rte_delay_ms(SFC_TX_QFLUSH_POLL_WAIT_MS);
602 sfc_ev_qpoll(txq->evq);
603 } while ((txq->state & SFC_TXQ_FLUSHING) &&
604 wait_count++ < SFC_TX_QFLUSH_POLL_ATTEMPTS);
606 if (txq->state & SFC_TXQ_FLUSHING)
607 sfc_err(sa, "TxQ %u flush timed out", sw_index);
609 if (txq->state & SFC_TXQ_FLUSHED)
610 sfc_notice(sa, "TxQ %u flushed", sw_index);
613 sa->dp_tx->qreap(txq->dp);
615 txq->state = SFC_TXQ_INITIALIZED;
617 efx_tx_qdestroy(txq->common);
619 sfc_ev_qstop(txq->evq);
622 * It seems to be used by DPDK for debug purposes only ('rte_ether')
624 dev_data = sa->eth_dev->data;
625 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STOPPED;
629 sfc_tx_start(struct sfc_adapter *sa)
631 unsigned int sw_index;
634 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
637 if (!efx_nic_cfg_get(sa->nic)->enc_fw_assisted_tso_v2_enabled) {
638 sfc_warn(sa, "TSO support was unable to be restored");
643 rc = efx_tx_init(sa->nic);
645 goto fail_efx_tx_init;
647 for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
648 if (!(sa->txq_info[sw_index].deferred_start) ||
649 sa->txq_info[sw_index].deferred_started) {
650 rc = sfc_tx_qstart(sa, sw_index);
659 while (sw_index-- > 0)
660 sfc_tx_qstop(sa, sw_index);
662 efx_tx_fini(sa->nic);
665 sfc_log_init(sa, "failed (rc = %d)", rc);
670 sfc_tx_stop(struct sfc_adapter *sa)
672 unsigned int sw_index;
674 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
676 sw_index = sa->txq_count;
677 while (sw_index-- > 0) {
678 if (sa->txq_info[sw_index].txq != NULL)
679 sfc_tx_qstop(sa, sw_index);
682 efx_tx_fini(sa->nic);
686 sfc_efx_tx_reap(struct sfc_efx_txq *txq)
688 unsigned int completed;
690 sfc_ev_qpoll(txq->evq);
692 for (completed = txq->completed;
693 completed != txq->pending; completed++) {
694 struct sfc_efx_tx_sw_desc *txd;
696 txd = &txq->sw_ring[completed & txq->ptr_mask];
698 if (txd->mbuf != NULL) {
699 rte_pktmbuf_free(txd->mbuf);
704 txq->completed = completed;
708 * The function is used to insert or update VLAN tag;
709 * the firmware has state of the firmware tag to insert per TxQ
710 * (controlled by option descriptors), hence, if the tag of the
711 * packet to be sent is different from one remembered by the firmware,
712 * the function will update it
715 sfc_efx_tx_maybe_insert_tag(struct sfc_efx_txq *txq, struct rte_mbuf *m,
718 uint16_t this_tag = ((m->ol_flags & PKT_TX_VLAN_PKT) ?
721 if (this_tag == txq->hw_vlan_tci)
725 * The expression inside SFC_ASSERT() is not desired to be checked in
726 * a non-debug build because it might be too expensive on the data path
728 SFC_ASSERT(efx_nic_cfg_get(txq->evq->sa->nic)->enc_hw_tx_insert_vlan_enabled);
730 efx_tx_qdesc_vlantci_create(txq->common, rte_cpu_to_be_16(this_tag),
733 txq->hw_vlan_tci = this_tag;
739 sfc_efx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
741 struct sfc_dp_txq *dp_txq = (struct sfc_dp_txq *)tx_queue;
742 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
743 unsigned int added = txq->added;
744 unsigned int pushed = added;
745 unsigned int pkts_sent = 0;
746 efx_desc_t *pend = &txq->pend_desc[0];
747 const unsigned int hard_max_fill = txq->max_fill_level;
748 const unsigned int soft_max_fill = hard_max_fill - txq->free_thresh;
749 unsigned int fill_level = added - txq->completed;
752 struct rte_mbuf **pktp;
754 if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) == 0))
758 * If insufficient space for a single packet is present,
759 * we should reap; otherwise, we shouldn't do that all the time
760 * to avoid latency increase
762 reap_done = (fill_level > soft_max_fill);
765 sfc_efx_tx_reap(txq);
767 * Recalculate fill level since 'txq->completed'
768 * might have changed on reap
770 fill_level = added - txq->completed;
773 for (pkts_sent = 0, pktp = &tx_pkts[0];
774 (pkts_sent < nb_pkts) && (fill_level <= soft_max_fill);
775 pkts_sent++, pktp++) {
776 struct rte_mbuf *m_seg = *pktp;
777 size_t pkt_len = m_seg->pkt_len;
778 unsigned int pkt_descs = 0;
782 * Here VLAN TCI is expected to be zero in case if no
783 * DEV_TX_OFFLOAD_VLAN_INSERT capability is advertised;
784 * if the calling app ignores the absence of
785 * DEV_TX_OFFLOAD_VLAN_INSERT and pushes VLAN TCI, then
786 * TX_ERROR will occur
788 pkt_descs += sfc_efx_tx_maybe_insert_tag(txq, m_seg, &pend);
790 if (m_seg->ol_flags & PKT_TX_TCP_SEG) {
792 * We expect correct 'pkt->l[2, 3, 4]_len' values
793 * to be set correctly by the caller
795 if (sfc_efx_tso_do(txq, added, &m_seg, &in_off, &pend,
796 &pkt_descs, &pkt_len) != 0) {
797 /* We may have reached this place for
798 * one of the following reasons:
800 * 1) Packet header length is greater
801 * than SFC_TSOH_STD_LEN
802 * 2) TCP header starts at more then
803 * 208 bytes into the frame
805 * We will deceive RTE saying that we have sent
806 * the packet, but we will actually drop it.
807 * Hence, we should revert 'pend' to the
808 * previous state (in case we have added
809 * VLAN descriptor) and start processing
810 * another one packet. But the original
811 * mbuf shouldn't be orphaned
815 rte_pktmbuf_free(*pktp);
821 * We've only added 2 FATSOv2 option descriptors
822 * and 1 descriptor for the linearized packet header.
823 * The outstanding work will be done in the same manner
824 * as for the usual non-TSO path
828 for (; m_seg != NULL; m_seg = m_seg->next) {
829 efsys_dma_addr_t next_frag;
832 seg_len = m_seg->data_len;
833 next_frag = rte_mbuf_data_iova(m_seg);
836 * If we've started TSO transaction few steps earlier,
837 * we'll skip packet header using an offset in the
838 * current segment (which has been set to the
839 * first one containing payload)
846 efsys_dma_addr_t frag_addr = next_frag;
850 * It is assumed here that there is no
851 * limitation on address boundary
852 * crossing by DMA descriptor.
854 frag_len = MIN(seg_len, txq->dma_desc_size_max);
855 next_frag += frag_len;
859 efx_tx_qdesc_dma_create(txq->common,
865 } while (seg_len != 0);
870 fill_level += pkt_descs;
871 if (unlikely(fill_level > hard_max_fill)) {
873 * Our estimation for maximum number of descriptors
874 * required to send a packet seems to be wrong.
875 * Try to reap (if we haven't yet).
878 sfc_efx_tx_reap(txq);
880 fill_level = added - txq->completed;
881 if (fill_level > hard_max_fill) {
891 /* Assign mbuf to the last used desc */
892 txq->sw_ring[(added - 1) & txq->ptr_mask].mbuf = *pktp;
895 if (likely(pkts_sent > 0)) {
896 rc = efx_tx_qdesc_post(txq->common, txq->pend_desc,
897 pend - &txq->pend_desc[0],
898 txq->completed, &txq->added);
901 if (likely(pushed != txq->added))
902 efx_tx_qpush(txq->common, txq->added, pushed);
905 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
907 sfc_efx_tx_reap(txq);
915 sfc_txq_by_dp_txq(const struct sfc_dp_txq *dp_txq)
917 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
918 struct rte_eth_dev *eth_dev;
919 struct sfc_adapter *sa;
922 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
923 eth_dev = &rte_eth_devices[dpq->port_id];
925 sa = eth_dev->data->dev_private;
927 SFC_ASSERT(dpq->queue_id < sa->txq_count);
928 txq = sa->txq_info[dpq->queue_id].txq;
930 SFC_ASSERT(txq != NULL);
934 static sfc_dp_tx_qsize_up_rings_t sfc_efx_tx_qsize_up_rings;
936 sfc_efx_tx_qsize_up_rings(uint16_t nb_tx_desc,
937 unsigned int *txq_entries,
938 unsigned int *evq_entries,
939 unsigned int *txq_max_fill_level)
941 *txq_entries = nb_tx_desc;
942 *evq_entries = nb_tx_desc;
943 *txq_max_fill_level = EFX_TXQ_LIMIT(*txq_entries);
947 static sfc_dp_tx_qcreate_t sfc_efx_tx_qcreate;
949 sfc_efx_tx_qcreate(uint16_t port_id, uint16_t queue_id,
950 const struct rte_pci_addr *pci_addr,
952 const struct sfc_dp_tx_qcreate_info *info,
953 struct sfc_dp_txq **dp_txqp)
955 struct sfc_efx_txq *txq;
956 struct sfc_txq *ctrl_txq;
960 txq = rte_zmalloc_socket("sfc-efx-txq", sizeof(*txq),
961 RTE_CACHE_LINE_SIZE, socket_id);
965 sfc_dp_queue_init(&txq->dp.dpq, port_id, queue_id, pci_addr);
968 txq->pend_desc = rte_calloc_socket("sfc-efx-txq-pend-desc",
969 EFX_TXQ_LIMIT(info->txq_entries),
970 sizeof(*txq->pend_desc), 0,
972 if (txq->pend_desc == NULL)
973 goto fail_pend_desc_alloc;
976 txq->sw_ring = rte_calloc_socket("sfc-efx-txq-sw_ring",
978 sizeof(*txq->sw_ring),
979 RTE_CACHE_LINE_SIZE, socket_id);
980 if (txq->sw_ring == NULL)
981 goto fail_sw_ring_alloc;
983 ctrl_txq = sfc_txq_by_dp_txq(&txq->dp);
984 if (ctrl_txq->evq->sa->tso) {
985 rc = sfc_efx_tso_alloc_tsoh_objs(txq->sw_ring,
986 info->txq_entries, socket_id);
988 goto fail_alloc_tsoh_objs;
991 txq->evq = ctrl_txq->evq;
992 txq->ptr_mask = info->txq_entries - 1;
993 txq->max_fill_level = info->max_fill_level;
994 txq->free_thresh = info->free_thresh;
995 txq->dma_desc_size_max = info->dma_desc_size_max;
1000 fail_alloc_tsoh_objs:
1001 rte_free(txq->sw_ring);
1004 rte_free(txq->pend_desc);
1006 fail_pend_desc_alloc:
1013 static sfc_dp_tx_qdestroy_t sfc_efx_tx_qdestroy;
1015 sfc_efx_tx_qdestroy(struct sfc_dp_txq *dp_txq)
1017 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1019 sfc_efx_tso_free_tsoh_objs(txq->sw_ring, txq->ptr_mask + 1);
1020 rte_free(txq->sw_ring);
1021 rte_free(txq->pend_desc);
1025 static sfc_dp_tx_qstart_t sfc_efx_tx_qstart;
1027 sfc_efx_tx_qstart(struct sfc_dp_txq *dp_txq,
1028 __rte_unused unsigned int evq_read_ptr,
1029 unsigned int txq_desc_index)
1031 /* libefx-based datapath is specific to libefx-based PMD */
1032 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1033 struct sfc_txq *ctrl_txq = sfc_txq_by_dp_txq(dp_txq);
1035 txq->common = ctrl_txq->common;
1037 txq->pending = txq->completed = txq->added = txq_desc_index;
1038 txq->hw_vlan_tci = 0;
1040 txq->flags |= (SFC_EFX_TXQ_FLAG_STARTED | SFC_EFX_TXQ_FLAG_RUNNING);
1045 static sfc_dp_tx_qstop_t sfc_efx_tx_qstop;
1047 sfc_efx_tx_qstop(struct sfc_dp_txq *dp_txq,
1048 __rte_unused unsigned int *evq_read_ptr)
1050 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1052 txq->flags &= ~SFC_EFX_TXQ_FLAG_RUNNING;
1055 static sfc_dp_tx_qreap_t sfc_efx_tx_qreap;
1057 sfc_efx_tx_qreap(struct sfc_dp_txq *dp_txq)
1059 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1062 sfc_efx_tx_reap(txq);
1064 for (txds = 0; txds <= txq->ptr_mask; txds++) {
1065 if (txq->sw_ring[txds].mbuf != NULL) {
1066 rte_pktmbuf_free(txq->sw_ring[txds].mbuf);
1067 txq->sw_ring[txds].mbuf = NULL;
1071 txq->flags &= ~SFC_EFX_TXQ_FLAG_STARTED;
1074 static sfc_dp_tx_qdesc_status_t sfc_efx_tx_qdesc_status;
1076 sfc_efx_tx_qdesc_status(struct sfc_dp_txq *dp_txq, uint16_t offset)
1078 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1080 if (unlikely(offset > txq->ptr_mask))
1083 if (unlikely(offset >= txq->max_fill_level))
1084 return RTE_ETH_TX_DESC_UNAVAIL;
1087 * Poll EvQ to derive up-to-date 'txq->pending' figure;
1088 * it is required for the queue to be running, but the
1089 * check is omitted because API design assumes that it
1090 * is the duty of the caller to satisfy all conditions
1092 SFC_ASSERT((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) ==
1093 SFC_EFX_TXQ_FLAG_RUNNING);
1094 sfc_ev_qpoll(txq->evq);
1097 * Ring tail is 'txq->pending', and although descriptors
1098 * between 'txq->completed' and 'txq->pending' are still
1099 * in use by the driver, they should be reported as DONE
1101 if (unlikely(offset < (txq->added - txq->pending)))
1102 return RTE_ETH_TX_DESC_FULL;
1105 * There is no separate return value for unused descriptors;
1106 * the latter will be reported as DONE because genuine DONE
1107 * descriptors will be freed anyway in SW on the next burst
1109 return RTE_ETH_TX_DESC_DONE;
1112 struct sfc_dp_tx sfc_efx_tx = {
1114 .name = SFC_KVARG_DATAPATH_EFX,
1118 .features = SFC_DP_TX_FEAT_VLAN_INSERT |
1119 SFC_DP_TX_FEAT_TSO |
1120 SFC_DP_TX_FEAT_MULTI_POOL |
1121 SFC_DP_TX_FEAT_REFCNT |
1122 SFC_DP_TX_FEAT_MULTI_SEG,
1123 .qsize_up_rings = sfc_efx_tx_qsize_up_rings,
1124 .qcreate = sfc_efx_tx_qcreate,
1125 .qdestroy = sfc_efx_tx_qdestroy,
1126 .qstart = sfc_efx_tx_qstart,
1127 .qstop = sfc_efx_tx_qstop,
1128 .qreap = sfc_efx_tx_qreap,
1129 .qdesc_status = sfc_efx_tx_qdesc_status,
1130 .pkt_burst = sfc_efx_xmit_pkts,