16c92544dSBjoern A. Zeeb /* SPDX-License-Identifier: ISC */
26c92544dSBjoern A. Zeeb
36c92544dSBjoern A. Zeeb #ifndef __MT7603_H
46c92544dSBjoern A. Zeeb #define __MT7603_H
56c92544dSBjoern A. Zeeb
66c92544dSBjoern A. Zeeb #include <linux/interrupt.h>
76c92544dSBjoern A. Zeeb #include <linux/ktime.h>
86c92544dSBjoern A. Zeeb #include "../mt76.h"
96c92544dSBjoern A. Zeeb #include "regs.h"
106c92544dSBjoern A. Zeeb
116c92544dSBjoern A. Zeeb #define MT7603_MAX_INTERFACES 4
126c92544dSBjoern A. Zeeb #define MT7603_WTBL_SIZE 128
136c92544dSBjoern A. Zeeb #define MT7603_WTBL_RESERVED (MT7603_WTBL_SIZE - 1)
146c92544dSBjoern A. Zeeb #define MT7603_WTBL_STA (MT7603_WTBL_RESERVED - MT7603_MAX_INTERFACES)
156c92544dSBjoern A. Zeeb
166c92544dSBjoern A. Zeeb #define MT7603_RATE_RETRY 2
176c92544dSBjoern A. Zeeb
186c92544dSBjoern A. Zeeb #define MT7603_MCU_RX_RING_SIZE 64
196c92544dSBjoern A. Zeeb #define MT7603_RX_RING_SIZE 128
206c92544dSBjoern A. Zeeb #define MT7603_TX_RING_SIZE 256
216c92544dSBjoern A. Zeeb #define MT7603_PSD_RING_SIZE 128
226c92544dSBjoern A. Zeeb
236c92544dSBjoern A. Zeeb #define MT7603_FIRMWARE_E1 "mt7603_e1.bin"
246c92544dSBjoern A. Zeeb #define MT7603_FIRMWARE_E2 "mt7603_e2.bin"
256c92544dSBjoern A. Zeeb #define MT7628_FIRMWARE_E1 "mt7628_e1.bin"
266c92544dSBjoern A. Zeeb #define MT7628_FIRMWARE_E2 "mt7628_e2.bin"
276c92544dSBjoern A. Zeeb
286c92544dSBjoern A. Zeeb #define MT7603_EEPROM_SIZE 1024
296c92544dSBjoern A. Zeeb
306c92544dSBjoern A. Zeeb #define MT_AGG_SIZE_LIMIT(_n) (((_n) + 1) * 4)
316c92544dSBjoern A. Zeeb
326c92544dSBjoern A. Zeeb #define MT7603_PRE_TBTT_TIME 5000 /* ms */
336c92544dSBjoern A. Zeeb
346c92544dSBjoern A. Zeeb #define MT7603_WATCHDOG_TIME 100 /* ms */
356c92544dSBjoern A. Zeeb #define MT7603_WATCHDOG_TIMEOUT 10 /* number of checks */
366c92544dSBjoern A. Zeeb
376c92544dSBjoern A. Zeeb #define MT7603_EDCCA_BLOCK_TH 10
386c92544dSBjoern A. Zeeb
396c92544dSBjoern A. Zeeb #define MT7603_CFEND_RATE_DEFAULT 0x69 /* chip default (24M) */
406c92544dSBjoern A. Zeeb #define MT7603_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
416c92544dSBjoern A. Zeeb
426c92544dSBjoern A. Zeeb struct mt7603_vif;
436c92544dSBjoern A. Zeeb struct mt7603_sta;
446c92544dSBjoern A. Zeeb
456c92544dSBjoern A. Zeeb enum {
466c92544dSBjoern A. Zeeb MT7603_REV_E1 = 0x00,
476c92544dSBjoern A. Zeeb MT7603_REV_E2 = 0x10,
486c92544dSBjoern A. Zeeb MT7628_REV_E1 = 0x8a00,
496c92544dSBjoern A. Zeeb };
506c92544dSBjoern A. Zeeb
516c92544dSBjoern A. Zeeb enum mt7603_bw {
526c92544dSBjoern A. Zeeb MT_BW_20,
536c92544dSBjoern A. Zeeb MT_BW_40,
546c92544dSBjoern A. Zeeb MT_BW_80,
556c92544dSBjoern A. Zeeb };
566c92544dSBjoern A. Zeeb
576c92544dSBjoern A. Zeeb struct mt7603_rate_set {
586c92544dSBjoern A. Zeeb struct ieee80211_tx_rate probe_rate;
596c92544dSBjoern A. Zeeb struct ieee80211_tx_rate rates[4];
606c92544dSBjoern A. Zeeb };
616c92544dSBjoern A. Zeeb
626c92544dSBjoern A. Zeeb struct mt7603_sta {
636c92544dSBjoern A. Zeeb struct mt76_wcid wcid; /* must be first */
646c92544dSBjoern A. Zeeb
656c92544dSBjoern A. Zeeb struct mt7603_vif *vif;
666c92544dSBjoern A. Zeeb
676c92544dSBjoern A. Zeeb u32 tx_airtime_ac[4];
686c92544dSBjoern A. Zeeb
696c92544dSBjoern A. Zeeb struct sk_buff_head psq;
706c92544dSBjoern A. Zeeb
716c92544dSBjoern A. Zeeb struct ieee80211_tx_rate rates[4];
726c92544dSBjoern A. Zeeb
736c92544dSBjoern A. Zeeb struct mt7603_rate_set rateset[2];
746c92544dSBjoern A. Zeeb u32 rate_set_tsf;
756c92544dSBjoern A. Zeeb
766c92544dSBjoern A. Zeeb u8 rate_count;
776c92544dSBjoern A. Zeeb u8 n_rates;
786c92544dSBjoern A. Zeeb
796c92544dSBjoern A. Zeeb u8 rate_probe;
806c92544dSBjoern A. Zeeb u8 smps;
816c92544dSBjoern A. Zeeb
826c92544dSBjoern A. Zeeb u8 ps;
836c92544dSBjoern A. Zeeb };
846c92544dSBjoern A. Zeeb
856c92544dSBjoern A. Zeeb struct mt7603_vif {
866c92544dSBjoern A. Zeeb struct mt7603_sta sta; /* must be first */
876c92544dSBjoern A. Zeeb
886c92544dSBjoern A. Zeeb u8 idx;
896c92544dSBjoern A. Zeeb };
906c92544dSBjoern A. Zeeb
916c92544dSBjoern A. Zeeb enum mt7603_reset_cause {
926c92544dSBjoern A. Zeeb RESET_CAUSE_TX_HANG,
936c92544dSBjoern A. Zeeb RESET_CAUSE_TX_BUSY,
946c92544dSBjoern A. Zeeb RESET_CAUSE_RX_BUSY,
956c92544dSBjoern A. Zeeb RESET_CAUSE_BEACON_STUCK,
966c92544dSBjoern A. Zeeb RESET_CAUSE_RX_PSE_BUSY,
976c92544dSBjoern A. Zeeb RESET_CAUSE_MCU_HANG,
986c92544dSBjoern A. Zeeb RESET_CAUSE_RESET_FAILED,
996c92544dSBjoern A. Zeeb __RESET_CAUSE_MAX
1006c92544dSBjoern A. Zeeb };
1016c92544dSBjoern A. Zeeb
1026c92544dSBjoern A. Zeeb struct mt7603_dev {
1036c92544dSBjoern A. Zeeb union { /* must be first */
1046c92544dSBjoern A. Zeeb struct mt76_dev mt76;
1056c92544dSBjoern A. Zeeb struct mt76_phy mphy;
1066c92544dSBjoern A. Zeeb };
1076c92544dSBjoern A. Zeeb
1086c92544dSBjoern A. Zeeb const struct mt76_bus_ops *bus_ops;
1096c92544dSBjoern A. Zeeb
1106c92544dSBjoern A. Zeeb u32 rxfilter;
1116c92544dSBjoern A. Zeeb
1126c92544dSBjoern A. Zeeb struct mt7603_sta global_sta;
1136c92544dSBjoern A. Zeeb
1146c92544dSBjoern A. Zeeb u32 agc0, agc3;
1156c92544dSBjoern A. Zeeb u32 false_cca_ofdm, false_cca_cck;
1166c92544dSBjoern A. Zeeb unsigned long last_cca_adj;
1176c92544dSBjoern A. Zeeb
1186c92544dSBjoern A. Zeeb u32 ampdu_ref;
1196c92544dSBjoern A. Zeeb u32 rx_ampdu_ts;
1206c92544dSBjoern A. Zeeb u8 rssi_offset[3];
1216c92544dSBjoern A. Zeeb
1226c92544dSBjoern A. Zeeb u8 slottime;
1236c92544dSBjoern A. Zeeb s16 coverage_class;
1246c92544dSBjoern A. Zeeb
1256c92544dSBjoern A. Zeeb s8 tx_power_limit;
1266c92544dSBjoern A. Zeeb
1276c92544dSBjoern A. Zeeb ktime_t ed_time;
1286c92544dSBjoern A. Zeeb
1296c92544dSBjoern A. Zeeb spinlock_t ps_lock;
1306c92544dSBjoern A. Zeeb
1316c92544dSBjoern A. Zeeb u8 mcu_running;
1326c92544dSBjoern A. Zeeb
1336c92544dSBjoern A. Zeeb u8 ed_monitor_enabled;
1346c92544dSBjoern A. Zeeb u8 ed_monitor;
1356c92544dSBjoern A. Zeeb s8 ed_trigger;
1366c92544dSBjoern A. Zeeb u8 ed_strict_mode;
1376c92544dSBjoern A. Zeeb u8 ed_strong_signal;
1386c92544dSBjoern A. Zeeb
1396c92544dSBjoern A. Zeeb bool dynamic_sensitivity;
1406c92544dSBjoern A. Zeeb s8 sensitivity;
1416c92544dSBjoern A. Zeeb u8 sensitivity_limit;
1426c92544dSBjoern A. Zeeb
1436c92544dSBjoern A. Zeeb u8 beacon_check;
1446c92544dSBjoern A. Zeeb u8 tx_hang_check;
1456c92544dSBjoern A. Zeeb u8 tx_dma_check;
1466c92544dSBjoern A. Zeeb u8 rx_dma_check;
1476c92544dSBjoern A. Zeeb u8 rx_pse_check;
1486c92544dSBjoern A. Zeeb u8 mcu_hang;
1496c92544dSBjoern A. Zeeb
1506c92544dSBjoern A. Zeeb enum mt7603_reset_cause cur_reset_cause;
1516c92544dSBjoern A. Zeeb
1526c92544dSBjoern A. Zeeb u16 tx_dma_idx[4];
1536c92544dSBjoern A. Zeeb u16 rx_dma_idx;
1546c92544dSBjoern A. Zeeb
1556c92544dSBjoern A. Zeeb u32 reset_test;
1566c92544dSBjoern A. Zeeb
1576c92544dSBjoern A. Zeeb unsigned int reset_cause[__RESET_CAUSE_MAX];
1586c92544dSBjoern A. Zeeb };
1596c92544dSBjoern A. Zeeb
1606c92544dSBjoern A. Zeeb extern const struct mt76_driver_ops mt7603_drv_ops;
1616c92544dSBjoern A. Zeeb extern const struct ieee80211_ops mt7603_ops;
1626c92544dSBjoern A. Zeeb extern struct pci_driver mt7603_pci_driver;
1636c92544dSBjoern A. Zeeb extern struct platform_driver mt76_wmac_driver;
1646c92544dSBjoern A. Zeeb
is_mt7603(struct mt7603_dev * dev)1656c92544dSBjoern A. Zeeb static inline bool is_mt7603(struct mt7603_dev *dev)
1666c92544dSBjoern A. Zeeb {
1676c92544dSBjoern A. Zeeb return mt76xx_chip(dev) == 0x7603;
1686c92544dSBjoern A. Zeeb }
1696c92544dSBjoern A. Zeeb
is_mt7628(struct mt7603_dev * dev)1706c92544dSBjoern A. Zeeb static inline bool is_mt7628(struct mt7603_dev *dev)
1716c92544dSBjoern A. Zeeb {
1726c92544dSBjoern A. Zeeb return mt76xx_chip(dev) == 0x7628;
1736c92544dSBjoern A. Zeeb }
1746c92544dSBjoern A. Zeeb
1756c92544dSBjoern A. Zeeb /* need offset to prevent conflict with ampdu_ack_len */
1766c92544dSBjoern A. Zeeb #define MT_RATE_DRIVER_DATA_OFFSET 4
1776c92544dSBjoern A. Zeeb
1786c92544dSBjoern A. Zeeb u32 mt7603_reg_map(struct mt7603_dev *dev, u32 addr);
1796c92544dSBjoern A. Zeeb
1806c92544dSBjoern A. Zeeb irqreturn_t mt7603_irq_handler(int irq, void *dev_instance);
1816c92544dSBjoern A. Zeeb
1826c92544dSBjoern A. Zeeb int mt7603_register_device(struct mt7603_dev *dev);
1836c92544dSBjoern A. Zeeb void mt7603_unregister_device(struct mt7603_dev *dev);
1846c92544dSBjoern A. Zeeb int mt7603_eeprom_init(struct mt7603_dev *dev);
1856c92544dSBjoern A. Zeeb int mt7603_dma_init(struct mt7603_dev *dev);
1866c92544dSBjoern A. Zeeb void mt7603_dma_cleanup(struct mt7603_dev *dev);
1876c92544dSBjoern A. Zeeb int mt7603_mcu_init(struct mt7603_dev *dev);
1886c92544dSBjoern A. Zeeb void mt7603_init_debugfs(struct mt7603_dev *dev);
1896c92544dSBjoern A. Zeeb
mt7603_irq_enable(struct mt7603_dev * dev,u32 mask)1906c92544dSBjoern A. Zeeb static inline void mt7603_irq_enable(struct mt7603_dev *dev, u32 mask)
1916c92544dSBjoern A. Zeeb {
1926c92544dSBjoern A. Zeeb mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
1936c92544dSBjoern A. Zeeb }
1946c92544dSBjoern A. Zeeb
mt7603_irq_disable(struct mt7603_dev * dev,u32 mask)1956c92544dSBjoern A. Zeeb static inline void mt7603_irq_disable(struct mt7603_dev *dev, u32 mask)
1966c92544dSBjoern A. Zeeb {
1976c92544dSBjoern A. Zeeb mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
1986c92544dSBjoern A. Zeeb }
1996c92544dSBjoern A. Zeeb
2006c92544dSBjoern A. Zeeb void mt7603_mac_reset_counters(struct mt7603_dev *dev);
2016c92544dSBjoern A. Zeeb void mt7603_mac_dma_start(struct mt7603_dev *dev);
2026c92544dSBjoern A. Zeeb void mt7603_mac_start(struct mt7603_dev *dev);
2036c92544dSBjoern A. Zeeb void mt7603_mac_stop(struct mt7603_dev *dev);
2046c92544dSBjoern A. Zeeb void mt7603_mac_work(struct work_struct *work);
2056c92544dSBjoern A. Zeeb void mt7603_mac_set_timing(struct mt7603_dev *dev);
2066c92544dSBjoern A. Zeeb void mt7603_beacon_set_timer(struct mt7603_dev *dev, int idx, int intval);
2076c92544dSBjoern A. Zeeb int mt7603_mac_fill_rx(struct mt7603_dev *dev, struct sk_buff *skb);
2086c92544dSBjoern A. Zeeb void mt7603_mac_add_txs(struct mt7603_dev *dev, void *data);
2096c92544dSBjoern A. Zeeb void mt7603_mac_rx_ba_reset(struct mt7603_dev *dev, void *addr, u8 tid);
2106c92544dSBjoern A. Zeeb void mt7603_mac_tx_ba_reset(struct mt7603_dev *dev, int wcid, int tid,
2116c92544dSBjoern A. Zeeb int ba_size);
2126c92544dSBjoern A. Zeeb void mt7603_mac_sta_poll(struct mt7603_dev *dev);
2136c92544dSBjoern A. Zeeb
2146c92544dSBjoern A. Zeeb void mt7603_pse_client_reset(struct mt7603_dev *dev);
2156c92544dSBjoern A. Zeeb
2166c92544dSBjoern A. Zeeb int mt7603_mcu_set_channel(struct mt7603_dev *dev);
2176c92544dSBjoern A. Zeeb int mt7603_mcu_set_eeprom(struct mt7603_dev *dev);
2186c92544dSBjoern A. Zeeb void mt7603_mcu_exit(struct mt7603_dev *dev);
2196c92544dSBjoern A. Zeeb
2206c92544dSBjoern A. Zeeb void mt7603_wtbl_init(struct mt7603_dev *dev, int idx, int vif,
2216c92544dSBjoern A. Zeeb const u8 *mac_addr);
2226c92544dSBjoern A. Zeeb void mt7603_wtbl_clear(struct mt7603_dev *dev, int idx);
2236c92544dSBjoern A. Zeeb void mt7603_wtbl_update_cap(struct mt7603_dev *dev, struct ieee80211_sta *sta);
2246c92544dSBjoern A. Zeeb void mt7603_wtbl_set_rates(struct mt7603_dev *dev, struct mt7603_sta *sta,
2256c92544dSBjoern A. Zeeb struct ieee80211_tx_rate *probe_rate,
2266c92544dSBjoern A. Zeeb struct ieee80211_tx_rate *rates);
2276c92544dSBjoern A. Zeeb int mt7603_wtbl_set_key(struct mt7603_dev *dev, int wcid,
2286c92544dSBjoern A. Zeeb struct ieee80211_key_conf *key);
2296c92544dSBjoern A. Zeeb void mt7603_wtbl_set_ps(struct mt7603_dev *dev, struct mt7603_sta *sta,
2306c92544dSBjoern A. Zeeb bool enabled);
2316c92544dSBjoern A. Zeeb void mt7603_wtbl_set_smps(struct mt7603_dev *dev, struct mt7603_sta *sta,
2326c92544dSBjoern A. Zeeb bool enabled);
233*cbb3ec25SBjoern A. Zeeb void mt7603_filter_tx(struct mt7603_dev *dev, int mac_idx, int idx, bool abort);
2346c92544dSBjoern A. Zeeb
2356c92544dSBjoern A. Zeeb int mt7603_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
2366c92544dSBjoern A. Zeeb enum mt76_txq_id qid, struct mt76_wcid *wcid,
2376c92544dSBjoern A. Zeeb struct ieee80211_sta *sta,
2386c92544dSBjoern A. Zeeb struct mt76_tx_info *tx_info);
2396c92544dSBjoern A. Zeeb
2406c92544dSBjoern A. Zeeb void mt7603_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e);
2416c92544dSBjoern A. Zeeb
2426c92544dSBjoern A. Zeeb void mt7603_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
243*cbb3ec25SBjoern A. Zeeb struct sk_buff *skb, u32 *info);
2446c92544dSBjoern A. Zeeb void mt7603_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
2456c92544dSBjoern A. Zeeb void mt7603_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
2466c92544dSBjoern A. Zeeb int mt7603_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
2476c92544dSBjoern A. Zeeb struct ieee80211_sta *sta);
2486c92544dSBjoern A. Zeeb void mt7603_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
2496c92544dSBjoern A. Zeeb struct ieee80211_sta *sta);
2506c92544dSBjoern A. Zeeb void mt7603_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
2516c92544dSBjoern A. Zeeb struct ieee80211_sta *sta);
2526c92544dSBjoern A. Zeeb
2536c92544dSBjoern A. Zeeb void mt7603_pre_tbtt_tasklet(struct tasklet_struct *t);
2546c92544dSBjoern A. Zeeb
2556c92544dSBjoern A. Zeeb void mt7603_update_channel(struct mt76_phy *mphy);
2566c92544dSBjoern A. Zeeb
2576c92544dSBjoern A. Zeeb void mt7603_edcca_set_strict(struct mt7603_dev *dev, bool val);
2586c92544dSBjoern A. Zeeb void mt7603_cca_stats_reset(struct mt7603_dev *dev);
2596c92544dSBjoern A. Zeeb
2606c92544dSBjoern A. Zeeb void mt7603_init_edcca(struct mt7603_dev *dev);
2616c92544dSBjoern A. Zeeb #endif
262