Skip to content

Commit e1781ed

Browse files
Kalle Valolinvjw
authored andcommitted
mac80211: annotate sleeping driver ops
To make it easier to notice cases of calling sleeping ops in atomic context, annotate driver-ops.h with appropiate might_sleep() calls. At the same time, also document in mac80211.h the op functions with missing contexts. mac80211 doesn't seem to use get_tx_stats anywhere currently. Just to be on the safe side, I documented it to be atomic, but hopefully the op can be removed in the future. Compile-tested only. Signed-off-by: Kalle Valo <[email protected]> Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: John W. Linville <[email protected]>
1 parent 095d5ef commit e1781ed

File tree

2 files changed

+87
-16
lines changed

2 files changed

+87
-16
lines changed

include/net/mac80211.h

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,15 +1383,15 @@ enum ieee80211_ampdu_mlme_action {
13831383
* When the device is started it should not have a MAC address
13841384
* to avoid acknowledging frames before a non-monitor device
13851385
* is added.
1386-
* Must be implemented.
1386+
* Must be implemented and can sleep.
13871387
*
13881388
* @stop: Called after last netdevice attached to the hardware
13891389
* is disabled. This should turn off the hardware (at least
13901390
* it must turn off frame reception.)
13911391
* May be called right after add_interface if that rejects
13921392
* an interface. If you added any work onto the mac80211 workqueue
13931393
* you should ensure to cancel it on this callback.
1394-
* Must be implemented.
1394+
* Must be implemented and can sleep.
13951395
*
13961396
* @add_interface: Called when a netdevice attached to the hardware is
13971397
* enabled. Because it is not called for monitor mode devices, @start
@@ -1401,7 +1401,7 @@ enum ieee80211_ampdu_mlme_action {
14011401
* interface is given in the conf parameter.
14021402
* The callback may refuse to add an interface by returning a
14031403
* negative error code (which will be seen in userspace.)
1404-
* Must be implemented.
1404+
* Must be implemented and can sleep.
14051405
*
14061406
* @remove_interface: Notifies a driver that an interface is going down.
14071407
* The @stop callback is called after this if it is the last interface
@@ -1410,40 +1410,43 @@ enum ieee80211_ampdu_mlme_action {
14101410
* must be cleared so the device no longer acknowledges packets,
14111411
* the mac_addr member of the conf structure is, however, set to the
14121412
* MAC address of the device going away.
1413-
* Hence, this callback must be implemented.
1413+
* Hence, this callback must be implemented. It can sleep.
14141414
*
14151415
* @config: Handler for configuration requests. IEEE 802.11 code calls this
14161416
* function to change hardware configuration, e.g., channel.
14171417
* This function should never fail but returns a negative error code
1418-
* if it does.
1418+
* if it does. The callback can sleep.
14191419
*
14201420
* @bss_info_changed: Handler for configuration requests related to BSS
14211421
* parameters that may vary during BSS's lifespan, and may affect low
14221422
* level driver (e.g. assoc/disassoc status, erp parameters).
14231423
* This function should not be used if no BSS has been set, unless
14241424
* for association indication. The @changed parameter indicates which
1425-
* of the bss parameters has changed when a call is made.
1425+
* of the bss parameters has changed when a call is made. The callback
1426+
* can sleep.
14261427
*
14271428
* @prepare_multicast: Prepare for multicast filter configuration.
14281429
* This callback is optional, and its return value is passed
14291430
* to configure_filter(). This callback must be atomic.
14301431
*
14311432
* @configure_filter: Configure the device's RX filter.
14321433
* See the section "Frame filtering" for more information.
1433-
* This callback must be implemented.
1434+
* This callback must be implemented and can sleep.
14341435
*
14351436
* @set_tim: Set TIM bit. mac80211 calls this function when a TIM bit
14361437
* must be set or cleared for a given STA. Must be atomic.
14371438
*
14381439
* @set_key: See the section "Hardware crypto acceleration"
1439-
* This callback can sleep, and is only called between add_interface
1440-
* and remove_interface calls, i.e. while the given virtual interface
1440+
* This callback is only called between add_interface and
1441+
* remove_interface calls, i.e. while the given virtual interface
14411442
* is enabled.
14421443
* Returns a negative error code if the key can't be added.
1444+
* The callback can sleep.
14431445
*
14441446
* @update_tkip_key: See the section "Hardware crypto acceleration"
14451447
* This callback will be called in the context of Rx. Called for drivers
14461448
* which set IEEE80211_KEY_FLAG_TKIP_REQ_RX_P1_KEY.
1449+
* The callback can sleep.
14471450
*
14481451
* @hw_scan: Ask the hardware to service the scan request, no need to start
14491452
* the scan state machine in stack. The scan must honour the channel
@@ -1457,21 +1460,28 @@ enum ieee80211_ampdu_mlme_action {
14571460
* When the scan finishes, ieee80211_scan_completed() must be called;
14581461
* note that it also must be called when the scan cannot finish due to
14591462
* any error unless this callback returned a negative error code.
1463+
* The callback can sleep.
14601464
*
14611465
* @sw_scan_start: Notifier function that is called just before a software scan
14621466
* is started. Can be NULL, if the driver doesn't need this notification.
1467+
* The callback can sleep.
14631468
*
1464-
* @sw_scan_complete: Notifier function that is called just after a software scan
1465-
* finished. Can be NULL, if the driver doesn't need this notification.
1469+
* @sw_scan_complete: Notifier function that is called just after a
1470+
* software scan finished. Can be NULL, if the driver doesn't need
1471+
* this notification.
1472+
* The callback can sleep.
14661473
*
14671474
* @get_stats: Return low-level statistics.
14681475
* Returns zero if statistics are available.
1476+
* The callback can sleep.
14691477
*
14701478
* @get_tkip_seq: If your device implements TKIP encryption in hardware this
14711479
* callback should be provided to read the TKIP transmit IVs (both IV32
14721480
* and IV16) for the given key from hardware.
1481+
* The callback must be atomic.
14731482
*
14741483
* @set_rts_threshold: Configuration of RTS threshold (if device needs it)
1484+
* The callback can sleep.
14751485
*
14761486
* @sta_notify: Notifies low level driver about addition, removal or power
14771487
* state transition of an associated station, AP, IBSS/WDS/mesh peer etc.
@@ -1480,30 +1490,36 @@ enum ieee80211_ampdu_mlme_action {
14801490
* @conf_tx: Configure TX queue parameters (EDCF (aifs, cw_min, cw_max),
14811491
* bursting) for a hardware TX queue.
14821492
* Returns a negative error code on failure.
1493+
* The callback can sleep.
14831494
*
14841495
* @get_tx_stats: Get statistics of the current TX queue status. This is used
14851496
* to get number of currently queued packets (queue length), maximum queue
14861497
* size (limit), and total number of packets sent using each TX queue
14871498
* (count). The 'stats' pointer points to an array that has hw->queues
14881499
* items.
1500+
* The callback must be atomic.
14891501
*
14901502
* @get_tsf: Get the current TSF timer value from firmware/hardware. Currently,
14911503
* this is only used for IBSS mode BSSID merging and debugging. Is not a
14921504
* required function.
1505+
* The callback can sleep.
14931506
*
14941507
* @set_tsf: Set the TSF timer to the specified value in the firmware/hardware.
14951508
* Currently, this is only used for IBSS mode debugging. Is not a
14961509
* required function.
1510+
* The callback can sleep.
14971511
*
14981512
* @reset_tsf: Reset the TSF timer and allow firmware/hardware to synchronize
14991513
* with other STAs in the IBSS. This is only used in IBSS mode. This
15001514
* function is optional if the firmware/hardware takes full care of
15011515
* TSF synchronization.
1516+
* The callback can sleep.
15021517
*
15031518
* @tx_last_beacon: Determine whether the last IBSS beacon was sent by us.
15041519
* This is needed only for IBSS mode and the result of this function is
15051520
* used to determine whether to reply to Probe Requests.
15061521
* Returns non-zero if this device sent the last beacon.
1522+
* The callback can sleep.
15071523
*
15081524
* @ampdu_action: Perform a certain A-MPDU action
15091525
* The RA/TID combination determines the destination and TID we want
@@ -1512,16 +1528,19 @@ enum ieee80211_ampdu_mlme_action {
15121528
* is the first frame we expect to perform the action on. Notice
15131529
* that TX/RX_STOP can pass NULL for this parameter.
15141530
* Returns a negative error code on failure.
1531+
* The callback must be atomic.
15151532
*
15161533
* @rfkill_poll: Poll rfkill hardware state. If you need this, you also
15171534
* need to set wiphy->rfkill_poll to %true before registration,
15181535
* and need to call wiphy_rfkill_set_hw_state() in the callback.
1536+
* The callback can sleep.
15191537
*
15201538
* @testmode_cmd: Implement a cfg80211 test mode command.
1539+
* The callback can sleep.
15211540
*
15221541
* @flush: Flush all pending frames from the hardware queue, making sure
15231542
* that the hardware queues are empty. If the parameter @drop is set
1524-
* to %true, pending frames may be dropped.
1543+
* to %true, pending frames may be dropped. The callback can sleep.
15251544
*/
15261545
struct ieee80211_ops {
15271546
int (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb);

net/mac80211/driver-ops.h

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static inline int drv_start(struct ieee80211_local *local)
1414
{
1515
int ret;
1616

17+
might_sleep();
18+
1719
local->started = true;
1820
smp_mb();
1921
ret = local->ops->start(&local->hw);
@@ -23,6 +25,8 @@ static inline int drv_start(struct ieee80211_local *local)
2325

2426
static inline void drv_stop(struct ieee80211_local *local)
2527
{
28+
might_sleep();
29+
2630
local->ops->stop(&local->hw);
2731
trace_drv_stop(local);
2832

@@ -38,21 +42,31 @@ static inline void drv_stop(struct ieee80211_local *local)
3842
static inline int drv_add_interface(struct ieee80211_local *local,
3943
struct ieee80211_vif *vif)
4044
{
41-
int ret = local->ops->add_interface(&local->hw, vif);
45+
int ret;
46+
47+
might_sleep();
48+
49+
ret = local->ops->add_interface(&local->hw, vif);
4250
trace_drv_add_interface(local, vif_to_sdata(vif), ret);
4351
return ret;
4452
}
4553

4654
static inline void drv_remove_interface(struct ieee80211_local *local,
4755
struct ieee80211_vif *vif)
4856
{
57+
might_sleep();
58+
4959
local->ops->remove_interface(&local->hw, vif);
5060
trace_drv_remove_interface(local, vif_to_sdata(vif));
5161
}
5262

5363
static inline int drv_config(struct ieee80211_local *local, u32 changed)
5464
{
55-
int ret = local->ops->config(&local->hw, changed);
65+
int ret;
66+
67+
might_sleep();
68+
69+
ret = local->ops->config(&local->hw, changed);
5670
trace_drv_config(local, changed, ret);
5771
return ret;
5872
}
@@ -62,6 +76,8 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local,
6276
struct ieee80211_bss_conf *info,
6377
u32 changed)
6478
{
79+
might_sleep();
80+
6581
if (local->ops->bss_info_changed)
6682
local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
6783
trace_drv_bss_info_changed(local, sdata, info, changed);
@@ -111,7 +127,11 @@ static inline int drv_set_key(struct ieee80211_local *local,
111127
struct ieee80211_sta *sta,
112128
struct ieee80211_key_conf *key)
113129
{
114-
int ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
130+
int ret;
131+
132+
might_sleep();
133+
134+
ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
115135
trace_drv_set_key(local, cmd, sdata, sta, key, ret);
116136
return ret;
117137
}
@@ -121,6 +141,8 @@ static inline void drv_update_tkip_key(struct ieee80211_local *local,
121141
const u8 *address, u32 iv32,
122142
u16 *phase1key)
123143
{
144+
might_sleep();
145+
124146
if (local->ops->update_tkip_key)
125147
local->ops->update_tkip_key(&local->hw, conf, address,
126148
iv32, phase1key);
@@ -130,20 +152,28 @@ static inline void drv_update_tkip_key(struct ieee80211_local *local,
130152
static inline int drv_hw_scan(struct ieee80211_local *local,
131153
struct cfg80211_scan_request *req)
132154
{
133-
int ret = local->ops->hw_scan(&local->hw, req);
155+
int ret;
156+
157+
might_sleep();
158+
159+
ret = local->ops->hw_scan(&local->hw, req);
134160
trace_drv_hw_scan(local, req, ret);
135161
return ret;
136162
}
137163

138164
static inline void drv_sw_scan_start(struct ieee80211_local *local)
139165
{
166+
might_sleep();
167+
140168
if (local->ops->sw_scan_start)
141169
local->ops->sw_scan_start(&local->hw);
142170
trace_drv_sw_scan_start(local);
143171
}
144172

145173
static inline void drv_sw_scan_complete(struct ieee80211_local *local)
146174
{
175+
might_sleep();
176+
147177
if (local->ops->sw_scan_complete)
148178
local->ops->sw_scan_complete(&local->hw);
149179
trace_drv_sw_scan_complete(local);
@@ -154,6 +184,8 @@ static inline int drv_get_stats(struct ieee80211_local *local,
154184
{
155185
int ret = -EOPNOTSUPP;
156186

187+
might_sleep();
188+
157189
if (local->ops->get_stats)
158190
ret = local->ops->get_stats(&local->hw, stats);
159191
trace_drv_get_stats(local, stats, ret);
@@ -173,6 +205,9 @@ static inline int drv_set_rts_threshold(struct ieee80211_local *local,
173205
u32 value)
174206
{
175207
int ret = 0;
208+
209+
might_sleep();
210+
176211
if (local->ops->set_rts_threshold)
177212
ret = local->ops->set_rts_threshold(&local->hw, value);
178213
trace_drv_set_rts_threshold(local, value, ret);
@@ -193,6 +228,9 @@ static inline int drv_conf_tx(struct ieee80211_local *local, u16 queue,
193228
const struct ieee80211_tx_queue_params *params)
194229
{
195230
int ret = -EOPNOTSUPP;
231+
232+
might_sleep();
233+
196234
if (local->ops->conf_tx)
197235
ret = local->ops->conf_tx(&local->hw, queue, params);
198236
trace_drv_conf_tx(local, queue, params, ret);
@@ -210,6 +248,9 @@ static inline int drv_get_tx_stats(struct ieee80211_local *local,
210248
static inline u64 drv_get_tsf(struct ieee80211_local *local)
211249
{
212250
u64 ret = -1ULL;
251+
252+
might_sleep();
253+
213254
if (local->ops->get_tsf)
214255
ret = local->ops->get_tsf(&local->hw);
215256
trace_drv_get_tsf(local, ret);
@@ -218,13 +259,17 @@ static inline u64 drv_get_tsf(struct ieee80211_local *local)
218259

219260
static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf)
220261
{
262+
might_sleep();
263+
221264
if (local->ops->set_tsf)
222265
local->ops->set_tsf(&local->hw, tsf);
223266
trace_drv_set_tsf(local, tsf);
224267
}
225268

226269
static inline void drv_reset_tsf(struct ieee80211_local *local)
227270
{
271+
might_sleep();
272+
228273
if (local->ops->reset_tsf)
229274
local->ops->reset_tsf(&local->hw);
230275
trace_drv_reset_tsf(local);
@@ -233,6 +278,9 @@ static inline void drv_reset_tsf(struct ieee80211_local *local)
233278
static inline int drv_tx_last_beacon(struct ieee80211_local *local)
234279
{
235280
int ret = 1;
281+
282+
might_sleep();
283+
236284
if (local->ops->tx_last_beacon)
237285
ret = local->ops->tx_last_beacon(&local->hw);
238286
trace_drv_tx_last_beacon(local, ret);
@@ -256,12 +304,16 @@ static inline int drv_ampdu_action(struct ieee80211_local *local,
256304

257305
static inline void drv_rfkill_poll(struct ieee80211_local *local)
258306
{
307+
might_sleep();
308+
259309
if (local->ops->rfkill_poll)
260310
local->ops->rfkill_poll(&local->hw);
261311
}
262312

263313
static inline void drv_flush(struct ieee80211_local *local, bool drop)
264314
{
315+
might_sleep();
316+
265317
trace_drv_flush(local, drop);
266318
if (local->ops->flush)
267319
local->ops->flush(&local->hw, drop);

0 commit comments

Comments
 (0)