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 struct mt7921_mcu_tx_done_event {
80 	u8 pid;
81 	u8 status;
82 	__le16 seq;
83 
84 	u8 wlan_idx;
85 	u8 tx_cnt;
86 	__le16 tx_rate;
87 
88 	u8 flag;
89 	u8 tid;
90 	u8 rsp_rate;
91 	u8 mcs;
92 
93 	u8 bw;
94 	u8 tx_pwr;
95 	u8 reason;
96 	u8 rsv0[1];
97 
98 	__le32 delay;
99 	__le32 timestamp;
100 	__le32 applied_flag;
101 	u8 txs[28];
102 
103 	u8 rsv1[32];
104 } __packed;
105 
106 /* ext event table */
107 enum {
108 	MCU_EXT_EVENT_RATE_REPORT = 0x87,
109 };
110 
111 struct mt7921_mcu_rxd {
112 	__le32 rxd[6];
113 
114 	__le16 len;
115 	__le16 pkt_type_id;
116 
117 	u8 eid;
118 	u8 seq;
119 	__le16 __rsv;
120 
121 	u8 ext_eid;
122 	u8 __rsv1[2];
123 	u8 s2d_index;
124 };
125 
126 struct mt7921_mcu_eeprom_info {
127 	__le32 addr;
128 	__le32 valid;
129 	u8 data[16];
130 } __packed;
131 
132 #define MT_RA_RATE_NSS			GENMASK(8, 6)
133 #define MT_RA_RATE_MCS			GENMASK(3, 0)
134 #define MT_RA_RATE_TX_MODE		GENMASK(12, 9)
135 #define MT_RA_RATE_DCM_EN		BIT(4)
136 #define MT_RA_RATE_BW			GENMASK(14, 13)
137 
138 #define MCU_PQ_ID(p, q)			(((p) << 15) | ((q) << 10))
139 #define MCU_PKT_ID			0xa0
140 
141 struct mt7921_mcu_uni_event {
142 	u8 cid;
143 	u8 pad[3];
144 	__le32 status; /* 0: success, others: fail */
145 } __packed;
146 
147 enum {
148 	MT_EBF = BIT(0),	/* explicit beamforming */
149 	MT_IBF = BIT(1)		/* implicit beamforming */
150 };
151 
152 struct mt7921_mcu_reg_event {
153 	__le32 reg;
154 	__le32 val;
155 } __packed;
156 
157 struct mt7921_mcu_ant_id_config {
158 	u8 ant_id[4];
159 } __packed;
160 
161 struct mt7921_txpwr_req {
162 	u8 ver;
163 	u8 action;
164 	__le16 len;
165 	u8 dbdc_idx;
166 	u8 rsv[3];
167 } __packed;
168 
169 struct mt7921_txpwr_event {
170 	u8 ver;
171 	u8 action;
172 	__le16 len;
173 	struct mt7921_txpwr txpwr;
174 } __packed;
175 
176 enum {
177 	TM_SWITCH_MODE,
178 	TM_SET_AT_CMD,
179 	TM_QUERY_AT_CMD,
180 };
181 
182 enum {
183 	MT7921_TM_NORMAL,
184 	MT7921_TM_TESTMODE,
185 	MT7921_TM_ICAP,
186 	MT7921_TM_ICAP_OVERLAP,
187 	MT7921_TM_WIFISPECTRUM,
188 };
189 
190 struct mt7921_rftest_cmd {
191 	u8 action;
192 	u8 rsv[3];
193 	__le32 param0;
194 	__le32 param1;
195 } __packed;
196 
197 struct mt7921_rftest_evt {
198 	__le32 param0;
199 	__le32 param1;
200 } __packed;
201 #endif
202