1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2016-2019 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_txq_info_by_ethdev_qid(struct sfc_adapter_shared *sas,
39 sfc_ethdev_qid_t ethdev_qid)
41 sfc_sw_index_t sw_index;
43 SFC_ASSERT((unsigned int)ethdev_qid < sas->ethdev_txq_count);
44 SFC_ASSERT(ethdev_qid != SFC_ETHDEV_QID_INVALID);
46 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
47 return &sas->txq_info[sw_index];
51 sfc_tx_get_offload_mask(struct sfc_adapter *sa)
53 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
56 if (!encp->enc_hw_tx_insert_vlan_enabled)
57 no_caps |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
59 if (!encp->enc_tunnel_encapsulations_supported)
60 no_caps |= RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
63 no_caps |= RTE_ETH_TX_OFFLOAD_TCP_TSO;
66 (encp->enc_tunnel_encapsulations_supported &
67 (1u << EFX_TUNNEL_PROTOCOL_VXLAN)) == 0)
68 no_caps |= RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO;
71 (encp->enc_tunnel_encapsulations_supported &
72 (1u << EFX_TUNNEL_PROTOCOL_GENEVE)) == 0)
73 no_caps |= RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO;
79 sfc_tx_get_dev_offload_caps(struct sfc_adapter *sa)
81 return sa->priv.dp_tx->dev_offload_capa & sfc_tx_get_offload_mask(sa);
85 sfc_tx_get_queue_offload_caps(struct sfc_adapter *sa)
87 return sa->priv.dp_tx->queue_offload_capa & sfc_tx_get_offload_mask(sa);
91 sfc_tx_qcheck_conf(struct sfc_adapter *sa, unsigned int txq_max_fill_level,
92 const struct rte_eth_txconf *tx_conf,
97 if (tx_conf->tx_rs_thresh != 0) {
98 sfc_err(sa, "RS bit in transmit descriptor is not supported");
102 if (tx_conf->tx_free_thresh > txq_max_fill_level) {
104 "TxQ free threshold too large: %u vs maximum %u",
105 tx_conf->tx_free_thresh, txq_max_fill_level);
109 if (tx_conf->tx_thresh.pthresh != 0 ||
110 tx_conf->tx_thresh.hthresh != 0 ||
111 tx_conf->tx_thresh.wthresh != 0) {
113 "prefetch/host/writeback thresholds are not supported");
116 /* We either perform both TCP and UDP offload, or no offload at all */
117 if (((offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) !=
118 ((offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0)) {
119 sfc_err(sa, "TCP and UDP offloads can't be set independently");
127 sfc_tx_qflush_done(struct sfc_txq_info *txq_info)
129 txq_info->state |= SFC_TXQ_FLUSHED;
130 txq_info->state &= ~SFC_TXQ_FLUSHING;
134 sfc_tx_qinit(struct sfc_adapter *sa, sfc_sw_index_t sw_index,
135 uint16_t nb_tx_desc, unsigned int socket_id,
136 const struct rte_eth_txconf *tx_conf)
138 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
139 sfc_ethdev_qid_t ethdev_qid;
140 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
141 unsigned int txq_entries;
142 unsigned int evq_entries;
143 unsigned int txq_max_fill_level;
144 struct sfc_txq_info *txq_info;
148 struct sfc_dp_tx_qcreate_info info;
150 struct sfc_dp_tx_hw_limits hw_limits;
152 ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
154 sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
156 memset(&hw_limits, 0, sizeof(hw_limits));
157 hw_limits.txq_max_entries = sa->txq_max_entries;
158 hw_limits.txq_min_entries = sa->txq_min_entries;
160 rc = sa->priv.dp_tx->qsize_up_rings(nb_tx_desc, &hw_limits,
161 &txq_entries, &evq_entries,
162 &txq_max_fill_level);
164 goto fail_size_up_rings;
165 SFC_ASSERT(txq_entries >= sa->txq_min_entries);
166 SFC_ASSERT(txq_entries <= sa->txq_max_entries);
167 SFC_ASSERT(txq_entries >= nb_tx_desc);
168 SFC_ASSERT(txq_max_fill_level <= nb_tx_desc);
170 offloads = tx_conf->offloads;
171 /* Add device level Tx offloads if the queue is an ethdev Tx queue */
172 if (ethdev_qid != SFC_ETHDEV_QID_INVALID)
173 offloads |= sa->eth_dev->data->dev_conf.txmode.offloads;
175 rc = sfc_tx_qcheck_conf(sa, txq_max_fill_level, tx_conf, offloads);
179 SFC_ASSERT(sw_index < sfc_sa2shared(sa)->txq_count);
180 txq_info = &sfc_sa2shared(sa)->txq_info[sw_index];
182 txq_info->entries = txq_entries;
184 rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_TX, sw_index,
185 evq_entries, socket_id, &evq);
189 txq = &sa->txq_ctrl[sw_index];
190 txq->hw_index = sw_index;
192 txq_info->free_thresh =
193 (tx_conf->tx_free_thresh) ? tx_conf->tx_free_thresh :
194 SFC_TX_DEFAULT_FREE_THRESH;
195 txq_info->offloads = offloads;
197 rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_NIC_DMA_ADDR_TX_RING,
198 efx_txq_size(sa->nic, txq_info->entries),
199 socket_id, &txq->mem);
203 memset(&info, 0, sizeof(info));
204 info.max_fill_level = txq_max_fill_level;
205 info.free_thresh = txq_info->free_thresh;
206 info.offloads = offloads;
207 info.txq_entries = txq_info->entries;
208 info.dma_desc_size_max = encp->enc_tx_dma_desc_size_max;
209 info.txq_hw_ring = txq->mem.esm_base;
210 info.evq_entries = evq_entries;
211 info.evq_hw_ring = evq->mem.esm_base;
212 info.hw_index = txq->hw_index;
213 info.mem_bar = sa->mem_bar.esb_base;
214 info.vi_window_shift = encp->enc_vi_window_shift;
215 info.tso_tcp_header_offset_limit =
216 encp->enc_tx_tso_tcp_header_offset_limit;
217 info.tso_max_nb_header_descs =
218 RTE_MIN(encp->enc_tx_tso_max_header_ndescs,
219 (uint32_t)UINT16_MAX);
220 info.tso_max_header_len =
221 RTE_MIN(encp->enc_tx_tso_max_header_length,
222 (uint32_t)UINT16_MAX);
223 info.tso_max_nb_payload_descs =
224 RTE_MIN(encp->enc_tx_tso_max_payload_ndescs,
225 (uint32_t)UINT16_MAX);
226 info.tso_max_payload_len = encp->enc_tx_tso_max_payload_length;
227 info.tso_max_nb_outgoing_frames = encp->enc_tx_tso_max_nframes;
229 info.nic_dma_info = &sas->nic_dma_info;
231 rc = sa->priv.dp_tx->qcreate(sa->eth_dev->data->port_id, sw_index,
232 &RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr,
233 socket_id, &info, &txq_info->dp);
235 goto fail_dp_tx_qinit;
237 evq->dp_txq = txq_info->dp;
239 txq_info->state = SFC_TXQ_INITIALIZED;
241 txq_info->deferred_start = (tx_conf->tx_deferred_start != 0);
246 sfc_dma_free(sa, &txq->mem);
252 txq_info->entries = 0;
256 sfc_log_init(sa, "failed (TxQ = %d (internal %u), rc = %d)", ethdev_qid,
262 sfc_tx_qfini(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
264 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
265 sfc_ethdev_qid_t ethdev_qid;
266 struct sfc_txq_info *txq_info;
269 ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
271 sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
273 SFC_ASSERT(sw_index < sfc_sa2shared(sa)->txq_count);
274 if (ethdev_qid != SFC_ETHDEV_QID_INVALID)
275 sa->eth_dev->data->tx_queues[ethdev_qid] = NULL;
277 txq_info = &sfc_sa2shared(sa)->txq_info[sw_index];
279 SFC_ASSERT(txq_info->state == SFC_TXQ_INITIALIZED);
281 sa->priv.dp_tx->qdestroy(txq_info->dp);
284 txq_info->state &= ~SFC_TXQ_INITIALIZED;
285 txq_info->entries = 0;
287 txq = &sa->txq_ctrl[sw_index];
289 sfc_dma_free(sa, &txq->mem);
291 sfc_ev_qfini(txq->evq);
296 sfc_tx_qinit_info(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
298 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
299 sfc_ethdev_qid_t ethdev_qid;
301 ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
303 sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
309 sfc_tx_check_mode(struct sfc_adapter *sa, const struct rte_eth_txmode *txmode)
313 switch (txmode->mq_mode) {
314 case RTE_ETH_MQ_TX_NONE:
317 sfc_err(sa, "Tx multi-queue mode %u not supported",
323 * These features are claimed to be i40e-specific,
324 * but it does make sense to double-check their absence
326 if (txmode->hw_vlan_reject_tagged) {
327 sfc_err(sa, "Rejecting tagged packets not supported");
331 if (txmode->hw_vlan_reject_untagged) {
332 sfc_err(sa, "Rejecting untagged packets not supported");
336 if (txmode->hw_vlan_insert_pvid) {
337 sfc_err(sa, "Port-based VLAN insertion not supported");
345 * Destroy excess queues that are no longer needed after reconfiguration
349 sfc_tx_fini_queues(struct sfc_adapter *sa, unsigned int nb_tx_queues)
351 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
352 sfc_sw_index_t sw_index;
353 sfc_ethdev_qid_t ethdev_qid;
355 SFC_ASSERT(nb_tx_queues <= sas->ethdev_txq_count);
358 * Finalize only ethdev queues since other ones are finalized only
359 * on device close and they may require additional deinitialization.
361 ethdev_qid = sas->ethdev_txq_count;
362 while (--ethdev_qid >= (int)nb_tx_queues) {
363 struct sfc_txq_info *txq_info;
365 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
366 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
367 if (txq_info->state & SFC_TXQ_INITIALIZED)
368 sfc_tx_qfini(sa, sw_index);
371 sas->ethdev_txq_count = nb_tx_queues;
375 sfc_tx_configure(struct sfc_adapter *sa)
377 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
378 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
379 const struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
380 const unsigned int nb_tx_queues = sa->eth_dev->data->nb_tx_queues;
381 const unsigned int nb_rsvd_tx_queues = sfc_nb_txq_reserved(sas);
382 const unsigned int nb_txq_total = nb_tx_queues + nb_rsvd_tx_queues;
386 sfc_log_init(sa, "nb_tx_queues=%u (old %u)",
387 nb_tx_queues, sas->ethdev_txq_count);
390 * The datapath implementation assumes absence of boundary
391 * limits on Tx DMA descriptors. Addition of these checks on
392 * datapath would simply make the datapath slower.
394 if (encp->enc_tx_dma_desc_boundary != 0) {
396 goto fail_tx_dma_desc_boundary;
399 rc = sfc_tx_check_mode(sa, &dev_conf->txmode);
401 goto fail_check_mode;
403 if (nb_txq_total == sas->txq_count)
406 if (sas->txq_info == NULL) {
408 sas->txq_info = rte_calloc_socket("sfc-txqs", nb_txq_total,
409 sizeof(sas->txq_info[0]), 0,
411 if (sas->txq_info == NULL)
412 goto fail_txqs_alloc;
415 * Allocate primary process only TxQ control from heap
416 * since it should not be shared.
419 sa->txq_ctrl = calloc(nb_txq_total, sizeof(sa->txq_ctrl[0]));
420 if (sa->txq_ctrl == NULL)
421 goto fail_txqs_ctrl_alloc;
423 struct sfc_txq_info *new_txq_info;
424 struct sfc_txq *new_txq_ctrl;
428 if (nb_tx_queues < sas->ethdev_txq_count)
429 sfc_tx_fini_queues(sa, nb_tx_queues);
432 rte_realloc(sas->txq_info,
433 nb_txq_total * sizeof(sas->txq_info[0]), 0);
434 if (new_txq_info == NULL && nb_txq_total > 0)
435 goto fail_txqs_realloc;
437 new_txq_ctrl = realloc(sa->txq_ctrl,
438 nb_txq_total * sizeof(sa->txq_ctrl[0]));
439 if (new_txq_ctrl == NULL && nb_txq_total > 0)
440 goto fail_txqs_ctrl_realloc;
442 sas->txq_info = new_txq_info;
443 sa->txq_ctrl = new_txq_ctrl;
444 if (nb_txq_total > sas->txq_count) {
445 memset(&sas->txq_info[sas->txq_count], 0,
446 (nb_txq_total - sas->txq_count) *
447 sizeof(sas->txq_info[0]));
448 memset(&sa->txq_ctrl[sas->txq_count], 0,
449 (nb_txq_total - sas->txq_count) *
450 sizeof(sa->txq_ctrl[0]));
454 while (sas->ethdev_txq_count < nb_tx_queues) {
455 sfc_sw_index_t sw_index;
457 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas,
458 sas->ethdev_txq_count);
459 rc = sfc_tx_qinit_info(sa, sw_index);
461 goto fail_tx_qinit_info;
463 sas->ethdev_txq_count++;
466 sas->txq_count = sas->ethdev_txq_count + nb_rsvd_tx_queues;
469 rc = sfc_repr_proxy_txq_init(sa);
471 goto fail_repr_proxy_txq_init;
477 fail_repr_proxy_txq_init:
479 fail_txqs_ctrl_realloc:
481 fail_txqs_ctrl_alloc:
486 fail_tx_dma_desc_boundary:
487 sfc_log_init(sa, "failed (rc = %d)", rc);
492 sfc_tx_close(struct sfc_adapter *sa)
494 sfc_tx_fini_queues(sa, 0);
495 sfc_repr_proxy_txq_fini(sa);
500 rte_free(sfc_sa2shared(sa)->txq_info);
501 sfc_sa2shared(sa)->txq_info = NULL;
505 sfc_tx_qstart(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
507 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
508 sfc_ethdev_qid_t ethdev_qid;
509 uint64_t offloads_supported = sfc_tx_get_dev_offload_caps(sa) |
510 sfc_tx_get_queue_offload_caps(sa);
511 struct sfc_txq_info *txq_info;
515 unsigned int desc_index;
518 ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
520 sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
522 SFC_ASSERT(sw_index < sas->txq_count);
523 txq_info = &sas->txq_info[sw_index];
525 SFC_ASSERT(txq_info->state == SFC_TXQ_INITIALIZED);
527 txq = &sa->txq_ctrl[sw_index];
530 rc = sfc_ev_qstart(evq, sfc_evq_sw_index_by_txq_sw_index(sa, sw_index));
534 if (txq_info->offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)
535 flags |= EFX_TXQ_CKSUM_IPV4;
537 if (txq_info->offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)
538 flags |= EFX_TXQ_CKSUM_INNER_IPV4;
540 if ((txq_info->offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ||
541 (txq_info->offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
542 flags |= EFX_TXQ_CKSUM_TCPUDP;
544 if (offloads_supported & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)
545 flags |= EFX_TXQ_CKSUM_INNER_TCPUDP;
548 if (txq_info->offloads & (RTE_ETH_TX_OFFLOAD_TCP_TSO |
549 RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
550 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
551 flags |= EFX_TXQ_FATSOV2;
553 rc = efx_tx_qcreate(sa->nic, txq->hw_index, 0, &txq->mem,
554 txq_info->entries, 0 /* not used on EF10 */,
556 &txq->common, &desc_index);
558 if (sa->tso && (rc == ENOSPC))
559 sfc_err(sa, "ran out of TSO contexts");
561 goto fail_tx_qcreate;
564 efx_tx_qenable(txq->common);
566 txq_info->state |= SFC_TXQ_STARTED;
568 rc = sa->priv.dp_tx->qstart(txq_info->dp, evq->read_ptr, desc_index);
572 if (ethdev_qid != SFC_ETHDEV_QID_INVALID) {
573 struct rte_eth_dev_data *dev_data;
576 * It sems to be used by DPDK for debug purposes only
579 dev_data = sa->eth_dev->data;
580 dev_data->tx_queue_state[ethdev_qid] =
581 RTE_ETH_QUEUE_STATE_STARTED;
587 txq_info->state = SFC_TXQ_INITIALIZED;
588 efx_tx_qdestroy(txq->common);
598 sfc_tx_qstop(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
600 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
601 sfc_ethdev_qid_t ethdev_qid;
602 struct sfc_txq_info *txq_info;
604 unsigned int retry_count;
605 unsigned int wait_count;
608 ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
610 sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
612 SFC_ASSERT(sw_index < sas->txq_count);
613 txq_info = &sas->txq_info[sw_index];
615 if (txq_info->state == SFC_TXQ_INITIALIZED)
618 SFC_ASSERT(txq_info->state & SFC_TXQ_STARTED);
620 txq = &sa->txq_ctrl[sw_index];
621 sa->priv.dp_tx->qstop(txq_info->dp, &txq->evq->read_ptr);
624 * Retry TX queue flushing in case of flush failed or
625 * timeout; in the worst case it can delay for 6 seconds
627 for (retry_count = 0;
628 ((txq_info->state & SFC_TXQ_FLUSHED) == 0) &&
629 (retry_count < SFC_TX_QFLUSH_ATTEMPTS);
631 rc = efx_tx_qflush(txq->common);
633 txq_info->state |= (rc == EALREADY) ?
634 SFC_TXQ_FLUSHED : SFC_TXQ_FLUSH_FAILED;
639 * Wait for TX queue flush done or flush failed event at least
640 * SFC_TX_QFLUSH_POLL_WAIT_MS milliseconds and not more
641 * than 2 seconds (SFC_TX_QFLUSH_POLL_WAIT_MS multiplied
642 * by SFC_TX_QFLUSH_POLL_ATTEMPTS)
646 rte_delay_ms(SFC_TX_QFLUSH_POLL_WAIT_MS);
647 sfc_ev_qpoll(txq->evq);
648 } while ((txq_info->state & SFC_TXQ_FLUSHING) &&
649 wait_count++ < SFC_TX_QFLUSH_POLL_ATTEMPTS);
651 if (txq_info->state & SFC_TXQ_FLUSHING)
652 sfc_err(sa, "TxQ %d (internal %u) flush timed out",
653 ethdev_qid, sw_index);
655 if (txq_info->state & SFC_TXQ_FLUSHED)
656 sfc_notice(sa, "TxQ %d (internal %u) flushed",
657 ethdev_qid, sw_index);
660 sa->priv.dp_tx->qreap(txq_info->dp);
662 txq_info->state = SFC_TXQ_INITIALIZED;
664 efx_tx_qdestroy(txq->common);
666 sfc_ev_qstop(txq->evq);
668 if (ethdev_qid != SFC_ETHDEV_QID_INVALID) {
669 struct rte_eth_dev_data *dev_data;
672 * It seems to be used by DPDK for debug purposes only
675 dev_data = sa->eth_dev->data;
676 dev_data->tx_queue_state[ethdev_qid] =
677 RTE_ETH_QUEUE_STATE_STOPPED;
682 sfc_tx_start(struct sfc_adapter *sa)
684 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
685 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
686 sfc_sw_index_t sw_index;
689 sfc_log_init(sa, "txq_count = %u (internal %u)",
690 sas->ethdev_txq_count, sas->txq_count);
693 if (!encp->enc_fw_assisted_tso_v2_enabled &&
694 !encp->enc_tso_v3_enabled) {
695 sfc_warn(sa, "TSO support was unable to be restored");
697 sa->tso_encap = B_FALSE;
701 if (sa->tso_encap && !encp->enc_fw_assisted_tso_v2_encap_enabled &&
702 !encp->enc_tso_v3_enabled) {
703 sfc_warn(sa, "Encapsulated TSO support was unable to be restored");
704 sa->tso_encap = B_FALSE;
707 rc = efx_tx_init(sa->nic);
709 goto fail_efx_tx_init;
711 for (sw_index = 0; sw_index < sas->txq_count; ++sw_index) {
712 if (sas->txq_info[sw_index].state == SFC_TXQ_INITIALIZED &&
713 (!(sas->txq_info[sw_index].deferred_start) ||
714 sas->txq_info[sw_index].deferred_started)) {
715 rc = sfc_tx_qstart(sa, sw_index);
724 while (sw_index-- > 0)
725 sfc_tx_qstop(sa, sw_index);
727 efx_tx_fini(sa->nic);
730 sfc_log_init(sa, "failed (rc = %d)", rc);
735 sfc_tx_stop(struct sfc_adapter *sa)
737 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
738 sfc_sw_index_t sw_index;
740 sfc_log_init(sa, "txq_count = %u (internal %u)",
741 sas->ethdev_txq_count, sas->txq_count);
743 sw_index = sas->txq_count;
744 while (sw_index-- > 0) {
745 if (sas->txq_info[sw_index].state & SFC_TXQ_STARTED)
746 sfc_tx_qstop(sa, sw_index);
749 efx_tx_fini(sa->nic);
753 sfc_efx_tx_reap(struct sfc_efx_txq *txq)
755 unsigned int completed;
757 sfc_ev_qpoll(txq->evq);
759 for (completed = txq->completed;
760 completed != txq->pending; completed++) {
761 struct sfc_efx_tx_sw_desc *txd;
763 txd = &txq->sw_ring[completed & txq->ptr_mask];
765 if (txd->mbuf != NULL) {
766 rte_pktmbuf_free(txd->mbuf);
771 txq->completed = completed;
775 * The function is used to insert or update VLAN tag;
776 * the firmware has state of the firmware tag to insert per TxQ
777 * (controlled by option descriptors), hence, if the tag of the
778 * packet to be sent is different from one remembered by the firmware,
779 * the function will update it
782 sfc_efx_tx_maybe_insert_tag(struct sfc_efx_txq *txq, struct rte_mbuf *m,
785 uint16_t this_tag = ((m->ol_flags & RTE_MBUF_F_TX_VLAN) ?
788 if (this_tag == txq->hw_vlan_tci)
792 * The expression inside SFC_ASSERT() is not desired to be checked in
793 * a non-debug build because it might be too expensive on the data path
795 SFC_ASSERT(efx_nic_cfg_get(txq->evq->sa->nic)->enc_hw_tx_insert_vlan_enabled);
797 efx_tx_qdesc_vlantci_create(txq->common, rte_cpu_to_be_16(this_tag),
800 txq->hw_vlan_tci = this_tag;
806 sfc_efx_prepare_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
809 struct sfc_dp_txq *dp_txq = tx_queue;
810 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
811 const efx_nic_cfg_t *encp = efx_nic_cfg_get(txq->evq->sa->nic);
814 for (i = 0; i < nb_pkts; i++) {
818 * EFX Tx datapath may require extra VLAN descriptor if VLAN
819 * insertion offload is requested regardless the offload
820 * requested/supported.
822 ret = sfc_dp_tx_prepare_pkt(tx_pkts[i], 0, SFC_TSOH_STD_LEN,
823 encp->enc_tx_tso_tcp_header_offset_limit,
824 txq->max_fill_level, EFX_TX_FATSOV2_OPT_NDESCS,
826 if (unlikely(ret != 0)) {
836 sfc_efx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
838 struct sfc_dp_txq *dp_txq = (struct sfc_dp_txq *)tx_queue;
839 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
840 unsigned int added = txq->added;
841 unsigned int pushed = added;
842 unsigned int pkts_sent = 0;
843 efx_desc_t *pend = &txq->pend_desc[0];
844 const unsigned int hard_max_fill = txq->max_fill_level;
845 const unsigned int soft_max_fill = hard_max_fill - txq->free_thresh;
846 unsigned int fill_level = added - txq->completed;
849 struct rte_mbuf **pktp;
851 if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) == 0))
855 * If insufficient space for a single packet is present,
856 * we should reap; otherwise, we shouldn't do that all the time
857 * to avoid latency increase
859 reap_done = (fill_level > soft_max_fill);
862 sfc_efx_tx_reap(txq);
864 * Recalculate fill level since 'txq->completed'
865 * might have changed on reap
867 fill_level = added - txq->completed;
870 for (pkts_sent = 0, pktp = &tx_pkts[0];
871 (pkts_sent < nb_pkts) && (fill_level <= soft_max_fill);
872 pkts_sent++, pktp++) {
873 uint16_t hw_vlan_tci_prev = txq->hw_vlan_tci;
874 struct rte_mbuf *m_seg = *pktp;
875 size_t pkt_len = m_seg->pkt_len;
876 unsigned int pkt_descs = 0;
880 * Here VLAN TCI is expected to be zero in case if no
881 * RTE_ETH_TX_OFFLOAD_VLAN_INSERT capability is advertised;
882 * if the calling app ignores the absence of
883 * RTE_ETH_TX_OFFLOAD_VLAN_INSERT and pushes VLAN TCI, then
884 * TX_ERROR will occur
886 pkt_descs += sfc_efx_tx_maybe_insert_tag(txq, m_seg, &pend);
888 if (m_seg->ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
890 * We expect correct 'pkt->l[2, 3, 4]_len' values
891 * to be set correctly by the caller
893 if (sfc_efx_tso_do(txq, added, &m_seg, &in_off, &pend,
894 &pkt_descs, &pkt_len) != 0) {
895 /* We may have reached this place if packet
896 * header linearization is needed but the
897 * header length is greater than
900 * We will deceive RTE saying that we have sent
901 * the packet, but we will actually drop it.
902 * Hence, we should revert 'pend' to the
903 * previous state (in case we have added
904 * VLAN descriptor) and start processing
905 * another one packet. But the original
906 * mbuf shouldn't be orphaned
909 txq->hw_vlan_tci = hw_vlan_tci_prev;
911 rte_pktmbuf_free(*pktp);
917 * We've only added 2 FATSOv2 option descriptors
918 * and 1 descriptor for the linearized packet header.
919 * The outstanding work will be done in the same manner
920 * as for the usual non-TSO path
924 for (; m_seg != NULL; m_seg = m_seg->next) {
925 efsys_dma_addr_t next_frag;
928 seg_len = m_seg->data_len;
929 next_frag = rte_mbuf_data_iova(m_seg);
932 * If we've started TSO transaction few steps earlier,
933 * we'll skip packet header using an offset in the
934 * current segment (which has been set to the
935 * first one containing payload)
942 efsys_dma_addr_t frag_addr = next_frag;
946 * It is assumed here that there is no
947 * limitation on address boundary
948 * crossing by DMA descriptor.
950 frag_len = MIN(seg_len, txq->dma_desc_size_max);
951 next_frag += frag_len;
955 efx_tx_qdesc_dma_create(txq->common,
961 } while (seg_len != 0);
966 fill_level += pkt_descs;
967 if (unlikely(fill_level > hard_max_fill)) {
969 * Our estimation for maximum number of descriptors
970 * required to send a packet seems to be wrong.
971 * Try to reap (if we haven't yet).
974 sfc_efx_tx_reap(txq);
976 fill_level = added - txq->completed;
977 if (fill_level > hard_max_fill) {
979 txq->hw_vlan_tci = hw_vlan_tci_prev;
984 txq->hw_vlan_tci = hw_vlan_tci_prev;
989 /* Assign mbuf to the last used desc */
990 txq->sw_ring[(added - 1) & txq->ptr_mask].mbuf = *pktp;
993 if (likely(pkts_sent > 0)) {
994 rc = efx_tx_qdesc_post(txq->common, txq->pend_desc,
995 pend - &txq->pend_desc[0],
996 txq->completed, &txq->added);
999 if (likely(pushed != txq->added)) {
1000 efx_tx_qpush(txq->common, txq->added, pushed);
1001 txq->dp.dpq.dbells++;
1005 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
1007 sfc_efx_tx_reap(txq);
1014 const struct sfc_dp_tx *
1015 sfc_dp_tx_by_dp_txq(const struct sfc_dp_txq *dp_txq)
1017 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
1018 struct rte_eth_dev *eth_dev;
1019 struct sfc_adapter_priv *sap;
1021 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
1022 eth_dev = &rte_eth_devices[dpq->port_id];
1024 sap = sfc_adapter_priv_by_eth_dev(eth_dev);
1029 struct sfc_txq_info *
1030 sfc_txq_info_by_dp_txq(const struct sfc_dp_txq *dp_txq)
1032 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
1033 struct rte_eth_dev *eth_dev;
1034 struct sfc_adapter_shared *sas;
1036 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
1037 eth_dev = &rte_eth_devices[dpq->port_id];
1039 sas = sfc_adapter_shared_by_eth_dev(eth_dev);
1041 SFC_ASSERT(dpq->queue_id < sas->txq_count);
1042 return &sas->txq_info[dpq->queue_id];
1046 sfc_txq_by_dp_txq(const struct sfc_dp_txq *dp_txq)
1048 const struct sfc_dp_queue *dpq = &dp_txq->dpq;
1049 struct rte_eth_dev *eth_dev;
1050 struct sfc_adapter *sa;
1052 SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
1053 eth_dev = &rte_eth_devices[dpq->port_id];
1055 sa = sfc_adapter_by_eth_dev(eth_dev);
1057 SFC_ASSERT(dpq->queue_id < sfc_sa2shared(sa)->txq_count);
1058 return &sa->txq_ctrl[dpq->queue_id];
1061 static sfc_dp_tx_qsize_up_rings_t sfc_efx_tx_qsize_up_rings;
1063 sfc_efx_tx_qsize_up_rings(uint16_t nb_tx_desc,
1064 __rte_unused struct sfc_dp_tx_hw_limits *limits,
1065 unsigned int *txq_entries,
1066 unsigned int *evq_entries,
1067 unsigned int *txq_max_fill_level)
1069 *txq_entries = nb_tx_desc;
1070 *evq_entries = nb_tx_desc;
1071 *txq_max_fill_level = EFX_TXQ_LIMIT(*txq_entries);
1075 static sfc_dp_tx_qcreate_t sfc_efx_tx_qcreate;
1077 sfc_efx_tx_qcreate(uint16_t port_id, uint16_t queue_id,
1078 const struct rte_pci_addr *pci_addr,
1080 const struct sfc_dp_tx_qcreate_info *info,
1081 struct sfc_dp_txq **dp_txqp)
1083 struct sfc_efx_txq *txq;
1084 struct sfc_txq *ctrl_txq;
1088 if (info->nic_dma_info->nb_regions > 0)
1092 txq = rte_zmalloc_socket("sfc-efx-txq", sizeof(*txq),
1093 RTE_CACHE_LINE_SIZE, socket_id);
1095 goto fail_txq_alloc;
1097 sfc_dp_queue_init(&txq->dp.dpq, port_id, queue_id, pci_addr);
1100 txq->pend_desc = rte_calloc_socket("sfc-efx-txq-pend-desc",
1101 EFX_TXQ_LIMIT(info->txq_entries),
1102 sizeof(*txq->pend_desc), 0,
1104 if (txq->pend_desc == NULL)
1105 goto fail_pend_desc_alloc;
1108 txq->sw_ring = rte_calloc_socket("sfc-efx-txq-sw_ring",
1110 sizeof(*txq->sw_ring),
1111 RTE_CACHE_LINE_SIZE, socket_id);
1112 if (txq->sw_ring == NULL)
1113 goto fail_sw_ring_alloc;
1115 ctrl_txq = sfc_txq_by_dp_txq(&txq->dp);
1116 if (ctrl_txq->evq->sa->tso) {
1117 rc = sfc_efx_tso_alloc_tsoh_objs(txq->sw_ring,
1118 info->txq_entries, socket_id);
1120 goto fail_alloc_tsoh_objs;
1123 txq->evq = ctrl_txq->evq;
1124 txq->ptr_mask = info->txq_entries - 1;
1125 txq->max_fill_level = info->max_fill_level;
1126 txq->free_thresh = info->free_thresh;
1127 txq->dma_desc_size_max = info->dma_desc_size_max;
1129 *dp_txqp = &txq->dp;
1132 fail_alloc_tsoh_objs:
1133 rte_free(txq->sw_ring);
1136 rte_free(txq->pend_desc);
1138 fail_pend_desc_alloc:
1146 static sfc_dp_tx_qdestroy_t sfc_efx_tx_qdestroy;
1148 sfc_efx_tx_qdestroy(struct sfc_dp_txq *dp_txq)
1150 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1152 sfc_efx_tso_free_tsoh_objs(txq->sw_ring, txq->ptr_mask + 1);
1153 rte_free(txq->sw_ring);
1154 rte_free(txq->pend_desc);
1158 static sfc_dp_tx_qstart_t sfc_efx_tx_qstart;
1160 sfc_efx_tx_qstart(struct sfc_dp_txq *dp_txq,
1161 __rte_unused unsigned int evq_read_ptr,
1162 unsigned int txq_desc_index)
1164 /* libefx-based datapath is specific to libefx-based PMD */
1165 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1166 struct sfc_txq *ctrl_txq = sfc_txq_by_dp_txq(dp_txq);
1168 txq->common = ctrl_txq->common;
1170 txq->pending = txq->completed = txq->added = txq_desc_index;
1171 txq->hw_vlan_tci = 0;
1173 txq->flags |= (SFC_EFX_TXQ_FLAG_STARTED | SFC_EFX_TXQ_FLAG_RUNNING);
1178 static sfc_dp_tx_qstop_t sfc_efx_tx_qstop;
1180 sfc_efx_tx_qstop(struct sfc_dp_txq *dp_txq,
1181 __rte_unused unsigned int *evq_read_ptr)
1183 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1185 txq->flags &= ~SFC_EFX_TXQ_FLAG_RUNNING;
1188 static sfc_dp_tx_qreap_t sfc_efx_tx_qreap;
1190 sfc_efx_tx_qreap(struct sfc_dp_txq *dp_txq)
1192 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1195 sfc_efx_tx_reap(txq);
1197 for (txds = 0; txds <= txq->ptr_mask; txds++) {
1198 if (txq->sw_ring[txds].mbuf != NULL) {
1199 rte_pktmbuf_free(txq->sw_ring[txds].mbuf);
1200 txq->sw_ring[txds].mbuf = NULL;
1204 txq->flags &= ~SFC_EFX_TXQ_FLAG_STARTED;
1207 static sfc_dp_tx_qdesc_status_t sfc_efx_tx_qdesc_status;
1209 sfc_efx_tx_qdesc_status(struct sfc_dp_txq *dp_txq, uint16_t offset)
1211 struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1213 if (unlikely(offset > txq->ptr_mask))
1216 if (unlikely(offset >= txq->max_fill_level))
1217 return RTE_ETH_TX_DESC_UNAVAIL;
1220 * Poll EvQ to derive up-to-date 'txq->pending' figure;
1221 * it is required for the queue to be running, but the
1222 * check is omitted because API design assumes that it
1223 * is the duty of the caller to satisfy all conditions
1225 SFC_ASSERT((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) ==
1226 SFC_EFX_TXQ_FLAG_RUNNING);
1227 sfc_ev_qpoll(txq->evq);
1230 * Ring tail is 'txq->pending', and although descriptors
1231 * between 'txq->completed' and 'txq->pending' are still
1232 * in use by the driver, they should be reported as DONE
1234 if (unlikely(offset < (txq->added - txq->pending)))
1235 return RTE_ETH_TX_DESC_FULL;
1238 * There is no separate return value for unused descriptors;
1239 * the latter will be reported as DONE because genuine DONE
1240 * descriptors will be freed anyway in SW on the next burst
1242 return RTE_ETH_TX_DESC_DONE;
1245 struct sfc_dp_tx sfc_efx_tx = {
1247 .name = SFC_KVARG_DATAPATH_EFX,
1249 .hw_fw_caps = SFC_DP_HW_FW_CAP_TX_EFX,
1252 .dev_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1253 RTE_ETH_TX_OFFLOAD_MULTI_SEGS,
1254 .queue_offload_capa = RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1255 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1256 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1257 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
1258 RTE_ETH_TX_OFFLOAD_TCP_TSO,
1259 .qsize_up_rings = sfc_efx_tx_qsize_up_rings,
1260 .qcreate = sfc_efx_tx_qcreate,
1261 .qdestroy = sfc_efx_tx_qdestroy,
1262 .qstart = sfc_efx_tx_qstart,
1263 .qstop = sfc_efx_tx_qstop,
1264 .qreap = sfc_efx_tx_qreap,
1265 .qdesc_status = sfc_efx_tx_qdesc_status,
1266 .pkt_prepare = sfc_efx_prepare_pkts,
1267 .pkt_burst = sfc_efx_xmit_pkts,