blob: 145e8458c6b9c66dd50c928fdcb37695404719ec [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From b884ffbff5630ccb06b2b9212b47b8c5cf56bb47 Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Mon, 8 May 2023 09:03:50 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 030/199] mtk: mt76: mt7996: enable SCS feature for mt7996
5 driver
developer66e89bc2024-04-23 14:50:01 +08006
7Enable Smart Carrier Sense algorithn by default to improve performance
8in a noisy environment.
9
10Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
11---
12 mt76_connac_mcu.h | 1 +
13 mt7996/init.c | 1 +
14 mt7996/mac.c | 2 +
15 mt7996/main.c | 7 +++
16 mt7996/mcu.c | 105 +++++++++++++++++++++++++++++++++++++++++++
17 mt7996/mcu.h | 6 +++
18 mt7996/mt7996.h | 15 +++++++
19 mt7996/mtk_debugfs.c | 11 +++++
20 8 files changed, 148 insertions(+)
21
22diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer05f3b2b2024-08-19 19:17:34 +080023index 0d30aff3..ea60e19c 100644
developer66e89bc2024-04-23 14:50:01 +080024--- a/mt76_connac_mcu.h
25+++ b/mt76_connac_mcu.h
developer05f3b2b2024-08-19 19:17:34 +080026@@ -1274,6 +1274,7 @@ enum {
developer66e89bc2024-04-23 14:50:01 +080027 MCU_UNI_CMD_GET_STAT_INFO = 0x23,
28 MCU_UNI_CMD_SNIFFER = 0x24,
29 MCU_UNI_CMD_SR = 0x25,
30+ MCU_UNI_CMD_SCS = 0x26,
31 MCU_UNI_CMD_ROC = 0x27,
32 MCU_UNI_CMD_SET_DBDC_PARMS = 0x28,
33 MCU_UNI_CMD_TXPOWER = 0x2b,
34diff --git a/mt7996/init.c b/mt7996/init.c
developer05f3b2b2024-08-19 19:17:34 +080035index 2749a5d7..7e813960 100644
developer66e89bc2024-04-23 14:50:01 +080036--- a/mt7996/init.c
37+++ b/mt7996/init.c
developer05f3b2b2024-08-19 19:17:34 +080038@@ -1416,6 +1416,7 @@ int mt7996_register_device(struct mt7996_dev *dev)
developer66e89bc2024-04-23 14:50:01 +080039 dev->mt76.phy.priv = &dev->phy;
40 INIT_WORK(&dev->rc_work, mt7996_mac_sta_rc_work);
41 INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7996_mac_work);
42+ INIT_DELAYED_WORK(&dev->scs_work, mt7996_mcu_scs_sta_poll);
43 INIT_LIST_HEAD(&dev->sta_rc_list);
44 INIT_LIST_HEAD(&dev->twt_list);
45
46diff --git a/mt7996/mac.c b/mt7996/mac.c
developer05f3b2b2024-08-19 19:17:34 +080047index a0fcd8aa..fd8bce0e 100644
developer66e89bc2024-04-23 14:50:01 +080048--- a/mt7996/mac.c
49+++ b/mt7996/mac.c
developer05f3b2b2024-08-19 19:17:34 +080050@@ -1804,6 +1804,7 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
developer66e89bc2024-04-23 14:50:01 +080051 cancel_delayed_work_sync(&phy2->mt76->mac_work);
52 if (phy3)
53 cancel_delayed_work_sync(&phy3->mt76->mac_work);
54+ cancel_delayed_work_sync(&dev->scs_work);
55
56 mutex_lock(&dev->mt76.mutex);
57 for (i = 0; i < 10; i++) {
developer05f3b2b2024-08-19 19:17:34 +080058@@ -1839,6 +1840,7 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
developer66e89bc2024-04-23 14:50:01 +080059 ieee80211_queue_delayed_work(phy3->mt76->hw,
60 &phy3->mt76->mac_work,
61 MT7996_WATCHDOG_TIME);
62+ ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
63 }
64
65 void mt7996_mac_reset_work(struct work_struct *work)
66diff --git a/mt7996/main.c b/mt7996/main.c
developer05f3b2b2024-08-19 19:17:34 +080067index 253bb2e3..22acd04e 100644
developer66e89bc2024-04-23 14:50:01 +080068--- a/mt7996/main.c
69+++ b/mt7996/main.c
70@@ -81,11 +81,17 @@ int mt7996_run(struct ieee80211_hw *hw)
71 if (ret)
72 goto out;
73
74+ ret = mt7996_mcu_set_scs(phy, SCS_ENABLE);
75+ if (ret)
76+ goto out;
77+
78 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
79
80 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
81 MT7996_WATCHDOG_TIME);
82
83+ ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
84+
85 if (!running)
86 mt7996_mac_reset_counters(phy);
87
88@@ -113,6 +119,7 @@ static void mt7996_stop(struct ieee80211_hw *hw)
89 struct mt7996_phy *phy = mt7996_hw_phy(hw);
90
91 cancel_delayed_work_sync(&phy->mt76->mac_work);
92+ cancel_delayed_work_sync(&dev->scs_work);
93
94 mutex_lock(&dev->mt76.mutex);
95
96diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developer05f3b2b2024-08-19 19:17:34 +080097index 7c5e94f8..8f725307 100644
developer66e89bc2024-04-23 14:50:01 +080098--- a/mt7996/mcu.c
99+++ b/mt7996/mcu.c
developer05f3b2b2024-08-19 19:17:34 +0800100@@ -4816,3 +4816,108 @@ int mt7996_mcu_set_tx_power_ctrl(struct mt7996_phy *phy, u8 power_ctrl_id, u8 da
developer66e89bc2024-04-23 14:50:01 +0800101 return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(TXPOWER),
102 &req, sizeof(req), false);
103 }
104+
105+int mt7996_mcu_set_scs_stats(struct mt7996_phy *phy)
106+{
107+ struct mt7996_scs_ctrl ctrl = phy->scs_ctrl;
108+ struct {
109+ u8 band_idx;
110+ u8 _rsv[3];
111+
112+ __le16 tag;
113+ __le16 len;
114+
115+ u8 _rsv2[6];
116+ s8 min_rssi;
117+ u8 _rsv3;
118+ } __packed req = {
119+ .band_idx = phy->mt76->band_idx,
120+ .tag = cpu_to_le16(UNI_CMD_SCS_SEND_DATA),
121+ .len = cpu_to_le16(sizeof(req) - 4),
122+
123+ .min_rssi = ctrl.sta_min_rssi,
124+ };
125+
126+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(SCS),
127+ &req, sizeof(req), false);
128+}
129+
130+void mt7996_sta_rssi_work(void *data, struct ieee80211_sta *sta)
131+{
132+ struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
133+ struct mt7996_phy *poll_phy = (struct mt7996_phy *) data;
134+
135+ if (poll_phy->scs_ctrl.sta_min_rssi > msta->ack_signal)
136+ poll_phy->scs_ctrl.sta_min_rssi = msta->ack_signal;
137+}
138+
139+void mt7996_mcu_scs_sta_poll(struct work_struct *work)
140+{
141+ struct mt7996_dev *dev = container_of(work, struct mt7996_dev,
142+ scs_work.work);
143+ bool scs_enable_flag = false;
144+ u8 i;
145+
146+ for (i = 0; i < __MT_MAX_BAND; i++) {
147+ struct mt7996_phy *phy;
148+
149+ switch (i) {
150+ case MT_BAND0:
151+ phy = dev->mphy.priv;
152+ break;
153+ case MT_BAND1:
154+ phy = mt7996_phy2(dev);
155+ break;
156+ case MT_BAND2:
157+ phy = mt7996_phy3(dev);
158+ break;
159+ default:
160+ phy = NULL;
161+ break;
162+ }
163+
164+ if (!phy || !test_bit(MT76_STATE_RUNNING, &phy->mt76->state) ||
165+ !phy->scs_ctrl.scs_enable)
166+ continue;
167+
168+ ieee80211_iterate_stations_atomic(phy->mt76->hw,
169+ mt7996_sta_rssi_work, phy);
170+
171+ scs_enable_flag = true;
172+ if (mt7996_mcu_set_scs_stats(phy))
173+ dev_err(dev->mt76.dev, "Failed to send scs mcu cmd\n");
174+ phy->scs_ctrl.sta_min_rssi = 0;
175+ }
176+
177+ if (scs_enable_flag)
178+ ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
179+}
180+
181+
182+int mt7996_mcu_set_scs(struct mt7996_phy *phy, u8 enable)
183+{
184+ struct mt7996_dev *dev = phy->dev;
185+ struct {
186+ u8 band_idx;
187+ u8 _rsv[3];
188+
189+ __le16 tag;
190+ __le16 len;
191+
192+ u8 scs_enable;
193+ u8 _rsv2[3];
194+ } __packed req = {
195+ .band_idx = phy->mt76->band_idx,
196+ .tag = cpu_to_le16(UNI_CMD_SCS_ENABLE),
197+ .len = cpu_to_le16(sizeof(req) - 4),
198+ .scs_enable = enable,
199+ };
200+
201+ phy->scs_ctrl.scs_enable = enable;
202+
203+ if (enable == SCS_ENABLE)
204+ ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
205+
206+ return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(SCS),
207+ &req, sizeof(req), false);
208+}
209diff --git a/mt7996/mcu.h b/mt7996/mcu.h
developer05f3b2b2024-08-19 19:17:34 +0800210index abf8ef48..f889cb8b 100644
developer66e89bc2024-04-23 14:50:01 +0800211--- a/mt7996/mcu.h
212+++ b/mt7996/mcu.h
213@@ -966,6 +966,12 @@ enum pp_mode {
214 PP_USR_MODE,
215 };
216
217+enum {
218+ UNI_CMD_SCS_SEND_DATA,
219+ UNI_CMD_SCS_SET_PD_THR_RANGE = 2,
220+ UNI_CMD_SCS_ENABLE,
221+};
222+
223 #define MT7996_PATCH_SEC GENMASK(31, 24)
224 #define MT7996_PATCH_SCRAMBLE_KEY GENMASK(15, 8)
225 #define MT7996_PATCH_AES_KEY GENMASK(7, 0)
226diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developer05f3b2b2024-08-19 19:17:34 +0800227index 1744998d..d5050d6d 100644
developer66e89bc2024-04-23 14:50:01 +0800228--- a/mt7996/mt7996.h
229+++ b/mt7996/mt7996.h
developer05f3b2b2024-08-19 19:17:34 +0800230@@ -233,6 +233,16 @@ struct mt7996_hif {
developer66e89bc2024-04-23 14:50:01 +0800231 int irq;
232 };
233
234+struct mt7996_scs_ctrl {
235+ u8 scs_enable;
236+ s8 sta_min_rssi;
237+};
238+
239+enum {
240+ SCS_DISABLE = 0,
241+ SCS_ENABLE,
242+};
243+
244 struct mt7996_wed_rro_addr {
245 u32 head_low;
246 u32 head_high : 4;
developer05f3b2b2024-08-19 19:17:34 +0800247@@ -283,6 +293,8 @@ struct mt7996_phy {
developer66e89bc2024-04-23 14:50:01 +0800248 u8 pp_mode;
249 u16 punct_bitmap;
250
251+ struct mt7996_scs_ctrl scs_ctrl;
252+
253 #ifdef CONFIG_NL80211_TESTMODE
254 struct {
255 u32 *reg_backup;
developer05f3b2b2024-08-19 19:17:34 +0800256@@ -329,6 +341,7 @@ struct mt7996_dev {
developer66e89bc2024-04-23 14:50:01 +0800257 struct work_struct rc_work;
258 struct work_struct dump_work;
259 struct work_struct reset_work;
260+ struct delayed_work scs_work;
261 wait_queue_head_t reset_wait;
262 struct {
263 u32 state;
developer05f3b2b2024-08-19 19:17:34 +0800264@@ -603,6 +616,8 @@ int mt7996_mcu_apply_tx_dpd(struct mt7996_phy *phy);
developer66e89bc2024-04-23 14:50:01 +0800265 #ifdef CONFIG_NL80211_TESTMODE
266 void mt7996_tm_rf_test_event(struct mt7996_dev *dev, struct sk_buff *skb);
267 #endif
268+int mt7996_mcu_set_scs(struct mt7996_phy *phy, u8 enable);
269+void mt7996_mcu_scs_sta_poll(struct work_struct *work);
270
271 static inline u8 mt7996_max_interface_num(struct mt7996_dev *dev)
272 {
273diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
developer05f3b2b2024-08-19 19:17:34 +0800274index 64952a73..8c576bac 100644
developer66e89bc2024-04-23 14:50:01 +0800275--- a/mt7996/mtk_debugfs.c
276+++ b/mt7996/mtk_debugfs.c
developer05f3b2b2024-08-19 19:17:34 +0800277@@ -2429,6 +2429,16 @@ static int mt7996_token_read(struct seq_file *s, void *data)
developer66e89bc2024-04-23 14:50:01 +0800278 return 0;
279 }
280
281+static int
282+mt7996_scs_enable_set(void *data, u64 val)
283+{
284+ struct mt7996_phy *phy = data;
285+
286+ return mt7996_mcu_set_scs(phy, (u8) val);
287+}
288+DEFINE_DEBUGFS_ATTRIBUTE(fops_scs_enable, NULL,
289+ mt7996_scs_enable_set, "%lld\n");
290+
291 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
292 {
293 struct mt7996_dev *dev = phy->dev;
developer05f3b2b2024-08-19 19:17:34 +0800294@@ -2499,6 +2509,7 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
developer66e89bc2024-04-23 14:50:01 +0800295 debugfs_create_devm_seqfile(dev->mt76.dev, "token", dir, mt7996_token_read);
296
297 debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable);
298+ debugfs_create_file("scs_enable", 0200, dir, phy, &fops_scs_enable);
299
300 return 0;
301 }
302--
developer9237f442024-06-14 17:13:04 +08003032.18.0
developer66e89bc2024-04-23 14:50:01 +0800304