2 * Copyright (c) 2016 Solarflare Communications Inc.
5 * This software was jointly developed between OKTET Labs (under contract
6 * for Solarflare) and Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "sfc_debug.h"
37 * Maximum number of TX queue flush attempts in case of
38 * failure or flush timeout
40 #define SFC_TX_QFLUSH_ATTEMPTS (3)
43 * Time to wait between event queue polling attempts when waiting for TX
44 * queue flush done or flush failed events
46 #define SFC_TX_QFLUSH_POLL_WAIT_MS (1)
49 * Maximum number of event queue polling attempts when waiting for TX queue
50 * flush done or flush failed events; it defines TX queue flush attempt timeout
51 * together with SFC_TX_QFLUSH_POLL_WAIT_MS
53 #define SFC_TX_QFLUSH_POLL_ATTEMPTS (2000)
56 sfc_tx_qcheck_conf(struct sfc_adapter *sa,
57 const struct rte_eth_txconf *tx_conf)
59 unsigned int flags = tx_conf->txq_flags;
62 if (tx_conf->tx_rs_thresh != 0) {
63 sfc_err(sa, "RS bit in transmit descriptor is not supported");
67 if (tx_conf->tx_free_thresh != 0) {
69 "setting explicit TX free threshold is not supported");
73 if (tx_conf->tx_deferred_start != 0) {
74 sfc_err(sa, "TX queue deferred start is not supported (yet)");
78 if (tx_conf->tx_thresh.pthresh != 0 ||
79 tx_conf->tx_thresh.hthresh != 0 ||
80 tx_conf->tx_thresh.wthresh != 0) {
82 "prefetch/host/writeback thresholds are not supported");
86 if ((flags & ETH_TXQ_FLAGS_NOVLANOFFL) == 0) {
87 sfc_err(sa, "VLAN offload is not supported");
91 if ((flags & ETH_TXQ_FLAGS_NOXSUMSCTP) == 0) {
92 sfc_err(sa, "SCTP offload is not supported");
96 /* We either perform both TCP and UDP offload, or no offload at all */
97 if (((flags & ETH_TXQ_FLAGS_NOXSUMTCP) == 0) !=
98 ((flags & ETH_TXQ_FLAGS_NOXSUMUDP) == 0)) {
99 sfc_err(sa, "TCP and UDP offloads can't be set independently");
107 sfc_tx_qflush_done(struct sfc_txq *txq)
109 txq->state |= SFC_TXQ_FLUSHED;
110 txq->state &= ~SFC_TXQ_FLUSHING;
114 sfc_tx_reap(struct sfc_txq *txq)
116 unsigned int completed;
119 sfc_ev_qpoll(txq->evq);
121 for (completed = txq->completed;
122 completed != txq->pending; completed++) {
123 struct sfc_tx_sw_desc *txd;
125 txd = &txq->sw_ring[completed & txq->ptr_mask];
127 if (txd->mbuf != NULL) {
128 rte_pktmbuf_free(txd->mbuf);
133 txq->completed = completed;
137 sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
138 uint16_t nb_tx_desc, unsigned int socket_id,
139 const struct rte_eth_txconf *tx_conf)
141 struct sfc_txq_info *txq_info;
144 unsigned int evq_index = sfc_evq_index_by_txq_sw_index(sa, sw_index);
147 sfc_log_init(sa, "TxQ = %u", sw_index);
149 rc = sfc_tx_qcheck_conf(sa, tx_conf);
153 SFC_ASSERT(sw_index < sa->txq_count);
154 txq_info = &sa->txq_info[sw_index];
156 SFC_ASSERT(nb_tx_desc <= sa->txq_max_entries);
157 txq_info->entries = nb_tx_desc;
159 rc = sfc_ev_qinit(sa, evq_index, txq_info->entries, socket_id);
163 evq = sa->evq_info[evq_index].evq;
166 txq = rte_zmalloc_socket("sfc-txq", sizeof(*txq), 0, socket_id);
170 rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_TXQ_SIZE(txq_info->entries),
171 socket_id, &txq->mem);
176 txq->pend_desc = rte_calloc_socket("sfc-txq-pend-desc",
177 EFX_TXQ_LIMIT(txq_info->entries),
178 sizeof(efx_desc_t), 0, socket_id);
179 if (txq->pend_desc == NULL)
180 goto fail_pend_desc_alloc;
183 txq->sw_ring = rte_calloc_socket("sfc-txq-desc", txq_info->entries,
184 sizeof(*txq->sw_ring), 0, socket_id);
185 if (txq->sw_ring == NULL)
186 goto fail_desc_alloc;
188 txq->state = SFC_TXQ_INITIALIZED;
189 txq->ptr_mask = txq_info->entries - 1;
190 txq->hw_index = sw_index;
191 txq->flags = tx_conf->txq_flags;
201 rte_free(txq->pend_desc);
203 fail_pend_desc_alloc:
204 sfc_dma_free(sa, &txq->mem);
210 sfc_ev_qfini(sa, evq_index);
213 txq_info->entries = 0;
216 sfc_log_init(sa, "failed (TxQ = %u, rc = %d)", sw_index, rc);
221 sfc_tx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
223 struct sfc_txq_info *txq_info;
226 sfc_log_init(sa, "TxQ = %u", sw_index);
228 SFC_ASSERT(sw_index < sa->txq_count);
229 txq_info = &sa->txq_info[sw_index];
232 SFC_ASSERT(txq != NULL);
233 SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
235 txq_info->txq = NULL;
236 txq_info->entries = 0;
238 rte_free(txq->sw_ring);
239 rte_free(txq->pend_desc);
240 sfc_dma_free(sa, &txq->mem);
245 sfc_tx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
247 sfc_log_init(sa, "TxQ = %u", sw_index);
253 sfc_tx_check_mode(struct sfc_adapter *sa, const struct rte_eth_txmode *txmode)
257 switch (txmode->mq_mode) {
261 sfc_err(sa, "Tx multi-queue mode %u not supported",
267 * These features are claimed to be i40e-specific,
268 * but it does make sense to double-check their absence
270 if (txmode->hw_vlan_reject_tagged) {
271 sfc_err(sa, "Rejecting tagged packets not supported");
275 if (txmode->hw_vlan_reject_untagged) {
276 sfc_err(sa, "Rejecting untagged packets not supported");
280 if (txmode->hw_vlan_insert_pvid) {
281 sfc_err(sa, "Port-based VLAN insertion not supported");
289 sfc_tx_init(struct sfc_adapter *sa)
291 const struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
292 unsigned int sw_index;
295 rc = sfc_tx_check_mode(sa, &dev_conf->txmode);
297 goto fail_check_mode;
299 sa->txq_count = sa->eth_dev->data->nb_tx_queues;
301 sa->txq_info = rte_calloc_socket("sfc-txqs", sa->txq_count,
302 sizeof(sa->txq_info[0]), 0,
304 if (sa->txq_info == NULL)
305 goto fail_txqs_alloc;
307 for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
308 rc = sfc_tx_qinit_info(sa, sw_index);
310 goto fail_tx_qinit_info;
316 rte_free(sa->txq_info);
323 sfc_log_init(sa, "failed (rc = %d)", rc);
328 sfc_tx_fini(struct sfc_adapter *sa)
332 sw_index = sa->txq_count;
333 while (--sw_index >= 0) {
334 if (sa->txq_info[sw_index].txq != NULL)
335 sfc_tx_qfini(sa, sw_index);
338 rte_free(sa->txq_info);
344 sfc_tx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
346 struct rte_eth_dev_data *dev_data;
347 struct sfc_txq_info *txq_info;
351 unsigned int desc_index;
354 sfc_log_init(sa, "TxQ = %u", sw_index);
356 SFC_ASSERT(sw_index < sa->txq_count);
357 txq_info = &sa->txq_info[sw_index];
361 SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
365 rc = sfc_ev_qstart(sa, evq->evq_index);
370 * It seems that DPDK has no controls regarding IPv4 offloads,
371 * hence, we always enable it here
373 if ((txq->flags & ETH_TXQ_FLAGS_NOXSUMTCP) ||
374 (txq->flags & ETH_TXQ_FLAGS_NOXSUMUDP))
375 flags = EFX_TXQ_CKSUM_IPV4;
377 flags = EFX_TXQ_CKSUM_IPV4 | EFX_TXQ_CKSUM_TCPUDP;
379 rc = efx_tx_qcreate(sa->nic, sw_index, 0, &txq->mem,
380 txq_info->entries, 0 /* not used on EF10 */,
382 &txq->common, &desc_index);
384 goto fail_tx_qcreate;
386 txq->added = txq->pending = txq->completed = desc_index;
388 efx_tx_qenable(txq->common);
390 txq->state |= (SFC_TXQ_STARTED | SFC_TXQ_RUNNING);
393 * It seems to be used by DPDK for debug purposes only ('rte_ether')
395 dev_data = sa->eth_dev->data;
396 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STARTED;
401 sfc_ev_qstop(sa, evq->evq_index);
408 sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index)
410 struct rte_eth_dev_data *dev_data;
411 struct sfc_txq_info *txq_info;
413 unsigned int retry_count;
414 unsigned int wait_count;
417 sfc_log_init(sa, "TxQ = %u", sw_index);
419 SFC_ASSERT(sw_index < sa->txq_count);
420 txq_info = &sa->txq_info[sw_index];
424 SFC_ASSERT(txq->state & SFC_TXQ_STARTED);
426 txq->state &= ~SFC_TXQ_RUNNING;
429 * Retry TX queue flushing in case of flush failed or
430 * timeout; in the worst case it can delay for 6 seconds
432 for (retry_count = 0;
433 ((txq->state & SFC_TXQ_FLUSHED) == 0) &&
434 (retry_count < SFC_TX_QFLUSH_ATTEMPTS);
436 if (efx_tx_qflush(txq->common) != 0) {
437 txq->state |= SFC_TXQ_FLUSHING;
442 * Wait for TX queue flush done or flush failed event at least
443 * SFC_TX_QFLUSH_POLL_WAIT_MS milliseconds and not more
444 * than 2 seconds (SFC_TX_QFLUSH_POLL_WAIT_MS multiplied
445 * by SFC_TX_QFLUSH_POLL_ATTEMPTS)
449 rte_delay_ms(SFC_TX_QFLUSH_POLL_WAIT_MS);
450 sfc_ev_qpoll(txq->evq);
451 } while ((txq->state & SFC_TXQ_FLUSHING) &&
452 wait_count++ < SFC_TX_QFLUSH_POLL_ATTEMPTS);
454 if (txq->state & SFC_TXQ_FLUSHING)
455 sfc_err(sa, "TxQ %u flush timed out", sw_index);
457 if (txq->state & SFC_TXQ_FLUSHED)
458 sfc_info(sa, "TxQ %u flushed", sw_index);
463 for (txds = 0; txds < txq_info->entries; txds++) {
464 if (txq->sw_ring[txds].mbuf != NULL) {
465 rte_pktmbuf_free(txq->sw_ring[txds].mbuf);
466 txq->sw_ring[txds].mbuf = NULL;
470 txq->state = SFC_TXQ_INITIALIZED;
472 efx_tx_qdestroy(txq->common);
474 sfc_ev_qstop(sa, txq->evq->evq_index);
477 * It seems to be used by DPDK for debug purposes only ('rte_ether')
479 dev_data = sa->eth_dev->data;
480 dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STOPPED;
484 sfc_tx_start(struct sfc_adapter *sa)
486 unsigned int sw_index;
489 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
491 rc = efx_tx_init(sa->nic);
493 goto fail_efx_tx_init;
495 for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
496 rc = sfc_tx_qstart(sa, sw_index);
504 while (sw_index-- > 0)
505 sfc_tx_qstop(sa, sw_index);
507 efx_tx_fini(sa->nic);
510 sfc_log_init(sa, "failed (rc = %d)", rc);
515 sfc_tx_stop(struct sfc_adapter *sa)
517 unsigned int sw_index;
519 sfc_log_init(sa, "txq_count = %u", sa->txq_count);
521 sw_index = sa->txq_count;
522 while (sw_index-- > 0) {
523 if (sa->txq_info[sw_index].txq != NULL)
524 sfc_tx_qstop(sa, sw_index);
527 efx_tx_fini(sa->nic);