b1a1d2c8945d49e9be27b3f3464c10bcdd7786dc
[openwrt/staging/wigyori.git] /
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Wed, 27 Oct 2021 11:03:42 +0200
3 Subject: [PATCH] cfg80211: move offchan_cac_event to a dedicated work
4
5 In order to make cfg80211_offchan_cac_abort() (renamed from
6 cfg80211_offchan_cac_event) callable in other contexts and
7 without so much locking restrictions, make it trigger a new
8 work instead of operating directly.
9
10 Do some other renames while at it to clarify.
11
12 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
13 Link: https://lore.kernel.org/r/6145c3d0f30400a568023f67981981d24c7c6133.1635325205.git.lorenzo@kernel.org
14 [rewrite commit log]
15 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
16 ---
17
18 --- a/include/net/cfg80211.h
19 +++ b/include/net/cfg80211.h
20 @@ -7620,19 +7620,13 @@ void cfg80211_cac_event(struct net_devic
21 enum nl80211_radar_event event, gfp_t gfp);
22
23 /**
24 - * cfg80211_offchan_cac_event - Channel Availability Check (CAC) offchan event
25 + * cfg80211_offchan_cac_abort - Channel Availability Check offchan abort event
26 * @wiphy: the wiphy
27 - * @chandef: chandef for the current channel
28 - * @event: type of event
29 *
30 - * This function is called when a Channel Availability Check (CAC) is finished,
31 - * started or aborted by a offchannel dedicated chain.
32 - *
33 - * Note that this acquires the wiphy lock.
34 + * This function is called by the driver when a Channel Availability Check
35 + * (CAC) is aborted by a offchannel dedicated chain.
36 */
37 -void cfg80211_offchan_cac_event(struct wiphy *wiphy,
38 - const struct cfg80211_chan_def *chandef,
39 - enum nl80211_radar_event event);
40 +void cfg80211_offchan_cac_abort(struct wiphy *wiphy);
41
42 /**
43 * cfg80211_gtk_rekey_notify - notify userspace about driver rekeying
44 --- a/net/wireless/core.c
45 +++ b/net/wireless/core.c
46 @@ -543,7 +543,9 @@ use_default_name:
47 INIT_WORK(&rdev->rfkill_block, cfg80211_rfkill_block_work);
48 INIT_WORK(&rdev->conn_work, cfg80211_conn_work);
49 INIT_WORK(&rdev->event_work, cfg80211_event_work);
50 - INIT_DELAYED_WORK(&rdev->offchan_cac_work, cfg80211_offchan_cac_work);
51 + INIT_WORK(&rdev->offchan_cac_abort_wk, cfg80211_offchan_cac_abort_wk);
52 + INIT_DELAYED_WORK(&rdev->offchan_cac_done_wk,
53 + cfg80211_offchan_cac_done_wk);
54
55 init_waitqueue_head(&rdev->dev_wait);
56
57 @@ -1053,11 +1055,13 @@ void wiphy_unregister(struct wiphy *wiph
58 cancel_work_sync(&rdev->conn_work);
59 flush_work(&rdev->event_work);
60 cancel_delayed_work_sync(&rdev->dfs_update_channels_wk);
61 + cancel_delayed_work_sync(&rdev->offchan_cac_done_wk);
62 flush_work(&rdev->destroy_work);
63 flush_work(&rdev->sched_scan_stop_wk);
64 flush_work(&rdev->propagate_radar_detect_wk);
65 flush_work(&rdev->propagate_cac_done_wk);
66 flush_work(&rdev->mgmt_registrations_update_wk);
67 + flush_work(&rdev->offchan_cac_abort_wk);
68
69 #ifdef CONFIG_PM
70 if (rdev->wiphy.wowlan_config && rdev->ops->set_wakeup)
71 --- a/net/wireless/core.h
72 +++ b/net/wireless/core.h
73 @@ -86,7 +86,8 @@ struct cfg80211_registered_device {
74
75 struct wireless_dev *offchan_radar_wdev;
76 struct cfg80211_chan_def offchan_radar_chandef;
77 - struct delayed_work offchan_cac_work;
78 + struct delayed_work offchan_cac_done_wk;
79 + struct work_struct offchan_cac_abort_wk;
80
81 /* netlink port which started critical protocol (0 means not started) */
82 u32 crit_proto_nlportid;
83 @@ -502,7 +503,9 @@ cfg80211_start_offchan_radar_detection(s
84
85 void cfg80211_stop_offchan_radar_detection(struct wireless_dev *wdev);
86
87 -void cfg80211_offchan_cac_work(struct work_struct *work);
88 +void cfg80211_offchan_cac_done_wk(struct work_struct *work);
89 +
90 +void cfg80211_offchan_cac_abort_wk(struct work_struct *work);
91
92 bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy,
93 struct ieee80211_channel *chan);
94 --- a/net/wireless/mlme.c
95 +++ b/net/wireless/mlme.c
96 @@ -971,17 +971,6 @@ void cfg80211_cac_event(struct net_devic
97 }
98 EXPORT_SYMBOL(cfg80211_cac_event);
99
100 -void cfg80211_offchan_cac_work(struct work_struct *work)
101 -{
102 - struct delayed_work *delayed_work = to_delayed_work(work);
103 - struct cfg80211_registered_device *rdev;
104 -
105 - rdev = container_of(delayed_work, struct cfg80211_registered_device,
106 - offchan_cac_work);
107 - cfg80211_offchan_cac_event(&rdev->wiphy, &rdev->offchan_radar_chandef,
108 - NL80211_RADAR_CAC_FINISHED);
109 -}
110 -
111 static void
112 __cfg80211_offchan_cac_event(struct cfg80211_registered_device *rdev,
113 struct wireless_dev *wdev,
114 @@ -1006,7 +995,7 @@ __cfg80211_offchan_cac_event(struct cfg8
115 rdev->offchan_radar_wdev = NULL;
116 break;
117 case NL80211_RADAR_CAC_ABORTED:
118 - cancel_delayed_work(&rdev->offchan_cac_work);
119 + cancel_delayed_work(&rdev->offchan_cac_done_wk);
120 wdev = rdev->offchan_radar_wdev;
121 rdev->offchan_radar_wdev = NULL;
122 break;
123 @@ -1022,17 +1011,44 @@ __cfg80211_offchan_cac_event(struct cfg8
124 nl80211_radar_notify(rdev, chandef, event, netdev, GFP_KERNEL);
125 }
126
127 -void cfg80211_offchan_cac_event(struct wiphy *wiphy,
128 - const struct cfg80211_chan_def *chandef,
129 - enum nl80211_radar_event event)
130 +static void
131 +cfg80211_offchan_cac_event(struct cfg80211_registered_device *rdev,
132 + const struct cfg80211_chan_def *chandef,
133 + enum nl80211_radar_event event)
134 +{
135 + wiphy_lock(&rdev->wiphy);
136 + __cfg80211_offchan_cac_event(rdev, NULL, chandef, event);
137 + wiphy_unlock(&rdev->wiphy);
138 +}
139 +
140 +void cfg80211_offchan_cac_done_wk(struct work_struct *work)
141 +{
142 + struct delayed_work *delayed_work = to_delayed_work(work);
143 + struct cfg80211_registered_device *rdev;
144 +
145 + rdev = container_of(delayed_work, struct cfg80211_registered_device,
146 + offchan_cac_done_wk);
147 + cfg80211_offchan_cac_event(rdev, &rdev->offchan_radar_chandef,
148 + NL80211_RADAR_CAC_FINISHED);
149 +}
150 +
151 +void cfg80211_offchan_cac_abort_wk(struct work_struct *work)
152 +{
153 + struct cfg80211_registered_device *rdev;
154 +
155 + rdev = container_of(work, struct cfg80211_registered_device,
156 + offchan_cac_abort_wk);
157 + cfg80211_offchan_cac_event(rdev, &rdev->offchan_radar_chandef,
158 + NL80211_RADAR_CAC_ABORTED);
159 +}
160 +
161 +void cfg80211_offchan_cac_abort(struct wiphy *wiphy)
162 {
163 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
164
165 - wiphy_lock(wiphy);
166 - __cfg80211_offchan_cac_event(rdev, NULL, chandef, event);
167 - wiphy_unlock(wiphy);
168 + queue_work(cfg80211_wq, &rdev->offchan_cac_abort_wk);
169 }
170 -EXPORT_SYMBOL(cfg80211_offchan_cac_event);
171 +EXPORT_SYMBOL(cfg80211_offchan_cac_abort);
172
173 int
174 cfg80211_start_offchan_radar_detection(struct cfg80211_registered_device *rdev,
175 @@ -1062,7 +1078,7 @@ cfg80211_start_offchan_radar_detection(s
176 rdev->offchan_radar_chandef = *chandef;
177 __cfg80211_offchan_cac_event(rdev, wdev, chandef,
178 NL80211_RADAR_CAC_STARTED);
179 - queue_delayed_work(cfg80211_wq, &rdev->offchan_cac_work,
180 + queue_delayed_work(cfg80211_wq, &rdev->offchan_cac_done_wk,
181 msecs_to_jiffies(cac_time_ms));
182
183 return 0;