blob: 654c31dc3c559e440065dcb140adc47574c02373 [file] [log] [blame]
developerf9b00212023-07-31 12:27:06 +08001From 822360269ad225fe0c1c1e39c50d572159edeb28 Mon Sep 17 00:00:00 2001
developer18dec8f2022-10-25 12:20:54 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Thu, 22 Sep 2022 14:27:41 +0800
developerf9b00212023-07-31 12:27:06 +08004Subject: [PATCH 09/19] cfg80211: mtk: implement DFS status show, cac and nop
5 skip command via debugfs
developer18dec8f2022-10-25 12:20:54 +08006
7Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
9 include/net/cfg80211.h | 1 +
10 net/mac80211/cfg.c | 19 +++
11 net/wireless/core.h | 3 +
developer8b64f1a2023-05-02 10:31:58 +080012 net/wireless/debugfs.c | 310 +++++++++++++++++++++++++++++++++++++++-
developer18dec8f2022-10-25 12:20:54 +080013 net/wireless/mlme.c | 6 +
developer8b64f1a2023-05-02 10:31:58 +080014 net/wireless/rdev-ops.h | 14 ++
developer18dec8f2022-10-25 12:20:54 +080015 net/wireless/trace.h | 12 ++
developer8b64f1a2023-05-02 10:31:58 +080016 7 files changed, 358 insertions(+), 7 deletions(-)
developer18dec8f2022-10-25 12:20:54 +080017
18diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
developerf9b00212023-07-31 12:27:06 +080019index 1170703..77276db 100644
developer18dec8f2022-10-25 12:20:54 +080020--- a/include/net/cfg80211.h
21+++ b/include/net/cfg80211.h
developerf9b00212023-07-31 12:27:06 +080022@@ -4402,6 +4402,7 @@ struct cfg80211_ops {
developer18dec8f2022-10-25 12:20:54 +080023 struct cfg80211_color_change_settings *params);
24 int (*set_radar_background)(struct wiphy *wiphy,
25 struct cfg80211_chan_def *chandef);
26+ void (*skip_cac)(struct wireless_dev *wdev);
27 };
28
29 /*
30diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
developerf9b00212023-07-31 12:27:06 +080031index e008a1e..2a173dd 100644
developer18dec8f2022-10-25 12:20:54 +080032--- a/net/mac80211/cfg.c
33+++ b/net/mac80211/cfg.c
developerc5ce7502022-12-19 11:33:22 +080034@@ -4501,6 +4501,24 @@ ieee80211_set_radar_background(struct wiphy *wiphy,
developer18dec8f2022-10-25 12:20:54 +080035 return local->ops->set_radar_background(&local->hw, chandef);
36 }
37
38+static void
39+ieee80211_skip_cac(struct wireless_dev *wdev)
40+{
41+ struct net_device *dev = wdev->netdev;
42+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
43+ unsigned int cac_time_ms;
44+
45+ cancel_delayed_work(&sdata->dfs_cac_timer_work);
46+ if (wdev->cac_started) {
47+ ieee80211_vif_release_channel(sdata);
48+ cac_time_ms = wdev->cac_time_ms;
49+ wdev->cac_start_time = jiffies -
50+ msecs_to_jiffies(cac_time_ms + 1);
51+ cfg80211_cac_event(wdev->netdev, &wdev->chandef,
52+ NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
53+ }
54+}
55+
56 const struct cfg80211_ops mac80211_config_ops = {
57 .add_virtual_intf = ieee80211_add_iface,
58 .del_virtual_intf = ieee80211_del_iface,
developerc5ce7502022-12-19 11:33:22 +080059@@ -4607,4 +4625,5 @@ const struct cfg80211_ops mac80211_config_ops = {
developer18dec8f2022-10-25 12:20:54 +080060 .set_sar_specs = ieee80211_set_sar_specs,
61 .color_change = ieee80211_color_change,
62 .set_radar_background = ieee80211_set_radar_background,
63+ .skip_cac = ieee80211_skip_cac,
64 };
65diff --git a/net/wireless/core.h b/net/wireless/core.h
66index b588e5a..10e8981 100644
67--- a/net/wireless/core.h
68+++ b/net/wireless/core.h
69@@ -86,6 +86,9 @@ struct cfg80211_registered_device {
70
71 struct wireless_dev *background_radar_wdev;
72 struct cfg80211_chan_def background_radar_chandef;
73+ bool background_cac_started;
74+ unsigned long background_cac_start_time;
75+ unsigned int background_cac_time_ms;
76 struct delayed_work background_cac_done_wk;
77 struct work_struct background_cac_abort_wk;
78
79diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c
developer8b64f1a2023-05-02 10:31:58 +080080index 0878b16..0637ed4 100644
developer18dec8f2022-10-25 12:20:54 +080081--- a/net/wireless/debugfs.c
82+++ b/net/wireless/debugfs.c
83@@ -9,6 +9,7 @@
84 #include <linux/slab.h>
85 #include "core.h"
86 #include "debugfs.h"
87+#include "rdev-ops.h"
88
89 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
90 static ssize_t name## _read(struct file *file, char __user *userbuf, \
developer8b64f1a2023-05-02 10:31:58 +080091@@ -96,16 +97,311 @@ static const struct file_operations ht40allow_map_ops = {
developer18dec8f2022-10-25 12:20:54 +080092 .llseek = default_llseek,
93 };
94
95-#define DEBUGFS_ADD(name) \
96- debugfs_create_file(#name, 0444, phyd, &rdev->wiphy, &name## _ops)
97+static int dfs_print_chan(struct ieee80211_channel *chan, int remain_time, int wait_time,
98+ char *buf, int buf_size, int offset, bool is_background)
99+{
100+ if (WARN_ON(offset > buf_size))
101+ return 0;
102+
103+ if (chan->dfs_state == NL80211_DFS_UNAVAILABLE) {
104+ offset += scnprintf(buf + offset, buf_size - offset,
105+ " Channel = %d, DFS_state = Unavailable",
106+ chan->hw_value);
107+ if (remain_time > 0)
108+ offset += scnprintf(buf + offset, buf_size - offset,
109+ ", Non-occupancy Remain Time = %d / %d [sec]",
110+ remain_time, wait_time);
111+ else
112+ offset += scnprintf(buf + offset, buf_size - offset,
113+ ", Changing state...");
114+ } else if (chan->dfs_state == NL80211_DFS_USABLE) {
115+ offset += scnprintf(buf + offset, buf_size - offset,
116+ " Channel = %d, DFS_state = Usable",
117+ chan->hw_value);
118+ if (remain_time > 0)
119+ offset += scnprintf(buf + offset, buf_size - offset,
120+ ", CAC Remain Time = %d / %d [sec]",
121+ remain_time, wait_time);
122+ } else if (chan->dfs_state == NL80211_DFS_AVAILABLE) {
123+ offset += scnprintf(buf + offset, buf_size - offset,
124+ " Channel = %d, DFS_state = Available",
125+ chan->hw_value);
126+ } else {
127+ offset += scnprintf(buf + offset, buf_size - offset,
128+ " Channel = %d, DFS_state = Unknown",
129+ chan->hw_value);
130+ }
131+
132+ if (is_background)
133+ offset += scnprintf(buf + offset, buf_size - offset,
134+ " (background chain)");
135+ offset += scnprintf(buf + offset, buf_size - offset, "\n");
136+
137+ return offset;
138+}
139+
140+static int dfs_status_read_wdev(struct wiphy *wiphy, struct wireless_dev *wdev, char *buf,
141+ unsigned int buf_size, unsigned int offset)
142+{
143+ struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
144+ struct cfg80211_chan_def *chandef = &wdev->chandef;
145+ struct cfg80211_chan_def *background_chandef = &rdev->background_radar_chandef;
146+ enum nl80211_band band;
147+ struct ieee80211_supported_band *sband;
148+ struct ieee80211_channel *chan;
149+ unsigned long jiffies_passed;
150+ int i, remain_time = 0, wait_time_ms = 0;
151+ bool is_background;
152+
153+ offset += scnprintf(buf + offset, buf_size - offset, "DFS Channel:\n");
154+
155+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
156+ sband = wiphy->bands[band];
157+ if (!sband)
158+ continue;
159+ for (i = 0; i < sband->n_channels; i++) {
160+ is_background = false;
161+ chan = &sband->channels[i];
162+
163+ if (!(chan->flags & IEEE80211_CHAN_RADAR))
164+ continue;
165+
166+ if (chan->dfs_state == NL80211_DFS_UNAVAILABLE) {
167+ jiffies_passed = jiffies - chan->dfs_state_entered;
168+ wait_time_ms = IEEE80211_DFS_MIN_NOP_TIME_MS;
169+ remain_time = (wait_time_ms - jiffies_to_msecs(jiffies_passed));
170+ if (remain_time > wait_time_ms)
171+ remain_time = 0;
172+ } else if (chan->dfs_state == NL80211_DFS_USABLE) {
173+ if (wdev->cac_started && cfg80211_is_sub_chan(chandef, chan)) {
174+ jiffies_passed = jiffies - wdev->cac_start_time;
175+ wait_time_ms = wdev->cac_time_ms;
176+ remain_time = (wait_time_ms -
177+ jiffies_to_msecs(jiffies_passed));
178+ }
179+
180+ if (rdev->background_radar_wdev == wdev &&
181+ rdev->background_cac_started &&
182+ cfg80211_is_sub_chan(background_chandef, chan)) {
183+ jiffies_passed = jiffies - rdev->background_cac_start_time;
184+ wait_time_ms = rdev->background_cac_time_ms;
185+ remain_time = (wait_time_ms -
186+ jiffies_to_msecs(jiffies_passed));
187+ is_background = true;
188+ }
189+
190+ if (remain_time > wait_time_ms)
191+ remain_time = 0;
192+
193+ } else {
194+ if (rdev->background_radar_wdev == wdev &&
195+ cfg80211_is_sub_chan(background_chandef, chan))
196+ is_background = true;
197+ }
198+
199+ offset = dfs_print_chan(chan, remain_time / 1000, wait_time_ms / 1000,
200+ buf, buf_size, offset, is_background);
201+ remain_time = 0;
202+ }
203+ }
204+
205+ return offset;
206+}
207+
208+static ssize_t dfs_status_read(struct file *file, char __user *user_buf,
209+ size_t count, loff_t *ppos)
210+{
211+ struct wiphy *wiphy = file->private_data;
212+ struct wireless_dev *wdev;
213+ char *buf;
214+ unsigned int offset = 0, buf_size = PAGE_SIZE, r;
215+ const char * const iftype_str[] = {
216+ [NL80211_IFTYPE_UNSPECIFIED] = "unspecified",
217+ [NL80211_IFTYPE_ADHOC] = "adhoc",
218+ [NL80211_IFTYPE_STATION] = "station",
219+ [NL80211_IFTYPE_AP] = "ap",
220+ [NL80211_IFTYPE_AP_VLAN] = "ap vlan",
221+ [NL80211_IFTYPE_WDS] = "wds",
222+ [NL80211_IFTYPE_MONITOR] = "monitor",
223+ [NL80211_IFTYPE_MESH_POINT] = "mesh point",
224+ [NL80211_IFTYPE_P2P_CLIENT] = "p2p client",
225+ [NL80211_IFTYPE_P2P_GO] = "p2p go",
226+ [NL80211_IFTYPE_P2P_DEVICE] = "p2p device",
227+ [NL80211_IFTYPE_OCB] = "ocb",
228+ [NL80211_IFTYPE_NAN] = "nan",
229+ };
230+
231+ buf = kzalloc(buf_size, GFP_KERNEL);
232+ if (!buf)
233+ return -ENOMEM;
234+
235+ list_for_each_entry(wdev, &wiphy->wdev_list, list) {
236+ offset += scnprintf(buf + offset, buf_size - offset,
237+ "wdev 0x%x\n"
238+ "interface type %s\n",
239+ wdev->identifier, iftype_str[wdev->iftype]);
240+ offset = dfs_status_read_wdev(wiphy, wdev, buf, buf_size, offset);
241+ }
242+
243+ r = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
244+
245+ kfree(buf);
246+
247+ return r;
248+}
249+
250+static const struct file_operations dfs_status_ops = {
251+ .read = dfs_status_read,
252+ .open = simple_open,
253+ .llseek = default_llseek,
254+};
255+
256+static int
257+dfs_nop_skip(void *data, u64 val)
258+{
259+ struct wiphy *wiphy = data;
260+ struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
261+ bool en = !!val;
262+ enum nl80211_band band;
263+ struct ieee80211_supported_band *sband;
264+ struct ieee80211_channel *chan;
265+ u32 nop_time = IEEE80211_DFS_MIN_NOP_TIME_MS;
266+ int i;
267+
268+ if (!en)
269+ return 0;
270+
271+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
272+ sband = wiphy->bands[band];
273+ if (!sband)
274+ continue;
275+ for (i = 0; i < sband->n_channels; i++) {
276+ chan = &sband->channels[i];
277+
278+ if (!(chan->flags & IEEE80211_CHAN_RADAR))
279+ continue;
280+
281+ if (chan->dfs_state == NL80211_DFS_UNAVAILABLE) {
282+ // Let current jiffies > dfs_state_entered_jiffies + NOP time
283+ chan->dfs_state_entered = jiffies -
284+ msecs_to_jiffies(nop_time + 1);
285+ }
286+ }
287+ }
288+
289+ cfg80211_sched_dfs_chan_update(rdev);
290+
291+ return 0;
292+}
293+
294+DEFINE_DEBUGFS_ATTRIBUTE(dfs_skip_nop_ops, NULL,
295+ dfs_nop_skip, "0x%08llx\n");
296+
297+static int
298+dfs_cac_skip(void *data, u64 val)
299+{
300+#define CAC_SKIP_MASK BIT(0)
301+#define CAC_SKIP_BACKGROUND_MASK BIT(1)
302+ struct wiphy *wiphy = data;
303+ struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
304+ struct wireless_dev *wdev;
305+ struct cfg80211_chan_def *chandef;
306+ unsigned int skip_mode = val;
307+ unsigned long cac_time;
308+ struct ieee80211_channel *chan;
309+
310+ if (!skip_mode || skip_mode > (CAC_SKIP_MASK | CAC_SKIP_BACKGROUND_MASK))
311+ return 0;
312+
313+ list_for_each_entry(wdev, &wiphy->wdev_list, list) {
314+ if ((skip_mode & CAC_SKIP_MASK) && wdev->chandef.chan) {
315+ chandef = &wdev->chandef;
316+ chan = chandef->chan;
317+
developer7a520b52023-03-14 14:09:34 +0800318+ if ((cfg80211_chandef_dfs_required(wiphy, chandef, wdev->iftype) > 0) &&
319+ cfg80211_chandef_dfs_usable(wiphy, chandef) && wdev->cac_started) {
developer18dec8f2022-10-25 12:20:54 +0800320+ rdev_skip_cac(rdev, wdev);
321+ }
322+ }
323+
324+ if ((skip_mode & CAC_SKIP_BACKGROUND_MASK) &&
325+ rdev->background_radar_wdev == wdev &&
326+ rdev->background_radar_chandef.chan) {
327+ chandef = &rdev->background_radar_chandef;
328+ chan = chandef->chan;
329+
developer7a520b52023-03-14 14:09:34 +0800330+ if ((cfg80211_chandef_dfs_required(wiphy, chandef, wdev->iftype) > 0) &&
331+ cfg80211_chandef_dfs_usable(wiphy, chandef) &&
developer18dec8f2022-10-25 12:20:54 +0800332+ rdev->background_cac_started) {
333+ // Let current jiffies > dfs_state_entered_jiffies + CAC time
334+ cac_time = rdev->background_cac_time_ms;
335+ rdev->background_cac_start_time = jiffies -
336+ msecs_to_jiffies(cac_time + 1);
337+ cancel_delayed_work(&rdev->background_cac_done_wk);
338+ queue_delayed_work(cfg80211_wq, &rdev->background_cac_done_wk, 0);
339+ }
340+ }
341+ }
342+
343+ return 0;
344+}
345+
346+DEFINE_DEBUGFS_ATTRIBUTE(dfs_skip_cac_ops, NULL,
347+ dfs_cac_skip, "0x%08llx\n");
348+
developer8b64f1a2023-05-02 10:31:58 +0800349+static int
350+dfs_available_reset(void *data, u64 val)
351+{
352+ struct wiphy *wiphy = data;
353+ struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
354+ bool en = !!val;
355+ enum nl80211_band band;
356+ struct ieee80211_supported_band *sband;
357+ struct ieee80211_channel *chan;
358+ int i;
359+
360+ if (!en)
361+ return 0;
362+
363+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
364+ sband = wiphy->bands[band];
365+ if (!sband)
366+ continue;
367+ for (i = 0; i < sband->n_channels; i++) {
368+ chan = &sband->channels[i];
369+
370+ if (!(chan->flags & IEEE80211_CHAN_RADAR))
371+ continue;
372+
373+ if (chan->dfs_state == NL80211_DFS_AVAILABLE) {
374+ chan->dfs_state = NL80211_DFS_USABLE;
375+ chan->dfs_state_entered = jiffies;
376+ }
377+ }
378+ }
379+
380+ cfg80211_sched_dfs_chan_update(rdev);
381+
382+ return 0;
383+}
384+
385+DEFINE_DEBUGFS_ATTRIBUTE(dfs_available_reset_ops, NULL,
386+ dfs_available_reset, "0x%08llx\n");
387+
developer18dec8f2022-10-25 12:20:54 +0800388+#define DEBUGFS_ADD(name, chmod) \
389+ debugfs_create_file(#name, chmod, phyd, &rdev->wiphy, &name## _ops)
390
391 void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
392 {
393 struct dentry *phyd = rdev->wiphy.debugfsdir;
394
395- DEBUGFS_ADD(rts_threshold);
396- DEBUGFS_ADD(fragmentation_threshold);
397- DEBUGFS_ADD(short_retry_limit);
398- DEBUGFS_ADD(long_retry_limit);
399- DEBUGFS_ADD(ht40allow_map);
400+ DEBUGFS_ADD(rts_threshold, 0444);
401+ DEBUGFS_ADD(fragmentation_threshold, 0444);
402+ DEBUGFS_ADD(short_retry_limit, 0444);
403+ DEBUGFS_ADD(long_retry_limit, 0444);
404+ DEBUGFS_ADD(ht40allow_map, 0444);
405+ DEBUGFS_ADD(dfs_status, 0444);
406+ DEBUGFS_ADD(dfs_skip_nop, 0600);
407+ DEBUGFS_ADD(dfs_skip_cac, 0600);
developer8b64f1a2023-05-02 10:31:58 +0800408+ DEBUGFS_ADD(dfs_available_reset, 0600);
developer18dec8f2022-10-25 12:20:54 +0800409 }
410diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
411index 00370ca..205c1bc 100644
412--- a/net/wireless/mlme.c
413+++ b/net/wireless/mlme.c
414@@ -998,13 +998,16 @@ __cfg80211_background_cac_event(struct cfg80211_registered_device *rdev,
415 queue_work(cfg80211_wq, &rdev->propagate_cac_done_wk);
416 cfg80211_sched_dfs_chan_update(rdev);
417 wdev = rdev->background_radar_wdev;
418+ rdev->background_cac_started = false;
419 break;
420 case NL80211_RADAR_CAC_ABORTED:
421 if (!cancel_delayed_work(&rdev->background_cac_done_wk))
422 return;
423 wdev = rdev->background_radar_wdev;
424+ rdev->background_cac_started = false;
425 break;
426 case NL80211_RADAR_CAC_STARTED:
427+ rdev->background_cac_started = true;
428 break;
429 default:
430 return;
431@@ -1024,6 +1027,7 @@ cfg80211_background_cac_event(struct cfg80211_registered_device *rdev,
432 chandef, event);
433 wiphy_unlock(&rdev->wiphy);
434 }
435+EXPORT_SYMBOL(cfg80211_background_cac_event);
436
437 void cfg80211_background_cac_done_wk(struct work_struct *work)
438 {
439@@ -1085,8 +1089,10 @@ cfg80211_start_background_radar_detection(struct cfg80211_registered_device *rde
440 if (!cac_time_ms)
441 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
442
443+ rdev->background_cac_time_ms = cac_time_ms;
444 rdev->background_radar_chandef = *chandef;
445 rdev->background_radar_wdev = wdev; /* Get offchain ownership */
446+ rdev->background_cac_start_time = jiffies;
447
448 __cfg80211_background_cac_event(rdev, wdev, chandef,
449 NL80211_RADAR_CAC_STARTED);
450diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h
451index 8555468..26f4604 100644
452--- a/net/wireless/rdev-ops.h
453+++ b/net/wireless/rdev-ops.h
454@@ -1398,4 +1398,18 @@ rdev_set_radar_background(struct cfg80211_registered_device *rdev,
455 return ret;
456 }
457
458+static inline int
459+rdev_skip_cac(struct cfg80211_registered_device *rdev,
460+ struct wireless_dev *wdev)
461+{
462+ if (!rdev->ops->skip_cac)
463+ return -EOPNOTSUPP;
464+
465+ trace_rdev_skip_cac(wdev);
466+ rdev->ops->skip_cac(wdev);
467+ trace_rdev_return_void(&rdev->wiphy);
468+
469+ return 0;
470+}
471+
472 #endif /* __CFG80211_RDEV_OPS */
473diff --git a/net/wireless/trace.h b/net/wireless/trace.h
474index 97a2937..eadabfa 100644
475--- a/net/wireless/trace.h
476+++ b/net/wireless/trace.h
477@@ -3665,6 +3665,18 @@ TRACE_EVENT(rdev_set_radar_background,
478 WIPHY_PR_ARG, CHAN_DEF_PR_ARG)
479 );
480
481+TRACE_EVENT(rdev_skip_cac,
482+ TP_PROTO(struct wireless_dev *wdev),
483+
484+ TP_ARGS(wdev),
485+
486+ TP_STRUCT__entry(WDEV_ENTRY),
487+
488+ TP_fast_assign(WDEV_ASSIGN;),
489+
490+ TP_printk(WDEV_PR_FMT, WDEV_PR_ARG)
491+);
492+
493 #endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */
494
495 #undef TRACE_INCLUDE_PATH
496--
developer7a520b52023-03-14 14:09:34 +08004972.18.0
developer18dec8f2022-10-25 12:20:54 +0800498