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->priv.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->priv.dp_tx->features & SFC_DP_TX_FEAT_MULTI_SEG)
48 caps |= DEV_TX_OFFLOAD_MULTI_SEGS;
50 if ((~sa->priv.dp_tx->features & SFC_DP_TX_FEAT_MULTI_POOL) &&
51 (~sa->priv.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_qcheck_conf(struct sfc_adapter *sa, unsigned int txq_max_fill_level,
78 const struct rte_eth_txconf *tx_conf,
83 if (tx_conf->tx_rs_thresh != 0) {
84 sfc_err(sa, "RS bit in transmit descriptor is not supported");
88 if (tx_conf->tx_free_thresh > txq_max_fill_level) {
90 "TxQ free threshold too large: %u vs maximum %u",
91 tx_conf->tx_free_thresh, txq_max_fill_level);
95 if (tx_conf->tx_thresh.pthresh != 0 ||
96 tx_conf->tx_thresh.hthresh != 0 ||
97 tx_conf->tx_thresh.wthresh != 0) {
99 "prefetch/host/writeback thresholds are not supported");
102 /* We either perform both TCP and UDP offload, or no offload at all */
103 if (((offloads & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) !=
104 ((offloads & DEV_TX_OFFLOAD_UDP_CKSUM) == 0)) {
105 sfc_err(sa, "TCP and UDP offloads can't be set independently");
113 sfc_tx_qflush_done(struct sfc_txq_info *txq_info)
115 txq_info->state |= SFC_TXQ_FLUSHED;
116 txq_info->state &= ~SFC_TXQ_FLUSHING;
120 sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
121 uint16_t nb_tx_desc, unsigned int socket_id,
122 const struct rte_eth_txconf *tx_conf)
124 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
125 unsigned int txq_entries;
126 unsigned int evq_entries;
127 unsigned int txq_max_fill_level;
128 struct sfc_txq_info *txq_info;
132 struct sfc_dp_tx_qcreate_info info;
135 sfc_log_init(sa, "TxQ = %u", sw_index);
137 rc = sa->priv.dp_tx->qsize_up_rings(nb_tx_desc, &txq_entries,
138 &evq_entries, &txq_max_fill_level);
140 goto fail_size_up_rings;
141 SFC_ASSERT(txq_entries >= EFX_TXQ_MINNDESCS);
142 SFC_ASSERT(txq_entries <= sa->txq_max_entries);
143 SFC_ASSERT(txq_entries >= nb_tx_desc);
144 SFC_ASSERT(txq_max_fill_level <= nb_tx_desc);
146 offloads = tx_conf->offloads |
147 sa->eth_dev->data->dev_conf.txmode.offloads;
148 rc = sfc_tx_qcheck_conf(sa, txq_max_fill_level, tx_conf, offloads);
152 SFC_ASSERT(sw_index < sa->txq_count);
153 txq_info = &sa->txq_info[sw_index];
155 txq_info->entries = txq_entries;
157 rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_TX, sw_index,
158 evq_entries, socket_id, &evq);
162 txq = &sa->txq_ctrl[sw_index];
163 txq->hw_index = sw_index;
165 txq_info->free_thresh =
166 (tx_conf->tx_free_thresh) ? tx_conf->tx_free_thresh :
167 SFC_TX_DEFAULT_FREE_THRESH;
168 txq_info->offloads = offloads;
170 rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_TXQ_SIZE(txq_info->entries),
171 socket_id, &txq->mem);
175 memset(&info, 0, sizeof(info));
176 info.max_fill_level = txq_max_fill_level;
177 info.free_thresh = txq_info->free_thresh;
178 info.offloads = offloads;
179 info.txq_entries = txq_info->entries;
180 info.dma_desc_size_max = encp->enc_tx_dma_desc_size_max;
181 info.txq_hw_ring = txq->mem.esm_base;
182 info.evq_entries = evq_entries;
183 info.evq_hw_ring = evq->mem.esm_base;
184 info.hw_index = txq->hw_index;
185 info.mem_bar = sa->mem_bar.esb_base;
186 info.vi_window_shift = encp->enc_vi_window_shift;
187 info.tso_tcp_header_offset_limit =
188 encp->enc_tx_tso_tcp_header_offset_limit;
190 rc = sa->priv.dp_tx->qcreate(sa->eth_dev->data->port_id, sw_index,
191 &RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr,
192 socket_id, &info, &txq_info->dp);
194 goto fail_dp_tx_qinit;
196 evq->dp_txq = txq_info->dp;
198 txq_info->state = SFC_TXQ_INITIALIZED;
200 txq_info->deferred_start = (tx_conf->tx_deferred_start != 0);
205 sfc_dma_free(sa, &txq->mem);
211 txq_info->entries = 0;
215 sfc_log_init(sa, "failed (TxQ = %u, rc = %d)", sw_index, rc);
220 sfc_tx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
222 struct sfc_txq_info *txq_info;
225 sfc_log_init(sa, "TxQ = %u", sw_index);
227 SFC_ASSERT(sw_index < sa->txq_count);
228 sa->eth_dev->data->tx_queues[sw_index] = NULL;
230 txq_info = &sa->txq_info[sw_index];
232 SFC_ASSERT(txq_info->state == SFC_TXQ_INITIALIZED);
234 sa->priv.dp_tx->qdestroy(txq_info->dp);
237 txq_info->state &= ~SFC_TXQ_INITIALIZED;
238 txq_info->entries = 0;
240 txq = &sa->txq_ctrl[sw_index];
242 sfc_dma_free(sa, &txq->mem);
244 sfc_ev_qfini(txq->evq);
249 sfc_tx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
251 sfc_log_init(sa, "TxQ = %u", sw_index);
257 sfc_tx_check_mode(struct sfc_adapter *sa, const struct rte_eth_txmode *txmode)
261 switch (txmode->mq_mode) {
265 sfc_err(sa, "Tx multi-queue mode %u not supported",
271 * These features are claimed to be i40e-specific,
272 * but it does make sense to double-check their absence
274 if (txmode->hw_vlan_reject_tagged) {
275 sfc_err(sa, "Rejecting tagged packets not supported");
279 if (txmode->hw_vlan_reject_untagged) {
280 sfc_err(sa, "Rejecting untagged packets not supported");
284 if (txmode->hw_vlan_insert_pvid) {
285 sfc_err(sa, "Port-based VLAN insertion not supported");
293 * Destroy excess queues that are no longer needed after reconfiguration
297 sfc_tx_fini_queues(struct sfc_adapter *sa, unsigned int nb_tx_queues)
301 SFC_ASSERT(nb_tx_queues <= sa->txq_count);
303 sw_index = sa->txq_count;
304 while (--sw_index >= (int)nb_tx_queues) {
305 if (sa->txq_info[sw_index].state & SFC_TXQ_INITIALIZED)
306 sfc_tx_qfini(sa, sw_index);
309 sa->txq_count = nb_tx_queues;
313 sfc_tx_configure(struct sfc_adapter *sa)
315 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
316 const struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
317 const unsigned int nb_tx_queues = sa->eth_dev->data->nb_tx_queues;
320 sfc_log_init(sa, "nb_tx_queues=%u (old %u)",
321 nb_tx_queues, sa->txq_count);
324 * The datapath implementation assumes absence of boundary
325 * limits on Tx DMA descriptors. Addition of these checks on
326 * datapath would simply make the datapath slower.
328 if (encp->enc_tx_dma_desc_boundary != 0) {
330 goto fail_tx_dma_desc_boundary;
333 rc = sfc_tx_check_mode(sa, &dev_conf->txmode);
335 goto fail_check_mode;
337 if (nb_tx_queues == sa->txq_count)
340 if (sa->txq_info == NULL) {
341 sa->txq_info = rte_calloc_socket("sfc-txqs", nb_tx_queues,
342 sizeof(sa->txq_info[0]), 0,
344 if (sa->txq_info == NULL)
345 goto fail_txqs_alloc;
348 * Allocate primary process only TxQ control from heap
349 * since it should not be shared.
352 sa->txq_ctrl = calloc(nb_tx_queues, sizeof(sa->txq_ctrl[0]));
353 if (sa->txq_ctrl == NULL)
354 goto fail_txqs_ctrl_alloc;
356 struct sfc_txq_info *new_txq_info;
357 struct sfc_txq *new_txq_ctrl;
359 if (nb_tx_queues < sa->txq_count)
360 sfc_tx_fini_queues(sa, nb_tx_queues);
363 rte_realloc(sa->txq_info,
364 nb_tx_queues * sizeof(sa->txq_info[0]), 0);
365 if (new_txq_info == NULL && nb_tx_queues > 0)
366 goto fail_txqs_realloc;
368 new_txq_ctrl = realloc(sa->txq_ctrl,
369 nb_tx_queues * sizeof(sa->txq_ctrl[0]));
370 if (new_txq_ctrl == NULL && nb_tx_queues > 0)
371 goto fail_txqs_ctrl_realloc;
373 sa->txq_info = new_txq_info;
374 sa->txq_ctrl = new_txq_ctrl;
375 if (nb_tx_queues > sa->txq_count) {
376 memset(&sa->txq_info[sa->txq_count], 0,
377 (nb_tx_queues - sa->txq_count) *
378 sizeof(sa->txq_info[0]));
379 memset(&sa->txq_ctrl[sa->txq_count], 0,
380 (nb_tx_queues - sa->txq_count) *
381 sizeof(sa->txq_ctrl[0]));
385 while (sa->txq_count < nb_tx_queues) {
386 rc = sfc_tx_qinit_info(sa, sa->txq_count);
388 goto fail_tx_qinit_info;
397 fail_txqs_ctrl_realloc:
399 fail_txqs_ctrl_alloc:
404 fail_tx_dma_desc_boundary:
405 sfc_log_init(sa, "failed (rc = %d)", rc);
410 sfc_tx_close(struct sfc_adapter *sa)
412 sfc_tx_fini_queues(sa, 0);
417 rte_free(sa->txq_info);
422 sfc_tx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
424 uint64_t offloads_supported = sfc_tx_get_dev_offload_caps(sa) |
425 sfc_tx_get_queue_offload_caps(sa);
426 struct rte_eth_dev_data *dev_data;
427 struct sfc_txq_info *txq_info;
431 unsigned int desc_index;
434 sfc_log_init(sa, "TxQ = %u", sw_index);
436 SFC_ASSERT(sw_index < sa->txq_count);
437 txq_info = &sa->txq_info[sw_index];
439 SFC_ASSERT(txq_info->state == SFC_TXQ_INITIALIZED);
441 txq = &sa->txq_ctrl[sw_index];
444 rc = sfc_ev_qstart(evq, sfc_evq_index_by_txq_sw_index(sa, sw_index));
448 if (txq_info->offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
449 flags |= EFX_TXQ_CKSUM_IPV4;
451 if (txq_info->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
452 flags |= EFX_TXQ_CKSUM_INNER_IPV4;
454 if ((txq_info->offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
455 (txq_info->offloads & DEV_TX_OFFLOAD_UDP_CKSUM)) {
456 flags |= EFX_TXQ_CKSUM_TCPUDP;
458 if (offloads_supported & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
459 flags |= EFX_TXQ_CKSUM_INNER_TCPUDP;
462 if (txq_info->offloads & DEV_TX_OFFLOAD_TCP_TSO)
463 flags |= EFX_TXQ_FATSOV2;
465 rc = efx_tx_qcreate(sa->nic, txq->hw_index, 0, &txq->mem,
466 txq_info->entries, 0 /* not used on EF10 */,
468 &txq->common, &desc_index);
470 if (sa->tso && (rc == ENOSPC))
471 sfc_err(sa, "ran out of TSO contexts");
473 goto fail_tx_qcreate;
476 efx_tx_qenable(txq->common);
478 txq_info->state |= SFC_TXQ_STARTED;
480 rc = sa->priv.dp_tx->qstart(txq_info->dp, evq->read_ptr, desc_index);
485 * It seems to be used by DPDK for debug purposes only ('rte_ether')
487 dev_data = sa->eth_dev->data;
488 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STARTED;
493 txq_info->state = SFC_TXQ_INITIALIZED;
494 efx_tx_qdestroy(txq->common);
504 sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index)
506 struct rte_eth_dev_data *dev_data;
507 struct sfc_txq_info *txq_info;
509 unsigned int retry_count;
510 unsigned int wait_count;
513 sfc_log_init(sa, "TxQ = %u", sw_index);
515 SFC_ASSERT(sw_index < sa->txq_count);
516 txq_info = &sa->txq_info[sw_index];
518 if (txq_info->state == SFC_TXQ_INITIALIZED)
521 SFC_ASSERT(txq_info->state & SFC_TXQ_STARTED);
523 txq = &sa->txq_ctrl[sw_index];
524 sa->priv.dp_tx->qstop(txq_info->dp, &txq->evq->read_ptr);
527 * Retry TX queue flushing in case of flush failed or
528 * timeout; in the worst case it can delay for 6 seconds
530 for (retry_count = 0;
531 ((txq_info->state & SFC_TXQ_FLUSHED) == 0) &&
532 (retry_count < SFC_TX_QFLUSH_ATTEMPTS);
534 rc = efx_tx_qflush(txq->common);
536 txq_info->state |= (rc == EALREADY) ?
537 SFC_TXQ_FLUSHED : SFC_TXQ_FLUSH_FAILED;
542 * Wait for TX queue flush done or flush failed event at least
543 * SFC_TX_QFLUSH_POLL_WAIT_MS milliseconds and not more
544 * than 2 seconds (SFC_TX_QFLUSH_POLL_WAIT_MS multiplied
545 * by SFC_TX_QFLUSH_POLL_ATTEMPTS)
549 rte_delay_ms(SFC_TX_QFLUSH_POLL_WAIT_MS);
550 sfc_ev_qpoll(txq->evq);
551 } while ((txq_info->state & SFC_TXQ_FLUSHING) &&
552 wait_count++ < SFC_TX_QFLUSH_POLL_ATTEMPTS);
554 if (txq_info->state & SFC_TXQ_FLUSHING)
555 sfc_err(sa, "TxQ %u flush timed out", sw_index);
557 if (txq_info->state & SFC_TXQ_FLUSHED)
558 sfc_notice(sa, "TxQ %u flushed", sw_index);
561 sa->priv.dp_tx->qreap(txq_info->dp);
563 txq_info->state = SFC_TXQ_INITIALIZED;
565 efx_tx_qdestroy(txq->common);
567 sfc_ev_qstop(txq->evq);
570 * It seems to be used by DPDK for debug purposes only ('rte_ether')
572 dev_data = sa->eth_dev->data;
573 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STOPPED;
577 sfc_tx_start(struct sfc_adapter *sa)
579 unsigned int sw_index;
582 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
585 if (!efx_nic_cfg_get(sa->nic)->enc_fw_assisted_tso_v2_enabled) {
586 sfc_warn(sa, "TSO support was unable to be restored");
591 rc = efx_tx_init(sa->nic);
593 goto fail_efx_tx_init;
595 for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
596 if (sa->txq_info[sw_index].state == SFC_TXQ_INITIALIZED &&
597 (!(sa->txq_info[sw_index].deferred_start) ||
598 sa->txq_info[sw_index].deferred_started)) {
599 rc = sfc_tx_qstart(sa, sw_index);
608 while (sw_index-- > 0)
609 sfc_tx_qstop(sa, sw_index);
611 efx_tx_fini(sa->nic);
614 sfc_log_init(sa, "failed (rc = %d)", rc);
619 sfc_tx_stop(struct sfc_adapter *sa)
621 unsigned int sw_index;
623 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
625 sw_index = sa->txq_count;
626 while (sw_index-- > 0) {
627 if (sa->txq_info[sw_index].state & SFC_TXQ_STARTED)
628 sfc_tx_qstop(sa, sw_index);
631 efx_tx_fini(sa->nic);
635 sfc_efx_tx_reap(struct sfc_efx_txq *txq)
637 unsigned int completed;
639 sfc_ev_qpoll(txq->evq);
641 for (completed = txq->completed;
642 completed != txq->pending; completed++) {
643 struct sfc_efx_tx_sw_desc *txd;
645 txd = &txq->sw_ring[completed & txq->ptr_mask];
647 if (txd->mbuf != NULL) {
648 rte_pktmbuf_free(txd->mbuf);
653 txq->completed = completed;
657 * The function is used to insert or update VLAN tag;
658 * the firmware has state of the firmware tag to insert per TxQ
659 * (controlled by option descriptors), hence, if the tag of the
660 * packet to be sent is different from one remembered by the firmware,
661 * the function will update it
664 sfc_efx_tx_maybe_insert_tag(struct sfc_efx_txq *txq, struct rte_mbuf *m,
667 uint16_t this_tag = ((m->ol_flags & PKT_TX_VLAN_PKT) ?
670 if (this_tag == txq->hw_vlan_tci)
674 * The expression inside SFC_ASSERT() is not desired to be checked in
675 * a non-debug build because it might be too expensive on the data path
677 SFC_ASSERT(efx_nic_cfg_get(txq->evq->sa->nic)->enc_hw_tx_insert_vlan_enabled);
679 efx_tx_qdesc_vlantci_create(txq->common, rte_cpu_to_be_16(this_tag),
682 txq->hw_vlan_tci = this_tag;
688 sfc_efx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
690 struct sfc_dp_txq *dp_txq = (struct sfc_dp_txq *)tx_queue;
691 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
692 unsigned int added = txq->added;
693 unsigned int pushed = added;
694 unsigned int pkts_sent = 0;
695 efx_desc_t *pend = &txq->pend_desc[0];
696 const unsigned int hard_max_fill = txq->max_fill_level;
697 const unsigned int soft_max_fill = hard_max_fill - txq->free_thresh;
698 unsigned int fill_level = added - txq->completed;
701 struct rte_mbuf **pktp;
703 if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) == 0))
707 * If insufficient space for a single packet is present,
708 * we should reap; otherwise, we shouldn't do that all the time
709 * to avoid latency increase
711 reap_done = (fill_level > soft_max_fill);
714 sfc_efx_tx_reap(txq);
716 * Recalculate fill level since 'txq->completed'
717 * might have changed on reap
719 fill_level = added - txq->completed;
722 for (pkts_sent = 0, pktp = &tx_pkts[0];
723 (pkts_sent < nb_pkts) && (fill_level <= soft_max_fill);
724 pkts_sent++, pktp++) {
725 uint16_t hw_vlan_tci_prev = txq->hw_vlan_tci;
726 struct rte_mbuf *m_seg = *pktp;
727 size_t pkt_len = m_seg->pkt_len;
728 unsigned int pkt_descs = 0;
732 * Here VLAN TCI is expected to be zero in case if no
733 * DEV_TX_OFFLOAD_VLAN_INSERT capability is advertised;
734 * if the calling app ignores the absence of
735 * DEV_TX_OFFLOAD_VLAN_INSERT and pushes VLAN TCI, then
736 * TX_ERROR will occur
738 pkt_descs += sfc_efx_tx_maybe_insert_tag(txq, m_seg, &pend);
740 if (m_seg->ol_flags & PKT_TX_TCP_SEG) {
742 * We expect correct 'pkt->l[2, 3, 4]_len' values
743 * to be set correctly by the caller
745 if (sfc_efx_tso_do(txq, added, &m_seg, &in_off, &pend,
746 &pkt_descs, &pkt_len) != 0) {
747 /* We may have reached this place for
748 * one of the following reasons:
750 * 1) Packet header length is greater
751 * than SFC_TSOH_STD_LEN
752 * 2) TCP header starts at more then
753 * 208 bytes into the frame
755 * We will deceive RTE saying that we have sent
756 * the packet, but we will actually drop it.
757 * Hence, we should revert 'pend' to the
758 * previous state (in case we have added
759 * VLAN descriptor) and start processing
760 * another one packet. But the original
761 * mbuf shouldn't be orphaned
764 txq->hw_vlan_tci = hw_vlan_tci_prev;
766 rte_pktmbuf_free(*pktp);
772 * We've only added 2 FATSOv2 option descriptors
773 * and 1 descriptor for the linearized packet header.
774 * The outstanding work will be done in the same manner
775 * as for the usual non-TSO path
779 for (; m_seg != NULL; m_seg = m_seg->next) {
780 efsys_dma_addr_t next_frag;
783 seg_len = m_seg->data_len;
784 next_frag = rte_mbuf_data_iova(m_seg);
787 * If we've started TSO transaction few steps earlier,
788 * we'll skip packet header using an offset in the
789 * current segment (which has been set to the
790 * first one containing payload)
797 efsys_dma_addr_t frag_addr = next_frag;
801 * It is assumed here that there is no
802 * limitation on address boundary
803 * crossing by DMA descriptor.
805 frag_len = MIN(seg_len, txq->dma_desc_size_max);
806 next_frag += frag_len;
810 efx_tx_qdesc_dma_create(txq->common,
816 } while (seg_len != 0);
821 fill_level += pkt_descs;
822 if (unlikely(fill_level > hard_max_fill)) {
824 * Our estimation for maximum number of descriptors
825 * required to send a packet seems to be wrong.
826 * Try to reap (if we haven't yet).
829 sfc_efx_tx_reap(txq);
831 fill_level = added - txq->completed;
832 if (fill_level > hard_max_fill) {
834 txq->hw_vlan_tci = hw_vlan_tci_prev;
839 txq->hw_vlan_tci = hw_vlan_tci_prev;
844 /* Assign mbuf to the last used desc */
845 txq->sw_ring[(added - 1) & txq->ptr_mask].mbuf = *pktp;
848 if (likely(pkts_sent > 0)) {
849 rc = efx_tx_qdesc_post(txq->common, txq->pend_desc,
850 pend - &txq->pend_desc[0],
851 txq->completed, &txq->added);
854 if (likely(pushed != txq->added))
855 efx_tx_qpush(txq->common, txq->added, pushed);
858 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
860 sfc_efx_tx_reap(txq);
867 const struct sfc_dp_tx *
868 sfc_dp_tx_by_dp_txq(const struct sfc_dp_txq *dp_txq)
870 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
871 struct rte_eth_dev *eth_dev;
872 struct sfc_adapter_priv *sap;
874 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
875 eth_dev = &rte_eth_devices[dpq->port_id];
877 sap = sfc_adapter_priv_by_eth_dev(eth_dev);
882 struct sfc_txq_info *
883 sfc_txq_info_by_dp_txq(const struct sfc_dp_txq *dp_txq)
885 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
886 struct rte_eth_dev *eth_dev;
887 struct sfc_adapter *sa;
889 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
890 eth_dev = &rte_eth_devices[dpq->port_id];
892 sa = eth_dev->data->dev_private;
894 SFC_ASSERT(dpq->queue_id < sa->txq_count);
895 return &sa->txq_info[dpq->queue_id];
899 sfc_txq_by_dp_txq(const struct sfc_dp_txq *dp_txq)
901 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
902 struct rte_eth_dev *eth_dev;
903 struct sfc_adapter *sa;
905 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
906 eth_dev = &rte_eth_devices[dpq->port_id];
908 sa = eth_dev->data->dev_private;
910 SFC_ASSERT(dpq->queue_id < sa->txq_count);
911 return &sa->txq_ctrl[dpq->queue_id];
914 static sfc_dp_tx_qsize_up_rings_t sfc_efx_tx_qsize_up_rings;
916 sfc_efx_tx_qsize_up_rings(uint16_t nb_tx_desc,
917 unsigned int *txq_entries,
918 unsigned int *evq_entries,
919 unsigned int *txq_max_fill_level)
921 *txq_entries = nb_tx_desc;
922 *evq_entries = nb_tx_desc;
923 *txq_max_fill_level = EFX_TXQ_LIMIT(*txq_entries);
927 static sfc_dp_tx_qcreate_t sfc_efx_tx_qcreate;
929 sfc_efx_tx_qcreate(uint16_t port_id, uint16_t queue_id,
930 const struct rte_pci_addr *pci_addr,
932 const struct sfc_dp_tx_qcreate_info *info,
933 struct sfc_dp_txq **dp_txqp)
935 struct sfc_efx_txq *txq;
936 struct sfc_txq *ctrl_txq;
940 txq = rte_zmalloc_socket("sfc-efx-txq", sizeof(*txq),
941 RTE_CACHE_LINE_SIZE, socket_id);
945 sfc_dp_queue_init(&txq->dp.dpq, port_id, queue_id, pci_addr);
948 txq->pend_desc = rte_calloc_socket("sfc-efx-txq-pend-desc",
949 EFX_TXQ_LIMIT(info->txq_entries),
950 sizeof(*txq->pend_desc), 0,
952 if (txq->pend_desc == NULL)
953 goto fail_pend_desc_alloc;
956 txq->sw_ring = rte_calloc_socket("sfc-efx-txq-sw_ring",
958 sizeof(*txq->sw_ring),
959 RTE_CACHE_LINE_SIZE, socket_id);
960 if (txq->sw_ring == NULL)
961 goto fail_sw_ring_alloc;
963 ctrl_txq = sfc_txq_by_dp_txq(&txq->dp);
964 if (ctrl_txq->evq->sa->tso) {
965 rc = sfc_efx_tso_alloc_tsoh_objs(txq->sw_ring,
966 info->txq_entries, socket_id);
968 goto fail_alloc_tsoh_objs;
971 txq->evq = ctrl_txq->evq;
972 txq->ptr_mask = info->txq_entries - 1;
973 txq->max_fill_level = info->max_fill_level;
974 txq->free_thresh = info->free_thresh;
975 txq->dma_desc_size_max = info->dma_desc_size_max;
980 fail_alloc_tsoh_objs:
981 rte_free(txq->sw_ring);
984 rte_free(txq->pend_desc);
986 fail_pend_desc_alloc:
993 static sfc_dp_tx_qdestroy_t sfc_efx_tx_qdestroy;
995 sfc_efx_tx_qdestroy(struct sfc_dp_txq *dp_txq)
997 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
999 sfc_efx_tso_free_tsoh_objs(txq->sw_ring, txq->ptr_mask + 1);
1000 rte_free(txq->sw_ring);
1001 rte_free(txq->pend_desc);
1005 static sfc_dp_tx_qstart_t sfc_efx_tx_qstart;
1007 sfc_efx_tx_qstart(struct sfc_dp_txq *dp_txq,
1008 __rte_unused unsigned int evq_read_ptr,
1009 unsigned int txq_desc_index)
1011 /* libefx-based datapath is specific to libefx-based PMD */
1012 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1013 struct sfc_txq *ctrl_txq = sfc_txq_by_dp_txq(dp_txq);
1015 txq->common = ctrl_txq->common;
1017 txq->pending = txq->completed = txq->added = txq_desc_index;
1018 txq->hw_vlan_tci = 0;
1020 txq->flags |= (SFC_EFX_TXQ_FLAG_STARTED | SFC_EFX_TXQ_FLAG_RUNNING);
1025 static sfc_dp_tx_qstop_t sfc_efx_tx_qstop;
1027 sfc_efx_tx_qstop(struct sfc_dp_txq *dp_txq,
1028 __rte_unused unsigned int *evq_read_ptr)
1030 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1032 txq->flags &= ~SFC_EFX_TXQ_FLAG_RUNNING;
1035 static sfc_dp_tx_qreap_t sfc_efx_tx_qreap;
1037 sfc_efx_tx_qreap(struct sfc_dp_txq *dp_txq)
1039 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1042 sfc_efx_tx_reap(txq);
1044 for (txds = 0; txds <= txq->ptr_mask; txds++) {
1045 if (txq->sw_ring[txds].mbuf != NULL) {
1046 rte_pktmbuf_free(txq->sw_ring[txds].mbuf);
1047 txq->sw_ring[txds].mbuf = NULL;
1051 txq->flags &= ~SFC_EFX_TXQ_FLAG_STARTED;
1054 static sfc_dp_tx_qdesc_status_t sfc_efx_tx_qdesc_status;
1056 sfc_efx_tx_qdesc_status(struct sfc_dp_txq *dp_txq, uint16_t offset)
1058 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1060 if (unlikely(offset > txq->ptr_mask))
1063 if (unlikely(offset >= txq->max_fill_level))
1064 return RTE_ETH_TX_DESC_UNAVAIL;
1067 * Poll EvQ to derive up-to-date 'txq->pending' figure;
1068 * it is required for the queue to be running, but the
1069 * check is omitted because API design assumes that it
1070 * is the duty of the caller to satisfy all conditions
1072 SFC_ASSERT((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) ==
1073 SFC_EFX_TXQ_FLAG_RUNNING);
1074 sfc_ev_qpoll(txq->evq);
1077 * Ring tail is 'txq->pending', and although descriptors
1078 * between 'txq->completed' and 'txq->pending' are still
1079 * in use by the driver, they should be reported as DONE
1081 if (unlikely(offset < (txq->added - txq->pending)))
1082 return RTE_ETH_TX_DESC_FULL;
1085 * There is no separate return value for unused descriptors;
1086 * the latter will be reported as DONE because genuine DONE
1087 * descriptors will be freed anyway in SW on the next burst
1089 return RTE_ETH_TX_DESC_DONE;
1092 struct sfc_dp_tx sfc_efx_tx = {
1094 .name = SFC_KVARG_DATAPATH_EFX,
1098 .features = SFC_DP_TX_FEAT_VLAN_INSERT |
1099 SFC_DP_TX_FEAT_TSO |
1100 SFC_DP_TX_FEAT_MULTI_POOL |
1101 SFC_DP_TX_FEAT_REFCNT |
1102 SFC_DP_TX_FEAT_MULTI_SEG,
1103 .qsize_up_rings = sfc_efx_tx_qsize_up_rings,
1104 .qcreate = sfc_efx_tx_qcreate,
1105 .qdestroy = sfc_efx_tx_qdestroy,
1106 .qstart = sfc_efx_tx_qstart,
1107 .qstop = sfc_efx_tx_qstop,
1108 .qreap = sfc_efx_tx_qreap,
1109 .qdesc_status = sfc_efx_tx_qdesc_status,
1110 .pkt_burst = sfc_efx_xmit_pkts,