aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Kazior <michal.kazior@tieto.com>2014-08-05 08:54:44 -0400
committerKalle Valo <kvalo@qca.qualcomm.com>2014-08-12 03:47:48 -0400
commit5c81c7fd62004be13a3c9345ca25607d14862cc4 (patch)
tree49826629326a55210f514427776fdc39fa8c51fb
parent9ff8b7247dd211158410af4bb5ebbc507182729f (diff)
ath10k: introduce a stricter scan state machine
This aims at fixing some rare scan bugs related to firmware reporting unexpected scan event sequences. One such bug was if spectral scan phyerr reporting prevented firmware from properly propagating scan events to host. This led to scan timeout. After that next scan would trigger scan completed event first (before scan started event) leading to ar->scan.in_progress and timeout timer states to be overwritten incorrectly and making the very next scan to hang forever. Reported-by: Janusz Dziedzic <janusz.dziedzic@tieto.com> Signed-off-by: Michal Kazior <michal.kazior@tieto.com> Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
-rw-r--r--drivers/net/wireless/ath/ath10k/core.c5
-rw-r--r--drivers/net/wireless/ath/ath10k/core.h28
-rw-r--r--drivers/net/wireless/ath/ath10k/mac.c238
-rw-r--r--drivers/net/wireless/ath/ath10k/mac.h4
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.c143
5 files changed, 281 insertions, 137 deletions
diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
index 440c3ff03aec..c090913d10d1 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -665,8 +665,7 @@ static void ath10k_core_restart(struct work_struct *work)
665 switch (ar->state) { 665 switch (ar->state) {
666 case ATH10K_STATE_ON: 666 case ATH10K_STATE_ON:
667 ar->state = ATH10K_STATE_RESTARTING; 667 ar->state = ATH10K_STATE_RESTARTING;
668 del_timer_sync(&ar->scan.timeout); 668 ath10k_scan_finish(ar);
669 ath10k_reset_scan((unsigned long)ar);
670 ieee80211_restart_hw(ar->hw); 669 ieee80211_restart_hw(ar->hw);
671 break; 670 break;
672 case ATH10K_STATE_OFF: 671 case ATH10K_STATE_OFF:
@@ -1086,7 +1085,7 @@ struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
1086 init_completion(&ar->install_key_done); 1085 init_completion(&ar->install_key_done);
1087 init_completion(&ar->vdev_setup_done); 1086 init_completion(&ar->vdev_setup_done);
1088 1087
1089 setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar); 1088 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1090 1089
1091 ar->workqueue = create_singlethread_workqueue("ath10k_wq"); 1090 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1092 if (!ar->workqueue) 1091 if (!ar->workqueue)
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index 94b1ff2082cf..95c611db43b8 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -348,6 +348,29 @@ enum ath10k_dev_flags {
348 ATH10K_FLAG_CORE_REGISTERED, 348 ATH10K_FLAG_CORE_REGISTERED,
349}; 349};
350 350
351enum ath10k_scan_state {
352 ATH10K_SCAN_IDLE,
353 ATH10K_SCAN_STARTING,
354 ATH10K_SCAN_RUNNING,
355 ATH10K_SCAN_ABORTING,
356};
357
358static inline const char *ath10k_scan_state_str(enum ath10k_scan_state state)
359{
360 switch (state) {
361 case ATH10K_SCAN_IDLE:
362 return "idle";
363 case ATH10K_SCAN_STARTING:
364 return "starting";
365 case ATH10K_SCAN_RUNNING:
366 return "running";
367 case ATH10K_SCAN_ABORTING:
368 return "aborting";
369 }
370
371 return "unknown";
372}
373
351struct ath10k { 374struct ath10k {
352 struct ath_common ath_common; 375 struct ath_common ath_common;
353 struct ieee80211_hw *hw; 376 struct ieee80211_hw *hw;
@@ -417,10 +440,9 @@ struct ath10k {
417 struct completion started; 440 struct completion started;
418 struct completion completed; 441 struct completion completed;
419 struct completion on_channel; 442 struct completion on_channel;
420 struct timer_list timeout; 443 struct delayed_work timeout;
444 enum ath10k_scan_state state;
421 bool is_roc; 445 bool is_roc;
422 bool in_progress;
423 bool aborting;
424 int vdev_id; 446 int vdev_id;
425 int roc_freq; 447 int roc_freq;
426 } scan; 448 } scan;
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index 3c7942030361..3bf7ddeb3271 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -2159,34 +2159,40 @@ void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2159/* Scanning */ 2159/* Scanning */
2160/************/ 2160/************/
2161 2161
2162/* 2162void __ath10k_scan_finish(struct ath10k *ar)
2163 * This gets called if we dont get a heart-beat during scan.
2164 * This may indicate the FW has hung and we need to abort the
2165 * scan manually to prevent cancel_hw_scan() from deadlocking
2166 */
2167void ath10k_reset_scan(unsigned long ptr)
2168{ 2163{
2169 struct ath10k *ar = (struct ath10k *)ptr; 2164 lockdep_assert_held(&ar->data_lock);
2170 2165
2171 spin_lock_bh(&ar->data_lock); 2166 switch (ar->scan.state) {
2172 if (!ar->scan.in_progress) { 2167 case ATH10K_SCAN_IDLE:
2173 spin_unlock_bh(&ar->data_lock); 2168 break;
2174 return; 2169 case ATH10K_SCAN_RUNNING:
2170 case ATH10K_SCAN_ABORTING:
2171 if (ar->scan.is_roc)
2172 ieee80211_remain_on_channel_expired(ar->hw);
2173 else
2174 ieee80211_scan_completed(ar->hw,
2175 (ar->scan.state ==
2176 ATH10K_SCAN_ABORTING));
2177 /* fall through */
2178 case ATH10K_SCAN_STARTING:
2179 ar->scan.state = ATH10K_SCAN_IDLE;
2180 ar->scan_channel = NULL;
2181 ath10k_offchan_tx_purge(ar);
2182 cancel_delayed_work(&ar->scan.timeout);
2183 complete_all(&ar->scan.completed);
2184 break;
2175 } 2185 }
2186}
2176 2187
2177 ath10k_warn("scan timed out, firmware problem?\n"); 2188void ath10k_scan_finish(struct ath10k *ar)
2178 2189{
2179 if (ar->scan.is_roc) 2190 spin_lock_bh(&ar->data_lock);
2180 ieee80211_remain_on_channel_expired(ar->hw); 2191 __ath10k_scan_finish(ar);
2181 else
2182 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2183
2184 ar->scan.in_progress = false;
2185 complete_all(&ar->scan.completed);
2186 spin_unlock_bh(&ar->data_lock); 2192 spin_unlock_bh(&ar->data_lock);
2187} 2193}
2188 2194
2189static int ath10k_abort_scan(struct ath10k *ar) 2195static int ath10k_scan_stop(struct ath10k *ar)
2190{ 2196{
2191 struct wmi_stop_scan_arg arg = { 2197 struct wmi_stop_scan_arg arg = {
2192 .req_id = 1, /* FIXME */ 2198 .req_id = 1, /* FIXME */
@@ -2197,47 +2203,79 @@ static int ath10k_abort_scan(struct ath10k *ar)
2197 2203
2198 lockdep_assert_held(&ar->conf_mutex); 2204 lockdep_assert_held(&ar->conf_mutex);
2199 2205
2200 del_timer_sync(&ar->scan.timeout);
2201
2202 spin_lock_bh(&ar->data_lock);
2203 if (!ar->scan.in_progress) {
2204 spin_unlock_bh(&ar->data_lock);
2205 return 0;
2206 }
2207
2208 ar->scan.aborting = true;
2209 spin_unlock_bh(&ar->data_lock);
2210
2211 ret = ath10k_wmi_stop_scan(ar, &arg); 2206 ret = ath10k_wmi_stop_scan(ar, &arg);
2212 if (ret) { 2207 if (ret) {
2213 ath10k_warn("failed to stop wmi scan: %d\n", ret); 2208 ath10k_warn("failed to stop wmi scan: %d\n", ret);
2214 spin_lock_bh(&ar->data_lock); 2209 goto out;
2215 ar->scan.in_progress = false;
2216 ath10k_offchan_tx_purge(ar);
2217 spin_unlock_bh(&ar->data_lock);
2218 return -EIO;
2219 } 2210 }
2220 2211
2221 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ); 2212 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2222 if (ret == 0) 2213 if (ret == 0) {
2223 ath10k_warn("timed out while waiting for scan to stop\n"); 2214 ath10k_warn("failed to receive scan abortion completion: timed out\n");
2215 ret = -ETIMEDOUT;
2216 } else if (ret > 0) {
2217 ret = 0;
2218 }
2224 2219
2225 /* scan completion may be done right after we timeout here, so let's 2220out:
2226 * check the in_progress and tell mac80211 scan is completed. if we 2221 /* Scan state should be updated upon scan completion but in case
2227 * don't do that and FW fails to send us scan completion indication 2222 * firmware fails to deliver the event (for whatever reason) it is
2228 * then userspace won't be able to scan anymore */ 2223 * desired to clean up scan state anyway. Firmware may have just
2229 ret = 0; 2224 * dropped the scan completion event delivery due to transport pipe
2225 * being overflown with data and/or it can recover on its own before
2226 * next scan request is submitted.
2227 */
2228 spin_lock_bh(&ar->data_lock);
2229 if (ar->scan.state != ATH10K_SCAN_IDLE)
2230 __ath10k_scan_finish(ar);
2231 spin_unlock_bh(&ar->data_lock);
2232
2233 return ret;
2234}
2235
2236static void ath10k_scan_abort(struct ath10k *ar)
2237{
2238 int ret;
2239
2240 lockdep_assert_held(&ar->conf_mutex);
2230 2241
2231 spin_lock_bh(&ar->data_lock); 2242 spin_lock_bh(&ar->data_lock);
2232 if (ar->scan.in_progress) { 2243
2233 ath10k_warn("failed to stop scan, it's still in progress\n"); 2244 switch (ar->scan.state) {
2234 ar->scan.in_progress = false; 2245 case ATH10K_SCAN_IDLE:
2235 ath10k_offchan_tx_purge(ar); 2246 /* This can happen if timeout worker kicked in and called
2236 ret = -ETIMEDOUT; 2247 * abortion while scan completion was being processed.
2248 */
2249 break;
2250 case ATH10K_SCAN_STARTING:
2251 case ATH10K_SCAN_ABORTING:
2252 ath10k_warn("refusing scan abortion due to invalid scan state: %s (%d)\n",
2253 ath10k_scan_state_str(ar->scan.state),
2254 ar->scan.state);
2255 break;
2256 case ATH10K_SCAN_RUNNING:
2257 ar->scan.state = ATH10K_SCAN_ABORTING;
2258 spin_unlock_bh(&ar->data_lock);
2259
2260 ret = ath10k_scan_stop(ar);
2261 if (ret)
2262 ath10k_warn("failed to abort scan: %d\n", ret);
2263
2264 spin_lock_bh(&ar->data_lock);
2265 break;
2237 } 2266 }
2267
2238 spin_unlock_bh(&ar->data_lock); 2268 spin_unlock_bh(&ar->data_lock);
2269}
2239 2270
2240 return ret; 2271void ath10k_scan_timeout_work(struct work_struct *work)
2272{
2273 struct ath10k *ar = container_of(work, struct ath10k,
2274 scan.timeout.work);
2275
2276 mutex_lock(&ar->conf_mutex);
2277 ath10k_scan_abort(ar);
2278 mutex_unlock(&ar->conf_mutex);
2241} 2279}
2242 2280
2243static int ath10k_start_scan(struct ath10k *ar, 2281static int ath10k_start_scan(struct ath10k *ar,
@@ -2253,17 +2291,16 @@ static int ath10k_start_scan(struct ath10k *ar,
2253 2291
2254 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ); 2292 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2255 if (ret == 0) { 2293 if (ret == 0) {
2256 ath10k_abort_scan(ar); 2294 ret = ath10k_scan_stop(ar);
2257 return ret; 2295 if (ret)
2296 ath10k_warn("failed to stop scan: %d\n", ret);
2297
2298 return -ETIMEDOUT;
2258 } 2299 }
2259 2300
2260 /* the scan can complete earlier, before we even 2301 /* Add a 200ms margin to account for event/command processing */
2261 * start the timer. in that case the timer handler 2302 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2262 * checks ar->scan.in_progress and bails out if its 2303 msecs_to_jiffies(arg->max_scan_time+200));
2263 * false. Add a 200ms margin to account event/command
2264 * processing. */
2265 mod_timer(&ar->scan.timeout, jiffies +
2266 msecs_to_jiffies(arg->max_scan_time+200));
2267 return 0; 2304 return 0;
2268} 2305}
2269 2306
@@ -2339,8 +2376,7 @@ void ath10k_halt(struct ath10k *ar)
2339 ath10k_monitor_stop(ar); 2376 ath10k_monitor_stop(ar);
2340 } 2377 }
2341 2378
2342 del_timer_sync(&ar->scan.timeout); 2379 ath10k_scan_finish(ar);
2343 ath10k_reset_scan((unsigned long)ar);
2344 ath10k_peer_cleanup_all(ar); 2380 ath10k_peer_cleanup_all(ar);
2345 ath10k_core_stop(ar); 2381 ath10k_core_stop(ar);
2346 ath10k_hif_power_down(ar); 2382 ath10k_hif_power_down(ar);
@@ -2531,6 +2567,7 @@ static void ath10k_stop(struct ieee80211_hw *hw)
2531 } 2567 }
2532 mutex_unlock(&ar->conf_mutex); 2568 mutex_unlock(&ar->conf_mutex);
2533 2569
2570 cancel_delayed_work_sync(&ar->scan.timeout);
2534 cancel_work_sync(&ar->restart_work); 2571 cancel_work_sync(&ar->restart_work);
2535} 2572}
2536 2573
@@ -3176,20 +3213,26 @@ static int ath10k_hw_scan(struct ieee80211_hw *hw,
3176 mutex_lock(&ar->conf_mutex); 3213 mutex_lock(&ar->conf_mutex);
3177 3214
3178 spin_lock_bh(&ar->data_lock); 3215 spin_lock_bh(&ar->data_lock);
3179 if (ar->scan.in_progress) { 3216 switch (ar->scan.state) {
3180 spin_unlock_bh(&ar->data_lock); 3217 case ATH10K_SCAN_IDLE:
3218 reinit_completion(&ar->scan.started);
3219 reinit_completion(&ar->scan.completed);
3220 ar->scan.state = ATH10K_SCAN_STARTING;
3221 ar->scan.is_roc = false;
3222 ar->scan.vdev_id = arvif->vdev_id;
3223 ret = 0;
3224 break;
3225 case ATH10K_SCAN_STARTING:
3226 case ATH10K_SCAN_RUNNING:
3227 case ATH10K_SCAN_ABORTING:
3181 ret = -EBUSY; 3228 ret = -EBUSY;
3182 goto exit; 3229 break;
3183 } 3230 }
3184
3185 reinit_completion(&ar->scan.started);
3186 reinit_completion(&ar->scan.completed);
3187 ar->scan.in_progress = true;
3188 ar->scan.aborting = false;
3189 ar->scan.is_roc = false;
3190 ar->scan.vdev_id = arvif->vdev_id;
3191 spin_unlock_bh(&ar->data_lock); 3231 spin_unlock_bh(&ar->data_lock);
3192 3232
3233 if (ret)
3234 goto exit;
3235
3193 memset(&arg, 0, sizeof(arg)); 3236 memset(&arg, 0, sizeof(arg));
3194 ath10k_wmi_start_scan_init(ar, &arg); 3237 ath10k_wmi_start_scan_init(ar, &arg);
3195 arg.vdev_id = arvif->vdev_id; 3238 arg.vdev_id = arvif->vdev_id;
@@ -3223,7 +3266,7 @@ static int ath10k_hw_scan(struct ieee80211_hw *hw,
3223 if (ret) { 3266 if (ret) {
3224 ath10k_warn("failed to start hw scan: %d\n", ret); 3267 ath10k_warn("failed to start hw scan: %d\n", ret);
3225 spin_lock_bh(&ar->data_lock); 3268 spin_lock_bh(&ar->data_lock);
3226 ar->scan.in_progress = false; 3269 ar->scan.state = ATH10K_SCAN_IDLE;
3227 spin_unlock_bh(&ar->data_lock); 3270 spin_unlock_bh(&ar->data_lock);
3228 } 3271 }
3229 3272
@@ -3236,14 +3279,10 @@ static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3236 struct ieee80211_vif *vif) 3279 struct ieee80211_vif *vif)
3237{ 3280{
3238 struct ath10k *ar = hw->priv; 3281 struct ath10k *ar = hw->priv;
3239 int ret;
3240 3282
3241 mutex_lock(&ar->conf_mutex); 3283 mutex_lock(&ar->conf_mutex);
3242 ret = ath10k_abort_scan(ar); 3284 cancel_delayed_work_sync(&ar->scan.timeout);
3243 if (ret) { 3285 ath10k_scan_abort(ar);
3244 ath10k_warn("failed to abort scan: %d\n", ret);
3245 ieee80211_scan_completed(hw, 1 /* aborted */);
3246 }
3247 mutex_unlock(&ar->conf_mutex); 3286 mutex_unlock(&ar->conf_mutex);
3248} 3287}
3249 3288
@@ -3666,27 +3705,33 @@ static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3666 struct ath10k *ar = hw->priv; 3705 struct ath10k *ar = hw->priv;
3667 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); 3706 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3668 struct wmi_start_scan_arg arg; 3707 struct wmi_start_scan_arg arg;
3669 int ret; 3708 int ret = 0;
3670 3709
3671 mutex_lock(&ar->conf_mutex); 3710 mutex_lock(&ar->conf_mutex);
3672 3711
3673 spin_lock_bh(&ar->data_lock); 3712 spin_lock_bh(&ar->data_lock);
3674 if (ar->scan.in_progress) { 3713 switch (ar->scan.state) {
3675 spin_unlock_bh(&ar->data_lock); 3714 case ATH10K_SCAN_IDLE:
3715 reinit_completion(&ar->scan.started);
3716 reinit_completion(&ar->scan.completed);
3717 reinit_completion(&ar->scan.on_channel);
3718 ar->scan.state = ATH10K_SCAN_STARTING;
3719 ar->scan.is_roc = true;
3720 ar->scan.vdev_id = arvif->vdev_id;
3721 ar->scan.roc_freq = chan->center_freq;
3722 ret = 0;
3723 break;
3724 case ATH10K_SCAN_STARTING:
3725 case ATH10K_SCAN_RUNNING:
3726 case ATH10K_SCAN_ABORTING:
3676 ret = -EBUSY; 3727 ret = -EBUSY;
3677 goto exit; 3728 break;
3678 } 3729 }
3679
3680 reinit_completion(&ar->scan.started);
3681 reinit_completion(&ar->scan.completed);
3682 reinit_completion(&ar->scan.on_channel);
3683 ar->scan.in_progress = true;
3684 ar->scan.aborting = false;
3685 ar->scan.is_roc = true;
3686 ar->scan.vdev_id = arvif->vdev_id;
3687 ar->scan.roc_freq = chan->center_freq;
3688 spin_unlock_bh(&ar->data_lock); 3730 spin_unlock_bh(&ar->data_lock);
3689 3731
3732 if (ret)
3733 goto exit;
3734
3690 memset(&arg, 0, sizeof(arg)); 3735 memset(&arg, 0, sizeof(arg));
3691 ath10k_wmi_start_scan_init(ar, &arg); 3736 ath10k_wmi_start_scan_init(ar, &arg);
3692 arg.vdev_id = arvif->vdev_id; 3737 arg.vdev_id = arvif->vdev_id;
@@ -3703,7 +3748,7 @@ static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3703 if (ret) { 3748 if (ret) {
3704 ath10k_warn("failed to start roc scan: %d\n", ret); 3749 ath10k_warn("failed to start roc scan: %d\n", ret);
3705 spin_lock_bh(&ar->data_lock); 3750 spin_lock_bh(&ar->data_lock);
3706 ar->scan.in_progress = false; 3751 ar->scan.state = ATH10K_SCAN_IDLE;
3707 spin_unlock_bh(&ar->data_lock); 3752 spin_unlock_bh(&ar->data_lock);
3708 goto exit; 3753 goto exit;
3709 } 3754 }
@@ -3711,7 +3756,11 @@ static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3711 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ); 3756 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3712 if (ret == 0) { 3757 if (ret == 0) {
3713 ath10k_warn("failed to switch to channel for roc scan\n"); 3758 ath10k_warn("failed to switch to channel for roc scan\n");
3714 ath10k_abort_scan(ar); 3759
3760 ret = ath10k_scan_stop(ar);
3761 if (ret)
3762 ath10k_warn("failed to stop scan: %d\n", ret);
3763
3715 ret = -ETIMEDOUT; 3764 ret = -ETIMEDOUT;
3716 goto exit; 3765 goto exit;
3717 } 3766 }
@@ -3727,7 +3776,8 @@ static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3727 struct ath10k *ar = hw->priv; 3776 struct ath10k *ar = hw->priv;
3728 3777
3729 mutex_lock(&ar->conf_mutex); 3778 mutex_lock(&ar->conf_mutex);
3730 ath10k_abort_scan(ar); 3779 cancel_delayed_work_sync(&ar->scan.timeout);
3780 ath10k_scan_abort(ar);
3731 mutex_unlock(&ar->conf_mutex); 3781 mutex_unlock(&ar->conf_mutex);
3732 3782
3733 return 0; 3783 return 0;
diff --git a/drivers/net/wireless/ath/ath10k/mac.h b/drivers/net/wireless/ath/ath10k/mac.h
index ef4f84376d7c..e64fce70e9eb 100644
--- a/drivers/net/wireless/ath/ath10k/mac.h
+++ b/drivers/net/wireless/ath/ath10k/mac.h
@@ -31,7 +31,9 @@ void ath10k_mac_destroy(struct ath10k *ar);
31int ath10k_mac_register(struct ath10k *ar); 31int ath10k_mac_register(struct ath10k *ar);
32void ath10k_mac_unregister(struct ath10k *ar); 32void ath10k_mac_unregister(struct ath10k *ar);
33struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id); 33struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id);
34void ath10k_reset_scan(unsigned long ptr); 34void __ath10k_scan_finish(struct ath10k *ar);
35void ath10k_scan_finish(struct ath10k *ar);
36void ath10k_scan_timeout_work(struct work_struct *work);
35void ath10k_offchan_tx_purge(struct ath10k *ar); 37void ath10k_offchan_tx_purge(struct ath10k *ar);
36void ath10k_offchan_tx_work(struct work_struct *work); 38void ath10k_offchan_tx_work(struct work_struct *work);
37void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar); 39void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar);
diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
index f48f29563a4d..23acbadeb8fa 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -811,6 +811,94 @@ int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
811 return ret; 811 return ret;
812} 812}
813 813
814static void ath10k_wmi_event_scan_started(struct ath10k *ar)
815{
816 lockdep_assert_held(&ar->data_lock);
817
818 switch (ar->scan.state) {
819 case ATH10K_SCAN_IDLE:
820 case ATH10K_SCAN_RUNNING:
821 case ATH10K_SCAN_ABORTING:
822 ath10k_warn("received scan started event in an invalid scan state: %s (%d)\n",
823 ath10k_scan_state_str(ar->scan.state),
824 ar->scan.state);
825 break;
826 case ATH10K_SCAN_STARTING:
827 ar->scan.state = ATH10K_SCAN_RUNNING;
828
829 if (ar->scan.is_roc)
830 ieee80211_ready_on_channel(ar->hw);
831
832 complete(&ar->scan.started);
833 break;
834 }
835}
836
837static void ath10k_wmi_event_scan_completed(struct ath10k *ar)
838{
839 lockdep_assert_held(&ar->data_lock);
840
841 switch (ar->scan.state) {
842 case ATH10K_SCAN_IDLE:
843 case ATH10K_SCAN_STARTING:
844 /* One suspected reason scan can be completed while starting is
845 * if firmware fails to deliver all scan events to the host,
846 * e.g. when transport pipe is full. This has been observed
847 * with spectral scan phyerr events starving wmi transport
848 * pipe. In such case the "scan completed" event should be (and
849 * is) ignored by the host as it may be just firmware's scan
850 * state machine recovering.
851 */
852 ath10k_warn("received scan completed event in an invalid scan state: %s (%d)\n",
853 ath10k_scan_state_str(ar->scan.state),
854 ar->scan.state);
855 break;
856 case ATH10K_SCAN_RUNNING:
857 case ATH10K_SCAN_ABORTING:
858 __ath10k_scan_finish(ar);
859 break;
860 }
861}
862
863static void ath10k_wmi_event_scan_bss_chan(struct ath10k *ar)
864{
865 lockdep_assert_held(&ar->data_lock);
866
867 switch (ar->scan.state) {
868 case ATH10K_SCAN_IDLE:
869 case ATH10K_SCAN_STARTING:
870 ath10k_warn("received scan bss chan event in an invalid scan state: %s (%d)\n",
871 ath10k_scan_state_str(ar->scan.state),
872 ar->scan.state);
873 break;
874 case ATH10K_SCAN_RUNNING:
875 case ATH10K_SCAN_ABORTING:
876 ar->scan_channel = NULL;
877 break;
878 }
879}
880
881static void ath10k_wmi_event_scan_foreign_chan(struct ath10k *ar, u32 freq)
882{
883 lockdep_assert_held(&ar->data_lock);
884
885 switch (ar->scan.state) {
886 case ATH10K_SCAN_IDLE:
887 case ATH10K_SCAN_STARTING:
888 ath10k_warn("received scan foreign chan event in an invalid scan state: %s (%d)\n",
889 ath10k_scan_state_str(ar->scan.state),
890 ar->scan.state);
891 break;
892 case ATH10K_SCAN_RUNNING:
893 case ATH10K_SCAN_ABORTING:
894 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
895
896 if (ar->scan.is_roc && ar->scan.roc_freq == freq)
897 complete(&ar->scan.on_channel);
898 break;
899 }
900}
901
814static const char * 902static const char *
815ath10k_wmi_event_scan_type_str(enum wmi_scan_event_type type, 903ath10k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
816 enum wmi_scan_completion_reason reason) 904 enum wmi_scan_completion_reason reason)
@@ -864,54 +952,32 @@ static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
864 scan_id = __le32_to_cpu(event->scan_id); 952 scan_id = __le32_to_cpu(event->scan_id);
865 vdev_id = __le32_to_cpu(event->vdev_id); 953 vdev_id = __le32_to_cpu(event->vdev_id);
866 954
955 spin_lock_bh(&ar->data_lock);
956
867 ath10k_dbg(ATH10K_DBG_WMI, 957 ath10k_dbg(ATH10K_DBG_WMI,
868 "scan event %s type %d reason %d freq %d req_id %d " 958 "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
869 "scan_id %d vdev_id %d\n",
870 ath10k_wmi_event_scan_type_str(event_type, reason), 959 ath10k_wmi_event_scan_type_str(event_type, reason),
871 event_type, reason, freq, req_id, scan_id, vdev_id); 960 event_type, reason, freq, req_id, scan_id, vdev_id,
872 961 ath10k_scan_state_str(ar->scan.state), ar->scan.state);
873 spin_lock_bh(&ar->data_lock);
874 962
875 switch (event_type) { 963 switch (event_type) {
876 case WMI_SCAN_EVENT_STARTED: 964 case WMI_SCAN_EVENT_STARTED:
877 if (ar->scan.in_progress && ar->scan.is_roc) 965 ath10k_wmi_event_scan_started(ar);
878 ieee80211_ready_on_channel(ar->hw);
879
880 complete(&ar->scan.started);
881 break; 966 break;
882 case WMI_SCAN_EVENT_COMPLETED: 967 case WMI_SCAN_EVENT_COMPLETED:
883 ar->scan_channel = NULL; 968 ath10k_wmi_event_scan_completed(ar);
884 if (!ar->scan.in_progress) {
885 ath10k_warn("no scan requested, ignoring\n");
886 break;
887 }
888
889 if (ar->scan.is_roc) {
890 ath10k_offchan_tx_purge(ar);
891
892 if (!ar->scan.aborting)
893 ieee80211_remain_on_channel_expired(ar->hw);
894 } else {
895 ieee80211_scan_completed(ar->hw, ar->scan.aborting);
896 }
897
898 del_timer(&ar->scan.timeout);
899 complete_all(&ar->scan.completed);
900 ar->scan.in_progress = false;
901 break; 969 break;
902 case WMI_SCAN_EVENT_BSS_CHANNEL: 970 case WMI_SCAN_EVENT_BSS_CHANNEL:
903 ar->scan_channel = NULL; 971 ath10k_wmi_event_scan_bss_chan(ar);
904 break; 972 break;
905 case WMI_SCAN_EVENT_FOREIGN_CHANNEL: 973 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
906 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq); 974 ath10k_wmi_event_scan_foreign_chan(ar, freq);
907 if (ar->scan.in_progress && ar->scan.is_roc && 975 break;
908 ar->scan.roc_freq == freq) { 976 case WMI_SCAN_EVENT_START_FAILED:
909 complete(&ar->scan.on_channel); 977 ath10k_warn("received scan start failure event\n");
910 }
911 break; 978 break;
912 case WMI_SCAN_EVENT_DEQUEUED: 979 case WMI_SCAN_EVENT_DEQUEUED:
913 case WMI_SCAN_EVENT_PREEMPTED: 980 case WMI_SCAN_EVENT_PREEMPTED:
914 case WMI_SCAN_EVENT_START_FAILED:
915 default: 981 default:
916 break; 982 break;
917 } 983 }
@@ -1171,9 +1237,14 @@ static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
1171 1237
1172 spin_lock_bh(&ar->data_lock); 1238 spin_lock_bh(&ar->data_lock);
1173 1239
1174 if (!ar->scan.in_progress) { 1240 switch (ar->scan.state) {
1175 ath10k_warn("chan info event without a scan request?\n"); 1241 case ATH10K_SCAN_IDLE:
1242 case ATH10K_SCAN_STARTING:
1243 ath10k_warn("received chan info event without a scan request, ignoring\n");
1176 goto exit; 1244 goto exit;
1245 case ATH10K_SCAN_RUNNING:
1246 case ATH10K_SCAN_ABORTING:
1247 break;
1177 } 1248 }
1178 1249
1179 idx = freq_to_idx(ar, freq); 1250 idx = freq_to_idx(ar, freq);