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