4 * Copyright (c) 2016-2017 Solarflare Communications Inc.
7 * This software was jointly developed between OKTET Labs (under contract
8 * for Solarflare) and Solarflare Communications, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "sfc_debug.h"
37 #include "sfc_tweak.h"
38 #include "sfc_kvargs.h"
41 * Maximum number of TX queue flush attempts in case of
42 * failure or flush timeout
44 #define SFC_TX_QFLUSH_ATTEMPTS (3)
47 * Time to wait between event queue polling attempts when waiting for TX
48 * queue flush done or flush failed events
50 #define SFC_TX_QFLUSH_POLL_WAIT_MS (1)
53 * Maximum number of event queue polling attempts when waiting for TX queue
54 * flush done or flush failed events; it defines TX queue flush attempt timeout
55 * together with SFC_TX_QFLUSH_POLL_WAIT_MS
57 #define SFC_TX_QFLUSH_POLL_ATTEMPTS (2000)
60 sfc_tx_qcheck_conf(struct sfc_adapter *sa, uint16_t nb_tx_desc,
61 const struct rte_eth_txconf *tx_conf)
63 unsigned int flags = tx_conf->txq_flags;
64 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
67 if (tx_conf->tx_rs_thresh != 0) {
68 sfc_err(sa, "RS bit in transmit descriptor is not supported");
72 if (tx_conf->tx_free_thresh > EFX_TXQ_LIMIT(nb_tx_desc)) {
74 "TxQ free threshold too large: %u vs maximum %u",
75 tx_conf->tx_free_thresh, EFX_TXQ_LIMIT(nb_tx_desc));
79 if (tx_conf->tx_thresh.pthresh != 0 ||
80 tx_conf->tx_thresh.hthresh != 0 ||
81 tx_conf->tx_thresh.wthresh != 0) {
83 "prefetch/host/writeback thresholds are not supported");
87 if (((flags & ETH_TXQ_FLAGS_NOMULTSEGS) == 0) &&
88 (~sa->dp_tx->features & SFC_DP_TX_FEAT_MULTI_SEG)) {
89 sfc_err(sa, "Multi-segment is not supported by %s datapath",
94 if ((flags & ETH_TXQ_FLAGS_NOVLANOFFL) == 0) {
95 if (!encp->enc_hw_tx_insert_vlan_enabled) {
96 sfc_err(sa, "VLAN offload is not supported");
98 } else if (~sa->dp_tx->features & SFC_DP_TX_FEAT_VLAN_INSERT) {
100 "VLAN offload is not supported by %s datapath",
106 if ((flags & ETH_TXQ_FLAGS_NOXSUMSCTP) == 0) {
107 sfc_err(sa, "SCTP offload is not supported");
111 /* We either perform both TCP and UDP offload, or no offload at all */
112 if (((flags & ETH_TXQ_FLAGS_NOXSUMTCP) == 0) !=
113 ((flags & ETH_TXQ_FLAGS_NOXSUMUDP) == 0)) {
114 sfc_err(sa, "TCP and UDP offloads can't be set independently");
122 sfc_tx_qflush_done(struct sfc_txq *txq)
124 txq->state |= SFC_TXQ_FLUSHED;
125 txq->state &= ~SFC_TXQ_FLUSHING;
129 sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
130 uint16_t nb_tx_desc, unsigned int socket_id,
131 const struct rte_eth_txconf *tx_conf)
133 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
134 struct sfc_txq_info *txq_info;
138 struct sfc_dp_tx_qcreate_info info;
140 sfc_log_init(sa, "TxQ = %u", sw_index);
142 rc = sfc_tx_qcheck_conf(sa, nb_tx_desc, tx_conf);
146 SFC_ASSERT(sw_index < sa->txq_count);
147 txq_info = &sa->txq_info[sw_index];
149 SFC_ASSERT(nb_tx_desc <= sa->txq_max_entries);
150 txq_info->entries = nb_tx_desc;
152 rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_TX, sw_index,
153 txq_info->entries, socket_id, &evq);
158 txq = rte_zmalloc_socket("sfc-txq", sizeof(*txq), 0, socket_id);
164 txq->hw_index = sw_index;
167 (tx_conf->tx_free_thresh) ? tx_conf->tx_free_thresh :
168 SFC_TX_DEFAULT_FREE_THRESH;
169 txq->flags = tx_conf->txq_flags;
171 rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_TXQ_SIZE(txq_info->entries),
172 socket_id, &txq->mem);
176 memset(&info, 0, sizeof(info));
177 info.free_thresh = txq->free_thresh;
178 info.flags = tx_conf->txq_flags;
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 = txq_info->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;
187 rc = sa->dp_tx->qcreate(sa->eth_dev->data->port_id, sw_index,
188 &RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr,
189 socket_id, &info, &txq->dp);
191 goto fail_dp_tx_qinit;
193 evq->dp_txq = txq->dp;
195 txq->state = SFC_TXQ_INITIALIZED;
197 txq_info->deferred_start = (tx_conf->tx_deferred_start != 0);
202 sfc_dma_free(sa, &txq->mem);
205 txq_info->txq = NULL;
212 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 txq_info = &sa->txq_info[sw_index];
231 SFC_ASSERT(txq != NULL);
232 SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
234 sa->dp_tx->qdestroy(txq->dp);
237 txq_info->txq = NULL;
238 txq_info->entries = 0;
240 sfc_dma_free(sa, &txq->mem);
242 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].txq != NULL)
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;
347 struct sfc_txq_info *new_txq_info;
349 if (nb_tx_queues < sa->txq_count)
350 sfc_tx_fini_queues(sa, nb_tx_queues);
353 rte_realloc(sa->txq_info,
354 nb_tx_queues * sizeof(sa->txq_info[0]), 0);
355 if (new_txq_info == NULL && nb_tx_queues > 0)
356 goto fail_txqs_realloc;
358 sa->txq_info = new_txq_info;
359 if (nb_tx_queues > sa->txq_count)
360 memset(&sa->txq_info[sa->txq_count], 0,
361 (nb_tx_queues - sa->txq_count) *
362 sizeof(sa->txq_info[0]));
365 while (sa->txq_count < nb_tx_queues) {
366 rc = sfc_tx_qinit_info(sa, sa->txq_count);
368 goto fail_tx_qinit_info;
382 fail_tx_dma_desc_boundary:
383 sfc_log_init(sa, "failed (rc = %d)", rc);
388 sfc_tx_close(struct sfc_adapter *sa)
390 sfc_tx_fini_queues(sa, 0);
392 rte_free(sa->txq_info);
397 sfc_tx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
399 struct rte_eth_dev_data *dev_data;
400 struct sfc_txq_info *txq_info;
404 unsigned int desc_index;
407 sfc_log_init(sa, "TxQ = %u", sw_index);
409 SFC_ASSERT(sw_index < sa->txq_count);
410 txq_info = &sa->txq_info[sw_index];
414 SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
418 rc = sfc_ev_qstart(evq, sfc_evq_index_by_txq_sw_index(sa, sw_index));
423 * It seems that DPDK has no controls regarding IPv4 offloads,
424 * hence, we always enable it here
426 if ((txq->flags & ETH_TXQ_FLAGS_NOXSUMTCP) ||
427 (txq->flags & ETH_TXQ_FLAGS_NOXSUMUDP)) {
428 flags = EFX_TXQ_CKSUM_IPV4;
430 flags = EFX_TXQ_CKSUM_IPV4 | EFX_TXQ_CKSUM_TCPUDP;
433 flags |= EFX_TXQ_FATSOV2;
436 rc = efx_tx_qcreate(sa->nic, sw_index, 0, &txq->mem,
437 txq_info->entries, 0 /* not used on EF10 */,
439 &txq->common, &desc_index);
441 if (sa->tso && (rc == ENOSPC))
442 sfc_err(sa, "ran out of TSO contexts");
444 goto fail_tx_qcreate;
447 efx_tx_qenable(txq->common);
449 txq->state |= SFC_TXQ_STARTED;
451 rc = sa->dp_tx->qstart(txq->dp, evq->read_ptr, desc_index);
456 * It seems to be used by DPDK for debug purposes only ('rte_ether')
458 dev_data = sa->eth_dev->data;
459 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STARTED;
464 txq->state = SFC_TXQ_INITIALIZED;
465 efx_tx_qdestroy(txq->common);
475 sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index)
477 struct rte_eth_dev_data *dev_data;
478 struct sfc_txq_info *txq_info;
480 unsigned int retry_count;
481 unsigned int wait_count;
484 sfc_log_init(sa, "TxQ = %u", sw_index);
486 SFC_ASSERT(sw_index < sa->txq_count);
487 txq_info = &sa->txq_info[sw_index];
491 if (txq->state == SFC_TXQ_INITIALIZED)
494 SFC_ASSERT(txq->state & SFC_TXQ_STARTED);
496 sa->dp_tx->qstop(txq->dp, &txq->evq->read_ptr);
499 * Retry TX queue flushing in case of flush failed or
500 * timeout; in the worst case it can delay for 6 seconds
502 for (retry_count = 0;
503 ((txq->state & SFC_TXQ_FLUSHED) == 0) &&
504 (retry_count < SFC_TX_QFLUSH_ATTEMPTS);
506 rc = efx_tx_qflush(txq->common);
508 txq->state |= (rc == EALREADY) ?
509 SFC_TXQ_FLUSHED : SFC_TXQ_FLUSH_FAILED;
514 * Wait for TX queue flush done or flush failed event at least
515 * SFC_TX_QFLUSH_POLL_WAIT_MS milliseconds and not more
516 * than 2 seconds (SFC_TX_QFLUSH_POLL_WAIT_MS multiplied
517 * by SFC_TX_QFLUSH_POLL_ATTEMPTS)
521 rte_delay_ms(SFC_TX_QFLUSH_POLL_WAIT_MS);
522 sfc_ev_qpoll(txq->evq);
523 } while ((txq->state & SFC_TXQ_FLUSHING) &&
524 wait_count++ < SFC_TX_QFLUSH_POLL_ATTEMPTS);
526 if (txq->state & SFC_TXQ_FLUSHING)
527 sfc_err(sa, "TxQ %u flush timed out", sw_index);
529 if (txq->state & SFC_TXQ_FLUSHED)
530 sfc_info(sa, "TxQ %u flushed", sw_index);
533 sa->dp_tx->qreap(txq->dp);
535 txq->state = SFC_TXQ_INITIALIZED;
537 efx_tx_qdestroy(txq->common);
539 sfc_ev_qstop(txq->evq);
542 * It seems to be used by DPDK for debug purposes only ('rte_ether')
544 dev_data = sa->eth_dev->data;
545 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STOPPED;
549 sfc_tx_start(struct sfc_adapter *sa)
551 unsigned int sw_index;
554 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
557 if (!efx_nic_cfg_get(sa->nic)->enc_fw_assisted_tso_v2_enabled) {
558 sfc_warn(sa, "TSO support was unable to be restored");
563 rc = efx_tx_init(sa->nic);
565 goto fail_efx_tx_init;
567 for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
568 if (!(sa->txq_info[sw_index].deferred_start) ||
569 sa->txq_info[sw_index].deferred_started) {
570 rc = sfc_tx_qstart(sa, sw_index);
579 while (sw_index-- > 0)
580 sfc_tx_qstop(sa, sw_index);
582 efx_tx_fini(sa->nic);
585 sfc_log_init(sa, "failed (rc = %d)", rc);
590 sfc_tx_stop(struct sfc_adapter *sa)
592 unsigned int sw_index;
594 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
596 sw_index = sa->txq_count;
597 while (sw_index-- > 0) {
598 if (sa->txq_info[sw_index].txq != NULL)
599 sfc_tx_qstop(sa, sw_index);
602 efx_tx_fini(sa->nic);
606 sfc_efx_tx_reap(struct sfc_efx_txq *txq)
608 unsigned int completed;
610 sfc_ev_qpoll(txq->evq);
612 for (completed = txq->completed;
613 completed != txq->pending; completed++) {
614 struct sfc_efx_tx_sw_desc *txd;
616 txd = &txq->sw_ring[completed & txq->ptr_mask];
618 if (txd->mbuf != NULL) {
619 rte_pktmbuf_free(txd->mbuf);
624 txq->completed = completed;
628 * The function is used to insert or update VLAN tag;
629 * the firmware has state of the firmware tag to insert per TxQ
630 * (controlled by option descriptors), hence, if the tag of the
631 * packet to be sent is different from one remembered by the firmware,
632 * the function will update it
635 sfc_efx_tx_maybe_insert_tag(struct sfc_efx_txq *txq, struct rte_mbuf *m,
638 uint16_t this_tag = ((m->ol_flags & PKT_TX_VLAN_PKT) ?
641 if (this_tag == txq->hw_vlan_tci)
645 * The expression inside SFC_ASSERT() is not desired to be checked in
646 * a non-debug build because it might be too expensive on the data path
648 SFC_ASSERT(efx_nic_cfg_get(txq->evq->sa->nic)->enc_hw_tx_insert_vlan_enabled);
650 efx_tx_qdesc_vlantci_create(txq->common, rte_cpu_to_be_16(this_tag),
653 txq->hw_vlan_tci = this_tag;
659 sfc_efx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
661 struct sfc_dp_txq *dp_txq = (struct sfc_dp_txq *)tx_queue;
662 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
663 unsigned int added = txq->added;
664 unsigned int pushed = added;
665 unsigned int pkts_sent = 0;
666 efx_desc_t *pend = &txq->pend_desc[0];
667 const unsigned int hard_max_fill = EFX_TXQ_LIMIT(txq->ptr_mask + 1);
668 const unsigned int soft_max_fill = hard_max_fill - txq->free_thresh;
669 unsigned int fill_level = added - txq->completed;
672 struct rte_mbuf **pktp;
674 if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) == 0))
678 * If insufficient space for a single packet is present,
679 * we should reap; otherwise, we shouldn't do that all the time
680 * to avoid latency increase
682 reap_done = (fill_level > soft_max_fill);
685 sfc_efx_tx_reap(txq);
687 * Recalculate fill level since 'txq->completed'
688 * might have changed on reap
690 fill_level = added - txq->completed;
693 for (pkts_sent = 0, pktp = &tx_pkts[0];
694 (pkts_sent < nb_pkts) && (fill_level <= soft_max_fill);
695 pkts_sent++, pktp++) {
696 struct rte_mbuf *m_seg = *pktp;
697 size_t pkt_len = m_seg->pkt_len;
698 unsigned int pkt_descs = 0;
702 * Here VLAN TCI is expected to be zero in case if no
703 * DEV_TX_VLAN_OFFLOAD capability is advertised;
704 * if the calling app ignores the absence of
705 * DEV_TX_VLAN_OFFLOAD and pushes VLAN TCI, then
706 * TX_ERROR will occur
708 pkt_descs += sfc_efx_tx_maybe_insert_tag(txq, m_seg, &pend);
710 if (m_seg->ol_flags & PKT_TX_TCP_SEG) {
712 * We expect correct 'pkt->l[2, 3, 4]_len' values
713 * to be set correctly by the caller
715 if (sfc_efx_tso_do(txq, added, &m_seg, &in_off, &pend,
716 &pkt_descs, &pkt_len) != 0) {
717 /* We may have reached this place for
718 * one of the following reasons:
720 * 1) Packet header length is greater
721 * than SFC_TSOH_STD_LEN
722 * 2) TCP header starts at more then
723 * 208 bytes into the frame
725 * We will deceive RTE saying that we have sent
726 * the packet, but we will actually drop it.
727 * Hence, we should revert 'pend' to the
728 * previous state (in case we have added
729 * VLAN descriptor) and start processing
730 * another one packet. But the original
731 * mbuf shouldn't be orphaned
735 rte_pktmbuf_free(*pktp);
741 * We've only added 2 FATSOv2 option descriptors
742 * and 1 descriptor for the linearized packet header.
743 * The outstanding work will be done in the same manner
744 * as for the usual non-TSO path
748 for (; m_seg != NULL; m_seg = m_seg->next) {
749 efsys_dma_addr_t next_frag;
752 seg_len = m_seg->data_len;
753 next_frag = rte_mbuf_data_dma_addr(m_seg);
756 * If we've started TSO transaction few steps earlier,
757 * we'll skip packet header using an offset in the
758 * current segment (which has been set to the
759 * first one containing payload)
766 efsys_dma_addr_t frag_addr = next_frag;
770 * It is assumed here that there is no
771 * limitation on address boundary
772 * crossing by DMA descriptor.
774 frag_len = MIN(seg_len, txq->dma_desc_size_max);
775 next_frag += frag_len;
779 efx_tx_qdesc_dma_create(txq->common,
785 } while (seg_len != 0);
790 fill_level += pkt_descs;
791 if (unlikely(fill_level > hard_max_fill)) {
793 * Our estimation for maximum number of descriptors
794 * required to send a packet seems to be wrong.
795 * Try to reap (if we haven't yet).
798 sfc_efx_tx_reap(txq);
800 fill_level = added - txq->completed;
801 if (fill_level > hard_max_fill) {
811 /* Assign mbuf to the last used desc */
812 txq->sw_ring[(added - 1) & txq->ptr_mask].mbuf = *pktp;
815 if (likely(pkts_sent > 0)) {
816 rc = efx_tx_qdesc_post(txq->common, txq->pend_desc,
817 pend - &txq->pend_desc[0],
818 txq->completed, &txq->added);
821 if (likely(pushed != txq->added))
822 efx_tx_qpush(txq->common, txq->added, pushed);
825 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
827 sfc_efx_tx_reap(txq);
835 sfc_txq_by_dp_txq(const struct sfc_dp_txq *dp_txq)
837 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
838 struct rte_eth_dev *eth_dev;
839 struct sfc_adapter *sa;
842 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
843 eth_dev = &rte_eth_devices[dpq->port_id];
845 sa = eth_dev->data->dev_private;
847 SFC_ASSERT(dpq->queue_id < sa->txq_count);
848 txq = sa->txq_info[dpq->queue_id].txq;
850 SFC_ASSERT(txq != NULL);
854 static sfc_dp_tx_qcreate_t sfc_efx_tx_qcreate;
856 sfc_efx_tx_qcreate(uint16_t port_id, uint16_t queue_id,
857 const struct rte_pci_addr *pci_addr,
859 const struct sfc_dp_tx_qcreate_info *info,
860 struct sfc_dp_txq **dp_txqp)
862 struct sfc_efx_txq *txq;
863 struct sfc_txq *ctrl_txq;
867 txq = rte_zmalloc_socket("sfc-efx-txq", sizeof(*txq),
868 RTE_CACHE_LINE_SIZE, socket_id);
872 sfc_dp_queue_init(&txq->dp.dpq, port_id, queue_id, pci_addr);
875 txq->pend_desc = rte_calloc_socket("sfc-efx-txq-pend-desc",
876 EFX_TXQ_LIMIT(info->txq_entries),
877 sizeof(*txq->pend_desc), 0,
879 if (txq->pend_desc == NULL)
880 goto fail_pend_desc_alloc;
883 txq->sw_ring = rte_calloc_socket("sfc-efx-txq-sw_ring",
885 sizeof(*txq->sw_ring),
886 RTE_CACHE_LINE_SIZE, socket_id);
887 if (txq->sw_ring == NULL)
888 goto fail_sw_ring_alloc;
890 ctrl_txq = sfc_txq_by_dp_txq(&txq->dp);
891 if (ctrl_txq->evq->sa->tso) {
892 rc = sfc_efx_tso_alloc_tsoh_objs(txq->sw_ring,
893 info->txq_entries, socket_id);
895 goto fail_alloc_tsoh_objs;
898 txq->evq = ctrl_txq->evq;
899 txq->ptr_mask = info->txq_entries - 1;
900 txq->free_thresh = info->free_thresh;
901 txq->dma_desc_size_max = info->dma_desc_size_max;
906 fail_alloc_tsoh_objs:
907 rte_free(txq->sw_ring);
910 rte_free(txq->pend_desc);
912 fail_pend_desc_alloc:
919 static sfc_dp_tx_qdestroy_t sfc_efx_tx_qdestroy;
921 sfc_efx_tx_qdestroy(struct sfc_dp_txq *dp_txq)
923 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
925 sfc_efx_tso_free_tsoh_objs(txq->sw_ring, txq->ptr_mask + 1);
926 rte_free(txq->sw_ring);
927 rte_free(txq->pend_desc);
931 static sfc_dp_tx_qstart_t sfc_efx_tx_qstart;
933 sfc_efx_tx_qstart(struct sfc_dp_txq *dp_txq,
934 __rte_unused unsigned int evq_read_ptr,
935 unsigned int txq_desc_index)
937 /* libefx-based datapath is specific to libefx-based PMD */
938 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
939 struct sfc_txq *ctrl_txq = sfc_txq_by_dp_txq(dp_txq);
941 txq->common = ctrl_txq->common;
943 txq->pending = txq->completed = txq->added = txq_desc_index;
944 txq->hw_vlan_tci = 0;
946 txq->flags |= (SFC_EFX_TXQ_FLAG_STARTED | SFC_EFX_TXQ_FLAG_RUNNING);
951 static sfc_dp_tx_qstop_t sfc_efx_tx_qstop;
953 sfc_efx_tx_qstop(struct sfc_dp_txq *dp_txq,
954 __rte_unused unsigned int *evq_read_ptr)
956 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
958 txq->flags &= ~SFC_EFX_TXQ_FLAG_RUNNING;
961 static sfc_dp_tx_qreap_t sfc_efx_tx_qreap;
963 sfc_efx_tx_qreap(struct sfc_dp_txq *dp_txq)
965 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
968 sfc_efx_tx_reap(txq);
970 for (txds = 0; txds <= txq->ptr_mask; txds++) {
971 if (txq->sw_ring[txds].mbuf != NULL) {
972 rte_pktmbuf_free(txq->sw_ring[txds].mbuf);
973 txq->sw_ring[txds].mbuf = NULL;
977 txq->flags &= ~SFC_EFX_TXQ_FLAG_STARTED;
980 static sfc_dp_tx_qdesc_status_t sfc_efx_tx_qdesc_status;
982 sfc_efx_tx_qdesc_status(struct sfc_dp_txq *dp_txq, uint16_t offset)
984 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
986 if (unlikely(offset > txq->ptr_mask))
989 if (unlikely(offset >= EFX_TXQ_LIMIT(txq->ptr_mask + 1)))
990 return RTE_ETH_TX_DESC_UNAVAIL;
993 * Poll EvQ to derive up-to-date 'txq->pending' figure;
994 * it is required for the queue to be running, but the
995 * check is omitted because API design assumes that it
996 * is the duty of the caller to satisfy all conditions
998 SFC_ASSERT((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) ==
999 SFC_EFX_TXQ_FLAG_RUNNING);
1000 sfc_ev_qpoll(txq->evq);
1003 * Ring tail is 'txq->pending', and although descriptors
1004 * between 'txq->completed' and 'txq->pending' are still
1005 * in use by the driver, they should be reported as DONE
1007 if (unlikely(offset < (txq->added - txq->pending)))
1008 return RTE_ETH_TX_DESC_FULL;
1011 * There is no separate return value for unused descriptors;
1012 * the latter will be reported as DONE because genuine DONE
1013 * descriptors will be freed anyway in SW on the next burst
1015 return RTE_ETH_TX_DESC_DONE;
1018 struct sfc_dp_tx sfc_efx_tx = {
1020 .name = SFC_KVARG_DATAPATH_EFX,
1024 .features = SFC_DP_TX_FEAT_VLAN_INSERT |
1025 SFC_DP_TX_FEAT_TSO |
1026 SFC_DP_TX_FEAT_MULTI_SEG,
1027 .qcreate = sfc_efx_tx_qcreate,
1028 .qdestroy = sfc_efx_tx_qdestroy,
1029 .qstart = sfc_efx_tx_qstart,
1030 .qstop = sfc_efx_tx_qstop,
1031 .qreap = sfc_efx_tx_qreap,
1032 .qdesc_status = sfc_efx_tx_qdesc_status,
1033 .pkt_burst = sfc_efx_xmit_pkts,