1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
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_NAN BIT(5)
27 #define MT792x_FW_CAP_CNM BIT(7)
28
29 #define MT792x_CHIP_CAP_CLC_EVT_EN BIT(0)
30 #define MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN BIT(1)
31 #define MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN BIT(3)
32 #define MT792x_CHIP_CAP_11D_EN BIT(4)
33 #define MT792x_CHIP_CAP_REGD_EN BIT(5)
34 #define MT792x_CHIP_CAP_MLO_EN BIT(8)
35 #define MT792x_CHIP_CAP_MLO_EML_EN BIT(9)
36
37 /* NOTE: used to map mt76_rates. idx may change if firmware expands table */
38 #define MT792x_BASIC_RATES_TBL 14
39
40 #define MT792x_WATCHDOG_TIME (HZ / 4)
41
42 #define MT792x_DRV_OWN_RETRY_COUNT 10
43 #define MT792x_MCU_INIT_RETRY_COUNT 10
44 #define MT792x_WFSYS_INIT_RETRY_COUNT 2
45
46 #define MT7902_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7902_1.bin"
47 #define MT7920_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1a.bin"
48 #define MT7921_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7961_1.bin"
49 #define MT7922_FIRMWARE_WM "mediatek/WIFI_RAM_CODE_MT7922_1.bin"
50 #define MT7925_FIRMWARE_WM "mediatek/mt7925/WIFI_RAM_CODE_MT7925_1_1.bin"
51 #define MT7927_FIRMWARE_WM "mediatek/mt7927/WIFI_RAM_CODE_MT6639_2_1.bin"
52 #define MT7928_FIRMWARE_WM "mediatek/mt7928/WIFI_RAM_CODE_MT7935_1_1.bin"
53
54 #define MT7902_ROM_PATCH "mediatek/WIFI_MT7902_patch_mcu_1_1_hdr.bin"
55 #define MT7920_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1a_2_hdr.bin"
56 #define MT7921_ROM_PATCH "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin"
57 #define MT7922_ROM_PATCH "mediatek/WIFI_MT7922_patch_mcu_1_1_hdr.bin"
58 #define MT7925_ROM_PATCH "mediatek/mt7925/WIFI_MT7925_PATCH_MCU_1_1_hdr.bin"
59 #define MT7927_ROM_PATCH "mediatek/mt7927/WIFI_MT6639_PATCH_MCU_2_1_hdr.bin"
60 #define MT7928_ROM_PATCH "mediatek/mt7928/WIFI_MT7935_PATCH_MCU_1_1_hdr.bin"
61
62 #define MT7928_CB_ROM_PATCH "mediatek/mt7928/CBMCU_CODE_MT7935_1_1.bin"
63 #define MT7928_PHY_RAM "mediatek/mt7928/WIFI_MT7935_PHY_RAM_CODE_1_1.bin"
64
65 #define MT792x_SDIO_HDR_TX_BYTES GENMASK(15, 0)
66 #define MT792x_SDIO_HDR_PKT_TYPE GENMASK(17, 16)
67
68 struct mt792x_vif;
69 struct mt792x_sta;
70
71 struct mt792x_realease_info {
72 __le16 len;
73 u8 pad_len;
74 u8 tag;
75 } __packed;
76
77 struct mt792x_fw_features {
78 u8 segment;
79 u8 data;
80 u8 rsv[14];
81 } __packed;
82
83 enum {
84 MT792x_CLC_POWER,
85 MT792x_CLC_POWER_EXT,
86 MT792x_CLC_BE_CTRL,
87 MT792x_CLC_REGD,
88 MT792x_CLC_MAX_NUM,
89 };
90
91 enum mt792x_reg_power_type {
92 MT_AP_UNSET = 0,
93 MT_AP_DEFAULT,
94 MT_AP_LPI,
95 MT_AP_SP,
96 MT_AP_VLP,
97 };
98
99 enum mt792x_mlo_pm_state {
100 MT792x_MLO_LINK_DISASSOC,
101 MT792x_MLO_LINK_ASSOC,
102 MT792x_MLO_CHANGED_PS_PENDING,
103 MT792x_MLO_CHANGED_PS,
104 };
105
106 DECLARE_EWMA(avg_signal, 10, 8)
107
108 struct mt792x_link_sta {
109 struct mt76_wcid wcid; /* must be first */
110 struct rcu_head rcu_head;
111
112 u32 airtime_ac[8];
113
114 int ack_signal;
115 struct ewma_avg_signal avg_ack_signal;
116
117 unsigned long last_txs;
118
119 struct mt76_connac_sta_key_conf bip;
120
121 struct mt792x_sta *sta;
122
123 struct ieee80211_link_sta *pri_link;
124 };
125
126 struct mt792x_sta_nan_sched {
127 /* protects NAN peer schedule state */
128 u16 committed_dw;
129 u32 sch_idx;
130 bool idx_assigned;
131 unsigned long ndp_ctx_bitmap;
132 bool ndp_ctx_assigned;
133 u8 ndp_ctx_id; /* assigned NDP context ID (for NDI sta) */
134 struct {
135 u8 map_id;
136 struct cfg80211_chan_def chans[CFG80211_NAN_SCHED_NUM_TIME_SLOTS];
137 } maps[CFG80211_NAN_MAX_PEER_MAPS];
138 };
139
140 struct mt792x_sta {
141 struct mt792x_link_sta deflink; /* must be first */
142 struct mt792x_link_sta __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
143
144 struct mt792x_vif *vif;
145
146 u16 valid_links;
147 u8 deflink_id;
148
149 /* NAN peer schedule */
150 struct mt792x_sta_nan_sched nan_sched;
151 };
152
153 DECLARE_EWMA(rssi, 10, 8);
154
155 struct mt792x_chanctx {
156 struct mt792x_bss_conf *bss_conf;
157 };
158
159 struct mt792x_bss_conf {
160 struct mt76_vif_link mt76; /* must be first */
161 struct mt792x_vif *vif;
162 struct ewma_rssi rssi;
163 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
164 unsigned int link_id;
165 };
166
167 struct mt792x_nan_conf {
168 u8 master_pref;
169 u8 bands;
170 u8 cluster_id[ETH_ALEN];
171 u32 discovery_beacon_interval;
172 bool enable_dw_notification;
173 };
174
175 struct mt792x_nan {
176 struct mt792x_nan_conf conf;
177
178 /* Scheduler */
179 struct cfg80211_chan_def local_sched[CFG80211_NAN_SCHED_NUM_TIME_SLOTS];
180 u32 seq_id;
181
182 /* Connection index bitmap, up to NAN_MAX_CONN_CFG peers */
183 unsigned long conn_bitmap;
184 };
185
186 struct mt792x_vif {
187 struct mt792x_bss_conf bss_conf; /* must be first */
188 struct mt792x_bss_conf __rcu *link_conf[IEEE80211_MLD_MAX_NUM_LINKS];
189
190 struct mt792x_sta sta;
191 struct mt792x_sta *wep_sta;
192
193 struct mt792x_phy *phy;
194 u16 valid_links;
195 u8 deflink_id;
196 enum mt792x_mlo_pm_state mlo_pm_state;
197
198 struct work_struct csa_work;
199 struct timer_list csa_timer;
200
201 struct mt792x_nan nan;
202 };
203
204 struct mt792x_phy {
205 struct mt76_phy *mt76;
206 struct mt792x_dev *dev;
207
208 struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES];
209
210 u64 omac_mask;
211
212 u16 noise;
213
214 s16 coverage_class;
215 u8 slottime;
216
217 u32 rx_ampdu_ts;
218 u32 ampdu_ref;
219
220 struct mt76_mib_stats mib;
221
222 u8 sta_work_count;
223 u8 clc_chan_conf;
224 enum mt792x_reg_power_type power_type;
225
226 struct sk_buff_head scan_event_list;
227 struct delayed_work scan_work;
228 #ifdef CONFIG_ACPI
229 void *acpisar;
230 #endif
231 void *clc[MT792x_CLC_MAX_NUM];
232 u64 chip_cap;
233 u16 eml_cap;
234
235 struct work_struct roc_work;
236 struct timer_list roc_timer;
237 wait_queue_head_t roc_wait;
238 u8 roc_token_id;
239 bool roc_grant;
240 };
241
242 struct mt792x_irq_map {
243 u32 host_irq_enable;
244 struct {
245 u32 all_complete_mask;
246 u32 mcu_complete_mask;
247 } tx;
248 struct {
249 u32 all_complete_mask;
250 u32 data_complete_mask;
251 u32 wm_complete_mask;
252 u32 wm2_complete_mask;
253 } rx;
254 };
255
256 struct mt792x_dma_ring {
257 u8 qid;
258 u16 n_desc;
259 u32 ring_base;
260 };
261
262 struct mt792x_dma_layout {
263 struct mt792x_dma_ring tx_data0;
264 struct mt792x_dma_ring tx_mcu;
265 struct mt792x_dma_ring tx_fwdl;
266 struct mt792x_dma_ring tx_done;
267 struct mt792x_dma_ring rx_data;
268 struct mt792x_dma_ring rx_mcu;
269 };
270
271 #define mt792x_dma_ring(_qid, _n_desc, _ring_base) \
272 { .qid = (_qid), .n_desc = (_n_desc), .ring_base = (_ring_base) }
273
274 #define mt792x_init_reset(dev) ((dev)->hif_ops->init_reset(dev))
275 #define mt792x_dev_reset(dev) ((dev)->hif_ops->reset(dev))
276 #define mt792x_mcu_init(dev) ((dev)->hif_ops->mcu_init(dev))
277 #define __mt792x_mcu_drv_pmctrl(dev) ((dev)->hif_ops->drv_own(dev))
278 #define __mt792x_mcu_fw_pmctrl(dev) ((dev)->hif_ops->fw_own(dev))
279
280 struct mt792x_hif_ops {
281 int (*init_reset)(struct mt792x_dev *dev);
282 int (*reset)(struct mt792x_dev *dev);
283 int (*mcu_init)(struct mt792x_dev *dev);
284 int (*drv_own)(struct mt792x_dev *dev);
285 int (*fw_own)(struct mt792x_dev *dev);
286 };
287
288 struct mt792x_pcie_reg {
289 u32 imask;
290 u32 pm;
291 };
292
293 struct mt792x_dev {
294 union { /* must be first */
295 struct mt76_dev mt76;
296 struct mt76_phy mphy;
297 };
298
299 struct mac_address macaddr_list[8];
300
301 const struct mt76_bus_ops *bus_ops;
302 struct mt792x_phy phy;
303
304 struct work_struct reset_work;
305 bool hw_full_reset:1;
306 bool hw_init_done:1;
307 bool fw_assert:1;
308 bool has_eht:1;
309 bool regd_user:1;
310 bool regd_in_progress:1;
311 bool aspm_supported:1;
312 bool hif_idle:1;
313 bool hif_resumed:1;
314 bool regd_change:1;
315 bool skip_wpdma_reinit:1;
316 wait_queue_head_t wait;
317
318 struct work_struct init_work;
319 struct work_struct usb_reset_work;
320 atomic_t usb_reset_pending;
321
322 u8 fw_debug;
323 u8 fw_features;
324
325 struct mt76_connac_pm pm;
326 struct mt76_connac_coredump coredump;
327 const struct mt792x_hif_ops *hif_ops;
328 const struct mt792x_irq_map *irq_map;
329 const struct mt792x_pcie_reg *pcie_reg;
330
331 struct work_struct ipv6_ns_work;
332 struct delayed_work mlo_pm_work;
333 /* IPv6 addresses for WoWLAN */
334 struct sk_buff_head ipv6_ns_list;
335
336 enum environment_cap country_ie_env;
337 u32 backup_l1;
338 u32 backup_l2;
339
340 struct ieee80211_chanctx_conf *new_ctx;
341
342 struct ieee80211_vif *nan_vif;
343 const struct ieee80211_iface_combination *iface_combinations;
344 int n_iface_combinations;
345 };
346
347 static inline struct mt792x_bss_conf *
mt792x_vif_to_link(struct mt792x_vif * mvif,u8 link_id)348 mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id)
349 {
350 struct ieee80211_vif *vif;
351 struct mt792x_bss_conf *bss_conf;
352
353 vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
354
355 if (!ieee80211_vif_is_mld(vif) ||
356 link_id >= IEEE80211_LINK_UNSPECIFIED)
357 return &mvif->bss_conf;
358
359 bss_conf = rcu_dereference_protected(mvif->link_conf[link_id],
360 lockdep_is_held(&mvif->phy->dev->mt76.mutex));
361
362 return bss_conf ? bss_conf : &mvif->bss_conf;
363 }
364
365 static inline struct mt792x_link_sta *
mt792x_sta_to_link(struct mt792x_sta * msta,u8 link_id)366 mt792x_sta_to_link(struct mt792x_sta *msta, u8 link_id)
367 {
368 struct ieee80211_vif *vif;
369
370 vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
371
372 if (!ieee80211_vif_is_mld(vif) ||
373 link_id >= IEEE80211_LINK_UNSPECIFIED)
374 return &msta->deflink;
375
376 return rcu_dereference_protected(msta->link[link_id],
377 lockdep_is_held(&msta->vif->phy->dev->mt76.mutex));
378 }
379
380 static inline struct mt792x_bss_conf *
mt792x_link_conf_to_mconf(struct ieee80211_bss_conf * link_conf)381 mt792x_link_conf_to_mconf(struct ieee80211_bss_conf *link_conf)
382 {
383 struct ieee80211_vif *vif = link_conf->vif;
384 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
385
386 return mt792x_vif_to_link(mvif, link_conf->link_id);
387 }
388
389 static inline struct ieee80211_bss_conf *
mt792x_vif_to_bss_conf(struct ieee80211_vif * vif,unsigned int link_id)390 mt792x_vif_to_bss_conf(struct ieee80211_vif *vif, unsigned int link_id)
391 {
392 if (!ieee80211_vif_is_mld(vif) ||
393 link_id >= IEEE80211_LINK_UNSPECIFIED)
394 return &vif->bss_conf;
395
396 return link_conf_dereference_protected(vif, link_id);
397 }
398
399 static inline struct ieee80211_link_sta *
mt792x_sta_to_link_sta(struct ieee80211_vif * vif,struct ieee80211_sta * sta,unsigned int link_id)400 mt792x_sta_to_link_sta(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
401 unsigned int link_id)
402 {
403 if (!ieee80211_vif_is_mld(vif) ||
404 link_id >= IEEE80211_LINK_UNSPECIFIED)
405 return &sta->deflink;
406
407 return link_sta_dereference_protected(sta, link_id);
408 }
409
410 static inline struct mt792x_dev *
mt792x_hw_dev(struct ieee80211_hw * hw)411 mt792x_hw_dev(struct ieee80211_hw *hw)
412 {
413 struct mt76_phy *phy = hw->priv;
414
415 return container_of(phy->dev, struct mt792x_dev, mt76);
416 }
417
418 static inline struct mt792x_phy *
mt792x_hw_phy(struct ieee80211_hw * hw)419 mt792x_hw_phy(struct ieee80211_hw *hw)
420 {
421 struct mt76_phy *phy = hw->priv;
422
423 return phy->priv;
424 }
425
426 static inline void
mt792x_get_status_freq_info(struct mt76_rx_status * status,u8 chfreq)427 mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)
428 {
429 if (chfreq > 180) {
430 status->band = NL80211_BAND_6GHZ;
431 chfreq = (chfreq - 181) * 4 + 1;
432 } else if (chfreq > 14) {
433 status->band = NL80211_BAND_5GHZ;
434 } else {
435 status->band = NL80211_BAND_2GHZ;
436 }
437 status->freq = ieee80211_channel_to_frequency(chfreq, status->band);
438 }
439
mt792x_dma_need_reinit(struct mt792x_dev * dev)440 static inline bool mt792x_dma_need_reinit(struct mt792x_dev *dev)
441 {
442 return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
443 }
444
445 #define mt792x_mutex_acquire(dev) \
446 mt76_connac_mutex_acquire(&(dev)->mt76, &(dev)->pm)
447 #define mt792x_mutex_release(dev) \
448 mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm)
449
450 void mt792x_stop(struct ieee80211_hw *hw, bool suspend);
451 void mt792x_pm_wake_work(struct work_struct *work);
452 void mt792x_pm_power_save_work(struct work_struct *work);
453 void mt792x_reset(struct mt76_dev *mdev);
454 void mt792x_update_channel(struct mt76_phy *mphy);
455 void mt792x_mac_reset_counters(struct mt792x_phy *phy);
456 void mt792x_mac_init_band(struct mt792x_dev *dev, u8 band);
457 void mt792x_mac_assoc_rssi(struct mt792x_dev *dev, struct sk_buff *skb);
458 struct mt76_wcid *mt792x_rx_get_wcid(struct mt792x_dev *dev, u16 idx,
459 bool unicast);
460 void mt792x_mac_update_mib_stats(struct mt792x_phy *phy);
461 void mt792x_mac_set_timeing(struct mt792x_phy *phy);
462 void mt792x_mac_work(struct work_struct *work);
463 void mt792x_remove_interface(struct ieee80211_hw *hw,
464 struct ieee80211_vif *vif);
465 void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
466 struct sk_buff *skb);
467 int mt792x_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
468 unsigned int link_id, u16 queue,
469 const struct ieee80211_tx_queue_params *params);
470 int mt792x_get_stats(struct ieee80211_hw *hw,
471 struct ieee80211_low_level_stats *stats);
472 u64 mt792x_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
473 void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
474 u64 timestamp);
475 void mt792x_tx_worker(struct mt76_worker *w);
476 void mt792x_roc_timer(struct timer_list *timer);
477 void mt792x_csa_timer(struct timer_list *timer);
478 void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
479 u32 queues, bool drop);
480 int mt792x_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
481 unsigned int link_id, int *dbm);
482 int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,
483 struct ieee80211_vif *vif,
484 struct ieee80211_bss_conf *link_conf,
485 struct ieee80211_chanctx_conf *ctx);
486 void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,
487 struct ieee80211_vif *vif,
488 struct ieee80211_bss_conf *link_conf,
489 struct ieee80211_chanctx_conf *ctx);
490 void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled);
491 void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
492 u32 sset, u8 *data);
493 int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
494 int sset);
495 void mt792x_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
496 struct ethtool_stats *stats, u64 *data);
497 void mt792x_sta_statistics(struct ieee80211_hw *hw,
498 struct ieee80211_vif *vif,
499 struct ieee80211_sta *sta,
500 struct station_info *sinfo);
501 void mt792x_set_coverage_class(struct ieee80211_hw *hw, int radio_idx,
502 s16 coverage_class);
503 void mt792x_dma_cleanup(struct mt792x_dev *dev);
504 int mt792x_dma_alloc_queues(struct mt792x_dev *dev,
505 const struct mt792x_dma_layout *layout);
506 int mt792x_dma_enable(struct mt792x_dev *dev);
507 int mt792x_wpdma_reset(struct mt792x_dev *dev, bool force);
508 int mt792x_wpdma_reinit_cond(struct mt792x_dev *dev);
509 int mt792x_dma_disable(struct mt792x_dev *dev, bool force);
510 irqreturn_t mt792x_irq_handler(int irq, void *dev_instance);
511 void mt792x_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
512 int mt792x_poll_tx(struct napi_struct *napi, int budget);
513 int mt792x_poll_rx(struct napi_struct *napi, int budget);
514 void mt792x_irq_tasklet(unsigned long data);
515 int mt792x_wfsys_reset(struct mt792x_dev *dev);
516 int mt792x_tx_stats_show(struct seq_file *file, void *data);
517 int mt792x_queues_acq(struct seq_file *s, void *data);
518 int mt792x_queues_read(struct seq_file *s, void *data);
519 int mt792x_pm_stats(struct seq_file *s, void *data);
520 int mt792x_pm_idle_timeout_set(void *data, u64 val);
521 int mt792x_pm_idle_timeout_get(void *data, u64 *val);
522 int mt792x_init_wiphy(struct ieee80211_hw *hw);
523 struct ieee80211_ops *
524 mt792x_get_mac80211_ops(struct device *dev,
525 const struct ieee80211_ops *mac80211_ops,
526 void *drv_data, u8 *fw_features);
527 int mt792x_init_wcid(struct mt792x_dev *dev);
528 int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);
529 int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);
530 void mt792x_mac_link_bss_remove(struct mt792x_dev *dev,
531 struct mt792x_bss_conf *mconf,
532 struct mt792x_link_sta *mlink);
533 void mt792x_config_mac_addr_list(struct mt792x_dev *dev);
534
mt792x_ram_name(struct mt792x_dev * dev)535 static inline char *mt792x_ram_name(struct mt792x_dev *dev)
536 {
537 switch (mt76_chip(&dev->mt76)) {
538 case 0x7902:
539 return MT7902_FIRMWARE_WM;
540 case 0x7920:
541 return MT7920_FIRMWARE_WM;
542 case 0x7922:
543 return MT7922_FIRMWARE_WM;
544 case 0x7925:
545 return MT7925_FIRMWARE_WM;
546 case 0x7927:
547 return MT7927_FIRMWARE_WM;
548 case 0x7928:
549 return MT7928_FIRMWARE_WM;
550 default:
551 return MT7921_FIRMWARE_WM;
552 }
553 }
554
mt792x_patch_name(struct mt792x_dev * dev)555 static inline char *mt792x_patch_name(struct mt792x_dev *dev)
556 {
557 switch (mt76_chip(&dev->mt76)) {
558 case 0x7902:
559 return MT7902_ROM_PATCH;
560 case 0x7920:
561 return MT7920_ROM_PATCH;
562 case 0x7922:
563 return MT7922_ROM_PATCH;
564 case 0x7925:
565 return MT7925_ROM_PATCH;
566 case 0x7927:
567 return MT7927_ROM_PATCH;
568 case 0x7928:
569 return MT7928_ROM_PATCH;
570 default:
571 return MT7921_ROM_PATCH;
572 }
573 }
574
mt792x_cb_patch_name(struct mt792x_dev * dev)575 static inline char *mt792x_cb_patch_name(struct mt792x_dev *dev)
576 {
577 switch (mt76_chip(&dev->mt76)) {
578 case 0x7928:
579 return MT7928_CB_ROM_PATCH;
580 default:
581 return NULL;
582 }
583 }
584
mt792x_phy_ram_name(struct mt792x_dev * dev)585 static inline char *mt792x_phy_ram_name(struct mt792x_dev *dev)
586 {
587 switch (mt76_chip(&dev->mt76)) {
588 case 0x7928:
589 return MT7928_PHY_RAM;
590 default:
591 return NULL;
592 }
593 }
594
595 int mt792x_load_firmware(struct mt792x_dev *dev);
596
597 /* usb */
598 #define MT_USB_TYPE_VENDOR (USB_TYPE_VENDOR | 0x1f)
599 #define MT_USB_TYPE_UHW_VENDOR (USB_TYPE_VENDOR | 0x1e)
600 int mt792xu_dma_init(struct mt792x_dev *dev, bool resume);
601 int mt792xu_mcu_power_on(struct mt792x_dev *dev);
602 int mt792xu_wfsys_reset(struct mt792x_dev *dev);
603 int mt792xu_init_reset(struct mt792x_dev *dev);
604 void mt792xu_reset_work_init(struct mt792x_dev *dev);
605 void mt792xu_reset_work_cleanup(struct mt792x_dev *dev);
606 int mt792xu_check_bus(struct mt792x_dev *dev);
607 int mt792xu_reset_on_bus_error(struct mt792x_dev *dev);
608 u32 mt792xu_rr(struct mt76_dev *dev, u32 addr);
609 void mt792xu_wr(struct mt76_dev *dev, u32 addr, u32 val);
610 u32 mt792xu_rmw(struct mt76_dev *dev, u32 addr, u32 mask, u32 val);
611 void mt792xu_copy(struct mt76_dev *dev, u32 offset, const void *data, int len);
612 void mt792xu_disconnect(struct usb_interface *usb_intf);
613 void mt792xu_stop(struct ieee80211_hw *hw, bool suspend);
614
615 static inline void
mt792x_skb_add_usb_sdio_hdr(struct mt792x_dev * dev,struct sk_buff * skb,int type)616 mt792x_skb_add_usb_sdio_hdr(struct mt792x_dev *dev, struct sk_buff *skb,
617 int type)
618 {
619 u32 hdr, len;
620
621 len = mt76_is_usb(&dev->mt76) ? skb->len : skb->len + sizeof(hdr);
622 hdr = FIELD_PREP(MT792x_SDIO_HDR_TX_BYTES, len) |
623 FIELD_PREP(MT792x_SDIO_HDR_PKT_TYPE, type);
624
625 put_unaligned_le32(hdr, skb_push(skb, sizeof(hdr)));
626 }
627
628 int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
629 int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev);
630 int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev);
631
632 #ifdef CONFIG_ACPI
633 int mt792x_init_acpi_sar(struct mt792x_dev *dev);
634 int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default);
635 u8 mt792x_acpi_get_flags(struct mt792x_phy *phy);
636 u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2);
637 #else
mt792x_init_acpi_sar(struct mt792x_dev * dev)638 static inline int mt792x_init_acpi_sar(struct mt792x_dev *dev)
639 {
640 return 0;
641 }
642
mt792x_init_acpi_sar_power(struct mt792x_phy * phy,bool set_default)643 static inline int mt792x_init_acpi_sar_power(struct mt792x_phy *phy,
644 bool set_default)
645 {
646 return 0;
647 }
648
mt792x_acpi_get_flags(struct mt792x_phy * phy)649 static inline u8 mt792x_acpi_get_flags(struct mt792x_phy *phy)
650 {
651 return 0;
652 }
653
mt792x_acpi_get_mtcl_conf(struct mt792x_phy * phy,char * alpha2)654 static inline u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2)
655 {
656 return MT792X_ACPI_MTCL_INVALID;
657 }
658 #endif
659
660 #endif /* __MT7925_H */
661