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