Skip to contentSkip to conversation

mac80211: Optimize scans on current operating channel.

RFC Superseded [email protected] 2 participants 11 messages Jan 26, 2011 – Jan 31, 2011 mac80211

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

RFC v3 1/1 mac80211: Optimize scans on current operating channel.

From: Ben Greear <[email protected]>

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.

---
:100644 100644 c47d7c0... 9508486... M net/mac80211/ieee80211_i.h
:100644 100644 09a2744... 1e845c5... M net/mac80211/main.c
:100644 100644 b4e5267... 0441b16... M net/mac80211/offchannel.c
:100644 100644 f36d70f... 76b3a68... M net/mac80211/rx.c
:100644 100644 f246d8a... b2eca7e... M net/mac80211/scan.c
:100644 100644 36305e0... 62ffc8e... M net/mac80211/work.c

 net/mac80211/ieee80211_i.h |   10 +++++++-
 net/mac80211/main.c        |   53 +++++++++++++++++++++++++++++++++++++++-----
 net/mac80211/offchannel.c  |   44 ++++++++----------------------------
 net/mac80211/rx.c          |   13 +++++++---
 net/mac80211/scan.c        |   43 +++++++++++++++++++++--------------
 net/mac80211/work.c        |   19 +++++++--------
 6 files changed, 110 insertions(+), 72 deletions(-)
net/mac80211/ieee80211_i.h +9 -1
index c47d7c0..9508486 100644
@@ -660,6 +660,10 @@ struct tpt_led_trigger {
  *	that the scan completed.
  * @SCAN_ABORTED: Set for our scan work function when the driver reported
  *	a scan complete for an aborted scan.
+ * @SCAN_LEFT_OPER_CHANNEL:  Set this flag if the scan process leaves the
+ *      operating channel at any time.  If scanning ONLY the current operating
+ *      channel this flag should not be set, and this will allow fewer
+ *      offchannel changes.
  */
 enum {
 	SCAN_SW_SCANNING,
@@ -667,6 +671,7 @@ enum {
 	SCAN_OFF_CHANNEL,
 	SCAN_COMPLETED,
 	SCAN_ABORTED,
+	SCAN_LEFT_OPER_CHANNEL,
 };
 
 /**
@@ -1147,7 +1152,10 @@ void ieee80211_rx_bss_put(struct ieee80211_local *local,
 			  struct ieee80211_bss *bss);
 
 /* off-channel helpers */
-void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local);
+/* Returns true if hardware is currently configured for the operating channel
+ * and if the logical configured state is to be on the operating channel.
+ */
+bool ieee80211_on_oper_channel(struct ieee80211_local *local);
 void ieee80211_offchannel_stop_station(struct ieee80211_local *local);
 void ieee80211_offchannel_return(struct ieee80211_local *local,
 				 bool enable_beaconing);
net/mac80211/main.c +47 -6

87 lines not on this page · raw message

net/mac80211/offchannel.c +10 -34

74 lines not on this page · raw message

net/mac80211/rx.c +9 -4
index f36d70f..76b3a68 100644
@@ -388,6 +388,7 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
 	struct ieee80211_local *local = rx->local;
 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
 	struct sk_buff *skb = rx->skb;
+	int ret;
 
 	if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN)))
 		return RX_CONTINUE;
@@ -396,10 +397,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
 		return ieee80211_scan_rx(rx->sdata, skb);
 
 	if (test_bit(SCAN_SW_SCANNING, &local->scanning)) {
-		/* drop all the other packets during a software scan anyway */
-		if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
+		ret = ieee80211_scan_rx(rx->sdata, skb);
+		/* drop all the other packets while scanning off channel */
+		if (ret != RX_QUEUED &&
+		    test_bit(SCAN_OFF_CHANNEL, &local->scanning)) {
 			dev_kfree_skb(skb);
-		return RX_QUEUED;
+			return RX_QUEUED;
+		}
+		return ret;
 	}
 
 	/* scanning finished during invoking of handlers */
@@ -2749,7 +2754,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
 		local->dot11ReceivedFragmentCount++;
 
 	if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
-		     test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
+		     test_bit(SCAN_SW_SCANNING, &local->scanning)))
 		status->rx_flags |= IEEE80211_RX_IN_SCAN;
 
 	if (ieee80211_is_mgmt(fc))
net/mac80211/scan.c +26 -17

93 lines not on this page · raw message

net/mac80211/work.c +9 -10
index 36305e0..62ffc8e 100644
@@ -924,18 +924,17 @@ static void ieee80211_work_work(struct work_struct *work)
 		}
 
 		if (!started && !local->tmp_channel) {
-			/*
-			 * TODO: could optimize this by leaving the
-			 *	 station vifs in awake mode if they
-			 *	 happen to be on the same channel as
-			 *	 the requested channel
-			 */
-			ieee80211_offchannel_stop_beaconing(local);
-			ieee80211_offchannel_stop_station(local);
-
 			local->tmp_channel = wk->chan;
 			local->tmp_channel_type = wk->chan_type;
-			ieee80211_hw_config(local, 0);
+			if (!ieee80211_on_oper_channel(local)) {
+				/*
+				 * Leave the station vifs in awake mode if they
+				 * happen to be on the same channel as
+				 * the requested channel
+				 */
+				ieee80211_offchannel_stop_station(local);
+				ieee80211_hw_config(local, 0);
+			}
 			started = true;
 			wk->timeout = jiffies;
 		}
Signature · 1 line
1.7.2.3
maintainer
#1 lore raw

net/mac80211/ieee80211_i.h void ieee80211_rx_bss_put(struct ieee80211_local *local, · line 1158

Quoted 4 lines · On Wed, 2011-01-26 at 12:37 -0800, [email protected] wrote:
net/mac80211/ieee80211_i.h +4 -0
+/* Returns true if hardware is currently configured for the operating channel
+ * and if the logical configured state is to be on the operating channel.
+ */
+bool ieee80211_on_oper_channel(struct ieee80211_local *local);

Maybe use proper kernel-doc

Quoted 4 lines

+/** If we are configured to be off the operating channel,
+ * or if we are already off the operating channel, return
+ * false.
+ */

But that clearly isn't kernel-doc, so no /**

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 110

Quoted 6 lines
net/mac80211/main.c +6 -0
+bool ieee80211_on_oper_channel(struct ieee80211_local *local)
+{
+	struct ieee80211_channel *chan, *scan_chan;
+	enum nl80211_channel_type channel_type;
+
+	/** This logic needs to match logic in ieee80211_hw_config */

ditto.

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 120

Quoted 10 lines
net/mac80211/main.c +10 -0
+	if (local->scan_channel) {
+		chan = local->scan_channel;
+		channel_type = NL80211_CHAN_NO_HT;
+	} else if (local->tmp_channel) {
+		chan = scan_chan = local->tmp_channel;
+		channel_type = local->tmp_channel_type;
+	} else {
+		chan = local->oper_channel;
+		channel_type = local->_oper_channel_type;
+	}

Don't understand -- why not return true in the else branch?

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 129

Quoted 8 lines
net/mac80211/main.c +8 -0
+	if (chan != local->oper_channel ||
+	    channel_type != local->_oper_channel_type)
+		return false;
+
+	/* Check current hardware-config against oper_channel. */
+	if ((local->oper_channel != local->hw.conf.channel) ||
+	    (local->_oper_channel_type != local->hw.conf.channel_type))
+		return false;

That's confusing, and kinda racy IIRC?

Quoted 12 lines
net/mac80211/main.c +4 -3
+	/* If this off-channel logic ever changes,  ieee80211_on_oper_channel
+	 * may need to change as well.
+	 */
 	offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
 	if (scan_chan) {
 		chan = scan_chan;
 		channel_type = NL80211_CHAN_NO_HT;
-		local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
-	} else if (local->tmp_channel &&
-		   local->oper_channel != local->tmp_channel) {
+	} else if (local->tmp_channel) {
 		chan = scan_chan = local->tmp_channel;

net/mac80211/main.c int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)

Quoted 10 lines
net/mac80211/main.c +7 -1
 		channel_type = local->tmp_channel_type;
-		local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
 
+
+	if (chan != local->oper_channel ||
+	    channel_type != local->_oper_channel_type)
+		local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
+	else
+		local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
+	$

whitespace damage ($ inserted by me)

net/mac80211/main.c int ieee80211_hw_config(struct ieee80211_local *local, u32 changed) · line 228

Quoted 8 lines
net/mac80211/main.c +1 -0
@@ -183,6 +222,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
 	return ret;
 }
 
+
 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
 				      u32 changed)
 {

pointless

net/mac80211/offchannel.c static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata) · line 98

Quoted 10 lines
net/mac80211/offchannel.c +1 -1
index b4e5267..0441b16 100644
@@ -95,57 +95,33 @@ static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
 	ieee80211_sta_reset_conn_monitor(sdata);
 }
 
-void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local)
+void ieee80211_offchannel_stop_station(struct ieee80211_local *local)

I think you should find a new name for the combined function, like "stop_interface".

net/mac80211/offchannel.c static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata) · line 122

Quoted 8 lines
net/mac80211/offchannel.c +3 -2
-		if (sdata->vif.type == NL80211_IFTYPE_STATION) {
+		if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
 			set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
 			netif_tx_stop_all_queues(sdata->dev);
-			if (sdata->u.mgd.associated)
+			if ((sdata->vif.type == NL80211_IFTYPE_STATION) &&
+			    sdata->u.mgd.associated)
 				ieee80211_offchannel_ps_enable(sdata);

what's the difference between sdata_state_offchannel and scan_off_channel?

net/mac80211/offchannel.c static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata) · line 125

Quoted 3 lines
net/mac80211/offchannel.c +1 -0
 		}
+
 	}

spurious whitespace

net/mac80211/offchannel.c void ieee80211_offchannel_return(struct ieee80211_local *local, · line 163

Quoted 11 lines
net/mac80211/offchannel.c +1 -1
 	mutex_unlock(&local->iflist_mtx);
 }
@@ -181,7 +157,7 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
 			netif_tx_wake_all_queues(sdata->dev);
 		}
 
-		/* re-enable beaconing */
+		/* Check to see if we should re-enable beaconing */
 		if (enable_beaconing &&
 		    (sdata->vif.type == NL80211_IFTYPE_AP ||
 		     sdata->vif.type == NL80211_IFTYPE_ADHOC ||

How does scan_off_channel get cleared before this?

Quoted 5 lines
net/mac80211/offchannel.c +0 -1
@@ -396,10 +397,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
 		return ieee80211_scan_rx(rx->sdata, skb);
 
 	if (test_bit(SCAN_SW_SCANNING, &local->scanning)) {
-		/* drop all the other packets during a software scan anyway */

net/mac80211/offchannel.c ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) · line 407

Quoted 10 lines
net/mac80211/offchannel.c +7 -2
-		if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
+		ret = ieee80211_scan_rx(rx->sdata, skb);
+		/* drop all the other packets while scanning off channel */
+		if (ret != RX_QUEUED &&
+		    test_bit(SCAN_OFF_CHANNEL, &local->scanning)) {
 			dev_kfree_skb(skb);
-		return RX_QUEUED;
+			return RX_QUEUED;
+		}
+		return ret;

Alright -- but does the mlme.c code know not to expect beacons during an on-channel scan?

net/mac80211/offchannel.c static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, · line 2758

Quoted 7 lines
net/mac80211/offchannel.c +1 -1
@@ -2749,7 +2754,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
 		local->dot11ReceivedFragmentCount++;
 
 	if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
-		     test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
+		     test_bit(SCAN_SW_SCANNING, &local->scanning)))
 		status->rx_flags |= IEEE80211_RX_IN_SCAN;

Not sure I understand this change?

Quoted 5 lines
net/mac80211/offchannel.c +1 -0
+++ b/net/mac80211/scan.c
@@ -294,11 +294,14 @@ static void __ieee80211_scan_completed_finish(struct ieee80211_hw *hw,
 {
 	struct ieee80211_local *local = hw_to_local(hw);
 

net/mac80211/offchannel.c static void __ieee80211_scan_completed_finish(struct ieee80211_hw *hw, · line 304

Quoted 10 lines
net/mac80211/offchannel.c +5 -2
-	ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
+	if ((local->oper_channel != local->hw.conf.channel) || was_hw_scan)
+		ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
+
 	if (!was_hw_scan) {
 		ieee80211_configure_filter(local);
 		drv_sw_scan_complete(local);
-		ieee80211_offchannel_return(local, true);
+		if (test_bit(SCAN_LEFT_OPER_CHANNEL, &local->scanning))
+			ieee80211_offchannel_return(local, true);

test_and_clear_bit ? Actually it's locked, no? So no need for atomic ops.

net/mac80211/offchannel.c static void ieee80211_scan_state_decision(struct ieee80211_local *local, · line 549

Quoted 8 lines
net/mac80211/offchannel.c +3 -1
@@ -544,7 +544,18 @@ static void ieee80211_scan_state_decision(struct ieee80211_local *local,
 	}
 	mutex_unlock(&local->iflist_mtx);
 
-	if (local->scan_channel) {
+	next_chan = local->scan_req->channels[local->scan_channel_idx];
+
+	if (local->oper_channel == local->hw.conf.channel) {

what's that for?

net/mac80211/offchannel.c static void ieee80211_scan_state_decision(struct ieee80211_local *local, · line 551

Quoted 2 lines
net/mac80211/offchannel.c +2 -0
+		if (next_chan == local->oper_channel)
+			local->next_scan_state = SCAN_SET_CHANNEL;

channel type?

Quoted 15 lines
net/mac80211/offchannel.c +4 -1
@@ -592,9 +596,12 @@ static void ieee80211_scan_state_decision(struct ieee80211_local *local,
 static void ieee80211_scan_state_leave_oper_channel(struct ieee80211_local *local,
 						    unsigned long *next_delay)
 {
+	/* This must be set before we do the stop_station logic. */
+	__set_bit(SCAN_OFF_CHANNEL, &local->scanning);
+
 	ieee80211_offchannel_stop_station(local);
 
-	__set_bit(SCAN_OFF_CHANNEL, &local->scanning);
+	__set_bit(SCAN_LEFT_OPER_CHANNEL, &local->scanning);
 
 
 

net/mac80211/offchannel.c static void ieee80211_scan_state_set_channel(struct ieee80211_local *local, · line 654

Quoted 9 lines
net/mac80211/offchannel.c +4 -2
@@ -641,8 +648,10 @@ static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
 	chan = local->scan_req->channels[local->scan_channel_idx];
 
 	local->scan_channel = chan;
-	if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
-		skip = 1;
+
+	if (chan != local->hw.conf.channel)
+		if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
+			skip = 1;

Why doesn't that test the bit? Or does this only cause setting it?

Quoted 19 lines
net/mac80211/work.c +0 -9
index 36305e0..62ffc8e 100644
@@ -924,18 +924,17 @@ static void ieee80211_work_work(struct work_struct *work)
 		}
 
 		if (!started && !local->tmp_channel) {
-			/*
-			 * TODO: could optimize this by leaving the
-			 *	 station vifs in awake mode if they
-			 *	 happen to be on the same channel as
-			 *	 the requested channel
-			 */
-			ieee80211_offchannel_stop_beaconing(local);
-			ieee80211_offchannel_stop_station(local);
-
 			local->tmp_channel = wk->chan;
 			local->tmp_channel_type = wk->chan_type;

net/mac80211/work.c static void ieee80211_work_work(struct work_struct *work) · line 937

Quoted 10 lines
net/mac80211/work.c +9 -1
-			ieee80211_hw_config(local, 0);
+			if (!ieee80211_on_oper_channel(local)) {
+				/*
+				 * Leave the station vifs in awake mode if they
+				 * happen to be on the same channel as
+				 * the requested channel
+				 */
+				ieee80211_offchannel_stop_station(local);
+				ieee80211_hw_config(local, 0);
+			}

Now I think ieee80211_on_oper_channel() is a confusing name -- should it be "_already_on_target_channel" or something?

Also, won't this do some weird things like not stop, but try to start stations again?

johannes

author
#2 lore raw
Quoted 4 lines · Johannes Berg
Quoted 4 lines
net/mac80211/main.c +4 -0
+	if (local->scan_channel) {
+		chan = local->scan_channel;
+		channel_type = NL80211_CHAN_NO_HT;
+	} else if (local->tmp_channel) {
Quoted 8 lines

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 120

Quoted 6 lines
net/mac80211/main.c +6 -0
+		chan = scan_chan = local->tmp_channel;
+		channel_type = local->tmp_channel_type;
+	} else {
+		chan = local->oper_channel;
+		channel_type = local->_oper_channel_type;
+	}

Don't understand -- why not return true in the else branch?

Because the hardware might not actually be set to the oper_channel. The idea is that you configure the mac80211 state as you want it, and then use this method to figure out if you really need to make hardware changes.

Quoted 10 lines

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 129

Quoted 8 lines
net/mac80211/main.c +8 -0
+	if (chan != local->oper_channel ||
+	    channel_type != local->_oper_channel_type)
+		return false;
+
+	/* Check current hardware-config against oper_channel. */
+	if ((local->oper_channel != local->hw.conf.channel) ||
+	    (local->_oper_channel_type != local->hw.conf.channel_type))
+		return false;

That's confusing, and kinda racy IIRC?

This method should be locked such that the hardware conf cannot be changed while it is being called. I can double check that this is true.

Quoted 9 lines
Quoted 9 lines
net/mac80211/offchannel.c +0 -0
index b4e5267..0441b16 100644
@@ -95,57 +95,33 @@ static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
  	ieee80211_sta_reset_conn_monitor(sdata);
  }
 
Quoted 5 lines

net/mac80211/offchannel.c static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata) · line 98

Quoted 2 lines
net/mac80211/offchannel.c +1 -1
-void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local)
+void ieee80211_offchannel_stop_station(struct ieee80211_local *local)

I think you should find a new name for the combined function, like "stop_interface".

Maybe stop_vifs() ?
It stops everything but Monitor interfaces...

Quoted 11 lines

net/mac80211/offchannel.c static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata) · line 122

Quoted 8 lines
net/mac80211/offchannel.c +3 -2
-		if (sdata->vif.type == NL80211_IFTYPE_STATION) {
+		if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
  			set_bit(SDATA_STATE_OFFCHANNEL,&sdata->state);
  			netif_tx_stop_all_queues(sdata->dev);
-			if (sdata->u.mgd.associated)
+			if ((sdata->vif.type == NL80211_IFTYPE_STATION)&&
+			    sdata->u.mgd.associated)
  				ieee80211_offchannel_ps_enable(sdata);

what's the difference between sdata_state_offchannel and scan_off_channel?

No idea, will have to take a look. Was just coping existing code...

Quoted 7 lines

net/mac80211/offchannel.c void ieee80211_offchannel_return(struct ieee80211_local *local, · line 163

Quoted 5 lines
net/mac80211/offchannel.c +1 -1
-		/* re-enable beaconing */
+		/* Check to see if we should re-enable beaconing */
  		if (enable_beaconing&&
  		(sdata->vif.type == NL80211_IFTYPE_AP ||
  		     sdata->vif.type == NL80211_IFTYPE_ADHOC ||

How does scan_off_channel get cleared before this?

Will check.

Quoted 4 lines
Quoted 4 lines
net/mac80211/offchannel.c +0 -0
@@ -396,10 +397,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
  		return ieee80211_scan_rx(rx->sdata, skb);
 
Quoted 15 lines

net/mac80211/offchannel.c ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) · line 407

Quoted 12 lines
net/mac80211/offchannel.c +7 -3
  	if (test_bit(SCAN_SW_SCANNING,&local->scanning)) {
-		/* drop all the other packets during a software scan anyway */
-		if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
+		ret = ieee80211_scan_rx(rx->sdata, skb);
+		/* drop all the other packets while scanning off channel */
+		if (ret != RX_QUEUED&&
+		    test_bit(SCAN_OFF_CHANNEL,&local->scanning)) {
  			dev_kfree_skb(skb);
-		return RX_QUEUED;
+			return RX_QUEUED;
+		}
+		return ret;

Alright -- but does the mlme.c code know not to expect beacons during an on-channel scan?

I think that code is just supposed to let regular packets through if we are scanning on the operating channel? I don't see how anything gets less beacons?

Quoted 10 lines

net/mac80211/offchannel.c static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, · line 2758

Quoted 8 lines
net/mac80211/offchannel.c +1 -1
@@ -2749,7 +2754,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  		local->dot11ReceivedFragmentCount++;
 
  	if (unlikely(test_bit(SCAN_HW_SCANNING,&local->scanning) ||
-		     test_bit(SCAN_OFF_CHANNEL,&local->scanning)))
+		     test_bit(SCAN_SW_SCANNING,&local->scanning)))
  		status->rx_flags |= IEEE80211_RX_IN_SCAN;

Not sure I understand this change?

Otherwise, scan results are not gathered while we are scanning on channel. This was the root cause of me not seeing scan results while scanning on channel. (There is other code that will ignore beacons if the RX_IN_SCAN bit isn't set).

Quoted 11 lines

net/mac80211/offchannel.c static void ieee80211_scan_state_decision(struct ieee80211_local *local, · line 549

Quoted 8 lines
net/mac80211/offchannel.c +3 -1
@@ -544,7 +544,18 @@ static void ieee80211_scan_state_decision(struct ieee80211_local *local,
  	}
  	mutex_unlock(&local->iflist_mtx);
 
-	if (local->scan_channel) {
+	next_chan = local->scan_req->channels[local->scan_channel_idx];
+
+	if (local->oper_channel == local->hw.conf.channel) {

what's that for?

Quoted 4 lines

net/mac80211/offchannel.c static void ieee80211_scan_state_decision(struct ieee80211_local *local, · line 551

Quoted 2 lines
net/mac80211/offchannel.c +2 -0
+		if (next_chan == local->oper_channel)
+			local->next_scan_state = SCAN_SET_CHANNEL;

channel type?

Yes, will add checks for channel type. That first bit is to try to avoid changes if we're already on the right channel, but it could be wrong. I'll review all of that.

Quoted 18 lines
Quoted 18 lines
net/mac80211/offchannel.c +4 -1
@@ -592,9 +596,12 @@ static void ieee80211_scan_state_decision(struct ieee80211_local *local,
  static void ieee80211_scan_state_leave_oper_channel(struct ieee80211_local *local,
  						    unsigned long *next_delay)
  {
+	/* This must be set before we do the stop_station logic. */
+	__set_bit(SCAN_OFF_CHANNEL,&local->scanning);
+
  	ieee80211_offchannel_stop_station(local);
 
-	__set_bit(SCAN_OFF_CHANNEL,&local->scanning);
+	__set_bit(SCAN_LEFT_OPER_CHANNEL,&local->scanning);
 
 
 
@@ -641,8 +648,10 @@ static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
  	chan = local->scan_req->channels[local->scan_channel_idx];
 
Quoted 9 lines

net/mac80211/offchannel.c static void ieee80211_scan_state_set_channel(struct ieee80211_local *local, · line 654

Quoted 7 lines
net/mac80211/offchannel.c +4 -2
  	local->scan_channel = chan;
-	if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
-		skip = 1;
+
+	if (chan != local->hw.conf.channel)
+		if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
+			skip = 1;

Why doesn't that test the bit? Or does this only cause setting it?

Which bit?

Either way, at the least I need to check for channel-type as well.

Quoted 25 lines
Quoted 25 lines
net/mac80211/work.c +4 -10
index 36305e0..62ffc8e 100644
@@ -924,18 +924,17 @@ static void ieee80211_work_work(struct work_struct *work)
  		}
 
  		if (!started&&  !local->tmp_channel) {
-			/*
-			 * TODO: could optimize this by leaving the
-			 *	 station vifs in awake mode if they
-			 *	 happen to be on the same channel as
-			 *	 the requested channel
-			 */
-			ieee80211_offchannel_stop_beaconing(local);
-			ieee80211_offchannel_stop_station(local);
-
  			local->tmp_channel = wk->chan;
  			local->tmp_channel_type = wk->chan_type;
-			ieee80211_hw_config(local, 0);
+			if (!ieee80211_on_oper_channel(local)) {
+				/*
+				 * Leave the station vifs in awake mode if they
+				 * happen to be on the same channel as
Quoted 8 lines

net/mac80211/work.c static void ieee80211_work_work(struct work_struct *work) · line 937

Quoted 5 lines
net/mac80211/work.c +5 -0
+				 * the requested channel
+				 */
+				ieee80211_offchannel_stop_station(local);
+				ieee80211_hw_config(local, 0);
+			}

Now I think ieee80211_on_oper_channel() is a confusing name -- should it be "_already_on_target_channel" or something?

That does sound better.

Quoted 3 lines

Also, won't this do some weird things like not stop, but try to start stations again?

I was thinking that should be harmless. As far as I can tell, current code would never actually stop beaconing in this method but might try to start it later, so it must not cause too much trouble.

Thanks for the review...I'll go over everything and try to repost something that incorporates your ideas.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
maintainer
#3 lore raw
Quoted 13 lines · Ben Greear
Quoted 4 lines
Quoted 4 lines
net/mac80211/main.c +4 -0
+	if (local->scan_channel) {
+		chan = local->scan_channel;
+		channel_type = NL80211_CHAN_NO_HT;
+	} else if (local->tmp_channel) {
Quoted 8 lines

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 120

Quoted 6 lines
net/mac80211/main.c +6 -0
+		chan = scan_chan = local->tmp_channel;
+		channel_type = local->tmp_channel_type;
+	} else {
+		chan = local->oper_channel;
+		channel_type = local->_oper_channel_type;
+	}

Don't understand -- why not return true in the else branch?

Quoted 4 lines

Because the hardware might not actually be set to the oper_channel. The idea is that you configure the mac80211 state as you want it, and then use this method to figure out if you really need to make hardware changes.

Oh. Wouldn't it make more sense to stick that into the _config() function then and return something there? Hmm. I kinda start to understand I guess.

Quoted 11 lines
Quoted 10 lines

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 129

Quoted 8 lines
net/mac80211/main.c +8 -0
+	if (chan != local->oper_channel ||
+	    channel_type != local->_oper_channel_type)
+		return false;
+
+	/* Check current hardware-config against oper_channel. */
+	if ((local->oper_channel != local->hw.conf.channel) ||
+	    (local->_oper_channel_type != local->hw.conf.channel_type))
+		return false;

That's confusing, and kinda racy IIRC?

Quoted 3 lines

This method should be locked such that the hardware conf cannot be changed while it is being called. I can double check that this is true.

Not all of this is always properly locked unfortunately. Not sure about this case though.

Quoted 10 lines
Quoted 8 lines

net/mac80211/scan.c static void ieee80211_scan_state_set_channel(struct ieee80211_local *local, · line 654

Quoted 6 lines
net/mac80211/scan.c +4 -2
-	if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
-		skip = 1;
+
+	if (chan != local->hw.conf.channel)
+		if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
+			skip = 1;

Why doesn't that test the bit? Or does this only cause setting it?

Which bit?

Err. Not sure, maybe I got confused.

Quoted 6 lines
Quoted 2 lines

Also, won't this do some weird things like not stop, but try to start stations again?

I was thinking that should be harmless. As far as I can tell, current code would never actually stop beaconing in this method but might try to start it later, so it must not cause too much trouble.

Yeah, maybe you're right and it doesn't matter, but I think it'd be nicer to always nest the calls. I see you've done that already.

Quoted 2 lines

Thanks for the review...I'll go over everything and try to repost something that incorporates your ideas.

Thanks for your patience with this! It's quite tricky I guess...

johannes

author
#4 lore raw
Quoted 15 lines · Johannes Berg
Quoted 13 lines · Ben Greear
Quoted 12 lines

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 120

Quoted 10 lines
net/mac80211/main.c +10 -0
+	if (local->scan_channel) {
+		chan = local->scan_channel;
+		channel_type = NL80211_CHAN_NO_HT;
+	} else if (local->tmp_channel) {
+		chan = scan_chan = local->tmp_channel;
+		channel_type = local->tmp_channel_type;
+	} else {
+		chan = local->oper_channel;
+		channel_type = local->_oper_channel_type;
+	}

Don't understand -- why not return true in the else branch?

Quoted 8 lines
Quoted 4 lines

Because the hardware might not actually be set to the oper_channel. The idea is that you configure the mac80211 state as you want it, and then use this method to figure out if you really need to make hardware changes.

Oh. Wouldn't it make more sense to stick that into the _config() function then and return something there? Hmm. I kinda start to understand I guess.

The code is similar..seems like it could be put into a common helper method, but I haven't thought of a clean way to do that yet.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

net/mac80211/main.c static void ieee80211_reconfig_filter(struct work_struct *work) · line 129

Quoted 8 lines
net/mac80211/main.c +8 -0
+	if (chan != local->oper_channel ||
+	    channel_type != local->_oper_channel_type)
+		return false;
+
+	/* Check current hardware-config against oper_channel. */
+	if ((local->oper_channel != local->hw.conf.channel) ||
+	    (local->_oper_channel_type != local->hw.conf.channel_type))
+		return false;

That's confusing, and kinda racy IIRC?

Quoted 6 lines
Quoted 3 lines

This method should be locked such that the hardware conf cannot be changed while it is being called. I can double check that this is true.

Not all of this is always properly locked unfortunately. Not sure about this case though.

On that note: It seems to me that __ieee80211_scan_completed_finish must grab the mutex_lock(&local->mtx); early in this method, before any calls to ieee80211_hw_config, for instance. I believe this would be an issue in both my patch and the existing code. I'm adding code to grab it early, but still release after recalc_idle() is called. I'll test it with lockdep enabled to make sure it's at least mostly sane.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Also, won't this do some weird things like not stop, but try to start stations again?

I was thinking that should be harmless. As far as I can tell, current code would never actually stop beaconing in this method but might try to start it later, so it must not cause too much trouble.

Yeah, maybe you're right and it doesn't matter, but I think it'd be nicer to always nest the calls. I see you've done that already.

Yeah, the v5 patch was better about this. The code is still complex, but perhaps we'll think of something simpler down the road.

I'll post a v6 soon, with the earlier mutex grab I mention above and the debug stuff removed.

Hopefully it's getting close!

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
author
#5 lore raw
In reply to Johannes Berg
Quoted 18 lines · Johannes Berg
Quoted 5 lines
net/mac80211/rx.c +0 -1
@@ -396,10 +397,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
  		return ieee80211_scan_rx(rx->sdata, skb);
 
  	if (test_bit(SCAN_SW_SCANNING,&local->scanning)) {
-		/* drop all the other packets during a software scan anyway */

net/mac80211/rx.c ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) · line 407

Quoted 10 lines
net/mac80211/rx.c +7 -2
-		if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
+		ret = ieee80211_scan_rx(rx->sdata, skb);
+		/* drop all the other packets while scanning off channel */
+		if (ret != RX_QUEUED&&
+		    test_bit(SCAN_OFF_CHANNEL,&local->scanning)) {
  			dev_kfree_skb(skb);
-		return RX_QUEUED;
+			return RX_QUEUED;
+		}
+		return ret;

Alright -- but does the mlme.c code know not to expect beacons during an on-channel scan?

I have a more basic question on this:

Should we just pass all packets on up the stack, regardless of whether we are offchannel or not? I think that would simplify things here,
and if/when we ever support things other than just scanning on different off-channels, that code would just work.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
maintainer
#6 lore raw
Quoted 19 lines · Ben Greear
Quoted 18 lines
Quoted 5 lines
net/mac80211/rx.c +0 -1
@@ -396,10 +397,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
  		return ieee80211_scan_rx(rx->sdata, skb);
 
  	if (test_bit(SCAN_SW_SCANNING,&local->scanning)) {
-		/* drop all the other packets during a software scan anyway */

net/mac80211/rx.c ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) · line 407

Quoted 10 lines
net/mac80211/rx.c +7 -2
-		if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
+		ret = ieee80211_scan_rx(rx->sdata, skb);
+		/* drop all the other packets while scanning off channel */
+		if (ret != RX_QUEUED&&
+		    test_bit(SCAN_OFF_CHANNEL,&local->scanning)) {
  			dev_kfree_skb(skb);
-		return RX_QUEUED;
+			return RX_QUEUED;
+		}
+		return ret;

Alright -- but does the mlme.c code know not to expect beacons during an on-channel scan?

Quoted 6 lines

I have a more basic question on this:

Should we just pass all packets on up the stack, regardless of whether we are offchannel or not? I think that would simplify things here,
and if/when we ever support things other than just scanning on different off-channels, that code would just work.

I'm not really exactly sure why we don't.

However -- I was thinking of something else, not data packets. While scanning, all received beacons will be handed to the scan code. But if the mlme code isn't told to stop looking for them, it'll still expect to see the beacons.

johannes

author
#7 lore raw
Quoted 28 lines · Johannes Berg
Quoted 19 lines · Ben Greear
Quoted 18 lines
Quoted 5 lines
net/mac80211/rx.c +0 -1
@@ -396,10 +397,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
   		return ieee80211_scan_rx(rx->sdata, skb);
 
   	if (test_bit(SCAN_SW_SCANNING,&local->scanning)) {
-		/* drop all the other packets during a software scan anyway */

net/mac80211/rx.c ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) · line 407

Quoted 10 lines
net/mac80211/rx.c +7 -2
-		if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
+		ret = ieee80211_scan_rx(rx->sdata, skb);
+		/* drop all the other packets while scanning off channel */
+		if (ret != RX_QUEUED&&
+		    test_bit(SCAN_OFF_CHANNEL,&local->scanning)) {
   			dev_kfree_skb(skb);
-		return RX_QUEUED;
+			return RX_QUEUED;
+		}
+		return ret;

Alright -- but does the mlme.c code know not to expect beacons during an on-channel scan?

Quoted 6 lines

I have a more basic question on this:

Should we just pass all packets on up the stack, regardless of whether we are offchannel or not? I think that would simplify things here,
and if/when we ever support things other than just scanning on different off-channels, that code would just work.

Quoted 6 lines

I'm not really exactly sure why we don't.

However -- I was thinking of something else, not data packets. While scanning, all received beacons will be handed to the scan code. But if the mlme code isn't told to stop looking for them, it'll still expect to see the beacons.

Currently, it seems mlme timers are stopped when we start scanning, and then started when scanning is complete.

However, I don't see any similar effort in the work_work() method when it goes off-channel.

Should we move the timer pause & restart logic into the offchannel_stop_vifs and offchannel_return methods?

If that seems like a good idea, I'll attempt that as a follow on patch.

I don't think my changes make this any worse, so not critical to add this to the current patch I'm working on.

Thanks,
Ben

Quoted 2 lines

johannes

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
maintainer
#8 lore raw
Quoted 8 lines
Quoted 5 lines

However -- I was thinking of something else, not data packets. While scanning, all received beacons will be handed to the scan code. But if the mlme code isn't told to stop looking for them, it'll still expect to see the beacons.

Currently, it seems mlme timers are stopped when we start scanning, and then started when scanning is complete.

Ok, I wasn't quite sure about that part -- whether it happened when going off-channel or when starting scan. If it happened while going off-channel this would've been problematic here.

Quoted 5 lines

However, I don't see any similar effort in the work_work() method when it goes off-channel.

Should we move the timer pause & restart logic into the offchannel_stop_vifs and offchannel_return methods?

Well, sort of no, and sort of yes -- both will disrupt that code in a sense, but even scanning on the same channel will disrupt it due to the beacon diversion, unless we copy the beacons and give them to both sides (scan and mlme)?

johannes

author
#9 lore raw
Quoted 16 lines · Johannes Berg
Quoted 8 lines
Quoted 5 lines

However -- I was thinking of something else, not data packets. While scanning, all received beacons will be handed to the scan code. But if the mlme code isn't told to stop looking for them, it'll still expect to see the beacons.

Currently, it seems mlme timers are stopped when we start scanning, and then started when scanning is complete.

Ok, I wasn't quite sure about that part -- whether it happened when going off-channel or when starting scan. If it happened while going off-channel this would've been problematic here.

Quoted 3 lines

However, I don't see any similar effort in the work_work() method when it goes off-channel.

Quoted 7 lines
Quoted 2 lines

Should we move the timer pause& restart logic into the offchannel_stop_vifs and offchannel_return methods?

Well, sort of no, and sort of yes -- both will disrupt that code in a sense, but even scanning on the same channel will disrupt it due to the beacon diversion, unless we copy the beacons and give them to both sides (scan and mlme)?

Seems to me both sides should get them. I'll try to figure out how to do that properly today.

But, if work_work() takes us off-channel often enough, wouldn't that cause undue beacon loss and/or timed-out tx acks? Are there any guarantees about how often and how long work_work() can take us off-channel?

Thanks,
Ben

Quoted 2 lines

johannes

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
maintainer
#10 lore raw
Quoted 10 lines · Ben Greear
Quoted 4 lines

Well, sort of no, and sort of yes -- both will disrupt that code in a sense, but even scanning on the same channel will disrupt it due to the beacon diversion, unless we copy the beacons and give them to both sides (scan and mlme)?

Seems to me both sides should get them. I'll try to figure out how to do that properly today.

But, if work_work() takes us off-channel often enough, wouldn't that cause undue beacon loss and/or timed-out tx acks?

Not TX ACKs really -- the device shouldn't be switching inbetween, but beacon loss yeah.

Quoted 2 lines

Are there any guarantees
about how often and how long work_work() can take us off-channel?

No, with p2p it can be quite a bit of time.

johannes