| 1 |
/* SPDX-License-Identifier: BSD-3-Clause-Clear */ |
| 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 |
|
| 10 |
#define MT7921_MAX_AID 20 |
| 11 |
|
| 12 |
#define MT7921_TX_RING_SIZE 2048 |
| 13 |
#define MT7921_TX_MCU_RING_SIZE 256 |
| 14 |
#define MT7921_TX_FWDL_RING_SIZE 128 |
| 15 |
|
| 16 |
#define MT7921_RX_RING_SIZE 1536 |
| 17 |
#define MT7921_RX_MCU_RING_SIZE 8 |
| 18 |
#define MT7921_RX_MCU_WA_RING_SIZE 512 |
| 19 |
|
| 20 |
#define MT7921_EEPROM_SIZE 3584 |
| 21 |
#define MT7921_TOKEN_SIZE 8192 |
| 22 |
|
| 23 |
#define MT7921_EEPROM_BLOCK_SIZE 16 |
| 24 |
|
| 25 |
#define MT7921_SKU_RATE_NUM 161 |
| 26 |
#define MT7921_SKU_MAX_DELTA_IDX MT7921_SKU_RATE_NUM |
| 27 |
#define MT7921_SKU_TABLE_SIZE (MT7921_SKU_RATE_NUM + 1) |
| 28 |
|
| 29 |
#define MCU_UNI_EVENT_ROC 0x27 |
| 30 |
#define MCU_UNI_EVENT_CLC 0x80 |
| 31 |
|
| 32 |
#define EXT_CMD_RADIO_LED_CTRL_ENABLE 0x1 |
| 33 |
#define EXT_CMD_RADIO_ON_LED 0x2 |
| 34 |
#define EXT_CMD_RADIO_OFF_LED 0x3 |
| 35 |
|
| 36 |
#define WF_RF_PIN_INIT 0x0 |
| 37 |
#define WF_RF_PIN_POLL 0x1 |
| 38 |
|
| 39 |
enum { |
| 40 |
UNI_ROC_ACQUIRE, |
| 41 |
UNI_ROC_ABORT, |
| 42 |
UNI_ROC_NUM |
| 43 |
}; |
| 44 |
|
| 45 |
enum mt7921_roc_req { |
| 46 |
MT7921_ROC_REQ_JOIN, |
| 47 |
MT7921_ROC_REQ_ROC, |
| 48 |
MT7921_ROC_REQ_NUM |
| 49 |
}; |
| 50 |
|
| 51 |
enum { |
| 52 |
UNI_EVENT_ROC_GRANT = 0, |
| 53 |
UNI_EVENT_ROC_TAG_NUM |
| 54 |
}; |
| 55 |
|
| 56 |
struct mt7921_realease_info { |
| 57 |
__le16 len; |
| 58 |
u8 pad_len; |
| 59 |
u8 tag; |
| 60 |
} __packed; |
| 61 |
|
| 62 |
struct mt7921_fw_features { |
| 63 |
u8 segment; |
| 64 |
u8 data; |
| 65 |
u8 rsv[14]; |
| 66 |
} __packed; |
| 67 |
|
| 68 |
struct mt7921_roc_grant_tlv { |
| 69 |
__le16 tag; |
| 70 |
__le16 len; |
| 71 |
u8 bss_idx; |
| 72 |
u8 tokenid; |
| 73 |
u8 status; |
| 74 |
u8 primarychannel; |
| 75 |
u8 rfsco; |
| 76 |
u8 rfband; |
| 77 |
u8 channelwidth; |
| 78 |
u8 centerfreqseg1; |
| 79 |
u8 centerfreqseg2; |
| 80 |
u8 reqtype; |
| 81 |
u8 dbdcband; |
| 82 |
u8 rsv[1]; |
| 83 |
__le32 max_interval; |
| 84 |
} __packed; |
| 85 |
|
| 86 |
enum mt7921_sdio_pkt_type { |
| 87 |
MT7921_SDIO_TXD, |
| 88 |
MT7921_SDIO_DATA, |
| 89 |
MT7921_SDIO_CMD, |
| 90 |
MT7921_SDIO_FWDL, |
| 91 |
}; |
| 92 |
|
| 93 |
struct mt7921_sdio_intr { |
| 94 |
u32 isr; |
| 95 |
struct { |
| 96 |
u32 wtqcr[16]; |
| 97 |
} tx; |
| 98 |
struct { |
| 99 |
u16 num[2]; |
| 100 |
u16 len0[16]; |
| 101 |
u16 len1[128]; |
| 102 |
} rx; |
| 103 |
u32 rec_mb[2]; |
| 104 |
} __packed; |
| 105 |
|
| 106 |
#define to_rssi(field, rxv) ((FIELD_GET(field, rxv) - 220) / 2) |
| 107 |
#define to_rcpi(rssi) (2 * (rssi) + 220) |
| 108 |
|
| 109 |
enum mt7921_txq_id { |
| 110 |
MT7921_TXQ_BAND0, |
| 111 |
MT7921_TXQ_BAND1, |
| 112 |
MT7921_TXQ_FWDL = 16, |
| 113 |
MT7921_TXQ_MCU_WM, |
| 114 |
}; |
| 115 |
|
| 116 |
enum mt7921_rxq_id { |
| 117 |
MT7921_RXQ_BAND0 = 0, |
| 118 |
MT7921_RXQ_BAND1, |
| 119 |
MT7921_RXQ_MCU_WM = 0, |
| 120 |
}; |
| 121 |
|
| 122 |
enum { |
| 123 |
MT7921_CLC_POWER, |
| 124 |
MT7921_CLC_CHAN, |
| 125 |
MT7921_CLC_MAX_NUM, |
| 126 |
}; |
| 127 |
|
| 128 |
struct mt7921_clc_rule { |
| 129 |
u8 alpha2[2]; |
| 130 |
u8 type[2]; |
| 131 |
__le16 len; |
| 132 |
u8 data[]; |
| 133 |
} __packed; |
| 134 |
|
| 135 |
struct mt7921_clc { |
| 136 |
__le32 len; |
| 137 |
u8 idx; |
| 138 |
u8 ver; |
| 139 |
u8 nr_country; |
| 140 |
u8 type; |
| 141 |
u8 rsv[8]; |
| 142 |
u8 data[]; |
| 143 |
} __packed; |
| 144 |
|
| 145 |
enum mt7921_eeprom_field { |
| 146 |
MT_EE_CHIP_ID = 0x000, |
| 147 |
MT_EE_VERSION = 0x002, |
| 148 |
MT_EE_MAC_ADDR = 0x004, |
| 149 |
MT_EE_WIFI_CONF = 0x07c, |
| 150 |
MT_EE_HW_TYPE = 0x55b, |
| 151 |
__MT_EE_MAX = 0x9ff |
| 152 |
}; |
| 153 |
|
| 154 |
#define MT_EE_HW_TYPE_ENCAP BIT(0) |
| 155 |
|
| 156 |
enum { |
| 157 |
TXPWR_USER, |
| 158 |
TXPWR_EEPROM, |
| 159 |
TXPWR_MAC, |
| 160 |
TXPWR_MAX_NUM, |
| 161 |
}; |
| 162 |
|
| 163 |
struct mt7921_txpwr { |
| 164 |
u8 ch; |
| 165 |
u8 rsv[3]; |
| 166 |
struct { |
| 167 |
u8 ch; |
| 168 |
u8 cck[4]; |
| 169 |
u8 ofdm[8]; |
| 170 |
u8 ht20[8]; |
| 171 |
u8 ht40[9]; |
| 172 |
u8 vht20[12]; |
| 173 |
u8 vht40[12]; |
| 174 |
u8 vht80[12]; |
| 175 |
u8 vht160[12]; |
| 176 |
u8 he26[12]; |
| 177 |
u8 he52[12]; |
| 178 |
u8 he106[12]; |
| 179 |
u8 he242[12]; |
| 180 |
u8 he484[12]; |
| 181 |
u8 he996[12]; |
| 182 |
u8 he996x2[12]; |
| 183 |
} data[TXPWR_MAX_NUM]; |
| 184 |
}; |
| 185 |
|
| 186 |
extern const struct ieee80211_ops mt7921_ops; |
| 187 |
|
| 188 |
u32 mt7921_reg_map(struct mt792x_dev *dev, u32 addr); |
| 189 |
|
| 190 |
int __mt7921_start(struct mt792x_phy *phy); |
| 191 |
int mt7921_register_device(struct mt792x_dev *dev); |
| 192 |
void mt7921_unregister_device(struct mt792x_dev *dev); |
| 193 |
int mt7921_run_firmware(struct mt792x_dev *dev); |
| 194 |
int mt7921_set_channel(struct mt76_phy *mphy); |
| 195 |
int mt7921_mcu_set_bss_pm(struct mt792x_dev *dev, struct ieee80211_vif *vif, |
| 196 |
bool enable); |
| 197 |
int mt7921_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_sta *sta, |
| 198 |
struct ieee80211_vif *vif, bool enable, |
| 199 |
enum mt76_sta_info_state state); |
| 200 |
int mt7921_mcu_set_chan_info(struct mt792x_phy *phy, int cmd); |
| 201 |
int mt7921_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_vif *vif); |
| 202 |
int mt7921_mcu_set_eeprom(struct mt792x_dev *dev); |
| 203 |
int mt7921_mcu_get_rx_rate(struct mt792x_phy *phy, struct ieee80211_vif *vif, |
| 204 |
struct ieee80211_sta *sta, struct rate_info *rate); |
| 205 |
int mt7921_mcu_fw_log_2_host(struct mt792x_dev *dev, u8 ctrl); |
| 206 |
void mt7921_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb); |
| 207 |
int mt7921_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, |
| 208 |
u8 bit_op, u32 bit_map); |
| 209 |
int mt7921_mcu_radio_led_ctrl(struct mt792x_dev *dev, u8 value); |
| 210 |
int mt7921_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy, u8 action); |
| 211 |
|
| 212 |
static inline u32 |
| 213 |
mt7921_reg_map_l1(struct mt792x_dev *dev, u32 addr) |
| 214 |
{ |
| 215 |
u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr); |
| 216 |
u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr); |
| 217 |
|
| 218 |
mt76_rmw_field(dev, MT_HIF_REMAP_L1, MT_HIF_REMAP_L1_MASK, base); |
| 219 |
/* use read to push write */ |
| 220 |
mt76_rr(dev, MT_HIF_REMAP_L1); |
| 221 |
|
| 222 |
return MT_HIF_REMAP_BASE_L1 + offset; |
| 223 |
} |
| 224 |
|
| 225 |
static inline u32 |
| 226 |
mt7921_l1_rr(struct mt792x_dev *dev, u32 addr) |
| 227 |
{ |
| 228 |
return mt76_rr(dev, mt7921_reg_map_l1(dev, addr)); |
| 229 |
} |
| 230 |
|
| 231 |
static inline void |
| 232 |
mt7921_l1_wr(struct mt792x_dev *dev, u32 addr, u32 val) |
| 233 |
{ |
| 234 |
mt76_wr(dev, mt7921_reg_map_l1(dev, addr), val); |
| 235 |
} |
| 236 |
|
| 237 |
static inline u32 |
| 238 |
mt7921_l1_rmw(struct mt792x_dev *dev, u32 addr, u32 mask, u32 val) |
| 239 |
{ |
| 240 |
val |= mt7921_l1_rr(dev, addr) & ~mask; |
| 241 |
mt7921_l1_wr(dev, addr, val); |
| 242 |
|
| 243 |
return val; |
| 244 |
} |
| 245 |
|
| 246 |
#define mt7921_l1_set(dev, addr, val) mt7921_l1_rmw(dev, addr, 0, val) |
| 247 |
#define mt7921_l1_clear(dev, addr, val) mt7921_l1_rmw(dev, addr, val, 0) |
| 248 |
|
| 249 |
void mt7921_regd_update(struct mt792x_dev *dev); |
| 250 |
int mt7921_mac_init(struct mt792x_dev *dev); |
| 251 |
bool mt7921_mac_wtbl_update(struct mt792x_dev *dev, int idx, u32 mask); |
| 252 |
int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, |
| 253 |
struct ieee80211_sta *sta); |
| 254 |
int mt7921_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, |
| 255 |
struct ieee80211_sta *sta, enum mt76_sta_event ev); |
| 256 |
void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, |
| 257 |
struct ieee80211_sta *sta); |
| 258 |
void mt7921_mac_reset_work(struct work_struct *work); |
| 259 |
int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 260 |
enum mt76_txq_id qid, struct mt76_wcid *wcid, |
| 261 |
struct ieee80211_sta *sta, |
| 262 |
struct mt76_tx_info *tx_info); |
| 263 |
|
| 264 |
bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len); |
| 265 |
void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 266 |
struct sk_buff *skb, u32 *info); |
| 267 |
void mt7921_stats_work(struct work_struct *work); |
| 268 |
void mt7921_set_stream_he_caps(struct mt792x_phy *phy); |
| 269 |
int mt7921_init_debugfs(struct mt792x_dev *dev); |
| 270 |
|
| 271 |
int mt7921_mcu_set_beacon_filter(struct mt792x_dev *dev, |
| 272 |
struct ieee80211_vif *vif, |
| 273 |
bool enable); |
| 274 |
int mt7921_mcu_uni_tx_ba(struct mt792x_dev *dev, |
| 275 |
struct ieee80211_ampdu_params *params, |
| 276 |
bool enable); |
| 277 |
int mt7921_mcu_uni_rx_ba(struct mt792x_dev *dev, |
| 278 |
struct ieee80211_ampdu_params *params, |
| 279 |
bool enable); |
| 280 |
void mt7921_scan_work(struct work_struct *work); |
| 281 |
void mt7921_roc_work(struct work_struct *work); |
| 282 |
void mt7921_csa_work(struct work_struct *work); |
| 283 |
int mt7921_mcu_uni_bss_ps(struct mt792x_dev *dev, struct ieee80211_vif *vif); |
| 284 |
void mt7921_coredump_work(struct work_struct *work); |
| 285 |
int mt7921_get_txpwr_info(struct mt792x_dev *dev, struct mt7921_txpwr *txpwr); |
| 286 |
int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 287 |
void *data, int len); |
| 288 |
int mt7921_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg, |
| 289 |
struct netlink_callback *cb, void *data, int len); |
| 290 |
int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd, |
| 291 |
struct sk_buff *skb, int seq); |
| 292 |
|
| 293 |
int mt7921e_driver_own(struct mt792x_dev *dev); |
| 294 |
int mt7921e_mac_reset(struct mt792x_dev *dev); |
| 295 |
int mt7921e_mcu_init(struct mt792x_dev *dev); |
| 296 |
int mt7921s_wfsys_reset(struct mt792x_dev *dev); |
| 297 |
int mt7921s_mac_reset(struct mt792x_dev *dev); |
| 298 |
int mt7921s_init_reset(struct mt792x_dev *dev); |
| 299 |
|
| 300 |
int mt7921s_mcu_init(struct mt792x_dev *dev); |
| 301 |
int mt7921s_mcu_drv_pmctrl(struct mt792x_dev *dev); |
| 302 |
int mt7921s_mcu_fw_pmctrl(struct mt792x_dev *dev); |
| 303 |
void mt7921_mac_add_txs(struct mt792x_dev *dev, void *data); |
| 304 |
void mt7921_set_runtime_pm(struct mt792x_dev *dev); |
| 305 |
void mt7921_mcu_set_suspend_iter(void *priv, u8 *mac, |
| 306 |
struct ieee80211_vif *vif); |
| 307 |
void mt7921_set_ipv6_ns_work(struct work_struct *work); |
| 308 |
|
| 309 |
int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, |
| 310 |
bool enable); |
| 311 |
int mt7921_mcu_config_sniffer(struct mt792x_vif *vif, |
| 312 |
struct ieee80211_chanctx_conf *ctx); |
| 313 |
int mt7921_mcu_get_temperature(struct mt792x_phy *phy); |
| 314 |
|
| 315 |
int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 316 |
enum mt76_txq_id qid, struct mt76_wcid *wcid, |
| 317 |
struct ieee80211_sta *sta, |
| 318 |
struct mt76_tx_info *tx_info); |
| 319 |
void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev, |
| 320 |
struct mt76_queue_entry *e); |
| 321 |
bool mt7921_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update); |
| 322 |
|
| 323 |
/* usb */ |
| 324 |
int mt7921_mcu_uni_add_beacon_offload(struct mt792x_dev *dev, |
| 325 |
struct ieee80211_hw *hw, |
| 326 |
struct ieee80211_vif *vif, |
| 327 |
bool enable); |
| 328 |
int mt7921_set_tx_sar_pwr(struct ieee80211_hw *hw, |
| 329 |
const struct cfg80211_sar_specs *sar); |
| 330 |
|
| 331 |
int mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, |
| 332 |
enum environment_cap env_cap); |
| 333 |
int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif, |
| 334 |
struct ieee80211_channel *chan, int duration, |
| 335 |
enum mt7921_roc_req type, u8 token_id); |
| 336 |
int mt7921_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif, |
| 337 |
u8 token_id); |
| 338 |
void mt7921_roc_abort_sync(struct mt792x_dev *dev); |
| 339 |
int mt7921_mcu_set_rssimonitor(struct mt792x_dev *dev, struct ieee80211_vif *vif); |
| 340 |
#endif |