18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ISC */ 28c2ecf20Sopenharmony_ci/* Copyright (C) 2020 MediaTek Inc. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __MT7915_H 58c2ecf20Sopenharmony_ci#define __MT7915_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 88c2ecf20Sopenharmony_ci#include <linux/ktime.h> 98c2ecf20Sopenharmony_ci#include "../mt76.h" 108c2ecf20Sopenharmony_ci#include "regs.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define MT7915_MAX_INTERFACES 4 138c2ecf20Sopenharmony_ci#define MT7915_MAX_WMM_SETS 4 148c2ecf20Sopenharmony_ci#define MT7915_WTBL_SIZE 288 158c2ecf20Sopenharmony_ci#define MT7915_WTBL_RESERVED (MT7915_WTBL_SIZE - 1) 168c2ecf20Sopenharmony_ci#define MT7915_WTBL_STA (MT7915_WTBL_RESERVED - \ 178c2ecf20Sopenharmony_ci MT7915_MAX_INTERFACES) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define MT7915_WATCHDOG_TIME (HZ / 10) 208c2ecf20Sopenharmony_ci#define MT7915_RESET_TIMEOUT (30 * HZ) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define MT7915_TX_RING_SIZE 2048 238c2ecf20Sopenharmony_ci#define MT7915_TX_MCU_RING_SIZE 256 248c2ecf20Sopenharmony_ci#define MT7915_TX_FWDL_RING_SIZE 128 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define MT7915_RX_RING_SIZE 1536 278c2ecf20Sopenharmony_ci#define MT7915_RX_MCU_RING_SIZE 512 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define MT7915_FIRMWARE_WA "mediatek/mt7915_wa.bin" 308c2ecf20Sopenharmony_ci#define MT7915_FIRMWARE_WM "mediatek/mt7915_wm.bin" 318c2ecf20Sopenharmony_ci#define MT7915_ROM_PATCH "mediatek/mt7915_rom_patch.bin" 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define MT7915_EEPROM_SIZE 3584 348c2ecf20Sopenharmony_ci#define MT7915_TOKEN_SIZE 8192 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define MT7915_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ 378c2ecf20Sopenharmony_ci#define MT7915_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ 388c2ecf20Sopenharmony_ci#define MT7915_5G_RATE_DEFAULT 0x4b /* OFDM 6M */ 398c2ecf20Sopenharmony_ci#define MT7915_2G_RATE_DEFAULT 0x0 /* CCK 1M */ 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define MT7915_SKU_RATE_NUM 161 428c2ecf20Sopenharmony_ci#define MT7915_SKU_MAX_DELTA_IDX MT7915_SKU_RATE_NUM 438c2ecf20Sopenharmony_ci#define MT7915_SKU_TABLE_SIZE (MT7915_SKU_RATE_NUM + 1) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct mt7915_vif; 468c2ecf20Sopenharmony_cistruct mt7915_sta; 478c2ecf20Sopenharmony_cistruct mt7915_dfs_pulse; 488c2ecf20Sopenharmony_cistruct mt7915_dfs_pattern; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cienum mt7915_txq_id { 518c2ecf20Sopenharmony_ci MT7915_TXQ_FWDL = 16, 528c2ecf20Sopenharmony_ci MT7915_TXQ_MCU_WM, 538c2ecf20Sopenharmony_ci MT7915_TXQ_BAND0, 548c2ecf20Sopenharmony_ci MT7915_TXQ_BAND1, 558c2ecf20Sopenharmony_ci MT7915_TXQ_MCU_WA, 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cienum mt7915_rxq_id { 598c2ecf20Sopenharmony_ci MT7915_RXQ_BAND0 = 0, 608c2ecf20Sopenharmony_ci MT7915_RXQ_BAND1, 618c2ecf20Sopenharmony_ci MT7915_RXQ_MCU_WM = 0, 628c2ecf20Sopenharmony_ci MT7915_RXQ_MCU_WA, 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistruct mt7915_sta_stats { 668c2ecf20Sopenharmony_ci struct rate_info prob_rate; 678c2ecf20Sopenharmony_ci struct rate_info tx_rate; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci unsigned long per; 708c2ecf20Sopenharmony_ci unsigned long changed; 718c2ecf20Sopenharmony_ci unsigned long jiffies; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistruct mt7915_sta { 758c2ecf20Sopenharmony_ci struct mt76_wcid wcid; /* must be first */ 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci struct mt7915_vif *vif; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci struct list_head stats_list; 808c2ecf20Sopenharmony_ci struct list_head poll_list; 818c2ecf20Sopenharmony_ci struct list_head rc_list; 828c2ecf20Sopenharmony_ci u32 airtime_ac[8]; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci struct mt7915_sta_stats stats; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci unsigned long ampdu_state; 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistruct mt7915_vif { 908c2ecf20Sopenharmony_ci u16 idx; 918c2ecf20Sopenharmony_ci u8 omac_idx; 928c2ecf20Sopenharmony_ci u8 band_idx; 938c2ecf20Sopenharmony_ci u8 wmm_idx; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci struct mt7915_sta sta; 968c2ecf20Sopenharmony_ci struct mt7915_phy *phy; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS]; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistruct mib_stats { 1028c2ecf20Sopenharmony_ci u32 ack_fail_cnt; 1038c2ecf20Sopenharmony_ci u32 fcs_err_cnt; 1048c2ecf20Sopenharmony_ci u32 rts_cnt; 1058c2ecf20Sopenharmony_ci u32 rts_retries_cnt; 1068c2ecf20Sopenharmony_ci u32 ba_miss_cnt; 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistruct mt7915_phy { 1108c2ecf20Sopenharmony_ci struct mt76_phy *mt76; 1118c2ecf20Sopenharmony_ci struct mt7915_dev *dev; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci struct ieee80211_sband_iftype_data iftype[2][NUM_NL80211_IFTYPES]; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci u32 rxfilter; 1168c2ecf20Sopenharmony_ci u32 omac_mask; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci u16 noise; 1198c2ecf20Sopenharmony_ci u16 chainmask; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci s16 coverage_class; 1228c2ecf20Sopenharmony_ci u8 slottime; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci u8 rdd_state; 1258c2ecf20Sopenharmony_ci int dfs_state; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci __le32 rx_ampdu_ts; 1288c2ecf20Sopenharmony_ci u32 ampdu_ref; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci struct mib_stats mib; 1318c2ecf20Sopenharmony_ci struct list_head stats_list; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci struct delayed_work mac_work; 1348c2ecf20Sopenharmony_ci u8 mac_work_count; 1358c2ecf20Sopenharmony_ci u8 sta_work_count; 1368c2ecf20Sopenharmony_ci}; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistruct mt7915_dev { 1398c2ecf20Sopenharmony_ci union { /* must be first */ 1408c2ecf20Sopenharmony_ci struct mt76_dev mt76; 1418c2ecf20Sopenharmony_ci struct mt76_phy mphy; 1428c2ecf20Sopenharmony_ci }; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci const struct mt76_bus_ops *bus_ops; 1458c2ecf20Sopenharmony_ci struct mt7915_phy phy; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci u16 chainmask; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci struct work_struct init_work; 1508c2ecf20Sopenharmony_ci struct work_struct rc_work; 1518c2ecf20Sopenharmony_ci struct work_struct reset_work; 1528c2ecf20Sopenharmony_ci wait_queue_head_t reset_wait; 1538c2ecf20Sopenharmony_ci u32 reset_state; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci struct list_head sta_rc_list; 1568c2ecf20Sopenharmony_ci struct list_head sta_poll_list; 1578c2ecf20Sopenharmony_ci spinlock_t sta_poll_lock; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci u32 hw_pattern; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci spinlock_t token_lock; 1628c2ecf20Sopenharmony_ci struct idr token; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci s8 **rate_power; /* TODO: use mt76_rate_power */ 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci bool fw_debug; 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cienum { 1708c2ecf20Sopenharmony_ci HW_BSSID_0 = 0x0, 1718c2ecf20Sopenharmony_ci HW_BSSID_1, 1728c2ecf20Sopenharmony_ci HW_BSSID_2, 1738c2ecf20Sopenharmony_ci HW_BSSID_3, 1748c2ecf20Sopenharmony_ci HW_BSSID_MAX, 1758c2ecf20Sopenharmony_ci EXT_BSSID_START = 0x10, 1768c2ecf20Sopenharmony_ci EXT_BSSID_1, 1778c2ecf20Sopenharmony_ci EXT_BSSID_2, 1788c2ecf20Sopenharmony_ci EXT_BSSID_3, 1798c2ecf20Sopenharmony_ci EXT_BSSID_4, 1808c2ecf20Sopenharmony_ci EXT_BSSID_5, 1818c2ecf20Sopenharmony_ci EXT_BSSID_6, 1828c2ecf20Sopenharmony_ci EXT_BSSID_7, 1838c2ecf20Sopenharmony_ci EXT_BSSID_8, 1848c2ecf20Sopenharmony_ci EXT_BSSID_9, 1858c2ecf20Sopenharmony_ci EXT_BSSID_10, 1868c2ecf20Sopenharmony_ci EXT_BSSID_11, 1878c2ecf20Sopenharmony_ci EXT_BSSID_12, 1888c2ecf20Sopenharmony_ci EXT_BSSID_13, 1898c2ecf20Sopenharmony_ci EXT_BSSID_14, 1908c2ecf20Sopenharmony_ci EXT_BSSID_15, 1918c2ecf20Sopenharmony_ci EXT_BSSID_END 1928c2ecf20Sopenharmony_ci}; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cienum { 1958c2ecf20Sopenharmony_ci MT_LMAC_AC00, 1968c2ecf20Sopenharmony_ci MT_LMAC_AC01, 1978c2ecf20Sopenharmony_ci MT_LMAC_AC02, 1988c2ecf20Sopenharmony_ci MT_LMAC_AC03, 1998c2ecf20Sopenharmony_ci MT_LMAC_ALTX0 = 0x10, 2008c2ecf20Sopenharmony_ci MT_LMAC_BMC0, 2018c2ecf20Sopenharmony_ci MT_LMAC_BCN0, 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cienum { 2058c2ecf20Sopenharmony_ci MT_RX_SEL0, 2068c2ecf20Sopenharmony_ci MT_RX_SEL1, 2078c2ecf20Sopenharmony_ci}; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cienum mt7915_rdd_cmd { 2108c2ecf20Sopenharmony_ci RDD_STOP, 2118c2ecf20Sopenharmony_ci RDD_START, 2128c2ecf20Sopenharmony_ci RDD_DET_MODE, 2138c2ecf20Sopenharmony_ci RDD_RADAR_EMULATE, 2148c2ecf20Sopenharmony_ci RDD_START_TXQ = 20, 2158c2ecf20Sopenharmony_ci RDD_CAC_START = 50, 2168c2ecf20Sopenharmony_ci RDD_CAC_END, 2178c2ecf20Sopenharmony_ci RDD_NORMAL_START, 2188c2ecf20Sopenharmony_ci RDD_DISABLE_DFS_CAL, 2198c2ecf20Sopenharmony_ci RDD_PULSE_DBG, 2208c2ecf20Sopenharmony_ci RDD_READ_PULSE, 2218c2ecf20Sopenharmony_ci RDD_RESUME_BF, 2228c2ecf20Sopenharmony_ci RDD_IRQ_OFF, 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cienum { 2268c2ecf20Sopenharmony_ci RATE_CTRL_RU_INFO, 2278c2ecf20Sopenharmony_ci RATE_CTRL_FIXED_RATE_INFO, 2288c2ecf20Sopenharmony_ci RATE_CTRL_DUMP_INFO, 2298c2ecf20Sopenharmony_ci RATE_CTRL_MU_INFO, 2308c2ecf20Sopenharmony_ci}; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic inline struct mt7915_phy * 2338c2ecf20Sopenharmony_cimt7915_hw_phy(struct ieee80211_hw *hw) 2348c2ecf20Sopenharmony_ci{ 2358c2ecf20Sopenharmony_ci struct mt76_phy *phy = hw->priv; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci return phy->priv; 2388c2ecf20Sopenharmony_ci} 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_cistatic inline struct mt7915_dev * 2418c2ecf20Sopenharmony_cimt7915_hw_dev(struct ieee80211_hw *hw) 2428c2ecf20Sopenharmony_ci{ 2438c2ecf20Sopenharmony_ci struct mt76_phy *phy = hw->priv; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci return container_of(phy->dev, struct mt7915_dev, mt76); 2468c2ecf20Sopenharmony_ci} 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_cistatic inline struct mt7915_phy * 2498c2ecf20Sopenharmony_cimt7915_ext_phy(struct mt7915_dev *dev) 2508c2ecf20Sopenharmony_ci{ 2518c2ecf20Sopenharmony_ci struct mt76_phy *phy = dev->mt76.phy2; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci if (!phy) 2548c2ecf20Sopenharmony_ci return NULL; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci return phy->priv; 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic inline u8 mt7915_lmac_mapping(struct mt7915_dev *dev, u8 ac) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci /* LMAC uses the reverse order of mac80211 AC indexes */ 2628c2ecf20Sopenharmony_ci return 3 - ac; 2638c2ecf20Sopenharmony_ci} 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ciextern const struct ieee80211_ops mt7915_ops; 2668c2ecf20Sopenharmony_ciextern struct pci_driver mt7915_pci_driver; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ciu32 mt7915_reg_map(struct mt7915_dev *dev, u32 addr); 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ciint mt7915_register_device(struct mt7915_dev *dev); 2718c2ecf20Sopenharmony_civoid mt7915_unregister_device(struct mt7915_dev *dev); 2728c2ecf20Sopenharmony_ciint mt7915_register_ext_phy(struct mt7915_dev *dev); 2738c2ecf20Sopenharmony_civoid mt7915_unregister_ext_phy(struct mt7915_dev *dev); 2748c2ecf20Sopenharmony_ciint mt7915_eeprom_init(struct mt7915_dev *dev); 2758c2ecf20Sopenharmony_ciu32 mt7915_eeprom_read(struct mt7915_dev *dev, u32 offset); 2768c2ecf20Sopenharmony_ciint mt7915_eeprom_get_target_power(struct mt7915_dev *dev, 2778c2ecf20Sopenharmony_ci struct ieee80211_channel *chan, 2788c2ecf20Sopenharmony_ci u8 chain_idx); 2798c2ecf20Sopenharmony_civoid mt7915_eeprom_init_sku(struct mt7915_dev *dev); 2808c2ecf20Sopenharmony_ciint mt7915_dma_init(struct mt7915_dev *dev); 2818c2ecf20Sopenharmony_civoid mt7915_dma_prefetch(struct mt7915_dev *dev); 2828c2ecf20Sopenharmony_civoid mt7915_dma_cleanup(struct mt7915_dev *dev); 2838c2ecf20Sopenharmony_ciint mt7915_mcu_init(struct mt7915_dev *dev); 2848c2ecf20Sopenharmony_ciint mt7915_mcu_add_dev_info(struct mt7915_dev *dev, 2858c2ecf20Sopenharmony_ci struct ieee80211_vif *vif, bool enable); 2868c2ecf20Sopenharmony_ciint mt7915_mcu_add_bss_info(struct mt7915_phy *phy, 2878c2ecf20Sopenharmony_ci struct ieee80211_vif *vif, int enable); 2888c2ecf20Sopenharmony_ciint mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif, 2898c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, bool enable); 2908c2ecf20Sopenharmony_ciint mt7915_mcu_add_sta_adv(struct mt7915_dev *dev, struct ieee80211_vif *vif, 2918c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, bool enable); 2928c2ecf20Sopenharmony_ciint mt7915_mcu_add_tx_ba(struct mt7915_dev *dev, 2938c2ecf20Sopenharmony_ci struct ieee80211_ampdu_params *params, 2948c2ecf20Sopenharmony_ci bool add); 2958c2ecf20Sopenharmony_ciint mt7915_mcu_add_rx_ba(struct mt7915_dev *dev, 2968c2ecf20Sopenharmony_ci struct ieee80211_ampdu_params *params, 2978c2ecf20Sopenharmony_ci bool add); 2988c2ecf20Sopenharmony_ciint mt7915_mcu_add_key(struct mt7915_dev *dev, struct ieee80211_vif *vif, 2998c2ecf20Sopenharmony_ci struct mt7915_sta *msta, struct ieee80211_key_conf *key, 3008c2ecf20Sopenharmony_ci enum set_key_cmd cmd); 3018c2ecf20Sopenharmony_ciint mt7915_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3028c2ecf20Sopenharmony_ci int enable); 3038c2ecf20Sopenharmony_ciint mt7915_mcu_add_obss_spr(struct mt7915_dev *dev, struct ieee80211_vif *vif, 3048c2ecf20Sopenharmony_ci bool enable); 3058c2ecf20Sopenharmony_ciint mt7915_mcu_add_rate_ctrl(struct mt7915_dev *dev, struct ieee80211_vif *vif, 3068c2ecf20Sopenharmony_ci struct ieee80211_sta *sta); 3078c2ecf20Sopenharmony_ciint mt7915_mcu_add_smps(struct mt7915_dev *dev, struct ieee80211_vif *vif, 3088c2ecf20Sopenharmony_ci struct ieee80211_sta *sta); 3098c2ecf20Sopenharmony_ciint mt7915_mcu_set_chan_info(struct mt7915_phy *phy, int cmd); 3108c2ecf20Sopenharmony_ciint mt7915_mcu_set_tx(struct mt7915_dev *dev, struct ieee80211_vif *vif); 3118c2ecf20Sopenharmony_ciint mt7915_mcu_set_fixed_rate(struct mt7915_dev *dev, 3128c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, u32 rate); 3138c2ecf20Sopenharmony_ciint mt7915_mcu_set_eeprom(struct mt7915_dev *dev); 3148c2ecf20Sopenharmony_ciint mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset); 3158c2ecf20Sopenharmony_ciint mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable, 3168c2ecf20Sopenharmony_ci bool hdr_trans); 3178c2ecf20Sopenharmony_ciint mt7915_mcu_set_scs(struct mt7915_dev *dev, u8 band, bool enable); 3188c2ecf20Sopenharmony_ciint mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band); 3198c2ecf20Sopenharmony_ciint mt7915_mcu_set_rts_thresh(struct mt7915_phy *phy, u32 val); 3208c2ecf20Sopenharmony_ciint mt7915_mcu_set_pm(struct mt7915_dev *dev, int band, int enter); 3218c2ecf20Sopenharmony_ciint mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable); 3228c2ecf20Sopenharmony_ciint mt7915_mcu_set_sku(struct mt7915_phy *phy); 3238c2ecf20Sopenharmony_ciint mt7915_mcu_set_txbf_type(struct mt7915_dev *dev); 3248c2ecf20Sopenharmony_ciint mt7915_mcu_set_txbf_sounding(struct mt7915_dev *dev); 3258c2ecf20Sopenharmony_ciint mt7915_mcu_set_fcc5_lpn(struct mt7915_dev *dev, int val); 3268c2ecf20Sopenharmony_ciint mt7915_mcu_set_pulse_th(struct mt7915_dev *dev, 3278c2ecf20Sopenharmony_ci const struct mt7915_dfs_pulse *pulse); 3288c2ecf20Sopenharmony_ciint mt7915_mcu_set_radar_th(struct mt7915_dev *dev, int index, 3298c2ecf20Sopenharmony_ci const struct mt7915_dfs_pattern *pattern); 3308c2ecf20Sopenharmony_ciint mt7915_mcu_get_rate_info(struct mt7915_dev *dev, u32 cmd, u16 wlan_idx); 3318c2ecf20Sopenharmony_ciint mt7915_mcu_get_temperature(struct mt7915_dev *dev, int index); 3328c2ecf20Sopenharmony_ciint mt7915_mcu_rdd_cmd(struct mt7915_dev *dev, enum mt7915_rdd_cmd cmd, 3338c2ecf20Sopenharmony_ci u8 index, u8 rx_sel, u8 val); 3348c2ecf20Sopenharmony_ciint mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 ctrl); 3358c2ecf20Sopenharmony_ciint mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level); 3368c2ecf20Sopenharmony_civoid mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb); 3378c2ecf20Sopenharmony_civoid mt7915_mcu_exit(struct mt7915_dev *dev); 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_cistatic inline bool is_mt7915(struct mt76_dev *dev) 3408c2ecf20Sopenharmony_ci{ 3418c2ecf20Sopenharmony_ci return mt76_chip(dev) == 0x7915; 3428c2ecf20Sopenharmony_ci} 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_cistatic inline void mt7915_irq_enable(struct mt7915_dev *dev, u32 mask) 3458c2ecf20Sopenharmony_ci{ 3468c2ecf20Sopenharmony_ci mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask); 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cistatic inline void mt7915_irq_disable(struct mt7915_dev *dev, u32 mask) 3508c2ecf20Sopenharmony_ci{ 3518c2ecf20Sopenharmony_ci mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0); 3528c2ecf20Sopenharmony_ci} 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_cistatic inline u32 3558c2ecf20Sopenharmony_cimt7915_reg_map_l1(struct mt7915_dev *dev, u32 addr) 3568c2ecf20Sopenharmony_ci{ 3578c2ecf20Sopenharmony_ci u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr); 3588c2ecf20Sopenharmony_ci u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr); 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci mt76_rmw_field(dev, MT_HIF_REMAP_L1, MT_HIF_REMAP_L1_MASK, base); 3618c2ecf20Sopenharmony_ci /* use read to push write */ 3628c2ecf20Sopenharmony_ci mt76_rr(dev, MT_HIF_REMAP_L1); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci return MT_HIF_REMAP_BASE_L1 + offset; 3658c2ecf20Sopenharmony_ci} 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_cistatic inline u32 3688c2ecf20Sopenharmony_cimt7915_l1_rr(struct mt7915_dev *dev, u32 addr) 3698c2ecf20Sopenharmony_ci{ 3708c2ecf20Sopenharmony_ci return mt76_rr(dev, mt7915_reg_map_l1(dev, addr)); 3718c2ecf20Sopenharmony_ci} 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_cistatic inline void 3748c2ecf20Sopenharmony_cimt7915_l1_wr(struct mt7915_dev *dev, u32 addr, u32 val) 3758c2ecf20Sopenharmony_ci{ 3768c2ecf20Sopenharmony_ci mt76_wr(dev, mt7915_reg_map_l1(dev, addr), val); 3778c2ecf20Sopenharmony_ci} 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistatic inline u32 3808c2ecf20Sopenharmony_cimt7915_l1_rmw(struct mt7915_dev *dev, u32 addr, u32 mask, u32 val) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci val |= mt7915_l1_rr(dev, addr) & ~mask; 3838c2ecf20Sopenharmony_ci mt7915_l1_wr(dev, addr, val); 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci return val; 3868c2ecf20Sopenharmony_ci} 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci#define mt7915_l1_set(dev, addr, val) mt7915_l1_rmw(dev, addr, 0, val) 3898c2ecf20Sopenharmony_ci#define mt7915_l1_clear(dev, addr, val) mt7915_l1_rmw(dev, addr, val, 0) 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_cistatic inline u32 3928c2ecf20Sopenharmony_cimt7915_reg_map_l2(struct mt7915_dev *dev, u32 addr) 3938c2ecf20Sopenharmony_ci{ 3948c2ecf20Sopenharmony_ci u32 offset = FIELD_GET(MT_HIF_REMAP_L2_OFFSET, addr); 3958c2ecf20Sopenharmony_ci u32 base = FIELD_GET(MT_HIF_REMAP_L2_BASE, addr); 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci mt76_rmw_field(dev, MT_HIF_REMAP_L2, MT_HIF_REMAP_L2_MASK, base); 3988c2ecf20Sopenharmony_ci /* use read to push write */ 3998c2ecf20Sopenharmony_ci mt76_rr(dev, MT_HIF_REMAP_L2); 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci return MT_HIF_REMAP_BASE_L2 + offset; 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_cistatic inline u32 4058c2ecf20Sopenharmony_cimt7915_l2_rr(struct mt7915_dev *dev, u32 addr) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci return mt76_rr(dev, mt7915_reg_map_l2(dev, addr)); 4088c2ecf20Sopenharmony_ci} 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_cistatic inline void 4118c2ecf20Sopenharmony_cimt7915_l2_wr(struct mt7915_dev *dev, u32 addr, u32 val) 4128c2ecf20Sopenharmony_ci{ 4138c2ecf20Sopenharmony_ci mt76_wr(dev, mt7915_reg_map_l2(dev, addr), val); 4148c2ecf20Sopenharmony_ci} 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_cistatic inline u32 4178c2ecf20Sopenharmony_cimt7915_l2_rmw(struct mt7915_dev *dev, u32 addr, u32 mask, u32 val) 4188c2ecf20Sopenharmony_ci{ 4198c2ecf20Sopenharmony_ci val |= mt7915_l2_rr(dev, addr) & ~mask; 4208c2ecf20Sopenharmony_ci mt7915_l2_wr(dev, addr, val); 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci return val; 4238c2ecf20Sopenharmony_ci} 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci#define mt7915_l2_set(dev, addr, val) mt7915_l2_rmw(dev, addr, 0, val) 4268c2ecf20Sopenharmony_ci#define mt7915_l2_clear(dev, addr, val) mt7915_l2_rmw(dev, addr, val, 0) 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_cibool mt7915_mac_wtbl_update(struct mt7915_dev *dev, int idx, u32 mask); 4298c2ecf20Sopenharmony_civoid mt7915_mac_reset_counters(struct mt7915_phy *phy); 4308c2ecf20Sopenharmony_civoid mt7915_mac_cca_stats_reset(struct mt7915_phy *phy); 4318c2ecf20Sopenharmony_civoid mt7915_mac_write_txwi(struct mt7915_dev *dev, __le32 *txwi, 4328c2ecf20Sopenharmony_ci struct sk_buff *skb, struct mt76_wcid *wcid, 4338c2ecf20Sopenharmony_ci struct ieee80211_key_conf *key, bool beacon); 4348c2ecf20Sopenharmony_civoid mt7915_mac_set_timing(struct mt7915_phy *phy); 4358c2ecf20Sopenharmony_ciint mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb); 4368c2ecf20Sopenharmony_civoid mt7915_mac_tx_free(struct mt7915_dev *dev, struct sk_buff *skb); 4378c2ecf20Sopenharmony_ciint mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 4388c2ecf20Sopenharmony_ci struct ieee80211_sta *sta); 4398c2ecf20Sopenharmony_civoid mt7915_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 4408c2ecf20Sopenharmony_ci struct ieee80211_sta *sta); 4418c2ecf20Sopenharmony_civoid mt7915_mac_work(struct work_struct *work); 4428c2ecf20Sopenharmony_civoid mt7915_mac_reset_work(struct work_struct *work); 4438c2ecf20Sopenharmony_civoid mt7915_mac_sta_rc_work(struct work_struct *work); 4448c2ecf20Sopenharmony_ciint mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 4458c2ecf20Sopenharmony_ci enum mt76_txq_id qid, struct mt76_wcid *wcid, 4468c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, 4478c2ecf20Sopenharmony_ci struct mt76_tx_info *tx_info); 4488c2ecf20Sopenharmony_civoid mt7915_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e); 4498c2ecf20Sopenharmony_civoid mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, 4508c2ecf20Sopenharmony_ci struct sk_buff *skb); 4518c2ecf20Sopenharmony_civoid mt7915_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); 4528c2ecf20Sopenharmony_civoid mt7915_stats_work(struct work_struct *work); 4538c2ecf20Sopenharmony_civoid mt7915_txp_skb_unmap(struct mt76_dev *dev, 4548c2ecf20Sopenharmony_ci struct mt76_txwi_cache *txwi); 4558c2ecf20Sopenharmony_ciint mt76_dfs_start_rdd(struct mt7915_dev *dev, bool force); 4568c2ecf20Sopenharmony_ciint mt7915_dfs_init_radar_detector(struct mt7915_phy *phy); 4578c2ecf20Sopenharmony_civoid mt7915_set_stream_he_caps(struct mt7915_phy *phy); 4588c2ecf20Sopenharmony_civoid mt7915_set_stream_vht_txbf_caps(struct mt7915_phy *phy); 4598c2ecf20Sopenharmony_civoid mt7915_update_channel(struct mt76_dev *mdev); 4608c2ecf20Sopenharmony_ciint mt7915_init_debugfs(struct mt7915_dev *dev); 4618c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_DEBUGFS 4628c2ecf20Sopenharmony_civoid mt7915_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4638c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, struct dentry *dir); 4648c2ecf20Sopenharmony_ci#endif 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci#endif 467