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 <stdbool.h>
11 : :
12 : : #include <rte_mbuf.h>
13 : : #include <rte_io.h>
14 : : #include <rte_ip.h>
15 : : #include <rte_tcp.h>
16 : :
17 : : #include "efx.h"
18 : : #include "efx_types.h"
19 : : #include "efx_regs.h"
20 : : #include "efx_regs_ef10.h"
21 : :
22 : : #include "sfc_debug.h"
23 : : #include "sfc_dp_tx.h"
24 : : #include "sfc_tweak.h"
25 : : #include "sfc_kvargs.h"
26 : : #include "sfc_ef10.h"
27 : : #include "sfc_tso.h"
28 : :
29 : : #define sfc_ef10_tx_err(dpq, ...) \
30 : : SFC_DP_LOG(SFC_KVARG_DATAPATH_EF10, ERR, dpq, __VA_ARGS__)
31 : :
32 : : #define sfc_ef10_tx_info(dpq, ...) \
33 : : SFC_DP_LOG(SFC_KVARG_DATAPATH_EF10, INFO, dpq, __VA_ARGS__)
34 : :
35 : : /** Maximum length of the DMA descriptor data */
36 : : #define SFC_EF10_TX_DMA_DESC_LEN_MAX \
37 : : ((1u << ESF_DZ_TX_KER_BYTE_CNT_WIDTH) - 1)
38 : :
39 : : /**
40 : : * Maximum number of descriptors/buffers in the Tx ring.
41 : : * It should guarantee that corresponding event queue never overfill.
42 : : * EF10 native datapath uses event queue of the same size as Tx queue.
43 : : * Maximum number of events on datapath can be estimated as number of
44 : : * Tx queue entries (one event per Tx buffer in the worst case) plus
45 : : * Tx error and flush events.
46 : : */
47 : : #define SFC_EF10_TXQ_LIMIT(_ndesc) \
48 : : ((_ndesc) - 1 /* head must not step on tail */ - \
49 : : (SFC_EF10_EV_PER_CACHE_LINE - 1) /* max unused EvQ entries */ - \
50 : : 1 /* Rx error */ - 1 /* flush */)
51 : :
52 : : struct sfc_ef10_tx_sw_desc {
53 : : struct rte_mbuf *mbuf;
54 : : };
55 : :
56 : : struct sfc_ef10_txq {
57 : : unsigned int flags;
58 : : #define SFC_EF10_TXQ_STARTED 0x1
59 : : #define SFC_EF10_TXQ_NOT_RUNNING 0x2
60 : : #define SFC_EF10_TXQ_EXCEPTION 0x4
61 : :
62 : : unsigned int ptr_mask;
63 : : unsigned int added;
64 : : unsigned int completed;
65 : : unsigned int max_fill_level;
66 : : unsigned int free_thresh;
67 : : unsigned int evq_read_ptr;
68 : : unsigned int max_pdu;
69 : : struct sfc_ef10_tx_sw_desc *sw_ring;
70 : : efx_qword_t *txq_hw_ring;
71 : : volatile void *doorbell;
72 : : efx_qword_t *evq_hw_ring;
73 : : uint8_t *tsoh;
74 : : rte_iova_t tsoh_iova;
75 : : uint16_t tso_tcp_header_offset_limit;
76 : :
77 : : /* Datapath transmit queue anchor */
78 : : struct sfc_dp_txq dp;
79 : : };
80 : :
81 : : static inline struct sfc_ef10_txq *
82 : : sfc_ef10_txq_by_dp_txq(struct sfc_dp_txq *dp_txq)
83 : : {
84 : 0 : return container_of(dp_txq, struct sfc_ef10_txq, dp);
85 : : }
86 : :
87 : : static bool
88 : 0 : sfc_ef10_tx_get_event(struct sfc_ef10_txq *txq, efx_qword_t *tx_ev)
89 : : {
90 : 0 : volatile efx_qword_t *evq_hw_ring = txq->evq_hw_ring;
91 : :
92 : : /*
93 : : * Exception flag is set when reap is done.
94 : : * It is never done twice per packet burst get and absence of
95 : : * the flag is checked on burst get entry.
96 : : */
97 : : SFC_ASSERT((txq->flags & SFC_EF10_TXQ_EXCEPTION) == 0);
98 : :
99 [ # # ]: 0 : *tx_ev = evq_hw_ring[txq->evq_read_ptr & txq->ptr_mask];
100 : :
101 [ # # ]: 0 : if (!sfc_ef10_ev_present(*tx_ev))
102 : : return false;
103 : :
104 [ # # ]: 0 : if (unlikely(EFX_QWORD_FIELD(*tx_ev, FSF_AZ_EV_CODE) !=
105 : : FSE_AZ_EV_CODE_TX_EV)) {
106 : : /*
107 : : * Do not move read_ptr to keep the event for exception
108 : : * handling by the control path.
109 : : */
110 : 0 : txq->flags |= SFC_EF10_TXQ_EXCEPTION;
111 : 0 : sfc_ef10_tx_err(&txq->dp.dpq,
112 : : "TxQ exception at EvQ read ptr %#x",
113 : : txq->evq_read_ptr);
114 : 0 : return false;
115 : : }
116 : :
117 : 0 : txq->evq_read_ptr++;
118 : 0 : return true;
119 : : }
120 : :
121 : : static unsigned int
122 : 0 : sfc_ef10_tx_process_events(struct sfc_ef10_txq *txq)
123 : : {
124 : 0 : const unsigned int curr_done = txq->completed - 1;
125 : : unsigned int anew_done = curr_done;
126 : : efx_qword_t tx_ev;
127 : :
128 [ # # ]: 0 : while (sfc_ef10_tx_get_event(txq, &tx_ev)) {
129 : : /*
130 : : * DROP_EVENT is an internal to the NIC, software should
131 : : * never see it and, therefore, may ignore it.
132 : : */
133 : :
134 : : /* Update the latest done descriptor */
135 : 0 : anew_done = EFX_QWORD_FIELD(tx_ev, ESF_DZ_TX_DESCR_INDX);
136 : : }
137 : 0 : return (anew_done - curr_done) & txq->ptr_mask;
138 : : }
139 : :
140 : : static void
141 : 0 : sfc_ef10_tx_reap(struct sfc_ef10_txq *txq)
142 : : {
143 : 0 : const unsigned int old_read_ptr = txq->evq_read_ptr;
144 : 0 : const unsigned int ptr_mask = txq->ptr_mask;
145 : 0 : unsigned int completed = txq->completed;
146 : : unsigned int pending = completed;
147 : :
148 : 0 : pending += sfc_ef10_tx_process_events(txq);
149 : :
150 [ # # ]: 0 : if (pending != completed) {
151 : : struct rte_mbuf *bulk[SFC_TX_REAP_BULK_SIZE];
152 : : unsigned int nb = 0;
153 : :
154 : : do {
155 : : struct sfc_ef10_tx_sw_desc *txd;
156 : : struct rte_mbuf *m;
157 : :
158 : 0 : txd = &txq->sw_ring[completed & ptr_mask];
159 [ # # ]: 0 : if (txd->mbuf == NULL)
160 : 0 : continue;
161 : :
162 : : m = rte_pktmbuf_prefree_seg(txd->mbuf);
163 : 0 : txd->mbuf = NULL;
164 : 0 : if (m == NULL)
165 : 0 : continue;
166 : :
167 [ # # # # ]: 0 : if ((nb == RTE_DIM(bulk)) ||
168 [ # # ]: 0 : ((nb != 0) && (m->pool != bulk[0]->pool))) {
169 [ # # ]: 0 : rte_mempool_put_bulk(bulk[0]->pool,
170 : : (void *)bulk, nb);
171 : : nb = 0;
172 : : }
173 : :
174 : 0 : bulk[nb++] = m;
175 [ # # ]: 0 : } while (++completed != pending);
176 : :
177 [ # # ]: 0 : if (nb != 0)
178 [ # # ]: 0 : rte_mempool_put_bulk(bulk[0]->pool, (void *)bulk, nb);
179 : :
180 : 0 : txq->completed = completed;
181 : : }
182 : :
183 : 0 : sfc_ef10_ev_qclear(txq->evq_hw_ring, ptr_mask, old_read_ptr,
184 : : txq->evq_read_ptr);
185 : 0 : }
186 : :
187 : : static void
188 : : sfc_ef10_tx_qdesc_dma_create(rte_iova_t addr, uint16_t size, bool eop,
189 : : efx_qword_t *edp)
190 : : {
191 : 0 : EFX_POPULATE_QWORD_4(*edp,
192 : : ESF_DZ_TX_KER_TYPE, 0,
193 : : ESF_DZ_TX_KER_CONT, !eop,
194 : : ESF_DZ_TX_KER_BYTE_CNT, size,
195 : : ESF_DZ_TX_KER_BUF_ADDR, addr);
196 : : }
197 : :
198 : : static void
199 : : sfc_ef10_tx_qdesc_tso2_create(struct sfc_ef10_txq * const txq,
200 : : unsigned int added, uint16_t ipv4_id,
201 : : uint16_t outer_ipv4_id, uint32_t tcp_seq,
202 : : uint16_t tcp_mss)
203 : : {
204 : 0 : EFX_POPULATE_QWORD_5(txq->txq_hw_ring[added & txq->ptr_mask],
205 : : ESF_DZ_TX_DESC_IS_OPT, 1,
206 : : ESF_DZ_TX_OPTION_TYPE,
207 : : ESE_DZ_TX_OPTION_DESC_TSO,
208 : : ESF_DZ_TX_TSO_OPTION_TYPE,
209 : : ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
210 : : ESF_DZ_TX_TSO_IP_ID, ipv4_id,
211 : : ESF_DZ_TX_TSO_TCP_SEQNO, tcp_seq);
212 : 0 : EFX_POPULATE_QWORD_5(txq->txq_hw_ring[(added + 1) & txq->ptr_mask],
213 : : ESF_DZ_TX_DESC_IS_OPT, 1,
214 : : ESF_DZ_TX_OPTION_TYPE,
215 : : ESE_DZ_TX_OPTION_DESC_TSO,
216 : : ESF_DZ_TX_TSO_OPTION_TYPE,
217 : : ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
218 : : ESF_DZ_TX_TSO_TCP_MSS, tcp_mss,
219 : : ESF_DZ_TX_TSO_OUTER_IPID, outer_ipv4_id);
220 : : }
221 : :
222 : : static inline void
223 : : sfc_ef10_tx_qpush(struct sfc_ef10_txq *txq, unsigned int added,
224 : : unsigned int pushed)
225 : : {
226 : : efx_qword_t desc;
227 : : efx_oword_t oword;
228 : :
229 : : /*
230 : : * This improves performance by pushing a TX descriptor at the same
231 : : * time as the doorbell. The descriptor must be added to the TXQ,
232 : : * so that can be used if the hardware decides not to use the pushed
233 : : * descriptor.
234 : : */
235 : 0 : desc.eq_u64[0] = txq->txq_hw_ring[pushed & txq->ptr_mask].eq_u64[0];
236 : 0 : EFX_POPULATE_OWORD_3(oword,
237 : : ERF_DZ_TX_DESC_WPTR, added & txq->ptr_mask,
238 : : ERF_DZ_TX_DESC_HWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_1),
239 : : ERF_DZ_TX_DESC_LWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_0));
240 : :
241 : : /* DMA sync to device is not required */
242 : :
243 : : /*
244 : : * rte_io_wmb() which guarantees that the STORE operations
245 : : * (i.e. Tx and event descriptor updates) that precede
246 : : * the rte_io_wmb() call are visible to NIC before the STORE
247 : : * operations that follow it (i.e. doorbell write).
248 : : */
249 : 0 : rte_io_wmb();
250 : :
251 : 0 : *(volatile efsys_uint128_t *)txq->doorbell = oword.eo_u128[0];
252 : 0 : txq->dp.dpq.dbells++;
253 : : }
254 : :
255 : : static unsigned int
256 : : sfc_ef10_tx_pkt_descs_max(const struct rte_mbuf *m, unsigned int max_pdu)
257 : : {
258 : : unsigned int extra_descs_per_seg;
259 : : unsigned int extra_descs_per_pkt;
260 : :
261 : : /*
262 : : * VLAN offload is not supported yet, so no extra descriptors
263 : : * are required for VLAN option descriptor.
264 : : */
265 : :
266 : : /** Maximum length of the mbuf segment data */
267 : : #define SFC_MBUF_SEG_LEN_MAX UINT16_MAX
268 : : RTE_BUILD_BUG_ON(sizeof(m->data_len) != 2);
269 : :
270 : : /*
271 : : * Each segment is already counted once below. So, calculate
272 : : * how many extra DMA descriptors may be required per segment in
273 : : * the worst case because of maximum DMA descriptor length limit.
274 : : * If maximum segment length is less or equal to maximum DMA
275 : : * descriptor length, no extra DMA descriptors are required.
276 : : */
277 : : extra_descs_per_seg =
278 : : (SFC_MBUF_SEG_LEN_MAX - 1) / SFC_EF10_TX_DMA_DESC_LEN_MAX;
279 : :
280 : : /** Maximum length of the packet */
281 : : #define SFC_MBUF_PKT_LEN_MAX UINT32_MAX
282 : : RTE_BUILD_BUG_ON(sizeof(m->pkt_len) != 4);
283 : :
284 : : /*
285 : : * One more limitation on maximum number of extra DMA descriptors
286 : : * comes from slicing entire packet because of DMA descriptor length
287 : : * limit taking into account that there is at least one segment
288 : : * which is already counted below (so division of the maximum
289 : : * packet length minus one with round down).
290 : : * TSO is not supported yet, so packet length is limited by
291 : : * maximum PDU size.
292 : : */
293 : 0 : extra_descs_per_pkt =
294 : 0 : (RTE_MIN(max_pdu, SFC_MBUF_PKT_LEN_MAX) - 1) /
295 : : SFC_EF10_TX_DMA_DESC_LEN_MAX;
296 : :
297 : 0 : return m->nb_segs + RTE_MIN(m->nb_segs * extra_descs_per_seg,
298 : : extra_descs_per_pkt);
299 : : }
300 : :
301 : : static bool
302 : 0 : sfc_ef10_try_reap(struct sfc_ef10_txq * const txq, unsigned int added,
303 : : unsigned int needed_desc, unsigned int *dma_desc_space,
304 : : bool *reap_done)
305 : : {
306 [ # # ]: 0 : if (*reap_done)
307 : : return false;
308 : :
309 [ # # ]: 0 : if (added != txq->added) {
310 : : sfc_ef10_tx_qpush(txq, added, txq->added);
311 : 0 : txq->added = added;
312 : : }
313 : :
314 : 0 : sfc_ef10_tx_reap(txq);
315 : 0 : *reap_done = true;
316 : :
317 : : /*
318 : : * Recalculate DMA descriptor space since Tx reap may change
319 : : * the number of completed descriptors
320 : : */
321 : 0 : *dma_desc_space = txq->max_fill_level -
322 : 0 : (added - txq->completed);
323 : :
324 : 0 : return (needed_desc <= *dma_desc_space);
325 : : }
326 : :
327 : : static uint16_t
328 : 0 : sfc_ef10_prepare_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
329 : : uint16_t nb_pkts)
330 : : {
331 : : struct sfc_ef10_txq * const txq = sfc_ef10_txq_by_dp_txq(tx_queue);
332 : : uint16_t i;
333 : :
334 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
335 : 0 : struct rte_mbuf *m = tx_pkts[i];
336 : : int ret;
337 : :
338 : : #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
339 : : /*
340 : : * In non-TSO case, check that a packet segments do not exceed
341 : : * the size limit. Perform the check in debug mode since MTU
342 : : * more than 9k is not supported, but the limit here is 16k-1.
343 : : */
344 : : if (!(m->ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
345 : : struct rte_mbuf *m_seg;
346 : :
347 : : for (m_seg = m; m_seg != NULL; m_seg = m_seg->next) {
348 : : if (m_seg->data_len >
349 : : SFC_EF10_TX_DMA_DESC_LEN_MAX) {
350 : : rte_errno = EINVAL;
351 : : break;
352 : : }
353 : : }
354 : : }
355 : : #endif
356 : 0 : ret = sfc_dp_tx_prepare_pkt(m, 0, SFC_TSOH_STD_LEN,
357 : 0 : txq->tso_tcp_header_offset_limit,
358 : : txq->max_fill_level,
359 : : SFC_EF10_TSO_OPT_DESCS_NUM, 0);
360 [ # # ]: 0 : if (unlikely(ret != 0)) {
361 : 0 : rte_errno = ret;
362 : 0 : break;
363 : : }
364 : : }
365 : :
366 : 0 : return i;
367 : : }
368 : :
369 : : static int
370 : 0 : sfc_ef10_xmit_tso_pkt(struct sfc_ef10_txq * const txq, struct rte_mbuf *m_seg,
371 : : unsigned int *added, unsigned int *dma_desc_space,
372 : : bool *reap_done)
373 : : {
374 : 0 : size_t iph_off = ((m_seg->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
375 [ # # ]: 0 : m_seg->outer_l2_len + m_seg->outer_l3_len : 0) +
376 : 0 : m_seg->l2_len;
377 : 0 : size_t tcph_off = iph_off + m_seg->l3_len;
378 : 0 : size_t header_len = tcph_off + m_seg->l4_len;
379 : : /* Offset of the payload in the last segment that contains the header */
380 : 0 : size_t in_off = 0;
381 : : const struct rte_tcp_hdr *th;
382 : : uint16_t packet_id = 0;
383 : : uint16_t outer_packet_id = 0;
384 : : uint32_t sent_seq;
385 : : uint8_t *hdr_addr;
386 : : rte_iova_t hdr_iova;
387 : : struct rte_mbuf *first_m_seg = m_seg;
388 : 0 : unsigned int pkt_start = *added;
389 : : unsigned int needed_desc;
390 : : struct rte_mbuf *m_seg_to_free_up_to = first_m_seg;
391 : : bool eop;
392 : :
393 : : /*
394 : : * Preliminary estimation of required DMA descriptors, including extra
395 : : * descriptor for TSO header that is needed when the header is
396 : : * separated from payload in one segment. It does not include
397 : : * extra descriptors that may appear when a big segment is split across
398 : : * several descriptors.
399 : : */
400 : 0 : needed_desc = m_seg->nb_segs +
401 : : (unsigned int)SFC_EF10_TSO_OPT_DESCS_NUM +
402 : : (unsigned int)SFC_EF10_TSO_HDR_DESCS_NUM;
403 : :
404 [ # # # # ]: 0 : if (needed_desc > *dma_desc_space &&
405 : 0 : !sfc_ef10_try_reap(txq, pkt_start, needed_desc,
406 : : dma_desc_space, reap_done)) {
407 : : /*
408 : : * If a future Tx reap may increase available DMA descriptor
409 : : * space, do not try to send the packet.
410 : : */
411 [ # # ]: 0 : if (txq->completed != pkt_start)
412 : : return ENOSPC;
413 : : /*
414 : : * Do not allow to send packet if the maximum DMA
415 : : * descriptor space is not sufficient to hold TSO
416 : : * descriptors, header descriptor and at least 1
417 : : * segment descriptor.
418 : : */
419 [ # # ]: 0 : if (*dma_desc_space < SFC_EF10_TSO_OPT_DESCS_NUM +
420 : : SFC_EF10_TSO_HDR_DESCS_NUM + 1)
421 : : return EMSGSIZE;
422 : : }
423 : :
424 : : /* Check if the header is not fragmented */
425 [ # # ]: 0 : if (rte_pktmbuf_data_len(m_seg) >= header_len) {
426 [ # # ]: 0 : hdr_addr = rte_pktmbuf_mtod(m_seg, uint8_t *);
427 : : hdr_iova = rte_mbuf_data_iova(m_seg);
428 [ # # ]: 0 : if (rte_pktmbuf_data_len(m_seg) == header_len) {
429 : : /* Cannot send a packet that consists only of header */
430 [ # # ]: 0 : if (unlikely(m_seg->next == NULL))
431 : : return EMSGSIZE;
432 : : /*
433 : : * Associate header mbuf with header descriptor
434 : : * which is located after TSO descriptors.
435 : : */
436 : 0 : txq->sw_ring[(pkt_start + SFC_EF10_TSO_OPT_DESCS_NUM) &
437 : 0 : txq->ptr_mask].mbuf = m_seg;
438 : 0 : m_seg = m_seg->next;
439 : 0 : in_off = 0;
440 : :
441 : : /*
442 : : * If there is no payload offset (payload starts at the
443 : : * beginning of a segment) then an extra descriptor for
444 : : * separated header is not needed.
445 : : */
446 : 0 : needed_desc--;
447 : : } else {
448 : 0 : in_off = header_len;
449 : : }
450 : : } else {
451 : : unsigned int copied_segs;
452 : 0 : unsigned int hdr_addr_off = (*added & txq->ptr_mask) *
453 : : SFC_TSOH_STD_LEN;
454 : :
455 : : /*
456 : : * Discard a packet if header linearization is needed but
457 : : * the header is too big.
458 : : * Duplicate Tx prepare check here to avoid spoil of
459 : : * memory if Tx prepare is skipped.
460 : : */
461 [ # # ]: 0 : if (unlikely(header_len > SFC_TSOH_STD_LEN))
462 : : return EMSGSIZE;
463 : :
464 : 0 : hdr_addr = txq->tsoh + hdr_addr_off;
465 : 0 : hdr_iova = txq->tsoh_iova + hdr_addr_off;
466 : 0 : copied_segs = sfc_tso_prepare_header(hdr_addr, header_len,
467 : : &m_seg, &in_off);
468 : :
469 : : /* Cannot send a packet that consists only of header */
470 [ # # ]: 0 : if (unlikely(m_seg == NULL))
471 : : return EMSGSIZE;
472 : :
473 : : m_seg_to_free_up_to = m_seg;
474 : : /*
475 : : * Reduce the number of needed descriptors by the number of
476 : : * segments that entirely consist of header data.
477 : : */
478 : 0 : needed_desc -= copied_segs;
479 : :
480 : : /* Extra descriptor for separated header is not needed */
481 [ # # ]: 0 : if (in_off == 0)
482 : 0 : needed_desc--;
483 : : }
484 : :
485 : : /*
486 : : * 8000-series EF10 hardware requires that innermost IP length
487 : : * be greater than or equal to the value which each segment is
488 : : * supposed to have; otherwise, TCP checksum will be incorrect.
489 : : *
490 : : * The same concern applies to outer UDP datagram length field.
491 : : */
492 [ # # ]: 0 : switch (m_seg->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
493 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
494 : : /* FALLTHROUGH */
495 : : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
496 : 0 : sfc_tso_outer_udp_fix_len(first_m_seg, hdr_addr);
497 : 0 : break;
498 : : default:
499 : : break;
500 : : }
501 : :
502 : 0 : sfc_tso_innermost_ip_fix_len(first_m_seg, hdr_addr, iph_off);
503 : :
504 : : /*
505 : : * Tx prepare has debug-only checks that offload flags are correctly
506 : : * filled in TSO mbuf. Use zero IPID if there is no IPv4 flag.
507 : : * If the packet is still IPv4, HW will simply start from zero IPID.
508 : : */
509 [ # # ]: 0 : if (first_m_seg->ol_flags & RTE_MBUF_F_TX_IPV4)
510 : : packet_id = sfc_tso_ip4_get_ipid(hdr_addr, iph_off);
511 : :
512 [ # # ]: 0 : if (first_m_seg->ol_flags & RTE_MBUF_F_TX_OUTER_IPV4)
513 : 0 : outer_packet_id = sfc_tso_ip4_get_ipid(hdr_addr,
514 [ # # ]: 0 : first_m_seg->outer_l2_len);
515 : :
516 : 0 : th = (const struct rte_tcp_hdr *)(hdr_addr + tcph_off);
517 [ # # ]: 0 : rte_memcpy(&sent_seq, &th->sent_seq, sizeof(uint32_t));
518 [ # # ]: 0 : sent_seq = rte_be_to_cpu_32(sent_seq);
519 : :
520 : 0 : sfc_ef10_tx_qdesc_tso2_create(txq, *added, packet_id, outer_packet_id,
521 : 0 : sent_seq, first_m_seg->tso_segsz);
522 : 0 : (*added) += SFC_EF10_TSO_OPT_DESCS_NUM;
523 : :
524 : 0 : sfc_ef10_tx_qdesc_dma_create(hdr_iova, header_len, false,
525 : 0 : &txq->txq_hw_ring[(*added) & txq->ptr_mask]);
526 : 0 : (*added)++;
527 : :
528 : : do {
529 : 0 : rte_iova_t next_frag = rte_mbuf_data_iova(m_seg);
530 : 0 : unsigned int seg_len = rte_pktmbuf_data_len(m_seg);
531 : : unsigned int id;
532 : :
533 : 0 : next_frag += in_off;
534 : 0 : seg_len -= in_off;
535 : 0 : in_off = 0;
536 : :
537 : : do {
538 : : rte_iova_t frag_addr = next_frag;
539 : : size_t frag_len;
540 : :
541 : 0 : frag_len = RTE_MIN(seg_len,
542 : : SFC_EF10_TX_DMA_DESC_LEN_MAX);
543 : :
544 : 0 : next_frag += frag_len;
545 : 0 : seg_len -= frag_len;
546 : :
547 [ # # # # ]: 0 : eop = (seg_len == 0 && m_seg->next == NULL);
548 : :
549 : 0 : id = (*added) & txq->ptr_mask;
550 : 0 : (*added)++;
551 : :
552 : : /*
553 : : * Initially we assume that one DMA descriptor is needed
554 : : * for every segment. When the segment is split across
555 : : * several DMA descriptors, increase the estimation.
556 : : */
557 : 0 : needed_desc += (seg_len != 0);
558 : :
559 : : /*
560 : : * When no more descriptors can be added, but not all
561 : : * segments are processed.
562 : : */
563 [ # # # # ]: 0 : if (*added - pkt_start == *dma_desc_space &&
564 [ # # ]: 0 : !eop &&
565 : 0 : !sfc_ef10_try_reap(txq, pkt_start, needed_desc,
566 : : dma_desc_space, reap_done)) {
567 : : struct rte_mbuf *m;
568 : : struct rte_mbuf *m_next;
569 : :
570 [ # # ]: 0 : if (txq->completed != pkt_start) {
571 : : unsigned int i;
572 : :
573 : : /*
574 : : * Reset mbuf associations with added
575 : : * descriptors.
576 : : */
577 [ # # ]: 0 : for (i = pkt_start; i != *added; i++) {
578 : 0 : id = i & txq->ptr_mask;
579 : 0 : txq->sw_ring[id].mbuf = NULL;
580 : : }
581 : : return ENOSPC;
582 : : }
583 : :
584 : : /* Free the segments that cannot be sent */
585 [ # # ]: 0 : for (m = m_seg->next; m != NULL; m = m_next) {
586 [ # # ]: 0 : m_next = m->next;
587 : : rte_pktmbuf_free_seg(m);
588 : : }
589 : : eop = true;
590 : : /* Ignore the rest of the segment */
591 : : seg_len = 0;
592 : : }
593 : :
594 : 0 : sfc_ef10_tx_qdesc_dma_create(frag_addr, frag_len,
595 : 0 : eop, &txq->txq_hw_ring[id]);
596 : :
597 [ # # ]: 0 : } while (seg_len != 0);
598 : :
599 : 0 : txq->sw_ring[id].mbuf = m_seg;
600 : :
601 : 0 : m_seg = m_seg->next;
602 [ # # ]: 0 : } while (!eop);
603 : :
604 : : /*
605 : : * Free segments which content was entirely copied to the TSO header
606 : : * memory space of Tx queue
607 : : */
608 [ # # ]: 0 : for (m_seg = first_m_seg; m_seg != m_seg_to_free_up_to;) {
609 : : struct rte_mbuf *seg_to_free = m_seg;
610 : :
611 [ # # ]: 0 : m_seg = m_seg->next;
612 : : rte_pktmbuf_free_seg(seg_to_free);
613 : : }
614 : :
615 : : return 0;
616 : : }
617 : :
618 : : static uint16_t
619 : 0 : sfc_ef10_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
620 : : {
621 : : struct sfc_ef10_txq * const txq = sfc_ef10_txq_by_dp_txq(tx_queue);
622 : : unsigned int added;
623 : : unsigned int dma_desc_space;
624 : : bool reap_done;
625 : : struct rte_mbuf **pktp;
626 : : struct rte_mbuf **pktp_end;
627 : :
628 [ # # ]: 0 : if (unlikely(txq->flags &
629 : : (SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION)))
630 : : return 0;
631 : :
632 : 0 : added = txq->added;
633 : 0 : dma_desc_space = txq->max_fill_level - (added - txq->completed);
634 : :
635 : 0 : reap_done = (dma_desc_space < txq->free_thresh);
636 [ # # ]: 0 : if (reap_done) {
637 : 0 : sfc_ef10_tx_reap(txq);
638 : 0 : dma_desc_space = txq->max_fill_level - (added - txq->completed);
639 : : }
640 : :
641 : 0 : for (pktp = &tx_pkts[0], pktp_end = &tx_pkts[nb_pkts];
642 [ # # ]: 0 : pktp != pktp_end;
643 : : ++pktp) {
644 : 0 : struct rte_mbuf *m_seg = *pktp;
645 : 0 : unsigned int pkt_start = added;
646 : : uint32_t pkt_len;
647 : :
648 [ # # ]: 0 : if (likely(pktp + 1 != pktp_end))
649 : 0 : rte_mbuf_prefetch_part1(pktp[1]);
650 : :
651 [ # # ]: 0 : if (m_seg->ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
652 : : int rc;
653 : :
654 : 0 : rc = sfc_ef10_xmit_tso_pkt(txq, m_seg, &added,
655 : : &dma_desc_space, &reap_done);
656 [ # # ]: 0 : if (rc != 0) {
657 : 0 : added = pkt_start;
658 : :
659 : : /* Packet can be sent in following xmit calls */
660 [ # # ]: 0 : if (likely(rc == ENOSPC))
661 : : break;
662 : :
663 : : /*
664 : : * Packet cannot be sent, tell RTE that
665 : : * it is sent, but actually drop it and
666 : : * continue with another packet
667 : : */
668 : 0 : rte_pktmbuf_free(*pktp);
669 : 0 : continue;
670 : : }
671 : :
672 : 0 : goto dma_desc_space_update;
673 : : }
674 : :
675 [ # # ]: 0 : if (sfc_ef10_tx_pkt_descs_max(m_seg, txq->max_pdu) >
676 : : dma_desc_space) {
677 [ # # ]: 0 : if (reap_done)
678 : : break;
679 : :
680 : : /* Push already prepared descriptors before polling */
681 [ # # ]: 0 : if (added != txq->added) {
682 : : sfc_ef10_tx_qpush(txq, added, txq->added);
683 : 0 : txq->added = added;
684 : : }
685 : :
686 : 0 : sfc_ef10_tx_reap(txq);
687 : 0 : reap_done = true;
688 : 0 : dma_desc_space = txq->max_fill_level -
689 : 0 : (added - txq->completed);
690 [ # # ]: 0 : if (sfc_ef10_tx_pkt_descs_max(m_seg, txq->max_pdu) >
691 : : dma_desc_space)
692 : : break;
693 : : }
694 : :
695 : 0 : pkt_len = m_seg->pkt_len;
696 : : do {
697 : : rte_iova_t seg_addr = rte_mbuf_data_iova(m_seg);
698 : 0 : unsigned int seg_len = rte_pktmbuf_data_len(m_seg);
699 : 0 : unsigned int id = added & txq->ptr_mask;
700 : :
701 : : SFC_ASSERT(seg_len <= SFC_EF10_TX_DMA_DESC_LEN_MAX);
702 : :
703 : 0 : pkt_len -= seg_len;
704 : :
705 : 0 : sfc_ef10_tx_qdesc_dma_create(seg_addr,
706 : : seg_len, (pkt_len == 0),
707 : 0 : &txq->txq_hw_ring[id]);
708 : :
709 : : /*
710 : : * rte_pktmbuf_free() is commonly used in DPDK for
711 : : * recycling packets - the function checks every
712 : : * segment's reference counter and returns the
713 : : * buffer to its pool whenever possible;
714 : : * nevertheless, freeing mbuf segments one by one
715 : : * may entail some performance decline;
716 : : * from this point, sfc_efx_tx_reap() does the same job
717 : : * on its own and frees buffers in bulks (all mbufs
718 : : * within a bulk belong to the same pool);
719 : : * from this perspective, individual segment pointers
720 : : * must be associated with the corresponding SW
721 : : * descriptors independently so that only one loop
722 : : * is sufficient on reap to inspect all the buffers
723 : : */
724 : 0 : txq->sw_ring[id].mbuf = m_seg;
725 : :
726 : 0 : ++added;
727 : :
728 [ # # ]: 0 : } while ((m_seg = m_seg->next) != 0);
729 : :
730 : 0 : dma_desc_space_update:
731 : 0 : dma_desc_space -= (added - pkt_start);
732 : : }
733 : :
734 [ # # ]: 0 : if (likely(added != txq->added)) {
735 : : sfc_ef10_tx_qpush(txq, added, txq->added);
736 : 0 : txq->added = added;
737 : : }
738 : :
739 : : #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
740 [ # # ]: 0 : if (!reap_done)
741 : 0 : sfc_ef10_tx_reap(txq);
742 : : #endif
743 : :
744 : 0 : return pktp - &tx_pkts[0];
745 : : }
746 : :
747 : : static void
748 : 0 : sfc_ef10_simple_tx_reap(struct sfc_ef10_txq *txq)
749 : : {
750 : 0 : const unsigned int old_read_ptr = txq->evq_read_ptr;
751 : 0 : const unsigned int ptr_mask = txq->ptr_mask;
752 : 0 : unsigned int completed = txq->completed;
753 : : unsigned int pending = completed;
754 : :
755 : 0 : pending += sfc_ef10_tx_process_events(txq);
756 : :
757 [ # # ]: 0 : if (pending != completed) {
758 : : struct rte_mbuf *bulk[SFC_TX_REAP_BULK_SIZE];
759 : : unsigned int nb = 0;
760 : :
761 : : do {
762 : : struct sfc_ef10_tx_sw_desc *txd;
763 : :
764 : 0 : txd = &txq->sw_ring[completed & ptr_mask];
765 : :
766 [ # # ]: 0 : if (nb == RTE_DIM(bulk)) {
767 [ # # ]: 0 : rte_mempool_put_bulk(bulk[0]->pool,
768 : : (void *)bulk, nb);
769 : : nb = 0;
770 : : }
771 : :
772 : 0 : bulk[nb++] = txd->mbuf;
773 [ # # ]: 0 : } while (++completed != pending);
774 : :
775 [ # # ]: 0 : rte_mempool_put_bulk(bulk[0]->pool, (void *)bulk, nb);
776 : :
777 : 0 : txq->completed = completed;
778 : : }
779 : :
780 : 0 : sfc_ef10_ev_qclear(txq->evq_hw_ring, ptr_mask, old_read_ptr,
781 : : txq->evq_read_ptr);
782 : 0 : }
783 : :
784 : : #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
785 : : static uint16_t
786 : : sfc_ef10_simple_prepare_pkts(__rte_unused void *tx_queue,
787 : : struct rte_mbuf **tx_pkts,
788 : : uint16_t nb_pkts)
789 : : {
790 : : uint16_t i;
791 : :
792 : : for (i = 0; i < nb_pkts; i++) {
793 : : struct rte_mbuf *m = tx_pkts[i];
794 : : int ret;
795 : :
796 : : ret = rte_validate_tx_offload(m);
797 : : if (unlikely(ret != 0)) {
798 : : /*
799 : : * Negative error code is returned by
800 : : * rte_validate_tx_offload(), but positive are used
801 : : * inside net/sfc PMD.
802 : : */
803 : : SFC_ASSERT(ret < 0);
804 : : rte_errno = -ret;
805 : : break;
806 : : }
807 : :
808 : : /* ef10_simple does not support TSO and VLAN insertion */
809 : : if (unlikely(m->ol_flags &
810 : : (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_VLAN))) {
811 : : rte_errno = ENOTSUP;
812 : : break;
813 : : }
814 : :
815 : : /* ef10_simple does not support scattered packets */
816 : : if (unlikely(m->nb_segs != 1)) {
817 : : rte_errno = ENOTSUP;
818 : : break;
819 : : }
820 : :
821 : : /*
822 : : * ef10_simple requires fast-free which ignores reference
823 : : * counters
824 : : */
825 : : if (unlikely(rte_mbuf_refcnt_read(m) != 1)) {
826 : : rte_errno = ENOTSUP;
827 : : break;
828 : : }
829 : :
830 : : /* ef10_simple requires single pool for all packets */
831 : : if (unlikely(m->pool != tx_pkts[0]->pool)) {
832 : : rte_errno = ENOTSUP;
833 : : break;
834 : : }
835 : : }
836 : :
837 : : return i;
838 : : }
839 : : #endif
840 : :
841 : : static uint16_t
842 : 0 : sfc_ef10_simple_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
843 : : uint16_t nb_pkts)
844 : : {
845 : : struct sfc_ef10_txq * const txq = sfc_ef10_txq_by_dp_txq(tx_queue);
846 : : unsigned int ptr_mask;
847 : : unsigned int added;
848 : : unsigned int dma_desc_space;
849 : : bool reap_done;
850 : : struct rte_mbuf **pktp;
851 : : struct rte_mbuf **pktp_end;
852 : :
853 [ # # ]: 0 : if (unlikely(txq->flags &
854 : : (SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION)))
855 : : return 0;
856 : :
857 : 0 : ptr_mask = txq->ptr_mask;
858 : 0 : added = txq->added;
859 : 0 : dma_desc_space = txq->max_fill_level - (added - txq->completed);
860 : :
861 : 0 : reap_done = (dma_desc_space < RTE_MAX(txq->free_thresh, nb_pkts));
862 [ # # ]: 0 : if (reap_done) {
863 : 0 : sfc_ef10_simple_tx_reap(txq);
864 : 0 : dma_desc_space = txq->max_fill_level - (added - txq->completed);
865 : : }
866 : :
867 [ # # ]: 0 : pktp_end = &tx_pkts[MIN(nb_pkts, dma_desc_space)];
868 [ # # ]: 0 : for (pktp = &tx_pkts[0]; pktp != pktp_end; ++pktp) {
869 : 0 : struct rte_mbuf *pkt = *pktp;
870 : 0 : unsigned int id = added & ptr_mask;
871 : :
872 : : SFC_ASSERT(rte_pktmbuf_data_len(pkt) <=
873 : : SFC_EF10_TX_DMA_DESC_LEN_MAX);
874 : :
875 : 0 : sfc_ef10_tx_qdesc_dma_create(rte_mbuf_data_iova(pkt),
876 : 0 : rte_pktmbuf_data_len(pkt),
877 : 0 : true, &txq->txq_hw_ring[id]);
878 : :
879 : 0 : txq->sw_ring[id].mbuf = pkt;
880 : :
881 : 0 : ++added;
882 : : }
883 : :
884 [ # # ]: 0 : if (likely(added != txq->added)) {
885 : : sfc_ef10_tx_qpush(txq, added, txq->added);
886 : 0 : txq->added = added;
887 : : }
888 : :
889 : : #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
890 [ # # ]: 0 : if (!reap_done)
891 : 0 : sfc_ef10_simple_tx_reap(txq);
892 : : #endif
893 : :
894 : 0 : return pktp - &tx_pkts[0];
895 : : }
896 : :
897 : : static sfc_dp_tx_get_dev_info_t sfc_ef10_get_dev_info;
898 : : static void
899 : 0 : sfc_ef10_get_dev_info(struct rte_eth_dev_info *dev_info)
900 : : {
901 : : /*
902 : : * Number of descriptors just defines maximum number of pushed
903 : : * descriptors (fill level).
904 : : */
905 : 0 : dev_info->tx_desc_lim.nb_min = 1;
906 : 0 : dev_info->tx_desc_lim.nb_align = 1;
907 : 0 : }
908 : :
909 : : static sfc_dp_tx_qsize_up_rings_t sfc_ef10_tx_qsize_up_rings;
910 : : static int
911 : 0 : sfc_ef10_tx_qsize_up_rings(uint16_t nb_tx_desc,
912 : : struct sfc_dp_tx_hw_limits *limits,
913 : : unsigned int *txq_entries,
914 : : unsigned int *evq_entries,
915 : : unsigned int *txq_max_fill_level)
916 : : {
917 : : /*
918 : : * rte_ethdev API guarantees that the number meets min, max and
919 : : * alignment requirements.
920 : : */
921 [ # # ]: 0 : if (nb_tx_desc <= limits->txq_min_entries)
922 : 0 : *txq_entries = limits->txq_min_entries;
923 : : else
924 : 0 : *txq_entries = rte_align32pow2(nb_tx_desc);
925 : :
926 : 0 : *evq_entries = *txq_entries;
927 : :
928 : 0 : *txq_max_fill_level = RTE_MIN(nb_tx_desc,
929 : : SFC_EF10_TXQ_LIMIT(*evq_entries));
930 : 0 : return 0;
931 : : }
932 : :
933 : : static sfc_dp_tx_qcreate_t sfc_ef10_tx_qcreate;
934 : : static int
935 : 0 : sfc_ef10_tx_qcreate(uint16_t port_id, uint16_t queue_id,
936 : : const struct rte_pci_addr *pci_addr, int socket_id,
937 : : const struct sfc_dp_tx_qcreate_info *info,
938 : : struct sfc_dp_txq **dp_txqp)
939 : : {
940 : : struct sfc_ef10_txq *txq;
941 : : int rc;
942 : :
943 : : rc = EINVAL;
944 [ # # ]: 0 : if (info->txq_entries != info->evq_entries)
945 : 0 : goto fail_bad_args;
946 : :
947 : : rc = ENOTSUP;
948 [ # # ]: 0 : if (info->nic_dma_info->nb_regions > 0)
949 : 0 : goto fail_nic_dma;
950 : :
951 : : rc = ENOMEM;
952 : 0 : txq = rte_zmalloc_socket("sfc-ef10-txq", sizeof(*txq),
953 : : RTE_CACHE_LINE_SIZE, socket_id);
954 [ # # ]: 0 : if (txq == NULL)
955 : 0 : goto fail_txq_alloc;
956 : :
957 : 0 : sfc_dp_queue_init(&txq->dp.dpq, port_id, queue_id, pci_addr);
958 : :
959 : : rc = ENOMEM;
960 : 0 : txq->sw_ring = rte_calloc_socket("sfc-ef10-txq-sw_ring",
961 : 0 : info->txq_entries,
962 : : sizeof(*txq->sw_ring),
963 : : RTE_CACHE_LINE_SIZE, socket_id);
964 [ # # ]: 0 : if (txq->sw_ring == NULL)
965 : 0 : goto fail_sw_ring_alloc;
966 : :
967 [ # # ]: 0 : if (info->offloads & (RTE_ETH_TX_OFFLOAD_TCP_TSO |
968 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
969 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO)) {
970 : 0 : txq->tsoh = rte_calloc_socket("sfc-ef10-txq-tsoh",
971 : 0 : info->txq_entries,
972 : : SFC_TSOH_STD_LEN,
973 : : RTE_CACHE_LINE_SIZE,
974 : : socket_id);
975 [ # # ]: 0 : if (txq->tsoh == NULL)
976 : 0 : goto fail_tsoh_alloc;
977 : :
978 : 0 : txq->tsoh_iova = rte_malloc_virt2iova(txq->tsoh);
979 : : }
980 : :
981 : 0 : txq->flags = SFC_EF10_TXQ_NOT_RUNNING;
982 : 0 : txq->ptr_mask = info->txq_entries - 1;
983 : 0 : txq->max_fill_level = info->max_fill_level;
984 : 0 : txq->free_thresh = info->free_thresh;
985 : 0 : txq->txq_hw_ring = info->txq_hw_ring;
986 : 0 : txq->doorbell = (volatile uint8_t *)info->mem_bar +
987 : 0 : ER_DZ_TX_DESC_UPD_REG_OFST +
988 : 0 : (info->hw_index << info->vi_window_shift);
989 : 0 : txq->evq_hw_ring = info->evq_hw_ring;
990 : 0 : txq->tso_tcp_header_offset_limit = info->tso_tcp_header_offset_limit;
991 : 0 : txq->max_pdu = info->max_pdu;
992 : :
993 : : sfc_ef10_tx_info(&txq->dp.dpq, "TxQ doorbell is %p", txq->doorbell);
994 : :
995 : 0 : *dp_txqp = &txq->dp;
996 : 0 : return 0;
997 : :
998 : : fail_tsoh_alloc:
999 : 0 : rte_free(txq->sw_ring);
1000 : :
1001 : 0 : fail_sw_ring_alloc:
1002 : 0 : rte_free(txq);
1003 : :
1004 : : fail_txq_alloc:
1005 : : fail_nic_dma:
1006 : : fail_bad_args:
1007 : : return rc;
1008 : : }
1009 : :
1010 : : static sfc_dp_tx_qdestroy_t sfc_ef10_tx_qdestroy;
1011 : : static void
1012 : 0 : sfc_ef10_tx_qdestroy(struct sfc_dp_txq *dp_txq)
1013 : : {
1014 : : struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1015 : :
1016 : 0 : rte_free(txq->tsoh);
1017 : 0 : rte_free(txq->sw_ring);
1018 : 0 : rte_free(txq);
1019 : 0 : }
1020 : :
1021 : : static sfc_dp_tx_qstart_t sfc_ef10_tx_qstart;
1022 : : static int
1023 : 0 : sfc_ef10_tx_qstart(struct sfc_dp_txq *dp_txq, unsigned int evq_read_ptr,
1024 : : unsigned int txq_desc_index)
1025 : : {
1026 : : struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1027 : :
1028 : 0 : txq->evq_read_ptr = evq_read_ptr;
1029 : 0 : txq->added = txq->completed = txq_desc_index;
1030 : :
1031 : 0 : txq->flags |= SFC_EF10_TXQ_STARTED;
1032 : 0 : txq->flags &= ~(SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION);
1033 : :
1034 : 0 : return 0;
1035 : : }
1036 : :
1037 : : static sfc_dp_tx_qstop_t sfc_ef10_tx_qstop;
1038 : : static void
1039 : 0 : sfc_ef10_tx_qstop(struct sfc_dp_txq *dp_txq, unsigned int *evq_read_ptr)
1040 : : {
1041 : : struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1042 : :
1043 : 0 : txq->flags |= SFC_EF10_TXQ_NOT_RUNNING;
1044 : :
1045 : 0 : *evq_read_ptr = txq->evq_read_ptr;
1046 : 0 : }
1047 : :
1048 : : static sfc_dp_tx_qtx_ev_t sfc_ef10_tx_qtx_ev;
1049 : : static bool
1050 : 0 : sfc_ef10_tx_qtx_ev(struct sfc_dp_txq *dp_txq, __rte_unused unsigned int id)
1051 : : {
1052 : : __rte_unused struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1053 : :
1054 : : SFC_ASSERT(txq->flags & SFC_EF10_TXQ_NOT_RUNNING);
1055 : :
1056 : : /*
1057 : : * It is safe to ignore Tx event since we reap all mbufs on
1058 : : * queue purge anyway.
1059 : : */
1060 : :
1061 : 0 : return false;
1062 : : }
1063 : :
1064 : : static sfc_dp_tx_qreap_t sfc_ef10_tx_qreap;
1065 : : static void
1066 : 0 : sfc_ef10_tx_qreap(struct sfc_dp_txq *dp_txq)
1067 : : {
1068 : : struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1069 : : unsigned int completed;
1070 : :
1071 [ # # ]: 0 : for (completed = txq->completed; completed != txq->added; ++completed) {
1072 : : struct sfc_ef10_tx_sw_desc *txd;
1073 : :
1074 : 0 : txd = &txq->sw_ring[completed & txq->ptr_mask];
1075 [ # # ]: 0 : if (txd->mbuf != NULL) {
1076 : : rte_pktmbuf_free_seg(txd->mbuf);
1077 : 0 : txd->mbuf = NULL;
1078 : : }
1079 : : }
1080 : :
1081 : 0 : txq->flags &= ~SFC_EF10_TXQ_STARTED;
1082 : 0 : }
1083 : :
1084 : : static unsigned int
1085 : 0 : sfc_ef10_tx_qdesc_npending(struct sfc_ef10_txq *txq)
1086 : : {
1087 : 0 : const unsigned int curr_done = txq->completed - 1;
1088 : : unsigned int anew_done = curr_done;
1089 : : efx_qword_t tx_ev;
1090 : 0 : const unsigned int evq_old_read_ptr = txq->evq_read_ptr;
1091 : :
1092 [ # # ]: 0 : if (unlikely(txq->flags &
1093 : : (SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION)))
1094 : : return 0;
1095 : :
1096 [ # # ]: 0 : while (sfc_ef10_tx_get_event(txq, &tx_ev))
1097 : 0 : anew_done = EFX_QWORD_FIELD(tx_ev, ESF_DZ_TX_DESCR_INDX);
1098 : :
1099 : : /*
1100 : : * The function does not process events, so return event queue read
1101 : : * pointer to the original position to allow the events that were
1102 : : * read to be processed later
1103 : : */
1104 : 0 : txq->evq_read_ptr = evq_old_read_ptr;
1105 : :
1106 : 0 : return (anew_done - curr_done) & txq->ptr_mask;
1107 : : }
1108 : :
1109 : : static sfc_dp_tx_qdesc_status_t sfc_ef10_tx_qdesc_status;
1110 : : static int
1111 : 0 : sfc_ef10_tx_qdesc_status(struct sfc_dp_txq *dp_txq,
1112 : : uint16_t offset)
1113 : : {
1114 : : struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1115 : 0 : unsigned int npending = sfc_ef10_tx_qdesc_npending(txq);
1116 : :
1117 [ # # ]: 0 : if (unlikely(offset > txq->ptr_mask))
1118 : : return -EINVAL;
1119 : :
1120 [ # # ]: 0 : if (unlikely(offset >= txq->max_fill_level))
1121 : : return RTE_ETH_TX_DESC_UNAVAIL;
1122 : :
1123 [ # # ]: 0 : if (unlikely(offset < npending))
1124 : 0 : return RTE_ETH_TX_DESC_FULL;
1125 : :
1126 : : return RTE_ETH_TX_DESC_DONE;
1127 : : }
1128 : :
1129 : : struct sfc_dp_tx sfc_ef10_tx = {
1130 : : .dp = {
1131 : : .name = SFC_KVARG_DATAPATH_EF10,
1132 : : .type = SFC_DP_TX,
1133 : : .hw_fw_caps = SFC_DP_HW_FW_CAP_EF10,
1134 : : },
1135 : : .features = SFC_DP_TX_FEAT_MULTI_PROCESS,
1136 : : .dev_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS,
1137 : : .queue_offload_capa = RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1138 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1139 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1140 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
1141 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
1142 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
1143 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO,
1144 : : .get_dev_info = sfc_ef10_get_dev_info,
1145 : : .qsize_up_rings = sfc_ef10_tx_qsize_up_rings,
1146 : : .qcreate = sfc_ef10_tx_qcreate,
1147 : : .qdestroy = sfc_ef10_tx_qdestroy,
1148 : : .qstart = sfc_ef10_tx_qstart,
1149 : : .qtx_ev = sfc_ef10_tx_qtx_ev,
1150 : : .qstop = sfc_ef10_tx_qstop,
1151 : : .qreap = sfc_ef10_tx_qreap,
1152 : : .qdesc_status = sfc_ef10_tx_qdesc_status,
1153 : : .pkt_prepare = sfc_ef10_prepare_pkts,
1154 : : .pkt_burst = sfc_ef10_xmit_pkts,
1155 : : };
1156 : :
1157 : : struct sfc_dp_tx sfc_ef10_simple_tx = {
1158 : : .dp = {
1159 : : .name = SFC_KVARG_DATAPATH_EF10_SIMPLE,
1160 : : .type = SFC_DP_TX,
1161 : : },
1162 : : .features = SFC_DP_TX_FEAT_MULTI_PROCESS,
1163 : : .dev_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE,
1164 : : .queue_offload_capa = RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1165 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1166 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1167 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM,
1168 : : .get_dev_info = sfc_ef10_get_dev_info,
1169 : : .qsize_up_rings = sfc_ef10_tx_qsize_up_rings,
1170 : : .qcreate = sfc_ef10_tx_qcreate,
1171 : : .qdestroy = sfc_ef10_tx_qdestroy,
1172 : : .qstart = sfc_ef10_tx_qstart,
1173 : : .qtx_ev = sfc_ef10_tx_qtx_ev,
1174 : : .qstop = sfc_ef10_tx_qstop,
1175 : : .qreap = sfc_ef10_tx_qreap,
1176 : : .qdesc_status = sfc_ef10_tx_qdesc_status,
1177 : : #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
1178 : : .pkt_prepare = sfc_ef10_simple_prepare_pkts,
1179 : : #endif
1180 : : .pkt_burst = sfc_ef10_simple_xmit_pkts,
1181 : : };
|