104b8e659SRyder Lee /* SPDX-License-Identifier: ISC */
204b8e659SRyder Lee /* Copyright (C) 2019 MediaTek Inc. */
304b8e659SRyder Lee 
404b8e659SRyder Lee #ifndef __MT7615_H
504b8e659SRyder Lee #define __MT7615_H
604b8e659SRyder Lee 
708523a2aSLorenzo Bianconi #include <linux/completion.h>
804b8e659SRyder Lee #include <linux/interrupt.h>
904b8e659SRyder Lee #include <linux/ktime.h>
1035da599fSFelix Fietkau #include <linux/regmap.h>
11d2bf7959SLorenzo Bianconi #include "../mt76_connac_mcu.h"
1204b8e659SRyder Lee #include "regs.h"
1304b8e659SRyder Lee 
14d8d59f66SRyder Lee #define MT7615_MAX_INTERFACES		16
1549f1132cSRyder Lee #define MT7615_MAX_WMM_SETS		4
168f997dddSLorenzo Bianconi #define MT7663_WTBL_SIZE		32
1704b8e659SRyder Lee #define MT7615_WTBL_SIZE		128
188f997dddSLorenzo Bianconi #define MT7615_WTBL_RESERVED		(mt7615_wtbl_size(dev) - 1)
1904b8e659SRyder Lee #define MT7615_WTBL_STA			(MT7615_WTBL_RESERVED - \
2004b8e659SRyder Lee 					 MT7615_MAX_INTERFACES)
2104b8e659SRyder Lee 
22de5ff3c9SLorenzo Bianconi #define MT7615_PM_TIMEOUT		(HZ / 12)
23fcdfc29eSLorenzo Bianconi #define MT7615_HW_SCAN_TIMEOUT		(HZ / 10)
2461c4fa72SFelix Fietkau #define MT7615_RESET_TIMEOUT		(30 * HZ)
2504b8e659SRyder Lee #define MT7615_RATE_RETRY		2
2604b8e659SRyder Lee 
2704b8e659SRyder Lee #define MT7615_TX_RING_SIZE		1024
28cdad4874SFelix Fietkau #define MT7615_TX_MGMT_RING_SIZE	128
2904b8e659SRyder Lee #define MT7615_TX_MCU_RING_SIZE		128
3004b8e659SRyder Lee #define MT7615_TX_FWDL_RING_SIZE	128
3104b8e659SRyder Lee 
3204b8e659SRyder Lee #define MT7615_RX_RING_SIZE		1024
3304b8e659SRyder Lee #define MT7615_RX_MCU_RING_SIZE		512
3404b8e659SRyder Lee 
35894b7767SLorenzo Bianconi #define MT7615_DRV_OWN_RETRY_COUNT	10
36894b7767SLorenzo Bianconi 
379d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_CR4		"mediatek/mt7615_cr4.bin"
389d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_N9		"mediatek/mt7615_n9.bin"
399d4d0d06SLorenzo Bianconi #define MT7615_ROM_PATCH		"mediatek/mt7615_rom_patch.bin"
4004b8e659SRyder Lee 
4135da599fSFelix Fietkau #define MT7622_FIRMWARE_N9		"mediatek/mt7622_n9.bin"
4235da599fSFelix Fietkau #define MT7622_ROM_PATCH		"mediatek/mt7622_rom_patch.bin"
4335da599fSFelix Fietkau 
446849e29eSRyder Lee #define MT7615_FIRMWARE_V1		1
456849e29eSRyder Lee #define MT7615_FIRMWARE_V2		2
46f40ac0f3SLorenzo Bianconi #define MT7615_FIRMWARE_V3		3
47f40ac0f3SLorenzo Bianconi 
48f2dc8ea1SLorenzo Bianconi #define MT7663_OFFLOAD_ROM_PATCH	"mediatek/mt7663pr2h.bin"
49f2dc8ea1SLorenzo Bianconi #define MT7663_OFFLOAD_FIRMWARE_N9	"mediatek/mt7663_n9_v3.bin"
50f2dc8ea1SLorenzo Bianconi #define MT7663_ROM_PATCH		"mediatek/mt7663pr2h_rebb.bin"
51f2dc8ea1SLorenzo Bianconi #define MT7663_FIRMWARE_N9		"mediatek/mt7663_n9_rebb.bin"
526849e29eSRyder Lee 
5304b8e659SRyder Lee #define MT7615_EEPROM_SIZE		1024
54*e12b2e99SFelix Fietkau #define MT7663_EEPROM_SIZE		1536
5504b8e659SRyder Lee #define MT7615_TOKEN_SIZE		4096
5604b8e659SRyder Lee 
5749de79adSLorenzo Bianconi #define MT_FRAC_SCALE		12
5849de79adSLorenzo Bianconi #define MT_FRAC(val, div)	(((val) << MT_FRAC_SCALE) / (div))
5949de79adSLorenzo Bianconi 
6027ae7219SFelix Fietkau #define MT_CHFREQ_VALID		BIT(7)
6127ae7219SFelix Fietkau #define MT_CHFREQ_DBDC_IDX	BIT(6)
6227ae7219SFelix Fietkau #define MT_CHFREQ_SEQ		GENMASK(5, 0)
6327ae7219SFelix Fietkau 
64a25c888fSRyder Lee #define MT7615_BAR_RATE_DEFAULT		0x4b /* OFDM 6M */
65a25c888fSRyder Lee #define MT7615_CFEND_RATE_DEFAULT	0x49 /* OFDM 24M */
66183d1fcfSLorenzo Bianconi #define MT7615_CFEND_RATE_11B		0x03 /* 11B LP, 11M */
67183d1fcfSLorenzo Bianconi 
6804b8e659SRyder Lee struct mt7615_vif;
6904b8e659SRyder Lee struct mt7615_sta;
702ce73efeSLorenzo Bianconi struct mt7615_dfs_pulse;
712ce73efeSLorenzo Bianconi struct mt7615_dfs_pattern;
72294f17aeSLorenzo Bianconi enum mt7615_cipher_type;
7304b8e659SRyder Lee 
7404b8e659SRyder Lee enum mt7615_hw_txq_id {
7504b8e659SRyder Lee 	MT7615_TXQ_MAIN,
7604b8e659SRyder Lee 	MT7615_TXQ_EXT,
7704b8e659SRyder Lee 	MT7615_TXQ_MCU,
7804b8e659SRyder Lee 	MT7615_TXQ_FWDL,
7904b8e659SRyder Lee };
8004b8e659SRyder Lee 
81cdad4874SFelix Fietkau enum mt7622_hw_txq_id {
82cdad4874SFelix Fietkau 	MT7622_TXQ_AC0,
83cdad4874SFelix Fietkau 	MT7622_TXQ_AC1,
84cdad4874SFelix Fietkau 	MT7622_TXQ_AC2,
85cdad4874SFelix Fietkau 	MT7622_TXQ_FWDL = MT7615_TXQ_FWDL,
86cdad4874SFelix Fietkau 	MT7622_TXQ_AC3,
87cdad4874SFelix Fietkau 	MT7622_TXQ_MGMT,
88cdad4874SFelix Fietkau 	MT7622_TXQ_MCU = 15,
89cdad4874SFelix Fietkau };
90cdad4874SFelix Fietkau 
914af81f02SFelix Fietkau struct mt7615_rate_set {
924af81f02SFelix Fietkau 	struct ieee80211_tx_rate probe_rate;
934af81f02SFelix Fietkau 	struct ieee80211_tx_rate rates[4];
944af81f02SFelix Fietkau };
954af81f02SFelix Fietkau 
968f93af9cSLorenzo Bianconi struct mt7615_rate_desc {
978f93af9cSLorenzo Bianconi 	bool rateset;
988f93af9cSLorenzo Bianconi 	u16 probe_val;
998f93af9cSLorenzo Bianconi 	u16 val[4];
1008f93af9cSLorenzo Bianconi 	u8 bw_idx;
1018f93af9cSLorenzo Bianconi 	u8 bw;
1028f93af9cSLorenzo Bianconi };
1038f93af9cSLorenzo Bianconi 
104d927ebb9SLorenzo Bianconi struct mt7615_wtbl_rate_desc {
1057d9f1d10SLorenzo Bianconi 	struct list_head node;
1067d9f1d10SLorenzo Bianconi 
1077d9f1d10SLorenzo Bianconi 	struct mt7615_rate_desc rate;
108d927ebb9SLorenzo Bianconi 	struct mt7615_sta *sta;
1097d9f1d10SLorenzo Bianconi };
1107d9f1d10SLorenzo Bianconi 
1113ad08509SLorenzo Bianconi struct mt7663s_intr {
1123ad08509SLorenzo Bianconi 	u32 isr;
1133ad08509SLorenzo Bianconi 	struct {
1143ad08509SLorenzo Bianconi 		u32 wtqcr[8];
1153ad08509SLorenzo Bianconi 	} tx;
1163ad08509SLorenzo Bianconi 	struct {
1173ad08509SLorenzo Bianconi 		u16 num[2];
1183ad08509SLorenzo Bianconi 		u16 len[2][16];
1193ad08509SLorenzo Bianconi 	} rx;
1203ad08509SLorenzo Bianconi 	u32 rec_mb[2];
1213ad08509SLorenzo Bianconi } __packed;
1223ad08509SLorenzo Bianconi 
12304b8e659SRyder Lee struct mt7615_sta {
12404b8e659SRyder Lee 	struct mt76_wcid wcid; /* must be first */
12504b8e659SRyder Lee 
12604b8e659SRyder Lee 	struct mt7615_vif *vif;
12704b8e659SRyder Lee 
128b2c2f029SLorenzo Bianconi 	u32 airtime_ac[8];
129b2c2f029SLorenzo Bianconi 
1304af81f02SFelix Fietkau 	struct ieee80211_tx_rate rates[4];
1314af81f02SFelix Fietkau 
1324af81f02SFelix Fietkau 	struct mt7615_rate_set rateset[2];
1334af81f02SFelix Fietkau 	u32 rate_set_tsf;
1344af81f02SFelix Fietkau 
13504b8e659SRyder Lee 	u8 rate_count;
13604b8e659SRyder Lee 	u8 n_rates;
13704b8e659SRyder Lee 
13804b8e659SRyder Lee 	u8 rate_probe;
13904b8e659SRyder Lee };
14004b8e659SRyder Lee 
14104b8e659SRyder Lee struct mt7615_vif {
14285d96704SLorenzo Bianconi 	struct mt76_vif mt76; /* must be first */
14304b8e659SRyder Lee 	struct mt7615_sta sta;
144df6b739fSFelix Fietkau 	bool sta_added;
14504b8e659SRyder Lee };
14604b8e659SRyder Lee 
147679b23feSRyder Lee struct mib_stats {
1482eb6f6c4SLorenzo Bianconi 	u32 ack_fail_cnt;
1492eb6f6c4SLorenzo Bianconi 	u32 fcs_err_cnt;
1502eb6f6c4SLorenzo Bianconi 	u32 rts_cnt;
1512eb6f6c4SLorenzo Bianconi 	u32 rts_retries_cnt;
1522eb6f6c4SLorenzo Bianconi 	u32 ba_miss_cnt;
153aef16345SRyder Lee 	unsigned long aggr_per;
154679b23feSRyder Lee };
155679b23feSRyder Lee 
156fdd2e570SFelix Fietkau struct mt7615_phy {
157fdd2e570SFelix Fietkau 	struct mt76_phy *mt76;
158fdd2e570SFelix Fietkau 	struct mt7615_dev *dev;
159fdd2e570SFelix Fietkau 
1604f0bce1cSFelix Fietkau 	struct ieee80211_vif *monitor_vif;
1614f0bce1cSFelix Fietkau 
1627124198aSLorenzo Bianconi 	u8 n_beacon_vif;
1637124198aSLorenzo Bianconi 
164fdd2e570SFelix Fietkau 	u32 rxfilter;
165d8d59f66SRyder Lee 	u64 omac_mask;
166d446a20fSFelix Fietkau 
167e5051965SFelix Fietkau 	u16 noise;
168e5051965SFelix Fietkau 
169594034b7SLorenzo Bianconi 	bool scs_en;
170594034b7SLorenzo Bianconi 
171d446a20fSFelix Fietkau 	unsigned long last_cca_adj;
172d446a20fSFelix Fietkau 	int false_cca_ofdm, false_cca_cck;
173d446a20fSFelix Fietkau 	s8 ofdm_sensitivity;
174d446a20fSFelix Fietkau 	s8 cck_sensitivity;
1755dabdf71SFelix Fietkau 
176183d1fcfSLorenzo Bianconi 	s16 coverage_class;
177183d1fcfSLorenzo Bianconi 	u8 slottime;
178183d1fcfSLorenzo Bianconi 
1790e544cb5SFelix Fietkau 	u8 chfreq;
1805dabdf71SFelix Fietkau 	u8 rdd_state;
18127ae7219SFelix Fietkau 
1820fda6d7bSRyder Lee 	u32 rx_ampdu_ts;
18327ae7219SFelix Fietkau 	u32 ampdu_ref;
184679b23feSRyder Lee 
185679b23feSRyder Lee 	struct mib_stats mib;
186fcdfc29eSLorenzo Bianconi 
18720305f98SLorenzo Bianconi 	struct sk_buff_head scan_event_list;
188fcdfc29eSLorenzo Bianconi 	struct delayed_work scan_work;
1897f8ebafeSLorenzo Bianconi 
1907307f296SLorenzo Bianconi 	struct work_struct roc_work;
1917307f296SLorenzo Bianconi 	struct timer_list roc_timer;
1927307f296SLorenzo Bianconi 	wait_queue_head_t roc_wait;
1937307f296SLorenzo Bianconi 	bool roc_grant;
1947517ea01SShayne Chen 
1957517ea01SShayne Chen #ifdef CONFIG_NL80211_TESTMODE
1967517ea01SShayne Chen 	struct {
1977517ea01SShayne Chen 		u32 *reg_backup;
1987517ea01SShayne Chen 
1997517ea01SShayne Chen 		s16 last_freq_offset;
2007517ea01SShayne Chen 		u8 last_rcpi[4];
2017517ea01SShayne Chen 		s8 last_ib_rssi[4];
2027517ea01SShayne Chen 		s8 last_wb_rssi[4];
2037517ea01SShayne Chen 	} test;
2047517ea01SShayne Chen #endif
205fdd2e570SFelix Fietkau };
206fdd2e570SFelix Fietkau 
2076f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_tx_ba(dev, ...)	(dev)->mcu_ops->add_tx_ba((dev), __VA_ARGS__)
2086f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_rx_ba(dev, ...)	(dev)->mcu_ops->add_rx_ba((dev), __VA_ARGS__)
209d0e274afSLorenzo Bianconi #define mt7615_mcu_sta_add(phy, ...)	((phy)->dev)->mcu_ops->sta_add((phy),  __VA_ARGS__)
210d0e274afSLorenzo Bianconi #define mt7615_mcu_add_dev_info(phy, ...) ((phy)->dev)->mcu_ops->add_dev_info((phy),  __VA_ARGS__)
211d0e274afSLorenzo Bianconi #define mt7615_mcu_add_bss_info(phy, ...) ((phy)->dev)->mcu_ops->add_bss_info((phy),  __VA_ARGS__)
212062c3699SLorenzo Bianconi #define mt7615_mcu_add_beacon(dev, ...)	(dev)->mcu_ops->add_beacon_offload((dev),  __VA_ARGS__)
213062c3699SLorenzo Bianconi #define mt7615_mcu_set_pm(dev, ...)	(dev)->mcu_ops->set_pm_state((dev),  __VA_ARGS__)
214186b659cSLorenzo Bianconi #define mt7615_mcu_set_drv_ctrl(dev)	(dev)->mcu_ops->set_drv_ctrl((dev))
215186b659cSLorenzo Bianconi #define mt7615_mcu_set_fw_ctrl(dev)	(dev)->mcu_ops->set_fw_ctrl((dev))
21654c31b9eSLorenzo Bianconi #define mt7615_mcu_set_sta_decap_offload(dev, ...) (dev)->mcu_ops->set_sta_decap_offload((dev), __VA_ARGS__)
2176f4d7cc8SLorenzo Bianconi struct mt7615_mcu_ops {
2186f4d7cc8SLorenzo Bianconi 	int (*add_tx_ba)(struct mt7615_dev *dev,
2196f4d7cc8SLorenzo Bianconi 			 struct ieee80211_ampdu_params *params,
2206f4d7cc8SLorenzo Bianconi 			 bool enable);
2216f4d7cc8SLorenzo Bianconi 	int (*add_rx_ba)(struct mt7615_dev *dev,
2226f4d7cc8SLorenzo Bianconi 			 struct ieee80211_ampdu_params *params,
2236f4d7cc8SLorenzo Bianconi 			 bool enable);
224d0e274afSLorenzo Bianconi 	int (*sta_add)(struct mt7615_phy *phy, struct ieee80211_vif *vif,
22599c457d9SLorenzo Bianconi 		       struct ieee80211_sta *sta, bool enable);
226d0e274afSLorenzo Bianconi 	int (*add_dev_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif,
227d0e274afSLorenzo Bianconi 			    bool enable);
2285d3a4a4bSLorenzo Bianconi 	int (*add_bss_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif,
229f5596850SLorenzo Bianconi 			    struct ieee80211_sta *sta, bool enable);
230062c3699SLorenzo Bianconi 	int (*add_beacon_offload)(struct mt7615_dev *dev,
231062c3699SLorenzo Bianconi 				  struct ieee80211_hw *hw,
232062c3699SLorenzo Bianconi 				  struct ieee80211_vif *vif, bool enable);
233062c3699SLorenzo Bianconi 	int (*set_pm_state)(struct mt7615_dev *dev, int band, int state);
234186b659cSLorenzo Bianconi 	int (*set_drv_ctrl)(struct mt7615_dev *dev);
235186b659cSLorenzo Bianconi 	int (*set_fw_ctrl)(struct mt7615_dev *dev);
23654c31b9eSLorenzo Bianconi 	int (*set_sta_decap_offload)(struct mt7615_dev *dev,
23754c31b9eSLorenzo Bianconi 				     struct ieee80211_vif *vif,
23854c31b9eSLorenzo Bianconi 				     struct ieee80211_sta *sta);
2396f4d7cc8SLorenzo Bianconi };
2406f4d7cc8SLorenzo Bianconi 
24104b8e659SRyder Lee struct mt7615_dev {
242ac24dd35SFelix Fietkau 	union { /* must be first */
243ac24dd35SFelix Fietkau 		struct mt76_dev mt76;
244ac24dd35SFelix Fietkau 		struct mt76_phy mphy;
245ac24dd35SFelix Fietkau 	};
246ac24dd35SFelix Fietkau 
247557b5a17SFelix Fietkau 	const struct mt76_bus_ops *bus_ops;
248fdd2e570SFelix Fietkau 	struct mt7615_phy phy;
249d8d59f66SRyder Lee 	u64 omac_mask;
25004b8e659SRyder Lee 
2510f2173f0SFelix Fietkau 	u16 chainmask;
2520f2173f0SFelix Fietkau 
253635cb010SFelix Fietkau 	struct ieee80211_ops *ops;
2546f4d7cc8SLorenzo Bianconi 	const struct mt7615_mcu_ops *mcu_ops;
25535da599fSFelix Fietkau 	struct regmap *infracfg;
25694f83b66SLorenzo Bianconi 	const u32 *reg_map;
25735da599fSFelix Fietkau 
258c3c25d09SFelix Fietkau 	struct work_struct mcu_work;
259c3c25d09SFelix Fietkau 
26061c4fa72SFelix Fietkau 	struct work_struct reset_work;
26161c4fa72SFelix Fietkau 	wait_queue_head_t reset_wait;
26261c4fa72SFelix Fietkau 	u32 reset_state;
26361c4fa72SFelix Fietkau 
26470911d96SLorenzo Bianconi 	struct {
26570911d96SLorenzo Bianconi 		u8 n_pulses;
26670911d96SLorenzo Bianconi 		u32 period;
26770911d96SLorenzo Bianconi 		u16 width;
26870911d96SLorenzo Bianconi 		s16 power;
26970911d96SLorenzo Bianconi 	} radar_pattern;
270d67a6646SLorenzo Bianconi 	u32 hw_pattern;
271d67a6646SLorenzo Bianconi 
272f347f81aSFelix Fietkau 	bool fw_debug;
273ad380ad1SFelix Fietkau 	bool flash_eeprom;
2747660a1bdSShayne Chen 	bool dbdc_support;
27549de79adSLorenzo Bianconi 
2766849e29eSRyder Lee 	u8 fw_ver;
277eb99cc95SLorenzo Bianconi 
278d927ebb9SLorenzo Bianconi 	struct work_struct rate_work;
279d927ebb9SLorenzo Bianconi 	struct list_head wrd_head;
280dc804058SFelix Fietkau 
281dc804058SFelix Fietkau 	u32 debugfs_rf_wf;
282dc804058SFelix Fietkau 	u32 debugfs_rf_reg;
2834f0bce1cSFelix Fietkau 
284d22da028SFelix Fietkau 	u32 muar_mask;
285d22da028SFelix Fietkau 
286b7dd3c2eSLorenzo Bianconi 	struct mt76_connac_pm pm;
287d2bf7959SLorenzo Bianconi 	struct mt76_connac_coredump coredump;
28804b8e659SRyder Lee };
28904b8e659SRyder Lee 
2901fec635bSLorenzo Bianconi enum tx_pkt_queue_idx {
2911fec635bSLorenzo Bianconi 	MT_LMAC_AC00,
2921fec635bSLorenzo Bianconi 	MT_LMAC_AC01,
2931fec635bSLorenzo Bianconi 	MT_LMAC_AC02,
2941fec635bSLorenzo Bianconi 	MT_LMAC_AC03,
2951fec635bSLorenzo Bianconi 	MT_LMAC_ALTX0 = 0x10,
2961fec635bSLorenzo Bianconi 	MT_LMAC_BMC0,
2971fec635bSLorenzo Bianconi 	MT_LMAC_BCN0,
2981fec635bSLorenzo Bianconi 	MT_LMAC_PSMP0,
2991fec635bSLorenzo Bianconi 	MT_LMAC_ALTX1,
3001fec635bSLorenzo Bianconi 	MT_LMAC_BMC1,
3011fec635bSLorenzo Bianconi 	MT_LMAC_BCN1,
3021fec635bSLorenzo Bianconi 	MT_LMAC_PSMP1,
3031fec635bSLorenzo Bianconi };
3041fec635bSLorenzo Bianconi 
30504b8e659SRyder Lee enum {
306d67a6646SLorenzo Bianconi 	MT_RX_SEL0,
307d67a6646SLorenzo Bianconi 	MT_RX_SEL1,
308d67a6646SLorenzo Bianconi };
309d67a6646SLorenzo Bianconi 
310d67a6646SLorenzo Bianconi enum mt7615_rdd_cmd {
311d67a6646SLorenzo Bianconi 	RDD_STOP,
312d67a6646SLorenzo Bianconi 	RDD_START,
313d67a6646SLorenzo Bianconi 	RDD_DET_MODE,
314d67a6646SLorenzo Bianconi 	RDD_DET_STOP,
315d67a6646SLorenzo Bianconi 	RDD_CAC_START,
316d67a6646SLorenzo Bianconi 	RDD_CAC_END,
317d67a6646SLorenzo Bianconi 	RDD_NORMAL_START,
318d67a6646SLorenzo Bianconi 	RDD_DISABLE_DFS_CAL,
319d67a6646SLorenzo Bianconi 	RDD_PULSE_DBG,
320d67a6646SLorenzo Bianconi 	RDD_READ_PULSE,
321d67a6646SLorenzo Bianconi 	RDD_RESUME_BF,
322d67a6646SLorenzo Bianconi };
323d67a6646SLorenzo Bianconi 
324fdd2e570SFelix Fietkau static inline struct mt7615_phy *
mt7615_hw_phy(struct ieee80211_hw * hw)325fdd2e570SFelix Fietkau mt7615_hw_phy(struct ieee80211_hw *hw)
326fdd2e570SFelix Fietkau {
327fdd2e570SFelix Fietkau 	struct mt76_phy *phy = hw->priv;
328fdd2e570SFelix Fietkau 
329fdd2e570SFelix Fietkau 	return phy->priv;
330fdd2e570SFelix Fietkau }
331fdd2e570SFelix Fietkau 
332fdd2e570SFelix Fietkau static inline struct mt7615_dev *
mt7615_hw_dev(struct ieee80211_hw * hw)333fdd2e570SFelix Fietkau mt7615_hw_dev(struct ieee80211_hw *hw)
334fdd2e570SFelix Fietkau {
335fdd2e570SFelix Fietkau 	struct mt76_phy *phy = hw->priv;
336fdd2e570SFelix Fietkau 
337fdd2e570SFelix Fietkau 	return container_of(phy->dev, struct mt7615_dev, mt76);
338fdd2e570SFelix Fietkau }
339fdd2e570SFelix Fietkau 
340fdd2e570SFelix Fietkau static inline struct mt7615_phy *
mt7615_ext_phy(struct mt7615_dev * dev)341fdd2e570SFelix Fietkau mt7615_ext_phy(struct mt7615_dev *dev)
342fdd2e570SFelix Fietkau {
343dc44c45cSLorenzo Bianconi 	struct mt76_phy *phy = dev->mt76.phys[MT_BAND1];
344fdd2e570SFelix Fietkau 
345fdd2e570SFelix Fietkau 	if (!phy)
346fdd2e570SFelix Fietkau 		return NULL;
347fdd2e570SFelix Fietkau 
348fdd2e570SFelix Fietkau 	return phy->priv;
349fdd2e570SFelix Fietkau }
350fdd2e570SFelix Fietkau 
351e90354e0SLorenzo Bianconi extern struct ieee80211_rate mt7615_rates[12];
35204b8e659SRyder Lee extern const struct ieee80211_ops mt7615_ops;
35394f83b66SLorenzo Bianconi extern const u32 mt7615e_reg_map[__MT_BASE_MAX];
354f40ac0f3SLorenzo Bianconi extern const u32 mt7663e_reg_map[__MT_BASE_MAX];
35590520afbSLorenzo Bianconi extern const u32 mt7663_usb_sdio_reg_map[__MT_BASE_MAX];
35604b8e659SRyder Lee extern struct pci_driver mt7615_pci_driver;
35735da599fSFelix Fietkau extern struct platform_driver mt7622_wmac_driver;
3584f0bce1cSFelix Fietkau extern const struct mt76_testmode_ops mt7615_testmode_ops;
35935da599fSFelix Fietkau 
36035da599fSFelix Fietkau #ifdef CONFIG_MT7622_WMAC
36135da599fSFelix Fietkau int mt7622_wmac_init(struct mt7615_dev *dev);
36235da599fSFelix Fietkau #else
mt7622_wmac_init(struct mt7615_dev * dev)36335da599fSFelix Fietkau static inline int mt7622_wmac_init(struct mt7615_dev *dev)
36435da599fSFelix Fietkau {
36535da599fSFelix Fietkau 	return 0;
36635da599fSFelix Fietkau }
36735da599fSFelix Fietkau #endif
36804b8e659SRyder Lee 
369109e505aSRyder Lee int mt7615_thermal_init(struct mt7615_dev *dev);
37094f83b66SLorenzo Bianconi int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base,
37194f83b66SLorenzo Bianconi 		      int irq, const u32 *map);
37204b8e659SRyder Lee u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
37304b8e659SRyder Lee 
37412a88d4dSLorenzo Bianconi u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
37512a88d4dSLorenzo Bianconi int mt7615_led_set_blink(struct led_classdev *led_cdev,
37612a88d4dSLorenzo Bianconi 			 unsigned long *delay_on,
37712a88d4dSLorenzo Bianconi 			 unsigned long *delay_off);
37812a88d4dSLorenzo Bianconi void mt7615_led_set_brightness(struct led_classdev *led_cdev,
37912a88d4dSLorenzo Bianconi 			       enum led_brightness brightness);
3802ee920c2SLorenzo Bianconi void mt7615_init_device(struct mt7615_dev *dev);
38104b8e659SRyder Lee int mt7615_register_device(struct mt7615_dev *dev);
38204b8e659SRyder Lee void mt7615_unregister_device(struct mt7615_dev *dev);
3830f2173f0SFelix Fietkau int mt7615_register_ext_phy(struct mt7615_dev *dev);
3840f2173f0SFelix Fietkau void mt7615_unregister_ext_phy(struct mt7615_dev *dev);
3856e5d2099SLorenzo Bianconi int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr);
386e0ec633dSLorenzo Bianconi int mt7615_eeprom_get_target_power_index(struct mt7615_dev *dev,
38716a2f8e2SLorenzo Bianconi 					 struct ieee80211_channel *chan,
38861d36824SLorenzo Bianconi 					 u8 chain_idx);
389c88bf52bSLorenzo Bianconi int mt7615_eeprom_get_power_delta_index(struct mt7615_dev *dev,
390c88bf52bSLorenzo Bianconi 					enum nl80211_band band);
3916dd4072cSLorenzo Bianconi int mt7615_wait_pdma_busy(struct mt7615_dev *dev);
39204b8e659SRyder Lee int mt7615_dma_init(struct mt7615_dev *dev);
3931cb7ea2aSFelix Fietkau void mt7615_dma_start(struct mt7615_dev *dev);
39404b8e659SRyder Lee void mt7615_dma_cleanup(struct mt7615_dev *dev);
39504b8e659SRyder Lee int mt7615_mcu_init(struct mt7615_dev *dev);
396c3c25d09SFelix Fietkau bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev);
397fdd2e570SFelix Fietkau void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
39804b8e659SRyder Lee 			  struct ieee80211_tx_rate *probe_rate,
39904b8e659SRyder Lee 			  struct ieee80211_tx_rate *rates);
40008523a2aSLorenzo Bianconi void mt7615_pm_wake_work(struct work_struct *work);
401de5ff3c9SLorenzo Bianconi void mt7615_pm_power_save_work(struct work_struct *work);
40204b8e659SRyder Lee int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
4034fe9218cSRyder Lee int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd);
40404b8e659SRyder Lee int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
40504b8e659SRyder Lee 		       const struct ieee80211_tx_queue_params *params);
406d67a6646SLorenzo Bianconi void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb);
40770911d96SLorenzo Bianconi int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
408f347f81aSFelix Fietkau int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl);
409d67a6646SLorenzo Bianconi 
mt7615_firmware_offload(struct mt7615_dev * dev)410bf18fcdcSLorenzo Bianconi static inline bool mt7615_firmware_offload(struct mt7615_dev *dev)
411bf18fcdcSLorenzo Bianconi {
412bf18fcdcSLorenzo Bianconi 	return dev->fw_ver > MT7615_FIRMWARE_V2;
413bf18fcdcSLorenzo Bianconi }
414bf18fcdcSLorenzo Bianconi 
mt7615_wtbl_size(struct mt7615_dev * dev)4158f997dddSLorenzo Bianconi static inline u16 mt7615_wtbl_size(struct mt7615_dev *dev)
4168f997dddSLorenzo Bianconi {
4178f997dddSLorenzo Bianconi 	if (is_mt7663(&dev->mt76) && mt7615_firmware_offload(dev))
4188f997dddSLorenzo Bianconi 		return MT7663_WTBL_SIZE;
4198f997dddSLorenzo Bianconi 	else
4208f997dddSLorenzo Bianconi 		return MT7615_WTBL_SIZE;
4218f997dddSLorenzo Bianconi }
4228f997dddSLorenzo Bianconi 
4231755f6adSLorenzo Bianconi #define mt7615_mutex_acquire(dev)	\
4241755f6adSLorenzo Bianconi 	mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm)
4251755f6adSLorenzo Bianconi #define mt7615_mutex_release(dev)	\
4261755f6adSLorenzo Bianconi 	mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm)
427adfd5112SLorenzo Bianconi 
mt7615_lmac_mapping(struct mt7615_dev * dev,u8 ac)4281fec635bSLorenzo Bianconi static inline u8 mt7615_lmac_mapping(struct mt7615_dev *dev, u8 ac)
4291fec635bSLorenzo Bianconi {
4301fec635bSLorenzo Bianconi 	static const u8 lmac_queue_map[] = {
4311fec635bSLorenzo Bianconi 		[IEEE80211_AC_BK] = MT_LMAC_AC00,
4321fec635bSLorenzo Bianconi 		[IEEE80211_AC_BE] = MT_LMAC_AC01,
4331fec635bSLorenzo Bianconi 		[IEEE80211_AC_VI] = MT_LMAC_AC02,
4341fec635bSLorenzo Bianconi 		[IEEE80211_AC_VO] = MT_LMAC_AC03,
4351fec635bSLorenzo Bianconi 	};
4361fec635bSLorenzo Bianconi 
4371fec635bSLorenzo Bianconi 	if (WARN_ON_ONCE(ac >= ARRAY_SIZE(lmac_queue_map)))
4381fec635bSLorenzo Bianconi 		return MT_LMAC_AC01; /* BE */
4391fec635bSLorenzo Bianconi 
4401fec635bSLorenzo Bianconi 	return lmac_queue_map[ac];
4411fec635bSLorenzo Bianconi }
4421fec635bSLorenzo Bianconi 
mt7615_tx_mcu_int_mask(struct mt7615_dev * dev)443e17d7945SFelix Fietkau static inline u32 mt7615_tx_mcu_int_mask(struct mt7615_dev *dev)
444e17d7945SFelix Fietkau {
445e637763bSLorenzo Bianconi 	return MT_INT_TX_DONE(dev->mt76.q_mcu[MT_MCUQ_WM]->hw_idx);
446e17d7945SFelix Fietkau }
447e17d7945SFelix Fietkau 
448a27238a0SLorenzo Bianconi static inline unsigned long
mt7615_get_macwork_timeout(struct mt7615_dev * dev)449a27238a0SLorenzo Bianconi mt7615_get_macwork_timeout(struct mt7615_dev *dev)
450a27238a0SLorenzo Bianconi {
451a27238a0SLorenzo Bianconi 	return dev->pm.enable ? HZ / 3 : HZ / 10;
452a27238a0SLorenzo Bianconi }
453a27238a0SLorenzo Bianconi 
4546dd4072cSLorenzo Bianconi void mt7615_dma_reset(struct mt7615_dev *dev);
455fcdfc29eSLorenzo Bianconi void mt7615_scan_work(struct work_struct *work);
4567307f296SLorenzo Bianconi void mt7615_roc_work(struct work_struct *work);
4577307f296SLorenzo Bianconi void mt7615_roc_timer(struct timer_list *timer);
458e90354e0SLorenzo Bianconi void mt7615_init_txpower(struct mt7615_dev *dev,
459e90354e0SLorenzo Bianconi 			 struct ieee80211_supported_band *sband);
4604f0bce1cSFelix Fietkau int mt7615_set_channel(struct mt7615_phy *phy);
46195f381c5SFelix Fietkau void mt7615_init_work(struct mt7615_dev *dev);
462e90354e0SLorenzo Bianconi 
463e90354e0SLorenzo Bianconi int mt7615_mcu_restart(struct mt76_dev *dev);
464c560b137SRyder Lee void mt7615_update_channel(struct mt76_phy *mphy);
46587d3cdebSLorenzo Bianconi bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
4661b9ba30eSLorenzo Bianconi void mt7615_mac_reset_counters(struct mt7615_phy *phy);
467d446a20fSFelix Fietkau void mt7615_mac_cca_stats_reset(struct mt7615_phy *phy);
468594034b7SLorenzo Bianconi void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable);
469e5051965SFelix Fietkau void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy);
470e34235ccSRyder Lee void mt7615_mac_enable_rtscts(struct mt7615_dev *dev,
471e34235ccSRyder Lee 			      struct ieee80211_vif *vif, bool enable);
472b2c2f029SLorenzo Bianconi void mt7615_mac_sta_poll(struct mt7615_dev *dev);
47304b8e659SRyder Lee int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
47404b8e659SRyder Lee 			  struct sk_buff *skb, struct mt76_wcid *wcid,
47504b8e659SRyder Lee 			  struct ieee80211_sta *sta, int pid,
4761d5af0acSFelix Fietkau 			  struct ieee80211_key_conf *key,
4771d5af0acSFelix Fietkau 			  enum mt76_txq_id qid, bool beacon);
478183d1fcfSLorenzo Bianconi void mt7615_mac_set_timing(struct mt7615_phy *phy);
479faa72684SLorenzo Bianconi int __mt7615_mac_wtbl_set_key(struct mt7615_dev *dev,
480faa72684SLorenzo Bianconi 			      struct mt76_wcid *wcid,
481e6db67faSFelix Fietkau 			      struct ieee80211_key_conf *key);
482faa72684SLorenzo Bianconi int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
483e6db67faSFelix Fietkau 			    struct ieee80211_key_conf *key);
48461c4fa72SFelix Fietkau void mt7615_mac_reset_work(struct work_struct *work);
485a28bef56SFelix Fietkau u32 mt7615_mac_get_sta_tid_sn(struct mt7615_dev *dev, int wcid, u8 tid);
48604b8e659SRyder Lee 
487f320d812SFelix Fietkau int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd,
488f320d812SFelix Fietkau 			      struct sk_buff *skb, int seq);
489dc804058SFelix Fietkau u32 mt7615_rf_rr(struct mt7615_dev *dev, u32 wf, u32 reg);
490dc804058SFelix Fietkau int mt7615_rf_wr(struct mt7615_dev *dev, u32 wf, u32 reg, u32 val);
491ac3ef85cSFelix Fietkau int mt7615_mcu_set_dbdc(struct mt7615_dev *dev);
49204b8e659SRyder Lee int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
493109e505aSRyder Lee int mt7615_mcu_get_temperature(struct mt7615_dev *dev);
4944f0bce1cSFelix Fietkau int mt7615_mcu_set_tx_power(struct mt7615_phy *phy);
49504b8e659SRyder Lee void mt7615_mcu_exit(struct mt7615_dev *dev);
49663f09b6bSLorenzo Bianconi void mt7615_mcu_fill_msg(struct mt7615_dev *dev, struct sk_buff *skb,
49763f09b6bSLorenzo Bianconi 			 int cmd, int *wait_seq);
49804b8e659SRyder Lee 
49904b8e659SRyder Lee int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
50004b8e659SRyder Lee 			  enum mt76_txq_id qid, struct mt76_wcid *wcid,
50104b8e659SRyder Lee 			  struct ieee80211_sta *sta,
50204b8e659SRyder Lee 			  struct mt76_tx_info *tx_info);
50304b8e659SRyder Lee 
504335e97acSLorenzo Bianconi void mt7615_tx_worker(struct mt76_worker *w);
505a6275e93SRyder Lee void mt7615_tx_token_put(struct mt7615_dev *dev);
50674bbb174SLorenzo Bianconi bool mt7615_rx_check(struct mt76_dev *mdev, void *data, int len);
50704b8e659SRyder Lee void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
508c3137942SSujuan Chen 			 struct sk_buff *skb, u32 *info);
5093e384828SFelix Fietkau int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
51004b8e659SRyder Lee 		       struct ieee80211_sta *sta);
5113e384828SFelix Fietkau void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
51204b8e659SRyder Lee 			   struct ieee80211_sta *sta);
51304b8e659SRyder Lee void mt7615_mac_work(struct work_struct *work);
514d4b98c63SRyder Lee int mt7615_mcu_set_rx_hdr_trans_blacklist(struct mt7615_dev *dev);
5152ce73efeSLorenzo Bianconi int mt7615_mcu_set_fcc5_lpn(struct mt7615_dev *dev, int val);
5162ce73efeSLorenzo Bianconi int mt7615_mcu_set_pulse_th(struct mt7615_dev *dev,
5172ce73efeSLorenzo Bianconi 			    const struct mt7615_dfs_pulse *pulse);
5182ce73efeSLorenzo Bianconi int mt7615_mcu_set_radar_th(struct mt7615_dev *dev, int index,
5192ce73efeSLorenzo Bianconi 			    const struct mt7615_dfs_pattern *pattern);
5204f0bce1cSFelix Fietkau int mt7615_mcu_set_test_param(struct mt7615_dev *dev, u8 param, bool test_mode,
5214f0bce1cSFelix Fietkau 			      u32 val);
52215d9a5d7SFelix Fietkau int mt7615_mcu_set_sku_en(struct mt7615_phy *phy, bool enable);
523ad380ad1SFelix Fietkau int mt7615_mcu_apply_rx_dcoc(struct mt7615_phy *phy);
524371a59d1SFelix Fietkau int mt7615_mcu_apply_tx_dpd(struct mt7615_phy *phy);
5255dabdf71SFelix Fietkau int mt7615_dfs_init_radar_detector(struct mt7615_phy *phy);
52604b8e659SRyder Lee 
5277307f296SLorenzo Bianconi int mt7615_mcu_set_roc(struct mt7615_phy *phy, struct ieee80211_vif *vif,
5287307f296SLorenzo Bianconi 		       struct ieee80211_channel *chan, int duration);
5296dd4072cSLorenzo Bianconi 
53070911d96SLorenzo Bianconi int mt7615_init_debugfs(struct mt7615_dev *dev);
531eb99cc95SLorenzo Bianconi int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq);
532eb99cc95SLorenzo Bianconi 
5337124198aSLorenzo Bianconi int mt7615_mac_set_beacon_filter(struct mt7615_phy *phy,
5347124198aSLorenzo Bianconi 				 struct ieee80211_vif *vif,
5357124198aSLorenzo Bianconi 				 bool enable);
53683b9f42aSLorenzo Bianconi int mt7615_mcu_set_bss_pm(struct mt7615_dev *dev, struct ieee80211_vif *vif,
53783b9f42aSLorenzo Bianconi 			  bool enable);
5388915c3ceSLorenzo Bianconi int __mt7663_load_firmware(struct mt7615_dev *dev);
539d2bf7959SLorenzo Bianconi void mt7615_coredump_work(struct work_struct *work);
54070911d96SLorenzo Bianconi 
541ad2a1ea4SRyder Lee void mt7622_trigger_hif_int(struct mt7615_dev *dev, bool en);
542ad2a1ea4SRyder Lee 
543eb99cc95SLorenzo Bianconi /* usb */
54490520afbSLorenzo Bianconi int mt7663_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
54590520afbSLorenzo Bianconi 				   enum mt76_txq_id qid, struct mt76_wcid *wcid,
54690520afbSLorenzo Bianconi 				   struct ieee80211_sta *sta,
54790520afbSLorenzo Bianconi 				   struct mt76_tx_info *tx_info);
54890520afbSLorenzo Bianconi bool mt7663_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update);
54990520afbSLorenzo Bianconi void mt7663_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,
55090520afbSLorenzo Bianconi 				     struct mt76_queue_entry *e);
55190520afbSLorenzo Bianconi int mt7663_usb_sdio_register_device(struct mt7615_dev *dev);
552eb99cc95SLorenzo Bianconi int mt7663u_mcu_init(struct mt7615_dev *dev);
5534dd4ad44SLorenzo Bianconi int mt7663u_mcu_power_on(struct mt7615_dev *dev);
554eb99cc95SLorenzo Bianconi 
555a66cbdd6SSean Wang /* sdio */
556a66cbdd6SSean Wang int mt7663s_mcu_init(struct mt7615_dev *dev);
557a66cbdd6SSean Wang 
55804b8e659SRyder Lee #endif
559