1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2019 MediaTek Inc. */
7 #include <linux/interrupt.h>
8 #include <linux/ktime.h>
9 #include <linux/regmap.h>
13 #define MT7615_MAX_INTERFACES 4
14 #define MT7615_MAX_WMM_SETS 4
15 #define MT7615_WTBL_SIZE 128
16 #define MT7615_WTBL_RESERVED (MT7615_WTBL_SIZE - 1)
17 #define MT7615_WTBL_STA (MT7615_WTBL_RESERVED - \
18 MT7615_MAX_INTERFACES)
20 #define MT7615_WATCHDOG_TIME (HZ / 10)
21 #define MT7615_HW_SCAN_TIMEOUT (HZ / 10)
22 #define MT7615_RESET_TIMEOUT (30 * HZ)
23 #define MT7615_RATE_RETRY 2
25 #define MT7615_TX_RING_SIZE 1024
26 #define MT7615_TX_MGMT_RING_SIZE 128
27 #define MT7615_TX_MCU_RING_SIZE 128
28 #define MT7615_TX_FWDL_RING_SIZE 128
30 #define MT7615_RX_RING_SIZE 1024
31 #define MT7615_RX_MCU_RING_SIZE 512
33 #define MT7615_FIRMWARE_CR4 "mediatek/mt7615_cr4.bin"
34 #define MT7615_FIRMWARE_N9 "mediatek/mt7615_n9.bin"
35 #define MT7615_ROM_PATCH "mediatek/mt7615_rom_patch.bin"
37 #define MT7622_FIRMWARE_N9 "mediatek/mt7622_n9.bin"
38 #define MT7622_ROM_PATCH "mediatek/mt7622_rom_patch.bin"
40 #define MT7615_FIRMWARE_V1 1
41 #define MT7615_FIRMWARE_V2 2
42 #define MT7615_FIRMWARE_V3 3
44 #define MT7663_ROM_PATCH "mediatek/mt7663pr2h.bin"
45 #define MT7663_FIRMWARE_N9 "mediatek/mt7663_n9_v3.bin"
47 #define MT7615_EEPROM_SIZE 1024
48 #define MT7615_TOKEN_SIZE 4096
50 #define MT_FRAC_SCALE 12
51 #define MT_FRAC(val, div) (((val) << MT_FRAC_SCALE) / (div))
53 #define MT_CHFREQ_VALID BIT(7)
54 #define MT_CHFREQ_DBDC_IDX BIT(6)
55 #define MT_CHFREQ_SEQ GENMASK(5, 0)
57 #define MT7615_BAR_RATE_DEFAULT 0x4b /* OFDM 6M */
58 #define MT7615_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
59 #define MT7615_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
61 #define MT7615_SCAN_IE_LEN 600
62 #define MT7615_MAX_SCHED_SCAN_INTERVAL 10
63 #define MT7615_MAX_SCHED_SCAN_SSID 10
64 #define MT7615_MAX_SCAN_MATCH 16
68 struct mt7615_dfs_pulse;
69 struct mt7615_dfs_pattern;
70 enum mt7615_cipher_type;
72 enum mt7615_hw_txq_id {
79 enum mt7622_hw_txq_id {
83 MT7622_TXQ_FWDL = MT7615_TXQ_FWDL,
89 struct mt7615_rate_set {
90 struct ieee80211_tx_rate probe_rate;
91 struct ieee80211_tx_rate rates[4];
94 struct mt7615_rate_desc {
102 enum mt7615_wtbl_desc_type {
103 MT7615_WTBL_RATE_DESC,
107 struct mt7615_key_desc {
108 enum set_key_cmd cmd;
115 struct mt7615_wtbl_desc {
116 struct list_head node;
118 enum mt7615_wtbl_desc_type type;
119 struct mt7615_sta *sta;
122 struct mt7615_rate_desc rate;
123 struct mt7615_key_desc key;
128 struct mt76_wcid wcid; /* must be first */
130 struct mt7615_vif *vif;
132 struct list_head poll_list;
135 struct ieee80211_tx_rate rates[4];
137 struct mt7615_rate_set rateset[2];
153 struct mt7615_sta sta;
162 unsigned long aggr_per;
166 struct mt76_phy *mt76;
167 struct mt7615_dev *dev;
176 unsigned long last_cca_adj;
177 int false_cca_ofdm, false_cca_cck;
193 struct mib_stats mib;
195 struct sk_buff_head scan_event_list;
196 struct delayed_work scan_work;
199 #define mt7615_mcu_add_tx_ba(dev, ...) (dev)->mcu_ops->add_tx_ba((dev), __VA_ARGS__)
200 #define mt7615_mcu_add_rx_ba(dev, ...) (dev)->mcu_ops->add_rx_ba((dev), __VA_ARGS__)
201 #define mt7615_mcu_sta_add(dev, ...) (dev)->mcu_ops->sta_add((dev), __VA_ARGS__)
202 #define mt7615_mcu_add_dev_info(dev, ...) (dev)->mcu_ops->add_dev_info((dev), __VA_ARGS__)
203 #define mt7615_mcu_add_bss_info(phy, ...) (phy->dev)->mcu_ops->add_bss_info((phy), __VA_ARGS__)
204 #define mt7615_mcu_add_beacon(dev, ...) (dev)->mcu_ops->add_beacon_offload((dev), __VA_ARGS__)
205 #define mt7615_mcu_set_pm(dev, ...) (dev)->mcu_ops->set_pm_state((dev), __VA_ARGS__)
206 struct mt7615_mcu_ops {
207 int (*add_tx_ba)(struct mt7615_dev *dev,
208 struct ieee80211_ampdu_params *params,
210 int (*add_rx_ba)(struct mt7615_dev *dev,
211 struct ieee80211_ampdu_params *params,
213 int (*sta_add)(struct mt7615_dev *dev,
214 struct ieee80211_vif *vif,
215 struct ieee80211_sta *sta, bool enable);
216 int (*add_dev_info)(struct mt7615_dev *dev,
217 struct ieee80211_vif *vif, bool enable);
218 int (*add_bss_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif,
220 int (*add_beacon_offload)(struct mt7615_dev *dev,
221 struct ieee80211_hw *hw,
222 struct ieee80211_vif *vif, bool enable);
223 int (*set_pm_state)(struct mt7615_dev *dev, int band, int state);
227 union { /* must be first */
228 struct mt76_dev mt76;
229 struct mt76_phy mphy;
232 struct mt7615_phy phy;
238 struct ieee80211_ops *ops;
239 const struct mt7615_mcu_ops *mcu_ops;
240 struct regmap *infracfg;
243 struct work_struct mcu_work;
245 struct work_struct reset_work;
246 wait_queue_head_t reset_wait;
249 struct list_head sta_poll_list;
250 spinlock_t sta_poll_lock;
264 spinlock_t token_lock;
276 EXT_BSSID_START = 0x10,
300 enum mt7615_rdd_cmd {
314 static inline struct mt7615_phy *
315 mt7615_hw_phy(struct ieee80211_hw *hw)
317 struct mt76_phy *phy = hw->priv;
322 static inline struct mt7615_dev *
323 mt7615_hw_dev(struct ieee80211_hw *hw)
325 struct mt76_phy *phy = hw->priv;
327 return container_of(phy->dev, struct mt7615_dev, mt76);
330 static inline struct mt7615_phy *
331 mt7615_ext_phy(struct mt7615_dev *dev)
333 struct mt76_phy *phy = dev->mt76.phy2;
341 extern const struct ieee80211_ops mt7615_ops;
342 extern const u32 mt7615e_reg_map[__MT_BASE_MAX];
343 extern const u32 mt7663e_reg_map[__MT_BASE_MAX];
344 extern struct pci_driver mt7615_pci_driver;
345 extern struct platform_driver mt7622_wmac_driver;
347 #ifdef CONFIG_MT7622_WMAC
348 int mt7622_wmac_init(struct mt7615_dev *dev);
350 static inline int mt7622_wmac_init(struct mt7615_dev *dev)
356 int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base,
357 int irq, const u32 *map);
358 u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr);
360 void mt7615_init_device(struct mt7615_dev *dev);
361 int mt7615_register_device(struct mt7615_dev *dev);
362 void mt7615_unregister_device(struct mt7615_dev *dev);
363 int mt7615_register_ext_phy(struct mt7615_dev *dev);
364 void mt7615_unregister_ext_phy(struct mt7615_dev *dev);
365 int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr);
366 int mt7615_eeprom_get_power_index(struct mt7615_dev *dev,
367 struct ieee80211_channel *chan,
369 int mt7615_dma_init(struct mt7615_dev *dev);
370 void mt7615_dma_cleanup(struct mt7615_dev *dev);
371 int mt7615_mcu_init(struct mt7615_dev *dev);
372 bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev);
373 void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
374 struct ieee80211_tx_rate *probe_rate,
375 struct ieee80211_tx_rate *rates);
376 int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
377 int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd);
378 int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
379 const struct ieee80211_tx_queue_params *params);
380 void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb);
381 int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
382 enum mt7615_rdd_cmd cmd, u8 index,
384 int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
385 int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl);
387 static inline bool is_mt7622(struct mt76_dev *dev)
389 if (!IS_ENABLED(CONFIG_MT7622_WMAC))
392 return mt76_chip(dev) == 0x7622;
395 static inline bool is_mt7615(struct mt76_dev *dev)
397 return mt76_chip(dev) == 0x7615;
400 static inline bool is_mt7663(struct mt76_dev *dev)
402 return mt76_chip(dev) == 0x7663;
405 static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask)
407 mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
410 static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
412 mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
415 static inline bool mt7615_firmware_offload(struct mt7615_dev *dev)
417 return dev->fw_ver > MT7615_FIRMWARE_V2;
420 void mt7615_scan_work(struct work_struct *work);
421 void mt7615_update_channel(struct mt76_dev *mdev);
422 bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
423 void mt7615_mac_reset_counters(struct mt7615_dev *dev);
424 void mt7615_mac_cca_stats_reset(struct mt7615_phy *phy);
425 void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable);
426 void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy);
427 void mt7615_mac_sta_poll(struct mt7615_dev *dev);
428 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
429 struct sk_buff *skb, struct mt76_wcid *wcid,
430 struct ieee80211_sta *sta, int pid,
431 struct ieee80211_key_conf *key, bool beacon);
432 void mt7615_mac_set_timing(struct mt7615_phy *phy);
433 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb);
434 void mt7615_mac_add_txs(struct mt7615_dev *dev, void *data);
435 void mt7615_mac_tx_free(struct mt7615_dev *dev, struct sk_buff *skb);
436 int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid,
437 struct ieee80211_key_conf *key,
438 enum set_key_cmd cmd);
439 int mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev,
440 struct mt76_wcid *wcid,
441 enum mt7615_cipher_type cipher,
442 int keyidx, enum set_key_cmd cmd);
443 void mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev,
444 struct mt76_wcid *wcid,
445 enum mt7615_cipher_type cipher,
446 enum set_key_cmd cmd);
447 int mt7615_mac_wtbl_update_key(struct mt7615_dev *dev,
448 struct mt76_wcid *wcid,
450 enum mt7615_cipher_type cipher,
451 enum set_key_cmd cmd);
452 void mt7615_mac_reset_work(struct work_struct *work);
454 int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq);
455 int mt7615_mcu_set_dbdc(struct mt7615_dev *dev);
456 int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
457 int mt7615_mcu_set_mac_enable(struct mt7615_dev *dev, int band, bool enable);
458 int mt7615_mcu_set_rts_thresh(struct mt7615_phy *phy, u32 val);
459 int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
460 void mt7615_mcu_exit(struct mt7615_dev *dev);
461 void mt7615_mcu_fill_msg(struct mt7615_dev *dev, struct sk_buff *skb,
462 int cmd, int *wait_seq);
463 int mt7615_mcu_set_channel_domain(struct mt7615_phy *phy);
464 int mt7615_mcu_hw_scan(struct mt7615_phy *phy, struct ieee80211_vif *vif,
465 struct ieee80211_scan_request *scan_req);
466 int mt7615_mcu_cancel_hw_scan(struct mt7615_phy *phy,
467 struct ieee80211_vif *vif);
468 int mt7615_mcu_sched_scan_req(struct mt7615_phy *phy,
469 struct ieee80211_vif *vif,
470 struct cfg80211_sched_scan_request *sreq);
471 int mt7615_mcu_sched_scan_enable(struct mt7615_phy *phy,
472 struct ieee80211_vif *vif,
475 int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
476 enum mt76_txq_id qid, struct mt76_wcid *wcid,
477 struct ieee80211_sta *sta,
478 struct mt76_tx_info *tx_info);
480 void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
481 struct mt76_queue_entry *e);
483 void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
484 struct sk_buff *skb);
485 void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
486 int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
487 struct ieee80211_sta *sta);
488 void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
489 struct ieee80211_sta *sta);
490 void mt7615_mac_work(struct work_struct *work);
491 void mt7615_txp_skb_unmap(struct mt76_dev *dev,
492 struct mt76_txwi_cache *txwi);
493 int mt7615_mcu_set_fcc5_lpn(struct mt7615_dev *dev, int val);
494 int mt7615_mcu_set_pulse_th(struct mt7615_dev *dev,
495 const struct mt7615_dfs_pulse *pulse);
496 int mt7615_mcu_set_radar_th(struct mt7615_dev *dev, int index,
497 const struct mt7615_dfs_pattern *pattern);
498 int mt7615_mcu_set_sku_en(struct mt7615_phy *phy, bool enable);
499 int mt7615_mcu_apply_rx_dcoc(struct mt7615_phy *phy);
500 int mt7615_mcu_apply_tx_dpd(struct mt7615_phy *phy);
501 int mt7615_dfs_init_radar_detector(struct mt7615_phy *phy);
503 int mt7615_init_debugfs(struct mt7615_dev *dev);
504 int __mt7663_load_firmware(struct mt7615_dev *dev);