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 708523a2aSLorenzo Bianconi #include <linux/completion.h> 804b8e659SRyder Lee #include <linux/interrupt.h> 904b8e659SRyder Lee #include <linux/ktime.h> 1035da599fSFelix Fietkau #include <linux/regmap.h> 11b7dd3c2eSLorenzo Bianconi #include "../mt76_connac.h" 1204b8e659SRyder Lee #include "regs.h" 1304b8e659SRyder Lee 14d8d59f66SRyder Lee #define MT7615_MAX_INTERFACES 16 1549f1132cSRyder Lee #define MT7615_MAX_WMM_SETS 4 168f997dddSLorenzo Bianconi #define MT7663_WTBL_SIZE 32 1704b8e659SRyder Lee #define MT7615_WTBL_SIZE 128 188f997dddSLorenzo Bianconi #define MT7615_WTBL_RESERVED (mt7615_wtbl_size(dev) - 1) 1904b8e659SRyder Lee #define MT7615_WTBL_STA (MT7615_WTBL_RESERVED - \ 2004b8e659SRyder Lee MT7615_MAX_INTERFACES) 2104b8e659SRyder Lee 22de5ff3c9SLorenzo Bianconi #define MT7615_PM_TIMEOUT (HZ / 12) 23457d19c7SLorenzo Bianconi #define MT7615_WATCHDOG_TIME (HZ / 10) 24fcdfc29eSLorenzo Bianconi #define MT7615_HW_SCAN_TIMEOUT (HZ / 10) 2561c4fa72SFelix Fietkau #define MT7615_RESET_TIMEOUT (30 * HZ) 2604b8e659SRyder Lee #define MT7615_RATE_RETRY 2 2704b8e659SRyder Lee 2804b8e659SRyder Lee #define MT7615_TX_RING_SIZE 1024 29cdad4874SFelix Fietkau #define MT7615_TX_MGMT_RING_SIZE 128 3004b8e659SRyder Lee #define MT7615_TX_MCU_RING_SIZE 128 3104b8e659SRyder Lee #define MT7615_TX_FWDL_RING_SIZE 128 3204b8e659SRyder Lee 3304b8e659SRyder Lee #define MT7615_RX_RING_SIZE 1024 3404b8e659SRyder Lee #define MT7615_RX_MCU_RING_SIZE 512 3504b8e659SRyder Lee 36894b7767SLorenzo Bianconi #define MT7615_DRV_OWN_RETRY_COUNT 10 37894b7767SLorenzo Bianconi 389d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_CR4 "mediatek/mt7615_cr4.bin" 399d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_N9 "mediatek/mt7615_n9.bin" 409d4d0d06SLorenzo Bianconi #define MT7615_ROM_PATCH "mediatek/mt7615_rom_patch.bin" 4104b8e659SRyder Lee 4235da599fSFelix Fietkau #define MT7622_FIRMWARE_N9 "mediatek/mt7622_n9.bin" 4335da599fSFelix Fietkau #define MT7622_ROM_PATCH "mediatek/mt7622_rom_patch.bin" 4435da599fSFelix Fietkau 456849e29eSRyder Lee #define MT7615_FIRMWARE_V1 1 466849e29eSRyder Lee #define MT7615_FIRMWARE_V2 2 47f40ac0f3SLorenzo Bianconi #define MT7615_FIRMWARE_V3 3 48f40ac0f3SLorenzo Bianconi 49f2dc8ea1SLorenzo Bianconi #define MT7663_OFFLOAD_ROM_PATCH "mediatek/mt7663pr2h.bin" 50f2dc8ea1SLorenzo Bianconi #define MT7663_OFFLOAD_FIRMWARE_N9 "mediatek/mt7663_n9_v3.bin" 51f2dc8ea1SLorenzo Bianconi #define MT7663_ROM_PATCH "mediatek/mt7663pr2h_rebb.bin" 52f2dc8ea1SLorenzo Bianconi #define MT7663_FIRMWARE_N9 "mediatek/mt7663_n9_rebb.bin" 536849e29eSRyder Lee 5404b8e659SRyder Lee #define MT7615_EEPROM_SIZE 1024 5504b8e659SRyder Lee #define MT7615_TOKEN_SIZE 4096 5604b8e659SRyder Lee 5749de79adSLorenzo Bianconi #define MT_FRAC_SCALE 12 5849de79adSLorenzo Bianconi #define MT_FRAC(val, div) (((val) << MT_FRAC_SCALE) / (div)) 5949de79adSLorenzo Bianconi 6027ae7219SFelix Fietkau #define MT_CHFREQ_VALID BIT(7) 6127ae7219SFelix Fietkau #define MT_CHFREQ_DBDC_IDX BIT(6) 6227ae7219SFelix Fietkau #define MT_CHFREQ_SEQ GENMASK(5, 0) 6327ae7219SFelix Fietkau 64a25c888fSRyder Lee #define MT7615_BAR_RATE_DEFAULT 0x4b /* OFDM 6M */ 65a25c888fSRyder Lee #define MT7615_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ 66183d1fcfSLorenzo Bianconi #define MT7615_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ 67183d1fcfSLorenzo Bianconi 6804b8e659SRyder Lee struct mt7615_vif; 6904b8e659SRyder Lee struct mt7615_sta; 702ce73efeSLorenzo Bianconi struct mt7615_dfs_pulse; 712ce73efeSLorenzo Bianconi struct mt7615_dfs_pattern; 72294f17aeSLorenzo Bianconi enum mt7615_cipher_type; 7304b8e659SRyder Lee 7404b8e659SRyder Lee enum mt7615_hw_txq_id { 7504b8e659SRyder Lee MT7615_TXQ_MAIN, 7604b8e659SRyder Lee MT7615_TXQ_EXT, 7704b8e659SRyder Lee MT7615_TXQ_MCU, 7804b8e659SRyder Lee MT7615_TXQ_FWDL, 7904b8e659SRyder Lee }; 8004b8e659SRyder Lee 81cdad4874SFelix Fietkau enum mt7622_hw_txq_id { 82cdad4874SFelix Fietkau MT7622_TXQ_AC0, 83cdad4874SFelix Fietkau MT7622_TXQ_AC1, 84cdad4874SFelix Fietkau MT7622_TXQ_AC2, 85cdad4874SFelix Fietkau MT7622_TXQ_FWDL = MT7615_TXQ_FWDL, 86cdad4874SFelix Fietkau MT7622_TXQ_AC3, 87cdad4874SFelix Fietkau MT7622_TXQ_MGMT, 88cdad4874SFelix Fietkau MT7622_TXQ_MCU = 15, 89cdad4874SFelix Fietkau }; 90cdad4874SFelix Fietkau 914af81f02SFelix Fietkau struct mt7615_rate_set { 924af81f02SFelix Fietkau struct ieee80211_tx_rate probe_rate; 934af81f02SFelix Fietkau struct ieee80211_tx_rate rates[4]; 944af81f02SFelix Fietkau }; 954af81f02SFelix Fietkau 968f93af9cSLorenzo Bianconi struct mt7615_rate_desc { 978f93af9cSLorenzo Bianconi bool rateset; 988f93af9cSLorenzo Bianconi u16 probe_val; 998f93af9cSLorenzo Bianconi u16 val[4]; 1008f93af9cSLorenzo Bianconi u8 bw_idx; 1018f93af9cSLorenzo Bianconi u8 bw; 1028f93af9cSLorenzo Bianconi }; 1038f93af9cSLorenzo Bianconi 104d927ebb9SLorenzo Bianconi struct mt7615_wtbl_rate_desc { 1057d9f1d10SLorenzo Bianconi struct list_head node; 1067d9f1d10SLorenzo Bianconi 1077d9f1d10SLorenzo Bianconi struct mt7615_rate_desc rate; 108d927ebb9SLorenzo Bianconi struct mt7615_sta *sta; 1097d9f1d10SLorenzo Bianconi }; 1107d9f1d10SLorenzo Bianconi 11104b8e659SRyder Lee struct mt7615_sta { 11204b8e659SRyder Lee struct mt76_wcid wcid; /* must be first */ 11304b8e659SRyder Lee 11404b8e659SRyder Lee struct mt7615_vif *vif; 11504b8e659SRyder Lee 116b2c2f029SLorenzo Bianconi struct list_head poll_list; 117b2c2f029SLorenzo Bianconi u32 airtime_ac[8]; 118b2c2f029SLorenzo Bianconi 1194af81f02SFelix Fietkau struct ieee80211_tx_rate rates[4]; 1204af81f02SFelix Fietkau 1214af81f02SFelix Fietkau struct mt7615_rate_set rateset[2]; 1224af81f02SFelix Fietkau u32 rate_set_tsf; 1234af81f02SFelix Fietkau 12404b8e659SRyder Lee u8 rate_count; 12504b8e659SRyder Lee u8 n_rates; 12604b8e659SRyder Lee 12704b8e659SRyder Lee u8 rate_probe; 12804b8e659SRyder Lee }; 12904b8e659SRyder Lee 13004b8e659SRyder Lee struct mt7615_vif { 13185d96704SLorenzo Bianconi struct mt76_vif mt76; /* must be first */ 13204b8e659SRyder Lee struct mt7615_sta sta; 13304b8e659SRyder Lee }; 13404b8e659SRyder Lee 135679b23feSRyder Lee struct mib_stats { 136b7825ca0SRyder Lee u16 ack_fail_cnt; 137b7825ca0SRyder Lee u16 fcs_err_cnt; 138b7825ca0SRyder Lee u16 rts_cnt; 139b7825ca0SRyder Lee u16 rts_retries_cnt; 140aef16345SRyder Lee u16 ba_miss_cnt; 141aef16345SRyder Lee unsigned long aggr_per; 142679b23feSRyder Lee }; 143679b23feSRyder Lee 144fdd2e570SFelix Fietkau struct mt7615_phy { 145fdd2e570SFelix Fietkau struct mt76_phy *mt76; 146fdd2e570SFelix Fietkau struct mt7615_dev *dev; 147fdd2e570SFelix Fietkau 1484f0bce1cSFelix Fietkau struct ieee80211_vif *monitor_vif; 1494f0bce1cSFelix Fietkau 1507124198aSLorenzo Bianconi u8 n_beacon_vif; 1517124198aSLorenzo Bianconi 152fdd2e570SFelix Fietkau u32 rxfilter; 153d8d59f66SRyder Lee u64 omac_mask; 154d446a20fSFelix Fietkau 155e5051965SFelix Fietkau u16 noise; 156e5051965SFelix Fietkau 157594034b7SLorenzo Bianconi bool scs_en; 158594034b7SLorenzo Bianconi 159d446a20fSFelix Fietkau unsigned long last_cca_adj; 160d446a20fSFelix Fietkau int false_cca_ofdm, false_cca_cck; 161d446a20fSFelix Fietkau s8 ofdm_sensitivity; 162d446a20fSFelix Fietkau s8 cck_sensitivity; 1635dabdf71SFelix Fietkau 164183d1fcfSLorenzo Bianconi s16 coverage_class; 165183d1fcfSLorenzo Bianconi u8 slottime; 166183d1fcfSLorenzo Bianconi 1670e544cb5SFelix Fietkau u8 chfreq; 1685dabdf71SFelix Fietkau u8 rdd_state; 1695dabdf71SFelix Fietkau int dfs_state; 17027ae7219SFelix Fietkau 17127ae7219SFelix Fietkau __le32 rx_ampdu_ts; 17227ae7219SFelix Fietkau u32 ampdu_ref; 173679b23feSRyder Lee 174679b23feSRyder Lee struct mib_stats mib; 175fcdfc29eSLorenzo Bianconi 17620305f98SLorenzo Bianconi struct sk_buff_head scan_event_list; 177fcdfc29eSLorenzo Bianconi struct delayed_work scan_work; 1787f8ebafeSLorenzo Bianconi 1797307f296SLorenzo Bianconi struct work_struct roc_work; 1807307f296SLorenzo Bianconi struct timer_list roc_timer; 1817307f296SLorenzo Bianconi wait_queue_head_t roc_wait; 1827307f296SLorenzo Bianconi bool roc_grant; 1837517ea01SShayne Chen 1847517ea01SShayne Chen #ifdef CONFIG_NL80211_TESTMODE 1857517ea01SShayne Chen struct { 1867517ea01SShayne Chen u32 *reg_backup; 1877517ea01SShayne Chen 1887517ea01SShayne Chen s16 last_freq_offset; 1897517ea01SShayne Chen u8 last_rcpi[4]; 1907517ea01SShayne Chen s8 last_ib_rssi[4]; 1917517ea01SShayne Chen s8 last_wb_rssi[4]; 1927517ea01SShayne Chen } test; 1937517ea01SShayne Chen #endif 194fdd2e570SFelix Fietkau }; 195fdd2e570SFelix Fietkau 1966f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_tx_ba(dev, ...) (dev)->mcu_ops->add_tx_ba((dev), __VA_ARGS__) 1976f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_rx_ba(dev, ...) (dev)->mcu_ops->add_rx_ba((dev), __VA_ARGS__) 198d0e274afSLorenzo Bianconi #define mt7615_mcu_sta_add(phy, ...) ((phy)->dev)->mcu_ops->sta_add((phy), __VA_ARGS__) 199d0e274afSLorenzo Bianconi #define mt7615_mcu_add_dev_info(phy, ...) ((phy)->dev)->mcu_ops->add_dev_info((phy), __VA_ARGS__) 200d0e274afSLorenzo Bianconi #define mt7615_mcu_add_bss_info(phy, ...) ((phy)->dev)->mcu_ops->add_bss_info((phy), __VA_ARGS__) 201062c3699SLorenzo Bianconi #define mt7615_mcu_add_beacon(dev, ...) (dev)->mcu_ops->add_beacon_offload((dev), __VA_ARGS__) 202062c3699SLorenzo Bianconi #define mt7615_mcu_set_pm(dev, ...) (dev)->mcu_ops->set_pm_state((dev), __VA_ARGS__) 203186b659cSLorenzo Bianconi #define mt7615_mcu_set_drv_ctrl(dev) (dev)->mcu_ops->set_drv_ctrl((dev)) 204186b659cSLorenzo Bianconi #define mt7615_mcu_set_fw_ctrl(dev) (dev)->mcu_ops->set_fw_ctrl((dev)) 2056f4d7cc8SLorenzo Bianconi struct mt7615_mcu_ops { 2066f4d7cc8SLorenzo Bianconi int (*add_tx_ba)(struct mt7615_dev *dev, 2076f4d7cc8SLorenzo Bianconi struct ieee80211_ampdu_params *params, 2086f4d7cc8SLorenzo Bianconi bool enable); 2096f4d7cc8SLorenzo Bianconi int (*add_rx_ba)(struct mt7615_dev *dev, 2106f4d7cc8SLorenzo Bianconi struct ieee80211_ampdu_params *params, 2116f4d7cc8SLorenzo Bianconi bool enable); 212d0e274afSLorenzo Bianconi int (*sta_add)(struct mt7615_phy *phy, struct ieee80211_vif *vif, 21399c457d9SLorenzo Bianconi struct ieee80211_sta *sta, bool enable); 214d0e274afSLorenzo Bianconi int (*add_dev_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif, 215d0e274afSLorenzo Bianconi bool enable); 2165d3a4a4bSLorenzo Bianconi int (*add_bss_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif, 217f5596850SLorenzo Bianconi struct ieee80211_sta *sta, bool enable); 218062c3699SLorenzo Bianconi int (*add_beacon_offload)(struct mt7615_dev *dev, 219062c3699SLorenzo Bianconi struct ieee80211_hw *hw, 220062c3699SLorenzo Bianconi struct ieee80211_vif *vif, bool enable); 221062c3699SLorenzo Bianconi int (*set_pm_state)(struct mt7615_dev *dev, int band, int state); 222186b659cSLorenzo Bianconi int (*set_drv_ctrl)(struct mt7615_dev *dev); 223186b659cSLorenzo Bianconi int (*set_fw_ctrl)(struct mt7615_dev *dev); 2246f4d7cc8SLorenzo Bianconi }; 2256f4d7cc8SLorenzo Bianconi 22604b8e659SRyder Lee struct mt7615_dev { 227ac24dd35SFelix Fietkau union { /* must be first */ 228ac24dd35SFelix Fietkau struct mt76_dev mt76; 229ac24dd35SFelix Fietkau struct mt76_phy mphy; 230ac24dd35SFelix Fietkau }; 231ac24dd35SFelix Fietkau 232557b5a17SFelix Fietkau const struct mt76_bus_ops *bus_ops; 2339b90ab32SFelix Fietkau struct tasklet_struct irq_tasklet; 2349b90ab32SFelix Fietkau 235fdd2e570SFelix Fietkau struct mt7615_phy phy; 236d8d59f66SRyder Lee u64 omac_mask; 23704b8e659SRyder Lee 2380f2173f0SFelix Fietkau u16 chainmask; 2390f2173f0SFelix Fietkau 240635cb010SFelix Fietkau struct ieee80211_ops *ops; 2416f4d7cc8SLorenzo Bianconi const struct mt7615_mcu_ops *mcu_ops; 24235da599fSFelix Fietkau struct regmap *infracfg; 24394f83b66SLorenzo Bianconi const u32 *reg_map; 24435da599fSFelix Fietkau 245c3c25d09SFelix Fietkau struct work_struct mcu_work; 246c3c25d09SFelix Fietkau 24761c4fa72SFelix Fietkau struct work_struct reset_work; 24861c4fa72SFelix Fietkau wait_queue_head_t reset_wait; 24961c4fa72SFelix Fietkau u32 reset_state; 25061c4fa72SFelix Fietkau 251b2c2f029SLorenzo Bianconi struct list_head sta_poll_list; 252b2c2f029SLorenzo Bianconi spinlock_t sta_poll_lock; 253b2c2f029SLorenzo Bianconi 25470911d96SLorenzo Bianconi struct { 25570911d96SLorenzo Bianconi u8 n_pulses; 25670911d96SLorenzo Bianconi u32 period; 25770911d96SLorenzo Bianconi u16 width; 25870911d96SLorenzo Bianconi s16 power; 25970911d96SLorenzo Bianconi } radar_pattern; 260d67a6646SLorenzo Bianconi u32 hw_pattern; 261d67a6646SLorenzo Bianconi 262f347f81aSFelix Fietkau bool fw_debug; 263ad380ad1SFelix Fietkau bool flash_eeprom; 2647660a1bdSShayne Chen bool dbdc_support; 26549de79adSLorenzo Bianconi 26604b8e659SRyder Lee spinlock_t token_lock; 26704b8e659SRyder Lee struct idr token; 2686849e29eSRyder Lee 2696849e29eSRyder Lee u8 fw_ver; 270eb99cc95SLorenzo Bianconi 271d927ebb9SLorenzo Bianconi struct work_struct rate_work; 272d927ebb9SLorenzo Bianconi struct list_head wrd_head; 273dc804058SFelix Fietkau 274dc804058SFelix Fietkau u32 debugfs_rf_wf; 275dc804058SFelix Fietkau u32 debugfs_rf_reg; 2764f0bce1cSFelix Fietkau 277d22da028SFelix Fietkau u32 muar_mask; 278d22da028SFelix Fietkau 279b7dd3c2eSLorenzo Bianconi struct mt76_connac_pm pm; 28004b8e659SRyder Lee }; 28104b8e659SRyder Lee 2821fec635bSLorenzo Bianconi enum tx_pkt_queue_idx { 2831fec635bSLorenzo Bianconi MT_LMAC_AC00, 2841fec635bSLorenzo Bianconi MT_LMAC_AC01, 2851fec635bSLorenzo Bianconi MT_LMAC_AC02, 2861fec635bSLorenzo Bianconi MT_LMAC_AC03, 2871fec635bSLorenzo Bianconi MT_LMAC_ALTX0 = 0x10, 2881fec635bSLorenzo Bianconi MT_LMAC_BMC0, 2891fec635bSLorenzo Bianconi MT_LMAC_BCN0, 2901fec635bSLorenzo Bianconi MT_LMAC_PSMP0, 2911fec635bSLorenzo Bianconi MT_LMAC_ALTX1, 2921fec635bSLorenzo Bianconi MT_LMAC_BMC1, 2931fec635bSLorenzo Bianconi MT_LMAC_BCN1, 2941fec635bSLorenzo Bianconi MT_LMAC_PSMP1, 2951fec635bSLorenzo Bianconi }; 2961fec635bSLorenzo Bianconi 29704b8e659SRyder Lee enum { 298d67a6646SLorenzo Bianconi MT_RX_SEL0, 299d67a6646SLorenzo Bianconi MT_RX_SEL1, 300d67a6646SLorenzo Bianconi }; 301d67a6646SLorenzo Bianconi 302d67a6646SLorenzo Bianconi enum mt7615_rdd_cmd { 303d67a6646SLorenzo Bianconi RDD_STOP, 304d67a6646SLorenzo Bianconi RDD_START, 305d67a6646SLorenzo Bianconi RDD_DET_MODE, 306d67a6646SLorenzo Bianconi RDD_DET_STOP, 307d67a6646SLorenzo Bianconi RDD_CAC_START, 308d67a6646SLorenzo Bianconi RDD_CAC_END, 309d67a6646SLorenzo Bianconi RDD_NORMAL_START, 310d67a6646SLorenzo Bianconi RDD_DISABLE_DFS_CAL, 311d67a6646SLorenzo Bianconi RDD_PULSE_DBG, 312d67a6646SLorenzo Bianconi RDD_READ_PULSE, 313d67a6646SLorenzo Bianconi RDD_RESUME_BF, 314d67a6646SLorenzo Bianconi }; 315d67a6646SLorenzo Bianconi 316fdd2e570SFelix Fietkau static inline struct mt7615_phy * 317fdd2e570SFelix Fietkau mt7615_hw_phy(struct ieee80211_hw *hw) 318fdd2e570SFelix Fietkau { 319fdd2e570SFelix Fietkau struct mt76_phy *phy = hw->priv; 320fdd2e570SFelix Fietkau 321fdd2e570SFelix Fietkau return phy->priv; 322fdd2e570SFelix Fietkau } 323fdd2e570SFelix Fietkau 324fdd2e570SFelix Fietkau static inline struct mt7615_dev * 325fdd2e570SFelix Fietkau mt7615_hw_dev(struct ieee80211_hw *hw) 326fdd2e570SFelix Fietkau { 327fdd2e570SFelix Fietkau struct mt76_phy *phy = hw->priv; 328fdd2e570SFelix Fietkau 329fdd2e570SFelix Fietkau return container_of(phy->dev, struct mt7615_dev, mt76); 330fdd2e570SFelix Fietkau } 331fdd2e570SFelix Fietkau 332fdd2e570SFelix Fietkau static inline struct mt7615_phy * 333fdd2e570SFelix Fietkau mt7615_ext_phy(struct mt7615_dev *dev) 334fdd2e570SFelix Fietkau { 335fdd2e570SFelix Fietkau struct mt76_phy *phy = dev->mt76.phy2; 336fdd2e570SFelix Fietkau 337fdd2e570SFelix Fietkau if (!phy) 338fdd2e570SFelix Fietkau return NULL; 339fdd2e570SFelix Fietkau 340fdd2e570SFelix Fietkau return phy->priv; 341fdd2e570SFelix Fietkau } 342fdd2e570SFelix Fietkau 343e90354e0SLorenzo Bianconi extern struct ieee80211_rate mt7615_rates[12]; 34404b8e659SRyder Lee extern const struct ieee80211_ops mt7615_ops; 34594f83b66SLorenzo Bianconi extern const u32 mt7615e_reg_map[__MT_BASE_MAX]; 346f40ac0f3SLorenzo Bianconi extern const u32 mt7663e_reg_map[__MT_BASE_MAX]; 34790520afbSLorenzo Bianconi extern const u32 mt7663_usb_sdio_reg_map[__MT_BASE_MAX]; 34804b8e659SRyder Lee extern struct pci_driver mt7615_pci_driver; 34935da599fSFelix Fietkau extern struct platform_driver mt7622_wmac_driver; 3504f0bce1cSFelix Fietkau extern const struct mt76_testmode_ops mt7615_testmode_ops; 35135da599fSFelix Fietkau 35235da599fSFelix Fietkau #ifdef CONFIG_MT7622_WMAC 35335da599fSFelix Fietkau int mt7622_wmac_init(struct mt7615_dev *dev); 35435da599fSFelix Fietkau #else 35535da599fSFelix Fietkau static inline int mt7622_wmac_init(struct mt7615_dev *dev) 35635da599fSFelix Fietkau { 35735da599fSFelix Fietkau return 0; 35835da599fSFelix Fietkau } 35935da599fSFelix Fietkau #endif 36004b8e659SRyder Lee 36194f83b66SLorenzo Bianconi int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base, 36294f83b66SLorenzo Bianconi int irq, const u32 *map); 36304b8e659SRyder Lee u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr); 36404b8e659SRyder Lee 3652ee920c2SLorenzo Bianconi void mt7615_init_device(struct mt7615_dev *dev); 36604b8e659SRyder Lee int mt7615_register_device(struct mt7615_dev *dev); 36704b8e659SRyder Lee void mt7615_unregister_device(struct mt7615_dev *dev); 3680f2173f0SFelix Fietkau int mt7615_register_ext_phy(struct mt7615_dev *dev); 3690f2173f0SFelix Fietkau void mt7615_unregister_ext_phy(struct mt7615_dev *dev); 3706e5d2099SLorenzo Bianconi int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr); 371e0ec633dSLorenzo Bianconi int mt7615_eeprom_get_target_power_index(struct mt7615_dev *dev, 37216a2f8e2SLorenzo Bianconi struct ieee80211_channel *chan, 37361d36824SLorenzo Bianconi u8 chain_idx); 374c88bf52bSLorenzo Bianconi int mt7615_eeprom_get_power_delta_index(struct mt7615_dev *dev, 375c88bf52bSLorenzo Bianconi enum nl80211_band band); 3766dd4072cSLorenzo Bianconi int mt7615_wait_pdma_busy(struct mt7615_dev *dev); 37704b8e659SRyder Lee int mt7615_dma_init(struct mt7615_dev *dev); 37804b8e659SRyder Lee void mt7615_dma_cleanup(struct mt7615_dev *dev); 37904b8e659SRyder Lee int mt7615_mcu_init(struct mt7615_dev *dev); 380c3c25d09SFelix Fietkau bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev); 381fdd2e570SFelix Fietkau void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta, 38204b8e659SRyder Lee struct ieee80211_tx_rate *probe_rate, 38304b8e659SRyder Lee struct ieee80211_tx_rate *rates); 38408523a2aSLorenzo Bianconi void mt7615_pm_wake_work(struct work_struct *work); 385de5ff3c9SLorenzo Bianconi void mt7615_pm_power_save_work(struct work_struct *work); 38604b8e659SRyder Lee int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev); 3874fe9218cSRyder Lee int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd); 38804b8e659SRyder Lee int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue, 38904b8e659SRyder Lee const struct ieee80211_tx_queue_params *params); 390d67a6646SLorenzo Bianconi void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb); 391d67a6646SLorenzo Bianconi int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev, 392d67a6646SLorenzo Bianconi enum mt7615_rdd_cmd cmd, u8 index, 393d67a6646SLorenzo Bianconi u8 rx_sel, u8 val); 39470911d96SLorenzo Bianconi int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev); 395f347f81aSFelix Fietkau int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl); 396d67a6646SLorenzo Bianconi 39749de79adSLorenzo Bianconi static inline bool is_mt7622(struct mt76_dev *dev) 39849de79adSLorenzo Bianconi { 39935da599fSFelix Fietkau if (!IS_ENABLED(CONFIG_MT7622_WMAC)) 40035da599fSFelix Fietkau return false; 40135da599fSFelix Fietkau 40249de79adSLorenzo Bianconi return mt76_chip(dev) == 0x7622; 40349de79adSLorenzo Bianconi } 40449de79adSLorenzo Bianconi 405cdad4874SFelix Fietkau static inline bool is_mt7615(struct mt76_dev *dev) 406cdad4874SFelix Fietkau { 407e47f2245SDENG Qingfang return mt76_chip(dev) == 0x7615 || mt76_chip(dev) == 0x7611; 408cdad4874SFelix Fietkau } 409cdad4874SFelix Fietkau 410f82282efSLorenzo Bianconi static inline bool is_mt7663(struct mt76_dev *dev) 411f82282efSLorenzo Bianconi { 412f82282efSLorenzo Bianconi return mt76_chip(dev) == 0x7663; 413f82282efSLorenzo Bianconi } 414f82282efSLorenzo Bianconi 415e47f2245SDENG Qingfang static inline bool is_mt7611(struct mt76_dev *dev) 416e47f2245SDENG Qingfang { 417e47f2245SDENG Qingfang return mt76_chip(dev) == 0x7611; 418e47f2245SDENG Qingfang } 419e47f2245SDENG Qingfang 42004b8e659SRyder Lee static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask) 42104b8e659SRyder Lee { 4229b90ab32SFelix Fietkau mt76_set_irq_mask(&dev->mt76, 0, 0, mask); 42304b8e659SRyder Lee 4249b90ab32SFelix Fietkau tasklet_schedule(&dev->irq_tasklet); 42504b8e659SRyder Lee } 42604b8e659SRyder Lee 427bf18fcdcSLorenzo Bianconi static inline bool mt7615_firmware_offload(struct mt7615_dev *dev) 428bf18fcdcSLorenzo Bianconi { 429bf18fcdcSLorenzo Bianconi return dev->fw_ver > MT7615_FIRMWARE_V2; 430bf18fcdcSLorenzo Bianconi } 431bf18fcdcSLorenzo Bianconi 4328f997dddSLorenzo Bianconi static inline u16 mt7615_wtbl_size(struct mt7615_dev *dev) 4338f997dddSLorenzo Bianconi { 4348f997dddSLorenzo Bianconi if (is_mt7663(&dev->mt76) && mt7615_firmware_offload(dev)) 4358f997dddSLorenzo Bianconi return MT7663_WTBL_SIZE; 4368f997dddSLorenzo Bianconi else 4378f997dddSLorenzo Bianconi return MT7615_WTBL_SIZE; 4388f997dddSLorenzo Bianconi } 4398f997dddSLorenzo Bianconi 440*1755f6adSLorenzo Bianconi #define mt7615_mutex_acquire(dev) \ 441*1755f6adSLorenzo Bianconi mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm) 442*1755f6adSLorenzo Bianconi #define mt7615_mutex_release(dev) \ 443*1755f6adSLorenzo Bianconi mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm) 444adfd5112SLorenzo Bianconi 4451fec635bSLorenzo Bianconi static inline u8 mt7615_lmac_mapping(struct mt7615_dev *dev, u8 ac) 4461fec635bSLorenzo Bianconi { 4471fec635bSLorenzo Bianconi static const u8 lmac_queue_map[] = { 4481fec635bSLorenzo Bianconi [IEEE80211_AC_BK] = MT_LMAC_AC00, 4491fec635bSLorenzo Bianconi [IEEE80211_AC_BE] = MT_LMAC_AC01, 4501fec635bSLorenzo Bianconi [IEEE80211_AC_VI] = MT_LMAC_AC02, 4511fec635bSLorenzo Bianconi [IEEE80211_AC_VO] = MT_LMAC_AC03, 4521fec635bSLorenzo Bianconi }; 4531fec635bSLorenzo Bianconi 4541fec635bSLorenzo Bianconi if (WARN_ON_ONCE(ac >= ARRAY_SIZE(lmac_queue_map))) 4551fec635bSLorenzo Bianconi return MT_LMAC_AC01; /* BE */ 4561fec635bSLorenzo Bianconi 4571fec635bSLorenzo Bianconi return lmac_queue_map[ac]; 4581fec635bSLorenzo Bianconi } 4591fec635bSLorenzo Bianconi 460e17d7945SFelix Fietkau static inline u32 mt7615_tx_mcu_int_mask(struct mt7615_dev *dev) 461e17d7945SFelix Fietkau { 462e637763bSLorenzo Bianconi return MT_INT_TX_DONE(dev->mt76.q_mcu[MT_MCUQ_WM]->hw_idx); 463e17d7945SFelix Fietkau } 464e17d7945SFelix Fietkau 4656dd4072cSLorenzo Bianconi void mt7615_dma_reset(struct mt7615_dev *dev); 466fcdfc29eSLorenzo Bianconi void mt7615_scan_work(struct work_struct *work); 4677307f296SLorenzo Bianconi void mt7615_roc_work(struct work_struct *work); 4687307f296SLorenzo Bianconi void mt7615_roc_timer(struct timer_list *timer); 469e90354e0SLorenzo Bianconi void mt7615_init_txpower(struct mt7615_dev *dev, 470e90354e0SLorenzo Bianconi struct ieee80211_supported_band *sband); 4714f0bce1cSFelix Fietkau int mt7615_set_channel(struct mt7615_phy *phy); 47295f381c5SFelix Fietkau void mt7615_init_work(struct mt7615_dev *dev); 473e90354e0SLorenzo Bianconi 474e90354e0SLorenzo Bianconi int mt7615_mcu_restart(struct mt76_dev *dev); 475863c15a1SLorenzo Bianconi void mt7615_update_channel(struct mt76_dev *mdev); 47687d3cdebSLorenzo Bianconi bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask); 47775601194SLorenzo Bianconi void mt7615_mac_reset_counters(struct mt7615_dev *dev); 478d446a20fSFelix Fietkau void mt7615_mac_cca_stats_reset(struct mt7615_phy *phy); 479594034b7SLorenzo Bianconi void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable); 480e5051965SFelix Fietkau void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy); 481b2c2f029SLorenzo Bianconi void mt7615_mac_sta_poll(struct mt7615_dev *dev); 48204b8e659SRyder Lee int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi, 48304b8e659SRyder Lee struct sk_buff *skb, struct mt76_wcid *wcid, 48404b8e659SRyder Lee struct ieee80211_sta *sta, int pid, 485c984457bSFelix Fietkau struct ieee80211_key_conf *key, bool beacon); 486183d1fcfSLorenzo Bianconi void mt7615_mac_set_timing(struct mt7615_phy *phy); 487faa72684SLorenzo Bianconi int __mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, 488faa72684SLorenzo Bianconi struct mt76_wcid *wcid, 48927b8a900SLorenzo Bianconi struct ieee80211_key_conf *key, 49027b8a900SLorenzo Bianconi enum set_key_cmd cmd); 491faa72684SLorenzo Bianconi int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid, 492faa72684SLorenzo Bianconi struct ieee80211_key_conf *key, 493294f17aeSLorenzo Bianconi enum set_key_cmd cmd); 49461c4fa72SFelix Fietkau void mt7615_mac_reset_work(struct work_struct *work); 495a28bef56SFelix Fietkau u32 mt7615_mac_get_sta_tid_sn(struct mt7615_dev *dev, int wcid, u8 tid); 49604b8e659SRyder Lee 497f320d812SFelix Fietkau int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, 498f320d812SFelix Fietkau struct sk_buff *skb, int seq); 499dc804058SFelix Fietkau u32 mt7615_rf_rr(struct mt7615_dev *dev, u32 wf, u32 reg); 500dc804058SFelix Fietkau int mt7615_rf_wr(struct mt7615_dev *dev, u32 wf, u32 reg, u32 val); 501ac3ef85cSFelix Fietkau int mt7615_mcu_set_dbdc(struct mt7615_dev *dev); 50204b8e659SRyder Lee int mt7615_mcu_set_eeprom(struct mt7615_dev *dev); 5030e6a29e4SLorenzo Bianconi int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index); 5044f0bce1cSFelix Fietkau int mt7615_mcu_set_tx_power(struct mt7615_phy *phy); 50504b8e659SRyder Lee void mt7615_mcu_exit(struct mt7615_dev *dev); 50663f09b6bSLorenzo Bianconi void mt7615_mcu_fill_msg(struct mt7615_dev *dev, struct sk_buff *skb, 50763f09b6bSLorenzo Bianconi int cmd, int *wait_seq); 50804b8e659SRyder Lee 50904b8e659SRyder Lee int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 51004b8e659SRyder Lee enum mt76_txq_id qid, struct mt76_wcid *wcid, 51104b8e659SRyder Lee struct ieee80211_sta *sta, 51204b8e659SRyder Lee struct mt76_tx_info *tx_info); 51304b8e659SRyder Lee 514d80e52c7SFelix Fietkau void mt7615_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e); 515a6275e93SRyder Lee void mt7615_tx_token_put(struct mt7615_dev *dev); 51604b8e659SRyder Lee void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, 51704b8e659SRyder Lee struct sk_buff *skb); 51804b8e659SRyder Lee void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); 5193e384828SFelix Fietkau int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 52004b8e659SRyder Lee struct ieee80211_sta *sta); 5213e384828SFelix Fietkau void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 52204b8e659SRyder Lee struct ieee80211_sta *sta); 52304b8e659SRyder Lee void mt7615_mac_work(struct work_struct *work); 52404b8e659SRyder Lee void mt7615_txp_skb_unmap(struct mt76_dev *dev, 52504b8e659SRyder Lee struct mt76_txwi_cache *txwi); 5262ce73efeSLorenzo Bianconi int mt7615_mcu_set_fcc5_lpn(struct mt7615_dev *dev, int val); 5272ce73efeSLorenzo Bianconi int mt7615_mcu_set_pulse_th(struct mt7615_dev *dev, 5282ce73efeSLorenzo Bianconi const struct mt7615_dfs_pulse *pulse); 5292ce73efeSLorenzo Bianconi int mt7615_mcu_set_radar_th(struct mt7615_dev *dev, int index, 5302ce73efeSLorenzo Bianconi const struct mt7615_dfs_pattern *pattern); 5314f0bce1cSFelix Fietkau int mt7615_mcu_set_test_param(struct mt7615_dev *dev, u8 param, bool test_mode, 5324f0bce1cSFelix Fietkau u32 val); 53315d9a5d7SFelix Fietkau int mt7615_mcu_set_sku_en(struct mt7615_phy *phy, bool enable); 534ad380ad1SFelix Fietkau int mt7615_mcu_apply_rx_dcoc(struct mt7615_phy *phy); 535371a59d1SFelix Fietkau int mt7615_mcu_apply_tx_dpd(struct mt7615_phy *phy); 5365dabdf71SFelix Fietkau int mt7615_dfs_init_radar_detector(struct mt7615_phy *phy); 53704b8e659SRyder Lee 53850eb0a88SLorenzo Bianconi int mt7615_mcu_set_p2p_oppps(struct ieee80211_hw *hw, 53950eb0a88SLorenzo Bianconi struct ieee80211_vif *vif); 5407307f296SLorenzo Bianconi int mt7615_mcu_set_roc(struct mt7615_phy *phy, struct ieee80211_vif *vif, 5417307f296SLorenzo Bianconi struct ieee80211_channel *chan, int duration); 5426dd4072cSLorenzo Bianconi 54370911d96SLorenzo Bianconi int mt7615_init_debugfs(struct mt7615_dev *dev); 544eb99cc95SLorenzo Bianconi int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq); 545eb99cc95SLorenzo Bianconi 5467124198aSLorenzo Bianconi int mt7615_mac_set_beacon_filter(struct mt7615_phy *phy, 5477124198aSLorenzo Bianconi struct ieee80211_vif *vif, 5487124198aSLorenzo Bianconi bool enable); 54983b9f42aSLorenzo Bianconi int mt7615_mcu_set_bss_pm(struct mt7615_dev *dev, struct ieee80211_vif *vif, 55083b9f42aSLorenzo Bianconi bool enable); 55173741b9bSSean Wang int mt7615_mcu_update_arp_filter(struct ieee80211_hw *hw, 55273741b9bSSean Wang struct ieee80211_vif *vif, 55373741b9bSSean Wang struct ieee80211_bss_conf *info); 5548915c3ceSLorenzo Bianconi int __mt7663_load_firmware(struct mt7615_dev *dev); 555a66cbdd6SSean Wang u32 mt7615_mcu_reg_rr(struct mt76_dev *dev, u32 offset); 556a66cbdd6SSean Wang void mt7615_mcu_reg_wr(struct mt76_dev *dev, u32 offset, u32 val); 55770911d96SLorenzo Bianconi 558eb99cc95SLorenzo Bianconi /* usb */ 55990520afbSLorenzo Bianconi int mt7663_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 56090520afbSLorenzo Bianconi enum mt76_txq_id qid, struct mt76_wcid *wcid, 56190520afbSLorenzo Bianconi struct ieee80211_sta *sta, 56290520afbSLorenzo Bianconi struct mt76_tx_info *tx_info); 56390520afbSLorenzo Bianconi bool mt7663_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update); 56490520afbSLorenzo Bianconi void mt7663_usb_sdio_tx_complete_skb(struct mt76_dev *mdev, 56590520afbSLorenzo Bianconi struct mt76_queue_entry *e); 56690520afbSLorenzo Bianconi int mt7663_usb_sdio_register_device(struct mt7615_dev *dev); 567eb99cc95SLorenzo Bianconi int mt7663u_mcu_init(struct mt7615_dev *dev); 568eb99cc95SLorenzo Bianconi 569a66cbdd6SSean Wang /* sdio */ 570a66cbdd6SSean Wang u32 mt7663s_read_pcr(struct mt7615_dev *dev); 571a66cbdd6SSean Wang int mt7663s_mcu_init(struct mt7615_dev *dev); 572fefb584dSLorenzo Bianconi void mt7663s_txrx_worker(struct mt76_worker *w); 5733e5f374dSLorenzo Bianconi void mt7663s_rx_work(struct work_struct *work); 574a66cbdd6SSean Wang void mt7663s_sdio_irq(struct sdio_func *func); 575a66cbdd6SSean Wang 57604b8e659SRyder Lee #endif 577