1 /* SPDX-License-Identifier: ISC */ 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 4 #ifndef __MT7921_MCU_H 5 #define __MT7921_MCU_H 6 7 #include "../mt76_connac_mcu.h" 8 9 struct mt7921_mcu_txd { 10 __le32 txd[8]; 11 12 __le16 len; 13 __le16 pq_id; 14 15 u8 cid; 16 u8 pkt_type; 17 u8 set_query; /* FW don't care */ 18 u8 seq; 19 20 u8 uc_d2b0_rev; 21 u8 ext_cid; 22 u8 s2d_index; 23 u8 ext_cid_ack; 24 25 u32 reserved[5]; 26 } __packed __aligned(4); 27 28 /** 29 * struct mt7921_uni_txd - mcu command descriptor for firmware v3 30 * @txd: hardware descriptor 31 * @len: total length not including txd 32 * @cid: command identifier 33 * @pkt_type: must be 0xa0 (cmd packet by long format) 34 * @frag_n: fragment number 35 * @seq: sequence number 36 * @checksum: 0 mean there is no checksum 37 * @s2d_index: index for command source and destination 38 * Definition | value | note 39 * CMD_S2D_IDX_H2N | 0x00 | command from HOST to WM 40 * CMD_S2D_IDX_C2N | 0x01 | command from WA to WM 41 * CMD_S2D_IDX_H2C | 0x02 | command from HOST to WA 42 * CMD_S2D_IDX_H2N_AND_H2C | 0x03 | command from HOST to WA and WM 43 * 44 * @option: command option 45 * BIT[0]: UNI_CMD_OPT_BIT_ACK 46 * set to 1 to request a fw reply 47 * if UNI_CMD_OPT_BIT_0_ACK is set and UNI_CMD_OPT_BIT_2_SET_QUERY 48 * is set, mcu firmware will send response event EID = 0x01 49 * (UNI_EVENT_ID_CMD_RESULT) to the host. 50 * BIT[1]: UNI_CMD_OPT_BIT_UNI_CMD 51 * 0: original command 52 * 1: unified command 53 * BIT[2]: UNI_CMD_OPT_BIT_SET_QUERY 54 * 0: QUERY command 55 * 1: SET command 56 */ 57 struct mt7921_uni_txd { 58 __le32 txd[8]; 59 60 /* DW1 */ 61 __le16 len; 62 __le16 cid; 63 64 /* DW2 */ 65 u8 reserved; 66 u8 pkt_type; 67 u8 frag_n; 68 u8 seq; 69 70 /* DW3 */ 71 __le16 checksum; 72 u8 s2d_index; 73 u8 option; 74 75 /* DW4 */ 76 u8 reserved2[4]; 77 } __packed __aligned(4); 78 79 /* event table */ 80 enum { 81 MCU_EVENT_REG_ACCESS = 0x05, 82 MCU_EVENT_SCAN_DONE = 0x0d, 83 MCU_EVENT_BSS_ABSENCE = 0x11, 84 MCU_EVENT_BSS_BEACON_LOSS = 0x13, 85 MCU_EVENT_CH_PRIVILEGE = 0x18, 86 MCU_EVENT_SCHED_SCAN_DONE = 0x23, 87 MCU_EVENT_DBG_MSG = 0x27, 88 MCU_EVENT_COREDUMP = 0xf0, 89 }; 90 91 /* ext event table */ 92 enum { 93 MCU_EXT_EVENT_RATE_REPORT = 0x87, 94 }; 95 96 struct mt7921_mcu_rxd { 97 __le32 rxd[6]; 98 99 __le16 len; 100 __le16 pkt_type_id; 101 102 u8 eid; 103 u8 seq; 104 __le16 __rsv; 105 106 u8 ext_eid; 107 u8 __rsv1[2]; 108 u8 s2d_index; 109 }; 110 111 struct mt7921_mcu_eeprom_info { 112 __le32 addr; 113 __le32 valid; 114 u8 data[16]; 115 } __packed; 116 117 #define MT_RA_RATE_NSS GENMASK(8, 6) 118 #define MT_RA_RATE_MCS GENMASK(3, 0) 119 #define MT_RA_RATE_TX_MODE GENMASK(12, 9) 120 #define MT_RA_RATE_DCM_EN BIT(4) 121 #define MT_RA_RATE_BW GENMASK(14, 13) 122 123 #define MCU_PQ_ID(p, q) (((p) << 15) | ((q) << 10)) 124 #define MCU_PKT_ID 0xa0 125 126 enum { 127 MCU_Q_QUERY, 128 MCU_Q_SET, 129 MCU_Q_RESERVED, 130 MCU_Q_NA 131 }; 132 133 enum { 134 MCU_S2D_H2N, 135 MCU_S2D_C2N, 136 MCU_S2D_H2C, 137 MCU_S2D_H2CN 138 }; 139 140 struct mt7921_mcu_uni_event { 141 u8 cid; 142 u8 pad[3]; 143 __le32 status; /* 0: success, others: fail */ 144 } __packed; 145 146 enum { 147 PATCH_NOT_DL_SEM_FAIL, 148 PATCH_IS_DL, 149 PATCH_NOT_DL_SEM_SUCCESS, 150 PATCH_REL_SEM_SUCCESS 151 }; 152 153 enum { 154 FW_STATE_INITIAL, 155 FW_STATE_FW_DOWNLOAD, 156 FW_STATE_NORMAL_OPERATION, 157 FW_STATE_NORMAL_TRX, 158 FW_STATE_WACPU_RDY = 7 159 }; 160 161 enum { 162 EE_MODE_EFUSE, 163 EE_MODE_BUFFER, 164 }; 165 166 enum { 167 EE_FORMAT_BIN, 168 EE_FORMAT_WHOLE, 169 EE_FORMAT_MULTIPLE, 170 }; 171 172 enum { 173 MCU_PHY_STATE_TX_RATE, 174 MCU_PHY_STATE_RX_RATE, 175 MCU_PHY_STATE_RSSI, 176 MCU_PHY_STATE_CONTENTION_RX_RATE, 177 MCU_PHY_STATE_OFDMLQ_CNINFO, 178 }; 179 180 #define STA_TYPE_STA BIT(0) 181 #define STA_TYPE_AP BIT(1) 182 #define STA_TYPE_ADHOC BIT(2) 183 #define STA_TYPE_WDS BIT(4) 184 #define STA_TYPE_BC BIT(5) 185 186 #define NETWORK_INFRA BIT(16) 187 #define NETWORK_P2P BIT(17) 188 #define NETWORK_IBSS BIT(18) 189 #define NETWORK_WDS BIT(21) 190 191 #define CONNECTION_INFRA_STA (STA_TYPE_STA | NETWORK_INFRA) 192 #define CONNECTION_INFRA_AP (STA_TYPE_AP | NETWORK_INFRA) 193 #define CONNECTION_P2P_GC (STA_TYPE_STA | NETWORK_P2P) 194 #define CONNECTION_P2P_GO (STA_TYPE_AP | NETWORK_P2P) 195 #define CONNECTION_IBSS_ADHOC (STA_TYPE_ADHOC | NETWORK_IBSS) 196 #define CONNECTION_WDS (STA_TYPE_WDS | NETWORK_WDS) 197 #define CONNECTION_INFRA_BC (STA_TYPE_BC | NETWORK_INFRA) 198 199 struct sec_key { 200 u8 cipher_id; 201 u8 cipher_len; 202 u8 key_id; 203 u8 key_len; 204 u8 key[32]; 205 } __packed; 206 207 struct sta_rec_sec { 208 __le16 tag; 209 __le16 len; 210 u8 add; 211 u8 n_cipher; 212 u8 rsv[2]; 213 214 struct sec_key key[2]; 215 } __packed; 216 217 enum mt7921_cipher_type { 218 MT_CIPHER_NONE, 219 MT_CIPHER_WEP40, 220 MT_CIPHER_WEP104, 221 MT_CIPHER_WEP128, 222 MT_CIPHER_TKIP, 223 MT_CIPHER_AES_CCMP, 224 MT_CIPHER_CCMP_256, 225 MT_CIPHER_GCMP, 226 MT_CIPHER_GCMP_256, 227 MT_CIPHER_WAPI, 228 MT_CIPHER_BIP_CMAC_128, 229 }; 230 231 enum { 232 CH_SWITCH_NORMAL = 0, 233 CH_SWITCH_SCAN = 3, 234 CH_SWITCH_MCC = 4, 235 CH_SWITCH_DFS = 5, 236 CH_SWITCH_BACKGROUND_SCAN_START = 6, 237 CH_SWITCH_BACKGROUND_SCAN_RUNNING = 7, 238 CH_SWITCH_BACKGROUND_SCAN_STOP = 8, 239 CH_SWITCH_SCAN_BYPASS_DPD = 9 240 }; 241 242 enum { 243 THERMAL_SENSOR_TEMP_QUERY, 244 THERMAL_SENSOR_MANUAL_CTRL, 245 THERMAL_SENSOR_INFO_QUERY, 246 THERMAL_SENSOR_TASK_CTRL, 247 }; 248 249 enum { 250 MT_EBF = BIT(0), /* explicit beamforming */ 251 MT_IBF = BIT(1) /* implicit beamforming */ 252 }; 253 254 #define MT7921_WTBL_UPDATE_MAX_SIZE (sizeof(struct wtbl_req_hdr) + \ 255 sizeof(struct wtbl_generic) + \ 256 sizeof(struct wtbl_rx) + \ 257 sizeof(struct wtbl_ht) + \ 258 sizeof(struct wtbl_vht) + \ 259 sizeof(struct wtbl_hdr_trans) +\ 260 sizeof(struct wtbl_ba) + \ 261 sizeof(struct wtbl_smps)) 262 263 #define MT7921_STA_UPDATE_MAX_SIZE (sizeof(struct sta_req_hdr) + \ 264 sizeof(struct sta_rec_basic) + \ 265 sizeof(struct sta_rec_ht) + \ 266 sizeof(struct sta_rec_he) + \ 267 sizeof(struct sta_rec_ba) + \ 268 sizeof(struct sta_rec_vht) + \ 269 sizeof(struct sta_rec_uapsd) + \ 270 sizeof(struct sta_rec_amsdu) + \ 271 sizeof(struct tlv) + \ 272 MT7921_WTBL_UPDATE_MAX_SIZE) 273 274 #define MT7921_WTBL_UPDATE_BA_SIZE (sizeof(struct wtbl_req_hdr) + \ 275 sizeof(struct wtbl_ba)) 276 277 #define STA_CAP_WMM BIT(0) 278 #define STA_CAP_SGI_20 BIT(4) 279 #define STA_CAP_SGI_40 BIT(5) 280 #define STA_CAP_TX_STBC BIT(6) 281 #define STA_CAP_RX_STBC BIT(7) 282 #define STA_CAP_VHT_SGI_80 BIT(16) 283 #define STA_CAP_VHT_SGI_160 BIT(17) 284 #define STA_CAP_VHT_TX_STBC BIT(18) 285 #define STA_CAP_VHT_RX_STBC BIT(19) 286 #define STA_CAP_VHT_LDPC BIT(23) 287 #define STA_CAP_LDPC BIT(24) 288 #define STA_CAP_HT BIT(26) 289 #define STA_CAP_VHT BIT(27) 290 #define STA_CAP_HE BIT(28) 291 292 struct mt7921_mcu_reg_event { 293 __le32 reg; 294 __le32 val; 295 } __packed; 296 297 struct mt7921_mcu_tx_config { 298 u8 peer_addr[ETH_ALEN]; 299 u8 sw; 300 u8 dis_rx_hdr_tran; 301 302 u8 aad_om; 303 u8 pfmu_idx; 304 __le16 partial_aid; 305 306 u8 ibf; 307 u8 ebf; 308 u8 is_ht; 309 u8 is_vht; 310 311 u8 mesh; 312 u8 baf_en; 313 u8 cf_ack; 314 u8 rdg_ba; 315 316 u8 rdg; 317 u8 pm; 318 u8 rts; 319 u8 smps; 320 321 u8 txop_ps; 322 u8 not_update_ipsm; 323 u8 skip_tx; 324 u8 ldpc; 325 326 u8 qos; 327 u8 from_ds; 328 u8 to_ds; 329 u8 dyn_bw; 330 331 u8 amdsu_cross_lg; 332 u8 check_per; 333 u8 gid_63; 334 u8 he; 335 336 u8 vht_ibf; 337 u8 vht_ebf; 338 u8 vht_ldpc; 339 u8 he_ldpc; 340 } __packed; 341 342 struct mt7921_mcu_sec_config { 343 u8 wpi_flag; 344 u8 rv; 345 u8 ikv; 346 u8 rkv; 347 348 u8 rcid; 349 u8 rca1; 350 u8 rca2; 351 u8 even_pn; 352 353 u8 key_id; 354 u8 muar_idx; 355 u8 cipher_suit; 356 u8 rsv[1]; 357 } __packed; 358 359 struct mt7921_mcu_key_config { 360 u8 key[32]; 361 } __packed; 362 363 struct mt7921_mcu_rate_info { 364 u8 mpdu_fail; 365 u8 mpdu_tx; 366 u8 rate_idx; 367 u8 rsv[1]; 368 __le16 rate[8]; 369 } __packed; 370 371 struct mt7921_mcu_ba_config { 372 u8 ba_en; 373 u8 rsv[3]; 374 __le32 ba_winsize; 375 } __packed; 376 377 struct mt7921_mcu_ant_id_config { 378 u8 ant_id[4]; 379 } __packed; 380 381 struct mt7921_mcu_peer_cap { 382 struct mt7921_mcu_ant_id_config ant_id_config; 383 384 u8 power_offset; 385 u8 bw_selector; 386 u8 change_bw_rate_n; 387 u8 bw; 388 u8 spe_idx; 389 390 u8 g2; 391 u8 g4; 392 u8 g8; 393 u8 g16; 394 395 u8 mmss; 396 u8 ampdu_factor; 397 u8 rsv[1]; 398 } __packed; 399 400 struct mt7921_mcu_rx_cnt { 401 u8 rx_rcpi[4]; 402 u8 rx_cc[4]; 403 u8 rx_cc_sel; 404 u8 ce_rmsd; 405 u8 rsv[2]; 406 } __packed; 407 408 struct mt7921_mcu_tx_cnt { 409 __le16 rate1_cnt; 410 __le16 rate1_fail_cnt; 411 __le16 rate2_cnt; 412 __le16 rate3_cnt; 413 __le16 cur_bw_tx_cnt; 414 __le16 cur_bw_tx_fail_cnt; 415 __le16 other_bw_tx_cnt; 416 __le16 other_bw_tx_fail_cnt; 417 } __packed; 418 419 struct mt7921_mcu_wlan_info_event { 420 struct mt7921_mcu_tx_config tx_config; 421 struct mt7921_mcu_sec_config sec_config; 422 struct mt7921_mcu_key_config key_config; 423 struct mt7921_mcu_rate_info rate_info; 424 struct mt7921_mcu_ba_config ba_config; 425 struct mt7921_mcu_peer_cap peer_cap; 426 struct mt7921_mcu_rx_cnt rx_cnt; 427 struct mt7921_mcu_tx_cnt tx_cnt; 428 } __packed; 429 430 struct mt7921_mcu_wlan_info { 431 __le32 wlan_idx; 432 struct mt7921_mcu_wlan_info_event event; 433 } __packed; 434 #endif 435