xref: /dpdk/drivers/net/sfc/sfc_tx.c (revision df2b82ca)
1 /*-
2  * Copyright (c) 2016 Solarflare Communications Inc.
3  * All rights reserved.
4  *
5  * This software was jointly developed between OKTET Labs (under contract
6  * for Solarflare) and Solarflare Communications, Inc.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
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.
16  *
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.
28  */
29 
30 #include "sfc.h"
31 #include "sfc_debug.h"
32 #include "sfc_log.h"
33 #include "sfc_ev.h"
34 #include "sfc_tx.h"
35 #include "sfc_tweak.h"
36 
37 /*
38  * Maximum number of TX queue flush attempts in case of
39  * failure or flush timeout
40  */
41 #define SFC_TX_QFLUSH_ATTEMPTS		(3)
42 
43 /*
44  * Time to wait between event queue polling attempts when waiting for TX
45  * queue flush done or flush failed events
46  */
47 #define SFC_TX_QFLUSH_POLL_WAIT_MS	(1)
48 
49 /*
50  * Maximum number of event queue polling attempts when waiting for TX queue
51  * flush done or flush failed events; it defines TX queue flush attempt timeout
52  * together with SFC_TX_QFLUSH_POLL_WAIT_MS
53  */
54 #define SFC_TX_QFLUSH_POLL_ATTEMPTS	(2000)
55 
56 static int
57 sfc_tx_qcheck_conf(struct sfc_adapter *sa, uint16_t nb_tx_desc,
58 		   const struct rte_eth_txconf *tx_conf)
59 {
60 	unsigned int flags = tx_conf->txq_flags;
61 	const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
62 	int rc = 0;
63 
64 	if (tx_conf->tx_rs_thresh != 0) {
65 		sfc_err(sa, "RS bit in transmit descriptor is not supported");
66 		rc = EINVAL;
67 	}
68 
69 	if (tx_conf->tx_free_thresh > EFX_TXQ_LIMIT(nb_tx_desc)) {
70 		sfc_err(sa,
71 			"TxQ free threshold too large: %u vs maximum %u",
72 			tx_conf->tx_free_thresh, EFX_TXQ_LIMIT(nb_tx_desc));
73 		rc = EINVAL;
74 	}
75 
76 	if (tx_conf->tx_thresh.pthresh != 0 ||
77 	    tx_conf->tx_thresh.hthresh != 0 ||
78 	    tx_conf->tx_thresh.wthresh != 0) {
79 		sfc_err(sa,
80 			"prefetch/host/writeback thresholds are not supported");
81 		rc = EINVAL;
82 	}
83 
84 	if (!encp->enc_hw_tx_insert_vlan_enabled &&
85 	    (flags & ETH_TXQ_FLAGS_NOVLANOFFL) == 0) {
86 		sfc_err(sa, "VLAN offload is not supported");
87 		rc = EINVAL;
88 	}
89 
90 	if ((flags & ETH_TXQ_FLAGS_NOXSUMSCTP) == 0) {
91 		sfc_err(sa, "SCTP offload is not supported");
92 		rc = EINVAL;
93 	}
94 
95 	/* We either perform both TCP and UDP offload, or no offload at all */
96 	if (((flags & ETH_TXQ_FLAGS_NOXSUMTCP) == 0) !=
97 	    ((flags & ETH_TXQ_FLAGS_NOXSUMUDP) == 0)) {
98 		sfc_err(sa, "TCP and UDP offloads can't be set independently");
99 		rc = EINVAL;
100 	}
101 
102 	return rc;
103 }
104 
105 void
106 sfc_tx_qflush_done(struct sfc_txq *txq)
107 {
108 	txq->state |= SFC_TXQ_FLUSHED;
109 	txq->state &= ~SFC_TXQ_FLUSHING;
110 }
111 
112 static void
113 sfc_tx_reap(struct sfc_txq *txq)
114 {
115 	unsigned int    completed;
116 
117 
118 	sfc_ev_qpoll(txq->evq);
119 
120 	for (completed = txq->completed;
121 	     completed != txq->pending; completed++) {
122 		struct sfc_tx_sw_desc *txd;
123 
124 		txd = &txq->sw_ring[completed & txq->ptr_mask];
125 
126 		if (txd->mbuf != NULL) {
127 			rte_pktmbuf_free(txd->mbuf);
128 			txd->mbuf = NULL;
129 		}
130 	}
131 
132 	txq->completed = completed;
133 }
134 
135 int
136 sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
137 	     uint16_t nb_tx_desc, unsigned int socket_id,
138 	     const struct rte_eth_txconf *tx_conf)
139 {
140 	struct sfc_txq_info *txq_info;
141 	struct sfc_evq *evq;
142 	struct sfc_txq *txq;
143 	unsigned int evq_index = sfc_evq_index_by_txq_sw_index(sa, sw_index);
144 	int rc = 0;
145 
146 	sfc_log_init(sa, "TxQ = %u", sw_index);
147 
148 	rc = sfc_tx_qcheck_conf(sa, nb_tx_desc, tx_conf);
149 	if (rc != 0)
150 		goto fail_bad_conf;
151 
152 	SFC_ASSERT(sw_index < sa->txq_count);
153 	txq_info = &sa->txq_info[sw_index];
154 
155 	SFC_ASSERT(nb_tx_desc <= sa->txq_max_entries);
156 	txq_info->entries = nb_tx_desc;
157 
158 	rc = sfc_ev_qinit(sa, evq_index, txq_info->entries, socket_id);
159 	if (rc != 0)
160 		goto fail_ev_qinit;
161 
162 	evq = sa->evq_info[evq_index].evq;
163 
164 	rc = ENOMEM;
165 	txq = rte_zmalloc_socket("sfc-txq", sizeof(*txq), 0, socket_id);
166 	if (txq == NULL)
167 		goto fail_txq_alloc;
168 
169 	rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_TXQ_SIZE(txq_info->entries),
170 			   socket_id, &txq->mem);
171 	if (rc != 0)
172 		goto fail_dma_alloc;
173 
174 	rc = ENOMEM;
175 	txq->pend_desc = rte_calloc_socket("sfc-txq-pend-desc",
176 					   EFX_TXQ_LIMIT(txq_info->entries),
177 					   sizeof(efx_desc_t), 0, socket_id);
178 	if (txq->pend_desc == NULL)
179 		goto fail_pend_desc_alloc;
180 
181 	rc = ENOMEM;
182 	txq->sw_ring = rte_calloc_socket("sfc-txq-desc", txq_info->entries,
183 					 sizeof(*txq->sw_ring), 0, socket_id);
184 	if (txq->sw_ring == NULL)
185 		goto fail_desc_alloc;
186 
187 	if (sa->tso) {
188 		rc = sfc_tso_alloc_tsoh_objs(txq->sw_ring, txq_info->entries,
189 					     socket_id);
190 		if (rc != 0)
191 			goto fail_alloc_tsoh_objs;
192 	}
193 
194 	txq->state = SFC_TXQ_INITIALIZED;
195 	txq->ptr_mask = txq_info->entries - 1;
196 	txq->free_thresh = (tx_conf->tx_free_thresh) ? tx_conf->tx_free_thresh :
197 						     SFC_TX_DEFAULT_FREE_THRESH;
198 	txq->hw_index = sw_index;
199 	txq->flags = tx_conf->txq_flags;
200 	txq->evq = evq;
201 
202 	evq->txq = txq;
203 
204 	txq_info->txq = txq;
205 	txq_info->deferred_start = (tx_conf->tx_deferred_start != 0);
206 
207 	return 0;
208 
209 fail_alloc_tsoh_objs:
210 	rte_free(txq->sw_ring);
211 
212 fail_desc_alloc:
213 	rte_free(txq->pend_desc);
214 
215 fail_pend_desc_alloc:
216 	sfc_dma_free(sa, &txq->mem);
217 
218 fail_dma_alloc:
219 	rte_free(txq);
220 
221 fail_txq_alloc:
222 	sfc_ev_qfini(sa, evq_index);
223 
224 fail_ev_qinit:
225 	txq_info->entries = 0;
226 
227 fail_bad_conf:
228 	sfc_log_init(sa, "failed (TxQ = %u, rc = %d)", sw_index, rc);
229 	return rc;
230 }
231 
232 void
233 sfc_tx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
234 {
235 	struct sfc_txq_info *txq_info;
236 	struct sfc_txq *txq;
237 
238 	sfc_log_init(sa, "TxQ = %u", sw_index);
239 
240 	SFC_ASSERT(sw_index < sa->txq_count);
241 	txq_info = &sa->txq_info[sw_index];
242 
243 	txq = txq_info->txq;
244 	SFC_ASSERT(txq != NULL);
245 	SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
246 
247 	sfc_tso_free_tsoh_objs(txq->sw_ring, txq_info->entries);
248 
249 	txq_info->txq = NULL;
250 	txq_info->entries = 0;
251 
252 	rte_free(txq->sw_ring);
253 	rte_free(txq->pend_desc);
254 	sfc_dma_free(sa, &txq->mem);
255 	rte_free(txq);
256 }
257 
258 static int
259 sfc_tx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
260 {
261 	sfc_log_init(sa, "TxQ = %u", sw_index);
262 
263 	return 0;
264 }
265 
266 static int
267 sfc_tx_check_mode(struct sfc_adapter *sa, const struct rte_eth_txmode *txmode)
268 {
269 	int rc = 0;
270 
271 	switch (txmode->mq_mode) {
272 	case ETH_MQ_TX_NONE:
273 		break;
274 	default:
275 		sfc_err(sa, "Tx multi-queue mode %u not supported",
276 			txmode->mq_mode);
277 		rc = EINVAL;
278 	}
279 
280 	/*
281 	 * These features are claimed to be i40e-specific,
282 	 * but it does make sense to double-check their absence
283 	 */
284 	if (txmode->hw_vlan_reject_tagged) {
285 		sfc_err(sa, "Rejecting tagged packets not supported");
286 		rc = EINVAL;
287 	}
288 
289 	if (txmode->hw_vlan_reject_untagged) {
290 		sfc_err(sa, "Rejecting untagged packets not supported");
291 		rc = EINVAL;
292 	}
293 
294 	if (txmode->hw_vlan_insert_pvid) {
295 		sfc_err(sa, "Port-based VLAN insertion not supported");
296 		rc = EINVAL;
297 	}
298 
299 	return rc;
300 }
301 
302 int
303 sfc_tx_init(struct sfc_adapter *sa)
304 {
305 	const struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
306 	unsigned int sw_index;
307 	int rc = 0;
308 
309 	rc = sfc_tx_check_mode(sa, &dev_conf->txmode);
310 	if (rc != 0)
311 		goto fail_check_mode;
312 
313 	sa->txq_count = sa->eth_dev->data->nb_tx_queues;
314 
315 	if (sa->tso)
316 		sa->txq_count = MIN(sa->txq_count,
317 		   efx_nic_cfg_get(sa->nic)->enc_fw_assisted_tso_v2_n_contexts /
318 		   efx_nic_cfg_get(sa->nic)->enc_hw_pf_count);
319 
320 	sa->txq_info = rte_calloc_socket("sfc-txqs", sa->txq_count,
321 					 sizeof(sa->txq_info[0]), 0,
322 					 sa->socket_id);
323 	if (sa->txq_info == NULL)
324 		goto fail_txqs_alloc;
325 
326 	for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
327 		rc = sfc_tx_qinit_info(sa, sw_index);
328 		if (rc != 0)
329 			goto fail_tx_qinit_info;
330 	}
331 
332 	return 0;
333 
334 fail_tx_qinit_info:
335 	rte_free(sa->txq_info);
336 	sa->txq_info = NULL;
337 
338 fail_txqs_alloc:
339 	sa->txq_count = 0;
340 
341 fail_check_mode:
342 	sfc_log_init(sa, "failed (rc = %d)", rc);
343 	return rc;
344 }
345 
346 void
347 sfc_tx_fini(struct sfc_adapter *sa)
348 {
349 	int sw_index;
350 
351 	sw_index = sa->txq_count;
352 	while (--sw_index >= 0) {
353 		if (sa->txq_info[sw_index].txq != NULL)
354 			sfc_tx_qfini(sa, sw_index);
355 	}
356 
357 	rte_free(sa->txq_info);
358 	sa->txq_info = NULL;
359 	sa->txq_count = 0;
360 }
361 
362 int
363 sfc_tx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
364 {
365 	struct rte_eth_dev_data *dev_data;
366 	struct sfc_txq_info *txq_info;
367 	struct sfc_txq *txq;
368 	struct sfc_evq *evq;
369 	uint16_t flags;
370 	unsigned int desc_index;
371 	int rc = 0;
372 
373 	sfc_log_init(sa, "TxQ = %u", sw_index);
374 
375 	SFC_ASSERT(sw_index < sa->txq_count);
376 	txq_info = &sa->txq_info[sw_index];
377 
378 	txq = txq_info->txq;
379 
380 	SFC_ASSERT(txq->state == SFC_TXQ_INITIALIZED);
381 
382 	evq = txq->evq;
383 
384 	rc = sfc_ev_qstart(sa, evq->evq_index);
385 	if (rc != 0)
386 		goto fail_ev_qstart;
387 
388 	/*
389 	 * It seems that DPDK has no controls regarding IPv4 offloads,
390 	 * hence, we always enable it here
391 	 */
392 	if ((txq->flags & ETH_TXQ_FLAGS_NOXSUMTCP) ||
393 	    (txq->flags & ETH_TXQ_FLAGS_NOXSUMUDP)) {
394 		flags = EFX_TXQ_CKSUM_IPV4;
395 	} else {
396 		flags = EFX_TXQ_CKSUM_IPV4 | EFX_TXQ_CKSUM_TCPUDP;
397 
398 		if (sa->tso)
399 			flags |= EFX_TXQ_FATSOV2;
400 	}
401 
402 	rc = efx_tx_qcreate(sa->nic, sw_index, 0, &txq->mem,
403 			    txq_info->entries, 0 /* not used on EF10 */,
404 			    flags, evq->common,
405 			    &txq->common, &desc_index);
406 	if (rc != 0) {
407 		if (sa->tso && (rc == ENOSPC))
408 			sfc_err(sa, "ran out of TSO contexts");
409 
410 		goto fail_tx_qcreate;
411 	}
412 
413 	txq->added = txq->pending = txq->completed = desc_index;
414 	txq->hw_vlan_tci = 0;
415 
416 	efx_tx_qenable(txq->common);
417 
418 	txq->state |= (SFC_TXQ_STARTED | SFC_TXQ_RUNNING);
419 
420 	/*
421 	 * It seems to be used by DPDK for debug purposes only ('rte_ether')
422 	 */
423 	dev_data = sa->eth_dev->data;
424 	dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STARTED;
425 
426 	return 0;
427 
428 fail_tx_qcreate:
429 	sfc_ev_qstop(sa, evq->evq_index);
430 
431 fail_ev_qstart:
432 	return rc;
433 }
434 
435 void
436 sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index)
437 {
438 	struct rte_eth_dev_data *dev_data;
439 	struct sfc_txq_info *txq_info;
440 	struct sfc_txq *txq;
441 	unsigned int retry_count;
442 	unsigned int wait_count;
443 	unsigned int txds;
444 
445 	sfc_log_init(sa, "TxQ = %u", sw_index);
446 
447 	SFC_ASSERT(sw_index < sa->txq_count);
448 	txq_info = &sa->txq_info[sw_index];
449 
450 	txq = txq_info->txq;
451 
452 	if (txq->state == SFC_TXQ_INITIALIZED)
453 		return;
454 
455 	SFC_ASSERT(txq->state & SFC_TXQ_STARTED);
456 
457 	txq->state &= ~SFC_TXQ_RUNNING;
458 
459 	/*
460 	 * Retry TX queue flushing in case of flush failed or
461 	 * timeout; in the worst case it can delay for 6 seconds
462 	 */
463 	for (retry_count = 0;
464 	     ((txq->state & SFC_TXQ_FLUSHED) == 0) &&
465 	     (retry_count < SFC_TX_QFLUSH_ATTEMPTS);
466 	     ++retry_count) {
467 		if (efx_tx_qflush(txq->common) != 0) {
468 			txq->state |= SFC_TXQ_FLUSHING;
469 			break;
470 		}
471 
472 		/*
473 		 * Wait for TX queue flush done or flush failed event at least
474 		 * SFC_TX_QFLUSH_POLL_WAIT_MS milliseconds and not more
475 		 * than 2 seconds (SFC_TX_QFLUSH_POLL_WAIT_MS multiplied
476 		 * by SFC_TX_QFLUSH_POLL_ATTEMPTS)
477 		 */
478 		wait_count = 0;
479 		do {
480 			rte_delay_ms(SFC_TX_QFLUSH_POLL_WAIT_MS);
481 			sfc_ev_qpoll(txq->evq);
482 		} while ((txq->state & SFC_TXQ_FLUSHING) &&
483 			 wait_count++ < SFC_TX_QFLUSH_POLL_ATTEMPTS);
484 
485 		if (txq->state & SFC_TXQ_FLUSHING)
486 			sfc_err(sa, "TxQ %u flush timed out", sw_index);
487 
488 		if (txq->state & SFC_TXQ_FLUSHED)
489 			sfc_info(sa, "TxQ %u flushed", sw_index);
490 	}
491 
492 	sfc_tx_reap(txq);
493 
494 	for (txds = 0; txds < txq_info->entries; txds++) {
495 		if (txq->sw_ring[txds].mbuf != NULL) {
496 			rte_pktmbuf_free(txq->sw_ring[txds].mbuf);
497 			txq->sw_ring[txds].mbuf = NULL;
498 		}
499 	}
500 
501 	txq->state = SFC_TXQ_INITIALIZED;
502 
503 	efx_tx_qdestroy(txq->common);
504 
505 	sfc_ev_qstop(sa, txq->evq->evq_index);
506 
507 	/*
508 	 * It seems to be used by DPDK for debug purposes only ('rte_ether')
509 	 */
510 	dev_data = sa->eth_dev->data;
511 	dev_data->tx_queue_state[sw_index] = RTE_ETH_QUEUE_STATE_STOPPED;
512 }
513 
514 int
515 sfc_tx_start(struct sfc_adapter *sa)
516 {
517 	unsigned int sw_index;
518 	int rc = 0;
519 
520 	sfc_log_init(sa, "txq_count = %u", sa->txq_count);
521 
522 	if (sa->tso) {
523 		if (!efx_nic_cfg_get(sa->nic)->enc_fw_assisted_tso_v2_enabled) {
524 			sfc_warn(sa, "TSO support was unable to be restored");
525 			sa->tso = B_FALSE;
526 		}
527 	}
528 
529 	rc = efx_tx_init(sa->nic);
530 	if (rc != 0)
531 		goto fail_efx_tx_init;
532 
533 	for (sw_index = 0; sw_index < sa->txq_count; ++sw_index) {
534 		if (!(sa->txq_info[sw_index].deferred_start) ||
535 		    sa->txq_info[sw_index].deferred_started) {
536 			rc = sfc_tx_qstart(sa, sw_index);
537 			if (rc != 0)
538 				goto fail_tx_qstart;
539 		}
540 	}
541 
542 	return 0;
543 
544 fail_tx_qstart:
545 	while (sw_index-- > 0)
546 		sfc_tx_qstop(sa, sw_index);
547 
548 	efx_tx_fini(sa->nic);
549 
550 fail_efx_tx_init:
551 	sfc_log_init(sa, "failed (rc = %d)", rc);
552 	return rc;
553 }
554 
555 void
556 sfc_tx_stop(struct sfc_adapter *sa)
557 {
558 	unsigned int sw_index;
559 
560 	sfc_log_init(sa, "txq_count = %u", sa->txq_count);
561 
562 	sw_index = sa->txq_count;
563 	while (sw_index-- > 0) {
564 		if (sa->txq_info[sw_index].txq != NULL)
565 			sfc_tx_qstop(sa, sw_index);
566 	}
567 
568 	efx_tx_fini(sa->nic);
569 }
570 
571 /*
572  * The function is used to insert or update VLAN tag;
573  * the firmware has state of the firmware tag to insert per TxQ
574  * (controlled by option descriptors), hence, if the tag of the
575  * packet to be sent is different from one remembered by the firmware,
576  * the function will update it
577  */
578 static unsigned int
579 sfc_tx_maybe_insert_tag(struct sfc_txq *txq, struct rte_mbuf *m,
580 			efx_desc_t **pend)
581 {
582 	uint16_t this_tag = ((m->ol_flags & PKT_TX_VLAN_PKT) ?
583 			     m->vlan_tci : 0);
584 
585 	if (this_tag == txq->hw_vlan_tci)
586 		return 0;
587 
588 	/*
589 	 * The expression inside SFC_ASSERT() is not desired to be checked in
590 	 * a non-debug build because it might be too expensive on the data path
591 	 */
592 	SFC_ASSERT(efx_nic_cfg_get(txq->evq->sa->nic)->enc_hw_tx_insert_vlan_enabled);
593 
594 	efx_tx_qdesc_vlantci_create(txq->common, rte_cpu_to_be_16(this_tag),
595 				    *pend);
596 	(*pend)++;
597 	txq->hw_vlan_tci = this_tag;
598 
599 	return 1;
600 }
601 
602 uint16_t
603 sfc_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
604 {
605 	struct sfc_txq *txq = (struct sfc_txq *)tx_queue;
606 	unsigned int added = txq->added;
607 	unsigned int pushed = added;
608 	unsigned int pkts_sent = 0;
609 	efx_desc_t *pend = &txq->pend_desc[0];
610 	const unsigned int hard_max_fill = EFX_TXQ_LIMIT(txq->ptr_mask + 1);
611 	const unsigned int soft_max_fill = hard_max_fill - txq->free_thresh;
612 	unsigned int fill_level = added - txq->completed;
613 	boolean_t reap_done;
614 	int rc __rte_unused;
615 	struct rte_mbuf **pktp;
616 
617 	if (unlikely((txq->state & SFC_TXQ_RUNNING) == 0))
618 		goto done;
619 
620 	/*
621 	 * If insufficient space for a single packet is present,
622 	 * we should reap; otherwise, we shouldn't do that all the time
623 	 * to avoid latency increase
624 	 */
625 	reap_done = (fill_level > soft_max_fill);
626 
627 	if (reap_done) {
628 		sfc_tx_reap(txq);
629 		/*
630 		 * Recalculate fill level since 'txq->completed'
631 		 * might have changed on reap
632 		 */
633 		fill_level = added - txq->completed;
634 	}
635 
636 	for (pkts_sent = 0, pktp = &tx_pkts[0];
637 	     (pkts_sent < nb_pkts) && (fill_level <= soft_max_fill);
638 	     pkts_sent++, pktp++) {
639 		struct rte_mbuf		*m_seg = *pktp;
640 		size_t			pkt_len = m_seg->pkt_len;
641 		unsigned int		pkt_descs = 0;
642 		size_t			in_off = 0;
643 
644 		/*
645 		 * Here VLAN TCI is expected to be zero in case if no
646 		 * DEV_TX_VLAN_OFFLOAD capability is advertised;
647 		 * if the calling app ignores the absence of
648 		 * DEV_TX_VLAN_OFFLOAD and pushes VLAN TCI, then
649 		 * TX_ERROR will occur
650 		 */
651 		pkt_descs += sfc_tx_maybe_insert_tag(txq, m_seg, &pend);
652 
653 #ifdef RTE_LIBRTE_SFC_EFX_TSO
654 		if (m_seg->ol_flags & PKT_TX_TCP_SEG) {
655 			/*
656 			 * We expect correct 'pkt->l[2, 3, 4]_len' values
657 			 * to be set correctly by the caller
658 			 */
659 			if (sfc_tso_do(txq, added, &m_seg, &in_off, &pend,
660 				       &pkt_descs, &pkt_len) != 0) {
661 				/* We may have reached this place for
662 				 * one of the following reasons:
663 				 *
664 				 * 1) Packet header length is greater
665 				 *    than SFC_TSOH_STD_LEN
666 				 * 2) TCP header starts at more then
667 				 *    208 bytes into the frame
668 				 *
669 				 * We will deceive RTE saying that we have sent
670 				 * the packet, but we will actually drop it.
671 				 * Hence, we should revert 'pend' to the
672 				 * previous state (in case we have added
673 				 * VLAN descriptor) and start processing
674 				 * another one packet. But the original
675 				 * mbuf shouldn't be orphaned
676 				 */
677 				pend -= pkt_descs;
678 
679 				rte_pktmbuf_free(*pktp);
680 
681 				continue;
682 			}
683 
684 			/*
685 			 * We've only added 2 FATSOv2 option descriptors
686 			 * and 1 descriptor for the linearized packet header.
687 			 * The outstanding work will be done in the same manner
688 			 * as for the usual non-TSO path
689 			 */
690 		}
691 #endif /* RTE_LIBRTE_SFC_EFX_TSO */
692 
693 		for (; m_seg != NULL; m_seg = m_seg->next) {
694 			efsys_dma_addr_t	next_frag;
695 			size_t			seg_len;
696 
697 			seg_len = m_seg->data_len;
698 			next_frag = rte_mbuf_data_dma_addr(m_seg);
699 
700 			/*
701 			 * If we've started TSO transaction few steps earlier,
702 			 * we'll skip packet header using an offset in the
703 			 * current segment (which has been set to the
704 			 * first one containing payload)
705 			 */
706 			seg_len -= in_off;
707 			next_frag += in_off;
708 			in_off = 0;
709 
710 			do {
711 				efsys_dma_addr_t	frag_addr = next_frag;
712 				size_t			frag_len;
713 
714 				next_frag = RTE_ALIGN(frag_addr + 1,
715 						      SFC_TX_SEG_BOUNDARY);
716 				frag_len = MIN(next_frag - frag_addr, seg_len);
717 				seg_len -= frag_len;
718 				pkt_len -= frag_len;
719 
720 				efx_tx_qdesc_dma_create(txq->common,
721 							frag_addr, frag_len,
722 							(pkt_len == 0),
723 							pend++);
724 
725 				pkt_descs++;
726 			} while (seg_len != 0);
727 		}
728 
729 		added += pkt_descs;
730 
731 		fill_level += pkt_descs;
732 		if (unlikely(fill_level > hard_max_fill)) {
733 			/*
734 			 * Our estimation for maximum number of descriptors
735 			 * required to send a packet seems to be wrong.
736 			 * Try to reap (if we haven't yet).
737 			 */
738 			if (!reap_done) {
739 				sfc_tx_reap(txq);
740 				reap_done = B_TRUE;
741 				fill_level = added - txq->completed;
742 				if (fill_level > hard_max_fill) {
743 					pend -= pkt_descs;
744 					break;
745 				}
746 			} else {
747 				pend -= pkt_descs;
748 				break;
749 			}
750 		}
751 
752 		/* Assign mbuf to the last used desc */
753 		txq->sw_ring[(added - 1) & txq->ptr_mask].mbuf = *pktp;
754 	}
755 
756 	if (likely(pkts_sent > 0)) {
757 		rc = efx_tx_qdesc_post(txq->common, txq->pend_desc,
758 				       pend - &txq->pend_desc[0],
759 				       txq->completed, &txq->added);
760 		SFC_ASSERT(rc == 0);
761 
762 		if (likely(pushed != txq->added))
763 			efx_tx_qpush(txq->common, txq->added, pushed);
764 	}
765 
766 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
767 	if (!reap_done)
768 		sfc_tx_reap(txq);
769 #endif
770 
771 done:
772 	return pkts_sent;
773 }
774