1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2019-2020  Realtek Corporation
3  */
4 
5 #ifndef __RTW89_CORE_H__
6 #define __RTW89_CORE_H__
7 
8 #include <linux/average.h>
9 #include <linux/bitfield.h>
10 #include <linux/firmware.h>
11 #include <linux/iopoll.h>
12 #include <linux/workqueue.h>
13 #include <net/mac80211.h>
14 
15 struct rtw89_dev;
16 struct rtw89_pci_info;
17 
18 extern const struct ieee80211_ops rtw89_ops;
19 
20 #define MASKBYTE0 0xff
21 #define MASKBYTE1 0xff00
22 #define MASKBYTE2 0xff0000
23 #define MASKBYTE3 0xff000000
24 #define MASKBYTE4 0xff00000000ULL
25 #define MASKHWORD 0xffff0000
26 #define MASKLWORD 0x0000ffff
27 #define MASKDWORD 0xffffffff
28 #define RFREG_MASK 0xfffff
29 #define INV_RF_DATA 0xffffffff
30 
31 #define RTW89_TRACK_WORK_PERIOD	round_jiffies_relative(HZ * 2)
32 #define RTW89_FORBID_BA_TIMER round_jiffies_relative(HZ * 4)
33 #define CFO_TRACK_MAX_USER 64
34 #define MAX_RSSI 110
35 #define RSSI_FACTOR 1
36 #define RTW89_RSSI_RAW_TO_DBM(rssi) ((s8)((rssi) >> RSSI_FACTOR) - MAX_RSSI)
37 #define RTW89_TX_DIV_RSSI_RAW_TH (2 << RSSI_FACTOR)
38 #define RTW89_RADIOTAP_ROOM ALIGN(sizeof(struct ieee80211_radiotap_he), 64)
39 
40 #define RTW89_HTC_MASK_VARIANT GENMASK(1, 0)
41 #define RTW89_HTC_VARIANT_HE 3
42 #define RTW89_HTC_MASK_CTL_ID GENMASK(5, 2)
43 #define RTW89_HTC_VARIANT_HE_CID_OM 1
44 #define RTW89_HTC_VARIANT_HE_CID_CAS 6
45 #define RTW89_HTC_MASK_CTL_INFO GENMASK(31, 6)
46 
47 #define RTW89_HTC_MASK_HTC_OM_RX_NSS GENMASK(8, 6)
48 enum htc_om_channel_width {
49 	HTC_OM_CHANNEL_WIDTH_20 = 0,
50 	HTC_OM_CHANNEL_WIDTH_40 = 1,
51 	HTC_OM_CHANNEL_WIDTH_80 = 2,
52 	HTC_OM_CHANNEL_WIDTH_160_OR_80_80 = 3,
53 };
54 #define RTW89_HTC_MASK_HTC_OM_CH_WIDTH GENMASK(10, 9)
55 #define RTW89_HTC_MASK_HTC_OM_UL_MU_DIS BIT(11)
56 #define RTW89_HTC_MASK_HTC_OM_TX_NSTS GENMASK(14, 12)
57 #define RTW89_HTC_MASK_HTC_OM_ER_SU_DIS BIT(15)
58 #define RTW89_HTC_MASK_HTC_OM_DL_MU_MIMO_RR BIT(16)
59 #define RTW89_HTC_MASK_HTC_OM_UL_MU_DATA_DIS BIT(17)
60 
61 #define RTW89_TF_PAD GENMASK(11, 0)
62 #define RTW89_TF_BASIC_USER_INFO_SZ 6
63 
64 #define RTW89_GET_TF_USER_INFO_AID12(data)	\
65 	le32_get_bits(*((const __le32 *)(data)), GENMASK(11, 0))
66 #define RTW89_GET_TF_USER_INFO_RUA(data)	\
67 	le32_get_bits(*((const __le32 *)(data)), GENMASK(19, 12))
68 #define RTW89_GET_TF_USER_INFO_UL_MCS(data)	\
69 	le32_get_bits(*((const __le32 *)(data)), GENMASK(24, 21))
70 
71 enum rtw89_subband {
72 	RTW89_CH_2G = 0,
73 	RTW89_CH_5G_BAND_1 = 1,
74 	/* RTW89_CH_5G_BAND_2 = 2, unused */
75 	RTW89_CH_5G_BAND_3 = 3,
76 	RTW89_CH_5G_BAND_4 = 4,
77 
78 	RTW89_CH_6G_BAND_IDX0, /* Low */
79 	RTW89_CH_6G_BAND_IDX1, /* Low */
80 	RTW89_CH_6G_BAND_IDX2, /* Mid */
81 	RTW89_CH_6G_BAND_IDX3, /* Mid */
82 	RTW89_CH_6G_BAND_IDX4, /* High */
83 	RTW89_CH_6G_BAND_IDX5, /* High */
84 	RTW89_CH_6G_BAND_IDX6, /* Ultra-high */
85 	RTW89_CH_6G_BAND_IDX7, /* Ultra-high */
86 
87 	RTW89_SUBBAND_NR,
88 	RTW89_SUBBAND_2GHZ_5GHZ_NR = RTW89_CH_5G_BAND_4 + 1,
89 };
90 
91 enum rtw89_gain_offset {
92 	RTW89_GAIN_OFFSET_2G_CCK,
93 	RTW89_GAIN_OFFSET_2G_OFDM,
94 	RTW89_GAIN_OFFSET_5G_LOW,
95 	RTW89_GAIN_OFFSET_5G_MID,
96 	RTW89_GAIN_OFFSET_5G_HIGH,
97 
98 	RTW89_GAIN_OFFSET_NR,
99 };
100 
101 enum rtw89_hci_type {
102 	RTW89_HCI_TYPE_PCIE,
103 	RTW89_HCI_TYPE_USB,
104 	RTW89_HCI_TYPE_SDIO,
105 };
106 
107 enum rtw89_core_chip_id {
108 	RTL8852A,
109 	RTL8852B,
110 	RTL8852C,
111 	RTL8851B,
112 };
113 
114 enum rtw89_cv {
115 	CHIP_CAV,
116 	CHIP_CBV,
117 	CHIP_CCV,
118 	CHIP_CDV,
119 	CHIP_CEV,
120 	CHIP_CFV,
121 	CHIP_CV_MAX,
122 	CHIP_CV_INVALID = CHIP_CV_MAX,
123 };
124 
125 enum rtw89_bacam_ver {
126 	RTW89_BACAM_V0,
127 	RTW89_BACAM_V1,
128 
129 	RTW89_BACAM_V0_EXT = 99,
130 };
131 
132 enum rtw89_core_tx_type {
133 	RTW89_CORE_TX_TYPE_DATA,
134 	RTW89_CORE_TX_TYPE_MGMT,
135 	RTW89_CORE_TX_TYPE_FWCMD,
136 };
137 
138 enum rtw89_core_rx_type {
139 	RTW89_CORE_RX_TYPE_WIFI		= 0,
140 	RTW89_CORE_RX_TYPE_PPDU_STAT	= 1,
141 	RTW89_CORE_RX_TYPE_CHAN_INFO	= 2,
142 	RTW89_CORE_RX_TYPE_BB_SCOPE	= 3,
143 	RTW89_CORE_RX_TYPE_F2P_TXCMD	= 4,
144 	RTW89_CORE_RX_TYPE_SS2FW	= 5,
145 	RTW89_CORE_RX_TYPE_TX_REPORT	= 6,
146 	RTW89_CORE_RX_TYPE_TX_REL_HOST	= 7,
147 	RTW89_CORE_RX_TYPE_DFS_REPORT	= 8,
148 	RTW89_CORE_RX_TYPE_TX_REL_CPU	= 9,
149 	RTW89_CORE_RX_TYPE_C2H		= 10,
150 	RTW89_CORE_RX_TYPE_CSI		= 11,
151 	RTW89_CORE_RX_TYPE_CQI		= 12,
152 	RTW89_CORE_RX_TYPE_H2C		= 13,
153 	RTW89_CORE_RX_TYPE_FWDL		= 14,
154 };
155 
156 enum rtw89_txq_flags {
157 	RTW89_TXQ_F_AMPDU		= 0,
158 	RTW89_TXQ_F_BLOCK_BA		= 1,
159 	RTW89_TXQ_F_FORBID_BA		= 2,
160 };
161 
162 enum rtw89_net_type {
163 	RTW89_NET_TYPE_NO_LINK		= 0,
164 	RTW89_NET_TYPE_AD_HOC		= 1,
165 	RTW89_NET_TYPE_INFRA		= 2,
166 	RTW89_NET_TYPE_AP_MODE		= 3,
167 };
168 
169 enum rtw89_wifi_role {
170 	RTW89_WIFI_ROLE_NONE,
171 	RTW89_WIFI_ROLE_STATION,
172 	RTW89_WIFI_ROLE_AP,
173 	RTW89_WIFI_ROLE_AP_VLAN,
174 	RTW89_WIFI_ROLE_ADHOC,
175 	RTW89_WIFI_ROLE_ADHOC_MASTER,
176 	RTW89_WIFI_ROLE_MESH_POINT,
177 	RTW89_WIFI_ROLE_MONITOR,
178 	RTW89_WIFI_ROLE_P2P_DEVICE,
179 	RTW89_WIFI_ROLE_P2P_CLIENT,
180 	RTW89_WIFI_ROLE_P2P_GO,
181 	RTW89_WIFI_ROLE_NAN,
182 	RTW89_WIFI_ROLE_MLME_MAX
183 };
184 
185 enum rtw89_upd_mode {
186 	RTW89_ROLE_CREATE,
187 	RTW89_ROLE_REMOVE,
188 	RTW89_ROLE_TYPE_CHANGE,
189 	RTW89_ROLE_INFO_CHANGE,
190 	RTW89_ROLE_CON_DISCONN,
191 	RTW89_ROLE_BAND_SW,
192 	RTW89_ROLE_FW_RESTORE,
193 };
194 
195 enum rtw89_self_role {
196 	RTW89_SELF_ROLE_CLIENT,
197 	RTW89_SELF_ROLE_AP,
198 	RTW89_SELF_ROLE_AP_CLIENT
199 };
200 
201 enum rtw89_msk_sO_el {
202 	RTW89_NO_MSK,
203 	RTW89_SMA,
204 	RTW89_TMA,
205 	RTW89_BSSID
206 };
207 
208 enum rtw89_sch_tx_sel {
209 	RTW89_SCH_TX_SEL_ALL,
210 	RTW89_SCH_TX_SEL_HIQ,
211 	RTW89_SCH_TX_SEL_MG0,
212 	RTW89_SCH_TX_SEL_MACID,
213 };
214 
215 /* RTW89_ADDR_CAM_SEC_NONE	: not enabled
216  * RTW89_ADDR_CAM_SEC_ALL_UNI	: 0 - 6 unicast
217  * RTW89_ADDR_CAM_SEC_NORMAL	: 0 - 1 unicast, 2 - 4 group, 5 - 6 BIP
218  * RTW89_ADDR_CAM_SEC_4GROUP	: 0 - 1 unicast, 2 - 5 group, 6 BIP
219  */
220 enum rtw89_add_cam_sec_mode {
221 	RTW89_ADDR_CAM_SEC_NONE		= 0,
222 	RTW89_ADDR_CAM_SEC_ALL_UNI	= 1,
223 	RTW89_ADDR_CAM_SEC_NORMAL	= 2,
224 	RTW89_ADDR_CAM_SEC_4GROUP	= 3,
225 };
226 
227 enum rtw89_sec_key_type {
228 	RTW89_SEC_KEY_TYPE_NONE		= 0,
229 	RTW89_SEC_KEY_TYPE_WEP40	= 1,
230 	RTW89_SEC_KEY_TYPE_WEP104	= 2,
231 	RTW89_SEC_KEY_TYPE_TKIP		= 3,
232 	RTW89_SEC_KEY_TYPE_WAPI		= 4,
233 	RTW89_SEC_KEY_TYPE_GCMSMS4	= 5,
234 	RTW89_SEC_KEY_TYPE_CCMP128	= 6,
235 	RTW89_SEC_KEY_TYPE_CCMP256	= 7,
236 	RTW89_SEC_KEY_TYPE_GCMP128	= 8,
237 	RTW89_SEC_KEY_TYPE_GCMP256	= 9,
238 	RTW89_SEC_KEY_TYPE_BIP_CCMP128	= 10,
239 };
240 
241 enum rtw89_port {
242 	RTW89_PORT_0 = 0,
243 	RTW89_PORT_1 = 1,
244 	RTW89_PORT_2 = 2,
245 	RTW89_PORT_3 = 3,
246 	RTW89_PORT_4 = 4,
247 	RTW89_PORT_NUM
248 };
249 
250 enum rtw89_band {
251 	RTW89_BAND_2G = 0,
252 	RTW89_BAND_5G = 1,
253 	RTW89_BAND_6G = 2,
254 	RTW89_BAND_NUM,
255 };
256 
257 enum rtw89_hw_rate {
258 	RTW89_HW_RATE_CCK1	= 0x0,
259 	RTW89_HW_RATE_CCK2	= 0x1,
260 	RTW89_HW_RATE_CCK5_5	= 0x2,
261 	RTW89_HW_RATE_CCK11	= 0x3,
262 	RTW89_HW_RATE_OFDM6	= 0x4,
263 	RTW89_HW_RATE_OFDM9	= 0x5,
264 	RTW89_HW_RATE_OFDM12	= 0x6,
265 	RTW89_HW_RATE_OFDM18	= 0x7,
266 	RTW89_HW_RATE_OFDM24	= 0x8,
267 	RTW89_HW_RATE_OFDM36	= 0x9,
268 	RTW89_HW_RATE_OFDM48	= 0xA,
269 	RTW89_HW_RATE_OFDM54	= 0xB,
270 	RTW89_HW_RATE_MCS0	= 0x80,
271 	RTW89_HW_RATE_MCS1	= 0x81,
272 	RTW89_HW_RATE_MCS2	= 0x82,
273 	RTW89_HW_RATE_MCS3	= 0x83,
274 	RTW89_HW_RATE_MCS4	= 0x84,
275 	RTW89_HW_RATE_MCS5	= 0x85,
276 	RTW89_HW_RATE_MCS6	= 0x86,
277 	RTW89_HW_RATE_MCS7	= 0x87,
278 	RTW89_HW_RATE_MCS8	= 0x88,
279 	RTW89_HW_RATE_MCS9	= 0x89,
280 	RTW89_HW_RATE_MCS10	= 0x8A,
281 	RTW89_HW_RATE_MCS11	= 0x8B,
282 	RTW89_HW_RATE_MCS12	= 0x8C,
283 	RTW89_HW_RATE_MCS13	= 0x8D,
284 	RTW89_HW_RATE_MCS14	= 0x8E,
285 	RTW89_HW_RATE_MCS15	= 0x8F,
286 	RTW89_HW_RATE_MCS16	= 0x90,
287 	RTW89_HW_RATE_MCS17	= 0x91,
288 	RTW89_HW_RATE_MCS18	= 0x92,
289 	RTW89_HW_RATE_MCS19	= 0x93,
290 	RTW89_HW_RATE_MCS20	= 0x94,
291 	RTW89_HW_RATE_MCS21	= 0x95,
292 	RTW89_HW_RATE_MCS22	= 0x96,
293 	RTW89_HW_RATE_MCS23	= 0x97,
294 	RTW89_HW_RATE_MCS24	= 0x98,
295 	RTW89_HW_RATE_MCS25	= 0x99,
296 	RTW89_HW_RATE_MCS26	= 0x9A,
297 	RTW89_HW_RATE_MCS27	= 0x9B,
298 	RTW89_HW_RATE_MCS28	= 0x9C,
299 	RTW89_HW_RATE_MCS29	= 0x9D,
300 	RTW89_HW_RATE_MCS30	= 0x9E,
301 	RTW89_HW_RATE_MCS31	= 0x9F,
302 	RTW89_HW_RATE_VHT_NSS1_MCS0	= 0x100,
303 	RTW89_HW_RATE_VHT_NSS1_MCS1	= 0x101,
304 	RTW89_HW_RATE_VHT_NSS1_MCS2	= 0x102,
305 	RTW89_HW_RATE_VHT_NSS1_MCS3	= 0x103,
306 	RTW89_HW_RATE_VHT_NSS1_MCS4	= 0x104,
307 	RTW89_HW_RATE_VHT_NSS1_MCS5	= 0x105,
308 	RTW89_HW_RATE_VHT_NSS1_MCS6	= 0x106,
309 	RTW89_HW_RATE_VHT_NSS1_MCS7	= 0x107,
310 	RTW89_HW_RATE_VHT_NSS1_MCS8	= 0x108,
311 	RTW89_HW_RATE_VHT_NSS1_MCS9	= 0x109,
312 	RTW89_HW_RATE_VHT_NSS2_MCS0	= 0x110,
313 	RTW89_HW_RATE_VHT_NSS2_MCS1	= 0x111,
314 	RTW89_HW_RATE_VHT_NSS2_MCS2	= 0x112,
315 	RTW89_HW_RATE_VHT_NSS2_MCS3	= 0x113,
316 	RTW89_HW_RATE_VHT_NSS2_MCS4	= 0x114,
317 	RTW89_HW_RATE_VHT_NSS2_MCS5	= 0x115,
318 	RTW89_HW_RATE_VHT_NSS2_MCS6	= 0x116,
319 	RTW89_HW_RATE_VHT_NSS2_MCS7	= 0x117,
320 	RTW89_HW_RATE_VHT_NSS2_MCS8	= 0x118,
321 	RTW89_HW_RATE_VHT_NSS2_MCS9	= 0x119,
322 	RTW89_HW_RATE_VHT_NSS3_MCS0	= 0x120,
323 	RTW89_HW_RATE_VHT_NSS3_MCS1	= 0x121,
324 	RTW89_HW_RATE_VHT_NSS3_MCS2	= 0x122,
325 	RTW89_HW_RATE_VHT_NSS3_MCS3	= 0x123,
326 	RTW89_HW_RATE_VHT_NSS3_MCS4	= 0x124,
327 	RTW89_HW_RATE_VHT_NSS3_MCS5	= 0x125,
328 	RTW89_HW_RATE_VHT_NSS3_MCS6	= 0x126,
329 	RTW89_HW_RATE_VHT_NSS3_MCS7	= 0x127,
330 	RTW89_HW_RATE_VHT_NSS3_MCS8	= 0x128,
331 	RTW89_HW_RATE_VHT_NSS3_MCS9	= 0x129,
332 	RTW89_HW_RATE_VHT_NSS4_MCS0	= 0x130,
333 	RTW89_HW_RATE_VHT_NSS4_MCS1	= 0x131,
334 	RTW89_HW_RATE_VHT_NSS4_MCS2	= 0x132,
335 	RTW89_HW_RATE_VHT_NSS4_MCS3	= 0x133,
336 	RTW89_HW_RATE_VHT_NSS4_MCS4	= 0x134,
337 	RTW89_HW_RATE_VHT_NSS4_MCS5	= 0x135,
338 	RTW89_HW_RATE_VHT_NSS4_MCS6	= 0x136,
339 	RTW89_HW_RATE_VHT_NSS4_MCS7	= 0x137,
340 	RTW89_HW_RATE_VHT_NSS4_MCS8	= 0x138,
341 	RTW89_HW_RATE_VHT_NSS4_MCS9	= 0x139,
342 	RTW89_HW_RATE_HE_NSS1_MCS0	= 0x180,
343 	RTW89_HW_RATE_HE_NSS1_MCS1	= 0x181,
344 	RTW89_HW_RATE_HE_NSS1_MCS2	= 0x182,
345 	RTW89_HW_RATE_HE_NSS1_MCS3	= 0x183,
346 	RTW89_HW_RATE_HE_NSS1_MCS4	= 0x184,
347 	RTW89_HW_RATE_HE_NSS1_MCS5	= 0x185,
348 	RTW89_HW_RATE_HE_NSS1_MCS6	= 0x186,
349 	RTW89_HW_RATE_HE_NSS1_MCS7	= 0x187,
350 	RTW89_HW_RATE_HE_NSS1_MCS8	= 0x188,
351 	RTW89_HW_RATE_HE_NSS1_MCS9	= 0x189,
352 	RTW89_HW_RATE_HE_NSS1_MCS10	= 0x18A,
353 	RTW89_HW_RATE_HE_NSS1_MCS11	= 0x18B,
354 	RTW89_HW_RATE_HE_NSS2_MCS0	= 0x190,
355 	RTW89_HW_RATE_HE_NSS2_MCS1	= 0x191,
356 	RTW89_HW_RATE_HE_NSS2_MCS2	= 0x192,
357 	RTW89_HW_RATE_HE_NSS2_MCS3	= 0x193,
358 	RTW89_HW_RATE_HE_NSS2_MCS4	= 0x194,
359 	RTW89_HW_RATE_HE_NSS2_MCS5	= 0x195,
360 	RTW89_HW_RATE_HE_NSS2_MCS6	= 0x196,
361 	RTW89_HW_RATE_HE_NSS2_MCS7	= 0x197,
362 	RTW89_HW_RATE_HE_NSS2_MCS8	= 0x198,
363 	RTW89_HW_RATE_HE_NSS2_MCS9	= 0x199,
364 	RTW89_HW_RATE_HE_NSS2_MCS10	= 0x19A,
365 	RTW89_HW_RATE_HE_NSS2_MCS11	= 0x19B,
366 	RTW89_HW_RATE_HE_NSS3_MCS0	= 0x1A0,
367 	RTW89_HW_RATE_HE_NSS3_MCS1	= 0x1A1,
368 	RTW89_HW_RATE_HE_NSS3_MCS2	= 0x1A2,
369 	RTW89_HW_RATE_HE_NSS3_MCS3	= 0x1A3,
370 	RTW89_HW_RATE_HE_NSS3_MCS4	= 0x1A4,
371 	RTW89_HW_RATE_HE_NSS3_MCS5	= 0x1A5,
372 	RTW89_HW_RATE_HE_NSS3_MCS6	= 0x1A6,
373 	RTW89_HW_RATE_HE_NSS3_MCS7	= 0x1A7,
374 	RTW89_HW_RATE_HE_NSS3_MCS8	= 0x1A8,
375 	RTW89_HW_RATE_HE_NSS3_MCS9	= 0x1A9,
376 	RTW89_HW_RATE_HE_NSS3_MCS10	= 0x1AA,
377 	RTW89_HW_RATE_HE_NSS3_MCS11	= 0x1AB,
378 	RTW89_HW_RATE_HE_NSS4_MCS0	= 0x1B0,
379 	RTW89_HW_RATE_HE_NSS4_MCS1	= 0x1B1,
380 	RTW89_HW_RATE_HE_NSS4_MCS2	= 0x1B2,
381 	RTW89_HW_RATE_HE_NSS4_MCS3	= 0x1B3,
382 	RTW89_HW_RATE_HE_NSS4_MCS4	= 0x1B4,
383 	RTW89_HW_RATE_HE_NSS4_MCS5	= 0x1B5,
384 	RTW89_HW_RATE_HE_NSS4_MCS6	= 0x1B6,
385 	RTW89_HW_RATE_HE_NSS4_MCS7	= 0x1B7,
386 	RTW89_HW_RATE_HE_NSS4_MCS8	= 0x1B8,
387 	RTW89_HW_RATE_HE_NSS4_MCS9	= 0x1B9,
388 	RTW89_HW_RATE_HE_NSS4_MCS10	= 0x1BA,
389 	RTW89_HW_RATE_HE_NSS4_MCS11	= 0x1BB,
390 	RTW89_HW_RATE_NR,
391 
392 	RTW89_HW_RATE_MASK_MOD = GENMASK(8, 7),
393 	RTW89_HW_RATE_MASK_VAL = GENMASK(6, 0),
394 };
395 
396 /* 2G channels,
397  * 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
398  */
399 #define RTW89_2G_CH_NUM 14
400 
401 /* 5G channels,
402  * 36, 38, 40, 42, 44, 46, 48, 50,
403  * 52, 54, 56, 58, 60, 62, 64,
404  * 100, 102, 104, 106, 108, 110, 112, 114,
405  * 116, 118, 120, 122, 124, 126, 128, 130,
406  * 132, 134, 136, 138, 140, 142, 144,
407  * 149, 151, 153, 155, 157, 159, 161, 163,
408  * 165, 167, 169, 171, 173, 175, 177
409  */
410 #define RTW89_5G_CH_NUM 53
411 
412 /* 6G channels,
413  * 1, 3, 5, 7, 9, 11, 13, 15,
414  * 17, 19, 21, 23, 25, 27, 29, 33,
415  * 35, 37, 39, 41, 43, 45, 47, 49,
416  * 51, 53, 55, 57, 59, 61, 65, 67,
417  * 69, 71, 73, 75, 77, 79, 81, 83,
418  * 85, 87, 89, 91, 93, 97, 99, 101,
419  * 103, 105, 107, 109, 111, 113, 115, 117,
420  * 119, 121, 123, 125, 129, 131, 133, 135,
421  * 137, 139, 141, 143, 145, 147, 149, 151,
422  * 153, 155, 157, 161, 163, 165, 167, 169,
423  * 171, 173, 175, 177, 179, 181, 183, 185,
424  * 187, 189, 193, 195, 197, 199, 201, 203,
425  * 205, 207, 209, 211, 213, 215, 217, 219,
426  * 221, 225, 227, 229, 231, 233, 235, 237,
427  * 239, 241, 243, 245, 247, 249, 251, 253,
428  */
429 #define RTW89_6G_CH_NUM 120
430 
431 enum rtw89_rate_section {
432 	RTW89_RS_CCK,
433 	RTW89_RS_OFDM,
434 	RTW89_RS_MCS, /* for HT/VHT/HE */
435 	RTW89_RS_HEDCM,
436 	RTW89_RS_OFFSET,
437 	RTW89_RS_NUM,
438 	RTW89_RS_LMT_NUM = RTW89_RS_MCS + 1,
439 	RTW89_RS_TX_SHAPE_NUM = RTW89_RS_OFDM + 1,
440 };
441 
442 enum rtw89_rate_num {
443 	RTW89_RATE_CCK_NUM	= 4,
444 	RTW89_RATE_OFDM_NUM	= 8,
445 	RTW89_RATE_MCS_NUM	= 12,
446 	RTW89_RATE_HEDCM_NUM	= 4, /* for HEDCM MCS0/1/3/4 */
447 	RTW89_RATE_OFFSET_NUM	= 5, /* for HE(HEDCM)/VHT/HT/OFDM/CCK offset */
448 };
449 
450 enum rtw89_nss {
451 	RTW89_NSS_1		= 0,
452 	RTW89_NSS_2		= 1,
453 	/* HE DCM only support 1ss and 2ss */
454 	RTW89_NSS_HEDCM_NUM	= RTW89_NSS_2 + 1,
455 	RTW89_NSS_3		= 2,
456 	RTW89_NSS_4		= 3,
457 	RTW89_NSS_NUM,
458 };
459 
460 enum rtw89_ntx {
461 	RTW89_1TX	= 0,
462 	RTW89_2TX	= 1,
463 	RTW89_NTX_NUM,
464 };
465 
466 enum rtw89_beamforming_type {
467 	RTW89_NONBF	= 0,
468 	RTW89_BF	= 1,
469 	RTW89_BF_NUM,
470 };
471 
472 enum rtw89_regulation_type {
473 	RTW89_WW	= 0,
474 	RTW89_ETSI	= 1,
475 	RTW89_FCC	= 2,
476 	RTW89_MKK	= 3,
477 	RTW89_NA	= 4,
478 	RTW89_IC	= 5,
479 	RTW89_KCC	= 6,
480 	RTW89_ACMA	= 7,
481 	RTW89_NCC	= 8,
482 	RTW89_MEXICO	= 9,
483 	RTW89_CHILE	= 10,
484 	RTW89_UKRAINE	= 11,
485 	RTW89_CN	= 12,
486 	RTW89_QATAR	= 13,
487 	RTW89_UK	= 14,
488 	RTW89_REGD_NUM,
489 };
490 
491 enum rtw89_reg_6ghz_power {
492 	RTW89_REG_6GHZ_POWER_VLP = 0,
493 	RTW89_REG_6GHZ_POWER_LPI = 1,
494 	RTW89_REG_6GHZ_POWER_STD = 2,
495 
496 	NUM_OF_RTW89_REG_6GHZ_POWER,
497 	RTW89_REG_6GHZ_POWER_DFLT = RTW89_REG_6GHZ_POWER_VLP,
498 };
499 
500 enum rtw89_fw_pkt_ofld_type {
501 	RTW89_PKT_OFLD_TYPE_PROBE_RSP = 0,
502 	RTW89_PKT_OFLD_TYPE_PS_POLL = 1,
503 	RTW89_PKT_OFLD_TYPE_NULL_DATA = 2,
504 	RTW89_PKT_OFLD_TYPE_QOS_NULL = 3,
505 	RTW89_PKT_OFLD_TYPE_CTS2SELF = 4,
506 	RTW89_PKT_OFLD_TYPE_ARP_RSP = 5,
507 	RTW89_PKT_OFLD_TYPE_NDP = 6,
508 	RTW89_PKT_OFLD_TYPE_EAPOL_KEY = 7,
509 	RTW89_PKT_OFLD_TYPE_SA_QUERY = 8,
510 	RTW89_PKT_OFLD_TYPE_PROBE_REQ = 12,
511 	RTW89_PKT_OFLD_TYPE_NUM,
512 };
513 
514 struct rtw89_txpwr_byrate {
515 	s8 cck[RTW89_RATE_CCK_NUM];
516 	s8 ofdm[RTW89_RATE_OFDM_NUM];
517 	s8 mcs[RTW89_NSS_NUM][RTW89_RATE_MCS_NUM];
518 	s8 hedcm[RTW89_NSS_HEDCM_NUM][RTW89_RATE_HEDCM_NUM];
519 	s8 offset[RTW89_RATE_OFFSET_NUM];
520 };
521 
522 enum rtw89_bandwidth_section_num {
523 	RTW89_BW20_SEC_NUM = 8,
524 	RTW89_BW40_SEC_NUM = 4,
525 	RTW89_BW80_SEC_NUM = 2,
526 };
527 
528 #define RTW89_TXPWR_LMT_PAGE_SIZE 40
529 
530 struct rtw89_txpwr_limit {
531 	s8 cck_20m[RTW89_BF_NUM];
532 	s8 cck_40m[RTW89_BF_NUM];
533 	s8 ofdm[RTW89_BF_NUM];
534 	s8 mcs_20m[RTW89_BW20_SEC_NUM][RTW89_BF_NUM];
535 	s8 mcs_40m[RTW89_BW40_SEC_NUM][RTW89_BF_NUM];
536 	s8 mcs_80m[RTW89_BW80_SEC_NUM][RTW89_BF_NUM];
537 	s8 mcs_160m[RTW89_BF_NUM];
538 	s8 mcs_40m_0p5[RTW89_BF_NUM];
539 	s8 mcs_40m_2p5[RTW89_BF_NUM];
540 };
541 
542 #define RTW89_RU_SEC_NUM 8
543 
544 #define RTW89_TXPWR_LMT_RU_PAGE_SIZE 24
545 
546 struct rtw89_txpwr_limit_ru {
547 	s8 ru26[RTW89_RU_SEC_NUM];
548 	s8 ru52[RTW89_RU_SEC_NUM];
549 	s8 ru106[RTW89_RU_SEC_NUM];
550 };
551 
552 struct rtw89_rate_desc {
553 	enum rtw89_nss nss;
554 	enum rtw89_rate_section rs;
555 	u8 idx;
556 };
557 
558 #define PHY_STS_HDR_LEN 8
559 #define RF_PATH_MAX 4
560 #define RTW89_MAX_PPDU_CNT 8
561 struct rtw89_rx_phy_ppdu {
562 	void *buf;
563 	u32 len;
564 	u8 rssi_avg;
565 	u8 rssi[RF_PATH_MAX];
566 	u8 mac_id;
567 	u8 chan_idx;
568 	u8 ie;
569 	u16 rate;
570 	struct {
571 		bool has;
572 		u8 avg_snr;
573 		u8 evm_max;
574 		u8 evm_min;
575 	} ofdm;
576 	bool to_self;
577 	bool valid;
578 };
579 
580 enum rtw89_mac_idx {
581 	RTW89_MAC_0 = 0,
582 	RTW89_MAC_1 = 1,
583 };
584 
585 enum rtw89_phy_idx {
586 	RTW89_PHY_0 = 0,
587 	RTW89_PHY_1 = 1,
588 	RTW89_PHY_MAX
589 };
590 
591 enum rtw89_sub_entity_idx {
592 	RTW89_SUB_ENTITY_0 = 0,
593 
594 	NUM_OF_RTW89_SUB_ENTITY,
595 	RTW89_SUB_ENTITY_IDLE = NUM_OF_RTW89_SUB_ENTITY,
596 };
597 
598 enum rtw89_rf_path {
599 	RF_PATH_A = 0,
600 	RF_PATH_B = 1,
601 	RF_PATH_C = 2,
602 	RF_PATH_D = 3,
603 	RF_PATH_AB,
604 	RF_PATH_AC,
605 	RF_PATH_AD,
606 	RF_PATH_BC,
607 	RF_PATH_BD,
608 	RF_PATH_CD,
609 	RF_PATH_ABC,
610 	RF_PATH_ABD,
611 	RF_PATH_ACD,
612 	RF_PATH_BCD,
613 	RF_PATH_ABCD,
614 };
615 
616 enum rtw89_rf_path_bit {
617 	RF_A	= BIT(0),
618 	RF_B	= BIT(1),
619 	RF_C	= BIT(2),
620 	RF_D	= BIT(3),
621 
622 	RF_AB	= (RF_A | RF_B),
623 	RF_AC	= (RF_A | RF_C),
624 	RF_AD	= (RF_A | RF_D),
625 	RF_BC	= (RF_B | RF_C),
626 	RF_BD	= (RF_B | RF_D),
627 	RF_CD	= (RF_C | RF_D),
628 
629 	RF_ABC	= (RF_A | RF_B | RF_C),
630 	RF_ABD	= (RF_A | RF_B | RF_D),
631 	RF_ACD	= (RF_A | RF_C | RF_D),
632 	RF_BCD	= (RF_B | RF_C | RF_D),
633 
634 	RF_ABCD	= (RF_A | RF_B | RF_C | RF_D),
635 };
636 
637 enum rtw89_bandwidth {
638 	RTW89_CHANNEL_WIDTH_20	= 0,
639 	RTW89_CHANNEL_WIDTH_40	= 1,
640 	RTW89_CHANNEL_WIDTH_80	= 2,
641 	RTW89_CHANNEL_WIDTH_160	= 3,
642 	RTW89_CHANNEL_WIDTH_80_80	= 4,
643 	RTW89_CHANNEL_WIDTH_5	= 5,
644 	RTW89_CHANNEL_WIDTH_10	= 6,
645 };
646 
647 enum rtw89_ps_mode {
648 	RTW89_PS_MODE_NONE	= 0,
649 	RTW89_PS_MODE_RFOFF	= 1,
650 	RTW89_PS_MODE_CLK_GATED	= 2,
651 	RTW89_PS_MODE_PWR_GATED	= 3,
652 };
653 
654 #define RTW89_2G_BW_NUM (RTW89_CHANNEL_WIDTH_40 + 1)
655 #define RTW89_5G_BW_NUM (RTW89_CHANNEL_WIDTH_160 + 1)
656 #define RTW89_6G_BW_NUM (RTW89_CHANNEL_WIDTH_160 + 1)
657 #define RTW89_PPE_BW_NUM (RTW89_CHANNEL_WIDTH_160 + 1)
658 
659 enum rtw89_ru_bandwidth {
660 	RTW89_RU26 = 0,
661 	RTW89_RU52 = 1,
662 	RTW89_RU106 = 2,
663 	RTW89_RU_NUM,
664 };
665 
666 enum rtw89_sc_offset {
667 	RTW89_SC_DONT_CARE	= 0,
668 	RTW89_SC_20_UPPER	= 1,
669 	RTW89_SC_20_LOWER	= 2,
670 	RTW89_SC_20_UPMOST	= 3,
671 	RTW89_SC_20_LOWEST	= 4,
672 	RTW89_SC_20_UP2X	= 5,
673 	RTW89_SC_20_LOW2X	= 6,
674 	RTW89_SC_20_UP3X	= 7,
675 	RTW89_SC_20_LOW3X	= 8,
676 	RTW89_SC_40_UPPER	= 9,
677 	RTW89_SC_40_LOWER	= 10,
678 };
679 
680 enum rtw89_wow_flags {
681 	RTW89_WOW_FLAG_EN_MAGIC_PKT,
682 	RTW89_WOW_FLAG_EN_REKEY_PKT,
683 	RTW89_WOW_FLAG_EN_DISCONNECT,
684 	RTW89_WOW_FLAG_NUM,
685 };
686 
687 struct rtw89_chan {
688 	u8 channel;
689 	u8 primary_channel;
690 	enum rtw89_band band_type;
691 	enum rtw89_bandwidth band_width;
692 
693 	/* The follow-up are derived from the above. We must ensure that it
694 	 * is assigned correctly in rtw89_chan_create() if new one is added.
695 	 */
696 	u32 freq;
697 	enum rtw89_subband subband_type;
698 	enum rtw89_sc_offset pri_ch_idx;
699 };
700 
701 struct rtw89_chan_rcd {
702 	u8 prev_primary_channel;
703 	enum rtw89_band prev_band_type;
704 };
705 
706 struct rtw89_channel_help_params {
707 	u32 tx_en;
708 };
709 
710 struct rtw89_port_reg {
711 	u32 port_cfg;
712 	u32 tbtt_prohib;
713 	u32 bcn_area;
714 	u32 bcn_early;
715 	u32 tbtt_early;
716 	u32 tbtt_agg;
717 	u32 bcn_space;
718 	u32 bcn_forcetx;
719 	u32 bcn_err_cnt;
720 	u32 bcn_err_flag;
721 	u32 dtim_ctrl;
722 	u32 tbtt_shift;
723 	u32 bcn_cnt_tmr;
724 	u32 tsftr_l;
725 	u32 tsftr_h;
726 };
727 
728 struct rtw89_txwd_body {
729 	__le32 dword0;
730 	__le32 dword1;
731 	__le32 dword2;
732 	__le32 dword3;
733 	__le32 dword4;
734 	__le32 dword5;
735 } __packed;
736 
737 struct rtw89_txwd_body_v1 {
738 	__le32 dword0;
739 	__le32 dword1;
740 	__le32 dword2;
741 	__le32 dword3;
742 	__le32 dword4;
743 	__le32 dword5;
744 	__le32 dword6;
745 	__le32 dword7;
746 } __packed;
747 
748 struct rtw89_txwd_info {
749 	__le32 dword0;
750 	__le32 dword1;
751 	__le32 dword2;
752 	__le32 dword3;
753 	__le32 dword4;
754 	__le32 dword5;
755 } __packed;
756 
757 struct rtw89_rx_desc_info {
758 	u16 pkt_size;
759 	u8 pkt_type;
760 	u8 drv_info_size;
761 	u8 shift;
762 	u8 wl_hd_iv_len;
763 	bool long_rxdesc;
764 	bool bb_sel;
765 	bool mac_info_valid;
766 	u16 data_rate;
767 	u8 gi_ltf;
768 	u8 bw;
769 	u32 free_run_cnt;
770 	u8 user_id;
771 	bool sr_en;
772 	u8 ppdu_cnt;
773 	u8 ppdu_type;
774 	bool icv_err;
775 	bool crc32_err;
776 	bool hw_dec;
777 	bool sw_dec;
778 	bool addr1_match;
779 	u8 frag;
780 	u16 seq;
781 	u8 frame_type;
782 	u8 rx_pl_id;
783 	bool addr_cam_valid;
784 	u8 addr_cam_id;
785 	u8 sec_cam_id;
786 	u8 mac_id;
787 	u16 offset;
788 	u16 rxd_len;
789 	bool ready;
790 };
791 
792 struct rtw89_rxdesc_short {
793 	__le32 dword0;
794 	__le32 dword1;
795 	__le32 dword2;
796 	__le32 dword3;
797 } __packed;
798 
799 struct rtw89_rxdesc_long {
800 	__le32 dword0;
801 	__le32 dword1;
802 	__le32 dword2;
803 	__le32 dword3;
804 	__le32 dword4;
805 	__le32 dword5;
806 	__le32 dword6;
807 	__le32 dword7;
808 } __packed;
809 
810 struct rtw89_tx_desc_info {
811 	u16 pkt_size;
812 	u8 wp_offset;
813 	u8 mac_id;
814 	u8 qsel;
815 	u8 ch_dma;
816 	u8 hdr_llc_len;
817 	bool is_bmc;
818 	bool en_wd_info;
819 	bool wd_page;
820 	bool use_rate;
821 	bool dis_data_fb;
822 	bool tid_indicate;
823 	bool agg_en;
824 	bool bk;
825 	u8 ampdu_density;
826 	u8 ampdu_num;
827 	bool sec_en;
828 	u8 addr_info_nr;
829 	u8 sec_keyid;
830 	u8 sec_type;
831 	u8 sec_cam_idx;
832 	u8 sec_seq[6];
833 	u16 data_rate;
834 	u16 data_retry_lowest_rate;
835 	bool fw_dl;
836 	u16 seq;
837 	bool a_ctrl_bsr;
838 	u8 hw_ssn_sel;
839 #define RTW89_MGMT_HW_SSN_SEL	1
840 	u8 hw_seq_mode;
841 #define RTW89_MGMT_HW_SEQ_MODE	1
842 	bool hiq;
843 	u8 port;
844 	bool er_cap;
845 };
846 
847 struct rtw89_core_tx_request {
848 	enum rtw89_core_tx_type tx_type;
849 
850 	struct sk_buff *skb;
851 	struct ieee80211_vif *vif;
852 	struct ieee80211_sta *sta;
853 	struct rtw89_tx_desc_info desc_info;
854 };
855 
856 struct rtw89_txq {
857 	struct list_head list;
858 	unsigned long flags;
859 	int wait_cnt;
860 };
861 
862 struct rtw89_mac_ax_gnt {
863 	u8 gnt_bt_sw_en;
864 	u8 gnt_bt;
865 	u8 gnt_wl_sw_en;
866 	u8 gnt_wl;
867 } __packed;
868 
869 #define RTW89_MAC_AX_COEX_GNT_NR 2
870 struct rtw89_mac_ax_coex_gnt {
871 	struct rtw89_mac_ax_gnt band[RTW89_MAC_AX_COEX_GNT_NR];
872 };
873 
874 enum rtw89_btc_ncnt {
875 	BTC_NCNT_POWER_ON = 0x0,
876 	BTC_NCNT_POWER_OFF,
877 	BTC_NCNT_INIT_COEX,
878 	BTC_NCNT_SCAN_START,
879 	BTC_NCNT_SCAN_FINISH,
880 	BTC_NCNT_SPECIAL_PACKET,
881 	BTC_NCNT_SWITCH_BAND,
882 	BTC_NCNT_RFK_TIMEOUT,
883 	BTC_NCNT_SHOW_COEX_INFO,
884 	BTC_NCNT_ROLE_INFO,
885 	BTC_NCNT_CONTROL,
886 	BTC_NCNT_RADIO_STATE,
887 	BTC_NCNT_CUSTOMERIZE,
888 	BTC_NCNT_WL_RFK,
889 	BTC_NCNT_WL_STA,
890 	BTC_NCNT_FWINFO,
891 	BTC_NCNT_TIMER,
892 	BTC_NCNT_NUM
893 };
894 
895 enum rtw89_btc_btinfo {
896 	BTC_BTINFO_L0 = 0,
897 	BTC_BTINFO_L1,
898 	BTC_BTINFO_L2,
899 	BTC_BTINFO_L3,
900 	BTC_BTINFO_H0,
901 	BTC_BTINFO_H1,
902 	BTC_BTINFO_H2,
903 	BTC_BTINFO_H3,
904 	BTC_BTINFO_MAX
905 };
906 
907 enum rtw89_btc_dcnt {
908 	BTC_DCNT_RUN = 0x0,
909 	BTC_DCNT_CX_RUNINFO,
910 	BTC_DCNT_RPT,
911 	BTC_DCNT_RPT_HANG,
912 	BTC_DCNT_CYCLE,
913 	BTC_DCNT_CYCLE_HANG,
914 	BTC_DCNT_W1,
915 	BTC_DCNT_W1_HANG,
916 	BTC_DCNT_B1,
917 	BTC_DCNT_B1_HANG,
918 	BTC_DCNT_TDMA_NONSYNC,
919 	BTC_DCNT_SLOT_NONSYNC,
920 	BTC_DCNT_BTCNT_HANG,
921 	BTC_DCNT_WL_SLOT_DRIFT,
922 	BTC_DCNT_WL_STA_LAST,
923 	BTC_DCNT_BT_SLOT_DRIFT,
924 	BTC_DCNT_BT_SLOT_FLOOD,
925 	BTC_DCNT_FDDT_TRIG,
926 	BTC_DCNT_E2G,
927 	BTC_DCNT_E2G_HANG,
928 	BTC_DCNT_NUM
929 };
930 
931 enum rtw89_btc_wl_state_cnt {
932 	BTC_WCNT_SCANAP = 0x0,
933 	BTC_WCNT_DHCP,
934 	BTC_WCNT_EAPOL,
935 	BTC_WCNT_ARP,
936 	BTC_WCNT_SCBDUPDATE,
937 	BTC_WCNT_RFK_REQ,
938 	BTC_WCNT_RFK_GO,
939 	BTC_WCNT_RFK_REJECT,
940 	BTC_WCNT_RFK_TIMEOUT,
941 	BTC_WCNT_CH_UPDATE,
942 	BTC_WCNT_NUM
943 };
944 
945 enum rtw89_btc_bt_state_cnt {
946 	BTC_BCNT_RETRY = 0x0,
947 	BTC_BCNT_REINIT,
948 	BTC_BCNT_REENABLE,
949 	BTC_BCNT_SCBDREAD,
950 	BTC_BCNT_RELINK,
951 	BTC_BCNT_IGNOWL,
952 	BTC_BCNT_INQPAG,
953 	BTC_BCNT_INQ,
954 	BTC_BCNT_PAGE,
955 	BTC_BCNT_ROLESW,
956 	BTC_BCNT_AFH,
957 	BTC_BCNT_INFOUPDATE,
958 	BTC_BCNT_INFOSAME,
959 	BTC_BCNT_SCBDUPDATE,
960 	BTC_BCNT_HIPRI_TX,
961 	BTC_BCNT_HIPRI_RX,
962 	BTC_BCNT_LOPRI_TX,
963 	BTC_BCNT_LOPRI_RX,
964 	BTC_BCNT_POLUT,
965 	BTC_BCNT_RATECHG,
966 	BTC_BCNT_NUM
967 };
968 
969 enum rtw89_btc_bt_profile {
970 	BTC_BT_NOPROFILE = 0,
971 	BTC_BT_HFP = BIT(0),
972 	BTC_BT_HID = BIT(1),
973 	BTC_BT_A2DP = BIT(2),
974 	BTC_BT_PAN = BIT(3),
975 	BTC_PROFILE_MAX = 4,
976 };
977 
978 struct rtw89_btc_ant_info {
979 	u8 type;  /* shared, dedicated */
980 	u8 num;
981 	u8 isolation;
982 
983 	u8 single_pos: 1;/* Single antenna at S0 or S1 */
984 	u8 diversity: 1;
985 	u8 btg_pos: 2;
986 	u8 stream_cnt: 4;
987 };
988 
989 enum rtw89_tfc_dir {
990 	RTW89_TFC_UL,
991 	RTW89_TFC_DL,
992 };
993 
994 struct rtw89_btc_wl_smap {
995 	u32 busy: 1;
996 	u32 scan: 1;
997 	u32 connecting: 1;
998 	u32 roaming: 1;
999 	u32 _4way: 1;
1000 	u32 rf_off: 1;
1001 	u32 lps: 2;
1002 	u32 ips: 1;
1003 	u32 init_ok: 1;
1004 	u32 traffic_dir : 2;
1005 	u32 rf_off_pre: 1;
1006 	u32 lps_pre: 2;
1007 };
1008 
1009 enum rtw89_tfc_lv {
1010 	RTW89_TFC_IDLE,
1011 	RTW89_TFC_ULTRA_LOW,
1012 	RTW89_TFC_LOW,
1013 	RTW89_TFC_MID,
1014 	RTW89_TFC_HIGH,
1015 };
1016 
1017 #define RTW89_TP_SHIFT 18 /* bytes/2s --> Mbps */
1018 DECLARE_EWMA(tp, 10, 2);
1019 
1020 struct rtw89_traffic_stats {
1021 	/* units in bytes */
1022 	u64 tx_unicast;
1023 	u64 rx_unicast;
1024 	u32 tx_avg_len;
1025 	u32 rx_avg_len;
1026 
1027 	/* count for packets */
1028 	u64 tx_cnt;
1029 	u64 rx_cnt;
1030 
1031 	/* units in Mbps */
1032 	u32 tx_throughput;
1033 	u32 rx_throughput;
1034 	u32 tx_throughput_raw;
1035 	u32 rx_throughput_raw;
1036 
1037 	u32 rx_tf_acc;
1038 	u32 rx_tf_periodic;
1039 
1040 	enum rtw89_tfc_lv tx_tfc_lv;
1041 	enum rtw89_tfc_lv rx_tfc_lv;
1042 	struct ewma_tp tx_ewma_tp;
1043 	struct ewma_tp rx_ewma_tp;
1044 
1045 	u16 tx_rate;
1046 	u16 rx_rate;
1047 };
1048 
1049 struct rtw89_btc_statistic {
1050 	u8 rssi; /* 0%~110% (dBm = rssi -110) */
1051 	struct rtw89_traffic_stats traffic;
1052 };
1053 
1054 #define BTC_WL_RSSI_THMAX 4
1055 
1056 struct rtw89_btc_wl_link_info {
1057 	struct rtw89_btc_statistic stat;
1058 	enum rtw89_tfc_dir dir;
1059 	u8 rssi_state[BTC_WL_RSSI_THMAX];
1060 	u8 mac_addr[ETH_ALEN];
1061 	u8 busy;
1062 	u8 ch;
1063 	u8 bw;
1064 	u8 band;
1065 	u8 role;
1066 	u8 pid;
1067 	u8 phy;
1068 	u8 dtim_period;
1069 	u8 mode;
1070 
1071 	u8 mac_id;
1072 	u8 tx_retry;
1073 
1074 	u32 bcn_period;
1075 	u32 busy_t;
1076 	u32 tx_time;
1077 	u32 client_cnt;
1078 	u32 rx_rate_drop_cnt;
1079 
1080 	u32 active: 1;
1081 	u32 noa: 1;
1082 	u32 client_ps: 1;
1083 	u32 connected: 2;
1084 };
1085 
1086 union rtw89_btc_wl_state_map {
1087 	u32 val;
1088 	struct rtw89_btc_wl_smap map;
1089 };
1090 
1091 struct rtw89_btc_bt_hfp_desc {
1092 	u32 exist: 1;
1093 	u32 type: 2;
1094 	u32 rsvd: 29;
1095 };
1096 
1097 struct rtw89_btc_bt_hid_desc {
1098 	u32 exist: 1;
1099 	u32 slot_info: 2;
1100 	u32 pair_cnt: 2;
1101 	u32 type: 8;
1102 	u32 rsvd: 19;
1103 };
1104 
1105 struct rtw89_btc_bt_a2dp_desc {
1106 	u8 exist: 1;
1107 	u8 exist_last: 1;
1108 	u8 play_latency: 1;
1109 	u8 type: 3;
1110 	u8 active: 1;
1111 	u8 sink: 1;
1112 
1113 	u8 bitpool;
1114 	u16 vendor_id;
1115 	u32 device_name;
1116 	u32 flush_time;
1117 };
1118 
1119 struct rtw89_btc_bt_pan_desc {
1120 	u32 exist: 1;
1121 	u32 type: 1;
1122 	u32 active: 1;
1123 	u32 rsvd: 29;
1124 };
1125 
1126 struct rtw89_btc_bt_rfk_info {
1127 	u32 run: 1;
1128 	u32 req: 1;
1129 	u32 timeout: 1;
1130 	u32 rsvd: 29;
1131 };
1132 
1133 union rtw89_btc_bt_rfk_info_map {
1134 	u32 val;
1135 	struct rtw89_btc_bt_rfk_info map;
1136 };
1137 
1138 struct rtw89_btc_bt_ver_info {
1139 	u32 fw_coex; /* match with which coex_ver */
1140 	u32 fw;
1141 };
1142 
1143 struct rtw89_btc_bool_sta_chg {
1144 	u32 now: 1;
1145 	u32 last: 1;
1146 	u32 remain: 1;
1147 	u32 srvd: 29;
1148 };
1149 
1150 struct rtw89_btc_u8_sta_chg {
1151 	u8 now;
1152 	u8 last;
1153 	u8 remain;
1154 	u8 rsvd;
1155 };
1156 
1157 struct rtw89_btc_wl_scan_info {
1158 	u8 band[RTW89_PHY_MAX];
1159 	u8 phy_map;
1160 	u8 rsvd;
1161 };
1162 
1163 struct rtw89_btc_wl_dbcc_info {
1164 	u8 op_band[RTW89_PHY_MAX]; /* op band in each phy */
1165 	u8 scan_band[RTW89_PHY_MAX]; /* scan band in  each phy */
1166 	u8 real_band[RTW89_PHY_MAX];
1167 	u8 role[RTW89_PHY_MAX]; /* role in each phy */
1168 };
1169 
1170 struct rtw89_btc_wl_active_role {
1171 	u8 connected: 1;
1172 	u8 pid: 3;
1173 	u8 phy: 1;
1174 	u8 noa: 1;
1175 	u8 band: 2;
1176 
1177 	u8 client_ps: 1;
1178 	u8 bw: 7;
1179 
1180 	u8 role;
1181 	u8 ch;
1182 
1183 	u16 tx_lvl;
1184 	u16 rx_lvl;
1185 	u16 tx_rate;
1186 	u16 rx_rate;
1187 };
1188 
1189 struct rtw89_btc_wl_active_role_v1 {
1190 	u8 connected: 1;
1191 	u8 pid: 3;
1192 	u8 phy: 1;
1193 	u8 noa: 1;
1194 	u8 band: 2;
1195 
1196 	u8 client_ps: 1;
1197 	u8 bw: 7;
1198 
1199 	u8 role;
1200 	u8 ch;
1201 
1202 	u16 tx_lvl;
1203 	u16 rx_lvl;
1204 	u16 tx_rate;
1205 	u16 rx_rate;
1206 
1207 	u32 noa_duration; /* ms */
1208 };
1209 
1210 struct rtw89_btc_wl_active_role_v2 {
1211 	u8 connected: 1;
1212 	u8 pid: 3;
1213 	u8 phy: 1;
1214 	u8 noa: 1;
1215 	u8 band: 2;
1216 
1217 	u8 client_ps: 1;
1218 	u8 bw: 7;
1219 
1220 	u8 role;
1221 	u8 ch;
1222 
1223 	u32 noa_duration; /* ms */
1224 };
1225 
1226 struct rtw89_btc_wl_role_info_bpos {
1227 	u16 none: 1;
1228 	u16 station: 1;
1229 	u16 ap: 1;
1230 	u16 vap: 1;
1231 	u16 adhoc: 1;
1232 	u16 adhoc_master: 1;
1233 	u16 mesh: 1;
1234 	u16 moniter: 1;
1235 	u16 p2p_device: 1;
1236 	u16 p2p_gc: 1;
1237 	u16 p2p_go: 1;
1238 	u16 nan: 1;
1239 };
1240 
1241 struct rtw89_btc_wl_scc_ctrl {
1242 	u8 null_role1;
1243 	u8 null_role2;
1244 	u8 ebt_null; /* if tx null at EBT slot */
1245 };
1246 
1247 union rtw89_btc_wl_role_info_map {
1248 	u16 val;
1249 	struct rtw89_btc_wl_role_info_bpos role;
1250 };
1251 
1252 struct rtw89_btc_wl_role_info { /* struct size must be n*4 bytes */
1253 	u8 connect_cnt;
1254 	u8 link_mode;
1255 	union rtw89_btc_wl_role_info_map role_map;
1256 	struct rtw89_btc_wl_active_role active_role[RTW89_PORT_NUM];
1257 };
1258 
1259 struct rtw89_btc_wl_role_info_v1 { /* struct size must be n*4 bytes */
1260 	u8 connect_cnt;
1261 	u8 link_mode;
1262 	union rtw89_btc_wl_role_info_map role_map;
1263 	struct rtw89_btc_wl_active_role_v1 active_role_v1[RTW89_PORT_NUM];
1264 	u32 mrole_type; /* btc_wl_mrole_type */
1265 	u32 mrole_noa_duration; /* ms */
1266 
1267 	u32 dbcc_en: 1;
1268 	u32 dbcc_chg: 1;
1269 	u32 dbcc_2g_phy: 2; /* which phy operate in 2G, HW_PHY_0 or HW_PHY_1 */
1270 	u32 link_mode_chg: 1;
1271 	u32 rsvd: 27;
1272 };
1273 
1274 struct rtw89_btc_wl_role_info_v2 { /* struct size must be n*4 bytes */
1275 	u8 connect_cnt;
1276 	u8 link_mode;
1277 	union rtw89_btc_wl_role_info_map role_map;
1278 	struct rtw89_btc_wl_active_role_v2 active_role_v2[RTW89_PORT_NUM];
1279 	u32 mrole_type; /* btc_wl_mrole_type */
1280 	u32 mrole_noa_duration; /* ms */
1281 
1282 	u32 dbcc_en: 1;
1283 	u32 dbcc_chg: 1;
1284 	u32 dbcc_2g_phy: 2; /* which phy operate in 2G, HW_PHY_0 or HW_PHY_1 */
1285 	u32 link_mode_chg: 1;
1286 	u32 rsvd: 27;
1287 };
1288 
1289 struct rtw89_btc_wl_ver_info {
1290 	u32 fw_coex; /* match with which coex_ver */
1291 	u32 fw;
1292 	u32 mac;
1293 	u32 bb;
1294 	u32 rf;
1295 };
1296 
1297 struct rtw89_btc_wl_afh_info {
1298 	u8 en;
1299 	u8 ch;
1300 	u8 bw;
1301 	u8 rsvd;
1302 } __packed;
1303 
1304 struct rtw89_btc_wl_rfk_info {
1305 	u32 state: 2;
1306 	u32 path_map: 4;
1307 	u32 phy_map: 2;
1308 	u32 band: 2;
1309 	u32 type: 8;
1310 	u32 rsvd: 14;
1311 };
1312 
1313 struct rtw89_btc_bt_smap {
1314 	u32 connect: 1;
1315 	u32 ble_connect: 1;
1316 	u32 acl_busy: 1;
1317 	u32 sco_busy: 1;
1318 	u32 mesh_busy: 1;
1319 	u32 inq_pag: 1;
1320 };
1321 
1322 union rtw89_btc_bt_state_map {
1323 	u32 val;
1324 	struct rtw89_btc_bt_smap map;
1325 };
1326 
1327 #define BTC_BT_RSSI_THMAX 4
1328 #define BTC_BT_AFH_GROUP 12
1329 #define BTC_BT_AFH_LE_GROUP 5
1330 
1331 struct rtw89_btc_bt_link_info {
1332 	struct rtw89_btc_u8_sta_chg profile_cnt;
1333 	struct rtw89_btc_bool_sta_chg multi_link;
1334 	struct rtw89_btc_bool_sta_chg relink;
1335 	struct rtw89_btc_bt_hfp_desc hfp_desc;
1336 	struct rtw89_btc_bt_hid_desc hid_desc;
1337 	struct rtw89_btc_bt_a2dp_desc a2dp_desc;
1338 	struct rtw89_btc_bt_pan_desc pan_desc;
1339 	union rtw89_btc_bt_state_map status;
1340 
1341 	u8 sut_pwr_level[BTC_PROFILE_MAX];
1342 	u8 golden_rx_shift[BTC_PROFILE_MAX];
1343 	u8 rssi_state[BTC_BT_RSSI_THMAX];
1344 	u8 afh_map[BTC_BT_AFH_GROUP];
1345 	u8 afh_map_le[BTC_BT_AFH_LE_GROUP];
1346 
1347 	u32 role_sw: 1;
1348 	u32 slave_role: 1;
1349 	u32 afh_update: 1;
1350 	u32 cqddr: 1;
1351 	u32 rssi: 8;
1352 	u32 tx_3m: 1;
1353 	u32 rsvd: 19;
1354 };
1355 
1356 struct rtw89_btc_3rdcx_info {
1357 	u8 type;   /* 0: none, 1:zigbee, 2:LTE  */
1358 	u8 hw_coex;
1359 	u16 rsvd;
1360 };
1361 
1362 struct rtw89_btc_dm_emap {
1363 	u32 init: 1;
1364 	u32 pta_owner: 1;
1365 	u32 wl_rfk_timeout: 1;
1366 	u32 bt_rfk_timeout: 1;
1367 	u32 wl_fw_hang: 1;
1368 	u32 cycle_hang: 1;
1369 	u32 w1_hang: 1;
1370 	u32 b1_hang: 1;
1371 	u32 tdma_no_sync: 1;
1372 	u32 slot_no_sync: 1;
1373 	u32 wl_slot_drift: 1;
1374 	u32 bt_slot_drift: 1;
1375 	u32 role_num_mismatch: 1;
1376 	u32 null1_tx_late: 1;
1377 	u32 bt_afh_conflict: 1;
1378 	u32 bt_leafh_conflict: 1;
1379 	u32 bt_slot_flood: 1;
1380 	u32 wl_e2g_hang: 1;
1381 	u32 wl_ver_mismatch: 1;
1382 	u32 bt_ver_mismatch: 1;
1383 };
1384 
1385 union rtw89_btc_dm_error_map {
1386 	u32 val;
1387 	struct rtw89_btc_dm_emap map;
1388 };
1389 
1390 struct rtw89_btc_rf_para {
1391 	u32 tx_pwr_freerun;
1392 	u32 rx_gain_freerun;
1393 	u32 tx_pwr_perpkt;
1394 	u32 rx_gain_perpkt;
1395 };
1396 
1397 struct rtw89_btc_wl_nhm {
1398 	u8 instant_wl_nhm_dbm;
1399 	u8 instant_wl_nhm_per_mhz;
1400 	u16 valid_record_times;
1401 	s8 record_pwr[16];
1402 	u8 record_ratio[16];
1403 	s8 pwr; /* dbm_per_MHz  */
1404 	u8 ratio;
1405 	u8 current_status;
1406 	u8 refresh;
1407 	bool start_flag;
1408 	s8 pwr_max;
1409 	s8 pwr_min;
1410 };
1411 
1412 struct rtw89_btc_wl_info {
1413 	struct rtw89_btc_wl_link_info link_info[RTW89_PORT_NUM];
1414 	struct rtw89_btc_wl_rfk_info rfk_info;
1415 	struct rtw89_btc_wl_ver_info  ver_info;
1416 	struct rtw89_btc_wl_afh_info afh_info;
1417 	struct rtw89_btc_wl_role_info role_info;
1418 	struct rtw89_btc_wl_role_info_v1 role_info_v1;
1419 	struct rtw89_btc_wl_role_info_v2 role_info_v2;
1420 	struct rtw89_btc_wl_scan_info scan_info;
1421 	struct rtw89_btc_wl_dbcc_info dbcc_info;
1422 	struct rtw89_btc_rf_para rf_para;
1423 	struct rtw89_btc_wl_nhm nhm;
1424 	union rtw89_btc_wl_state_map status;
1425 
1426 	u8 port_id[RTW89_WIFI_ROLE_MLME_MAX];
1427 	u8 rssi_level;
1428 	u8 cn_report;
1429 
1430 	bool scbd_change;
1431 	u32 scbd;
1432 };
1433 
1434 struct rtw89_btc_module {
1435 	struct rtw89_btc_ant_info ant;
1436 	u8 rfe_type;
1437 	u8 cv;
1438 
1439 	u8 bt_solo: 1;
1440 	u8 bt_pos: 1;
1441 	u8 switch_type: 1;
1442 	u8 wa_type: 3;
1443 
1444 	u8 kt_ver_adie;
1445 };
1446 
1447 #define RTW89_BTC_DM_MAXSTEP 30
1448 #define RTW89_BTC_DM_CNT_MAX (RTW89_BTC_DM_MAXSTEP * 8)
1449 
1450 struct rtw89_btc_dm_step {
1451 	u16 step[RTW89_BTC_DM_MAXSTEP];
1452 	u8 step_pos;
1453 	bool step_ov;
1454 };
1455 
1456 struct rtw89_btc_init_info {
1457 	struct rtw89_btc_module module;
1458 	u8 wl_guard_ch;
1459 
1460 	u8 wl_only: 1;
1461 	u8 wl_init_ok: 1;
1462 	u8 dbcc_en: 1;
1463 	u8 cx_other: 1;
1464 	u8 bt_only: 1;
1465 
1466 	u16 rsvd;
1467 };
1468 
1469 struct rtw89_btc_wl_tx_limit_para {
1470 	u16 enable;
1471 	u32 tx_time;	/* unit: us */
1472 	u16 tx_retry;
1473 };
1474 
1475 enum rtw89_btc_bt_scan_type {
1476 	BTC_SCAN_INQ	= 0,
1477 	BTC_SCAN_PAGE,
1478 	BTC_SCAN_BLE,
1479 	BTC_SCAN_INIT,
1480 	BTC_SCAN_TV,
1481 	BTC_SCAN_ADV,
1482 	BTC_SCAN_MAX1,
1483 };
1484 
1485 enum rtw89_btc_ble_scan_type {
1486 	CXSCAN_BG = 0,
1487 	CXSCAN_INIT,
1488 	CXSCAN_LE,
1489 	CXSCAN_MAX
1490 };
1491 
1492 #define RTW89_BTC_BTC_SCAN_V1_FLAG_ENABLE BIT(0)
1493 #define RTW89_BTC_BTC_SCAN_V1_FLAG_INTERLACE BIT(1)
1494 
1495 struct rtw89_btc_bt_scan_info_v1 {
1496 	__le16 win;
1497 	__le16 intvl;
1498 	__le32 flags;
1499 } __packed;
1500 
1501 struct rtw89_btc_bt_scan_info_v2 {
1502 	__le16 win;
1503 	__le16 intvl;
1504 } __packed;
1505 
1506 struct rtw89_btc_fbtc_btscan_v1 {
1507 	u8 fver; /* btc_ver::fcxbtscan */
1508 	u8 rsvd;
1509 	__le16 rsvd2;
1510 	struct rtw89_btc_bt_scan_info_v1 scan[BTC_SCAN_MAX1];
1511 } __packed;
1512 
1513 struct rtw89_btc_fbtc_btscan_v2 {
1514 	u8 fver; /* btc_ver::fcxbtscan */
1515 	u8 type;
1516 	__le16 rsvd2;
1517 	struct rtw89_btc_bt_scan_info_v2 para[CXSCAN_MAX];
1518 } __packed;
1519 
1520 union rtw89_btc_fbtc_btscan {
1521 	struct rtw89_btc_fbtc_btscan_v1 v1;
1522 	struct rtw89_btc_fbtc_btscan_v2 v2;
1523 };
1524 
1525 struct rtw89_btc_bt_info {
1526 	struct rtw89_btc_bt_link_info link_info;
1527 	struct rtw89_btc_bt_scan_info_v1 scan_info_v1[BTC_SCAN_MAX1];
1528 	struct rtw89_btc_bt_scan_info_v2 scan_info_v2[CXSCAN_MAX];
1529 	struct rtw89_btc_bt_ver_info ver_info;
1530 	struct rtw89_btc_bool_sta_chg enable;
1531 	struct rtw89_btc_bool_sta_chg inq_pag;
1532 	struct rtw89_btc_rf_para rf_para;
1533 	union rtw89_btc_bt_rfk_info_map rfk_info;
1534 
1535 	u8 raw_info[BTC_BTINFO_MAX]; /* raw bt info from mailbox */
1536 
1537 	u32 scbd;
1538 	u32 feature;
1539 
1540 	u32 mbx_avl: 1;
1541 	u32 whql_test: 1;
1542 	u32 igno_wl: 1;
1543 	u32 reinit: 1;
1544 	u32 ble_scan_en: 1;
1545 	u32 btg_type: 1;
1546 	u32 inq: 1;
1547 	u32 pag: 1;
1548 	u32 run_patch_code: 1;
1549 	u32 hi_lna_rx: 1;
1550 	u32 scan_rx_low_pri: 1;
1551 	u32 scan_info_update: 1;
1552 	u32 rsvd: 20;
1553 };
1554 
1555 struct rtw89_btc_cx {
1556 	struct rtw89_btc_wl_info wl;
1557 	struct rtw89_btc_bt_info bt;
1558 	struct rtw89_btc_3rdcx_info other;
1559 	u32 state_map;
1560 	u32 cnt_bt[BTC_BCNT_NUM];
1561 	u32 cnt_wl[BTC_WCNT_NUM];
1562 };
1563 
1564 struct rtw89_btc_fbtc_tdma {
1565 	u8 type; /* btc_ver::fcxtdma */
1566 	u8 rxflctrl;
1567 	u8 txpause;
1568 	u8 wtgle_n;
1569 	u8 leak_n;
1570 	u8 ext_ctrl;
1571 	u8 rxflctrl_role;
1572 	u8 option_ctrl;
1573 } __packed;
1574 
1575 struct rtw89_btc_fbtc_tdma_v3 {
1576 	u8 fver; /* btc_ver::fcxtdma */
1577 	u8 rsvd;
1578 	__le16 rsvd1;
1579 	struct rtw89_btc_fbtc_tdma tdma;
1580 } __packed;
1581 
1582 union rtw89_btc_fbtc_tdma_le32 {
1583 	struct rtw89_btc_fbtc_tdma v1;
1584 	struct rtw89_btc_fbtc_tdma_v3 v3;
1585 };
1586 
1587 #define CXMREG_MAX 30
1588 #define CXMREG_MAX_V2 20
1589 #define FCXMAX_STEP 255 /*STEP trace record cnt, Max:65535, default:255*/
1590 #define BTC_CYCLE_SLOT_MAX 48 /* must be even number, non-zero */
1591 
1592 enum rtw89_btc_bt_sta_counter {
1593 	BTC_BCNT_RFK_REQ = 0,
1594 	BTC_BCNT_RFK_GO = 1,
1595 	BTC_BCNT_RFK_REJECT = 2,
1596 	BTC_BCNT_RFK_FAIL = 3,
1597 	BTC_BCNT_RFK_TIMEOUT = 4,
1598 	BTC_BCNT_HI_TX = 5,
1599 	BTC_BCNT_HI_RX = 6,
1600 	BTC_BCNT_LO_TX = 7,
1601 	BTC_BCNT_LO_RX = 8,
1602 	BTC_BCNT_POLLUTED = 9,
1603 	BTC_BCNT_STA_MAX
1604 };
1605 
1606 enum rtw89_btc_bt_sta_counter_v105 {
1607 	BTC_BCNT_RFK_REQ_V105 = 0,
1608 	BTC_BCNT_HI_TX_V105 = 1,
1609 	BTC_BCNT_HI_RX_V105 = 2,
1610 	BTC_BCNT_LO_TX_V105 = 3,
1611 	BTC_BCNT_LO_RX_V105 = 4,
1612 	BTC_BCNT_POLLUTED_V105 = 5,
1613 	BTC_BCNT_STA_MAX_V105
1614 };
1615 
1616 struct rtw89_btc_fbtc_rpt_ctrl_v1 {
1617 	u16 fver; /* btc_ver::fcxbtcrpt */
1618 	u16 rpt_cnt; /* tmr counters */
1619 	u32 wl_fw_coex_ver; /* match which driver's coex version */
1620 	u32 wl_fw_cx_offload;
1621 	u32 wl_fw_ver;
1622 	u32 rpt_enable;
1623 	u32 rpt_para; /* ms */
1624 	u32 mb_send_fail_cnt; /* fw send mailbox fail counter */
1625 	u32 mb_send_ok_cnt; /* fw send mailbox ok counter */
1626 	u32 mb_recv_cnt; /* fw recv mailbox counter */
1627 	u32 mb_a2dp_empty_cnt; /* a2dp empty count */
1628 	u32 mb_a2dp_flct_cnt; /* a2dp empty flow control counter */
1629 	u32 mb_a2dp_full_cnt; /* a2dp empty full counter */
1630 	u32 bt_rfk_cnt[BTC_BCNT_HI_TX];
1631 	u32 c2h_cnt; /* fw send c2h counter  */
1632 	u32 h2c_cnt; /* fw recv h2c counter */
1633 } __packed;
1634 
1635 struct rtw89_btc_fbtc_rpt_ctrl_info {
1636 	__le32 cnt; /* fw report counter */
1637 	__le32 en; /* report map */
1638 	__le32 para; /* not used */
1639 
1640 	__le32 cnt_c2h; /* fw send c2h counter  */
1641 	__le32 cnt_h2c; /* fw recv h2c counter */
1642 	__le32 len_c2h; /* The total length of the last C2H  */
1643 
1644 	__le32 cnt_aoac_rf_on;  /* rf-on counter for aoac switch notify */
1645 	__le32 cnt_aoac_rf_off; /* rf-off counter for aoac switch notify */
1646 } __packed;
1647 
1648 struct rtw89_btc_fbtc_rpt_ctrl_info_v5 {
1649 	__le32 cx_ver; /* match which driver's coex version */
1650 	__le32 fw_ver;
1651 	__le32 en; /* report map */
1652 
1653 	__le16 cnt; /* fw report counter */
1654 	__le16 cnt_c2h; /* fw send c2h counter  */
1655 	__le16 cnt_h2c; /* fw recv h2c counter */
1656 	__le16 len_c2h; /* The total length of the last C2H  */
1657 
1658 	__le16 cnt_aoac_rf_on;  /* rf-on counter for aoac switch notify */
1659 	__le16 cnt_aoac_rf_off; /* rf-off counter for aoac switch notify */
1660 } __packed;
1661 
1662 struct rtw89_btc_fbtc_rpt_ctrl_wl_fw_info {
1663 	__le32 cx_ver; /* match which driver's coex version */
1664 	__le32 cx_offload;
1665 	__le32 fw_ver;
1666 } __packed;
1667 
1668 struct rtw89_btc_fbtc_rpt_ctrl_a2dp_empty {
1669 	__le32 cnt_empty; /* a2dp empty count */
1670 	__le32 cnt_flowctrl; /* a2dp empty flow control counter */
1671 	__le32 cnt_tx;
1672 	__le32 cnt_ack;
1673 	__le32 cnt_nack;
1674 } __packed;
1675 
1676 struct rtw89_btc_fbtc_rpt_ctrl_bt_mailbox {
1677 	__le32 cnt_send_ok; /* fw send mailbox ok counter */
1678 	__le32 cnt_send_fail; /* fw send mailbox fail counter */
1679 	__le32 cnt_recv; /* fw recv mailbox counter */
1680 	struct rtw89_btc_fbtc_rpt_ctrl_a2dp_empty a2dp;
1681 } __packed;
1682 
1683 struct rtw89_btc_fbtc_rpt_ctrl_v4 {
1684 	u8 fver;
1685 	u8 rsvd;
1686 	__le16 rsvd1;
1687 	struct rtw89_btc_fbtc_rpt_ctrl_info rpt_info;
1688 	struct rtw89_btc_fbtc_rpt_ctrl_wl_fw_info wl_fw_info;
1689 	struct rtw89_btc_fbtc_rpt_ctrl_bt_mailbox bt_mbx_info;
1690 	__le32 bt_cnt[BTC_BCNT_STA_MAX];
1691 	struct rtw89_mac_ax_gnt gnt_val[RTW89_PHY_MAX];
1692 } __packed;
1693 
1694 struct rtw89_btc_fbtc_rpt_ctrl_v5 {
1695 	u8 fver;
1696 	u8 rsvd;
1697 	__le16 rsvd1;
1698 
1699 	u8 gnt_val[RTW89_PHY_MAX][4];
1700 	__le16 bt_cnt[BTC_BCNT_STA_MAX];
1701 
1702 	struct rtw89_btc_fbtc_rpt_ctrl_info_v5 rpt_info;
1703 	struct rtw89_btc_fbtc_rpt_ctrl_bt_mailbox bt_mbx_info;
1704 } __packed;
1705 
1706 struct rtw89_btc_fbtc_rpt_ctrl_v105 {
1707 	u8 fver;
1708 	u8 rsvd;
1709 	__le16 rsvd1;
1710 
1711 	u8 gnt_val[RTW89_PHY_MAX][4];
1712 	__le16 bt_cnt[BTC_BCNT_STA_MAX_V105];
1713 
1714 	struct rtw89_btc_fbtc_rpt_ctrl_info_v5 rpt_info;
1715 	struct rtw89_btc_fbtc_rpt_ctrl_bt_mailbox bt_mbx_info;
1716 } __packed;
1717 
1718 union rtw89_btc_fbtc_rpt_ctrl_ver_info {
1719 	struct rtw89_btc_fbtc_rpt_ctrl_v1 v1;
1720 	struct rtw89_btc_fbtc_rpt_ctrl_v4 v4;
1721 	struct rtw89_btc_fbtc_rpt_ctrl_v5 v5;
1722 	struct rtw89_btc_fbtc_rpt_ctrl_v105 v105;
1723 };
1724 
1725 enum rtw89_fbtc_ext_ctrl_type {
1726 	CXECTL_OFF = 0x0, /* tdma off */
1727 	CXECTL_B2 = 0x1, /* allow B2 (beacon-early) */
1728 	CXECTL_EXT = 0x2,
1729 	CXECTL_MAX
1730 };
1731 
1732 union rtw89_btc_fbtc_rxflct {
1733 	u8 val;
1734 	u8 type: 3;
1735 	u8 tgln_n: 5;
1736 };
1737 
1738 enum rtw89_btc_cxst_state {
1739 	CXST_OFF = 0x0,
1740 	CXST_B2W = 0x1,
1741 	CXST_W1 = 0x2,
1742 	CXST_W2 = 0x3,
1743 	CXST_W2B = 0x4,
1744 	CXST_B1 = 0x5,
1745 	CXST_B2 = 0x6,
1746 	CXST_B3 = 0x7,
1747 	CXST_B4 = 0x8,
1748 	CXST_LK = 0x9,
1749 	CXST_BLK = 0xa,
1750 	CXST_E2G = 0xb,
1751 	CXST_E5G = 0xc,
1752 	CXST_EBT = 0xd,
1753 	CXST_ENULL = 0xe,
1754 	CXST_WLK = 0xf,
1755 	CXST_W1FDD = 0x10,
1756 	CXST_B1FDD = 0x11,
1757 	CXST_MAX = 0x12,
1758 };
1759 
1760 enum rtw89_btc_cxevnt {
1761 	CXEVNT_TDMA_ENTRY = 0x0,
1762 	CXEVNT_WL_TMR,
1763 	CXEVNT_B1_TMR,
1764 	CXEVNT_B2_TMR,
1765 	CXEVNT_B3_TMR,
1766 	CXEVNT_B4_TMR,
1767 	CXEVNT_W2B_TMR,
1768 	CXEVNT_B2W_TMR,
1769 	CXEVNT_BCN_EARLY,
1770 	CXEVNT_A2DP_EMPTY,
1771 	CXEVNT_LK_END,
1772 	CXEVNT_RX_ISR,
1773 	CXEVNT_RX_FC0,
1774 	CXEVNT_RX_FC1,
1775 	CXEVNT_BT_RELINK,
1776 	CXEVNT_BT_RETRY,
1777 	CXEVNT_E2G,
1778 	CXEVNT_E5G,
1779 	CXEVNT_EBT,
1780 	CXEVNT_ENULL,
1781 	CXEVNT_DRV_WLK,
1782 	CXEVNT_BCN_OK,
1783 	CXEVNT_BT_CHANGE,
1784 	CXEVNT_EBT_EXTEND,
1785 	CXEVNT_E2G_NULL1,
1786 	CXEVNT_B1FDD_TMR,
1787 	CXEVNT_MAX
1788 };
1789 
1790 enum {
1791 	CXBCN_ALL = 0x0,
1792 	CXBCN_ALL_OK,
1793 	CXBCN_BT_SLOT,
1794 	CXBCN_BT_OK,
1795 	CXBCN_MAX
1796 };
1797 
1798 enum btc_slot_type {
1799 	SLOT_MIX = 0x0, /* accept BT Lower-Pri Tx/Rx request 0x778 = 1 */
1800 	SLOT_ISO = 0x1, /* no accept BT Lower-Pri Tx/Rx request 0x778 = d*/
1801 	CXSTYPE_NUM,
1802 };
1803 
1804 enum { /* TIME */
1805 	CXT_BT = 0x0,
1806 	CXT_WL = 0x1,
1807 	CXT_MAX
1808 };
1809 
1810 enum { /* TIME-A2DP */
1811 	CXT_FLCTRL_OFF = 0x0,
1812 	CXT_FLCTRL_ON = 0x1,
1813 	CXT_FLCTRL_MAX
1814 };
1815 
1816 enum { /* STEP TYPE */
1817 	CXSTEP_NONE = 0x0,
1818 	CXSTEP_EVNT = 0x1,
1819 	CXSTEP_SLOT = 0x2,
1820 	CXSTEP_MAX,
1821 };
1822 
1823 enum rtw89_btc_afh_map_type { /*AFH MAP TYPE */
1824 	RPT_BT_AFH_SEQ_LEGACY = 0x10,
1825 	RPT_BT_AFH_SEQ_LE = 0x20
1826 };
1827 
1828 #define BTC_DBG_MAX1  32
1829 struct rtw89_btc_fbtc_gpio_dbg {
1830 	u8 fver; /* btc_ver::fcxgpiodbg */
1831 	u8 rsvd;
1832 	u16 rsvd2;
1833 	u32 en_map; /* which debug signal (see btc_wl_gpio_debug) is enable */
1834 	u32 pre_state; /* the debug signal is 1 or 0  */
1835 	u8 gpio_map[BTC_DBG_MAX1]; /*the debug signals to GPIO-Position */
1836 } __packed;
1837 
1838 struct rtw89_btc_fbtc_mreg_val_v1 {
1839 	u8 fver; /* btc_ver::fcxmreg */
1840 	u8 reg_num;
1841 	__le16 rsvd;
1842 	__le32 mreg_val[CXMREG_MAX];
1843 } __packed;
1844 
1845 struct rtw89_btc_fbtc_mreg_val_v2 {
1846 	u8 fver; /* btc_ver::fcxmreg */
1847 	u8 reg_num;
1848 	__le16 rsvd;
1849 	__le32 mreg_val[CXMREG_MAX_V2];
1850 } __packed;
1851 
1852 union rtw89_btc_fbtc_mreg_val {
1853 	struct rtw89_btc_fbtc_mreg_val_v1 v1;
1854 	struct rtw89_btc_fbtc_mreg_val_v2 v2;
1855 };
1856 
1857 #define RTW89_DEF_FBTC_MREG(__type, __bytes, __offset) \
1858 	{ .type = cpu_to_le16(__type), .bytes = cpu_to_le16(__bytes), \
1859 	  .offset = cpu_to_le32(__offset), }
1860 
1861 struct rtw89_btc_fbtc_mreg {
1862 	__le16 type;
1863 	__le16 bytes;
1864 	__le32 offset;
1865 } __packed;
1866 
1867 struct rtw89_btc_fbtc_slot {
1868 	__le16 dur;
1869 	__le32 cxtbl;
1870 	__le16 cxtype;
1871 } __packed;
1872 
1873 struct rtw89_btc_fbtc_slots {
1874 	u8 fver; /* btc_ver::fcxslots */
1875 	u8 tbl_num;
1876 	__le16 rsvd;
1877 	__le32 update_map;
1878 	struct rtw89_btc_fbtc_slot slot[CXST_MAX];
1879 } __packed;
1880 
1881 struct rtw89_btc_fbtc_step {
1882 	u8 type;
1883 	u8 val;
1884 	__le16 difft;
1885 } __packed;
1886 
1887 struct rtw89_btc_fbtc_steps_v2 {
1888 	u8 fver; /* btc_ver::fcxstep */
1889 	u8 rsvd;
1890 	__le16 cnt;
1891 	__le16 pos_old;
1892 	__le16 pos_new;
1893 	struct rtw89_btc_fbtc_step step[FCXMAX_STEP];
1894 } __packed;
1895 
1896 struct rtw89_btc_fbtc_steps_v3 {
1897 	u8 fver;
1898 	u8 en;
1899 	__le16 rsvd;
1900 	__le32 cnt;
1901 	struct rtw89_btc_fbtc_step step[FCXMAX_STEP];
1902 } __packed;
1903 
1904 union rtw89_btc_fbtc_steps_info {
1905 	struct rtw89_btc_fbtc_steps_v2 v2;
1906 	struct rtw89_btc_fbtc_steps_v3 v3;
1907 };
1908 
1909 struct rtw89_btc_fbtc_cysta_v2 { /* statistics for cycles */
1910 	u8 fver; /* btc_ver::fcxcysta */
1911 	u8 rsvd;
1912 	__le16 cycles; /* total cycle number */
1913 	__le16 cycles_a2dp[CXT_FLCTRL_MAX];
1914 	__le16 a2dpept; /* a2dp empty cnt */
1915 	__le16 a2dpeptto; /* a2dp empty timeout cnt*/
1916 	__le16 tavg_cycle[CXT_MAX]; /* avg wl/bt cycle time */
1917 	__le16 tmax_cycle[CXT_MAX]; /* max wl/bt cycle time */
1918 	__le16 tmaxdiff_cycle[CXT_MAX]; /* max wl-wl bt-bt cycle diff time */
1919 	__le16 tavg_a2dp[CXT_FLCTRL_MAX]; /* avg a2dp PSTDMA/TDMA time */
1920 	__le16 tmax_a2dp[CXT_FLCTRL_MAX]; /* max a2dp PSTDMA/TDMA time */
1921 	__le16 tavg_a2dpept; /* avg a2dp empty time */
1922 	__le16 tmax_a2dpept; /* max a2dp empty time */
1923 	__le16 tavg_lk; /* avg leak-slot time */
1924 	__le16 tmax_lk; /* max leak-slot time */
1925 	__le32 slot_cnt[CXST_MAX]; /* slot count */
1926 	__le32 bcn_cnt[CXBCN_MAX];
1927 	__le32 leakrx_cnt; /* the rximr occur at leak slot  */
1928 	__le32 collision_cnt; /* counter for event/timer occur at same time */
1929 	__le32 skip_cnt;
1930 	__le32 exception;
1931 	__le32 except_cnt;
1932 	__le16 tslot_cycle[BTC_CYCLE_SLOT_MAX];
1933 } __packed;
1934 
1935 struct rtw89_btc_fbtc_fdd_try_info {
1936 	__le16 cycles[CXT_FLCTRL_MAX];
1937 	__le16 tavg[CXT_FLCTRL_MAX]; /* avg try BT-Slot-TDD/BT-slot-FDD time */
1938 	__le16 tmax[CXT_FLCTRL_MAX]; /* max try BT-Slot-TDD/BT-slot-FDD time */
1939 } __packed;
1940 
1941 struct rtw89_btc_fbtc_cycle_time_info {
1942 	__le16 tavg[CXT_MAX]; /* avg wl/bt cycle time */
1943 	__le16 tmax[CXT_MAX]; /* max wl/bt cycle time */
1944 	__le16 tmaxdiff[CXT_MAX]; /* max wl-wl bt-bt cycle diff time */
1945 } __packed;
1946 
1947 struct rtw89_btc_fbtc_cycle_time_info_v5 {
1948 	__le16 tavg[CXT_MAX]; /* avg wl/bt cycle time */
1949 	__le16 tmax[CXT_MAX]; /* max wl/bt cycle time */
1950 } __packed;
1951 
1952 struct rtw89_btc_fbtc_a2dp_trx_stat {
1953 	u8 empty_cnt;
1954 	u8 retry_cnt;
1955 	u8 tx_rate;
1956 	u8 tx_cnt;
1957 	u8 ack_cnt;
1958 	u8 nack_cnt;
1959 	u8 rsvd1;
1960 	u8 rsvd2;
1961 } __packed;
1962 
1963 struct rtw89_btc_fbtc_a2dp_trx_stat_v4 {
1964 	u8 empty_cnt;
1965 	u8 retry_cnt;
1966 	u8 tx_rate;
1967 	u8 tx_cnt;
1968 	u8 ack_cnt;
1969 	u8 nack_cnt;
1970 	u8 no_empty_cnt;
1971 	u8 rsvd;
1972 } __packed;
1973 
1974 struct rtw89_btc_fbtc_cycle_a2dp_empty_info {
1975 	__le16 cnt; /* a2dp empty cnt */
1976 	__le16 cnt_timeout; /* a2dp empty timeout cnt*/
1977 	__le16 tavg; /* avg a2dp empty time */
1978 	__le16 tmax; /* max a2dp empty time */
1979 } __packed;
1980 
1981 struct rtw89_btc_fbtc_cycle_leak_info {
1982 	__le32 cnt_rximr; /* the rximr occur at leak slot  */
1983 	__le16 tavg; /* avg leak-slot time */
1984 	__le16 tmax; /* max leak-slot time */
1985 } __packed;
1986 
1987 #define RTW89_BTC_FDDT_PHASE_CYCLE GENMASK(9, 0)
1988 #define RTW89_BTC_FDDT_TRAIN_STEP GENMASK(15, 10)
1989 
1990 struct rtw89_btc_fbtc_cycle_fddt_info {
1991 	__le16 train_cycle;
1992 	__le16 tp;
1993 
1994 	s8 tx_power; /* absolute Tx power (dBm), 0xff-> no BTC control */
1995 	s8 bt_tx_power; /* decrease Tx power (dB) */
1996 	s8 bt_rx_gain;  /* LNA constrain level */
1997 	u8 no_empty_cnt;
1998 
1999 	u8 rssi; /* [7:4] -> bt_rssi_level, [3:0]-> wl_rssi_level */
2000 	u8 cn; /* condition_num */
2001 	u8 train_status; /* [7:4]-> train-state, [3:0]-> train-phase */
2002 	u8 train_result; /* refer to enum btc_fddt_check_map */
2003 } __packed;
2004 
2005 #define RTW89_BTC_FDDT_CELL_TRAIN_STATE GENMASK(3, 0)
2006 #define RTW89_BTC_FDDT_CELL_TRAIN_PHASE GENMASK(7, 4)
2007 
2008 struct rtw89_btc_fbtc_cycle_fddt_info_v5 {
2009 	__le16 train_cycle;
2010 	__le16 tp;
2011 
2012 	s8 tx_power; /* absolute Tx power (dBm), 0xff-> no BTC control */
2013 	s8 bt_tx_power; /* decrease Tx power (dB) */
2014 	s8 bt_rx_gain;  /* LNA constrain level */
2015 	u8 no_empty_cnt;
2016 
2017 	u8 rssi; /* [7:4] -> bt_rssi_level, [3:0]-> wl_rssi_level */
2018 	u8 cn; /* condition_num */
2019 	u8 train_status; /* [7:4]-> train-state, [3:0]-> train-phase */
2020 	u8 train_result; /* refer to enum btc_fddt_check_map */
2021 } __packed;
2022 
2023 struct rtw89_btc_fbtc_fddt_cell_status {
2024 	s8 wl_tx_pwr;
2025 	s8 bt_tx_pwr;
2026 	s8 bt_rx_gain;
2027 	u8 state_phase; /* [0:3] train state, [4:7] train phase */
2028 } __packed;
2029 
2030 struct rtw89_btc_fbtc_fddt_cell_status_v5 {
2031 	s8 wl_tx_pwr;
2032 	s8 bt_tx_pwr;
2033 	s8 bt_rx_gain;
2034 } __packed;
2035 
2036 struct rtw89_btc_fbtc_cysta_v3 { /* statistics for cycles */
2037 	u8 fver;
2038 	u8 rsvd;
2039 	__le16 cycles; /* total cycle number */
2040 	__le16 slot_step_time[BTC_CYCLE_SLOT_MAX];
2041 	struct rtw89_btc_fbtc_cycle_time_info cycle_time;
2042 	struct rtw89_btc_fbtc_fdd_try_info fdd_try;
2043 	struct rtw89_btc_fbtc_cycle_a2dp_empty_info a2dp_ept;
2044 	struct rtw89_btc_fbtc_a2dp_trx_stat a2dp_trx[BTC_CYCLE_SLOT_MAX];
2045 	struct rtw89_btc_fbtc_cycle_leak_info leak_slot;
2046 	__le32 slot_cnt[CXST_MAX]; /* slot count */
2047 	__le32 bcn_cnt[CXBCN_MAX];
2048 	__le32 collision_cnt; /* counter for event/timer occur at the same time */
2049 	__le32 skip_cnt;
2050 	__le32 except_cnt;
2051 	__le32 except_map;
2052 } __packed;
2053 
2054 #define FDD_TRAIN_WL_DIRECTION 2
2055 #define FDD_TRAIN_WL_RSSI_LEVEL 5
2056 #define FDD_TRAIN_BT_RSSI_LEVEL 5
2057 
2058 struct rtw89_btc_fbtc_cysta_v4 { /* statistics for cycles */
2059 	u8 fver;
2060 	u8 rsvd;
2061 	u8 collision_cnt; /* counter for event/timer occur at the same time */
2062 	u8 except_cnt;
2063 
2064 	__le16 skip_cnt;
2065 	__le16 cycles; /* total cycle number */
2066 
2067 	__le16 slot_step_time[BTC_CYCLE_SLOT_MAX]; /* record the wl/bt slot time */
2068 	__le16 slot_cnt[CXST_MAX]; /* slot count */
2069 	__le16 bcn_cnt[CXBCN_MAX];
2070 	struct rtw89_btc_fbtc_cycle_time_info cycle_time;
2071 	struct rtw89_btc_fbtc_cycle_leak_info leak_slot;
2072 	struct rtw89_btc_fbtc_cycle_a2dp_empty_info a2dp_ept;
2073 	struct rtw89_btc_fbtc_a2dp_trx_stat_v4 a2dp_trx[BTC_CYCLE_SLOT_MAX];
2074 	struct rtw89_btc_fbtc_cycle_fddt_info fddt_trx[BTC_CYCLE_SLOT_MAX];
2075 	struct rtw89_btc_fbtc_fddt_cell_status fddt_cells[FDD_TRAIN_WL_DIRECTION]
2076 							 [FDD_TRAIN_WL_RSSI_LEVEL]
2077 							 [FDD_TRAIN_BT_RSSI_LEVEL];
2078 	__le32 except_map;
2079 } __packed;
2080 
2081 struct rtw89_btc_fbtc_cysta_v5 { /* statistics for cycles */
2082 	u8 fver;
2083 	u8 rsvd;
2084 	u8 collision_cnt; /* counter for event/timer occur at the same time */
2085 	u8 except_cnt;
2086 	u8 wl_rx_err_ratio[BTC_CYCLE_SLOT_MAX];
2087 
2088 	__le16 skip_cnt;
2089 	__le16 cycles; /* total cycle number */
2090 
2091 	__le16 slot_step_time[BTC_CYCLE_SLOT_MAX]; /* record the wl/bt slot time */
2092 	__le16 slot_cnt[CXST_MAX]; /* slot count */
2093 	__le16 bcn_cnt[CXBCN_MAX];
2094 	struct rtw89_btc_fbtc_cycle_time_info_v5 cycle_time;
2095 	struct rtw89_btc_fbtc_cycle_leak_info leak_slot;
2096 	struct rtw89_btc_fbtc_cycle_a2dp_empty_info a2dp_ept;
2097 	struct rtw89_btc_fbtc_a2dp_trx_stat_v4 a2dp_trx[BTC_CYCLE_SLOT_MAX];
2098 	struct rtw89_btc_fbtc_cycle_fddt_info_v5 fddt_trx[BTC_CYCLE_SLOT_MAX];
2099 	struct rtw89_btc_fbtc_fddt_cell_status_v5 fddt_cells[FDD_TRAIN_WL_DIRECTION]
2100 							    [FDD_TRAIN_WL_RSSI_LEVEL]
2101 							    [FDD_TRAIN_BT_RSSI_LEVEL];
2102 	__le32 except_map;
2103 } __packed;
2104 
2105 union rtw89_btc_fbtc_cysta_info {
2106 	struct rtw89_btc_fbtc_cysta_v2 v2;
2107 	struct rtw89_btc_fbtc_cysta_v3 v3;
2108 	struct rtw89_btc_fbtc_cysta_v4 v4;
2109 	struct rtw89_btc_fbtc_cysta_v5 v5;
2110 };
2111 
2112 struct rtw89_btc_fbtc_cynullsta_v1 { /* cycle null statistics */
2113 	u8 fver; /* btc_ver::fcxnullsta */
2114 	u8 rsvd;
2115 	__le16 rsvd2;
2116 	__le32 max_t[2]; /* max_t for 0:null0/1:null1 */
2117 	__le32 avg_t[2]; /* avg_t for 0:null0/1:null1 */
2118 	__le32 result[2][4]; /* 0:fail, 1:ok, 2:on_time, 3:retry */
2119 } __packed;
2120 
2121 struct rtw89_btc_fbtc_cynullsta_v2 { /* cycle null statistics */
2122 	u8 fver; /* btc_ver::fcxnullsta */
2123 	u8 rsvd;
2124 	__le16 rsvd2;
2125 	__le32 max_t[2]; /* max_t for 0:null0/1:null1 */
2126 	__le32 avg_t[2]; /* avg_t for 0:null0/1:null1 */
2127 	__le32 result[2][5]; /* 0:fail, 1:ok, 2:on_time, 3:retry, 4:tx */
2128 } __packed;
2129 
2130 union rtw89_btc_fbtc_cynullsta_info {
2131 	struct rtw89_btc_fbtc_cynullsta_v1 v1; /* info from fw */
2132 	struct rtw89_btc_fbtc_cynullsta_v2 v2;
2133 };
2134 
2135 struct rtw89_btc_fbtc_btver {
2136 	u8 fver; /* btc_ver::fcxbtver */
2137 	u8 rsvd;
2138 	__le16 rsvd2;
2139 	__le32 coex_ver; /*bit[15:8]->shared, bit[7:0]->non-shared */
2140 	__le32 fw_ver;
2141 	__le32 feature;
2142 } __packed;
2143 
2144 struct rtw89_btc_fbtc_btafh {
2145 	u8 fver; /* btc_ver::fcxbtafh */
2146 	u8 rsvd;
2147 	__le16 rsvd2;
2148 	u8 afh_l[4]; /*bit0:2402, bit1: 2403.... bit31:2433 */
2149 	u8 afh_m[4]; /*bit0:2434, bit1: 2435.... bit31:2465 */
2150 	u8 afh_h[4]; /*bit0:2466, bit1:2467......bit14:2480 */
2151 } __packed;
2152 
2153 struct rtw89_btc_fbtc_btafh_v2 {
2154 	u8 fver; /* btc_ver::fcxbtafh */
2155 	u8 rsvd;
2156 	u8 rsvd2;
2157 	u8 map_type;
2158 	u8 afh_l[4];
2159 	u8 afh_m[4];
2160 	u8 afh_h[4];
2161 	u8 afh_le_a[4];
2162 	u8 afh_le_b[4];
2163 } __packed;
2164 
2165 struct rtw89_btc_fbtc_btdevinfo {
2166 	u8 fver; /* btc_ver::fcxbtdevinfo */
2167 	u8 rsvd;
2168 	__le16 vendor_id;
2169 	__le32 dev_name; /* only 24 bits valid */
2170 	__le32 flush_time;
2171 } __packed;
2172 
2173 #define RTW89_BTC_WL_DEF_TX_PWR GENMASK(7, 0)
2174 struct rtw89_btc_rf_trx_para {
2175 	u32 wl_tx_power; /* absolute Tx power (dBm), 0xff-> no BTC control */
2176 	u32 wl_rx_gain;  /* rx gain table index (TBD.) */
2177 	u8 bt_tx_power; /* decrease Tx power (dB) */
2178 	u8 bt_rx_gain;  /* LNA constrain level */
2179 };
2180 
2181 struct rtw89_btc_trx_info {
2182 	u8 tx_lvl;
2183 	u8 rx_lvl;
2184 	u8 wl_rssi;
2185 	u8 bt_rssi;
2186 
2187 	s8 tx_power; /* absolute Tx power (dBm), 0xff-> no BTC control */
2188 	s8 rx_gain;  /* rx gain table index (TBD.) */
2189 	s8 bt_tx_power; /* decrease Tx power (dB) */
2190 	s8 bt_rx_gain;  /* LNA constrain level */
2191 
2192 	u8 cn; /* condition_num */
2193 	s8 nhm;
2194 	u8 bt_profile;
2195 	u8 rsvd2;
2196 
2197 	u16 tx_rate;
2198 	u16 rx_rate;
2199 
2200 	u32 tx_tp;
2201 	u32 rx_tp;
2202 	u32 rx_err_ratio;
2203 };
2204 
2205 struct rtw89_btc_dm {
2206 	struct rtw89_btc_fbtc_slot slot[CXST_MAX];
2207 	struct rtw89_btc_fbtc_slot slot_now[CXST_MAX];
2208 	struct rtw89_btc_fbtc_tdma tdma;
2209 	struct rtw89_btc_fbtc_tdma tdma_now;
2210 	struct rtw89_mac_ax_coex_gnt gnt;
2211 	struct rtw89_btc_init_info init_info; /* pass to wl_fw if offload */
2212 	struct rtw89_btc_rf_trx_para rf_trx_para;
2213 	struct rtw89_btc_wl_tx_limit_para wl_tx_limit;
2214 	struct rtw89_btc_dm_step dm_step;
2215 	struct rtw89_btc_wl_scc_ctrl wl_scc;
2216 	struct rtw89_btc_trx_info trx_info;
2217 	union rtw89_btc_dm_error_map error;
2218 	u32 cnt_dm[BTC_DCNT_NUM];
2219 	u32 cnt_notify[BTC_NCNT_NUM];
2220 
2221 	u32 update_slot_map;
2222 	u32 set_ant_path;
2223 
2224 	u32 wl_only: 1;
2225 	u32 wl_fw_cx_offload: 1;
2226 	u32 freerun: 1;
2227 	u32 fddt_train: 1;
2228 	u32 wl_ps_ctrl: 2;
2229 	u32 wl_mimo_ps: 1;
2230 	u32 leak_ap: 1;
2231 	u32 noisy_level: 3;
2232 	u32 coex_info_map: 8;
2233 	u32 bt_only: 1;
2234 	u32 wl_btg_rx: 1;
2235 	u32 trx_para_level: 8;
2236 	u32 wl_stb_chg: 1;
2237 	u32 pta_owner: 1;
2238 	u32 tdma_instant_excute: 1;
2239 
2240 	u16 slot_dur[CXST_MAX];
2241 
2242 	u8 run_reason;
2243 	u8 run_action;
2244 
2245 	u8 wl_lna2: 1;
2246 };
2247 
2248 struct rtw89_btc_ctrl {
2249 	u32 manual: 1;
2250 	u32 igno_bt: 1;
2251 	u32 always_freerun: 1;
2252 	u32 trace_step: 16;
2253 	u32 rsvd: 12;
2254 };
2255 
2256 struct rtw89_btc_dbg {
2257 	/* cmd "rb" */
2258 	bool rb_done;
2259 	u32 rb_val;
2260 };
2261 
2262 enum rtw89_btc_btf_fw_event {
2263 	BTF_EVNT_RPT = 0,
2264 	BTF_EVNT_BT_INFO = 1,
2265 	BTF_EVNT_BT_SCBD = 2,
2266 	BTF_EVNT_BT_REG = 3,
2267 	BTF_EVNT_CX_RUNINFO = 4,
2268 	BTF_EVNT_BT_PSD = 5,
2269 	BTF_EVNT_BUF_OVERFLOW,
2270 	BTF_EVNT_C2H_LOOPBACK,
2271 	BTF_EVNT_MAX,
2272 };
2273 
2274 enum btf_fw_event_report {
2275 	BTC_RPT_TYPE_CTRL = 0x0,
2276 	BTC_RPT_TYPE_TDMA,
2277 	BTC_RPT_TYPE_SLOT,
2278 	BTC_RPT_TYPE_CYSTA,
2279 	BTC_RPT_TYPE_STEP,
2280 	BTC_RPT_TYPE_NULLSTA,
2281 	BTC_RPT_TYPE_MREG,
2282 	BTC_RPT_TYPE_GPIO_DBG,
2283 	BTC_RPT_TYPE_BT_VER,
2284 	BTC_RPT_TYPE_BT_SCAN,
2285 	BTC_RPT_TYPE_BT_AFH,
2286 	BTC_RPT_TYPE_BT_DEVICE,
2287 	BTC_RPT_TYPE_TEST,
2288 	BTC_RPT_TYPE_MAX = 31
2289 };
2290 
2291 enum rtw_btc_btf_reg_type {
2292 	REG_MAC = 0x0,
2293 	REG_BB = 0x1,
2294 	REG_RF = 0x2,
2295 	REG_BT_RF = 0x3,
2296 	REG_BT_MODEM = 0x4,
2297 	REG_BT_BLUEWIZE = 0x5,
2298 	REG_BT_VENDOR = 0x6,
2299 	REG_BT_LE = 0x7,
2300 	REG_MAX_TYPE,
2301 };
2302 
2303 struct rtw89_btc_rpt_cmn_info {
2304 	u32 rx_cnt;
2305 	u32 rx_len;
2306 	u32 req_len; /* expected rsp len */
2307 	u8 req_fver; /* expected rsp fver */
2308 	u8 rsp_fver; /* fver from fw */
2309 	u8 valid;
2310 } __packed;
2311 
2312 union rtw89_btc_fbtc_btafh_info {
2313 	struct rtw89_btc_fbtc_btafh v1;
2314 	struct rtw89_btc_fbtc_btafh_v2 v2;
2315 };
2316 
2317 struct rtw89_btc_report_ctrl_state {
2318 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2319 	union rtw89_btc_fbtc_rpt_ctrl_ver_info finfo;
2320 };
2321 
2322 struct rtw89_btc_rpt_fbtc_tdma {
2323 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2324 	union rtw89_btc_fbtc_tdma_le32 finfo;
2325 };
2326 
2327 struct rtw89_btc_rpt_fbtc_slots {
2328 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2329 	struct rtw89_btc_fbtc_slots finfo; /* info from fw */
2330 };
2331 
2332 struct rtw89_btc_rpt_fbtc_cysta {
2333 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2334 	union rtw89_btc_fbtc_cysta_info finfo;
2335 };
2336 
2337 struct rtw89_btc_rpt_fbtc_step {
2338 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2339 	union rtw89_btc_fbtc_steps_info finfo; /* info from fw */
2340 };
2341 
2342 struct rtw89_btc_rpt_fbtc_nullsta {
2343 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2344 	union rtw89_btc_fbtc_cynullsta_info finfo;
2345 };
2346 
2347 struct rtw89_btc_rpt_fbtc_mreg {
2348 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2349 	union rtw89_btc_fbtc_mreg_val finfo; /* info from fw */
2350 };
2351 
2352 struct rtw89_btc_rpt_fbtc_gpio_dbg {
2353 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2354 	struct rtw89_btc_fbtc_gpio_dbg finfo; /* info from fw */
2355 };
2356 
2357 struct rtw89_btc_rpt_fbtc_btver {
2358 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2359 	struct rtw89_btc_fbtc_btver finfo; /* info from fw */
2360 };
2361 
2362 struct rtw89_btc_rpt_fbtc_btscan {
2363 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2364 	union rtw89_btc_fbtc_btscan finfo; /* info from fw */
2365 };
2366 
2367 struct rtw89_btc_rpt_fbtc_btafh {
2368 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2369 	union rtw89_btc_fbtc_btafh_info finfo;
2370 };
2371 
2372 struct rtw89_btc_rpt_fbtc_btdev {
2373 	struct rtw89_btc_rpt_cmn_info cinfo; /* common info, by driver */
2374 	struct rtw89_btc_fbtc_btdevinfo finfo; /* info from fw */
2375 };
2376 
2377 enum rtw89_btc_btfre_type {
2378 	BTFRE_INVALID_INPUT = 0x0, /* invalid input parameters */
2379 	BTFRE_UNDEF_TYPE,
2380 	BTFRE_EXCEPTION,
2381 	BTFRE_MAX,
2382 };
2383 
2384 struct rtw89_btc_btf_fwinfo {
2385 	u32 cnt_c2h;
2386 	u32 cnt_h2c;
2387 	u32 cnt_h2c_fail;
2388 	u32 event[BTF_EVNT_MAX];
2389 
2390 	u32 err[BTFRE_MAX];
2391 	u32 len_mismch;
2392 	u32 fver_mismch;
2393 	u32 rpt_en_map;
2394 
2395 	struct rtw89_btc_report_ctrl_state rpt_ctrl;
2396 	struct rtw89_btc_rpt_fbtc_tdma rpt_fbtc_tdma;
2397 	struct rtw89_btc_rpt_fbtc_slots rpt_fbtc_slots;
2398 	struct rtw89_btc_rpt_fbtc_cysta rpt_fbtc_cysta;
2399 	struct rtw89_btc_rpt_fbtc_step rpt_fbtc_step;
2400 	struct rtw89_btc_rpt_fbtc_nullsta rpt_fbtc_nullsta;
2401 	struct rtw89_btc_rpt_fbtc_mreg rpt_fbtc_mregval;
2402 	struct rtw89_btc_rpt_fbtc_gpio_dbg rpt_fbtc_gpio_dbg;
2403 	struct rtw89_btc_rpt_fbtc_btver rpt_fbtc_btver;
2404 	struct rtw89_btc_rpt_fbtc_btscan rpt_fbtc_btscan;
2405 	struct rtw89_btc_rpt_fbtc_btafh rpt_fbtc_btafh;
2406 	struct rtw89_btc_rpt_fbtc_btdev rpt_fbtc_btdev;
2407 };
2408 
2409 struct rtw89_btc_ver {
2410 	enum rtw89_core_chip_id chip_id;
2411 	u32 fw_ver_code;
2412 
2413 	u8 fcxbtcrpt;
2414 	u8 fcxtdma;
2415 	u8 fcxslots;
2416 	u8 fcxcysta;
2417 	u8 fcxstep;
2418 	u8 fcxnullsta;
2419 	u8 fcxmreg;
2420 	u8 fcxgpiodbg;
2421 	u8 fcxbtver;
2422 	u8 fcxbtscan;
2423 	u8 fcxbtafh;
2424 	u8 fcxbtdevinfo;
2425 	u8 fwlrole;
2426 	u8 frptmap;
2427 	u8 fcxctrl;
2428 
2429 	u16 info_buf;
2430 	u8 max_role_num;
2431 };
2432 
2433 #define RTW89_BTC_POLICY_MAXLEN 512
2434 
2435 struct rtw89_btc {
2436 	const struct rtw89_btc_ver *ver;
2437 
2438 	struct rtw89_btc_cx cx;
2439 	struct rtw89_btc_dm dm;
2440 	struct rtw89_btc_ctrl ctrl;
2441 	struct rtw89_btc_module mdinfo;
2442 	struct rtw89_btc_btf_fwinfo fwinfo;
2443 	struct rtw89_btc_dbg dbg;
2444 
2445 	struct work_struct eapol_notify_work;
2446 	struct work_struct arp_notify_work;
2447 	struct work_struct dhcp_notify_work;
2448 	struct work_struct icmp_notify_work;
2449 
2450 	u32 bt_req_len;
2451 
2452 	u8 policy[RTW89_BTC_POLICY_MAXLEN];
2453 	u16 policy_len;
2454 	u16 policy_type;
2455 	bool bt_req_en;
2456 	bool update_policy_force;
2457 	bool lps;
2458 };
2459 
2460 enum rtw89_ra_mode {
2461 	RTW89_RA_MODE_CCK = BIT(0),
2462 	RTW89_RA_MODE_OFDM = BIT(1),
2463 	RTW89_RA_MODE_HT = BIT(2),
2464 	RTW89_RA_MODE_VHT = BIT(3),
2465 	RTW89_RA_MODE_HE = BIT(4),
2466 };
2467 
2468 enum rtw89_ra_report_mode {
2469 	RTW89_RA_RPT_MODE_LEGACY,
2470 	RTW89_RA_RPT_MODE_HT,
2471 	RTW89_RA_RPT_MODE_VHT,
2472 	RTW89_RA_RPT_MODE_HE,
2473 };
2474 
2475 enum rtw89_dig_noisy_level {
2476 	RTW89_DIG_NOISY_LEVEL0 = -1,
2477 	RTW89_DIG_NOISY_LEVEL1 = 0,
2478 	RTW89_DIG_NOISY_LEVEL2 = 1,
2479 	RTW89_DIG_NOISY_LEVEL3 = 2,
2480 	RTW89_DIG_NOISY_LEVEL_MAX = 3,
2481 };
2482 
2483 enum rtw89_gi_ltf {
2484 	RTW89_GILTF_LGI_4XHE32 = 0,
2485 	RTW89_GILTF_SGI_4XHE08 = 1,
2486 	RTW89_GILTF_2XHE16 = 2,
2487 	RTW89_GILTF_2XHE08 = 3,
2488 	RTW89_GILTF_1XHE16 = 4,
2489 	RTW89_GILTF_1XHE08 = 5,
2490 	RTW89_GILTF_MAX
2491 };
2492 
2493 enum rtw89_rx_frame_type {
2494 	RTW89_RX_TYPE_MGNT = 0,
2495 	RTW89_RX_TYPE_CTRL = 1,
2496 	RTW89_RX_TYPE_DATA = 2,
2497 	RTW89_RX_TYPE_RSVD = 3,
2498 };
2499 
2500 struct rtw89_ra_info {
2501 	u8 is_dis_ra:1;
2502 	/* Bit0 : CCK
2503 	 * Bit1 : OFDM
2504 	 * Bit2 : HT
2505 	 * Bit3 : VHT
2506 	 * Bit4 : HE
2507 	 */
2508 	u8 mode_ctrl:5;
2509 	u8 bw_cap:2;
2510 	u8 macid;
2511 	u8 dcm_cap:1;
2512 	u8 er_cap:1;
2513 	u8 init_rate_lv:2;
2514 	u8 upd_all:1;
2515 	u8 en_sgi:1;
2516 	u8 ldpc_cap:1;
2517 	u8 stbc_cap:1;
2518 	u8 ss_num:3;
2519 	u8 giltf:3;
2520 	u8 upd_bw_nss_mask:1;
2521 	u8 upd_mask:1;
2522 	u64 ra_mask; /* 63 bits ra_mask + 1 bit CSI ctrl */
2523 	/* BFee CSI */
2524 	u8 band_num;
2525 	u8 ra_csi_rate_en:1;
2526 	u8 fixed_csi_rate_en:1;
2527 	u8 cr_tbl_sel:1;
2528 	u8 fix_giltf_en:1;
2529 	u8 fix_giltf:3;
2530 	u8 rsvd2:1;
2531 	u8 csi_mcs_ss_idx;
2532 	u8 csi_mode:2;
2533 	u8 csi_gi_ltf:3;
2534 	u8 csi_bw:3;
2535 };
2536 
2537 #define RTW89_PPDU_MAX_USR 4
2538 #define RTW89_PPDU_MAC_INFO_USR_SIZE 4
2539 #define RTW89_PPDU_MAC_INFO_SIZE 8
2540 #define RTW89_PPDU_MAC_RX_CNT_SIZE 96
2541 
2542 #define RTW89_MAX_RX_AGG_NUM 64
2543 #define RTW89_MAX_TX_AGG_NUM 128
2544 
2545 struct rtw89_ampdu_params {
2546 	u16 agg_num;
2547 	bool amsdu;
2548 };
2549 
2550 struct rtw89_ra_report {
2551 	struct rate_info txrate;
2552 	u32 bit_rate;
2553 	u16 hw_rate;
2554 	bool might_fallback_legacy;
2555 };
2556 
2557 DECLARE_EWMA(rssi, 10, 16);
2558 DECLARE_EWMA(evm, 10, 16);
2559 DECLARE_EWMA(snr, 10, 16);
2560 
2561 struct rtw89_ba_cam_entry {
2562 	struct list_head list;
2563 	u8 tid;
2564 };
2565 
2566 #define RTW89_MAX_ADDR_CAM_NUM		128
2567 #define RTW89_MAX_BSSID_CAM_NUM		20
2568 #define RTW89_MAX_SEC_CAM_NUM		128
2569 #define RTW89_MAX_BA_CAM_NUM		8
2570 #define RTW89_SEC_CAM_IN_ADDR_CAM	7
2571 
2572 struct rtw89_addr_cam_entry {
2573 	u8 addr_cam_idx;
2574 	u8 offset;
2575 	u8 len;
2576 	u8 valid	: 1;
2577 	u8 addr_mask	: 6;
2578 	u8 wapi		: 1;
2579 	u8 mask_sel	: 2;
2580 	u8 bssid_cam_idx: 6;
2581 
2582 	u8 sec_ent_mode;
2583 	DECLARE_BITMAP(sec_cam_map, RTW89_SEC_CAM_IN_ADDR_CAM);
2584 	u8 sec_ent_keyid[RTW89_SEC_CAM_IN_ADDR_CAM];
2585 	u8 sec_ent[RTW89_SEC_CAM_IN_ADDR_CAM];
2586 	struct rtw89_sec_cam_entry *sec_entries[RTW89_SEC_CAM_IN_ADDR_CAM];
2587 };
2588 
2589 struct rtw89_bssid_cam_entry {
2590 	u8 bssid[ETH_ALEN];
2591 	u8 phy_idx;
2592 	u8 bssid_cam_idx;
2593 	u8 offset;
2594 	u8 len;
2595 	u8 valid : 1;
2596 	u8 num;
2597 };
2598 
2599 struct rtw89_sec_cam_entry {
2600 	u8 sec_cam_idx;
2601 	u8 offset;
2602 	u8 len;
2603 	u8 type : 4;
2604 	u8 ext_key : 1;
2605 	u8 spp_mode : 1;
2606 	/* 256 bits */
2607 	u8 key[32];
2608 };
2609 
2610 struct rtw89_sta {
2611 	u8 mac_id;
2612 	bool disassoc;
2613 	bool er_cap;
2614 	struct rtw89_dev *rtwdev;
2615 	struct rtw89_vif *rtwvif;
2616 	struct rtw89_ra_info ra;
2617 	struct rtw89_ra_report ra_report;
2618 	int max_agg_wait;
2619 	u8 prev_rssi;
2620 	struct ewma_rssi avg_rssi;
2621 	struct ewma_rssi rssi[RF_PATH_MAX];
2622 	struct ewma_snr avg_snr;
2623 	struct ewma_evm evm_min[RF_PATH_MAX];
2624 	struct ewma_evm evm_max[RF_PATH_MAX];
2625 	struct rtw89_ampdu_params ampdu_params[IEEE80211_NUM_TIDS];
2626 	struct ieee80211_rx_status rx_status;
2627 	u16 rx_hw_rate;
2628 	__le32 htc_template;
2629 	struct rtw89_addr_cam_entry addr_cam; /* AP mode or TDLS peer only */
2630 	struct rtw89_bssid_cam_entry bssid_cam; /* TDLS peer only */
2631 	struct list_head ba_cam_list;
2632 	struct sk_buff_head roc_queue;
2633 
2634 	bool use_cfg_mask;
2635 	struct cfg80211_bitrate_mask mask;
2636 
2637 	bool cctl_tx_time;
2638 	u32 ampdu_max_time:4;
2639 	bool cctl_tx_retry_limit;
2640 	u32 data_tx_cnt_lmt:6;
2641 };
2642 
2643 struct rtw89_efuse {
2644 	bool valid;
2645 	bool power_k_valid;
2646 	u8 xtal_cap;
2647 	u8 addr[ETH_ALEN];
2648 	u8 rfe_type;
2649 	char country_code[2];
2650 };
2651 
2652 struct rtw89_phy_rate_pattern {
2653 	u64 ra_mask;
2654 	u16 rate;
2655 	u8 ra_mode;
2656 	bool enable;
2657 };
2658 
2659 struct rtw89_tx_wait_info {
2660 	struct rcu_head rcu_head;
2661 	struct completion completion;
2662 	bool tx_done;
2663 };
2664 
2665 struct rtw89_tx_skb_data {
2666 	struct rtw89_tx_wait_info __rcu *wait;
2667 	u8 hci_priv[];
2668 };
2669 
2670 #define RTW89_ROC_IDLE_TIMEOUT 500
2671 #define RTW89_ROC_TX_TIMEOUT 30
2672 enum rtw89_roc_state {
2673 	RTW89_ROC_IDLE,
2674 	RTW89_ROC_NORMAL,
2675 	RTW89_ROC_MGMT,
2676 };
2677 
2678 struct rtw89_roc {
2679 	struct ieee80211_channel chan;
2680 	struct delayed_work roc_work;
2681 	enum ieee80211_roc_type type;
2682 	enum rtw89_roc_state state;
2683 	int duration;
2684 };
2685 
2686 #define RTW89_P2P_MAX_NOA_NUM 2
2687 
2688 struct rtw89_vif {
2689 	struct list_head list;
2690 	struct rtw89_dev *rtwdev;
2691 	struct rtw89_roc roc;
2692 	enum rtw89_sub_entity_idx sub_entity_idx;
2693 	enum rtw89_reg_6ghz_power reg_6ghz_power;
2694 
2695 	u8 mac_id;
2696 	u8 port;
2697 	u8 mac_addr[ETH_ALEN];
2698 	u8 bssid[ETH_ALEN];
2699 	u8 phy_idx;
2700 	u8 mac_idx;
2701 	u8 net_type;
2702 	u8 wifi_role;
2703 	u8 self_role;
2704 	u8 wmm;
2705 	u8 bcn_hit_cond;
2706 	u8 hit_rule;
2707 	u8 last_noa_nr;
2708 	bool offchan;
2709 	bool trigger;
2710 	bool lsig_txop;
2711 	u8 tgt_ind;
2712 	u8 frm_tgt_ind;
2713 	bool wowlan_pattern;
2714 	bool wowlan_uc;
2715 	bool wowlan_magic;
2716 	bool is_hesta;
2717 	bool last_a_ctrl;
2718 	bool dyn_tb_bedge_en;
2719 	u8 def_tri_idx;
2720 	u32 tdls_peer;
2721 	struct work_struct update_beacon_work;
2722 	struct rtw89_addr_cam_entry addr_cam;
2723 	struct rtw89_bssid_cam_entry bssid_cam;
2724 	struct ieee80211_tx_queue_params tx_params[IEEE80211_NUM_ACS];
2725 	struct rtw89_traffic_stats stats;
2726 	struct rtw89_phy_rate_pattern rate_pattern;
2727 	struct cfg80211_scan_request *scan_req;
2728 	struct ieee80211_scan_ies *scan_ies;
2729 	struct list_head general_pkt_list;
2730 };
2731 
2732 enum rtw89_lv1_rcvy_step {
2733 	RTW89_LV1_RCVY_STEP_1,
2734 	RTW89_LV1_RCVY_STEP_2,
2735 };
2736 
2737 struct rtw89_hci_ops {
2738 	int (*tx_write)(struct rtw89_dev *rtwdev, struct rtw89_core_tx_request *tx_req);
2739 	void (*tx_kick_off)(struct rtw89_dev *rtwdev, u8 txch);
2740 	void (*flush_queues)(struct rtw89_dev *rtwdev, u32 queues, bool drop);
2741 	void (*reset)(struct rtw89_dev *rtwdev);
2742 	int (*start)(struct rtw89_dev *rtwdev);
2743 	void (*stop)(struct rtw89_dev *rtwdev);
2744 	void (*pause)(struct rtw89_dev *rtwdev, bool pause);
2745 	void (*switch_mode)(struct rtw89_dev *rtwdev, bool low_power);
2746 	void (*recalc_int_mit)(struct rtw89_dev *rtwdev);
2747 
2748 	u8 (*read8)(struct rtw89_dev *rtwdev, u32 addr);
2749 	u16 (*read16)(struct rtw89_dev *rtwdev, u32 addr);
2750 	u32 (*read32)(struct rtw89_dev *rtwdev, u32 addr);
2751 	void (*write8)(struct rtw89_dev *rtwdev, u32 addr, u8 data);
2752 	void (*write16)(struct rtw89_dev *rtwdev, u32 addr, u16 data);
2753 	void (*write32)(struct rtw89_dev *rtwdev, u32 addr, u32 data);
2754 
2755 	int (*mac_pre_init)(struct rtw89_dev *rtwdev);
2756 	int (*mac_post_init)(struct rtw89_dev *rtwdev);
2757 	int (*deinit)(struct rtw89_dev *rtwdev);
2758 
2759 	u32 (*check_and_reclaim_tx_resource)(struct rtw89_dev *rtwdev, u8 txch);
2760 	int (*mac_lv1_rcvy)(struct rtw89_dev *rtwdev, enum rtw89_lv1_rcvy_step step);
2761 	void (*dump_err_status)(struct rtw89_dev *rtwdev);
2762 	int (*napi_poll)(struct napi_struct *napi, int budget);
2763 
2764 	/* Deal with locks inside recovery_start and recovery_complete callbacks
2765 	 * by hci instance, and handle things which need to consider under SER.
2766 	 * e.g. turn on/off interrupts except for the one for halt notification.
2767 	 */
2768 	void (*recovery_start)(struct rtw89_dev *rtwdev);
2769 	void (*recovery_complete)(struct rtw89_dev *rtwdev);
2770 
2771 	void (*ctrl_txdma_ch)(struct rtw89_dev *rtwdev, bool enable);
2772 	void (*ctrl_txdma_fw_ch)(struct rtw89_dev *rtwdev, bool enable);
2773 	void (*ctrl_trxhci)(struct rtw89_dev *rtwdev, bool enable);
2774 	int (*poll_txdma_ch)(struct rtw89_dev *rtwdev);
2775 	void (*clr_idx_all)(struct rtw89_dev *rtwdev);
2776 	void (*clear)(struct rtw89_dev *rtwdev, struct pci_dev *pdev);
2777 	void (*disable_intr)(struct rtw89_dev *rtwdev);
2778 	void (*enable_intr)(struct rtw89_dev *rtwdev);
2779 	int (*rst_bdram)(struct rtw89_dev *rtwdev);
2780 };
2781 
2782 struct rtw89_hci_info {
2783 	const struct rtw89_hci_ops *ops;
2784 	enum rtw89_hci_type type;
2785 	u32 rpwm_addr;
2786 	u32 cpwm_addr;
2787 	bool paused;
2788 };
2789 
2790 struct rtw89_chip_ops {
2791 	int (*enable_bb_rf)(struct rtw89_dev *rtwdev);
2792 	int (*disable_bb_rf)(struct rtw89_dev *rtwdev);
2793 	void (*bb_reset)(struct rtw89_dev *rtwdev,
2794 			 enum rtw89_phy_idx phy_idx);
2795 	void (*bb_sethw)(struct rtw89_dev *rtwdev);
2796 	u32 (*read_rf)(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
2797 		       u32 addr, u32 mask);
2798 	bool (*write_rf)(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
2799 			 u32 addr, u32 mask, u32 data);
2800 	void (*set_channel)(struct rtw89_dev *rtwdev,
2801 			    const struct rtw89_chan *chan,
2802 			    enum rtw89_mac_idx mac_idx,
2803 			    enum rtw89_phy_idx phy_idx);
2804 	void (*set_channel_help)(struct rtw89_dev *rtwdev, bool enter,
2805 				 struct rtw89_channel_help_params *p,
2806 				 const struct rtw89_chan *chan,
2807 				 enum rtw89_mac_idx mac_idx,
2808 				 enum rtw89_phy_idx phy_idx);
2809 	int (*read_efuse)(struct rtw89_dev *rtwdev, u8 *log_map);
2810 	int (*read_phycap)(struct rtw89_dev *rtwdev, u8 *phycap_map);
2811 	void (*fem_setup)(struct rtw89_dev *rtwdev);
2812 	void (*rfe_gpio)(struct rtw89_dev *rtwdev);
2813 	void (*rfk_init)(struct rtw89_dev *rtwdev);
2814 	void (*rfk_channel)(struct rtw89_dev *rtwdev);
2815 	void (*rfk_band_changed)(struct rtw89_dev *rtwdev,
2816 				 enum rtw89_phy_idx phy_idx);
2817 	void (*rfk_scan)(struct rtw89_dev *rtwdev, bool start);
2818 	void (*rfk_track)(struct rtw89_dev *rtwdev);
2819 	void (*power_trim)(struct rtw89_dev *rtwdev);
2820 	void (*set_txpwr)(struct rtw89_dev *rtwdev,
2821 			  const struct rtw89_chan *chan,
2822 			  enum rtw89_phy_idx phy_idx);
2823 	void (*set_txpwr_ctrl)(struct rtw89_dev *rtwdev,
2824 			       enum rtw89_phy_idx phy_idx);
2825 	int (*init_txpwr_unit)(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx);
2826 	u8 (*get_thermal)(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path);
2827 	void (*ctrl_btg)(struct rtw89_dev *rtwdev, bool btg);
2828 	void (*query_ppdu)(struct rtw89_dev *rtwdev,
2829 			   struct rtw89_rx_phy_ppdu *phy_ppdu,
2830 			   struct ieee80211_rx_status *status);
2831 	void (*bb_ctrl_btc_preagc)(struct rtw89_dev *rtwdev, bool bt_en);
2832 	void (*cfg_txrx_path)(struct rtw89_dev *rtwdev);
2833 	void (*set_txpwr_ul_tb_offset)(struct rtw89_dev *rtwdev,
2834 				       s8 pw_ofst, enum rtw89_mac_idx mac_idx);
2835 	int (*pwr_on_func)(struct rtw89_dev *rtwdev);
2836 	int (*pwr_off_func)(struct rtw89_dev *rtwdev);
2837 	void (*query_rxdesc)(struct rtw89_dev *rtwdev,
2838 			     struct rtw89_rx_desc_info *desc_info,
2839 			     u8 *data, u32 data_offset);
2840 	void (*fill_txdesc)(struct rtw89_dev *rtwdev,
2841 			    struct rtw89_tx_desc_info *desc_info,
2842 			    void *txdesc);
2843 	void (*fill_txdesc_fwcmd)(struct rtw89_dev *rtwdev,
2844 				  struct rtw89_tx_desc_info *desc_info,
2845 				  void *txdesc);
2846 	int (*cfg_ctrl_path)(struct rtw89_dev *rtwdev, bool wl);
2847 	int (*mac_cfg_gnt)(struct rtw89_dev *rtwdev,
2848 			   const struct rtw89_mac_ax_coex_gnt *gnt_cfg);
2849 	int (*stop_sch_tx)(struct rtw89_dev *rtwdev, u8 mac_idx,
2850 			   u32 *tx_en, enum rtw89_sch_tx_sel sel);
2851 	int (*resume_sch_tx)(struct rtw89_dev *rtwdev, u8 mac_idx, u32 tx_en);
2852 	int (*h2c_dctl_sec_cam)(struct rtw89_dev *rtwdev,
2853 				struct rtw89_vif *rtwvif,
2854 				struct rtw89_sta *rtwsta);
2855 
2856 	void (*btc_set_rfe)(struct rtw89_dev *rtwdev);
2857 	void (*btc_init_cfg)(struct rtw89_dev *rtwdev);
2858 	void (*btc_set_wl_pri)(struct rtw89_dev *rtwdev, u8 map, bool state);
2859 	void (*btc_set_wl_txpwr_ctrl)(struct rtw89_dev *rtwdev, u32 txpwr_val);
2860 	s8 (*btc_get_bt_rssi)(struct rtw89_dev *rtwdev, s8 val);
2861 	void (*btc_update_bt_cnt)(struct rtw89_dev *rtwdev);
2862 	void (*btc_wl_s1_standby)(struct rtw89_dev *rtwdev, bool state);
2863 	void (*btc_set_policy)(struct rtw89_dev *rtwdev, u16 policy_type);
2864 	void (*btc_set_wl_rx_gain)(struct rtw89_dev *rtwdev, u32 level);
2865 };
2866 
2867 enum rtw89_dma_ch {
2868 	RTW89_DMA_ACH0 = 0,
2869 	RTW89_DMA_ACH1 = 1,
2870 	RTW89_DMA_ACH2 = 2,
2871 	RTW89_DMA_ACH3 = 3,
2872 	RTW89_DMA_ACH4 = 4,
2873 	RTW89_DMA_ACH5 = 5,
2874 	RTW89_DMA_ACH6 = 6,
2875 	RTW89_DMA_ACH7 = 7,
2876 	RTW89_DMA_B0MG = 8,
2877 	RTW89_DMA_B0HI = 9,
2878 	RTW89_DMA_B1MG = 10,
2879 	RTW89_DMA_B1HI = 11,
2880 	RTW89_DMA_H2C = 12,
2881 	RTW89_DMA_CH_NUM = 13
2882 };
2883 
2884 enum rtw89_qta_mode {
2885 	RTW89_QTA_SCC,
2886 	RTW89_QTA_DLFW,
2887 	RTW89_QTA_WOW,
2888 
2889 	/* keep last */
2890 	RTW89_QTA_INVALID,
2891 };
2892 
2893 struct rtw89_hfc_ch_cfg {
2894 	u16 min;
2895 	u16 max;
2896 #define grp_0 0
2897 #define grp_1 1
2898 #define grp_num 2
2899 	u8 grp;
2900 };
2901 
2902 struct rtw89_hfc_ch_info {
2903 	u16 aval;
2904 	u16 used;
2905 };
2906 
2907 struct rtw89_hfc_pub_cfg {
2908 	u16 grp0;
2909 	u16 grp1;
2910 	u16 pub_max;
2911 	u16 wp_thrd;
2912 };
2913 
2914 struct rtw89_hfc_pub_info {
2915 	u16 g0_used;
2916 	u16 g1_used;
2917 	u16 g0_aval;
2918 	u16 g1_aval;
2919 	u16 pub_aval;
2920 	u16 wp_aval;
2921 };
2922 
2923 struct rtw89_hfc_prec_cfg {
2924 	u16 ch011_prec;
2925 	u16 h2c_prec;
2926 	u16 wp_ch07_prec;
2927 	u16 wp_ch811_prec;
2928 	u8 ch011_full_cond;
2929 	u8 h2c_full_cond;
2930 	u8 wp_ch07_full_cond;
2931 	u8 wp_ch811_full_cond;
2932 };
2933 
2934 struct rtw89_hfc_param {
2935 	bool en;
2936 	bool h2c_en;
2937 	u8 mode;
2938 	const struct rtw89_hfc_ch_cfg *ch_cfg;
2939 	struct rtw89_hfc_ch_info ch_info[RTW89_DMA_CH_NUM];
2940 	struct rtw89_hfc_pub_cfg pub_cfg;
2941 	struct rtw89_hfc_pub_info pub_info;
2942 	struct rtw89_hfc_prec_cfg prec_cfg;
2943 };
2944 
2945 struct rtw89_hfc_param_ini {
2946 	const struct rtw89_hfc_ch_cfg *ch_cfg;
2947 	const struct rtw89_hfc_pub_cfg *pub_cfg;
2948 	const struct rtw89_hfc_prec_cfg *prec_cfg;
2949 	u8 mode;
2950 };
2951 
2952 struct rtw89_dle_size {
2953 	u16 pge_size;
2954 	u16 lnk_pge_num;
2955 	u16 unlnk_pge_num;
2956 };
2957 
2958 struct rtw89_wde_quota {
2959 	u16 hif;
2960 	u16 wcpu;
2961 	u16 pkt_in;
2962 	u16 cpu_io;
2963 };
2964 
2965 struct rtw89_ple_quota {
2966 	u16 cma0_tx;
2967 	u16 cma1_tx;
2968 	u16 c2h;
2969 	u16 h2c;
2970 	u16 wcpu;
2971 	u16 mpdu_proc;
2972 	u16 cma0_dma;
2973 	u16 cma1_dma;
2974 	u16 bb_rpt;
2975 	u16 wd_rel;
2976 	u16 cpu_io;
2977 	u16 tx_rpt;
2978 };
2979 
2980 struct rtw89_dle_mem {
2981 	enum rtw89_qta_mode mode;
2982 	const struct rtw89_dle_size *wde_size;
2983 	const struct rtw89_dle_size *ple_size;
2984 	const struct rtw89_wde_quota *wde_min_qt;
2985 	const struct rtw89_wde_quota *wde_max_qt;
2986 	const struct rtw89_ple_quota *ple_min_qt;
2987 	const struct rtw89_ple_quota *ple_max_qt;
2988 };
2989 
2990 struct rtw89_reg_def {
2991 	u32 addr;
2992 	u32 mask;
2993 };
2994 
2995 struct rtw89_reg2_def {
2996 	u32 addr;
2997 	u32 data;
2998 };
2999 
3000 struct rtw89_reg3_def {
3001 	u32 addr;
3002 	u32 mask;
3003 	u32 data;
3004 };
3005 
3006 struct rtw89_reg5_def {
3007 	u8 flag; /* recognized by parsers */
3008 	u8 path;
3009 	u32 addr;
3010 	u32 mask;
3011 	u32 data;
3012 };
3013 
3014 struct rtw89_phy_table {
3015 	const struct rtw89_reg2_def *regs;
3016 	u32 n_regs;
3017 	enum rtw89_rf_path rf_path;
3018 	void (*config)(struct rtw89_dev *rtwdev, const struct rtw89_reg2_def *reg,
3019 		       enum rtw89_rf_path rf_path, void *data);
3020 };
3021 
3022 struct rtw89_txpwr_table {
3023 	const void *data;
3024 	u32 size;
3025 	void (*load)(struct rtw89_dev *rtwdev,
3026 		     const struct rtw89_txpwr_table *tbl);
3027 };
3028 
3029 struct rtw89_txpwr_rule_2ghz {
3030 	const s8 (*lmt)[RTW89_2G_BW_NUM][RTW89_NTX_NUM]
3031 		       [RTW89_RS_LMT_NUM][RTW89_BF_NUM]
3032 		       [RTW89_REGD_NUM][RTW89_2G_CH_NUM];
3033 	const s8 (*lmt_ru)[RTW89_RU_NUM][RTW89_NTX_NUM]
3034 			  [RTW89_REGD_NUM][RTW89_2G_CH_NUM];
3035 };
3036 
3037 struct rtw89_txpwr_rule_5ghz {
3038 	const s8 (*lmt)[RTW89_5G_BW_NUM][RTW89_NTX_NUM]
3039 		       [RTW89_RS_LMT_NUM][RTW89_BF_NUM]
3040 		       [RTW89_REGD_NUM][RTW89_5G_CH_NUM];
3041 	const s8 (*lmt_ru)[RTW89_RU_NUM][RTW89_NTX_NUM]
3042 			  [RTW89_REGD_NUM][RTW89_5G_CH_NUM];
3043 };
3044 
3045 struct rtw89_txpwr_rule_6ghz {
3046 	const s8 (*lmt)[RTW89_6G_BW_NUM][RTW89_NTX_NUM]
3047 		       [RTW89_RS_LMT_NUM][RTW89_BF_NUM]
3048 		       [RTW89_REGD_NUM][NUM_OF_RTW89_REG_6GHZ_POWER]
3049 		       [RTW89_6G_CH_NUM];
3050 	const s8 (*lmt_ru)[RTW89_RU_NUM][RTW89_NTX_NUM]
3051 			  [RTW89_REGD_NUM][NUM_OF_RTW89_REG_6GHZ_POWER]
3052 			  [RTW89_6G_CH_NUM];
3053 };
3054 
3055 struct rtw89_rfe_parms {
3056 	struct rtw89_txpwr_rule_2ghz rule_2ghz;
3057 	struct rtw89_txpwr_rule_5ghz rule_5ghz;
3058 	struct rtw89_txpwr_rule_6ghz rule_6ghz;
3059 };
3060 
3061 struct rtw89_rfe_parms_conf {
3062 	const struct rtw89_rfe_parms *rfe_parms;
3063 	u8 rfe_type;
3064 };
3065 
3066 struct rtw89_page_regs {
3067 	u32 hci_fc_ctrl;
3068 	u32 ch_page_ctrl;
3069 	u32 ach_page_ctrl;
3070 	u32 ach_page_info;
3071 	u32 pub_page_info3;
3072 	u32 pub_page_ctrl1;
3073 	u32 pub_page_ctrl2;
3074 	u32 pub_page_info1;
3075 	u32 pub_page_info2;
3076 	u32 wp_page_ctrl1;
3077 	u32 wp_page_ctrl2;
3078 	u32 wp_page_info1;
3079 };
3080 
3081 struct rtw89_imr_info {
3082 	u32 wdrls_imr_set;
3083 	u32 wsec_imr_reg;
3084 	u32 wsec_imr_set;
3085 	u32 mpdu_tx_imr_set;
3086 	u32 mpdu_rx_imr_set;
3087 	u32 sta_sch_imr_set;
3088 	u32 txpktctl_imr_b0_reg;
3089 	u32 txpktctl_imr_b0_clr;
3090 	u32 txpktctl_imr_b0_set;
3091 	u32 txpktctl_imr_b1_reg;
3092 	u32 txpktctl_imr_b1_clr;
3093 	u32 txpktctl_imr_b1_set;
3094 	u32 wde_imr_clr;
3095 	u32 wde_imr_set;
3096 	u32 ple_imr_clr;
3097 	u32 ple_imr_set;
3098 	u32 host_disp_imr_clr;
3099 	u32 host_disp_imr_set;
3100 	u32 cpu_disp_imr_clr;
3101 	u32 cpu_disp_imr_set;
3102 	u32 other_disp_imr_clr;
3103 	u32 other_disp_imr_set;
3104 	u32 bbrpt_com_err_imr_reg;
3105 	u32 bbrpt_chinfo_err_imr_reg;
3106 	u32 bbrpt_err_imr_set;
3107 	u32 bbrpt_dfs_err_imr_reg;
3108 	u32 ptcl_imr_clr;
3109 	u32 ptcl_imr_set;
3110 	u32 cdma_imr_0_reg;
3111 	u32 cdma_imr_0_clr;
3112 	u32 cdma_imr_0_set;
3113 	u32 cdma_imr_1_reg;
3114 	u32 cdma_imr_1_clr;
3115 	u32 cdma_imr_1_set;
3116 	u32 phy_intf_imr_reg;
3117 	u32 phy_intf_imr_clr;
3118 	u32 phy_intf_imr_set;
3119 	u32 rmac_imr_reg;
3120 	u32 rmac_imr_clr;
3121 	u32 rmac_imr_set;
3122 	u32 tmac_imr_reg;
3123 	u32 tmac_imr_clr;
3124 	u32 tmac_imr_set;
3125 };
3126 
3127 struct rtw89_xtal_info {
3128 	u32 xcap_reg;
3129 	u32 sc_xo_mask;
3130 	u32 sc_xi_mask;
3131 };
3132 
3133 struct rtw89_rrsr_cfgs {
3134 	struct rtw89_reg3_def ref_rate;
3135 	struct rtw89_reg3_def rsc;
3136 };
3137 
3138 struct rtw89_dig_regs {
3139 	u32 seg0_pd_reg;
3140 	u32 pd_lower_bound_mask;
3141 	u32 pd_spatial_reuse_en;
3142 	struct rtw89_reg_def p0_lna_init;
3143 	struct rtw89_reg_def p1_lna_init;
3144 	struct rtw89_reg_def p0_tia_init;
3145 	struct rtw89_reg_def p1_tia_init;
3146 	struct rtw89_reg_def p0_rxb_init;
3147 	struct rtw89_reg_def p1_rxb_init;
3148 	struct rtw89_reg_def p0_p20_pagcugc_en;
3149 	struct rtw89_reg_def p0_s20_pagcugc_en;
3150 	struct rtw89_reg_def p1_p20_pagcugc_en;
3151 	struct rtw89_reg_def p1_s20_pagcugc_en;
3152 };
3153 
3154 struct rtw89_phy_ul_tb_info {
3155 	bool dyn_tb_tri_en;
3156 	u8 def_if_bandedge;
3157 };
3158 
3159 struct rtw89_antdiv_stats {
3160 	struct ewma_rssi cck_rssi_avg;
3161 	struct ewma_rssi ofdm_rssi_avg;
3162 	struct ewma_rssi non_legacy_rssi_avg;
3163 	u16 pkt_cnt_cck;
3164 	u16 pkt_cnt_ofdm;
3165 	u16 pkt_cnt_non_legacy;
3166 	u32 evm;
3167 };
3168 
3169 struct rtw89_antdiv_info {
3170 	struct rtw89_antdiv_stats target_stats;
3171 	struct rtw89_antdiv_stats main_stats;
3172 	struct rtw89_antdiv_stats aux_stats;
3173 	u8 training_count;
3174 	u8 rssi_pre;
3175 	bool get_stats;
3176 };
3177 
3178 struct rtw89_chip_info {
3179 	enum rtw89_core_chip_id chip_id;
3180 	const struct rtw89_chip_ops *ops;
3181 	const char *fw_basename;
3182 	u8 fw_format_max;
3183 	bool try_ce_fw;
3184 	u32 fifo_size;
3185 	bool small_fifo_size;
3186 	u32 dle_scc_rsvd_size;
3187 	u16 max_amsdu_limit;
3188 	bool dis_2g_40m_ul_ofdma;
3189 	u32 rsvd_ple_ofst;
3190 	const struct rtw89_hfc_param_ini *hfc_param_ini;
3191 	const struct rtw89_dle_mem *dle_mem;
3192 	u8 wde_qempty_acq_num;
3193 	u8 wde_qempty_mgq_sel;
3194 	u32 rf_base_addr[2];
3195 	u8 support_chanctx_num;
3196 	u8 support_bands;
3197 	bool support_bw160;
3198 	bool support_unii4;
3199 	bool support_ul_tb_ctrl;
3200 	bool hw_sec_hdr;
3201 	u8 rf_path_num;
3202 	u8 tx_nss;
3203 	u8 rx_nss;
3204 	u8 acam_num;
3205 	u8 bcam_num;
3206 	u8 scam_num;
3207 	u8 bacam_num;
3208 	u8 bacam_dynamic_num;
3209 	enum rtw89_bacam_ver bacam_ver;
3210 
3211 	u8 sec_ctrl_efuse_size;
3212 	u32 physical_efuse_size;
3213 	u32 logical_efuse_size;
3214 	u32 limit_efuse_size;
3215 	u32 dav_phy_efuse_size;
3216 	u32 dav_log_efuse_size;
3217 	u32 phycap_addr;
3218 	u32 phycap_size;
3219 
3220 	const struct rtw89_pwr_cfg * const *pwr_on_seq;
3221 	const struct rtw89_pwr_cfg * const *pwr_off_seq;
3222 	const struct rtw89_phy_table *bb_table;
3223 	const struct rtw89_phy_table *bb_gain_table;
3224 	const struct rtw89_phy_table *rf_table[RF_PATH_MAX];
3225 	const struct rtw89_phy_table *nctl_table;
3226 	const struct rtw89_rfk_tbl *nctl_post_table;
3227 	const struct rtw89_txpwr_table *byr_table;
3228 	const struct rtw89_phy_dig_gain_table *dig_table;
3229 	const struct rtw89_dig_regs *dig_regs;
3230 	const struct rtw89_phy_tssi_dbw_table *tssi_dbw_table;
3231 
3232 	/* NULL if no rfe-specific, or a null-terminated array by rfe_parms */
3233 	const struct rtw89_rfe_parms_conf *rfe_parms_conf;
3234 	const struct rtw89_rfe_parms *dflt_parms;
3235 
3236 	u8 txpwr_factor_rf;
3237 	u8 txpwr_factor_mac;
3238 
3239 	u32 para_ver;
3240 	u32 wlcx_desired;
3241 	u8 btcx_desired;
3242 	u8 scbd;
3243 	u8 mailbox;
3244 
3245 	u8 afh_guard_ch;
3246 	const u8 *wl_rssi_thres;
3247 	const u8 *bt_rssi_thres;
3248 	u8 rssi_tol;
3249 
3250 	u8 mon_reg_num;
3251 	const struct rtw89_btc_fbtc_mreg *mon_reg;
3252 	u8 rf_para_ulink_num;
3253 	const struct rtw89_btc_rf_trx_para *rf_para_ulink;
3254 	u8 rf_para_dlink_num;
3255 	const struct rtw89_btc_rf_trx_para *rf_para_dlink;
3256 	u8 ps_mode_supported;
3257 	u8 low_power_hci_modes;
3258 
3259 	u32 h2c_cctl_func_id;
3260 	u32 hci_func_en_addr;
3261 	u32 h2c_desc_size;
3262 	u32 txwd_body_size;
3263 	u32 h2c_ctrl_reg;
3264 	const u32 *h2c_regs;
3265 	struct rtw89_reg_def h2c_counter_reg;
3266 	u32 c2h_ctrl_reg;
3267 	const u32 *c2h_regs;
3268 	struct rtw89_reg_def c2h_counter_reg;
3269 	const struct rtw89_page_regs *page_regs;
3270 	bool cfo_src_fd;
3271 	bool cfo_hw_comp;
3272 	const struct rtw89_reg_def *dcfo_comp;
3273 	u8 dcfo_comp_sft;
3274 	const struct rtw89_imr_info *imr_info;
3275 	const struct rtw89_rrsr_cfgs *rrsr_cfgs;
3276 	u32 bss_clr_map_reg;
3277 	u32 dma_ch_mask;
3278 	u32 edcca_lvl_reg;
3279 	const struct wiphy_wowlan_support *wowlan_stub;
3280 	const struct rtw89_xtal_info *xtal_info;
3281 };
3282 
3283 union rtw89_bus_info {
3284 	const struct rtw89_pci_info *pci;
3285 };
3286 
3287 struct rtw89_driver_info {
3288 	const struct rtw89_chip_info *chip;
3289 	union rtw89_bus_info bus;
3290 };
3291 
3292 enum rtw89_hcifc_mode {
3293 	RTW89_HCIFC_POH = 0,
3294 	RTW89_HCIFC_STF = 1,
3295 	RTW89_HCIFC_SDIO = 2,
3296 
3297 	/* keep last */
3298 	RTW89_HCIFC_MODE_INVALID,
3299 };
3300 
3301 struct rtw89_dle_info {
3302 	enum rtw89_qta_mode qta_mode;
3303 	u16 ple_pg_size;
3304 	u16 c0_rx_qta;
3305 	u16 c1_rx_qta;
3306 };
3307 
3308 enum rtw89_host_rpr_mode {
3309 	RTW89_RPR_MODE_POH = 0,
3310 	RTW89_RPR_MODE_STF
3311 };
3312 
3313 #define RTW89_COMPLETION_BUF_SIZE 24
3314 #define RTW89_WAIT_COND_IDLE UINT_MAX
3315 
3316 struct rtw89_completion_data {
3317 	bool err;
3318 	u8 buf[RTW89_COMPLETION_BUF_SIZE];
3319 };
3320 
3321 struct rtw89_wait_info {
3322 	atomic_t cond;
3323 	struct completion completion;
3324 	struct rtw89_completion_data data;
3325 };
3326 
3327 #define RTW89_WAIT_FOR_COND_TIMEOUT msecs_to_jiffies(100)
3328 
3329 static inline void rtw89_init_wait(struct rtw89_wait_info *wait)
3330 {
3331 	init_completion(&wait->completion);
3332 	atomic_set(&wait->cond, RTW89_WAIT_COND_IDLE);
3333 }
3334 
3335 struct rtw89_mac_info {
3336 	struct rtw89_dle_info dle_info;
3337 	struct rtw89_hfc_param hfc_param;
3338 	enum rtw89_qta_mode qta_mode;
3339 	u8 rpwm_seq_num;
3340 	u8 cpwm_seq_num;
3341 
3342 	/* see RTW89_FW_OFLD_WAIT_COND series for wait condition */
3343 	struct rtw89_wait_info fw_ofld_wait;
3344 };
3345 
3346 enum rtw89_fw_type {
3347 	RTW89_FW_NORMAL = 1,
3348 	RTW89_FW_WOWLAN = 3,
3349 	RTW89_FW_NORMAL_CE = 5,
3350 };
3351 
3352 enum rtw89_fw_feature {
3353 	RTW89_FW_FEATURE_OLD_HT_RA_FORMAT,
3354 	RTW89_FW_FEATURE_SCAN_OFFLOAD,
3355 	RTW89_FW_FEATURE_TX_WAKE,
3356 	RTW89_FW_FEATURE_CRASH_TRIGGER,
3357 	RTW89_FW_FEATURE_NO_PACKET_DROP,
3358 	RTW89_FW_FEATURE_NO_DEEP_PS,
3359 	RTW89_FW_FEATURE_NO_LPS_PG,
3360 	RTW89_FW_FEATURE_BEACON_FILTER,
3361 };
3362 
3363 struct rtw89_fw_suit {
3364 	const u8 *data;
3365 	u32 size;
3366 	u8 major_ver;
3367 	u8 minor_ver;
3368 	u8 sub_ver;
3369 	u8 sub_idex;
3370 	u16 build_year;
3371 	u16 build_mon;
3372 	u16 build_date;
3373 	u16 build_hour;
3374 	u16 build_min;
3375 	u8 cmd_ver;
3376 };
3377 
3378 #define RTW89_FW_VER_CODE(major, minor, sub, idx)	\
3379 	(((major) << 24) | ((minor) << 16) | ((sub) << 8) | (idx))
3380 #define RTW89_FW_SUIT_VER_CODE(s)	\
3381 	RTW89_FW_VER_CODE((s)->major_ver, (s)->minor_ver, (s)->sub_ver, (s)->sub_idex)
3382 
3383 #define RTW89_MFW_HDR_VER_CODE(mfw_hdr)		\
3384 	RTW89_FW_VER_CODE((mfw_hdr)->ver.major,	\
3385 			  (mfw_hdr)->ver.minor,	\
3386 			  (mfw_hdr)->ver.sub,	\
3387 			  (mfw_hdr)->ver.idx)
3388 
3389 #define RTW89_FW_HDR_VER_CODE(fw_hdr)				\
3390 	RTW89_FW_VER_CODE(le32_get_bits((fw_hdr)->w1, FW_HDR_W1_MAJOR_VERSION),	\
3391 			  le32_get_bits((fw_hdr)->w1, FW_HDR_W1_MINOR_VERSION),	\
3392 			  le32_get_bits((fw_hdr)->w1, FW_HDR_W1_SUBVERSION),	\
3393 			  le32_get_bits((fw_hdr)->w1, FW_HDR_W1_SUBINDEX))
3394 
3395 struct rtw89_fw_req_info {
3396 	const struct firmware *firmware;
3397 	struct completion completion;
3398 };
3399 
3400 struct rtw89_fw_info {
3401 	struct rtw89_fw_req_info req;
3402 	int fw_format;
3403 	u8 h2c_seq;
3404 	u8 rec_seq;
3405 	u8 h2c_counter;
3406 	u8 c2h_counter;
3407 	struct rtw89_fw_suit normal;
3408 	struct rtw89_fw_suit wowlan;
3409 	bool fw_log_enable;
3410 	u32 feature_map;
3411 };
3412 
3413 #define RTW89_CHK_FW_FEATURE(_feat, _fw) \
3414 	(!!((_fw)->feature_map & BIT(RTW89_FW_FEATURE_ ## _feat)))
3415 
3416 #define RTW89_SET_FW_FEATURE(_fw_feature, _fw) \
3417 	((_fw)->feature_map |= BIT(_fw_feature))
3418 
3419 struct rtw89_cam_info {
3420 	DECLARE_BITMAP(addr_cam_map, RTW89_MAX_ADDR_CAM_NUM);
3421 	DECLARE_BITMAP(bssid_cam_map, RTW89_MAX_BSSID_CAM_NUM);
3422 	DECLARE_BITMAP(sec_cam_map, RTW89_MAX_SEC_CAM_NUM);
3423 	DECLARE_BITMAP(ba_cam_map, RTW89_MAX_BA_CAM_NUM);
3424 	struct rtw89_ba_cam_entry ba_cam_entry[RTW89_MAX_BA_CAM_NUM];
3425 };
3426 
3427 enum rtw89_sar_sources {
3428 	RTW89_SAR_SOURCE_NONE,
3429 	RTW89_SAR_SOURCE_COMMON,
3430 
3431 	RTW89_SAR_SOURCE_NR,
3432 };
3433 
3434 enum rtw89_sar_subband {
3435 	RTW89_SAR_2GHZ_SUBBAND,
3436 	RTW89_SAR_5GHZ_SUBBAND_1_2, /* U-NII-1 and U-NII-2 */
3437 	RTW89_SAR_5GHZ_SUBBAND_2_E, /* U-NII-2-Extended */
3438 	RTW89_SAR_5GHZ_SUBBAND_3,   /* U-NII-3 */
3439 	RTW89_SAR_6GHZ_SUBBAND_5_L, /* U-NII-5 lower part */
3440 	RTW89_SAR_6GHZ_SUBBAND_5_H, /* U-NII-5 higher part */
3441 	RTW89_SAR_6GHZ_SUBBAND_6,   /* U-NII-6 */
3442 	RTW89_SAR_6GHZ_SUBBAND_7_L, /* U-NII-7 lower part */
3443 	RTW89_SAR_6GHZ_SUBBAND_7_H, /* U-NII-7 higher part */
3444 	RTW89_SAR_6GHZ_SUBBAND_8,   /* U-NII-8 */
3445 
3446 	RTW89_SAR_SUBBAND_NR,
3447 };
3448 
3449 struct rtw89_sar_cfg_common {
3450 	bool set[RTW89_SAR_SUBBAND_NR];
3451 	s32 cfg[RTW89_SAR_SUBBAND_NR];
3452 };
3453 
3454 struct rtw89_sar_info {
3455 	/* used to decide how to acces SAR cfg union */
3456 	enum rtw89_sar_sources src;
3457 
3458 	/* reserved for different knids of SAR cfg struct.
3459 	 * supposed that a single cfg struct cannot handle various SAR sources.
3460 	 */
3461 	union {
3462 		struct rtw89_sar_cfg_common cfg_common;
3463 	};
3464 };
3465 
3466 struct rtw89_chanctx_cfg {
3467 	enum rtw89_sub_entity_idx idx;
3468 };
3469 
3470 enum rtw89_entity_mode {
3471 	RTW89_ENTITY_MODE_SCC,
3472 };
3473 
3474 struct rtw89_sub_entity {
3475 	struct cfg80211_chan_def chandef;
3476 	struct rtw89_chan chan;
3477 	struct rtw89_chan_rcd rcd;
3478 	struct rtw89_chanctx_cfg *cfg;
3479 };
3480 
3481 struct rtw89_hal {
3482 	u32 rx_fltr;
3483 	u8 cv;
3484 	u8 acv;
3485 	u32 antenna_tx;
3486 	u32 antenna_rx;
3487 	u8 tx_nss;
3488 	u8 rx_nss;
3489 	bool tx_path_diversity;
3490 	bool ant_diversity;
3491 	bool ant_diversity_fixed;
3492 	bool support_cckpd;
3493 	bool support_igi;
3494 	atomic_t roc_entity_idx;
3495 
3496 	DECLARE_BITMAP(entity_map, NUM_OF_RTW89_SUB_ENTITY);
3497 	struct rtw89_sub_entity sub[NUM_OF_RTW89_SUB_ENTITY];
3498 	struct cfg80211_chan_def roc_chandef;
3499 
3500 	bool entity_active;
3501 	enum rtw89_entity_mode entity_mode;
3502 
3503 	u32 edcca_bak;
3504 };
3505 
3506 #define RTW89_MAX_MAC_ID_NUM 128
3507 #define RTW89_MAX_PKT_OFLD_NUM 255
3508 
3509 enum rtw89_flags {
3510 	RTW89_FLAG_POWERON,
3511 	RTW89_FLAG_FW_RDY,
3512 	RTW89_FLAG_RUNNING,
3513 	RTW89_FLAG_BFEE_MON,
3514 	RTW89_FLAG_BFEE_EN,
3515 	RTW89_FLAG_BFEE_TIMER_KEEP,
3516 	RTW89_FLAG_NAPI_RUNNING,
3517 	RTW89_FLAG_LEISURE_PS,
3518 	RTW89_FLAG_LOW_POWER_MODE,
3519 	RTW89_FLAG_INACTIVE_PS,
3520 	RTW89_FLAG_CRASH_SIMULATING,
3521 	RTW89_FLAG_SER_HANDLING,
3522 	RTW89_FLAG_WOWLAN,
3523 	RTW89_FLAG_FORBIDDEN_TRACK_WROK,
3524 	RTW89_FLAG_CHANGING_INTERFACE,
3525 
3526 	NUM_OF_RTW89_FLAGS,
3527 };
3528 
3529 enum rtw89_pkt_drop_sel {
3530 	RTW89_PKT_DROP_SEL_MACID_BE_ONCE,
3531 	RTW89_PKT_DROP_SEL_MACID_BK_ONCE,
3532 	RTW89_PKT_DROP_SEL_MACID_VI_ONCE,
3533 	RTW89_PKT_DROP_SEL_MACID_VO_ONCE,
3534 	RTW89_PKT_DROP_SEL_MACID_ALL,
3535 	RTW89_PKT_DROP_SEL_MG0_ONCE,
3536 	RTW89_PKT_DROP_SEL_HIQ_ONCE,
3537 	RTW89_PKT_DROP_SEL_HIQ_PORT,
3538 	RTW89_PKT_DROP_SEL_HIQ_MBSSID,
3539 	RTW89_PKT_DROP_SEL_BAND,
3540 	RTW89_PKT_DROP_SEL_BAND_ONCE,
3541 	RTW89_PKT_DROP_SEL_REL_MACID,
3542 	RTW89_PKT_DROP_SEL_REL_HIQ_PORT,
3543 	RTW89_PKT_DROP_SEL_REL_HIQ_MBSSID,
3544 };
3545 
3546 struct rtw89_pkt_drop_params {
3547 	enum rtw89_pkt_drop_sel sel;
3548 	enum rtw89_mac_idx mac_band;
3549 	u8 macid;
3550 	u8 port;
3551 	u8 mbssid;
3552 	bool tf_trs;
3553 	u32 macid_band_sel[4];
3554 };
3555 
3556 struct rtw89_pkt_stat {
3557 	u16 beacon_nr;
3558 	u32 rx_rate_cnt[RTW89_HW_RATE_NR];
3559 };
3560 
3561 DECLARE_EWMA(thermal, 4, 4);
3562 
3563 struct rtw89_phy_stat {
3564 	struct ewma_thermal avg_thermal[RF_PATH_MAX];
3565 	struct rtw89_pkt_stat cur_pkt_stat;
3566 	struct rtw89_pkt_stat last_pkt_stat;
3567 };
3568 
3569 #define RTW89_DACK_PATH_NR 2
3570 #define RTW89_DACK_IDX_NR 2
3571 #define RTW89_DACK_MSBK_NR 16
3572 struct rtw89_dack_info {
3573 	bool dack_done;
3574 	u8 msbk_d[RTW89_DACK_PATH_NR][RTW89_DACK_IDX_NR][RTW89_DACK_MSBK_NR];
3575 	u8 dadck_d[RTW89_DACK_PATH_NR][RTW89_DACK_IDX_NR];
3576 	u16 addck_d[RTW89_DACK_PATH_NR][RTW89_DACK_IDX_NR];
3577 	u16 biask_d[RTW89_DACK_PATH_NR][RTW89_DACK_IDX_NR];
3578 	u32 dack_cnt;
3579 	bool addck_timeout[RTW89_DACK_PATH_NR];
3580 	bool dadck_timeout[RTW89_DACK_PATH_NR];
3581 	bool msbk_timeout[RTW89_DACK_PATH_NR];
3582 };
3583 
3584 #define RTW89_IQK_CHS_NR 2
3585 #define RTW89_IQK_PATH_NR 4
3586 
3587 struct rtw89_rfk_mcc_info {
3588 	u8 ch[RTW89_IQK_CHS_NR];
3589 	u8 band[RTW89_IQK_CHS_NR];
3590 	u8 table_idx;
3591 };
3592 
3593 struct rtw89_lck_info {
3594 	u8 thermal[RF_PATH_MAX];
3595 };
3596 
3597 struct rtw89_rx_dck_info {
3598 	u8 thermal[RF_PATH_MAX];
3599 };
3600 
3601 struct rtw89_iqk_info {
3602 	bool lok_cor_fail[RTW89_IQK_CHS_NR][RTW89_IQK_PATH_NR];
3603 	bool lok_fin_fail[RTW89_IQK_CHS_NR][RTW89_IQK_PATH_NR];
3604 	bool lok_fail[RTW89_IQK_PATH_NR];
3605 	bool iqk_tx_fail[RTW89_IQK_CHS_NR][RTW89_IQK_PATH_NR];
3606 	bool iqk_rx_fail[RTW89_IQK_CHS_NR][RTW89_IQK_PATH_NR];
3607 	u32 iqk_fail_cnt;
3608 	bool is_iqk_init;
3609 	u32 iqk_channel[RTW89_IQK_CHS_NR];
3610 	u8 iqk_band[RTW89_IQK_PATH_NR];
3611 	u8 iqk_ch[RTW89_IQK_PATH_NR];
3612 	u8 iqk_bw[RTW89_IQK_PATH_NR];
3613 	u8 iqk_times;
3614 	u8 version;
3615 	u32 nb_txcfir[RTW89_IQK_PATH_NR];
3616 	u32 nb_rxcfir[RTW89_IQK_PATH_NR];
3617 	u32 bp_txkresult[RTW89_IQK_PATH_NR];
3618 	u32 bp_rxkresult[RTW89_IQK_PATH_NR];
3619 	u32 bp_iqkenable[RTW89_IQK_PATH_NR];
3620 	bool is_wb_txiqk[RTW89_IQK_PATH_NR];
3621 	bool is_wb_rxiqk[RTW89_IQK_PATH_NR];
3622 	bool is_nbiqk;
3623 	bool iqk_fft_en;
3624 	bool iqk_xym_en;
3625 	bool iqk_sram_en;
3626 	bool iqk_cfir_en;
3627 	u32 syn1to2;
3628 	u8 iqk_mcc_ch[RTW89_IQK_CHS_NR][RTW89_IQK_PATH_NR];
3629 	u8 iqk_table_idx[RTW89_IQK_PATH_NR];
3630 	u32 lok_idac[RTW89_IQK_CHS_NR][RTW89_IQK_PATH_NR];
3631 	u32 lok_vbuf[RTW89_IQK_CHS_NR][RTW89_IQK_PATH_NR];
3632 };
3633 
3634 #define RTW89_DPK_RF_PATH 2
3635 #define RTW89_DPK_AVG_THERMAL_NUM 8
3636 #define RTW89_DPK_BKUP_NUM 2
3637 struct rtw89_dpk_bkup_para {
3638 	enum rtw89_band band;
3639 	enum rtw89_bandwidth bw;
3640 	u8 ch;
3641 	bool path_ok;
3642 	u8 mdpd_en;
3643 	u8 txagc_dpk;
3644 	u8 ther_dpk;
3645 	u8 gs;
3646 	u16 pwsf;
3647 };
3648 
3649 struct rtw89_dpk_info {
3650 	bool is_dpk_enable;
3651 	bool is_dpk_reload_en;
3652 	u8 dpk_gs[RTW89_PHY_MAX];
3653 	u16 dc_i[RTW89_DPK_RF_PATH][RTW89_DPK_BKUP_NUM];
3654 	u16 dc_q[RTW89_DPK_RF_PATH][RTW89_DPK_BKUP_NUM];
3655 	u8 corr_val[RTW89_DPK_RF_PATH][RTW89_DPK_BKUP_NUM];
3656 	u8 corr_idx[RTW89_DPK_RF_PATH][RTW89_DPK_BKUP_NUM];
3657 	u8 cur_idx[RTW89_DPK_RF_PATH];
3658 	u8 cur_k_set;
3659 	struct rtw89_dpk_bkup_para bp[RTW89_DPK_RF_PATH][RTW89_DPK_BKUP_NUM];
3660 };
3661 
3662 struct rtw89_fem_info {
3663 	bool elna_2g;
3664 	bool elna_5g;
3665 	bool epa_2g;
3666 	bool epa_5g;
3667 	bool epa_6g;
3668 };
3669 
3670 struct rtw89_phy_ch_info {
3671 	u8 rssi_min;
3672 	u16 rssi_min_macid;
3673 	u8 pre_rssi_min;
3674 	u8 rssi_max;
3675 	u16 rssi_max_macid;
3676 	u8 rxsc_160;
3677 	u8 rxsc_80;
3678 	u8 rxsc_40;
3679 	u8 rxsc_20;
3680 	u8 rxsc_l;
3681 	u8 is_noisy;
3682 };
3683 
3684 struct rtw89_agc_gaincode_set {
3685 	u8 lna_idx;
3686 	u8 tia_idx;
3687 	u8 rxb_idx;
3688 };
3689 
3690 #define IGI_RSSI_TH_NUM 5
3691 #define FA_TH_NUM 4
3692 #define LNA_GAIN_NUM 7
3693 #define TIA_GAIN_NUM 2
3694 struct rtw89_dig_info {
3695 	struct rtw89_agc_gaincode_set cur_gaincode;
3696 	bool force_gaincode_idx_en;
3697 	struct rtw89_agc_gaincode_set force_gaincode;
3698 	u8 igi_rssi_th[IGI_RSSI_TH_NUM];
3699 	u16 fa_th[FA_TH_NUM];
3700 	u8 igi_rssi;
3701 	u8 igi_fa_rssi;
3702 	u8 fa_rssi_ofst;
3703 	u8 dyn_igi_max;
3704 	u8 dyn_igi_min;
3705 	bool dyn_pd_th_en;
3706 	u8 dyn_pd_th_max;
3707 	u8 pd_low_th_ofst;
3708 	u8 ib_pbk;
3709 	s8 ib_pkpwr;
3710 	s8 lna_gain_a[LNA_GAIN_NUM];
3711 	s8 lna_gain_g[LNA_GAIN_NUM];
3712 	s8 *lna_gain;
3713 	s8 tia_gain_a[TIA_GAIN_NUM];
3714 	s8 tia_gain_g[TIA_GAIN_NUM];
3715 	s8 *tia_gain;
3716 	bool is_linked_pre;
3717 	bool bypass_dig;
3718 };
3719 
3720 enum rtw89_multi_cfo_mode {
3721 	RTW89_PKT_BASED_AVG_MODE = 0,
3722 	RTW89_ENTRY_BASED_AVG_MODE = 1,
3723 	RTW89_TP_BASED_AVG_MODE = 2,
3724 };
3725 
3726 enum rtw89_phy_cfo_status {
3727 	RTW89_PHY_DCFO_STATE_NORMAL = 0,
3728 	RTW89_PHY_DCFO_STATE_ENHANCE = 1,
3729 	RTW89_PHY_DCFO_STATE_HOLD = 2,
3730 	RTW89_PHY_DCFO_STATE_MAX
3731 };
3732 
3733 enum rtw89_phy_cfo_ul_ofdma_acc_mode {
3734 	RTW89_CFO_UL_OFDMA_ACC_DISABLE = 0,
3735 	RTW89_CFO_UL_OFDMA_ACC_ENABLE = 1
3736 };
3737 
3738 struct rtw89_cfo_tracking_info {
3739 	u16 cfo_timer_ms;
3740 	bool cfo_trig_by_timer_en;
3741 	enum rtw89_phy_cfo_status phy_cfo_status;
3742 	enum rtw89_phy_cfo_ul_ofdma_acc_mode cfo_ul_ofdma_acc_mode;
3743 	u8 phy_cfo_trk_cnt;
3744 	bool is_adjust;
3745 	enum rtw89_multi_cfo_mode rtw89_multi_cfo_mode;
3746 	bool apply_compensation;
3747 	u8 crystal_cap;
3748 	u8 crystal_cap_default;
3749 	u8 def_x_cap;
3750 	s8 x_cap_ofst;
3751 	u32 sta_cfo_tolerance;
3752 	s32 cfo_tail[CFO_TRACK_MAX_USER];
3753 	u16 cfo_cnt[CFO_TRACK_MAX_USER];
3754 	s32 cfo_avg_pre;
3755 	s32 cfo_avg[CFO_TRACK_MAX_USER];
3756 	s32 pre_cfo_avg[CFO_TRACK_MAX_USER];
3757 	s32 dcfo_avg;
3758 	s32 dcfo_avg_pre;
3759 	u32 packet_count;
3760 	u32 packet_count_pre;
3761 	s32 residual_cfo_acc;
3762 	u8 phy_cfotrk_state;
3763 	u8 phy_cfotrk_cnt;
3764 	bool divergence_lock_en;
3765 	u8 x_cap_lb;
3766 	u8 x_cap_ub;
3767 	u8 lock_cnt;
3768 };
3769 
3770 enum rtw89_tssi_alimk_band {
3771 	TSSI_ALIMK_2G = 0,
3772 	TSSI_ALIMK_5GL,
3773 	TSSI_ALIMK_5GM,
3774 	TSSI_ALIMK_5GH,
3775 	TSSI_ALIMK_MAX
3776 };
3777 
3778 /* 2GL, 2GH, 5GL1, 5GH1, 5GM1, 5GM2, 5GH1, 5GH2 */
3779 #define TSSI_TRIM_CH_GROUP_NUM 8
3780 #define TSSI_TRIM_CH_GROUP_NUM_6G 16
3781 
3782 #define TSSI_CCK_CH_GROUP_NUM 6
3783 #define TSSI_MCS_2G_CH_GROUP_NUM 5
3784 #define TSSI_MCS_5G_CH_GROUP_NUM 14
3785 #define TSSI_MCS_6G_CH_GROUP_NUM 32
3786 #define TSSI_MCS_CH_GROUP_NUM \
3787 	(TSSI_MCS_2G_CH_GROUP_NUM + TSSI_MCS_5G_CH_GROUP_NUM)
3788 #define TSSI_MAX_CH_NUM 67
3789 #define TSSI_ALIMK_VALUE_NUM 8
3790 
3791 struct rtw89_tssi_info {
3792 	u8 thermal[RF_PATH_MAX];
3793 	s8 tssi_trim[RF_PATH_MAX][TSSI_TRIM_CH_GROUP_NUM];
3794 	s8 tssi_trim_6g[RF_PATH_MAX][TSSI_TRIM_CH_GROUP_NUM_6G];
3795 	s8 tssi_cck[RF_PATH_MAX][TSSI_CCK_CH_GROUP_NUM];
3796 	s8 tssi_mcs[RF_PATH_MAX][TSSI_MCS_CH_GROUP_NUM];
3797 	s8 tssi_6g_mcs[RF_PATH_MAX][TSSI_MCS_6G_CH_GROUP_NUM];
3798 	s8 extra_ofst[RF_PATH_MAX];
3799 	bool tssi_tracking_check[RF_PATH_MAX];
3800 	u8 default_txagc_offset[RF_PATH_MAX];
3801 	u32 base_thermal[RF_PATH_MAX];
3802 	bool check_backup_aligmk[RF_PATH_MAX][TSSI_MAX_CH_NUM];
3803 	u32 alignment_backup_by_ch[RF_PATH_MAX][TSSI_MAX_CH_NUM][TSSI_ALIMK_VALUE_NUM];
3804 	u32 alignment_value[RF_PATH_MAX][TSSI_ALIMK_MAX][TSSI_ALIMK_VALUE_NUM];
3805 	bool alignment_done[RF_PATH_MAX][TSSI_ALIMK_MAX];
3806 	u32 tssi_alimk_time;
3807 };
3808 
3809 struct rtw89_power_trim_info {
3810 	bool pg_thermal_trim;
3811 	bool pg_pa_bias_trim;
3812 	u8 thermal_trim[RF_PATH_MAX];
3813 	u8 pa_bias_trim[RF_PATH_MAX];
3814 };
3815 
3816 struct rtw89_regd {
3817 	char alpha2[3];
3818 	u8 txpwr_regd[RTW89_BAND_NUM];
3819 };
3820 
3821 struct rtw89_regulatory_info {
3822 	const struct rtw89_regd *regd;
3823 	enum rtw89_reg_6ghz_power reg_6ghz_power;
3824 };
3825 
3826 enum rtw89_ifs_clm_application {
3827 	RTW89_IFS_CLM_INIT = 0,
3828 	RTW89_IFS_CLM_BACKGROUND = 1,
3829 	RTW89_IFS_CLM_ACS = 2,
3830 	RTW89_IFS_CLM_DIG = 3,
3831 	RTW89_IFS_CLM_TDMA_DIG = 4,
3832 	RTW89_IFS_CLM_DBG = 5,
3833 	RTW89_IFS_CLM_DBG_MANUAL = 6
3834 };
3835 
3836 enum rtw89_env_racing_lv {
3837 	RTW89_RAC_RELEASE = 0,
3838 	RTW89_RAC_LV_1 = 1,
3839 	RTW89_RAC_LV_2 = 2,
3840 	RTW89_RAC_LV_3 = 3,
3841 	RTW89_RAC_LV_4 = 4,
3842 	RTW89_RAC_MAX_NUM = 5
3843 };
3844 
3845 struct rtw89_ccx_para_info {
3846 	enum rtw89_env_racing_lv rac_lv;
3847 	u16 mntr_time;
3848 	u8 nhm_manual_th_ofst;
3849 	u8 nhm_manual_th0;
3850 	enum rtw89_ifs_clm_application ifs_clm_app;
3851 	u32 ifs_clm_manual_th_times;
3852 	u32 ifs_clm_manual_th0;
3853 	u8 fahm_manual_th_ofst;
3854 	u8 fahm_manual_th0;
3855 	u8 fahm_numer_opt;
3856 	u8 fahm_denom_opt;
3857 };
3858 
3859 enum rtw89_ccx_edcca_opt_sc_idx {
3860 	RTW89_CCX_EDCCA_SEG0_P0 = 0,
3861 	RTW89_CCX_EDCCA_SEG0_S1 = 1,
3862 	RTW89_CCX_EDCCA_SEG0_S2 = 2,
3863 	RTW89_CCX_EDCCA_SEG0_S3 = 3,
3864 	RTW89_CCX_EDCCA_SEG1_P0 = 4,
3865 	RTW89_CCX_EDCCA_SEG1_S1 = 5,
3866 	RTW89_CCX_EDCCA_SEG1_S2 = 6,
3867 	RTW89_CCX_EDCCA_SEG1_S3 = 7
3868 };
3869 
3870 enum rtw89_ccx_edcca_opt_bw_idx {
3871 	RTW89_CCX_EDCCA_BW20_0 = 0,
3872 	RTW89_CCX_EDCCA_BW20_1 = 1,
3873 	RTW89_CCX_EDCCA_BW20_2 = 2,
3874 	RTW89_CCX_EDCCA_BW20_3 = 3,
3875 	RTW89_CCX_EDCCA_BW20_4 = 4,
3876 	RTW89_CCX_EDCCA_BW20_5 = 5,
3877 	RTW89_CCX_EDCCA_BW20_6 = 6,
3878 	RTW89_CCX_EDCCA_BW20_7 = 7
3879 };
3880 
3881 #define RTW89_NHM_TH_NUM 11
3882 #define RTW89_FAHM_TH_NUM 11
3883 #define RTW89_NHM_RPT_NUM 12
3884 #define RTW89_FAHM_RPT_NUM 12
3885 #define RTW89_IFS_CLM_NUM 4
3886 struct rtw89_env_monitor_info {
3887 	u8 ccx_watchdog_result;
3888 	bool ccx_ongoing;
3889 	u8 ccx_rac_lv;
3890 	bool ccx_manual_ctrl;
3891 	u16 ifs_clm_mntr_time;
3892 	enum rtw89_ifs_clm_application ifs_clm_app;
3893 	u16 ccx_period;
3894 	u8 ccx_unit_idx;
3895 	u16 ifs_clm_th_l[RTW89_IFS_CLM_NUM];
3896 	u16 ifs_clm_th_h[RTW89_IFS_CLM_NUM];
3897 	u16 ifs_clm_tx;
3898 	u16 ifs_clm_edcca_excl_cca;
3899 	u16 ifs_clm_ofdmfa;
3900 	u16 ifs_clm_ofdmcca_excl_fa;
3901 	u16 ifs_clm_cckfa;
3902 	u16 ifs_clm_cckcca_excl_fa;
3903 	u16 ifs_clm_total_ifs;
3904 	u8 ifs_clm_his[RTW89_IFS_CLM_NUM];
3905 	u16 ifs_clm_avg[RTW89_IFS_CLM_NUM];
3906 	u16 ifs_clm_cca[RTW89_IFS_CLM_NUM];
3907 	u8 ifs_clm_tx_ratio;
3908 	u8 ifs_clm_edcca_excl_cca_ratio;
3909 	u8 ifs_clm_cck_fa_ratio;
3910 	u8 ifs_clm_ofdm_fa_ratio;
3911 	u8 ifs_clm_cck_cca_excl_fa_ratio;
3912 	u8 ifs_clm_ofdm_cca_excl_fa_ratio;
3913 	u16 ifs_clm_cck_fa_permil;
3914 	u16 ifs_clm_ofdm_fa_permil;
3915 	u32 ifs_clm_ifs_avg[RTW89_IFS_CLM_NUM];
3916 	u32 ifs_clm_cca_avg[RTW89_IFS_CLM_NUM];
3917 };
3918 
3919 enum rtw89_ser_rcvy_step {
3920 	RTW89_SER_DRV_STOP_TX,
3921 	RTW89_SER_DRV_STOP_RX,
3922 	RTW89_SER_DRV_STOP_RUN,
3923 	RTW89_SER_HAL_STOP_DMA,
3924 	RTW89_SER_SUPPRESS_LOG,
3925 	RTW89_NUM_OF_SER_FLAGS
3926 };
3927 
3928 struct rtw89_ser {
3929 	u8 state;
3930 	u8 alarm_event;
3931 	bool prehandle_l1;
3932 
3933 	struct work_struct ser_hdl_work;
3934 	struct delayed_work ser_alarm_work;
3935 	const struct state_ent *st_tbl;
3936 	const struct event_ent *ev_tbl;
3937 	struct list_head msg_q;
3938 	spinlock_t msg_q_lock; /* lock when read/write ser msg */
3939 	DECLARE_BITMAP(flags, RTW89_NUM_OF_SER_FLAGS);
3940 };
3941 
3942 enum rtw89_mac_ax_ps_mode {
3943 	RTW89_MAC_AX_PS_MODE_ACTIVE = 0,
3944 	RTW89_MAC_AX_PS_MODE_LEGACY = 1,
3945 	RTW89_MAC_AX_PS_MODE_WMMPS  = 2,
3946 	RTW89_MAC_AX_PS_MODE_MAX    = 3,
3947 };
3948 
3949 enum rtw89_last_rpwm_mode {
3950 	RTW89_LAST_RPWM_PS        = 0x0,
3951 	RTW89_LAST_RPWM_ACTIVE    = 0x6,
3952 };
3953 
3954 struct rtw89_lps_parm {
3955 	u8 macid;
3956 	u8 psmode; /* enum rtw89_mac_ax_ps_mode */
3957 	u8 lastrpwm; /* enum rtw89_last_rpwm_mode */
3958 };
3959 
3960 struct rtw89_ppdu_sts_info {
3961 	struct sk_buff_head rx_queue[RTW89_PHY_MAX];
3962 	u8 curr_rx_ppdu_cnt[RTW89_PHY_MAX];
3963 };
3964 
3965 struct rtw89_early_h2c {
3966 	struct list_head list;
3967 	u8 *h2c;
3968 	u16 h2c_len;
3969 };
3970 
3971 struct rtw89_hw_scan_info {
3972 	struct ieee80211_vif *scanning_vif;
3973 	struct list_head pkt_list[NUM_NL80211_BANDS];
3974 	struct rtw89_chan op_chan;
3975 	u32 last_chan_idx;
3976 };
3977 
3978 enum rtw89_phy_bb_gain_band {
3979 	RTW89_BB_GAIN_BAND_2G = 0,
3980 	RTW89_BB_GAIN_BAND_5G_L = 1,
3981 	RTW89_BB_GAIN_BAND_5G_M = 2,
3982 	RTW89_BB_GAIN_BAND_5G_H = 3,
3983 	RTW89_BB_GAIN_BAND_6G_L = 4,
3984 	RTW89_BB_GAIN_BAND_6G_M = 5,
3985 	RTW89_BB_GAIN_BAND_6G_H = 6,
3986 	RTW89_BB_GAIN_BAND_6G_UH = 7,
3987 
3988 	RTW89_BB_GAIN_BAND_NR,
3989 };
3990 
3991 enum rtw89_phy_bb_rxsc_num {
3992 	RTW89_BB_RXSC_NUM_40 = 9, /* SC: 0, 1~8 */
3993 	RTW89_BB_RXSC_NUM_80 = 13, /* SC: 0, 1~8, 9~12 */
3994 	RTW89_BB_RXSC_NUM_160 = 15, /* SC: 0, 1~8, 9~12, 13~14 */
3995 };
3996 
3997 struct rtw89_phy_bb_gain_info {
3998 	s8 lna_gain[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX][LNA_GAIN_NUM];
3999 	s8 tia_gain[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX][TIA_GAIN_NUM];
4000 	s8 lna_gain_bypass[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX][LNA_GAIN_NUM];
4001 	s8 lna_op1db[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX][LNA_GAIN_NUM];
4002 	s8 tia_lna_op1db[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX]
4003 			[LNA_GAIN_NUM + 1]; /* TIA0_LNA0~6 + TIA1_LNA6 */
4004 	s8 rpl_ofst_20[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX];
4005 	s8 rpl_ofst_40[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX]
4006 		      [RTW89_BB_RXSC_NUM_40];
4007 	s8 rpl_ofst_80[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX]
4008 		      [RTW89_BB_RXSC_NUM_80];
4009 	s8 rpl_ofst_160[RTW89_BB_GAIN_BAND_NR][RF_PATH_MAX]
4010 		       [RTW89_BB_RXSC_NUM_160];
4011 };
4012 
4013 struct rtw89_phy_efuse_gain {
4014 	bool offset_valid;
4015 	bool comp_valid;
4016 	s8 offset[RF_PATH_MAX][RTW89_GAIN_OFFSET_NR]; /* S(8, 0) */
4017 	s8 offset_base[RTW89_PHY_MAX]; /* S(8, 4) */
4018 	s8 rssi_base[RTW89_PHY_MAX]; /* S(8, 4) */
4019 	s8 comp[RF_PATH_MAX][RTW89_SUBBAND_NR]; /* S(8, 0) */
4020 };
4021 
4022 #define RTW89_MAX_PATTERN_NUM             18
4023 #define RTW89_MAX_PATTERN_MASK_SIZE       4
4024 #define RTW89_MAX_PATTERN_SIZE            128
4025 
4026 struct rtw89_wow_cam_info {
4027 	bool r_w;
4028 	u8 idx;
4029 	u32 mask[RTW89_MAX_PATTERN_MASK_SIZE];
4030 	u16 crc;
4031 	bool negative_pattern_match;
4032 	bool skip_mac_hdr;
4033 	bool uc;
4034 	bool mc;
4035 	bool bc;
4036 	bool valid;
4037 };
4038 
4039 struct rtw89_wow_param {
4040 	struct ieee80211_vif *wow_vif;
4041 	DECLARE_BITMAP(flags, RTW89_WOW_FLAG_NUM);
4042 	struct rtw89_wow_cam_info patterns[RTW89_MAX_PATTERN_NUM];
4043 	u8 pattern_cnt;
4044 };
4045 
4046 struct rtw89_mcc_info {
4047 	struct rtw89_wait_info wait;
4048 };
4049 
4050 struct rtw89_dev {
4051 	struct ieee80211_hw *hw;
4052 	struct device *dev;
4053 	const struct ieee80211_ops *ops;
4054 
4055 	bool dbcc_en;
4056 	struct rtw89_hw_scan_info scan_info;
4057 	const struct rtw89_chip_info *chip;
4058 	const struct rtw89_pci_info *pci_info;
4059 	const struct rtw89_rfe_parms *rfe_parms;
4060 	struct rtw89_hal hal;
4061 	struct rtw89_mcc_info mcc;
4062 	struct rtw89_mac_info mac;
4063 	struct rtw89_fw_info fw;
4064 	struct rtw89_hci_info hci;
4065 	struct rtw89_efuse efuse;
4066 	struct rtw89_traffic_stats stats;
4067 
4068 	/* ensures exclusive access from mac80211 callbacks */
4069 	struct mutex mutex;
4070 	struct list_head rtwvifs_list;
4071 	/* used to protect rf read write */
4072 	struct mutex rf_mutex;
4073 	struct workqueue_struct *txq_wq;
4074 	struct work_struct txq_work;
4075 	struct delayed_work txq_reinvoke_work;
4076 	/* used to protect ba_list and forbid_ba_list */
4077 	spinlock_t ba_lock;
4078 	/* txqs to setup ba session */
4079 	struct list_head ba_list;
4080 	/* txqs to forbid ba session */
4081 	struct list_head forbid_ba_list;
4082 	struct work_struct ba_work;
4083 	/* used to protect rpwm */
4084 	spinlock_t rpwm_lock;
4085 
4086 	struct rtw89_cam_info cam_info;
4087 
4088 	struct sk_buff_head c2h_queue;
4089 	struct work_struct c2h_work;
4090 	struct work_struct ips_work;
4091 	struct work_struct load_firmware_work;
4092 	struct work_struct cancel_6ghz_probe_work;
4093 
4094 	struct list_head early_h2c_list;
4095 
4096 	struct rtw89_ser ser;
4097 
4098 	DECLARE_BITMAP(hw_port, RTW89_PORT_NUM);
4099 	DECLARE_BITMAP(mac_id_map, RTW89_MAX_MAC_ID_NUM);
4100 	DECLARE_BITMAP(flags, NUM_OF_RTW89_FLAGS);
4101 	DECLARE_BITMAP(pkt_offload, RTW89_MAX_PKT_OFLD_NUM);
4102 
4103 	struct rtw89_phy_stat phystat;
4104 	struct rtw89_dack_info dack;
4105 	struct rtw89_iqk_info iqk;
4106 	struct rtw89_dpk_info dpk;
4107 	struct rtw89_rfk_mcc_info rfk_mcc;
4108 	struct rtw89_lck_info lck;
4109 	struct rtw89_rx_dck_info rx_dck;
4110 	bool is_tssi_mode[RF_PATH_MAX];
4111 	bool is_bt_iqk_timeout;
4112 
4113 	struct rtw89_fem_info fem;
4114 	struct rtw89_txpwr_byrate byr[RTW89_BAND_NUM];
4115 	struct rtw89_tssi_info tssi;
4116 	struct rtw89_power_trim_info pwr_trim;
4117 
4118 	struct rtw89_cfo_tracking_info cfo_tracking;
4119 	struct rtw89_env_monitor_info env_monitor;
4120 	struct rtw89_dig_info dig;
4121 	struct rtw89_phy_ch_info ch_info;
4122 	struct rtw89_phy_bb_gain_info bb_gain;
4123 	struct rtw89_phy_efuse_gain efuse_gain;
4124 	struct rtw89_phy_ul_tb_info ul_tb_info;
4125 	struct rtw89_antdiv_info antdiv;
4126 
4127 	struct delayed_work track_work;
4128 	struct delayed_work coex_act1_work;
4129 	struct delayed_work coex_bt_devinfo_work;
4130 	struct delayed_work coex_rfk_chk_work;
4131 	struct delayed_work cfo_track_work;
4132 	struct delayed_work forbid_ba_work;
4133 	struct delayed_work roc_work;
4134 	struct delayed_work antdiv_work;
4135 	struct rtw89_ppdu_sts_info ppdu_sts;
4136 	u8 total_sta_assoc;
4137 	bool scanning;
4138 
4139 	struct rtw89_regulatory_info regulatory;
4140 	struct rtw89_sar_info sar;
4141 
4142 	struct rtw89_btc btc;
4143 	enum rtw89_ps_mode ps_mode;
4144 	bool lps_enabled;
4145 
4146 	struct rtw89_wow_param wow;
4147 
4148 	/* napi structure */
4149 	struct net_device netdev;
4150 	struct napi_struct napi;
4151 	int napi_budget_countdown;
4152 
4153 	/* HCI related data, keep last */
4154 	u8 priv[] __aligned(sizeof(void *));
4155 };
4156 
4157 static inline int rtw89_hci_tx_write(struct rtw89_dev *rtwdev,
4158 				     struct rtw89_core_tx_request *tx_req)
4159 {
4160 	return rtwdev->hci.ops->tx_write(rtwdev, tx_req);
4161 }
4162 
4163 static inline void rtw89_hci_reset(struct rtw89_dev *rtwdev)
4164 {
4165 	rtwdev->hci.ops->reset(rtwdev);
4166 }
4167 
4168 static inline int rtw89_hci_start(struct rtw89_dev *rtwdev)
4169 {
4170 	return rtwdev->hci.ops->start(rtwdev);
4171 }
4172 
4173 static inline void rtw89_hci_stop(struct rtw89_dev *rtwdev)
4174 {
4175 	rtwdev->hci.ops->stop(rtwdev);
4176 }
4177 
4178 static inline int rtw89_hci_deinit(struct rtw89_dev *rtwdev)
4179 {
4180 	return rtwdev->hci.ops->deinit(rtwdev);
4181 }
4182 
4183 static inline void rtw89_hci_pause(struct rtw89_dev *rtwdev, bool pause)
4184 {
4185 	rtwdev->hci.ops->pause(rtwdev, pause);
4186 }
4187 
4188 static inline void rtw89_hci_switch_mode(struct rtw89_dev *rtwdev, bool low_power)
4189 {
4190 	rtwdev->hci.ops->switch_mode(rtwdev, low_power);
4191 }
4192 
4193 static inline void rtw89_hci_recalc_int_mit(struct rtw89_dev *rtwdev)
4194 {
4195 	rtwdev->hci.ops->recalc_int_mit(rtwdev);
4196 }
4197 
4198 static inline u32 rtw89_hci_check_and_reclaim_tx_resource(struct rtw89_dev *rtwdev, u8 txch)
4199 {
4200 	return rtwdev->hci.ops->check_and_reclaim_tx_resource(rtwdev, txch);
4201 }
4202 
4203 static inline void rtw89_hci_tx_kick_off(struct rtw89_dev *rtwdev, u8 txch)
4204 {
4205 	return rtwdev->hci.ops->tx_kick_off(rtwdev, txch);
4206 }
4207 
4208 static inline void rtw89_hci_flush_queues(struct rtw89_dev *rtwdev, u32 queues,
4209 					  bool drop)
4210 {
4211 	if (!test_bit(RTW89_FLAG_POWERON, rtwdev->flags))
4212 		return;
4213 
4214 	if (rtwdev->hci.ops->flush_queues)
4215 		return rtwdev->hci.ops->flush_queues(rtwdev, queues, drop);
4216 }
4217 
4218 static inline void rtw89_hci_recovery_start(struct rtw89_dev *rtwdev)
4219 {
4220 	if (rtwdev->hci.ops->recovery_start)
4221 		rtwdev->hci.ops->recovery_start(rtwdev);
4222 }
4223 
4224 static inline void rtw89_hci_recovery_complete(struct rtw89_dev *rtwdev)
4225 {
4226 	if (rtwdev->hci.ops->recovery_complete)
4227 		rtwdev->hci.ops->recovery_complete(rtwdev);
4228 }
4229 
4230 static inline void rtw89_hci_enable_intr(struct rtw89_dev *rtwdev)
4231 {
4232 	if (rtwdev->hci.ops->enable_intr)
4233 		rtwdev->hci.ops->enable_intr(rtwdev);
4234 }
4235 
4236 static inline void rtw89_hci_disable_intr(struct rtw89_dev *rtwdev)
4237 {
4238 	if (rtwdev->hci.ops->disable_intr)
4239 		rtwdev->hci.ops->disable_intr(rtwdev);
4240 }
4241 
4242 static inline void rtw89_hci_ctrl_txdma_ch(struct rtw89_dev *rtwdev, bool enable)
4243 {
4244 	if (rtwdev->hci.ops->ctrl_txdma_ch)
4245 		rtwdev->hci.ops->ctrl_txdma_ch(rtwdev, enable);
4246 }
4247 
4248 static inline void rtw89_hci_ctrl_txdma_fw_ch(struct rtw89_dev *rtwdev, bool enable)
4249 {
4250 	if (rtwdev->hci.ops->ctrl_txdma_fw_ch)
4251 		rtwdev->hci.ops->ctrl_txdma_fw_ch(rtwdev, enable);
4252 }
4253 
4254 static inline void rtw89_hci_ctrl_trxhci(struct rtw89_dev *rtwdev, bool enable)
4255 {
4256 	if (rtwdev->hci.ops->ctrl_trxhci)
4257 		rtwdev->hci.ops->ctrl_trxhci(rtwdev, enable);
4258 }
4259 
4260 static inline int rtw89_hci_poll_txdma_ch(struct rtw89_dev *rtwdev)
4261 {
4262 	int ret = 0;
4263 
4264 	if (rtwdev->hci.ops->poll_txdma_ch)
4265 		ret = rtwdev->hci.ops->poll_txdma_ch(rtwdev);
4266 	return ret;
4267 }
4268 
4269 static inline void rtw89_hci_clr_idx_all(struct rtw89_dev *rtwdev)
4270 {
4271 	if (rtwdev->hci.ops->clr_idx_all)
4272 		rtwdev->hci.ops->clr_idx_all(rtwdev);
4273 }
4274 
4275 static inline int rtw89_hci_rst_bdram(struct rtw89_dev *rtwdev)
4276 {
4277 	int ret = 0;
4278 
4279 	if (rtwdev->hci.ops->rst_bdram)
4280 		ret = rtwdev->hci.ops->rst_bdram(rtwdev);
4281 	return ret;
4282 }
4283 
4284 static inline void rtw89_hci_clear(struct rtw89_dev *rtwdev, struct pci_dev *pdev)
4285 {
4286 	if (rtwdev->hci.ops->clear)
4287 		rtwdev->hci.ops->clear(rtwdev, pdev);
4288 }
4289 
4290 static inline
4291 struct rtw89_tx_skb_data *RTW89_TX_SKB_CB(struct sk_buff *skb)
4292 {
4293 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4294 
4295 	return (struct rtw89_tx_skb_data *)info->status.status_driver_data;
4296 }
4297 
4298 static inline u8 rtw89_read8(struct rtw89_dev *rtwdev, u32 addr)
4299 {
4300 	return rtwdev->hci.ops->read8(rtwdev, addr);
4301 }
4302 
4303 static inline u16 rtw89_read16(struct rtw89_dev *rtwdev, u32 addr)
4304 {
4305 	return rtwdev->hci.ops->read16(rtwdev, addr);
4306 }
4307 
4308 static inline u32 rtw89_read32(struct rtw89_dev *rtwdev, u32 addr)
4309 {
4310 	return rtwdev->hci.ops->read32(rtwdev, addr);
4311 }
4312 
4313 static inline void rtw89_write8(struct rtw89_dev *rtwdev, u32 addr, u8 data)
4314 {
4315 	rtwdev->hci.ops->write8(rtwdev, addr, data);
4316 }
4317 
4318 static inline void rtw89_write16(struct rtw89_dev *rtwdev, u32 addr, u16 data)
4319 {
4320 	rtwdev->hci.ops->write16(rtwdev, addr, data);
4321 }
4322 
4323 static inline void rtw89_write32(struct rtw89_dev *rtwdev, u32 addr, u32 data)
4324 {
4325 	rtwdev->hci.ops->write32(rtwdev, addr, data);
4326 }
4327 
4328 static inline void
4329 rtw89_write8_set(struct rtw89_dev *rtwdev, u32 addr, u8 bit)
4330 {
4331 	u8 val;
4332 
4333 	val = rtw89_read8(rtwdev, addr);
4334 	rtw89_write8(rtwdev, addr, val | bit);
4335 }
4336 
4337 static inline void
4338 rtw89_write16_set(struct rtw89_dev *rtwdev, u32 addr, u16 bit)
4339 {
4340 	u16 val;
4341 
4342 	val = rtw89_read16(rtwdev, addr);
4343 	rtw89_write16(rtwdev, addr, val | bit);
4344 }
4345 
4346 static inline void
4347 rtw89_write32_set(struct rtw89_dev *rtwdev, u32 addr, u32 bit)
4348 {
4349 	u32 val;
4350 
4351 	val = rtw89_read32(rtwdev, addr);
4352 	rtw89_write32(rtwdev, addr, val | bit);
4353 }
4354 
4355 static inline void
4356 rtw89_write8_clr(struct rtw89_dev *rtwdev, u32 addr, u8 bit)
4357 {
4358 	u8 val;
4359 
4360 	val = rtw89_read8(rtwdev, addr);
4361 	rtw89_write8(rtwdev, addr, val & ~bit);
4362 }
4363 
4364 static inline void
4365 rtw89_write16_clr(struct rtw89_dev *rtwdev, u32 addr, u16 bit)
4366 {
4367 	u16 val;
4368 
4369 	val = rtw89_read16(rtwdev, addr);
4370 	rtw89_write16(rtwdev, addr, val & ~bit);
4371 }
4372 
4373 static inline void
4374 rtw89_write32_clr(struct rtw89_dev *rtwdev, u32 addr, u32 bit)
4375 {
4376 	u32 val;
4377 
4378 	val = rtw89_read32(rtwdev, addr);
4379 	rtw89_write32(rtwdev, addr, val & ~bit);
4380 }
4381 
4382 static inline u32
4383 rtw89_read32_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask)
4384 {
4385 	u32 shift = __ffs(mask);
4386 	u32 orig;
4387 	u32 ret;
4388 
4389 	orig = rtw89_read32(rtwdev, addr);
4390 	ret = (orig & mask) >> shift;
4391 
4392 	return ret;
4393 }
4394 
4395 static inline u16
4396 rtw89_read16_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask)
4397 {
4398 	u32 shift = __ffs(mask);
4399 	u32 orig;
4400 	u32 ret;
4401 
4402 	orig = rtw89_read16(rtwdev, addr);
4403 	ret = (orig & mask) >> shift;
4404 
4405 	return ret;
4406 }
4407 
4408 static inline u8
4409 rtw89_read8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask)
4410 {
4411 	u32 shift = __ffs(mask);
4412 	u32 orig;
4413 	u32 ret;
4414 
4415 	orig = rtw89_read8(rtwdev, addr);
4416 	ret = (orig & mask) >> shift;
4417 
4418 	return ret;
4419 }
4420 
4421 static inline void
4422 rtw89_write32_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u32 data)
4423 {
4424 	u32 shift = __ffs(mask);
4425 	u32 orig;
4426 	u32 set;
4427 
4428 	WARN(addr & 0x3, "should be 4-byte aligned, addr = 0x%08x\n", addr);
4429 
4430 	orig = rtw89_read32(rtwdev, addr);
4431 	set = (orig & ~mask) | ((data << shift) & mask);
4432 	rtw89_write32(rtwdev, addr, set);
4433 }
4434 
4435 static inline void
4436 rtw89_write16_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u16 data)
4437 {
4438 	u32 shift;
4439 	u16 orig, set;
4440 
4441 	mask &= 0xffff;
4442 	shift = __ffs(mask);
4443 
4444 	orig = rtw89_read16(rtwdev, addr);
4445 	set = (orig & ~mask) | ((data << shift) & mask);
4446 	rtw89_write16(rtwdev, addr, set);
4447 }
4448 
4449 static inline void
4450 rtw89_write8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u8 data)
4451 {
4452 	u32 shift;
4453 	u8 orig, set;
4454 
4455 	mask &= 0xff;
4456 	shift = __ffs(mask);
4457 
4458 	orig = rtw89_read8(rtwdev, addr);
4459 	set = (orig & ~mask) | ((data << shift) & mask);
4460 	rtw89_write8(rtwdev, addr, set);
4461 }
4462 
4463 static inline u32
4464 rtw89_read_rf(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
4465 	      u32 addr, u32 mask)
4466 {
4467 	u32 val;
4468 
4469 	mutex_lock(&rtwdev->rf_mutex);
4470 	val = rtwdev->chip->ops->read_rf(rtwdev, rf_path, addr, mask);
4471 	mutex_unlock(&rtwdev->rf_mutex);
4472 
4473 	return val;
4474 }
4475 
4476 static inline void
4477 rtw89_write_rf(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
4478 	       u32 addr, u32 mask, u32 data)
4479 {
4480 	mutex_lock(&rtwdev->rf_mutex);
4481 	rtwdev->chip->ops->write_rf(rtwdev, rf_path, addr, mask, data);
4482 	mutex_unlock(&rtwdev->rf_mutex);
4483 }
4484 
4485 static inline struct ieee80211_txq *rtw89_txq_to_txq(struct rtw89_txq *rtwtxq)
4486 {
4487 	void *p = rtwtxq;
4488 
4489 	return container_of(p, struct ieee80211_txq, drv_priv);
4490 }
4491 
4492 static inline void rtw89_core_txq_init(struct rtw89_dev *rtwdev,
4493 				       struct ieee80211_txq *txq)
4494 {
4495 	struct rtw89_txq *rtwtxq;
4496 
4497 	if (!txq)
4498 		return;
4499 
4500 	rtwtxq = (struct rtw89_txq *)txq->drv_priv;
4501 	INIT_LIST_HEAD(&rtwtxq->list);
4502 }
4503 
4504 static inline struct ieee80211_vif *rtwvif_to_vif(struct rtw89_vif *rtwvif)
4505 {
4506 	void *p = rtwvif;
4507 
4508 	return container_of(p, struct ieee80211_vif, drv_priv);
4509 }
4510 
4511 static inline struct ieee80211_vif *rtwvif_to_vif_safe(struct rtw89_vif *rtwvif)
4512 {
4513 	return rtwvif ? rtwvif_to_vif(rtwvif) : NULL;
4514 }
4515 
4516 static inline struct rtw89_vif *vif_to_rtwvif_safe(struct ieee80211_vif *vif)
4517 {
4518 	return vif ? (struct rtw89_vif *)vif->drv_priv : NULL;
4519 }
4520 
4521 static inline struct ieee80211_sta *rtwsta_to_sta(struct rtw89_sta *rtwsta)
4522 {
4523 	void *p = rtwsta;
4524 
4525 	return container_of(p, struct ieee80211_sta, drv_priv);
4526 }
4527 
4528 static inline struct ieee80211_sta *rtwsta_to_sta_safe(struct rtw89_sta *rtwsta)
4529 {
4530 	return rtwsta ? rtwsta_to_sta(rtwsta) : NULL;
4531 }
4532 
4533 static inline struct rtw89_sta *sta_to_rtwsta_safe(struct ieee80211_sta *sta)
4534 {
4535 	return sta ? (struct rtw89_sta *)sta->drv_priv : NULL;
4536 }
4537 
4538 static inline u8 rtw89_hw_to_rate_info_bw(enum rtw89_bandwidth hw_bw)
4539 {
4540 	if (hw_bw == RTW89_CHANNEL_WIDTH_160)
4541 		return RATE_INFO_BW_160;
4542 	else if (hw_bw == RTW89_CHANNEL_WIDTH_80)
4543 		return RATE_INFO_BW_80;
4544 	else if (hw_bw == RTW89_CHANNEL_WIDTH_40)
4545 		return RATE_INFO_BW_40;
4546 	else
4547 		return RATE_INFO_BW_20;
4548 }
4549 
4550 static inline
4551 enum nl80211_band rtw89_hw_to_nl80211_band(enum rtw89_band hw_band)
4552 {
4553 	switch (hw_band) {
4554 	default:
4555 	case RTW89_BAND_2G:
4556 		return NL80211_BAND_2GHZ;
4557 	case RTW89_BAND_5G:
4558 		return NL80211_BAND_5GHZ;
4559 	case RTW89_BAND_6G:
4560 		return NL80211_BAND_6GHZ;
4561 	}
4562 }
4563 
4564 static inline
4565 enum rtw89_band rtw89_nl80211_to_hw_band(enum nl80211_band nl_band)
4566 {
4567 	switch (nl_band) {
4568 	default:
4569 	case NL80211_BAND_2GHZ:
4570 		return RTW89_BAND_2G;
4571 	case NL80211_BAND_5GHZ:
4572 		return RTW89_BAND_5G;
4573 	case NL80211_BAND_6GHZ:
4574 		return RTW89_BAND_6G;
4575 	}
4576 }
4577 
4578 static inline
4579 enum rtw89_bandwidth nl_to_rtw89_bandwidth(enum nl80211_chan_width width)
4580 {
4581 	switch (width) {
4582 	default:
4583 		WARN(1, "Not support bandwidth %d\n", width);
4584 		fallthrough;
4585 	case NL80211_CHAN_WIDTH_20_NOHT:
4586 	case NL80211_CHAN_WIDTH_20:
4587 		return RTW89_CHANNEL_WIDTH_20;
4588 	case NL80211_CHAN_WIDTH_40:
4589 		return RTW89_CHANNEL_WIDTH_40;
4590 	case NL80211_CHAN_WIDTH_80:
4591 		return RTW89_CHANNEL_WIDTH_80;
4592 	case NL80211_CHAN_WIDTH_160:
4593 		return RTW89_CHANNEL_WIDTH_160;
4594 	}
4595 }
4596 
4597 static inline
4598 struct rtw89_addr_cam_entry *rtw89_get_addr_cam_of(struct rtw89_vif *rtwvif,
4599 						   struct rtw89_sta *rtwsta)
4600 {
4601 	if (rtwsta) {
4602 		struct ieee80211_sta *sta = rtwsta_to_sta(rtwsta);
4603 
4604 		if (rtwvif->net_type == RTW89_NET_TYPE_AP_MODE || sta->tdls)
4605 			return &rtwsta->addr_cam;
4606 	}
4607 	return &rtwvif->addr_cam;
4608 }
4609 
4610 static inline
4611 struct rtw89_bssid_cam_entry *rtw89_get_bssid_cam_of(struct rtw89_vif *rtwvif,
4612 						     struct rtw89_sta *rtwsta)
4613 {
4614 	if (rtwsta) {
4615 		struct ieee80211_sta *sta = rtwsta_to_sta(rtwsta);
4616 
4617 		if (sta->tdls)
4618 			return &rtwsta->bssid_cam;
4619 	}
4620 	return &rtwvif->bssid_cam;
4621 }
4622 
4623 static inline
4624 void rtw89_chip_set_channel_prepare(struct rtw89_dev *rtwdev,
4625 				    struct rtw89_channel_help_params *p,
4626 				    const struct rtw89_chan *chan,
4627 				    enum rtw89_mac_idx mac_idx,
4628 				    enum rtw89_phy_idx phy_idx)
4629 {
4630 	rtwdev->chip->ops->set_channel_help(rtwdev, true, p, chan,
4631 					    mac_idx, phy_idx);
4632 }
4633 
4634 static inline
4635 void rtw89_chip_set_channel_done(struct rtw89_dev *rtwdev,
4636 				 struct rtw89_channel_help_params *p,
4637 				 const struct rtw89_chan *chan,
4638 				 enum rtw89_mac_idx mac_idx,
4639 				 enum rtw89_phy_idx phy_idx)
4640 {
4641 	rtwdev->chip->ops->set_channel_help(rtwdev, false, p, chan,
4642 					    mac_idx, phy_idx);
4643 }
4644 
4645 static inline
4646 const struct cfg80211_chan_def *rtw89_chandef_get(struct rtw89_dev *rtwdev,
4647 						  enum rtw89_sub_entity_idx idx)
4648 {
4649 	struct rtw89_hal *hal = &rtwdev->hal;
4650 	enum rtw89_sub_entity_idx roc_idx = atomic_read(&hal->roc_entity_idx);
4651 
4652 	if (roc_idx == idx)
4653 		return &hal->roc_chandef;
4654 
4655 	return &hal->sub[idx].chandef;
4656 }
4657 
4658 static inline
4659 const struct rtw89_chan *rtw89_chan_get(struct rtw89_dev *rtwdev,
4660 					enum rtw89_sub_entity_idx idx)
4661 {
4662 	struct rtw89_hal *hal = &rtwdev->hal;
4663 
4664 	return &hal->sub[idx].chan;
4665 }
4666 
4667 static inline
4668 const struct rtw89_chan_rcd *rtw89_chan_rcd_get(struct rtw89_dev *rtwdev,
4669 						enum rtw89_sub_entity_idx idx)
4670 {
4671 	struct rtw89_hal *hal = &rtwdev->hal;
4672 
4673 	return &hal->sub[idx].rcd;
4674 }
4675 
4676 static inline void rtw89_chip_fem_setup(struct rtw89_dev *rtwdev)
4677 {
4678 	const struct rtw89_chip_info *chip = rtwdev->chip;
4679 
4680 	if (chip->ops->fem_setup)
4681 		chip->ops->fem_setup(rtwdev);
4682 }
4683 
4684 static inline void rtw89_chip_rfe_gpio(struct rtw89_dev *rtwdev)
4685 {
4686 	const struct rtw89_chip_info *chip = rtwdev->chip;
4687 
4688 	if (chip->ops->rfe_gpio)
4689 		chip->ops->rfe_gpio(rtwdev);
4690 }
4691 
4692 static inline void rtw89_chip_bb_sethw(struct rtw89_dev *rtwdev)
4693 {
4694 	const struct rtw89_chip_info *chip = rtwdev->chip;
4695 
4696 	if (chip->ops->bb_sethw)
4697 		chip->ops->bb_sethw(rtwdev);
4698 }
4699 
4700 static inline void rtw89_chip_rfk_init(struct rtw89_dev *rtwdev)
4701 {
4702 	const struct rtw89_chip_info *chip = rtwdev->chip;
4703 
4704 	if (chip->ops->rfk_init)
4705 		chip->ops->rfk_init(rtwdev);
4706 }
4707 
4708 static inline void rtw89_chip_rfk_channel(struct rtw89_dev *rtwdev)
4709 {
4710 	const struct rtw89_chip_info *chip = rtwdev->chip;
4711 
4712 	if (chip->ops->rfk_channel)
4713 		chip->ops->rfk_channel(rtwdev);
4714 }
4715 
4716 static inline void rtw89_chip_rfk_band_changed(struct rtw89_dev *rtwdev,
4717 					       enum rtw89_phy_idx phy_idx)
4718 {
4719 	const struct rtw89_chip_info *chip = rtwdev->chip;
4720 
4721 	if (chip->ops->rfk_band_changed)
4722 		chip->ops->rfk_band_changed(rtwdev, phy_idx);
4723 }
4724 
4725 static inline void rtw89_chip_rfk_scan(struct rtw89_dev *rtwdev, bool start)
4726 {
4727 	const struct rtw89_chip_info *chip = rtwdev->chip;
4728 
4729 	if (chip->ops->rfk_scan)
4730 		chip->ops->rfk_scan(rtwdev, start);
4731 }
4732 
4733 static inline void rtw89_chip_rfk_track(struct rtw89_dev *rtwdev)
4734 {
4735 	const struct rtw89_chip_info *chip = rtwdev->chip;
4736 
4737 	if (chip->ops->rfk_track)
4738 		chip->ops->rfk_track(rtwdev);
4739 }
4740 
4741 static inline void rtw89_chip_set_txpwr_ctrl(struct rtw89_dev *rtwdev)
4742 {
4743 	const struct rtw89_chip_info *chip = rtwdev->chip;
4744 
4745 	if (chip->ops->set_txpwr_ctrl)
4746 		chip->ops->set_txpwr_ctrl(rtwdev,  RTW89_PHY_0);
4747 }
4748 
4749 static inline void rtw89_chip_power_trim(struct rtw89_dev *rtwdev)
4750 {
4751 	const struct rtw89_chip_info *chip = rtwdev->chip;
4752 
4753 	if (chip->ops->power_trim)
4754 		chip->ops->power_trim(rtwdev);
4755 }
4756 
4757 static inline void rtw89_chip_init_txpwr_unit(struct rtw89_dev *rtwdev,
4758 					      enum rtw89_phy_idx phy_idx)
4759 {
4760 	const struct rtw89_chip_info *chip = rtwdev->chip;
4761 
4762 	if (chip->ops->init_txpwr_unit)
4763 		chip->ops->init_txpwr_unit(rtwdev, phy_idx);
4764 }
4765 
4766 static inline u8 rtw89_chip_get_thermal(struct rtw89_dev *rtwdev,
4767 					enum rtw89_rf_path rf_path)
4768 {
4769 	const struct rtw89_chip_info *chip = rtwdev->chip;
4770 
4771 	if (!chip->ops->get_thermal)
4772 		return 0x10;
4773 
4774 	return chip->ops->get_thermal(rtwdev, rf_path);
4775 }
4776 
4777 static inline void rtw89_chip_query_ppdu(struct rtw89_dev *rtwdev,
4778 					 struct rtw89_rx_phy_ppdu *phy_ppdu,
4779 					 struct ieee80211_rx_status *status)
4780 {
4781 	const struct rtw89_chip_info *chip = rtwdev->chip;
4782 
4783 	if (chip->ops->query_ppdu)
4784 		chip->ops->query_ppdu(rtwdev, phy_ppdu, status);
4785 }
4786 
4787 static inline void rtw89_chip_bb_ctrl_btc_preagc(struct rtw89_dev *rtwdev,
4788 						 bool bt_en)
4789 {
4790 	const struct rtw89_chip_info *chip = rtwdev->chip;
4791 
4792 	if (chip->ops->bb_ctrl_btc_preagc)
4793 		chip->ops->bb_ctrl_btc_preagc(rtwdev, bt_en);
4794 }
4795 
4796 static inline void rtw89_chip_cfg_txrx_path(struct rtw89_dev *rtwdev)
4797 {
4798 	const struct rtw89_chip_info *chip = rtwdev->chip;
4799 
4800 	if (chip->ops->cfg_txrx_path)
4801 		chip->ops->cfg_txrx_path(rtwdev);
4802 }
4803 
4804 static inline
4805 void rtw89_chip_cfg_txpwr_ul_tb_offset(struct rtw89_dev *rtwdev,
4806 				       struct ieee80211_vif *vif)
4807 {
4808 	struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
4809 	const struct rtw89_chip_info *chip = rtwdev->chip;
4810 
4811 	if (!vif->bss_conf.he_support || !vif->cfg.assoc)
4812 		return;
4813 
4814 	if (chip->ops->set_txpwr_ul_tb_offset)
4815 		chip->ops->set_txpwr_ul_tb_offset(rtwdev, 0, rtwvif->mac_idx);
4816 }
4817 
4818 static inline void rtw89_load_txpwr_table(struct rtw89_dev *rtwdev,
4819 					  const struct rtw89_txpwr_table *tbl)
4820 {
4821 	tbl->load(rtwdev, tbl);
4822 }
4823 
4824 static inline u8 rtw89_regd_get(struct rtw89_dev *rtwdev, u8 band)
4825 {
4826 	const struct rtw89_regd *regd = rtwdev->regulatory.regd;
4827 
4828 	return regd->txpwr_regd[band];
4829 }
4830 
4831 static inline void rtw89_ctrl_btg(struct rtw89_dev *rtwdev, bool btg)
4832 {
4833 	const struct rtw89_chip_info *chip = rtwdev->chip;
4834 
4835 	if (chip->ops->ctrl_btg)
4836 		chip->ops->ctrl_btg(rtwdev, btg);
4837 }
4838 
4839 static inline
4840 void rtw89_chip_query_rxdesc(struct rtw89_dev *rtwdev,
4841 			     struct rtw89_rx_desc_info *desc_info,
4842 			     u8 *data, u32 data_offset)
4843 {
4844 	const struct rtw89_chip_info *chip = rtwdev->chip;
4845 
4846 	chip->ops->query_rxdesc(rtwdev, desc_info, data, data_offset);
4847 }
4848 
4849 static inline
4850 void rtw89_chip_fill_txdesc(struct rtw89_dev *rtwdev,
4851 			    struct rtw89_tx_desc_info *desc_info,
4852 			    void *txdesc)
4853 {
4854 	const struct rtw89_chip_info *chip = rtwdev->chip;
4855 
4856 	chip->ops->fill_txdesc(rtwdev, desc_info, txdesc);
4857 }
4858 
4859 static inline
4860 void rtw89_chip_fill_txdesc_fwcmd(struct rtw89_dev *rtwdev,
4861 				  struct rtw89_tx_desc_info *desc_info,
4862 				  void *txdesc)
4863 {
4864 	const struct rtw89_chip_info *chip = rtwdev->chip;
4865 
4866 	chip->ops->fill_txdesc_fwcmd(rtwdev, desc_info, txdesc);
4867 }
4868 
4869 static inline
4870 void rtw89_chip_mac_cfg_gnt(struct rtw89_dev *rtwdev,
4871 			    const struct rtw89_mac_ax_coex_gnt *gnt_cfg)
4872 {
4873 	const struct rtw89_chip_info *chip = rtwdev->chip;
4874 
4875 	chip->ops->mac_cfg_gnt(rtwdev, gnt_cfg);
4876 }
4877 
4878 static inline void rtw89_chip_cfg_ctrl_path(struct rtw89_dev *rtwdev, bool wl)
4879 {
4880 	const struct rtw89_chip_info *chip = rtwdev->chip;
4881 
4882 	chip->ops->cfg_ctrl_path(rtwdev, wl);
4883 }
4884 
4885 static inline
4886 int rtw89_chip_stop_sch_tx(struct rtw89_dev *rtwdev, u8 mac_idx,
4887 			   u32 *tx_en, enum rtw89_sch_tx_sel sel)
4888 {
4889 	const struct rtw89_chip_info *chip = rtwdev->chip;
4890 
4891 	return chip->ops->stop_sch_tx(rtwdev, mac_idx, tx_en, sel);
4892 }
4893 
4894 static inline
4895 int rtw89_chip_resume_sch_tx(struct rtw89_dev *rtwdev, u8 mac_idx, u32 tx_en)
4896 {
4897 	const struct rtw89_chip_info *chip = rtwdev->chip;
4898 
4899 	return chip->ops->resume_sch_tx(rtwdev, mac_idx, tx_en);
4900 }
4901 
4902 static inline
4903 int rtw89_chip_h2c_dctl_sec_cam(struct rtw89_dev *rtwdev,
4904 				struct rtw89_vif *rtwvif,
4905 				struct rtw89_sta *rtwsta)
4906 {
4907 	const struct rtw89_chip_info *chip = rtwdev->chip;
4908 
4909 	if (!chip->ops->h2c_dctl_sec_cam)
4910 		return 0;
4911 	return chip->ops->h2c_dctl_sec_cam(rtwdev, rtwvif, rtwsta);
4912 }
4913 
4914 static inline u8 *get_hdr_bssid(struct ieee80211_hdr *hdr)
4915 {
4916 	__le16 fc = hdr->frame_control;
4917 
4918 	if (ieee80211_has_tods(fc))
4919 		return hdr->addr1;
4920 	else if (ieee80211_has_fromds(fc))
4921 		return hdr->addr2;
4922 	else
4923 		return hdr->addr3;
4924 }
4925 
4926 static inline bool rtw89_sta_has_beamformer_cap(struct ieee80211_sta *sta)
4927 {
4928 	if ((sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) ||
4929 	    (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) ||
4930 	    (sta->deflink.he_cap.he_cap_elem.phy_cap_info[3] &
4931 			IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER) ||
4932 	    (sta->deflink.he_cap.he_cap_elem.phy_cap_info[4] &
4933 			IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER))
4934 		return true;
4935 	return false;
4936 }
4937 
4938 static inline struct rtw89_fw_suit *rtw89_fw_suit_get(struct rtw89_dev *rtwdev,
4939 						      enum rtw89_fw_type type)
4940 {
4941 	struct rtw89_fw_info *fw_info = &rtwdev->fw;
4942 
4943 	if (type == RTW89_FW_WOWLAN)
4944 		return &fw_info->wowlan;
4945 	return &fw_info->normal;
4946 }
4947 
4948 static inline struct sk_buff *rtw89_alloc_skb_for_rx(struct rtw89_dev *rtwdev,
4949 						     unsigned int length)
4950 {
4951 	struct sk_buff *skb;
4952 
4953 	if (rtwdev->hw->conf.flags & IEEE80211_CONF_MONITOR) {
4954 		skb = dev_alloc_skb(length + RTW89_RADIOTAP_ROOM);
4955 		if (!skb)
4956 			return NULL;
4957 
4958 		skb_reserve(skb, RTW89_RADIOTAP_ROOM);
4959 		return skb;
4960 	}
4961 
4962 	return dev_alloc_skb(length);
4963 }
4964 
4965 static inline void rtw89_core_tx_wait_complete(struct rtw89_dev *rtwdev,
4966 					       struct rtw89_tx_skb_data *skb_data,
4967 					       bool tx_done)
4968 {
4969 	struct rtw89_tx_wait_info *wait;
4970 
4971 	rcu_read_lock();
4972 
4973 	wait = rcu_dereference(skb_data->wait);
4974 	if (!wait)
4975 		goto out;
4976 
4977 	wait->tx_done = tx_done;
4978 	complete(&wait->completion);
4979 
4980 out:
4981 	rcu_read_unlock();
4982 }
4983 
4984 int rtw89_core_tx_write(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif,
4985 			struct ieee80211_sta *sta, struct sk_buff *skb, int *qsel);
4986 int rtw89_h2c_tx(struct rtw89_dev *rtwdev,
4987 		 struct sk_buff *skb, bool fwdl);
4988 void rtw89_core_tx_kick_off(struct rtw89_dev *rtwdev, u8 qsel);
4989 int rtw89_core_tx_kick_off_and_wait(struct rtw89_dev *rtwdev, struct sk_buff *skb,
4990 				    int qsel, unsigned int timeout);
4991 void rtw89_core_fill_txdesc(struct rtw89_dev *rtwdev,
4992 			    struct rtw89_tx_desc_info *desc_info,
4993 			    void *txdesc);
4994 void rtw89_core_fill_txdesc_v1(struct rtw89_dev *rtwdev,
4995 			       struct rtw89_tx_desc_info *desc_info,
4996 			       void *txdesc);
4997 void rtw89_core_fill_txdesc_fwcmd_v1(struct rtw89_dev *rtwdev,
4998 				     struct rtw89_tx_desc_info *desc_info,
4999 				     void *txdesc);
5000 void rtw89_core_rx(struct rtw89_dev *rtwdev,
5001 		   struct rtw89_rx_desc_info *desc_info,
5002 		   struct sk_buff *skb);
5003 void rtw89_core_query_rxdesc(struct rtw89_dev *rtwdev,
5004 			     struct rtw89_rx_desc_info *desc_info,
5005 			     u8 *data, u32 data_offset);
5006 void rtw89_core_napi_start(struct rtw89_dev *rtwdev);
5007 void rtw89_core_napi_stop(struct rtw89_dev *rtwdev);
5008 void rtw89_core_napi_init(struct rtw89_dev *rtwdev);
5009 void rtw89_core_napi_deinit(struct rtw89_dev *rtwdev);
5010 int rtw89_core_sta_add(struct rtw89_dev *rtwdev,
5011 		       struct ieee80211_vif *vif,
5012 		       struct ieee80211_sta *sta);
5013 int rtw89_core_sta_assoc(struct rtw89_dev *rtwdev,
5014 			 struct ieee80211_vif *vif,
5015 			 struct ieee80211_sta *sta);
5016 int rtw89_core_sta_disassoc(struct rtw89_dev *rtwdev,
5017 			    struct ieee80211_vif *vif,
5018 			    struct ieee80211_sta *sta);
5019 int rtw89_core_sta_disconnect(struct rtw89_dev *rtwdev,
5020 			      struct ieee80211_vif *vif,
5021 			      struct ieee80211_sta *sta);
5022 int rtw89_core_sta_remove(struct rtw89_dev *rtwdev,
5023 			  struct ieee80211_vif *vif,
5024 			  struct ieee80211_sta *sta);
5025 void rtw89_core_set_tid_config(struct rtw89_dev *rtwdev,
5026 			       struct ieee80211_sta *sta,
5027 			       struct cfg80211_tid_config *tid_config);
5028 int rtw89_core_init(struct rtw89_dev *rtwdev);
5029 void rtw89_core_deinit(struct rtw89_dev *rtwdev);
5030 int rtw89_core_register(struct rtw89_dev *rtwdev);
5031 void rtw89_core_unregister(struct rtw89_dev *rtwdev);
5032 struct rtw89_dev *rtw89_alloc_ieee80211_hw(struct device *device,
5033 					   u32 bus_data_size,
5034 					   const struct rtw89_chip_info *chip);
5035 void rtw89_free_ieee80211_hw(struct rtw89_dev *rtwdev);
5036 void rtw89_core_set_chip_txpwr(struct rtw89_dev *rtwdev);
5037 void rtw89_get_default_chandef(struct cfg80211_chan_def *chandef);
5038 void rtw89_set_channel(struct rtw89_dev *rtwdev);
5039 void rtw89_get_channel(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
5040 		       struct rtw89_chan *chan);
5041 u8 rtw89_core_acquire_bit_map(unsigned long *addr, unsigned long size);
5042 void rtw89_core_release_bit_map(unsigned long *addr, u8 bit);
5043 void rtw89_core_release_all_bits_map(unsigned long *addr, unsigned int nbits);
5044 int rtw89_core_acquire_sta_ba_entry(struct rtw89_dev *rtwdev,
5045 				    struct rtw89_sta *rtwsta, u8 tid, u8 *cam_idx);
5046 int rtw89_core_release_sta_ba_entry(struct rtw89_dev *rtwdev,
5047 				    struct rtw89_sta *rtwsta, u8 tid, u8 *cam_idx);
5048 void rtw89_vif_type_mapping(struct ieee80211_vif *vif, bool assoc);
5049 int rtw89_chip_info_setup(struct rtw89_dev *rtwdev);
5050 bool rtw89_ra_report_to_bitrate(struct rtw89_dev *rtwdev, u8 rpt_rate, u16 *bitrate);
5051 int rtw89_regd_setup(struct rtw89_dev *rtwdev);
5052 int rtw89_regd_init(struct rtw89_dev *rtwdev,
5053 		    void (*reg_notifier)(struct wiphy *wiphy, struct regulatory_request *request));
5054 void rtw89_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request);
5055 void rtw89_traffic_stats_init(struct rtw89_dev *rtwdev,
5056 			      struct rtw89_traffic_stats *stats);
5057 int rtw89_wait_for_cond(struct rtw89_wait_info *wait, unsigned int cond);
5058 void rtw89_complete_cond(struct rtw89_wait_info *wait, unsigned int cond,
5059 			 const struct rtw89_completion_data *data);
5060 int rtw89_core_start(struct rtw89_dev *rtwdev);
5061 void rtw89_core_stop(struct rtw89_dev *rtwdev);
5062 void rtw89_core_update_beacon_work(struct work_struct *work);
5063 void rtw89_roc_work(struct work_struct *work);
5064 void rtw89_roc_start(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif);
5065 void rtw89_roc_end(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif);
5066 void rtw89_core_scan_start(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
5067 			   const u8 *mac_addr, bool hw_scan);
5068 void rtw89_core_scan_complete(struct rtw89_dev *rtwdev,
5069 			      struct ieee80211_vif *vif, bool hw_scan);
5070 void rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev,
5071 				 struct rtw89_vif *rtwvif, bool active);
5072 
5073 #endif
5074