Skip to content

Commit b23b025

Browse files
greearblinvjw
authored andcommitted
mac80211: Optimize scans on current operating channel.
This should decrease un-necessary flushes, on/off channel work, and channel changes in cases where the only scanned channel is the current operating channel. * Removes SCAN_OFF_CHANNEL flag, uses SDATA_STATE_OFFCHANNEL and is-scanning flags instead. * Add helper method to determine if we are currently configured for the operating channel. * Do no blindly go off/on channel in work.c Instead, only call appropriate on/off code when we really need to change channels. Always enable offchannel-ps mode when starting work, and disable it when we are done. * Consolidate ieee80211_offchannel_stop_station and ieee80211_offchannel_stop_beaconing, call it ieee80211_offchannel_stop_vifs instead. * Accept non-beacon frames when scanning on operating channel. * Scan state machine optimized to minimize on/off channel transitions. Also, when going on-channel, go ahead and re-enable beaconing. We're going to be there for 200ms, so seems like some useful beaconing could happen. Always enable offchannel-ps mode when starting software scan, and disable it when we are done. * Grab local->mtx earlier in __ieee80211_scan_completed_finish so that we are protected when calling hw_config(), etc. * Pass probe-responses up the stack if scanning on local channel, so that mlme can take a look. Signed-off-by: Ben Greear <greearb@candelatech.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent cb8d61d commit b23b025

7 files changed

Lines changed: 214 additions & 89 deletions

File tree

‎net/mac80211/ieee80211_i.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,6 @@ struct tpt_led_trigger {
655655
* well be on the operating channel
656656
* @SCAN_HW_SCANNING: The hardware is scanning for us, we have no way to
657657
* determine if we are on the operating channel or not
658-
* @SCAN_OFF_CHANNEL: We're off our operating channel for scanning,
659-
* gets only set in conjunction with SCAN_SW_SCANNING
660658
* @SCAN_COMPLETED: Set for our scan work function when the driver reported
661659
* that the scan completed.
662660
* @SCAN_ABORTED: Set for our scan work function when the driver reported
@@ -665,7 +663,6 @@ struct tpt_led_trigger {
665663
enum {
666664
SCAN_SW_SCANNING,
667665
SCAN_HW_SCANNING,
668-
SCAN_OFF_CHANNEL,
669666
SCAN_COMPLETED,
670667
SCAN_ABORTED,
671668
};
@@ -1148,10 +1145,14 @@ void ieee80211_rx_bss_put(struct ieee80211_local *local,
11481145
struct ieee80211_bss *bss);
11491146

11501147
/* off-channel helpers */
1151-
void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local);
1152-
void ieee80211_offchannel_stop_station(struct ieee80211_local *local);
1148+
bool ieee80211_cfg_on_oper_channel(struct ieee80211_local *local);
1149+
void ieee80211_offchannel_enable_all_ps(struct ieee80211_local *local,
1150+
bool tell_ap);
1151+
void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local,
1152+
bool offchannel_ps_enable);
11531153
void ieee80211_offchannel_return(struct ieee80211_local *local,
1154-
bool enable_beaconing);
1154+
bool enable_beaconing,
1155+
bool offchannel_ps_disable);
11551156
void ieee80211_hw_roc_setup(struct ieee80211_local *local);
11561157

11571158
/* interface handling */

‎net/mac80211/main.c‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ static void ieee80211_reconfig_filter(struct work_struct *work)
9898
ieee80211_configure_filter(local);
9999
}
100100

101+
/*
102+
* Returns true if we are logically configured to be on
103+
* the operating channel AND the hardware-conf is currently
104+
* configured on the operating channel. Compares channel-type
105+
* as well.
106+
*/
107+
bool ieee80211_cfg_on_oper_channel(struct ieee80211_local *local)
108+
{
109+
struct ieee80211_channel *chan, *scan_chan;
110+
enum nl80211_channel_type channel_type;
111+
112+
/* This logic needs to match logic in ieee80211_hw_config */
113+
if (local->scan_channel) {
114+
chan = local->scan_channel;
115+
channel_type = NL80211_CHAN_NO_HT;
116+
} else if (local->tmp_channel) {
117+
chan = scan_chan = local->tmp_channel;
118+
channel_type = local->tmp_channel_type;
119+
} else {
120+
chan = local->oper_channel;
121+
channel_type = local->_oper_channel_type;
122+
}
123+
124+
if (chan != local->oper_channel ||
125+
channel_type != local->_oper_channel_type)
126+
return false;
127+
128+
/* Check current hardware-config against oper_channel. */
129+
if ((local->oper_channel != local->hw.conf.channel) ||
130+
(local->_oper_channel_type != local->hw.conf.channel_type))
131+
return false;
132+
133+
return true;
134+
}
135+
101136
int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
102137
{
103138
struct ieee80211_channel *chan, *scan_chan;
@@ -110,21 +145,27 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
110145

111146
scan_chan = local->scan_channel;
112147

148+
/* If this off-channel logic ever changes, ieee80211_on_oper_channel
149+
* may need to change as well.
150+
*/
113151
offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
114152
if (scan_chan) {
115153
chan = scan_chan;
116154
channel_type = NL80211_CHAN_NO_HT;
117-
local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
118-
} else if (local->tmp_channel &&
119-
local->oper_channel != local->tmp_channel) {
155+
} else if (local->tmp_channel) {
120156
chan = scan_chan = local->tmp_channel;
121157
channel_type = local->tmp_channel_type;
122-
local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
123158
} else {
124159
chan = local->oper_channel;
125160
channel_type = local->_oper_channel_type;
126-
local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
127161
}
162+
163+
if (chan != local->oper_channel ||
164+
channel_type != local->_oper_channel_type)
165+
local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
166+
else
167+
local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
168+
128169
offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
129170

130171
if (offchannel_flag || chan != local->hw.conf.channel ||
@@ -231,7 +272,7 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
231272

232273
if (changed & BSS_CHANGED_BEACON_ENABLED) {
233274
if (local->quiescing || !ieee80211_sdata_running(sdata) ||
234-
test_bit(SCAN_SW_SCANNING, &local->scanning)) {
275+
test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) {
235276
sdata->vif.bss_conf.enable_beacon = false;
236277
} else {
237278
/*

‎net/mac80211/offchannel.c‎

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
#include "driver-trace.h"
1818

1919
/*
20-
* inform AP that we will go to sleep so that it will buffer the frames
21-
* while we scan
20+
* Tell our hardware to disable PS.
21+
* Optionally inform AP that we will go to sleep so that it will buffer
22+
* the frames while we are doing off-channel work. This is optional
23+
* because we *may* be doing work on-operating channel, and want our
24+
* hardware unconditionally awake, but still let the AP send us normal frames.
2225
*/
23-
static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata)
26+
static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata,
27+
bool tell_ap)
2428
{
2529
struct ieee80211_local *local = sdata->local;
2630
struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
@@ -41,8 +45,8 @@ static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata)
4145
ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
4246
}
4347

44-
if (!(local->offchannel_ps_enabled) ||
45-
!(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK))
48+
if (tell_ap && (!local->offchannel_ps_enabled ||
49+
!(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)))
4650
/*
4751
* If power save was enabled, no need to send a nullfunc
4852
* frame because AP knows that we are sleeping. But if the
@@ -77,6 +81,9 @@ static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
7781
* we are sleeping, let's just enable power save mode in
7882
* hardware.
7983
*/
84+
/* TODO: Only set hardware if CONF_PS changed?
85+
* TODO: Should we set offchannel_ps_enabled to false?
86+
*/
8087
local->hw.conf.flags |= IEEE80211_CONF_PS;
8188
ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
8289
} else if (local->hw.conf.dynamic_ps_timeout > 0) {
@@ -95,63 +102,61 @@ static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
95102
ieee80211_sta_reset_conn_monitor(sdata);
96103
}
97104

98-
void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local)
105+
void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local,
106+
bool offchannel_ps_enable)
99107
{
100108
struct ieee80211_sub_if_data *sdata;
101109

110+
/*
111+
* notify the AP about us leaving the channel and stop all
112+
* STA interfaces.
113+
*/
102114
mutex_lock(&local->iflist_mtx);
103115
list_for_each_entry(sdata, &local->interfaces, list) {
104116
if (!ieee80211_sdata_running(sdata))
105117
continue;
106118

107-
/* disable beaconing */
119+
if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
120+
set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
121+
122+
/* Check to see if we should disable beaconing. */
108123
if (sdata->vif.type == NL80211_IFTYPE_AP ||
109124
sdata->vif.type == NL80211_IFTYPE_ADHOC ||
110125
sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
111126
ieee80211_bss_info_change_notify(
112127
sdata, BSS_CHANGED_BEACON_ENABLED);
113128

114-
/*
115-
* only handle non-STA interfaces here, STA interfaces
116-
* are handled in ieee80211_offchannel_stop_station(),
117-
* e.g., from the background scan state machine.
118-
*
119-
* In addition, do not stop monitor interface to allow it to be
120-
* used from user space controlled off-channel operations.
121-
*/
122-
if (sdata->vif.type != NL80211_IFTYPE_STATION &&
123-
sdata->vif.type != NL80211_IFTYPE_MONITOR) {
124-
set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
129+
if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
125130
netif_tx_stop_all_queues(sdata->dev);
131+
if (offchannel_ps_enable &&
132+
(sdata->vif.type == NL80211_IFTYPE_STATION) &&
133+
sdata->u.mgd.associated)
134+
ieee80211_offchannel_ps_enable(sdata, true);
126135
}
127136
}
128137
mutex_unlock(&local->iflist_mtx);
129138
}
130139

131-
void ieee80211_offchannel_stop_station(struct ieee80211_local *local)
140+
void ieee80211_offchannel_enable_all_ps(struct ieee80211_local *local,
141+
bool tell_ap)
132142
{
133143
struct ieee80211_sub_if_data *sdata;
134144

135-
/*
136-
* notify the AP about us leaving the channel and stop all STA interfaces
137-
*/
138145
mutex_lock(&local->iflist_mtx);
139146
list_for_each_entry(sdata, &local->interfaces, list) {
140147
if (!ieee80211_sdata_running(sdata))
141148
continue;
142149

143-
if (sdata->vif.type == NL80211_IFTYPE_STATION) {
144-
set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
145-
netif_tx_stop_all_queues(sdata->dev);
146-
if (sdata->u.mgd.associated)
147-
ieee80211_offchannel_ps_enable(sdata);
148-
}
150+
if (sdata->vif.type == NL80211_IFTYPE_STATION &&
151+
sdata->u.mgd.associated)
152+
ieee80211_offchannel_ps_enable(sdata, tell_ap);
149153
}
150154
mutex_unlock(&local->iflist_mtx);
151155
}
152156

153157
void ieee80211_offchannel_return(struct ieee80211_local *local,
154-
bool enable_beaconing)
158+
bool enable_beaconing,
159+
bool offchannel_ps_disable)
155160
{
156161
struct ieee80211_sub_if_data *sdata;
157162

@@ -161,7 +166,8 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
161166
continue;
162167

163168
/* Tell AP we're back */
164-
if (sdata->vif.type == NL80211_IFTYPE_STATION) {
169+
if (offchannel_ps_disable &&
170+
sdata->vif.type == NL80211_IFTYPE_STATION) {
165171
if (sdata->u.mgd.associated)
166172
ieee80211_offchannel_ps_disable(sdata);
167173
}
@@ -181,7 +187,7 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
181187
netif_tx_wake_all_queues(sdata->dev);
182188
}
183189

184-
/* re-enable beaconing */
190+
/* Check to see if we should re-enable beaconing */
185191
if (enable_beaconing &&
186192
(sdata->vif.type == NL80211_IFTYPE_AP ||
187193
sdata->vif.type == NL80211_IFTYPE_ADHOC ||

‎net/mac80211/rx.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,10 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
409409
if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN)))
410410
return RX_CONTINUE;
411411

412-
if (test_bit(SCAN_HW_SCANNING, &local->scanning))
412+
if (test_bit(SCAN_HW_SCANNING, &local->scanning) ||
413+
test_bit(SCAN_SW_SCANNING, &local->scanning))
413414
return ieee80211_scan_rx(rx->sdata, skb);
414415

415-
if (test_bit(SCAN_SW_SCANNING, &local->scanning)) {
416-
/* drop all the other packets during a software scan anyway */
417-
if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
418-
dev_kfree_skb(skb);
419-
return RX_QUEUED;
420-
}
421-
422416
/* scanning finished during invoking of handlers */
423417
I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
424418
return RX_DROP_UNUSABLE;
@@ -2793,7 +2787,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
27932787
local->dot11ReceivedFragmentCount++;
27942788

27952789
if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
2796-
test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
2790+
test_bit(SCAN_SW_SCANNING, &local->scanning)))
27972791
status->rx_flags |= IEEE80211_RX_IN_SCAN;
27982792

27992793
if (ieee80211_is_mgmt(fc))

0 commit comments

Comments
 (0)