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 }; 89 90 /* ext event table */ 91 enum { 92 MCU_EXT_EVENT_RATE_REPORT = 0x87, 93 }; 94 95 struct mt7921_mcu_rxd { 96 __le32 rxd[6]; 97 98 __le16 len; 99 __le16 pkt_type_id; 100 101 u8 eid; 102 u8 seq; 103 __le16 __rsv; 104 105 u8 ext_eid; 106 u8 __rsv1[2]; 107 u8 s2d_index; 108 }; 109 110 struct mt7921_mcu_eeprom_info { 111 __le32 addr; 112 __le32 valid; 113 u8 data[16]; 114 } __packed; 115 116 #define MT_RA_RATE_NSS GENMASK(8, 6) 117 #define MT_RA_RATE_MCS GENMASK(3, 0) 118 #define MT_RA_RATE_TX_MODE GENMASK(12, 9) 119 #define MT_RA_RATE_DCM_EN BIT(4) 120 #define MT_RA_RATE_BW GENMASK(14, 13) 121 122 #define MCU_PQ_ID(p, q) (((p) << 15) | ((q) << 10)) 123 #define MCU_PKT_ID 0xa0 124 125 enum { 126 MCU_Q_QUERY, 127 MCU_Q_SET, 128 MCU_Q_RESERVED, 129 MCU_Q_NA 130 }; 131 132 enum { 133 MCU_S2D_H2N, 134 MCU_S2D_C2N, 135 MCU_S2D_H2C, 136 MCU_S2D_H2CN 137 }; 138 139 struct mt7921_mcu_uni_event { 140 u8 cid; 141 u8 pad[3]; 142 __le32 status; /* 0: success, others: fail */ 143 } __packed; 144 145 struct mt7921_wow_ctrl_tlv { 146 __le16 tag; 147 __le16 len; 148 u8 cmd; /* 0x1: PM_WOWLAN_REQ_START 149 * 0x2: PM_WOWLAN_REQ_STOP 150 * 0x3: PM_WOWLAN_PARAM_CLEAR 151 */ 152 u8 trigger; /* 0: NONE 153 * BIT(0): NL80211_WOWLAN_TRIG_MAGIC_PKT 154 * BIT(1): NL80211_WOWLAN_TRIG_ANY 155 * BIT(2): NL80211_WOWLAN_TRIG_DISCONNECT 156 * BIT(3): NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE 157 * BIT(4): BEACON_LOST 158 * BIT(5): NL80211_WOWLAN_TRIG_NET_DETECT 159 */ 160 u8 wakeup_hif; /* 0x0: HIF_SDIO 161 * 0x1: HIF_USB 162 * 0x2: HIF_PCIE 163 * 0x3: HIF_GPIO 164 */ 165 u8 pad; 166 u8 rsv[4]; 167 } __packed; 168 169 struct mt7921_wow_gpio_param_tlv { 170 __le16 tag; 171 __le16 len; 172 u8 gpio_pin; 173 u8 trigger_lvl; 174 u8 pad[2]; 175 __le32 gpio_interval; 176 u8 rsv[4]; 177 } __packed; 178 179 #define MT7921_WOW_MASK_MAX_LEN 16 180 #define MT7921_WOW_PATTEN_MAX_LEN 128 181 struct mt7921_wow_pattern_tlv { 182 __le16 tag; 183 __le16 len; 184 u8 index; /* pattern index */ 185 u8 enable; /* 0: disable 186 * 1: enable 187 */ 188 u8 data_len; /* pattern length */ 189 u8 pad; 190 u8 mask[MT7921_WOW_MASK_MAX_LEN]; 191 u8 pattern[MT7921_WOW_PATTEN_MAX_LEN]; 192 u8 rsv[4]; 193 } __packed; 194 195 struct mt7921_suspend_tlv { 196 __le16 tag; 197 __le16 len; 198 u8 enable; /* 0: suspend mode disabled 199 * 1: suspend mode enabled 200 */ 201 u8 mdtim; /* LP parameter */ 202 u8 wow_suspend; /* 0: update by origin policy 203 * 1: update by wow dtim 204 */ 205 u8 pad[5]; 206 } __packed; 207 208 struct mt7921_gtk_rekey_tlv { 209 __le16 tag; 210 __le16 len; 211 u8 kek[NL80211_KEK_LEN]; 212 u8 kck[NL80211_KCK_LEN]; 213 u8 replay_ctr[NL80211_REPLAY_CTR_LEN]; 214 u8 rekey_mode; /* 0: rekey offload enable 215 * 1: rekey offload disable 216 * 2: rekey update 217 */ 218 u8 keyid; 219 u8 pad[2]; 220 __le32 proto; /* WPA-RSN-WAPI-OPSN */ 221 __le32 pairwise_cipher; 222 __le32 group_cipher; 223 __le32 key_mgmt; /* NONE-PSK-IEEE802.1X */ 224 __le32 mgmt_group_cipher; 225 u8 option; /* 1: rekey data update without enabling offload */ 226 u8 reserverd[3]; 227 } __packed; 228 229 struct mt7921_arpns_tlv { 230 __le16 tag; 231 __le16 len; 232 u8 mode; 233 u8 ips_num; 234 u8 option; 235 u8 pad[1]; 236 } __packed; 237 238 enum { 239 PATCH_NOT_DL_SEM_FAIL, 240 PATCH_IS_DL, 241 PATCH_NOT_DL_SEM_SUCCESS, 242 PATCH_REL_SEM_SUCCESS 243 }; 244 245 enum { 246 FW_STATE_INITIAL, 247 FW_STATE_FW_DOWNLOAD, 248 FW_STATE_NORMAL_OPERATION, 249 FW_STATE_NORMAL_TRX, 250 FW_STATE_WACPU_RDY = 7 251 }; 252 253 enum { 254 EE_MODE_EFUSE, 255 EE_MODE_BUFFER, 256 }; 257 258 enum { 259 EE_FORMAT_BIN, 260 EE_FORMAT_WHOLE, 261 EE_FORMAT_MULTIPLE, 262 }; 263 264 enum { 265 MCU_PHY_STATE_TX_RATE, 266 MCU_PHY_STATE_RX_RATE, 267 MCU_PHY_STATE_RSSI, 268 MCU_PHY_STATE_CONTENTION_RX_RATE, 269 MCU_PHY_STATE_OFDMLQ_CNINFO, 270 }; 271 272 #define STA_TYPE_STA BIT(0) 273 #define STA_TYPE_AP BIT(1) 274 #define STA_TYPE_ADHOC BIT(2) 275 #define STA_TYPE_WDS BIT(4) 276 #define STA_TYPE_BC BIT(5) 277 278 #define NETWORK_INFRA BIT(16) 279 #define NETWORK_P2P BIT(17) 280 #define NETWORK_IBSS BIT(18) 281 #define NETWORK_WDS BIT(21) 282 283 #define CONNECTION_INFRA_STA (STA_TYPE_STA | NETWORK_INFRA) 284 #define CONNECTION_INFRA_AP (STA_TYPE_AP | NETWORK_INFRA) 285 #define CONNECTION_P2P_GC (STA_TYPE_STA | NETWORK_P2P) 286 #define CONNECTION_P2P_GO (STA_TYPE_AP | NETWORK_P2P) 287 #define CONNECTION_IBSS_ADHOC (STA_TYPE_ADHOC | NETWORK_IBSS) 288 #define CONNECTION_WDS (STA_TYPE_WDS | NETWORK_WDS) 289 #define CONNECTION_INFRA_BC (STA_TYPE_BC | NETWORK_INFRA) 290 291 struct sec_key { 292 u8 cipher_id; 293 u8 cipher_len; 294 u8 key_id; 295 u8 key_len; 296 u8 key[32]; 297 } __packed; 298 299 struct sta_rec_sec { 300 __le16 tag; 301 __le16 len; 302 u8 add; 303 u8 n_cipher; 304 u8 rsv[2]; 305 306 struct sec_key key[2]; 307 } __packed; 308 309 enum mt7921_cipher_type { 310 MT_CIPHER_NONE, 311 MT_CIPHER_WEP40, 312 MT_CIPHER_WEP104, 313 MT_CIPHER_WEP128, 314 MT_CIPHER_TKIP, 315 MT_CIPHER_AES_CCMP, 316 MT_CIPHER_CCMP_256, 317 MT_CIPHER_GCMP, 318 MT_CIPHER_GCMP_256, 319 MT_CIPHER_WAPI, 320 MT_CIPHER_BIP_CMAC_128, 321 }; 322 323 enum { 324 CH_SWITCH_NORMAL = 0, 325 CH_SWITCH_SCAN = 3, 326 CH_SWITCH_MCC = 4, 327 CH_SWITCH_DFS = 5, 328 CH_SWITCH_BACKGROUND_SCAN_START = 6, 329 CH_SWITCH_BACKGROUND_SCAN_RUNNING = 7, 330 CH_SWITCH_BACKGROUND_SCAN_STOP = 8, 331 CH_SWITCH_SCAN_BYPASS_DPD = 9 332 }; 333 334 enum { 335 THERMAL_SENSOR_TEMP_QUERY, 336 THERMAL_SENSOR_MANUAL_CTRL, 337 THERMAL_SENSOR_INFO_QUERY, 338 THERMAL_SENSOR_TASK_CTRL, 339 }; 340 341 enum { 342 MT_EBF = BIT(0), /* explicit beamforming */ 343 MT_IBF = BIT(1) /* implicit beamforming */ 344 }; 345 346 #define MT7921_WTBL_UPDATE_MAX_SIZE (sizeof(struct wtbl_req_hdr) + \ 347 sizeof(struct wtbl_generic) + \ 348 sizeof(struct wtbl_rx) + \ 349 sizeof(struct wtbl_ht) + \ 350 sizeof(struct wtbl_vht) + \ 351 sizeof(struct wtbl_hdr_trans) +\ 352 sizeof(struct wtbl_ba) + \ 353 sizeof(struct wtbl_smps)) 354 355 #define MT7921_STA_UPDATE_MAX_SIZE (sizeof(struct sta_req_hdr) + \ 356 sizeof(struct sta_rec_basic) + \ 357 sizeof(struct sta_rec_ht) + \ 358 sizeof(struct sta_rec_he) + \ 359 sizeof(struct sta_rec_ba) + \ 360 sizeof(struct sta_rec_vht) + \ 361 sizeof(struct sta_rec_uapsd) + \ 362 sizeof(struct sta_rec_amsdu) + \ 363 sizeof(struct tlv) + \ 364 MT7921_WTBL_UPDATE_MAX_SIZE) 365 366 #define MT7921_WTBL_UPDATE_BA_SIZE (sizeof(struct wtbl_req_hdr) + \ 367 sizeof(struct wtbl_ba)) 368 369 #define STA_CAP_WMM BIT(0) 370 #define STA_CAP_SGI_20 BIT(4) 371 #define STA_CAP_SGI_40 BIT(5) 372 #define STA_CAP_TX_STBC BIT(6) 373 #define STA_CAP_RX_STBC BIT(7) 374 #define STA_CAP_VHT_SGI_80 BIT(16) 375 #define STA_CAP_VHT_SGI_160 BIT(17) 376 #define STA_CAP_VHT_TX_STBC BIT(18) 377 #define STA_CAP_VHT_RX_STBC BIT(19) 378 #define STA_CAP_VHT_LDPC BIT(23) 379 #define STA_CAP_LDPC BIT(24) 380 #define STA_CAP_HT BIT(26) 381 #define STA_CAP_VHT BIT(27) 382 #define STA_CAP_HE BIT(28) 383 384 struct mt7921_mcu_reg_event { 385 __le32 reg; 386 __le32 val; 387 } __packed; 388 389 struct mt7921_mcu_scan_ssid { 390 __le32 ssid_len; 391 u8 ssid[IEEE80211_MAX_SSID_LEN]; 392 } __packed; 393 394 struct mt7921_mcu_scan_channel { 395 u8 band; /* 1: 2.4GHz 396 * 2: 5.0GHz 397 * Others: Reserved 398 */ 399 u8 channel_num; 400 } __packed; 401 402 struct mt7921_mcu_scan_match { 403 __le32 rssi_th; 404 u8 ssid[IEEE80211_MAX_SSID_LEN]; 405 u8 ssid_len; 406 u8 rsv[3]; 407 } __packed; 408 409 struct mt7921_hw_scan_req { 410 u8 seq_num; 411 u8 bss_idx; 412 u8 scan_type; /* 0: PASSIVE SCAN 413 * 1: ACTIVE SCAN 414 */ 415 u8 ssid_type; /* BIT(0) wildcard SSID 416 * BIT(1) P2P wildcard SSID 417 * BIT(2) specified SSID + wildcard SSID 418 * BIT(2) + ssid_type_ext BIT(0) specified SSID only 419 */ 420 u8 ssids_num; 421 u8 probe_req_num; /* Number of probe request for each SSID */ 422 u8 scan_func; /* BIT(0) Enable random MAC scan 423 * BIT(1) Disable DBDC scan type 1~3. 424 * BIT(2) Use DBDC scan type 3 (dedicated one RF to scan). 425 */ 426 u8 version; /* 0: Not support fields after ies. 427 * 1: Support fields after ies. 428 */ 429 struct mt7921_mcu_scan_ssid ssids[4]; 430 __le16 probe_delay_time; 431 __le16 channel_dwell_time; /* channel Dwell interval */ 432 __le16 timeout_value; 433 u8 channel_type; /* 0: Full channels 434 * 1: Only 2.4GHz channels 435 * 2: Only 5GHz channels 436 * 3: P2P social channel only (channel #1, #6 and #11) 437 * 4: Specified channels 438 * Others: Reserved 439 */ 440 u8 channels_num; /* valid when channel_type is 4 */ 441 /* valid when channels_num is set */ 442 struct mt7921_mcu_scan_channel channels[32]; 443 __le16 ies_len; 444 u8 ies[MT7921_SCAN_IE_LEN]; 445 /* following fields are valid if version > 0 */ 446 u8 ext_channels_num; 447 u8 ext_ssids_num; 448 __le16 channel_min_dwell_time; 449 struct mt7921_mcu_scan_channel ext_channels[32]; 450 struct mt7921_mcu_scan_ssid ext_ssids[6]; 451 u8 bssid[ETH_ALEN]; 452 u8 random_mac[ETH_ALEN]; /* valid when BIT(1) in scan_func is set. */ 453 u8 pad[63]; 454 u8 ssid_type_ext; 455 } __packed; 456 457 #define SCAN_DONE_EVENT_MAX_CHANNEL_NUM 64 458 struct mt7921_hw_scan_done { 459 u8 seq_num; 460 u8 sparse_channel_num; 461 struct mt7921_mcu_scan_channel sparse_channel; 462 u8 complete_channel_num; 463 u8 current_state; 464 u8 version; 465 u8 pad; 466 __le32 beacon_scan_num; 467 u8 pno_enabled; 468 u8 pad2[3]; 469 u8 sparse_channel_valid_num; 470 u8 pad3[3]; 471 u8 channel_num[SCAN_DONE_EVENT_MAX_CHANNEL_NUM]; 472 /* idle format for channel_idle_time 473 * 0: first bytes: idle time(ms) 2nd byte: dwell time(ms) 474 * 1: first bytes: idle time(8ms) 2nd byte: dwell time(8ms) 475 * 2: dwell time (16us) 476 */ 477 __le16 channel_idle_time[SCAN_DONE_EVENT_MAX_CHANNEL_NUM]; 478 /* beacon and probe response count */ 479 u8 beacon_probe_num[SCAN_DONE_EVENT_MAX_CHANNEL_NUM]; 480 u8 mdrdy_count[SCAN_DONE_EVENT_MAX_CHANNEL_NUM]; 481 __le32 beacon_2g_num; 482 __le32 beacon_5g_num; 483 } __packed; 484 485 struct mt7921_sched_scan_req { 486 u8 version; 487 u8 seq_num; 488 u8 stop_on_match; 489 u8 ssids_num; 490 u8 match_num; 491 u8 pad; 492 __le16 ie_len; 493 struct mt7921_mcu_scan_ssid ssids[MT7921_MAX_SCHED_SCAN_SSID]; 494 struct mt7921_mcu_scan_match match[MT7921_MAX_SCAN_MATCH]; 495 u8 channel_type; 496 u8 channels_num; 497 u8 intervals_num; 498 u8 scan_func; 499 struct mt7921_mcu_scan_channel channels[64]; 500 __le16 intervals[MT7921_MAX_SCHED_SCAN_INTERVAL]; 501 u8 bss_idx; 502 u8 pad2[64]; 503 } __packed; 504 505 struct mt7921_mcu_tx_config { 506 u8 peer_addr[ETH_ALEN]; 507 u8 sw; 508 u8 dis_rx_hdr_tran; 509 510 u8 aad_om; 511 u8 pfmu_idx; 512 __le16 partial_aid; 513 514 u8 ibf; 515 u8 ebf; 516 u8 is_ht; 517 u8 is_vht; 518 519 u8 mesh; 520 u8 baf_en; 521 u8 cf_ack; 522 u8 rdg_ba; 523 524 u8 rdg; 525 u8 pm; 526 u8 rts; 527 u8 smps; 528 529 u8 txop_ps; 530 u8 not_update_ipsm; 531 u8 skip_tx; 532 u8 ldpc; 533 534 u8 qos; 535 u8 from_ds; 536 u8 to_ds; 537 u8 dyn_bw; 538 539 u8 amdsu_cross_lg; 540 u8 check_per; 541 u8 gid_63; 542 u8 he; 543 544 u8 vht_ibf; 545 u8 vht_ebf; 546 u8 vht_ldpc; 547 u8 he_ldpc; 548 } __packed; 549 550 struct mt7921_mcu_sec_config { 551 u8 wpi_flag; 552 u8 rv; 553 u8 ikv; 554 u8 rkv; 555 556 u8 rcid; 557 u8 rca1; 558 u8 rca2; 559 u8 even_pn; 560 561 u8 key_id; 562 u8 muar_idx; 563 u8 cipher_suit; 564 u8 rsv[1]; 565 } __packed; 566 567 struct mt7921_mcu_key_config { 568 u8 key[32]; 569 } __packed; 570 571 struct mt7921_mcu_rate_info { 572 u8 mpdu_fail; 573 u8 mpdu_tx; 574 u8 rate_idx; 575 u8 rsv[1]; 576 __le16 rate[8]; 577 } __packed; 578 579 struct mt7921_mcu_ba_config { 580 u8 ba_en; 581 u8 rsv[3]; 582 __le32 ba_winsize; 583 } __packed; 584 585 struct mt7921_mcu_ant_id_config { 586 u8 ant_id[4]; 587 } __packed; 588 589 struct mt7921_mcu_peer_cap { 590 struct mt7921_mcu_ant_id_config ant_id_config; 591 592 u8 power_offset; 593 u8 bw_selector; 594 u8 change_bw_rate_n; 595 u8 bw; 596 u8 spe_idx; 597 598 u8 g2; 599 u8 g4; 600 u8 g8; 601 u8 g16; 602 603 u8 mmss; 604 u8 ampdu_factor; 605 u8 rsv[1]; 606 } __packed; 607 608 struct mt7921_mcu_rx_cnt { 609 u8 rx_rcpi[4]; 610 u8 rx_cc[4]; 611 u8 rx_cc_sel; 612 u8 ce_rmsd; 613 u8 rsv[2]; 614 } __packed; 615 616 struct mt7921_mcu_tx_cnt { 617 __le16 rate1_cnt; 618 __le16 rate1_fail_cnt; 619 __le16 rate2_cnt; 620 __le16 rate3_cnt; 621 __le16 cur_bw_tx_cnt; 622 __le16 cur_bw_tx_fail_cnt; 623 __le16 other_bw_tx_cnt; 624 __le16 other_bw_tx_fail_cnt; 625 } __packed; 626 627 struct mt7921_mcu_wlan_info_event { 628 struct mt7921_mcu_tx_config tx_config; 629 struct mt7921_mcu_sec_config sec_config; 630 struct mt7921_mcu_key_config key_config; 631 struct mt7921_mcu_rate_info rate_info; 632 struct mt7921_mcu_ba_config ba_config; 633 struct mt7921_mcu_peer_cap peer_cap; 634 struct mt7921_mcu_rx_cnt rx_cnt; 635 struct mt7921_mcu_tx_cnt tx_cnt; 636 } __packed; 637 638 struct mt7921_mcu_wlan_info { 639 __le32 wlan_idx; 640 struct mt7921_mcu_wlan_info_event event; 641 } __packed; 642 #endif 643