iwl-scan.c 17 KB

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