1 /* SPDX-License-Identifier: ISC */ 2 /* Copyright (C) 2023 MediaTek Inc. */ 3 4 #ifndef __MT792X_H 5 #define __MT792X_H 6 7 #include <linux/interrupt.h> 8 #include <linux/ktime.h> 9 10 #include "mt76_connac_mcu.h" 11 12 #define MT792x_MAX_INTERFACES 4 13 #define MT792x_WTBL_SIZE 20 14 #define MT792x_WTBL_RESERVED (MT792x_WTBL_SIZE - 1) 15 #define MT792x_WTBL_STA (MT792x_WTBL_RESERVED - MT792x_MAX_INTERFACES) 16 17 #define MT792x_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ 18 #define MT792x_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ 19 20 /* NOTE: used to map mt76_rates. idx may change if firmware expands table */ 21 #define MT792x_BASIC_RATES_TBL 11 22 23 #define MT792x_WATCHDOG_TIME (HZ / 4) 24 25 struct mt792x_vif; 26 struct mt792x_sta; 27 28 enum { 29 MT792x_CLC_POWER, 30 MT792x_CLC_CHAN, 31 MT792x_CLC_MAX_NUM, 32 }; 33 34 DECLARE_EWMA(avg_signal, 10, 8) 35 36 struct mt792x_sta { 37 struct mt76_wcid wcid; /* must be first */ 38 39 struct mt792x_vif *vif; 40 41 u32 airtime_ac[8]; 42 43 int ack_signal; 44 struct ewma_avg_signal avg_ack_signal; 45 46 unsigned long last_txs; 47 48 struct mt76_connac_sta_key_conf bip; 49 }; 50 51 DECLARE_EWMA(rssi, 10, 8); 52 53 struct mt792x_vif { 54 struct mt76_vif mt76; /* must be first */ 55 56 struct mt792x_sta sta; 57 struct mt792x_sta *wep_sta; 58 59 struct mt792x_phy *phy; 60 61 struct ewma_rssi rssi; 62 63 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS]; 64 struct ieee80211_chanctx_conf *ctx; 65 }; 66 67 struct mt792x_phy { 68 struct mt76_phy *mt76; 69 struct mt792x_dev *dev; 70 71 struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES]; 72 73 u64 omac_mask; 74 75 u16 noise; 76 77 s16 coverage_class; 78 u8 slottime; 79 80 u32 rx_ampdu_ts; 81 u32 ampdu_ref; 82 83 struct mt76_mib_stats mib; 84 85 u8 sta_work_count; 86 87 struct sk_buff_head scan_event_list; 88 struct delayed_work scan_work; 89 #ifdef CONFIG_ACPI 90 void *acpisar; 91 #endif 92 void *clc[MT792x_CLC_MAX_NUM]; 93 94 struct work_struct roc_work; 95 struct timer_list roc_timer; 96 wait_queue_head_t roc_wait; 97 u8 roc_token_id; 98 bool roc_grant; 99 }; 100 101 struct mt792x_hif_ops { 102 int (*init_reset)(struct mt792x_dev *dev); 103 int (*reset)(struct mt792x_dev *dev); 104 int (*mcu_init)(struct mt792x_dev *dev); 105 int (*drv_own)(struct mt792x_dev *dev); 106 int (*fw_own)(struct mt792x_dev *dev); 107 }; 108 109 struct mt792x_dev { 110 union { /* must be first */ 111 struct mt76_dev mt76; 112 struct mt76_phy mphy; 113 }; 114 115 const struct mt76_bus_ops *bus_ops; 116 struct mt792x_phy phy; 117 118 struct work_struct reset_work; 119 bool hw_full_reset:1; 120 bool hw_init_done:1; 121 bool fw_assert:1; 122 bool has_eht:1; 123 124 struct work_struct init_work; 125 126 u8 fw_debug; 127 u8 fw_features; 128 129 struct mt76_connac_pm pm; 130 struct mt76_connac_coredump coredump; 131 const struct mt792x_hif_ops *hif_ops; 132 133 struct work_struct ipv6_ns_work; 134 /* IPv6 addresses for WoWLAN */ 135 struct sk_buff_head ipv6_ns_list; 136 137 enum environment_cap country_ie_env; 138 u32 backup_l1; 139 u32 backup_l2; 140 }; 141 142 static inline struct mt792x_dev * 143 mt792x_hw_dev(struct ieee80211_hw *hw) 144 { 145 struct mt76_phy *phy = hw->priv; 146 147 return container_of(phy->dev, struct mt792x_dev, mt76); 148 } 149 150 static inline struct mt792x_phy * 151 mt792x_hw_phy(struct ieee80211_hw *hw) 152 { 153 struct mt76_phy *phy = hw->priv; 154 155 return phy->priv; 156 } 157 158 #define mt792x_mutex_acquire(dev) \ 159 mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm) 160 #define mt792x_mutex_release(dev) \ 161 mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm) 162 163 void mt792x_mac_update_mib_stats(struct mt792x_phy *phy); 164 void mt792x_mac_set_timeing(struct mt792x_phy *phy); 165 void mt792x_mac_work(struct work_struct *work); 166 void mt792x_remove_interface(struct ieee80211_hw *hw, 167 struct ieee80211_vif *vif); 168 void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, 169 struct sk_buff *skb); 170 int mt792x_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 171 unsigned int link_id, u16 queue, 172 const struct ieee80211_tx_queue_params *params); 173 int mt792x_get_stats(struct ieee80211_hw *hw, 174 struct ieee80211_low_level_stats *stats); 175 u64 mt792x_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 176 void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 177 u64 timestamp); 178 void mt792x_tx_worker(struct mt76_worker *w); 179 void mt792x_roc_timer(struct timer_list *timer); 180 void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 181 u32 queues, bool drop); 182 int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw, 183 struct ieee80211_vif *vif, 184 struct ieee80211_bss_conf *link_conf, 185 struct ieee80211_chanctx_conf *ctx); 186 void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw, 187 struct ieee80211_vif *vif, 188 struct ieee80211_bss_conf *link_conf, 189 struct ieee80211_chanctx_conf *ctx); 190 void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled); 191 void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 192 u32 sset, u8 *data); 193 int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 194 int sset); 195 void mt792x_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 196 struct ethtool_stats *stats, u64 *data); 197 void mt792x_sta_statistics(struct ieee80211_hw *hw, 198 struct ieee80211_vif *vif, 199 struct ieee80211_sta *sta, 200 struct station_info *sinfo); 201 void mt792x_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class); 202 203 #endif /* __MT7925_H */ 204