xref: /freebsd/sys/dev/qat/include/common/adf_gen2_hw_data.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1a977168cSMichal Gulbicki /* SPDX-License-Identifier: BSD-3-Clause  */
2a977168cSMichal Gulbicki /* Copyright(c) 2021 Intel Corporation */
3a977168cSMichal Gulbicki #ifndef ADF_GEN2_HW_DATA_H_
4a977168cSMichal Gulbicki #define ADF_GEN2_HW_DATA_H_
5a977168cSMichal Gulbicki 
6a977168cSMichal Gulbicki #include "adf_accel_devices.h"
7a977168cSMichal Gulbicki #include "adf_cfg_common.h"
8a977168cSMichal Gulbicki 
9a977168cSMichal Gulbicki /* Transport access */
10a977168cSMichal Gulbicki #define ADF_BANK_INT_SRC_SEL_MASK_0 0x4444444CUL
11a977168cSMichal Gulbicki #define ADF_BANK_INT_SRC_SEL_MASK_X 0x44444444UL
12a977168cSMichal Gulbicki #define ADF_RING_CSR_RING_CONFIG 0x000
13a977168cSMichal Gulbicki #define ADF_RING_CSR_RING_LBASE 0x040
14a977168cSMichal Gulbicki #define ADF_RING_CSR_RING_UBASE 0x080
15a977168cSMichal Gulbicki #define ADF_RING_CSR_RING_HEAD 0x0C0
16a977168cSMichal Gulbicki #define ADF_RING_CSR_RING_TAIL 0x100
17a977168cSMichal Gulbicki #define ADF_RING_CSR_E_STAT 0x14C
18a977168cSMichal Gulbicki #define ADF_RING_CSR_INT_FLAG 0x170
19a977168cSMichal Gulbicki #define ADF_RING_CSR_INT_SRCSEL 0x174
20a977168cSMichal Gulbicki #define ADF_RING_CSR_INT_SRCSEL_2 0x178
21a977168cSMichal Gulbicki #define ADF_RING_CSR_INT_COL_EN 0x17C
22a977168cSMichal Gulbicki #define ADF_RING_CSR_INT_COL_CTL 0x180
23a977168cSMichal Gulbicki #define ADF_RING_CSR_INT_FLAG_AND_COL 0x184
24a977168cSMichal Gulbicki #define ADF_RING_CSR_INT_COL_CTL_ENABLE 0x80000000
25*266b0663SKrzysztof Zdziarski #define ADF_RING_CSR_ADDR_OFFSET 0x0
26a977168cSMichal Gulbicki #define ADF_RING_BUNDLE_SIZE 0x1000
27a977168cSMichal Gulbicki #define ADF_GEN2_RX_RINGS_OFFSET 8
28a977168cSMichal Gulbicki #define ADF_GEN2_TX_RINGS_MASK 0xFF
29a977168cSMichal Gulbicki 
30a977168cSMichal Gulbicki #define BUILD_RING_BASE_ADDR(addr, size)                                       \
31a977168cSMichal Gulbicki 	(((addr) >> 6) & (GENMASK_ULL(63, 0) << (size)))
32a977168cSMichal Gulbicki #define READ_CSR_RING_HEAD(csr_base_addr, bank, ring)                          \
33a977168cSMichal Gulbicki 	ADF_CSR_RD(csr_base_addr,                                              \
34a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_RING_HEAD +  \
35a977168cSMichal Gulbicki 		       ((ring) << 2))
36a977168cSMichal Gulbicki #define READ_CSR_RING_TAIL(csr_base_addr, bank, ring)                          \
37a977168cSMichal Gulbicki 	ADF_CSR_RD(csr_base_addr,                                              \
38a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_RING_TAIL +  \
39a977168cSMichal Gulbicki 		       ((ring) << 2))
40a977168cSMichal Gulbicki #define READ_CSR_E_STAT(csr_base_addr, bank)                                   \
41a977168cSMichal Gulbicki 	ADF_CSR_RD(csr_base_addr,                                              \
42a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_E_STAT)
43a977168cSMichal Gulbicki #define WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value)                \
44a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_base_addr,                                              \
45a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) +                           \
46a977168cSMichal Gulbicki 		       ADF_RING_CSR_RING_CONFIG + ((ring) << 2),               \
47a977168cSMichal Gulbicki 		   value)
48*266b0663SKrzysztof Zdziarski 
49*266b0663SKrzysztof Zdziarski static inline uint64_t
read_base(struct resource * csr_base_addr,u32 bank,u32 ring)50*266b0663SKrzysztof Zdziarski read_base(struct resource *csr_base_addr, u32 bank, u32 ring)
51*266b0663SKrzysztof Zdziarski {
52*266b0663SKrzysztof Zdziarski 	u32 l_base, u_base;
53*266b0663SKrzysztof Zdziarski 	u64 addr;
54*266b0663SKrzysztof Zdziarski 
55*266b0663SKrzysztof Zdziarski 	l_base = ADF_CSR_RD(csr_base_addr,
56*266b0663SKrzysztof Zdziarski 			    (ADF_RING_BUNDLE_SIZE * bank) +
57*266b0663SKrzysztof Zdziarski 				ADF_RING_CSR_RING_LBASE + (ring << 2));
58*266b0663SKrzysztof Zdziarski 	u_base = ADF_CSR_RD(csr_base_addr,
59*266b0663SKrzysztof Zdziarski 			    (ADF_RING_BUNDLE_SIZE * bank) +
60*266b0663SKrzysztof Zdziarski 				ADF_RING_CSR_RING_UBASE + (ring << 2));
61*266b0663SKrzysztof Zdziarski 
62*266b0663SKrzysztof Zdziarski 	addr = (uint64_t)l_base & 0x00000000FFFFFFFFULL;
63*266b0663SKrzysztof Zdziarski 	addr |= (uint64_t)u_base << 32 & 0xFFFFFFFF00000000ULL;
64*266b0663SKrzysztof Zdziarski 
65*266b0663SKrzysztof Zdziarski 	return addr;
66*266b0663SKrzysztof Zdziarski }
67*266b0663SKrzysztof Zdziarski 
68*266b0663SKrzysztof Zdziarski #define READ_CSR_RING_BASE(csr_base_addr, bank, ring)                          \
69*266b0663SKrzysztof Zdziarski 	read_base(csr_base_addr, bank, ring)
70*266b0663SKrzysztof Zdziarski 
71a977168cSMichal Gulbicki #define WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, value)                  \
72a977168cSMichal Gulbicki 	do {                                                                   \
73a977168cSMichal Gulbicki 		u32 l_base = 0, u_base = 0;                                    \
74a977168cSMichal Gulbicki 		l_base = (u32)((value)&0xFFFFFFFF);                            \
75a977168cSMichal Gulbicki 		u_base = (u32)(((value)&0xFFFFFFFF00000000ULL) >> 32);         \
76a977168cSMichal Gulbicki 		ADF_CSR_WR(csr_base_addr,                                      \
77a977168cSMichal Gulbicki 			   (ADF_RING_BUNDLE_SIZE * (bank)) +                   \
78a977168cSMichal Gulbicki 			       ADF_RING_CSR_RING_LBASE + ((ring) << 2),        \
79a977168cSMichal Gulbicki 			   l_base);                                            \
80a977168cSMichal Gulbicki 		ADF_CSR_WR(csr_base_addr,                                      \
81a977168cSMichal Gulbicki 			   (ADF_RING_BUNDLE_SIZE * (bank)) +                   \
82a977168cSMichal Gulbicki 			       ADF_RING_CSR_RING_UBASE + ((ring) << 2),        \
83a977168cSMichal Gulbicki 			   u_base);                                            \
84a977168cSMichal Gulbicki 	} while (0)
85a977168cSMichal Gulbicki 
86a977168cSMichal Gulbicki #define WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value)                  \
87a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_base_addr,                                              \
88a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_RING_HEAD +  \
89a977168cSMichal Gulbicki 		       ((ring) << 2),                                          \
90a977168cSMichal Gulbicki 		   value)
91a977168cSMichal Gulbicki #define WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value)                  \
92a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_base_addr,                                              \
93a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_RING_TAIL +  \
94a977168cSMichal Gulbicki 		       ((ring) << 2),                                          \
95a977168cSMichal Gulbicki 		   value)
96a977168cSMichal Gulbicki #define WRITE_CSR_INT_FLAG(csr_base_addr, bank, value)                         \
97a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_base_addr,                                              \
98a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_INT_FLAG,    \
99a977168cSMichal Gulbicki 		   value)
100a977168cSMichal Gulbicki #define WRITE_CSR_INT_SRCSEL(csr_base_addr, bank)                              \
101a977168cSMichal Gulbicki 	do {                                                                   \
102a977168cSMichal Gulbicki 		ADF_CSR_WR(csr_base_addr,                                      \
103a977168cSMichal Gulbicki 			   (ADF_RING_BUNDLE_SIZE * (bank)) +                   \
104a977168cSMichal Gulbicki 			       ADF_RING_CSR_INT_SRCSEL,                        \
105a977168cSMichal Gulbicki 			   ADF_BANK_INT_SRC_SEL_MASK_0);                       \
106a977168cSMichal Gulbicki 		ADF_CSR_WR(csr_base_addr,                                      \
107a977168cSMichal Gulbicki 			   (ADF_RING_BUNDLE_SIZE * (bank)) +                   \
108a977168cSMichal Gulbicki 			       ADF_RING_CSR_INT_SRCSEL_2,                      \
109a977168cSMichal Gulbicki 			   ADF_BANK_INT_SRC_SEL_MASK_X);                       \
110a977168cSMichal Gulbicki 	} while (0)
111a977168cSMichal Gulbicki #define WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value)                       \
112a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_base_addr,                                              \
113a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_INT_COL_EN,  \
114a977168cSMichal Gulbicki 		   value)
115a977168cSMichal Gulbicki #define WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value)                      \
116a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_base_addr,                                              \
117a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) + ADF_RING_CSR_INT_COL_CTL, \
118a977168cSMichal Gulbicki 		   ADF_RING_CSR_INT_COL_CTL_ENABLE | (value))
119a977168cSMichal Gulbicki #define WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value)                 \
120a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_base_addr,                                              \
121a977168cSMichal Gulbicki 		   (ADF_RING_BUNDLE_SIZE * (bank)) +                           \
122a977168cSMichal Gulbicki 		       ADF_RING_CSR_INT_FLAG_AND_COL,                          \
123a977168cSMichal Gulbicki 		   value)
124a977168cSMichal Gulbicki 
125a977168cSMichal Gulbicki /* AE to function map */
126a977168cSMichal Gulbicki #define AE2FUNCTION_MAP_A_OFFSET (0x3A400 + 0x190)
127a977168cSMichal Gulbicki #define AE2FUNCTION_MAP_B_OFFSET (0x3A400 + 0x310)
128a977168cSMichal Gulbicki #define AE2FUNCTION_MAP_REG_SIZE 4
129a977168cSMichal Gulbicki #define AE2FUNCTION_MAP_VALID BIT(7)
130a977168cSMichal Gulbicki 
131a977168cSMichal Gulbicki #define READ_CSR_AE2FUNCTION_MAP_A(pmisc_bar_addr, index)                      \
132a977168cSMichal Gulbicki 	ADF_CSR_RD(pmisc_bar_addr,                                             \
133a977168cSMichal Gulbicki 		   AE2FUNCTION_MAP_A_OFFSET +                                  \
134a977168cSMichal Gulbicki 		       AE2FUNCTION_MAP_REG_SIZE * (index))
135a977168cSMichal Gulbicki #define WRITE_CSR_AE2FUNCTION_MAP_A(pmisc_bar_addr, index, value)              \
136a977168cSMichal Gulbicki 	ADF_CSR_WR(pmisc_bar_addr,                                             \
137a977168cSMichal Gulbicki 		   AE2FUNCTION_MAP_A_OFFSET +                                  \
138a977168cSMichal Gulbicki 		       AE2FUNCTION_MAP_REG_SIZE * (index),                     \
139a977168cSMichal Gulbicki 		   value)
140a977168cSMichal Gulbicki #define READ_CSR_AE2FUNCTION_MAP_B(pmisc_bar_addr, index)                      \
141a977168cSMichal Gulbicki 	ADF_CSR_RD(pmisc_bar_addr,                                             \
142a977168cSMichal Gulbicki 		   AE2FUNCTION_MAP_B_OFFSET +                                  \
143a977168cSMichal Gulbicki 		       AE2FUNCTION_MAP_REG_SIZE * (index))
144a977168cSMichal Gulbicki #define WRITE_CSR_AE2FUNCTION_MAP_B(pmisc_bar_addr, index, value)              \
145a977168cSMichal Gulbicki 	ADF_CSR_WR(pmisc_bar_addr,                                             \
146a977168cSMichal Gulbicki 		   AE2FUNCTION_MAP_B_OFFSET +                                  \
147a977168cSMichal Gulbicki 		       AE2FUNCTION_MAP_REG_SIZE * (index),                     \
148a977168cSMichal Gulbicki 		   value)
149a977168cSMichal Gulbicki 
150a977168cSMichal Gulbicki /* Admin Interface Offsets */
151a977168cSMichal Gulbicki #define ADF_ADMINMSGUR_OFFSET (0x3A000 + 0x574)
152a977168cSMichal Gulbicki #define ADF_ADMINMSGLR_OFFSET (0x3A000 + 0x578)
153a977168cSMichal Gulbicki #define ADF_MAILBOX_BASE_OFFSET 0x20970
154a977168cSMichal Gulbicki 
155a977168cSMichal Gulbicki /* Arbiter configuration */
156a977168cSMichal Gulbicki #define ADF_ARB_OFFSET 0x30000
157a977168cSMichal Gulbicki #define ADF_ARB_WRK_2_SER_MAP_OFFSET 0x180
158a977168cSMichal Gulbicki #define ADF_ARB_CONFIG (BIT(31) | BIT(6) | BIT(0))
159a977168cSMichal Gulbicki #define ADF_ARB_REG_SLOT 0x1000
160a977168cSMichal Gulbicki #define ADF_ARB_RINGSRVARBEN_OFFSET 0x19C
161a977168cSMichal Gulbicki 
162a977168cSMichal Gulbicki #define READ_CSR_RING_SRV_ARB_EN(csr_addr, index)                              \
163a977168cSMichal Gulbicki 	ADF_CSR_RD(csr_addr,                                                   \
164a977168cSMichal Gulbicki 		   ADF_ARB_RINGSRVARBEN_OFFSET + (ADF_ARB_REG_SLOT * (index)))
165a977168cSMichal Gulbicki 
166a977168cSMichal Gulbicki #define WRITE_CSR_RING_SRV_ARB_EN(csr_addr, index, value)                      \
167a977168cSMichal Gulbicki 	ADF_CSR_WR(csr_addr,                                                   \
168a977168cSMichal Gulbicki 		   ADF_ARB_RINGSRVARBEN_OFFSET + (ADF_ARB_REG_SLOT * (index)), \
169a977168cSMichal Gulbicki 		   value)
170a977168cSMichal Gulbicki 
171a977168cSMichal Gulbicki /* Power gating */
172a977168cSMichal Gulbicki #define ADF_POWERGATE_DC BIT(23)
173a977168cSMichal Gulbicki #define ADF_POWERGATE_PKE BIT(24)
174a977168cSMichal Gulbicki 
175a977168cSMichal Gulbicki /* Default ring mapping */
176a977168cSMichal Gulbicki #define ADF_GEN2_DEFAULT_RING_TO_SRV_MAP                                       \
177a977168cSMichal Gulbicki 	(CRYPTO << ADF_CFG_SERV_RING_PAIR_0_SHIFT |                            \
178a977168cSMichal Gulbicki 	 CRYPTO << ADF_CFG_SERV_RING_PAIR_1_SHIFT |                            \
179a977168cSMichal Gulbicki 	 UNUSED << ADF_CFG_SERV_RING_PAIR_2_SHIFT |                            \
180a977168cSMichal Gulbicki 	 COMP << ADF_CFG_SERV_RING_PAIR_3_SHIFT)
181a977168cSMichal Gulbicki 
182a977168cSMichal Gulbicki /* Error detection and correction */
183a977168cSMichal Gulbicki #define ADF_GEN2_AE_CTX_ENABLES(i) ((i)*0x1000 + 0x20818)
184a977168cSMichal Gulbicki #define ADF_GEN2_AE_MISC_CONTROL(i) ((i)*0x1000 + 0x20960)
185a977168cSMichal Gulbicki #define ADF_GEN2_ENABLE_AE_ECC_ERR BIT(28)
186a977168cSMichal Gulbicki #define ADF_GEN2_ENABLE_AE_ECC_PARITY_CORR (BIT(24) | BIT(12))
187a977168cSMichal Gulbicki #define ADF_GEN2_UERRSSMSH(i) ((i)*0x4000 + 0x18)
188a977168cSMichal Gulbicki #define ADF_GEN2_CERRSSMSH(i) ((i)*0x4000 + 0x10)
189a977168cSMichal Gulbicki #define ADF_GEN2_ERRSSMSH_EN BIT(3)
190a977168cSMichal Gulbicki 
191a977168cSMichal Gulbicki #define ADF_NUM_HB_CNT_PER_AE (ADF_NUM_THREADS_PER_AE + ADF_NUM_PKE_STRAND)
192a977168cSMichal Gulbicki 
193a977168cSMichal Gulbicki void adf_gen2_init_hw_csr_info(struct adf_hw_csr_info *csr_info);
194a977168cSMichal Gulbicki 
195a977168cSMichal Gulbicki #endif
196