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