1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2019 MediaTek Inc. */
7 #include <linux/interrupt.h>
8 #include <linux/ktime.h>
12 #define MT7615_MAX_INTERFACES 4
13 #define MT7615_MAX_WMM_SETS 4
14 #define MT7615_WTBL_SIZE 128
15 #define MT7615_WTBL_RESERVED (MT7615_WTBL_SIZE - 1)
16 #define MT7615_WTBL_STA (MT7615_WTBL_RESERVED - \
17 MT7615_MAX_INTERFACES)
19 #define MT7615_WATCHDOG_TIME (HZ / 10)
20 #define MT7615_RATE_RETRY 2
22 #define MT7615_TX_RING_SIZE 1024
23 #define MT7615_TX_MCU_RING_SIZE 128
24 #define MT7615_TX_FWDL_RING_SIZE 128
26 #define MT7615_RX_RING_SIZE 1024
27 #define MT7615_RX_MCU_RING_SIZE 512
29 #define MT7615_FIRMWARE_CR4 "mediatek/mt7615_cr4.bin"
30 #define MT7615_FIRMWARE_N9 "mediatek/mt7615_n9.bin"
31 #define MT7615_ROM_PATCH "mediatek/mt7615_rom_patch.bin"
33 #define MT7615_EEPROM_SIZE 1024
34 #define MT7615_TOKEN_SIZE 4096
36 #define MT_FRAC_SCALE 12
37 #define MT_FRAC(val, div) (((val) << MT_FRAC_SCALE) / (div))
39 #define MT_CHFREQ_VALID BIT(7)
40 #define MT_CHFREQ_DBDC_IDX BIT(6)
41 #define MT_CHFREQ_SEQ GENMASK(5, 0)
43 #define MT7615_BAR_RATE_DEFAULT 0x4b /* OFDM 6M */
44 #define MT7615_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
45 #define MT7615_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
50 enum mt7615_hw_txq_id {
57 struct mt7615_rate_set {
58 struct ieee80211_tx_rate probe_rate;
59 struct ieee80211_tx_rate rates[4];
63 struct mt76_wcid wcid; /* must be first */
65 struct mt7615_vif *vif;
67 struct list_head poll_list;
70 struct ieee80211_tx_rate rates[4];
72 struct mt7615_rate_set rateset[2];
87 struct mt7615_sta sta;
91 struct mt76_phy *mt76;
92 struct mt7615_dev *dev;
99 unsigned long last_cca_adj;
100 int false_cca_ofdm, false_cca_cck;
118 union { /* must be first */
119 struct mt76_dev mt76;
120 struct mt76_phy mphy;
123 struct mt7615_phy phy;
129 struct work_struct mcu_work;
131 struct list_head sta_poll_list;
132 spinlock_t sta_poll_lock;
145 spinlock_t token_lock;
155 EXT_BSSID_START = 0x10,
179 enum mt7615_rdd_cmd {
193 static inline struct mt7615_phy *
194 mt7615_hw_phy(struct ieee80211_hw *hw)
196 struct mt76_phy *phy = hw->priv;
201 static inline struct mt7615_dev *
202 mt7615_hw_dev(struct ieee80211_hw *hw)
204 struct mt76_phy *phy = hw->priv;
206 return container_of(phy->dev, struct mt7615_dev, mt76);
209 static inline struct mt7615_phy *
210 mt7615_ext_phy(struct mt7615_dev *dev)
212 struct mt76_phy *phy = dev->mt76.phy2;
220 extern const struct ieee80211_ops mt7615_ops;
221 extern struct pci_driver mt7615_pci_driver;
223 u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
225 int mt7615_register_device(struct mt7615_dev *dev);
226 void mt7615_unregister_device(struct mt7615_dev *dev);
227 int mt7615_register_ext_phy(struct mt7615_dev *dev);
228 void mt7615_unregister_ext_phy(struct mt7615_dev *dev);
229 int mt7615_eeprom_init(struct mt7615_dev *dev);
230 int mt7615_eeprom_get_power_index(struct mt7615_dev *dev,
231 struct ieee80211_channel *chan,
233 int mt7615_dma_init(struct mt7615_dev *dev);
234 void mt7615_dma_cleanup(struct mt7615_dev *dev);
235 int mt7615_mcu_init(struct mt7615_dev *dev);
236 bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev);
237 int mt7615_mcu_set_dev_info(struct mt7615_dev *dev,
238 struct ieee80211_vif *vif, bool enable);
239 int mt7615_mcu_set_bss_info(struct mt7615_dev *dev, struct ieee80211_vif *vif,
241 void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
242 struct ieee80211_tx_rate *probe_rate,
243 struct ieee80211_tx_rate *rates);
244 int mt7615_mcu_wtbl_bmc(struct mt7615_dev *dev, struct ieee80211_vif *vif,
246 int mt7615_mcu_add_wtbl(struct mt7615_dev *dev, struct ieee80211_vif *vif,
247 struct ieee80211_sta *sta);
248 int mt7615_mcu_del_wtbl(struct mt7615_dev *dev, struct ieee80211_sta *sta);
249 int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
250 int mt7615_mcu_set_sta_rec_bmc(struct mt7615_dev *dev,
251 struct ieee80211_vif *vif, bool en);
252 int mt7615_mcu_set_sta_rec(struct mt7615_dev *dev, struct ieee80211_vif *vif,
253 struct ieee80211_sta *sta, bool en);
254 int mt7615_mcu_set_bcn(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
256 int mt7615_mcu_set_channel(struct mt7615_phy *phy);
257 int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
258 const struct ieee80211_tx_queue_params *params);
259 int mt7615_mcu_set_tx_ba(struct mt7615_dev *dev,
260 struct ieee80211_ampdu_params *params,
262 int mt7615_mcu_set_rx_ba(struct mt7615_dev *dev,
263 struct ieee80211_ampdu_params *params,
265 int mt7615_mcu_set_ht_cap(struct mt7615_dev *dev, struct ieee80211_vif *vif,
266 struct ieee80211_sta *sta);
267 void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb);
268 int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
269 enum mt7615_rdd_cmd cmd, u8 index,
271 int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
273 static inline bool is_mt7622(struct mt76_dev *dev)
275 return mt76_chip(dev) == 0x7622;
278 static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask)
280 mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
283 static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
285 mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
288 void mt7615_update_channel(struct mt76_dev *mdev);
289 bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
290 void mt7615_mac_reset_counters(struct mt7615_dev *dev);
291 void mt7615_mac_cca_stats_reset(struct mt7615_phy *phy);
292 void mt7615_mac_set_scs(struct mt7615_dev *dev, bool enable);
293 void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy);
294 void mt7615_mac_sta_poll(struct mt7615_dev *dev);
295 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
296 struct sk_buff *skb, struct mt76_wcid *wcid,
297 struct ieee80211_sta *sta, int pid,
298 struct ieee80211_key_conf *key);
299 void mt7615_mac_set_timing(struct mt7615_phy *phy);
300 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb);
301 void mt7615_mac_add_txs(struct mt7615_dev *dev, void *data);
302 void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb);
303 int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
304 struct ieee80211_key_conf *key,
305 enum set_key_cmd cmd);
307 int mt7615_mcu_set_dbdc(struct mt7615_dev *dev);
308 int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
309 int mt7615_mcu_set_mac_enable(struct mt7615_dev *dev, int band, bool enable);
310 int mt7615_mcu_set_rts_thresh(struct mt7615_phy *phy, u32 val);
311 int mt7615_mcu_ctrl_pm_state(struct mt7615_dev *dev, int band, int enter);
312 int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
313 int mt7615_mcu_set_tx_power(struct mt7615_phy *phy);
314 void mt7615_mcu_exit(struct mt7615_dev *dev);
316 int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
317 enum mt76_txq_id qid, struct mt76_wcid *wcid,
318 struct ieee80211_sta *sta,
319 struct mt76_tx_info *tx_info);
321 void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
322 struct mt76_queue_entry *e);
324 void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
325 struct sk_buff *skb);
326 void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
327 int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
328 struct ieee80211_sta *sta);
329 void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
330 struct ieee80211_sta *sta);
331 void mt7615_mac_work(struct work_struct *work);
332 void mt7615_txp_skb_unmap(struct mt76_dev *dev,
333 struct mt76_txwi_cache *txwi);
334 int mt76_dfs_start_rdd(struct mt7615_dev *dev, bool force);
335 int mt7615_dfs_init_radar_detector(struct mt7615_phy *phy);
337 int mt7615_init_debugfs(struct mt7615_dev *dev);