1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2020 MediaTek Inc. */
3 
4 #ifndef __MT76_CONNAC_H
5 #define __MT76_CONNAC_H
6 
7 #include "mt76.h"
8 
9 #define MT76_CONNAC_SCAN_IE_LEN			600
10 #define MT76_CONNAC_MAX_SCHED_SCAN_INTERVAL	10
11 #define MT76_CONNAC_MAX_SCHED_SCAN_SSID		10
12 #define MT76_CONNAC_MAX_SCAN_MATCH		16
13 
14 #define MT76_CONNAC_COREDUMP_TIMEOUT		(HZ / 20)
15 #define MT76_CONNAC_COREDUMP_SZ			(128 * 1024)
16 
17 enum {
18 	CMD_CBW_20MHZ = IEEE80211_STA_RX_BW_20,
19 	CMD_CBW_40MHZ = IEEE80211_STA_RX_BW_40,
20 	CMD_CBW_80MHZ = IEEE80211_STA_RX_BW_80,
21 	CMD_CBW_160MHZ = IEEE80211_STA_RX_BW_160,
22 	CMD_CBW_10MHZ,
23 	CMD_CBW_5MHZ,
24 	CMD_CBW_8080MHZ,
25 
26 	CMD_HE_MCS_BW80 = 0,
27 	CMD_HE_MCS_BW160,
28 	CMD_HE_MCS_BW8080,
29 	CMD_HE_MCS_BW_NUM
30 };
31 
32 enum {
33 	HW_BSSID_0 = 0x0,
34 	HW_BSSID_1,
35 	HW_BSSID_2,
36 	HW_BSSID_3,
37 	HW_BSSID_MAX = HW_BSSID_3,
38 	EXT_BSSID_START = 0x10,
39 	EXT_BSSID_1,
40 	EXT_BSSID_15 = 0x1f,
41 	EXT_BSSID_MAX = EXT_BSSID_15,
42 	REPEATER_BSSID_START = 0x20,
43 	REPEATER_BSSID_MAX = 0x3f,
44 };
45 
46 struct mt76_connac_pm {
47 	bool enable;
48 
49 	spinlock_t txq_lock;
50 	struct {
51 		struct mt76_wcid *wcid;
52 		struct sk_buff *skb;
53 	} tx_q[IEEE80211_NUM_ACS];
54 
55 	struct work_struct wake_work;
56 	struct completion wake_cmpl;
57 
58 	struct delayed_work ps_work;
59 	unsigned long last_activity;
60 	unsigned long idle_timeout;
61 };
62 
63 struct mt76_connac_coredump {
64 	struct sk_buff_head msg_list;
65 	struct delayed_work work;
66 	unsigned long last_activity;
67 };
68 
69 extern const struct wiphy_wowlan_support mt76_connac_wowlan_support;
70 
71 static inline bool is_mt7921(struct mt76_dev *dev)
72 {
73 	return mt76_chip(dev) == 0x7961;
74 }
75 
76 int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm);
77 void mt76_connac_power_save_sched(struct mt76_phy *phy,
78 				  struct mt76_connac_pm *pm);
79 void mt76_connac_free_pending_tx_skbs(struct mt76_connac_pm *pm,
80 				      struct mt76_wcid *wcid);
81 
82 static inline void
83 mt76_connac_mutex_acquire(struct mt76_dev *dev, struct mt76_connac_pm *pm)
84 	__acquires(&dev->mutex)
85 {
86 	mutex_lock(&dev->mutex);
87 	mt76_connac_pm_wake(&dev->phy, pm);
88 }
89 
90 static inline void
91 mt76_connac_mutex_release(struct mt76_dev *dev, struct mt76_connac_pm *pm)
92 	__releases(&dev->mutex)
93 {
94 	mt76_connac_power_save_sched(&dev->phy, pm);
95 	mutex_unlock(&dev->mutex);
96 }
97 
98 void mt76_connac_pm_queue_skb(struct ieee80211_hw *hw,
99 			      struct mt76_connac_pm *pm,
100 			      struct mt76_wcid *wcid,
101 			      struct sk_buff *skb);
102 void mt76_connac_pm_dequeue_skbs(struct mt76_phy *phy,
103 				 struct mt76_connac_pm *pm);
104 
105 #endif /* __MT76_CONNAC_H */
106