1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
10 /* EF10 native datapath implementation */
14 #include <rte_byteorder.h>
15 #include <rte_mbuf_ptype.h>
20 #include "efx_types.h"
22 #include "efx_regs_ef10.h"
24 #include "sfc_tweak.h"
25 #include "sfc_dp_rx.h"
26 #include "sfc_kvargs.h"
29 #define sfc_ef10_rx_err(dpq, ...) \
30 SFC_DP_LOG(SFC_KVARG_DATAPATH_EF10, ERR, dpq, __VA_ARGS__)
33 * Alignment requirement for value written to RX WPTR:
34 * the WPTR must be aligned to an 8 descriptor boundary.
36 #define SFC_EF10_RX_WPTR_ALIGN 8
39 * Maximum number of descriptors/buffers in the Rx ring.
40 * It should guarantee that corresponding event queue never overfill.
41 * EF10 native datapath uses event queue of the same size as Rx queue.
42 * Maximum number of events on datapath can be estimated as number of
43 * Rx queue entries (one event per Rx buffer in the worst case) plus
44 * Rx error and flush events.
46 #define SFC_EF10_RXQ_LIMIT(_ndesc) \
47 ((_ndesc) - 1 /* head must not step on tail */ - \
48 (SFC_EF10_EV_PER_CACHE_LINE - 1) /* max unused EvQ entries */ - \
49 1 /* Rx error */ - 1 /* flush */)
51 struct sfc_ef10_rx_sw_desc {
52 struct rte_mbuf *mbuf;
56 /* Used on data path */
58 #define SFC_EF10_RXQ_STARTED 0x1
59 #define SFC_EF10_RXQ_NOT_RUNNING 0x2
60 #define SFC_EF10_RXQ_EXCEPTION 0x4
61 #define SFC_EF10_RXQ_RSS_HASH 0x8
62 unsigned int ptr_mask;
63 unsigned int prepared;
64 unsigned int completed;
65 unsigned int evq_read_ptr;
66 efx_qword_t *evq_hw_ring;
67 struct sfc_ef10_rx_sw_desc *sw_ring;
74 unsigned int max_fill_level;
75 unsigned int refill_threshold;
76 struct rte_mempool *refill_mb_pool;
77 efx_qword_t *rxq_hw_ring;
78 volatile void *doorbell;
80 /* Datapath receive queue anchor */
84 static inline struct sfc_ef10_rxq *
85 sfc_ef10_rxq_by_dp_rxq(struct sfc_dp_rxq *dp_rxq)
87 return container_of(dp_rxq, struct sfc_ef10_rxq, dp);
91 sfc_ef10_rx_qpush(struct sfc_ef10_rxq *rxq)
95 /* Hardware has alignment restriction for WPTR */
96 RTE_BUILD_BUG_ON(SFC_RX_REFILL_BULK % SFC_EF10_RX_WPTR_ALIGN != 0);
97 SFC_ASSERT(RTE_ALIGN(rxq->added, SFC_EF10_RX_WPTR_ALIGN) == rxq->added);
99 EFX_POPULATE_DWORD_1(dword, ERF_DZ_RX_DESC_WPTR,
100 rxq->added & rxq->ptr_mask);
102 /* DMA sync to device is not required */
105 * rte_write32() has rte_io_wmb() which guarantees that the STORE
106 * operations (i.e. Rx and event descriptor updates) that precede
107 * the rte_io_wmb() call are visible to NIC before the STORE
108 * operations that follow it (i.e. doorbell write).
110 rte_write32(dword.ed_u32[0], rxq->doorbell);
114 sfc_ef10_rx_qrefill(struct sfc_ef10_rxq *rxq)
116 const unsigned int ptr_mask = rxq->ptr_mask;
117 const uint32_t buf_size = rxq->buf_size;
118 unsigned int free_space;
120 void *objs[SFC_RX_REFILL_BULK];
121 unsigned int added = rxq->added;
123 free_space = rxq->max_fill_level - (added - rxq->completed);
125 if (free_space < rxq->refill_threshold)
128 bulks = free_space / RTE_DIM(objs);
129 /* refill_threshold guarantees that bulks is positive */
130 SFC_ASSERT(bulks > 0);
136 if (unlikely(rte_mempool_get_bulk(rxq->refill_mb_pool, objs,
137 RTE_DIM(objs)) < 0)) {
138 struct rte_eth_dev_data *dev_data =
139 rte_eth_devices[rxq->dp.dpq.port_id].data;
142 * It is hardly a safe way to increment counter
143 * from different contexts, but all PMDs do it.
145 dev_data->rx_mbuf_alloc_failed += RTE_DIM(objs);
146 /* Return if we have posted nothing yet */
147 if (added == rxq->added)
153 for (i = 0, id = added & ptr_mask;
156 struct rte_mbuf *m = objs[i];
157 struct sfc_ef10_rx_sw_desc *rxd;
158 rte_iova_t phys_addr;
160 SFC_ASSERT((id & ~ptr_mask) == 0);
161 rxd = &rxq->sw_ring[id];
165 * Avoid writing to mbuf. It is cheaper to do it
166 * when we receive packet and fill in nearby
170 phys_addr = rte_mbuf_data_iova_default(m);
171 EFX_POPULATE_QWORD_2(rxq->rxq_hw_ring[id],
172 ESF_DZ_RX_KER_BYTE_CNT, buf_size,
173 ESF_DZ_RX_KER_BUF_ADDR, phys_addr);
176 added += RTE_DIM(objs);
177 } while (--bulks > 0);
179 SFC_ASSERT(rxq->added != added);
181 sfc_ef10_rx_qpush(rxq);
185 sfc_ef10_rx_prefetch_next(struct sfc_ef10_rxq *rxq, unsigned int next_id)
187 struct rte_mbuf *next_mbuf;
189 /* Prefetch next bunch of software descriptors */
190 if ((next_id % (RTE_CACHE_LINE_SIZE / sizeof(rxq->sw_ring[0]))) == 0)
191 rte_prefetch0(&rxq->sw_ring[next_id]);
194 * It looks strange to prefetch depending on previous prefetch
195 * data, but measurements show that it is really efficient and
196 * increases packet rate.
198 next_mbuf = rxq->sw_ring[next_id].mbuf;
199 if (likely(next_mbuf != NULL)) {
200 /* Prefetch the next mbuf structure */
201 rte_mbuf_prefetch_part1(next_mbuf);
203 /* Prefetch pseudo header of the next packet */
204 /* data_off is not filled in yet */
205 /* Yes, data could be not ready yet, but we hope */
206 rte_prefetch0((uint8_t *)next_mbuf->buf_addr +
207 RTE_PKTMBUF_HEADROOM);
212 sfc_ef10_rx_prepared(struct sfc_ef10_rxq *rxq, struct rte_mbuf **rx_pkts,
215 uint16_t n_rx_pkts = RTE_MIN(nb_pkts, rxq->prepared);
216 unsigned int completed = rxq->completed;
219 rxq->prepared -= n_rx_pkts;
220 rxq->completed = completed + n_rx_pkts;
222 for (i = 0; i < n_rx_pkts; ++i, ++completed)
223 rx_pkts[i] = rxq->sw_ring[completed & rxq->ptr_mask].mbuf;
229 sfc_ef10_rx_ev_to_offloads(struct sfc_ef10_rxq *rxq, const efx_qword_t rx_ev,
232 uint32_t tun_ptype = 0;
233 /* Which event bit is mapped to PKT_RX_IP_CKSUM_* */
234 int8_t ip_csum_err_bit;
235 /* Which event bit is mapped to PKT_RX_L4_CKSUM_* */
236 int8_t l4_csum_err_bit;
237 uint32_t l2_ptype = 0;
238 uint32_t l3_ptype = 0;
239 uint32_t l4_ptype = 0;
240 uint64_t ol_flags = 0;
242 if (unlikely(EFX_TEST_QWORD_BIT(rx_ev, ESF_DZ_RX_PARSE_INCOMPLETE_LBN)))
245 switch (EFX_QWORD_FIELD(rx_ev, ESF_EZ_RX_ENCAP_HDR)) {
247 /* Unexpected encapsulation tag class */
250 case ESE_EZ_ENCAP_HDR_NONE:
252 case ESE_EZ_ENCAP_HDR_VXLAN:
254 * It is definitely UDP, but we have no information
255 * about IPv4 vs IPv6 and VLAN tagging.
257 tun_ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP;
259 case ESE_EZ_ENCAP_HDR_GRE:
261 * We have no information about IPv4 vs IPv6 and VLAN tagging.
263 tun_ptype = RTE_PTYPE_TUNNEL_NVGRE;
267 if (tun_ptype == 0) {
268 ip_csum_err_bit = ESF_DZ_RX_IPCKSUM_ERR_LBN;
269 l4_csum_err_bit = ESF_DZ_RX_TCPUDP_CKSUM_ERR_LBN;
271 ip_csum_err_bit = ESF_EZ_RX_IP_INNER_CHKSUM_ERR_LBN;
272 l4_csum_err_bit = ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR_LBN;
273 if (unlikely(EFX_TEST_QWORD_BIT(rx_ev,
274 ESF_DZ_RX_IPCKSUM_ERR_LBN)))
275 ol_flags |= PKT_RX_EIP_CKSUM_BAD;
278 switch (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_ETH_TAG_CLASS)) {
279 case ESE_DZ_ETH_TAG_CLASS_NONE:
280 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER :
281 RTE_PTYPE_INNER_L2_ETHER;
283 case ESE_DZ_ETH_TAG_CLASS_VLAN1:
284 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER_VLAN :
285 RTE_PTYPE_INNER_L2_ETHER_VLAN;
287 case ESE_DZ_ETH_TAG_CLASS_VLAN2:
288 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER_QINQ :
289 RTE_PTYPE_INNER_L2_ETHER_QINQ;
292 /* Unexpected Eth tag class */
296 switch (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_L3_CLASS)) {
297 case ESE_DZ_L3_CLASS_IP4_FRAG:
298 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_FRAG :
299 RTE_PTYPE_INNER_L4_FRAG;
301 case ESE_DZ_L3_CLASS_IP4:
302 l3_ptype = (tun_ptype == 0) ? RTE_PTYPE_L3_IPV4_EXT_UNKNOWN :
303 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
304 ol_flags |= PKT_RX_RSS_HASH |
305 ((EFX_TEST_QWORD_BIT(rx_ev, ip_csum_err_bit)) ?
306 PKT_RX_IP_CKSUM_BAD : PKT_RX_IP_CKSUM_GOOD);
308 case ESE_DZ_L3_CLASS_IP6_FRAG:
309 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_FRAG :
310 RTE_PTYPE_INNER_L4_FRAG;
312 case ESE_DZ_L3_CLASS_IP6:
313 l3_ptype = (tun_ptype == 0) ? RTE_PTYPE_L3_IPV6_EXT_UNKNOWN :
314 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
315 ol_flags |= PKT_RX_RSS_HASH;
317 case ESE_DZ_L3_CLASS_ARP:
318 /* Override Layer 2 packet type */
319 /* There is no ARP classification for inner packets */
321 l2_ptype = RTE_PTYPE_L2_ETHER_ARP;
324 /* Unexpected Layer 3 class */
329 * RX_L4_CLASS is 3 bits wide on Huntington and Medford, but is only
330 * 2 bits wide on Medford2. Check it is safe to use the Medford2 field
331 * and values for all EF10 controllers.
333 RTE_BUILD_BUG_ON(ESF_FZ_RX_L4_CLASS_LBN != ESF_DE_RX_L4_CLASS_LBN);
334 switch (EFX_QWORD_FIELD(rx_ev, ESF_FZ_RX_L4_CLASS)) {
335 case ESE_FZ_L4_CLASS_TCP:
336 RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_TCP != ESE_DE_L4_CLASS_TCP);
337 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_TCP :
338 RTE_PTYPE_INNER_L4_TCP;
340 (EFX_TEST_QWORD_BIT(rx_ev, l4_csum_err_bit)) ?
341 PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD;
343 case ESE_FZ_L4_CLASS_UDP:
344 RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_UDP != ESE_DE_L4_CLASS_UDP);
345 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_UDP :
346 RTE_PTYPE_INNER_L4_UDP;
348 (EFX_TEST_QWORD_BIT(rx_ev, l4_csum_err_bit)) ?
349 PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD;
351 case ESE_FZ_L4_CLASS_UNKNOWN:
352 RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_UNKNOWN !=
353 ESE_DE_L4_CLASS_UNKNOWN);
356 /* Unexpected Layer 4 class */
360 /* Remove RSS hash offload flag if RSS is not enabled */
361 if (~rxq->flags & SFC_EF10_RXQ_RSS_HASH)
362 ol_flags &= ~PKT_RX_RSS_HASH;
365 m->ol_flags = ol_flags;
366 m->packet_type = tun_ptype | l2_ptype | l3_ptype | l4_ptype;
370 sfc_ef10_rx_pseudo_hdr_get_len(const uint8_t *pseudo_hdr)
372 return rte_le_to_cpu_16(*(const uint16_t *)&pseudo_hdr[8]);
376 sfc_ef10_rx_pseudo_hdr_get_hash(const uint8_t *pseudo_hdr)
378 return rte_le_to_cpu_32(*(const uint32_t *)pseudo_hdr);
382 sfc_ef10_rx_process_event(struct sfc_ef10_rxq *rxq, efx_qword_t rx_ev,
383 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
385 const unsigned int ptr_mask = rxq->ptr_mask;
386 unsigned int completed = rxq->completed;
388 struct sfc_ef10_rx_sw_desc *rxd;
392 const uint8_t *pseudo_hdr;
395 ready = (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_DSC_PTR_LBITS) - completed) &
396 EFX_MASK32(ESF_DZ_RX_DSC_PTR_LBITS);
397 SFC_ASSERT(ready > 0);
399 if (rx_ev.eq_u64[0] &
400 rte_cpu_to_le_64((1ull << ESF_DZ_RX_ECC_ERR_LBN) |
401 (1ull << ESF_DZ_RX_ECRC_ERR_LBN))) {
402 SFC_ASSERT(rxq->prepared == 0);
403 rxq->completed += ready;
404 while (ready-- > 0) {
405 rxd = &rxq->sw_ring[completed++ & ptr_mask];
406 rte_mempool_put(rxq->refill_mb_pool, rxd->mbuf);
411 n_rx_pkts = RTE_MIN(ready, nb_pkts);
412 rxq->prepared = ready - n_rx_pkts;
413 rxq->completed += n_rx_pkts;
415 rxd = &rxq->sw_ring[completed++ & ptr_mask];
417 sfc_ef10_rx_prefetch_next(rxq, completed & ptr_mask);
423 RTE_BUILD_BUG_ON(sizeof(m->rearm_data[0]) != sizeof(rxq->rearm_data));
424 m->rearm_data[0] = rxq->rearm_data;
426 /* Classify packet based on Rx event */
427 sfc_ef10_rx_ev_to_offloads(rxq, rx_ev, m);
429 /* data_off already moved past pseudo header */
430 pseudo_hdr = (uint8_t *)m->buf_addr + RTE_PKTMBUF_HEADROOM;
433 * Always get RSS hash from pseudo header to avoid
434 * condition/branching. If it is valid or not depends on
435 * PKT_RX_RSS_HASH in m->ol_flags.
437 m->hash.rss = sfc_ef10_rx_pseudo_hdr_get_hash(pseudo_hdr);
440 pkt_len = EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_BYTES) -
443 pkt_len = sfc_ef10_rx_pseudo_hdr_get_len(pseudo_hdr);
444 SFC_ASSERT(pkt_len > 0);
445 rte_pktmbuf_data_len(m) = pkt_len;
446 rte_pktmbuf_pkt_len(m) = pkt_len;
448 SFC_ASSERT(m->next == NULL);
450 /* Remember mbuf to copy offload flags and packet type from */
452 for (--ready; ready > 0; --ready) {
453 rxd = &rxq->sw_ring[completed++ & ptr_mask];
455 sfc_ef10_rx_prefetch_next(rxq, completed & ptr_mask);
459 if (ready > rxq->prepared)
462 RTE_BUILD_BUG_ON(sizeof(m->rearm_data[0]) !=
463 sizeof(rxq->rearm_data));
464 m->rearm_data[0] = rxq->rearm_data;
466 /* Event-dependent information is the same */
467 m->ol_flags = m0->ol_flags;
468 m->packet_type = m0->packet_type;
470 /* data_off already moved past pseudo header */
471 pseudo_hdr = (uint8_t *)m->buf_addr + RTE_PKTMBUF_HEADROOM;
474 * Always get RSS hash from pseudo header to avoid
475 * condition/branching. If it is valid or not depends on
476 * PKT_RX_RSS_HASH in m->ol_flags.
478 m->hash.rss = sfc_ef10_rx_pseudo_hdr_get_hash(pseudo_hdr);
480 pkt_len = sfc_ef10_rx_pseudo_hdr_get_len(pseudo_hdr);
481 SFC_ASSERT(pkt_len > 0);
482 rte_pktmbuf_data_len(m) = pkt_len;
483 rte_pktmbuf_pkt_len(m) = pkt_len;
485 SFC_ASSERT(m->next == NULL);
492 sfc_ef10_rx_get_event(struct sfc_ef10_rxq *rxq, efx_qword_t *rx_ev)
494 *rx_ev = rxq->evq_hw_ring[rxq->evq_read_ptr & rxq->ptr_mask];
496 if (!sfc_ef10_ev_present(*rx_ev))
499 if (unlikely(EFX_QWORD_FIELD(*rx_ev, FSF_AZ_EV_CODE) !=
500 FSE_AZ_EV_CODE_RX_EV)) {
502 * Do not move read_ptr to keep the event for exception
503 * handling by the control path.
505 rxq->flags |= SFC_EF10_RXQ_EXCEPTION;
506 sfc_ef10_rx_err(&rxq->dp.dpq,
507 "RxQ exception at EvQ read ptr %#x",
517 sfc_ef10_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
519 struct sfc_ef10_rxq *rxq = sfc_ef10_rxq_by_dp_rxq(rx_queue);
520 unsigned int evq_old_read_ptr;
524 if (unlikely(rxq->flags &
525 (SFC_EF10_RXQ_NOT_RUNNING | SFC_EF10_RXQ_EXCEPTION)))
528 n_rx_pkts = sfc_ef10_rx_prepared(rxq, rx_pkts, nb_pkts);
530 evq_old_read_ptr = rxq->evq_read_ptr;
531 while (n_rx_pkts != nb_pkts && sfc_ef10_rx_get_event(rxq, &rx_ev)) {
533 * DROP_EVENT is an internal to the NIC, software should
534 * never see it and, therefore, may ignore it.
537 n_rx_pkts += sfc_ef10_rx_process_event(rxq, rx_ev,
539 nb_pkts - n_rx_pkts);
542 sfc_ef10_ev_qclear(rxq->evq_hw_ring, rxq->ptr_mask, evq_old_read_ptr,
545 /* It is not a problem if we refill in the case of exception */
546 sfc_ef10_rx_qrefill(rxq);
551 static const uint32_t *
552 sfc_ef10_supported_ptypes_get(uint32_t tunnel_encaps)
554 static const uint32_t ef10_native_ptypes[] = {
556 RTE_PTYPE_L2_ETHER_ARP,
557 RTE_PTYPE_L2_ETHER_VLAN,
558 RTE_PTYPE_L2_ETHER_QINQ,
559 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
560 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
566 static const uint32_t ef10_overlay_ptypes[] = {
568 RTE_PTYPE_L2_ETHER_ARP,
569 RTE_PTYPE_L2_ETHER_VLAN,
570 RTE_PTYPE_L2_ETHER_QINQ,
571 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
572 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
576 RTE_PTYPE_TUNNEL_VXLAN,
577 RTE_PTYPE_TUNNEL_NVGRE,
578 RTE_PTYPE_INNER_L2_ETHER,
579 RTE_PTYPE_INNER_L2_ETHER_VLAN,
580 RTE_PTYPE_INNER_L2_ETHER_QINQ,
581 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
582 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
583 RTE_PTYPE_INNER_L4_FRAG,
584 RTE_PTYPE_INNER_L4_TCP,
585 RTE_PTYPE_INNER_L4_UDP,
590 * The function returns static set of supported packet types,
591 * so we can't build it dynamically based on supported tunnel
592 * encapsulations and should limit to known sets.
594 switch (tunnel_encaps) {
595 case (1u << EFX_TUNNEL_PROTOCOL_VXLAN |
596 1u << EFX_TUNNEL_PROTOCOL_GENEVE |
597 1u << EFX_TUNNEL_PROTOCOL_NVGRE):
598 return ef10_overlay_ptypes;
601 "Unexpected set of supported tunnel encapsulations: %#x",
605 return ef10_native_ptypes;
609 static sfc_dp_rx_qdesc_npending_t sfc_ef10_rx_qdesc_npending;
611 sfc_ef10_rx_qdesc_npending(__rte_unused struct sfc_dp_rxq *dp_rxq)
614 * Correct implementation requires EvQ polling and events
615 * processing (keeping all ready mbufs in prepared).
620 static sfc_dp_rx_qdesc_status_t sfc_ef10_rx_qdesc_status;
622 sfc_ef10_rx_qdesc_status(__rte_unused struct sfc_dp_rxq *dp_rxq,
623 __rte_unused uint16_t offset)
629 static sfc_dp_rx_get_dev_info_t sfc_ef10_rx_get_dev_info;
631 sfc_ef10_rx_get_dev_info(struct rte_eth_dev_info *dev_info)
634 * Number of descriptors just defines maximum number of pushed
635 * descriptors (fill level).
637 dev_info->rx_desc_lim.nb_min = SFC_RX_REFILL_BULK;
638 dev_info->rx_desc_lim.nb_align = SFC_RX_REFILL_BULK;
642 static sfc_dp_rx_qsize_up_rings_t sfc_ef10_rx_qsize_up_rings;
644 sfc_ef10_rx_qsize_up_rings(uint16_t nb_rx_desc,
645 unsigned int *rxq_entries,
646 unsigned int *evq_entries,
647 unsigned int *rxq_max_fill_level)
650 * rte_ethdev API guarantees that the number meets min, max and
651 * alignment requirements.
653 if (nb_rx_desc <= EFX_RXQ_MINNDESCS)
654 *rxq_entries = EFX_RXQ_MINNDESCS;
656 *rxq_entries = rte_align32pow2(nb_rx_desc);
658 *evq_entries = *rxq_entries;
660 *rxq_max_fill_level = RTE_MIN(nb_rx_desc,
661 SFC_EF10_RXQ_LIMIT(*evq_entries));
667 sfc_ef10_mk_mbuf_rearm_data(uint16_t port_id, uint16_t prefix_size)
671 memset(&m, 0, sizeof(m));
673 rte_mbuf_refcnt_set(&m, 1);
674 m.data_off = RTE_PKTMBUF_HEADROOM + prefix_size;
678 /* rearm_data covers structure members filled in above */
679 rte_compiler_barrier();
680 RTE_BUILD_BUG_ON(sizeof(m.rearm_data[0]) != sizeof(uint64_t));
681 return m.rearm_data[0];
684 static sfc_dp_rx_qcreate_t sfc_ef10_rx_qcreate;
686 sfc_ef10_rx_qcreate(uint16_t port_id, uint16_t queue_id,
687 const struct rte_pci_addr *pci_addr, int socket_id,
688 const struct sfc_dp_rx_qcreate_info *info,
689 struct sfc_dp_rxq **dp_rxqp)
691 struct sfc_ef10_rxq *rxq;
695 if (info->rxq_entries != info->evq_entries)
699 rxq = rte_zmalloc_socket("sfc-ef10-rxq", sizeof(*rxq),
700 RTE_CACHE_LINE_SIZE, socket_id);
704 sfc_dp_queue_init(&rxq->dp.dpq, port_id, queue_id, pci_addr);
707 rxq->sw_ring = rte_calloc_socket("sfc-ef10-rxq-sw_ring",
709 sizeof(*rxq->sw_ring),
710 RTE_CACHE_LINE_SIZE, socket_id);
711 if (rxq->sw_ring == NULL)
712 goto fail_desc_alloc;
714 rxq->flags |= SFC_EF10_RXQ_NOT_RUNNING;
715 if (info->flags & SFC_RXQ_FLAG_RSS_HASH)
716 rxq->flags |= SFC_EF10_RXQ_RSS_HASH;
717 rxq->ptr_mask = info->rxq_entries - 1;
718 rxq->evq_hw_ring = info->evq_hw_ring;
719 rxq->max_fill_level = info->max_fill_level;
720 rxq->refill_threshold = info->refill_threshold;
722 sfc_ef10_mk_mbuf_rearm_data(port_id, info->prefix_size);
723 rxq->prefix_size = info->prefix_size;
724 rxq->buf_size = info->buf_size;
725 rxq->refill_mb_pool = info->refill_mb_pool;
726 rxq->rxq_hw_ring = info->rxq_hw_ring;
727 rxq->doorbell = (volatile uint8_t *)info->mem_bar +
728 ER_DZ_RX_DESC_UPD_REG_OFST +
729 (info->hw_index << info->vi_window_shift);
742 static sfc_dp_rx_qdestroy_t sfc_ef10_rx_qdestroy;
744 sfc_ef10_rx_qdestroy(struct sfc_dp_rxq *dp_rxq)
746 struct sfc_ef10_rxq *rxq = sfc_ef10_rxq_by_dp_rxq(dp_rxq);
748 rte_free(rxq->sw_ring);
752 static sfc_dp_rx_qstart_t sfc_ef10_rx_qstart;
754 sfc_ef10_rx_qstart(struct sfc_dp_rxq *dp_rxq, unsigned int evq_read_ptr)
756 struct sfc_ef10_rxq *rxq = sfc_ef10_rxq_by_dp_rxq(dp_rxq);
759 rxq->completed = rxq->added = 0;
761 sfc_ef10_rx_qrefill(rxq);
763 rxq->evq_read_ptr = evq_read_ptr;
765 rxq->flags |= SFC_EF10_RXQ_STARTED;
766 rxq->flags &= ~(SFC_EF10_RXQ_NOT_RUNNING | SFC_EF10_RXQ_EXCEPTION);
771 static sfc_dp_rx_qstop_t sfc_ef10_rx_qstop;
773 sfc_ef10_rx_qstop(struct sfc_dp_rxq *dp_rxq, unsigned int *evq_read_ptr)
775 struct sfc_ef10_rxq *rxq = sfc_ef10_rxq_by_dp_rxq(dp_rxq);
777 rxq->flags |= SFC_EF10_RXQ_NOT_RUNNING;
779 *evq_read_ptr = rxq->evq_read_ptr;
782 static sfc_dp_rx_qrx_ev_t sfc_ef10_rx_qrx_ev;
784 sfc_ef10_rx_qrx_ev(struct sfc_dp_rxq *dp_rxq, __rte_unused unsigned int id)
786 __rte_unused struct sfc_ef10_rxq *rxq = sfc_ef10_rxq_by_dp_rxq(dp_rxq);
788 SFC_ASSERT(rxq->flags & SFC_EF10_RXQ_NOT_RUNNING);
791 * It is safe to ignore Rx event since we free all mbufs on
792 * queue purge anyway.
798 static sfc_dp_rx_qpurge_t sfc_ef10_rx_qpurge;
800 sfc_ef10_rx_qpurge(struct sfc_dp_rxq *dp_rxq)
802 struct sfc_ef10_rxq *rxq = sfc_ef10_rxq_by_dp_rxq(dp_rxq);
804 struct sfc_ef10_rx_sw_desc *rxd;
806 for (i = rxq->completed; i != rxq->added; ++i) {
807 rxd = &rxq->sw_ring[i & rxq->ptr_mask];
808 rte_mempool_put(rxq->refill_mb_pool, rxd->mbuf);
812 rxq->flags &= ~SFC_EF10_RXQ_STARTED;
815 struct sfc_dp_rx sfc_ef10_rx = {
817 .name = SFC_KVARG_DATAPATH_EF10,
819 .hw_fw_caps = SFC_DP_HW_FW_CAP_EF10,
821 .features = SFC_DP_RX_FEAT_MULTI_PROCESS |
822 SFC_DP_RX_FEAT_TUNNELS,
823 .get_dev_info = sfc_ef10_rx_get_dev_info,
824 .qsize_up_rings = sfc_ef10_rx_qsize_up_rings,
825 .qcreate = sfc_ef10_rx_qcreate,
826 .qdestroy = sfc_ef10_rx_qdestroy,
827 .qstart = sfc_ef10_rx_qstart,
828 .qstop = sfc_ef10_rx_qstop,
829 .qrx_ev = sfc_ef10_rx_qrx_ev,
830 .qpurge = sfc_ef10_rx_qpurge,
831 .supported_ptypes_get = sfc_ef10_supported_ptypes_get,
832 .qdesc_npending = sfc_ef10_rx_qdesc_npending,
833 .qdesc_status = sfc_ef10_rx_qdesc_status,
834 .pkt_burst = sfc_ef10_recv_pkts,