1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2016-2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
18 #include "efx_types.h"
20 #include "efx_regs_ef10.h"
22 #include "sfc_debug.h"
23 #include "sfc_dp_tx.h"
24 #include "sfc_tweak.h"
25 #include "sfc_kvargs.h"
29 #define sfc_ef10_tx_err(dpq, ...) \
30 SFC_DP_LOG(SFC_KVARG_DATAPATH_EF10, ERR, dpq, __VA_ARGS__)
32 #define sfc_ef10_tx_info(dpq, ...) \
33 SFC_DP_LOG(SFC_KVARG_DATAPATH_EF10, INFO, dpq, __VA_ARGS__)
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)
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.
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 */)
52 struct sfc_ef10_tx_sw_desc {
53 struct rte_mbuf *mbuf;
58 #define SFC_EF10_TXQ_STARTED 0x1
59 #define SFC_EF10_TXQ_NOT_RUNNING 0x2
60 #define SFC_EF10_TXQ_EXCEPTION 0x4
62 unsigned int ptr_mask;
64 unsigned int completed;
65 unsigned int max_fill_level;
66 unsigned int free_thresh;
67 unsigned int evq_read_ptr;
68 struct sfc_ef10_tx_sw_desc *sw_ring;
69 efx_qword_t *txq_hw_ring;
70 volatile void *doorbell;
71 efx_qword_t *evq_hw_ring;
74 uint16_t tso_tcp_header_offset_limit;
76 /* Datapath transmit queue anchor */
80 static inline struct sfc_ef10_txq *
81 sfc_ef10_txq_by_dp_txq(struct sfc_dp_txq *dp_txq)
83 return container_of(dp_txq, struct sfc_ef10_txq, dp);
87 sfc_ef10_tx_get_event(struct sfc_ef10_txq *txq, efx_qword_t *tx_ev)
89 volatile efx_qword_t *evq_hw_ring = txq->evq_hw_ring;
92 * Exception flag is set when reap is done.
93 * It is never done twice per packet burst get and absence of
94 * the flag is checked on burst get entry.
96 SFC_ASSERT((txq->flags & SFC_EF10_TXQ_EXCEPTION) == 0);
98 *tx_ev = evq_hw_ring[txq->evq_read_ptr & txq->ptr_mask];
100 if (!sfc_ef10_ev_present(*tx_ev))
103 if (unlikely(EFX_QWORD_FIELD(*tx_ev, FSF_AZ_EV_CODE) !=
104 FSE_AZ_EV_CODE_TX_EV)) {
106 * Do not move read_ptr to keep the event for exception
107 * handling by the control path.
109 txq->flags |= SFC_EF10_TXQ_EXCEPTION;
110 sfc_ef10_tx_err(&txq->dp.dpq,
111 "TxQ exception at EvQ read ptr %#x",
121 sfc_ef10_tx_process_events(struct sfc_ef10_txq *txq)
123 const unsigned int curr_done = txq->completed - 1;
124 unsigned int anew_done = curr_done;
127 while (sfc_ef10_tx_get_event(txq, &tx_ev)) {
129 * DROP_EVENT is an internal to the NIC, software should
130 * never see it and, therefore, may ignore it.
133 /* Update the latest done descriptor */
134 anew_done = EFX_QWORD_FIELD(tx_ev, ESF_DZ_TX_DESCR_INDX);
136 return (anew_done - curr_done) & txq->ptr_mask;
140 sfc_ef10_tx_reap(struct sfc_ef10_txq *txq)
142 const unsigned int old_read_ptr = txq->evq_read_ptr;
143 const unsigned int ptr_mask = txq->ptr_mask;
144 unsigned int completed = txq->completed;
145 unsigned int pending = completed;
147 pending += sfc_ef10_tx_process_events(txq);
149 if (pending != completed) {
150 struct rte_mbuf *bulk[SFC_TX_REAP_BULK_SIZE];
154 struct sfc_ef10_tx_sw_desc *txd;
157 txd = &txq->sw_ring[completed & ptr_mask];
158 if (txd->mbuf == NULL)
161 m = rte_pktmbuf_prefree_seg(txd->mbuf);
166 if ((nb == RTE_DIM(bulk)) ||
167 ((nb != 0) && (m->pool != bulk[0]->pool))) {
168 rte_mempool_put_bulk(bulk[0]->pool,
174 } while (++completed != pending);
177 rte_mempool_put_bulk(bulk[0]->pool, (void *)bulk, nb);
179 txq->completed = completed;
182 sfc_ef10_ev_qclear(txq->evq_hw_ring, ptr_mask, old_read_ptr,
187 sfc_ef10_tx_qdesc_dma_create(rte_iova_t addr, uint16_t size, bool eop,
190 EFX_POPULATE_QWORD_4(*edp,
191 ESF_DZ_TX_KER_TYPE, 0,
192 ESF_DZ_TX_KER_CONT, !eop,
193 ESF_DZ_TX_KER_BYTE_CNT, size,
194 ESF_DZ_TX_KER_BUF_ADDR, addr);
198 sfc_ef10_tx_qdesc_tso2_create(struct sfc_ef10_txq * const txq,
199 unsigned int added, uint16_t ipv4_id,
200 uint16_t outer_ipv4_id, uint32_t tcp_seq,
203 EFX_POPULATE_QWORD_5(txq->txq_hw_ring[added & txq->ptr_mask],
204 ESF_DZ_TX_DESC_IS_OPT, 1,
205 ESF_DZ_TX_OPTION_TYPE,
206 ESE_DZ_TX_OPTION_DESC_TSO,
207 ESF_DZ_TX_TSO_OPTION_TYPE,
208 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
209 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
210 ESF_DZ_TX_TSO_TCP_SEQNO, tcp_seq);
211 EFX_POPULATE_QWORD_5(txq->txq_hw_ring[(added + 1) & txq->ptr_mask],
212 ESF_DZ_TX_DESC_IS_OPT, 1,
213 ESF_DZ_TX_OPTION_TYPE,
214 ESE_DZ_TX_OPTION_DESC_TSO,
215 ESF_DZ_TX_TSO_OPTION_TYPE,
216 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
217 ESF_DZ_TX_TSO_TCP_MSS, tcp_mss,
218 ESF_DZ_TX_TSO_OUTER_IPID, outer_ipv4_id);
222 sfc_ef10_tx_qpush(struct sfc_ef10_txq *txq, unsigned int added,
229 * This improves performance by pushing a TX descriptor at the same
230 * time as the doorbell. The descriptor must be added to the TXQ,
231 * so that can be used if the hardware decides not to use the pushed
234 desc.eq_u64[0] = txq->txq_hw_ring[pushed & txq->ptr_mask].eq_u64[0];
235 EFX_POPULATE_OWORD_3(oword,
236 ERF_DZ_TX_DESC_WPTR, added & txq->ptr_mask,
237 ERF_DZ_TX_DESC_HWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_1),
238 ERF_DZ_TX_DESC_LWORD, EFX_QWORD_FIELD(desc, EFX_DWORD_0));
240 /* DMA sync to device is not required */
243 * rte_io_wmb() which guarantees that the STORE operations
244 * (i.e. Tx and event descriptor updates) that precede
245 * the rte_io_wmb() call are visible to NIC before the STORE
246 * operations that follow it (i.e. doorbell write).
250 *(volatile efsys_uint128_t *)txq->doorbell = oword.eo_u128[0];
251 txq->dp.dpq.tx_dbells++;
255 sfc_ef10_tx_pkt_descs_max(const struct rte_mbuf *m)
257 unsigned int extra_descs_per_seg;
258 unsigned int extra_descs_per_pkt;
261 * VLAN offload is not supported yet, so no extra descriptors
262 * are required for VLAN option descriptor.
265 /** Maximum length of the mbuf segment data */
266 #define SFC_MBUF_SEG_LEN_MAX UINT16_MAX
267 RTE_BUILD_BUG_ON(sizeof(m->data_len) != 2);
270 * Each segment is already counted once below. So, calculate
271 * how many extra DMA descriptors may be required per segment in
272 * the worst case because of maximum DMA descriptor length limit.
273 * If maximum segment length is less or equal to maximum DMA
274 * descriptor length, no extra DMA descriptors are required.
276 extra_descs_per_seg =
277 (SFC_MBUF_SEG_LEN_MAX - 1) / SFC_EF10_TX_DMA_DESC_LEN_MAX;
279 /** Maximum length of the packet */
280 #define SFC_MBUF_PKT_LEN_MAX UINT32_MAX
281 RTE_BUILD_BUG_ON(sizeof(m->pkt_len) != 4);
284 * One more limitation on maximum number of extra DMA descriptors
285 * comes from slicing entire packet because of DMA descriptor length
286 * limit taking into account that there is at least one segment
287 * which is already counted below (so division of the maximum
288 * packet length minus one with round down).
289 * TSO is not supported yet, so packet length is limited by
292 extra_descs_per_pkt =
293 (RTE_MIN((unsigned int)EFX_MAC_PDU_MAX,
294 SFC_MBUF_PKT_LEN_MAX) - 1) /
295 SFC_EF10_TX_DMA_DESC_LEN_MAX;
297 return m->nb_segs + RTE_MIN(m->nb_segs * extra_descs_per_seg,
298 extra_descs_per_pkt);
302 sfc_ef10_try_reap(struct sfc_ef10_txq * const txq, unsigned int added,
303 unsigned int needed_desc, unsigned int *dma_desc_space,
309 if (added != txq->added) {
310 sfc_ef10_tx_qpush(txq, added, txq->added);
314 sfc_ef10_tx_reap(txq);
318 * Recalculate DMA descriptor space since Tx reap may change
319 * the number of completed descriptors
321 *dma_desc_space = txq->max_fill_level -
322 (added - txq->completed);
324 return (needed_desc <= *dma_desc_space);
328 sfc_ef10_prepare_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
331 struct sfc_ef10_txq * const txq = sfc_ef10_txq_by_dp_txq(tx_queue);
334 for (i = 0; i < nb_pkts; i++) {
335 struct rte_mbuf *m = tx_pkts[i];
338 #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
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.
344 if (!(m->ol_flags & PKT_TX_TCP_SEG)) {
345 struct rte_mbuf *m_seg;
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) {
356 ret = sfc_dp_tx_prepare_pkt(m, 0, SFC_TSOH_STD_LEN,
357 txq->tso_tcp_header_offset_limit,
359 SFC_EF10_TSO_OPT_DESCS_NUM, 0);
360 if (unlikely(ret != 0)) {
370 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,
374 size_t iph_off = ((m_seg->ol_flags & PKT_TX_TUNNEL_MASK) ?
375 m_seg->outer_l2_len + m_seg->outer_l3_len : 0) +
377 size_t tcph_off = iph_off + m_seg->l3_len;
378 size_t header_len = tcph_off + m_seg->l4_len;
379 /* Offset of the payload in the last segment that contains the header */
381 const struct rte_tcp_hdr *th;
382 uint16_t packet_id = 0;
383 uint16_t outer_packet_id = 0;
387 struct rte_mbuf *first_m_seg = m_seg;
388 unsigned int pkt_start = *added;
389 unsigned int needed_desc;
390 struct rte_mbuf *m_seg_to_free_up_to = first_m_seg;
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.
400 needed_desc = m_seg->nb_segs +
401 (unsigned int)SFC_EF10_TSO_OPT_DESCS_NUM +
402 (unsigned int)SFC_EF10_TSO_HDR_DESCS_NUM;
404 if (needed_desc > *dma_desc_space &&
405 !sfc_ef10_try_reap(txq, pkt_start, needed_desc,
406 dma_desc_space, reap_done)) {
408 * If a future Tx reap may increase available DMA descriptor
409 * space, do not try to send the packet.
411 if (txq->completed != pkt_start)
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.
419 if (*dma_desc_space < SFC_EF10_TSO_OPT_DESCS_NUM +
420 SFC_EF10_TSO_HDR_DESCS_NUM + 1)
424 /* Check if the header is not fragmented */
425 if (rte_pktmbuf_data_len(m_seg) >= header_len) {
426 hdr_addr = rte_pktmbuf_mtod(m_seg, uint8_t *);
427 hdr_iova = rte_mbuf_data_iova(m_seg);
428 if (rte_pktmbuf_data_len(m_seg) == header_len) {
429 /* Cannot send a packet that consists only of header */
430 if (unlikely(m_seg->next == NULL))
433 * Associate header mbuf with header descriptor
434 * which is located after TSO descriptors.
436 txq->sw_ring[(pkt_start + SFC_EF10_TSO_OPT_DESCS_NUM) &
437 txq->ptr_mask].mbuf = m_seg;
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.
451 unsigned int copied_segs;
452 unsigned int hdr_addr_off = (*added & txq->ptr_mask) *
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.
461 if (unlikely(header_len > SFC_TSOH_STD_LEN))
464 hdr_addr = txq->tsoh + hdr_addr_off;
465 hdr_iova = txq->tsoh_iova + hdr_addr_off;
466 copied_segs = sfc_tso_prepare_header(hdr_addr, header_len,
469 /* Cannot send a packet that consists only of header */
470 if (unlikely(m_seg == NULL))
473 m_seg_to_free_up_to = m_seg;
475 * Reduce the number of needed descriptors by the number of
476 * segments that entirely consist of header data.
478 needed_desc -= copied_segs;
480 /* Extra descriptor for separated header is not needed */
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.
490 * The same concern applies to outer UDP datagram length field.
492 switch (m_seg->ol_flags & PKT_TX_TUNNEL_MASK) {
493 case PKT_TX_TUNNEL_VXLAN:
495 case PKT_TX_TUNNEL_GENEVE:
496 sfc_tso_outer_udp_fix_len(first_m_seg, hdr_addr);
502 sfc_tso_innermost_ip_fix_len(first_m_seg, hdr_addr, iph_off);
505 * Tx prepare has debug-only checks that offload flags are correctly
506 * filled in 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.
509 if (first_m_seg->ol_flags & PKT_TX_IPV4)
510 packet_id = sfc_tso_ip4_get_ipid(hdr_addr, iph_off);
512 if (first_m_seg->ol_flags & PKT_TX_OUTER_IPV4)
513 outer_packet_id = sfc_tso_ip4_get_ipid(hdr_addr,
514 first_m_seg->outer_l2_len);
516 th = (const struct rte_tcp_hdr *)(hdr_addr + tcph_off);
517 rte_memcpy(&sent_seq, &th->sent_seq, sizeof(uint32_t));
518 sent_seq = rte_be_to_cpu_32(sent_seq);
520 sfc_ef10_tx_qdesc_tso2_create(txq, *added, packet_id, outer_packet_id,
521 sent_seq, first_m_seg->tso_segsz);
522 (*added) += SFC_EF10_TSO_OPT_DESCS_NUM;
524 sfc_ef10_tx_qdesc_dma_create(hdr_iova, header_len, false,
525 &txq->txq_hw_ring[(*added) & txq->ptr_mask]);
529 rte_iova_t next_frag = rte_mbuf_data_iova(m_seg);
530 unsigned int seg_len = rte_pktmbuf_data_len(m_seg);
538 rte_iova_t frag_addr = next_frag;
541 frag_len = RTE_MIN(seg_len,
542 SFC_EF10_TX_DMA_DESC_LEN_MAX);
544 next_frag += frag_len;
547 eop = (seg_len == 0 && m_seg->next == NULL);
549 id = (*added) & txq->ptr_mask;
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.
557 needed_desc += (seg_len != 0);
560 * When no more descriptors can be added, but not all
561 * segments are processed.
563 if (*added - pkt_start == *dma_desc_space &&
565 !sfc_ef10_try_reap(txq, pkt_start, needed_desc,
566 dma_desc_space, reap_done)) {
568 struct rte_mbuf *m_next;
570 if (txq->completed != pkt_start) {
574 * Reset mbuf associations with added
577 for (i = pkt_start; i != *added; i++) {
578 id = i & txq->ptr_mask;
579 txq->sw_ring[id].mbuf = NULL;
584 /* Free the segments that cannot be sent */
585 for (m = m_seg->next; m != NULL; m = m_next) {
587 rte_pktmbuf_free_seg(m);
590 /* Ignore the rest of the segment */
594 sfc_ef10_tx_qdesc_dma_create(frag_addr, frag_len,
595 eop, &txq->txq_hw_ring[id]);
597 } while (seg_len != 0);
599 txq->sw_ring[id].mbuf = m_seg;
605 * Free segments which content was entirely copied to the TSO header
606 * memory space of Tx queue
608 for (m_seg = first_m_seg; m_seg != m_seg_to_free_up_to;) {
609 struct rte_mbuf *seg_to_free = m_seg;
612 rte_pktmbuf_free_seg(seg_to_free);
619 sfc_ef10_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
621 struct sfc_ef10_txq * const txq = sfc_ef10_txq_by_dp_txq(tx_queue);
623 unsigned int dma_desc_space;
625 struct rte_mbuf **pktp;
626 struct rte_mbuf **pktp_end;
628 if (unlikely(txq->flags &
629 (SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION)))
633 dma_desc_space = txq->max_fill_level - (added - txq->completed);
635 reap_done = (dma_desc_space < txq->free_thresh);
637 sfc_ef10_tx_reap(txq);
638 dma_desc_space = txq->max_fill_level - (added - txq->completed);
641 for (pktp = &tx_pkts[0], pktp_end = &tx_pkts[nb_pkts];
644 struct rte_mbuf *m_seg = *pktp;
645 unsigned int pkt_start = added;
648 if (likely(pktp + 1 != pktp_end))
649 rte_mbuf_prefetch_part1(pktp[1]);
651 if (m_seg->ol_flags & PKT_TX_TCP_SEG) {
654 rc = sfc_ef10_xmit_tso_pkt(txq, m_seg, &added,
655 &dma_desc_space, &reap_done);
659 /* Packet can be sent in following xmit calls */
660 if (likely(rc == ENOSPC))
664 * Packet cannot be sent, tell RTE that
665 * it is sent, but actually drop it and
666 * continue with another packet
668 rte_pktmbuf_free(*pktp);
672 goto dma_desc_space_update;
675 if (sfc_ef10_tx_pkt_descs_max(m_seg) > dma_desc_space) {
679 /* Push already prepared descriptors before polling */
680 if (added != txq->added) {
681 sfc_ef10_tx_qpush(txq, added, txq->added);
685 sfc_ef10_tx_reap(txq);
687 dma_desc_space = txq->max_fill_level -
688 (added - txq->completed);
689 if (sfc_ef10_tx_pkt_descs_max(m_seg) > dma_desc_space)
693 pkt_len = m_seg->pkt_len;
695 rte_iova_t seg_addr = rte_mbuf_data_iova(m_seg);
696 unsigned int seg_len = rte_pktmbuf_data_len(m_seg);
697 unsigned int id = added & txq->ptr_mask;
699 SFC_ASSERT(seg_len <= SFC_EF10_TX_DMA_DESC_LEN_MAX);
703 sfc_ef10_tx_qdesc_dma_create(seg_addr,
704 seg_len, (pkt_len == 0),
705 &txq->txq_hw_ring[id]);
708 * rte_pktmbuf_free() is commonly used in DPDK for
709 * recycling packets - the function checks every
710 * segment's reference counter and returns the
711 * buffer to its pool whenever possible;
712 * nevertheless, freeing mbuf segments one by one
713 * may entail some performance decline;
714 * from this point, sfc_efx_tx_reap() does the same job
715 * on its own and frees buffers in bulks (all mbufs
716 * within a bulk belong to the same pool);
717 * from this perspective, individual segment pointers
718 * must be associated with the corresponding SW
719 * descriptors independently so that only one loop
720 * is sufficient on reap to inspect all the buffers
722 txq->sw_ring[id].mbuf = m_seg;
726 } while ((m_seg = m_seg->next) != 0);
728 dma_desc_space_update:
729 dma_desc_space -= (added - pkt_start);
732 if (likely(added != txq->added)) {
733 sfc_ef10_tx_qpush(txq, added, txq->added);
737 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
739 sfc_ef10_tx_reap(txq);
742 return pktp - &tx_pkts[0];
746 sfc_ef10_simple_tx_reap(struct sfc_ef10_txq *txq)
748 const unsigned int old_read_ptr = txq->evq_read_ptr;
749 const unsigned int ptr_mask = txq->ptr_mask;
750 unsigned int completed = txq->completed;
751 unsigned int pending = completed;
753 pending += sfc_ef10_tx_process_events(txq);
755 if (pending != completed) {
756 struct rte_mbuf *bulk[SFC_TX_REAP_BULK_SIZE];
760 struct sfc_ef10_tx_sw_desc *txd;
762 txd = &txq->sw_ring[completed & ptr_mask];
764 if (nb == RTE_DIM(bulk)) {
765 rte_mempool_put_bulk(bulk[0]->pool,
770 bulk[nb++] = txd->mbuf;
771 } while (++completed != pending);
773 rte_mempool_put_bulk(bulk[0]->pool, (void *)bulk, nb);
775 txq->completed = completed;
778 sfc_ef10_ev_qclear(txq->evq_hw_ring, ptr_mask, old_read_ptr,
782 #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
784 sfc_ef10_simple_prepare_pkts(__rte_unused void *tx_queue,
785 struct rte_mbuf **tx_pkts,
790 for (i = 0; i < nb_pkts; i++) {
791 struct rte_mbuf *m = tx_pkts[i];
794 ret = rte_validate_tx_offload(m);
795 if (unlikely(ret != 0)) {
797 * Negative error code is returned by
798 * rte_validate_tx_offload(), but positive are used
799 * inside net/sfc PMD.
806 /* ef10_simple does not support TSO and VLAN insertion */
807 if (unlikely(m->ol_flags &
808 (PKT_TX_TCP_SEG | PKT_TX_VLAN_PKT))) {
813 /* ef10_simple does not support scattered packets */
814 if (unlikely(m->nb_segs != 1)) {
820 * ef10_simple requires fast-free which ignores reference
823 if (unlikely(rte_mbuf_refcnt_read(m) != 1)) {
828 /* ef10_simple requires single pool for all packets */
829 if (unlikely(m->pool != tx_pkts[0]->pool)) {
840 sfc_ef10_simple_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
843 struct sfc_ef10_txq * const txq = sfc_ef10_txq_by_dp_txq(tx_queue);
844 unsigned int ptr_mask;
846 unsigned int dma_desc_space;
848 struct rte_mbuf **pktp;
849 struct rte_mbuf **pktp_end;
851 if (unlikely(txq->flags &
852 (SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION)))
855 ptr_mask = txq->ptr_mask;
857 dma_desc_space = txq->max_fill_level - (added - txq->completed);
859 reap_done = (dma_desc_space < RTE_MAX(txq->free_thresh, nb_pkts));
861 sfc_ef10_simple_tx_reap(txq);
862 dma_desc_space = txq->max_fill_level - (added - txq->completed);
865 pktp_end = &tx_pkts[MIN(nb_pkts, dma_desc_space)];
866 for (pktp = &tx_pkts[0]; pktp != pktp_end; ++pktp) {
867 struct rte_mbuf *pkt = *pktp;
868 unsigned int id = added & ptr_mask;
870 SFC_ASSERT(rte_pktmbuf_data_len(pkt) <=
871 SFC_EF10_TX_DMA_DESC_LEN_MAX);
873 sfc_ef10_tx_qdesc_dma_create(rte_mbuf_data_iova(pkt),
874 rte_pktmbuf_data_len(pkt),
875 true, &txq->txq_hw_ring[id]);
877 txq->sw_ring[id].mbuf = pkt;
882 if (likely(added != txq->added)) {
883 sfc_ef10_tx_qpush(txq, added, txq->added);
887 #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE
889 sfc_ef10_simple_tx_reap(txq);
892 return pktp - &tx_pkts[0];
895 static sfc_dp_tx_get_dev_info_t sfc_ef10_get_dev_info;
897 sfc_ef10_get_dev_info(struct rte_eth_dev_info *dev_info)
900 * Number of descriptors just defines maximum number of pushed
901 * descriptors (fill level).
903 dev_info->tx_desc_lim.nb_min = 1;
904 dev_info->tx_desc_lim.nb_align = 1;
907 static sfc_dp_tx_qsize_up_rings_t sfc_ef10_tx_qsize_up_rings;
909 sfc_ef10_tx_qsize_up_rings(uint16_t nb_tx_desc,
910 struct sfc_dp_tx_hw_limits *limits,
911 unsigned int *txq_entries,
912 unsigned int *evq_entries,
913 unsigned int *txq_max_fill_level)
916 * rte_ethdev API guarantees that the number meets min, max and
917 * alignment requirements.
919 if (nb_tx_desc <= limits->txq_min_entries)
920 *txq_entries = limits->txq_min_entries;
922 *txq_entries = rte_align32pow2(nb_tx_desc);
924 *evq_entries = *txq_entries;
926 *txq_max_fill_level = RTE_MIN(nb_tx_desc,
927 SFC_EF10_TXQ_LIMIT(*evq_entries));
931 static sfc_dp_tx_qcreate_t sfc_ef10_tx_qcreate;
933 sfc_ef10_tx_qcreate(uint16_t port_id, uint16_t queue_id,
934 const struct rte_pci_addr *pci_addr, int socket_id,
935 const struct sfc_dp_tx_qcreate_info *info,
936 struct sfc_dp_txq **dp_txqp)
938 struct sfc_ef10_txq *txq;
942 if (info->txq_entries != info->evq_entries)
946 txq = rte_zmalloc_socket("sfc-ef10-txq", sizeof(*txq),
947 RTE_CACHE_LINE_SIZE, socket_id);
951 sfc_dp_queue_init(&txq->dp.dpq, port_id, queue_id, pci_addr);
954 txq->sw_ring = rte_calloc_socket("sfc-ef10-txq-sw_ring",
956 sizeof(*txq->sw_ring),
957 RTE_CACHE_LINE_SIZE, socket_id);
958 if (txq->sw_ring == NULL)
959 goto fail_sw_ring_alloc;
961 if (info->offloads & (DEV_TX_OFFLOAD_TCP_TSO |
962 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
963 DEV_TX_OFFLOAD_GENEVE_TNL_TSO)) {
964 txq->tsoh = rte_calloc_socket("sfc-ef10-txq-tsoh",
969 if (txq->tsoh == NULL)
970 goto fail_tsoh_alloc;
972 txq->tsoh_iova = rte_malloc_virt2iova(txq->tsoh);
975 txq->flags = SFC_EF10_TXQ_NOT_RUNNING;
976 txq->ptr_mask = info->txq_entries - 1;
977 txq->max_fill_level = info->max_fill_level;
978 txq->free_thresh = info->free_thresh;
979 txq->txq_hw_ring = info->txq_hw_ring;
980 txq->doorbell = (volatile uint8_t *)info->mem_bar +
981 ER_DZ_TX_DESC_UPD_REG_OFST +
982 (info->hw_index << info->vi_window_shift);
983 txq->evq_hw_ring = info->evq_hw_ring;
984 txq->tso_tcp_header_offset_limit = info->tso_tcp_header_offset_limit;
986 sfc_ef10_tx_info(&txq->dp.dpq, "TxQ doorbell is %p", txq->doorbell);
992 rte_free(txq->sw_ring);
1002 static sfc_dp_tx_qdestroy_t sfc_ef10_tx_qdestroy;
1004 sfc_ef10_tx_qdestroy(struct sfc_dp_txq *dp_txq)
1006 struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1008 rte_free(txq->tsoh);
1009 rte_free(txq->sw_ring);
1013 static sfc_dp_tx_qstart_t sfc_ef10_tx_qstart;
1015 sfc_ef10_tx_qstart(struct sfc_dp_txq *dp_txq, unsigned int evq_read_ptr,
1016 unsigned int txq_desc_index)
1018 struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1020 txq->evq_read_ptr = evq_read_ptr;
1021 txq->added = txq->completed = txq_desc_index;
1023 txq->flags |= SFC_EF10_TXQ_STARTED;
1024 txq->flags &= ~(SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION);
1029 static sfc_dp_tx_qstop_t sfc_ef10_tx_qstop;
1031 sfc_ef10_tx_qstop(struct sfc_dp_txq *dp_txq, unsigned int *evq_read_ptr)
1033 struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1035 txq->flags |= SFC_EF10_TXQ_NOT_RUNNING;
1037 *evq_read_ptr = txq->evq_read_ptr;
1040 static sfc_dp_tx_qtx_ev_t sfc_ef10_tx_qtx_ev;
1042 sfc_ef10_tx_qtx_ev(struct sfc_dp_txq *dp_txq, __rte_unused unsigned int id)
1044 __rte_unused struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1046 SFC_ASSERT(txq->flags & SFC_EF10_TXQ_NOT_RUNNING);
1049 * It is safe to ignore Tx event since we reap all mbufs on
1050 * queue purge anyway.
1056 static sfc_dp_tx_qreap_t sfc_ef10_tx_qreap;
1058 sfc_ef10_tx_qreap(struct sfc_dp_txq *dp_txq)
1060 struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1061 unsigned int completed;
1063 for (completed = txq->completed; completed != txq->added; ++completed) {
1064 struct sfc_ef10_tx_sw_desc *txd;
1066 txd = &txq->sw_ring[completed & txq->ptr_mask];
1067 if (txd->mbuf != NULL) {
1068 rte_pktmbuf_free_seg(txd->mbuf);
1073 txq->flags &= ~SFC_EF10_TXQ_STARTED;
1077 sfc_ef10_tx_qdesc_npending(struct sfc_ef10_txq *txq)
1079 const unsigned int curr_done = txq->completed - 1;
1080 unsigned int anew_done = curr_done;
1082 const unsigned int evq_old_read_ptr = txq->evq_read_ptr;
1084 if (unlikely(txq->flags &
1085 (SFC_EF10_TXQ_NOT_RUNNING | SFC_EF10_TXQ_EXCEPTION)))
1088 while (sfc_ef10_tx_get_event(txq, &tx_ev))
1089 anew_done = EFX_QWORD_FIELD(tx_ev, ESF_DZ_TX_DESCR_INDX);
1092 * The function does not process events, so return event queue read
1093 * pointer to the original position to allow the events that were
1094 * read to be processed later
1096 txq->evq_read_ptr = evq_old_read_ptr;
1098 return (anew_done - curr_done) & txq->ptr_mask;
1101 static sfc_dp_tx_qdesc_status_t sfc_ef10_tx_qdesc_status;
1103 sfc_ef10_tx_qdesc_status(struct sfc_dp_txq *dp_txq,
1106 struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq);
1107 unsigned int npending = sfc_ef10_tx_qdesc_npending(txq);
1109 if (unlikely(offset > txq->ptr_mask))
1112 if (unlikely(offset >= txq->max_fill_level))
1113 return RTE_ETH_TX_DESC_UNAVAIL;
1115 if (unlikely(offset < npending))
1116 return RTE_ETH_TX_DESC_FULL;
1118 return RTE_ETH_TX_DESC_DONE;
1121 struct sfc_dp_tx sfc_ef10_tx = {
1123 .name = SFC_KVARG_DATAPATH_EF10,
1125 .hw_fw_caps = SFC_DP_HW_FW_CAP_EF10,
1127 .features = SFC_DP_TX_FEAT_MULTI_PROCESS,
1128 .dev_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS,
1129 .queue_offload_capa = DEV_TX_OFFLOAD_IPV4_CKSUM |
1130 DEV_TX_OFFLOAD_UDP_CKSUM |
1131 DEV_TX_OFFLOAD_TCP_CKSUM |
1132 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
1133 DEV_TX_OFFLOAD_TCP_TSO |
1134 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
1135 DEV_TX_OFFLOAD_GENEVE_TNL_TSO,
1136 .get_dev_info = sfc_ef10_get_dev_info,
1137 .qsize_up_rings = sfc_ef10_tx_qsize_up_rings,
1138 .qcreate = sfc_ef10_tx_qcreate,
1139 .qdestroy = sfc_ef10_tx_qdestroy,
1140 .qstart = sfc_ef10_tx_qstart,
1141 .qtx_ev = sfc_ef10_tx_qtx_ev,
1142 .qstop = sfc_ef10_tx_qstop,
1143 .qreap = sfc_ef10_tx_qreap,
1144 .qdesc_status = sfc_ef10_tx_qdesc_status,
1145 .pkt_prepare = sfc_ef10_prepare_pkts,
1146 .pkt_burst = sfc_ef10_xmit_pkts,
1149 struct sfc_dp_tx sfc_ef10_simple_tx = {
1151 .name = SFC_KVARG_DATAPATH_EF10_SIMPLE,
1154 .features = SFC_DP_TX_FEAT_MULTI_PROCESS,
1155 .dev_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE,
1156 .queue_offload_capa = DEV_TX_OFFLOAD_IPV4_CKSUM |
1157 DEV_TX_OFFLOAD_UDP_CKSUM |
1158 DEV_TX_OFFLOAD_TCP_CKSUM |
1159 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM,
1160 .get_dev_info = sfc_ef10_get_dev_info,
1161 .qsize_up_rings = sfc_ef10_tx_qsize_up_rings,
1162 .qcreate = sfc_ef10_tx_qcreate,
1163 .qdestroy = sfc_ef10_tx_qdestroy,
1164 .qstart = sfc_ef10_tx_qstart,
1165 .qtx_ev = sfc_ef10_tx_qtx_ev,
1166 .qstop = sfc_ef10_tx_qstop,
1167 .qreap = sfc_ef10_tx_qreap,
1168 .qdesc_status = sfc_ef10_tx_qdesc_status,
1169 #ifdef RTE_LIBRTE_SFC_EFX_DEBUG
1170 .pkt_prepare = sfc_ef10_simple_prepare_pkts,
1172 .pkt_burst = sfc_ef10_simple_xmit_pkts,