Skip to content

Commit 7da7cc1

Browse files
jmberg-intellinvjw
authored andcommitted
mac80211: per interface idle notification
Sometimes we don't just need to know whether or not the device is idle, but also per interface. This adds that reporting capability to mac80211. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 1fdaa46 commit 7da7cc1

7 files changed

Lines changed: 81 additions & 16 deletions

File tree

‎include/net/mac80211.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct ieee80211_low_level_stats {
149149
* @BSS_CHANGED_ARP_FILTER: Hardware ARP filter address list or state changed.
150150
* @BSS_CHANGED_QOS: QoS for this association was enabled/disabled. Note
151151
* that it is only ever disabled for station mode.
152+
* @BSS_CHANGED_IDLE: Idle changed for this BSS/interface.
152153
*/
153154
enum ieee80211_bss_change {
154155
BSS_CHANGED_ASSOC = 1<<0,
@@ -165,6 +166,7 @@ enum ieee80211_bss_change {
165166
BSS_CHANGED_IBSS = 1<<11,
166167
BSS_CHANGED_ARP_FILTER = 1<<12,
167168
BSS_CHANGED_QOS = 1<<13,
169+
BSS_CHANGED_IDLE = 1<<14,
168170

169171
/* when adding here, make sure to change ieee80211_reconfig */
170172
};
@@ -223,6 +225,9 @@ enum ieee80211_bss_change {
223225
* hardware must not perform any ARP filtering. Note, that the filter will
224226
* be enabled also in promiscuous mode.
225227
* @qos: This is a QoS-enabled BSS.
228+
* @idle: This interface is idle. There's also a global idle flag in the
229+
* hardware config which may be more appropriate depending on what
230+
* your driver/device needs to do.
226231
*/
227232
struct ieee80211_bss_conf {
228233
const u8 *bssid;
@@ -247,6 +252,7 @@ struct ieee80211_bss_conf {
247252
u8 arp_addr_cnt;
248253
bool arp_filter_enabled;
249254
bool qos;
255+
bool idle;
250256
};
251257

252258
/**

‎net/mac80211/ibss.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,12 +920,14 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
920920
memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
921921
sdata->u.ibss.ssid_len = params->ssid_len;
922922

923+
mutex_unlock(&sdata->u.ibss.mtx);
924+
925+
mutex_lock(&sdata->local->mtx);
923926
ieee80211_recalc_idle(sdata->local);
927+
mutex_unlock(&sdata->local->mtx);
924928

925929
ieee80211_queue_work(&sdata->local->hw, &sdata->work);
926930

927-
mutex_unlock(&sdata->u.ibss.mtx);
928-
929931
return 0;
930932
}
931933

@@ -980,7 +982,9 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
980982

981983
mutex_unlock(&sdata->u.ibss.mtx);
982984

985+
mutex_lock(&local->mtx);
983986
ieee80211_recalc_idle(sdata->local);
987+
mutex_unlock(&local->mtx);
984988

985989
return 0;
986990
}

‎net/mac80211/ieee80211_i.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ struct ieee80211_sub_if_data {
497497
*/
498498
bool ht_opmode_valid;
499499

500+
/* to detect idle changes */
501+
bool old_idle;
502+
500503
/* Fragment table for host-based reassembly */
501504
struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
502505
unsigned int fragment_next;

‎net/mac80211/iface.c‎

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ static int ieee80211_open(struct net_device *dev)
309309
if (sdata->flags & IEEE80211_SDATA_PROMISC)
310310
atomic_inc(&local->iff_promiscs);
311311

312+
mutex_lock(&local->mtx);
312313
hw_reconf_flags |= __ieee80211_recalc_idle(local);
314+
mutex_unlock(&local->mtx);
313315

314316
local->open_count++;
315317
if (hw_reconf_flags) {
@@ -516,7 +518,9 @@ static int ieee80211_stop(struct net_device *dev)
516518

517519
sdata->bss = NULL;
518520

521+
mutex_lock(&local->mtx);
519522
hw_reconf_flags |= __ieee80211_recalc_idle(local);
523+
mutex_unlock(&local->mtx);
520524

521525
ieee80211_recalc_ps(local, -1);
522526

@@ -1199,28 +1203,61 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
11991203
{
12001204
struct ieee80211_sub_if_data *sdata;
12011205
int count = 0;
1206+
bool working = false, scanning = false;
1207+
struct ieee80211_work *wk;
12021208

1203-
if (!list_empty(&local->work_list))
1204-
return ieee80211_idle_off(local, "working");
1205-
1206-
if (local->scanning)
1207-
return ieee80211_idle_off(local, "scanning");
1209+
#ifdef CONFIG_PROVE_LOCKING
1210+
WARN_ON(debug_locks && !lockdep_rtnl_is_held() &&
1211+
!lockdep_is_held(&local->iflist_mtx));
1212+
#endif
1213+
lockdep_assert_held(&local->mtx);
12081214

12091215
list_for_each_entry(sdata, &local->interfaces, list) {
1210-
if (!ieee80211_sdata_running(sdata))
1216+
if (!ieee80211_sdata_running(sdata)) {
1217+
sdata->vif.bss_conf.idle = true;
12111218
continue;
1219+
}
1220+
1221+
sdata->old_idle = sdata->vif.bss_conf.idle;
1222+
12121223
/* do not count disabled managed interfaces */
12131224
if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1214-
!sdata->u.mgd.associated)
1225+
!sdata->u.mgd.associated) {
1226+
sdata->vif.bss_conf.idle = true;
12151227
continue;
1228+
}
12161229
/* do not count unused IBSS interfaces */
12171230
if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
1218-
!sdata->u.ibss.ssid_len)
1231+
!sdata->u.ibss.ssid_len) {
1232+
sdata->vif.bss_conf.idle = true;
12191233
continue;
1234+
}
12201235
/* count everything else */
12211236
count++;
12221237
}
12231238

1239+
list_for_each_entry(wk, &local->work_list, list) {
1240+
working = true;
1241+
wk->sdata->vif.bss_conf.idle = false;
1242+
}
1243+
1244+
if (local->scan_sdata) {
1245+
scanning = true;
1246+
local->scan_sdata->vif.bss_conf.idle = false;
1247+
}
1248+
1249+
list_for_each_entry(sdata, &local->interfaces, list) {
1250+
if (sdata->old_idle == sdata->vif.bss_conf.idle)
1251+
continue;
1252+
if (!ieee80211_sdata_running(sdata))
1253+
continue;
1254+
ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE);
1255+
}
1256+
1257+
if (working)
1258+
return ieee80211_idle_off(local, "working");
1259+
if (scanning)
1260+
return ieee80211_idle_off(local, "scanning");
12241261
if (!count)
12251262
return ieee80211_idle_on(local);
12261263
else

‎net/mac80211/mlme.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,11 @@ static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
11031103
printk(KERN_DEBUG "Connection to AP %pM lost.\n", bssid);
11041104

11051105
ieee80211_set_disassoc(sdata, true);
1106-
ieee80211_recalc_idle(local);
11071106
mutex_unlock(&ifmgd->mtx);
1107+
1108+
mutex_lock(&local->mtx);
1109+
ieee80211_recalc_idle(local);
1110+
mutex_unlock(&local->mtx);
11081111
/*
11091112
* must be outside lock due to cfg80211,
11101113
* but that's not a problem.
@@ -1173,7 +1176,9 @@ ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
11731176
sdata->name, bssid, reason_code);
11741177

11751178
ieee80211_set_disassoc(sdata, true);
1179+
mutex_lock(&sdata->local->mtx);
11761180
ieee80211_recalc_idle(sdata->local);
1181+
mutex_unlock(&sdata->local->mtx);
11771182

11781183
return RX_MGMT_CFG80211_DEAUTH;
11791184
}
@@ -1203,7 +1208,9 @@ ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
12031208
sdata->name, mgmt->sa, reason_code);
12041209

12051210
ieee80211_set_disassoc(sdata, true);
1211+
mutex_lock(&sdata->local->mtx);
12061212
ieee80211_recalc_idle(sdata->local);
1213+
mutex_unlock(&sdata->local->mtx);
12071214
return RX_MGMT_CFG80211_DISASSOC;
12081215
}
12091216

@@ -1840,8 +1847,10 @@ void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
18401847
" after %dms, disconnecting.\n",
18411848
bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
18421849
ieee80211_set_disassoc(sdata, true);
1843-
ieee80211_recalc_idle(local);
18441850
mutex_unlock(&ifmgd->mtx);
1851+
mutex_lock(&local->mtx);
1852+
ieee80211_recalc_idle(local);
1853+
mutex_unlock(&local->mtx);
18451854
/*
18461855
* must be outside lock due to cfg80211,
18471856
* but that's not a problem.
@@ -2319,7 +2328,9 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
23192328
if (assoc_bss)
23202329
sta_info_destroy_addr(sdata, bssid);
23212330

2331+
mutex_lock(&sdata->local->mtx);
23222332
ieee80211_recalc_idle(sdata->local);
2333+
mutex_unlock(&sdata->local->mtx);
23232334

23242335
return 0;
23252336
}
@@ -2357,7 +2368,9 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
23572368
cookie, !req->local_state_change);
23582369
sta_info_destroy_addr(sdata, bssid);
23592370

2371+
mutex_lock(&sdata->local->mtx);
23602372
ieee80211_recalc_idle(sdata->local);
2373+
mutex_unlock(&sdata->local->mtx);
23612374

23622375
return 0;
23632376
}

‎net/mac80211/scan.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
304304
ieee80211_offchannel_return(local, true);
305305

306306
done:
307+
mutex_lock(&local->mtx);
307308
ieee80211_recalc_idle(local);
309+
mutex_unlock(&local->mtx);
308310
ieee80211_mlme_notify_scan_completed(local);
309311
ieee80211_ibss_notify_scan_completed(local);
310312
ieee80211_mesh_notify_scan_completed(local);

‎net/mac80211/work.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,10 @@ static void ieee80211_work_work(struct work_struct *work)
888888
while ((skb = skb_dequeue(&local->work_skb_queue)))
889889
ieee80211_work_rx_queued_mgmt(local, skb);
890890

891-
ieee80211_recalc_idle(local);
892-
893891
mutex_lock(&local->mtx);
894892

893+
ieee80211_recalc_idle(local);
894+
895895
list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
896896
bool started = wk->started;
897897

@@ -1001,10 +1001,10 @@ static void ieee80211_work_work(struct work_struct *work)
10011001
&local->scan_work,
10021002
round_jiffies_relative(0));
10031003

1004-
mutex_unlock(&local->mtx);
1005-
10061004
ieee80211_recalc_idle(local);
10071005

1006+
mutex_unlock(&local->mtx);
1007+
10081008
list_for_each_entry_safe(wk, tmp, &free_work, list) {
10091009
wk->done(wk, NULL);
10101010
list_del(&wk->list);

0 commit comments

Comments
 (0)