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 
704b8e659SRyder Lee #include <linux/interrupt.h>
804b8e659SRyder Lee #include <linux/ktime.h>
935da599fSFelix Fietkau #include <linux/regmap.h>
1004b8e659SRyder Lee #include "../mt76.h"
1104b8e659SRyder Lee #include "regs.h"
1204b8e659SRyder Lee 
1304b8e659SRyder Lee #define MT7615_MAX_INTERFACES		4
1449f1132cSRyder Lee #define MT7615_MAX_WMM_SETS		4
158f997dddSLorenzo Bianconi #define MT7663_WTBL_SIZE		32
1604b8e659SRyder Lee #define MT7615_WTBL_SIZE		128
178f997dddSLorenzo Bianconi #define MT7615_WTBL_RESERVED		(mt7615_wtbl_size(dev) - 1)
1804b8e659SRyder Lee #define MT7615_WTBL_STA			(MT7615_WTBL_RESERVED - \
1904b8e659SRyder Lee 					 MT7615_MAX_INTERFACES)
2004b8e659SRyder Lee 
21457d19c7SLorenzo Bianconi #define MT7615_WATCHDOG_TIME		(HZ / 10)
22fcdfc29eSLorenzo Bianconi #define MT7615_HW_SCAN_TIMEOUT		(HZ / 10)
2361c4fa72SFelix Fietkau #define MT7615_RESET_TIMEOUT		(30 * HZ)
2404b8e659SRyder Lee #define MT7615_RATE_RETRY		2
2504b8e659SRyder Lee 
2604b8e659SRyder Lee #define MT7615_TX_RING_SIZE		1024
27cdad4874SFelix Fietkau #define MT7615_TX_MGMT_RING_SIZE	128
2804b8e659SRyder Lee #define MT7615_TX_MCU_RING_SIZE		128
2904b8e659SRyder Lee #define MT7615_TX_FWDL_RING_SIZE	128
3004b8e659SRyder Lee 
3104b8e659SRyder Lee #define MT7615_RX_RING_SIZE		1024
3204b8e659SRyder Lee #define MT7615_RX_MCU_RING_SIZE		512
3304b8e659SRyder Lee 
349d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_CR4		"mediatek/mt7615_cr4.bin"
359d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_N9		"mediatek/mt7615_n9.bin"
369d4d0d06SLorenzo Bianconi #define MT7615_ROM_PATCH		"mediatek/mt7615_rom_patch.bin"
3704b8e659SRyder Lee 
3835da599fSFelix Fietkau #define MT7622_FIRMWARE_N9		"mediatek/mt7622_n9.bin"
3935da599fSFelix Fietkau #define MT7622_ROM_PATCH		"mediatek/mt7622_rom_patch.bin"
4035da599fSFelix Fietkau 
416849e29eSRyder Lee #define MT7615_FIRMWARE_V1		1
426849e29eSRyder Lee #define MT7615_FIRMWARE_V2		2
43f40ac0f3SLorenzo Bianconi #define MT7615_FIRMWARE_V3		3
44f40ac0f3SLorenzo Bianconi 
45044883e3SSean Wang #define MT7663_ROM_PATCH		"mediatek/mt7663pr2h.bin"
46f40ac0f3SLorenzo Bianconi #define MT7663_FIRMWARE_N9              "mediatek/mt7663_n9_v3.bin"
476849e29eSRyder Lee 
4804b8e659SRyder Lee #define MT7615_EEPROM_SIZE		1024
4904b8e659SRyder Lee #define MT7615_TOKEN_SIZE		4096
5004b8e659SRyder Lee 
5149de79adSLorenzo Bianconi #define MT_FRAC_SCALE		12
5249de79adSLorenzo Bianconi #define MT_FRAC(val, div)	(((val) << MT_FRAC_SCALE) / (div))
5349de79adSLorenzo Bianconi 
5427ae7219SFelix Fietkau #define MT_CHFREQ_VALID		BIT(7)
5527ae7219SFelix Fietkau #define MT_CHFREQ_DBDC_IDX	BIT(6)
5627ae7219SFelix Fietkau #define MT_CHFREQ_SEQ		GENMASK(5, 0)
5727ae7219SFelix Fietkau 
58a25c888fSRyder Lee #define MT7615_BAR_RATE_DEFAULT		0x4b /* OFDM 6M */
59a25c888fSRyder Lee #define MT7615_CFEND_RATE_DEFAULT	0x49 /* OFDM 24M */
60183d1fcfSLorenzo Bianconi #define MT7615_CFEND_RATE_11B		0x03 /* 11B LP, 11M */
61183d1fcfSLorenzo Bianconi 
62fcdfc29eSLorenzo Bianconi #define MT7615_SCAN_IE_LEN		600
6320305f98SLorenzo Bianconi #define MT7615_MAX_SCHED_SCAN_INTERVAL	10
6420305f98SLorenzo Bianconi #define MT7615_MAX_SCHED_SCAN_SSID	10
6520305f98SLorenzo Bianconi #define MT7615_MAX_SCAN_MATCH		16
66fcdfc29eSLorenzo Bianconi 
6704b8e659SRyder Lee struct mt7615_vif;
6804b8e659SRyder Lee struct mt7615_sta;
692ce73efeSLorenzo Bianconi struct mt7615_dfs_pulse;
702ce73efeSLorenzo Bianconi struct mt7615_dfs_pattern;
71294f17aeSLorenzo Bianconi enum mt7615_cipher_type;
7204b8e659SRyder Lee 
7304b8e659SRyder Lee enum mt7615_hw_txq_id {
7404b8e659SRyder Lee 	MT7615_TXQ_MAIN,
7504b8e659SRyder Lee 	MT7615_TXQ_EXT,
7604b8e659SRyder Lee 	MT7615_TXQ_MCU,
7704b8e659SRyder Lee 	MT7615_TXQ_FWDL,
7804b8e659SRyder Lee };
7904b8e659SRyder Lee 
80cdad4874SFelix Fietkau enum mt7622_hw_txq_id {
81cdad4874SFelix Fietkau 	MT7622_TXQ_AC0,
82cdad4874SFelix Fietkau 	MT7622_TXQ_AC1,
83cdad4874SFelix Fietkau 	MT7622_TXQ_AC2,
84cdad4874SFelix Fietkau 	MT7622_TXQ_FWDL = MT7615_TXQ_FWDL,
85cdad4874SFelix Fietkau 	MT7622_TXQ_AC3,
86cdad4874SFelix Fietkau 	MT7622_TXQ_MGMT,
87cdad4874SFelix Fietkau 	MT7622_TXQ_MCU = 15,
88cdad4874SFelix Fietkau };
89cdad4874SFelix Fietkau 
904af81f02SFelix Fietkau struct mt7615_rate_set {
914af81f02SFelix Fietkau 	struct ieee80211_tx_rate probe_rate;
924af81f02SFelix Fietkau 	struct ieee80211_tx_rate rates[4];
934af81f02SFelix Fietkau };
944af81f02SFelix Fietkau 
958f93af9cSLorenzo Bianconi struct mt7615_rate_desc {
968f93af9cSLorenzo Bianconi 	bool rateset;
978f93af9cSLorenzo Bianconi 	u16 probe_val;
988f93af9cSLorenzo Bianconi 	u16 val[4];
998f93af9cSLorenzo Bianconi 	u8 bw_idx;
1008f93af9cSLorenzo Bianconi 	u8 bw;
1018f93af9cSLorenzo Bianconi };
1028f93af9cSLorenzo Bianconi 
1037d9f1d10SLorenzo Bianconi enum mt7615_wtbl_desc_type {
1047d9f1d10SLorenzo Bianconi 	MT7615_WTBL_RATE_DESC,
1057d9f1d10SLorenzo Bianconi 	MT7615_WTBL_KEY_DESC
1067d9f1d10SLorenzo Bianconi };
1077d9f1d10SLorenzo Bianconi 
1087d9f1d10SLorenzo Bianconi struct mt7615_key_desc {
1097d9f1d10SLorenzo Bianconi 	enum set_key_cmd cmd;
1107d9f1d10SLorenzo Bianconi 	u32 cipher;
1117d9f1d10SLorenzo Bianconi 	s8 keyidx;
1127d9f1d10SLorenzo Bianconi 	u8 keylen;
1137d9f1d10SLorenzo Bianconi 	u8 *key;
1147d9f1d10SLorenzo Bianconi };
1157d9f1d10SLorenzo Bianconi 
1167d9f1d10SLorenzo Bianconi struct mt7615_wtbl_desc {
1177d9f1d10SLorenzo Bianconi 	struct list_head node;
1187d9f1d10SLorenzo Bianconi 
1197d9f1d10SLorenzo Bianconi 	enum mt7615_wtbl_desc_type type;
1207d9f1d10SLorenzo Bianconi 	struct mt7615_sta *sta;
1217d9f1d10SLorenzo Bianconi 
1227d9f1d10SLorenzo Bianconi 	union {
1237d9f1d10SLorenzo Bianconi 		struct mt7615_rate_desc rate;
1247d9f1d10SLorenzo Bianconi 		struct mt7615_key_desc key;
1257d9f1d10SLorenzo Bianconi 	};
1267d9f1d10SLorenzo Bianconi };
1277d9f1d10SLorenzo Bianconi 
12804b8e659SRyder Lee struct mt7615_sta {
12904b8e659SRyder Lee 	struct mt76_wcid wcid; /* must be first */
13004b8e659SRyder Lee 
13104b8e659SRyder Lee 	struct mt7615_vif *vif;
13204b8e659SRyder Lee 
133b2c2f029SLorenzo Bianconi 	struct list_head poll_list;
134b2c2f029SLorenzo Bianconi 	u32 airtime_ac[8];
135b2c2f029SLorenzo Bianconi 
1364af81f02SFelix Fietkau 	struct ieee80211_tx_rate rates[4];
1374af81f02SFelix Fietkau 
1384af81f02SFelix Fietkau 	struct mt7615_rate_set rateset[2];
1394af81f02SFelix Fietkau 	u32 rate_set_tsf;
1404af81f02SFelix Fietkau 
14104b8e659SRyder Lee 	u8 rate_count;
14204b8e659SRyder Lee 	u8 n_rates;
14304b8e659SRyder Lee 
14404b8e659SRyder Lee 	u8 rate_probe;
14504b8e659SRyder Lee };
14604b8e659SRyder Lee 
14704b8e659SRyder Lee struct mt7615_vif {
14804b8e659SRyder Lee 	u8 idx;
14904b8e659SRyder Lee 	u8 omac_idx;
15004b8e659SRyder Lee 	u8 band_idx;
15104b8e659SRyder Lee 	u8 wmm_idx;
152fcdfc29eSLorenzo Bianconi 	u8 scan_seq_num;
15304b8e659SRyder Lee 
15404b8e659SRyder Lee 	struct mt7615_sta sta;
15504b8e659SRyder Lee };
15604b8e659SRyder Lee 
157679b23feSRyder Lee struct mib_stats {
158b7825ca0SRyder Lee 	u16 ack_fail_cnt;
159b7825ca0SRyder Lee 	u16 fcs_err_cnt;
160b7825ca0SRyder Lee 	u16 rts_cnt;
161b7825ca0SRyder Lee 	u16 rts_retries_cnt;
162aef16345SRyder Lee 	u16 ba_miss_cnt;
163aef16345SRyder Lee 	unsigned long aggr_per;
164679b23feSRyder Lee };
165679b23feSRyder Lee 
166fdd2e570SFelix Fietkau struct mt7615_phy {
167fdd2e570SFelix Fietkau 	struct mt76_phy *mt76;
168fdd2e570SFelix Fietkau 	struct mt7615_dev *dev;
169fdd2e570SFelix Fietkau 
170fdd2e570SFelix Fietkau 	u32 rxfilter;
171ac3ef85cSFelix Fietkau 	u32 omac_mask;
172d446a20fSFelix Fietkau 
173e5051965SFelix Fietkau 	u16 noise;
174e5051965SFelix Fietkau 
175594034b7SLorenzo Bianconi 	bool scs_en;
176594034b7SLorenzo Bianconi 
177d446a20fSFelix Fietkau 	unsigned long last_cca_adj;
178d446a20fSFelix Fietkau 	int false_cca_ofdm, false_cca_cck;
179d446a20fSFelix Fietkau 	s8 ofdm_sensitivity;
180d446a20fSFelix Fietkau 	s8 cck_sensitivity;
1815dabdf71SFelix Fietkau 
1822bed2a3eSFelix Fietkau 	u16 chainmask;
1832bed2a3eSFelix Fietkau 
184183d1fcfSLorenzo Bianconi 	s16 coverage_class;
185183d1fcfSLorenzo Bianconi 	u8 slottime;
186183d1fcfSLorenzo Bianconi 
1870e544cb5SFelix Fietkau 	u8 chfreq;
1885dabdf71SFelix Fietkau 	u8 rdd_state;
1895dabdf71SFelix Fietkau 	int dfs_state;
19027ae7219SFelix Fietkau 
19127ae7219SFelix Fietkau 	__le32 rx_ampdu_ts;
19227ae7219SFelix Fietkau 	u32 ampdu_ref;
193679b23feSRyder Lee 
194679b23feSRyder Lee 	struct mib_stats mib;
195fcdfc29eSLorenzo Bianconi 
1964fcf6e77SLorenzo Bianconi 	struct delayed_work mac_work;
1974fcf6e77SLorenzo Bianconi 	u8 mac_work_count;
1984fcf6e77SLorenzo Bianconi 
19920305f98SLorenzo Bianconi 	struct sk_buff_head scan_event_list;
200fcdfc29eSLorenzo Bianconi 	struct delayed_work scan_work;
2017f8ebafeSLorenzo Bianconi 
2027f8ebafeSLorenzo Bianconi 	struct work_struct ps_work;
203fdd2e570SFelix Fietkau };
204fdd2e570SFelix Fietkau 
2056f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_tx_ba(dev, ...)	(dev)->mcu_ops->add_tx_ba((dev), __VA_ARGS__)
2066f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_rx_ba(dev, ...)	(dev)->mcu_ops->add_rx_ba((dev), __VA_ARGS__)
20799c457d9SLorenzo Bianconi #define mt7615_mcu_sta_add(dev, ...)	(dev)->mcu_ops->sta_add((dev),  __VA_ARGS__)
208062c3699SLorenzo Bianconi #define mt7615_mcu_add_dev_info(dev, ...) (dev)->mcu_ops->add_dev_info((dev),  __VA_ARGS__)
2095d3a4a4bSLorenzo Bianconi #define mt7615_mcu_add_bss_info(phy, ...) (phy->dev)->mcu_ops->add_bss_info((phy),  __VA_ARGS__)
210062c3699SLorenzo Bianconi #define mt7615_mcu_add_beacon(dev, ...)	(dev)->mcu_ops->add_beacon_offload((dev),  __VA_ARGS__)
211062c3699SLorenzo Bianconi #define mt7615_mcu_set_pm(dev, ...)	(dev)->mcu_ops->set_pm_state((dev),  __VA_ARGS__)
2126f4d7cc8SLorenzo Bianconi struct mt7615_mcu_ops {
2136f4d7cc8SLorenzo Bianconi 	int (*add_tx_ba)(struct mt7615_dev *dev,
2146f4d7cc8SLorenzo Bianconi 			 struct ieee80211_ampdu_params *params,
2156f4d7cc8SLorenzo Bianconi 			 bool enable);
2166f4d7cc8SLorenzo Bianconi 	int (*add_rx_ba)(struct mt7615_dev *dev,
2176f4d7cc8SLorenzo Bianconi 			 struct ieee80211_ampdu_params *params,
2186f4d7cc8SLorenzo Bianconi 			 bool enable);
21999c457d9SLorenzo Bianconi 	int (*sta_add)(struct mt7615_dev *dev,
22099c457d9SLorenzo Bianconi 		       struct ieee80211_vif *vif,
22199c457d9SLorenzo Bianconi 		       struct ieee80211_sta *sta, bool enable);
222062c3699SLorenzo Bianconi 	int (*add_dev_info)(struct mt7615_dev *dev,
223062c3699SLorenzo Bianconi 			    struct ieee80211_vif *vif, bool enable);
2245d3a4a4bSLorenzo Bianconi 	int (*add_bss_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif,
225f5596850SLorenzo Bianconi 			    struct ieee80211_sta *sta, bool enable);
226062c3699SLorenzo Bianconi 	int (*add_beacon_offload)(struct mt7615_dev *dev,
227062c3699SLorenzo Bianconi 				  struct ieee80211_hw *hw,
228062c3699SLorenzo Bianconi 				  struct ieee80211_vif *vif, bool enable);
229062c3699SLorenzo Bianconi 	int (*set_pm_state)(struct mt7615_dev *dev, int band, int state);
2306f4d7cc8SLorenzo Bianconi };
2316f4d7cc8SLorenzo Bianconi 
23204b8e659SRyder Lee struct mt7615_dev {
233ac24dd35SFelix Fietkau 	union { /* must be first */
234ac24dd35SFelix Fietkau 		struct mt76_dev mt76;
235ac24dd35SFelix Fietkau 		struct mt76_phy mphy;
236ac24dd35SFelix Fietkau 	};
237ac24dd35SFelix Fietkau 
2389b90ab32SFelix Fietkau 	struct tasklet_struct irq_tasklet;
2399b90ab32SFelix Fietkau 
240fdd2e570SFelix Fietkau 	struct mt7615_phy phy;
24104b8e659SRyder Lee 	u32 vif_mask;
24204b8e659SRyder Lee 	u32 omac_mask;
24304b8e659SRyder Lee 
2440f2173f0SFelix Fietkau 	u16 chainmask;
2450f2173f0SFelix Fietkau 
246635cb010SFelix Fietkau 	struct ieee80211_ops *ops;
2476f4d7cc8SLorenzo Bianconi 	const struct mt7615_mcu_ops *mcu_ops;
24835da599fSFelix Fietkau 	struct regmap *infracfg;
24994f83b66SLorenzo Bianconi 	const u32 *reg_map;
25035da599fSFelix Fietkau 
251c3c25d09SFelix Fietkau 	struct work_struct mcu_work;
252c3c25d09SFelix Fietkau 
25361c4fa72SFelix Fietkau 	struct work_struct reset_work;
25461c4fa72SFelix Fietkau 	wait_queue_head_t reset_wait;
25561c4fa72SFelix Fietkau 	u32 reset_state;
25661c4fa72SFelix Fietkau 
257b2c2f029SLorenzo Bianconi 	struct list_head sta_poll_list;
258b2c2f029SLorenzo Bianconi 	spinlock_t sta_poll_lock;
259b2c2f029SLorenzo Bianconi 
26070911d96SLorenzo Bianconi 	struct {
26170911d96SLorenzo Bianconi 		u8 n_pulses;
26270911d96SLorenzo Bianconi 		u32 period;
26370911d96SLorenzo Bianconi 		u16 width;
26470911d96SLorenzo Bianconi 		s16 power;
26570911d96SLorenzo Bianconi 	} radar_pattern;
266d67a6646SLorenzo Bianconi 	u32 hw_pattern;
267d67a6646SLorenzo Bianconi 
268f347f81aSFelix Fietkau 	bool fw_debug;
269ad380ad1SFelix Fietkau 	bool flash_eeprom;
27049de79adSLorenzo Bianconi 
27104b8e659SRyder Lee 	spinlock_t token_lock;
27204b8e659SRyder Lee 	struct idr token;
2736849e29eSRyder Lee 
2746849e29eSRyder Lee 	u8 fw_ver;
275eb99cc95SLorenzo Bianconi 
276eb99cc95SLorenzo Bianconi 	struct work_struct wtbl_work;
277eb99cc95SLorenzo Bianconi 	struct list_head wd_head;
27804b8e659SRyder Lee };
27904b8e659SRyder Lee 
28004b8e659SRyder Lee enum {
28104b8e659SRyder Lee 	HW_BSSID_0 = 0x0,
28204b8e659SRyder Lee 	HW_BSSID_1,
28304b8e659SRyder Lee 	HW_BSSID_2,
28404b8e659SRyder Lee 	HW_BSSID_3,
28504b8e659SRyder Lee 	HW_BSSID_MAX,
28604b8e659SRyder Lee 	EXT_BSSID_START = 0x10,
28704b8e659SRyder Lee 	EXT_BSSID_1,
28804b8e659SRyder Lee 	EXT_BSSID_2,
28904b8e659SRyder Lee 	EXT_BSSID_3,
29004b8e659SRyder Lee 	EXT_BSSID_4,
29104b8e659SRyder Lee 	EXT_BSSID_5,
29204b8e659SRyder Lee 	EXT_BSSID_6,
29304b8e659SRyder Lee 	EXT_BSSID_7,
29404b8e659SRyder Lee 	EXT_BSSID_8,
29504b8e659SRyder Lee 	EXT_BSSID_9,
29604b8e659SRyder Lee 	EXT_BSSID_10,
29704b8e659SRyder Lee 	EXT_BSSID_11,
29804b8e659SRyder Lee 	EXT_BSSID_12,
29904b8e659SRyder Lee 	EXT_BSSID_13,
30004b8e659SRyder Lee 	EXT_BSSID_14,
30104b8e659SRyder Lee 	EXT_BSSID_15,
30204b8e659SRyder Lee 	EXT_BSSID_END
30304b8e659SRyder Lee };
30404b8e659SRyder Lee 
305d67a6646SLorenzo Bianconi 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 *
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 *
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 *
341fdd2e570SFelix Fietkau mt7615_ext_phy(struct mt7615_dev *dev)
342fdd2e570SFelix Fietkau {
343fdd2e570SFelix Fietkau 	struct mt76_phy *phy = dev->mt76.phy2;
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];
35504b8e659SRyder Lee extern struct pci_driver mt7615_pci_driver;
35635da599fSFelix Fietkau extern struct platform_driver mt7622_wmac_driver;
35735da599fSFelix Fietkau 
35835da599fSFelix Fietkau #ifdef CONFIG_MT7622_WMAC
35935da599fSFelix Fietkau int mt7622_wmac_init(struct mt7615_dev *dev);
36035da599fSFelix Fietkau #else
36135da599fSFelix Fietkau static inline int mt7622_wmac_init(struct mt7615_dev *dev)
36235da599fSFelix Fietkau {
36335da599fSFelix Fietkau 	return 0;
36435da599fSFelix Fietkau }
36535da599fSFelix Fietkau #endif
36604b8e659SRyder Lee 
36794f83b66SLorenzo Bianconi int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base,
36894f83b66SLorenzo Bianconi 		      int irq, const u32 *map);
36904b8e659SRyder Lee u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
37004b8e659SRyder Lee 
3712ee920c2SLorenzo Bianconi void mt7615_init_device(struct mt7615_dev *dev);
37204b8e659SRyder Lee int mt7615_register_device(struct mt7615_dev *dev);
37304b8e659SRyder Lee void mt7615_unregister_device(struct mt7615_dev *dev);
3740f2173f0SFelix Fietkau int mt7615_register_ext_phy(struct mt7615_dev *dev);
3750f2173f0SFelix Fietkau void mt7615_unregister_ext_phy(struct mt7615_dev *dev);
3766e5d2099SLorenzo Bianconi int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr);
37716a2f8e2SLorenzo Bianconi int mt7615_eeprom_get_power_index(struct mt7615_dev *dev,
37816a2f8e2SLorenzo Bianconi 				  struct ieee80211_channel *chan,
37961d36824SLorenzo Bianconi 				  u8 chain_idx);
38004b8e659SRyder Lee int mt7615_dma_init(struct mt7615_dev *dev);
38104b8e659SRyder Lee void mt7615_dma_cleanup(struct mt7615_dev *dev);
38204b8e659SRyder Lee int mt7615_mcu_init(struct mt7615_dev *dev);
383c3c25d09SFelix Fietkau bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev);
384fdd2e570SFelix Fietkau void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
38504b8e659SRyder Lee 			  struct ieee80211_tx_rate *probe_rate,
38604b8e659SRyder Lee 			  struct ieee80211_tx_rate *rates);
38704b8e659SRyder Lee int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
3884fe9218cSRyder Lee int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd);
38904b8e659SRyder Lee int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
39004b8e659SRyder Lee 		       const struct ieee80211_tx_queue_params *params);
391d67a6646SLorenzo Bianconi void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb);
392d67a6646SLorenzo Bianconi int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
393d67a6646SLorenzo Bianconi 		       enum mt7615_rdd_cmd cmd, u8 index,
394d67a6646SLorenzo Bianconi 		       u8 rx_sel, u8 val);
39570911d96SLorenzo Bianconi int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
396f347f81aSFelix Fietkau int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl);
397d67a6646SLorenzo Bianconi 
39849de79adSLorenzo Bianconi static inline bool is_mt7622(struct mt76_dev *dev)
39949de79adSLorenzo Bianconi {
40035da599fSFelix Fietkau 	if (!IS_ENABLED(CONFIG_MT7622_WMAC))
40135da599fSFelix Fietkau 		return false;
40235da599fSFelix Fietkau 
40349de79adSLorenzo Bianconi 	return mt76_chip(dev) == 0x7622;
40449de79adSLorenzo Bianconi }
40549de79adSLorenzo Bianconi 
406cdad4874SFelix Fietkau static inline bool is_mt7615(struct mt76_dev *dev)
407cdad4874SFelix Fietkau {
408cdad4874SFelix Fietkau 	return mt76_chip(dev) == 0x7615;
409cdad4874SFelix Fietkau }
410cdad4874SFelix Fietkau 
411f82282efSLorenzo Bianconi static inline bool is_mt7663(struct mt76_dev *dev)
412f82282efSLorenzo Bianconi {
413f82282efSLorenzo Bianconi 	return mt76_chip(dev) == 0x7663;
414f82282efSLorenzo Bianconi }
415f82282efSLorenzo Bianconi 
41604b8e659SRyder Lee static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask)
41704b8e659SRyder Lee {
4189b90ab32SFelix Fietkau 	mt76_set_irq_mask(&dev->mt76, 0, 0, mask);
41904b8e659SRyder Lee 
4209b90ab32SFelix Fietkau 	tasklet_schedule(&dev->irq_tasklet);
42104b8e659SRyder Lee }
42204b8e659SRyder Lee 
423bf18fcdcSLorenzo Bianconi static inline bool mt7615_firmware_offload(struct mt7615_dev *dev)
424bf18fcdcSLorenzo Bianconi {
425bf18fcdcSLorenzo Bianconi 	return dev->fw_ver > MT7615_FIRMWARE_V2;
426bf18fcdcSLorenzo Bianconi }
427bf18fcdcSLorenzo Bianconi 
4288f997dddSLorenzo Bianconi static inline u16 mt7615_wtbl_size(struct mt7615_dev *dev)
4298f997dddSLorenzo Bianconi {
4308f997dddSLorenzo Bianconi 	if (is_mt7663(&dev->mt76) && mt7615_firmware_offload(dev))
4318f997dddSLorenzo Bianconi 		return MT7663_WTBL_SIZE;
4328f997dddSLorenzo Bianconi 	else
4338f997dddSLorenzo Bianconi 		return MT7615_WTBL_SIZE;
4348f997dddSLorenzo Bianconi }
4358f997dddSLorenzo Bianconi 
436fcdfc29eSLorenzo Bianconi void mt7615_scan_work(struct work_struct *work);
4377f8ebafeSLorenzo Bianconi void mt7615_ps_work(struct work_struct *work);
438e90354e0SLorenzo Bianconi void mt7615_init_txpower(struct mt7615_dev *dev,
439e90354e0SLorenzo Bianconi 			 struct ieee80211_supported_band *sband);
440e90354e0SLorenzo Bianconi void mt7615_phy_init(struct mt7615_dev *dev);
441e90354e0SLorenzo Bianconi void mt7615_mac_init(struct mt7615_dev *dev);
442e90354e0SLorenzo Bianconi 
443e90354e0SLorenzo Bianconi int mt7615_mcu_restart(struct mt76_dev *dev);
444863c15a1SLorenzo Bianconi void mt7615_update_channel(struct mt76_dev *mdev);
44587d3cdebSLorenzo Bianconi bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
44675601194SLorenzo Bianconi void mt7615_mac_reset_counters(struct mt7615_dev *dev);
447d446a20fSFelix Fietkau void mt7615_mac_cca_stats_reset(struct mt7615_phy *phy);
448594034b7SLorenzo Bianconi void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable);
449e5051965SFelix Fietkau void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy);
450b2c2f029SLorenzo Bianconi void mt7615_mac_sta_poll(struct mt7615_dev *dev);
45104b8e659SRyder Lee int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
45204b8e659SRyder Lee 			  struct sk_buff *skb, struct mt76_wcid *wcid,
45304b8e659SRyder Lee 			  struct ieee80211_sta *sta, int pid,
454c984457bSFelix Fietkau 			  struct ieee80211_key_conf *key, bool beacon);
455183d1fcfSLorenzo Bianconi void mt7615_mac_set_timing(struct mt7615_phy *phy);
45627b8a900SLorenzo Bianconi int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
45727b8a900SLorenzo Bianconi 			    struct ieee80211_key_conf *key,
45827b8a900SLorenzo Bianconi 			    enum set_key_cmd cmd);
459294f17aeSLorenzo Bianconi int mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev,
460294f17aeSLorenzo Bianconi 			      struct mt76_wcid *wcid,
461294f17aeSLorenzo Bianconi 			      enum mt7615_cipher_type cipher,
462294f17aeSLorenzo Bianconi 			      int keyidx, enum set_key_cmd cmd);
463294f17aeSLorenzo Bianconi void mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev,
464294f17aeSLorenzo Bianconi 				   struct mt76_wcid *wcid,
465294f17aeSLorenzo Bianconi 				   enum mt7615_cipher_type cipher,
466294f17aeSLorenzo Bianconi 				   enum set_key_cmd cmd);
467294f17aeSLorenzo Bianconi int mt7615_mac_wtbl_update_key(struct mt7615_dev *dev,
468294f17aeSLorenzo Bianconi 			       struct mt76_wcid *wcid,
469294f17aeSLorenzo Bianconi 			       u8 *key, u8 keylen,
470294f17aeSLorenzo Bianconi 			       enum mt7615_cipher_type cipher,
471294f17aeSLorenzo Bianconi 			       enum set_key_cmd cmd);
47261c4fa72SFelix Fietkau void mt7615_mac_reset_work(struct work_struct *work);
47304b8e659SRyder Lee 
474b899150eSLorenzo Bianconi int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq);
475e90354e0SLorenzo Bianconi int mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
476e90354e0SLorenzo Bianconi 			int len, bool wait_resp);
477ac3ef85cSFelix Fietkau int mt7615_mcu_set_dbdc(struct mt7615_dev *dev);
47804b8e659SRyder Lee int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
479b0b5426eSFelix Fietkau int mt7615_mcu_set_mac_enable(struct mt7615_dev *dev, int band, bool enable);
480fdd2e570SFelix Fietkau int mt7615_mcu_set_rts_thresh(struct mt7615_phy *phy, u32 val);
4810e6a29e4SLorenzo Bianconi int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
48204b8e659SRyder Lee void mt7615_mcu_exit(struct mt7615_dev *dev);
48363f09b6bSLorenzo Bianconi void mt7615_mcu_fill_msg(struct mt7615_dev *dev, struct sk_buff *skb,
48463f09b6bSLorenzo Bianconi 			 int cmd, int *wait_seq);
485bf18fcdcSLorenzo Bianconi int mt7615_mcu_set_channel_domain(struct mt7615_phy *phy);
486fcdfc29eSLorenzo Bianconi int mt7615_mcu_hw_scan(struct mt7615_phy *phy, struct ieee80211_vif *vif,
487fcdfc29eSLorenzo Bianconi 		       struct ieee80211_scan_request *scan_req);
488fcdfc29eSLorenzo Bianconi int mt7615_mcu_cancel_hw_scan(struct mt7615_phy *phy,
489fcdfc29eSLorenzo Bianconi 			      struct ieee80211_vif *vif);
49020305f98SLorenzo Bianconi int mt7615_mcu_sched_scan_req(struct mt7615_phy *phy,
49120305f98SLorenzo Bianconi 			      struct ieee80211_vif *vif,
49220305f98SLorenzo Bianconi 			      struct cfg80211_sched_scan_request *sreq);
49320305f98SLorenzo Bianconi int mt7615_mcu_sched_scan_enable(struct mt7615_phy *phy,
49420305f98SLorenzo Bianconi 				 struct ieee80211_vif *vif,
49520305f98SLorenzo Bianconi 				 bool enable);
49604b8e659SRyder Lee 
49704b8e659SRyder Lee int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
49804b8e659SRyder Lee 			  enum mt76_txq_id qid, struct mt76_wcid *wcid,
49904b8e659SRyder Lee 			  struct ieee80211_sta *sta,
50004b8e659SRyder Lee 			  struct mt76_tx_info *tx_info);
50104b8e659SRyder Lee 
50204b8e659SRyder Lee void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
50304b8e659SRyder Lee 			    struct mt76_queue_entry *e);
50404b8e659SRyder Lee 
50504b8e659SRyder Lee void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
50604b8e659SRyder Lee 			 struct sk_buff *skb);
50704b8e659SRyder Lee void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
5083e384828SFelix Fietkau int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
50904b8e659SRyder Lee 		       struct ieee80211_sta *sta);
5103e384828SFelix Fietkau void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
51104b8e659SRyder Lee 			   struct ieee80211_sta *sta);
51204b8e659SRyder Lee void mt7615_mac_work(struct work_struct *work);
51304b8e659SRyder Lee void mt7615_txp_skb_unmap(struct mt76_dev *dev,
51404b8e659SRyder Lee 			  struct mt76_txwi_cache *txwi);
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);
52015d9a5d7SFelix Fietkau int mt7615_mcu_set_sku_en(struct mt7615_phy *phy, bool enable);
521ad380ad1SFelix Fietkau int mt7615_mcu_apply_rx_dcoc(struct mt7615_phy *phy);
522371a59d1SFelix Fietkau int mt7615_mcu_apply_tx_dpd(struct mt7615_phy *phy);
5237f8ebafeSLorenzo Bianconi void m7615_mcu_set_ps_iter(void *priv, u8 *mac, struct ieee80211_vif *vif);
5245dabdf71SFelix Fietkau int mt7615_dfs_init_radar_detector(struct mt7615_phy *phy);
52504b8e659SRyder Lee 
52670911d96SLorenzo Bianconi int mt7615_init_debugfs(struct mt7615_dev *dev);
527eb99cc95SLorenzo Bianconi int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq);
528eb99cc95SLorenzo Bianconi 
5298915c3ceSLorenzo Bianconi int __mt7663_load_firmware(struct mt7615_dev *dev);
53070911d96SLorenzo Bianconi 
531eb99cc95SLorenzo Bianconi /* usb */
532eb99cc95SLorenzo Bianconi void mt7663u_wtbl_work(struct work_struct *work);
533eb99cc95SLorenzo Bianconi int mt7663u_mcu_init(struct mt7615_dev *dev);
534eb99cc95SLorenzo Bianconi int mt7663u_register_device(struct mt7615_dev *dev);
535eb99cc95SLorenzo Bianconi 
53604b8e659SRyder Lee #endif
537