scan.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2012 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 "dev.h"
  33. #include "agn.h"
  34. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  35. * sending probe req. This should be set long enough to hear probe responses
  36. * from more than one AP. */
  37. #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
  38. #define IWL_ACTIVE_DWELL_TIME_52 (20)
  39. #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
  40. #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
  41. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  42. * Must be set longer than active dwell time.
  43. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  44. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  45. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  46. #define IWL_PASSIVE_DWELL_BASE (100)
  47. #define IWL_CHANNEL_TUNE_TIME 5
  48. #define MAX_SCAN_CHANNEL 50
  49. /* For reset radio, need minimal dwell time only */
  50. #define IWL_RADIO_RESET_DWELL_TIME 5
  51. static int iwl_send_scan_abort(struct iwl_priv *priv)
  52. {
  53. int ret;
  54. struct iwl_host_cmd cmd = {
  55. .id = REPLY_SCAN_ABORT_CMD,
  56. .flags = CMD_SYNC | CMD_WANT_SKB,
  57. };
  58. __le32 *status;
  59. /* Exit instantly with error when device is not ready
  60. * to receive scan abort command or it does not perform
  61. * hardware scan currently */
  62. if (!test_bit(STATUS_READY, &priv->status) ||
  63. !test_bit(STATUS_SCAN_HW, &priv->status) ||
  64. test_bit(STATUS_FW_ERROR, &priv->status))
  65. return -EIO;
  66. ret = iwl_dvm_send_cmd(priv, &cmd);
  67. if (ret)
  68. return ret;
  69. status = (void *)cmd.resp_pkt->data;
  70. if (*status != CAN_ABORT_STATUS) {
  71. /* The scan abort will return 1 for success or
  72. * 2 for "failure". A failure condition can be
  73. * due to simply not being in an active scan which
  74. * can occur if we send the scan abort before we
  75. * the microcode has notified us that a scan is
  76. * completed. */
  77. IWL_DEBUG_SCAN(priv, "SCAN_ABORT ret %d.\n",
  78. le32_to_cpu(*status));
  79. ret = -EIO;
  80. }
  81. iwl_free_resp(&cmd);
  82. return ret;
  83. }
  84. static void iwl_complete_scan(struct iwl_priv *priv, bool aborted)
  85. {
  86. /* check if scan was requested from mac80211 */
  87. if (priv->scan_request) {
  88. IWL_DEBUG_SCAN(priv, "Complete scan in mac80211\n");
  89. ieee80211_scan_completed(priv->hw, aborted);
  90. }
  91. if (priv->scan_type == IWL_SCAN_ROC)
  92. iwl_scan_roc_expired(priv);
  93. priv->scan_type = IWL_SCAN_NORMAL;
  94. priv->scan_vif = NULL;
  95. priv->scan_request = NULL;
  96. }
  97. static void iwl_process_scan_complete(struct iwl_priv *priv)
  98. {
  99. bool aborted;
  100. lockdep_assert_held(&priv->mutex);
  101. if (!test_and_clear_bit(STATUS_SCAN_COMPLETE, &priv->status))
  102. return;
  103. IWL_DEBUG_SCAN(priv, "Completed scan.\n");
  104. cancel_delayed_work(&priv->scan_check);
  105. aborted = test_and_clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  106. if (aborted)
  107. IWL_DEBUG_SCAN(priv, "Aborted scan completed.\n");
  108. if (!test_and_clear_bit(STATUS_SCANNING, &priv->status)) {
  109. IWL_DEBUG_SCAN(priv, "Scan already completed.\n");
  110. goto out_settings;
  111. }
  112. if (priv->scan_type == IWL_SCAN_ROC)
  113. iwl_scan_roc_expired(priv);
  114. if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) {
  115. int err;
  116. /* Check if mac80211 requested scan during our internal scan */
  117. if (priv->scan_request == NULL)
  118. goto out_complete;
  119. /* If so request a new scan */
  120. err = iwl_scan_initiate(priv, priv->scan_vif, IWL_SCAN_NORMAL,
  121. priv->scan_request->channels[0]->band);
  122. if (err) {
  123. IWL_DEBUG_SCAN(priv,
  124. "failed to initiate pending scan: %d\n", err);
  125. aborted = true;
  126. goto out_complete;
  127. }
  128. return;
  129. }
  130. out_complete:
  131. iwl_complete_scan(priv, aborted);
  132. out_settings:
  133. /* Can we still talk to firmware ? */
  134. if (!iwl_is_ready_rf(priv))
  135. return;
  136. iwlagn_post_scan(priv);
  137. }
  138. void iwl_force_scan_end(struct iwl_priv *priv)
  139. {
  140. lockdep_assert_held(&priv->mutex);
  141. if (!test_bit(STATUS_SCANNING, &priv->status)) {
  142. IWL_DEBUG_SCAN(priv, "Forcing scan end while not scanning\n");
  143. return;
  144. }
  145. IWL_DEBUG_SCAN(priv, "Forcing scan end\n");
  146. clear_bit(STATUS_SCANNING, &priv->status);
  147. clear_bit(STATUS_SCAN_HW, &priv->status);
  148. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  149. clear_bit(STATUS_SCAN_COMPLETE, &priv->status);
  150. iwl_complete_scan(priv, true);
  151. }
  152. static void iwl_do_scan_abort(struct iwl_priv *priv)
  153. {
  154. int ret;
  155. lockdep_assert_held(&priv->mutex);
  156. if (!test_bit(STATUS_SCANNING, &priv->status)) {
  157. IWL_DEBUG_SCAN(priv, "Not performing scan to abort\n");
  158. return;
  159. }
  160. if (test_and_set_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  161. IWL_DEBUG_SCAN(priv, "Scan abort in progress\n");
  162. return;
  163. }
  164. ret = iwl_send_scan_abort(priv);
  165. if (ret) {
  166. IWL_DEBUG_SCAN(priv, "Send scan abort failed %d\n", ret);
  167. iwl_force_scan_end(priv);
  168. } else
  169. IWL_DEBUG_SCAN(priv, "Successfully send scan abort\n");
  170. }
  171. /**
  172. * iwl_scan_cancel - Cancel any currently executing HW scan
  173. */
  174. int iwl_scan_cancel(struct iwl_priv *priv)
  175. {
  176. IWL_DEBUG_SCAN(priv, "Queuing abort scan\n");
  177. queue_work(priv->workqueue, &priv->abort_scan);
  178. return 0;
  179. }
  180. /**
  181. * iwl_scan_cancel_timeout - Cancel any currently executing HW scan
  182. * @ms: amount of time to wait (in milliseconds) for scan to abort
  183. *
  184. */
  185. void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
  186. {
  187. unsigned long timeout = jiffies + msecs_to_jiffies(ms);
  188. lockdep_assert_held(&priv->mutex);
  189. IWL_DEBUG_SCAN(priv, "Scan cancel timeout\n");
  190. iwl_do_scan_abort(priv);
  191. while (time_before_eq(jiffies, timeout)) {
  192. if (!test_bit(STATUS_SCAN_HW, &priv->status))
  193. goto finished;
  194. msleep(20);
  195. }
  196. return;
  197. finished:
  198. /*
  199. * Now STATUS_SCAN_HW is clear. This means that the
  200. * device finished, but the background work is going
  201. * to execute at best as soon as we release the mutex.
  202. * Since we need to be able to issue a new scan right
  203. * after this function returns, run the complete here.
  204. * The STATUS_SCAN_COMPLETE bit will then be cleared
  205. * and prevent the background work from "completing"
  206. * a possible new scan.
  207. */
  208. iwl_process_scan_complete(priv);
  209. }
  210. /* Service response to REPLY_SCAN_CMD (0x80) */
  211. static int iwl_rx_reply_scan(struct iwl_priv *priv,
  212. struct iwl_rx_cmd_buffer *rxb,
  213. struct iwl_device_cmd *cmd)
  214. {
  215. #ifdef CONFIG_IWLWIFI_DEBUG
  216. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  217. struct iwl_scanreq_notification *notif = (void *)pkt->data;
  218. IWL_DEBUG_SCAN(priv, "Scan request status = 0x%x\n", notif->status);
  219. #endif
  220. return 0;
  221. }
  222. /* Service SCAN_START_NOTIFICATION (0x82) */
  223. static int iwl_rx_scan_start_notif(struct iwl_priv *priv,
  224. struct iwl_rx_cmd_buffer *rxb,
  225. struct iwl_device_cmd *cmd)
  226. {
  227. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  228. struct iwl_scanstart_notification *notif = (void *)pkt->data;
  229. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  230. IWL_DEBUG_SCAN(priv, "Scan start: "
  231. "%d [802.11%s] "
  232. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  233. notif->channel,
  234. notif->band ? "bg" : "a",
  235. le32_to_cpu(notif->tsf_high),
  236. le32_to_cpu(notif->tsf_low),
  237. notif->status, notif->beacon_timer);
  238. if (priv->scan_type == IWL_SCAN_ROC &&
  239. !priv->hw_roc_start_notified) {
  240. ieee80211_ready_on_channel(priv->hw);
  241. priv->hw_roc_start_notified = true;
  242. }
  243. return 0;
  244. }
  245. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  246. static int iwl_rx_scan_results_notif(struct iwl_priv *priv,
  247. struct iwl_rx_cmd_buffer *rxb,
  248. struct iwl_device_cmd *cmd)
  249. {
  250. #ifdef CONFIG_IWLWIFI_DEBUG
  251. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  252. struct iwl_scanresults_notification *notif = (void *)pkt->data;
  253. IWL_DEBUG_SCAN(priv, "Scan ch.res: "
  254. "%d [802.11%s] "
  255. "probe status: %u:%u "
  256. "(TSF: 0x%08X:%08X) - %d "
  257. "elapsed=%lu usec\n",
  258. notif->channel,
  259. notif->band ? "bg" : "a",
  260. notif->probe_status, notif->num_probe_not_sent,
  261. le32_to_cpu(notif->tsf_high),
  262. le32_to_cpu(notif->tsf_low),
  263. le32_to_cpu(notif->statistics[0]),
  264. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf);
  265. #endif
  266. return 0;
  267. }
  268. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  269. static int iwl_rx_scan_complete_notif(struct iwl_priv *priv,
  270. struct iwl_rx_cmd_buffer *rxb,
  271. struct iwl_device_cmd *cmd)
  272. {
  273. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  274. struct iwl_scancomplete_notification *scan_notif = (void *)pkt->data;
  275. IWL_DEBUG_SCAN(priv, "Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  276. scan_notif->scanned_channels,
  277. scan_notif->tsf_low,
  278. scan_notif->tsf_high, scan_notif->status);
  279. IWL_DEBUG_SCAN(priv, "Scan on %sGHz took %dms\n",
  280. (priv->scan_band == IEEE80211_BAND_2GHZ) ? "2.4" : "5.2",
  281. jiffies_to_msecs(jiffies - priv->scan_start));
  282. /*
  283. * When aborting, we run the scan completed background work inline
  284. * and the background work must then do nothing. The SCAN_COMPLETE
  285. * bit helps implement that logic and thus needs to be set before
  286. * queueing the work. Also, since the scan abort waits for SCAN_HW
  287. * to clear, we need to set SCAN_COMPLETE before clearing SCAN_HW
  288. * to avoid a race there.
  289. */
  290. set_bit(STATUS_SCAN_COMPLETE, &priv->status);
  291. clear_bit(STATUS_SCAN_HW, &priv->status);
  292. queue_work(priv->workqueue, &priv->scan_completed);
  293. if (priv->iw_mode != NL80211_IFTYPE_ADHOC &&
  294. iwl_advanced_bt_coexist(priv) &&
  295. priv->bt_status != scan_notif->bt_status) {
  296. if (scan_notif->bt_status) {
  297. /* BT on */
  298. if (!priv->bt_ch_announce)
  299. priv->bt_traffic_load =
  300. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  301. /*
  302. * otherwise, no traffic load information provided
  303. * no changes made
  304. */
  305. } else {
  306. /* BT off */
  307. priv->bt_traffic_load =
  308. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  309. }
  310. priv->bt_status = scan_notif->bt_status;
  311. queue_work(priv->workqueue,
  312. &priv->bt_traffic_change_work);
  313. }
  314. return 0;
  315. }
  316. void iwl_setup_rx_scan_handlers(struct iwl_priv *priv)
  317. {
  318. /* scan handlers */
  319. priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan;
  320. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif;
  321. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  322. iwl_rx_scan_results_notif;
  323. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  324. iwl_rx_scan_complete_notif;
  325. }
  326. static u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
  327. enum ieee80211_band band, u8 n_probes)
  328. {
  329. if (band == IEEE80211_BAND_5GHZ)
  330. return IWL_ACTIVE_DWELL_TIME_52 +
  331. IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1);
  332. else
  333. return IWL_ACTIVE_DWELL_TIME_24 +
  334. IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
  335. }
  336. static u16 iwl_limit_dwell(struct iwl_priv *priv, u16 dwell_time)
  337. {
  338. struct iwl_rxon_context *ctx;
  339. int limits[NUM_IWL_RXON_CTX] = {};
  340. int n_active = 0;
  341. u16 limit;
  342. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  343. /*
  344. * If we're associated, we clamp the dwell time 98%
  345. * of the beacon interval (minus 2 * channel tune time)
  346. * If both contexts are active, we have to restrict to
  347. * 1/2 of the minimum of them, because they might be in
  348. * lock-step with the time inbetween only half of what
  349. * time we'd have in each of them.
  350. */
  351. for_each_context(priv, ctx) {
  352. switch (ctx->staging.dev_type) {
  353. case RXON_DEV_TYPE_P2P:
  354. /* no timing constraints */
  355. continue;
  356. case RXON_DEV_TYPE_ESS:
  357. default:
  358. /* timing constraints if associated */
  359. if (!iwl_is_associated_ctx(ctx))
  360. continue;
  361. break;
  362. case RXON_DEV_TYPE_CP:
  363. case RXON_DEV_TYPE_2STA:
  364. /*
  365. * These seem to always have timers for TBTT
  366. * active in uCode even when not associated yet.
  367. */
  368. break;
  369. }
  370. limits[n_active++] = ctx->beacon_int ?: IWL_PASSIVE_DWELL_BASE;
  371. }
  372. switch (n_active) {
  373. case 0:
  374. return dwell_time;
  375. case 2:
  376. limit = (limits[1] * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  377. limit /= 2;
  378. dwell_time = min(limit, dwell_time);
  379. /* fall through to limit further */
  380. case 1:
  381. limit = (limits[0] * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  382. limit /= n_active;
  383. return min(limit, dwell_time);
  384. default:
  385. WARN_ON_ONCE(1);
  386. return dwell_time;
  387. }
  388. }
  389. static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
  390. enum ieee80211_band band)
  391. {
  392. u16 passive = (band == IEEE80211_BAND_2GHZ) ?
  393. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  394. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  395. return iwl_limit_dwell(priv, passive);
  396. }
  397. /* Return valid, unused, channel for a passive scan to reset the RF */
  398. static u8 iwl_get_single_channel_number(struct iwl_priv *priv,
  399. enum ieee80211_band band)
  400. {
  401. struct ieee80211_supported_band *sband = priv->hw->wiphy->bands[band];
  402. struct iwl_rxon_context *ctx;
  403. int i;
  404. for (i = 0; i < sband->n_channels; i++) {
  405. bool busy = false;
  406. for_each_context(priv, ctx) {
  407. busy = sband->channels[i].hw_value ==
  408. le16_to_cpu(ctx->staging.channel);
  409. if (busy)
  410. break;
  411. }
  412. if (busy)
  413. continue;
  414. if (!(sband->channels[i].flags & IEEE80211_CHAN_DISABLED))
  415. return sband->channels[i].hw_value;
  416. }
  417. return 0;
  418. }
  419. static int iwl_get_channel_for_reset_scan(struct iwl_priv *priv,
  420. struct ieee80211_vif *vif,
  421. enum ieee80211_band band,
  422. struct iwl_scan_channel *scan_ch)
  423. {
  424. const struct ieee80211_supported_band *sband;
  425. u16 channel;
  426. sband = iwl_get_hw_mode(priv, band);
  427. if (!sband) {
  428. IWL_ERR(priv, "invalid band\n");
  429. return 0;
  430. }
  431. channel = iwl_get_single_channel_number(priv, band);
  432. if (channel) {
  433. scan_ch->channel = cpu_to_le16(channel);
  434. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  435. scan_ch->active_dwell =
  436. cpu_to_le16(IWL_RADIO_RESET_DWELL_TIME);
  437. scan_ch->passive_dwell =
  438. cpu_to_le16(IWL_RADIO_RESET_DWELL_TIME);
  439. /* Set txpower levels to defaults */
  440. scan_ch->dsp_atten = 110;
  441. if (band == IEEE80211_BAND_5GHZ)
  442. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  443. else
  444. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  445. return 1;
  446. }
  447. IWL_ERR(priv, "no valid channel found\n");
  448. return 0;
  449. }
  450. static int iwl_get_channels_for_scan(struct iwl_priv *priv,
  451. struct ieee80211_vif *vif,
  452. enum ieee80211_band band,
  453. u8 is_active, u8 n_probes,
  454. struct iwl_scan_channel *scan_ch)
  455. {
  456. struct ieee80211_channel *chan;
  457. const struct ieee80211_supported_band *sband;
  458. u16 passive_dwell = 0;
  459. u16 active_dwell = 0;
  460. int added, i;
  461. u16 channel;
  462. sband = iwl_get_hw_mode(priv, band);
  463. if (!sband)
  464. return 0;
  465. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  466. passive_dwell = iwl_get_passive_dwell_time(priv, band);
  467. if (passive_dwell <= active_dwell)
  468. passive_dwell = active_dwell + 1;
  469. for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
  470. chan = priv->scan_request->channels[i];
  471. if (chan->band != band)
  472. continue;
  473. channel = chan->hw_value;
  474. scan_ch->channel = cpu_to_le16(channel);
  475. if (!is_active || (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  476. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  477. else
  478. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  479. if (n_probes)
  480. scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
  481. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  482. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  483. /* Set txpower levels to defaults */
  484. scan_ch->dsp_atten = 110;
  485. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  486. * power level:
  487. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  488. */
  489. if (band == IEEE80211_BAND_5GHZ)
  490. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  491. else
  492. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  493. IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
  494. channel, le32_to_cpu(scan_ch->type),
  495. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  496. "ACTIVE" : "PASSIVE",
  497. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  498. active_dwell : passive_dwell);
  499. scan_ch++;
  500. added++;
  501. }
  502. IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
  503. return added;
  504. }
  505. /**
  506. * iwl_fill_probe_req - fill in all required fields and IE for probe request
  507. */
  508. static u16 iwl_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta,
  509. const u8 *ies, int ie_len, const u8 *ssid,
  510. u8 ssid_len, int left)
  511. {
  512. int len = 0;
  513. u8 *pos = NULL;
  514. /* Make sure there is enough space for the probe request,
  515. * two mandatory IEs and the data */
  516. left -= 24;
  517. if (left < 0)
  518. return 0;
  519. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  520. memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
  521. memcpy(frame->sa, ta, ETH_ALEN);
  522. memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
  523. frame->seq_ctrl = 0;
  524. len += 24;
  525. /* ...next IE... */
  526. pos = &frame->u.probe_req.variable[0];
  527. /* fill in our SSID IE */
  528. left -= ssid_len + 2;
  529. if (left < 0)
  530. return 0;
  531. *pos++ = WLAN_EID_SSID;
  532. *pos++ = ssid_len;
  533. if (ssid && ssid_len) {
  534. memcpy(pos, ssid, ssid_len);
  535. pos += ssid_len;
  536. }
  537. len += ssid_len + 2;
  538. if (WARN_ON(left < ie_len))
  539. return len;
  540. if (ies && ie_len) {
  541. memcpy(pos, ies, ie_len);
  542. len += ie_len;
  543. }
  544. return (u16)len;
  545. }
  546. static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
  547. {
  548. struct iwl_host_cmd cmd = {
  549. .id = REPLY_SCAN_CMD,
  550. .len = { sizeof(struct iwl_scan_cmd), },
  551. .flags = CMD_SYNC,
  552. };
  553. struct iwl_scan_cmd *scan;
  554. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  555. u32 rate_flags = 0;
  556. u16 cmd_len = 0;
  557. u16 rx_chain = 0;
  558. enum ieee80211_band band;
  559. u8 n_probes = 0;
  560. u8 rx_ant = priv->eeprom_data->valid_rx_ant;
  561. u8 rate;
  562. bool is_active = false;
  563. int chan_mod;
  564. u8 active_chains;
  565. u8 scan_tx_antennas = priv->eeprom_data->valid_tx_ant;
  566. int ret;
  567. int scan_cmd_size = sizeof(struct iwl_scan_cmd) +
  568. MAX_SCAN_CHANNEL * sizeof(struct iwl_scan_channel) +
  569. priv->fw->ucode_capa.max_probe_length;
  570. const u8 *ssid = NULL;
  571. u8 ssid_len = 0;
  572. if (WARN_ON_ONCE(priv->scan_request &&
  573. priv->scan_request->n_channels > MAX_SCAN_CHANNEL))
  574. return -EINVAL;
  575. lockdep_assert_held(&priv->mutex);
  576. if (vif)
  577. ctx = iwl_rxon_ctx_from_vif(vif);
  578. if (!priv->scan_cmd) {
  579. priv->scan_cmd = kmalloc(scan_cmd_size, GFP_KERNEL);
  580. if (!priv->scan_cmd) {
  581. IWL_DEBUG_SCAN(priv,
  582. "fail to allocate memory for scan\n");
  583. return -ENOMEM;
  584. }
  585. }
  586. scan = priv->scan_cmd;
  587. memset(scan, 0, scan_cmd_size);
  588. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  589. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  590. if (priv->scan_type != IWL_SCAN_ROC &&
  591. iwl_is_any_associated(priv)) {
  592. u16 interval = 0;
  593. u32 extra;
  594. u32 suspend_time = 100;
  595. u32 scan_suspend_time = 100;
  596. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  597. switch (priv->scan_type) {
  598. case IWL_SCAN_ROC:
  599. WARN_ON(1);
  600. break;
  601. case IWL_SCAN_RADIO_RESET:
  602. interval = 0;
  603. break;
  604. case IWL_SCAN_NORMAL:
  605. interval = vif->bss_conf.beacon_int;
  606. break;
  607. }
  608. scan->suspend_time = 0;
  609. scan->max_out_time = cpu_to_le32(200 * 1024);
  610. if (!interval)
  611. interval = suspend_time;
  612. extra = (suspend_time / interval) << 22;
  613. scan_suspend_time = (extra |
  614. ((suspend_time % interval) * 1024));
  615. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  616. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  617. scan_suspend_time, interval);
  618. } else if (priv->scan_type == IWL_SCAN_ROC) {
  619. scan->suspend_time = 0;
  620. scan->max_out_time = 0;
  621. scan->quiet_time = 0;
  622. scan->quiet_plcp_th = 0;
  623. }
  624. switch (priv->scan_type) {
  625. case IWL_SCAN_RADIO_RESET:
  626. IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
  627. /*
  628. * Override quiet time as firmware checks that active
  629. * dwell is >= quiet; since we use passive scan it'll
  630. * not actually be used.
  631. */
  632. scan->quiet_time = cpu_to_le16(IWL_RADIO_RESET_DWELL_TIME);
  633. break;
  634. case IWL_SCAN_NORMAL:
  635. if (priv->scan_request->n_ssids) {
  636. int i, p = 0;
  637. IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
  638. /*
  639. * The highest priority SSID is inserted to the
  640. * probe request template.
  641. */
  642. ssid_len = priv->scan_request->ssids[0].ssid_len;
  643. ssid = priv->scan_request->ssids[0].ssid;
  644. /*
  645. * Invert the order of ssids, the firmware will invert
  646. * it back.
  647. */
  648. for (i = priv->scan_request->n_ssids - 1; i >= 1; i--) {
  649. scan->direct_scan[p].id = WLAN_EID_SSID;
  650. scan->direct_scan[p].len =
  651. priv->scan_request->ssids[i].ssid_len;
  652. memcpy(scan->direct_scan[p].ssid,
  653. priv->scan_request->ssids[i].ssid,
  654. priv->scan_request->ssids[i].ssid_len);
  655. n_probes++;
  656. p++;
  657. }
  658. is_active = true;
  659. } else
  660. IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
  661. break;
  662. case IWL_SCAN_ROC:
  663. IWL_DEBUG_SCAN(priv, "Start ROC scan.\n");
  664. break;
  665. }
  666. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  667. scan->tx_cmd.sta_id = ctx->bcast_sta_id;
  668. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  669. switch (priv->scan_band) {
  670. case IEEE80211_BAND_2GHZ:
  671. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  672. chan_mod = le32_to_cpu(
  673. priv->contexts[IWL_RXON_CTX_BSS].active.flags &
  674. RXON_FLG_CHANNEL_MODE_MSK)
  675. >> RXON_FLG_CHANNEL_MODE_POS;
  676. if ((priv->scan_request && priv->scan_request->no_cck) ||
  677. chan_mod == CHANNEL_MODE_PURE_40) {
  678. rate = IWL_RATE_6M_PLCP;
  679. } else {
  680. rate = IWL_RATE_1M_PLCP;
  681. rate_flags = RATE_MCS_CCK_MSK;
  682. }
  683. /*
  684. * Internal scans are passive, so we can indiscriminately set
  685. * the BT ignore flag on 2.4 GHz since it applies to TX only.
  686. */
  687. if (priv->cfg->bt_params &&
  688. priv->cfg->bt_params->advanced_bt_coexist)
  689. scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
  690. break;
  691. case IEEE80211_BAND_5GHZ:
  692. rate = IWL_RATE_6M_PLCP;
  693. break;
  694. default:
  695. IWL_WARN(priv, "Invalid scan band\n");
  696. return -EIO;
  697. }
  698. /*
  699. * If active scanning is requested but a certain channel is
  700. * marked passive, we can do active scanning if we detect
  701. * transmissions.
  702. *
  703. * There is an issue with some firmware versions that triggers
  704. * a sysassert on a "good CRC threshold" of zero (== disabled),
  705. * on a radar channel even though this means that we should NOT
  706. * send probes.
  707. *
  708. * The "good CRC threshold" is the number of frames that we
  709. * need to receive during our dwell time on a channel before
  710. * sending out probes -- setting this to a huge value will
  711. * mean we never reach it, but at the same time work around
  712. * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
  713. * here instead of IWL_GOOD_CRC_TH_DISABLED.
  714. *
  715. * This was fixed in later versions along with some other
  716. * scan changes, and the threshold behaves as a flag in those
  717. * versions.
  718. */
  719. if (priv->new_scan_threshold_behaviour)
  720. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  721. IWL_GOOD_CRC_TH_DISABLED;
  722. else
  723. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  724. IWL_GOOD_CRC_TH_NEVER;
  725. band = priv->scan_band;
  726. if (band == IEEE80211_BAND_2GHZ &&
  727. priv->cfg->bt_params &&
  728. priv->cfg->bt_params->advanced_bt_coexist) {
  729. /* transmit 2.4 GHz probes only on first antenna */
  730. scan_tx_antennas = first_antenna(scan_tx_antennas);
  731. }
  732. priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv,
  733. priv->scan_tx_ant[band],
  734. scan_tx_antennas);
  735. rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
  736. scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
  737. /*
  738. * In power save mode while associated use one chain,
  739. * otherwise use all chains
  740. */
  741. if (test_bit(STATUS_POWER_PMI, &priv->status) &&
  742. !(priv->hw->conf.flags & IEEE80211_CONF_IDLE)) {
  743. /* rx_ant has been set to all valid chains previously */
  744. active_chains = rx_ant &
  745. ((u8)(priv->chain_noise_data.active_chains));
  746. if (!active_chains)
  747. active_chains = rx_ant;
  748. IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
  749. priv->chain_noise_data.active_chains);
  750. rx_ant = first_antenna(active_chains);
  751. }
  752. if (priv->cfg->bt_params &&
  753. priv->cfg->bt_params->advanced_bt_coexist &&
  754. priv->bt_full_concurrent) {
  755. /* operated as 1x1 in full concurrency mode */
  756. rx_ant = first_antenna(rx_ant);
  757. }
  758. /* MIMO is not used here, but value is required */
  759. rx_chain |=
  760. priv->eeprom_data->valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  761. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  762. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  763. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  764. scan->rx_chain = cpu_to_le16(rx_chain);
  765. switch (priv->scan_type) {
  766. case IWL_SCAN_NORMAL:
  767. cmd_len = iwl_fill_probe_req(
  768. (struct ieee80211_mgmt *)scan->data,
  769. vif->addr,
  770. priv->scan_request->ie,
  771. priv->scan_request->ie_len,
  772. ssid, ssid_len,
  773. scan_cmd_size - sizeof(*scan));
  774. break;
  775. case IWL_SCAN_RADIO_RESET:
  776. case IWL_SCAN_ROC:
  777. /* use bcast addr, will not be transmitted but must be valid */
  778. cmd_len = iwl_fill_probe_req(
  779. (struct ieee80211_mgmt *)scan->data,
  780. iwl_bcast_addr, NULL, 0,
  781. NULL, 0,
  782. scan_cmd_size - sizeof(*scan));
  783. break;
  784. default:
  785. BUG();
  786. }
  787. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  788. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  789. RXON_FILTER_BCON_AWARE_MSK);
  790. switch (priv->scan_type) {
  791. case IWL_SCAN_RADIO_RESET:
  792. scan->channel_count =
  793. iwl_get_channel_for_reset_scan(priv, vif, band,
  794. (void *)&scan->data[cmd_len]);
  795. break;
  796. case IWL_SCAN_NORMAL:
  797. scan->channel_count =
  798. iwl_get_channels_for_scan(priv, vif, band,
  799. is_active, n_probes,
  800. (void *)&scan->data[cmd_len]);
  801. break;
  802. case IWL_SCAN_ROC: {
  803. struct iwl_scan_channel *scan_ch;
  804. int n_chan, i;
  805. u16 dwell;
  806. dwell = iwl_limit_dwell(priv, priv->hw_roc_duration);
  807. n_chan = DIV_ROUND_UP(priv->hw_roc_duration, dwell);
  808. scan->channel_count = n_chan;
  809. scan_ch = (void *)&scan->data[cmd_len];
  810. for (i = 0; i < n_chan; i++) {
  811. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  812. scan_ch->channel =
  813. cpu_to_le16(priv->hw_roc_channel->hw_value);
  814. if (i == n_chan - 1)
  815. dwell = priv->hw_roc_duration - i * dwell;
  816. scan_ch->active_dwell =
  817. scan_ch->passive_dwell = cpu_to_le16(dwell);
  818. /* Set txpower levels to defaults */
  819. scan_ch->dsp_atten = 110;
  820. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  821. * power level:
  822. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  823. */
  824. if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ)
  825. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  826. else
  827. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  828. scan_ch++;
  829. }
  830. }
  831. break;
  832. }
  833. if (scan->channel_count == 0) {
  834. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  835. return -EIO;
  836. }
  837. cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) +
  838. scan->channel_count * sizeof(struct iwl_scan_channel);
  839. cmd.data[0] = scan;
  840. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  841. scan->len = cpu_to_le16(cmd.len[0]);
  842. /* set scan bit here for PAN params */
  843. set_bit(STATUS_SCAN_HW, &priv->status);
  844. ret = iwlagn_set_pan_params(priv);
  845. if (ret) {
  846. clear_bit(STATUS_SCAN_HW, &priv->status);
  847. return ret;
  848. }
  849. ret = iwl_dvm_send_cmd(priv, &cmd);
  850. if (ret) {
  851. clear_bit(STATUS_SCAN_HW, &priv->status);
  852. iwlagn_set_pan_params(priv);
  853. }
  854. return ret;
  855. }
  856. void iwl_init_scan_params(struct iwl_priv *priv)
  857. {
  858. u8 ant_idx = fls(priv->eeprom_data->valid_tx_ant) - 1;
  859. if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ])
  860. priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx;
  861. if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
  862. priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx;
  863. }
  864. int __must_check iwl_scan_initiate(struct iwl_priv *priv,
  865. struct ieee80211_vif *vif,
  866. enum iwl_scan_type scan_type,
  867. enum ieee80211_band band)
  868. {
  869. int ret;
  870. lockdep_assert_held(&priv->mutex);
  871. cancel_delayed_work(&priv->scan_check);
  872. if (!iwl_is_ready_rf(priv)) {
  873. IWL_WARN(priv, "Request scan called when driver not ready.\n");
  874. return -EIO;
  875. }
  876. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  877. IWL_DEBUG_SCAN(priv,
  878. "Multiple concurrent scan requests in parallel.\n");
  879. return -EBUSY;
  880. }
  881. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  882. IWL_DEBUG_SCAN(priv, "Scan request while abort pending.\n");
  883. return -EBUSY;
  884. }
  885. IWL_DEBUG_SCAN(priv, "Starting %sscan...\n",
  886. scan_type == IWL_SCAN_NORMAL ? "" :
  887. scan_type == IWL_SCAN_ROC ? "remain-on-channel " :
  888. "internal short ");
  889. set_bit(STATUS_SCANNING, &priv->status);
  890. priv->scan_type = scan_type;
  891. priv->scan_start = jiffies;
  892. priv->scan_band = band;
  893. ret = iwlagn_request_scan(priv, vif);
  894. if (ret) {
  895. clear_bit(STATUS_SCANNING, &priv->status);
  896. priv->scan_type = IWL_SCAN_NORMAL;
  897. return ret;
  898. }
  899. queue_delayed_work(priv->workqueue, &priv->scan_check,
  900. IWL_SCAN_CHECK_WATCHDOG);
  901. return 0;
  902. }
  903. /*
  904. * internal short scan, this function should only been called while associated.
  905. * It will reset and tune the radio to prevent possible RF related problem
  906. */
  907. void iwl_internal_short_hw_scan(struct iwl_priv *priv)
  908. {
  909. queue_work(priv->workqueue, &priv->start_internal_scan);
  910. }
  911. static void iwl_bg_start_internal_scan(struct work_struct *work)
  912. {
  913. struct iwl_priv *priv =
  914. container_of(work, struct iwl_priv, start_internal_scan);
  915. IWL_DEBUG_SCAN(priv, "Start internal scan\n");
  916. mutex_lock(&priv->mutex);
  917. if (priv->scan_type == IWL_SCAN_RADIO_RESET) {
  918. IWL_DEBUG_SCAN(priv, "Internal scan already in progress\n");
  919. goto unlock;
  920. }
  921. if (test_bit(STATUS_SCANNING, &priv->status)) {
  922. IWL_DEBUG_SCAN(priv, "Scan already in progress.\n");
  923. goto unlock;
  924. }
  925. if (iwl_scan_initiate(priv, NULL, IWL_SCAN_RADIO_RESET, priv->band))
  926. IWL_DEBUG_SCAN(priv, "failed to start internal short scan\n");
  927. unlock:
  928. mutex_unlock(&priv->mutex);
  929. }
  930. static void iwl_bg_scan_check(struct work_struct *data)
  931. {
  932. struct iwl_priv *priv =
  933. container_of(data, struct iwl_priv, scan_check.work);
  934. IWL_DEBUG_SCAN(priv, "Scan check work\n");
  935. /* Since we are here firmware does not finish scan and
  936. * most likely is in bad shape, so we don't bother to
  937. * send abort command, just force scan complete to mac80211 */
  938. mutex_lock(&priv->mutex);
  939. iwl_force_scan_end(priv);
  940. mutex_unlock(&priv->mutex);
  941. }
  942. static void iwl_bg_abort_scan(struct work_struct *work)
  943. {
  944. struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
  945. IWL_DEBUG_SCAN(priv, "Abort scan work\n");
  946. /* We keep scan_check work queued in case when firmware will not
  947. * report back scan completed notification */
  948. mutex_lock(&priv->mutex);
  949. iwl_scan_cancel_timeout(priv, 200);
  950. mutex_unlock(&priv->mutex);
  951. }
  952. static void iwl_bg_scan_completed(struct work_struct *work)
  953. {
  954. struct iwl_priv *priv =
  955. container_of(work, struct iwl_priv, scan_completed);
  956. mutex_lock(&priv->mutex);
  957. iwl_process_scan_complete(priv);
  958. mutex_unlock(&priv->mutex);
  959. }
  960. void iwl_setup_scan_deferred_work(struct iwl_priv *priv)
  961. {
  962. INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
  963. INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
  964. INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan);
  965. INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
  966. }
  967. void iwl_cancel_scan_deferred_work(struct iwl_priv *priv)
  968. {
  969. cancel_work_sync(&priv->start_internal_scan);
  970. cancel_work_sync(&priv->abort_scan);
  971. cancel_work_sync(&priv->scan_completed);
  972. if (cancel_delayed_work_sync(&priv->scan_check)) {
  973. mutex_lock(&priv->mutex);
  974. iwl_force_scan_end(priv);
  975. mutex_unlock(&priv->mutex);
  976. }
  977. }
  978. void iwl_scan_roc_expired(struct iwl_priv *priv)
  979. {
  980. /*
  981. * The status bit should be set here, to prevent a race
  982. * where the atomic_read returns 1, but before the execution continues
  983. * iwl_scan_offchannel_skb_status() checks if the status bit is set
  984. */
  985. set_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status);
  986. if (atomic_read(&priv->num_aux_in_flight) == 0) {
  987. ieee80211_remain_on_channel_expired(priv->hw);
  988. priv->hw_roc_channel = NULL;
  989. schedule_delayed_work(&priv->hw_roc_disable_work,
  990. 10 * HZ);
  991. clear_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status);
  992. } else {
  993. IWL_DEBUG_SCAN(priv, "ROC done with %d frames in aux\n",
  994. atomic_read(&priv->num_aux_in_flight));
  995. }
  996. }
  997. void iwl_scan_offchannel_skb(struct iwl_priv *priv)
  998. {
  999. WARN_ON(!priv->hw_roc_start_notified);
  1000. atomic_inc(&priv->num_aux_in_flight);
  1001. }
  1002. void iwl_scan_offchannel_skb_status(struct iwl_priv *priv)
  1003. {
  1004. if (atomic_dec_return(&priv->num_aux_in_flight) == 0 &&
  1005. test_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status)) {
  1006. IWL_DEBUG_SCAN(priv, "0 aux frames. Calling ROC expired\n");
  1007. iwl_scan_roc_expired(priv);
  1008. }
  1009. }