blob: 90ff7e857f817ff6e0ffcf5edc958ca66f391c59 [file] [log] [blame]
developerd243af02023-12-21 14:49:33 +08001From d96436bbd8f0aa903bb0ee905a2654f81ebbfbff Mon Sep 17 00:00:00 2001
developer281084d2023-06-19 12:03:50 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Mon, 8 May 2023 09:03:50 +0800
developerd243af02023-12-21 14:49:33 +08004Subject: [PATCH 1006/1041] mtk: wifi: mt76: mt7996: enable SCS feature for
5 mt7996 driver
developer281084d2023-06-19 12:03:50 +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---
developerd243af02023-12-21 14:49:33 +080012 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(+)
developer281084d2023-06-19 12:03:50 +080021
22diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developerd243af02023-12-21 14:49:33 +080023index 3447f523..5e1b15c4 100644
developer281084d2023-06-19 12:03:50 +080024--- a/mt76_connac_mcu.h
25+++ b/mt76_connac_mcu.h
developerd243af02023-12-21 14:49:33 +080026@@ -1250,6 +1250,7 @@ enum {
developere35b8e42023-10-16 11:04:00 +080027 MCU_UNI_CMD_GET_STAT_INFO = 0x23,
developer281084d2023-06-19 12:03:50 +080028 MCU_UNI_CMD_SNIFFER = 0x24,
29 MCU_UNI_CMD_SR = 0x25,
30+ MCU_UNI_CMD_SCS = 0x26,
31 MCU_UNI_CMD_ROC = 0x27,
developere35b8e42023-10-16 11:04:00 +080032 MCU_UNI_CMD_SET_DBDC_PARMS = 0x28,
developer281084d2023-06-19 12:03:50 +080033 MCU_UNI_CMD_TXPOWER = 0x2b,
developer281084d2023-06-19 12:03:50 +080034diff --git a/mt7996/init.c b/mt7996/init.c
developerd243af02023-12-21 14:49:33 +080035index 7bfebd38..c9c7c20a 100644
developer281084d2023-06-19 12:03:50 +080036--- a/mt7996/init.c
37+++ b/mt7996/init.c
developerd243af02023-12-21 14:49:33 +080038@@ -1378,6 +1378,7 @@ int mt7996_register_device(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +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);
developer281084d2023-06-19 12:03:50 +080044 INIT_LIST_HEAD(&dev->twt_list);
developere35b8e42023-10-16 11:04:00 +080045
developerd243af02023-12-21 14:49:33 +080046diff --git a/mt7996/mac.c b/mt7996/mac.c
47index 924b05e4..e307ddc3 100644
48--- a/mt7996/mac.c
49+++ b/mt7996/mac.c
50@@ -1798,6 +1798,7 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
51 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++) {
58@@ -1833,6 +1834,7 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
59 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)
developer281084d2023-06-19 12:03:50 +080066diff --git a/mt7996/main.c b/mt7996/main.c
developerd243af02023-12-21 14:49:33 +080067index 2a93e8c2..97f1ef8c 100644
developer281084d2023-06-19 12:03:50 +080068--- a/mt7996/main.c
69+++ b/mt7996/main.c
70@@ -73,11 +73,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@@ -105,6 +111,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
developerd243af02023-12-21 14:49:33 +080097index eb346a9c..cc417039 100644
developer281084d2023-06-19 12:03:50 +080098--- a/mt7996/mcu.c
99+++ b/mt7996/mcu.c
developerd243af02023-12-21 14:49:33 +0800100@@ -4609,3 +4609,108 @@ int mt7996_mcu_set_tx_power_ctrl(struct mt7996_phy *phy, u8 power_ctrl_id, u8 da
developer281084d2023-06-19 12:03:50 +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;
developerd243af02023-12-21 14:49:33 +0800133+ struct mt7996_phy *poll_phy = (struct mt7996_phy *) data;
developer281084d2023-06-19 12:03:50 +0800134+
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+
developer281084d2023-06-19 12:03:50 +0800146+ 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+
developerd243af02023-12-21 14:49:33 +0800164+ 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;
developer281084d2023-06-19 12:03:50 +0800175+ }
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
developerd243af02023-12-21 14:49:33 +0800210index 325c3c97..4f4994d8 100644
developer281084d2023-06-19 12:03:50 +0800211--- a/mt7996/mcu.h
212+++ b/mt7996/mcu.h
developerd243af02023-12-21 14:49:33 +0800213@@ -960,6 +960,12 @@ enum {
developere35b8e42023-10-16 11:04:00 +0800214 UNI_CMD_PP_EN_CTRL,
developer281084d2023-06-19 12:03:50 +0800215 };
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
developerd243af02023-12-21 14:49:33 +0800227index e7609c63..384157c8 100644
developer281084d2023-06-19 12:03:50 +0800228--- a/mt7996/mt7996.h
229+++ b/mt7996/mt7996.h
developerd243af02023-12-21 14:49:33 +0800230@@ -233,6 +233,16 @@ struct mt7996_hif {
developer281084d2023-06-19 12:03:50 +0800231 int irq;
232 };
233
developer281084d2023-06-19 12:03:50 +0800234+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+
developere35b8e42023-10-16 11:04:00 +0800244 struct mt7996_wed_rro_addr {
245 u32 head_low;
246 u32 head_high : 4;
developerd243af02023-12-21 14:49:33 +0800247@@ -280,6 +290,8 @@ struct mt7996_phy {
developer281084d2023-06-19 12:03:50 +0800248
249 bool has_aux_rx;
250
251+ struct mt7996_scs_ctrl scs_ctrl;
252+
253 #ifdef CONFIG_NL80211_TESTMODE
254 struct {
255 u32 *reg_backup;
developerd243af02023-12-21 14:49:33 +0800256@@ -326,6 +338,7 @@ struct mt7996_dev {
developer281084d2023-06-19 12:03:50 +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;
developerd243af02023-12-21 14:49:33 +0800264@@ -596,6 +609,8 @@ int mt7996_mcu_set_tx_power_ctrl(struct mt7996_phy *phy, u8 power_ctrl_id, u8 da
265 #ifdef CONFIG_NL80211_TESTMODE
266 void mt7996_tm_rf_test_event(struct mt7996_dev *dev, struct sk_buff *skb);
267 #endif
developer281084d2023-06-19 12:03:50 +0800268+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 {
developerd243af02023-12-21 14:49:33 +0800273diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
274index 53b11d54..ccb147e9 100644
275--- a/mt7996/mtk_debugfs.c
276+++ b/mt7996/mtk_debugfs.c
277@@ -2407,6 +2407,16 @@ static int mt7996_token_read(struct seq_file *s, void *data)
278 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;
294@@ -2477,6 +2487,7 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
295 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 }
developer281084d2023-06-19 12:03:50 +0800302--
developer36fe7092023-09-27 12:24:47 +08003032.18.0
developer281084d2023-06-19 12:03:50 +0800304