xref: /freebsd/sys/contrib/dev/rtw89/pci.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2020  Realtek Corporation
3  */
4 
5 #ifndef __RTW89_PCI_H__
6 #define __RTW89_PCI_H__
7 
8 #include "txrx.h"
9 
10 #define MDIO_PG0_G1 0
11 #define MDIO_PG1_G1 1
12 #define MDIO_PG0_G2 2
13 #define MDIO_PG1_G2 3
14 #define RAC_CTRL_PPR			0x00
15 #define RAC_ANA0A			0x0A
16 #define B_BAC_EQ_SEL			BIT(5)
17 #define RAC_ANA0C			0x0C
18 #define B_PCIE_BIT_PSAVE		BIT(15)
19 #define RAC_ANA10			0x10
20 #define B_PCIE_BIT_PINOUT_DIS		BIT(3)
21 #define RAC_REG_REV2			0x1B
22 #define BAC_CMU_EN_DLY_MASK		GENMASK(15, 12)
23 #define PCIE_DPHY_DLY_25US		0x1
24 #define RAC_ANA19			0x19
25 #define B_PCIE_BIT_RD_SEL		BIT(2)
26 #define RAC_ANA1F			0x1F
27 #define RAC_ANA24			0x24
28 #define B_AX_DEGLITCH			GENMASK(11, 8)
29 #define RAC_ANA26			0x26
30 #define B_AX_RXEN			GENMASK(15, 14)
31 #define RAC_CTRL_PPR_V1			0x30
32 #define B_AX_CLK_CALIB_EN		BIT(12)
33 #define B_AX_CALIB_EN			BIT(13)
34 #define B_AX_DIV			GENMASK(15, 14)
35 #define RAC_SET_PPR_V1			0x31
36 
37 #define R_AX_DBI_FLAG			0x1090
38 #define B_AX_DBI_RFLAG			BIT(17)
39 #define B_AX_DBI_WFLAG			BIT(16)
40 #define B_AX_DBI_WREN_MSK		GENMASK(15, 12)
41 #define B_AX_DBI_ADDR_MSK		GENMASK(11, 2)
42 #define R_AX_DBI_WDATA			0x1094
43 #define R_AX_DBI_RDATA			0x1098
44 
45 #define R_AX_MDIO_WDATA			0x10A4
46 #define R_AX_MDIO_RDATA			0x10A6
47 
48 #define R_AX_PCIE_PS_CTRL_V1		0x3008
49 #define B_AX_CMAC_EXIT_L1_EN		BIT(7)
50 #define B_AX_DMAC0_EXIT_L1_EN		BIT(6)
51 #define B_AX_SEL_XFER_PENDING		BIT(3)
52 #define B_AX_SEL_REQ_ENTR_L1		BIT(2)
53 #define B_AX_SEL_REQ_EXIT_L1		BIT(0)
54 
55 #define R_AX_PCIE_MIX_CFG_V1		0x300C
56 #define B_AX_ASPM_CTRL_L1		BIT(17)
57 #define B_AX_ASPM_CTRL_L0		BIT(16)
58 #define B_AX_ASPM_CTRL_MASK		GENMASK(17, 16)
59 #define B_AX_XFER_PENDING_FW		BIT(11)
60 #define B_AX_XFER_PENDING		BIT(10)
61 #define B_AX_REQ_EXIT_L1		BIT(9)
62 #define B_AX_REQ_ENTR_L1		BIT(8)
63 #define B_AX_L1SUB_DISABLE		BIT(0)
64 
65 #define R_AX_L1_CLK_CTRL		0x3010
66 #define B_AX_CLK_REQ_N			BIT(1)
67 
68 #define R_AX_PCIE_BG_CLR		0x303C
69 #define B_AX_BG_CLR_ASYNC_M3		BIT(4)
70 
71 #define R_AX_PCIE_LAT_CTRL		0x3044
72 #define B_AX_CLK_REQ_SEL_OPT		BIT(1)
73 #define B_AX_CLK_REQ_SEL		BIT(0)
74 
75 #define R_AX_PCIE_IO_RCY_M1 0x3100
76 #define B_AX_PCIE_IO_RCY_P_M1 BIT(5)
77 #define B_AX_PCIE_IO_RCY_WDT_P_M1 BIT(4)
78 #define B_AX_PCIE_IO_RCY_WDT_MODE_M1 BIT(3)
79 #define B_AX_PCIE_IO_RCY_TRIG_M1 BIT(0)
80 
81 #define R_AX_PCIE_WDT_TIMER_M1 0x3104
82 #define B_AX_PCIE_WDT_TIMER_M1_MASK GENMASK(31, 0)
83 
84 #define R_AX_PCIE_IO_RCY_M2 0x310C
85 #define B_AX_PCIE_IO_RCY_P_M2 BIT(5)
86 #define B_AX_PCIE_IO_RCY_WDT_P_M2 BIT(4)
87 #define B_AX_PCIE_IO_RCY_WDT_MODE_M2 BIT(3)
88 #define B_AX_PCIE_IO_RCY_TRIG_M2 BIT(0)
89 
90 #define R_AX_PCIE_WDT_TIMER_M2 0x3110
91 #define B_AX_PCIE_WDT_TIMER_M2_MASK GENMASK(31, 0)
92 
93 #define R_AX_PCIE_IO_RCY_E0 0x3118
94 #define B_AX_PCIE_IO_RCY_P_E0 BIT(5)
95 #define B_AX_PCIE_IO_RCY_WDT_P_E0 BIT(4)
96 #define B_AX_PCIE_IO_RCY_WDT_MODE_E0 BIT(3)
97 #define B_AX_PCIE_IO_RCY_TRIG_E0 BIT(0)
98 
99 #define R_AX_PCIE_WDT_TIMER_E0 0x311C
100 #define B_AX_PCIE_WDT_TIMER_E0_MASK GENMASK(31, 0)
101 
102 #define R_AX_PCIE_IO_RCY_S1 0x3124
103 #define B_AX_PCIE_IO_RCY_RP_S1 BIT(7)
104 #define B_AX_PCIE_IO_RCY_WP_S1 BIT(6)
105 #define B_AX_PCIE_IO_RCY_WDT_RP_S1 BIT(5)
106 #define B_AX_PCIE_IO_RCY_WDT_WP_S1 BIT(4)
107 #define B_AX_PCIE_IO_RCY_WDT_MODE_S1 BIT(3)
108 #define B_AX_PCIE_IO_RCY_RTRIG_S1 BIT(1)
109 #define B_AX_PCIE_IO_RCY_WTRIG_S1 BIT(0)
110 
111 #define R_AX_PCIE_WDT_TIMER_S1 0x3128
112 #define B_AX_PCIE_WDT_TIMER_S1_MASK GENMASK(31, 0)
113 
114 #define R_RAC_DIRECT_OFFSET_G1 0x3800
115 #define FILTER_OUT_EQ_MASK GENMASK(14, 10)
116 #define R_RAC_DIRECT_OFFSET_G2 0x3880
117 #define REG_FILTER_OUT_MASK GENMASK(6, 2)
118 #define RAC_MULT 2
119 
120 #define RTW89_PCI_WR_RETRY_CNT		20
121 
122 /* Interrupts */
123 #define R_AX_HIMR0 0x01A0
124 #define B_AX_WDT_TIMEOUT_INT_EN BIT(22)
125 #define B_AX_HALT_C2H_INT_EN BIT(21)
126 #define R_AX_HISR0 0x01A4
127 
128 #define R_AX_HIMR1 0x01A8
129 #define B_AX_GPIO18_INT_EN BIT(2)
130 #define B_AX_GPIO17_INT_EN BIT(1)
131 #define B_AX_GPIO16_INT_EN BIT(0)
132 
133 #define R_AX_HISR1 0x01AC
134 #define B_AX_GPIO18_INT BIT(2)
135 #define B_AX_GPIO17_INT BIT(1)
136 #define B_AX_GPIO16_INT BIT(0)
137 
138 #define R_AX_MDIO_CFG			0x10A0
139 #define B_AX_MDIO_PHY_ADDR_MASK		GENMASK(13, 12)
140 #define B_AX_MDIO_RFLAG			BIT(9)
141 #define B_AX_MDIO_WFLAG			BIT(8)
142 #define B_AX_MDIO_ADDR_MASK		GENMASK(4, 0)
143 
144 #define R_AX_PCIE_HIMR00	0x10B0
145 #define R_AX_HAXI_HIMR00 0x10B0
146 #define B_AX_HC00ISR_IND_INT_EN		BIT(27)
147 #define B_AX_HD1ISR_IND_INT_EN		BIT(26)
148 #define B_AX_HD0ISR_IND_INT_EN		BIT(25)
149 #define B_AX_HS0ISR_IND_INT_EN		BIT(24)
150 #define B_AX_RETRAIN_INT_EN		BIT(21)
151 #define B_AX_RPQBD_FULL_INT_EN		BIT(20)
152 #define B_AX_RDU_INT_EN			BIT(19)
153 #define B_AX_RXDMA_STUCK_INT_EN		BIT(18)
154 #define B_AX_TXDMA_STUCK_INT_EN		BIT(17)
155 #define B_AX_PCIE_HOTRST_INT_EN		BIT(16)
156 #define B_AX_PCIE_FLR_INT_EN		BIT(15)
157 #define B_AX_PCIE_PERST_INT_EN		BIT(14)
158 #define B_AX_TXDMA_CH12_INT_EN		BIT(13)
159 #define B_AX_TXDMA_CH9_INT_EN		BIT(12)
160 #define B_AX_TXDMA_CH8_INT_EN		BIT(11)
161 #define B_AX_TXDMA_ACH7_INT_EN		BIT(10)
162 #define B_AX_TXDMA_ACH6_INT_EN		BIT(9)
163 #define B_AX_TXDMA_ACH5_INT_EN		BIT(8)
164 #define B_AX_TXDMA_ACH4_INT_EN		BIT(7)
165 #define B_AX_TXDMA_ACH3_INT_EN		BIT(6)
166 #define B_AX_TXDMA_ACH2_INT_EN		BIT(5)
167 #define B_AX_TXDMA_ACH1_INT_EN		BIT(4)
168 #define B_AX_TXDMA_ACH0_INT_EN		BIT(3)
169 #define B_AX_RPQDMA_INT_EN		BIT(2)
170 #define B_AX_RXP1DMA_INT_EN		BIT(1)
171 #define B_AX_RXDMA_INT_EN		BIT(0)
172 
173 #define R_AX_PCIE_HISR00	0x10B4
174 #define R_AX_HAXI_HISR00 0x10B4
175 #define B_AX_HC00ISR_IND_INT		BIT(27)
176 #define B_AX_HD1ISR_IND_INT		BIT(26)
177 #define B_AX_HD0ISR_IND_INT		BIT(25)
178 #define B_AX_HS0ISR_IND_INT		BIT(24)
179 #define B_AX_RETRAIN_INT		BIT(21)
180 #define B_AX_RPQBD_FULL_INT		BIT(20)
181 #define B_AX_RDU_INT			BIT(19)
182 #define B_AX_RXDMA_STUCK_INT		BIT(18)
183 #define B_AX_TXDMA_STUCK_INT		BIT(17)
184 #define B_AX_PCIE_HOTRST_INT		BIT(16)
185 #define B_AX_PCIE_FLR_INT		BIT(15)
186 #define B_AX_PCIE_PERST_INT		BIT(14)
187 #define B_AX_TXDMA_CH12_INT		BIT(13)
188 #define B_AX_TXDMA_CH9_INT		BIT(12)
189 #define B_AX_TXDMA_CH8_INT		BIT(11)
190 #define B_AX_TXDMA_ACH7_INT		BIT(10)
191 #define B_AX_TXDMA_ACH6_INT		BIT(9)
192 #define B_AX_TXDMA_ACH5_INT		BIT(8)
193 #define B_AX_TXDMA_ACH4_INT		BIT(7)
194 #define B_AX_TXDMA_ACH3_INT		BIT(6)
195 #define B_AX_TXDMA_ACH2_INT		BIT(5)
196 #define B_AX_TXDMA_ACH1_INT		BIT(4)
197 #define B_AX_TXDMA_ACH0_INT		BIT(3)
198 #define B_AX_RPQDMA_INT			BIT(2)
199 #define B_AX_RXP1DMA_INT		BIT(1)
200 #define B_AX_RXDMA_INT			BIT(0)
201 
202 #define R_AX_HAXI_HIMR10 0x11E0
203 #define B_AX_TXDMA_CH11_INT_EN_V1 BIT(1)
204 #define B_AX_TXDMA_CH10_INT_EN_V1 BIT(0)
205 
206 #define R_AX_PCIE_HIMR10	0x13B0
207 #define B_AX_HC10ISR_IND_INT_EN		BIT(28)
208 #define B_AX_TXDMA_CH11_INT_EN		BIT(12)
209 #define B_AX_TXDMA_CH10_INT_EN		BIT(11)
210 
211 #define R_AX_PCIE_HISR10	0x13B4
212 #define B_AX_HC10ISR_IND_INT		BIT(28)
213 #define B_AX_TXDMA_CH11_INT		BIT(12)
214 #define B_AX_TXDMA_CH10_INT		BIT(11)
215 
216 #define R_AX_PCIE_HIMR00_V1 0x30B0
217 #define B_AX_HCI_AXIDMA_INT_EN BIT(29)
218 #define B_AX_HC00ISR_IND_INT_EN_V1 BIT(28)
219 #define B_AX_HD1ISR_IND_INT_EN_V1 BIT(27)
220 #define B_AX_HD0ISR_IND_INT_EN_V1 BIT(26)
221 #define B_AX_HS1ISR_IND_INT_EN BIT(25)
222 #define B_AX_PCIE_DBG_STE_INT_EN BIT(13)
223 
224 #define R_AX_PCIE_HISR00_V1 0x30B4
225 #define B_AX_HCI_AXIDMA_INT BIT(29)
226 #define B_AX_HC00ISR_IND_INT_V1 BIT(28)
227 #define B_AX_HD1ISR_IND_INT_V1 BIT(27)
228 #define B_AX_HD0ISR_IND_INT_V1 BIT(26)
229 #define B_AX_HS1ISR_IND_INT BIT(25)
230 #define B_AX_PCIE_DBG_STE_INT BIT(13)
231 
232 /* TX/RX */
233 #define R_AX_DRV_FW_HSK_0	0x01B0
234 #define R_AX_DRV_FW_HSK_1	0x01B4
235 #define R_AX_DRV_FW_HSK_2	0x01B8
236 #define R_AX_DRV_FW_HSK_3	0x01BC
237 #define R_AX_DRV_FW_HSK_4	0x01C0
238 #define R_AX_DRV_FW_HSK_5	0x01C4
239 #define R_AX_DRV_FW_HSK_6	0x01C8
240 #define R_AX_DRV_FW_HSK_7	0x01CC
241 
242 #define R_AX_RXQ_RXBD_IDX	0x1050
243 #define R_AX_RPQ_RXBD_IDX	0x1054
244 #define R_AX_ACH0_TXBD_IDX	0x1058
245 #define R_AX_ACH1_TXBD_IDX	0x105C
246 #define R_AX_ACH2_TXBD_IDX	0x1060
247 #define R_AX_ACH3_TXBD_IDX	0x1064
248 #define R_AX_ACH4_TXBD_IDX	0x1068
249 #define R_AX_ACH5_TXBD_IDX	0x106C
250 #define R_AX_ACH6_TXBD_IDX	0x1070
251 #define R_AX_ACH7_TXBD_IDX	0x1074
252 #define R_AX_CH8_TXBD_IDX	0x1078 /* Management Queue band 0 */
253 #define R_AX_CH9_TXBD_IDX	0x107C /* HI Queue band 0 */
254 #define R_AX_CH10_TXBD_IDX	0x137C /* Management Queue band 1 */
255 #define R_AX_CH11_TXBD_IDX	0x1380 /* HI Queue band 1 */
256 #define R_AX_CH12_TXBD_IDX	0x1080 /* FWCMD Queue */
257 #define R_AX_CH10_TXBD_IDX_V1	0x11D0
258 #define R_AX_CH11_TXBD_IDX_V1	0x11D4
259 #define R_AX_RXQ_RXBD_IDX_V1	0x1218
260 #define R_AX_RPQ_RXBD_IDX_V1	0x121C
261 #define TXBD_HW_IDX_MASK	GENMASK(27, 16)
262 #define TXBD_HOST_IDX_MASK	GENMASK(11, 0)
263 
264 #define R_AX_ACH0_TXBD_DESA_L	0x1110
265 #define R_AX_ACH0_TXBD_DESA_H	0x1114
266 #define R_AX_ACH1_TXBD_DESA_L	0x1118
267 #define R_AX_ACH1_TXBD_DESA_H	0x111C
268 #define R_AX_ACH2_TXBD_DESA_L	0x1120
269 #define R_AX_ACH2_TXBD_DESA_H	0x1124
270 #define R_AX_ACH3_TXBD_DESA_L	0x1128
271 #define R_AX_ACH3_TXBD_DESA_H	0x112C
272 #define R_AX_ACH4_TXBD_DESA_L	0x1130
273 #define R_AX_ACH4_TXBD_DESA_H	0x1134
274 #define R_AX_ACH5_TXBD_DESA_L	0x1138
275 #define R_AX_ACH5_TXBD_DESA_H	0x113C
276 #define R_AX_ACH6_TXBD_DESA_L	0x1140
277 #define R_AX_ACH6_TXBD_DESA_H	0x1144
278 #define R_AX_ACH7_TXBD_DESA_L	0x1148
279 #define R_AX_ACH7_TXBD_DESA_H	0x114C
280 #define R_AX_CH8_TXBD_DESA_L	0x1150
281 #define R_AX_CH8_TXBD_DESA_H	0x1154
282 #define R_AX_CH9_TXBD_DESA_L	0x1158
283 #define R_AX_CH9_TXBD_DESA_H	0x115C
284 #define R_AX_CH10_TXBD_DESA_L	0x1358
285 #define R_AX_CH10_TXBD_DESA_H	0x135C
286 #define R_AX_CH11_TXBD_DESA_L	0x1360
287 #define R_AX_CH11_TXBD_DESA_H	0x1364
288 #define R_AX_CH12_TXBD_DESA_L	0x1160
289 #define R_AX_CH12_TXBD_DESA_H	0x1164
290 #define R_AX_RXQ_RXBD_DESA_L	0x1100
291 #define R_AX_RXQ_RXBD_DESA_H	0x1104
292 #define R_AX_RPQ_RXBD_DESA_L	0x1108
293 #define R_AX_RPQ_RXBD_DESA_H	0x110C
294 #define R_AX_RXQ_RXBD_DESA_L_V1 0x1220
295 #define R_AX_RXQ_RXBD_DESA_H_V1 0x1224
296 #define R_AX_RPQ_RXBD_DESA_L_V1 0x1228
297 #define R_AX_RPQ_RXBD_DESA_H_V1 0x122C
298 #define R_AX_ACH0_TXBD_DESA_L_V1 0x1230
299 #define R_AX_ACH0_TXBD_DESA_H_V1 0x1234
300 #define R_AX_ACH1_TXBD_DESA_L_V1 0x1238
301 #define R_AX_ACH1_TXBD_DESA_H_V1 0x123C
302 #define R_AX_ACH2_TXBD_DESA_L_V1 0x1240
303 #define R_AX_ACH2_TXBD_DESA_H_V1 0x1244
304 #define R_AX_ACH3_TXBD_DESA_L_V1 0x1248
305 #define R_AX_ACH3_TXBD_DESA_H_V1 0x124C
306 #define R_AX_ACH4_TXBD_DESA_L_V1 0x1250
307 #define R_AX_ACH4_TXBD_DESA_H_V1 0x1254
308 #define R_AX_ACH5_TXBD_DESA_L_V1 0x1258
309 #define R_AX_ACH5_TXBD_DESA_H_V1 0x125C
310 #define R_AX_ACH6_TXBD_DESA_L_V1 0x1260
311 #define R_AX_ACH6_TXBD_DESA_H_V1 0x1264
312 #define R_AX_ACH7_TXBD_DESA_L_V1 0x1268
313 #define R_AX_ACH7_TXBD_DESA_H_V1 0x126C
314 #define R_AX_CH8_TXBD_DESA_L_V1 0x1270
315 #define R_AX_CH8_TXBD_DESA_H_V1 0x1274
316 #define R_AX_CH9_TXBD_DESA_L_V1 0x1278
317 #define R_AX_CH9_TXBD_DESA_H_V1 0x127C
318 #define R_AX_CH12_TXBD_DESA_L_V1 0x1280
319 #define R_AX_CH12_TXBD_DESA_H_V1 0x1284
320 #define R_AX_CH10_TXBD_DESA_L_V1 0x1458
321 #define R_AX_CH10_TXBD_DESA_H_V1 0x145C
322 #define R_AX_CH11_TXBD_DESA_L_V1 0x1460
323 #define R_AX_CH11_TXBD_DESA_H_V1 0x1464
324 #define B_AX_DESC_NUM_MSK		GENMASK(11, 0)
325 
326 #define R_AX_RXQ_RXBD_NUM	0x1020
327 #define R_AX_RPQ_RXBD_NUM	0x1022
328 #define R_AX_ACH0_TXBD_NUM	0x1024
329 #define R_AX_ACH1_TXBD_NUM	0x1026
330 #define R_AX_ACH2_TXBD_NUM	0x1028
331 #define R_AX_ACH3_TXBD_NUM	0x102A
332 #define R_AX_ACH4_TXBD_NUM	0x102C
333 #define R_AX_ACH5_TXBD_NUM	0x102E
334 #define R_AX_ACH6_TXBD_NUM	0x1030
335 #define R_AX_ACH7_TXBD_NUM	0x1032
336 #define R_AX_CH8_TXBD_NUM	0x1034
337 #define R_AX_CH9_TXBD_NUM	0x1036
338 #define R_AX_CH10_TXBD_NUM	0x1338
339 #define R_AX_CH11_TXBD_NUM	0x133A
340 #define R_AX_CH12_TXBD_NUM	0x1038
341 #define R_AX_RXQ_RXBD_NUM_V1	0x1210
342 #define R_AX_RPQ_RXBD_NUM_V1	0x1212
343 #define R_AX_CH10_TXBD_NUM_V1	0x1438
344 #define R_AX_CH11_TXBD_NUM_V1	0x143A
345 
346 #define R_AX_ACH0_BDRAM_CTRL	0x1200
347 #define R_AX_ACH1_BDRAM_CTRL	0x1204
348 #define R_AX_ACH2_BDRAM_CTRL	0x1208
349 #define R_AX_ACH3_BDRAM_CTRL	0x120C
350 #define R_AX_ACH4_BDRAM_CTRL	0x1210
351 #define R_AX_ACH5_BDRAM_CTRL	0x1214
352 #define R_AX_ACH6_BDRAM_CTRL	0x1218
353 #define R_AX_ACH7_BDRAM_CTRL	0x121C
354 #define R_AX_CH8_BDRAM_CTRL	0x1220
355 #define R_AX_CH9_BDRAM_CTRL	0x1224
356 #define R_AX_CH10_BDRAM_CTRL	0x1320
357 #define R_AX_CH11_BDRAM_CTRL	0x1324
358 #define R_AX_CH12_BDRAM_CTRL	0x1228
359 #define R_AX_ACH0_BDRAM_CTRL_V1 0x1300
360 #define R_AX_ACH1_BDRAM_CTRL_V1 0x1304
361 #define R_AX_ACH2_BDRAM_CTRL_V1 0x1308
362 #define R_AX_ACH3_BDRAM_CTRL_V1 0x130C
363 #define R_AX_ACH4_BDRAM_CTRL_V1 0x1310
364 #define R_AX_ACH5_BDRAM_CTRL_V1 0x1314
365 #define R_AX_ACH6_BDRAM_CTRL_V1 0x1318
366 #define R_AX_ACH7_BDRAM_CTRL_V1 0x131C
367 #define R_AX_CH8_BDRAM_CTRL_V1 0x1320
368 #define R_AX_CH9_BDRAM_CTRL_V1 0x1324
369 #define R_AX_CH12_BDRAM_CTRL_V1 0x1328
370 #define R_AX_CH10_BDRAM_CTRL_V1 0x1420
371 #define R_AX_CH11_BDRAM_CTRL_V1 0x1424
372 #define BDRAM_SIDX_MASK		GENMASK(7, 0)
373 #define BDRAM_MAX_MASK		GENMASK(15, 8)
374 #define BDRAM_MIN_MASK		GENMASK(23, 16)
375 
376 #define R_AX_PCIE_INIT_CFG1	0x1000
377 #define B_AX_PCIE_RXRST_KEEP_REG	BIT(23)
378 #define B_AX_PCIE_TXRST_KEEP_REG	BIT(22)
379 #define B_AX_PCIE_PERST_KEEP_REG	BIT(21)
380 #define B_AX_PCIE_FLR_KEEP_REG		BIT(20)
381 #define B_AX_PCIE_TRAIN_KEEP_REG	BIT(19)
382 #define B_AX_RXBD_MODE			BIT(18)
383 #define B_AX_PCIE_MAX_RXDMA_MASK	GENMASK(16, 14)
384 #define B_AX_RXHCI_EN			BIT(13)
385 #define B_AX_LATENCY_CONTROL		BIT(12)
386 #define B_AX_TXHCI_EN			BIT(11)
387 #define B_AX_PCIE_MAX_TXDMA_MASK	GENMASK(10, 8)
388 #define B_AX_TX_TRUNC_MODE		BIT(5)
389 #define B_AX_RX_TRUNC_MODE		BIT(4)
390 #define B_AX_RST_BDRAM			BIT(3)
391 #define B_AX_DIS_RXDMA_PRE		BIT(2)
392 
393 #define R_AX_TXDMA_ADDR_H	0x10F0
394 #define R_AX_RXDMA_ADDR_H	0x10F4
395 
396 #define R_AX_PCIE_DMA_STOP1	0x1010
397 #define B_AX_STOP_PCIEIO		BIT(20)
398 #define B_AX_STOP_WPDMA			BIT(19)
399 #define B_AX_STOP_CH12			BIT(18)
400 #define B_AX_STOP_CH9			BIT(17)
401 #define B_AX_STOP_CH8			BIT(16)
402 #define B_AX_STOP_ACH7			BIT(15)
403 #define B_AX_STOP_ACH6			BIT(14)
404 #define B_AX_STOP_ACH5			BIT(13)
405 #define B_AX_STOP_ACH4			BIT(12)
406 #define B_AX_STOP_ACH3			BIT(11)
407 #define B_AX_STOP_ACH2			BIT(10)
408 #define B_AX_STOP_ACH1			BIT(9)
409 #define B_AX_STOP_ACH0			BIT(8)
410 #define B_AX_STOP_RPQ			BIT(1)
411 #define B_AX_STOP_RXQ			BIT(0)
412 #define B_AX_TX_STOP1_ALL		GENMASK(18, 8)
413 
414 #define R_AX_PCIE_DMA_STOP2	0x1310
415 #define B_AX_STOP_CH11			BIT(1)
416 #define B_AX_STOP_CH10			BIT(0)
417 #define B_AX_TX_STOP2_ALL		GENMASK(1, 0)
418 
419 #define R_AX_TXBD_RWPTR_CLR1	0x1014
420 #define B_AX_CLR_CH12_IDX		BIT(10)
421 #define B_AX_CLR_CH9_IDX		BIT(9)
422 #define B_AX_CLR_CH8_IDX		BIT(8)
423 #define B_AX_CLR_ACH7_IDX		BIT(7)
424 #define B_AX_CLR_ACH6_IDX		BIT(6)
425 #define B_AX_CLR_ACH5_IDX		BIT(5)
426 #define B_AX_CLR_ACH4_IDX		BIT(4)
427 #define B_AX_CLR_ACH3_IDX		BIT(3)
428 #define B_AX_CLR_ACH2_IDX		BIT(2)
429 #define B_AX_CLR_ACH1_IDX		BIT(1)
430 #define B_AX_CLR_ACH0_IDX		BIT(0)
431 #define B_AX_TXBD_CLR1_ALL		GENMASK(10, 0)
432 
433 #define R_AX_RXBD_RWPTR_CLR	0x1018
434 #define B_AX_CLR_RPQ_IDX		BIT(1)
435 #define B_AX_CLR_RXQ_IDX		BIT(0)
436 #define B_AX_RXBD_CLR_ALL		GENMASK(1, 0)
437 
438 #define R_AX_TXBD_RWPTR_CLR2	0x1314
439 #define B_AX_CLR_CH11_IDX		BIT(1)
440 #define B_AX_CLR_CH10_IDX		BIT(0)
441 #define B_AX_TXBD_CLR2_ALL		GENMASK(1, 0)
442 
443 #define R_AX_PCIE_DMA_BUSY1	0x101C
444 #define B_AX_PCIEIO_RX_BUSY		BIT(22)
445 #define B_AX_PCIEIO_TX_BUSY		BIT(21)
446 #define B_AX_PCIEIO_BUSY		BIT(20)
447 #define B_AX_WPDMA_BUSY			BIT(19)
448 #define B_AX_CH12_BUSY			BIT(18)
449 #define B_AX_CH9_BUSY			BIT(17)
450 #define B_AX_CH8_BUSY			BIT(16)
451 #define B_AX_ACH7_BUSY			BIT(15)
452 #define B_AX_ACH6_BUSY			BIT(14)
453 #define B_AX_ACH5_BUSY			BIT(13)
454 #define B_AX_ACH4_BUSY			BIT(12)
455 #define B_AX_ACH3_BUSY			BIT(11)
456 #define B_AX_ACH2_BUSY			BIT(10)
457 #define B_AX_ACH1_BUSY			BIT(9)
458 #define B_AX_ACH0_BUSY			BIT(8)
459 #define B_AX_RPQ_BUSY			BIT(1)
460 #define B_AX_RXQ_BUSY			BIT(0)
461 
462 #define R_AX_PCIE_DMA_BUSY2	0x131C
463 #define B_AX_CH11_BUSY			BIT(1)
464 #define B_AX_CH10_BUSY			BIT(0)
465 
466 /* Configure */
467 #define R_AX_PCIE_INIT_CFG2		0x1004
468 #define B_AX_WD_ITVL_IDLE		GENMASK(27, 24)
469 #define B_AX_WD_ITVL_ACT		GENMASK(19, 16)
470 #define B_AX_PCIE_RX_APPLEN_MASK	GENMASK(13, 0)
471 
472 #define R_AX_PCIE_PS_CTRL		0x1008
473 #define B_AX_L1OFF_PWR_OFF_EN		BIT(5)
474 
475 #define R_AX_INT_MIT_RX			0x10D4
476 #define B_AX_RXMIT_RXP2_SEL		BIT(19)
477 #define B_AX_RXMIT_RXP1_SEL		BIT(18)
478 #define B_AX_RXTIMER_UNIT_MASK		GENMASK(17, 16)
479 #define AX_RXTIMER_UNIT_64US		0
480 #define AX_RXTIMER_UNIT_128US		1
481 #define AX_RXTIMER_UNIT_256US		2
482 #define AX_RXTIMER_UNIT_512US		3
483 #define B_AX_RXCOUNTER_MATCH_MASK	GENMASK(15, 8)
484 #define B_AX_RXTIMER_MATCH_MASK		GENMASK(7, 0)
485 
486 #define R_AX_DBG_ERR_FLAG		0x11C4
487 #define B_AX_PCIE_RPQ_FULL		BIT(29)
488 #define B_AX_PCIE_RXQ_FULL		BIT(28)
489 #define B_AX_CPL_STATUS_MASK		GENMASK(27, 25)
490 #define B_AX_RX_STUCK			BIT(22)
491 #define B_AX_TX_STUCK			BIT(21)
492 #define B_AX_PCIEDBG_TXERR0		BIT(16)
493 #define B_AX_PCIE_RXP1_ERR0		BIT(4)
494 #define B_AX_PCIE_TXBD_LEN0		BIT(1)
495 #define B_AX_PCIE_TXBD_4KBOUD_LENERR	BIT(0)
496 
497 #define R_AX_TXBD_RWPTR_CLR2_V1		0x11C4
498 #define B_AX_CLR_CH11_IDX		BIT(1)
499 #define B_AX_CLR_CH10_IDX		BIT(0)
500 
501 #define R_AX_LBC_WATCHDOG		0x11D8
502 #define B_AX_LBC_TIMER			GENMASK(7, 4)
503 #define B_AX_LBC_FLAG			BIT(1)
504 #define B_AX_LBC_EN			BIT(0)
505 
506 #define R_AX_RXBD_RWPTR_CLR_V1		0x1200
507 #define B_AX_CLR_RPQ_IDX		BIT(1)
508 #define B_AX_CLR_RXQ_IDX		BIT(0)
509 
510 #define R_AX_HAXI_EXP_CTRL		0x1204
511 #define B_AX_MAX_TAG_NUM_V1_MASK	GENMASK(2, 0)
512 
513 #define R_AX_PCIE_EXP_CTRL		0x13F0
514 #define B_AX_EN_CHKDSC_NO_RX_STUCK	BIT(20)
515 #define B_AX_MAX_TAG_NUM		GENMASK(18, 16)
516 #define B_AX_SIC_EN_FORCE_CLKREQ	BIT(4)
517 
518 #define R_AX_PCIE_RX_PREF_ADV		0x13F4
519 #define B_AX_RXDMA_PREF_ADV_EN		BIT(0)
520 
521 #define R_AX_PCIE_HRPWM_V1		0x30C0
522 #define R_AX_PCIE_CRPWM			0x30C4
523 
524 #define RTW89_PCI_TXBD_NUM_MAX		256
525 #define RTW89_PCI_RXBD_NUM_MAX		256
526 #define RTW89_PCI_TXWD_NUM_MAX		512
527 #define RTW89_PCI_TXWD_PAGE_SIZE	128
528 #define RTW89_PCI_ADDRINFO_MAX		4
529 #define RTW89_PCI_RX_BUF_SIZE		11460
530 
531 #define RTW89_PCI_POLL_BDRAM_RST_CNT	100
532 #define RTW89_PCI_MULTITAG		8
533 
534 /* PCIE CFG register */
535 #define RTW89_PCIE_L1_STS_V1		0x80
536 #define RTW89_BCFG_LINK_SPEED_MASK	GENMASK(19, 16)
537 #define RTW89_PCIE_GEN1_SPEED		0x01
538 #define RTW89_PCIE_GEN2_SPEED		0x02
539 #define RTW89_PCIE_PHY_RATE		0x82
540 #define RTW89_PCIE_PHY_RATE_MASK	GENMASK(1, 0)
541 #define RTW89_PCIE_L1SS_STS_V1		0x0168
542 #define RTW89_PCIE_BIT_ASPM_L11		BIT(3)
543 #define RTW89_PCIE_BIT_ASPM_L12		BIT(2)
544 #define RTW89_PCIE_BIT_PCI_L11		BIT(1)
545 #define RTW89_PCIE_BIT_PCI_L12		BIT(0)
546 #define RTW89_PCIE_ASPM_CTRL		0x070F
547 #define RTW89_L1DLY_MASK		GENMASK(5, 3)
548 #define RTW89_L0DLY_MASK		GENMASK(2, 0)
549 #define RTW89_PCIE_TIMER_CTRL		0x0718
550 #define RTW89_PCIE_BIT_L1SUB		BIT(5)
551 #define RTW89_PCIE_L1_CTRL		0x0719
552 #define RTW89_PCIE_BIT_CLK		BIT(4)
553 #define RTW89_PCIE_BIT_L1		BIT(3)
554 #define RTW89_PCIE_CLK_CTRL		0x0725
555 #define RTW89_PCIE_RST_MSTATE		0x0B48
556 #define RTW89_PCIE_BIT_CFG_RST_MSTATE	BIT(0)
557 
558 #define INTF_INTGRA_MINREF_V1	90
559 #define INTF_INTGRA_HOSTREF_V1	100
560 
561 enum rtw89_pcie_phy {
562 	PCIE_PHY_GEN1,
563 	PCIE_PHY_GEN2,
564 	PCIE_PHY_GEN1_UNDEFINE = 0x7F,
565 };
566 
567 enum mac_ax_func_sw {
568 	MAC_AX_FUNC_DIS,
569 	MAC_AX_FUNC_EN,
570 };
571 
572 enum rtw89_pcie_l0sdly {
573 	PCIE_L0SDLY_1US = 0,
574 	PCIE_L0SDLY_2US = 1,
575 	PCIE_L0SDLY_3US = 2,
576 	PCIE_L0SDLY_4US = 3,
577 	PCIE_L0SDLY_5US = 4,
578 	PCIE_L0SDLY_6US = 5,
579 	PCIE_L0SDLY_7US = 6,
580 };
581 
582 enum rtw89_pcie_l1dly {
583 	PCIE_L1DLY_16US = 4,
584 	PCIE_L1DLY_32US = 5,
585 	PCIE_L1DLY_64US = 6,
586 	PCIE_L1DLY_HW_INFI = 7,
587 };
588 
589 enum rtw89_pcie_clkdly_hw {
590 	PCIE_CLKDLY_HW_0 = 0,
591 	PCIE_CLKDLY_HW_30US = 0x1,
592 	PCIE_CLKDLY_HW_50US = 0x2,
593 	PCIE_CLKDLY_HW_100US = 0x3,
594 	PCIE_CLKDLY_HW_150US = 0x4,
595 	PCIE_CLKDLY_HW_200US = 0x5,
596 };
597 
598 enum mac_ax_bd_trunc_mode {
599 	MAC_AX_BD_NORM,
600 	MAC_AX_BD_TRUNC,
601 	MAC_AX_BD_DEF = 0xFE
602 };
603 
604 enum mac_ax_rxbd_mode {
605 	MAC_AX_RXBD_PKT,
606 	MAC_AX_RXBD_SEP,
607 	MAC_AX_RXBD_DEF = 0xFE
608 };
609 
610 enum mac_ax_tag_mode {
611 	MAC_AX_TAG_SGL,
612 	MAC_AX_TAG_MULTI,
613 	MAC_AX_TAG_DEF = 0xFE
614 };
615 
616 enum mac_ax_tx_burst {
617 	MAC_AX_TX_BURST_16B = 0,
618 	MAC_AX_TX_BURST_32B = 1,
619 	MAC_AX_TX_BURST_64B = 2,
620 	MAC_AX_TX_BURST_V1_64B = 0,
621 	MAC_AX_TX_BURST_128B = 3,
622 	MAC_AX_TX_BURST_V1_128B = 1,
623 	MAC_AX_TX_BURST_256B = 4,
624 	MAC_AX_TX_BURST_V1_256B = 2,
625 	MAC_AX_TX_BURST_512B = 5,
626 	MAC_AX_TX_BURST_1024B = 6,
627 	MAC_AX_TX_BURST_2048B = 7,
628 	MAC_AX_TX_BURST_DEF = 0xFE
629 };
630 
631 enum mac_ax_rx_burst {
632 	MAC_AX_RX_BURST_16B = 0,
633 	MAC_AX_RX_BURST_32B = 1,
634 	MAC_AX_RX_BURST_64B = 2,
635 	MAC_AX_RX_BURST_V1_64B = 0,
636 	MAC_AX_RX_BURST_128B = 3,
637 	MAC_AX_RX_BURST_V1_128B = 1,
638 	MAC_AX_RX_BURST_V1_256B = 0,
639 	MAC_AX_RX_BURST_DEF = 0xFE
640 };
641 
642 enum mac_ax_wd_dma_intvl {
643 	MAC_AX_WD_DMA_INTVL_0S,
644 	MAC_AX_WD_DMA_INTVL_256NS,
645 	MAC_AX_WD_DMA_INTVL_512NS,
646 	MAC_AX_WD_DMA_INTVL_768NS,
647 	MAC_AX_WD_DMA_INTVL_1US,
648 	MAC_AX_WD_DMA_INTVL_1_5US,
649 	MAC_AX_WD_DMA_INTVL_2US,
650 	MAC_AX_WD_DMA_INTVL_4US,
651 	MAC_AX_WD_DMA_INTVL_8US,
652 	MAC_AX_WD_DMA_INTVL_16US,
653 	MAC_AX_WD_DMA_INTVL_DEF = 0xFE
654 };
655 
656 enum mac_ax_multi_tag_num {
657 	MAC_AX_TAG_NUM_1,
658 	MAC_AX_TAG_NUM_2,
659 	MAC_AX_TAG_NUM_3,
660 	MAC_AX_TAG_NUM_4,
661 	MAC_AX_TAG_NUM_5,
662 	MAC_AX_TAG_NUM_6,
663 	MAC_AX_TAG_NUM_7,
664 	MAC_AX_TAG_NUM_8,
665 	MAC_AX_TAG_NUM_DEF = 0xFE
666 };
667 
668 enum mac_ax_lbc_tmr {
669 	MAC_AX_LBC_TMR_8US = 0,
670 	MAC_AX_LBC_TMR_16US,
671 	MAC_AX_LBC_TMR_32US,
672 	MAC_AX_LBC_TMR_64US,
673 	MAC_AX_LBC_TMR_128US,
674 	MAC_AX_LBC_TMR_256US,
675 	MAC_AX_LBC_TMR_512US,
676 	MAC_AX_LBC_TMR_1MS,
677 	MAC_AX_LBC_TMR_2MS,
678 	MAC_AX_LBC_TMR_4MS,
679 	MAC_AX_LBC_TMR_8MS,
680 	MAC_AX_LBC_TMR_DEF = 0xFE
681 };
682 
683 enum mac_ax_pcie_func_ctrl {
684 	MAC_AX_PCIE_DISABLE = 0,
685 	MAC_AX_PCIE_ENABLE = 1,
686 	MAC_AX_PCIE_DEFAULT = 0xFE,
687 	MAC_AX_PCIE_IGNORE = 0xFF
688 };
689 
690 enum mac_ax_io_rcy_tmr {
691 	MAC_AX_IO_RCY_ANA_TMR_2MS = 24000,
692 	MAC_AX_IO_RCY_ANA_TMR_4MS = 48000,
693 	MAC_AX_IO_RCY_ANA_TMR_6MS = 72000,
694 	MAC_AX_IO_RCY_ANA_TMR_DEF = 0xFE
695 };
696 
697 enum rtw89_pci_intr_mask_cfg {
698 	RTW89_PCI_INTR_MASK_RESET,
699 	RTW89_PCI_INTR_MASK_NORMAL,
700 	RTW89_PCI_INTR_MASK_LOW_POWER,
701 	RTW89_PCI_INTR_MASK_RECOVERY_START,
702 	RTW89_PCI_INTR_MASK_RECOVERY_COMPLETE,
703 };
704 
705 struct rtw89_pci_isrs;
706 struct rtw89_pci;
707 
708 struct rtw89_pci_bd_idx_addr {
709 	u32 tx_bd_addrs[RTW89_TXCH_NUM];
710 	u32 rx_bd_addrs[RTW89_RXCH_NUM];
711 };
712 
713 struct rtw89_pci_ch_dma_addr {
714 	u32 num;
715 	u32 idx;
716 	u32 bdram;
717 	u32 desa_l;
718 	u32 desa_h;
719 };
720 
721 struct rtw89_pci_ch_dma_addr_set {
722 	struct rtw89_pci_ch_dma_addr tx[RTW89_TXCH_NUM];
723 	struct rtw89_pci_ch_dma_addr rx[RTW89_RXCH_NUM];
724 };
725 
726 struct rtw89_pci_info {
727 	enum mac_ax_bd_trunc_mode txbd_trunc_mode;
728 	enum mac_ax_bd_trunc_mode rxbd_trunc_mode;
729 	enum mac_ax_rxbd_mode rxbd_mode;
730 	enum mac_ax_tag_mode tag_mode;
731 	enum mac_ax_tx_burst tx_burst;
732 	enum mac_ax_rx_burst rx_burst;
733 	enum mac_ax_wd_dma_intvl wd_dma_idle_intvl;
734 	enum mac_ax_wd_dma_intvl wd_dma_act_intvl;
735 	enum mac_ax_multi_tag_num multi_tag_num;
736 	enum mac_ax_pcie_func_ctrl lbc_en;
737 	enum mac_ax_lbc_tmr lbc_tmr;
738 	enum mac_ax_pcie_func_ctrl autok_en;
739 	enum mac_ax_pcie_func_ctrl io_rcy_en;
740 	enum mac_ax_io_rcy_tmr io_rcy_tmr;
741 
742 	u32 init_cfg_reg;
743 	u32 txhci_en_bit;
744 	u32 rxhci_en_bit;
745 	u32 rxbd_mode_bit;
746 	u32 exp_ctrl_reg;
747 	u32 max_tag_num_mask;
748 	u32 rxbd_rwptr_clr_reg;
749 	u32 txbd_rwptr_clr2_reg;
750 	u32 dma_stop1_reg;
751 	u32 dma_stop2_reg;
752 	u32 dma_busy1_reg;
753 	u32 dma_busy2_reg;
754 	u32 dma_busy3_reg;
755 
756 	u32 rpwm_addr;
757 	u32 cpwm_addr;
758 	const struct rtw89_pci_bd_idx_addr *bd_idx_addr_low_power;
759 	const struct rtw89_pci_ch_dma_addr_set *dma_addr_set;
760 
761 	int (*ltr_set)(struct rtw89_dev *rtwdev, bool en);
762 	u32 (*fill_txaddr_info)(struct rtw89_dev *rtwdev,
763 				void *txaddr_info_addr, u32 total_len,
764 				dma_addr_t dma, u8 *add_info_nr);
765 	void (*config_intr_mask)(struct rtw89_dev *rtwdev);
766 	void (*enable_intr)(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci);
767 	void (*disable_intr)(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci);
768 	void (*recognize_intrs)(struct rtw89_dev *rtwdev,
769 				struct rtw89_pci *rtwpci,
770 				struct rtw89_pci_isrs *isrs);
771 };
772 
773 struct rtw89_pci_bd_ram {
774 	u8 start_idx;
775 	u8 max_num;
776 	u8 min_num;
777 };
778 
779 struct rtw89_pci_tx_data {
780 	dma_addr_t dma;
781 };
782 
783 struct rtw89_pci_rx_info {
784 	dma_addr_t dma;
785 	u32 fs:1, ls:1, tag:11, len:14;
786 };
787 
788 #define RTW89_PCI_TXBD_OPTION_LS	BIT(14)
789 
790 struct rtw89_pci_tx_bd_32 {
791 	__le16 length;
792 	__le16 option;
793 	__le32 dma;
794 } __packed;
795 
796 #define RTW89_PCI_TXWP_VALID		BIT(15)
797 
798 struct rtw89_pci_tx_wp_info {
799 	__le16 seq0;
800 	__le16 seq1;
801 	__le16 seq2;
802 	__le16 seq3;
803 } __packed;
804 
805 #define RTW89_PCI_ADDR_MSDU_LS		BIT(15)
806 #define RTW89_PCI_ADDR_LS		BIT(14)
807 #define RTW89_PCI_ADDR_HIGH(a)		(((a) << 6) & GENMASK(13, 6))
808 #define RTW89_PCI_ADDR_NUM(x)		((x) & GENMASK(5, 0))
809 
810 struct rtw89_pci_tx_addr_info_32 {
811 	__le16 length;
812 	__le16 option;
813 	__le32 dma;
814 } __packed;
815 
816 #define RTW89_TXADDR_INFO_NR_V1		10
817 
818 struct rtw89_pci_tx_addr_info_32_v1 {
819 	__le16 length_opt;
820 #define B_PCIADDR_LEN_V1_MASK		GENMASK(10, 0)
821 #define B_PCIADDR_HIGH_SEL_V1_MASK	GENMASK(14, 11)
822 #define B_PCIADDR_LS_V1_MASK		BIT(15)
823 #define TXADDR_INFO_LENTHG_V1_MAX	ALIGN_DOWN(BIT(11) - 1, 4)
824 	__le16 dma_low_lsb;
825 	__le16 dma_low_msb;
826 } __packed;
827 
828 #define RTW89_PCI_RPP_POLLUTED		BIT(31)
829 #define RTW89_PCI_RPP_SEQ		GENMASK(30, 16)
830 #define RTW89_PCI_RPP_TX_STATUS		GENMASK(15, 13)
831 #define RTW89_TX_DONE			0x0
832 #define RTW89_TX_RETRY_LIMIT		0x1
833 #define RTW89_TX_LIFE_TIME		0x2
834 #define RTW89_TX_MACID_DROP		0x3
835 #define RTW89_PCI_RPP_QSEL		GENMASK(12, 8)
836 #define RTW89_PCI_RPP_MACID		GENMASK(7, 0)
837 
838 struct rtw89_pci_rpp_fmt {
839 	__le32 dword;
840 } __packed;
841 
842 struct rtw89_pci_rx_bd_32 {
843 	__le16 buf_size;
844 	__le16 rsvd;
845 	__le32 dma;
846 } __packed;
847 
848 #define RTW89_PCI_RXBD_FS		BIT(15)
849 #define RTW89_PCI_RXBD_LS		BIT(14)
850 #define RTW89_PCI_RXBD_WRITE_SIZE	GENMASK(13, 0)
851 #define RTW89_PCI_RXBD_TAG		GENMASK(28, 16)
852 
853 struct rtw89_pci_rxbd_info {
854 	__le32 dword;
855 };
856 
857 struct rtw89_pci_tx_wd {
858 	struct list_head list;
859 	struct sk_buff_head queue;
860 
861 	void *vaddr;
862 	dma_addr_t paddr;
863 	u32 len;
864 	u32 seq;
865 };
866 
867 struct rtw89_pci_dma_ring {
868 	void *head;
869 	u8 desc_size;
870 	dma_addr_t dma;
871 
872 	struct rtw89_pci_ch_dma_addr addr;
873 
874 	u32 len;
875 	u32 wp; /* host idx */
876 	u32 rp; /* hw idx */
877 };
878 
879 struct rtw89_pci_tx_wd_ring {
880 	void *head;
881 	dma_addr_t dma;
882 
883 	struct rtw89_pci_tx_wd pages[RTW89_PCI_TXWD_NUM_MAX];
884 	struct list_head free_pages;
885 
886 	u32 page_size;
887 	u32 page_num;
888 	u32 curr_num;
889 };
890 
891 #define RTW89_RX_TAG_MAX		0x1fff
892 
893 struct rtw89_pci_tx_ring {
894 	struct rtw89_pci_tx_wd_ring wd_ring;
895 	struct rtw89_pci_dma_ring bd_ring;
896 	struct list_head busy_pages;
897 	u8 txch;
898 	bool dma_enabled;
899 	u16 tag; /* range from 0x0001 ~ 0x1fff */
900 
901 	u64 tx_cnt;
902 	u64 tx_acked;
903 	u64 tx_retry_lmt;
904 	u64 tx_life_time;
905 	u64 tx_mac_id_drop;
906 };
907 
908 struct rtw89_pci_rx_ring {
909 	struct rtw89_pci_dma_ring bd_ring;
910 	struct sk_buff *buf[RTW89_PCI_RXBD_NUM_MAX];
911 	u32 buf_sz;
912 	struct sk_buff *diliver_skb;
913 	struct rtw89_rx_desc_info diliver_desc;
914 };
915 
916 struct rtw89_pci_isrs {
917 	u32 ind_isrs;
918 	u32 halt_c2h_isrs;
919 	u32 isrs[2];
920 };
921 
922 struct rtw89_pci {
923 	struct pci_dev *pdev;
924 
925 	/* protect HW irq related registers */
926 	spinlock_t irq_lock;
927 	/* protect TRX resources (exclude RXQ) */
928 	spinlock_t trx_lock;
929 	bool running;
930 	bool low_power;
931 	bool under_recovery;
932 	struct rtw89_pci_tx_ring tx_rings[RTW89_TXCH_NUM];
933 	struct rtw89_pci_rx_ring rx_rings[RTW89_RXCH_NUM];
934 	struct sk_buff_head h2c_queue;
935 	struct sk_buff_head h2c_release_queue;
936 	DECLARE_BITMAP(kick_map, RTW89_TXCH_NUM);
937 
938 	u32 ind_intrs;
939 	u32 halt_c2h_intrs;
940 	u32 intrs[2];
941 	void __iomem *mmap;
942 };
943 
944 static inline struct rtw89_pci_rx_info *RTW89_PCI_RX_SKB_CB(struct sk_buff *skb)
945 {
946 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
947 
948 	BUILD_BUG_ON(sizeof(struct rtw89_pci_tx_data) >
949 		     sizeof(info->status.status_driver_data));
950 
951 	return (struct rtw89_pci_rx_info *)skb->cb;
952 }
953 
954 static inline struct rtw89_pci_rx_bd_32 *
955 RTW89_PCI_RX_BD(struct rtw89_pci_rx_ring *rx_ring, u32 idx)
956 {
957 	struct rtw89_pci_dma_ring *bd_ring = &rx_ring->bd_ring;
958 	u8 *head = bd_ring->head;
959 	u32 desc_size = bd_ring->desc_size;
960 	u32 offset = idx * desc_size;
961 
962 	return (struct rtw89_pci_rx_bd_32 *)(head + offset);
963 }
964 
965 static inline void
966 rtw89_pci_rxbd_increase(struct rtw89_pci_rx_ring *rx_ring, u32 cnt)
967 {
968 	struct rtw89_pci_dma_ring *bd_ring = &rx_ring->bd_ring;
969 
970 	bd_ring->wp += cnt;
971 
972 	if (bd_ring->wp >= bd_ring->len)
973 		bd_ring->wp -= bd_ring->len;
974 }
975 
976 static inline struct rtw89_pci_tx_data *RTW89_PCI_TX_SKB_CB(struct sk_buff *skb)
977 {
978 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
979 
980 	return (struct rtw89_pci_tx_data *)info->status.status_driver_data;
981 }
982 
983 static inline struct rtw89_pci_tx_bd_32 *
984 rtw89_pci_get_next_txbd(struct rtw89_pci_tx_ring *tx_ring)
985 {
986 	struct rtw89_pci_dma_ring *bd_ring = &tx_ring->bd_ring;
987 	struct rtw89_pci_tx_bd_32 *tx_bd, *head;
988 
989 	head = bd_ring->head;
990 	tx_bd = head + bd_ring->wp;
991 
992 	return tx_bd;
993 }
994 
995 static inline struct rtw89_pci_tx_wd *
996 rtw89_pci_dequeue_txwd(struct rtw89_pci_tx_ring *tx_ring)
997 {
998 	struct rtw89_pci_tx_wd_ring *wd_ring = &tx_ring->wd_ring;
999 	struct rtw89_pci_tx_wd *txwd;
1000 
1001 	txwd = list_first_entry_or_null(&wd_ring->free_pages,
1002 					struct rtw89_pci_tx_wd, list);
1003 	if (!txwd)
1004 		return NULL;
1005 
1006 	list_del_init(&txwd->list);
1007 	txwd->len = 0;
1008 	wd_ring->curr_num--;
1009 
1010 	return txwd;
1011 }
1012 
1013 static inline void
1014 rtw89_pci_enqueue_txwd(struct rtw89_pci_tx_ring *tx_ring,
1015 		       struct rtw89_pci_tx_wd *txwd)
1016 {
1017 	struct rtw89_pci_tx_wd_ring *wd_ring = &tx_ring->wd_ring;
1018 
1019 	memset(txwd->vaddr, 0, wd_ring->page_size);
1020 	list_add_tail(&txwd->list, &wd_ring->free_pages);
1021 	wd_ring->curr_num++;
1022 }
1023 
1024 static inline bool rtw89_pci_ltr_is_err_reg_val(u32 val)
1025 {
1026 	return val == 0xffffffff || val == 0xeaeaeaea;
1027 }
1028 
1029 extern const struct dev_pm_ops rtw89_pm_ops;
1030 extern const struct rtw89_pci_ch_dma_addr_set rtw89_pci_ch_dma_addr_set;
1031 extern const struct rtw89_pci_ch_dma_addr_set rtw89_pci_ch_dma_addr_set_v1;
1032 
1033 struct pci_device_id;
1034 
1035 int rtw89_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id);
1036 void rtw89_pci_remove(struct pci_dev *pdev);
1037 int rtw89_pci_ltr_set(struct rtw89_dev *rtwdev, bool en);
1038 int rtw89_pci_ltr_set_v1(struct rtw89_dev *rtwdev, bool en);
1039 u32 rtw89_pci_fill_txaddr_info(struct rtw89_dev *rtwdev,
1040 			       void *txaddr_info_addr, u32 total_len,
1041 			       dma_addr_t dma, u8 *add_info_nr);
1042 u32 rtw89_pci_fill_txaddr_info_v1(struct rtw89_dev *rtwdev,
1043 				  void *txaddr_info_addr, u32 total_len,
1044 				  dma_addr_t dma, u8 *add_info_nr);
1045 void rtw89_pci_config_intr_mask(struct rtw89_dev *rtwdev);
1046 void rtw89_pci_config_intr_mask_v1(struct rtw89_dev *rtwdev);
1047 void rtw89_pci_enable_intr(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci);
1048 void rtw89_pci_disable_intr(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci);
1049 void rtw89_pci_enable_intr_v1(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci);
1050 void rtw89_pci_disable_intr_v1(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci);
1051 void rtw89_pci_recognize_intrs(struct rtw89_dev *rtwdev,
1052 			       struct rtw89_pci *rtwpci,
1053 			       struct rtw89_pci_isrs *isrs);
1054 void rtw89_pci_recognize_intrs_v1(struct rtw89_dev *rtwdev,
1055 				  struct rtw89_pci *rtwpci,
1056 				  struct rtw89_pci_isrs *isrs);
1057 
1058 static inline
1059 u32 rtw89_chip_fill_txaddr_info(struct rtw89_dev *rtwdev,
1060 				void *txaddr_info_addr, u32 total_len,
1061 				dma_addr_t dma, u8 *add_info_nr)
1062 {
1063 	const struct rtw89_pci_info *info = rtwdev->pci_info;
1064 
1065 	return info->fill_txaddr_info(rtwdev, txaddr_info_addr, total_len,
1066 				      dma, add_info_nr);
1067 }
1068 
1069 static inline void rtw89_chip_config_intr_mask(struct rtw89_dev *rtwdev,
1070 					       enum rtw89_pci_intr_mask_cfg cfg)
1071 {
1072 	struct rtw89_pci *rtwpci = (struct rtw89_pci *)rtwdev->priv;
1073 	const struct rtw89_pci_info *info = rtwdev->pci_info;
1074 
1075 	switch (cfg) {
1076 	default:
1077 	case RTW89_PCI_INTR_MASK_RESET:
1078 		rtwpci->low_power = false;
1079 		rtwpci->under_recovery = false;
1080 		break;
1081 	case RTW89_PCI_INTR_MASK_NORMAL:
1082 		rtwpci->low_power = false;
1083 		break;
1084 	case RTW89_PCI_INTR_MASK_LOW_POWER:
1085 		rtwpci->low_power = true;
1086 		break;
1087 	case RTW89_PCI_INTR_MASK_RECOVERY_START:
1088 		rtwpci->under_recovery = true;
1089 		break;
1090 	case RTW89_PCI_INTR_MASK_RECOVERY_COMPLETE:
1091 		rtwpci->under_recovery = false;
1092 		break;
1093 	}
1094 
1095 	rtw89_debug(rtwdev, RTW89_DBG_HCI,
1096 		    "Configure PCI interrupt mask mode low_power=%d under_recovery=%d\n",
1097 		    rtwpci->low_power, rtwpci->under_recovery);
1098 
1099 	info->config_intr_mask(rtwdev);
1100 }
1101 
1102 static inline
1103 void rtw89_chip_enable_intr(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci)
1104 {
1105 	const struct rtw89_pci_info *info = rtwdev->pci_info;
1106 
1107 	info->enable_intr(rtwdev, rtwpci);
1108 }
1109 
1110 static inline
1111 void rtw89_chip_disable_intr(struct rtw89_dev *rtwdev, struct rtw89_pci *rtwpci)
1112 {
1113 	const struct rtw89_pci_info *info = rtwdev->pci_info;
1114 
1115 	info->disable_intr(rtwdev, rtwpci);
1116 }
1117 
1118 static inline
1119 void rtw89_chip_recognize_intrs(struct rtw89_dev *rtwdev,
1120 				struct rtw89_pci *rtwpci,
1121 				struct rtw89_pci_isrs *isrs)
1122 {
1123 	const struct rtw89_pci_info *info = rtwdev->pci_info;
1124 
1125 	info->recognize_intrs(rtwdev, rtwpci, isrs);
1126 }
1127 
1128 #endif
1129