Loading...
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#include "mt792x_regs.h"
12#include "mt792x_acpi_sar.h"
13
14#define MT792x_PM_TIMEOUT (HZ / 12)
15#define MT792x_HW_SCAN_TIMEOUT (HZ / 10)
16
17#define MT792x_MAX_INTERFACES 4
18#define MT792x_WTBL_SIZE 20
19#define MT792x_WTBL_RESERVED (MT792x_WTBL_SIZE - 1)
20#define MT792x_WTBL_STA (MT792x_WTBL_RESERVED - MT792x_MAX_INTERFACES)
21
22#define MT792x_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
23#define MT792x_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
24
25#define MT792x_FW_TAG_FEATURE 4
26#define MT792x_FW_CAP_CNM BIT(7)
27
28#define MT792x_CHIP_CAP_CLC_EVT_EN BIT(0)
29
30/* NOTE: used to map mt76_rates. idx may change if firmware expands table */
31#define MT792x_BASIC_RATES_TBL 11
32
33#define MT792x_WATCHDOG_TIME (HZ / 4)
34
35#define MT792x_DRV_OWN_RETRY_COUNT 10
36#define MT792x_MCU_INIT_RETRY_COUNT 10
37#define MT792x_WFSYS_INIT_RETRY_COUNT 2
38
39#define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin"
40#define MT7922_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7922_1.bin"
41#define MT7925_FIRMWARE_WM "mediatek/mt7925/WIFI_RAM_CODE_MT7925_1_1.bin"
42
43#define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin"
44#define MT7922_ROM_PATCH "mediatek/WIFI_MT7922_patch_mcu_1_1_hdr.bin"
45#define MT7925_ROM_PATCH "mediatek/mt7925/WIFI_MT7925_PATCH_MCU_1_1_hdr.bin"
46
47#define MT792x_SDIO_HDR_TX_BYTES GENMASK(15, 0)
48#define MT792x_SDIO_HDR_PKT_TYPE GENMASK(17, 16)
49
50struct mt792x_vif;
51struct mt792x_sta;
52
53struct mt792x_realease_info {
54 __le16 len;
55 u8 pad_len;
56 u8 tag;
57} __packed;
58
59struct mt792x_fw_features {
60 u8 segment;
61 u8 data;
62 u8 rsv[14];
63} __packed;
64
65enum {
66 MT792x_CLC_POWER,
67 MT792x_CLC_CHAN,
68 MT792x_CLC_MAX_NUM,
69};
70
71enum mt792x_reg_power_type {
72 MT_AP_UNSET = 0,
73 MT_AP_DEFAULT,
74 MT_AP_LPI,
75 MT_AP_SP,
76 MT_AP_VLP,
77};
78
79DECLARE_EWMA(avg_signal, 10, 8)
80
81struct mt792x_sta {
82 struct mt76_wcid wcid; /* must be first */
83
84 struct mt792x_vif *vif;
85
86 u32 airtime_ac[8];
87
88 int ack_signal;
89 struct ewma_avg_signal avg_ack_signal;
90
91 unsigned long last_txs;
92
93 struct mt76_connac_sta_key_conf bip;
94};
95
96DECLARE_EWMA(rssi, 10, 8);
97
98struct mt792x_vif {
99 struct mt76_vif mt76; /* must be first */
100
101 struct mt792x_sta sta;
102 struct mt792x_sta *wep_sta;
103
104 struct mt792x_phy *phy;
105
106 struct ewma_rssi rssi;
107
108 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
109};
110
111struct mt792x_phy {
112 struct mt76_phy *mt76;
113 struct mt792x_dev *dev;
114
115 struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
116
117 u64 omac_mask;
118
119 u16 noise;
120
121 s16 coverage_class;
122 u8 slottime;
123
124 u32 rx_ampdu_ts;
125 u32 ampdu_ref;
126
127 struct mt76_mib_stats mib;
128
129 u8 sta_work_count;
130 u8 clc_chan_conf;
131 enum mt792x_reg_power_type power_type;
132
133 struct sk_buff_head scan_event_list;
134 struct delayed_work scan_work;
135#ifdef CONFIG_ACPI
136 void *acpisar;
137#endif
138 void *clc[MT792x_CLC_MAX_NUM];
139 u64 chip_cap;
140
141 struct work_struct roc_work;
142 struct timer_list roc_timer;
143 wait_queue_head_t roc_wait;
144 u8 roc_token_id;
145 bool roc_grant;
146};
147
148struct mt792x_irq_map {
149 u32 host_irq_enable;
150 struct {
151 u32 all_complete_mask;
152 u32 mcu_complete_mask;
153 } tx;
154 struct {
155 u32 data_complete_mask;
156 u32 wm_complete_mask;
157 u32 wm2_complete_mask;
158 } rx;
159};
160
161#define mt792x_init_reset(dev) ((dev)->hif_ops->init_reset(dev))
162#define mt792x_dev_reset(dev) ((dev)->hif_ops->reset(dev))
163#define mt792x_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev))
164#define __mt792x_mcu_drv_pmctrl(dev) ((dev)->hif_ops->drv_own(dev))
165#define __mt792x_mcu_fw_pmctrl(dev) ((dev)->hif_ops->fw_own(dev))
166
167struct mt792x_hif_ops {
168 int (*init_reset)(struct mt792x_dev *dev);
169 int (*reset)(struct mt792x_dev *dev);
170 int (*mcu_init)(struct mt792x_dev *dev);
171 int (*drv_own)(struct mt792x_dev *dev);
172 int (*fw_own)(struct mt792x_dev *dev);
173};
174
175struct mt792x_dev {
176 union { /* must be first */
177 struct mt76_dev mt76;
178 struct mt76_phy mphy;
179 };
180
181 const struct mt76_bus_ops *bus_ops;
182 struct mt792x_phy phy;
183
184 struct work_struct reset_work;
185 bool hw_full_reset:1;
186 bool hw_init_done:1;
187 bool fw_assert:1;
188 bool has_eht:1;
189 bool regd_in_progress:1;
190 wait_queue_head_t wait;
191
192 struct work_struct init_work;
193
194 u8 fw_debug;
195 u8 fw_features;
196
197 struct mt76_connac_pm pm;
198 struct mt76_connac_coredump coredump;
199 const struct mt792x_hif_ops *hif_ops;
200 const struct mt792x_irq_map *irq_map;
201
202 struct work_struct ipv6_ns_work;
203 /* IPv6 addresses for WoWLAN */
204 struct sk_buff_head ipv6_ns_list;
205
206 enum environment_cap country_ie_env;
207 u32 backup_l1;
208 u32 backup_l2;
209};
210
211static inline struct mt792x_dev *
212mt792x_hw_dev(struct ieee80211_hw *hw)
213{
214 struct mt76_phy *phy = hw->priv;
215
216 return container_of(phy->dev, struct mt792x_dev, mt76);
217}
218
219static inline struct mt792x_phy *
220mt792x_hw_phy(struct ieee80211_hw *hw)
221{
222 struct mt76_phy *phy = hw->priv;
223
224 return phy->priv;
225}
226
227static inline void
228mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)
229{
230 if (chfreq > 180) {
231 status->band = NL80211_BAND_6GHZ;
232 chfreq = (chfreq - 181) * 4 + 1;
233 } else if (chfreq > 14) {
234 status->band = NL80211_BAND_5GHZ;
235 } else {
236 status->band = NL80211_BAND_2GHZ;
237 }
238 status->freq = ieee80211_channel_to_frequency(chfreq, status->band);
239}
240
241static inline bool mt792x_dma_need_reinit(struct mt792x_dev *dev)
242{
243 return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
244}
245
246#define mt792x_mutex_acquire(dev) \
247 mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm)
248#define mt792x_mutex_release(dev) \
249 mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm)
250
251void mt792x_stop(struct ieee80211_hw *hw);
252void mt792x_pm_wake_work(struct work_struct *work);
253void mt792x_pm_power_save_work(struct work_struct *work);
254void mt792x_reset(struct mt76_dev *mdev);
255void mt792x_update_channel(struct mt76_phy *mphy);
256void mt792x_mac_reset_counters(struct mt792x_phy *phy);
257void mt792x_mac_init_band(struct mt792x_dev *dev, u8 band);
258void mt792x_mac_assoc_rssi(struct mt792x_dev *dev, struct sk_buff *skb);
259struct mt76_wcid *mt792x_rx_get_wcid(struct mt792x_dev *dev, u16 idx,
260 bool unicast);
261void mt792x_mac_update_mib_stats(struct mt792x_phy *phy);
262void mt792x_mac_set_timeing(struct mt792x_phy *phy);
263void mt792x_mac_work(struct work_struct *work);
264void mt792x_remove_interface(struct ieee80211_hw *hw,
265 struct ieee80211_vif *vif);
266void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
267 struct sk_buff *skb);
268int mt792x_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
269 unsigned int link_id, u16 queue,
270 const struct ieee80211_tx_queue_params *params);
271int mt792x_get_stats(struct ieee80211_hw *hw,
272 struct ieee80211_low_level_stats *stats);
273u64 mt792x_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
274void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
275 u64 timestamp);
276void mt792x_tx_worker(struct mt76_worker *w);
277void mt792x_roc_timer(struct timer_list *timer);
278void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
279 u32 queues, bool drop);
280int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,
281 struct ieee80211_vif *vif,
282 struct ieee80211_bss_conf *link_conf,
283 struct ieee80211_chanctx_conf *ctx);
284void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,
285 struct ieee80211_vif *vif,
286 struct ieee80211_bss_conf *link_conf,
287 struct ieee80211_chanctx_conf *ctx);
288void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled);
289void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
290 u32 sset, u8 *data);
291int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
292 int sset);
293void mt792x_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
294 struct ethtool_stats *stats, u64 *data);
295void mt792x_sta_statistics(struct ieee80211_hw *hw,
296 struct ieee80211_vif *vif,
297 struct ieee80211_sta *sta,
298 struct station_info *sinfo);
299void mt792x_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class);
300void mt792x_dma_cleanup(struct mt792x_dev *dev);
301int mt792x_dma_enable(struct mt792x_dev *dev);
302int mt792x_wpdma_reset(struct mt792x_dev *dev, bool force);
303int mt792x_wpdma_reinit_cond(struct mt792x_dev *dev);
304int mt792x_dma_disable(struct mt792x_dev *dev, bool force);
305irqreturn_t mt792x_irq_handler(int irq, void *dev_instance);
306void mt792x_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
307int mt792x_poll_tx(struct napi_struct *napi, int budget);
308int mt792x_poll_rx(struct napi_struct *napi, int budget);
309void mt792x_irq_tasklet(unsigned long data);
310int mt792x_wfsys_reset(struct mt792x_dev *dev);
311int mt792x_tx_stats_show(struct seq_file *file, void *data);
312int mt792x_queues_acq(struct seq_file *s, void *data);
313int mt792x_queues_read(struct seq_file *s, void *data);
314int mt792x_pm_stats(struct seq_file *s, void *data);
315int mt792x_pm_idle_timeout_set(void *data, u64 val);
316int mt792x_pm_idle_timeout_get(void *data, u64 *val);
317int mt792x_init_wiphy(struct ieee80211_hw *hw);
318struct ieee80211_ops *
319mt792x_get_mac80211_ops(struct device *dev,
320 const struct ieee80211_ops *mac80211_ops,
321 void *drv_data, u8 *fw_features);
322int mt792x_init_wcid(struct mt792x_dev *dev);
323int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);
324int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);
325
326static inline char *mt792x_ram_name(struct mt792x_dev *dev)
327{
328 switch (mt76_chip(&dev->mt76)) {
329 case 0x7922:
330 return MT7922_FIRMWARE_WM;
331 case 0x7925:
332 return MT7925_FIRMWARE_WM;
333 default:
334 return MT7921_FIRMWARE_WM;
335 }
336}
337
338static inline char *mt792x_patch_name(struct mt792x_dev *dev)
339{
340 switch (mt76_chip(&dev->mt76)) {
341 case 0x7922:
342 return MT7922_ROM_PATCH;
343 case 0x7925:
344 return MT7925_ROM_PATCH;
345 default:
346 return MT7921_ROM_PATCH;
347 }
348}
349
350int mt792x_load_firmware(struct mt792x_dev *dev);
351
352/* usb */
353#define MT_USB_TYPE_VENDOR (USB_TYPE_VENDOR | 0x1f)
354#define MT_USB_TYPE_UHW_VENDOR (USB_TYPE_VENDOR | 0x1e)
355int mt792xu_dma_init(struct mt792x_dev *dev, bool resume);
356int mt792xu_mcu_power_on(struct mt792x_dev *dev);
357int mt792xu_wfsys_reset(struct mt792x_dev *dev);
358int mt792xu_init_reset(struct mt792x_dev *dev);
359u32 mt792xu_rr(struct mt76_dev *dev, u32 addr);
360void mt792xu_wr(struct mt76_dev *dev, u32 addr, u32 val);
361u32 mt792xu_rmw(struct mt76_dev *dev, u32 addr, u32 mask, u32 val);
362void mt792xu_copy(struct mt76_dev *dev, u32 offset, const void *data, int len);
363void mt792xu_disconnect(struct usb_interface *usb_intf);
364void mt792xu_stop(struct ieee80211_hw *hw);
365
366static inline void
367mt792x_skb_add_usb_sdio_hdr(struct mt792x_dev *dev, struct sk_buff *skb,
368 int type)
369{
370 u32 hdr, len;
371
372 len = mt76_is_usb(&dev->mt76) ? skb->len : skb->len + sizeof(hdr);
373 hdr = FIELD_PREP(MT792x_SDIO_HDR_TX_BYTES, len) |
374 FIELD_PREP(MT792x_SDIO_HDR_PKT_TYPE, type);
375
376 put_unaligned_le32(hdr, skb_push(skb, sizeof(hdr)));
377}
378
379int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
380int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
381int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev);
382
383#ifdef CONFIG_ACPI
384int mt792x_init_acpi_sar(struct mt792x_dev *dev);
385int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default);
386u8 mt792x_acpi_get_flags(struct mt792x_phy *phy);
387u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2);
388#else
389static inline int mt792x_init_acpi_sar(struct mt792x_dev *dev)
390{
391 return 0;
392}
393
394static inline int mt792x_init_acpi_sar_power(struct mt792x_phy *phy,
395 bool set_default)
396{
397 return 0;
398}
399
400static inline u8 mt792x_acpi_get_flags(struct mt792x_phy *phy)
401{
402 return 0;
403}
404
405static inline u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2)
406{
407 return 0xf;
408}
409#endif
410
411#endif /* __MT7925_H */
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#include "mt792x_regs.h"
12#include "mt792x_acpi_sar.h"
13
14#define MT792x_PM_TIMEOUT (HZ / 12)
15#define MT792x_HW_SCAN_TIMEOUT (HZ / 10)
16
17#define MT792x_MAX_INTERFACES 4
18#define MT792x_WTBL_SIZE 20
19#define MT792x_WTBL_RESERVED (MT792x_WTBL_SIZE - 1)
20#define MT792x_WTBL_STA (MT792x_WTBL_RESERVED - MT792x_MAX_INTERFACES)
21
22#define MT792x_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
23#define MT792x_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
24
25#define MT792x_FW_TAG_FEATURE 4
26#define MT792x_FW_CAP_CNM BIT(7)
27
28#define MT792x_CHIP_CAP_CLC_EVT_EN BIT(0)
29#define MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN BIT(1)
30#define MT792x_CHIP_CAP_MLO_EVT_EN BIT(2)
31
32/* NOTE: used to map mt76_rates. idx may change if firmware expands table */
33#define MT792x_BASIC_RATES_TBL 11
34
35#define MT792x_WATCHDOG_TIME (HZ / 4)
36
37#define MT792x_DRV_OWN_RETRY_COUNT 10
38#define MT792x_MCU_INIT_RETRY_COUNT 10
39#define MT792x_WFSYS_INIT_RETRY_COUNT 2
40
41#define MT7920_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1a.bin"
42#define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin"
43#define MT7922_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7922_1.bin"
44#define MT7925_FIRMWARE_WM "mediatek/mt7925/WIFI_RAM_CODE_MT7925_1_1.bin"
45
46#define MT7920_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1a_2_hdr.bin"
47#define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin"
48#define MT7922_ROM_PATCH "mediatek/WIFI_MT7922_patch_mcu_1_1_hdr.bin"
49#define MT7925_ROM_PATCH "mediatek/mt7925/WIFI_MT7925_PATCH_MCU_1_1_hdr.bin"
50
51#define MT792x_SDIO_HDR_TX_BYTES GENMASK(15, 0)
52#define MT792x_SDIO_HDR_PKT_TYPE GENMASK(17, 16)
53
54struct mt792x_vif;
55struct mt792x_sta;
56
57struct mt792x_realease_info {
58 __le16 len;
59 u8 pad_len;
60 u8 tag;
61} __packed;
62
63struct mt792x_fw_features {
64 u8 segment;
65 u8 data;
66 u8 rsv[14];
67} __packed;
68
69enum {
70 MT792x_CLC_POWER,
71 MT792x_CLC_POWER_EXT,
72 MT792x_CLC_MAX_NUM,
73};
74
75enum mt792x_reg_power_type {
76 MT_AP_UNSET = 0,
77 MT_AP_DEFAULT,
78 MT_AP_LPI,
79 MT_AP_SP,
80 MT_AP_VLP,
81};
82
83DECLARE_EWMA(avg_signal, 10, 8)
84
85struct mt792x_link_sta {
86 struct mt76_wcid wcid; /* must be first */
87
88 u32 airtime_ac[8];
89
90 int ack_signal;
91 struct ewma_avg_signal avg_ack_signal;
92
93 unsigned long last_txs;
94
95 struct mt76_connac_sta_key_conf bip;
96
97 struct mt792x_sta *sta;
98
99 struct ieee80211_link_sta *pri_link;
100};
101
102struct mt792x_sta {
103 struct mt792x_link_sta deflink; /* must be first */
104 struct mt792x_link_sta __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
105
106 struct mt792x_vif *vif;
107
108 u16 valid_links;
109 u8 deflink_id;
110};
111
112DECLARE_EWMA(rssi, 10, 8);
113
114struct mt792x_chanctx {
115 struct mt792x_bss_conf *bss_conf;
116};
117
118struct mt792x_bss_conf {
119 struct mt76_vif mt76; /* must be first */
120 struct mt792x_vif *vif;
121 struct ewma_rssi rssi;
122 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
123 unsigned int link_id;
124};
125
126struct mt792x_vif {
127 struct mt792x_bss_conf bss_conf; /* must be first */
128 struct mt792x_bss_conf __rcu *link_conf[IEEE80211_MLD_MAX_NUM_LINKS];
129
130 struct mt792x_sta sta;
131 struct mt792x_sta *wep_sta;
132
133 struct mt792x_phy *phy;
134 u16 valid_links;
135 u8 deflink_id;
136};
137
138struct mt792x_phy {
139 struct mt76_phy *mt76;
140 struct mt792x_dev *dev;
141
142 struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
143
144 u64 omac_mask;
145
146 u16 noise;
147
148 s16 coverage_class;
149 u8 slottime;
150
151 u32 rx_ampdu_ts;
152 u32 ampdu_ref;
153
154 struct mt76_mib_stats mib;
155
156 u8 sta_work_count;
157 u8 clc_chan_conf;
158 enum mt792x_reg_power_type power_type;
159
160 struct sk_buff_head scan_event_list;
161 struct delayed_work scan_work;
162#ifdef CONFIG_ACPI
163 void *acpisar;
164#endif
165 void *clc[MT792x_CLC_MAX_NUM];
166 u64 chip_cap;
167 u16 eml_cap;
168
169 struct work_struct roc_work;
170 struct timer_list roc_timer;
171 wait_queue_head_t roc_wait;
172 u8 roc_token_id;
173 bool roc_grant;
174};
175
176struct mt792x_irq_map {
177 u32 host_irq_enable;
178 struct {
179 u32 all_complete_mask;
180 u32 mcu_complete_mask;
181 } tx;
182 struct {
183 u32 data_complete_mask;
184 u32 wm_complete_mask;
185 u32 wm2_complete_mask;
186 } rx;
187};
188
189#define mt792x_init_reset(dev) ((dev)->hif_ops->init_reset(dev))
190#define mt792x_dev_reset(dev) ((dev)->hif_ops->reset(dev))
191#define mt792x_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev))
192#define __mt792x_mcu_drv_pmctrl(dev) ((dev)->hif_ops->drv_own(dev))
193#define __mt792x_mcu_fw_pmctrl(dev) ((dev)->hif_ops->fw_own(dev))
194
195struct mt792x_hif_ops {
196 int (*init_reset)(struct mt792x_dev *dev);
197 int (*reset)(struct mt792x_dev *dev);
198 int (*mcu_init)(struct mt792x_dev *dev);
199 int (*drv_own)(struct mt792x_dev *dev);
200 int (*fw_own)(struct mt792x_dev *dev);
201};
202
203struct mt792x_dev {
204 union { /* must be first */
205 struct mt76_dev mt76;
206 struct mt76_phy mphy;
207 };
208
209 const struct mt76_bus_ops *bus_ops;
210 struct mt792x_phy phy;
211
212 struct work_struct reset_work;
213 bool hw_full_reset:1;
214 bool hw_init_done:1;
215 bool fw_assert:1;
216 bool has_eht:1;
217 bool regd_in_progress:1;
218 bool aspm_supported:1;
219 wait_queue_head_t wait;
220
221 struct work_struct init_work;
222
223 u8 fw_debug;
224 u8 fw_features;
225
226 struct mt76_connac_pm pm;
227 struct mt76_connac_coredump coredump;
228 const struct mt792x_hif_ops *hif_ops;
229 const struct mt792x_irq_map *irq_map;
230
231 struct work_struct ipv6_ns_work;
232 /* IPv6 addresses for WoWLAN */
233 struct sk_buff_head ipv6_ns_list;
234
235 enum environment_cap country_ie_env;
236 u32 backup_l1;
237 u32 backup_l2;
238};
239
240static inline struct mt792x_bss_conf *
241mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id)
242{
243 struct ieee80211_vif *vif;
244 struct mt792x_bss_conf *bss_conf;
245
246 vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
247
248 if (!ieee80211_vif_is_mld(vif) ||
249 link_id >= IEEE80211_LINK_UNSPECIFIED)
250 return &mvif->bss_conf;
251
252 bss_conf = rcu_dereference_protected(mvif->link_conf[link_id],
253 lockdep_is_held(&mvif->phy->dev->mt76.mutex));
254
255 return bss_conf ? bss_conf : &mvif->bss_conf;
256}
257
258static inline struct mt792x_link_sta *
259mt792x_sta_to_link(struct mt792x_sta *msta, u8 link_id)
260{
261 struct ieee80211_vif *vif;
262
263 vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
264
265 if (!ieee80211_vif_is_mld(vif) ||
266 link_id >= IEEE80211_LINK_UNSPECIFIED)
267 return &msta->deflink;
268
269 return rcu_dereference_protected(msta->link[link_id],
270 lockdep_is_held(&msta->vif->phy->dev->mt76.mutex));
271}
272
273static inline struct mt792x_bss_conf *
274mt792x_link_conf_to_mconf(struct ieee80211_bss_conf *link_conf)
275{
276 struct ieee80211_vif *vif = link_conf->vif;
277 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
278
279 return mt792x_vif_to_link(mvif, link_conf->link_id);
280}
281
282static inline struct ieee80211_bss_conf *
283mt792x_vif_to_bss_conf(struct ieee80211_vif *vif, unsigned int link_id)
284{
285 if (!ieee80211_vif_is_mld(vif) ||
286 link_id >= IEEE80211_LINK_UNSPECIFIED)
287 return &vif->bss_conf;
288
289 return link_conf_dereference_protected(vif, link_id);
290}
291
292static inline struct ieee80211_link_sta *
293mt792x_sta_to_link_sta(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
294 unsigned int link_id)
295{
296 if (!ieee80211_vif_is_mld(vif) ||
297 link_id >= IEEE80211_LINK_UNSPECIFIED)
298 return &sta->deflink;
299
300 return link_sta_dereference_protected(sta, link_id);
301}
302
303static inline struct mt792x_dev *
304mt792x_hw_dev(struct ieee80211_hw *hw)
305{
306 struct mt76_phy *phy = hw->priv;
307
308 return container_of(phy->dev, struct mt792x_dev, mt76);
309}
310
311static inline struct mt792x_phy *
312mt792x_hw_phy(struct ieee80211_hw *hw)
313{
314 struct mt76_phy *phy = hw->priv;
315
316 return phy->priv;
317}
318
319static inline void
320mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)
321{
322 if (chfreq > 180) {
323 status->band = NL80211_BAND_6GHZ;
324 chfreq = (chfreq - 181) * 4 + 1;
325 } else if (chfreq > 14) {
326 status->band = NL80211_BAND_5GHZ;
327 } else {
328 status->band = NL80211_BAND_2GHZ;
329 }
330 status->freq = ieee80211_channel_to_frequency(chfreq, status->band);
331}
332
333static inline bool mt792x_dma_need_reinit(struct mt792x_dev *dev)
334{
335 return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
336}
337
338#define mt792x_mutex_acquire(dev) \
339 mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm)
340#define mt792x_mutex_release(dev) \
341 mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm)
342
343void mt792x_stop(struct ieee80211_hw *hw, bool suspend);
344void mt792x_pm_wake_work(struct work_struct *work);
345void mt792x_pm_power_save_work(struct work_struct *work);
346void mt792x_reset(struct mt76_dev *mdev);
347void mt792x_update_channel(struct mt76_phy *mphy);
348void mt792x_mac_reset_counters(struct mt792x_phy *phy);
349void mt792x_mac_init_band(struct mt792x_dev *dev, u8 band);
350void mt792x_mac_assoc_rssi(struct mt792x_dev *dev, struct sk_buff *skb);
351struct mt76_wcid *mt792x_rx_get_wcid(struct mt792x_dev *dev, u16 idx,
352 bool unicast);
353void mt792x_mac_update_mib_stats(struct mt792x_phy *phy);
354void mt792x_mac_set_timeing(struct mt792x_phy *phy);
355void mt792x_mac_work(struct work_struct *work);
356void mt792x_remove_interface(struct ieee80211_hw *hw,
357 struct ieee80211_vif *vif);
358void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
359 struct sk_buff *skb);
360int mt792x_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
361 unsigned int link_id, u16 queue,
362 const struct ieee80211_tx_queue_params *params);
363int mt792x_get_stats(struct ieee80211_hw *hw,
364 struct ieee80211_low_level_stats *stats);
365u64 mt792x_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
366void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
367 u64 timestamp);
368void mt792x_tx_worker(struct mt76_worker *w);
369void mt792x_roc_timer(struct timer_list *timer);
370void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
371 u32 queues, bool drop);
372int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,
373 struct ieee80211_vif *vif,
374 struct ieee80211_bss_conf *link_conf,
375 struct ieee80211_chanctx_conf *ctx);
376void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,
377 struct ieee80211_vif *vif,
378 struct ieee80211_bss_conf *link_conf,
379 struct ieee80211_chanctx_conf *ctx);
380void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled);
381void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
382 u32 sset, u8 *data);
383int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
384 int sset);
385void mt792x_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
386 struct ethtool_stats *stats, u64 *data);
387void mt792x_sta_statistics(struct ieee80211_hw *hw,
388 struct ieee80211_vif *vif,
389 struct ieee80211_sta *sta,
390 struct station_info *sinfo);
391void mt792x_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class);
392void mt792x_dma_cleanup(struct mt792x_dev *dev);
393int mt792x_dma_enable(struct mt792x_dev *dev);
394int mt792x_wpdma_reset(struct mt792x_dev *dev, bool force);
395int mt792x_wpdma_reinit_cond(struct mt792x_dev *dev);
396int mt792x_dma_disable(struct mt792x_dev *dev, bool force);
397irqreturn_t mt792x_irq_handler(int irq, void *dev_instance);
398void mt792x_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
399int mt792x_poll_tx(struct napi_struct *napi, int budget);
400int mt792x_poll_rx(struct napi_struct *napi, int budget);
401void mt792x_irq_tasklet(unsigned long data);
402int mt792x_wfsys_reset(struct mt792x_dev *dev);
403int mt792x_tx_stats_show(struct seq_file *file, void *data);
404int mt792x_queues_acq(struct seq_file *s, void *data);
405int mt792x_queues_read(struct seq_file *s, void *data);
406int mt792x_pm_stats(struct seq_file *s, void *data);
407int mt792x_pm_idle_timeout_set(void *data, u64 val);
408int mt792x_pm_idle_timeout_get(void *data, u64 *val);
409int mt792x_init_wiphy(struct ieee80211_hw *hw);
410struct ieee80211_ops *
411mt792x_get_mac80211_ops(struct device *dev,
412 const struct ieee80211_ops *mac80211_ops,
413 void *drv_data, u8 *fw_features);
414int mt792x_init_wcid(struct mt792x_dev *dev);
415int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);
416int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);
417void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
418 struct mt792x_bss_conf *mconf,
419 struct mt792x_link_sta *mlink);
420
421static inline char *mt792x_ram_name(struct mt792x_dev *dev)
422{
423 switch (mt76_chip(&dev->mt76)) {
424 case 0x7920:
425 return MT7920_FIRMWARE_WM;
426 case 0x7922:
427 return MT7922_FIRMWARE_WM;
428 case 0x7925:
429 return MT7925_FIRMWARE_WM;
430 default:
431 return MT7921_FIRMWARE_WM;
432 }
433}
434
435static inline char *mt792x_patch_name(struct mt792x_dev *dev)
436{
437 switch (mt76_chip(&dev->mt76)) {
438 case 0x7920:
439 return MT7920_ROM_PATCH;
440 case 0x7922:
441 return MT7922_ROM_PATCH;
442 case 0x7925:
443 return MT7925_ROM_PATCH;
444 default:
445 return MT7921_ROM_PATCH;
446 }
447}
448
449int mt792x_load_firmware(struct mt792x_dev *dev);
450
451/* usb */
452#define MT_USB_TYPE_VENDOR (USB_TYPE_VENDOR | 0x1f)
453#define MT_USB_TYPE_UHW_VENDOR (USB_TYPE_VENDOR | 0x1e)
454int mt792xu_dma_init(struct mt792x_dev *dev, bool resume);
455int mt792xu_mcu_power_on(struct mt792x_dev *dev);
456int mt792xu_wfsys_reset(struct mt792x_dev *dev);
457int mt792xu_init_reset(struct mt792x_dev *dev);
458u32 mt792xu_rr(struct mt76_dev *dev, u32 addr);
459void mt792xu_wr(struct mt76_dev *dev, u32 addr, u32 val);
460u32 mt792xu_rmw(struct mt76_dev *dev, u32 addr, u32 mask, u32 val);
461void mt792xu_copy(struct mt76_dev *dev, u32 offset, const void *data, int len);
462void mt792xu_disconnect(struct usb_interface *usb_intf);
463void mt792xu_stop(struct ieee80211_hw *hw, bool suspend);
464
465static inline void
466mt792x_skb_add_usb_sdio_hdr(struct mt792x_dev *dev, struct sk_buff *skb,
467 int type)
468{
469 u32 hdr, len;
470
471 len = mt76_is_usb(&dev->mt76) ? skb->len : skb->len + sizeof(hdr);
472 hdr = FIELD_PREP(MT792x_SDIO_HDR_TX_BYTES, len) |
473 FIELD_PREP(MT792x_SDIO_HDR_PKT_TYPE, type);
474
475 put_unaligned_le32(hdr, skb_push(skb, sizeof(hdr)));
476}
477
478int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
479int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
480int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev);
481
482#ifdef CONFIG_ACPI
483int mt792x_init_acpi_sar(struct mt792x_dev *dev);
484int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default);
485u8 mt792x_acpi_get_flags(struct mt792x_phy *phy);
486u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2);
487#else
488static inline int mt792x_init_acpi_sar(struct mt792x_dev *dev)
489{
490 return 0;
491}
492
493static inline int mt792x_init_acpi_sar_power(struct mt792x_phy *phy,
494 bool set_default)
495{
496 return 0;
497}
498
499static inline u8 mt792x_acpi_get_flags(struct mt792x_phy *phy)
500{
501 return 0;
502}
503
504static inline u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2)
505{
506 return 0xf;
507}
508#endif
509
510#endif /* __MT7925_H */