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 enum { 163 TXPWR_USER, 164 TXPWR_EEPROM, 165 TXPWR_MAC, 166 TXPWR_MAX_NUM, 167 }; 168 169 struct mt7921_txpwr { 170 u8 ch; 171 u8 rsv[3]; 172 struct { 173 u8 ch; 174 u8 cck[4]; 175 u8 ofdm[8]; 176 u8 ht20[8]; 177 u8 ht40[9]; 178 u8 vht20[12]; 179 u8 vht40[12]; 180 u8 vht80[12]; 181 u8 vht160[12]; 182 u8 he26[12]; 183 u8 he52[12]; 184 u8 he106[12]; 185 u8 he242[12]; 186 u8 he484[12]; 187 u8 he996[12]; 188 u8 he996x2[12]; 189 } data[TXPWR_MAX_NUM]; 190 }; 191 192 extern const struct ieee80211_ops mt7921_ops; 193 194 u32 mt7921_reg_map(struct mt792x_dev *dev, u32 addr); 195 196 int __mt7921_start(struct mt792x_phy *phy); 197 int mt7921_register_device(struct mt792x_dev *dev); 198 void mt7921_unregister_device(struct mt792x_dev *dev); 199 int mt7921_dma_init(struct mt792x_dev *dev); 200 int mt7921_run_firmware(struct mt792x_dev *dev); 201 int mt7921_mcu_set_bss_pm(struct mt792x_dev *dev, struct ieee80211_vif *vif, 202 bool enable); 203 int mt7921_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_sta *sta, 204 struct ieee80211_vif *vif, bool enable, 205 enum mt76_sta_info_state state); 206 int mt7921_mcu_set_chan_info(struct mt792x_phy *phy, int cmd); 207 int mt7921_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_vif *vif); 208 int mt7921_mcu_set_eeprom(struct mt792x_dev *dev); 209 int mt7921_mcu_get_rx_rate(struct mt792x_phy *phy, struct ieee80211_vif *vif, 210 struct ieee80211_sta *sta, struct rate_info *rate); 211 int mt7921_mcu_fw_log_2_host(struct mt792x_dev *dev, u8 ctrl); 212 void mt7921_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb); 213 int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, 214 u8 bit_op, u32 bit_map); 215 216 static inline u32 217 mt7921_reg_map_l1(struct mt792x_dev *dev, u32 addr) 218 { 219 u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr); 220 u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr); 221 222 mt76_rmw_field(dev, MT_HIF_REMAP_L1, MT_HIF_REMAP_L1_MASK, base); 223 /* use read to push write */ 224 mt76_rr(dev, MT_HIF_REMAP_L1); 225 226 return MT_HIF_REMAP_BASE_L1 + offset; 227 } 228 229 static inline u32 230 mt7921_l1_rr(struct mt792x_dev *dev, u32 addr) 231 { 232 return mt76_rr(dev, mt7921_reg_map_l1(dev, addr)); 233 } 234 235 static inline void 236 mt7921_l1_wr(struct mt792x_dev *dev, u32 addr, u32 val) 237 { 238 mt76_wr(dev, mt7921_reg_map_l1(dev, addr), val); 239 } 240 241 static inline u32 242 mt7921_l1_rmw(struct mt792x_dev *dev, u32 addr, u32 mask, u32 val) 243 { 244 val |= mt7921_l1_rr(dev, addr) & ~mask; 245 mt7921_l1_wr(dev, addr, val); 246 247 return val; 248 } 249 250 #define mt7921_l1_set(dev, addr, val) mt7921_l1_rmw(dev, addr, 0, val) 251 #define mt7921_l1_clear(dev, addr, val) mt7921_l1_rmw(dev, addr, val, 0) 252 253 static inline void 254 mt7921_skb_add_usb_sdio_hdr(struct mt792x_dev *dev, struct sk_buff *skb, 255 int type) 256 { 257 u32 hdr, len; 258 259 len = mt76_is_usb(&dev->mt76) ? skb->len : skb->len + sizeof(hdr); 260 hdr = FIELD_PREP(MT7921_SDIO_HDR_TX_BYTES, len) | 261 FIELD_PREP(MT7921_SDIO_HDR_PKT_TYPE, type); 262 263 put_unaligned_le32(hdr, skb_push(skb, sizeof(hdr))); 264 } 265 266 void mt7921_stop(struct ieee80211_hw *hw); 267 int mt7921_mac_init(struct mt792x_dev *dev); 268 bool mt7921_mac_wtbl_update(struct mt792x_dev *dev, int idx, u32 mask); 269 int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 270 struct ieee80211_sta *sta); 271 void mt7921_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif, 272 struct ieee80211_sta *sta); 273 void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 274 struct ieee80211_sta *sta); 275 void mt7921_mac_reset_work(struct work_struct *work); 276 int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 277 enum mt76_txq_id qid, struct mt76_wcid *wcid, 278 struct ieee80211_sta *sta, 279 struct mt76_tx_info *tx_info); 280 281 bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len); 282 void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, 283 struct sk_buff *skb, u32 *info); 284 void mt7921_stats_work(struct work_struct *work); 285 void mt7921_set_stream_he_caps(struct mt792x_phy *phy); 286 int mt7921_init_debugfs(struct mt792x_dev *dev); 287 288 int mt7921_mcu_set_beacon_filter(struct mt792x_dev *dev, 289 struct ieee80211_vif *vif, 290 bool enable); 291 int mt7921_mcu_uni_tx_ba(struct mt792x_dev *dev, 292 struct ieee80211_ampdu_params *params, 293 bool enable); 294 int mt7921_mcu_uni_rx_ba(struct mt792x_dev *dev, 295 struct ieee80211_ampdu_params *params, 296 bool enable); 297 void mt7921_scan_work(struct work_struct *work); 298 void mt7921_roc_work(struct work_struct *work); 299 int mt7921_mcu_uni_bss_ps(struct mt792x_dev *dev, struct ieee80211_vif *vif); 300 int mt7921_mcu_drv_pmctrl(struct mt792x_dev *dev); 301 int mt7921_mcu_fw_pmctrl(struct mt792x_dev *dev); 302 void mt7921_pm_wake_work(struct work_struct *work); 303 void mt7921_pm_power_save_work(struct work_struct *work); 304 void mt7921_coredump_work(struct work_struct *work); 305 int mt7921_get_txpwr_info(struct mt792x_dev *dev, struct mt7921_txpwr *txpwr); 306 int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 307 void *data, int len); 308 int mt7921_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg, 309 struct netlink_callback *cb, void *data, int len); 310 int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd, 311 struct sk_buff *skb, int seq); 312 313 int mt7921e_driver_own(struct mt792x_dev *dev); 314 int mt7921e_mac_reset(struct mt792x_dev *dev); 315 int mt7921e_mcu_init(struct mt792x_dev *dev); 316 int mt7921s_wfsys_reset(struct mt792x_dev *dev); 317 int mt7921s_mac_reset(struct mt792x_dev *dev); 318 int mt7921s_init_reset(struct mt792x_dev *dev); 319 int __mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev); 320 int mt7921e_mcu_drv_pmctrl(struct mt792x_dev *dev); 321 int mt7921e_mcu_fw_pmctrl(struct mt792x_dev *dev); 322 323 int mt7921s_mcu_init(struct mt792x_dev *dev); 324 int mt7921s_mcu_drv_pmctrl(struct mt792x_dev *dev); 325 int mt7921s_mcu_fw_pmctrl(struct mt792x_dev *dev); 326 void mt7921_mac_add_txs(struct mt792x_dev *dev, void *data); 327 void mt7921_set_runtime_pm(struct mt792x_dev *dev); 328 void mt7921_mcu_set_suspend_iter(void *priv, u8 *mac, 329 struct ieee80211_vif *vif); 330 void mt7921_set_ipv6_ns_work(struct work_struct *work); 331 332 int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, 333 bool enable); 334 int mt7921_mcu_config_sniffer(struct mt792x_vif *vif, 335 struct ieee80211_chanctx_conf *ctx); 336 int mt7921_mcu_get_temperature(struct mt792x_phy *phy); 337 338 int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, 339 enum mt76_txq_id qid, struct mt76_wcid *wcid, 340 struct ieee80211_sta *sta, 341 struct mt76_tx_info *tx_info); 342 void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev, 343 struct mt76_queue_entry *e); 344 bool mt7921_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update); 345 346 /* usb */ 347 #define MT_USB_TYPE_VENDOR (USB_TYPE_VENDOR | 0x1f) 348 #define MT_USB_TYPE_UHW_VENDOR (USB_TYPE_VENDOR | 0x1e) 349 350 int mt7921u_mcu_power_on(struct mt792x_dev *dev); 351 int mt7921u_wfsys_reset(struct mt792x_dev *dev); 352 int mt7921u_dma_init(struct mt792x_dev *dev, bool resume); 353 int mt7921u_init_reset(struct mt792x_dev *dev); 354 int mt7921u_mac_reset(struct mt792x_dev *dev); 355 int mt7921_mcu_uni_add_beacon_offload(struct mt792x_dev *dev, 356 struct ieee80211_hw *hw, 357 struct ieee80211_vif *vif, 358 bool enable); 359 #ifdef CONFIG_ACPI 360 int mt7921_init_acpi_sar(struct mt792x_dev *dev); 361 int mt7921_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default); 362 u8 mt7921_acpi_get_flags(struct mt792x_phy *phy); 363 #else 364 static inline int 365 mt7921_init_acpi_sar(struct mt792x_dev *dev) 366 { 367 return 0; 368 } 369 370 static inline int 371 mt7921_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default) 372 { 373 return 0; 374 } 375 376 static inline u8 377 mt7921_acpi_get_flags(struct mt792x_phy *phy) 378 { 379 return 0; 380 } 381 #endif 382 int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw, 383 const struct cfg80211_sar_specs *sar); 384 385 int mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, 386 enum environment_cap env_cap); 387 int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif, 388 struct ieee80211_channel *chan, int duration, 389 enum mt7921_roc_req type, u8 token_id); 390 int mt7921_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif, 391 u8 token_id); 392 #endif 393