1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2020 MediaTek Inc. */
3 
4 #ifndef __MT76_CONNAC_MCU_H
5 #define __MT76_CONNAC_MCU_H
6 
7 #include "mt76_connac.h"
8 
9 struct tlv {
10 	__le16 tag;
11 	__le16 len;
12 } __packed;
13 
14 struct bss_info_omac {
15 	__le16 tag;
16 	__le16 len;
17 	u8 hw_bss_idx;
18 	u8 omac_idx;
19 	u8 band_idx;
20 	u8 rsv0;
21 	__le32 conn_type;
22 	u32 rsv1;
23 } __packed;
24 
25 struct bss_info_basic {
26 	__le16 tag;
27 	__le16 len;
28 	__le32 network_type;
29 	u8 active;
30 	u8 rsv0;
31 	__le16 bcn_interval;
32 	u8 bssid[ETH_ALEN];
33 	u8 wmm_idx;
34 	u8 dtim_period;
35 	u8 bmc_wcid_lo;
36 	u8 cipher;
37 	u8 phy_mode;
38 	u8 max_bssid;	/* max BSSID. range: 1 ~ 8, 0: MBSSID disabled */
39 	u8 non_tx_bssid;/* non-transmitted BSSID, 0: transmitted BSSID */
40 	u8 bmc_wcid_hi;	/* high Byte and version */
41 	u8 rsv[2];
42 } __packed;
43 
44 struct bss_info_rf_ch {
45 	__le16 tag;
46 	__le16 len;
47 	u8 pri_ch;
48 	u8 center_ch0;
49 	u8 center_ch1;
50 	u8 bw;
51 	u8 he_ru26_block;	/* 1: don't send HETB in RU26, 0: allow */
52 	u8 he_all_disable;	/* 1: disallow all HETB, 0: allow */
53 	u8 rsv[2];
54 } __packed;
55 
56 struct bss_info_ext_bss {
57 	__le16 tag;
58 	__le16 len;
59 	__le32 mbss_tsf_offset; /* in unit of us */
60 	u8 rsv[8];
61 } __packed;
62 
63 enum {
64 	BSS_INFO_OMAC,
65 	BSS_INFO_BASIC,
66 	BSS_INFO_RF_CH,		/* optional, for BT/LTE coex */
67 	BSS_INFO_PM,		/* sta only */
68 	BSS_INFO_UAPSD,		/* sta only */
69 	BSS_INFO_ROAM_DETECT,	/* obsoleted */
70 	BSS_INFO_LQ_RM,		/* obsoleted */
71 	BSS_INFO_EXT_BSS,
72 	BSS_INFO_BMC_RATE,	/* for bmc rate control in CR4 */
73 	BSS_INFO_SYNC_MODE,	/* obsoleted */
74 	BSS_INFO_RA,
75 	BSS_INFO_HW_AMSDU,
76 	BSS_INFO_BSS_COLOR,
77 	BSS_INFO_HE_BASIC,
78 	BSS_INFO_PROTECT_INFO,
79 	BSS_INFO_OFFLOAD,
80 	BSS_INFO_11V_MBSSID,
81 	BSS_INFO_MAX_NUM
82 };
83 
84 /* sta_rec */
85 
86 struct sta_ntlv_hdr {
87 	u8 rsv[2];
88 	__le16 tlv_num;
89 } __packed;
90 
91 struct sta_req_hdr {
92 	u8 bss_idx;
93 	u8 wlan_idx_lo;
94 	__le16 tlv_num;
95 	u8 is_tlv_append;
96 	u8 muar_idx;
97 	u8 wlan_idx_hi;
98 	u8 rsv;
99 } __packed;
100 
101 struct sta_rec_basic {
102 	__le16 tag;
103 	__le16 len;
104 	__le32 conn_type;
105 	u8 conn_state;
106 	u8 qos;
107 	__le16 aid;
108 	u8 peer_addr[ETH_ALEN];
109 #define EXTRA_INFO_VER	BIT(0)
110 #define EXTRA_INFO_NEW	BIT(1)
111 	__le16 extra_info;
112 } __packed;
113 
114 struct sta_rec_ht {
115 	__le16 tag;
116 	__le16 len;
117 	__le16 ht_cap;
118 	u16 rsv;
119 } __packed;
120 
121 struct sta_rec_vht {
122 	__le16 tag;
123 	__le16 len;
124 	__le32 vht_cap;
125 	__le16 vht_rx_mcs_map;
126 	__le16 vht_tx_mcs_map;
127 	/* mt7915 - mt7921 */
128 	u8 rts_bw_sig;
129 	u8 rsv[3];
130 } __packed;
131 
132 struct sta_rec_uapsd {
133 	__le16 tag;
134 	__le16 len;
135 	u8 dac_map;
136 	u8 tac_map;
137 	u8 max_sp;
138 	u8 rsv0;
139 	__le16 listen_interval;
140 	u8 rsv1[2];
141 } __packed;
142 
143 struct sta_rec_ba {
144 	__le16 tag;
145 	__le16 len;
146 	u8 tid;
147 	u8 ba_type;
148 	u8 amsdu;
149 	u8 ba_en;
150 	__le16 ssn;
151 	__le16 winsize;
152 } __packed;
153 
154 struct sta_rec_he {
155 	__le16 tag;
156 	__le16 len;
157 
158 	__le32 he_cap;
159 
160 	u8 t_frame_dur;
161 	u8 max_ampdu_exp;
162 	u8 bw_set;
163 	u8 device_class;
164 	u8 dcm_tx_mode;
165 	u8 dcm_tx_max_nss;
166 	u8 dcm_rx_mode;
167 	u8 dcm_rx_max_nss;
168 	u8 dcm_max_ru;
169 	u8 punc_pream_rx;
170 	u8 pkt_ext;
171 	u8 rsv1;
172 
173 	__le16 max_nss_mcs[CMD_HE_MCS_BW_NUM];
174 
175 	u8 rsv2[2];
176 } __packed;
177 
178 struct sta_rec_amsdu {
179 	__le16 tag;
180 	__le16 len;
181 	u8 max_amsdu_num;
182 	u8 max_mpdu_size;
183 	u8 amsdu_en;
184 	u8 rsv;
185 } __packed;
186 
187 struct sta_rec_state {
188 	__le16 tag;
189 	__le16 len;
190 	__le32 flags;
191 	u8 state;
192 	u8 vht_opmode;
193 	u8 action;
194 	u8 rsv[1];
195 } __packed;
196 
197 #define RA_LEGACY_OFDM GENMASK(13, 6)
198 #define RA_LEGACY_CCK  GENMASK(3, 0)
199 #define HT_MCS_MASK_NUM 10
200 struct sta_rec_ra_info {
201 	__le16 tag;
202 	__le16 len;
203 	__le16 legacy;
204 	u8 rx_mcs_bitmask[HT_MCS_MASK_NUM];
205 } __packed;
206 
207 struct sta_rec_phy {
208 	__le16 tag;
209 	__le16 len;
210 	__le16 basic_rate;
211 	u8 phy_type;
212 	u8 ampdu;
213 	u8 rts_policy;
214 	u8 rcpi;
215 	u8 rsv[2];
216 } __packed;
217 
218 struct sta_rec_he_6g_capa {
219 	__le16 tag;
220 	__le16 len;
221 	__le16 capa;
222 	u8 rsv[2];
223 } __packed;
224 
225 struct sec_key {
226 	u8 cipher_id;
227 	u8 cipher_len;
228 	u8 key_id;
229 	u8 key_len;
230 	u8 key[32];
231 } __packed;
232 
233 struct sta_rec_sec {
234 	__le16 tag;
235 	__le16 len;
236 	u8 add;
237 	u8 n_cipher;
238 	u8 rsv[2];
239 
240 	struct sec_key key[2];
241 } __packed;
242 
243 struct sta_rec_bf {
244 	__le16 tag;
245 	__le16 len;
246 
247 	__le16 pfmu;		/* 0xffff: no access right for PFMU */
248 	bool su_mu;		/* 0: SU, 1: MU */
249 	u8 bf_cap;		/* 0: iBF, 1: eBF */
250 	u8 sounding_phy;	/* 0: legacy, 1: OFDM, 2: HT, 4: VHT */
251 	u8 ndpa_rate;
252 	u8 ndp_rate;
253 	u8 rept_poll_rate;
254 	u8 tx_mode;		/* 0: legacy, 1: OFDM, 2: HT, 4: VHT ... */
255 	u8 ncol;
256 	u8 nrow;
257 	u8 bw;			/* 0: 20M, 1: 40M, 2: 80M, 3: 160M */
258 
259 	u8 mem_total;
260 	u8 mem_20m;
261 	struct {
262 		u8 row;
263 		u8 col: 6, row_msb: 2;
264 	} mem[4];
265 
266 	__le16 smart_ant;
267 	u8 se_idx;
268 	u8 auto_sounding;	/* b7: low traffic indicator
269 				 * b6: Stop sounding for this entry
270 				 * b5 ~ b0: postpone sounding
271 				 */
272 	u8 ibf_timeout;
273 	u8 ibf_dbw;
274 	u8 ibf_ncol;
275 	u8 ibf_nrow;
276 	u8 nrow_bw160;
277 	u8 ncol_bw160;
278 	u8 ru_start_idx;
279 	u8 ru_end_idx;
280 
281 	bool trigger_su;
282 	bool trigger_mu;
283 	bool ng16_su;
284 	bool ng16_mu;
285 	bool codebook42_su;
286 	bool codebook75_mu;
287 
288 	u8 he_ltf;
289 	u8 rsv[3];
290 } __packed;
291 
292 struct sta_rec_bfee {
293 	__le16 tag;
294 	__le16 len;
295 	bool fb_identity_matrix;	/* 1: feedback identity matrix */
296 	bool ignore_feedback;		/* 1: ignore */
297 	u8 rsv[2];
298 } __packed;
299 
300 struct sta_rec_muru {
301 	__le16 tag;
302 	__le16 len;
303 
304 	struct {
305 		bool ofdma_dl_en;
306 		bool ofdma_ul_en;
307 		bool mimo_dl_en;
308 		bool mimo_ul_en;
309 		u8 rsv[4];
310 	} cfg;
311 
312 	struct {
313 		u8 punc_pream_rx;
314 		bool he_20m_in_40m_2g;
315 		bool he_20m_in_160m;
316 		bool he_80m_in_160m;
317 		bool lt16_sigb;
318 		bool rx_su_comp_sigb;
319 		bool rx_su_non_comp_sigb;
320 		u8 rsv;
321 	} ofdma_dl;
322 
323 	struct {
324 		u8 t_frame_dur;
325 		u8 mu_cascading;
326 		u8 uo_ra;
327 		u8 he_2x996_tone;
328 		u8 rx_t_frame_11ac;
329 		u8 rsv[3];
330 	} ofdma_ul;
331 
332 	struct {
333 		bool vht_mu_bfee;
334 		bool partial_bw_dl_mimo;
335 		u8 rsv[2];
336 	} mimo_dl;
337 
338 	struct {
339 		bool full_ul_mimo;
340 		bool partial_ul_mimo;
341 		u8 rsv[2];
342 	} mimo_ul;
343 } __packed;
344 
345 struct sta_phy {
346 	u8 type;
347 	u8 flag;
348 	u8 stbc;
349 	u8 sgi;
350 	u8 bw;
351 	u8 ldpc;
352 	u8 mcs;
353 	u8 nss;
354 	u8 he_ltf;
355 };
356 
357 struct sta_rec_ra {
358 	__le16 tag;
359 	__le16 len;
360 
361 	u8 valid;
362 	u8 auto_rate;
363 	u8 phy_mode;
364 	u8 channel;
365 	u8 bw;
366 	u8 disable_cck;
367 	u8 ht_mcs32;
368 	u8 ht_gf;
369 	u8 ht_mcs[4];
370 	u8 mmps_mode;
371 	u8 gband_256;
372 	u8 af;
373 	u8 auth_wapi_mode;
374 	u8 rate_len;
375 
376 	u8 supp_mode;
377 	u8 supp_cck_rate;
378 	u8 supp_ofdm_rate;
379 	__le32 supp_ht_mcs;
380 	__le16 supp_vht_mcs[4];
381 
382 	u8 op_mode;
383 	u8 op_vht_chan_width;
384 	u8 op_vht_rx_nss;
385 	u8 op_vht_rx_nss_type;
386 
387 	__le32 sta_cap;
388 
389 	struct sta_phy phy;
390 } __packed;
391 
392 struct sta_rec_ra_fixed {
393 	__le16 tag;
394 	__le16 len;
395 
396 	__le32 field;
397 	u8 op_mode;
398 	u8 op_vht_chan_width;
399 	u8 op_vht_rx_nss;
400 	u8 op_vht_rx_nss_type;
401 
402 	struct sta_phy phy;
403 
404 	u8 spe_en;
405 	u8 short_preamble;
406 	u8 is_5g;
407 	u8 mmps_mode;
408 } __packed;
409 
410 /* wtbl_rec */
411 
412 struct wtbl_req_hdr {
413 	u8 wlan_idx_lo;
414 	u8 operation;
415 	__le16 tlv_num;
416 	u8 wlan_idx_hi;
417 	u8 rsv[3];
418 } __packed;
419 
420 struct wtbl_generic {
421 	__le16 tag;
422 	__le16 len;
423 	u8 peer_addr[ETH_ALEN];
424 	u8 muar_idx;
425 	u8 skip_tx;
426 	u8 cf_ack;
427 	u8 qos;
428 	u8 mesh;
429 	u8 adm;
430 	__le16 partial_aid;
431 	u8 baf_en;
432 	u8 aad_om;
433 } __packed;
434 
435 struct wtbl_rx {
436 	__le16 tag;
437 	__le16 len;
438 	u8 rcid;
439 	u8 rca1;
440 	u8 rca2;
441 	u8 rv;
442 	u8 rsv[4];
443 } __packed;
444 
445 struct wtbl_ht {
446 	__le16 tag;
447 	__le16 len;
448 	u8 ht;
449 	u8 ldpc;
450 	u8 af;
451 	u8 mm;
452 	u8 rsv[4];
453 } __packed;
454 
455 struct wtbl_vht {
456 	__le16 tag;
457 	__le16 len;
458 	u8 ldpc;
459 	u8 dyn_bw;
460 	u8 vht;
461 	u8 txop_ps;
462 	u8 rsv[4];
463 } __packed;
464 
465 struct wtbl_tx_ps {
466 	__le16 tag;
467 	__le16 len;
468 	u8 txps;
469 	u8 rsv[3];
470 } __packed;
471 
472 struct wtbl_hdr_trans {
473 	__le16 tag;
474 	__le16 len;
475 	u8 to_ds;
476 	u8 from_ds;
477 	u8 no_rx_trans;
478 	u8 rsv;
479 } __packed;
480 
481 struct wtbl_ba {
482 	__le16 tag;
483 	__le16 len;
484 	/* common */
485 	u8 tid;
486 	u8 ba_type;
487 	u8 rsv0[2];
488 	/* originator only */
489 	__le16 sn;
490 	u8 ba_en;
491 	u8 ba_winsize_idx;
492 	/* originator & recipient */
493 	__le16 ba_winsize;
494 	/* recipient only */
495 	u8 peer_addr[ETH_ALEN];
496 	u8 rst_ba_tid;
497 	u8 rst_ba_sel;
498 	u8 rst_ba_sb;
499 	u8 band_idx;
500 	u8 rsv1[4];
501 } __packed;
502 
503 struct wtbl_smps {
504 	__le16 tag;
505 	__le16 len;
506 	u8 smps;
507 	u8 rsv[3];
508 } __packed;
509 
510 /* mt7615 only */
511 
512 struct wtbl_bf {
513 	__le16 tag;
514 	__le16 len;
515 	u8 ibf;
516 	u8 ebf;
517 	u8 ibf_vht;
518 	u8 ebf_vht;
519 	u8 gid;
520 	u8 pfmu_idx;
521 	u8 rsv[2];
522 } __packed;
523 
524 struct wtbl_pn {
525 	__le16 tag;
526 	__le16 len;
527 	u8 pn[6];
528 	u8 rsv[2];
529 } __packed;
530 
531 struct wtbl_spe {
532 	__le16 tag;
533 	__le16 len;
534 	u8 spe_idx;
535 	u8 rsv[3];
536 } __packed;
537 
538 struct wtbl_raw {
539 	__le16 tag;
540 	__le16 len;
541 	u8 wtbl_idx;
542 	u8 dw;
543 	u8 rsv[2];
544 	__le32 msk;
545 	__le32 val;
546 } __packed;
547 
548 #define MT76_CONNAC_WTBL_UPDATE_MAX_SIZE (sizeof(struct wtbl_req_hdr) +	\
549 					  sizeof(struct wtbl_generic) +	\
550 					  sizeof(struct wtbl_rx) +	\
551 					  sizeof(struct wtbl_ht) +	\
552 					  sizeof(struct wtbl_vht) +	\
553 					  sizeof(struct wtbl_tx_ps) +	\
554 					  sizeof(struct wtbl_hdr_trans) +\
555 					  sizeof(struct wtbl_ba) +	\
556 					  sizeof(struct wtbl_bf) +	\
557 					  sizeof(struct wtbl_smps) +	\
558 					  sizeof(struct wtbl_pn) +	\
559 					  sizeof(struct wtbl_spe))
560 
561 #define MT76_CONNAC_STA_UPDATE_MAX_SIZE	(sizeof(struct sta_req_hdr) +	\
562 					 sizeof(struct sta_rec_basic) +	\
563 					 sizeof(struct sta_rec_bf) +	\
564 					 sizeof(struct sta_rec_ht) +	\
565 					 sizeof(struct sta_rec_he) +	\
566 					 sizeof(struct sta_rec_ba) +	\
567 					 sizeof(struct sta_rec_vht) +	\
568 					 sizeof(struct sta_rec_uapsd) + \
569 					 sizeof(struct sta_rec_amsdu) +	\
570 					 sizeof(struct sta_rec_muru) +	\
571 					 sizeof(struct sta_rec_bfee) +	\
572 					 sizeof(struct sta_rec_ra) +	\
573 					 sizeof(struct sta_rec_sec) +	\
574 					 sizeof(struct sta_rec_ra_fixed) + \
575 					 sizeof(struct sta_rec_he_6g_capa) + \
576 					 sizeof(struct tlv) +		\
577 					 MT76_CONNAC_WTBL_UPDATE_MAX_SIZE)
578 
579 enum {
580 	STA_REC_BASIC,
581 	STA_REC_RA,
582 	STA_REC_RA_CMM_INFO,
583 	STA_REC_RA_UPDATE,
584 	STA_REC_BF,
585 	STA_REC_AMSDU,
586 	STA_REC_BA,
587 	STA_REC_STATE,
588 	STA_REC_TX_PROC,	/* for hdr trans and CSO in CR4 */
589 	STA_REC_HT,
590 	STA_REC_VHT,
591 	STA_REC_APPS,
592 	STA_REC_KEY,
593 	STA_REC_WTBL,
594 	STA_REC_HE,
595 	STA_REC_HW_AMSDU,
596 	STA_REC_WTBL_AADOM,
597 	STA_REC_KEY_V2,
598 	STA_REC_MURU,
599 	STA_REC_MUEDCA,
600 	STA_REC_BFEE,
601 	STA_REC_PHY = 0x15,
602 	STA_REC_HE_6G = 0x17,
603 	STA_REC_MAX_NUM
604 };
605 
606 enum {
607 	WTBL_GENERIC,
608 	WTBL_RX,
609 	WTBL_HT,
610 	WTBL_VHT,
611 	WTBL_PEER_PS,		/* not used */
612 	WTBL_TX_PS,
613 	WTBL_HDR_TRANS,
614 	WTBL_SEC_KEY,
615 	WTBL_BA,
616 	WTBL_RDG,		/* obsoleted */
617 	WTBL_PROTECT,		/* not used */
618 	WTBL_CLEAR,		/* not used */
619 	WTBL_BF,
620 	WTBL_SMPS,
621 	WTBL_RAW_DATA,		/* debug only */
622 	WTBL_PN,
623 	WTBL_SPE,
624 	WTBL_MAX_NUM
625 };
626 
627 #define STA_TYPE_STA			BIT(0)
628 #define STA_TYPE_AP			BIT(1)
629 #define STA_TYPE_ADHOC			BIT(2)
630 #define STA_TYPE_WDS			BIT(4)
631 #define STA_TYPE_BC			BIT(5)
632 
633 #define NETWORK_INFRA			BIT(16)
634 #define NETWORK_P2P			BIT(17)
635 #define NETWORK_IBSS			BIT(18)
636 #define NETWORK_WDS			BIT(21)
637 
638 #define SCAN_FUNC_RANDOM_MAC		BIT(0)
639 #define SCAN_FUNC_SPLIT_SCAN		BIT(5)
640 
641 #define CONNECTION_INFRA_STA		(STA_TYPE_STA | NETWORK_INFRA)
642 #define CONNECTION_INFRA_AP		(STA_TYPE_AP | NETWORK_INFRA)
643 #define CONNECTION_P2P_GC		(STA_TYPE_STA | NETWORK_P2P)
644 #define CONNECTION_P2P_GO		(STA_TYPE_AP | NETWORK_P2P)
645 #define CONNECTION_IBSS_ADHOC		(STA_TYPE_ADHOC | NETWORK_IBSS)
646 #define CONNECTION_WDS			(STA_TYPE_WDS | NETWORK_WDS)
647 #define CONNECTION_INFRA_BC		(STA_TYPE_BC | NETWORK_INFRA)
648 
649 #define CONN_STATE_DISCONNECT		0
650 #define CONN_STATE_CONNECT		1
651 #define CONN_STATE_PORT_SECURE		2
652 
653 /* HE MAC */
654 #define STA_REC_HE_CAP_HTC			BIT(0)
655 #define STA_REC_HE_CAP_BQR			BIT(1)
656 #define STA_REC_HE_CAP_BSR			BIT(2)
657 #define STA_REC_HE_CAP_OM			BIT(3)
658 #define STA_REC_HE_CAP_AMSDU_IN_AMPDU		BIT(4)
659 /* HE PHY */
660 #define STA_REC_HE_CAP_DUAL_BAND		BIT(5)
661 #define STA_REC_HE_CAP_LDPC			BIT(6)
662 #define STA_REC_HE_CAP_TRIG_CQI_FK		BIT(7)
663 #define STA_REC_HE_CAP_PARTIAL_BW_EXT_RANGE	BIT(8)
664 /* STBC */
665 #define STA_REC_HE_CAP_LE_EQ_80M_TX_STBC	BIT(9)
666 #define STA_REC_HE_CAP_LE_EQ_80M_RX_STBC	BIT(10)
667 #define STA_REC_HE_CAP_GT_80M_TX_STBC		BIT(11)
668 #define STA_REC_HE_CAP_GT_80M_RX_STBC		BIT(12)
669 /* GI */
670 #define STA_REC_HE_CAP_SU_PPDU_1LTF_8US_GI	BIT(13)
671 #define STA_REC_HE_CAP_SU_MU_PPDU_4LTF_8US_GI	BIT(14)
672 #define STA_REC_HE_CAP_ER_SU_PPDU_1LTF_8US_GI	BIT(15)
673 #define STA_REC_HE_CAP_ER_SU_PPDU_4LTF_8US_GI	BIT(16)
674 #define STA_REC_HE_CAP_NDP_4LTF_3DOT2MS_GI	BIT(17)
675 /* 242 TONE */
676 #define STA_REC_HE_CAP_BW20_RU242_SUPPORT	BIT(18)
677 #define STA_REC_HE_CAP_TX_1024QAM_UNDER_RU242	BIT(19)
678 #define STA_REC_HE_CAP_RX_1024QAM_UNDER_RU242	BIT(20)
679 
680 #define PHY_MODE_A				BIT(0)
681 #define PHY_MODE_B				BIT(1)
682 #define PHY_MODE_G				BIT(2)
683 #define PHY_MODE_GN				BIT(3)
684 #define PHY_MODE_AN				BIT(4)
685 #define PHY_MODE_AC				BIT(5)
686 #define PHY_MODE_AX_24G				BIT(6)
687 #define PHY_MODE_AX_5G				BIT(7)
688 
689 #define PHY_MODE_AX_6G				BIT(0) /* phymode_ext */
690 
691 #define MODE_CCK				BIT(0)
692 #define MODE_OFDM				BIT(1)
693 #define MODE_HT					BIT(2)
694 #define MODE_VHT				BIT(3)
695 #define MODE_HE					BIT(4)
696 
697 #define STA_CAP_WMM				BIT(0)
698 #define STA_CAP_SGI_20				BIT(4)
699 #define STA_CAP_SGI_40				BIT(5)
700 #define STA_CAP_TX_STBC				BIT(6)
701 #define STA_CAP_RX_STBC				BIT(7)
702 #define STA_CAP_VHT_SGI_80			BIT(16)
703 #define STA_CAP_VHT_SGI_160			BIT(17)
704 #define STA_CAP_VHT_TX_STBC			BIT(18)
705 #define STA_CAP_VHT_RX_STBC			BIT(19)
706 #define STA_CAP_VHT_LDPC			BIT(23)
707 #define STA_CAP_LDPC				BIT(24)
708 #define STA_CAP_HT				BIT(26)
709 #define STA_CAP_VHT				BIT(27)
710 #define STA_CAP_HE				BIT(28)
711 
712 enum {
713 	PHY_TYPE_HR_DSSS_INDEX = 0,
714 	PHY_TYPE_ERP_INDEX,
715 	PHY_TYPE_ERP_P2P_INDEX,
716 	PHY_TYPE_OFDM_INDEX,
717 	PHY_TYPE_HT_INDEX,
718 	PHY_TYPE_VHT_INDEX,
719 	PHY_TYPE_HE_INDEX,
720 	PHY_TYPE_INDEX_NUM
721 };
722 
723 #define PHY_TYPE_BIT_HR_DSSS			BIT(PHY_TYPE_HR_DSSS_INDEX)
724 #define PHY_TYPE_BIT_ERP			BIT(PHY_TYPE_ERP_INDEX)
725 #define PHY_TYPE_BIT_OFDM			BIT(PHY_TYPE_OFDM_INDEX)
726 #define PHY_TYPE_BIT_HT				BIT(PHY_TYPE_HT_INDEX)
727 #define PHY_TYPE_BIT_VHT			BIT(PHY_TYPE_VHT_INDEX)
728 #define PHY_TYPE_BIT_HE				BIT(PHY_TYPE_HE_INDEX)
729 
730 #define MT_WTBL_RATE_TX_MODE			GENMASK(9, 6)
731 #define MT_WTBL_RATE_MCS			GENMASK(5, 0)
732 #define MT_WTBL_RATE_NSS			GENMASK(12, 10)
733 #define MT_WTBL_RATE_HE_GI			GENMASK(7, 4)
734 #define MT_WTBL_RATE_GI				GENMASK(3, 0)
735 
736 #define MT_WTBL_W5_CHANGE_BW_RATE		GENMASK(7, 5)
737 #define MT_WTBL_W5_SHORT_GI_20			BIT(8)
738 #define MT_WTBL_W5_SHORT_GI_40			BIT(9)
739 #define MT_WTBL_W5_SHORT_GI_80			BIT(10)
740 #define MT_WTBL_W5_SHORT_GI_160			BIT(11)
741 #define MT_WTBL_W5_BW_CAP			GENMASK(13, 12)
742 #define MT_WTBL_W5_MPDU_FAIL_COUNT		GENMASK(25, 23)
743 #define MT_WTBL_W5_MPDU_OK_COUNT		GENMASK(28, 26)
744 #define MT_WTBL_W5_RATE_IDX			GENMASK(31, 29)
745 
746 enum {
747 	WTBL_RESET_AND_SET = 1,
748 	WTBL_SET,
749 	WTBL_QUERY,
750 	WTBL_RESET_ALL
751 };
752 
753 enum {
754 	MT_BA_TYPE_INVALID,
755 	MT_BA_TYPE_ORIGINATOR,
756 	MT_BA_TYPE_RECIPIENT
757 };
758 
759 enum {
760 	RST_BA_MAC_TID_MATCH,
761 	RST_BA_MAC_MATCH,
762 	RST_BA_NO_MATCH
763 };
764 
765 enum {
766 	DEV_INFO_ACTIVE,
767 	DEV_INFO_MAX_NUM
768 };
769 
770 /* event table */
771 enum {
772 	MCU_EVENT_TARGET_ADDRESS_LEN = 0x01,
773 	MCU_EVENT_FW_START = 0x01,
774 	MCU_EVENT_GENERIC = 0x01,
775 	MCU_EVENT_ACCESS_REG = 0x02,
776 	MCU_EVENT_MT_PATCH_SEM = 0x04,
777 	MCU_EVENT_REG_ACCESS = 0x05,
778 	MCU_EVENT_LP_INFO = 0x07,
779 	MCU_EVENT_SCAN_DONE = 0x0d,
780 	MCU_EVENT_TX_DONE = 0x0f,
781 	MCU_EVENT_ROC = 0x10,
782 	MCU_EVENT_BSS_ABSENCE  = 0x11,
783 	MCU_EVENT_BSS_BEACON_LOSS = 0x13,
784 	MCU_EVENT_CH_PRIVILEGE = 0x18,
785 	MCU_EVENT_SCHED_SCAN_DONE = 0x23,
786 	MCU_EVENT_DBG_MSG = 0x27,
787 	MCU_EVENT_TXPWR = 0xd0,
788 	MCU_EVENT_EXT = 0xed,
789 	MCU_EVENT_RESTART_DL = 0xef,
790 	MCU_EVENT_COREDUMP = 0xf0,
791 };
792 
793 /* ext event table */
794 enum {
795 	MCU_EXT_EVENT_PS_SYNC = 0x5,
796 	MCU_EXT_EVENT_FW_LOG_2_HOST = 0x13,
797 	MCU_EXT_EVENT_THERMAL_PROTECT = 0x22,
798 	MCU_EXT_EVENT_ASSERT_DUMP = 0x23,
799 	MCU_EXT_EVENT_RDD_REPORT = 0x3a,
800 	MCU_EXT_EVENT_CSA_NOTIFY = 0x4f,
801 	MCU_EXT_EVENT_BCC_NOTIFY = 0x75,
802 	MCU_EXT_EVENT_MURU_CTRL = 0x9f,
803 };
804 
805 enum {
806 	MCU_Q_QUERY,
807 	MCU_Q_SET,
808 	MCU_Q_RESERVED,
809 	MCU_Q_NA
810 };
811 
812 enum {
813 	MCU_S2D_H2N,
814 	MCU_S2D_C2N,
815 	MCU_S2D_H2C,
816 	MCU_S2D_H2CN
817 };
818 
819 enum {
820 	PATCH_NOT_DL_SEM_FAIL,
821 	PATCH_IS_DL,
822 	PATCH_NOT_DL_SEM_SUCCESS,
823 	PATCH_REL_SEM_SUCCESS
824 };
825 
826 enum {
827 	FW_STATE_INITIAL,
828 	FW_STATE_FW_DOWNLOAD,
829 	FW_STATE_NORMAL_OPERATION,
830 	FW_STATE_NORMAL_TRX,
831 	FW_STATE_RDY = 7
832 };
833 
834 enum {
835 	CH_SWITCH_NORMAL = 0,
836 	CH_SWITCH_SCAN = 3,
837 	CH_SWITCH_MCC = 4,
838 	CH_SWITCH_DFS = 5,
839 	CH_SWITCH_BACKGROUND_SCAN_START = 6,
840 	CH_SWITCH_BACKGROUND_SCAN_RUNNING = 7,
841 	CH_SWITCH_BACKGROUND_SCAN_STOP = 8,
842 	CH_SWITCH_SCAN_BYPASS_DPD = 9
843 };
844 
845 enum {
846 	THERMAL_SENSOR_TEMP_QUERY,
847 	THERMAL_SENSOR_MANUAL_CTRL,
848 	THERMAL_SENSOR_INFO_QUERY,
849 	THERMAL_SENSOR_TASK_CTRL,
850 };
851 
852 enum mcu_cipher_type {
853 	MCU_CIPHER_NONE = 0,
854 	MCU_CIPHER_WEP40,
855 	MCU_CIPHER_WEP104,
856 	MCU_CIPHER_WEP128,
857 	MCU_CIPHER_TKIP,
858 	MCU_CIPHER_AES_CCMP,
859 	MCU_CIPHER_CCMP_256,
860 	MCU_CIPHER_GCMP,
861 	MCU_CIPHER_GCMP_256,
862 	MCU_CIPHER_WAPI,
863 	MCU_CIPHER_BIP_CMAC_128,
864 };
865 
866 enum {
867 	EE_MODE_EFUSE,
868 	EE_MODE_BUFFER,
869 };
870 
871 enum {
872 	EE_FORMAT_BIN,
873 	EE_FORMAT_WHOLE,
874 	EE_FORMAT_MULTIPLE,
875 };
876 
877 enum {
878 	MCU_PHY_STATE_TX_RATE,
879 	MCU_PHY_STATE_RX_RATE,
880 	MCU_PHY_STATE_RSSI,
881 	MCU_PHY_STATE_CONTENTION_RX_RATE,
882 	MCU_PHY_STATE_OFDMLQ_CNINFO,
883 };
884 
885 #define MCU_CMD_ACK				BIT(0)
886 #define MCU_CMD_UNI				BIT(1)
887 #define MCU_CMD_QUERY				BIT(2)
888 
889 #define MCU_CMD_UNI_EXT_ACK			(MCU_CMD_ACK | MCU_CMD_UNI | \
890 						 MCU_CMD_QUERY)
891 
892 #define __MCU_CMD_FIELD_ID			GENMASK(7, 0)
893 #define __MCU_CMD_FIELD_EXT_ID			GENMASK(15, 8)
894 #define __MCU_CMD_FIELD_QUERY			BIT(16)
895 #define __MCU_CMD_FIELD_UNI			BIT(17)
896 #define __MCU_CMD_FIELD_CE			BIT(18)
897 #define __MCU_CMD_FIELD_WA			BIT(19)
898 
899 #define MCU_CMD(_t)				FIELD_PREP(__MCU_CMD_FIELD_ID,		\
900 							   MCU_CMD_##_t)
901 #define MCU_EXT_CMD(_t)				(MCU_CMD(EXT_CID) | \
902 						 FIELD_PREP(__MCU_CMD_FIELD_EXT_ID,	\
903 							    MCU_EXT_CMD_##_t))
904 #define MCU_EXT_QUERY(_t)			(MCU_EXT_CMD(_t) | __MCU_CMD_FIELD_QUERY)
905 #define MCU_UNI_CMD(_t)				(__MCU_CMD_FIELD_UNI |			\
906 						 FIELD_PREP(__MCU_CMD_FIELD_ID,		\
907 							    MCU_UNI_CMD_##_t))
908 #define MCU_CE_CMD(_t)				(__MCU_CMD_FIELD_CE |			\
909 						 FIELD_PREP(__MCU_CMD_FIELD_ID,		\
910 							   MCU_CE_CMD_##_t))
911 #define MCU_CE_QUERY(_t)			(MCU_CE_CMD(_t) | __MCU_CMD_FIELD_QUERY)
912 
913 #define MCU_WA_CMD(_t)				(MCU_CMD(_t) | __MCU_CMD_FIELD_WA)
914 #define MCU_WA_EXT_CMD(_t)			(MCU_EXT_CMD(_t) | __MCU_CMD_FIELD_WA)
915 #define MCU_WA_PARAM_CMD(_t)			(MCU_WA_CMD(WA_PARAM) | \
916 						 FIELD_PREP(__MCU_CMD_FIELD_EXT_ID, \
917 							    MCU_WA_PARAM_CMD_##_t))
918 
919 enum {
920 	MCU_EXT_CMD_EFUSE_ACCESS = 0x01,
921 	MCU_EXT_CMD_RF_REG_ACCESS = 0x02,
922 	MCU_EXT_CMD_RF_TEST = 0x04,
923 	MCU_EXT_CMD_PM_STATE_CTRL = 0x07,
924 	MCU_EXT_CMD_CHANNEL_SWITCH = 0x08,
925 	MCU_EXT_CMD_SET_TX_POWER_CTRL = 0x11,
926 	MCU_EXT_CMD_FW_LOG_2_HOST = 0x13,
927 	MCU_EXT_CMD_TXBF_ACTION = 0x1e,
928 	MCU_EXT_CMD_EFUSE_BUFFER_MODE = 0x21,
929 	MCU_EXT_CMD_THERMAL_PROT = 0x23,
930 	MCU_EXT_CMD_STA_REC_UPDATE = 0x25,
931 	MCU_EXT_CMD_BSS_INFO_UPDATE = 0x26,
932 	MCU_EXT_CMD_EDCA_UPDATE = 0x27,
933 	MCU_EXT_CMD_DEV_INFO_UPDATE = 0x2A,
934 	MCU_EXT_CMD_THERMAL_CTRL = 0x2c,
935 	MCU_EXT_CMD_WTBL_UPDATE = 0x32,
936 	MCU_EXT_CMD_SET_DRR_CTRL = 0x36,
937 	MCU_EXT_CMD_SET_RDD_CTRL = 0x3a,
938 	MCU_EXT_CMD_ATE_CTRL = 0x3d,
939 	MCU_EXT_CMD_PROTECT_CTRL = 0x3e,
940 	MCU_EXT_CMD_DBDC_CTRL = 0x45,
941 	MCU_EXT_CMD_MAC_INIT_CTRL = 0x46,
942 	MCU_EXT_CMD_RX_HDR_TRANS = 0x47,
943 	MCU_EXT_CMD_MUAR_UPDATE = 0x48,
944 	MCU_EXT_CMD_BCN_OFFLOAD = 0x49,
945 	MCU_EXT_CMD_RX_AIRTIME_CTRL = 0x4a,
946 	MCU_EXT_CMD_SET_RX_PATH = 0x4e,
947 	MCU_EXT_CMD_EFUSE_FREE_BLOCK = 0x4f,
948 	MCU_EXT_CMD_TX_POWER_FEATURE_CTRL = 0x58,
949 	MCU_EXT_CMD_RXDCOC_CAL = 0x59,
950 	MCU_EXT_CMD_GET_MIB_INFO = 0x5a,
951 	MCU_EXT_CMD_TXDPD_CAL = 0x60,
952 	MCU_EXT_CMD_CAL_CACHE = 0x67,
953 	MCU_EXT_CMD_SET_RADAR_TH = 0x7c,
954 	MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d,
955 	MCU_EXT_CMD_MWDS_SUPPORT = 0x80,
956 	MCU_EXT_CMD_SET_SER_TRIGGER = 0x81,
957 	MCU_EXT_CMD_SCS_CTRL = 0x82,
958 	MCU_EXT_CMD_TWT_AGRT_UPDATE = 0x94,
959 	MCU_EXT_CMD_FW_DBG_CTRL = 0x95,
960 	MCU_EXT_CMD_SET_RDD_TH = 0x9d,
961 	MCU_EXT_CMD_MURU_CTRL = 0x9f,
962 	MCU_EXT_CMD_SET_SPR = 0xa8,
963 	MCU_EXT_CMD_GROUP_PRE_CAL_INFO = 0xab,
964 	MCU_EXT_CMD_DPD_PRE_CAL_INFO = 0xac,
965 	MCU_EXT_CMD_PHY_STAT_INFO = 0xad,
966 };
967 
968 enum {
969 	MCU_UNI_CMD_DEV_INFO_UPDATE = 0x01,
970 	MCU_UNI_CMD_BSS_INFO_UPDATE = 0x02,
971 	MCU_UNI_CMD_STA_REC_UPDATE = 0x03,
972 	MCU_UNI_CMD_SUSPEND = 0x05,
973 	MCU_UNI_CMD_OFFLOAD = 0x06,
974 	MCU_UNI_CMD_HIF_CTRL = 0x07,
975 };
976 
977 enum {
978 	MCU_CMD_TARGET_ADDRESS_LEN_REQ = 0x01,
979 	MCU_CMD_FW_START_REQ = 0x02,
980 	MCU_CMD_INIT_ACCESS_REG = 0x3,
981 	MCU_CMD_NIC_POWER_CTRL = 0x4,
982 	MCU_CMD_PATCH_START_REQ = 0x05,
983 	MCU_CMD_PATCH_FINISH_REQ = 0x07,
984 	MCU_CMD_PATCH_SEM_CONTROL = 0x10,
985 	MCU_CMD_WA_PARAM = 0xc4,
986 	MCU_CMD_EXT_CID = 0xed,
987 	MCU_CMD_FW_SCATTER = 0xee,
988 	MCU_CMD_RESTART_DL_REQ = 0xef,
989 };
990 
991 /* offload mcu commands */
992 enum {
993 	MCU_CE_CMD_TEST_CTRL = 0x01,
994 	MCU_CE_CMD_START_HW_SCAN = 0x03,
995 	MCU_CE_CMD_SET_PS_PROFILE = 0x05,
996 	MCU_CE_CMD_SET_CHAN_DOMAIN = 0x0f,
997 	MCU_CE_CMD_SET_BSS_CONNECTED = 0x16,
998 	MCU_CE_CMD_SET_BSS_ABORT = 0x17,
999 	MCU_CE_CMD_CANCEL_HW_SCAN = 0x1b,
1000 	MCU_CE_CMD_SET_ROC = 0x1d,
1001 	MCU_CE_CMD_SET_P2P_OPPPS = 0x33,
1002 	MCU_CE_CMD_SET_RATE_TX_POWER = 0x5d,
1003 	MCU_CE_CMD_SCHED_SCAN_ENABLE = 0x61,
1004 	MCU_CE_CMD_SCHED_SCAN_REQ = 0x62,
1005 	MCU_CE_CMD_GET_NIC_CAPAB = 0x8a,
1006 	MCU_CE_CMD_SET_MU_EDCA_PARMS = 0xb0,
1007 	MCU_CE_CMD_REG_WRITE = 0xc0,
1008 	MCU_CE_CMD_REG_READ = 0xc0,
1009 	MCU_CE_CMD_CHIP_CONFIG = 0xca,
1010 	MCU_CE_CMD_FWLOG_2_HOST = 0xc5,
1011 	MCU_CE_CMD_GET_WTBL = 0xcd,
1012 	MCU_CE_CMD_GET_TXPWR = 0xd0,
1013 };
1014 
1015 enum {
1016 	PATCH_SEM_RELEASE,
1017 	PATCH_SEM_GET
1018 };
1019 
1020 enum {
1021 	UNI_BSS_INFO_BASIC = 0,
1022 	UNI_BSS_INFO_RLM = 2,
1023 	UNI_BSS_INFO_BSS_COLOR = 4,
1024 	UNI_BSS_INFO_HE_BASIC = 5,
1025 	UNI_BSS_INFO_BCN_CONTENT = 7,
1026 	UNI_BSS_INFO_QBSS = 15,
1027 	UNI_BSS_INFO_UAPSD = 19,
1028 	UNI_BSS_INFO_PS = 21,
1029 	UNI_BSS_INFO_BCNFT = 22,
1030 };
1031 
1032 enum {
1033 	UNI_OFFLOAD_OFFLOAD_ARP,
1034 	UNI_OFFLOAD_OFFLOAD_ND,
1035 	UNI_OFFLOAD_OFFLOAD_GTK_REKEY,
1036 	UNI_OFFLOAD_OFFLOAD_BMC_RPY_DETECT,
1037 };
1038 
1039 enum {
1040 	MT_NIC_CAP_TX_RESOURCE,
1041 	MT_NIC_CAP_TX_EFUSE_ADDR,
1042 	MT_NIC_CAP_COEX,
1043 	MT_NIC_CAP_SINGLE_SKU,
1044 	MT_NIC_CAP_CSUM_OFFLOAD,
1045 	MT_NIC_CAP_HW_VER,
1046 	MT_NIC_CAP_SW_VER,
1047 	MT_NIC_CAP_MAC_ADDR,
1048 	MT_NIC_CAP_PHY,
1049 	MT_NIC_CAP_MAC,
1050 	MT_NIC_CAP_FRAME_BUF,
1051 	MT_NIC_CAP_BEAM_FORM,
1052 	MT_NIC_CAP_LOCATION,
1053 	MT_NIC_CAP_MUMIMO,
1054 	MT_NIC_CAP_BUFFER_MODE_INFO,
1055 	MT_NIC_CAP_HW_ADIE_VERSION = 0x14,
1056 	MT_NIC_CAP_ANTSWP = 0x16,
1057 	MT_NIC_CAP_WFDMA_REALLOC,
1058 	MT_NIC_CAP_6G,
1059 };
1060 
1061 #define UNI_WOW_DETECT_TYPE_MAGIC		BIT(0)
1062 #define UNI_WOW_DETECT_TYPE_ANY			BIT(1)
1063 #define UNI_WOW_DETECT_TYPE_DISCONNECT		BIT(2)
1064 #define UNI_WOW_DETECT_TYPE_GTK_REKEY_FAIL	BIT(3)
1065 #define UNI_WOW_DETECT_TYPE_BCN_LOST		BIT(4)
1066 #define UNI_WOW_DETECT_TYPE_SCH_SCAN_HIT	BIT(5)
1067 #define UNI_WOW_DETECT_TYPE_BITMAP		BIT(6)
1068 
1069 enum {
1070 	UNI_SUSPEND_MODE_SETTING,
1071 	UNI_SUSPEND_WOW_CTRL,
1072 	UNI_SUSPEND_WOW_GPIO_PARAM,
1073 	UNI_SUSPEND_WOW_WAKEUP_PORT,
1074 	UNI_SUSPEND_WOW_PATTERN,
1075 };
1076 
1077 enum {
1078 	WOW_USB = 1,
1079 	WOW_PCIE = 2,
1080 	WOW_GPIO = 3,
1081 };
1082 
1083 struct mt76_connac_bss_basic_tlv {
1084 	__le16 tag;
1085 	__le16 len;
1086 	u8 active;
1087 	u8 omac_idx;
1088 	u8 hw_bss_idx;
1089 	u8 band_idx;
1090 	__le32 conn_type;
1091 	u8 conn_state;
1092 	u8 wmm_idx;
1093 	u8 bssid[ETH_ALEN];
1094 	__le16 bmc_tx_wlan_idx;
1095 	__le16 bcn_interval;
1096 	u8 dtim_period;
1097 	u8 phymode; /* bit(0): A
1098 		     * bit(1): B
1099 		     * bit(2): G
1100 		     * bit(3): GN
1101 		     * bit(4): AN
1102 		     * bit(5): AC
1103 		     * bit(6): AX2
1104 		     * bit(7): AX5
1105 		     * bit(8): AX6
1106 		     */
1107 	__le16 sta_idx;
1108 	__le16 nonht_basic_phy;
1109 	u8 phymode_ext; /* bit(0) AX_6G */
1110 	u8 pad[1];
1111 } __packed;
1112 
1113 struct mt76_connac_bss_qos_tlv {
1114 	__le16 tag;
1115 	__le16 len;
1116 	u8 qos;
1117 	u8 pad[3];
1118 } __packed;
1119 
1120 struct mt76_connac_beacon_loss_event {
1121 	u8 bss_idx;
1122 	u8 reason;
1123 	u8 pad[2];
1124 } __packed;
1125 
1126 struct mt76_connac_mcu_bss_event {
1127 	u8 bss_idx;
1128 	u8 is_absent;
1129 	u8 free_quota;
1130 	u8 pad;
1131 } __packed;
1132 
1133 struct mt76_connac_mcu_scan_ssid {
1134 	__le32 ssid_len;
1135 	u8 ssid[IEEE80211_MAX_SSID_LEN];
1136 } __packed;
1137 
1138 struct mt76_connac_mcu_scan_channel {
1139 	u8 band; /* 1: 2.4GHz
1140 		  * 2: 5.0GHz
1141 		  * Others: Reserved
1142 		  */
1143 	u8 channel_num;
1144 } __packed;
1145 
1146 struct mt76_connac_mcu_scan_match {
1147 	__le32 rssi_th;
1148 	u8 ssid[IEEE80211_MAX_SSID_LEN];
1149 	u8 ssid_len;
1150 	u8 rsv[3];
1151 } __packed;
1152 
1153 struct mt76_connac_hw_scan_req {
1154 	u8 seq_num;
1155 	u8 bss_idx;
1156 	u8 scan_type; /* 0: PASSIVE SCAN
1157 		       * 1: ACTIVE SCAN
1158 		       */
1159 	u8 ssid_type; /* BIT(0) wildcard SSID
1160 		       * BIT(1) P2P wildcard SSID
1161 		       * BIT(2) specified SSID + wildcard SSID
1162 		       * BIT(2) + ssid_type_ext BIT(0) specified SSID only
1163 		       */
1164 	u8 ssids_num;
1165 	u8 probe_req_num; /* Number of probe request for each SSID */
1166 	u8 scan_func; /* BIT(0) Enable random MAC scan
1167 		       * BIT(1) Disable DBDC scan type 1~3.
1168 		       * BIT(2) Use DBDC scan type 3 (dedicated one RF to scan).
1169 		       */
1170 	u8 version; /* 0: Not support fields after ies.
1171 		     * 1: Support fields after ies.
1172 		     */
1173 	struct mt76_connac_mcu_scan_ssid ssids[4];
1174 	__le16 probe_delay_time;
1175 	__le16 channel_dwell_time; /* channel Dwell interval */
1176 	__le16 timeout_value;
1177 	u8 channel_type; /* 0: Full channels
1178 			  * 1: Only 2.4GHz channels
1179 			  * 2: Only 5GHz channels
1180 			  * 3: P2P social channel only (channel #1, #6 and #11)
1181 			  * 4: Specified channels
1182 			  * Others: Reserved
1183 			  */
1184 	u8 channels_num; /* valid when channel_type is 4 */
1185 	/* valid when channels_num is set */
1186 	struct mt76_connac_mcu_scan_channel channels[32];
1187 	__le16 ies_len;
1188 	u8 ies[MT76_CONNAC_SCAN_IE_LEN];
1189 	/* following fields are valid if version > 0 */
1190 	u8 ext_channels_num;
1191 	u8 ext_ssids_num;
1192 	__le16 channel_min_dwell_time;
1193 	struct mt76_connac_mcu_scan_channel ext_channels[32];
1194 	struct mt76_connac_mcu_scan_ssid ext_ssids[6];
1195 	u8 bssid[ETH_ALEN];
1196 	u8 random_mac[ETH_ALEN]; /* valid when BIT(1) in scan_func is set. */
1197 	u8 pad[63];
1198 	u8 ssid_type_ext;
1199 } __packed;
1200 
1201 #define MT76_CONNAC_SCAN_DONE_EVENT_MAX_CHANNEL_NUM		64
1202 
1203 struct mt76_connac_hw_scan_done {
1204 	u8 seq_num;
1205 	u8 sparse_channel_num;
1206 	struct mt76_connac_mcu_scan_channel sparse_channel;
1207 	u8 complete_channel_num;
1208 	u8 current_state;
1209 	u8 version;
1210 	u8 pad;
1211 	__le32 beacon_scan_num;
1212 	u8 pno_enabled;
1213 	u8 pad2[3];
1214 	u8 sparse_channel_valid_num;
1215 	u8 pad3[3];
1216 	u8 channel_num[MT76_CONNAC_SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
1217 	/* idle format for channel_idle_time
1218 	 * 0: first bytes: idle time(ms) 2nd byte: dwell time(ms)
1219 	 * 1: first bytes: idle time(8ms) 2nd byte: dwell time(8ms)
1220 	 * 2: dwell time (16us)
1221 	 */
1222 	__le16 channel_idle_time[MT76_CONNAC_SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
1223 	/* beacon and probe response count */
1224 	u8 beacon_probe_num[MT76_CONNAC_SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
1225 	u8 mdrdy_count[MT76_CONNAC_SCAN_DONE_EVENT_MAX_CHANNEL_NUM];
1226 	__le32 beacon_2g_num;
1227 	__le32 beacon_5g_num;
1228 } __packed;
1229 
1230 struct mt76_connac_sched_scan_req {
1231 	u8 version;
1232 	u8 seq_num;
1233 	u8 stop_on_match;
1234 	u8 ssids_num;
1235 	u8 match_num;
1236 	u8 pad;
1237 	__le16 ie_len;
1238 	struct mt76_connac_mcu_scan_ssid ssids[MT76_CONNAC_MAX_SCHED_SCAN_SSID];
1239 	struct mt76_connac_mcu_scan_match match[MT76_CONNAC_MAX_SCAN_MATCH];
1240 	u8 channel_type;
1241 	u8 channels_num;
1242 	u8 intervals_num;
1243 	u8 scan_func; /* MT7663: BIT(0) eable random mac address */
1244 	struct mt76_connac_mcu_scan_channel channels[64];
1245 	__le16 intervals[MT76_CONNAC_MAX_NUM_SCHED_SCAN_INTERVAL];
1246 	union {
1247 		struct {
1248 			u8 random_mac[ETH_ALEN];
1249 			u8 pad2[58];
1250 		} mt7663;
1251 		struct {
1252 			u8 bss_idx;
1253 			u8 pad1[3];
1254 			__le32 delay;
1255 			u8 pad2[12];
1256 			u8 random_mac[ETH_ALEN];
1257 			u8 pad3[38];
1258 		} mt7921;
1259 	};
1260 } __packed;
1261 
1262 struct mt76_connac_sched_scan_done {
1263 	u8 seq_num;
1264 	u8 status; /* 0: ssid found */
1265 	__le16 pad;
1266 } __packed;
1267 
1268 struct bss_info_uni_bss_color {
1269 	__le16 tag;
1270 	__le16 len;
1271 	u8 enable;
1272 	u8 bss_color;
1273 	u8 rsv[2];
1274 } __packed;
1275 
1276 struct bss_info_uni_he {
1277 	__le16 tag;
1278 	__le16 len;
1279 	__le16 he_rts_thres;
1280 	u8 he_pe_duration;
1281 	u8 su_disable;
1282 	__le16 max_nss_mcs[CMD_HE_MCS_BW_NUM];
1283 	u8 rsv[2];
1284 } __packed;
1285 
1286 struct mt76_connac_gtk_rekey_tlv {
1287 	__le16 tag;
1288 	__le16 len;
1289 	u8 kek[NL80211_KEK_LEN];
1290 	u8 kck[NL80211_KCK_LEN];
1291 	u8 replay_ctr[NL80211_REPLAY_CTR_LEN];
1292 	u8 rekey_mode; /* 0: rekey offload enable
1293 			* 1: rekey offload disable
1294 			* 2: rekey update
1295 			*/
1296 	u8 keyid;
1297 	u8 option; /* 1: rekey data update without enabling offload */
1298 	u8 pad[1];
1299 	__le32 proto; /* WPA-RSN-WAPI-OPSN */
1300 	__le32 pairwise_cipher;
1301 	__le32 group_cipher;
1302 	__le32 key_mgmt; /* NONE-PSK-IEEE802.1X */
1303 	__le32 mgmt_group_cipher;
1304 	u8 reserverd[4];
1305 } __packed;
1306 
1307 #define MT76_CONNAC_WOW_MASK_MAX_LEN			16
1308 #define MT76_CONNAC_WOW_PATTEN_MAX_LEN			128
1309 
1310 struct mt76_connac_wow_pattern_tlv {
1311 	__le16 tag;
1312 	__le16 len;
1313 	u8 index; /* pattern index */
1314 	u8 enable; /* 0: disable
1315 		    * 1: enable
1316 		    */
1317 	u8 data_len; /* pattern length */
1318 	u8 pad;
1319 	u8 mask[MT76_CONNAC_WOW_MASK_MAX_LEN];
1320 	u8 pattern[MT76_CONNAC_WOW_PATTEN_MAX_LEN];
1321 	u8 rsv[4];
1322 } __packed;
1323 
1324 struct mt76_connac_wow_ctrl_tlv {
1325 	__le16 tag;
1326 	__le16 len;
1327 	u8 cmd; /* 0x1: PM_WOWLAN_REQ_START
1328 		 * 0x2: PM_WOWLAN_REQ_STOP
1329 		 * 0x3: PM_WOWLAN_PARAM_CLEAR
1330 		 */
1331 	u8 trigger; /* 0: NONE
1332 		     * BIT(0): NL80211_WOWLAN_TRIG_MAGIC_PKT
1333 		     * BIT(1): NL80211_WOWLAN_TRIG_ANY
1334 		     * BIT(2): NL80211_WOWLAN_TRIG_DISCONNECT
1335 		     * BIT(3): NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
1336 		     * BIT(4): BEACON_LOST
1337 		     * BIT(5): NL80211_WOWLAN_TRIG_NET_DETECT
1338 		     */
1339 	u8 wakeup_hif; /* 0x0: HIF_SDIO
1340 			* 0x1: HIF_USB
1341 			* 0x2: HIF_PCIE
1342 			* 0x3: HIF_GPIO
1343 			*/
1344 	u8 pad;
1345 	u8 rsv[4];
1346 } __packed;
1347 
1348 struct mt76_connac_wow_gpio_param_tlv {
1349 	__le16 tag;
1350 	__le16 len;
1351 	u8 gpio_pin;
1352 	u8 trigger_lvl;
1353 	u8 pad[2];
1354 	__le32 gpio_interval;
1355 	u8 rsv[4];
1356 } __packed;
1357 
1358 struct mt76_connac_arpns_tlv {
1359 	__le16 tag;
1360 	__le16 len;
1361 	u8 mode;
1362 	u8 ips_num;
1363 	u8 option;
1364 	u8 pad[1];
1365 } __packed;
1366 
1367 struct mt76_connac_suspend_tlv {
1368 	__le16 tag;
1369 	__le16 len;
1370 	u8 enable; /* 0: suspend mode disabled
1371 		    * 1: suspend mode enabled
1372 		    */
1373 	u8 mdtim; /* LP parameter */
1374 	u8 wow_suspend; /* 0: update by origin policy
1375 			 * 1: update by wow dtim
1376 			 */
1377 	u8 pad[5];
1378 } __packed;
1379 
1380 enum mt76_sta_info_state {
1381 	MT76_STA_INFO_STATE_NONE,
1382 	MT76_STA_INFO_STATE_AUTH,
1383 	MT76_STA_INFO_STATE_ASSOC
1384 };
1385 
1386 struct mt76_sta_cmd_info {
1387 	struct ieee80211_sta *sta;
1388 	struct mt76_wcid *wcid;
1389 
1390 	struct ieee80211_vif *vif;
1391 
1392 	bool offload_fw;
1393 	bool enable;
1394 	bool newly;
1395 	int cmd;
1396 	u8 rcpi;
1397 	u8 state;
1398 };
1399 
1400 #define MT_SKU_POWER_LIMIT	161
1401 
1402 struct mt76_connac_sku_tlv {
1403 	u8 channel;
1404 	s8 pwr_limit[MT_SKU_POWER_LIMIT];
1405 } __packed;
1406 
1407 struct mt76_connac_tx_power_limit_tlv {
1408 	/* DW0 - common info*/
1409 	u8 ver;
1410 	u8 pad0;
1411 	__le16 len;
1412 	/* DW1 - cmd hint */
1413 	u8 n_chan; /* # channel */
1414 	u8 band; /* 2.4GHz - 5GHz - 6GHz */
1415 	u8 last_msg;
1416 	u8 pad1;
1417 	/* DW3 */
1418 	u8 alpha2[4]; /* regulatory_request.alpha2 */
1419 	u8 pad2[32];
1420 } __packed;
1421 
1422 struct mt76_connac_config {
1423 	__le16 id;
1424 	u8 type;
1425 	u8 resp_type;
1426 	__le16 data_size;
1427 	__le16 resv;
1428 	u8 data[320];
1429 } __packed;
1430 
1431 static inline enum mcu_cipher_type
1432 mt76_connac_mcu_get_cipher(int cipher)
1433 {
1434 	switch (cipher) {
1435 	case WLAN_CIPHER_SUITE_WEP40:
1436 		return MCU_CIPHER_WEP40;
1437 	case WLAN_CIPHER_SUITE_WEP104:
1438 		return MCU_CIPHER_WEP104;
1439 	case WLAN_CIPHER_SUITE_TKIP:
1440 		return MCU_CIPHER_TKIP;
1441 	case WLAN_CIPHER_SUITE_AES_CMAC:
1442 		return MCU_CIPHER_BIP_CMAC_128;
1443 	case WLAN_CIPHER_SUITE_CCMP:
1444 		return MCU_CIPHER_AES_CCMP;
1445 	case WLAN_CIPHER_SUITE_CCMP_256:
1446 		return MCU_CIPHER_CCMP_256;
1447 	case WLAN_CIPHER_SUITE_GCMP:
1448 		return MCU_CIPHER_GCMP;
1449 	case WLAN_CIPHER_SUITE_GCMP_256:
1450 		return MCU_CIPHER_GCMP_256;
1451 	case WLAN_CIPHER_SUITE_SMS4:
1452 		return MCU_CIPHER_WAPI;
1453 	default:
1454 		return MCU_CIPHER_NONE;
1455 	}
1456 }
1457 
1458 #define to_wcid_lo(id)		FIELD_GET(GENMASK(7, 0), (u16)id)
1459 #define to_wcid_hi(id)		FIELD_GET(GENMASK(9, 8), (u16)id)
1460 
1461 static inline void
1462 mt76_connac_mcu_get_wlan_idx(struct mt76_dev *dev, struct mt76_wcid *wcid,
1463 			     u8 *wlan_idx_lo, u8 *wlan_idx_hi)
1464 {
1465 	*wlan_idx_hi = 0;
1466 
1467 	if (is_mt7921(dev) || is_mt7915(dev) || is_mt7916(dev)) {
1468 		*wlan_idx_lo = wcid ? to_wcid_lo(wcid->idx) : 0;
1469 		*wlan_idx_hi = wcid ? to_wcid_hi(wcid->idx) : 0;
1470 	} else {
1471 		*wlan_idx_lo = wcid ? wcid->idx : 0;
1472 	}
1473 }
1474 
1475 struct sk_buff *
1476 __mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif *mvif,
1477 				struct mt76_wcid *wcid, int len);
1478 static inline struct sk_buff *
1479 mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif *mvif,
1480 			      struct mt76_wcid *wcid)
1481 {
1482 	return __mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid,
1483 					       MT76_CONNAC_STA_UPDATE_MAX_SIZE);
1484 }
1485 
1486 struct wtbl_req_hdr *
1487 mt76_connac_mcu_alloc_wtbl_req(struct mt76_dev *dev, struct mt76_wcid *wcid,
1488 			       int cmd, void *sta_wtbl, struct sk_buff **skb);
1489 struct tlv *mt76_connac_mcu_add_nested_tlv(struct sk_buff *skb, int tag,
1490 					   int len, void *sta_ntlv,
1491 					   void *sta_wtbl);
1492 static inline struct tlv *
1493 mt76_connac_mcu_add_tlv(struct sk_buff *skb, int tag, int len)
1494 {
1495 	return mt76_connac_mcu_add_nested_tlv(skb, tag, len, skb->data, NULL);
1496 }
1497 
1498 int mt76_connac_mcu_set_channel_domain(struct mt76_phy *phy);
1499 int mt76_connac_mcu_set_vif_ps(struct mt76_dev *dev, struct ieee80211_vif *vif);
1500 void mt76_connac_mcu_sta_basic_tlv(struct sk_buff *skb,
1501 				   struct ieee80211_vif *vif,
1502 				   struct ieee80211_sta *sta, bool enable,
1503 				   bool newly);
1504 void mt76_connac_mcu_wtbl_generic_tlv(struct mt76_dev *dev, struct sk_buff *skb,
1505 				      struct ieee80211_vif *vif,
1506 				      struct ieee80211_sta *sta, void *sta_wtbl,
1507 				      void *wtbl_tlv);
1508 void mt76_connac_mcu_wtbl_hdr_trans_tlv(struct sk_buff *skb,
1509 					struct ieee80211_vif *vif,
1510 					struct mt76_wcid *wcid,
1511 					void *sta_wtbl, void *wtbl_tlv);
1512 int mt76_connac_mcu_sta_update_hdr_trans(struct mt76_dev *dev,
1513 					 struct ieee80211_vif *vif,
1514 					 struct mt76_wcid *wcid, int cmd);
1515 void mt76_connac_mcu_sta_tlv(struct mt76_phy *mphy, struct sk_buff *skb,
1516 			     struct ieee80211_sta *sta,
1517 			     struct ieee80211_vif *vif,
1518 			     u8 rcpi, u8 state);
1519 void mt76_connac_mcu_wtbl_ht_tlv(struct mt76_dev *dev, struct sk_buff *skb,
1520 				 struct ieee80211_sta *sta, void *sta_wtbl,
1521 				 void *wtbl_tlv);
1522 void mt76_connac_mcu_wtbl_ba_tlv(struct mt76_dev *dev, struct sk_buff *skb,
1523 				 struct ieee80211_ampdu_params *params,
1524 				 bool enable, bool tx, void *sta_wtbl,
1525 				 void *wtbl_tlv);
1526 void mt76_connac_mcu_sta_ba_tlv(struct sk_buff *skb,
1527 				struct ieee80211_ampdu_params *params,
1528 				bool enable, bool tx);
1529 int mt76_connac_mcu_uni_add_dev(struct mt76_phy *phy,
1530 				struct ieee80211_vif *vif,
1531 				struct mt76_wcid *wcid,
1532 				bool enable);
1533 int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif,
1534 			   struct ieee80211_ampdu_params *params,
1535 			   bool enable, bool tx);
1536 int mt76_connac_mcu_uni_add_bss(struct mt76_phy *phy,
1537 				struct ieee80211_vif *vif,
1538 				struct mt76_wcid *wcid,
1539 				bool enable);
1540 int mt76_connac_mcu_sta_cmd(struct mt76_phy *phy,
1541 			    struct mt76_sta_cmd_info *info);
1542 void mt76_connac_mcu_beacon_loss_iter(void *priv, u8 *mac,
1543 				      struct ieee80211_vif *vif);
1544 int mt76_connac_mcu_set_rts_thresh(struct mt76_dev *dev, u32 val, u8 band);
1545 int mt76_connac_mcu_set_mac_enable(struct mt76_dev *dev, int band, bool enable,
1546 				   bool hdr_trans);
1547 int mt76_connac_mcu_init_download(struct mt76_dev *dev, u32 addr, u32 len,
1548 				  u32 mode);
1549 int mt76_connac_mcu_start_patch(struct mt76_dev *dev);
1550 int mt76_connac_mcu_patch_sem_ctrl(struct mt76_dev *dev, bool get);
1551 int mt76_connac_mcu_start_firmware(struct mt76_dev *dev, u32 addr, u32 option);
1552 int mt76_connac_mcu_get_nic_capability(struct mt76_phy *phy);
1553 
1554 int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,
1555 			    struct ieee80211_scan_request *scan_req);
1556 int mt76_connac_mcu_cancel_hw_scan(struct mt76_phy *phy,
1557 				   struct ieee80211_vif *vif);
1558 int mt76_connac_mcu_sched_scan_req(struct mt76_phy *phy,
1559 				   struct ieee80211_vif *vif,
1560 				   struct cfg80211_sched_scan_request *sreq);
1561 int mt76_connac_mcu_sched_scan_enable(struct mt76_phy *phy,
1562 				      struct ieee80211_vif *vif,
1563 				      bool enable);
1564 int mt76_connac_mcu_update_arp_filter(struct mt76_dev *dev,
1565 				      struct mt76_vif *vif,
1566 				      struct ieee80211_bss_conf *info);
1567 int mt76_connac_mcu_update_gtk_rekey(struct ieee80211_hw *hw,
1568 				     struct ieee80211_vif *vif,
1569 				     struct cfg80211_gtk_rekey_data *key);
1570 int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend);
1571 void mt76_connac_mcu_set_suspend_iter(void *priv, u8 *mac,
1572 				      struct ieee80211_vif *vif);
1573 int mt76_connac_sta_state_dp(struct mt76_dev *dev,
1574 			     enum ieee80211_sta_state old_state,
1575 			     enum ieee80211_sta_state new_state);
1576 int mt76_connac_mcu_chip_config(struct mt76_dev *dev);
1577 int mt76_connac_mcu_set_deep_sleep(struct mt76_dev *dev, bool enable);
1578 void mt76_connac_mcu_coredump_event(struct mt76_dev *dev, struct sk_buff *skb,
1579 				    struct mt76_connac_coredump *coredump);
1580 int mt76_connac_mcu_set_rate_txpower(struct mt76_phy *phy);
1581 int mt76_connac_mcu_set_p2p_oppps(struct ieee80211_hw *hw,
1582 				  struct ieee80211_vif *vif);
1583 u32 mt76_connac_mcu_reg_rr(struct mt76_dev *dev, u32 offset);
1584 void mt76_connac_mcu_reg_wr(struct mt76_dev *dev, u32 offset, u32 val);
1585 
1586 const struct ieee80211_sta_he_cap *
1587 mt76_connac_get_he_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif);
1588 u8 mt76_connac_get_phy_mode(struct mt76_phy *phy, struct ieee80211_vif *vif,
1589 			    enum nl80211_band band, struct ieee80211_sta *sta);
1590 
1591 int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
1592 			    struct mt76_connac_sta_key_conf *sta_key_conf,
1593 			    struct ieee80211_key_conf *key, int mcu_cmd,
1594 			    struct mt76_wcid *wcid, enum set_key_cmd cmd);
1595 
1596 void mt76_connac_mcu_bss_omac_tlv(struct sk_buff *skb,
1597 				  struct ieee80211_vif *vif);
1598 #endif /* __MT76_CONNAC_MCU_H */
1599