xref: /linux/drivers/net/wireless/mediatek/mt76/mt7996/mcu.h (revision bb118e86dfcc096b8a3889c1a5c88f214e1f65fa)
1 /* SPDX-License-Identifier: ISC */
2 /*
3  * Copyright (C) 2022 MediaTek Inc.
4  */
5 
6 #ifndef __MT7996_MCU_H
7 #define __MT7996_MCU_H
8 
9 #include "../mt76_connac_mcu.h"
10 
11 struct mt7996_mcu_rxd {
12 	__le32 rxd[8];
13 
14 	__le16 len;
15 	__le16 pkt_type_id;
16 
17 	u8 eid;
18 	u8 seq;
19 	u8 option;
20 	u8 __rsv;
21 
22 	u8 ext_eid;
23 	u8 __rsv1[2];
24 	u8 s2d_index;
25 };
26 
27 struct mt7996_mcu_uni_event {
28 	u8 cid;
29 	u8 __rsv[3];
30 	__le32 status; /* 0: success, others: fail */
31 } __packed;
32 
33 struct mt7996_mcu_csa_notify {
34 	struct mt7996_mcu_rxd rxd;
35 
36 	u8 omac_idx;
37 	u8 csa_count;
38 	u8 band_idx;
39 	u8 rsv;
40 } __packed;
41 
42 struct mt7996_mcu_rdd_report {
43 	struct mt7996_mcu_rxd rxd;
44 
45 	u8 __rsv1[4];
46 
47 	__le16 tag;
48 	__le16 len;
49 
50 	u8 band_idx;
51 	u8 long_detected;
52 	u8 constant_prf_detected;
53 	u8 staggered_prf_detected;
54 	u8 radar_type_idx;
55 	u8 periodic_pulse_num;
56 	u8 long_pulse_num;
57 	u8 hw_pulse_num;
58 
59 	u8 out_lpn;
60 	u8 out_spn;
61 	u8 out_crpn;
62 	u8 out_crpw;
63 	u8 out_crbn;
64 	u8 out_stgpn;
65 	u8 out_stgpw;
66 
67 	u8 __rsv2;
68 
69 	__le32 out_pri_const;
70 	__le32 out_pri_stg[3];
71 	__le32 out_pri_stg_dmin;
72 
73 	struct {
74 		__le32 start;
75 		__le16 pulse_width;
76 		__le16 pulse_power;
77 		u8 mdrdy_flag;
78 		u8 rsv[3];
79 	} long_pulse[32];
80 
81 	struct {
82 		__le32 start;
83 		__le16 pulse_width;
84 		__le16 pulse_power;
85 		u8 mdrdy_flag;
86 		u8 rsv[3];
87 	} periodic_pulse[32];
88 
89 	struct {
90 		__le32 start;
91 		__le16 pulse_width;
92 		__le16 pulse_power;
93 		u8 sc_pass;
94 		u8 sw_reset;
95 		u8 mdrdy_flag;
96 		u8 tx_active;
97 	} hw_pulse[32];
98 } __packed;
99 
100 struct mt7996_mcu_background_chain_ctrl {
101 	u8 _rsv[4];
102 
103 	__le16 tag;
104 	__le16 len;
105 
106 	u8 chan;		/* primary channel */
107 	u8 central_chan;	/* central channel */
108 	u8 bw;
109 	u8 tx_stream;
110 	u8 rx_stream;
111 
112 	u8 monitor_chan;	/* monitor channel */
113 	u8 monitor_central_chan;/* monitor central channel */
114 	u8 monitor_bw;
115 	u8 monitor_tx_stream;
116 	u8 monitor_rx_stream;
117 
118 	u8 scan_mode;		/* 0: ScanStop
119 				 * 1: ScanStart
120 				 * 2: ScanRunning
121 				 */
122 	u8 band_idx;		/* DBDC */
123 	u8 monitor_scan_type;
124 	u8 band;		/* 0: 2.4GHz, 1: 5GHz */
125 	u8 rsv[2];
126 } __packed;
127 
128 struct mt7996_mcu_eeprom {
129 	u8 _rsv[4];
130 
131 	__le16 tag;
132 	__le16 len;
133 	u8 buffer_mode;
134 	u8 format;
135 	__le16 buf_len;
136 } __packed;
137 
138 struct mt7996_mcu_phy_rx_info {
139 	u8 category;
140 	u8 rate;
141 	u8 mode;
142 	u8 nsts;
143 	u8 gi;
144 	u8 coding;
145 	u8 stbc;
146 	u8 bw;
147 };
148 
149 struct mt7996_mcu_mib {
150 	__le16 tag;
151 	__le16 len;
152 	__le32 offs;
153 	__le64 data;
154 } __packed;
155 
156 struct mt7996_mcu_all_sta_info_event {
157 	u8 rsv[4];
158 	__le16 tag;
159 	__le16 len;
160 	u8 more;
161 	u8 rsv2;
162 	__le16 sta_num;
163 	u8 rsv3[2];
164 
165 	union {
166 		struct {
167 			__le16 wlan_idx;
168 			u8 rsv[2];
169 			__le32 tx_bytes[IEEE80211_NUM_ACS];
170 			__le32 rx_bytes[IEEE80211_NUM_ACS];
171 		} adm_stat[0];
172 
173 		struct {
174 			__le16 wlan_idx;
175 			u8 rsv[2];
176 			__le32 tx_msdu_cnt;
177 			__le32 rx_msdu_cnt;
178 		} msdu_cnt[0];
179 	};
180 } __packed;
181 
182 enum mt7996_chan_mib_offs {
183 	UNI_MIB_OBSS_AIRTIME = 26,
184 	UNI_MIB_NON_WIFI_TIME = 27,
185 	UNI_MIB_TX_TIME = 28,
186 	UNI_MIB_RX_TIME = 29
187 };
188 
189 struct edca {
190 	__le16 tag;
191 	__le16 len;
192 
193 	u8 queue;
194 	u8 set;
195 	u8 cw_min;
196 	u8 cw_max;
197 	__le16 txop;
198 	u8 aifs;
199 	u8 __rsv;
200 };
201 
202 #define MCU_PQ_ID(p, q)			(((p) << 15) | ((q) << 10))
203 #define MCU_PKT_ID			0xa0
204 
205 enum {
206 	MCU_FW_LOG_WM,
207 	MCU_FW_LOG_WA,
208 	MCU_FW_LOG_TO_HOST,
209 	MCU_FW_LOG_RELAY = 16
210 };
211 
212 enum {
213 	MCU_TWT_AGRT_ADD,
214 	MCU_TWT_AGRT_MODIFY,
215 	MCU_TWT_AGRT_DELETE,
216 	MCU_TWT_AGRT_TEARDOWN,
217 	MCU_TWT_AGRT_GET_TSF,
218 };
219 
220 enum {
221 	MCU_WA_PARAM_CMD_QUERY,
222 	MCU_WA_PARAM_CMD_SET,
223 	MCU_WA_PARAM_CMD_CAPABILITY,
224 	MCU_WA_PARAM_CMD_DEBUG,
225 };
226 
227 enum {
228 	MCU_WA_PARAM_PDMA_RX = 0x04,
229 	MCU_WA_PARAM_CPU_UTIL = 0x0b,
230 	MCU_WA_PARAM_RED = 0x0e,
231 	MCU_WA_PARAM_HW_PATH_HIF_VER = 0x2f,
232 };
233 
234 enum mcu_mmps_mode {
235 	MCU_MMPS_STATIC,
236 	MCU_MMPS_DYNAMIC,
237 	MCU_MMPS_RSV,
238 	MCU_MMPS_DISABLE,
239 };
240 
241 struct bss_rate_tlv {
242 	__le16 tag;
243 	__le16 len;
244 	u8 __rsv1[4];
245 	__le16 bc_trans;
246 	__le16 mc_trans;
247 	u8 short_preamble;
248 	u8 bc_fixed_rate;
249 	u8 mc_fixed_rate;
250 	u8 __rsv2[1];
251 } __packed;
252 
253 struct bss_ra_tlv {
254 	__le16 tag;
255 	__le16 len;
256 	u8 short_preamble;
257 	u8 force_sgi;
258 	u8 force_gf;
259 	u8 ht_mode;
260 	u8 se_off;
261 	u8 antenna_idx;
262 	__le16 max_phyrate;
263 	u8 force_tx_streams;
264 	u8 __rsv[3];
265 } __packed;
266 
267 struct bss_rlm_tlv {
268 	__le16 tag;
269 	__le16 len;
270 	u8 control_channel;
271 	u8 center_chan;
272 	u8 center_chan2;
273 	u8 bw;
274 	u8 tx_streams;
275 	u8 rx_streams;
276 	u8 ht_op_info;
277 	u8 sco;
278 	u8 band;
279 	u8 __rsv[3];
280 } __packed;
281 
282 struct bss_color_tlv {
283 	__le16 tag;
284 	__le16 len;
285 	u8 enable;
286 	u8 color;
287 	u8 rsv[2];
288 } __packed;
289 
290 struct bss_inband_discovery_tlv {
291 	__le16 tag;
292 	__le16 len;
293 	u8 tx_type;
294 	u8 tx_mode;
295 	u8 tx_interval;
296 	u8 enable;
297 	__le16 wcid;
298 	__le16 prob_rsp_len;
299 } __packed;
300 
301 struct bss_bcn_content_tlv {
302 	__le16 tag;
303 	__le16 len;
304 	__le16 tim_ie_pos;
305 	__le16 csa_ie_pos;
306 	__le16 bcc_ie_pos;
307 	u8 enable;
308 	u8 type;
309 	__le16 pkt_len;
310 } __packed;
311 
312 struct bss_bcn_cntdwn_tlv {
313 	__le16 tag;
314 	__le16 len;
315 	u8 cnt;
316 	u8 rsv[3];
317 } __packed;
318 
319 struct bss_bcn_mbss_tlv {
320 	__le16 tag;
321 	__le16 len;
322 	__le32 bitmap;
323 #define MAX_BEACON_NUM	32
324 	__le16 offset[MAX_BEACON_NUM];
325 } __packed __aligned(4);
326 
327 struct bss_txcmd_tlv {
328 	__le16 tag;
329 	__le16 len;
330 	u8 txcmd_mode;
331 	u8 __rsv[3];
332 } __packed;
333 
334 struct bss_sec_tlv {
335 	__le16 tag;
336 	__le16 len;
337 	u8 __rsv1[2];
338 	u8 cipher;
339 	u8 __rsv2[1];
340 } __packed;
341 
342 struct bss_ifs_time_tlv {
343 	__le16 tag;
344 	__le16 len;
345 	u8 slot_valid;
346 	u8 sifs_valid;
347 	u8 rifs_valid;
348 	u8 eifs_valid;
349 	__le16 slot_time;
350 	__le16 sifs_time;
351 	__le16 rifs_time;
352 	__le16 eifs_time;
353 	u8 eifs_cck_valid;
354 	u8 rsv;
355 	__le16 eifs_cck_time;
356 } __packed;
357 
358 struct bss_power_save {
359 	__le16 tag;
360 	__le16 len;
361 	u8 profile;
362 	u8 _rsv[3];
363 } __packed;
364 
365 struct bss_mld_tlv {
366 	__le16 tag;
367 	__le16 len;
368 	u8 group_mld_id;
369 	u8 own_mld_id;
370 	u8 mac_addr[ETH_ALEN];
371 	u8 remap_idx;
372 	u8 __rsv[3];
373 } __packed;
374 
375 struct sta_rec_ba_uni {
376 	__le16 tag;
377 	__le16 len;
378 	u8 tid;
379 	u8 ba_type;
380 	u8 amsdu;
381 	u8 ba_en;
382 	__le16 ssn;
383 	__le16 winsize;
384 	u8 ba_rdd_rro;
385 	u8 __rsv[3];
386 } __packed;
387 
388 struct sta_rec_eht {
389 	__le16 tag;
390 	__le16 len;
391 	u8 tid_bitmap;
392 	u8 _rsv;
393 	__le16 mac_cap;
394 	__le64 phy_cap;
395 	__le64 phy_cap_ext;
396 	u8 mcs_map_bw20[4];
397 	u8 mcs_map_bw80[3];
398 	u8 mcs_map_bw160[3];
399 	u8 mcs_map_bw320[3];
400 	u8 _rsv2[3];
401 } __packed;
402 
403 struct sec_key_uni {
404 	__le16 wlan_idx;
405 	u8 mgmt_prot;
406 	u8 cipher_id;
407 	u8 cipher_len;
408 	u8 key_id;
409 	u8 key_len;
410 	u8 need_resp;
411 	u8 key[32];
412 } __packed;
413 
414 struct sta_rec_sec_uni {
415 	__le16 tag;
416 	__le16 len;
417 	u8 add;
418 	u8 n_cipher;
419 	u8 rsv[2];
420 
421 	struct sec_key_uni key[2];
422 } __packed;
423 
424 struct sta_rec_hdrt {
425 	__le16 tag;
426 	__le16 len;
427 	u8 hdrt_mode;
428 	u8 rsv[3];
429 } __packed;
430 
431 struct sta_rec_hdr_trans {
432 	__le16 tag;
433 	__le16 len;
434 	u8 from_ds;
435 	u8 to_ds;
436 	u8 dis_rx_hdr_tran;
437 	u8 mesh;
438 } __packed;
439 
440 struct hdr_trans_en {
441 	__le16 tag;
442 	__le16 len;
443 	u8 enable;
444 	u8 check_bssid;
445 	u8 mode;
446 	u8 __rsv;
447 } __packed;
448 
449 struct hdr_trans_vlan {
450 	__le16 tag;
451 	__le16 len;
452 	u8 insert_vlan;
453 	u8 remove_vlan;
454 	u8 tid;
455 	u8 __rsv;
456 } __packed;
457 
458 struct hdr_trans_blacklist {
459 	__le16 tag;
460 	__le16 len;
461 	u8 idx;
462 	u8 enable;
463 	__le16 type;
464 } __packed;
465 
466 struct uni_header {
467 	u8 __rsv[4];
468 } __packed;
469 
470 struct vow_rx_airtime {
471 	__le16 tag;
472 	__le16 len;
473 
474 	u8 enable;
475 	u8 band;
476 	u8 __rsv[2];
477 } __packed;
478 
479 struct bf_sounding_on {
480 	__le16 tag;
481 	__le16 len;
482 
483 	u8 snd_mode;
484 	u8 sta_num;
485 	u8 __rsv[2];
486 	__le16 wlan_id[4];
487 	__le32 snd_period;
488 } __packed;
489 
490 struct bf_hw_en_status_update {
491 	__le16 tag;
492 	__le16 len;
493 
494 	bool ebf;
495 	bool ibf;
496 	u8 __rsv[2];
497 } __packed;
498 
499 struct bf_mod_en_ctrl {
500 	__le16 tag;
501 	__le16 len;
502 
503 	u8 bf_num;
504 	u8 bf_bitmap;
505 	u8 bf_sel[8];
506 	u8 __rsv[2];
507 } __packed;
508 
509 union bf_tag_tlv {
510 	struct bf_sounding_on bf_snd;
511 	struct bf_hw_en_status_update bf_hw_en;
512 	struct bf_mod_en_ctrl bf_mod_en;
513 };
514 
515 struct ra_rate {
516 	__le16 wlan_idx;
517 	u8 mode;
518 	u8 stbc;
519 	__le16 gi;
520 	u8 bw;
521 	u8 ldpc;
522 	u8 mcs;
523 	u8 nss;
524 	__le16 ltf;
525 	u8 spe;
526 	u8 preamble;
527 	u8 __rsv[2];
528 } __packed;
529 
530 struct ra_fixed_rate {
531 	__le16 tag;
532 	__le16 len;
533 
534 	__le16 version;
535 	struct ra_rate rate;
536 } __packed;
537 
538 enum {
539 	UNI_RA_FIXED_RATE = 0xf,
540 };
541 
542 #define MT7996_HDR_TRANS_MAX_SIZE	(sizeof(struct hdr_trans_en) +	 \
543 					 sizeof(struct hdr_trans_vlan) + \
544 					 sizeof(struct hdr_trans_blacklist))
545 
546 enum {
547 	UNI_HDR_TRANS_EN,
548 	UNI_HDR_TRANS_VLAN,
549 	UNI_HDR_TRANS_BLACKLIST,
550 };
551 
552 enum {
553 	RATE_PARAM_FIXED = 3,
554 	RATE_PARAM_MMPS_UPDATE = 5,
555 	RATE_PARAM_FIXED_HE_LTF = 7,
556 	RATE_PARAM_FIXED_MCS,
557 	RATE_PARAM_FIXED_GI = 11,
558 	RATE_PARAM_AUTO = 20,
559 };
560 
561 enum {
562 	BF_SOUNDING_ON = 1,
563 	BF_HW_EN_UPDATE = 17,
564 	BF_MOD_EN_CTRL = 20,
565 };
566 
567 enum {
568 	CMD_BAND_NONE,
569 	CMD_BAND_24G,
570 	CMD_BAND_5G,
571 	CMD_BAND_6G,
572 };
573 
574 struct bss_req_hdr {
575 	u8 bss_idx;
576 	u8 __rsv[3];
577 } __packed;
578 
579 enum {
580 	UNI_CHANNEL_SWITCH,
581 	UNI_CHANNEL_RX_PATH,
582 };
583 
584 #define MT7996_BSS_UPDATE_MAX_SIZE	(sizeof(struct bss_req_hdr) +		\
585 					 sizeof(struct mt76_connac_bss_basic_tlv) +	\
586 					 sizeof(struct bss_rlm_tlv) +		\
587 					 sizeof(struct bss_ra_tlv) +		\
588 					 sizeof(struct bss_info_uni_he) +	\
589 					 sizeof(struct bss_rate_tlv) +		\
590 					 sizeof(struct bss_txcmd_tlv) +		\
591 					 sizeof(struct bss_power_save) +	\
592 					 sizeof(struct bss_sec_tlv) +		\
593 					 sizeof(struct bss_ifs_time_tlv) +	\
594 					 sizeof(struct bss_mld_tlv))
595 
596 #define MT7996_STA_UPDATE_MAX_SIZE	(sizeof(struct sta_req_hdr) +		\
597 					 sizeof(struct sta_rec_basic) +		\
598 					 sizeof(struct sta_rec_bf) +		\
599 					 sizeof(struct sta_rec_ht) +		\
600 					 sizeof(struct sta_rec_he_v2) +		\
601 					 sizeof(struct sta_rec_ba_uni) +	\
602 					 sizeof(struct sta_rec_vht) +		\
603 					 sizeof(struct sta_rec_uapsd) + 	\
604 					 sizeof(struct sta_rec_amsdu) +		\
605 					 sizeof(struct sta_rec_bfee) +		\
606 					 sizeof(struct sta_rec_phy) +		\
607 					 sizeof(struct sta_rec_ra) +		\
608 					 sizeof(struct sta_rec_sec) +		\
609 					 sizeof(struct sta_rec_ra_fixed) +	\
610 					 sizeof(struct sta_rec_he_6g_capa) +	\
611 					 sizeof(struct sta_rec_eht) +		\
612 					 sizeof(struct sta_rec_hdrt) +		\
613 					 sizeof(struct sta_rec_hdr_trans) +	\
614 					 sizeof(struct tlv))
615 
616 #define MT7996_MAX_BEACON_SIZE		1342
617 #define MT7996_BEACON_UPDATE_SIZE	(sizeof(struct bss_req_hdr) +		\
618 					 sizeof(struct bss_bcn_content_tlv) +	\
619 					 MT_TXD_SIZE +				\
620 					 sizeof(struct bss_bcn_cntdwn_tlv) +	\
621 					 sizeof(struct bss_bcn_mbss_tlv))
622 #define MT7996_MAX_BSS_OFFLOAD_SIZE	(MT7996_MAX_BEACON_SIZE +		\
623 					 MT7996_BEACON_UPDATE_SIZE)
624 
625 enum {
626 	UNI_BAND_CONFIG_RADIO_ENABLE,
627 	UNI_BAND_CONFIG_RTS_THRESHOLD = 0x08,
628 };
629 
630 enum {
631 	UNI_WSYS_CONFIG_FW_LOG_CTRL,
632 	UNI_WSYS_CONFIG_FW_DBG_CTRL,
633 };
634 
635 enum {
636 	UNI_RDD_CTRL_PARM,
637 	UNI_RDD_CTRL_SET_TH = 0x3,
638 };
639 
640 enum {
641 	UNI_EFUSE_ACCESS = 1,
642 	UNI_EFUSE_BUFFER_MODE,
643 	UNI_EFUSE_FREE_BLOCK,
644 	UNI_EFUSE_BUFFER_RD,
645 };
646 
647 enum {
648 	UNI_VOW_DRR_CTRL,
649 	UNI_VOW_RX_AT_AIRTIME_EN = 0x0b,
650 	UNI_VOW_RX_AT_AIRTIME_CLR_EN = 0x0e,
651 };
652 
653 enum {
654 	UNI_CMD_MIB_DATA,
655 };
656 
657 enum {
658 	UNI_POWER_OFF,
659 };
660 
661 enum {
662 	UNI_CMD_TWT_ARGT_UPDATE = 0x0,
663 	UNI_CMD_TWT_MGMT_OFFLOAD,
664 };
665 
666 enum {
667 	UNI_RRO_DEL_ENTRY = 0x1,
668 	UNI_RRO_SET_PLATFORM_TYPE,
669 	UNI_RRO_GET_BA_SESSION_TABLE,
670 	UNI_RRO_SET_BYPASS_MODE,
671 	UNI_RRO_SET_TXFREE_PATH,
672 };
673 
674 enum{
675 	UNI_CMD_SR_ENABLE = 0x1,
676 	UNI_CMD_SR_ENABLE_SD,
677 	UNI_CMD_SR_ENABLE_MODE,
678 	UNI_CMD_SR_ENABLE_DPD = 0x12,
679 	UNI_CMD_SR_ENABLE_TX,
680 	UNI_CMD_SR_SET_SRG_BITMAP = 0x80,
681 	UNI_CMD_SR_SET_PARAM = 0xc1,
682 	UNI_CMD_SR_SET_SIGA = 0xd0,
683 };
684 
685 enum {
686 	UNI_CMD_ACCESS_REG_BASIC = 0x0,
687 	UNI_CMD_ACCESS_RF_REG_BASIC,
688 };
689 
690 enum {
691 	UNI_CMD_SER_QUERY,
692 	/* recovery */
693 	UNI_CMD_SER_SET_RECOVER_L1,
694 	UNI_CMD_SER_SET_RECOVER_L2,
695 	UNI_CMD_SER_SET_RECOVER_L3_RX_ABORT,
696 	UNI_CMD_SER_SET_RECOVER_L3_TX_ABORT,
697 	UNI_CMD_SER_SET_RECOVER_L3_TX_DISABLE,
698 	UNI_CMD_SER_SET_RECOVER_L3_BF,
699 	UNI_CMD_SER_SET_RECOVER_L4_MDP,
700 	UNI_CMD_SER_SET_RECOVER_FULL,
701 	UNI_CMD_SER_SET_SYSTEM_ASSERT,
702 	/* action */
703 	UNI_CMD_SER_ENABLE = 1,
704 	UNI_CMD_SER_SET,
705 	UNI_CMD_SER_TRIGGER
706 };
707 
708 enum {
709 	MT7996_SEC_MODE_PLAIN,
710 	MT7996_SEC_MODE_AES,
711 	MT7996_SEC_MODE_SCRAMBLE,
712 	MT7996_SEC_MODE_MAX,
713 };
714 
715 #define MT7996_PATCH_SEC		GENMASK(31, 24)
716 #define MT7996_PATCH_SCRAMBLE_KEY	GENMASK(15, 8)
717 #define MT7996_PATCH_AES_KEY		GENMASK(7, 0)
718 
719 #define MT7996_SEC_ENCRYPT		BIT(0)
720 #define MT7996_SEC_KEY_IDX		GENMASK(2, 1)
721 #define MT7996_SEC_IV			BIT(3)
722 
723 #endif
724