xref: /linux/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h (revision 7255fcc80d4b525cc10cfaaf7f485830d4ed2000)
1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2020 MediaTek Inc. */
3 
4 #ifndef __MT7921_H
5 #define __MT7921_H
6 
7 #include "../mt792x.h"
8 #include "regs.h"
9 
10 #define MT7921_TX_RING_SIZE		2048
11 #define MT7921_TX_MCU_RING_SIZE		256
12 #define MT7921_TX_FWDL_RING_SIZE	128
13 
14 #define MT7921_RX_RING_SIZE		1536
15 #define MT7921_RX_MCU_RING_SIZE		8
16 #define MT7921_RX_MCU_WA_RING_SIZE	512
17 
18 #define MT7921_EEPROM_SIZE		3584
19 #define MT7921_TOKEN_SIZE		8192
20 
21 #define MT7921_EEPROM_BLOCK_SIZE	16
22 
23 #define MT7921_SKU_RATE_NUM		161
24 #define MT7921_SKU_MAX_DELTA_IDX	MT7921_SKU_RATE_NUM
25 #define MT7921_SKU_TABLE_SIZE		(MT7921_SKU_RATE_NUM + 1)
26 
27 #define MCU_UNI_EVENT_ROC  0x27
28 #define MCU_UNI_EVENT_CLC  0x80
29 
30 enum {
31 	UNI_ROC_ACQUIRE,
32 	UNI_ROC_ABORT,
33 	UNI_ROC_NUM
34 };
35 
36 enum mt7921_roc_req {
37 	MT7921_ROC_REQ_JOIN,
38 	MT7921_ROC_REQ_ROC,
39 	MT7921_ROC_REQ_NUM
40 };
41 
42 enum {
43 	UNI_EVENT_ROC_GRANT = 0,
44 	UNI_EVENT_ROC_TAG_NUM
45 };
46 
47 struct mt7921_realease_info {
48 	__le16 len;
49 	u8 pad_len;
50 	u8 tag;
51 } __packed;
52 
53 struct mt7921_fw_features {
54 	u8 segment;
55 	u8 data;
56 	u8 rsv[14];
57 } __packed;
58 
59 struct mt7921_roc_grant_tlv {
60 	__le16 tag;
61 	__le16 len;
62 	u8 bss_idx;
63 	u8 tokenid;
64 	u8 status;
65 	u8 primarychannel;
66 	u8 rfsco;
67 	u8 rfband;
68 	u8 channelwidth;
69 	u8 centerfreqseg1;
70 	u8 centerfreqseg2;
71 	u8 reqtype;
72 	u8 dbdcband;
73 	u8 rsv[1];
74 	__le32 max_interval;
75 } __packed;
76 
77 enum mt7921_sdio_pkt_type {
78 	MT7921_SDIO_TXD,
79 	MT7921_SDIO_DATA,
80 	MT7921_SDIO_CMD,
81 	MT7921_SDIO_FWDL,
82 };
83 
84 struct mt7921_sdio_intr {
85 	u32 isr;
86 	struct {
87 		u32 wtqcr[16];
88 	} tx;
89 	struct {
90 		u16 num[2];
91 		u16 len0[16];
92 		u16 len1[128];
93 	} rx;
94 	u32 rec_mb[2];
95 } __packed;
96 
97 #define to_rssi(field, rxv)		((FIELD_GET(field, rxv) - 220) / 2)
98 #define to_rcpi(rssi)			(2 * (rssi) + 220)
99 
100 enum mt7921_txq_id {
101 	MT7921_TXQ_BAND0,
102 	MT7921_TXQ_BAND1,
103 	MT7921_TXQ_FWDL = 16,
104 	MT7921_TXQ_MCU_WM,
105 };
106 
107 enum mt7921_rxq_id {
108 	MT7921_RXQ_BAND0 = 0,
109 	MT7921_RXQ_BAND1,
110 	MT7921_RXQ_MCU_WM = 0,
111 };
112 
113 enum {
114 	MT7921_CLC_POWER,
115 	MT7921_CLC_CHAN,
116 	MT7921_CLC_MAX_NUM,
117 };
118 
119 struct mt7921_clc_rule {
120 	u8 alpha2[2];
121 	u8 type[2];
122 	__le16 len;
123 	u8 data[];
124 } __packed;
125 
126 struct mt7921_clc {
127 	__le32 len;
128 	u8 idx;
129 	u8 ver;
130 	u8 nr_country;
131 	u8 type;
132 	u8 rsv[8];
133 	u8 data[];
134 } __packed;
135 
136 enum mt7921_eeprom_field {
137 	MT_EE_CHIP_ID =		0x000,
138 	MT_EE_VERSION =		0x002,
139 	MT_EE_MAC_ADDR =	0x004,
140 	MT_EE_WIFI_CONF =	0x07c,
141 	MT_EE_HW_TYPE =		0x55b,
142 	__MT_EE_MAX =		0x9ff
143 };
144 
145 #define MT_EE_HW_TYPE_ENCAP			BIT(0)
146 
147 enum {
148 	TXPWR_USER,
149 	TXPWR_EEPROM,
150 	TXPWR_MAC,
151 	TXPWR_MAX_NUM,
152 };
153 
154 struct mt7921_txpwr {
155 	u8 ch;
156 	u8 rsv[3];
157 	struct {
158 		u8 ch;
159 		u8 cck[4];
160 		u8 ofdm[8];
161 		u8 ht20[8];
162 		u8 ht40[9];
163 		u8 vht20[12];
164 		u8 vht40[12];
165 		u8 vht80[12];
166 		u8 vht160[12];
167 		u8 he26[12];
168 		u8 he52[12];
169 		u8 he106[12];
170 		u8 he242[12];
171 		u8 he484[12];
172 		u8 he996[12];
173 		u8 he996x2[12];
174 	} data[TXPWR_MAX_NUM];
175 };
176 
177 extern const struct ieee80211_ops mt7921_ops;
178 
179 u32 mt7921_reg_map(struct mt792x_dev *dev, u32 addr);
180 
181 int __mt7921_start(struct mt792x_phy *phy);
182 int mt7921_register_device(struct mt792x_dev *dev);
183 void mt7921_unregister_device(struct mt792x_dev *dev);
184 int mt7921_run_firmware(struct mt792x_dev *dev);
185 int mt7921_mcu_set_bss_pm(struct mt792x_dev *dev, struct ieee80211_vif *vif,
186 			  bool enable);
187 int mt7921_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_sta *sta,
188 			  struct ieee80211_vif *vif, bool enable,
189 			  enum mt76_sta_info_state state);
190 int mt7921_mcu_set_chan_info(struct mt792x_phy *phy, int cmd);
191 int mt7921_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_vif *vif);
192 int mt7921_mcu_set_eeprom(struct mt792x_dev *dev);
193 int mt7921_mcu_get_rx_rate(struct mt792x_phy *phy, struct ieee80211_vif *vif,
194 			   struct ieee80211_sta *sta, struct rate_info *rate);
195 int mt7921_mcu_fw_log_2_host(struct mt792x_dev *dev, u8 ctrl);
196 void mt7921_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb);
197 int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif,
198 			    u8 bit_op, u32 bit_map);
199 
200 static inline u32
201 mt7921_reg_map_l1(struct mt792x_dev *dev, u32 addr)
202 {
203 	u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr);
204 	u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr);
205 
206 	mt76_rmw_field(dev, MT_HIF_REMAP_L1, MT_HIF_REMAP_L1_MASK, base);
207 	/* use read to push write */
208 	mt76_rr(dev, MT_HIF_REMAP_L1);
209 
210 	return MT_HIF_REMAP_BASE_L1 + offset;
211 }
212 
213 static inline u32
214 mt7921_l1_rr(struct mt792x_dev *dev, u32 addr)
215 {
216 	return mt76_rr(dev, mt7921_reg_map_l1(dev, addr));
217 }
218 
219 static inline void
220 mt7921_l1_wr(struct mt792x_dev *dev, u32 addr, u32 val)
221 {
222 	mt76_wr(dev, mt7921_reg_map_l1(dev, addr), val);
223 }
224 
225 static inline u32
226 mt7921_l1_rmw(struct mt792x_dev *dev, u32 addr, u32 mask, u32 val)
227 {
228 	val |= mt7921_l1_rr(dev, addr) & ~mask;
229 	mt7921_l1_wr(dev, addr, val);
230 
231 	return val;
232 }
233 
234 #define mt7921_l1_set(dev, addr, val)	mt7921_l1_rmw(dev, addr, 0, val)
235 #define mt7921_l1_clear(dev, addr, val)	mt7921_l1_rmw(dev, addr, val, 0)
236 
237 void mt7921_regd_update(struct mt792x_dev *dev);
238 int mt7921_mac_init(struct mt792x_dev *dev);
239 bool mt7921_mac_wtbl_update(struct mt792x_dev *dev, int idx, u32 mask);
240 int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
241 		       struct ieee80211_sta *sta);
242 void mt7921_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
243 			  struct ieee80211_sta *sta);
244 void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
245 			   struct ieee80211_sta *sta);
246 void mt7921_mac_reset_work(struct work_struct *work);
247 int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
248 			   enum mt76_txq_id qid, struct mt76_wcid *wcid,
249 			   struct ieee80211_sta *sta,
250 			   struct mt76_tx_info *tx_info);
251 
252 bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len);
253 void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
254 			 struct sk_buff *skb, u32 *info);
255 void mt7921_stats_work(struct work_struct *work);
256 void mt7921_set_stream_he_caps(struct mt792x_phy *phy);
257 int mt7921_init_debugfs(struct mt792x_dev *dev);
258 
259 int mt7921_mcu_set_beacon_filter(struct mt792x_dev *dev,
260 				 struct ieee80211_vif *vif,
261 				 bool enable);
262 int mt7921_mcu_uni_tx_ba(struct mt792x_dev *dev,
263 			 struct ieee80211_ampdu_params *params,
264 			 bool enable);
265 int mt7921_mcu_uni_rx_ba(struct mt792x_dev *dev,
266 			 struct ieee80211_ampdu_params *params,
267 			 bool enable);
268 void mt7921_scan_work(struct work_struct *work);
269 void mt7921_roc_work(struct work_struct *work);
270 int mt7921_mcu_uni_bss_ps(struct mt792x_dev *dev, struct ieee80211_vif *vif);
271 void mt7921_coredump_work(struct work_struct *work);
272 int mt7921_get_txpwr_info(struct mt792x_dev *dev, struct mt7921_txpwr *txpwr);
273 int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
274 			void *data, int len);
275 int mt7921_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
276 			 struct netlink_callback *cb, void *data, int len);
277 int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
278 			      struct sk_buff *skb, int seq);
279 
280 int mt7921e_driver_own(struct mt792x_dev *dev);
281 int mt7921e_mac_reset(struct mt792x_dev *dev);
282 int mt7921e_mcu_init(struct mt792x_dev *dev);
283 int mt7921s_wfsys_reset(struct mt792x_dev *dev);
284 int mt7921s_mac_reset(struct mt792x_dev *dev);
285 int mt7921s_init_reset(struct mt792x_dev *dev);
286 
287 int mt7921s_mcu_init(struct mt792x_dev *dev);
288 int mt7921s_mcu_drv_pmctrl(struct mt792x_dev *dev);
289 int mt7921s_mcu_fw_pmctrl(struct mt792x_dev *dev);
290 void mt7921_mac_add_txs(struct mt792x_dev *dev, void *data);
291 void mt7921_set_runtime_pm(struct mt792x_dev *dev);
292 void mt7921_mcu_set_suspend_iter(void *priv, u8 *mac,
293 				 struct ieee80211_vif *vif);
294 void mt7921_set_ipv6_ns_work(struct work_struct *work);
295 
296 int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif,
297 			   bool enable);
298 int mt7921_mcu_config_sniffer(struct mt792x_vif *vif,
299 			      struct ieee80211_chanctx_conf *ctx);
300 int mt7921_mcu_get_temperature(struct mt792x_phy *phy);
301 
302 int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
303 				   enum mt76_txq_id qid, struct mt76_wcid *wcid,
304 				   struct ieee80211_sta *sta,
305 				   struct mt76_tx_info *tx_info);
306 void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,
307 				     struct mt76_queue_entry *e);
308 bool mt7921_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update);
309 
310 /* usb */
311 int mt7921_mcu_uni_add_beacon_offload(struct mt792x_dev *dev,
312 				      struct ieee80211_hw *hw,
313 				      struct ieee80211_vif *vif,
314 				      bool enable);
315 int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw,
316 			  const struct cfg80211_sar_specs *sar);
317 
318 int mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
319 		       enum environment_cap env_cap);
320 int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
321 		       struct ieee80211_channel *chan, int duration,
322 		       enum mt7921_roc_req type, u8 token_id);
323 int mt7921_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
324 			 u8 token_id);
325 void mt7921_roc_abort_sync(struct mt792x_dev *dev);
326 #endif
327