1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2023 MediaTek Inc. */
3 
4 #ifndef __MT7925_MCU_H
5 #define __MT7925_MCU_H
6 
7 #include "../mt76_connac_mcu.h"
8 
9 /* ext event table */
10 enum {
11 	MCU_EXT_EVENT_RATE_REPORT = 0x87,
12 };
13 
14 struct mt7925_mcu_eeprom_info {
15 	__le32 addr;
16 	__le32 valid;
17 	u8 data[MT7925_EEPROM_BLOCK_SIZE];
18 } __packed;
19 
20 #define MT_RA_RATE_NSS			GENMASK(8, 6)
21 #define MT_RA_RATE_MCS			GENMASK(3, 0)
22 #define MT_RA_RATE_TX_MODE		GENMASK(12, 9)
23 #define MT_RA_RATE_DCM_EN		BIT(4)
24 #define MT_RA_RATE_BW			GENMASK(14, 13)
25 
26 struct mt7925_mcu_rxd {
27 	__le32 rxd[8];
28 
29 	__le16 len;
30 	__le16 pkt_type_id;
31 
32 	u8 eid;
33 	u8 seq;
34 	u8 option;
35 	u8 __rsv;
36 
37 	u8 ext_eid;
38 	u8 __rsv1[2];
39 	u8 s2d_index;
40 
41 	u8 tlv[];
42 };
43 
44 struct mt7925_mcu_uni_event {
45 	u8 cid;
46 	u8 pad[3];
47 	__le32 status; /* 0: success, others: fail */
48 } __packed;
49 
50 enum {
51 	MT_EBF = BIT(0),	/* explicit beamforming */
52 	MT_IBF = BIT(1)		/* implicit beamforming */
53 };
54 
55 struct mt7925_mcu_reg_event {
56 	__le32 reg;
57 	__le32 val;
58 } __packed;
59 
60 struct mt7925_mcu_ant_id_config {
61 	u8 ant_id[4];
62 } __packed;
63 
64 struct mt7925_txpwr_req {
65 	u8 _rsv[4];
66 	__le16 tag;
67 	__le16 len;
68 
69 	u8 format_id;
70 	u8 catg;
71 	u8 band_idx;
72 	u8 _rsv1;
73 } __packed;
74 
75 struct mt7925_txpwr_event {
76 	u8 rsv[4];
77 	__le16 tag;
78 	__le16 len;
79 
80 	u8 catg;
81 	u8 band_idx;
82 	u8 ch_band;
83 	u8 format; /* 0:Legacy, 1:HE */
84 
85 	/* Rate power info */
86 	struct mt7925_txpwr txpwr;
87 
88 	s8 pwr_max;
89 	s8 pwr_min;
90 	u8 rsv1;
91 } __packed;
92 
93 enum {
94 	TM_SWITCH_MODE,
95 	TM_SET_AT_CMD,
96 	TM_QUERY_AT_CMD,
97 };
98 
99 enum {
100 	MT7925_TM_NORMAL,
101 	MT7925_TM_TESTMODE,
102 	MT7925_TM_ICAP,
103 	MT7925_TM_ICAP_OVERLAP,
104 	MT7925_TM_WIFISPECTRUM,
105 };
106 
107 struct mt7925_rftest_cmd {
108 	u8 action;
109 	u8 rsv[3];
110 	__le32 param0;
111 	__le32 param1;
112 } __packed;
113 
114 struct mt7925_rftest_evt {
115 	__le32 param0;
116 	__le32 param1;
117 } __packed;
118 
119 enum {
120 	UNI_CHANNEL_SWITCH,
121 	UNI_CHANNEL_RX_PATH,
122 };
123 
124 enum {
125 	UNI_CHIP_CONFIG_CHIP_CFG = 0x2,
126 	UNI_CHIP_CONFIG_NIC_CAPA = 0x3,
127 };
128 
129 enum {
130 	UNI_BAND_CONFIG_RADIO_ENABLE,
131 	UNI_BAND_CONFIG_RTS_THRESHOLD = 0x08,
132 	UNI_BAND_CONFIG_SET_MAC80211_RX_FILTER = 0x0C,
133 };
134 
135 enum {
136 	UNI_WSYS_CONFIG_FW_LOG_CTRL,
137 	UNI_WSYS_CONFIG_FW_DBG_CTRL,
138 };
139 
140 enum {
141 	UNI_EFUSE_ACCESS = 1,
142 	UNI_EFUSE_BUFFER_MODE,
143 	UNI_EFUSE_FREE_BLOCK,
144 	UNI_EFUSE_BUFFER_RD,
145 };
146 
147 enum {
148 	UNI_CMD_ACCESS_REG_BASIC = 0x0,
149 	UNI_CMD_ACCESS_RF_REG_BASIC,
150 };
151 
152 enum {
153 	UNI_MBMC_SETTING,
154 };
155 
156 enum {
157 	UNI_EVENT_SCAN_DONE_BASIC = 0,
158 	UNI_EVENT_SCAN_DONE_CHNLINFO = 2,
159 	UNI_EVENT_SCAN_DONE_NLO = 3,
160 };
161 
162 struct mt7925_mcu_scan_chinfo_event {
163 	u8 nr_chan;
164 	u8 alpha2[3];
165 } __packed;
166 
167 enum {
168 	UNI_SCAN_REQ = 1,
169 	UNI_SCAN_CANCEL = 2,
170 	UNI_SCAN_SCHED_REQ = 3,
171 	UNI_SCAN_SCHED_ENABLE = 4,
172 	UNI_SCAN_SSID = 10,
173 	UNI_SCAN_BSSID,
174 	UNI_SCAN_CHANNEL,
175 	UNI_SCAN_IE,
176 	UNI_SCAN_MISC,
177 	UNI_SCAN_SSID_MATCH_SETS,
178 };
179 
180 enum {
181 	UNI_SNIFFER_ENABLE,
182 	UNI_SNIFFER_CONFIG,
183 };
184 
185 struct scan_hdr_tlv {
186 	/* fixed field */
187 	u8 seq_num;
188 	u8 bss_idx;
189 	u8 pad[2];
190 	/* tlv */
191 	u8 data[];
192 } __packed;
193 
194 struct scan_req_tlv {
195 	__le16 tag;
196 	__le16 len;
197 
198 	u8 scan_type; /* 0: PASSIVE SCAN
199 		       * 1: ACTIVE SCAN
200 		       */
201 	u8 probe_req_num; /* Number of probe request for each SSID */
202 	u8 scan_func; /* BIT(0) Enable random MAC scan
203 		       * BIT(1) Disable DBDC scan type 1~3.
204 		       * BIT(2) Use DBDC scan type 3 (dedicated one RF to scan).
205 		       */
206 	u8 src_mask;
207 	__le16 channel_min_dwell_time;
208 	__le16 channel_dwell_time; /* channel Dwell interval */
209 	__le16 timeout_value;
210 	__le16 probe_delay_time;
211 	u8 func_mask_ext;
212 };
213 
214 struct scan_ssid_tlv {
215 	__le16 tag;
216 	__le16 len;
217 
218 	u8 ssid_type; /* BIT(0) wildcard SSID
219 		       * BIT(1) P2P wildcard SSID
220 		       * BIT(2) specified SSID + wildcard SSID
221 		       * BIT(2) + ssid_type_ext BIT(0) specified SSID only
222 		       */
223 	u8 ssids_num;
224 	u8 pad[2];
225 	struct mt76_connac_mcu_scan_ssid ssids[4];
226 };
227 
228 struct scan_bssid_tlv {
229 	__le16 tag;
230 	__le16 len;
231 
232 	u8 bssid[ETH_ALEN];
233 	u8 match_ch;
234 	u8 match_ssid_ind;
235 	u8 rcpi;
236 	u8 pad[3];
237 };
238 
239 struct scan_chan_info_tlv {
240 	__le16 tag;
241 	__le16 len;
242 
243 	u8 channel_type; /* 0: Full channels
244 			  * 1: Only 2.4GHz channels
245 			  * 2: Only 5GHz channels
246 			  * 3: P2P social channel only (channel #1, #6 and #11)
247 			  * 4: Specified channels
248 			  * Others: Reserved
249 			  */
250 	u8 channels_num; /* valid when channel_type is 4 */
251 	u8 pad[2];
252 	struct mt76_connac_mcu_scan_channel channels[64];
253 };
254 
255 struct scan_ie_tlv {
256 	__le16 tag;
257 	__le16 len;
258 
259 	__le16 ies_len;
260 	u8 band;
261 	u8 pad;
262 	u8 ies[MT76_CONNAC_SCAN_IE_LEN];
263 };
264 
265 struct scan_misc_tlv {
266 	__le16 tag;
267 	__le16 len;
268 
269 	u8 random_mac[ETH_ALEN];
270 	u8 rsv[2];
271 };
272 
273 struct scan_sched_req {
274 	__le16 tag;
275 	__le16 len;
276 
277 	u8 version;
278 	u8 stop_on_match;
279 	u8 intervals_num;
280 	u8 scan_func;
281 	__le16 intervals[MT76_CONNAC_MAX_NUM_SCHED_SCAN_INTERVAL];
282 };
283 
284 struct scan_sched_ssid_match_sets {
285 	__le16 tag;
286 	__le16 len;
287 
288 	u8 match_num;
289 	u8 rsv[3];
290 
291 	struct mt76_connac_mcu_scan_match match[MT76_CONNAC_MAX_SCAN_MATCH];
292 };
293 
294 struct scan_sched_enable {
295 	__le16 tag;
296 	__le16 len;
297 
298 	u8 active;
299 	u8 rsv[3];
300 };
301 
302 struct mbmc_set_req {
303 	u8 pad[4];
304 	u8 data[];
305 } __packed;
306 
307 struct mbmc_conf_tlv {
308 	__le16 tag;
309 	__le16 len;
310 
311 	u8 mbmc_en;
312 	u8 band;
313 	u8 pad[2];
314 } __packed;
315 
316 struct edca {
317 	__le16 tag;
318 	__le16 len;
319 
320 	u8 queue;
321 	u8 set;
322 	u8 cw_min;
323 	u8 cw_max;
324 	__le16 txop;
325 	u8 aifs;
326 	u8 __rsv;
327 };
328 
329 struct bss_req_hdr {
330 	u8 bss_idx;
331 	u8 __rsv[3];
332 } __packed;
333 
334 struct bss_rate_tlv {
335 	__le16 tag;
336 	__le16 len;
337 	u8 __rsv1[4];
338 	__le16 bc_trans;
339 	__le16 mc_trans;
340 	u8 short_preamble;
341 	u8 bc_fixed_rate;
342 	u8 mc_fixed_rate;
343 	u8 __rsv2;
344 } __packed;
345 
346 struct bss_mld_tlv {
347 	__le16 tag;
348 	__le16 len;
349 	u8 group_mld_id;
350 	u8 own_mld_id;
351 	u8 mac_addr[ETH_ALEN];
352 	u8 remap_idx;
353 	u8 link_id;
354 	u8 __rsv[2];
355 } __packed;
356 
357 struct sta_rec_ba_uni {
358 	__le16 tag;
359 	__le16 len;
360 	u8 tid;
361 	u8 ba_type;
362 	u8 amsdu;
363 	u8 ba_en;
364 	__le16 ssn;
365 	__le16 winsize;
366 	u8 ba_rdd_rro;
367 	u8 __rsv[3];
368 } __packed;
369 
370 struct sta_rec_eht {
371 	__le16 tag;
372 	__le16 len;
373 	u8 tid_bitmap;
374 	u8 _rsv;
375 	__le16 mac_cap;
376 	__le64 phy_cap;
377 	__le64 phy_cap_ext;
378 	u8 mcs_map_bw20[4];
379 	u8 mcs_map_bw80[3];
380 	u8 mcs_map_bw160[3];
381 	u8 mcs_map_bw320[3];
382 	u8 _rsv2[3];
383 } __packed;
384 
385 struct sec_key_uni {
386 	__le16 wlan_idx;
387 	u8 mgmt_prot;
388 	u8 cipher_id;
389 	u8 cipher_len;
390 	u8 key_id;
391 	u8 key_len;
392 	u8 need_resp;
393 	u8 key[32];
394 } __packed;
395 
396 struct sta_rec_sec_uni {
397 	__le16 tag;
398 	__le16 len;
399 	u8 add;
400 	u8 n_cipher;
401 	u8 rsv[2];
402 
403 	struct sec_key_uni key[2];
404 } __packed;
405 
406 struct sta_rec_hdr_trans {
407 	__le16 tag;
408 	__le16 len;
409 	u8 from_ds;
410 	u8 to_ds;
411 	u8 dis_rx_hdr_tran;
412 	u8 rsv;
413 } __packed;
414 
415 struct sta_rec_mld {
416 	__le16 tag;
417 	__le16 len;
418 	u8 mac_addr[ETH_ALEN];
419 	__le16 primary_id;
420 	__le16 secondary_id;
421 	__le16 wlan_id;
422 	u8 link_num;
423 	u8 rsv[3];
424 	struct {
425 		__le16 wlan_id;
426 		u8 bss_idx;
427 		u8 rsv;
428 	} __packed link[2];
429 } __packed;
430 
431 #define MT7925_STA_UPDATE_MAX_SIZE	(sizeof(struct sta_req_hdr) +		\
432 					 sizeof(struct sta_rec_basic) +		\
433 					 sizeof(struct sta_rec_bf) +		\
434 					 sizeof(struct sta_rec_ht) +		\
435 					 sizeof(struct sta_rec_he_v2) +		\
436 					 sizeof(struct sta_rec_ba_uni) +	\
437 					 sizeof(struct sta_rec_vht) +		\
438 					 sizeof(struct sta_rec_uapsd) +		\
439 					 sizeof(struct sta_rec_amsdu) +		\
440 					 sizeof(struct sta_rec_bfee) +		\
441 					 sizeof(struct sta_rec_phy) +		\
442 					 sizeof(struct sta_rec_ra) +		\
443 					 sizeof(struct sta_rec_sec) +		\
444 					 sizeof(struct sta_rec_ra_fixed) +	\
445 					 sizeof(struct sta_rec_he_6g_capa) +	\
446 					 sizeof(struct sta_rec_eht) +		\
447 					 sizeof(struct sta_rec_hdr_trans) +	\
448 					 sizeof(struct sta_rec_mld) +		\
449 					 sizeof(struct tlv))
450 
451 #define MT7925_BSS_UPDATE_MAX_SIZE	(sizeof(struct bss_req_hdr) +		\
452 					 sizeof(struct mt76_connac_bss_basic_tlv) +	\
453 					 sizeof(struct mt76_connac_bss_qos_tlv) +	\
454 					 sizeof(struct bss_rate_tlv) +			\
455 					 sizeof(struct bss_mld_tlv) +			\
456 					 sizeof(struct bss_info_uni_he) +		\
457 					 sizeof(struct bss_info_uni_bss_color) +	\
458 					 sizeof(struct tlv))
459 
460 #define MT_CONNAC3_SKU_POWER_LIMIT      449
461 struct mt7925_sku_tlv {
462 	u8 channel;
463 	s8 pwr_limit[MT_CONNAC3_SKU_POWER_LIMIT];
464 } __packed;
465 
466 struct mt7925_tx_power_limit_tlv {
467 	u8 rsv[4];
468 
469 	__le16 tag;
470 	__le16 len;
471 
472 	/* DW0 - common info*/
473 	u8 ver;
474 	u8 pad0;
475 	__le16 rsv1;
476 	/* DW1 - cmd hint */
477 	u8 n_chan; /* # channel */
478 	u8 band; /* 2.4GHz - 5GHz - 6GHz */
479 	u8 last_msg;
480 	u8 limit_type;
481 	/* DW3 */
482 	u8 alpha2[4]; /* regulatory_request.alpha2 */
483 	u8 pad2[32];
484 
485 	u8 data[];
486 } __packed;
487 
488 struct mt7925_arpns_tlv {
489 	__le16 tag;
490 	__le16 len;
491 
492 	u8 enable;
493 	u8 ips_num;
494 	u8 rsv[2];
495 } __packed;
496 
497 struct mt7925_wow_pattern_tlv {
498 	__le16 tag;
499 	__le16 len;
500 	u8 bss_idx;
501 	u8 index; /* pattern index */
502 	u8 enable; /* 0: disable
503 		    * 1: enable
504 		    */
505 	u8 data_len; /* pattern length */
506 	u8 offset;
507 	u8 mask[MT76_CONNAC_WOW_MASK_MAX_LEN];
508 	u8 pattern[MT76_CONNAC_WOW_PATTEN_MAX_LEN];
509 	u8 rsv[4];
510 } __packed;
511 
512 int mt7925_mcu_set_dbdc(struct mt76_phy *phy);
513 int mt7925_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,
514 		       struct ieee80211_scan_request *scan_req);
515 int mt7925_mcu_cancel_hw_scan(struct mt76_phy *phy,
516 			      struct ieee80211_vif *vif);
517 int mt7925_mcu_sched_scan_req(struct mt76_phy *phy,
518 			      struct ieee80211_vif *vif,
519 			      struct cfg80211_sched_scan_request *sreq);
520 int mt7925_mcu_sched_scan_enable(struct mt76_phy *phy,
521 				 struct ieee80211_vif *vif,
522 				 bool enable);
523 int mt7925_mcu_add_bss_info(struct mt792x_phy *phy,
524 			    struct ieee80211_chanctx_conf *ctx,
525 			    struct ieee80211_vif *vif,
526 			    struct ieee80211_sta *sta,
527 			    int enable);
528 int mt7925_mcu_set_deep_sleep(struct mt792x_dev *dev, bool enable);
529 int mt7925_mcu_set_channel_domain(struct mt76_phy *phy);
530 int mt7925_mcu_set_radio_en(struct mt792x_phy *phy, bool enable);
531 int mt7925_mcu_set_chctx(struct mt76_phy *phy, struct mt76_vif *mvif,
532 			 struct ieee80211_chanctx_conf *ctx);
533 int mt7925_mcu_set_rate_txpower(struct mt76_phy *phy);
534 int mt7925_mcu_update_arp_filter(struct mt76_dev *dev,
535 				 struct mt76_vif *vif,
536 				 struct ieee80211_bss_conf *info);
537 #endif
538