1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2017-2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
13 #include "sfc_debug.h"
19 /* Number of events in one cache line */
20 #define SFC_EF10_EV_PER_CACHE_LINE \
21 (RTE_CACHE_LINE_SIZE / sizeof(efx_qword_t))
23 #define SFC_EF10_EV_QCLEAR_MASK (~(SFC_EF10_EV_PER_CACHE_LINE - 1))
26 * Use simple libefx-based implementation of the
27 * sfc_ef10_ev_qclear_cache_line() if SSE2 is not available
28 * since optimized implementation uses __m128i intrinsics.
31 #define SFC_EF10_EV_QCLEAR_USE_EFX
34 #if defined(SFC_EF10_EV_QCLEAR_USE_EFX)
36 sfc_ef10_ev_qclear_cache_line(void *ptr)
38 efx_qword_t *entry = ptr;
41 for (i = 0; i < SFC_EF10_EV_PER_CACHE_LINE; ++i)
42 EFX_SET_QWORD(entry[i]);
46 * It is possible to do it using AVX2 and AVX512F, but it shows less
50 sfc_ef10_ev_qclear_cache_line(void *ptr)
52 const efsys_uint128_t val = _mm_set1_epi64x(UINT64_MAX);
53 efsys_uint128_t *addr = ptr;
56 RTE_BUILD_BUG_ON(sizeof(val) > RTE_CACHE_LINE_SIZE);
57 RTE_BUILD_BUG_ON(RTE_CACHE_LINE_SIZE % sizeof(val) != 0);
59 for (i = 0; i < RTE_CACHE_LINE_SIZE / sizeof(val); ++i)
60 _mm_store_si128(&addr[i], val);
65 sfc_ef10_ev_qclear(efx_qword_t *hw_ring, unsigned int ptr_mask,
66 unsigned int old_read_ptr, unsigned int read_ptr)
68 const unsigned int clear_ptr = read_ptr & SFC_EF10_EV_QCLEAR_MASK;
69 unsigned int old_clear_ptr = old_read_ptr & SFC_EF10_EV_QCLEAR_MASK;
71 while (old_clear_ptr != clear_ptr) {
72 sfc_ef10_ev_qclear_cache_line(
73 &hw_ring[old_clear_ptr & ptr_mask]);
74 old_clear_ptr += SFC_EF10_EV_PER_CACHE_LINE;
79 * Functions which push doorbell should care about correct
80 * ordering: store instructions which fill in EvQ ring should be
81 * retired from CPU and DMA sync before doorbell which will allow
82 * to use these event entries.
87 sfc_ef10_ev_present(const efx_qword_t ev)
89 return ~EFX_QWORD_FIELD(ev, EFX_DWORD_0) |
90 ~EFX_QWORD_FIELD(ev, EFX_DWORD_1);
95 * Alignment requirement for value written to RX WPTR:
96 * the WPTR must be aligned to an 8 descriptor boundary.
98 #define SFC_EF10_RX_WPTR_ALIGN 8u
101 sfc_ef10_rx_qpush(volatile void *doorbell, unsigned int added,
102 unsigned int ptr_mask, uint32_t *dbell_counter)
106 /* Hardware has alignment restriction for WPTR */
107 RTE_BUILD_BUG_ON(SFC_RX_REFILL_BULK % SFC_EF10_RX_WPTR_ALIGN != 0);
108 SFC_ASSERT(RTE_ALIGN(added, SFC_EF10_RX_WPTR_ALIGN) == added);
110 EFX_POPULATE_DWORD_1(dword, ERF_DZ_RX_DESC_WPTR, added & ptr_mask);
112 /* DMA sync to device is not required */
115 * rte_write32() has rte_io_wmb() which guarantees that the STORE
116 * operations (i.e. Rx and event descriptor updates) that precede
117 * the rte_io_wmb() call are visible to NIC before the STORE
118 * operations that follow it (i.e. doorbell write).
120 rte_write32(dword.ed_u32[0], doorbell);
125 sfc_ef10_ev_qprime(volatile void *qprime, unsigned int read_ptr,
126 unsigned int ptr_mask)
130 EFX_POPULATE_DWORD_1(dword, ERF_DZ_EVQ_RPTR, read_ptr & ptr_mask);
132 rte_write32_relaxed(dword.ed_u32[0], qprime);
137 const uint32_t * sfc_ef10_supported_ptypes_get(uint32_t tunnel_encaps);
143 #endif /* _SFC_EF10_H */