1*e3ec7017SPing-Ke Shih /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2*e3ec7017SPing-Ke Shih /* Copyright(c) 2020  Realtek Corporation
3*e3ec7017SPing-Ke Shih  */
4*e3ec7017SPing-Ke Shih 
5*e3ec7017SPing-Ke Shih #ifndef __RTW89_PCI_H__
6*e3ec7017SPing-Ke Shih #define __RTW89_PCI_H__
7*e3ec7017SPing-Ke Shih 
8*e3ec7017SPing-Ke Shih #include "txrx.h"
9*e3ec7017SPing-Ke Shih 
10*e3ec7017SPing-Ke Shih #define MDIO_PG0_G1 0
11*e3ec7017SPing-Ke Shih #define MDIO_PG1_G1 1
12*e3ec7017SPing-Ke Shih #define MDIO_PG0_G2 2
13*e3ec7017SPing-Ke Shih #define MDIO_PG1_G2 3
14*e3ec7017SPing-Ke Shih #define RAC_ANA10			0x10
15*e3ec7017SPing-Ke Shih #define RAC_ANA19			0x19
16*e3ec7017SPing-Ke Shih #define RAC_ANA1F			0x1F
17*e3ec7017SPing-Ke Shih #define RAC_ANA24			0x24
18*e3ec7017SPing-Ke Shih #define B_AX_DEGLITCH			GENMASK(11, 8)
19*e3ec7017SPing-Ke Shih #define RAC_ANA26			0x26
20*e3ec7017SPing-Ke Shih #define B_AX_RXEN			GENMASK(15, 14)
21*e3ec7017SPing-Ke Shih #define RAC_CTRL_PPR_V1			0x30
22*e3ec7017SPing-Ke Shih #define B_AX_CLK_CALIB_EN		BIT(12)
23*e3ec7017SPing-Ke Shih #define B_AX_CALIB_EN			BIT(13)
24*e3ec7017SPing-Ke Shih #define B_AX_DIV			GENMASK(15, 14)
25*e3ec7017SPing-Ke Shih #define RAC_SET_PPR_V1			0x31
26*e3ec7017SPing-Ke Shih 
27*e3ec7017SPing-Ke Shih #define R_AX_DBI_FLAG			0x1090
28*e3ec7017SPing-Ke Shih #define B_AX_DBI_RFLAG			BIT(17)
29*e3ec7017SPing-Ke Shih #define B_AX_DBI_WFLAG			BIT(16)
30*e3ec7017SPing-Ke Shih #define B_AX_DBI_WREN_MSK		GENMASK(15, 12)
31*e3ec7017SPing-Ke Shih #define B_AX_DBI_ADDR_MSK		GENMASK(11, 2)
32*e3ec7017SPing-Ke Shih #define R_AX_DBI_WDATA			0x1094
33*e3ec7017SPing-Ke Shih #define R_AX_DBI_RDATA			0x1098
34*e3ec7017SPing-Ke Shih 
35*e3ec7017SPing-Ke Shih #define R_AX_MDIO_WDATA			0x10A4
36*e3ec7017SPing-Ke Shih #define R_AX_MDIO_RDATA			0x10A6
37*e3ec7017SPing-Ke Shih 
38*e3ec7017SPing-Ke Shih #define RTW89_PCI_WR_RETRY_CNT		20
39*e3ec7017SPing-Ke Shih 
40*e3ec7017SPing-Ke Shih /* Interrupts */
41*e3ec7017SPing-Ke Shih #define R_AX_HIMR0 0x01A0
42*e3ec7017SPing-Ke Shih #define B_AX_HALT_C2H_INT_EN BIT(21)
43*e3ec7017SPing-Ke Shih #define R_AX_HISR0 0x01A4
44*e3ec7017SPing-Ke Shih 
45*e3ec7017SPing-Ke Shih #define R_AX_MDIO_CFG			0x10A0
46*e3ec7017SPing-Ke Shih #define B_AX_MDIO_PHY_ADDR_MASK		GENMASK(13, 12)
47*e3ec7017SPing-Ke Shih #define B_AX_MDIO_RFLAG			BIT(9)
48*e3ec7017SPing-Ke Shih #define B_AX_MDIO_WFLAG			BIT(8)
49*e3ec7017SPing-Ke Shih #define B_AX_MDIO_ADDR_MASK		GENMASK(4, 0)
50*e3ec7017SPing-Ke Shih 
51*e3ec7017SPing-Ke Shih #define R_AX_PCIE_HIMR00	0x10B0
52*e3ec7017SPing-Ke Shih #define B_AX_HC00ISR_IND_INT_EN		BIT(27)
53*e3ec7017SPing-Ke Shih #define B_AX_HD1ISR_IND_INT_EN		BIT(26)
54*e3ec7017SPing-Ke Shih #define B_AX_HD0ISR_IND_INT_EN		BIT(25)
55*e3ec7017SPing-Ke Shih #define B_AX_HS0ISR_IND_INT_EN		BIT(24)
56*e3ec7017SPing-Ke Shih #define B_AX_RETRAIN_INT_EN		BIT(21)
57*e3ec7017SPing-Ke Shih #define B_AX_RPQBD_FULL_INT_EN		BIT(20)
58*e3ec7017SPing-Ke Shih #define B_AX_RDU_INT_EN			BIT(19)
59*e3ec7017SPing-Ke Shih #define B_AX_RXDMA_STUCK_INT_EN		BIT(18)
60*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_STUCK_INT_EN		BIT(17)
61*e3ec7017SPing-Ke Shih #define B_AX_PCIE_HOTRST_INT_EN		BIT(16)
62*e3ec7017SPing-Ke Shih #define B_AX_PCIE_FLR_INT_EN		BIT(15)
63*e3ec7017SPing-Ke Shih #define B_AX_PCIE_PERST_INT_EN		BIT(14)
64*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH12_INT_EN		BIT(13)
65*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH9_INT_EN		BIT(12)
66*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH8_INT_EN		BIT(11)
67*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH7_INT_EN		BIT(10)
68*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH6_INT_EN		BIT(9)
69*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH5_INT_EN		BIT(8)
70*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH4_INT_EN		BIT(7)
71*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH3_INT_EN		BIT(6)
72*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH2_INT_EN		BIT(5)
73*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH1_INT_EN		BIT(4)
74*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH0_INT_EN		BIT(3)
75*e3ec7017SPing-Ke Shih #define B_AX_RPQDMA_INT_EN		BIT(2)
76*e3ec7017SPing-Ke Shih #define B_AX_RXP1DMA_INT_EN		BIT(1)
77*e3ec7017SPing-Ke Shih #define B_AX_RXDMA_INT_EN		BIT(0)
78*e3ec7017SPing-Ke Shih 
79*e3ec7017SPing-Ke Shih #define R_AX_PCIE_HISR00	0x10B4
80*e3ec7017SPing-Ke Shih #define B_AX_HC00ISR_IND_INT		BIT(27)
81*e3ec7017SPing-Ke Shih #define B_AX_HD1ISR_IND_INT		BIT(26)
82*e3ec7017SPing-Ke Shih #define B_AX_HD0ISR_IND_INT		BIT(25)
83*e3ec7017SPing-Ke Shih #define B_AX_HS0ISR_IND_INT		BIT(24)
84*e3ec7017SPing-Ke Shih #define B_AX_RETRAIN_INT		BIT(21)
85*e3ec7017SPing-Ke Shih #define B_AX_RPQBD_FULL_INT		BIT(20)
86*e3ec7017SPing-Ke Shih #define B_AX_RDU_INT			BIT(19)
87*e3ec7017SPing-Ke Shih #define B_AX_RXDMA_STUCK_INT		BIT(18)
88*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_STUCK_INT		BIT(17)
89*e3ec7017SPing-Ke Shih #define B_AX_PCIE_HOTRST_INT		BIT(16)
90*e3ec7017SPing-Ke Shih #define B_AX_PCIE_FLR_INT		BIT(15)
91*e3ec7017SPing-Ke Shih #define B_AX_PCIE_PERST_INT		BIT(14)
92*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH12_INT		BIT(13)
93*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH9_INT		BIT(12)
94*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH8_INT		BIT(11)
95*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH7_INT		BIT(10)
96*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH6_INT		BIT(9)
97*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH5_INT		BIT(8)
98*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH4_INT		BIT(7)
99*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH3_INT		BIT(6)
100*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH2_INT		BIT(5)
101*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH1_INT		BIT(4)
102*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_ACH0_INT		BIT(3)
103*e3ec7017SPing-Ke Shih #define B_AX_RPQDMA_INT			BIT(2)
104*e3ec7017SPing-Ke Shih #define B_AX_RXP1DMA_INT		BIT(1)
105*e3ec7017SPing-Ke Shih #define B_AX_RXDMA_INT			BIT(0)
106*e3ec7017SPing-Ke Shih 
107*e3ec7017SPing-Ke Shih #define R_AX_PCIE_HIMR10	0x13B0
108*e3ec7017SPing-Ke Shih #define B_AX_HC10ISR_IND_INT_EN		BIT(28)
109*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH11_INT_EN		BIT(12)
110*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH10_INT_EN		BIT(11)
111*e3ec7017SPing-Ke Shih 
112*e3ec7017SPing-Ke Shih #define R_AX_PCIE_HISR10	0x13B4
113*e3ec7017SPing-Ke Shih #define B_AX_HC10ISR_IND_INT		BIT(28)
114*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH11_INT		BIT(12)
115*e3ec7017SPing-Ke Shih #define B_AX_TXDMA_CH10_INT		BIT(11)
116*e3ec7017SPing-Ke Shih 
117*e3ec7017SPing-Ke Shih /* TX/RX */
118*e3ec7017SPing-Ke Shih #define R_AX_RXQ_RXBD_IDX	0x1050
119*e3ec7017SPing-Ke Shih #define R_AX_RPQ_RXBD_IDX	0x1054
120*e3ec7017SPing-Ke Shih #define R_AX_ACH0_TXBD_IDX	0x1058
121*e3ec7017SPing-Ke Shih #define R_AX_ACH1_TXBD_IDX	0x105C
122*e3ec7017SPing-Ke Shih #define R_AX_ACH2_TXBD_IDX	0x1060
123*e3ec7017SPing-Ke Shih #define R_AX_ACH3_TXBD_IDX	0x1064
124*e3ec7017SPing-Ke Shih #define R_AX_ACH4_TXBD_IDX	0x1068
125*e3ec7017SPing-Ke Shih #define R_AX_ACH5_TXBD_IDX	0x106C
126*e3ec7017SPing-Ke Shih #define R_AX_ACH6_TXBD_IDX	0x1070
127*e3ec7017SPing-Ke Shih #define R_AX_ACH7_TXBD_IDX	0x1074
128*e3ec7017SPing-Ke Shih #define R_AX_CH8_TXBD_IDX	0x1078 /* Management Queue band 0 */
129*e3ec7017SPing-Ke Shih #define R_AX_CH9_TXBD_IDX	0x107C /* HI Queue band 0 */
130*e3ec7017SPing-Ke Shih #define R_AX_CH10_TXBD_IDX	0x137C /* Management Queue band 1 */
131*e3ec7017SPing-Ke Shih #define R_AX_CH11_TXBD_IDX	0x1380 /* HI Queue band 1 */
132*e3ec7017SPing-Ke Shih #define R_AX_CH12_TXBD_IDX	0x1080 /* FWCMD Queue */
133*e3ec7017SPing-Ke Shih #define TXBD_HW_IDX_MASK	GENMASK(27, 16)
134*e3ec7017SPing-Ke Shih #define TXBD_HOST_IDX_MASK	GENMASK(11, 0)
135*e3ec7017SPing-Ke Shih 
136*e3ec7017SPing-Ke Shih #define R_AX_ACH0_TXBD_DESA_L	0x1110
137*e3ec7017SPing-Ke Shih #define R_AX_ACH0_TXBD_DESA_H	0x1114
138*e3ec7017SPing-Ke Shih #define R_AX_ACH1_TXBD_DESA_L	0x1118
139*e3ec7017SPing-Ke Shih #define R_AX_ACH1_TXBD_DESA_H	0x111C
140*e3ec7017SPing-Ke Shih #define R_AX_ACH2_TXBD_DESA_L	0x1120
141*e3ec7017SPing-Ke Shih #define R_AX_ACH2_TXBD_DESA_H	0x1124
142*e3ec7017SPing-Ke Shih #define R_AX_ACH3_TXBD_DESA_L	0x1128
143*e3ec7017SPing-Ke Shih #define R_AX_ACH3_TXBD_DESA_H	0x112C
144*e3ec7017SPing-Ke Shih #define R_AX_ACH4_TXBD_DESA_L	0x1130
145*e3ec7017SPing-Ke Shih #define R_AX_ACH4_TXBD_DESA_H	0x1134
146*e3ec7017SPing-Ke Shih #define R_AX_ACH5_TXBD_DESA_L	0x1138
147*e3ec7017SPing-Ke Shih #define R_AX_ACH5_TXBD_DESA_H	0x113C
148*e3ec7017SPing-Ke Shih #define R_AX_ACH6_TXBD_DESA_L	0x1140
149*e3ec7017SPing-Ke Shih #define R_AX_ACH6_TXBD_DESA_H	0x1144
150*e3ec7017SPing-Ke Shih #define R_AX_ACH7_TXBD_DESA_L	0x1148
151*e3ec7017SPing-Ke Shih #define R_AX_ACH7_TXBD_DESA_H	0x114C
152*e3ec7017SPing-Ke Shih #define R_AX_CH8_TXBD_DESA_L	0x1150
153*e3ec7017SPing-Ke Shih #define R_AX_CH8_TXBD_DESA_H	0x1154
154*e3ec7017SPing-Ke Shih #define R_AX_CH9_TXBD_DESA_L	0x1158
155*e3ec7017SPing-Ke Shih #define R_AX_CH9_TXBD_DESA_H	0x115C
156*e3ec7017SPing-Ke Shih #define R_AX_CH10_TXBD_DESA_L	0x1358
157*e3ec7017SPing-Ke Shih #define R_AX_CH10_TXBD_DESA_H	0x135C
158*e3ec7017SPing-Ke Shih #define R_AX_CH11_TXBD_DESA_L	0x1360
159*e3ec7017SPing-Ke Shih #define R_AX_CH11_TXBD_DESA_H	0x1364
160*e3ec7017SPing-Ke Shih #define R_AX_CH12_TXBD_DESA_L	0x1160
161*e3ec7017SPing-Ke Shih #define R_AX_CH12_TXBD_DESA_H	0x1164
162*e3ec7017SPing-Ke Shih #define R_AX_RXQ_RXBD_DESA_L	0x1100
163*e3ec7017SPing-Ke Shih #define R_AX_RXQ_RXBD_DESA_H	0x1104
164*e3ec7017SPing-Ke Shih #define R_AX_RPQ_RXBD_DESA_L	0x1108
165*e3ec7017SPing-Ke Shih #define R_AX_RPQ_RXBD_DESA_H	0x110C
166*e3ec7017SPing-Ke Shih #define B_AX_DESC_NUM_MSK		GENMASK(11, 0)
167*e3ec7017SPing-Ke Shih 
168*e3ec7017SPing-Ke Shih #define R_AX_RXQ_RXBD_NUM	0x1020
169*e3ec7017SPing-Ke Shih #define R_AX_RPQ_RXBD_NUM	0x1022
170*e3ec7017SPing-Ke Shih #define R_AX_ACH0_TXBD_NUM	0x1024
171*e3ec7017SPing-Ke Shih #define R_AX_ACH1_TXBD_NUM	0x1026
172*e3ec7017SPing-Ke Shih #define R_AX_ACH2_TXBD_NUM	0x1028
173*e3ec7017SPing-Ke Shih #define R_AX_ACH3_TXBD_NUM	0x102A
174*e3ec7017SPing-Ke Shih #define R_AX_ACH4_TXBD_NUM	0x102C
175*e3ec7017SPing-Ke Shih #define R_AX_ACH5_TXBD_NUM	0x102E
176*e3ec7017SPing-Ke Shih #define R_AX_ACH6_TXBD_NUM	0x1030
177*e3ec7017SPing-Ke Shih #define R_AX_ACH7_TXBD_NUM	0x1032
178*e3ec7017SPing-Ke Shih #define R_AX_CH8_TXBD_NUM	0x1034
179*e3ec7017SPing-Ke Shih #define R_AX_CH9_TXBD_NUM	0x1036
180*e3ec7017SPing-Ke Shih #define R_AX_CH10_TXBD_NUM	0x1338
181*e3ec7017SPing-Ke Shih #define R_AX_CH11_TXBD_NUM	0x133A
182*e3ec7017SPing-Ke Shih #define R_AX_CH12_TXBD_NUM	0x1038
183*e3ec7017SPing-Ke Shih 
184*e3ec7017SPing-Ke Shih #define R_AX_ACH0_BDRAM_CTRL	0x1200
185*e3ec7017SPing-Ke Shih #define R_AX_ACH1_BDRAM_CTRL	0x1204
186*e3ec7017SPing-Ke Shih #define R_AX_ACH2_BDRAM_CTRL	0x1208
187*e3ec7017SPing-Ke Shih #define R_AX_ACH3_BDRAM_CTRL	0x120C
188*e3ec7017SPing-Ke Shih #define R_AX_ACH4_BDRAM_CTRL	0x1210
189*e3ec7017SPing-Ke Shih #define R_AX_ACH5_BDRAM_CTRL	0x1214
190*e3ec7017SPing-Ke Shih #define R_AX_ACH6_BDRAM_CTRL	0x1218
191*e3ec7017SPing-Ke Shih #define R_AX_ACH7_BDRAM_CTRL	0x121C
192*e3ec7017SPing-Ke Shih #define R_AX_CH8_BDRAM_CTRL	0x1220
193*e3ec7017SPing-Ke Shih #define R_AX_CH9_BDRAM_CTRL	0x1224
194*e3ec7017SPing-Ke Shih #define R_AX_CH10_BDRAM_CTRL	0x1320
195*e3ec7017SPing-Ke Shih #define R_AX_CH11_BDRAM_CTRL	0x1324
196*e3ec7017SPing-Ke Shih #define R_AX_CH12_BDRAM_CTRL	0x1228
197*e3ec7017SPing-Ke Shih #define BDRAM_SIDX_MASK		GENMASK(7, 0)
198*e3ec7017SPing-Ke Shih #define BDRAM_MAX_MASK		GENMASK(15, 8)
199*e3ec7017SPing-Ke Shih #define BDRAM_MIN_MASK		GENMASK(23, 16)
200*e3ec7017SPing-Ke Shih 
201*e3ec7017SPing-Ke Shih #define R_AX_PCIE_INIT_CFG1	0x1000
202*e3ec7017SPing-Ke Shih #define B_AX_PCIE_RXRST_KEEP_REG	BIT(23)
203*e3ec7017SPing-Ke Shih #define B_AX_PCIE_TXRST_KEEP_REG	BIT(22)
204*e3ec7017SPing-Ke Shih #define B_AX_PCIE_PERST_KEEP_REG	BIT(21)
205*e3ec7017SPing-Ke Shih #define B_AX_PCIE_FLR_KEEP_REG		BIT(20)
206*e3ec7017SPing-Ke Shih #define B_AX_PCIE_TRAIN_KEEP_REG	BIT(19)
207*e3ec7017SPing-Ke Shih #define B_AX_RXBD_MODE			BIT(18)
208*e3ec7017SPing-Ke Shih #define B_AX_PCIE_MAX_RXDMA_MASK	GENMASK(16, 14)
209*e3ec7017SPing-Ke Shih #define B_AX_RXHCI_EN			BIT(13)
210*e3ec7017SPing-Ke Shih #define B_AX_LATENCY_CONTROL		BIT(12)
211*e3ec7017SPing-Ke Shih #define B_AX_TXHCI_EN			BIT(11)
212*e3ec7017SPing-Ke Shih #define B_AX_PCIE_MAX_TXDMA_MASK	GENMASK(10, 8)
213*e3ec7017SPing-Ke Shih #define B_AX_TX_TRUNC_MODE		BIT(5)
214*e3ec7017SPing-Ke Shih #define B_AX_RX_TRUNC_MODE		BIT(4)
215*e3ec7017SPing-Ke Shih #define B_AX_RST_BDRAM			BIT(3)
216*e3ec7017SPing-Ke Shih #define B_AX_DIS_RXDMA_PRE		BIT(2)
217*e3ec7017SPing-Ke Shih 
218*e3ec7017SPing-Ke Shih #define R_AX_TXDMA_ADDR_H	0x10F0
219*e3ec7017SPing-Ke Shih #define R_AX_RXDMA_ADDR_H	0x10F4
220*e3ec7017SPing-Ke Shih 
221*e3ec7017SPing-Ke Shih #define R_AX_PCIE_DMA_STOP1	0x1010
222*e3ec7017SPing-Ke Shih #define B_AX_STOP_PCIEIO		BIT(20)
223*e3ec7017SPing-Ke Shih #define B_AX_STOP_WPDMA			BIT(19)
224*e3ec7017SPing-Ke Shih #define B_AX_STOP_CH12			BIT(18)
225*e3ec7017SPing-Ke Shih #define B_AX_STOP_CH9			BIT(17)
226*e3ec7017SPing-Ke Shih #define B_AX_STOP_CH8			BIT(16)
227*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH7			BIT(15)
228*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH6			BIT(14)
229*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH5			BIT(13)
230*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH4			BIT(12)
231*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH3			BIT(11)
232*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH2			BIT(10)
233*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH1			BIT(9)
234*e3ec7017SPing-Ke Shih #define B_AX_STOP_ACH0			BIT(8)
235*e3ec7017SPing-Ke Shih #define B_AX_STOP_RPQ			BIT(1)
236*e3ec7017SPing-Ke Shih #define B_AX_STOP_RXQ			BIT(0)
237*e3ec7017SPing-Ke Shih #define B_AX_TX_STOP1_ALL		GENMASK(18, 8)
238*e3ec7017SPing-Ke Shih 
239*e3ec7017SPing-Ke Shih #define R_AX_PCIE_DMA_STOP2	0x1310
240*e3ec7017SPing-Ke Shih #define B_AX_STOP_CH11			BIT(1)
241*e3ec7017SPing-Ke Shih #define B_AX_STOP_CH10			BIT(0)
242*e3ec7017SPing-Ke Shih #define B_AX_TX_STOP2_ALL		GENMASK(1, 0)
243*e3ec7017SPing-Ke Shih 
244*e3ec7017SPing-Ke Shih #define R_AX_TXBD_RWPTR_CLR1	0x1014
245*e3ec7017SPing-Ke Shih #define B_AX_CLR_CH12_IDX		BIT(10)
246*e3ec7017SPing-Ke Shih #define B_AX_CLR_CH9_IDX		BIT(9)
247*e3ec7017SPing-Ke Shih #define B_AX_CLR_CH8_IDX		BIT(8)
248*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH7_IDX		BIT(7)
249*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH6_IDX		BIT(6)
250*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH5_IDX		BIT(5)
251*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH4_IDX		BIT(4)
252*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH3_IDX		BIT(3)
253*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH2_IDX		BIT(2)
254*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH1_IDX		BIT(1)
255*e3ec7017SPing-Ke Shih #define B_AX_CLR_ACH0_IDX		BIT(0)
256*e3ec7017SPing-Ke Shih #define B_AX_TXBD_CLR1_ALL		GENMASK(10, 0)
257*e3ec7017SPing-Ke Shih 
258*e3ec7017SPing-Ke Shih #define R_AX_RXBD_RWPTR_CLR	0x1018
259*e3ec7017SPing-Ke Shih #define B_AX_CLR_RPQ_IDX		BIT(1)
260*e3ec7017SPing-Ke Shih #define B_AX_CLR_RXQ_IDX		BIT(0)
261*e3ec7017SPing-Ke Shih #define B_AX_RXBD_CLR_ALL		GENMASK(1, 0)
262*e3ec7017SPing-Ke Shih 
263*e3ec7017SPing-Ke Shih #define R_AX_TXBD_RWPTR_CLR2	0x1314
264*e3ec7017SPing-Ke Shih #define B_AX_CLR_CH11_IDX		BIT(1)
265*e3ec7017SPing-Ke Shih #define B_AX_CLR_CH10_IDX		BIT(0)
266*e3ec7017SPing-Ke Shih #define B_AX_TXBD_CLR2_ALL		GENMASK(1, 0)
267*e3ec7017SPing-Ke Shih 
268*e3ec7017SPing-Ke Shih #define R_AX_PCIE_DMA_BUSY1	0x101C
269*e3ec7017SPing-Ke Shih #define B_AX_PCIEIO_RX_BUSY		BIT(22)
270*e3ec7017SPing-Ke Shih #define B_AX_PCIEIO_TX_BUSY		BIT(21)
271*e3ec7017SPing-Ke Shih #define B_AX_PCIEIO_BUSY		BIT(20)
272*e3ec7017SPing-Ke Shih #define B_AX_WPDMA_BUSY			BIT(19)
273*e3ec7017SPing-Ke Shih 
274*e3ec7017SPing-Ke Shih #define R_AX_PCIE_DMA_BUSY2	0x131C
275*e3ec7017SPing-Ke Shih #define B_AX_CH11_BUSY			BIT(1)
276*e3ec7017SPing-Ke Shih #define B_AX_CH10_BUSY			BIT(0)
277*e3ec7017SPing-Ke Shih 
278*e3ec7017SPing-Ke Shih /* Configure */
279*e3ec7017SPing-Ke Shih #define R_AX_PCIE_INIT_CFG1	0x1000
280*e3ec7017SPing-Ke Shih #define B_AX_PCIE_RXRST_KEEP_REG	BIT(23)
281*e3ec7017SPing-Ke Shih #define B_AX_PCIE_TXRST_KEEP_REG	BIT(22)
282*e3ec7017SPing-Ke Shih #define B_AX_DIS_RXDMA_PRE		BIT(2)
283*e3ec7017SPing-Ke Shih 
284*e3ec7017SPing-Ke Shih #define R_AX_PCIE_INIT_CFG2		0x1004
285*e3ec7017SPing-Ke Shih #define B_AX_WD_ITVL_IDLE		GENMASK(27, 24)
286*e3ec7017SPing-Ke Shih #define B_AX_WD_ITVL_ACT		GENMASK(19, 16)
287*e3ec7017SPing-Ke Shih 
288*e3ec7017SPing-Ke Shih #define R_AX_PCIE_PS_CTRL		0x1008
289*e3ec7017SPing-Ke Shih #define B_AX_L1OFF_PWR_OFF_EN		BIT(5)
290*e3ec7017SPing-Ke Shih 
291*e3ec7017SPing-Ke Shih #define R_AX_INT_MIT_RX			0x10D4
292*e3ec7017SPing-Ke Shih #define B_AX_RXMIT_RXP2_SEL		BIT(19)
293*e3ec7017SPing-Ke Shih #define B_AX_RXMIT_RXP1_SEL		BIT(18)
294*e3ec7017SPing-Ke Shih #define B_AX_RXTIMER_UNIT_MASK		GENMASK(17, 16)
295*e3ec7017SPing-Ke Shih #define AX_RXTIMER_UNIT_64US		0
296*e3ec7017SPing-Ke Shih #define AX_RXTIMER_UNIT_128US		1
297*e3ec7017SPing-Ke Shih #define AX_RXTIMER_UNIT_256US		2
298*e3ec7017SPing-Ke Shih #define AX_RXTIMER_UNIT_512US		3
299*e3ec7017SPing-Ke Shih #define B_AX_RXCOUNTER_MATCH_MASK	GENMASK(15, 8)
300*e3ec7017SPing-Ke Shih #define B_AX_RXTIMER_MATCH_MASK		GENMASK(7, 0)
301*e3ec7017SPing-Ke Shih 
302*e3ec7017SPing-Ke Shih #define R_AX_DBG_ERR_FLAG		0x11C4
303*e3ec7017SPing-Ke Shih #define B_AX_PCIE_RPQ_FULL		BIT(29)
304*e3ec7017SPing-Ke Shih #define B_AX_PCIE_RXQ_FULL		BIT(28)
305*e3ec7017SPing-Ke Shih #define B_AX_CPL_STATUS_MASK		GENMASK(27, 25)
306*e3ec7017SPing-Ke Shih #define B_AX_RX_STUCK			BIT(22)
307*e3ec7017SPing-Ke Shih #define B_AX_TX_STUCK			BIT(21)
308*e3ec7017SPing-Ke Shih #define B_AX_PCIEDBG_TXERR0		BIT(16)
309*e3ec7017SPing-Ke Shih #define B_AX_PCIE_RXP1_ERR0		BIT(4)
310*e3ec7017SPing-Ke Shih #define B_AX_PCIE_TXBD_LEN0		BIT(1)
311*e3ec7017SPing-Ke Shih #define B_AX_PCIE_TXBD_4KBOUD_LENERR	BIT(0)
312*e3ec7017SPing-Ke Shih 
313*e3ec7017SPing-Ke Shih #define R_AX_LBC_WATCHDOG		0x11D8
314*e3ec7017SPing-Ke Shih #define B_AX_LBC_TIMER			GENMASK(7, 4)
315*e3ec7017SPing-Ke Shih #define B_AX_LBC_FLAG			BIT(1)
316*e3ec7017SPing-Ke Shih #define B_AX_LBC_EN			BIT(0)
317*e3ec7017SPing-Ke Shih 
318*e3ec7017SPing-Ke Shih #define R_AX_PCIE_EXP_CTRL		0x13F0
319*e3ec7017SPing-Ke Shih #define B_AX_EN_CHKDSC_NO_RX_STUCK	BIT(20)
320*e3ec7017SPing-Ke Shih #define B_AX_MAX_TAG_NUM		GENMASK(18, 16)
321*e3ec7017SPing-Ke Shih #define B_AX_SIC_EN_FORCE_CLKREQ	BIT(4)
322*e3ec7017SPing-Ke Shih 
323*e3ec7017SPing-Ke Shih #define R_AX_PCIE_RX_PREF_ADV		0x13F4
324*e3ec7017SPing-Ke Shih #define B_AX_RXDMA_PREF_ADV_EN		BIT(0)
325*e3ec7017SPing-Ke Shih 
326*e3ec7017SPing-Ke Shih #define RTW89_PCI_TXBD_NUM_MAX		256
327*e3ec7017SPing-Ke Shih #define RTW89_PCI_RXBD_NUM_MAX		256
328*e3ec7017SPing-Ke Shih #define RTW89_PCI_TXWD_NUM_MAX		512
329*e3ec7017SPing-Ke Shih #define RTW89_PCI_TXWD_PAGE_SIZE	128
330*e3ec7017SPing-Ke Shih #define RTW89_PCI_ADDRINFO_MAX		4
331*e3ec7017SPing-Ke Shih #define RTW89_PCI_RX_BUF_SIZE		11460
332*e3ec7017SPing-Ke Shih 
333*e3ec7017SPing-Ke Shih #define RTW89_PCI_POLL_BDRAM_RST_CNT	100
334*e3ec7017SPing-Ke Shih #define RTW89_PCI_MULTITAG		8
335*e3ec7017SPing-Ke Shih 
336*e3ec7017SPing-Ke Shih /* PCIE CFG register */
337*e3ec7017SPing-Ke Shih #define RTW89_PCIE_ASPM_CTRL		0x070F
338*e3ec7017SPing-Ke Shih #define RTW89_L1DLY_MASK		GENMASK(5, 3)
339*e3ec7017SPing-Ke Shih #define RTW89_L0DLY_MASK		GENMASK(2, 0)
340*e3ec7017SPing-Ke Shih #define RTW89_PCIE_TIMER_CTRL		0x0718
341*e3ec7017SPing-Ke Shih #define RTW89_PCIE_BIT_L1SUB		BIT(5)
342*e3ec7017SPing-Ke Shih #define RTW89_PCIE_L1_CTRL		0x0719
343*e3ec7017SPing-Ke Shih #define RTW89_PCIE_BIT_CLK		BIT(4)
344*e3ec7017SPing-Ke Shih #define RTW89_PCIE_BIT_L1		BIT(3)
345*e3ec7017SPing-Ke Shih #define RTW89_PCIE_CLK_CTRL		0x0725
346*e3ec7017SPing-Ke Shih #define RTW89_PCIE_RST_MSTATE		0x0B48
347*e3ec7017SPing-Ke Shih #define RTW89_PCIE_BIT_CFG_RST_MSTATE	BIT(0)
348*e3ec7017SPing-Ke Shih #define RTW89_PCIE_PHY_RATE		0x82
349*e3ec7017SPing-Ke Shih #define RTW89_PCIE_PHY_RATE_MASK	GENMASK(1, 0)
350*e3ec7017SPing-Ke Shih #define INTF_INTGRA_MINREF_V1	90
351*e3ec7017SPing-Ke Shih #define INTF_INTGRA_HOSTREF_V1	100
352*e3ec7017SPing-Ke Shih 
353*e3ec7017SPing-Ke Shih enum rtw89_pcie_phy {
354*e3ec7017SPing-Ke Shih 	PCIE_PHY_GEN1,
355*e3ec7017SPing-Ke Shih 	PCIE_PHY_GEN2,
356*e3ec7017SPing-Ke Shih 	PCIE_PHY_GEN1_UNDEFINE = 0x7F,
357*e3ec7017SPing-Ke Shih };
358*e3ec7017SPing-Ke Shih 
359*e3ec7017SPing-Ke Shih enum mac_ax_func_sw {
360*e3ec7017SPing-Ke Shih 	MAC_AX_FUNC_DIS,
361*e3ec7017SPing-Ke Shih 	MAC_AX_FUNC_EN,
362*e3ec7017SPing-Ke Shih };
363*e3ec7017SPing-Ke Shih 
364*e3ec7017SPing-Ke Shih enum rtw89_pcie_l0sdly {
365*e3ec7017SPing-Ke Shih 	PCIE_L0SDLY_1US = 0,
366*e3ec7017SPing-Ke Shih 	PCIE_L0SDLY_2US = 1,
367*e3ec7017SPing-Ke Shih 	PCIE_L0SDLY_3US = 2,
368*e3ec7017SPing-Ke Shih 	PCIE_L0SDLY_4US = 3,
369*e3ec7017SPing-Ke Shih 	PCIE_L0SDLY_5US = 4,
370*e3ec7017SPing-Ke Shih 	PCIE_L0SDLY_6US = 5,
371*e3ec7017SPing-Ke Shih 	PCIE_L0SDLY_7US = 6,
372*e3ec7017SPing-Ke Shih };
373*e3ec7017SPing-Ke Shih 
374*e3ec7017SPing-Ke Shih enum rtw89_pcie_l1dly {
375*e3ec7017SPing-Ke Shih 	PCIE_L1DLY_16US = 4,
376*e3ec7017SPing-Ke Shih 	PCIE_L1DLY_32US = 5,
377*e3ec7017SPing-Ke Shih 	PCIE_L1DLY_64US = 6,
378*e3ec7017SPing-Ke Shih 	PCIE_L1DLY_HW_INFI = 7,
379*e3ec7017SPing-Ke Shih };
380*e3ec7017SPing-Ke Shih 
381*e3ec7017SPing-Ke Shih enum rtw89_pcie_clkdly_hw {
382*e3ec7017SPing-Ke Shih 	PCIE_CLKDLY_HW_0 = 0,
383*e3ec7017SPing-Ke Shih 	PCIE_CLKDLY_HW_30US = 0x1,
384*e3ec7017SPing-Ke Shih 	PCIE_CLKDLY_HW_50US = 0x2,
385*e3ec7017SPing-Ke Shih 	PCIE_CLKDLY_HW_100US = 0x3,
386*e3ec7017SPing-Ke Shih 	PCIE_CLKDLY_HW_150US = 0x4,
387*e3ec7017SPing-Ke Shih 	PCIE_CLKDLY_HW_200US = 0x5,
388*e3ec7017SPing-Ke Shih };
389*e3ec7017SPing-Ke Shih 
390*e3ec7017SPing-Ke Shih struct rtw89_pci_bd_ram {
391*e3ec7017SPing-Ke Shih 	u8 start_idx;
392*e3ec7017SPing-Ke Shih 	u8 max_num;
393*e3ec7017SPing-Ke Shih 	u8 min_num;
394*e3ec7017SPing-Ke Shih };
395*e3ec7017SPing-Ke Shih 
396*e3ec7017SPing-Ke Shih struct rtw89_pci_tx_data {
397*e3ec7017SPing-Ke Shih 	dma_addr_t dma;
398*e3ec7017SPing-Ke Shih };
399*e3ec7017SPing-Ke Shih 
400*e3ec7017SPing-Ke Shih struct rtw89_pci_rx_info {
401*e3ec7017SPing-Ke Shih 	dma_addr_t dma;
402*e3ec7017SPing-Ke Shih 	u32 fs:1, ls:1, tag:11, len:14;
403*e3ec7017SPing-Ke Shih };
404*e3ec7017SPing-Ke Shih 
405*e3ec7017SPing-Ke Shih #define RTW89_PCI_TXBD_OPTION_LS	BIT(14)
406*e3ec7017SPing-Ke Shih 
407*e3ec7017SPing-Ke Shih struct rtw89_pci_tx_bd_32 {
408*e3ec7017SPing-Ke Shih 	__le16 length;
409*e3ec7017SPing-Ke Shih 	__le16 option;
410*e3ec7017SPing-Ke Shih 	__le32 dma;
411*e3ec7017SPing-Ke Shih } __packed;
412*e3ec7017SPing-Ke Shih 
413*e3ec7017SPing-Ke Shih #define RTW89_PCI_TXWP_VALID		BIT(15)
414*e3ec7017SPing-Ke Shih 
415*e3ec7017SPing-Ke Shih struct rtw89_pci_tx_wp_info {
416*e3ec7017SPing-Ke Shih 	__le16 seq0;
417*e3ec7017SPing-Ke Shih 	__le16 seq1;
418*e3ec7017SPing-Ke Shih 	__le16 seq2;
419*e3ec7017SPing-Ke Shih 	__le16 seq3;
420*e3ec7017SPing-Ke Shih } __packed;
421*e3ec7017SPing-Ke Shih 
422*e3ec7017SPing-Ke Shih #define RTW89_PCI_ADDR_MSDU_LS		BIT(15)
423*e3ec7017SPing-Ke Shih #define RTW89_PCI_ADDR_LS		BIT(14)
424*e3ec7017SPing-Ke Shih #define RTW89_PCI_ADDR_HIGH(a)		(((a) << 6) & GENMASK(13, 6))
425*e3ec7017SPing-Ke Shih #define RTW89_PCI_ADDR_NUM(x)		((x) & GENMASK(5, 0))
426*e3ec7017SPing-Ke Shih 
427*e3ec7017SPing-Ke Shih struct rtw89_pci_tx_addr_info_32 {
428*e3ec7017SPing-Ke Shih 	__le16 length;
429*e3ec7017SPing-Ke Shih 	__le16 option;
430*e3ec7017SPing-Ke Shih 	__le32 dma;
431*e3ec7017SPing-Ke Shih } __packed;
432*e3ec7017SPing-Ke Shih 
433*e3ec7017SPing-Ke Shih #define RTW89_PCI_RPP_POLLUTED		BIT(31)
434*e3ec7017SPing-Ke Shih #define RTW89_PCI_RPP_SEQ		GENMASK(30, 16)
435*e3ec7017SPing-Ke Shih #define RTW89_PCI_RPP_TX_STATUS		GENMASK(15, 13)
436*e3ec7017SPing-Ke Shih #define RTW89_TX_DONE			0x0
437*e3ec7017SPing-Ke Shih #define RTW89_TX_RETRY_LIMIT		0x1
438*e3ec7017SPing-Ke Shih #define RTW89_TX_LIFE_TIME		0x2
439*e3ec7017SPing-Ke Shih #define RTW89_TX_MACID_DROP		0x3
440*e3ec7017SPing-Ke Shih #define RTW89_PCI_RPP_QSEL		GENMASK(12, 8)
441*e3ec7017SPing-Ke Shih #define RTW89_PCI_RPP_MACID		GENMASK(7, 0)
442*e3ec7017SPing-Ke Shih 
443*e3ec7017SPing-Ke Shih struct rtw89_pci_rpp_fmt {
444*e3ec7017SPing-Ke Shih 	__le32 dword;
445*e3ec7017SPing-Ke Shih } __packed;
446*e3ec7017SPing-Ke Shih 
447*e3ec7017SPing-Ke Shih struct rtw89_pci_rx_bd_32 {
448*e3ec7017SPing-Ke Shih 	__le16 buf_size;
449*e3ec7017SPing-Ke Shih 	__le16 rsvd;
450*e3ec7017SPing-Ke Shih 	__le32 dma;
451*e3ec7017SPing-Ke Shih } __packed;
452*e3ec7017SPing-Ke Shih 
453*e3ec7017SPing-Ke Shih #define RTW89_PCI_RXBD_FS		BIT(15)
454*e3ec7017SPing-Ke Shih #define RTW89_PCI_RXBD_LS		BIT(14)
455*e3ec7017SPing-Ke Shih #define RTW89_PCI_RXBD_WRITE_SIZE	GENMASK(13, 0)
456*e3ec7017SPing-Ke Shih #define RTW89_PCI_RXBD_TAG		GENMASK(28, 16)
457*e3ec7017SPing-Ke Shih 
458*e3ec7017SPing-Ke Shih struct rtw89_pci_rxbd_info {
459*e3ec7017SPing-Ke Shih 	__le32 dword;
460*e3ec7017SPing-Ke Shih };
461*e3ec7017SPing-Ke Shih 
462*e3ec7017SPing-Ke Shih struct rtw89_pci_tx_wd {
463*e3ec7017SPing-Ke Shih 	struct list_head list;
464*e3ec7017SPing-Ke Shih 	struct sk_buff_head queue;
465*e3ec7017SPing-Ke Shih 
466*e3ec7017SPing-Ke Shih 	void *vaddr;
467*e3ec7017SPing-Ke Shih 	dma_addr_t paddr;
468*e3ec7017SPing-Ke Shih 	u32 len;
469*e3ec7017SPing-Ke Shih 	u32 seq;
470*e3ec7017SPing-Ke Shih };
471*e3ec7017SPing-Ke Shih 
472*e3ec7017SPing-Ke Shih struct rtw89_pci_dma_ring {
473*e3ec7017SPing-Ke Shih 	void *head;
474*e3ec7017SPing-Ke Shih 	u8 desc_size;
475*e3ec7017SPing-Ke Shih 	dma_addr_t dma;
476*e3ec7017SPing-Ke Shih 
477*e3ec7017SPing-Ke Shih 	u32 addr_num;
478*e3ec7017SPing-Ke Shih 	u32 addr_idx;
479*e3ec7017SPing-Ke Shih 	u32 addr_bdram;
480*e3ec7017SPing-Ke Shih 	u32 addr_desa_l;
481*e3ec7017SPing-Ke Shih 	u32 addr_desa_h;
482*e3ec7017SPing-Ke Shih 
483*e3ec7017SPing-Ke Shih 	u32 len;
484*e3ec7017SPing-Ke Shih 	u32 wp; /* host idx */
485*e3ec7017SPing-Ke Shih 	u32 rp; /* hw idx */
486*e3ec7017SPing-Ke Shih };
487*e3ec7017SPing-Ke Shih 
488*e3ec7017SPing-Ke Shih struct rtw89_pci_tx_wd_ring {
489*e3ec7017SPing-Ke Shih 	void *head;
490*e3ec7017SPing-Ke Shih 	dma_addr_t dma;
491*e3ec7017SPing-Ke Shih 
492*e3ec7017SPing-Ke Shih 	struct rtw89_pci_tx_wd pages[RTW89_PCI_TXWD_NUM_MAX];
493*e3ec7017SPing-Ke Shih 	struct list_head free_pages;
494*e3ec7017SPing-Ke Shih 
495*e3ec7017SPing-Ke Shih 	u32 page_size;
496*e3ec7017SPing-Ke Shih 	u32 page_num;
497*e3ec7017SPing-Ke Shih 	u32 curr_num;
498*e3ec7017SPing-Ke Shih };
499*e3ec7017SPing-Ke Shih 
500*e3ec7017SPing-Ke Shih #define RTW89_RX_TAG_MAX		0x1fff
501*e3ec7017SPing-Ke Shih 
502*e3ec7017SPing-Ke Shih struct rtw89_pci_tx_ring {
503*e3ec7017SPing-Ke Shih 	struct rtw89_pci_tx_wd_ring wd_ring;
504*e3ec7017SPing-Ke Shih 	struct rtw89_pci_dma_ring bd_ring;
505*e3ec7017SPing-Ke Shih 	struct list_head busy_pages;
506*e3ec7017SPing-Ke Shih 	u8 txch;
507*e3ec7017SPing-Ke Shih 	bool dma_enabled;
508*e3ec7017SPing-Ke Shih 	u16 tag; /* range from 0x0001 ~ 0x1fff */
509*e3ec7017SPing-Ke Shih 
510*e3ec7017SPing-Ke Shih 	u64 tx_cnt;
511*e3ec7017SPing-Ke Shih 	u64 tx_acked;
512*e3ec7017SPing-Ke Shih 	u64 tx_retry_lmt;
513*e3ec7017SPing-Ke Shih 	u64 tx_life_time;
514*e3ec7017SPing-Ke Shih 	u64 tx_mac_id_drop;
515*e3ec7017SPing-Ke Shih };
516*e3ec7017SPing-Ke Shih 
517*e3ec7017SPing-Ke Shih struct rtw89_pci_rx_ring {
518*e3ec7017SPing-Ke Shih 	struct rtw89_pci_dma_ring bd_ring;
519*e3ec7017SPing-Ke Shih 	struct sk_buff *buf[RTW89_PCI_RXBD_NUM_MAX];
520*e3ec7017SPing-Ke Shih 	u32 buf_sz;
521*e3ec7017SPing-Ke Shih 	struct sk_buff *diliver_skb;
522*e3ec7017SPing-Ke Shih 	struct rtw89_rx_desc_info diliver_desc;
523*e3ec7017SPing-Ke Shih };
524*e3ec7017SPing-Ke Shih 
525*e3ec7017SPing-Ke Shih struct rtw89_pci_isrs {
526*e3ec7017SPing-Ke Shih 	u32 halt_c2h_isrs;
527*e3ec7017SPing-Ke Shih 	u32 isrs[2];
528*e3ec7017SPing-Ke Shih };
529*e3ec7017SPing-Ke Shih 
530*e3ec7017SPing-Ke Shih struct rtw89_pci {
531*e3ec7017SPing-Ke Shih 	struct pci_dev *pdev;
532*e3ec7017SPing-Ke Shih 
533*e3ec7017SPing-Ke Shih 	/* protect HW irq related registers */
534*e3ec7017SPing-Ke Shih 	spinlock_t irq_lock;
535*e3ec7017SPing-Ke Shih 	/* protect TRX resources (exclude RXQ) */
536*e3ec7017SPing-Ke Shih 	spinlock_t trx_lock;
537*e3ec7017SPing-Ke Shih 	bool running;
538*e3ec7017SPing-Ke Shih 	struct rtw89_pci_tx_ring tx_rings[RTW89_TXCH_NUM];
539*e3ec7017SPing-Ke Shih 	struct rtw89_pci_rx_ring rx_rings[RTW89_RXCH_NUM];
540*e3ec7017SPing-Ke Shih 	struct sk_buff_head h2c_queue;
541*e3ec7017SPing-Ke Shih 	struct sk_buff_head h2c_release_queue;
542*e3ec7017SPing-Ke Shih 
543*e3ec7017SPing-Ke Shih 	u32 halt_c2h_intrs;
544*e3ec7017SPing-Ke Shih 	u32 intrs[2];
545*e3ec7017SPing-Ke Shih 	void __iomem *mmap;
546*e3ec7017SPing-Ke Shih };
547*e3ec7017SPing-Ke Shih 
548*e3ec7017SPing-Ke Shih static inline struct rtw89_pci_rx_info *RTW89_PCI_RX_SKB_CB(struct sk_buff *skb)
549*e3ec7017SPing-Ke Shih {
550*e3ec7017SPing-Ke Shih 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
551*e3ec7017SPing-Ke Shih 
552*e3ec7017SPing-Ke Shih 	BUILD_BUG_ON(sizeof(struct rtw89_pci_tx_data) >
553*e3ec7017SPing-Ke Shih 		     sizeof(info->status.status_driver_data));
554*e3ec7017SPing-Ke Shih 
555*e3ec7017SPing-Ke Shih 	return (struct rtw89_pci_rx_info *)skb->cb;
556*e3ec7017SPing-Ke Shih }
557*e3ec7017SPing-Ke Shih 
558*e3ec7017SPing-Ke Shih static inline struct rtw89_pci_rx_bd_32 *
559*e3ec7017SPing-Ke Shih RTW89_PCI_RX_BD(struct rtw89_pci_rx_ring *rx_ring, u32 idx)
560*e3ec7017SPing-Ke Shih {
561*e3ec7017SPing-Ke Shih 	struct rtw89_pci_dma_ring *bd_ring = &rx_ring->bd_ring;
562*e3ec7017SPing-Ke Shih 	u8 *head = bd_ring->head;
563*e3ec7017SPing-Ke Shih 	u32 desc_size = bd_ring->desc_size;
564*e3ec7017SPing-Ke Shih 	u32 offset = idx * desc_size;
565*e3ec7017SPing-Ke Shih 
566*e3ec7017SPing-Ke Shih 	return (struct rtw89_pci_rx_bd_32 *)(head + offset);
567*e3ec7017SPing-Ke Shih }
568*e3ec7017SPing-Ke Shih 
569*e3ec7017SPing-Ke Shih static inline void
570*e3ec7017SPing-Ke Shih rtw89_pci_rxbd_increase(struct rtw89_pci_rx_ring *rx_ring, u32 cnt)
571*e3ec7017SPing-Ke Shih {
572*e3ec7017SPing-Ke Shih 	struct rtw89_pci_dma_ring *bd_ring = &rx_ring->bd_ring;
573*e3ec7017SPing-Ke Shih 
574*e3ec7017SPing-Ke Shih 	bd_ring->wp += cnt;
575*e3ec7017SPing-Ke Shih 
576*e3ec7017SPing-Ke Shih 	if (bd_ring->wp >= bd_ring->len)
577*e3ec7017SPing-Ke Shih 		bd_ring->wp -= bd_ring->len;
578*e3ec7017SPing-Ke Shih }
579*e3ec7017SPing-Ke Shih 
580*e3ec7017SPing-Ke Shih static inline struct rtw89_pci_tx_data *RTW89_PCI_TX_SKB_CB(struct sk_buff *skb)
581*e3ec7017SPing-Ke Shih {
582*e3ec7017SPing-Ke Shih 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
583*e3ec7017SPing-Ke Shih 
584*e3ec7017SPing-Ke Shih 	return (struct rtw89_pci_tx_data *)info->status.status_driver_data;
585*e3ec7017SPing-Ke Shih }
586*e3ec7017SPing-Ke Shih 
587*e3ec7017SPing-Ke Shih static inline struct rtw89_pci_tx_bd_32 *
588*e3ec7017SPing-Ke Shih rtw89_pci_get_next_txbd(struct rtw89_pci_tx_ring *tx_ring)
589*e3ec7017SPing-Ke Shih {
590*e3ec7017SPing-Ke Shih 	struct rtw89_pci_dma_ring *bd_ring = &tx_ring->bd_ring;
591*e3ec7017SPing-Ke Shih 	struct rtw89_pci_tx_bd_32 *tx_bd, *head;
592*e3ec7017SPing-Ke Shih 
593*e3ec7017SPing-Ke Shih 	head = bd_ring->head;
594*e3ec7017SPing-Ke Shih 	tx_bd = head + bd_ring->wp;
595*e3ec7017SPing-Ke Shih 
596*e3ec7017SPing-Ke Shih 	return tx_bd;
597*e3ec7017SPing-Ke Shih }
598*e3ec7017SPing-Ke Shih 
599*e3ec7017SPing-Ke Shih static inline struct rtw89_pci_tx_wd *
600*e3ec7017SPing-Ke Shih rtw89_pci_dequeue_txwd(struct rtw89_pci_tx_ring *tx_ring)
601*e3ec7017SPing-Ke Shih {
602*e3ec7017SPing-Ke Shih 	struct rtw89_pci_tx_wd_ring *wd_ring = &tx_ring->wd_ring;
603*e3ec7017SPing-Ke Shih 	struct rtw89_pci_tx_wd *txwd;
604*e3ec7017SPing-Ke Shih 
605*e3ec7017SPing-Ke Shih 	txwd = list_first_entry_or_null(&wd_ring->free_pages,
606*e3ec7017SPing-Ke Shih 					struct rtw89_pci_tx_wd, list);
607*e3ec7017SPing-Ke Shih 	if (!txwd)
608*e3ec7017SPing-Ke Shih 		return NULL;
609*e3ec7017SPing-Ke Shih 
610*e3ec7017SPing-Ke Shih 	list_del_init(&txwd->list);
611*e3ec7017SPing-Ke Shih 	txwd->len = 0;
612*e3ec7017SPing-Ke Shih 	wd_ring->curr_num--;
613*e3ec7017SPing-Ke Shih 
614*e3ec7017SPing-Ke Shih 	return txwd;
615*e3ec7017SPing-Ke Shih }
616*e3ec7017SPing-Ke Shih 
617*e3ec7017SPing-Ke Shih static inline void
618*e3ec7017SPing-Ke Shih rtw89_pci_enqueue_txwd(struct rtw89_pci_tx_ring *tx_ring,
619*e3ec7017SPing-Ke Shih 		       struct rtw89_pci_tx_wd *txwd)
620*e3ec7017SPing-Ke Shih {
621*e3ec7017SPing-Ke Shih 	struct rtw89_pci_tx_wd_ring *wd_ring = &tx_ring->wd_ring;
622*e3ec7017SPing-Ke Shih 
623*e3ec7017SPing-Ke Shih 	memset(txwd->vaddr, 0, wd_ring->page_size);
624*e3ec7017SPing-Ke Shih 	list_add_tail(&txwd->list, &wd_ring->free_pages);
625*e3ec7017SPing-Ke Shih 	wd_ring->curr_num++;
626*e3ec7017SPing-Ke Shih }
627*e3ec7017SPing-Ke Shih 
628*e3ec7017SPing-Ke Shih static inline bool rtw89_pci_ltr_is_err_reg_val(u32 val)
629*e3ec7017SPing-Ke Shih {
630*e3ec7017SPing-Ke Shih 	return val == 0xffffffff || val == 0xeaeaeaea;
631*e3ec7017SPing-Ke Shih }
632*e3ec7017SPing-Ke Shih 
633*e3ec7017SPing-Ke Shih extern const struct dev_pm_ops rtw89_pm_ops;
634*e3ec7017SPing-Ke Shih 
635*e3ec7017SPing-Ke Shih #endif
636