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