iwl-scan.c 17 KB

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