net/sfc: reserve queues for port representors
[dpdk.git] / drivers / net / sfc / sfc_tx.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2016-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #include "sfc.h"
11 #include "sfc_debug.h"
12 #include "sfc_log.h"
13 #include "sfc_ev.h"
14 #include "sfc_tx.h"
15 #include "sfc_tweak.h"
16 #include "sfc_kvargs.h"
17
18 /*
19  * Maximum number of TX queue flush attempts in case of
20  * failure or flush timeout
21  */
22 #define SFC_TX_QFLUSH_ATTEMPTS          (3)
23
24 /*
25  * Time to wait between event queue polling attempts when waiting for TX
26  * queue flush done or flush failed events
27  */
28 #define SFC_TX_QFLUSH_POLL_WAIT_MS      (1)
29
30 /*
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
34  */
35 #define SFC_TX_QFLUSH_POLL_ATTEMPTS     (2000)
36
37 struct sfc_txq_info *
38 sfc_txq_info_by_ethdev_qid(struct sfc_adapter_shared *sas,
39                            sfc_ethdev_qid_t ethdev_qid)
40 {
41         sfc_sw_index_t sw_index;
42
43         SFC_ASSERT((unsigned int)ethdev_qid < sas->ethdev_txq_count);
44         SFC_ASSERT(ethdev_qid != SFC_ETHDEV_QID_INVALID);
45
46         sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
47         return &sas->txq_info[sw_index];
48 }
49
50 static uint64_t
51 sfc_tx_get_offload_mask(struct sfc_adapter *sa)
52 {
53         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
54         uint64_t no_caps = 0;
55
56         if (!encp->enc_hw_tx_insert_vlan_enabled)
57                 no_caps |= DEV_TX_OFFLOAD_VLAN_INSERT;
58
59         if (!encp->enc_tunnel_encapsulations_supported)
60                 no_caps |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
61
62         if (!sa->tso)
63                 no_caps |= DEV_TX_OFFLOAD_TCP_TSO;
64
65         if (!sa->tso_encap ||
66             (encp->enc_tunnel_encapsulations_supported &
67              (1u << EFX_TUNNEL_PROTOCOL_VXLAN)) == 0)
68                 no_caps |= DEV_TX_OFFLOAD_VXLAN_TNL_TSO;
69
70         if (!sa->tso_encap ||
71             (encp->enc_tunnel_encapsulations_supported &
72              (1u << EFX_TUNNEL_PROTOCOL_GENEVE)) == 0)
73                 no_caps |= DEV_TX_OFFLOAD_GENEVE_TNL_TSO;
74
75         return ~no_caps;
76 }
77
78 uint64_t
79 sfc_tx_get_dev_offload_caps(struct sfc_adapter *sa)
80 {
81         return sa->priv.dp_tx->dev_offload_capa & sfc_tx_get_offload_mask(sa);
82 }
83
84 uint64_t
85 sfc_tx_get_queue_offload_caps(struct sfc_adapter *sa)
86 {
87         return sa->priv.dp_tx->queue_offload_capa & sfc_tx_get_offload_mask(sa);
88 }
89
90 static int
91 sfc_tx_qcheck_conf(struct sfc_adapter *sa, unsigned int txq_max_fill_level,
92                    const struct rte_eth_txconf *tx_conf,
93                    uint64_t offloads)
94 {
95         int rc = 0;
96
97         if (tx_conf->tx_rs_thresh != 0) {
98                 sfc_err(sa, "RS bit in transmit descriptor is not supported");
99                 rc = EINVAL;
100         }
101
102         if (tx_conf->tx_free_thresh > txq_max_fill_level) {
103                 sfc_err(sa,
104                         "TxQ free threshold too large: %u vs maximum %u",
105                         tx_conf->tx_free_thresh, txq_max_fill_level);
106                 rc = EINVAL;
107         }
108
109         if (tx_conf->tx_thresh.pthresh != 0 ||
110             tx_conf->tx_thresh.hthresh != 0 ||
111             tx_conf->tx_thresh.wthresh != 0) {
112                 sfc_warn(sa,
113                         "prefetch/host/writeback thresholds are not supported");
114         }
115
116         /* We either perform both TCP and UDP offload, or no offload at all */
117         if (((offloads & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) !=
118             ((offloads & DEV_TX_OFFLOAD_UDP_CKSUM) == 0)) {
119                 sfc_err(sa, "TCP and UDP offloads can't be set independently");
120                 rc = EINVAL;
121         }
122
123         return rc;
124 }
125
126 void
127 sfc_tx_qflush_done(struct sfc_txq_info *txq_info)
128 {
129         txq_info->state |= SFC_TXQ_FLUSHED;
130         txq_info->state &= ~SFC_TXQ_FLUSHING;
131 }
132
133 int
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)
137 {
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;
145         struct sfc_evq *evq;
146         struct sfc_txq *txq;
147         int rc = 0;
148         struct sfc_dp_tx_qcreate_info info;
149         uint64_t offloads;
150         struct sfc_dp_tx_hw_limits hw_limits;
151
152         ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
153
154         sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
155
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;
159
160         rc = sa->priv.dp_tx->qsize_up_rings(nb_tx_desc, &hw_limits,
161                                             &txq_entries, &evq_entries,
162                                             &txq_max_fill_level);
163         if (rc != 0)
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);
169
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;
174
175         rc = sfc_tx_qcheck_conf(sa, txq_max_fill_level, tx_conf, offloads);
176         if (rc != 0)
177                 goto fail_bad_conf;
178
179         SFC_ASSERT(sw_index < sfc_sa2shared(sa)->txq_count);
180         txq_info = &sfc_sa2shared(sa)->txq_info[sw_index];
181
182         txq_info->entries = txq_entries;
183
184         rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_TX, sw_index,
185                           evq_entries, socket_id, &evq);
186         if (rc != 0)
187                 goto fail_ev_qinit;
188
189         txq = &sa->txq_ctrl[sw_index];
190         txq->hw_index = sw_index;
191         txq->evq = evq;
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;
196
197         rc = sfc_dma_alloc(sa, "txq", sw_index,
198                            efx_txq_size(sa->nic, txq_info->entries),
199                            socket_id, &txq->mem);
200         if (rc != 0)
201                 goto fail_dma_alloc;
202
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;
228
229         rc = sa->priv.dp_tx->qcreate(sa->eth_dev->data->port_id, sw_index,
230                                      &RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr,
231                                      socket_id, &info, &txq_info->dp);
232         if (rc != 0)
233                 goto fail_dp_tx_qinit;
234
235         evq->dp_txq = txq_info->dp;
236
237         txq_info->state = SFC_TXQ_INITIALIZED;
238
239         txq_info->deferred_start = (tx_conf->tx_deferred_start != 0);
240
241         return 0;
242
243 fail_dp_tx_qinit:
244         sfc_dma_free(sa, &txq->mem);
245
246 fail_dma_alloc:
247         sfc_ev_qfini(evq);
248
249 fail_ev_qinit:
250         txq_info->entries = 0;
251
252 fail_bad_conf:
253 fail_size_up_rings:
254         sfc_log_init(sa, "failed (TxQ = %d (internal %u), rc = %d)", ethdev_qid,
255                      sw_index, rc);
256         return rc;
257 }
258
259 void
260 sfc_tx_qfini(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
261 {
262         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
263         sfc_ethdev_qid_t ethdev_qid;
264         struct sfc_txq_info *txq_info;
265         struct sfc_txq *txq;
266
267         ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
268
269         sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
270
271         SFC_ASSERT(sw_index < sfc_sa2shared(sa)->txq_count);
272         if (ethdev_qid != SFC_ETHDEV_QID_INVALID)
273                 sa->eth_dev->data->tx_queues[ethdev_qid] = NULL;
274
275         txq_info = &sfc_sa2shared(sa)->txq_info[sw_index];
276
277         SFC_ASSERT(txq_info->state == SFC_TXQ_INITIALIZED);
278
279         sa->priv.dp_tx->qdestroy(txq_info->dp);
280         txq_info->dp = NULL;
281
282         txq_info->state &= ~SFC_TXQ_INITIALIZED;
283         txq_info->entries = 0;
284
285         txq = &sa->txq_ctrl[sw_index];
286
287         sfc_dma_free(sa, &txq->mem);
288
289         sfc_ev_qfini(txq->evq);
290         txq->evq = NULL;
291 }
292
293 static int
294 sfc_tx_qinit_info(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
295 {
296         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
297         sfc_ethdev_qid_t ethdev_qid;
298
299         ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
300
301         sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
302
303         return 0;
304 }
305
306 static int
307 sfc_tx_check_mode(struct sfc_adapter *sa, const struct rte_eth_txmode *txmode)
308 {
309         int rc = 0;
310
311         switch (txmode->mq_mode) {
312         case ETH_MQ_TX_NONE:
313                 break;
314         default:
315                 sfc_err(sa, "Tx multi-queue mode %u not supported",
316                         txmode->mq_mode);
317                 rc = EINVAL;
318         }
319
320         /*
321          * These features are claimed to be i40e-specific,
322          * but it does make sense to double-check their absence
323          */
324         if (txmode->hw_vlan_reject_tagged) {
325                 sfc_err(sa, "Rejecting tagged packets not supported");
326                 rc = EINVAL;
327         }
328
329         if (txmode->hw_vlan_reject_untagged) {
330                 sfc_err(sa, "Rejecting untagged packets not supported");
331                 rc = EINVAL;
332         }
333
334         if (txmode->hw_vlan_insert_pvid) {
335                 sfc_err(sa, "Port-based VLAN insertion not supported");
336                 rc = EINVAL;
337         }
338
339         return rc;
340 }
341
342 /**
343  * Destroy excess queues that are no longer needed after reconfiguration
344  * or complete close.
345  */
346 static void
347 sfc_tx_fini_queues(struct sfc_adapter *sa, unsigned int nb_tx_queues)
348 {
349         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
350         sfc_sw_index_t sw_index;
351         sfc_ethdev_qid_t ethdev_qid;
352
353         SFC_ASSERT(nb_tx_queues <= sas->ethdev_txq_count);
354
355         /*
356          * Finalize only ethdev queues since other ones are finalized only
357          * on device close and they may require additional deinitializaton.
358          */
359         ethdev_qid = sas->ethdev_txq_count;
360         while (--ethdev_qid >= (int)nb_tx_queues) {
361                 struct sfc_txq_info *txq_info;
362
363                 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
364                 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
365                 if (txq_info->state & SFC_TXQ_INITIALIZED)
366                         sfc_tx_qfini(sa, sw_index);
367         }
368
369         sas->ethdev_txq_count = nb_tx_queues;
370 }
371
372 int
373 sfc_tx_configure(struct sfc_adapter *sa)
374 {
375         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
376         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
377         const struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf;
378         const unsigned int nb_tx_queues = sa->eth_dev->data->nb_tx_queues;
379         const unsigned int nb_rsvd_tx_queues = sfc_nb_txq_reserved(sas);
380         const unsigned int nb_txq_total = nb_tx_queues + nb_rsvd_tx_queues;
381         int rc = 0;
382
383         sfc_log_init(sa, "nb_tx_queues=%u (old %u)",
384                      nb_tx_queues, sas->ethdev_txq_count);
385
386         /*
387          * The datapath implementation assumes absence of boundary
388          * limits on Tx DMA descriptors. Addition of these checks on
389          * datapath would simply make the datapath slower.
390          */
391         if (encp->enc_tx_dma_desc_boundary != 0) {
392                 rc = ENOTSUP;
393                 goto fail_tx_dma_desc_boundary;
394         }
395
396         rc = sfc_tx_check_mode(sa, &dev_conf->txmode);
397         if (rc != 0)
398                 goto fail_check_mode;
399
400         if (nb_txq_total == sas->txq_count)
401                 goto done;
402
403         if (sas->txq_info == NULL) {
404                 sas->txq_info = rte_calloc_socket("sfc-txqs", nb_txq_total,
405                                                   sizeof(sas->txq_info[0]), 0,
406                                                   sa->socket_id);
407                 if (sas->txq_info == NULL)
408                         goto fail_txqs_alloc;
409
410                 /*
411                  * Allocate primary process only TxQ control from heap
412                  * since it should not be shared.
413                  */
414                 rc = ENOMEM;
415                 sa->txq_ctrl = calloc(nb_txq_total, sizeof(sa->txq_ctrl[0]));
416                 if (sa->txq_ctrl == NULL)
417                         goto fail_txqs_ctrl_alloc;
418         } else {
419                 struct sfc_txq_info *new_txq_info;
420                 struct sfc_txq *new_txq_ctrl;
421
422                 if (nb_tx_queues < sas->ethdev_txq_count)
423                         sfc_tx_fini_queues(sa, nb_tx_queues);
424
425                 new_txq_info =
426                         rte_realloc(sas->txq_info,
427                                     nb_txq_total * sizeof(sas->txq_info[0]), 0);
428                 if (new_txq_info == NULL && nb_txq_total > 0)
429                         goto fail_txqs_realloc;
430
431                 new_txq_ctrl = realloc(sa->txq_ctrl,
432                                        nb_txq_total * sizeof(sa->txq_ctrl[0]));
433                 if (new_txq_ctrl == NULL && nb_txq_total > 0)
434                         goto fail_txqs_ctrl_realloc;
435
436                 sas->txq_info = new_txq_info;
437                 sa->txq_ctrl = new_txq_ctrl;
438                 if (nb_txq_total > sas->txq_count) {
439                         memset(&sas->txq_info[sas->txq_count], 0,
440                                (nb_txq_total - sas->txq_count) *
441                                sizeof(sas->txq_info[0]));
442                         memset(&sa->txq_ctrl[sas->txq_count], 0,
443                                (nb_txq_total - sas->txq_count) *
444                                sizeof(sa->txq_ctrl[0]));
445                 }
446         }
447
448         while (sas->ethdev_txq_count < nb_tx_queues) {
449                 sfc_sw_index_t sw_index;
450
451                 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas,
452                                 sas->ethdev_txq_count);
453                 rc = sfc_tx_qinit_info(sa, sw_index);
454                 if (rc != 0)
455                         goto fail_tx_qinit_info;
456
457                 sas->ethdev_txq_count++;
458         }
459
460         /* TODO: initialize reserved queues when supported. */
461         sas->txq_count = sas->ethdev_txq_count + nb_rsvd_tx_queues;
462
463 done:
464         return 0;
465
466 fail_tx_qinit_info:
467 fail_txqs_ctrl_realloc:
468 fail_txqs_realloc:
469 fail_txqs_ctrl_alloc:
470 fail_txqs_alloc:
471         sfc_tx_close(sa);
472
473 fail_check_mode:
474 fail_tx_dma_desc_boundary:
475         sfc_log_init(sa, "failed (rc = %d)", rc);
476         return rc;
477 }
478
479 void
480 sfc_tx_close(struct sfc_adapter *sa)
481 {
482         sfc_tx_fini_queues(sa, 0);
483
484         free(sa->txq_ctrl);
485         sa->txq_ctrl = NULL;
486
487         rte_free(sfc_sa2shared(sa)->txq_info);
488         sfc_sa2shared(sa)->txq_info = NULL;
489 }
490
491 int
492 sfc_tx_qstart(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
493 {
494         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
495         sfc_ethdev_qid_t ethdev_qid;
496         uint64_t offloads_supported = sfc_tx_get_dev_offload_caps(sa) |
497                                       sfc_tx_get_queue_offload_caps(sa);
498         struct sfc_txq_info *txq_info;
499         struct sfc_txq *txq;
500         struct sfc_evq *evq;
501         uint16_t flags = 0;
502         unsigned int desc_index;
503         int rc = 0;
504
505         ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
506
507         sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
508
509         SFC_ASSERT(sw_index < sas->txq_count);
510         txq_info = &sas->txq_info[sw_index];
511
512         SFC_ASSERT(txq_info->state == SFC_TXQ_INITIALIZED);
513
514         txq = &sa->txq_ctrl[sw_index];
515         evq = txq->evq;
516
517         rc = sfc_ev_qstart(evq, sfc_evq_sw_index_by_txq_sw_index(sa, sw_index));
518         if (rc != 0)
519                 goto fail_ev_qstart;
520
521         if (txq_info->offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
522                 flags |= EFX_TXQ_CKSUM_IPV4;
523
524         if (txq_info->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
525                 flags |= EFX_TXQ_CKSUM_INNER_IPV4;
526
527         if ((txq_info->offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
528             (txq_info->offloads & DEV_TX_OFFLOAD_UDP_CKSUM)) {
529                 flags |= EFX_TXQ_CKSUM_TCPUDP;
530
531                 if (offloads_supported & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
532                         flags |= EFX_TXQ_CKSUM_INNER_TCPUDP;
533         }
534
535         if (txq_info->offloads & (DEV_TX_OFFLOAD_TCP_TSO |
536                                   DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
537                                   DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
538                 flags |= EFX_TXQ_FATSOV2;
539
540         rc = efx_tx_qcreate(sa->nic, txq->hw_index, 0, &txq->mem,
541                             txq_info->entries, 0 /* not used on EF10 */,
542                             flags, evq->common,
543                             &txq->common, &desc_index);
544         if (rc != 0) {
545                 if (sa->tso && (rc == ENOSPC))
546                         sfc_err(sa, "ran out of TSO contexts");
547
548                 goto fail_tx_qcreate;
549         }
550
551         efx_tx_qenable(txq->common);
552
553         txq_info->state |= SFC_TXQ_STARTED;
554
555         rc = sa->priv.dp_tx->qstart(txq_info->dp, evq->read_ptr, desc_index);
556         if (rc != 0)
557                 goto fail_dp_qstart;
558
559         if (ethdev_qid != SFC_ETHDEV_QID_INVALID) {
560                 struct rte_eth_dev_data *dev_data;
561
562                 /*
563                  * It sems to be used by DPDK for debug purposes only
564                  * ('rte_ether').
565                  */
566                 dev_data = sa->eth_dev->data;
567                 dev_data->tx_queue_state[ethdev_qid] =
568                         RTE_ETH_QUEUE_STATE_STARTED;
569         }
570
571         return 0;
572
573 fail_dp_qstart:
574         txq_info->state = SFC_TXQ_INITIALIZED;
575         efx_tx_qdestroy(txq->common);
576
577 fail_tx_qcreate:
578         sfc_ev_qstop(evq);
579
580 fail_ev_qstart:
581         return rc;
582 }
583
584 void
585 sfc_tx_qstop(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
586 {
587         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
588         sfc_ethdev_qid_t ethdev_qid;
589         struct sfc_txq_info *txq_info;
590         struct sfc_txq *txq;
591         unsigned int retry_count;
592         unsigned int wait_count;
593         int rc;
594
595         ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, sw_index);
596
597         sfc_log_init(sa, "TxQ = %d (internal %u)", ethdev_qid, sw_index);
598
599         SFC_ASSERT(sw_index < sas->txq_count);
600         txq_info = &sas->txq_info[sw_index];
601
602         if (txq_info->state == SFC_TXQ_INITIALIZED)
603                 return;
604
605         SFC_ASSERT(txq_info->state & SFC_TXQ_STARTED);
606
607         txq = &sa->txq_ctrl[sw_index];
608         sa->priv.dp_tx->qstop(txq_info->dp, &txq->evq->read_ptr);
609
610         /*
611          * Retry TX queue flushing in case of flush failed or
612          * timeout; in the worst case it can delay for 6 seconds
613          */
614         for (retry_count = 0;
615              ((txq_info->state & SFC_TXQ_FLUSHED) == 0) &&
616              (retry_count < SFC_TX_QFLUSH_ATTEMPTS);
617              ++retry_count) {
618                 rc = efx_tx_qflush(txq->common);
619                 if (rc != 0) {
620                         txq_info->state |= (rc == EALREADY) ?
621                                 SFC_TXQ_FLUSHED : SFC_TXQ_FLUSH_FAILED;
622                         break;
623                 }
624
625                 /*
626                  * Wait for TX queue flush done or flush failed event at least
627                  * SFC_TX_QFLUSH_POLL_WAIT_MS milliseconds and not more
628                  * than 2 seconds (SFC_TX_QFLUSH_POLL_WAIT_MS multiplied
629                  * by SFC_TX_QFLUSH_POLL_ATTEMPTS)
630                  */
631                 wait_count = 0;
632                 do {
633                         rte_delay_ms(SFC_TX_QFLUSH_POLL_WAIT_MS);
634                         sfc_ev_qpoll(txq->evq);
635                 } while ((txq_info->state & SFC_TXQ_FLUSHING) &&
636                          wait_count++ < SFC_TX_QFLUSH_POLL_ATTEMPTS);
637
638                 if (txq_info->state & SFC_TXQ_FLUSHING)
639                         sfc_err(sa, "TxQ %d (internal %u) flush timed out",
640                                 ethdev_qid, sw_index);
641
642                 if (txq_info->state & SFC_TXQ_FLUSHED)
643                         sfc_notice(sa, "TxQ %d (internal %u) flushed",
644                                    ethdev_qid, sw_index);
645         }
646
647         sa->priv.dp_tx->qreap(txq_info->dp);
648
649         txq_info->state = SFC_TXQ_INITIALIZED;
650
651         efx_tx_qdestroy(txq->common);
652
653         sfc_ev_qstop(txq->evq);
654
655         if (ethdev_qid != SFC_ETHDEV_QID_INVALID) {
656                 struct rte_eth_dev_data *dev_data;
657
658                 /*
659                  * It seems to be used by DPDK for debug purposes only
660                  * ('rte_ether')
661                  */
662                 dev_data = sa->eth_dev->data;
663                 dev_data->tx_queue_state[ethdev_qid] =
664                         RTE_ETH_QUEUE_STATE_STOPPED;
665         }
666 }
667
668 int
669 sfc_tx_start(struct sfc_adapter *sa)
670 {
671         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
672         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
673         sfc_sw_index_t sw_index;
674         int rc = 0;
675
676         sfc_log_init(sa, "txq_count = %u (internal %u)",
677                      sas->ethdev_txq_count, sas->txq_count);
678
679         if (sa->tso) {
680                 if (!encp->enc_fw_assisted_tso_v2_enabled &&
681                     !encp->enc_tso_v3_enabled) {
682                         sfc_warn(sa, "TSO support was unable to be restored");
683                         sa->tso = B_FALSE;
684                         sa->tso_encap = B_FALSE;
685                 }
686         }
687
688         if (sa->tso_encap && !encp->enc_fw_assisted_tso_v2_encap_enabled &&
689             !encp->enc_tso_v3_enabled) {
690                 sfc_warn(sa, "Encapsulated TSO support was unable to be restored");
691                 sa->tso_encap = B_FALSE;
692         }
693
694         rc = efx_tx_init(sa->nic);
695         if (rc != 0)
696                 goto fail_efx_tx_init;
697
698         for (sw_index = 0; sw_index < sas->txq_count; ++sw_index) {
699                 if (sas->txq_info[sw_index].state == SFC_TXQ_INITIALIZED &&
700                     (!(sas->txq_info[sw_index].deferred_start) ||
701                      sas->txq_info[sw_index].deferred_started)) {
702                         rc = sfc_tx_qstart(sa, sw_index);
703                         if (rc != 0)
704                                 goto fail_tx_qstart;
705                 }
706         }
707
708         return 0;
709
710 fail_tx_qstart:
711         while (sw_index-- > 0)
712                 sfc_tx_qstop(sa, sw_index);
713
714         efx_tx_fini(sa->nic);
715
716 fail_efx_tx_init:
717         sfc_log_init(sa, "failed (rc = %d)", rc);
718         return rc;
719 }
720
721 void
722 sfc_tx_stop(struct sfc_adapter *sa)
723 {
724         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
725         sfc_sw_index_t sw_index;
726
727         sfc_log_init(sa, "txq_count = %u (internal %u)",
728                      sas->ethdev_txq_count, sas->txq_count);
729
730         sw_index = sas->txq_count;
731         while (sw_index-- > 0) {
732                 if (sas->txq_info[sw_index].state & SFC_TXQ_STARTED)
733                         sfc_tx_qstop(sa, sw_index);
734         }
735
736         efx_tx_fini(sa->nic);
737 }
738
739 static void
740 sfc_efx_tx_reap(struct sfc_efx_txq *txq)
741 {
742         unsigned int completed;
743
744         sfc_ev_qpoll(txq->evq);
745
746         for (completed = txq->completed;
747              completed != txq->pending; completed++) {
748                 struct sfc_efx_tx_sw_desc *txd;
749
750                 txd = &txq->sw_ring[completed & txq->ptr_mask];
751
752                 if (txd->mbuf != NULL) {
753                         rte_pktmbuf_free(txd->mbuf);
754                         txd->mbuf = NULL;
755                 }
756         }
757
758         txq->completed = completed;
759 }
760
761 /*
762  * The function is used to insert or update VLAN tag;
763  * the firmware has state of the firmware tag to insert per TxQ
764  * (controlled by option descriptors), hence, if the tag of the
765  * packet to be sent is different from one remembered by the firmware,
766  * the function will update it
767  */
768 static unsigned int
769 sfc_efx_tx_maybe_insert_tag(struct sfc_efx_txq *txq, struct rte_mbuf *m,
770                             efx_desc_t **pend)
771 {
772         uint16_t this_tag = ((m->ol_flags & PKT_TX_VLAN_PKT) ?
773                              m->vlan_tci : 0);
774
775         if (this_tag == txq->hw_vlan_tci)
776                 return 0;
777
778         /*
779          * The expression inside SFC_ASSERT() is not desired to be checked in
780          * a non-debug build because it might be too expensive on the data path
781          */
782         SFC_ASSERT(efx_nic_cfg_get(txq->evq->sa->nic)->enc_hw_tx_insert_vlan_enabled);
783
784         efx_tx_qdesc_vlantci_create(txq->common, rte_cpu_to_be_16(this_tag),
785                                     *pend);
786         (*pend)++;
787         txq->hw_vlan_tci = this_tag;
788
789         return 1;
790 }
791
792 static uint16_t
793 sfc_efx_prepare_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
794                      uint16_t nb_pkts)
795 {
796         struct sfc_dp_txq *dp_txq = tx_queue;
797         struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
798         const efx_nic_cfg_t *encp = efx_nic_cfg_get(txq->evq->sa->nic);
799         uint16_t i;
800
801         for (i = 0; i < nb_pkts; i++) {
802                 int ret;
803
804                 /*
805                  * EFX Tx datapath may require extra VLAN descriptor if VLAN
806                  * insertion offload is requested regardless the offload
807                  * requested/supported.
808                  */
809                 ret = sfc_dp_tx_prepare_pkt(tx_pkts[i], 0, SFC_TSOH_STD_LEN,
810                                 encp->enc_tx_tso_tcp_header_offset_limit,
811                                 txq->max_fill_level, EFX_TX_FATSOV2_OPT_NDESCS,
812                                 1);
813                 if (unlikely(ret != 0)) {
814                         rte_errno = ret;
815                         break;
816                 }
817         }
818
819         return i;
820 }
821
822 static uint16_t
823 sfc_efx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
824 {
825         struct sfc_dp_txq *dp_txq = (struct sfc_dp_txq *)tx_queue;
826         struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
827         unsigned int added = txq->added;
828         unsigned int pushed = added;
829         unsigned int pkts_sent = 0;
830         efx_desc_t *pend = &txq->pend_desc[0];
831         const unsigned int hard_max_fill = txq->max_fill_level;
832         const unsigned int soft_max_fill = hard_max_fill - txq->free_thresh;
833         unsigned int fill_level = added - txq->completed;
834         boolean_t reap_done;
835         int rc __rte_unused;
836         struct rte_mbuf **pktp;
837
838         if (unlikely((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) == 0))
839                 goto done;
840
841         /*
842          * If insufficient space for a single packet is present,
843          * we should reap; otherwise, we shouldn't do that all the time
844          * to avoid latency increase
845          */
846         reap_done = (fill_level > soft_max_fill);
847
848         if (reap_done) {
849                 sfc_efx_tx_reap(txq);
850                 /*
851                  * Recalculate fill level since 'txq->completed'
852                  * might have changed on reap
853                  */
854                 fill_level = added - txq->completed;
855         }
856
857         for (pkts_sent = 0, pktp = &tx_pkts[0];
858              (pkts_sent < nb_pkts) && (fill_level <= soft_max_fill);
859              pkts_sent++, pktp++) {
860                 uint16_t                hw_vlan_tci_prev = txq->hw_vlan_tci;
861                 struct rte_mbuf         *m_seg = *pktp;
862                 size_t                  pkt_len = m_seg->pkt_len;
863                 unsigned int            pkt_descs = 0;
864                 size_t                  in_off = 0;
865
866                 /*
867                  * Here VLAN TCI is expected to be zero in case if no
868                  * DEV_TX_OFFLOAD_VLAN_INSERT capability is advertised;
869                  * if the calling app ignores the absence of
870                  * DEV_TX_OFFLOAD_VLAN_INSERT and pushes VLAN TCI, then
871                  * TX_ERROR will occur
872                  */
873                 pkt_descs += sfc_efx_tx_maybe_insert_tag(txq, m_seg, &pend);
874
875                 if (m_seg->ol_flags & PKT_TX_TCP_SEG) {
876                         /*
877                          * We expect correct 'pkt->l[2, 3, 4]_len' values
878                          * to be set correctly by the caller
879                          */
880                         if (sfc_efx_tso_do(txq, added, &m_seg, &in_off, &pend,
881                                            &pkt_descs, &pkt_len) != 0) {
882                                 /* We may have reached this place if packet
883                                  * header linearization is needed but the
884                                  * header length is greater than
885                                  * SFC_TSOH_STD_LEN
886                                  *
887                                  * We will deceive RTE saying that we have sent
888                                  * the packet, but we will actually drop it.
889                                  * Hence, we should revert 'pend' to the
890                                  * previous state (in case we have added
891                                  * VLAN descriptor) and start processing
892                                  * another one packet. But the original
893                                  * mbuf shouldn't be orphaned
894                                  */
895                                 pend -= pkt_descs;
896                                 txq->hw_vlan_tci = hw_vlan_tci_prev;
897
898                                 rte_pktmbuf_free(*pktp);
899
900                                 continue;
901                         }
902
903                         /*
904                          * We've only added 2 FATSOv2 option descriptors
905                          * and 1 descriptor for the linearized packet header.
906                          * The outstanding work will be done in the same manner
907                          * as for the usual non-TSO path
908                          */
909                 }
910
911                 for (; m_seg != NULL; m_seg = m_seg->next) {
912                         efsys_dma_addr_t        next_frag;
913                         size_t                  seg_len;
914
915                         seg_len = m_seg->data_len;
916                         next_frag = rte_mbuf_data_iova(m_seg);
917
918                         /*
919                          * If we've started TSO transaction few steps earlier,
920                          * we'll skip packet header using an offset in the
921                          * current segment (which has been set to the
922                          * first one containing payload)
923                          */
924                         seg_len -= in_off;
925                         next_frag += in_off;
926                         in_off = 0;
927
928                         do {
929                                 efsys_dma_addr_t        frag_addr = next_frag;
930                                 size_t                  frag_len;
931
932                                 /*
933                                  * It is assumed here that there is no
934                                  * limitation on address boundary
935                                  * crossing by DMA descriptor.
936                                  */
937                                 frag_len = MIN(seg_len, txq->dma_desc_size_max);
938                                 next_frag += frag_len;
939                                 seg_len -= frag_len;
940                                 pkt_len -= frag_len;
941
942                                 efx_tx_qdesc_dma_create(txq->common,
943                                                         frag_addr, frag_len,
944                                                         (pkt_len == 0),
945                                                         pend++);
946
947                                 pkt_descs++;
948                         } while (seg_len != 0);
949                 }
950
951                 added += pkt_descs;
952
953                 fill_level += pkt_descs;
954                 if (unlikely(fill_level > hard_max_fill)) {
955                         /*
956                          * Our estimation for maximum number of descriptors
957                          * required to send a packet seems to be wrong.
958                          * Try to reap (if we haven't yet).
959                          */
960                         if (!reap_done) {
961                                 sfc_efx_tx_reap(txq);
962                                 reap_done = B_TRUE;
963                                 fill_level = added - txq->completed;
964                                 if (fill_level > hard_max_fill) {
965                                         pend -= pkt_descs;
966                                         txq->hw_vlan_tci = hw_vlan_tci_prev;
967                                         break;
968                                 }
969                         } else {
970                                 pend -= pkt_descs;
971                                 txq->hw_vlan_tci = hw_vlan_tci_prev;
972                                 break;
973                         }
974                 }
975
976                 /* Assign mbuf to the last used desc */
977                 txq->sw_ring[(added - 1) & txq->ptr_mask].mbuf = *pktp;
978         }
979
980         if (likely(pkts_sent > 0)) {
981                 rc = efx_tx_qdesc_post(txq->common, txq->pend_desc,
982                                        pend - &txq->pend_desc[0],
983                                        txq->completed, &txq->added);
984                 SFC_ASSERT(rc == 0);
985
986                 if (likely(pushed != txq->added)) {
987                         efx_tx_qpush(txq->common, txq->added, pushed);
988                         txq->dp.dpq.tx_dbells++;
989                 }
990         }
991
992 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
993         if (!reap_done)
994                 sfc_efx_tx_reap(txq);
995 #endif
996
997 done:
998         return pkts_sent;
999 }
1000
1001 const struct sfc_dp_tx *
1002 sfc_dp_tx_by_dp_txq(const struct sfc_dp_txq *dp_txq)
1003 {
1004         const struct sfc_dp_queue *dpq = &dp_txq->dpq;
1005         struct rte_eth_dev *eth_dev;
1006         struct sfc_adapter_priv *sap;
1007
1008         SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
1009         eth_dev = &rte_eth_devices[dpq->port_id];
1010
1011         sap = sfc_adapter_priv_by_eth_dev(eth_dev);
1012
1013         return sap->dp_tx;
1014 }
1015
1016 struct sfc_txq_info *
1017 sfc_txq_info_by_dp_txq(const struct sfc_dp_txq *dp_txq)
1018 {
1019         const struct sfc_dp_queue *dpq = &dp_txq->dpq;
1020         struct rte_eth_dev *eth_dev;
1021         struct sfc_adapter_shared *sas;
1022
1023         SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
1024         eth_dev = &rte_eth_devices[dpq->port_id];
1025
1026         sas = sfc_adapter_shared_by_eth_dev(eth_dev);
1027
1028         SFC_ASSERT(dpq->queue_id < sas->txq_count);
1029         return &sas->txq_info[dpq->queue_id];
1030 }
1031
1032 struct sfc_txq *
1033 sfc_txq_by_dp_txq(const struct sfc_dp_txq *dp_txq)
1034 {
1035         const struct sfc_dp_queue *dpq = &dp_txq->dpq;
1036         struct rte_eth_dev *eth_dev;
1037         struct sfc_adapter *sa;
1038
1039         SFC_ASSERT(rte_eth_dev_is_valid_port(dpq->port_id));
1040         eth_dev = &rte_eth_devices[dpq->port_id];
1041
1042         sa = sfc_adapter_by_eth_dev(eth_dev);
1043
1044         SFC_ASSERT(dpq->queue_id < sfc_sa2shared(sa)->txq_count);
1045         return &sa->txq_ctrl[dpq->queue_id];
1046 }
1047
1048 static sfc_dp_tx_qsize_up_rings_t sfc_efx_tx_qsize_up_rings;
1049 static int
1050 sfc_efx_tx_qsize_up_rings(uint16_t nb_tx_desc,
1051                           __rte_unused struct sfc_dp_tx_hw_limits *limits,
1052                           unsigned int *txq_entries,
1053                           unsigned int *evq_entries,
1054                           unsigned int *txq_max_fill_level)
1055 {
1056         *txq_entries = nb_tx_desc;
1057         *evq_entries = nb_tx_desc;
1058         *txq_max_fill_level = EFX_TXQ_LIMIT(*txq_entries);
1059         return 0;
1060 }
1061
1062 static sfc_dp_tx_qcreate_t sfc_efx_tx_qcreate;
1063 static int
1064 sfc_efx_tx_qcreate(uint16_t port_id, uint16_t queue_id,
1065                    const struct rte_pci_addr *pci_addr,
1066                    int socket_id,
1067                    const struct sfc_dp_tx_qcreate_info *info,
1068                    struct sfc_dp_txq **dp_txqp)
1069 {
1070         struct sfc_efx_txq *txq;
1071         struct sfc_txq *ctrl_txq;
1072         int rc;
1073
1074         rc = ENOMEM;
1075         txq = rte_zmalloc_socket("sfc-efx-txq", sizeof(*txq),
1076                                  RTE_CACHE_LINE_SIZE, socket_id);
1077         if (txq == NULL)
1078                 goto fail_txq_alloc;
1079
1080         sfc_dp_queue_init(&txq->dp.dpq, port_id, queue_id, pci_addr);
1081
1082         rc = ENOMEM;
1083         txq->pend_desc = rte_calloc_socket("sfc-efx-txq-pend-desc",
1084                                            EFX_TXQ_LIMIT(info->txq_entries),
1085                                            sizeof(*txq->pend_desc), 0,
1086                                            socket_id);
1087         if (txq->pend_desc == NULL)
1088                 goto fail_pend_desc_alloc;
1089
1090         rc = ENOMEM;
1091         txq->sw_ring = rte_calloc_socket("sfc-efx-txq-sw_ring",
1092                                          info->txq_entries,
1093                                          sizeof(*txq->sw_ring),
1094                                          RTE_CACHE_LINE_SIZE, socket_id);
1095         if (txq->sw_ring == NULL)
1096                 goto fail_sw_ring_alloc;
1097
1098         ctrl_txq = sfc_txq_by_dp_txq(&txq->dp);
1099         if (ctrl_txq->evq->sa->tso) {
1100                 rc = sfc_efx_tso_alloc_tsoh_objs(txq->sw_ring,
1101                                                  info->txq_entries, socket_id);
1102                 if (rc != 0)
1103                         goto fail_alloc_tsoh_objs;
1104         }
1105
1106         txq->evq = ctrl_txq->evq;
1107         txq->ptr_mask = info->txq_entries - 1;
1108         txq->max_fill_level = info->max_fill_level;
1109         txq->free_thresh = info->free_thresh;
1110         txq->dma_desc_size_max = info->dma_desc_size_max;
1111
1112         *dp_txqp = &txq->dp;
1113         return 0;
1114
1115 fail_alloc_tsoh_objs:
1116         rte_free(txq->sw_ring);
1117
1118 fail_sw_ring_alloc:
1119         rte_free(txq->pend_desc);
1120
1121 fail_pend_desc_alloc:
1122         rte_free(txq);
1123
1124 fail_txq_alloc:
1125         return rc;
1126 }
1127
1128 static sfc_dp_tx_qdestroy_t sfc_efx_tx_qdestroy;
1129 static void
1130 sfc_efx_tx_qdestroy(struct sfc_dp_txq *dp_txq)
1131 {
1132         struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1133
1134         sfc_efx_tso_free_tsoh_objs(txq->sw_ring, txq->ptr_mask + 1);
1135         rte_free(txq->sw_ring);
1136         rte_free(txq->pend_desc);
1137         rte_free(txq);
1138 }
1139
1140 static sfc_dp_tx_qstart_t sfc_efx_tx_qstart;
1141 static int
1142 sfc_efx_tx_qstart(struct sfc_dp_txq *dp_txq,
1143                   __rte_unused unsigned int evq_read_ptr,
1144                   unsigned int txq_desc_index)
1145 {
1146         /* libefx-based datapath is specific to libefx-based PMD */
1147         struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1148         struct sfc_txq *ctrl_txq = sfc_txq_by_dp_txq(dp_txq);
1149
1150         txq->common = ctrl_txq->common;
1151
1152         txq->pending = txq->completed = txq->added = txq_desc_index;
1153         txq->hw_vlan_tci = 0;
1154
1155         txq->flags |= (SFC_EFX_TXQ_FLAG_STARTED | SFC_EFX_TXQ_FLAG_RUNNING);
1156
1157         return 0;
1158 }
1159
1160 static sfc_dp_tx_qstop_t sfc_efx_tx_qstop;
1161 static void
1162 sfc_efx_tx_qstop(struct sfc_dp_txq *dp_txq,
1163                  __rte_unused unsigned int *evq_read_ptr)
1164 {
1165         struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1166
1167         txq->flags &= ~SFC_EFX_TXQ_FLAG_RUNNING;
1168 }
1169
1170 static sfc_dp_tx_qreap_t sfc_efx_tx_qreap;
1171 static void
1172 sfc_efx_tx_qreap(struct sfc_dp_txq *dp_txq)
1173 {
1174         struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1175         unsigned int txds;
1176
1177         sfc_efx_tx_reap(txq);
1178
1179         for (txds = 0; txds <= txq->ptr_mask; txds++) {
1180                 if (txq->sw_ring[txds].mbuf != NULL) {
1181                         rte_pktmbuf_free(txq->sw_ring[txds].mbuf);
1182                         txq->sw_ring[txds].mbuf = NULL;
1183                 }
1184         }
1185
1186         txq->flags &= ~SFC_EFX_TXQ_FLAG_STARTED;
1187 }
1188
1189 static sfc_dp_tx_qdesc_status_t sfc_efx_tx_qdesc_status;
1190 static int
1191 sfc_efx_tx_qdesc_status(struct sfc_dp_txq *dp_txq, uint16_t offset)
1192 {
1193         struct sfc_efx_txq *txq = sfc_efx_txq_by_dp_txq(dp_txq);
1194
1195         if (unlikely(offset > txq->ptr_mask))
1196                 return -EINVAL;
1197
1198         if (unlikely(offset >= txq->max_fill_level))
1199                 return RTE_ETH_TX_DESC_UNAVAIL;
1200
1201         /*
1202          * Poll EvQ to derive up-to-date 'txq->pending' figure;
1203          * it is required for the queue to be running, but the
1204          * check is omitted because API design assumes that it
1205          * is the duty of the caller to satisfy all conditions
1206          */
1207         SFC_ASSERT((txq->flags & SFC_EFX_TXQ_FLAG_RUNNING) ==
1208                    SFC_EFX_TXQ_FLAG_RUNNING);
1209         sfc_ev_qpoll(txq->evq);
1210
1211         /*
1212          * Ring tail is 'txq->pending', and although descriptors
1213          * between 'txq->completed' and 'txq->pending' are still
1214          * in use by the driver, they should be reported as DONE
1215          */
1216         if (unlikely(offset < (txq->added - txq->pending)))
1217                 return RTE_ETH_TX_DESC_FULL;
1218
1219         /*
1220          * There is no separate return value for unused descriptors;
1221          * the latter will be reported as DONE because genuine DONE
1222          * descriptors will be freed anyway in SW on the next burst
1223          */
1224         return RTE_ETH_TX_DESC_DONE;
1225 }
1226
1227 struct sfc_dp_tx sfc_efx_tx = {
1228         .dp = {
1229                 .name           = SFC_KVARG_DATAPATH_EFX,
1230                 .type           = SFC_DP_TX,
1231                 .hw_fw_caps     = SFC_DP_HW_FW_CAP_TX_EFX,
1232         },
1233         .features               = 0,
1234         .dev_offload_capa       = DEV_TX_OFFLOAD_VLAN_INSERT |
1235                                   DEV_TX_OFFLOAD_MULTI_SEGS,
1236         .queue_offload_capa     = DEV_TX_OFFLOAD_IPV4_CKSUM |
1237                                   DEV_TX_OFFLOAD_UDP_CKSUM |
1238                                   DEV_TX_OFFLOAD_TCP_CKSUM |
1239                                   DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
1240                                   DEV_TX_OFFLOAD_TCP_TSO,
1241         .qsize_up_rings         = sfc_efx_tx_qsize_up_rings,
1242         .qcreate                = sfc_efx_tx_qcreate,
1243         .qdestroy               = sfc_efx_tx_qdestroy,
1244         .qstart                 = sfc_efx_tx_qstart,
1245         .qstop                  = sfc_efx_tx_qstop,
1246         .qreap                  = sfc_efx_tx_qreap,
1247         .qdesc_status           = sfc_efx_tx_qdesc_status,
1248         .pkt_prepare            = sfc_efx_prepare_pkts,
1249         .pkt_burst              = sfc_efx_xmit_pkts,
1250 };