iwl-scan.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/slab.h>
  29. #include <linux/types.h>
  30. #include <linux/etherdevice.h>
  31. #include <net/mac80211.h>
  32. #include "iwl-eeprom.h"
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. #include "iwl-sta.h"
  36. #include "iwl-io.h"
  37. #include "iwl-helpers.h"
  38. #include "iwl-agn.h"
  39. #include "iwl-trans.h"
  40. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  41. * sending probe req. This should be set long enough to hear probe responses
  42. * from more than one AP. */
  43. #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
  44. #define IWL_ACTIVE_DWELL_TIME_52 (20)
  45. #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
  46. #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
  47. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  48. * Must be set longer than active dwell time.
  49. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  50. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  51. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  52. #define IWL_PASSIVE_DWELL_BASE (100)
  53. #define IWL_CHANNEL_TUNE_TIME 5
  54. static int iwl_send_scan_abort(struct iwl_priv *priv)
  55. {
  56. int ret;
  57. struct iwl_rx_packet *pkt;
  58. struct iwl_host_cmd cmd = {
  59. .id = REPLY_SCAN_ABORT_CMD,
  60. .flags = CMD_SYNC | CMD_WANT_SKB,
  61. };
  62. /* Exit instantly with error when device is not ready
  63. * to receive scan abort command or it does not perform
  64. * hardware scan currently */
  65. if (!test_bit(STATUS_READY, &priv->status) ||
  66. !test_bit(STATUS_GEO_CONFIGURED, &priv->status) ||
  67. !test_bit(STATUS_SCAN_HW, &priv->status) ||
  68. test_bit(STATUS_FW_ERROR, &priv->status) ||
  69. test_bit(STATUS_EXIT_PENDING, &priv->status))
  70. return -EIO;
  71. ret = trans_send_cmd(&priv->trans, &cmd);
  72. if (ret)
  73. return ret;
  74. pkt = (struct iwl_rx_packet *)cmd.reply_page;
  75. if (pkt->u.status != CAN_ABORT_STATUS) {
  76. /* The scan abort will return 1 for success or
  77. * 2 for "failure". A failure condition can be
  78. * due to simply not being in an active scan which
  79. * can occur if we send the scan abort before we
  80. * the microcode has notified us that a scan is
  81. * completed. */
  82. IWL_DEBUG_SCAN(priv, "SCAN_ABORT ret %d.\n", pkt->u.status);
  83. ret = -EIO;
  84. }
  85. iwl_free_pages(priv, cmd.reply_page);
  86. return ret;
  87. }
  88. static void iwl_complete_scan(struct iwl_priv *priv, bool aborted)
  89. {
  90. /* check if scan was requested from mac80211 */
  91. if (priv->scan_request) {
  92. IWL_DEBUG_SCAN(priv, "Complete scan in mac80211\n");
  93. ieee80211_scan_completed(priv->hw, aborted);
  94. }
  95. priv->scan_type = IWL_SCAN_NORMAL;
  96. priv->scan_vif = NULL;
  97. priv->scan_request = NULL;
  98. }
  99. void iwl_force_scan_end(struct iwl_priv *priv)
  100. {
  101. lockdep_assert_held(&priv->mutex);
  102. if (!test_bit(STATUS_SCANNING, &priv->status)) {
  103. IWL_DEBUG_SCAN(priv, "Forcing scan end while not scanning\n");
  104. return;
  105. }
  106. IWL_DEBUG_SCAN(priv, "Forcing scan end\n");
  107. clear_bit(STATUS_SCANNING, &priv->status);
  108. clear_bit(STATUS_SCAN_HW, &priv->status);
  109. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  110. iwl_complete_scan(priv, true);
  111. }
  112. static void iwl_do_scan_abort(struct iwl_priv *priv)
  113. {
  114. int ret;
  115. lockdep_assert_held(&priv->mutex);
  116. if (!test_bit(STATUS_SCANNING, &priv->status)) {
  117. IWL_DEBUG_SCAN(priv, "Not performing scan to abort\n");
  118. return;
  119. }
  120. if (test_and_set_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  121. IWL_DEBUG_SCAN(priv, "Scan abort in progress\n");
  122. return;
  123. }
  124. ret = iwl_send_scan_abort(priv);
  125. if (ret) {
  126. IWL_DEBUG_SCAN(priv, "Send scan abort failed %d\n", ret);
  127. iwl_force_scan_end(priv);
  128. } else
  129. IWL_DEBUG_SCAN(priv, "Successfully send scan abort\n");
  130. }
  131. /**
  132. * iwl_scan_cancel - Cancel any currently executing HW scan
  133. */
  134. int iwl_scan_cancel(struct iwl_priv *priv)
  135. {
  136. IWL_DEBUG_SCAN(priv, "Queuing abort scan\n");
  137. queue_work(priv->workqueue, &priv->abort_scan);
  138. return 0;
  139. }
  140. /**
  141. * iwl_scan_cancel_timeout - Cancel any currently executing HW scan
  142. * @ms: amount of time to wait (in milliseconds) for scan to abort
  143. *
  144. */
  145. int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
  146. {
  147. unsigned long timeout = jiffies + msecs_to_jiffies(ms);
  148. lockdep_assert_held(&priv->mutex);
  149. IWL_DEBUG_SCAN(priv, "Scan cancel timeout\n");
  150. iwl_do_scan_abort(priv);
  151. while (time_before_eq(jiffies, timeout)) {
  152. if (!test_bit(STATUS_SCAN_HW, &priv->status))
  153. break;
  154. msleep(20);
  155. }
  156. return test_bit(STATUS_SCAN_HW, &priv->status);
  157. }
  158. /* Service response to REPLY_SCAN_CMD (0x80) */
  159. static void iwl_rx_reply_scan(struct iwl_priv *priv,
  160. struct iwl_rx_mem_buffer *rxb)
  161. {
  162. #ifdef CONFIG_IWLWIFI_DEBUG
  163. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  164. struct iwl_scanreq_notification *notif =
  165. (struct iwl_scanreq_notification *)pkt->u.raw;
  166. IWL_DEBUG_SCAN(priv, "Scan request status = 0x%x\n", notif->status);
  167. #endif
  168. }
  169. /* Service SCAN_START_NOTIFICATION (0x82) */
  170. static void iwl_rx_scan_start_notif(struct iwl_priv *priv,
  171. struct iwl_rx_mem_buffer *rxb)
  172. {
  173. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  174. struct iwl_scanstart_notification *notif =
  175. (struct iwl_scanstart_notification *)pkt->u.raw;
  176. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  177. IWL_DEBUG_SCAN(priv, "Scan start: "
  178. "%d [802.11%s] "
  179. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  180. notif->channel,
  181. notif->band ? "bg" : "a",
  182. le32_to_cpu(notif->tsf_high),
  183. le32_to_cpu(notif->tsf_low),
  184. notif->status, notif->beacon_timer);
  185. }
  186. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  187. static void iwl_rx_scan_results_notif(struct iwl_priv *priv,
  188. struct iwl_rx_mem_buffer *rxb)
  189. {
  190. #ifdef CONFIG_IWLWIFI_DEBUG
  191. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  192. struct iwl_scanresults_notification *notif =
  193. (struct iwl_scanresults_notification *)pkt->u.raw;
  194. IWL_DEBUG_SCAN(priv, "Scan ch.res: "
  195. "%d [802.11%s] "
  196. "(TSF: 0x%08X:%08X) - %d "
  197. "elapsed=%lu usec\n",
  198. notif->channel,
  199. notif->band ? "bg" : "a",
  200. le32_to_cpu(notif->tsf_high),
  201. le32_to_cpu(notif->tsf_low),
  202. le32_to_cpu(notif->statistics[0]),
  203. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf);
  204. #endif
  205. }
  206. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  207. static void iwl_rx_scan_complete_notif(struct iwl_priv *priv,
  208. struct iwl_rx_mem_buffer *rxb)
  209. {
  210. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  211. struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  212. IWL_DEBUG_SCAN(priv, "Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  213. scan_notif->scanned_channels,
  214. scan_notif->tsf_low,
  215. scan_notif->tsf_high, scan_notif->status);
  216. /* The HW is no longer scanning */
  217. clear_bit(STATUS_SCAN_HW, &priv->status);
  218. IWL_DEBUG_SCAN(priv, "Scan on %sGHz took %dms\n",
  219. (priv->scan_band == IEEE80211_BAND_2GHZ) ? "2.4" : "5.2",
  220. jiffies_to_msecs(jiffies - priv->scan_start));
  221. queue_work(priv->workqueue, &priv->scan_completed);
  222. if (priv->iw_mode != NL80211_IFTYPE_ADHOC &&
  223. iwl_advanced_bt_coexist(priv) &&
  224. priv->bt_status != scan_notif->bt_status) {
  225. if (scan_notif->bt_status) {
  226. /* BT on */
  227. if (!priv->bt_ch_announce)
  228. priv->bt_traffic_load =
  229. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  230. /*
  231. * otherwise, no traffic load information provided
  232. * no changes made
  233. */
  234. } else {
  235. /* BT off */
  236. priv->bt_traffic_load =
  237. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  238. }
  239. priv->bt_status = scan_notif->bt_status;
  240. queue_work(priv->workqueue, &priv->bt_traffic_change_work);
  241. }
  242. }
  243. void iwl_setup_rx_scan_handlers(struct iwl_priv *priv)
  244. {
  245. /* scan handlers */
  246. priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan;
  247. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif;
  248. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  249. iwl_rx_scan_results_notif;
  250. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  251. iwl_rx_scan_complete_notif;
  252. }
  253. inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
  254. enum ieee80211_band band,
  255. u8 n_probes)
  256. {
  257. if (band == IEEE80211_BAND_5GHZ)
  258. return IWL_ACTIVE_DWELL_TIME_52 +
  259. IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1);
  260. else
  261. return IWL_ACTIVE_DWELL_TIME_24 +
  262. IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
  263. }
  264. u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
  265. enum ieee80211_band band,
  266. struct ieee80211_vif *vif)
  267. {
  268. struct iwl_rxon_context *ctx;
  269. u16 passive = (band == IEEE80211_BAND_2GHZ) ?
  270. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  271. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  272. if (iwl_is_any_associated(priv)) {
  273. /*
  274. * If we're associated, we clamp the maximum passive
  275. * dwell time to be 98% of the smallest beacon interval
  276. * (minus 2 * channel tune time)
  277. */
  278. for_each_context(priv, ctx) {
  279. u16 value;
  280. if (!iwl_is_associated_ctx(ctx))
  281. continue;
  282. value = ctx->vif ? ctx->vif->bss_conf.beacon_int : 0;
  283. if ((value > IWL_PASSIVE_DWELL_BASE) || !value)
  284. value = IWL_PASSIVE_DWELL_BASE;
  285. value = (value * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  286. passive = min(value, passive);
  287. }
  288. }
  289. return passive;
  290. }
  291. void iwl_init_scan_params(struct iwl_priv *priv)
  292. {
  293. u8 ant_idx = fls(priv->hw_params.valid_tx_ant) - 1;
  294. if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ])
  295. priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx;
  296. if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
  297. priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx;
  298. }
  299. int __must_check iwl_scan_initiate(struct iwl_priv *priv,
  300. struct ieee80211_vif *vif,
  301. enum iwl_scan_type scan_type,
  302. enum ieee80211_band band)
  303. {
  304. int ret;
  305. lockdep_assert_held(&priv->mutex);
  306. cancel_delayed_work(&priv->scan_check);
  307. if (!iwl_is_ready_rf(priv)) {
  308. IWL_WARN(priv, "Request scan called when driver not ready.\n");
  309. return -EIO;
  310. }
  311. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  312. IWL_DEBUG_SCAN(priv,
  313. "Multiple concurrent scan requests in parallel.\n");
  314. return -EBUSY;
  315. }
  316. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  317. IWL_DEBUG_SCAN(priv, "Scan request while abort pending.\n");
  318. return -EBUSY;
  319. }
  320. IWL_DEBUG_SCAN(priv, "Starting %sscan...\n",
  321. scan_type == IWL_SCAN_NORMAL ? "" :
  322. scan_type == IWL_SCAN_OFFCH_TX ? "offchan TX " :
  323. "internal short ");
  324. set_bit(STATUS_SCANNING, &priv->status);
  325. priv->scan_type = scan_type;
  326. priv->scan_start = jiffies;
  327. priv->scan_band = band;
  328. ret = iwlagn_request_scan(priv, vif);
  329. if (ret) {
  330. clear_bit(STATUS_SCANNING, &priv->status);
  331. priv->scan_type = IWL_SCAN_NORMAL;
  332. return ret;
  333. }
  334. queue_delayed_work(priv->workqueue, &priv->scan_check,
  335. IWL_SCAN_CHECK_WATCHDOG);
  336. return 0;
  337. }
  338. int iwl_mac_hw_scan(struct ieee80211_hw *hw,
  339. struct ieee80211_vif *vif,
  340. struct cfg80211_scan_request *req)
  341. {
  342. struct iwl_priv *priv = hw->priv;
  343. int ret;
  344. IWL_DEBUG_MAC80211(priv, "enter\n");
  345. if (req->n_channels == 0)
  346. return -EINVAL;
  347. mutex_lock(&priv->mutex);
  348. if (test_bit(STATUS_SCANNING, &priv->status) &&
  349. priv->scan_type != IWL_SCAN_NORMAL) {
  350. IWL_DEBUG_SCAN(priv, "Scan already in progress.\n");
  351. ret = -EAGAIN;
  352. goto out_unlock;
  353. }
  354. /* mac80211 will only ask for one band at a time */
  355. priv->scan_request = req;
  356. priv->scan_vif = vif;
  357. /*
  358. * If an internal scan is in progress, just set
  359. * up the scan_request as per above.
  360. */
  361. if (priv->scan_type != IWL_SCAN_NORMAL) {
  362. IWL_DEBUG_SCAN(priv, "SCAN request during internal scan\n");
  363. ret = 0;
  364. } else
  365. ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
  366. req->channels[0]->band);
  367. IWL_DEBUG_MAC80211(priv, "leave\n");
  368. out_unlock:
  369. mutex_unlock(&priv->mutex);
  370. return ret;
  371. }
  372. /*
  373. * internal short scan, this function should only been called while associated.
  374. * It will reset and tune the radio to prevent possible RF related problem
  375. */
  376. void iwl_internal_short_hw_scan(struct iwl_priv *priv)
  377. {
  378. queue_work(priv->workqueue, &priv->start_internal_scan);
  379. }
  380. static void iwl_bg_start_internal_scan(struct work_struct *work)
  381. {
  382. struct iwl_priv *priv =
  383. container_of(work, struct iwl_priv, start_internal_scan);
  384. IWL_DEBUG_SCAN(priv, "Start internal scan\n");
  385. mutex_lock(&priv->mutex);
  386. if (priv->scan_type == IWL_SCAN_RADIO_RESET) {
  387. IWL_DEBUG_SCAN(priv, "Internal scan already in progress\n");
  388. goto unlock;
  389. }
  390. if (test_bit(STATUS_SCANNING, &priv->status)) {
  391. IWL_DEBUG_SCAN(priv, "Scan already in progress.\n");
  392. goto unlock;
  393. }
  394. if (iwl_scan_initiate(priv, NULL, IWL_SCAN_RADIO_RESET, priv->band))
  395. IWL_DEBUG_SCAN(priv, "failed to start internal short scan\n");
  396. unlock:
  397. mutex_unlock(&priv->mutex);
  398. }
  399. static void iwl_bg_scan_check(struct work_struct *data)
  400. {
  401. struct iwl_priv *priv =
  402. container_of(data, struct iwl_priv, scan_check.work);
  403. IWL_DEBUG_SCAN(priv, "Scan check work\n");
  404. /* Since we are here firmware does not finish scan and
  405. * most likely is in bad shape, so we don't bother to
  406. * send abort command, just force scan complete to mac80211 */
  407. mutex_lock(&priv->mutex);
  408. iwl_force_scan_end(priv);
  409. mutex_unlock(&priv->mutex);
  410. }
  411. /**
  412. * iwl_fill_probe_req - fill in all required fields and IE for probe request
  413. */
  414. u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
  415. const u8 *ta, const u8 *ies, int ie_len, int left)
  416. {
  417. int len = 0;
  418. u8 *pos = NULL;
  419. /* Make sure there is enough space for the probe request,
  420. * two mandatory IEs and the data */
  421. left -= 24;
  422. if (left < 0)
  423. return 0;
  424. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  425. memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
  426. memcpy(frame->sa, ta, ETH_ALEN);
  427. memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
  428. frame->seq_ctrl = 0;
  429. len += 24;
  430. /* ...next IE... */
  431. pos = &frame->u.probe_req.variable[0];
  432. /* fill in our indirect SSID IE */
  433. left -= 2;
  434. if (left < 0)
  435. return 0;
  436. *pos++ = WLAN_EID_SSID;
  437. *pos++ = 0;
  438. len += 2;
  439. if (WARN_ON(left < ie_len))
  440. return len;
  441. if (ies && ie_len) {
  442. memcpy(pos, ies, ie_len);
  443. len += ie_len;
  444. }
  445. return (u16)len;
  446. }
  447. static void iwl_bg_abort_scan(struct work_struct *work)
  448. {
  449. struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
  450. IWL_DEBUG_SCAN(priv, "Abort scan work\n");
  451. /* We keep scan_check work queued in case when firmware will not
  452. * report back scan completed notification */
  453. mutex_lock(&priv->mutex);
  454. iwl_scan_cancel_timeout(priv, 200);
  455. mutex_unlock(&priv->mutex);
  456. }
  457. static void iwl_bg_scan_completed(struct work_struct *work)
  458. {
  459. struct iwl_priv *priv =
  460. container_of(work, struct iwl_priv, scan_completed);
  461. bool aborted;
  462. IWL_DEBUG_SCAN(priv, "Completed scan.\n");
  463. cancel_delayed_work(&priv->scan_check);
  464. mutex_lock(&priv->mutex);
  465. aborted = test_and_clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  466. if (aborted)
  467. IWL_DEBUG_SCAN(priv, "Aborted scan completed.\n");
  468. if (!test_and_clear_bit(STATUS_SCANNING, &priv->status)) {
  469. IWL_DEBUG_SCAN(priv, "Scan already completed.\n");
  470. goto out_settings;
  471. }
  472. if (priv->scan_type == IWL_SCAN_OFFCH_TX && priv->offchan_tx_skb) {
  473. ieee80211_tx_status_irqsafe(priv->hw,
  474. priv->offchan_tx_skb);
  475. priv->offchan_tx_skb = NULL;
  476. }
  477. if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) {
  478. int err;
  479. /* Check if mac80211 requested scan during our internal scan */
  480. if (priv->scan_request == NULL)
  481. goto out_complete;
  482. /* If so request a new scan */
  483. err = iwl_scan_initiate(priv, priv->scan_vif, IWL_SCAN_NORMAL,
  484. priv->scan_request->channels[0]->band);
  485. if (err) {
  486. IWL_DEBUG_SCAN(priv,
  487. "failed to initiate pending scan: %d\n", err);
  488. aborted = true;
  489. goto out_complete;
  490. }
  491. goto out;
  492. }
  493. out_complete:
  494. iwl_complete_scan(priv, aborted);
  495. out_settings:
  496. /* Can we still talk to firmware ? */
  497. if (!iwl_is_ready_rf(priv))
  498. goto out;
  499. iwlagn_post_scan(priv);
  500. out:
  501. mutex_unlock(&priv->mutex);
  502. }
  503. void iwl_setup_scan_deferred_work(struct iwl_priv *priv)
  504. {
  505. INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
  506. INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
  507. INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan);
  508. INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
  509. }
  510. void iwl_cancel_scan_deferred_work(struct iwl_priv *priv)
  511. {
  512. cancel_work_sync(&priv->start_internal_scan);
  513. cancel_work_sync(&priv->abort_scan);
  514. cancel_work_sync(&priv->scan_completed);
  515. if (cancel_delayed_work_sync(&priv->scan_check)) {
  516. mutex_lock(&priv->mutex);
  517. iwl_force_scan_end(priv);
  518. mutex_unlock(&priv->mutex);
  519. }
  520. }