blob: b2c2cff4519b03abd9a740f88129e546e94e4a74 [file] [log] [blame]
developer4eb49d92022-12-05 11:29:56 +08001From 6d245b62cf147bb813898da2ccb43a14ae0fac5c 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
developer4eb49d92022-12-05 11:29:56 +08004Subject: [PATCH 909/911] cfg80211: mtk: implement DFS status show, cac and nop
developer3609d782022-11-29 18:07:22 +08005 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 +
12 net/wireless/debugfs.c | 270 ++++++++++++++++++++++++++++++++++++++--
13 net/wireless/mlme.c | 6 +
14 net/wireless/rdev-ops.h | 14 +++
15 net/wireless/trace.h | 12 ++
16 7 files changed, 318 insertions(+), 7 deletions(-)
17
18diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
developer3609d782022-11-29 18:07:22 +080019index ae2af09..b97ddbd 100644
developer18dec8f2022-10-25 12:20:54 +080020--- a/include/net/cfg80211.h
21+++ b/include/net/cfg80211.h
22@@ -4401,6 +4401,7 @@ struct cfg80211_ops {
23 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
developer3609d782022-11-29 18:07:22 +080031index bf71594..97c5e5d 100644
developer18dec8f2022-10-25 12:20:54 +080032--- a/net/mac80211/cfg.c
33+++ b/net/mac80211/cfg.c
developer3609d782022-11-29 18:07:22 +080034@@ -4504,6 +4504,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,
developer3609d782022-11-29 18:07:22 +080059@@ -4610,4 +4628,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
developer3609d782022-11-29 18:07:22 +080080index 0878b16..ea50cc7 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, \
developer3609d782022-11-29 18:07:22 +080091@@ -96,16 +97,271 @@ 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+
318+ if ((chan->flags & IEEE80211_CHAN_RADAR) &&
319+ chan->dfs_state == NL80211_DFS_USABLE && wdev->cac_started) {
320+ 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+
330+ if ((chan->flags & IEEE80211_CHAN_RADAR) &&
331+ chan->dfs_state == NL80211_DFS_USABLE &&
332+ 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+
349+#define DEBUGFS_ADD(name, chmod) \
350+ debugfs_create_file(#name, chmod, phyd, &rdev->wiphy, &name## _ops)
351
352 void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
353 {
354 struct dentry *phyd = rdev->wiphy.debugfsdir;
355
356- DEBUGFS_ADD(rts_threshold);
357- DEBUGFS_ADD(fragmentation_threshold);
358- DEBUGFS_ADD(short_retry_limit);
359- DEBUGFS_ADD(long_retry_limit);
360- DEBUGFS_ADD(ht40allow_map);
361+ DEBUGFS_ADD(rts_threshold, 0444);
362+ DEBUGFS_ADD(fragmentation_threshold, 0444);
363+ DEBUGFS_ADD(short_retry_limit, 0444);
364+ DEBUGFS_ADD(long_retry_limit, 0444);
365+ DEBUGFS_ADD(ht40allow_map, 0444);
366+ DEBUGFS_ADD(dfs_status, 0444);
367+ DEBUGFS_ADD(dfs_skip_nop, 0600);
368+ DEBUGFS_ADD(dfs_skip_cac, 0600);
369 }
370diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
371index 00370ca..205c1bc 100644
372--- a/net/wireless/mlme.c
373+++ b/net/wireless/mlme.c
374@@ -998,13 +998,16 @@ __cfg80211_background_cac_event(struct cfg80211_registered_device *rdev,
375 queue_work(cfg80211_wq, &rdev->propagate_cac_done_wk);
376 cfg80211_sched_dfs_chan_update(rdev);
377 wdev = rdev->background_radar_wdev;
378+ rdev->background_cac_started = false;
379 break;
380 case NL80211_RADAR_CAC_ABORTED:
381 if (!cancel_delayed_work(&rdev->background_cac_done_wk))
382 return;
383 wdev = rdev->background_radar_wdev;
384+ rdev->background_cac_started = false;
385 break;
386 case NL80211_RADAR_CAC_STARTED:
387+ rdev->background_cac_started = true;
388 break;
389 default:
390 return;
391@@ -1024,6 +1027,7 @@ cfg80211_background_cac_event(struct cfg80211_registered_device *rdev,
392 chandef, event);
393 wiphy_unlock(&rdev->wiphy);
394 }
395+EXPORT_SYMBOL(cfg80211_background_cac_event);
396
397 void cfg80211_background_cac_done_wk(struct work_struct *work)
398 {
399@@ -1085,8 +1089,10 @@ cfg80211_start_background_radar_detection(struct cfg80211_registered_device *rde
400 if (!cac_time_ms)
401 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
402
403+ rdev->background_cac_time_ms = cac_time_ms;
404 rdev->background_radar_chandef = *chandef;
405 rdev->background_radar_wdev = wdev; /* Get offchain ownership */
406+ rdev->background_cac_start_time = jiffies;
407
408 __cfg80211_background_cac_event(rdev, wdev, chandef,
409 NL80211_RADAR_CAC_STARTED);
410diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h
411index 8555468..26f4604 100644
412--- a/net/wireless/rdev-ops.h
413+++ b/net/wireless/rdev-ops.h
414@@ -1398,4 +1398,18 @@ rdev_set_radar_background(struct cfg80211_registered_device *rdev,
415 return ret;
416 }
417
418+static inline int
419+rdev_skip_cac(struct cfg80211_registered_device *rdev,
420+ struct wireless_dev *wdev)
421+{
422+ if (!rdev->ops->skip_cac)
423+ return -EOPNOTSUPP;
424+
425+ trace_rdev_skip_cac(wdev);
426+ rdev->ops->skip_cac(wdev);
427+ trace_rdev_return_void(&rdev->wiphy);
428+
429+ return 0;
430+}
431+
432 #endif /* __CFG80211_RDEV_OPS */
433diff --git a/net/wireless/trace.h b/net/wireless/trace.h
434index 97a2937..eadabfa 100644
435--- a/net/wireless/trace.h
436+++ b/net/wireless/trace.h
437@@ -3665,6 +3665,18 @@ TRACE_EVENT(rdev_set_radar_background,
438 WIPHY_PR_ARG, CHAN_DEF_PR_ARG)
439 );
440
441+TRACE_EVENT(rdev_skip_cac,
442+ TP_PROTO(struct wireless_dev *wdev),
443+
444+ TP_ARGS(wdev),
445+
446+ TP_STRUCT__entry(WDEV_ENTRY),
447+
448+ TP_fast_assign(WDEV_ASSIGN;),
449+
450+ TP_printk(WDEV_PR_FMT, WDEV_PR_ARG)
451+);
452+
453 #endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */
454
455 #undef TRACE_INCLUDE_PATH
456--
developer3609d782022-11-29 18:07:22 +08004572.36.1
developer18dec8f2022-10-25 12:20:54 +0800458