xref: /linux/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h (revision 9410645520e9b820069761f3450ef6661418e279)
1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2023 MediaTek Inc. */
3 
4 #ifndef __MT7925_H
5 #define __MT7925_H
6 
7 #include "../mt792x.h"
8 #include "regs.h"
9 
10 #define MT7925_BEACON_RATES_TBL		25
11 
12 #define MT7925_TX_RING_SIZE		2048
13 #define MT7925_TX_MCU_RING_SIZE		256
14 #define MT7925_TX_FWDL_RING_SIZE	128
15 
16 #define MT7925_RX_RING_SIZE		1536
17 #define MT7925_RX_MCU_RING_SIZE		512
18 
19 #define MT7925_EEPROM_SIZE		3584
20 #define MT7925_TOKEN_SIZE		8192
21 
22 #define MT7925_EEPROM_BLOCK_SIZE	16
23 
24 #define MT7925_SKU_RATE_NUM		161
25 #define MT7925_SKU_MAX_DELTA_IDX	MT7925_SKU_RATE_NUM
26 #define MT7925_SKU_TABLE_SIZE		(MT7925_SKU_RATE_NUM + 1)
27 
28 #define MCU_UNI_EVENT_ROC  0x27
29 
30 enum {
31 	UNI_ROC_ACQUIRE,
32 	UNI_ROC_ABORT,
33 	UNI_ROC_SUB_LINK = 3,
34 	UNI_ROC_NUM
35 };
36 
37 enum mt7925_roc_req {
38 	MT7925_ROC_REQ_JOIN,
39 	MT7925_ROC_REQ_ROC,
40 	MT7925_ROC_REQ_SUB_LINK,
41 	MT7925_ROC_REQ_MLSR_AG = 10,
42 	MT7925_ROC_REQ_MLSR_AA,
43 	MT7925_ROC_REQ_NUM
44 };
45 
46 enum {
47 	UNI_EVENT_ROC_GRANT = 0,
48 	UNI_EVENT_ROC_GRANT_SUB_LINK = 4,
49 	UNI_EVENT_ROC_TAG_NUM
50 };
51 
52 struct mt7925_roc_grant_tlv {
53 	__le16 tag;
54 	__le16 len;
55 	u8 bss_idx;
56 	u8 tokenid;
57 	u8 status;
58 	u8 primarychannel;
59 	u8 rfsco;
60 	u8 rfband;
61 	u8 channelwidth;
62 	u8 centerfreqseg1;
63 	u8 centerfreqseg2;
64 	u8 reqtype;
65 	u8 dbdcband;
66 	u8 rsv[1];
67 	__le32 max_interval;
68 } __packed;
69 
70 struct mt7925_beacon_loss_tlv {
71 	__le16 tag;
72 	__le16 len;
73 	u8 reason;
74 	u8 nr_btolink;
75 	u8 pad[2];
76 } __packed;
77 
78 struct mt7925_uni_beacon_loss_event {
79 	struct {
80 		u8 bss_idx;
81 		u8 pad[3];
82 	} __packed hdr;
83 	struct mt7925_beacon_loss_tlv beacon_loss;
84 } __packed;
85 
86 #define to_rssi(field, rxv)		((FIELD_GET(field, rxv) - 220) / 2)
87 #define to_rcpi(rssi)			(2 * (rssi) + 220)
88 
89 enum mt7925_txq_id {
90 	MT7925_TXQ_BAND0,
91 	MT7925_TXQ_BAND1,
92 	MT7925_TXQ_MCU_WM = 15,
93 	MT7925_TXQ_FWDL,
94 };
95 
96 enum mt7925_rxq_id {
97 	MT7925_RXQ_BAND0 = 2,
98 	MT7925_RXQ_BAND1,
99 	MT7925_RXQ_MCU_WM = 0,
100 	MT7925_RXQ_MCU_WM2, /* for tx done */
101 };
102 
103 enum {
104 	MODE_OPEN = 0,
105 	MODE_SHARED = 1,
106 	MODE_WPA = 3,
107 	MODE_WPA_PSK = 4,
108 	MODE_WPA_NONE = 5,
109 	MODE_WPA2 = 6,
110 	MODE_WPA2_PSK = 7,
111 	MODE_WPA3_SAE = 11,
112 };
113 
114 enum {
115 	MT7925_CLC_POWER,
116 	MT7925_CLC_CHAN,
117 	MT7925_CLC_MAX_NUM,
118 };
119 
120 struct mt7925_clc_rule {
121 	u8 alpha2[2];
122 	u8 type[2];
123 	u8 seg_idx;
124 	u8 rsv[3];
125 } __packed;
126 
127 struct mt7925_clc_segment {
128 	u8 idx;
129 	u8 rsv1[3];
130 	u32 offset;
131 	u32 len;
132 	u8 rsv2[4];
133 } __packed;
134 
135 struct mt7925_clc {
136 	__le32 len;
137 	u8 idx;
138 	u8 ver;
139 	u8 nr_country;
140 	u8 type;
141 	u8 nr_seg;
142 	u8 rsv[7];
143 	u8 data[];
144 } __packed;
145 
146 enum mt7925_eeprom_field {
147 	MT_EE_CHIP_ID =		0x000,
148 	MT_EE_VERSION =		0x002,
149 	MT_EE_MAC_ADDR =	0x004,
150 	__MT_EE_MAX =		0x9ff
151 };
152 
153 enum {
154 	TXPWR_USER,
155 	TXPWR_EEPROM,
156 	TXPWR_MAC,
157 	TXPWR_MAX_NUM,
158 };
159 
160 struct mt7925_txpwr {
161 	s8 cck[4][2];
162 	s8 ofdm[8][2];
163 	s8 ht20[8][2];
164 	s8 ht40[9][2];
165 	s8 vht20[12][2];
166 	s8 vht40[12][2];
167 	s8 vht80[12][2];
168 	s8 vht160[12][2];
169 	s8 he26[12][2];
170 	s8 he52[12][2];
171 	s8 he106[12][2];
172 	s8 he242[12][2];
173 	s8 he484[12][2];
174 	s8 he996[12][2];
175 	s8 he996x2[12][2];
176 	s8 eht26[16][2];
177 	s8 eht52[16][2];
178 	s8 eht106[16][2];
179 	s8 eht242[16][2];
180 	s8 eht484[16][2];
181 	s8 eht996[16][2];
182 	s8 eht996x2[16][2];
183 	s8 eht996x4[16][2];
184 	s8 eht26_52[16][2];
185 	s8 eht26_106[16][2];
186 	s8 eht484_242[16][2];
187 	s8 eht996_484[16][2];
188 	s8 eht996_484_242[16][2];
189 	s8 eht996x2_484[16][2];
190 	s8 eht996x3[16][2];
191 	s8 eht996x3_484[16][2];
192 };
193 
194 extern const struct ieee80211_ops mt7925_ops;
195 
196 int __mt7925_start(struct mt792x_phy *phy);
197 int mt7925_register_device(struct mt792x_dev *dev);
198 void mt7925_unregister_device(struct mt792x_dev *dev);
199 int mt7925_run_firmware(struct mt792x_dev *dev);
200 int mt7925_mcu_set_bss_pm(struct mt792x_dev *dev,
201 			  struct ieee80211_bss_conf *link_conf,
202 			  bool enable);
203 int mt7925_mcu_sta_update(struct mt792x_dev *dev,
204 			  struct ieee80211_link_sta *link_sta,
205 			  struct ieee80211_vif *vif, bool enable,
206 			  enum mt76_sta_info_state state);
207 int mt7925_mcu_set_chan_info(struct mt792x_phy *phy, u16 tag);
208 int mt7925_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_bss_conf *bss_conf);
209 int mt7925_mcu_set_eeprom(struct mt792x_dev *dev);
210 int mt7925_mcu_get_rx_rate(struct mt792x_phy *phy, struct ieee80211_vif *vif,
211 			   struct ieee80211_sta *sta, struct rate_info *rate);
212 int mt7925_mcu_fw_log_2_host(struct mt792x_dev *dev, u8 ctrl);
213 void mt7925_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb);
214 int mt7925_mcu_chip_config(struct mt792x_dev *dev, const char *cmd);
215 int mt7925_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif,
216 			    u8 bit_op, u32 bit_map);
217 
218 int mt7925_mac_init(struct mt792x_dev *dev);
219 int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
220 		       struct ieee80211_sta *sta);
221 bool mt7925_mac_wtbl_update(struct mt792x_dev *dev, int idx, u32 mask);
222 int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
223 			 struct ieee80211_sta *sta, enum mt76_sta_event ev);
224 void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
225 			   struct ieee80211_sta *sta);
226 void mt7925_mac_reset_work(struct work_struct *work);
227 int mt7925e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
228 			   enum mt76_txq_id qid, struct mt76_wcid *wcid,
229 			   struct ieee80211_sta *sta,
230 			   struct mt76_tx_info *tx_info);
231 
232 void mt7925_tx_token_put(struct mt792x_dev *dev);
233 bool mt7925_rx_check(struct mt76_dev *mdev, void *data, int len);
234 void mt7925_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
235 			 struct sk_buff *skb, u32 *info);
236 void mt7925_stats_work(struct work_struct *work);
237 void mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy);
238 int mt7925_init_mlo_caps(struct mt792x_phy *phy);
239 int mt7925_init_debugfs(struct mt792x_dev *dev);
240 
241 int mt7925_mcu_set_beacon_filter(struct mt792x_dev *dev,
242 				 struct ieee80211_vif *vif,
243 				 bool enable);
244 int mt7925_mcu_uni_tx_ba(struct mt792x_dev *dev,
245 			 struct ieee80211_ampdu_params *params,
246 			 bool enable);
247 int mt7925_mcu_uni_rx_ba(struct mt792x_dev *dev,
248 			 struct ieee80211_ampdu_params *params,
249 			 bool enable);
250 void mt7925_scan_work(struct work_struct *work);
251 void mt7925_roc_work(struct work_struct *work);
252 int mt7925_mcu_uni_bss_ps(struct mt792x_dev *dev,
253 			  struct ieee80211_bss_conf *link_conf);
254 void mt7925_coredump_work(struct work_struct *work);
255 int mt7925_get_txpwr_info(struct mt792x_dev *dev, u8 band_idx,
256 			  struct mt7925_txpwr *txpwr);
257 void mt7925_mac_set_fixed_rate_table(struct mt792x_dev *dev,
258 				     u8 tbl_idx, u16 rate_idx);
259 void mt7925_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
260 			   struct sk_buff *skb, struct mt76_wcid *wcid,
261 			   struct ieee80211_key_conf *key, int pid,
262 			   enum mt76_txq_id qid, u32 changed);
263 void mt7925_txwi_free(struct mt792x_dev *dev, struct mt76_txwi_cache *t,
264 		      struct ieee80211_sta *sta, struct mt76_wcid *wcid,
265 		      struct list_head *free_list);
266 int mt7925_mcu_parse_response(struct mt76_dev *mdev, int cmd,
267 			      struct sk_buff *skb, int seq);
268 
269 int mt7925e_mac_reset(struct mt792x_dev *dev);
270 int mt7925e_mcu_init(struct mt792x_dev *dev);
271 void mt7925_mac_add_txs(struct mt792x_dev *dev, void *data);
272 void mt7925_set_runtime_pm(struct mt792x_dev *dev);
273 void mt7925_mcu_set_suspend_iter(void *priv, u8 *mac,
274 				 struct ieee80211_vif *vif);
275 void mt7925_connac_mcu_set_suspend_iter(void *priv, u8 *mac,
276 					struct ieee80211_vif *vif);
277 void mt7925_set_ipv6_ns_work(struct work_struct *work);
278 
279 int mt7925_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif,
280 			   bool enable);
281 int mt7925_mcu_config_sniffer(struct mt792x_vif *vif,
282 			      struct ieee80211_chanctx_conf *ctx);
283 int mt7925_mcu_get_temperature(struct mt792x_phy *phy);
284 
285 int mt7925_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
286 				   enum mt76_txq_id qid, struct mt76_wcid *wcid,
287 				   struct ieee80211_sta *sta,
288 				   struct mt76_tx_info *tx_info);
289 void mt7925_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,
290 				     struct mt76_queue_entry *e);
291 bool mt7925_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update);
292 
293 int mt7925_mcu_uni_add_beacon_offload(struct mt792x_dev *dev,
294 				      struct ieee80211_hw *hw,
295 				      struct ieee80211_vif *vif,
296 				      bool enable);
297 int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw,
298 			  const struct cfg80211_sar_specs *sar);
299 
300 int mt7925_mcu_regval(struct mt792x_dev *dev, u32 regidx, u32 *val, bool set);
301 int mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
302 		       enum environment_cap env_cap);
303 int mt7925_mcu_set_mlo_roc(struct mt792x_bss_conf *mconf, u16 sel_links,
304 			   int duration, u8 token_id);
305 int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
306 		       struct ieee80211_channel *chan, int duration,
307 		       enum mt7925_roc_req type, u8 token_id);
308 int mt7925_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
309 			 u8 token_id);
310 void mt7925_roc_abort_sync(struct mt792x_dev *dev);
311 int mt7925_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb,
312 			    int cmd, int *wait_seq);
313 int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
314 		       struct mt76_connac_sta_key_conf *sta_key_conf,
315 		       struct ieee80211_key_conf *key, int mcu_cmd,
316 		       struct mt76_wcid *wcid, enum set_key_cmd cmd,
317 		       struct mt792x_sta *msta);
318 int mt7925_mcu_set_rts_thresh(struct mt792x_phy *phy, u32 val);
319 int mt7925_mcu_wtbl_update_hdr_trans(struct mt792x_dev *dev,
320 				     struct ieee80211_vif *vif,
321 				     struct ieee80211_sta *sta,
322 				     int link_id);
323 
324 #endif
325