Commit 8f1ba8b0 authored by Benjamin Li's avatar Benjamin Li Committed by Kalle Valo

wcn36xx: ensure pairing of init_scan/finish_scan and start_scan/end_scan

An SMD capture from the downstream prima driver on WCN3680B shows the
following command sequence for connected scans:

- init_scan_req
    - start_scan_req, channel 1
    - end_scan_req, channel 1
    - start_scan_req, channel 2
    - ...
    - end_scan_req, channel 3
- finish_scan_req
- init_scan_req
    - start_scan_req, channel 4
    - ...
    - end_scan_req, channel 6
- finish_scan_req
- ...
    - end_scan_req, channel 165
- finish_scan_req

Upstream currently never calls wcn36xx_smd_end_scan, and in some cases[1]
still sends finish_scan_req twice in a row or before init_scan_req. A
typical connected scan looks like this:

- init_scan_req
    - start_scan_req, channel 1
- finish_scan_req
- init_scan_req
    - start_scan_req, channel 2
- ...
    - start_scan_req, channel 165
- finish_scan_req
- finish_scan_req

This patch cleans up scanning so that init/finish and start/end are always
paired together and correctly nested.

- init_scan_req
    - start_scan_req, channel 1
    - end_scan_req, channel 1
- finish_scan_req
- init_scan_req
    - start_scan_req, channel 2
    - end_scan_req, channel 2
- ...
    - start_scan_req, channel 165
    - end_scan_req, channel 165
- finish_scan_req

Note that upstream will not do batching of 3 active-probe scans before
returning to the operating channel, and this patch does not change that.
To match downstream in this aspect, adjust IEEE80211_PROBE_DELAY and/or
the 125ms max off-channel time in ieee80211_scan_state_decision.

[1]: commit d195d7aa ("wcn36xx: Ensure finish scan is not requested
before start scan") addressed one case of finish_scan_req being sent
without a preceding init_scan_req (the case of the operating channel
coinciding with the first scan channel); two other cases are:
1) if SW scan is started and aborted immediately, without scanning any
   channels, we send a finish_scan_req without ever sending init_scan_req,
   and
2) as SW scan logic always returns us to the operating channel before
   calling wcn36xx_sw_scan_complete, finish_scan_req is always sent twice
   at the end of a SW scan

Fixes: 8e84c258 ("wcn36xx: mac80211 driver for Qualcomm WCN3660/WCN3680 hardware")
Signed-off-by: default avatarBenjamin Li <benl@squareup.com>
Tested-by: default avatarBryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20211027170306.555535-4-benl@squareup.com
parent f02e1cc2
...@@ -402,6 +402,7 @@ static void wcn36xx_change_opchannel(struct wcn36xx *wcn, int ch) ...@@ -402,6 +402,7 @@ static void wcn36xx_change_opchannel(struct wcn36xx *wcn, int ch)
static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed) static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
{ {
struct wcn36xx *wcn = hw->priv; struct wcn36xx *wcn = hw->priv;
int ret;
wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed); wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
...@@ -417,17 +418,31 @@ static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed) ...@@ -417,17 +418,31 @@ static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
* want to receive/transmit regular data packets, then * want to receive/transmit regular data packets, then
* simply stop the scan session and exit PS mode. * simply stop the scan session and exit PS mode.
*/ */
if (wcn->sw_scan_channel)
wcn36xx_smd_end_scan(wcn, wcn->sw_scan_channel);
if (wcn->sw_scan_init) {
wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN, wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN,
wcn->sw_scan_vif); wcn->sw_scan_vif);
wcn->sw_scan_channel = 0; }
} else if (wcn->sw_scan) { } else if (wcn->sw_scan) {
/* A scan is ongoing, do not change the operating /* A scan is ongoing, do not change the operating
* channel, but start a scan session on the channel. * channel, but start a scan session on the channel.
*/ */
wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN, if (wcn->sw_scan_channel)
wcn36xx_smd_end_scan(wcn, wcn->sw_scan_channel);
if (!wcn->sw_scan_init) {
/* This can fail if we are unable to notify the
* operating channel.
*/
ret = wcn36xx_smd_init_scan(wcn,
HAL_SYS_MODE_SCAN,
wcn->sw_scan_vif); wcn->sw_scan_vif);
if (ret) {
mutex_unlock(&wcn->conf_mutex);
return -EIO;
}
}
wcn36xx_smd_start_scan(wcn, ch); wcn36xx_smd_start_scan(wcn, ch);
wcn->sw_scan_channel = ch;
} else { } else {
wcn36xx_change_opchannel(wcn, ch); wcn36xx_change_opchannel(wcn, ch);
} }
...@@ -726,7 +741,12 @@ static void wcn36xx_sw_scan_complete(struct ieee80211_hw *hw, ...@@ -726,7 +741,12 @@ static void wcn36xx_sw_scan_complete(struct ieee80211_hw *hw,
wcn36xx_dbg(WCN36XX_DBG_MAC, "sw_scan_complete"); wcn36xx_dbg(WCN36XX_DBG_MAC, "sw_scan_complete");
/* ensure that any scan session is finished */ /* ensure that any scan session is finished */
wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN, wcn->sw_scan_vif); if (wcn->sw_scan_channel)
wcn36xx_smd_end_scan(wcn, wcn->sw_scan_channel);
if (wcn->sw_scan_init) {
wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN,
wcn->sw_scan_vif);
}
wcn->sw_scan = false; wcn->sw_scan = false;
wcn->sw_scan_opchannel = 0; wcn->sw_scan_opchannel = 0;
} }
......
...@@ -722,6 +722,7 @@ int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode, ...@@ -722,6 +722,7 @@ int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode,
wcn36xx_err("hal_init_scan response failed err=%d\n", ret); wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
goto out; goto out;
} }
wcn->sw_scan_init = true;
out: out:
mutex_unlock(&wcn->hal_mutex); mutex_unlock(&wcn->hal_mutex);
return ret; return ret;
...@@ -752,6 +753,7 @@ int wcn36xx_smd_start_scan(struct wcn36xx *wcn, u8 scan_channel) ...@@ -752,6 +753,7 @@ int wcn36xx_smd_start_scan(struct wcn36xx *wcn, u8 scan_channel)
wcn36xx_err("hal_start_scan response failed err=%d\n", ret); wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
goto out; goto out;
} }
wcn->sw_scan_channel = scan_channel;
out: out:
mutex_unlock(&wcn->hal_mutex); mutex_unlock(&wcn->hal_mutex);
return ret; return ret;
...@@ -782,6 +784,7 @@ int wcn36xx_smd_end_scan(struct wcn36xx *wcn, u8 scan_channel) ...@@ -782,6 +784,7 @@ int wcn36xx_smd_end_scan(struct wcn36xx *wcn, u8 scan_channel)
wcn36xx_err("hal_end_scan response failed err=%d\n", ret); wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
goto out; goto out;
} }
wcn->sw_scan_channel = 0;
out: out:
mutex_unlock(&wcn->hal_mutex); mutex_unlock(&wcn->hal_mutex);
return ret; return ret;
...@@ -823,6 +826,7 @@ int wcn36xx_smd_finish_scan(struct wcn36xx *wcn, ...@@ -823,6 +826,7 @@ int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
wcn36xx_err("hal_finish_scan response failed err=%d\n", ret); wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
goto out; goto out;
} }
wcn->sw_scan_init = false;
out: out:
mutex_unlock(&wcn->hal_mutex); mutex_unlock(&wcn->hal_mutex);
return ret; return ret;
......
...@@ -248,6 +248,7 @@ struct wcn36xx { ...@@ -248,6 +248,7 @@ struct wcn36xx {
struct cfg80211_scan_request *scan_req; struct cfg80211_scan_request *scan_req;
bool sw_scan; bool sw_scan;
u8 sw_scan_opchannel; u8 sw_scan_opchannel;
bool sw_scan_init;
u8 sw_scan_channel; u8 sw_scan_channel;
struct ieee80211_vif *sw_scan_vif; struct ieee80211_vif *sw_scan_vif;
struct mutex scan_lock; struct mutex scan_lock;
......
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