1 /* SPDX-License-Identifier: ISC */ 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 4 #ifndef __MT7921_H 5 #define __MT7921_H 6 7 #include "../mt792x.h" 8 #include "regs.h" 9 #include "acpi_sar.h" 10 11 #define MT7921_PM_TIMEOUT (HZ / 12) 12 #define MT7921_HW_SCAN_TIMEOUT (HZ / 10) 13 14 #define MT7921_TX_RING_SIZE 2048 15 #define MT7921_TX_MCU_RING_SIZE 256 16 #define MT7921_TX_FWDL_RING_SIZE 128 17 18 #define MT7921_RX_RING_SIZE 1536 19 #define MT7921_RX_MCU_RING_SIZE 512 20 21 #define MT7921_DRV_OWN_RETRY_COUNT 10 22 #define MT7921_MCU_INIT_RETRY_COUNT 10 23 #define MT7921_WFSYS_INIT_RETRY_COUNT 2 24 25 #define MT7921_FW_TAG_FEATURE 4 26 #define MT7921_FW_CAP_CNM BIT(7) 27 28 #define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin" 29 #define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin" 30 31 #define MT7922_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7922_1.bin" 32 #define MT7922_ROM_PATCH "mediatek/WIFI_MT7922_patch_mcu_1_1_hdr.bin" 33 34 #define MT7921_EEPROM_SIZE 3584 35 #define MT7921_TOKEN_SIZE 8192 36 37 #define MT7921_EEPROM_BLOCK_SIZE 16 38 39 #define MT7921_SKU_RATE_NUM 161 40 #define MT7921_SKU_MAX_DELTA_IDX MT7921_SKU_RATE_NUM 41 #define MT7921_SKU_TABLE_SIZE (MT7921_SKU_RATE_NUM + 1) 42 43 #define MT7921_SDIO_HDR_TX_BYTES GENMASK(15, 0) 44 #define MT7921_SDIO_HDR_PKT_TYPE GENMASK(17, 16) 45 46 #define MCU_UNI_EVENT_ROC 0x27 47 48 enum { 49 UNI_ROC_ACQUIRE, 50 UNI_ROC_ABORT, 51 UNI_ROC_NUM 52 }; 53 54 enum mt7921_roc_req { 55 MT7921_ROC_REQ_JOIN, 56 MT7921_ROC_REQ_ROC, 57 MT7921_ROC_REQ_NUM 58 }; 59 60 enum { 61 UNI_EVENT_ROC_GRANT = 0, 62 UNI_EVENT_ROC_TAG_NUM 63 }; 64 65 struct mt7921_realease_info { 66 __le16 len; 67 u8 pad_len; 68 u8 tag; 69 } __packed; 70 71 struct mt7921_fw_features { 72 u8 segment; 73 u8 data; 74 u8 rsv[14]; 75 } __packed; 76 77 struct mt7921_roc_grant_tlv { 78 __le16 tag; 79 __le16 len; 80 u8 bss_idx; 81 u8 tokenid; 82 u8 status; 83 u8 primarychannel; 84 u8 rfsco; 85 u8 rfband; 86 u8 channelwidth; 87 u8 centerfreqseg1; 88 u8 centerfreqseg2; 89 u8 reqtype; 90 u8 dbdcband; 91 u8 rsv[1]; 92 __le32 max_interval; 93 } __packed; 94 95 enum mt7921_sdio_pkt_type { 96 MT7921_SDIO_TXD, 97 MT7921_SDIO_DATA, 98 MT7921_SDIO_CMD, 99 MT7921_SDIO_FWDL, 100 }; 101 102 struct mt7921_sdio_intr { 103 u32 isr; 104 struct { 105 u32 wtqcr[16]; 106 } tx; 107 struct { 108 u16 num[2]; 109 u16 len0[16]; 110 u16 len1[128]; 111 } rx; 112 u32 rec_mb[2]; 113 } __packed; 114 115 #define to_rssi(field, rxv) ((FIELD_GET(field, rxv) - 220) / 2) 116 #define to_rcpi(rssi) (2 * (rssi) + 220) 117 118 enum mt7921_txq_id { 119 MT7921_TXQ_BAND0, 120 MT7921_TXQ_BAND1, 121 MT7921_TXQ_FWDL = 16, 122 MT7921_TXQ_MCU_WM, 123 }; 124 125 enum mt7921_rxq_id { 126 MT7921_RXQ_BAND0 = 0, 127 MT7921_RXQ_BAND1, 128 MT7921_RXQ_MCU_WM = 0, 129 }; 130 131 enum { 132 MT7921_CLC_POWER, 133 MT7921_CLC_CHAN, 134 MT7921_CLC_MAX_NUM, 135 }; 136 137 struct mt7921_clc_rule { 138 u8 alpha2[2]; 139 u8 type[2]; 140 __le16 len; 141 u8 data[]; 142 } __packed; 143 144 struct mt7921_clc { 145 __le32 len; 146 u8 idx; 147 u8 ver; 148 u8 nr_country; 149 u8 type; 150 u8 rsv[8]; 151 u8 data[]; 152 } __packed; 153 154 enum mt7921_eeprom_field { 155 MT_EE_CHIP_ID = 0x000, 156 MT_EE_VERSION = 0x002, 157 MT_EE_MAC_ADDR = 0x004, 158 MT_EE_WIFI_CONF = 0x07c, 159 MT_EE_HW_TYPE = 0x55b, 160 __MT_EE_MAX = 0x9ff 161 }; 162 163 #define MT_EE_HW_TYPE_ENCAP BIT(0) 164 165 #define mt7921_init_reset(dev) ((dev)->hif_ops->init_reset(dev)) 166 #define mt7921_dev_reset(dev) ((dev)->hif_ops->reset(dev)) 167 #define mt7921_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev)) 168 #define __mt7921_mcu_drv_pmctrl(dev) ((dev)->hif_ops->drv_own(dev)) 169 #define __mt7921_mcu_fw_pmctrl(dev) ((dev)->hif_ops->fw_own(dev)) 170 171 enum { 172 TXPWR_USER, 173 TXPWR_EEPROM, 174 TXPWR_MAC, 175 TXPWR_MAX_NUM, 176 }; 177 178 struct mt7921_txpwr { 179 u8 ch; 180 u8 rsv[3]; 181 struct { 182 u8 ch; 183 u8 cck[4]; 184 u8 ofdm[8]; 185 u8 ht20[8]; 186 u8 ht40[9]; 187 u8 vht20[12]; 188 u8 vht40[12]; 189 u8 vht80[12]; 190 u8 vht160[12]; 191 u8 he26[12]; 192 u8 he52[12]; 193 u8 he106[12]; 194 u8 he242[12]; 195 u8 he484[12]; 196 u8 he996[12]; 197 u8 he996x2[12]; 198 } data[TXPWR_MAX_NUM]; 199 }; 200 201 extern const struct ieee80211_ops mt7921_ops; 202 203 u32 mt7921_reg_map(struct mt792x_dev *dev, u32 addr); 204 205 int __mt7921_start(struct mt792x_phy *phy); 206 int mt7921_register_device(struct mt792x_dev *dev); 207 void mt7921_unregister_device(struct mt792x_dev *dev); 208 int mt7921_dma_init(struct mt792x_dev *dev); 209 int mt7921_wpdma_reset(struct mt792x_dev *dev, bool force); 210 int mt7921_wpdma_reinit_cond(struct mt792x_dev *dev); 211 void mt7921_dma_cleanup(struct mt792x_dev *dev); 212 int mt7921_run_firmware(struct mt792x_dev *dev); 213 int mt7921_mcu_set_bss_pm(struct mt792x_dev *dev, struct ieee80211_vif *vif, 214 bool enable); 215 int mt7921_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_sta *sta, 216 struct ieee80211_vif *vif, bool enable, 217 enum mt76_sta_info_state state); 218 int mt7921_mcu_set_chan_info(struct mt792x_phy *phy, int cmd); 219 int mt7921_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_vif *vif); 220 int mt7921_mcu_set_eeprom(struct mt792x_dev *dev); 221 int mt7921_mcu_get_rx_rate(struct mt792x_phy *phy, struct ieee80211_vif *vif, 222 struct ieee80211_sta *sta, struct rate_info *rate); 223 int mt7921_mcu_fw_log_2_host(struct mt792x_dev *dev, u8 ctrl); 224 void mt7921_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb); 225 int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, 226 u8 bit_op, u32 bit_map); 227 228 static inline u32 229 mt7921_reg_map_l1(struct mt792x_dev *dev, u32 addr) 230 { 231 u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr); 232 u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr); 233 234 mt76_rmw_field(dev, MT_HIF_REMAP_L1, MT_HIF_REMAP_L1_MASK, base); 235 /* use read to push write */ 236 mt76_rr(dev, MT_HIF_REMAP_L1); 237 238 return MT_HIF_REMAP_BASE_L1 + offset; 239 } 240 241 static inline u32 242 mt7921_l1_rr(struct mt792x_dev *dev, u32 addr) 243 { 244 return mt76_rr(dev, mt7921_reg_map_l1(dev, addr)); 245 } 246 247 static inline void 248 mt7921_l1_wr(struct mt792x_dev *dev, u32 addr, u32 val) 249 { 250 mt76_wr(dev, mt7921_reg_map_l1(dev, addr), val); 251 } 252 253 static inline u32 254 mt7921_l1_rmw(struct mt792x_dev *dev, u32 addr, u32 mask, u32 val) 255 { 256 val |= mt7921_l1_rr(dev, addr) & ~mask; 257 mt7921_l1_wr(dev, addr, val); 258 259 return val; 260 } 261 262 #define mt7921_l1_set(dev, addr, val) mt7921_l1_rmw(dev, addr, 0, val) 263 #define mt7921_l1_clear(dev, addr, val) mt7921_l1_rmw(dev, addr, val, 0) 264 265 static inline bool mt7921_dma_need_reinit(struct mt792x_dev *dev) 266 { 267 return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT); 268 } 269 270 static inline void 271 mt7921_skb_add_usb_sdio_hdr(struct mt792x_dev *dev, struct sk_buff *skb, 272 int type) 273 { 274 u32 hdr, len; 275 276 len = mt76_is_usb(&dev->mt76) ? skb->len : skb->len + sizeof(hdr); 277 hdr = FIELD_PREP(MT7921_SDIO_HDR_TX_BYTES, len) | 278 FIELD_PREP(MT7921_SDIO_HDR_PKT_TYPE, type); 279 280 put_unaligned_le32(hdr, skb_push(skb, sizeof(hdr))); 281 } 282 283 void mt7921_stop(struct ieee80211_hw *hw); 284 int mt7921_mac_init(struct mt792x_dev *dev); 285 void mt7921_mac_reset_counters(struct mt792x_phy *phy); 286 bool mt7921_mac_wtbl_update(struct mt792x_dev *dev, int idx, u32 mask); 287 int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 288 struct ieee80211_sta *sta); 289 void mt7921_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif, 290 struct ieee80211_sta *sta); 291 void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 292 struct ieee80211_sta *sta); 293 void mt7921_mac_reset_work(struct work_struct *work); 294 void mt7921_reset(struct mt76_dev *mdev); 295 int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 296 enum mt76_txq_id qid, struct mt76_wcid *wcid, 297 struct ieee80211_sta *sta, 298 struct mt76_tx_info *tx_info); 299 300 bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len); 301 void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, 302 struct sk_buff *skb, u32 *info); 303 void mt7921_stats_work(struct work_struct *work); 304 void mt7921_set_stream_he_caps(struct mt792x_phy *phy); 305 void mt7921_update_channel(struct mt76_phy *mphy); 306 int mt7921_init_debugfs(struct mt792x_dev *dev); 307 308 int mt7921_mcu_set_beacon_filter(struct mt792x_dev *dev, 309 struct ieee80211_vif *vif, 310 bool enable); 311 int mt7921_mcu_uni_tx_ba(struct mt792x_dev *dev, 312 struct ieee80211_ampdu_params *params, 313 bool enable); 314 int mt7921_mcu_uni_rx_ba(struct mt792x_dev *dev, 315 struct ieee80211_ampdu_params *params, 316 bool enable); 317 void mt7921_scan_work(struct work_struct *work); 318 void mt7921_roc_work(struct work_struct *work); 319 int mt7921_mcu_uni_bss_ps(struct mt792x_dev *dev, struct ieee80211_vif *vif); 320 int mt7921_mcu_drv_pmctrl(struct mt792x_dev *dev); 321 int mt7921_mcu_fw_pmctrl(struct mt792x_dev *dev); 322 void mt7921_pm_wake_work(struct work_struct *work); 323 void mt7921_pm_power_save_work(struct work_struct *work); 324 void mt7921_coredump_work(struct work_struct *work); 325 int mt7921_wfsys_reset(struct mt792x_dev *dev); 326 int mt7921_get_txpwr_info(struct mt792x_dev *dev, struct mt7921_txpwr *txpwr); 327 int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 328 void *data, int len); 329 int mt7921_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg, 330 struct netlink_callback *cb, void *data, int len); 331 int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd, 332 struct sk_buff *skb, int seq); 333 334 int mt7921e_driver_own(struct mt792x_dev *dev); 335 int mt7921e_mac_reset(struct mt792x_dev *dev); 336 int mt7921e_mcu_init(struct mt792x_dev *dev); 337 int mt7921s_wfsys_reset(struct mt792x_dev *dev); 338 int mt7921s_mac_reset(struct mt792x_dev *dev); 339 int mt7921s_init_reset(struct mt792x_dev *dev); 340 int __mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev); 341 int mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev); 342 int mt7921e_mcu_fw_pmctrl(struct mt792x_dev *dev); 343 344 int mt7921s_mcu_init(struct mt792x_dev *dev); 345 int mt7921s_mcu_drv_pmctrl(struct mt792x_dev *dev); 346 int mt7921s_mcu_fw_pmctrl(struct mt792x_dev *dev); 347 void mt7921_mac_add_txs(struct mt792x_dev *dev, void *data); 348 void mt7921_set_runtime_pm(struct mt792x_dev *dev); 349 void mt7921_mcu_set_suspend_iter(void *priv, u8 *mac, 350 struct ieee80211_vif *vif); 351 void mt7921_set_ipv6_ns_work(struct work_struct *work); 352 353 int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, 354 bool enable); 355 int mt7921_mcu_config_sniffer(struct mt792x_vif *vif, 356 struct ieee80211_chanctx_conf *ctx); 357 int mt7921_mcu_get_temperature(struct mt792x_phy *phy); 358 359 int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 360 enum mt76_txq_id qid, struct mt76_wcid *wcid, 361 struct ieee80211_sta *sta, 362 struct mt76_tx_info *tx_info); 363 void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev, 364 struct mt76_queue_entry *e); 365 bool mt7921_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update); 366 367 /* usb */ 368 #define MT_USB_TYPE_VENDOR (USB_TYPE_VENDOR | 0x1f) 369 #define MT_USB_TYPE_UHW_VENDOR (USB_TYPE_VENDOR | 0x1e) 370 371 int mt7921u_mcu_power_on(struct mt792x_dev *dev); 372 int mt7921u_wfsys_reset(struct mt792x_dev *dev); 373 int mt7921u_dma_init(struct mt792x_dev *dev, bool resume); 374 int mt7921u_init_reset(struct mt792x_dev *dev); 375 int mt7921u_mac_reset(struct mt792x_dev *dev); 376 int mt7921_mcu_uni_add_beacon_offload(struct mt792x_dev *dev, 377 struct ieee80211_hw *hw, 378 struct ieee80211_vif *vif, 379 bool enable); 380 #ifdef CONFIG_ACPI 381 int mt7921_init_acpi_sar(struct mt792x_dev *dev); 382 int mt7921_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default); 383 u8 mt7921_acpi_get_flags(struct mt792x_phy *phy); 384 #else 385 static inline int 386 mt7921_init_acpi_sar(struct mt792x_dev *dev) 387 { 388 return 0; 389 } 390 391 static inline int 392 mt7921_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default) 393 { 394 return 0; 395 } 396 397 static inline u8 398 mt7921_acpi_get_flags(struct mt792x_phy *phy) 399 { 400 return 0; 401 } 402 #endif 403 int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw, 404 const struct cfg80211_sar_specs *sar); 405 406 int mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, 407 enum environment_cap env_cap); 408 int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif, 409 struct ieee80211_channel *chan, int duration, 410 enum mt7921_roc_req type, u8 token_id); 411 int mt7921_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif, 412 u8 token_id); 413 struct ieee80211_ops *mt7921_get_mac80211_ops(struct device *dev, 414 void *drv_data, u8 *fw_features); 415 #endif 416