xref: /openbmc/linux/drivers/net/wireless/mediatek/mt76/mt7603/mt7603.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1c8846e10SFelix Fietkau /* SPDX-License-Identifier: ISC */
2c8846e10SFelix Fietkau 
3c8846e10SFelix Fietkau #ifndef __MT7603_H
4c8846e10SFelix Fietkau #define __MT7603_H
5c8846e10SFelix Fietkau 
6c8846e10SFelix Fietkau #include <linux/interrupt.h>
7c8846e10SFelix Fietkau #include <linux/ktime.h>
8c8846e10SFelix Fietkau #include "../mt76.h"
9c8846e10SFelix Fietkau #include "regs.h"
10c8846e10SFelix Fietkau 
11c8846e10SFelix Fietkau #define MT7603_MAX_INTERFACES	4
12c8846e10SFelix Fietkau #define MT7603_WTBL_SIZE	128
13c8846e10SFelix Fietkau #define MT7603_WTBL_RESERVED	(MT7603_WTBL_SIZE - 1)
14c8846e10SFelix Fietkau #define MT7603_WTBL_STA		(MT7603_WTBL_RESERVED - MT7603_MAX_INTERFACES)
15c8846e10SFelix Fietkau 
16c8846e10SFelix Fietkau #define MT7603_RATE_RETRY	2
17c8846e10SFelix Fietkau 
18e970e665SFelix Fietkau #define MT7603_MCU_RX_RING_SIZE	64
19c8846e10SFelix Fietkau #define MT7603_RX_RING_SIZE     128
2021fd4bb7SFelix Fietkau #define MT7603_TX_RING_SIZE	256
2121fd4bb7SFelix Fietkau #define MT7603_PSD_RING_SIZE	128
22c8846e10SFelix Fietkau 
23c8846e10SFelix Fietkau #define MT7603_FIRMWARE_E1	"mt7603_e1.bin"
24c8846e10SFelix Fietkau #define MT7603_FIRMWARE_E2	"mt7603_e2.bin"
25c8846e10SFelix Fietkau #define MT7628_FIRMWARE_E1	"mt7628_e1.bin"
26c8846e10SFelix Fietkau #define MT7628_FIRMWARE_E2	"mt7628_e2.bin"
27c8846e10SFelix Fietkau 
28c8846e10SFelix Fietkau #define MT7603_EEPROM_SIZE	1024
29c8846e10SFelix Fietkau 
30c8846e10SFelix Fietkau #define MT_AGG_SIZE_LIMIT(_n)	(((_n) + 1) * 4)
31c8846e10SFelix Fietkau 
32c8846e10SFelix Fietkau #define MT7603_PRE_TBTT_TIME	5000 /* ms */
33c8846e10SFelix Fietkau 
34c8846e10SFelix Fietkau #define MT7603_WATCHDOG_TIME	100 /* ms */
35c8846e10SFelix Fietkau #define MT7603_WATCHDOG_TIMEOUT	10 /* number of checks */
36c8846e10SFelix Fietkau 
37c8846e10SFelix Fietkau #define MT7603_EDCCA_BLOCK_TH	10
38c8846e10SFelix Fietkau 
39c8846e10SFelix Fietkau #define MT7603_CFEND_RATE_DEFAULT	0x69 /* chip default (24M) */
40c8846e10SFelix Fietkau #define MT7603_CFEND_RATE_11B		0x03 /* 11B LP, 11M */
41c8846e10SFelix Fietkau 
42c8846e10SFelix Fietkau struct mt7603_vif;
43c8846e10SFelix Fietkau struct mt7603_sta;
44c8846e10SFelix Fietkau 
45c8846e10SFelix Fietkau enum {
46c8846e10SFelix Fietkau 	MT7603_REV_E1 = 0x00,
47c8846e10SFelix Fietkau 	MT7603_REV_E2 = 0x10,
48c8846e10SFelix Fietkau 	MT7628_REV_E1 = 0x8a00,
49c8846e10SFelix Fietkau };
50c8846e10SFelix Fietkau 
51c8846e10SFelix Fietkau enum mt7603_bw {
52c8846e10SFelix Fietkau 	MT_BW_20,
53c8846e10SFelix Fietkau 	MT_BW_40,
54c8846e10SFelix Fietkau 	MT_BW_80,
55c8846e10SFelix Fietkau };
56c8846e10SFelix Fietkau 
57c5211e99SFelix Fietkau struct mt7603_rate_set {
58c5211e99SFelix Fietkau 	struct ieee80211_tx_rate probe_rate;
59c5211e99SFelix Fietkau 	struct ieee80211_tx_rate rates[4];
60c5211e99SFelix Fietkau };
61c5211e99SFelix Fietkau 
62c8846e10SFelix Fietkau struct mt7603_sta {
63c8846e10SFelix Fietkau 	struct mt76_wcid wcid; /* must be first */
64c8846e10SFelix Fietkau 
65c8846e10SFelix Fietkau 	struct mt7603_vif *vif;
66c8846e10SFelix Fietkau 
67ea565833SFelix Fietkau 	u32 tx_airtime_ac[4];
68ea565833SFelix Fietkau 
69c8846e10SFelix Fietkau 	struct sk_buff_head psq;
70c8846e10SFelix Fietkau 
71c5211e99SFelix Fietkau 	struct ieee80211_tx_rate rates[4];
72c5211e99SFelix Fietkau 
73c5211e99SFelix Fietkau 	struct mt7603_rate_set rateset[2];
74c5211e99SFelix Fietkau 	u32 rate_set_tsf;
75c5211e99SFelix Fietkau 
76c8846e10SFelix Fietkau 	u8 rate_count;
77c8846e10SFelix Fietkau 	u8 n_rates;
78c8846e10SFelix Fietkau 
79c8846e10SFelix Fietkau 	u8 rate_probe;
80c8846e10SFelix Fietkau 	u8 smps;
81c8846e10SFelix Fietkau 
82c8846e10SFelix Fietkau 	u8 ps;
83c8846e10SFelix Fietkau };
84c8846e10SFelix Fietkau 
85c8846e10SFelix Fietkau struct mt7603_vif {
86c8846e10SFelix Fietkau 	struct mt7603_sta sta; /* must be first */
87c8846e10SFelix Fietkau 
88c8846e10SFelix Fietkau 	u8 idx;
89c8846e10SFelix Fietkau };
90c8846e10SFelix Fietkau 
91c8846e10SFelix Fietkau enum mt7603_reset_cause {
92c8846e10SFelix Fietkau 	RESET_CAUSE_TX_HANG,
93c8846e10SFelix Fietkau 	RESET_CAUSE_TX_BUSY,
94c8846e10SFelix Fietkau 	RESET_CAUSE_RX_BUSY,
95c8846e10SFelix Fietkau 	RESET_CAUSE_BEACON_STUCK,
96c8846e10SFelix Fietkau 	RESET_CAUSE_RX_PSE_BUSY,
97c8846e10SFelix Fietkau 	RESET_CAUSE_MCU_HANG,
98c8846e10SFelix Fietkau 	RESET_CAUSE_RESET_FAILED,
99c8846e10SFelix Fietkau 	__RESET_CAUSE_MAX
100c8846e10SFelix Fietkau };
101c8846e10SFelix Fietkau 
102c8846e10SFelix Fietkau struct mt7603_dev {
103ac24dd35SFelix Fietkau 	union { /* must be first */
104ac24dd35SFelix Fietkau 		struct mt76_dev mt76;
105ac24dd35SFelix Fietkau 		struct mt76_phy mphy;
106ac24dd35SFelix Fietkau 	};
107c8846e10SFelix Fietkau 
108c8846e10SFelix Fietkau 	const struct mt76_bus_ops *bus_ops;
109c8846e10SFelix Fietkau 
110c8846e10SFelix Fietkau 	u32 rxfilter;
111c8846e10SFelix Fietkau 
112c8846e10SFelix Fietkau 	struct mt7603_sta global_sta;
113c8846e10SFelix Fietkau 
114c8846e10SFelix Fietkau 	u32 agc0, agc3;
115c8846e10SFelix Fietkau 	u32 false_cca_ofdm, false_cca_cck;
116c8846e10SFelix Fietkau 	unsigned long last_cca_adj;
117c8846e10SFelix Fietkau 
11830684481SFelix Fietkau 	u32 ampdu_ref;
1190fda6d7bSRyder Lee 	u32 rx_ampdu_ts;
120c8846e10SFelix Fietkau 	u8 rssi_offset[3];
121c8846e10SFelix Fietkau 
122c8846e10SFelix Fietkau 	u8 slottime;
123c8846e10SFelix Fietkau 	s16 coverage_class;
124c8846e10SFelix Fietkau 
125c8846e10SFelix Fietkau 	s8 tx_power_limit;
126c8846e10SFelix Fietkau 
127c8846e10SFelix Fietkau 	ktime_t ed_time;
128c8846e10SFelix Fietkau 
129c8846e10SFelix Fietkau 	spinlock_t ps_lock;
130c8846e10SFelix Fietkau 
131c8846e10SFelix Fietkau 	u8 mcu_running;
132c8846e10SFelix Fietkau 
133984d8854SLorenzo Bianconi 	u8 ed_monitor_enabled;
134984d8854SLorenzo Bianconi 	u8 ed_monitor;
135c8846e10SFelix Fietkau 	s8 ed_trigger;
136c8846e10SFelix Fietkau 	u8 ed_strict_mode;
137c8846e10SFelix Fietkau 	u8 ed_strong_signal;
138c8846e10SFelix Fietkau 
139e9415009SFelix Fietkau 	bool dynamic_sensitivity;
140c8846e10SFelix Fietkau 	s8 sensitivity;
141633348f2SFelix Fietkau 	u8 sensitivity_limit;
142c8846e10SFelix Fietkau 
143c8846e10SFelix Fietkau 	u8 beacon_check;
144c8846e10SFelix Fietkau 	u8 tx_hang_check;
145c8846e10SFelix Fietkau 	u8 tx_dma_check;
146c8846e10SFelix Fietkau 	u8 rx_dma_check;
147c8846e10SFelix Fietkau 	u8 rx_pse_check;
148c8846e10SFelix Fietkau 	u8 mcu_hang;
149c8846e10SFelix Fietkau 
150c8846e10SFelix Fietkau 	enum mt7603_reset_cause cur_reset_cause;
151c8846e10SFelix Fietkau 
152c8846e10SFelix Fietkau 	u16 tx_dma_idx[4];
153c8846e10SFelix Fietkau 	u16 rx_dma_idx;
154c8846e10SFelix Fietkau 
155c8846e10SFelix Fietkau 	u32 reset_test;
156c8846e10SFelix Fietkau 
157c8846e10SFelix Fietkau 	unsigned int reset_cause[__RESET_CAUSE_MAX];
158c8846e10SFelix Fietkau };
159c8846e10SFelix Fietkau 
160c8846e10SFelix Fietkau extern const struct mt76_driver_ops mt7603_drv_ops;
161c8846e10SFelix Fietkau extern const struct ieee80211_ops mt7603_ops;
162c8846e10SFelix Fietkau extern struct pci_driver mt7603_pci_driver;
163c8846e10SFelix Fietkau extern struct platform_driver mt76_wmac_driver;
164c8846e10SFelix Fietkau 
is_mt7603(struct mt7603_dev * dev)165c8846e10SFelix Fietkau static inline bool is_mt7603(struct mt7603_dev *dev)
166c8846e10SFelix Fietkau {
167c8846e10SFelix Fietkau 	return mt76xx_chip(dev) == 0x7603;
168c8846e10SFelix Fietkau }
169c8846e10SFelix Fietkau 
is_mt7628(struct mt7603_dev * dev)170c8846e10SFelix Fietkau static inline bool is_mt7628(struct mt7603_dev *dev)
171c8846e10SFelix Fietkau {
172c8846e10SFelix Fietkau 	return mt76xx_chip(dev) == 0x7628;
173c8846e10SFelix Fietkau }
174c8846e10SFelix Fietkau 
175c8846e10SFelix Fietkau /* need offset to prevent conflict with ampdu_ack_len */
176c8846e10SFelix Fietkau #define MT_RATE_DRIVER_DATA_OFFSET	4
177c8846e10SFelix Fietkau 
178c8846e10SFelix Fietkau u32 mt7603_reg_map(struct mt7603_dev *dev, u32 addr);
179c8846e10SFelix Fietkau 
180c8846e10SFelix Fietkau irqreturn_t mt7603_irq_handler(int irq, void *dev_instance);
181c8846e10SFelix Fietkau 
182c8846e10SFelix Fietkau int mt7603_register_device(struct mt7603_dev *dev);
183c8846e10SFelix Fietkau void mt7603_unregister_device(struct mt7603_dev *dev);
184c8846e10SFelix Fietkau int mt7603_eeprom_init(struct mt7603_dev *dev);
185c8846e10SFelix Fietkau int mt7603_dma_init(struct mt7603_dev *dev);
186c8846e10SFelix Fietkau void mt7603_dma_cleanup(struct mt7603_dev *dev);
187cc173875SLorenzo Bianconi int mt7603_mcu_init(struct mt7603_dev *dev);
188c8846e10SFelix Fietkau void mt7603_init_debugfs(struct mt7603_dev *dev);
189c8846e10SFelix Fietkau 
mt7603_irq_enable(struct mt7603_dev * dev,u32 mask)190c8846e10SFelix Fietkau static inline void mt7603_irq_enable(struct mt7603_dev *dev, u32 mask)
191c8846e10SFelix Fietkau {
1929220f695SLorenzo Bianconi 	mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
193c8846e10SFelix Fietkau }
194c8846e10SFelix Fietkau 
mt7603_irq_disable(struct mt7603_dev * dev,u32 mask)195c8846e10SFelix Fietkau static inline void mt7603_irq_disable(struct mt7603_dev *dev, u32 mask)
196c8846e10SFelix Fietkau {
1979220f695SLorenzo Bianconi 	mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
198c8846e10SFelix Fietkau }
199c8846e10SFelix Fietkau 
2005a8d4678SLorenzo Bianconi void mt7603_mac_reset_counters(struct mt7603_dev *dev);
201c8846e10SFelix Fietkau void mt7603_mac_dma_start(struct mt7603_dev *dev);
202c8846e10SFelix Fietkau void mt7603_mac_start(struct mt7603_dev *dev);
203c8846e10SFelix Fietkau void mt7603_mac_stop(struct mt7603_dev *dev);
204c8846e10SFelix Fietkau void mt7603_mac_work(struct work_struct *work);
205c8846e10SFelix Fietkau void mt7603_mac_set_timing(struct mt7603_dev *dev);
206c8846e10SFelix Fietkau void mt7603_beacon_set_timer(struct mt7603_dev *dev, int idx, int intval);
207c8846e10SFelix Fietkau int mt7603_mac_fill_rx(struct mt7603_dev *dev, struct sk_buff *skb);
208c8846e10SFelix Fietkau void mt7603_mac_add_txs(struct mt7603_dev *dev, void *data);
209c8846e10SFelix Fietkau void mt7603_mac_rx_ba_reset(struct mt7603_dev *dev, void *addr, u8 tid);
210aa3cb24bSFelix Fietkau void mt7603_mac_tx_ba_reset(struct mt7603_dev *dev, int wcid, int tid,
211c8846e10SFelix Fietkau 			    int ba_size);
212ea565833SFelix Fietkau void mt7603_mac_sta_poll(struct mt7603_dev *dev);
213c8846e10SFelix Fietkau 
214c8846e10SFelix Fietkau void mt7603_pse_client_reset(struct mt7603_dev *dev);
215c8846e10SFelix Fietkau 
216c8846e10SFelix Fietkau int mt7603_mcu_set_channel(struct mt7603_dev *dev);
217c8846e10SFelix Fietkau int mt7603_mcu_set_eeprom(struct mt7603_dev *dev);
218c8846e10SFelix Fietkau void mt7603_mcu_exit(struct mt7603_dev *dev);
219c8846e10SFelix Fietkau 
220c8846e10SFelix Fietkau void mt7603_wtbl_init(struct mt7603_dev *dev, int idx, int vif,
221c8846e10SFelix Fietkau 		      const u8 *mac_addr);
222c8846e10SFelix Fietkau void mt7603_wtbl_clear(struct mt7603_dev *dev, int idx);
223c8846e10SFelix Fietkau void mt7603_wtbl_update_cap(struct mt7603_dev *dev, struct ieee80211_sta *sta);
224c8846e10SFelix Fietkau void mt7603_wtbl_set_rates(struct mt7603_dev *dev, struct mt7603_sta *sta,
225c8846e10SFelix Fietkau 			   struct ieee80211_tx_rate *probe_rate,
226c8846e10SFelix Fietkau 			   struct ieee80211_tx_rate *rates);
227c8846e10SFelix Fietkau int mt7603_wtbl_set_key(struct mt7603_dev *dev, int wcid,
228c8846e10SFelix Fietkau 			struct ieee80211_key_conf *key);
229c8846e10SFelix Fietkau void mt7603_wtbl_set_ps(struct mt7603_dev *dev, struct mt7603_sta *sta,
230c8846e10SFelix Fietkau 			bool enabled);
231c8846e10SFelix Fietkau void mt7603_wtbl_set_smps(struct mt7603_dev *dev, struct mt7603_sta *sta,
232c8846e10SFelix Fietkau 			  bool enabled);
233*fe0ea395SFelix Fietkau void mt7603_filter_tx(struct mt7603_dev *dev, int mac_idx, int idx, bool abort);
234c8846e10SFelix Fietkau 
235c8846e10SFelix Fietkau int mt7603_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
236cfaae9e6SLorenzo Bianconi 			  enum mt76_txq_id qid, struct mt76_wcid *wcid,
237cfaae9e6SLorenzo Bianconi 			  struct ieee80211_sta *sta,
238b5903c47SLorenzo Bianconi 			  struct mt76_tx_info *tx_info);
239c8846e10SFelix Fietkau 
240d80e52c7SFelix Fietkau void mt7603_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e);
241c8846e10SFelix Fietkau 
242c8846e10SFelix Fietkau void mt7603_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
243c3137942SSujuan Chen 			 struct sk_buff *skb, u32 *info);
244c8846e10SFelix Fietkau void mt7603_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
245c8846e10SFelix Fietkau void mt7603_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
246c8846e10SFelix Fietkau int mt7603_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
247c8846e10SFelix Fietkau 		   struct ieee80211_sta *sta);
248c8846e10SFelix Fietkau void mt7603_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
249c8846e10SFelix Fietkau 		      struct ieee80211_sta *sta);
250c8846e10SFelix Fietkau void mt7603_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
251c8846e10SFelix Fietkau 		       struct ieee80211_sta *sta);
252c8846e10SFelix Fietkau 
2535ee3e780SAllen Pais void mt7603_pre_tbtt_tasklet(struct tasklet_struct *t);
254c8846e10SFelix Fietkau 
255c560b137SRyder Lee void mt7603_update_channel(struct mt76_phy *mphy);
256c8846e10SFelix Fietkau 
257c8846e10SFelix Fietkau void mt7603_edcca_set_strict(struct mt7603_dev *dev, bool val);
258c8846e10SFelix Fietkau void mt7603_cca_stats_reset(struct mt7603_dev *dev);
259c8846e10SFelix Fietkau 
260984d8854SLorenzo Bianconi void mt7603_init_edcca(struct mt7603_dev *dev);
261c8846e10SFelix Fietkau #endif
262