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