1 /* SPDX-License-Identifier: ISC */ 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 4 #ifndef __MT7921_H 5 #define __MT7921_H 6 7 #include <linux/interrupt.h> 8 #include <linux/ktime.h> 9 #include "../mt76_connac.h" 10 #include "regs.h" 11 12 #define MT7921_MAX_INTERFACES 4 13 #define MT7921_MAX_WMM_SETS 4 14 #define MT7921_WTBL_SIZE 20 15 #define MT7921_WTBL_RESERVED (MT7921_WTBL_SIZE - 1) 16 #define MT7921_WTBL_STA (MT7921_WTBL_RESERVED - \ 17 MT7921_MAX_INTERFACES) 18 19 #define MT7921_PM_TIMEOUT (HZ / 12) 20 #define MT7921_HW_SCAN_TIMEOUT (HZ / 10) 21 #define MT7921_WATCHDOG_TIME (HZ / 10) 22 #define MT7921_RESET_TIMEOUT (30 * HZ) 23 24 #define MT7921_TX_RING_SIZE 2048 25 #define MT7921_TX_MCU_RING_SIZE 256 26 #define MT7921_TX_FWDL_RING_SIZE 128 27 28 #define MT7921_RX_RING_SIZE 1536 29 #define MT7921_RX_MCU_RING_SIZE 512 30 31 #define MT7921_DRV_OWN_RETRY_COUNT 10 32 33 #define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin" 34 #define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin" 35 36 #define MT7921_EEPROM_SIZE 3584 37 #define MT7921_TOKEN_SIZE 8192 38 #define MT7921_TOKEN_FREE_THR 64 39 40 #define MT7921_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ 41 #define MT7921_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ 42 #define MT7921_5G_RATE_DEFAULT 0x4b /* OFDM 6M */ 43 #define MT7921_2G_RATE_DEFAULT 0x0 /* CCK 1M */ 44 45 #define MT7921_SKU_RATE_NUM 161 46 #define MT7921_SKU_MAX_DELTA_IDX MT7921_SKU_RATE_NUM 47 #define MT7921_SKU_TABLE_SIZE (MT7921_SKU_RATE_NUM + 1) 48 49 struct mt7921_vif; 50 struct mt7921_sta; 51 52 enum mt7921_txq_id { 53 MT7921_TXQ_BAND0, 54 MT7921_TXQ_BAND1, 55 MT7921_TXQ_FWDL = 16, 56 MT7921_TXQ_MCU_WM, 57 }; 58 59 enum mt7921_rxq_id { 60 MT7921_RXQ_BAND0 = 0, 61 MT7921_RXQ_BAND1, 62 MT7921_RXQ_MCU_WM = 0, 63 }; 64 65 struct mt7921_sta_stats { 66 struct rate_info prob_rate; 67 struct rate_info tx_rate; 68 69 unsigned long per; 70 unsigned long changed; 71 unsigned long jiffies; 72 }; 73 74 struct mt7921_sta_key_conf { 75 s8 keyidx; 76 u8 key[16]; 77 }; 78 79 struct mt7921_sta { 80 struct mt76_wcid wcid; /* must be first */ 81 82 struct mt7921_vif *vif; 83 84 struct list_head stats_list; 85 struct list_head poll_list; 86 u32 airtime_ac[8]; 87 88 struct mt7921_sta_stats stats; 89 90 unsigned long ampdu_state; 91 92 struct mt7921_sta_key_conf bip; 93 }; 94 95 struct mt7921_vif { 96 struct mt76_vif mt76; /* must be first */ 97 98 struct mt7921_sta sta; 99 struct mt7921_phy *phy; 100 101 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS]; 102 }; 103 104 struct mib_stats { 105 u16 ack_fail_cnt; 106 u16 fcs_err_cnt; 107 u16 rts_cnt; 108 u16 rts_retries_cnt; 109 u16 ba_miss_cnt; 110 }; 111 112 struct mt7921_phy { 113 struct mt76_phy *mt76; 114 struct mt7921_dev *dev; 115 116 struct ieee80211_sband_iftype_data iftype[2][NUM_NL80211_IFTYPES]; 117 118 struct ieee80211_vif *monitor_vif; 119 120 u32 rxfilter; 121 u64 omac_mask; 122 123 u16 noise; 124 125 s16 coverage_class; 126 u8 slottime; 127 128 __le32 rx_ampdu_ts; 129 u32 ampdu_ref; 130 131 struct mib_stats mib; 132 struct list_head stats_list; 133 134 u8 sta_work_count; 135 136 struct sk_buff_head scan_event_list; 137 struct delayed_work scan_work; 138 }; 139 140 struct mt7921_dev { 141 union { /* must be first */ 142 struct mt76_dev mt76; 143 struct mt76_phy mphy; 144 }; 145 146 const struct mt76_bus_ops *bus_ops; 147 struct mt7921_phy phy; 148 struct tasklet_struct irq_tasklet; 149 150 u16 chainmask; 151 152 struct work_struct init_work; 153 struct work_struct reset_work; 154 wait_queue_head_t reset_wait; 155 u32 reset_state; 156 157 struct list_head sta_poll_list; 158 spinlock_t sta_poll_lock; 159 160 spinlock_t token_lock; 161 int token_count; 162 struct idr token; 163 164 u8 fw_debug; 165 166 struct mt76_connac_pm pm; 167 }; 168 169 enum { 170 MT_LMAC_AC00, 171 MT_LMAC_AC01, 172 MT_LMAC_AC02, 173 MT_LMAC_AC03, 174 MT_LMAC_ALTX0 = 0x10, 175 MT_LMAC_BMC0, 176 MT_LMAC_BCN0, 177 }; 178 179 static inline struct mt7921_phy * 180 mt7921_hw_phy(struct ieee80211_hw *hw) 181 { 182 struct mt76_phy *phy = hw->priv; 183 184 return phy->priv; 185 } 186 187 static inline struct mt7921_dev * 188 mt7921_hw_dev(struct ieee80211_hw *hw) 189 { 190 struct mt76_phy *phy = hw->priv; 191 192 return container_of(phy->dev, struct mt7921_dev, mt76); 193 } 194 195 #define mt7921_mutex_acquire(dev) \ 196 mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm) 197 #define mt7921_mutex_release(dev) \ 198 mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm) 199 200 static inline u8 mt7921_lmac_mapping(struct mt7921_dev *dev, u8 ac) 201 { 202 /* LMAC uses the reverse order of mac80211 AC indexes */ 203 return 3 - ac; 204 } 205 206 extern const struct ieee80211_ops mt7921_ops; 207 extern struct pci_driver mt7921_pci_driver; 208 209 u32 mt7921_reg_map(struct mt7921_dev *dev, u32 addr); 210 211 int mt7921_register_device(struct mt7921_dev *dev); 212 void mt7921_unregister_device(struct mt7921_dev *dev); 213 int mt7921_eeprom_init(struct mt7921_dev *dev); 214 void mt7921_eeprom_parse_band_config(struct mt7921_phy *phy); 215 int mt7921_eeprom_get_target_power(struct mt7921_dev *dev, 216 struct ieee80211_channel *chan, 217 u8 chain_idx); 218 void mt7921_eeprom_init_sku(struct mt7921_dev *dev); 219 int mt7921_dma_init(struct mt7921_dev *dev); 220 void mt7921_dma_prefetch(struct mt7921_dev *dev); 221 void mt7921_dma_cleanup(struct mt7921_dev *dev); 222 int mt7921_mcu_init(struct mt7921_dev *dev); 223 int mt7921_mcu_add_bss_info(struct mt7921_phy *phy, 224 struct ieee80211_vif *vif, int enable); 225 int mt7921_mcu_add_key(struct mt7921_dev *dev, struct ieee80211_vif *vif, 226 struct mt7921_sta *msta, struct ieee80211_key_conf *key, 227 enum set_key_cmd cmd); 228 int mt7921_set_channel(struct mt7921_phy *phy); 229 int mt7921_mcu_set_chan_info(struct mt7921_phy *phy, int cmd); 230 int mt7921_mcu_set_tx(struct mt7921_dev *dev, struct ieee80211_vif *vif); 231 int mt7921_mcu_set_eeprom(struct mt7921_dev *dev); 232 int mt7921_mcu_get_eeprom(struct mt7921_dev *dev, u32 offset); 233 int mt7921_mcu_get_rx_rate(struct mt7921_phy *phy, struct ieee80211_vif *vif, 234 struct ieee80211_sta *sta, struct rate_info *rate); 235 int mt7921_mcu_fw_log_2_host(struct mt7921_dev *dev, u8 ctrl); 236 void mt7921_mcu_rx_event(struct mt7921_dev *dev, struct sk_buff *skb); 237 void mt7921_mcu_exit(struct mt7921_dev *dev); 238 239 static inline void mt7921_irq_enable(struct mt7921_dev *dev, u32 mask) 240 { 241 mt76_set_irq_mask(&dev->mt76, 0, 0, mask); 242 243 tasklet_schedule(&dev->irq_tasklet); 244 } 245 246 static inline u32 247 mt7921_reg_map_l1(struct mt7921_dev *dev, u32 addr) 248 { 249 u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr); 250 u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr); 251 252 mt76_rmw_field(dev, MT_HIF_REMAP_L1, MT_HIF_REMAP_L1_MASK, base); 253 /* use read to push write */ 254 mt76_rr(dev, MT_HIF_REMAP_L1); 255 256 return MT_HIF_REMAP_BASE_L1 + offset; 257 } 258 259 static inline u32 260 mt7921_l1_rr(struct mt7921_dev *dev, u32 addr) 261 { 262 return mt76_rr(dev, mt7921_reg_map_l1(dev, addr)); 263 } 264 265 static inline void 266 mt7921_l1_wr(struct mt7921_dev *dev, u32 addr, u32 val) 267 { 268 mt76_wr(dev, mt7921_reg_map_l1(dev, addr), val); 269 } 270 271 static inline u32 272 mt7921_l1_rmw(struct mt7921_dev *dev, u32 addr, u32 mask, u32 val) 273 { 274 val |= mt7921_l1_rr(dev, addr) & ~mask; 275 mt7921_l1_wr(dev, addr, val); 276 277 return val; 278 } 279 280 #define mt7921_l1_set(dev, addr, val) mt7921_l1_rmw(dev, addr, 0, val) 281 #define mt7921_l1_clear(dev, addr, val) mt7921_l1_rmw(dev, addr, val, 0) 282 283 bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask); 284 void mt7921_mac_reset_counters(struct mt7921_phy *phy); 285 void mt7921_mac_write_txwi(struct mt7921_dev *dev, __le32 *txwi, 286 struct sk_buff *skb, struct mt76_wcid *wcid, 287 struct ieee80211_key_conf *key, bool beacon); 288 void mt7921_mac_set_timing(struct mt7921_phy *phy); 289 int mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb); 290 void mt7921_mac_fill_rx_vector(struct mt7921_dev *dev, struct sk_buff *skb); 291 void mt7921_mac_tx_free(struct mt7921_dev *dev, struct sk_buff *skb); 292 int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 293 struct ieee80211_sta *sta); 294 void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 295 struct ieee80211_sta *sta); 296 void mt7921_mac_work(struct work_struct *work); 297 void mt7921_mac_reset_work(struct work_struct *work); 298 int mt7921_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 299 enum mt76_txq_id qid, struct mt76_wcid *wcid, 300 struct ieee80211_sta *sta, 301 struct mt76_tx_info *tx_info); 302 void mt7921_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e); 303 int mt7921_init_tx_queues(struct mt7921_phy *phy, int idx, int n_desc); 304 void mt7921_tx_token_put(struct mt7921_dev *dev); 305 void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, 306 struct sk_buff *skb); 307 void mt7921_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); 308 void mt7921_stats_work(struct work_struct *work); 309 void mt7921_txp_skb_unmap(struct mt76_dev *dev, 310 struct mt76_txwi_cache *txwi); 311 void mt7921_set_stream_he_caps(struct mt7921_phy *phy); 312 void mt7921_update_channel(struct mt76_dev *mdev); 313 int mt7921_init_debugfs(struct mt7921_dev *dev); 314 315 int mt7921_mcu_uni_tx_ba(struct mt7921_dev *dev, 316 struct ieee80211_ampdu_params *params, 317 bool enable); 318 int mt7921_mcu_uni_rx_ba(struct mt7921_dev *dev, 319 struct ieee80211_ampdu_params *params, 320 bool enable); 321 void mt7921_scan_work(struct work_struct *work); 322 u32 mt7921_get_wtbl_info(struct mt7921_dev *dev, u32 wlan_idx); 323 int mt7921_mcu_uni_bss_ps(struct mt7921_dev *dev, struct ieee80211_vif *vif); 324 int mt7921_mcu_uni_bss_bcnft(struct mt7921_dev *dev, struct ieee80211_vif *vif, 325 bool enable); 326 int mt7921_mcu_set_bss_pm(struct mt7921_dev *dev, struct ieee80211_vif *vif, 327 bool enable); 328 int mt7921_mcu_update_arp_filter(struct ieee80211_hw *hw, 329 struct ieee80211_vif *vif, 330 struct ieee80211_bss_conf *info); 331 int mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev); 332 int mt7921_mcu_fw_pmctrl(struct mt7921_dev *dev); 333 void mt7921_pm_wake_work(struct work_struct *work); 334 void mt7921_pm_power_save_work(struct work_struct *work); 335 bool mt7921_wait_for_mcu_init(struct mt7921_dev *dev); 336 int mt7921_mac_set_beacon_filter(struct mt7921_phy *phy, 337 struct ieee80211_vif *vif, 338 bool enable); 339 void mt7921_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif); 340 #endif 341