net/hns3: support SVE Rx
[dpdk.git] / drivers / net / sfc / sfc_ef10.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2020 Xilinx, Inc.
4  * Copyright(c) 2017-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 #ifndef _SFC_EF10_H
11 #define _SFC_EF10_H
12
13 #include "sfc_debug.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
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))
22
23 #define SFC_EF10_EV_QCLEAR_MASK         (~(SFC_EF10_EV_PER_CACHE_LINE - 1))
24
25 #if defined(SFC_EF10_EV_QCLEAR_USE_EFX)
26 static inline void
27 sfc_ef10_ev_qclear_cache_line(void *ptr)
28 {
29         efx_qword_t *entry = ptr;
30         unsigned int i;
31
32         for (i = 0; i < SFC_EF10_EV_PER_CACHE_LINE; ++i)
33                 EFX_SET_QWORD(entry[i]);
34 }
35 #else
36 /*
37  * It is possible to do it using AVX2 and AVX512F, but it shows less
38  * performance.
39  */
40 static inline void
41 sfc_ef10_ev_qclear_cache_line(void *ptr)
42 {
43         const __m128i val = _mm_set1_epi64x(UINT64_MAX);
44         __m128i *addr = ptr;
45         unsigned int i;
46
47         RTE_BUILD_BUG_ON(sizeof(val) > RTE_CACHE_LINE_SIZE);
48         RTE_BUILD_BUG_ON(RTE_CACHE_LINE_SIZE % sizeof(val) != 0);
49
50         for (i = 0; i < RTE_CACHE_LINE_SIZE / sizeof(val); ++i)
51                 _mm_store_si128(&addr[i], val);
52 }
53 #endif
54
55 static inline void
56 sfc_ef10_ev_qclear(efx_qword_t *hw_ring, unsigned int ptr_mask,
57                    unsigned int old_read_ptr, unsigned int read_ptr)
58 {
59         const unsigned int clear_ptr = read_ptr & SFC_EF10_EV_QCLEAR_MASK;
60         unsigned int old_clear_ptr = old_read_ptr & SFC_EF10_EV_QCLEAR_MASK;
61
62         while (old_clear_ptr != clear_ptr) {
63                 sfc_ef10_ev_qclear_cache_line(
64                         &hw_ring[old_clear_ptr & ptr_mask]);
65                 old_clear_ptr += SFC_EF10_EV_PER_CACHE_LINE;
66         }
67
68         /*
69          * No barriers here.
70          * Functions which push doorbell should care about correct
71          * ordering: store instructions which fill in EvQ ring should be
72          * retired from CPU and DMA sync before doorbell which will allow
73          * to use these event entries.
74          */
75 }
76
77 static inline bool
78 sfc_ef10_ev_present(const efx_qword_t ev)
79 {
80         return ~EFX_QWORD_FIELD(ev, EFX_DWORD_0) |
81                ~EFX_QWORD_FIELD(ev, EFX_DWORD_1);
82 }
83
84
85 /**
86  * Alignment requirement for value written to RX WPTR:
87  * the WPTR must be aligned to an 8 descriptor boundary.
88  */
89 #define SFC_EF10_RX_WPTR_ALIGN  8u
90
91 static inline void
92 sfc_ef10_rx_qpush(volatile void *doorbell, unsigned int added,
93                   unsigned int ptr_mask)
94 {
95         efx_dword_t dword;
96
97         /* Hardware has alignment restriction for WPTR */
98         RTE_BUILD_BUG_ON(SFC_RX_REFILL_BULK % SFC_EF10_RX_WPTR_ALIGN != 0);
99         SFC_ASSERT(RTE_ALIGN(added, SFC_EF10_RX_WPTR_ALIGN) == added);
100
101         EFX_POPULATE_DWORD_1(dword, ERF_DZ_RX_DESC_WPTR, added & ptr_mask);
102
103         /* DMA sync to device is not required */
104
105         /*
106          * rte_write32() has rte_io_wmb() which guarantees that the STORE
107          * operations (i.e. Rx and event descriptor updates) that precede
108          * the rte_io_wmb() call are visible to NIC before the STORE
109          * operations that follow it (i.e. doorbell write).
110          */
111         rte_write32(dword.ed_u32[0], doorbell);
112 }
113
114 static inline void
115 sfc_ef10_ev_qprime(volatile void *qprime, unsigned int read_ptr,
116                   unsigned int ptr_mask)
117 {
118         efx_dword_t dword;
119
120         EFX_POPULATE_DWORD_1(dword, ERF_DZ_EVQ_RPTR, read_ptr & ptr_mask);
121
122         rte_write32_relaxed(dword.ed_u32[0], qprime);
123         rte_wmb();
124 }
125
126
127 const uint32_t * sfc_ef10_supported_ptypes_get(uint32_t tunnel_encaps);
128
129
130 #ifdef __cplusplus
131 }
132 #endif
133 #endif /* _SFC_EF10_H */