Path: blob/main/sys/contrib/dev/mediatek/mt76/mt792x.h
106764 views
/* SPDX-License-Identifier: BSD-3-Clause-Clear */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_11D_EN BIT(4)31#define MT792x_CHIP_CAP_MLO_EN BIT(8)32#define MT792x_CHIP_CAP_MLO_EML_EN BIT(9)3334/* NOTE: used to map mt76_rates. idx may change if firmware expands table */35#define MT792x_BASIC_RATES_TBL 113637#define MT792x_WATCHDOG_TIME (HZ / 4)3839#define MT792x_DRV_OWN_RETRY_COUNT 1040#define MT792x_MCU_INIT_RETRY_COUNT 1041#define MT792x_WFSYS_INIT_RETRY_COUNT 24243#define MT7920_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1a.bin"44#define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin"45#define MT7922_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7922_1.bin"46#define MT7925_FIRMWARE_WM "mediatek/mt7925/WIFI_RAM_CODE_MT7925_1_1.bin"4748#define MT7920_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1a_2_hdr.bin"49#define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin"50#define MT7922_ROM_PATCH "mediatek/WIFI_MT7922_patch_mcu_1_1_hdr.bin"51#define MT7925_ROM_PATCH "mediatek/mt7925/WIFI_MT7925_PATCH_MCU_1_1_hdr.bin"5253#define MT792x_SDIO_HDR_TX_BYTES GENMASK(15, 0)54#define MT792x_SDIO_HDR_PKT_TYPE GENMASK(17, 16)5556struct mt792x_vif;57struct mt792x_sta;5859struct mt792x_realease_info {60__le16 len;61u8 pad_len;62u8 tag;63} __packed;6465struct mt792x_fw_features {66u8 segment;67u8 data;68u8 rsv[14];69} __packed;7071enum {72MT792x_CLC_POWER,73MT792x_CLC_POWER_EXT,74MT792x_CLC_BE_CTRL,75MT792x_CLC_MAX_NUM,76};7778enum mt792x_reg_power_type {79MT_AP_UNSET = 0,80MT_AP_DEFAULT,81MT_AP_LPI,82MT_AP_SP,83MT_AP_VLP,84};8586enum mt792x_mlo_pm_state {87MT792x_MLO_LINK_DISASSOC,88MT792x_MLO_LINK_ASSOC,89MT792x_MLO_CHANGED_PS_PENDING,90MT792x_MLO_CHANGED_PS,91};9293DECLARE_EWMA(avg_signal, 10, 8)9495struct mt792x_link_sta {96struct mt76_wcid wcid; /* must be first */9798u32 airtime_ac[8];99100int ack_signal;101struct ewma_avg_signal avg_ack_signal;102103unsigned long last_txs;104105struct mt76_connac_sta_key_conf bip;106107struct mt792x_sta *sta;108109struct ieee80211_link_sta *pri_link;110};111112struct mt792x_sta {113struct mt792x_link_sta deflink; /* must be first */114struct mt792x_link_sta __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];115116struct mt792x_vif *vif;117118u16 valid_links;119u8 deflink_id;120};121122DECLARE_EWMA(rssi, 10, 8);123124struct mt792x_chanctx {125struct mt792x_bss_conf *bss_conf;126};127128struct mt792x_bss_conf {129struct mt76_vif_link mt76; /* must be first */130struct mt792x_vif *vif;131struct ewma_rssi rssi;132struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];133unsigned int link_id;134};135136struct mt792x_vif {137struct mt792x_bss_conf bss_conf; /* must be first */138struct mt792x_bss_conf __rcu *link_conf[IEEE80211_MLD_MAX_NUM_LINKS];139140struct mt792x_sta sta;141struct mt792x_sta *wep_sta;142143struct mt792x_phy *phy;144u16 valid_links;145u8 deflink_id;146enum mt792x_mlo_pm_state mlo_pm_state;147148struct work_struct csa_work;149struct timer_list csa_timer;150};151152struct mt792x_phy {153struct mt76_phy *mt76;154struct mt792x_dev *dev;155156struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];157158u64 omac_mask;159160u16 noise;161162s16 coverage_class;163u8 slottime;164165u32 rx_ampdu_ts;166u32 ampdu_ref;167168struct mt76_mib_stats mib;169170u8 sta_work_count;171u8 clc_chan_conf;172enum mt792x_reg_power_type power_type;173174struct sk_buff_head scan_event_list;175struct delayed_work scan_work;176#ifdef CONFIG_ACPI177void *acpisar;178#endif179void *clc[MT792x_CLC_MAX_NUM];180u64 chip_cap;181u16 eml_cap;182183struct work_struct roc_work;184struct timer_list roc_timer;185wait_queue_head_t roc_wait;186u8 roc_token_id;187bool roc_grant;188};189190struct mt792x_irq_map {191u32 host_irq_enable;192struct {193u32 all_complete_mask;194u32 mcu_complete_mask;195} tx;196struct {197u32 data_complete_mask;198u32 wm_complete_mask;199u32 wm2_complete_mask;200} rx;201};202203#define mt792x_init_reset(dev) ((dev)->hif_ops->init_reset(dev))204#define mt792x_dev_reset(dev) ((dev)->hif_ops->reset(dev))205#define mt792x_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev))206#define __mt792x_mcu_drv_pmctrl(dev) ((dev)->hif_ops->drv_own(dev))207#define __mt792x_mcu_fw_pmctrl(dev) ((dev)->hif_ops->fw_own(dev))208209struct mt792x_hif_ops {210int (*init_reset)(struct mt792x_dev *dev);211int (*reset)(struct mt792x_dev *dev);212int (*mcu_init)(struct mt792x_dev *dev);213int (*drv_own)(struct mt792x_dev *dev);214int (*fw_own)(struct mt792x_dev *dev);215};216217struct mt792x_dev {218union { /* must be first */219struct mt76_dev mt76;220struct mt76_phy mphy;221};222223struct mac_address macaddr_list[8];224225const struct mt76_bus_ops *bus_ops;226struct mt792x_phy phy;227228struct work_struct reset_work;229bool hw_full_reset:1;230bool hw_init_done:1;231bool fw_assert:1;232bool has_eht:1;233bool regd_user:1;234bool regd_in_progress:1;235bool aspm_supported:1;236bool hif_idle:1;237bool hif_resumed:1;238bool regd_change:1;239wait_queue_head_t wait;240241struct work_struct init_work;242243u8 fw_debug;244u8 fw_features;245246struct mt76_connac_pm pm;247struct mt76_connac_coredump coredump;248const struct mt792x_hif_ops *hif_ops;249const struct mt792x_irq_map *irq_map;250251struct work_struct ipv6_ns_work;252struct delayed_work mlo_pm_work;253/* IPv6 addresses for WoWLAN */254struct sk_buff_head ipv6_ns_list;255256enum environment_cap country_ie_env;257u32 backup_l1;258u32 backup_l2;259260struct ieee80211_chanctx_conf *new_ctx;261};262263static inline struct mt792x_bss_conf *264mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id)265{266struct ieee80211_vif *vif;267struct mt792x_bss_conf *bss_conf;268269vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);270271if (!ieee80211_vif_is_mld(vif) ||272link_id >= IEEE80211_LINK_UNSPECIFIED)273return &mvif->bss_conf;274275bss_conf = rcu_dereference_protected(mvif->link_conf[link_id],276lockdep_is_held(&mvif->phy->dev->mt76.mutex));277278return bss_conf ? bss_conf : &mvif->bss_conf;279}280281static inline struct mt792x_link_sta *282mt792x_sta_to_link(struct mt792x_sta *msta, u8 link_id)283{284struct ieee80211_vif *vif;285286vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);287288if (!ieee80211_vif_is_mld(vif) ||289link_id >= IEEE80211_LINK_UNSPECIFIED)290return &msta->deflink;291292return rcu_dereference_protected(msta->link[link_id],293lockdep_is_held(&msta->vif->phy->dev->mt76.mutex));294}295296static inline struct mt792x_bss_conf *297mt792x_link_conf_to_mconf(struct ieee80211_bss_conf *link_conf)298{299struct ieee80211_vif *vif = link_conf->vif;300struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;301302return mt792x_vif_to_link(mvif, link_conf->link_id);303}304305static inline struct ieee80211_bss_conf *306mt792x_vif_to_bss_conf(struct ieee80211_vif *vif, unsigned int link_id)307{308if (!ieee80211_vif_is_mld(vif) ||309link_id >= IEEE80211_LINK_UNSPECIFIED)310return &vif->bss_conf;311312return link_conf_dereference_protected(vif, link_id);313}314315static inline struct ieee80211_link_sta *316mt792x_sta_to_link_sta(struct ieee80211_vif *vif, struct ieee80211_sta *sta,317unsigned int link_id)318{319if (!ieee80211_vif_is_mld(vif) ||320link_id >= IEEE80211_LINK_UNSPECIFIED)321return &sta->deflink;322323return link_sta_dereference_protected(sta, link_id);324}325326static inline struct mt792x_dev *327mt792x_hw_dev(struct ieee80211_hw *hw)328{329struct mt76_phy *phy = hw->priv;330331return container_of(phy->dev, struct mt792x_dev, mt76);332}333334static inline struct mt792x_phy *335mt792x_hw_phy(struct ieee80211_hw *hw)336{337struct mt76_phy *phy = hw->priv;338339return phy->priv;340}341342static inline void343mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)344{345if (chfreq > 180) {346status->band = NL80211_BAND_6GHZ;347chfreq = (chfreq - 181) * 4 + 1;348} else if (chfreq > 14) {349status->band = NL80211_BAND_5GHZ;350} else {351status->band = NL80211_BAND_2GHZ;352}353status->freq = ieee80211_channel_to_frequency(chfreq, status->band);354}355356static inline bool mt792x_dma_need_reinit(struct mt792x_dev *dev)357{358return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);359}360361#define mt792x_mutex_acquire(dev) \362mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm)363#define mt792x_mutex_release(dev) \364mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm)365366void mt792x_stop(struct ieee80211_hw *hw, bool suspend);367void mt792x_pm_wake_work(struct work_struct *work);368void mt792x_pm_power_save_work(struct work_struct *work);369void mt792x_reset(struct mt76_dev *mdev);370void mt792x_update_channel(struct mt76_phy *mphy);371void mt792x_mac_reset_counters(struct mt792x_phy *phy);372void mt792x_mac_init_band(struct mt792x_dev *dev, u8 band);373void mt792x_mac_assoc_rssi(struct mt792x_dev *dev, struct sk_buff *skb);374struct mt76_wcid *mt792x_rx_get_wcid(struct mt792x_dev *dev, u16 idx,375bool unicast);376void mt792x_mac_update_mib_stats(struct mt792x_phy *phy);377void mt792x_mac_set_timeing(struct mt792x_phy *phy);378void mt792x_mac_work(struct work_struct *work);379void mt792x_remove_interface(struct ieee80211_hw *hw,380struct ieee80211_vif *vif);381void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,382struct sk_buff *skb);383int mt792x_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,384unsigned int link_id, u16 queue,385const struct ieee80211_tx_queue_params *params);386int mt792x_get_stats(struct ieee80211_hw *hw,387struct ieee80211_low_level_stats *stats);388u64 mt792x_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);389void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,390u64 timestamp);391void mt792x_tx_worker(struct mt76_worker *w);392void mt792x_roc_timer(struct timer_list *timer);393void mt792x_csa_timer(struct timer_list *timer);394void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,395u32 queues, bool drop);396int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,397struct ieee80211_vif *vif,398struct ieee80211_bss_conf *link_conf,399struct ieee80211_chanctx_conf *ctx);400void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,401struct ieee80211_vif *vif,402struct ieee80211_bss_conf *link_conf,403struct ieee80211_chanctx_conf *ctx);404void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled);405void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif,406u32 sset, u8 *data);407int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif,408int sset);409void mt792x_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif,410struct ethtool_stats *stats, u64 *data);411void mt792x_sta_statistics(struct ieee80211_hw *hw,412struct ieee80211_vif *vif,413struct ieee80211_sta *sta,414struct station_info *sinfo);415void mt792x_set_coverage_class(struct ieee80211_hw *hw, int radio_idx,416s16 coverage_class);417void mt792x_dma_cleanup(struct mt792x_dev *dev);418int mt792x_dma_enable(struct mt792x_dev *dev);419int mt792x_wpdma_reset(struct mt792x_dev *dev, bool force);420int mt792x_wpdma_reinit_cond(struct mt792x_dev *dev);421int mt792x_dma_disable(struct mt792x_dev *dev, bool force);422irqreturn_t mt792x_irq_handler(int irq, void *dev_instance);423void mt792x_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);424int mt792x_poll_tx(struct napi_struct *napi, int budget);425int mt792x_poll_rx(struct napi_struct *napi, int budget);426void mt792x_irq_tasklet(unsigned long data);427int mt792x_wfsys_reset(struct mt792x_dev *dev);428int mt792x_tx_stats_show(struct seq_file *file, void *data);429int mt792x_queues_acq(struct seq_file *s, void *data);430int mt792x_queues_read(struct seq_file *s, void *data);431int mt792x_pm_stats(struct seq_file *s, void *data);432int mt792x_pm_idle_timeout_set(void *data, u64 val);433int mt792x_pm_idle_timeout_get(void *data, u64 *val);434int mt792x_init_wiphy(struct ieee80211_hw *hw);435struct ieee80211_ops *436mt792x_get_mac80211_ops(struct device *dev,437const struct ieee80211_ops *mac80211_ops,438void *drv_data, u8 *fw_features);439int mt792x_init_wcid(struct mt792x_dev *dev);440int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);441int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);442void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,443struct mt792x_bss_conf *mconf,444struct mt792x_link_sta *mlink);445void mt792x_config_mac_addr_list(struct mt792x_dev *dev);446447static inline char *mt792x_ram_name(struct mt792x_dev *dev)448{449switch (mt76_chip(&dev->mt76)) {450case 0x7920:451return MT7920_FIRMWARE_WM;452case 0x7922:453return MT7922_FIRMWARE_WM;454case 0x7925:455return MT7925_FIRMWARE_WM;456default:457return MT7921_FIRMWARE_WM;458}459}460461static inline char *mt792x_patch_name(struct mt792x_dev *dev)462{463switch (mt76_chip(&dev->mt76)) {464case 0x7920:465return MT7920_ROM_PATCH;466case 0x7922:467return MT7922_ROM_PATCH;468case 0x7925:469return MT7925_ROM_PATCH;470default:471return MT7921_ROM_PATCH;472}473}474475int mt792x_load_firmware(struct mt792x_dev *dev);476477/* usb */478#define MT_USB_TYPE_VENDOR (USB_TYPE_VENDOR | 0x1f)479#define MT_USB_TYPE_UHW_VENDOR (USB_TYPE_VENDOR | 0x1e)480int mt792xu_dma_init(struct mt792x_dev *dev, bool resume);481int mt792xu_mcu_power_on(struct mt792x_dev *dev);482int mt792xu_wfsys_reset(struct mt792x_dev *dev);483int mt792xu_init_reset(struct mt792x_dev *dev);484u32 mt792xu_rr(struct mt76_dev *dev, u32 addr);485void mt792xu_wr(struct mt76_dev *dev, u32 addr, u32 val);486u32 mt792xu_rmw(struct mt76_dev *dev, u32 addr, u32 mask, u32 val);487void mt792xu_copy(struct mt76_dev *dev, u32 offset, const void *data, int len);488void mt792xu_disconnect(struct usb_interface *usb_intf);489void mt792xu_stop(struct ieee80211_hw *hw, bool suspend);490491static inline void492mt792x_skb_add_usb_sdio_hdr(struct mt792x_dev *dev, struct sk_buff *skb,493int type)494{495u32 hdr, len;496497len = mt76_is_usb(&dev->mt76) ? skb->len : skb->len + sizeof(hdr);498hdr = FIELD_PREP(MT792x_SDIO_HDR_TX_BYTES, len) |499FIELD_PREP(MT792x_SDIO_HDR_PKT_TYPE, type);500501put_unaligned_le32(hdr, skb_push(skb, sizeof(hdr)));502}503504int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);505int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);506int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev);507508#ifdef CONFIG_ACPI509int mt792x_init_acpi_sar(struct mt792x_dev *dev);510int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default);511u8 mt792x_acpi_get_flags(struct mt792x_phy *phy);512u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2);513#else514static inline int mt792x_init_acpi_sar(struct mt792x_dev *dev)515{516return 0;517}518519static inline int mt792x_init_acpi_sar_power(struct mt792x_phy *phy,520bool set_default)521{522return 0;523}524525static inline u8 mt792x_acpi_get_flags(struct mt792x_phy *phy)526{527return 0;528}529530static inline u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2)531{532return MT792X_ACPI_MTCL_INVALID;533}534#endif535536#endif /* __MT7925_H */537538539