Path: blob/main/sys/contrib/dev/mediatek/mt76/mt792x.h
48375 views
/* SPDX-License-Identifier: ISC */1/* Copyright (C) 2023 MediaTek Inc. */23#ifndef __MT792X_H4#define __MT792X_H56#include <linux/interrupt.h>7#include <linux/ktime.h>89#include "mt76_connac_mcu.h"10#include "mt792x_regs.h"11#include "mt792x_acpi_sar.h"1213#define MT792x_PM_TIMEOUT (HZ / 12)14#define MT792x_HW_SCAN_TIMEOUT (HZ / 10)1516#define MT792x_MAX_INTERFACES 417#define MT792x_WTBL_SIZE 2018#define MT792x_WTBL_RESERVED (MT792x_WTBL_SIZE - 1)19#define MT792x_WTBL_STA (MT792x_WTBL_RESERVED - MT792x_MAX_INTERFACES)2021#define MT792x_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */22#define MT792x_CFEND_RATE_11B 0x03 /* 11B LP, 11M */2324#define MT792x_FW_TAG_FEATURE 425#define MT792x_FW_CAP_CNM BIT(7)2627#define MT792x_CHIP_CAP_CLC_EVT_EN BIT(0)28#define MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN BIT(1)29#define MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN BIT(3)30#define MT792x_CHIP_CAP_MLO_EN BIT(8)31#define MT792x_CHIP_CAP_MLO_EML_EN BIT(9)3233/* NOTE: used to map mt76_rates. idx may change if firmware expands table */34#define MT792x_BASIC_RATES_TBL 113536#define MT792x_WATCHDOG_TIME (HZ / 4)3738#define MT792x_DRV_OWN_RETRY_COUNT 1039#define MT792x_MCU_INIT_RETRY_COUNT 1040#define MT792x_WFSYS_INIT_RETRY_COUNT 24142#define MT7920_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1a.bin"43#define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin"44#define MT7922_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7922_1.bin"45#define MT7925_FIRMWARE_WM "mediatek/mt7925/WIFI_RAM_CODE_MT7925_1_1.bin"4647#define MT7920_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1a_2_hdr.bin"48#define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin"49#define MT7922_ROM_PATCH "mediatek/WIFI_MT7922_patch_mcu_1_1_hdr.bin"50#define MT7925_ROM_PATCH "mediatek/mt7925/WIFI_MT7925_PATCH_MCU_1_1_hdr.bin"5152#define MT792x_SDIO_HDR_TX_BYTES GENMASK(15, 0)53#define MT792x_SDIO_HDR_PKT_TYPE GENMASK(17, 16)5455struct mt792x_vif;56struct mt792x_sta;5758struct mt792x_realease_info {59__le16 len;60u8 pad_len;61u8 tag;62} __packed;6364struct mt792x_fw_features {65u8 segment;66u8 data;67u8 rsv[14];68} __packed;6970enum {71MT792x_CLC_POWER,72MT792x_CLC_POWER_EXT,73MT792x_CLC_BE_CTRL,74MT792x_CLC_MAX_NUM,75};7677enum mt792x_reg_power_type {78MT_AP_UNSET = 0,79MT_AP_DEFAULT,80MT_AP_LPI,81MT_AP_SP,82MT_AP_VLP,83};8485enum mt792x_mlo_pm_state {86MT792x_MLO_LINK_DISASSOC,87MT792x_MLO_LINK_ASSOC,88MT792x_MLO_CHANGED_PS_PENDING,89MT792x_MLO_CHANGED_PS,90};9192DECLARE_EWMA(avg_signal, 10, 8)9394struct mt792x_link_sta {95struct mt76_wcid wcid; /* must be first */9697u32 airtime_ac[8];9899int ack_signal;100struct ewma_avg_signal avg_ack_signal;101102unsigned long last_txs;103104struct mt76_connac_sta_key_conf bip;105106struct mt792x_sta *sta;107108struct ieee80211_link_sta *pri_link;109};110111struct mt792x_sta {112struct mt792x_link_sta deflink; /* must be first */113struct mt792x_link_sta __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];114115struct mt792x_vif *vif;116117u16 valid_links;118u8 deflink_id;119};120121DECLARE_EWMA(rssi, 10, 8);122123struct mt792x_chanctx {124struct mt792x_bss_conf *bss_conf;125};126127struct mt792x_bss_conf {128struct mt76_vif_link mt76; /* must be first */129struct mt792x_vif *vif;130struct ewma_rssi rssi;131struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];132unsigned int link_id;133};134135struct mt792x_vif {136struct mt792x_bss_conf bss_conf; /* must be first */137struct mt792x_bss_conf __rcu *link_conf[IEEE80211_MLD_MAX_NUM_LINKS];138139struct mt792x_sta sta;140struct mt792x_sta *wep_sta;141142struct mt792x_phy *phy;143u16 valid_links;144u8 deflink_id;145enum mt792x_mlo_pm_state mlo_pm_state;146147struct work_struct csa_work;148struct timer_list csa_timer;149};150151struct mt792x_phy {152struct mt76_phy *mt76;153struct mt792x_dev *dev;154155struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];156157u64 omac_mask;158159u16 noise;160161s16 coverage_class;162u8 slottime;163164u32 rx_ampdu_ts;165u32 ampdu_ref;166167struct mt76_mib_stats mib;168169u8 sta_work_count;170u8 clc_chan_conf;171enum mt792x_reg_power_type power_type;172173struct sk_buff_head scan_event_list;174struct delayed_work scan_work;175#ifdef CONFIG_ACPI176void *acpisar;177#endif178void *clc[MT792x_CLC_MAX_NUM];179u64 chip_cap;180u16 eml_cap;181182struct work_struct roc_work;183struct timer_list roc_timer;184wait_queue_head_t roc_wait;185u8 roc_token_id;186bool roc_grant;187};188189struct mt792x_irq_map {190u32 host_irq_enable;191struct {192u32 all_complete_mask;193u32 mcu_complete_mask;194} tx;195struct {196u32 data_complete_mask;197u32 wm_complete_mask;198u32 wm2_complete_mask;199} rx;200};201202#define mt792x_init_reset(dev) ((dev)->hif_ops->init_reset(dev))203#define mt792x_dev_reset(dev) ((dev)->hif_ops->reset(dev))204#define mt792x_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev))205#define __mt792x_mcu_drv_pmctrl(dev) ((dev)->hif_ops->drv_own(dev))206#define __mt792x_mcu_fw_pmctrl(dev) ((dev)->hif_ops->fw_own(dev))207208struct mt792x_hif_ops {209int (*init_reset)(struct mt792x_dev *dev);210int (*reset)(struct mt792x_dev *dev);211int (*mcu_init)(struct mt792x_dev *dev);212int (*drv_own)(struct mt792x_dev *dev);213int (*fw_own)(struct mt792x_dev *dev);214};215216struct mt792x_dev {217union { /* must be first */218struct mt76_dev mt76;219struct mt76_phy mphy;220};221222struct mac_address macaddr_list[8];223224const struct mt76_bus_ops *bus_ops;225struct mt792x_phy phy;226227struct work_struct reset_work;228bool hw_full_reset:1;229bool hw_init_done:1;230bool fw_assert:1;231bool has_eht:1;232bool regd_in_progress:1;233bool aspm_supported:1;234bool hif_idle:1;235bool hif_resumed:1;236bool sar_inited:1;237bool regd_change:1;238wait_queue_head_t wait;239240struct work_struct init_work;241242u8 fw_debug;243u8 fw_features;244245struct mt76_connac_pm pm;246struct mt76_connac_coredump coredump;247const struct mt792x_hif_ops *hif_ops;248const struct mt792x_irq_map *irq_map;249250struct work_struct ipv6_ns_work;251struct delayed_work mlo_pm_work;252/* IPv6 addresses for WoWLAN */253struct sk_buff_head ipv6_ns_list;254255enum environment_cap country_ie_env;256u32 backup_l1;257u32 backup_l2;258259struct ieee80211_chanctx_conf *new_ctx;260};261262static inline struct mt792x_bss_conf *263mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id)264{265struct ieee80211_vif *vif;266struct mt792x_bss_conf *bss_conf;267268vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);269270if (!ieee80211_vif_is_mld(vif) ||271link_id >= IEEE80211_LINK_UNSPECIFIED)272return &mvif->bss_conf;273274bss_conf = rcu_dereference_protected(mvif->link_conf[link_id],275lockdep_is_held(&mvif->phy->dev->mt76.mutex));276277return bss_conf ? bss_conf : &mvif->bss_conf;278}279280static inline struct mt792x_link_sta *281mt792x_sta_to_link(struct mt792x_sta *msta, u8 link_id)282{283struct ieee80211_vif *vif;284285vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);286287if (!ieee80211_vif_is_mld(vif) ||288link_id >= IEEE80211_LINK_UNSPECIFIED)289return &msta->deflink;290291return rcu_dereference_protected(msta->link[link_id],292lockdep_is_held(&msta->vif->phy->dev->mt76.mutex));293}294295static inline struct mt792x_bss_conf *296mt792x_link_conf_to_mconf(struct ieee80211_bss_conf *link_conf)297{298struct ieee80211_vif *vif = link_conf->vif;299struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;300301return mt792x_vif_to_link(mvif, link_conf->link_id);302}303304static inline struct ieee80211_bss_conf *305mt792x_vif_to_bss_conf(struct ieee80211_vif *vif, unsigned int link_id)306{307if (!ieee80211_vif_is_mld(vif) ||308link_id >= IEEE80211_LINK_UNSPECIFIED)309return &vif->bss_conf;310311return link_conf_dereference_protected(vif, link_id);312}313314static inline struct ieee80211_link_sta *315mt792x_sta_to_link_sta(struct ieee80211_vif *vif, struct ieee80211_sta *sta,316unsigned int link_id)317{318if (!ieee80211_vif_is_mld(vif) ||319link_id >= IEEE80211_LINK_UNSPECIFIED)320return &sta->deflink;321322return link_sta_dereference_protected(sta, link_id);323}324325static inline struct mt792x_dev *326mt792x_hw_dev(struct ieee80211_hw *hw)327{328struct mt76_phy *phy = hw->priv;329330return container_of(phy->dev, struct mt792x_dev, mt76);331}332333static inline struct mt792x_phy *334mt792x_hw_phy(struct ieee80211_hw *hw)335{336struct mt76_phy *phy = hw->priv;337338return phy->priv;339}340341static inline void342mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)343{344if (chfreq > 180) {345status->band = NL80211_BAND_6GHZ;346chfreq = (chfreq - 181) * 4 + 1;347} else if (chfreq > 14) {348status->band = NL80211_BAND_5GHZ;349} else {350status->band = NL80211_BAND_2GHZ;351}352status->freq = ieee80211_channel_to_frequency(chfreq, status->band);353}354355static inline bool mt792x_dma_need_reinit(struct mt792x_dev *dev)356{357return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);358}359360#define mt792x_mutex_acquire(dev) \361mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm)362#define mt792x_mutex_release(dev) \363mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm)364365void mt792x_stop(struct ieee80211_hw *hw, bool suspend);366void mt792x_pm_wake_work(struct work_struct *work);367void mt792x_pm_power_save_work(struct work_struct *work);368void mt792x_reset(struct mt76_dev *mdev);369void mt792x_update_channel(struct mt76_phy *mphy);370void mt792x_mac_reset_counters(struct mt792x_phy *phy);371void mt792x_mac_init_band(struct mt792x_dev *dev, u8 band);372void mt792x_mac_assoc_rssi(struct mt792x_dev *dev, struct sk_buff *skb);373struct mt76_wcid *mt792x_rx_get_wcid(struct mt792x_dev *dev, u16 idx,374bool unicast);375void mt792x_mac_update_mib_stats(struct mt792x_phy *phy);376void mt792x_mac_set_timeing(struct mt792x_phy *phy);377void mt792x_mac_work(struct work_struct *work);378void mt792x_remove_interface(struct ieee80211_hw *hw,379struct ieee80211_vif *vif);380void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,381struct sk_buff *skb);382int mt792x_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,383unsigned int link_id, u16 queue,384const struct ieee80211_tx_queue_params *params);385int mt792x_get_stats(struct ieee80211_hw *hw,386struct ieee80211_low_level_stats *stats);387u64 mt792x_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);388void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,389u64 timestamp);390void mt792x_tx_worker(struct mt76_worker *w);391void mt792x_roc_timer(struct timer_list *timer);392void mt792x_csa_timer(struct timer_list *timer);393void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,394u32 queues, bool drop);395int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,396struct ieee80211_vif *vif,397struct ieee80211_bss_conf *link_conf,398struct ieee80211_chanctx_conf *ctx);399void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,400struct ieee80211_vif *vif,401struct ieee80211_bss_conf *link_conf,402struct ieee80211_chanctx_conf *ctx);403void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled);404void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif,405u32 sset, u8 *data);406int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif,407int sset);408void mt792x_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif,409struct ethtool_stats *stats, u64 *data);410void mt792x_sta_statistics(struct ieee80211_hw *hw,411struct ieee80211_vif *vif,412struct ieee80211_sta *sta,413struct station_info *sinfo);414void mt792x_set_coverage_class(struct ieee80211_hw *hw, int radio_idx,415s16 coverage_class);416void mt792x_dma_cleanup(struct mt792x_dev *dev);417int mt792x_dma_enable(struct mt792x_dev *dev);418int mt792x_wpdma_reset(struct mt792x_dev *dev, bool force);419int mt792x_wpdma_reinit_cond(struct mt792x_dev *dev);420int mt792x_dma_disable(struct mt792x_dev *dev, bool force);421irqreturn_t mt792x_irq_handler(int irq, void *dev_instance);422void mt792x_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);423int mt792x_poll_tx(struct napi_struct *napi, int budget);424int mt792x_poll_rx(struct napi_struct *napi, int budget);425void mt792x_irq_tasklet(unsigned long data);426int mt792x_wfsys_reset(struct mt792x_dev *dev);427int mt792x_tx_stats_show(struct seq_file *file, void *data);428int mt792x_queues_acq(struct seq_file *s, void *data);429int mt792x_queues_read(struct seq_file *s, void *data);430int mt792x_pm_stats(struct seq_file *s, void *data);431int mt792x_pm_idle_timeout_set(void *data, u64 val);432int mt792x_pm_idle_timeout_get(void *data, u64 *val);433int mt792x_init_wiphy(struct ieee80211_hw *hw);434struct ieee80211_ops *435mt792x_get_mac80211_ops(struct device *dev,436const struct ieee80211_ops *mac80211_ops,437void *drv_data, u8 *fw_features);438int mt792x_init_wcid(struct mt792x_dev *dev);439int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);440int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);441void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,442struct mt792x_bss_conf *mconf,443struct mt792x_link_sta *mlink);444void mt792x_config_mac_addr_list(struct mt792x_dev *dev);445446static inline char *mt792x_ram_name(struct mt792x_dev *dev)447{448switch (mt76_chip(&dev->mt76)) {449case 0x7920:450return MT7920_FIRMWARE_WM;451case 0x7922:452return MT7922_FIRMWARE_WM;453case 0x7925:454return MT7925_FIRMWARE_WM;455default:456return MT7921_FIRMWARE_WM;457}458}459460static inline char *mt792x_patch_name(struct mt792x_dev *dev)461{462switch (mt76_chip(&dev->mt76)) {463case 0x7920:464return MT7920_ROM_PATCH;465case 0x7922:466return MT7922_ROM_PATCH;467case 0x7925:468return MT7925_ROM_PATCH;469default:470return MT7921_ROM_PATCH;471}472}473474int mt792x_load_firmware(struct mt792x_dev *dev);475476/* usb */477#define MT_USB_TYPE_VENDOR (USB_TYPE_VENDOR | 0x1f)478#define MT_USB_TYPE_UHW_VENDOR (USB_TYPE_VENDOR | 0x1e)479int mt792xu_dma_init(struct mt792x_dev *dev, bool resume);480int mt792xu_mcu_power_on(struct mt792x_dev *dev);481int mt792xu_wfsys_reset(struct mt792x_dev *dev);482int mt792xu_init_reset(struct mt792x_dev *dev);483u32 mt792xu_rr(struct mt76_dev *dev, u32 addr);484void mt792xu_wr(struct mt76_dev *dev, u32 addr, u32 val);485u32 mt792xu_rmw(struct mt76_dev *dev, u32 addr, u32 mask, u32 val);486void mt792xu_copy(struct mt76_dev *dev, u32 offset, const void *data, int len);487void mt792xu_disconnect(struct usb_interface *usb_intf);488void mt792xu_stop(struct ieee80211_hw *hw, bool suspend);489490static inline void491mt792x_skb_add_usb_sdio_hdr(struct mt792x_dev *dev, struct sk_buff *skb,492int type)493{494u32 hdr, len;495496len = mt76_is_usb(&dev->mt76) ? skb->len : skb->len + sizeof(hdr);497hdr = FIELD_PREP(MT792x_SDIO_HDR_TX_BYTES, len) |498FIELD_PREP(MT792x_SDIO_HDR_PKT_TYPE, type);499500put_unaligned_le32(hdr, skb_push(skb, sizeof(hdr)));501}502503int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);504int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);505int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev);506507#ifdef CONFIG_ACPI508int mt792x_init_acpi_sar(struct mt792x_dev *dev);509int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default);510u8 mt792x_acpi_get_flags(struct mt792x_phy *phy);511u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2);512#else513static inline int mt792x_init_acpi_sar(struct mt792x_dev *dev)514{515return 0;516}517518static inline int mt792x_init_acpi_sar_power(struct mt792x_phy *phy,519bool set_default)520{521return 0;522}523524static inline u8 mt792x_acpi_get_flags(struct mt792x_phy *phy)525{526return 0;527}528529static inline u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2)530{531return MT792X_ACPI_MTCL_INVALID;532}533#endif534535#endif /* __MT7925_H */536537538