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 704b8e659SRyder Lee #include <linux/interrupt.h> 804b8e659SRyder Lee #include <linux/ktime.h> 935da599fSFelix Fietkau #include <linux/regmap.h> 1004b8e659SRyder Lee #include "../mt76.h" 1104b8e659SRyder Lee #include "regs.h" 1204b8e659SRyder Lee 1304b8e659SRyder Lee #define MT7615_MAX_INTERFACES 4 1449f1132cSRyder Lee #define MT7615_MAX_WMM_SETS 4 158f997dddSLorenzo Bianconi #define MT7663_WTBL_SIZE 32 1604b8e659SRyder Lee #define MT7615_WTBL_SIZE 128 178f997dddSLorenzo Bianconi #define MT7615_WTBL_RESERVED (mt7615_wtbl_size(dev) - 1) 1804b8e659SRyder Lee #define MT7615_WTBL_STA (MT7615_WTBL_RESERVED - \ 1904b8e659SRyder Lee MT7615_MAX_INTERFACES) 2004b8e659SRyder Lee 21457d19c7SLorenzo Bianconi #define MT7615_WATCHDOG_TIME (HZ / 10) 22fcdfc29eSLorenzo Bianconi #define MT7615_HW_SCAN_TIMEOUT (HZ / 10) 2361c4fa72SFelix Fietkau #define MT7615_RESET_TIMEOUT (30 * HZ) 2404b8e659SRyder Lee #define MT7615_RATE_RETRY 2 2504b8e659SRyder Lee 2604b8e659SRyder Lee #define MT7615_TX_RING_SIZE 1024 27cdad4874SFelix Fietkau #define MT7615_TX_MGMT_RING_SIZE 128 2804b8e659SRyder Lee #define MT7615_TX_MCU_RING_SIZE 128 2904b8e659SRyder Lee #define MT7615_TX_FWDL_RING_SIZE 128 3004b8e659SRyder Lee 3104b8e659SRyder Lee #define MT7615_RX_RING_SIZE 1024 3204b8e659SRyder Lee #define MT7615_RX_MCU_RING_SIZE 512 3304b8e659SRyder Lee 349d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_CR4 "mediatek/mt7615_cr4.bin" 359d4d0d06SLorenzo Bianconi #define MT7615_FIRMWARE_N9 "mediatek/mt7615_n9.bin" 369d4d0d06SLorenzo Bianconi #define MT7615_ROM_PATCH "mediatek/mt7615_rom_patch.bin" 3704b8e659SRyder Lee 3835da599fSFelix Fietkau #define MT7622_FIRMWARE_N9 "mediatek/mt7622_n9.bin" 3935da599fSFelix Fietkau #define MT7622_ROM_PATCH "mediatek/mt7622_rom_patch.bin" 4035da599fSFelix Fietkau 416849e29eSRyder Lee #define MT7615_FIRMWARE_V1 1 426849e29eSRyder Lee #define MT7615_FIRMWARE_V2 2 43f40ac0f3SLorenzo Bianconi #define MT7615_FIRMWARE_V3 3 44f40ac0f3SLorenzo Bianconi 45f2dc8ea1SLorenzo Bianconi #define MT7663_OFFLOAD_ROM_PATCH "mediatek/mt7663pr2h.bin" 46f2dc8ea1SLorenzo Bianconi #define MT7663_OFFLOAD_FIRMWARE_N9 "mediatek/mt7663_n9_v3.bin" 47f2dc8ea1SLorenzo Bianconi #define MT7663_ROM_PATCH "mediatek/mt7663pr2h_rebb.bin" 48f2dc8ea1SLorenzo Bianconi #define MT7663_FIRMWARE_N9 "mediatek/mt7663_n9_rebb.bin" 496849e29eSRyder Lee 5004b8e659SRyder Lee #define MT7615_EEPROM_SIZE 1024 5104b8e659SRyder Lee #define MT7615_TOKEN_SIZE 4096 5204b8e659SRyder Lee 5349de79adSLorenzo Bianconi #define MT_FRAC_SCALE 12 5449de79adSLorenzo Bianconi #define MT_FRAC(val, div) (((val) << MT_FRAC_SCALE) / (div)) 5549de79adSLorenzo Bianconi 5627ae7219SFelix Fietkau #define MT_CHFREQ_VALID BIT(7) 5727ae7219SFelix Fietkau #define MT_CHFREQ_DBDC_IDX BIT(6) 5827ae7219SFelix Fietkau #define MT_CHFREQ_SEQ GENMASK(5, 0) 5927ae7219SFelix Fietkau 60a25c888fSRyder Lee #define MT7615_BAR_RATE_DEFAULT 0x4b /* OFDM 6M */ 61a25c888fSRyder Lee #define MT7615_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ 62183d1fcfSLorenzo Bianconi #define MT7615_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ 63183d1fcfSLorenzo Bianconi 64fcdfc29eSLorenzo Bianconi #define MT7615_SCAN_IE_LEN 600 6520305f98SLorenzo Bianconi #define MT7615_MAX_SCHED_SCAN_INTERVAL 10 6620305f98SLorenzo Bianconi #define MT7615_MAX_SCHED_SCAN_SSID 10 6720305f98SLorenzo Bianconi #define MT7615_MAX_SCAN_MATCH 16 68fcdfc29eSLorenzo Bianconi 6904b8e659SRyder Lee struct mt7615_vif; 7004b8e659SRyder Lee struct mt7615_sta; 712ce73efeSLorenzo Bianconi struct mt7615_dfs_pulse; 722ce73efeSLorenzo Bianconi struct mt7615_dfs_pattern; 73294f17aeSLorenzo Bianconi enum mt7615_cipher_type; 7404b8e659SRyder Lee 7504b8e659SRyder Lee enum mt7615_hw_txq_id { 7604b8e659SRyder Lee MT7615_TXQ_MAIN, 7704b8e659SRyder Lee MT7615_TXQ_EXT, 7804b8e659SRyder Lee MT7615_TXQ_MCU, 7904b8e659SRyder Lee MT7615_TXQ_FWDL, 8004b8e659SRyder Lee }; 8104b8e659SRyder Lee 82cdad4874SFelix Fietkau enum mt7622_hw_txq_id { 83cdad4874SFelix Fietkau MT7622_TXQ_AC0, 84cdad4874SFelix Fietkau MT7622_TXQ_AC1, 85cdad4874SFelix Fietkau MT7622_TXQ_AC2, 86cdad4874SFelix Fietkau MT7622_TXQ_FWDL = MT7615_TXQ_FWDL, 87cdad4874SFelix Fietkau MT7622_TXQ_AC3, 88cdad4874SFelix Fietkau MT7622_TXQ_MGMT, 89cdad4874SFelix Fietkau MT7622_TXQ_MCU = 15, 90cdad4874SFelix Fietkau }; 91cdad4874SFelix Fietkau 924af81f02SFelix Fietkau struct mt7615_rate_set { 934af81f02SFelix Fietkau struct ieee80211_tx_rate probe_rate; 944af81f02SFelix Fietkau struct ieee80211_tx_rate rates[4]; 954af81f02SFelix Fietkau }; 964af81f02SFelix Fietkau 978f93af9cSLorenzo Bianconi struct mt7615_rate_desc { 988f93af9cSLorenzo Bianconi bool rateset; 998f93af9cSLorenzo Bianconi u16 probe_val; 1008f93af9cSLorenzo Bianconi u16 val[4]; 1018f93af9cSLorenzo Bianconi u8 bw_idx; 1028f93af9cSLorenzo Bianconi u8 bw; 1038f93af9cSLorenzo Bianconi }; 1048f93af9cSLorenzo Bianconi 1057d9f1d10SLorenzo Bianconi enum mt7615_wtbl_desc_type { 1067d9f1d10SLorenzo Bianconi MT7615_WTBL_RATE_DESC, 1077d9f1d10SLorenzo Bianconi MT7615_WTBL_KEY_DESC 1087d9f1d10SLorenzo Bianconi }; 1097d9f1d10SLorenzo Bianconi 1107d9f1d10SLorenzo Bianconi struct mt7615_key_desc { 1117d9f1d10SLorenzo Bianconi enum set_key_cmd cmd; 1127d9f1d10SLorenzo Bianconi u32 cipher; 1137d9f1d10SLorenzo Bianconi s8 keyidx; 1147d9f1d10SLorenzo Bianconi u8 keylen; 1157d9f1d10SLorenzo Bianconi u8 *key; 1167d9f1d10SLorenzo Bianconi }; 1177d9f1d10SLorenzo Bianconi 1187d9f1d10SLorenzo Bianconi struct mt7615_wtbl_desc { 1197d9f1d10SLorenzo Bianconi struct list_head node; 1207d9f1d10SLorenzo Bianconi 1217d9f1d10SLorenzo Bianconi enum mt7615_wtbl_desc_type type; 1227d9f1d10SLorenzo Bianconi struct mt7615_sta *sta; 1237d9f1d10SLorenzo Bianconi 1247d9f1d10SLorenzo Bianconi union { 1257d9f1d10SLorenzo Bianconi struct mt7615_rate_desc rate; 1267d9f1d10SLorenzo Bianconi struct mt7615_key_desc key; 1277d9f1d10SLorenzo Bianconi }; 1287d9f1d10SLorenzo Bianconi }; 1297d9f1d10SLorenzo Bianconi 13004b8e659SRyder Lee struct mt7615_sta { 13104b8e659SRyder Lee struct mt76_wcid wcid; /* must be first */ 13204b8e659SRyder Lee 13304b8e659SRyder Lee struct mt7615_vif *vif; 13404b8e659SRyder Lee 135b2c2f029SLorenzo Bianconi struct list_head poll_list; 136b2c2f029SLorenzo Bianconi u32 airtime_ac[8]; 137b2c2f029SLorenzo Bianconi 1384af81f02SFelix Fietkau struct ieee80211_tx_rate rates[4]; 1394af81f02SFelix Fietkau 1404af81f02SFelix Fietkau struct mt7615_rate_set rateset[2]; 1414af81f02SFelix Fietkau u32 rate_set_tsf; 1424af81f02SFelix Fietkau 14304b8e659SRyder Lee u8 rate_count; 14404b8e659SRyder Lee u8 n_rates; 14504b8e659SRyder Lee 14604b8e659SRyder Lee u8 rate_probe; 14704b8e659SRyder Lee }; 14804b8e659SRyder Lee 14904b8e659SRyder Lee struct mt7615_vif { 15004b8e659SRyder Lee u8 idx; 15104b8e659SRyder Lee u8 omac_idx; 15204b8e659SRyder Lee u8 band_idx; 15304b8e659SRyder Lee u8 wmm_idx; 154fcdfc29eSLorenzo Bianconi u8 scan_seq_num; 15504b8e659SRyder Lee 15604b8e659SRyder Lee struct mt7615_sta sta; 15704b8e659SRyder Lee }; 15804b8e659SRyder Lee 159679b23feSRyder Lee struct mib_stats { 160b7825ca0SRyder Lee u16 ack_fail_cnt; 161b7825ca0SRyder Lee u16 fcs_err_cnt; 162b7825ca0SRyder Lee u16 rts_cnt; 163b7825ca0SRyder Lee u16 rts_retries_cnt; 164aef16345SRyder Lee u16 ba_miss_cnt; 165aef16345SRyder Lee unsigned long aggr_per; 166679b23feSRyder Lee }; 167679b23feSRyder Lee 168fdd2e570SFelix Fietkau struct mt7615_phy { 169fdd2e570SFelix Fietkau struct mt76_phy *mt76; 170fdd2e570SFelix Fietkau struct mt7615_dev *dev; 171fdd2e570SFelix Fietkau 172fdd2e570SFelix Fietkau u32 rxfilter; 173ac3ef85cSFelix Fietkau u32 omac_mask; 174d446a20fSFelix Fietkau 175e5051965SFelix Fietkau u16 noise; 176e5051965SFelix Fietkau 177594034b7SLorenzo Bianconi bool scs_en; 178594034b7SLorenzo Bianconi 179d446a20fSFelix Fietkau unsigned long last_cca_adj; 180d446a20fSFelix Fietkau int false_cca_ofdm, false_cca_cck; 181d446a20fSFelix Fietkau s8 ofdm_sensitivity; 182d446a20fSFelix Fietkau s8 cck_sensitivity; 1835dabdf71SFelix Fietkau 1842bed2a3eSFelix Fietkau u16 chainmask; 1852bed2a3eSFelix Fietkau 186183d1fcfSLorenzo Bianconi s16 coverage_class; 187183d1fcfSLorenzo Bianconi u8 slottime; 188183d1fcfSLorenzo Bianconi 1890e544cb5SFelix Fietkau u8 chfreq; 1905dabdf71SFelix Fietkau u8 rdd_state; 1915dabdf71SFelix Fietkau int dfs_state; 19227ae7219SFelix Fietkau 19327ae7219SFelix Fietkau __le32 rx_ampdu_ts; 19427ae7219SFelix Fietkau u32 ampdu_ref; 195679b23feSRyder Lee 196679b23feSRyder Lee struct mib_stats mib; 197fcdfc29eSLorenzo Bianconi 1984fcf6e77SLorenzo Bianconi struct delayed_work mac_work; 1994fcf6e77SLorenzo Bianconi u8 mac_work_count; 2004fcf6e77SLorenzo Bianconi 20120305f98SLorenzo Bianconi struct sk_buff_head scan_event_list; 202fcdfc29eSLorenzo Bianconi struct delayed_work scan_work; 2037f8ebafeSLorenzo Bianconi 2047307f296SLorenzo Bianconi struct work_struct roc_work; 2057307f296SLorenzo Bianconi struct timer_list roc_timer; 2067307f296SLorenzo Bianconi wait_queue_head_t roc_wait; 2077307f296SLorenzo Bianconi bool roc_grant; 208fdd2e570SFelix Fietkau }; 209fdd2e570SFelix Fietkau 2106f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_tx_ba(dev, ...) (dev)->mcu_ops->add_tx_ba((dev), __VA_ARGS__) 2116f4d7cc8SLorenzo Bianconi #define mt7615_mcu_add_rx_ba(dev, ...) (dev)->mcu_ops->add_rx_ba((dev), __VA_ARGS__) 21299c457d9SLorenzo Bianconi #define mt7615_mcu_sta_add(dev, ...) (dev)->mcu_ops->sta_add((dev), __VA_ARGS__) 213062c3699SLorenzo Bianconi #define mt7615_mcu_add_dev_info(dev, ...) (dev)->mcu_ops->add_dev_info((dev), __VA_ARGS__) 2145d3a4a4bSLorenzo Bianconi #define mt7615_mcu_add_bss_info(phy, ...) (phy->dev)->mcu_ops->add_bss_info((phy), __VA_ARGS__) 215062c3699SLorenzo Bianconi #define mt7615_mcu_add_beacon(dev, ...) (dev)->mcu_ops->add_beacon_offload((dev), __VA_ARGS__) 216062c3699SLorenzo Bianconi #define mt7615_mcu_set_pm(dev, ...) (dev)->mcu_ops->set_pm_state((dev), __VA_ARGS__) 2176f4d7cc8SLorenzo Bianconi struct mt7615_mcu_ops { 2186f4d7cc8SLorenzo Bianconi int (*add_tx_ba)(struct mt7615_dev *dev, 2196f4d7cc8SLorenzo Bianconi struct ieee80211_ampdu_params *params, 2206f4d7cc8SLorenzo Bianconi bool enable); 2216f4d7cc8SLorenzo Bianconi int (*add_rx_ba)(struct mt7615_dev *dev, 2226f4d7cc8SLorenzo Bianconi struct ieee80211_ampdu_params *params, 2236f4d7cc8SLorenzo Bianconi bool enable); 22499c457d9SLorenzo Bianconi int (*sta_add)(struct mt7615_dev *dev, 22599c457d9SLorenzo Bianconi struct ieee80211_vif *vif, 22699c457d9SLorenzo Bianconi struct ieee80211_sta *sta, bool enable); 227062c3699SLorenzo Bianconi int (*add_dev_info)(struct mt7615_dev *dev, 228062c3699SLorenzo Bianconi struct ieee80211_vif *vif, bool enable); 2295d3a4a4bSLorenzo Bianconi int (*add_bss_info)(struct mt7615_phy *phy, struct ieee80211_vif *vif, 230f5596850SLorenzo Bianconi struct ieee80211_sta *sta, bool enable); 231062c3699SLorenzo Bianconi int (*add_beacon_offload)(struct mt7615_dev *dev, 232062c3699SLorenzo Bianconi struct ieee80211_hw *hw, 233062c3699SLorenzo Bianconi struct ieee80211_vif *vif, bool enable); 234062c3699SLorenzo Bianconi int (*set_pm_state)(struct mt7615_dev *dev, int band, int state); 2356f4d7cc8SLorenzo Bianconi }; 2366f4d7cc8SLorenzo Bianconi 23704b8e659SRyder Lee struct mt7615_dev { 238ac24dd35SFelix Fietkau union { /* must be first */ 239ac24dd35SFelix Fietkau struct mt76_dev mt76; 240ac24dd35SFelix Fietkau struct mt76_phy mphy; 241ac24dd35SFelix Fietkau }; 242ac24dd35SFelix Fietkau 243557b5a17SFelix Fietkau const struct mt76_bus_ops *bus_ops; 2449b90ab32SFelix Fietkau struct tasklet_struct irq_tasklet; 2459b90ab32SFelix Fietkau 246fdd2e570SFelix Fietkau struct mt7615_phy phy; 24704b8e659SRyder Lee u32 vif_mask; 24804b8e659SRyder Lee u32 omac_mask; 24904b8e659SRyder Lee 2500f2173f0SFelix Fietkau u16 chainmask; 2510f2173f0SFelix Fietkau 252635cb010SFelix Fietkau struct ieee80211_ops *ops; 2536f4d7cc8SLorenzo Bianconi const struct mt7615_mcu_ops *mcu_ops; 25435da599fSFelix Fietkau struct regmap *infracfg; 25594f83b66SLorenzo Bianconi const u32 *reg_map; 25635da599fSFelix Fietkau 257c3c25d09SFelix Fietkau struct work_struct mcu_work; 258c3c25d09SFelix Fietkau 25961c4fa72SFelix Fietkau struct work_struct reset_work; 26061c4fa72SFelix Fietkau wait_queue_head_t reset_wait; 26161c4fa72SFelix Fietkau u32 reset_state; 26261c4fa72SFelix Fietkau 263b2c2f029SLorenzo Bianconi struct list_head sta_poll_list; 264b2c2f029SLorenzo Bianconi spinlock_t sta_poll_lock; 265b2c2f029SLorenzo Bianconi 26670911d96SLorenzo Bianconi struct { 26770911d96SLorenzo Bianconi u8 n_pulses; 26870911d96SLorenzo Bianconi u32 period; 26970911d96SLorenzo Bianconi u16 width; 27070911d96SLorenzo Bianconi s16 power; 27170911d96SLorenzo Bianconi } radar_pattern; 272d67a6646SLorenzo Bianconi u32 hw_pattern; 273d67a6646SLorenzo Bianconi 274f347f81aSFelix Fietkau bool fw_debug; 275ad380ad1SFelix Fietkau bool flash_eeprom; 27649de79adSLorenzo Bianconi 27704b8e659SRyder Lee spinlock_t token_lock; 27804b8e659SRyder Lee struct idr token; 2796849e29eSRyder Lee 2806849e29eSRyder Lee u8 fw_ver; 281eb99cc95SLorenzo Bianconi 282eb99cc95SLorenzo Bianconi struct work_struct wtbl_work; 283eb99cc95SLorenzo Bianconi struct list_head wd_head; 284dc804058SFelix Fietkau 285dc804058SFelix Fietkau u32 debugfs_rf_wf; 286dc804058SFelix Fietkau u32 debugfs_rf_reg; 28704b8e659SRyder Lee }; 28804b8e659SRyder Lee 2891fec635bSLorenzo Bianconi enum tx_pkt_queue_idx { 2901fec635bSLorenzo Bianconi MT_LMAC_AC00, 2911fec635bSLorenzo Bianconi MT_LMAC_AC01, 2921fec635bSLorenzo Bianconi MT_LMAC_AC02, 2931fec635bSLorenzo Bianconi MT_LMAC_AC03, 2941fec635bSLorenzo Bianconi MT_LMAC_ALTX0 = 0x10, 2951fec635bSLorenzo Bianconi MT_LMAC_BMC0, 2961fec635bSLorenzo Bianconi MT_LMAC_BCN0, 2971fec635bSLorenzo Bianconi MT_LMAC_PSMP0, 2981fec635bSLorenzo Bianconi MT_LMAC_ALTX1, 2991fec635bSLorenzo Bianconi MT_LMAC_BMC1, 3001fec635bSLorenzo Bianconi MT_LMAC_BCN1, 3011fec635bSLorenzo Bianconi MT_LMAC_PSMP1, 3021fec635bSLorenzo Bianconi }; 3031fec635bSLorenzo Bianconi 30404b8e659SRyder Lee enum { 30504b8e659SRyder Lee HW_BSSID_0 = 0x0, 30604b8e659SRyder Lee HW_BSSID_1, 30704b8e659SRyder Lee HW_BSSID_2, 30804b8e659SRyder Lee HW_BSSID_3, 30904b8e659SRyder Lee HW_BSSID_MAX, 31004b8e659SRyder Lee EXT_BSSID_START = 0x10, 31104b8e659SRyder Lee EXT_BSSID_1, 31204b8e659SRyder Lee EXT_BSSID_2, 31304b8e659SRyder Lee EXT_BSSID_3, 31404b8e659SRyder Lee EXT_BSSID_4, 31504b8e659SRyder Lee EXT_BSSID_5, 31604b8e659SRyder Lee EXT_BSSID_6, 31704b8e659SRyder Lee EXT_BSSID_7, 31804b8e659SRyder Lee EXT_BSSID_8, 31904b8e659SRyder Lee EXT_BSSID_9, 32004b8e659SRyder Lee EXT_BSSID_10, 32104b8e659SRyder Lee EXT_BSSID_11, 32204b8e659SRyder Lee EXT_BSSID_12, 32304b8e659SRyder Lee EXT_BSSID_13, 32404b8e659SRyder Lee EXT_BSSID_14, 32504b8e659SRyder Lee EXT_BSSID_15, 32604b8e659SRyder Lee EXT_BSSID_END 32704b8e659SRyder Lee }; 32804b8e659SRyder Lee 329d67a6646SLorenzo Bianconi enum { 330d67a6646SLorenzo Bianconi MT_RX_SEL0, 331d67a6646SLorenzo Bianconi MT_RX_SEL1, 332d67a6646SLorenzo Bianconi }; 333d67a6646SLorenzo Bianconi 334d67a6646SLorenzo Bianconi enum mt7615_rdd_cmd { 335d67a6646SLorenzo Bianconi RDD_STOP, 336d67a6646SLorenzo Bianconi RDD_START, 337d67a6646SLorenzo Bianconi RDD_DET_MODE, 338d67a6646SLorenzo Bianconi RDD_DET_STOP, 339d67a6646SLorenzo Bianconi RDD_CAC_START, 340d67a6646SLorenzo Bianconi RDD_CAC_END, 341d67a6646SLorenzo Bianconi RDD_NORMAL_START, 342d67a6646SLorenzo Bianconi RDD_DISABLE_DFS_CAL, 343d67a6646SLorenzo Bianconi RDD_PULSE_DBG, 344d67a6646SLorenzo Bianconi RDD_READ_PULSE, 345d67a6646SLorenzo Bianconi RDD_RESUME_BF, 346d67a6646SLorenzo Bianconi }; 347d67a6646SLorenzo Bianconi 348fdd2e570SFelix Fietkau static inline struct mt7615_phy * 349fdd2e570SFelix Fietkau mt7615_hw_phy(struct ieee80211_hw *hw) 350fdd2e570SFelix Fietkau { 351fdd2e570SFelix Fietkau struct mt76_phy *phy = hw->priv; 352fdd2e570SFelix Fietkau 353fdd2e570SFelix Fietkau return phy->priv; 354fdd2e570SFelix Fietkau } 355fdd2e570SFelix Fietkau 356fdd2e570SFelix Fietkau static inline struct mt7615_dev * 357fdd2e570SFelix Fietkau mt7615_hw_dev(struct ieee80211_hw *hw) 358fdd2e570SFelix Fietkau { 359fdd2e570SFelix Fietkau struct mt76_phy *phy = hw->priv; 360fdd2e570SFelix Fietkau 361fdd2e570SFelix Fietkau return container_of(phy->dev, struct mt7615_dev, mt76); 362fdd2e570SFelix Fietkau } 363fdd2e570SFelix Fietkau 364fdd2e570SFelix Fietkau static inline struct mt7615_phy * 365fdd2e570SFelix Fietkau mt7615_ext_phy(struct mt7615_dev *dev) 366fdd2e570SFelix Fietkau { 367fdd2e570SFelix Fietkau struct mt76_phy *phy = dev->mt76.phy2; 368fdd2e570SFelix Fietkau 369fdd2e570SFelix Fietkau if (!phy) 370fdd2e570SFelix Fietkau return NULL; 371fdd2e570SFelix Fietkau 372fdd2e570SFelix Fietkau return phy->priv; 373fdd2e570SFelix Fietkau } 374fdd2e570SFelix Fietkau 375e90354e0SLorenzo Bianconi extern struct ieee80211_rate mt7615_rates[12]; 37604b8e659SRyder Lee extern const struct ieee80211_ops mt7615_ops; 37794f83b66SLorenzo Bianconi extern const u32 mt7615e_reg_map[__MT_BASE_MAX]; 378f40ac0f3SLorenzo Bianconi extern const u32 mt7663e_reg_map[__MT_BASE_MAX]; 37904b8e659SRyder Lee extern struct pci_driver mt7615_pci_driver; 38035da599fSFelix Fietkau extern struct platform_driver mt7622_wmac_driver; 38135da599fSFelix Fietkau 38235da599fSFelix Fietkau #ifdef CONFIG_MT7622_WMAC 38335da599fSFelix Fietkau int mt7622_wmac_init(struct mt7615_dev *dev); 38435da599fSFelix Fietkau #else 38535da599fSFelix Fietkau static inline int mt7622_wmac_init(struct mt7615_dev *dev) 38635da599fSFelix Fietkau { 38735da599fSFelix Fietkau return 0; 38835da599fSFelix Fietkau } 38935da599fSFelix Fietkau #endif 39004b8e659SRyder Lee 39194f83b66SLorenzo Bianconi int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base, 39294f83b66SLorenzo Bianconi int irq, const u32 *map); 39304b8e659SRyder Lee u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr); 39404b8e659SRyder Lee 39553b42ae2SLorenzo Bianconi void mt7615_check_offload_capability(struct mt7615_dev *dev); 3962ee920c2SLorenzo Bianconi void mt7615_init_device(struct mt7615_dev *dev); 39704b8e659SRyder Lee int mt7615_register_device(struct mt7615_dev *dev); 39804b8e659SRyder Lee void mt7615_unregister_device(struct mt7615_dev *dev); 3990f2173f0SFelix Fietkau int mt7615_register_ext_phy(struct mt7615_dev *dev); 4000f2173f0SFelix Fietkau void mt7615_unregister_ext_phy(struct mt7615_dev *dev); 4016e5d2099SLorenzo Bianconi int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr); 402e0ec633dSLorenzo Bianconi int mt7615_eeprom_get_target_power_index(struct mt7615_dev *dev, 40316a2f8e2SLorenzo Bianconi struct ieee80211_channel *chan, 40461d36824SLorenzo Bianconi u8 chain_idx); 405c88bf52bSLorenzo Bianconi int mt7615_eeprom_get_power_delta_index(struct mt7615_dev *dev, 406c88bf52bSLorenzo Bianconi enum nl80211_band band); 4076dd4072cSLorenzo Bianconi int mt7615_wait_pdma_busy(struct mt7615_dev *dev); 40804b8e659SRyder Lee int mt7615_dma_init(struct mt7615_dev *dev); 40904b8e659SRyder Lee void mt7615_dma_cleanup(struct mt7615_dev *dev); 41004b8e659SRyder Lee int mt7615_mcu_init(struct mt7615_dev *dev); 411c3c25d09SFelix Fietkau bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev); 412fdd2e570SFelix Fietkau void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta, 41304b8e659SRyder Lee struct ieee80211_tx_rate *probe_rate, 41404b8e659SRyder Lee struct ieee80211_tx_rate *rates); 41504b8e659SRyder Lee int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev); 4164fe9218cSRyder Lee int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd); 41704b8e659SRyder Lee int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue, 41804b8e659SRyder Lee const struct ieee80211_tx_queue_params *params); 419d67a6646SLorenzo Bianconi void mt7615_mcu_rx_event(struct mt7615_dev *dev, struct sk_buff *skb); 420d67a6646SLorenzo Bianconi int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev, 421d67a6646SLorenzo Bianconi enum mt7615_rdd_cmd cmd, u8 index, 422d67a6646SLorenzo Bianconi u8 rx_sel, u8 val); 42370911d96SLorenzo Bianconi int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev); 424f347f81aSFelix Fietkau int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl); 425d67a6646SLorenzo Bianconi 42649de79adSLorenzo Bianconi static inline bool is_mt7622(struct mt76_dev *dev) 42749de79adSLorenzo Bianconi { 42835da599fSFelix Fietkau if (!IS_ENABLED(CONFIG_MT7622_WMAC)) 42935da599fSFelix Fietkau return false; 43035da599fSFelix Fietkau 43149de79adSLorenzo Bianconi return mt76_chip(dev) == 0x7622; 43249de79adSLorenzo Bianconi } 43349de79adSLorenzo Bianconi 434cdad4874SFelix Fietkau static inline bool is_mt7615(struct mt76_dev *dev) 435cdad4874SFelix Fietkau { 436e47f2245SDENG Qingfang return mt76_chip(dev) == 0x7615 || mt76_chip(dev) == 0x7611; 437cdad4874SFelix Fietkau } 438cdad4874SFelix Fietkau 439f82282efSLorenzo Bianconi static inline bool is_mt7663(struct mt76_dev *dev) 440f82282efSLorenzo Bianconi { 441f82282efSLorenzo Bianconi return mt76_chip(dev) == 0x7663; 442f82282efSLorenzo Bianconi } 443f82282efSLorenzo Bianconi 444e47f2245SDENG Qingfang static inline bool is_mt7611(struct mt76_dev *dev) 445e47f2245SDENG Qingfang { 446e47f2245SDENG Qingfang return mt76_chip(dev) == 0x7611; 447e47f2245SDENG Qingfang } 448e47f2245SDENG Qingfang 44904b8e659SRyder Lee static inline void mt7615_irq_enable(struct mt7615_dev *dev, u32 mask) 45004b8e659SRyder Lee { 4519b90ab32SFelix Fietkau mt76_set_irq_mask(&dev->mt76, 0, 0, mask); 45204b8e659SRyder Lee 4539b90ab32SFelix Fietkau tasklet_schedule(&dev->irq_tasklet); 45404b8e659SRyder Lee } 45504b8e659SRyder Lee 456bf18fcdcSLorenzo Bianconi static inline bool mt7615_firmware_offload(struct mt7615_dev *dev) 457bf18fcdcSLorenzo Bianconi { 458bf18fcdcSLorenzo Bianconi return dev->fw_ver > MT7615_FIRMWARE_V2; 459bf18fcdcSLorenzo Bianconi } 460bf18fcdcSLorenzo Bianconi 4618f997dddSLorenzo Bianconi static inline u16 mt7615_wtbl_size(struct mt7615_dev *dev) 4628f997dddSLorenzo Bianconi { 4638f997dddSLorenzo Bianconi if (is_mt7663(&dev->mt76) && mt7615_firmware_offload(dev)) 4648f997dddSLorenzo Bianconi return MT7663_WTBL_SIZE; 4658f997dddSLorenzo Bianconi else 4668f997dddSLorenzo Bianconi return MT7615_WTBL_SIZE; 4678f997dddSLorenzo Bianconi } 4688f997dddSLorenzo Bianconi 4691fec635bSLorenzo Bianconi static inline u8 mt7615_lmac_mapping(struct mt7615_dev *dev, u8 ac) 4701fec635bSLorenzo Bianconi { 4711fec635bSLorenzo Bianconi static const u8 lmac_queue_map[] = { 4721fec635bSLorenzo Bianconi [IEEE80211_AC_BK] = MT_LMAC_AC00, 4731fec635bSLorenzo Bianconi [IEEE80211_AC_BE] = MT_LMAC_AC01, 4741fec635bSLorenzo Bianconi [IEEE80211_AC_VI] = MT_LMAC_AC02, 4751fec635bSLorenzo Bianconi [IEEE80211_AC_VO] = MT_LMAC_AC03, 4761fec635bSLorenzo Bianconi }; 4771fec635bSLorenzo Bianconi 4781fec635bSLorenzo Bianconi if (WARN_ON_ONCE(ac >= ARRAY_SIZE(lmac_queue_map))) 4791fec635bSLorenzo Bianconi return MT_LMAC_AC01; /* BE */ 4801fec635bSLorenzo Bianconi 4811fec635bSLorenzo Bianconi return lmac_queue_map[ac]; 4821fec635bSLorenzo Bianconi } 4831fec635bSLorenzo Bianconi 4846dd4072cSLorenzo Bianconi void mt7615_dma_reset(struct mt7615_dev *dev); 485fcdfc29eSLorenzo Bianconi void mt7615_scan_work(struct work_struct *work); 4867307f296SLorenzo Bianconi void mt7615_roc_work(struct work_struct *work); 4877307f296SLorenzo Bianconi void mt7615_roc_timer(struct timer_list *timer); 488e90354e0SLorenzo Bianconi void mt7615_init_txpower(struct mt7615_dev *dev, 489e90354e0SLorenzo Bianconi struct ieee80211_supported_band *sband); 490e90354e0SLorenzo Bianconi void mt7615_phy_init(struct mt7615_dev *dev); 491e90354e0SLorenzo Bianconi void mt7615_mac_init(struct mt7615_dev *dev); 492e90354e0SLorenzo Bianconi 493e90354e0SLorenzo Bianconi int mt7615_mcu_restart(struct mt76_dev *dev); 494863c15a1SLorenzo Bianconi void mt7615_update_channel(struct mt76_dev *mdev); 49587d3cdebSLorenzo Bianconi bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask); 49675601194SLorenzo Bianconi void mt7615_mac_reset_counters(struct mt7615_dev *dev); 497d446a20fSFelix Fietkau void mt7615_mac_cca_stats_reset(struct mt7615_phy *phy); 498594034b7SLorenzo Bianconi void mt7615_mac_set_scs(struct mt7615_phy *phy, bool enable); 499e5051965SFelix Fietkau void mt7615_mac_enable_nf(struct mt7615_dev *dev, bool ext_phy); 500b2c2f029SLorenzo Bianconi void mt7615_mac_sta_poll(struct mt7615_dev *dev); 50104b8e659SRyder Lee int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi, 50204b8e659SRyder Lee struct sk_buff *skb, struct mt76_wcid *wcid, 50304b8e659SRyder Lee struct ieee80211_sta *sta, int pid, 504c984457bSFelix Fietkau struct ieee80211_key_conf *key, bool beacon); 505183d1fcfSLorenzo Bianconi void mt7615_mac_set_timing(struct mt7615_phy *phy); 50627b8a900SLorenzo Bianconi int mt7615_mac_wtbl_set_key(struct mt7615_dev *dev, struct mt76_wcid *wcid, 50727b8a900SLorenzo Bianconi struct ieee80211_key_conf *key, 50827b8a900SLorenzo Bianconi enum set_key_cmd cmd); 509294f17aeSLorenzo Bianconi int mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev, 510294f17aeSLorenzo Bianconi struct mt76_wcid *wcid, 511294f17aeSLorenzo Bianconi enum mt7615_cipher_type cipher, 512294f17aeSLorenzo Bianconi int keyidx, enum set_key_cmd cmd); 513294f17aeSLorenzo Bianconi void mt7615_mac_wtbl_update_cipher(struct mt7615_dev *dev, 514294f17aeSLorenzo Bianconi struct mt76_wcid *wcid, 515294f17aeSLorenzo Bianconi enum mt7615_cipher_type cipher, 516294f17aeSLorenzo Bianconi enum set_key_cmd cmd); 517294f17aeSLorenzo Bianconi int mt7615_mac_wtbl_update_key(struct mt7615_dev *dev, 518294f17aeSLorenzo Bianconi struct mt76_wcid *wcid, 519294f17aeSLorenzo Bianconi u8 *key, u8 keylen, 520294f17aeSLorenzo Bianconi enum mt7615_cipher_type cipher, 521294f17aeSLorenzo Bianconi enum set_key_cmd cmd); 52261c4fa72SFelix Fietkau void mt7615_mac_reset_work(struct work_struct *work); 523a28bef56SFelix Fietkau u32 mt7615_mac_get_sta_tid_sn(struct mt7615_dev *dev, int wcid, u8 tid); 52404b8e659SRyder Lee 525b899150eSLorenzo Bianconi int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq); 526e90354e0SLorenzo Bianconi int mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data, 527e90354e0SLorenzo Bianconi int len, bool wait_resp); 528dc804058SFelix Fietkau u32 mt7615_rf_rr(struct mt7615_dev *dev, u32 wf, u32 reg); 529dc804058SFelix Fietkau int mt7615_rf_wr(struct mt7615_dev *dev, u32 wf, u32 reg, u32 val); 530ac3ef85cSFelix Fietkau int mt7615_mcu_set_dbdc(struct mt7615_dev *dev); 53104b8e659SRyder Lee int mt7615_mcu_set_eeprom(struct mt7615_dev *dev); 532b0b5426eSFelix Fietkau int mt7615_mcu_set_mac_enable(struct mt7615_dev *dev, int band, bool enable); 533fdd2e570SFelix Fietkau int mt7615_mcu_set_rts_thresh(struct mt7615_phy *phy, u32 val); 5340e6a29e4SLorenzo Bianconi int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index); 53504b8e659SRyder Lee void mt7615_mcu_exit(struct mt7615_dev *dev); 53663f09b6bSLorenzo Bianconi void mt7615_mcu_fill_msg(struct mt7615_dev *dev, struct sk_buff *skb, 53763f09b6bSLorenzo Bianconi int cmd, int *wait_seq); 538bf18fcdcSLorenzo Bianconi int mt7615_mcu_set_channel_domain(struct mt7615_phy *phy); 539fcdfc29eSLorenzo Bianconi int mt7615_mcu_hw_scan(struct mt7615_phy *phy, struct ieee80211_vif *vif, 540fcdfc29eSLorenzo Bianconi struct ieee80211_scan_request *scan_req); 541fcdfc29eSLorenzo Bianconi int mt7615_mcu_cancel_hw_scan(struct mt7615_phy *phy, 542fcdfc29eSLorenzo Bianconi struct ieee80211_vif *vif); 54320305f98SLorenzo Bianconi int mt7615_mcu_sched_scan_req(struct mt7615_phy *phy, 54420305f98SLorenzo Bianconi struct ieee80211_vif *vif, 54520305f98SLorenzo Bianconi struct cfg80211_sched_scan_request *sreq); 54620305f98SLorenzo Bianconi int mt7615_mcu_sched_scan_enable(struct mt7615_phy *phy, 54720305f98SLorenzo Bianconi struct ieee80211_vif *vif, 54820305f98SLorenzo Bianconi bool enable); 54904b8e659SRyder Lee 55004b8e659SRyder Lee int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 55104b8e659SRyder Lee enum mt76_txq_id qid, struct mt76_wcid *wcid, 55204b8e659SRyder Lee struct ieee80211_sta *sta, 55304b8e659SRyder Lee struct mt76_tx_info *tx_info); 55404b8e659SRyder Lee 55504b8e659SRyder Lee void mt7615_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid, 55604b8e659SRyder Lee struct mt76_queue_entry *e); 55704b8e659SRyder Lee 55804b8e659SRyder Lee void mt7615_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, 55904b8e659SRyder Lee struct sk_buff *skb); 56004b8e659SRyder Lee void mt7615_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); 5613e384828SFelix Fietkau int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 56204b8e659SRyder Lee struct ieee80211_sta *sta); 5633e384828SFelix Fietkau void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 56404b8e659SRyder Lee struct ieee80211_sta *sta); 56504b8e659SRyder Lee void mt7615_mac_work(struct work_struct *work); 56604b8e659SRyder Lee void mt7615_txp_skb_unmap(struct mt76_dev *dev, 56704b8e659SRyder Lee struct mt76_txwi_cache *txwi); 5682ce73efeSLorenzo Bianconi int mt7615_mcu_set_fcc5_lpn(struct mt7615_dev *dev, int val); 5692ce73efeSLorenzo Bianconi int mt7615_mcu_set_pulse_th(struct mt7615_dev *dev, 5702ce73efeSLorenzo Bianconi const struct mt7615_dfs_pulse *pulse); 5712ce73efeSLorenzo Bianconi int mt7615_mcu_set_radar_th(struct mt7615_dev *dev, int index, 5722ce73efeSLorenzo Bianconi const struct mt7615_dfs_pattern *pattern); 57315d9a5d7SFelix Fietkau int mt7615_mcu_set_sku_en(struct mt7615_phy *phy, bool enable); 574ad380ad1SFelix Fietkau int mt7615_mcu_apply_rx_dcoc(struct mt7615_phy *phy); 575371a59d1SFelix Fietkau int mt7615_mcu_apply_tx_dpd(struct mt7615_phy *phy); 576a5e0aa78SLorenzo Bianconi int mt7615_mcu_set_vif_ps(struct mt7615_dev *dev, struct ieee80211_vif *vif); 5775dabdf71SFelix Fietkau int mt7615_dfs_init_radar_detector(struct mt7615_phy *phy); 57804b8e659SRyder Lee 57950eb0a88SLorenzo Bianconi int mt7615_mcu_set_p2p_oppps(struct ieee80211_hw *hw, 58050eb0a88SLorenzo Bianconi struct ieee80211_vif *vif); 5817307f296SLorenzo Bianconi int mt7615_mcu_set_roc(struct mt7615_phy *phy, struct ieee80211_vif *vif, 5827307f296SLorenzo Bianconi struct ieee80211_channel *chan, int duration); 5836dd4072cSLorenzo Bianconi int mt7615_firmware_own(struct mt7615_dev *dev); 5846dd4072cSLorenzo Bianconi int mt7615_driver_own(struct mt7615_dev *dev); 5856dd4072cSLorenzo Bianconi 58670911d96SLorenzo Bianconi int mt7615_init_debugfs(struct mt7615_dev *dev); 587eb99cc95SLorenzo Bianconi int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq); 588eb99cc95SLorenzo Bianconi 5896f117852SSean Wang int mt7615_mcu_set_hif_suspend(struct mt7615_dev *dev, bool suspend); 590c6bf2010SLorenzo Bianconi void mt7615_mcu_set_suspend_iter(void *priv, u8 *mac, 591c6bf2010SLorenzo Bianconi struct ieee80211_vif *vif); 592b47e21e7SLorenzo Bianconi int mt7615_mcu_update_gtk_rekey(struct ieee80211_hw *hw, 593b47e21e7SLorenzo Bianconi struct ieee80211_vif *vif, 594b47e21e7SLorenzo Bianconi struct cfg80211_gtk_rekey_data *key); 59573741b9bSSean Wang int mt7615_mcu_update_arp_filter(struct ieee80211_hw *hw, 59673741b9bSSean Wang struct ieee80211_vif *vif, 59773741b9bSSean Wang struct ieee80211_bss_conf *info); 5988915c3ceSLorenzo Bianconi int __mt7663_load_firmware(struct mt7615_dev *dev); 59970911d96SLorenzo Bianconi 600eb99cc95SLorenzo Bianconi /* usb */ 601eb99cc95SLorenzo Bianconi void mt7663u_wtbl_work(struct work_struct *work); 602eb99cc95SLorenzo Bianconi int mt7663u_mcu_init(struct mt7615_dev *dev); 603eb99cc95SLorenzo Bianconi int mt7663u_register_device(struct mt7615_dev *dev); 604eb99cc95SLorenzo Bianconi 60504b8e659SRyder Lee #endif 606