Commit ece8eddd authored by Zhu Yi's avatar Zhu Yi Committed by David S. Miller

mac80211: hardware scan rework

The scan code in mac80211 makes the software scan assumption in various
places. For example, we stop the Tx queue during a software scan so that
all the Tx packets will be queued by the stack. We also drop frames not
related to scan in the software scan process. But these are not true for
hardware scan.

Some wireless hardwares (for example iwl3945/4965) has the ability to
perform the whole scan process by hardware and/or firmware. The hardware
scan is relative powerful in that it tries to maintain normal network
traffic while doing a scan in the background. Some drivers (i.e iwlwifi)
do provide a way to tune the hardware scan parameters (for example if the
STA is associated, what's the max time could the STA leave from the
associated channel, how long the scans get suspended after returning to
the service channel, etc). But basically this is transparent to the
stack. mac80211 should not stop Tx queues or drop Rx packets during a
hardware scan.

This patch resolves the above problem by spliting the current scan
indicator local->sta_scanning into local->sta_sw_scanning and
local->sta_hw_scanning. It then changes the scan related code to be aware
of hardware scan or software scan in various places. With this patch,
iwlwifi performs much better in the scan-while-associated condition and
disable_hw_scan=1 should never be required.

Cc: Mohamed Abbas <mohamed.abbas@intel.com>
Cc: Ben Cahill <ben.m.cahill@intel.com>
Signed-off-by: default avatarZhu Yi <yi.zhu@intel.com>
Acked-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f68635e6
...@@ -350,11 +350,14 @@ static int ieee80211_stop(struct net_device *dev) ...@@ -350,11 +350,14 @@ static int ieee80211_stop(struct net_device *dev)
synchronize_rcu(); synchronize_rcu();
skb_queue_purge(&sdata->u.sta.skb_queue); skb_queue_purge(&sdata->u.sta.skb_queue);
if (!local->ops->hw_scan && if (local->scan_dev == sdata->dev) {
local->scan_dev == sdata->dev) { if (!local->ops->hw_scan) {
local->sta_scanning = 0; local->sta_sw_scanning = 0;
cancel_delayed_work(&local->scan_work); cancel_delayed_work(&local->scan_work);
} else
local->sta_hw_scanning = 0;
} }
flush_workqueue(local->hw.workqueue); flush_workqueue(local->hw.workqueue);
sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
...@@ -526,7 +529,7 @@ int ieee80211_hw_config(struct ieee80211_local *local) ...@@ -526,7 +529,7 @@ int ieee80211_hw_config(struct ieee80211_local *local)
struct ieee80211_channel *chan; struct ieee80211_channel *chan;
int ret = 0; int ret = 0;
if (local->sta_scanning) { if (local->sta_sw_scanning) {
chan = local->scan_channel; chan = local->scan_channel;
mode = local->scan_hw_mode; mode = local->scan_hw_mode;
} else { } else {
......
...@@ -470,7 +470,8 @@ struct ieee80211_local { ...@@ -470,7 +470,8 @@ struct ieee80211_local {
struct list_head interfaces; struct list_head interfaces;
int sta_scanning; bool sta_sw_scanning;
bool sta_hw_scanning;
int scan_channel_idx; int scan_channel_idx;
enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state; enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
unsigned long last_scan_completed; unsigned long last_scan_completed;
...@@ -745,7 +746,8 @@ int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len); ...@@ -745,7 +746,8 @@ int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
void ieee80211_sta_req_auth(struct net_device *dev, void ieee80211_sta_req_auth(struct net_device *dev,
struct ieee80211_if_sta *ifsta); struct ieee80211_if_sta *ifsta);
int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len); int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb, ieee80211_txrx_result ieee80211_sta_rx_scan(struct net_device *dev,
struct sk_buff *skb,
struct ieee80211_rx_status *rx_status); struct ieee80211_rx_status *rx_status);
void ieee80211_rx_bss_list_init(struct net_device *dev); void ieee80211_rx_bss_list_init(struct net_device *dev);
void ieee80211_rx_bss_list_deinit(struct net_device *dev); void ieee80211_rx_bss_list_deinit(struct net_device *dev);
......
...@@ -315,7 +315,7 @@ int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq) ...@@ -315,7 +315,7 @@ int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq)
} }
if (set) { if (set) {
if (local->sta_scanning) if (local->sta_sw_scanning)
ret = 0; ret = 0;
else else
ret = ieee80211_hw_config(local); ret = ieee80211_hw_config(local);
...@@ -545,8 +545,10 @@ static int ieee80211_ioctl_giwscan(struct net_device *dev, ...@@ -545,8 +545,10 @@ static int ieee80211_ioctl_giwscan(struct net_device *dev,
{ {
int res; int res;
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
if (local->sta_scanning)
if (local->sta_sw_scanning || local->sta_hw_scanning)
return -EAGAIN; return -EAGAIN;
res = ieee80211_sta_scan_results(dev, extra, data->length); res = ieee80211_sta_scan_results(dev, extra, data->length);
if (res >= 0) { if (res >= 0) {
data->length = res; data->length = res;
......
...@@ -1483,8 +1483,18 @@ static void ieee80211_rx_bss_info(struct net_device *dev, ...@@ -1483,8 +1483,18 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
u32 supp_rates, prev_rates; u32 supp_rates, prev_rates;
int i, j; int i, j;
mode = local->sta_scanning ? mode = local->sta_sw_scanning ?
local->scan_hw_mode : local->oper_hw_mode; local->scan_hw_mode : local->oper_hw_mode;
if (local->sta_hw_scanning) {
/* search for the correct mode matches the beacon */
list_for_each_entry(mode, &local->modes_list, list)
if (mode->mode == rx_status->phymode)
break;
if (mode == NULL)
mode = local->oper_hw_mode;
}
rates = mode->rates; rates = mode->rates;
num_rates = mode->num_rates; num_rates = mode->num_rates;
...@@ -1867,31 +1877,39 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev, ...@@ -1867,31 +1877,39 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
} }
void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb, ieee80211_txrx_result
ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
struct ieee80211_rx_status *rx_status) struct ieee80211_rx_status *rx_status)
{ {
struct ieee80211_mgmt *mgmt; struct ieee80211_mgmt *mgmt;
u16 fc; u16 fc;
if (skb->len < 24) { if (skb->len < 2)
dev_kfree_skb(skb); return TXRX_DROP;
return;
}
mgmt = (struct ieee80211_mgmt *) skb->data; mgmt = (struct ieee80211_mgmt *) skb->data;
fc = le16_to_cpu(mgmt->frame_control); fc = le16_to_cpu(mgmt->frame_control);
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
return TXRX_CONTINUE;
if (skb->len < 24)
return TXRX_DROP;
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) { if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
ieee80211_rx_mgmt_probe_resp(dev, mgmt, ieee80211_rx_mgmt_probe_resp(dev, mgmt,
skb->len, rx_status); skb->len, rx_status);
dev_kfree_skb(skb);
return TXRX_QUEUED;
} else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) { } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
rx_status); rx_status);
dev_kfree_skb(skb);
return TXRX_QUEUED;
} }
} }
return TXRX_CONTINUE;
dev_kfree_skb(skb);
} }
...@@ -1981,7 +1999,7 @@ void ieee80211_sta_work(struct work_struct *work) ...@@ -1981,7 +1999,7 @@ void ieee80211_sta_work(struct work_struct *work)
if (!netif_running(dev)) if (!netif_running(dev))
return; return;
if (local->sta_scanning) if (local->sta_sw_scanning || local->sta_hw_scanning)
return; return;
if (sdata->type != IEEE80211_IF_TYPE_STA && if (sdata->type != IEEE80211_IF_TYPE_STA &&
...@@ -2639,9 +2657,15 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw) ...@@ -2639,9 +2657,15 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
union iwreq_data wrqu; union iwreq_data wrqu;
local->last_scan_completed = jiffies; local->last_scan_completed = jiffies;
wmb(); memset(&wrqu, 0, sizeof(wrqu));
local->sta_scanning = 0; wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
if (local->sta_hw_scanning) {
local->sta_hw_scanning = 0;
goto done;
}
local->sta_sw_scanning = 0;
if (ieee80211_hw_config(local)) if (ieee80211_hw_config(local))
printk(KERN_DEBUG "%s: failed to restore operational " printk(KERN_DEBUG "%s: failed to restore operational "
"channel after scan\n", dev->name); "channel after scan\n", dev->name);
...@@ -2657,9 +2681,6 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw) ...@@ -2657,9 +2681,6 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
netif_tx_unlock_bh(local->mdev); netif_tx_unlock_bh(local->mdev);
memset(&wrqu, 0, sizeof(wrqu));
wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(sdata, &local->interfaces, list) { list_for_each_entry_rcu(sdata, &local->interfaces, list) {
...@@ -2677,6 +2698,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw) ...@@ -2677,6 +2698,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
} }
rcu_read_unlock(); rcu_read_unlock();
done:
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->type == IEEE80211_IF_TYPE_IBSS) { if (sdata->type == IEEE80211_IF_TYPE_IBSS) {
struct ieee80211_if_sta *ifsta = &sdata->u.sta; struct ieee80211_if_sta *ifsta = &sdata->u.sta;
...@@ -2699,7 +2721,7 @@ void ieee80211_sta_scan_work(struct work_struct *work) ...@@ -2699,7 +2721,7 @@ void ieee80211_sta_scan_work(struct work_struct *work)
int skip; int skip;
unsigned long next_delay = 0; unsigned long next_delay = 0;
if (!local->sta_scanning) if (!local->sta_sw_scanning)
return; return;
switch (local->scan_state) { switch (local->scan_state) {
...@@ -2762,7 +2784,7 @@ void ieee80211_sta_scan_work(struct work_struct *work) ...@@ -2762,7 +2784,7 @@ void ieee80211_sta_scan_work(struct work_struct *work)
break; break;
} }
if (local->sta_scanning) if (local->sta_sw_scanning)
queue_delayed_work(local->hw.workqueue, &local->scan_work, queue_delayed_work(local->hw.workqueue, &local->scan_work,
next_delay); next_delay);
} }
...@@ -2794,7 +2816,7 @@ static int ieee80211_sta_start_scan(struct net_device *dev, ...@@ -2794,7 +2816,7 @@ static int ieee80211_sta_start_scan(struct net_device *dev,
* ResultCode: SUCCESS, INVALID_PARAMETERS * ResultCode: SUCCESS, INVALID_PARAMETERS
*/ */
if (local->sta_scanning) { if (local->sta_sw_scanning || local->sta_hw_scanning) {
if (local->scan_dev == dev) if (local->scan_dev == dev)
return 0; return 0;
return -EBUSY; return -EBUSY;
...@@ -2804,13 +2826,13 @@ static int ieee80211_sta_start_scan(struct net_device *dev, ...@@ -2804,13 +2826,13 @@ static int ieee80211_sta_start_scan(struct net_device *dev,
int rc = local->ops->hw_scan(local_to_hw(local), int rc = local->ops->hw_scan(local_to_hw(local),
ssid, ssid_len); ssid, ssid_len);
if (!rc) { if (!rc) {
local->sta_scanning = 1; local->sta_hw_scanning = 1;
local->scan_dev = dev; local->scan_dev = dev;
} }
return rc; return rc;
} }
local->sta_scanning = 1; local->sta_sw_scanning = 1;
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(sdata, &local->interfaces, list) { list_for_each_entry_rcu(sdata, &local->interfaces, list) {
...@@ -2865,7 +2887,7 @@ int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len) ...@@ -2865,7 +2887,7 @@ int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
if (sdata->type != IEEE80211_IF_TYPE_STA) if (sdata->type != IEEE80211_IF_TYPE_STA)
return ieee80211_sta_start_scan(dev, ssid, ssid_len); return ieee80211_sta_start_scan(dev, ssid, ssid_len);
if (local->sta_scanning) { if (local->sta_sw_scanning || local->sta_hw_scanning) {
if (local->scan_dev == dev) if (local->scan_dev == dev)
return 0; return 0;
return -EBUSY; return -EBUSY;
......
...@@ -338,8 +338,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx) ...@@ -338,8 +338,14 @@ ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
struct ieee80211_local *local = rx->local; struct ieee80211_local *local = rx->local;
struct sk_buff *skb = rx->skb; struct sk_buff *skb = rx->skb;
if (unlikely(local->sta_scanning != 0)) { if (unlikely(local->sta_hw_scanning))
ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status); return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
if (unlikely(local->sta_sw_scanning)) {
/* drop all the other packets during a software scan anyway */
if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status)
!= TXRX_QUEUED)
dev_kfree_skb(skb);
return TXRX_QUEUED; return TXRX_QUEUED;
} }
...@@ -1499,7 +1505,7 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, ...@@ -1499,7 +1505,7 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
goto end; goto end;
} }
if (unlikely(local->sta_scanning)) if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
rx.flags |= IEEE80211_TXRXD_RXIN_SCAN; rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx, if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
......
...@@ -225,7 +225,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx) ...@@ -225,7 +225,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
if (unlikely(tx->flags & IEEE80211_TXRXD_TX_INJECTED)) if (unlikely(tx->flags & IEEE80211_TXRXD_TX_INJECTED))
return TXRX_CONTINUE; return TXRX_CONTINUE;
if (unlikely(tx->local->sta_scanning != 0) && if (unlikely(tx->local->sta_sw_scanning) &&
((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || ((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
(tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ)) (tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ))
return TXRX_DROP; return TXRX_DROP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment