iwl-scan.c 32 KB

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