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_mcu.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 struct mt76_connac_coredump coredump; 168 }; 169 170 enum { 171 MT_LMAC_AC00, 172 MT_LMAC_AC01, 173 MT_LMAC_AC02, 174 MT_LMAC_AC03, 175 MT_LMAC_ALTX0 = 0x10, 176 MT_LMAC_BMC0, 177 MT_LMAC_BCN0, 178 }; 179 180 static inline struct mt7921_phy * 181 mt7921_hw_phy(struct ieee80211_hw *hw) 182 { 183 struct mt76_phy *phy = hw->priv; 184 185 return phy->priv; 186 } 187 188 static inline struct mt7921_dev * 189 mt7921_hw_dev(struct ieee80211_hw *hw) 190 { 191 struct mt76_phy *phy = hw->priv; 192 193 return container_of(phy->dev, struct mt7921_dev, mt76); 194 } 195 196 #define mt7921_mutex_acquire(dev) \ 197 mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm) 198 #define mt7921_mutex_release(dev) \ 199 mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm) 200 201 static inline u8 mt7921_lmac_mapping(struct mt7921_dev *dev, u8 ac) 202 { 203 /* LMAC uses the reverse order of mac80211 AC indexes */ 204 return 3 - ac; 205 } 206 207 extern const struct ieee80211_ops mt7921_ops; 208 extern struct pci_driver mt7921_pci_driver; 209 210 u32 mt7921_reg_map(struct mt7921_dev *dev, u32 addr); 211 212 int mt7921_register_device(struct mt7921_dev *dev); 213 void mt7921_unregister_device(struct mt7921_dev *dev); 214 int mt7921_eeprom_init(struct mt7921_dev *dev); 215 void mt7921_eeprom_parse_band_config(struct mt7921_phy *phy); 216 int mt7921_eeprom_get_target_power(struct mt7921_dev *dev, 217 struct ieee80211_channel *chan, 218 u8 chain_idx); 219 void mt7921_eeprom_init_sku(struct mt7921_dev *dev); 220 int mt7921_dma_init(struct mt7921_dev *dev); 221 void mt7921_dma_prefetch(struct mt7921_dev *dev); 222 void mt7921_dma_cleanup(struct mt7921_dev *dev); 223 int mt7921_mcu_init(struct mt7921_dev *dev); 224 int mt7921_mcu_add_bss_info(struct mt7921_phy *phy, 225 struct ieee80211_vif *vif, int enable); 226 int mt7921_mcu_add_key(struct mt7921_dev *dev, struct ieee80211_vif *vif, 227 struct mt7921_sta *msta, struct ieee80211_key_conf *key, 228 enum set_key_cmd cmd); 229 int mt7921_set_channel(struct mt7921_phy *phy); 230 int mt7921_mcu_set_chan_info(struct mt7921_phy *phy, int cmd); 231 int mt7921_mcu_set_tx(struct mt7921_dev *dev, struct ieee80211_vif *vif); 232 int mt7921_mcu_set_eeprom(struct mt7921_dev *dev); 233 int mt7921_mcu_get_eeprom(struct mt7921_dev *dev, u32 offset); 234 int mt7921_mcu_get_rx_rate(struct mt7921_phy *phy, struct ieee80211_vif *vif, 235 struct ieee80211_sta *sta, struct rate_info *rate); 236 int mt7921_mcu_fw_log_2_host(struct mt7921_dev *dev, u8 ctrl); 237 void mt7921_mcu_rx_event(struct mt7921_dev *dev, struct sk_buff *skb); 238 void mt7921_mcu_exit(struct mt7921_dev *dev); 239 240 static inline void mt7921_irq_enable(struct mt7921_dev *dev, u32 mask) 241 { 242 mt76_set_irq_mask(&dev->mt76, 0, 0, mask); 243 244 tasklet_schedule(&dev->irq_tasklet); 245 } 246 247 static inline u32 248 mt7921_reg_map_l1(struct mt7921_dev *dev, u32 addr) 249 { 250 u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr); 251 u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr); 252 253 mt76_rmw_field(dev, MT_HIF_REMAP_L1, MT_HIF_REMAP_L1_MASK, base); 254 /* use read to push write */ 255 mt76_rr(dev, MT_HIF_REMAP_L1); 256 257 return MT_HIF_REMAP_BASE_L1 + offset; 258 } 259 260 static inline u32 261 mt7921_l1_rr(struct mt7921_dev *dev, u32 addr) 262 { 263 return mt76_rr(dev, mt7921_reg_map_l1(dev, addr)); 264 } 265 266 static inline void 267 mt7921_l1_wr(struct mt7921_dev *dev, u32 addr, u32 val) 268 { 269 mt76_wr(dev, mt7921_reg_map_l1(dev, addr), val); 270 } 271 272 static inline u32 273 mt7921_l1_rmw(struct mt7921_dev *dev, u32 addr, u32 mask, u32 val) 274 { 275 val |= mt7921_l1_rr(dev, addr) & ~mask; 276 mt7921_l1_wr(dev, addr, val); 277 278 return val; 279 } 280 281 #define mt7921_l1_set(dev, addr, val) mt7921_l1_rmw(dev, addr, 0, val) 282 #define mt7921_l1_clear(dev, addr, val) mt7921_l1_rmw(dev, addr, val, 0) 283 284 bool mt7921_mac_wtbl_update(struct mt7921_dev *dev, int idx, u32 mask); 285 void mt7921_mac_reset_counters(struct mt7921_phy *phy); 286 void mt7921_mac_write_txwi(struct mt7921_dev *dev, __le32 *txwi, 287 struct sk_buff *skb, struct mt76_wcid *wcid, 288 struct ieee80211_key_conf *key, bool beacon); 289 void mt7921_mac_set_timing(struct mt7921_phy *phy); 290 int mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb); 291 void mt7921_mac_fill_rx_vector(struct mt7921_dev *dev, struct sk_buff *skb); 292 void mt7921_mac_tx_free(struct mt7921_dev *dev, struct sk_buff *skb); 293 int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 294 struct ieee80211_sta *sta); 295 void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 296 struct ieee80211_sta *sta); 297 void mt7921_mac_work(struct work_struct *work); 298 void mt7921_mac_reset_work(struct work_struct *work); 299 int mt7921_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 300 enum mt76_txq_id qid, struct mt76_wcid *wcid, 301 struct ieee80211_sta *sta, 302 struct mt76_tx_info *tx_info); 303 void mt7921_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e); 304 int mt7921_init_tx_queues(struct mt7921_phy *phy, int idx, int n_desc); 305 void mt7921_tx_token_put(struct mt7921_dev *dev); 306 void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, 307 struct sk_buff *skb); 308 void mt7921_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps); 309 void mt7921_stats_work(struct work_struct *work); 310 void mt7921_txp_skb_unmap(struct mt76_dev *dev, 311 struct mt76_txwi_cache *txwi); 312 void mt7921_set_stream_he_caps(struct mt7921_phy *phy); 313 void mt7921_update_channel(struct mt76_dev *mdev); 314 int mt7921_init_debugfs(struct mt7921_dev *dev); 315 316 int mt7921_mcu_uni_tx_ba(struct mt7921_dev *dev, 317 struct ieee80211_ampdu_params *params, 318 bool enable); 319 int mt7921_mcu_uni_rx_ba(struct mt7921_dev *dev, 320 struct ieee80211_ampdu_params *params, 321 bool enable); 322 void mt7921_scan_work(struct work_struct *work); 323 u32 mt7921_get_wtbl_info(struct mt7921_dev *dev, u32 wlan_idx); 324 int mt7921_mcu_uni_bss_ps(struct mt7921_dev *dev, struct ieee80211_vif *vif); 325 int mt7921_mcu_uni_bss_bcnft(struct mt7921_dev *dev, struct ieee80211_vif *vif, 326 bool enable); 327 int mt7921_mcu_set_bss_pm(struct mt7921_dev *dev, struct ieee80211_vif *vif, 328 bool enable); 329 int mt7921_mcu_update_arp_filter(struct ieee80211_hw *hw, 330 struct ieee80211_vif *vif, 331 struct ieee80211_bss_conf *info); 332 int mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev); 333 int mt7921_mcu_fw_pmctrl(struct mt7921_dev *dev); 334 void mt7921_pm_wake_work(struct work_struct *work); 335 void mt7921_pm_power_save_work(struct work_struct *work); 336 bool mt7921_wait_for_mcu_init(struct mt7921_dev *dev); 337 int mt7921_mac_set_beacon_filter(struct mt7921_phy *phy, 338 struct ieee80211_vif *vif, 339 bool enable); 340 void mt7921_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif); 341 void mt7921_coredump_work(struct work_struct *work); 342 #endif 343