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