blob: 9163c759e0eac89f0d086a6554afc39023181a46 [file] [log] [blame]
developera20cdc22024-05-31 18:57:31 +08001From 0bb9fb5e89b2891ab7b9f9216ae5ef73a9210c25 Mon Sep 17 00:00:00 2001
developer1a173672023-12-21 14:49:33 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Wed, 6 Dec 2023 08:53:03 +0800
developera20cdc22024-05-31 18:57:31 +08004Subject: [PATCH 1040/1051] wifi: mt76: mt7915: support scs feature
developer1a173672023-12-21 14:49:33 +08005
6Add support scs feature for connac2 codebase. This commit includes three
7parts.
81. enable scs feature when interface is up.
92. support configure scs feature on/off by debugfs scs_enable.
103. Firmware needs driver to provide the tx_bytes, rx_bytes,
11active_station_number, total throughtput and min rssi of all connected
12stations. In mt76 driver, we run a delayed work to send all must-need
13statistics through mcu command every second.
14
15Please noted that the scs feature is only enable for apsoc is 7986 or
167981 (WED Rx 2.0).
17
18Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
19---
20 mt76.h | 2 +
21 mt76_connac_mcu.h | 1 +
22 mt7915/init.c | 1 +
23 mt7915/mac.c | 11 ++++
24 mt7915/main.c | 13 +++++
25 mt7915/mcu.c | 118 +++++++++++++++++++++++++++++++++++++++++++
26 mt7915/mcu.h | 4 ++
developer753619c2024-02-22 13:42:45 +080027 mt7915/mt7915.h | 14 +++++
developer1a173672023-12-21 14:49:33 +080028 mt7915/mtk_debugfs.c | 24 +++++++++
developer753619c2024-02-22 13:42:45 +080029 9 files changed, 188 insertions(+)
developer1a173672023-12-21 14:49:33 +080030
31diff --git a/mt76.h b/mt76.h
developerdad89a32024-04-29 14:17:17 +080032index cff22f5..7ffba7d 100644
developer1a173672023-12-21 14:49:33 +080033--- a/mt76.h
34+++ b/mt76.h
developer753619c2024-02-22 13:42:45 +080035@@ -311,6 +311,7 @@ struct mt76_sta_stats {
developer1a173672023-12-21 14:49:33 +080036 u64 tx_nss[4]; /* 1, 2, 3, 4 */
37 u64 tx_mcs[16]; /* mcs idx */
38 u64 tx_bytes;
39+ u64 last_tx_bytes;
40 /* WED TX */
41 u32 tx_packets; /* unit: MSDU */
42 u32 tx_retries;
developer753619c2024-02-22 13:42:45 +080043@@ -320,6 +321,7 @@ struct mt76_sta_stats {
developer1a173672023-12-21 14:49:33 +080044 u32 rx_packets;
45 u32 rx_errors;
46 u32 rx_drops;
47+ u64 last_rx_bytes;
48 };
49
50 enum mt76_wcid_flags {
51diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developerdad89a32024-04-29 14:17:17 +080052index 94fcf32..247b520 100644
developer1a173672023-12-21 14:49:33 +080053--- a/mt76_connac_mcu.h
54+++ b/mt76_connac_mcu.h
developerdc9eeae2024-04-08 14:36:46 +080055@@ -1236,6 +1236,7 @@ enum {
developer1a173672023-12-21 14:49:33 +080056 MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d,
57 MCU_EXT_CMD_MWDS_SUPPORT = 0x80,
58 MCU_EXT_CMD_SET_SER_TRIGGER = 0x81,
59+ MCU_EXT_CMD_SCS_FEATURE_CTRL = 0x82,
60 MCU_EXT_CMD_TWT_AGRT_UPDATE = 0x94,
61 MCU_EXT_CMD_FW_DBG_CTRL = 0x95,
62 MCU_EXT_CMD_OFFCH_SCAN_CTRL = 0x9a,
63diff --git a/mt7915/init.c b/mt7915/init.c
developera20cdc22024-05-31 18:57:31 +080064index 0f8a772..2196d5f 100644
developer1a173672023-12-21 14:49:33 +080065--- a/mt7915/init.c
66+++ b/mt7915/init.c
developera20cdc22024-05-31 18:57:31 +080067@@ -1213,6 +1213,7 @@ int mt7915_register_device(struct mt7915_dev *dev)
developer1a173672023-12-21 14:49:33 +080068 spin_lock_init(&dev->phy.stats_lock);
69 INIT_WORK(&dev->rc_work, mt7915_mac_sta_rc_work);
70 INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7915_mac_work);
71+ INIT_DELAYED_WORK(&dev->scs_work, mt7915_mcu_scs_sta_poll);
72 INIT_LIST_HEAD(&dev->sta_rc_list);
73 INIT_LIST_HEAD(&dev->twt_list);
74
75diff --git a/mt7915/mac.c b/mt7915/mac.c
developera20cdc22024-05-31 18:57:31 +080076index c421447..fb98940 100644
developer1a173672023-12-21 14:49:33 +080077--- a/mt7915/mac.c
78+++ b/mt7915/mac.c
developera20cdc22024-05-31 18:57:31 +080079@@ -1463,6 +1463,8 @@ mt7915_mac_full_reset(struct mt7915_dev *dev)
developer1a173672023-12-21 14:49:33 +080080 if (ext_phy)
81 cancel_delayed_work_sync(&ext_phy->mac_work);
82
83+ cancel_delayed_work_sync(&dev->scs_work);
84+
85 mutex_lock(&dev->mt76.mutex);
86 for (i = 0; i < 10; i++) {
87 if (!mt7915_mac_restart(dev))
developera20cdc22024-05-31 18:57:31 +080088@@ -1488,6 +1490,10 @@ mt7915_mac_full_reset(struct mt7915_dev *dev)
developer1a173672023-12-21 14:49:33 +080089 ieee80211_queue_delayed_work(ext_phy->hw,
90 &ext_phy->mac_work,
91 MT7915_WATCHDOG_TIME);
92+
93+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
94+ mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
95+ ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
96 }
97
98 /* system error recovery */
developera20cdc22024-05-31 18:57:31 +080099@@ -1546,6 +1552,7 @@ void mt7915_mac_reset_work(struct work_struct *work)
developer1a173672023-12-21 14:49:33 +0800100 set_bit(MT76_RESET, &phy2->mt76->state);
101 cancel_delayed_work_sync(&phy2->mt76->mac_work);
102 }
103+ cancel_delayed_work_sync(&dev->scs_work);
104 mt76_worker_disable(&dev->mt76.tx_worker);
105 mt76_for_each_q_rx(&dev->mt76, i)
106 napi_disable(&dev->mt76.napi[i]);
developera20cdc22024-05-31 18:57:31 +0800107@@ -1610,6 +1617,10 @@ void mt7915_mac_reset_work(struct work_struct *work)
developer1a173672023-12-21 14:49:33 +0800108 &phy2->mt76->mac_work,
109 MT7915_WATCHDOG_TIME);
110
111+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
112+ mtk_wed_get_rx_capa(&dev->mt76.mmio.wed))
113+ ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
114+
115 dev_info(dev->mt76.dev,"\n%s L1 SER recovery completed.",
116 wiphy_name(dev->mt76.hw->wiphy));
117 }
118diff --git a/mt7915/main.c b/mt7915/main.c
developera20cdc22024-05-31 18:57:31 +0800119index 3db1c0b..da998e1 100644
developer1a173672023-12-21 14:49:33 +0800120--- a/mt7915/main.c
121+++ b/mt7915/main.c
developer753619c2024-02-22 13:42:45 +0800122@@ -89,12 +89,24 @@ int mt7915_run(struct ieee80211_hw *hw)
developer1a173672023-12-21 14:49:33 +0800123 if (ret)
124 goto out;
125
126+ /* Enable SCS if and only if WED Rx (2.0 and after) is supported. */
127+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
128+ mtk_wed_get_rx_capa(&dev->mt76.mmio.wed) &&
129+ !mt76_testmode_enabled(phy->mt76)) {
130+ ret = mt7915_mcu_set_scs_en(phy, true);
131+ if (ret)
132+ goto out;
133+ }
134+
135 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
136
137 if (!mt76_testmode_enabled(phy->mt76))
138 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
139 MT7915_WATCHDOG_TIME);
140
141+ if (!running && phy->scs_ctrl.scs_enable)
142+ ieee80211_queue_delayed_work(hw, &dev->scs_work, HZ);
143+
144 if (!running)
145 mt7915_mac_reset_counters(phy);
146
developer753619c2024-02-22 13:42:45 +0800147@@ -135,6 +147,7 @@ static void mt7915_stop(struct ieee80211_hw *hw)
developer1a173672023-12-21 14:49:33 +0800148 }
149
150 if (!mt7915_dev_running(dev)) {
151+ cancel_delayed_work_sync(&dev->scs_work);
152 mt76_connac_mcu_set_pm(&dev->mt76, dev->phy.mt76->band_idx, 1);
153 mt7915_mcu_set_mac(dev, dev->phy.mt76->band_idx, false, false);
154 }
155diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developera20cdc22024-05-31 18:57:31 +0800156index ef9f0ce..762c035 100644
developer1a173672023-12-21 14:49:33 +0800157--- a/mt7915/mcu.c
158+++ b/mt7915/mcu.c
developerdad89a32024-04-29 14:17:17 +0800159@@ -5239,6 +5239,124 @@ int mt7915_mcu_sw_aci_set(struct mt7915_dev *dev, bool val)
developer1a173672023-12-21 14:49:33 +0800160 sizeof(req), NULL);
161 }
developerdad89a32024-04-29 14:17:17 +0800162
developer1a173672023-12-21 14:49:33 +0800163+int mt7915_mcu_set_scs_en(struct mt7915_phy *phy, u8 enable)
164+{
165+ struct mt7915_dev *dev = phy->dev;
166+ struct {
167+ __le32 subcmd;
168+ u8 band_idx;
169+ u8 enable;
170+ } __packed req = {
171+ .subcmd = cpu_to_le32(SCS_ENABLE),
172+ .band_idx = phy->mt76->band_idx,
173+ .enable = enable + 1,
174+ };
175+
176+ phy->scs_ctrl.scs_enable = !!enable;
177+
178+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SCS_FEATURE_CTRL),
179+ &req, sizeof(req), NULL);
180+}
181+
182+void mt7915_sta_scs_para(void *data, struct ieee80211_sta *sta)
183+{
184+#define SCS_ACTIVE_STA_CRITERIA_2M 250000
185+ struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
186+ struct mt7915_phy *poll_phy = (struct mt7915_phy *)data;
187+ u8 band_idx = msta->wcid.phy_idx;
188+ s64 tx_bytes_last_sec, rx_bytes_last_sec;
189+ u64 total_bytes_last_sec;
190+
191+ if (band_idx > MT_BAND1)
192+ return;
193+
194+ tx_bytes_last_sec = (s64)msta->wcid.stats.tx_bytes -
195+ (s64)msta->wcid.stats.last_tx_bytes;
196+ rx_bytes_last_sec = (s64)msta->wcid.stats.rx_bytes -
197+ (s64)msta->wcid.stats.last_rx_bytes;
198+
199+ /**
200+ * Since wo reports rx stats every 900ms, it needs to be converted as
201+ * statistics every one second.
202+ */
203+ rx_bytes_last_sec = rx_bytes_last_sec / 9 * 10;
204+
205+ poll_phy->scs_ctrl.tx_bytes_last_sec += tx_bytes_last_sec;
206+ poll_phy->scs_ctrl.rx_bytes_last_sec += rx_bytes_last_sec;
207+
208+ total_bytes_last_sec = tx_bytes_last_sec + rx_bytes_last_sec;
209+ if (total_bytes_last_sec > SCS_ACTIVE_STA_CRITERIA_2M) {
210+ poll_phy->scs_ctrl.tput += total_bytes_last_sec >> 17;
211+ poll_phy->scs_ctrl.active_sta++;
212+ }
213+
214+ msta->wcid.stats.last_tx_bytes = msta->wcid.stats.tx_bytes;
215+ msta->wcid.stats.last_rx_bytes = msta->wcid.stats.rx_bytes;
216+
217+ if (poll_phy->scs_ctrl.sta_min_rssi > msta->ack_signal)
218+ poll_phy->scs_ctrl.sta_min_rssi = msta->ack_signal;
219+}
220+
221+int mt7915_mcu_set_scs_stats(struct mt7915_phy *phy)
222+{
223+ struct mt7915_dev *dev = phy->dev;
224+ struct {
225+ __le32 subcmd;
226+ u8 band_idx;
227+ u8 active_sta;
228+ __le16 tput;
229+ bool rx_only_mode;
230+ u8 __rsv;
231+ s8 min_rssi;
232+ } __packed req = {
233+ .subcmd = cpu_to_le32(SCS_SEND_DATA),
234+ .band_idx = phy->mt76->band_idx,
235+ .active_sta = phy->scs_ctrl.active_sta,
236+ .tput = cpu_to_le16(phy->scs_ctrl.tput),
237+ .rx_only_mode = false,
238+ .min_rssi = phy->scs_ctrl.sta_min_rssi,
239+ };
240+
241+ /* Rx only mode is that Rx percentage is larger than 90% */
242+ if (phy->scs_ctrl.tx_bytes_last_sec < phy->scs_ctrl.rx_bytes_last_sec / 9)
243+ req.rx_only_mode = true;
244+
245+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SCS_FEATURE_CTRL),
246+ &req, sizeof(req), NULL);
247+}
248+
249+void mt7915_mcu_scs_sta_poll(struct work_struct *work)
250+{
251+ struct mt7915_dev *dev = container_of(work, struct mt7915_dev,
252+ scs_work.work);
253+ struct mt7915_phy *phy;
254+ bool scs_enable_flag = false;
255+ u8 i;
256+
257+ for (i = MT_BAND0; i < MT_BAND2; i++) {
258+ if (!dev->mt76.phys[i])
259+ continue;
260+
261+ phy = dev->mt76.phys[i]->priv;
262+ if (!phy->scs_ctrl.scs_enable ||
263+ !test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
264+ continue;
265+
266+ ieee80211_iterate_stations_atomic(dev->mt76.phys[i]->hw,
267+ mt7915_sta_scs_para, phy);
268+
269+ mt7915_mcu_set_scs_stats(phy);
270+
271+ memset(&phy->scs_ctrl, 0, sizeof(phy->scs_ctrl));
272+ phy->scs_ctrl.scs_enable = true;
273+
274+ scs_enable_flag = true;
275+ }
276+
277+ if (scs_enable_flag)
278+ ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ);
279+}
developerdad89a32024-04-29 14:17:17 +0800280+
281 int mt7915_mcu_set_qos_map(struct mt7915_dev *dev, struct ieee80211_vif *vif)
282 {
283 #define IP_DSCP_NUM 64
developer1a173672023-12-21 14:49:33 +0800284diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developerdc9eeae2024-04-08 14:36:46 +0800285index 3089fb6..742a785 100644
developer1a173672023-12-21 14:49:33 +0800286--- a/mt7915/mcu.h
287+++ b/mt7915/mcu.h
developer753619c2024-02-22 13:42:45 +0800288@@ -1200,4 +1200,8 @@ struct mt7915_mcu_edcca_info {
developer1a173672023-12-21 14:49:33 +0800289 };
290 #endif
291
292+enum {
293+ SCS_SEND_DATA = 0,
294+ SCS_ENABLE = 3,
295+};
296 #endif
297diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developera20cdc22024-05-31 18:57:31 +0800298index 3170aca..696db7b 100644
developer1a173672023-12-21 14:49:33 +0800299--- a/mt7915/mt7915.h
300+++ b/mt7915/mt7915.h
developera20cdc22024-05-31 18:57:31 +0800301@@ -272,6 +272,15 @@ struct mt7915_air_monitor_ctrl {
developer1a173672023-12-21 14:49:33 +0800302 };
303 #endif
304
305+struct mt7915_scs_ctrl {
306+ u64 tx_bytes_last_sec;
307+ u64 rx_bytes_last_sec;
308+ bool scs_enable;
309+ s8 sta_min_rssi;
310+ u16 tput;
311+ u8 active_sta;
312+};
313+
314 struct mt7915_phy {
315 struct mt76_phy *mt76;
316 struct mt7915_dev *dev;
developera20cdc22024-05-31 18:57:31 +0800317@@ -346,6 +355,7 @@ struct mt7915_phy {
developer1a173672023-12-21 14:49:33 +0800318
319 struct mt7915_air_monitor_ctrl amnt_ctrl;
320 #endif
321+ struct mt7915_scs_ctrl scs_ctrl;
322 };
323
developera46f6132024-03-26 14:09:54 +0800324 #ifdef MTK_DEBUG
developera20cdc22024-05-31 18:57:31 +0800325@@ -478,6 +488,8 @@ struct mt7915_dev {
developera46f6132024-03-26 14:09:54 +0800326 } adie[ADIE_MAX_CNT];
developer1a173672023-12-21 14:49:33 +0800327 #endif
developer753619c2024-02-22 13:42:45 +0800328
developer1a173672023-12-21 14:49:33 +0800329+ struct delayed_work scs_work;
developer753619c2024-02-22 13:42:45 +0800330+
331 bool wmm_pbc_enable;
332 struct work_struct wmm_pbc_work;
developera46f6132024-03-26 14:09:54 +0800333 u32 adie_type;
developera20cdc22024-05-31 18:57:31 +0800334@@ -805,6 +817,8 @@ int mt7915_mcu_sw_aci_set(struct mt7915_dev *dev, bool val);
developer1a173672023-12-21 14:49:33 +0800335 int mt7915_mcu_ipi_hist_ctrl(struct mt7915_phy *phy, void *data, u8 cmd, bool wait_resp);
336 int mt7915_mcu_ipi_hist_scan(struct mt7915_phy *phy, void *data, u8 mode, bool wait_resp);
337 int mt7915_mcu_enable_obss_spr(struct mt7915_phy *phy, u8 action, u8 val);
338+int mt7915_mcu_set_scs_en(struct mt7915_phy *phy, u8 enable);
339+void mt7915_mcu_scs_sta_poll(struct work_struct *work);
340
341 #ifdef MTK_DEBUG
342 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir);
343diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developerdad89a32024-04-29 14:17:17 +0800344index dad5ed7..0953223 100644
developer1a173672023-12-21 14:49:33 +0800345--- a/mt7915/mtk_debugfs.c
346+++ b/mt7915/mtk_debugfs.c
developera46f6132024-03-26 14:09:54 +0800347@@ -3820,6 +3820,29 @@ mt7915_sr_enable_set(void *data, u64 val)
developer1a173672023-12-21 14:49:33 +0800348 DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enable, NULL,
349 mt7915_sr_enable_set, "%llx\n");
350
351+static int
352+mt7915_scs_enable_set(void *data, u64 val)
353+{
354+ struct mt7915_phy *phy = data;
355+ int ret;
356+
357+ /* Enable scs if and only if WED Rx (2.0 and after) is supported */
358+ if (!mtk_wed_device_active(&phy->dev->mt76.mmio.wed) ||
359+ !mtk_wed_get_rx_capa(&phy->dev->mt76.mmio.wed))
360+ return 0;
361+
362+ ret = mt7915_mcu_set_scs_en(phy, (u8) val);
363+ if (ret)
364+ return ret;
365+
366+ if (phy->scs_ctrl.scs_enable)
367+ ieee80211_queue_delayed_work(phy->mt76->hw, &phy->dev->scs_work, HZ);
368+
369+ return 0;
370+}
371+DEFINE_DEBUGFS_ATTRIBUTE(fops_scs_enable, NULL,
372+ mt7915_scs_enable_set, "%lld\n");
373+
374 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
375 {
376 struct mt7915_dev *dev = phy->dev;
developera46f6132024-03-26 14:09:54 +0800377@@ -3912,6 +3935,7 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
developer1a173672023-12-21 14:49:33 +0800378 debugfs_create_file("sw_aci", 0600, dir, dev,
379 &fops_sw_aci);
380 debugfs_create_file("sr_enable", 0200, dir, phy, &fops_sr_enable);
381+ debugfs_create_file("scs_enable", 0200, dir, phy, &fops_scs_enable);
382 return 0;
383 }
384 #endif
385--
3862.18.0
387