scan.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <linuxwifi@intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/etherdevice.h>
  66. #include <net/mac80211.h>
  67. #include "mvm.h"
  68. #include "fw-api-scan.h"
  69. #define IWL_DENSE_EBS_SCAN_RATIO 5
  70. #define IWL_SPARSE_EBS_SCAN_RATIO 1
  71. enum iwl_mvm_traffic_load {
  72. IWL_MVM_TRAFFIC_LOW,
  73. IWL_MVM_TRAFFIC_MEDIUM,
  74. IWL_MVM_TRAFFIC_HIGH,
  75. };
  76. struct iwl_mvm_scan_timing_params {
  77. u32 dwell_active;
  78. u32 dwell_passive;
  79. u32 dwell_fragmented;
  80. u32 suspend_time;
  81. u32 max_out_time;
  82. };
  83. static struct iwl_mvm_scan_timing_params scan_timing[] = {
  84. [IWL_SCAN_TYPE_UNASSOC] = {
  85. .dwell_active = 10,
  86. .dwell_passive = 110,
  87. .dwell_fragmented = 44,
  88. .suspend_time = 0,
  89. .max_out_time = 0,
  90. },
  91. [IWL_SCAN_TYPE_WILD] = {
  92. .dwell_active = 10,
  93. .dwell_passive = 110,
  94. .dwell_fragmented = 44,
  95. .suspend_time = 30,
  96. .max_out_time = 120,
  97. },
  98. [IWL_SCAN_TYPE_MILD] = {
  99. .dwell_active = 10,
  100. .dwell_passive = 110,
  101. .dwell_fragmented = 44,
  102. .suspend_time = 120,
  103. .max_out_time = 120,
  104. },
  105. [IWL_SCAN_TYPE_FRAGMENTED] = {
  106. .dwell_active = 10,
  107. .dwell_passive = 110,
  108. .dwell_fragmented = 44,
  109. .suspend_time = 95,
  110. .max_out_time = 44,
  111. },
  112. };
  113. struct iwl_mvm_scan_params {
  114. enum iwl_mvm_scan_type type;
  115. u32 n_channels;
  116. u16 delay;
  117. int n_ssids;
  118. struct cfg80211_ssid *ssids;
  119. struct ieee80211_channel **channels;
  120. u32 flags;
  121. u8 *mac_addr;
  122. u8 *mac_addr_mask;
  123. bool no_cck;
  124. bool pass_all;
  125. int n_match_sets;
  126. struct iwl_scan_probe_req preq;
  127. struct cfg80211_match_set *match_sets;
  128. int n_scan_plans;
  129. struct cfg80211_sched_scan_plan *scan_plans;
  130. };
  131. static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
  132. {
  133. if (mvm->scan_rx_ant != ANT_NONE)
  134. return mvm->scan_rx_ant;
  135. return iwl_mvm_get_valid_rx_ant(mvm);
  136. }
  137. static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
  138. {
  139. u16 rx_chain;
  140. u8 rx_ant;
  141. rx_ant = iwl_mvm_scan_rx_ant(mvm);
  142. rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
  143. rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
  144. rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
  145. rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
  146. return cpu_to_le16(rx_chain);
  147. }
  148. static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
  149. {
  150. if (band == IEEE80211_BAND_2GHZ)
  151. return cpu_to_le32(PHY_BAND_24);
  152. else
  153. return cpu_to_le32(PHY_BAND_5);
  154. }
  155. static inline __le32
  156. iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
  157. bool no_cck)
  158. {
  159. u32 tx_ant;
  160. mvm->scan_last_antenna_idx =
  161. iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
  162. mvm->scan_last_antenna_idx);
  163. tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
  164. if (band == IEEE80211_BAND_2GHZ && !no_cck)
  165. return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
  166. tx_ant);
  167. else
  168. return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
  169. }
  170. static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
  171. struct ieee80211_vif *vif)
  172. {
  173. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  174. int *global_cnt = data;
  175. if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
  176. mvmvif->phy_ctxt->id < MAX_PHYS)
  177. *global_cnt += 1;
  178. }
  179. static enum iwl_mvm_traffic_load iwl_mvm_get_traffic_load(struct iwl_mvm *mvm)
  180. {
  181. return IWL_MVM_TRAFFIC_LOW;
  182. }
  183. static enum
  184. iwl_mvm_scan_type iwl_mvm_get_scan_type(struct iwl_mvm *mvm, bool p2p_device)
  185. {
  186. int global_cnt = 0;
  187. enum iwl_mvm_traffic_load load;
  188. bool low_latency;
  189. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  190. IEEE80211_IFACE_ITER_NORMAL,
  191. iwl_mvm_scan_condition_iterator,
  192. &global_cnt);
  193. if (!global_cnt)
  194. return IWL_SCAN_TYPE_UNASSOC;
  195. load = iwl_mvm_get_traffic_load(mvm);
  196. low_latency = iwl_mvm_low_latency(mvm);
  197. if ((load == IWL_MVM_TRAFFIC_HIGH || low_latency) && !p2p_device &&
  198. fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAGMENTED_SCAN))
  199. return IWL_SCAN_TYPE_FRAGMENTED;
  200. if (load >= IWL_MVM_TRAFFIC_MEDIUM || low_latency)
  201. return IWL_SCAN_TYPE_MILD;
  202. return IWL_SCAN_TYPE_WILD;
  203. }
  204. static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
  205. {
  206. /* require rrm scan whenever the fw supports it */
  207. return fw_has_capa(&mvm->fw->ucode_capa,
  208. IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT);
  209. }
  210. static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)
  211. {
  212. int max_probe_len;
  213. max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
  214. /* we create the 802.11 header and SSID element */
  215. max_probe_len -= 24 + 2;
  216. /* DS parameter set element is added on 2.4GHZ band if required */
  217. if (iwl_mvm_rrm_scan_needed(mvm))
  218. max_probe_len -= 3;
  219. return max_probe_len;
  220. }
  221. int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
  222. {
  223. int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);
  224. /* TODO: [BUG] This function should return the maximum allowed size of
  225. * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
  226. * in the same command. So the correct implementation of this function
  227. * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
  228. * command has only 512 bytes and it would leave us with about 240
  229. * bytes for scan IEs, which is clearly not enough. So meanwhile
  230. * we will report an incorrect value. This may result in a failure to
  231. * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
  232. * functions with -ENOBUFS, if a large enough probe will be provided.
  233. */
  234. return max_ie_len;
  235. }
  236. static u8 *iwl_mvm_dump_channel_list(struct iwl_scan_results_notif *res,
  237. int num_res, u8 *buf, size_t buf_size)
  238. {
  239. int i;
  240. u8 *pos = buf, *end = buf + buf_size;
  241. for (i = 0; pos < end && i < num_res; i++)
  242. pos += snprintf(pos, end - pos, " %u", res[i].channel);
  243. /* terminate the string in case the buffer was too short */
  244. *(buf + buf_size - 1) = '\0';
  245. return buf;
  246. }
  247. void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
  248. struct iwl_rx_cmd_buffer *rxb)
  249. {
  250. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  251. struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
  252. u8 buf[256];
  253. IWL_DEBUG_SCAN(mvm,
  254. "Scan offload iteration complete: status=0x%x scanned channels=%d channels list: %s\n",
  255. notif->status, notif->scanned_channels,
  256. iwl_mvm_dump_channel_list(notif->results,
  257. notif->scanned_channels, buf,
  258. sizeof(buf)));
  259. }
  260. void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
  261. struct iwl_rx_cmd_buffer *rxb)
  262. {
  263. IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
  264. ieee80211_sched_scan_results(mvm->hw);
  265. }
  266. static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status)
  267. {
  268. switch (status) {
  269. case IWL_SCAN_EBS_SUCCESS:
  270. return "successful";
  271. case IWL_SCAN_EBS_INACTIVE:
  272. return "inactive";
  273. case IWL_SCAN_EBS_FAILED:
  274. case IWL_SCAN_EBS_CHAN_NOT_FOUND:
  275. default:
  276. return "failed";
  277. }
  278. }
  279. void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
  280. struct iwl_rx_cmd_buffer *rxb)
  281. {
  282. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  283. struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;
  284. bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
  285. /* If this happens, the firmware has mistakenly sent an LMAC
  286. * notification during UMAC scans -- warn and ignore it.
  287. */
  288. if (WARN_ON_ONCE(fw_has_capa(&mvm->fw->ucode_capa,
  289. IWL_UCODE_TLV_CAPA_UMAC_SCAN)))
  290. return;
  291. /* scan status must be locked for proper checking */
  292. lockdep_assert_held(&mvm->mutex);
  293. /* We first check if we were stopping a scan, in which case we
  294. * just clear the stopping flag. Then we check if it was a
  295. * firmware initiated stop, in which case we need to inform
  296. * mac80211.
  297. * Note that we can have a stopping and a running scan
  298. * simultaneously, but we can't have two different types of
  299. * scans stopping or running at the same time (since LMAC
  300. * doesn't support it).
  301. */
  302. if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {
  303. WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);
  304. IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
  305. aborted ? "aborted" : "completed",
  306. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  307. IWL_DEBUG_SCAN(mvm,
  308. "Last line %d, Last iteration %d, Time after last iteration %d\n",
  309. scan_notif->last_schedule_line,
  310. scan_notif->last_schedule_iteration,
  311. __le32_to_cpu(scan_notif->time_after_last_iter));
  312. mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;
  313. } else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {
  314. IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",
  315. aborted ? "aborted" : "completed",
  316. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  317. mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;
  318. } else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
  319. WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);
  320. IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
  321. aborted ? "aborted" : "completed",
  322. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  323. IWL_DEBUG_SCAN(mvm,
  324. "Last line %d, Last iteration %d, Time after last iteration %d (FW)\n",
  325. scan_notif->last_schedule_line,
  326. scan_notif->last_schedule_iteration,
  327. __le32_to_cpu(scan_notif->time_after_last_iter));
  328. mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
  329. ieee80211_sched_scan_stopped(mvm->hw);
  330. } else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
  331. IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",
  332. aborted ? "aborted" : "completed",
  333. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  334. mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
  335. ieee80211_scan_completed(mvm->hw,
  336. scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
  337. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  338. }
  339. mvm->last_ebs_successful =
  340. scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ||
  341. scan_notif->ebs_status == IWL_SCAN_EBS_INACTIVE;
  342. }
  343. static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
  344. {
  345. int i;
  346. for (i = 0; i < PROBE_OPTION_MAX; i++) {
  347. if (!ssid_list[i].len)
  348. break;
  349. if (ssid_list[i].len == ssid_len &&
  350. !memcmp(ssid_list->ssid, ssid, ssid_len))
  351. return i;
  352. }
  353. return -1;
  354. }
  355. /* We insert the SSIDs in an inverted order, because the FW will
  356. * invert it back.
  357. */
  358. static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,
  359. struct iwl_ssid_ie *ssids,
  360. u32 *ssid_bitmap)
  361. {
  362. int i, j;
  363. int index;
  364. /*
  365. * copy SSIDs from match list.
  366. * iwl_config_sched_scan_profiles() uses the order of these ssids to
  367. * config match list.
  368. */
  369. for (i = 0, j = params->n_match_sets - 1;
  370. j >= 0 && i < PROBE_OPTION_MAX;
  371. i++, j--) {
  372. /* skip empty SSID matchsets */
  373. if (!params->match_sets[j].ssid.ssid_len)
  374. continue;
  375. ssids[i].id = WLAN_EID_SSID;
  376. ssids[i].len = params->match_sets[j].ssid.ssid_len;
  377. memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,
  378. ssids[i].len);
  379. }
  380. /* add SSIDs from scan SSID list */
  381. *ssid_bitmap = 0;
  382. for (j = params->n_ssids - 1;
  383. j >= 0 && i < PROBE_OPTION_MAX;
  384. i++, j--) {
  385. index = iwl_ssid_exist(params->ssids[j].ssid,
  386. params->ssids[j].ssid_len,
  387. ssids);
  388. if (index < 0) {
  389. ssids[i].id = WLAN_EID_SSID;
  390. ssids[i].len = params->ssids[j].ssid_len;
  391. memcpy(ssids[i].ssid, params->ssids[j].ssid,
  392. ssids[i].len);
  393. *ssid_bitmap |= BIT(i);
  394. } else {
  395. *ssid_bitmap |= BIT(index);
  396. }
  397. }
  398. }
  399. static int
  400. iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
  401. struct cfg80211_sched_scan_request *req)
  402. {
  403. struct iwl_scan_offload_profile *profile;
  404. struct iwl_scan_offload_profile_cfg *profile_cfg;
  405. struct iwl_scan_offload_blacklist *blacklist;
  406. struct iwl_host_cmd cmd = {
  407. .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
  408. .len[1] = sizeof(*profile_cfg),
  409. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  410. .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
  411. };
  412. int blacklist_len;
  413. int i;
  414. int ret;
  415. if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
  416. return -EIO;
  417. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
  418. blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
  419. else
  420. blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
  421. blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
  422. if (!blacklist)
  423. return -ENOMEM;
  424. profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
  425. if (!profile_cfg) {
  426. ret = -ENOMEM;
  427. goto free_blacklist;
  428. }
  429. cmd.data[0] = blacklist;
  430. cmd.len[0] = sizeof(*blacklist) * blacklist_len;
  431. cmd.data[1] = profile_cfg;
  432. /* No blacklist configuration */
  433. profile_cfg->num_profiles = req->n_match_sets;
  434. profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
  435. profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
  436. profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
  437. if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
  438. profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
  439. for (i = 0; i < req->n_match_sets; i++) {
  440. profile = &profile_cfg->profiles[i];
  441. profile->ssid_index = i;
  442. /* Support any cipher and auth algorithm */
  443. profile->unicast_cipher = 0xff;
  444. profile->auth_alg = 0xff;
  445. profile->network_type = IWL_NETWORK_TYPE_ANY;
  446. profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
  447. profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
  448. }
  449. IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
  450. ret = iwl_mvm_send_cmd(mvm, &cmd);
  451. kfree(profile_cfg);
  452. free_blacklist:
  453. kfree(blacklist);
  454. return ret;
  455. }
  456. static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
  457. struct cfg80211_sched_scan_request *req)
  458. {
  459. if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
  460. IWL_DEBUG_SCAN(mvm,
  461. "Sending scheduled scan with filtering, n_match_sets %d\n",
  462. req->n_match_sets);
  463. return false;
  464. }
  465. IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
  466. return true;
  467. }
  468. static int iwl_mvm_lmac_scan_abort(struct iwl_mvm *mvm)
  469. {
  470. int ret;
  471. struct iwl_host_cmd cmd = {
  472. .id = SCAN_OFFLOAD_ABORT_CMD,
  473. };
  474. u32 status;
  475. ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
  476. if (ret)
  477. return ret;
  478. if (status != CAN_ABORT_STATUS) {
  479. /*
  480. * The scan abort will return 1 for success or
  481. * 2 for "failure". A failure condition can be
  482. * due to simply not being in an active scan which
  483. * can occur if we send the scan abort before the
  484. * microcode has notified us that a scan is completed.
  485. */
  486. IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
  487. ret = -ENOENT;
  488. }
  489. return ret;
  490. }
  491. static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,
  492. struct iwl_scan_req_tx_cmd *tx_cmd,
  493. bool no_cck)
  494. {
  495. tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
  496. TX_CMD_FLG_BT_DIS);
  497. tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
  498. IEEE80211_BAND_2GHZ,
  499. no_cck);
  500. tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
  501. tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
  502. TX_CMD_FLG_BT_DIS);
  503. tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
  504. IEEE80211_BAND_5GHZ,
  505. no_cck);
  506. tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
  507. }
  508. static void
  509. iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
  510. struct ieee80211_channel **channels,
  511. int n_channels, u32 ssid_bitmap,
  512. struct iwl_scan_req_lmac *cmd)
  513. {
  514. struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
  515. int i;
  516. for (i = 0; i < n_channels; i++) {
  517. channel_cfg[i].channel_num =
  518. cpu_to_le16(channels[i]->hw_value);
  519. channel_cfg[i].iter_count = cpu_to_le16(1);
  520. channel_cfg[i].iter_interval = 0;
  521. channel_cfg[i].flags =
  522. cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
  523. ssid_bitmap);
  524. }
  525. }
  526. static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
  527. size_t len, u8 *const pos)
  528. {
  529. static const u8 before_ds_params[] = {
  530. WLAN_EID_SSID,
  531. WLAN_EID_SUPP_RATES,
  532. WLAN_EID_REQUEST,
  533. WLAN_EID_EXT_SUPP_RATES,
  534. };
  535. size_t offs;
  536. u8 *newpos = pos;
  537. if (!iwl_mvm_rrm_scan_needed(mvm)) {
  538. memcpy(newpos, ies, len);
  539. return newpos + len;
  540. }
  541. offs = ieee80211_ie_split(ies, len,
  542. before_ds_params,
  543. ARRAY_SIZE(before_ds_params),
  544. 0);
  545. memcpy(newpos, ies, offs);
  546. newpos += offs;
  547. /* Add a placeholder for DS Parameter Set element */
  548. *newpos++ = WLAN_EID_DS_PARAMS;
  549. *newpos++ = 1;
  550. *newpos++ = 0;
  551. memcpy(newpos, ies + offs, len - offs);
  552. newpos += len - offs;
  553. return newpos;
  554. }
  555. static void
  556. iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  557. struct ieee80211_scan_ies *ies,
  558. struct iwl_mvm_scan_params *params)
  559. {
  560. struct ieee80211_mgmt *frame = (void *)params->preq.buf;
  561. u8 *pos, *newpos;
  562. const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
  563. params->mac_addr : NULL;
  564. /*
  565. * Unfortunately, right now the offload scan doesn't support randomising
  566. * within the firmware, so until the firmware API is ready we implement
  567. * it in the driver. This means that the scan iterations won't really be
  568. * random, only when it's restarted, but at least that helps a bit.
  569. */
  570. if (mac_addr)
  571. get_random_mask_addr(frame->sa, mac_addr,
  572. params->mac_addr_mask);
  573. else
  574. memcpy(frame->sa, vif->addr, ETH_ALEN);
  575. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  576. eth_broadcast_addr(frame->da);
  577. eth_broadcast_addr(frame->bssid);
  578. frame->seq_ctrl = 0;
  579. pos = frame->u.probe_req.variable;
  580. *pos++ = WLAN_EID_SSID;
  581. *pos++ = 0;
  582. params->preq.mac_header.offset = 0;
  583. params->preq.mac_header.len = cpu_to_le16(24 + 2);
  584. /* Insert ds parameter set element on 2.4 GHz band */
  585. newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
  586. ies->ies[IEEE80211_BAND_2GHZ],
  587. ies->len[IEEE80211_BAND_2GHZ],
  588. pos);
  589. params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);
  590. params->preq.band_data[0].len = cpu_to_le16(newpos - pos);
  591. pos = newpos;
  592. memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ],
  593. ies->len[IEEE80211_BAND_5GHZ]);
  594. params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);
  595. params->preq.band_data[1].len =
  596. cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]);
  597. pos += ies->len[IEEE80211_BAND_5GHZ];
  598. memcpy(pos, ies->common_ies, ies->common_ie_len);
  599. params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);
  600. params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);
  601. }
  602. static __le32 iwl_mvm_scan_priority(struct iwl_mvm *mvm,
  603. enum iwl_scan_priority_ext prio)
  604. {
  605. if (fw_has_api(&mvm->fw->ucode_capa,
  606. IWL_UCODE_TLV_API_EXT_SCAN_PRIORITY))
  607. return cpu_to_le32(prio);
  608. if (prio <= IWL_SCAN_PRIORITY_EXT_2)
  609. return cpu_to_le32(IWL_SCAN_PRIORITY_LOW);
  610. if (prio <= IWL_SCAN_PRIORITY_EXT_4)
  611. return cpu_to_le32(IWL_SCAN_PRIORITY_MEDIUM);
  612. return cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
  613. }
  614. static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,
  615. struct iwl_scan_req_lmac *cmd,
  616. struct iwl_mvm_scan_params *params)
  617. {
  618. cmd->active_dwell = scan_timing[params->type].dwell_active;
  619. cmd->passive_dwell = scan_timing[params->type].dwell_passive;
  620. cmd->fragmented_dwell = scan_timing[params->type].dwell_fragmented;
  621. cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);
  622. cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);
  623. cmd->scan_prio = iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
  624. }
  625. static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,
  626. struct ieee80211_scan_ies *ies,
  627. int n_channels)
  628. {
  629. return ((n_ssids <= PROBE_OPTION_MAX) &&
  630. (n_channels <= mvm->fw->ucode_capa.n_scan_channels) &
  631. (ies->common_ie_len +
  632. ies->len[NL80211_BAND_2GHZ] +
  633. ies->len[NL80211_BAND_5GHZ] <=
  634. iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));
  635. }
  636. static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm,
  637. struct ieee80211_vif *vif)
  638. {
  639. const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;
  640. /* We can only use EBS if:
  641. * 1. the feature is supported;
  642. * 2. the last EBS was successful;
  643. * 3. if only single scan, the single scan EBS API is supported;
  644. * 4. it's not a p2p find operation.
  645. */
  646. return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
  647. mvm->last_ebs_successful &&
  648. vif->type != NL80211_IFTYPE_P2P_DEVICE);
  649. }
  650. static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
  651. struct iwl_mvm_scan_params *params)
  652. {
  653. int flags = 0;
  654. if (params->n_ssids == 0)
  655. flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
  656. if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
  657. flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
  658. if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
  659. flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
  660. if (iwl_mvm_rrm_scan_needed(mvm))
  661. flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
  662. if (params->pass_all)
  663. flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
  664. else
  665. flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
  666. #ifdef CONFIG_IWLWIFI_DEBUGFS
  667. if (mvm->scan_iter_notif_enabled)
  668. flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
  669. #endif
  670. return flags;
  671. }
  672. static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  673. struct iwl_mvm_scan_params *params)
  674. {
  675. struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
  676. struct iwl_scan_probe_req *preq =
  677. (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
  678. mvm->fw->ucode_capa.n_scan_channels);
  679. u32 ssid_bitmap = 0;
  680. int i;
  681. lockdep_assert_held(&mvm->mutex);
  682. memset(cmd, 0, ksize(cmd));
  683. if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
  684. return -EINVAL;
  685. iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
  686. cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
  687. cmd->iter_num = cpu_to_le32(1);
  688. cmd->n_channels = (u8)params->n_channels;
  689. cmd->delay = cpu_to_le32(params->delay);
  690. cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params));
  691. cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
  692. cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
  693. MAC_FILTER_IN_BEACON);
  694. iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
  695. iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
  696. /* this API uses bits 1-20 instead of 0-19 */
  697. ssid_bitmap <<= 1;
  698. for (i = 0; i < params->n_scan_plans; i++) {
  699. struct cfg80211_sched_scan_plan *scan_plan =
  700. &params->scan_plans[i];
  701. cmd->schedule[i].delay =
  702. cpu_to_le16(scan_plan->interval);
  703. cmd->schedule[i].iterations = scan_plan->iterations;
  704. cmd->schedule[i].full_scan_mul = 1;
  705. }
  706. /*
  707. * If the number of iterations of the last scan plan is set to
  708. * zero, it should run infinitely. However, this is not always the case.
  709. * For example, when regular scan is requested the driver sets one scan
  710. * plan with one iteration.
  711. */
  712. if (!cmd->schedule[i - 1].iterations)
  713. cmd->schedule[i - 1].iterations = 0xff;
  714. if (iwl_mvm_scan_use_ebs(mvm, vif)) {
  715. cmd->channel_opt[0].flags =
  716. cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
  717. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  718. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
  719. cmd->channel_opt[0].non_ebs_ratio =
  720. cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
  721. cmd->channel_opt[1].flags =
  722. cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
  723. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  724. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
  725. cmd->channel_opt[1].non_ebs_ratio =
  726. cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
  727. }
  728. iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
  729. params->n_channels, ssid_bitmap, cmd);
  730. *preq = params->preq;
  731. return 0;
  732. }
  733. static int rate_to_scan_rate_flag(unsigned int rate)
  734. {
  735. static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
  736. [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
  737. [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
  738. [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
  739. [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
  740. [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
  741. [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
  742. [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
  743. [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
  744. [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
  745. [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
  746. [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
  747. [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
  748. };
  749. return rate_to_scan_rate[rate];
  750. }
  751. static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
  752. {
  753. struct ieee80211_supported_band *band;
  754. unsigned int rates = 0;
  755. int i;
  756. band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  757. for (i = 0; i < band->n_bitrates; i++)
  758. rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
  759. band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  760. for (i = 0; i < band->n_bitrates; i++)
  761. rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
  762. /* Set both basic rates and supported rates */
  763. rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
  764. return cpu_to_le32(rates);
  765. }
  766. int iwl_mvm_config_scan(struct iwl_mvm *mvm)
  767. {
  768. struct iwl_scan_config *scan_config;
  769. struct ieee80211_supported_band *band;
  770. int num_channels =
  771. mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels +
  772. mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
  773. int ret, i, j = 0, cmd_size;
  774. struct iwl_host_cmd cmd = {
  775. .id = iwl_cmd_id(SCAN_CFG_CMD, IWL_ALWAYS_LONG_GROUP, 0),
  776. };
  777. enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, false);
  778. if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
  779. return -ENOBUFS;
  780. if (type == mvm->scan_type)
  781. return 0;
  782. cmd_size = sizeof(*scan_config) + mvm->fw->ucode_capa.n_scan_channels;
  783. scan_config = kzalloc(cmd_size, GFP_KERNEL);
  784. if (!scan_config)
  785. return -ENOMEM;
  786. scan_config->flags = cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE |
  787. SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
  788. SCAN_CONFIG_FLAG_SET_TX_CHAINS |
  789. SCAN_CONFIG_FLAG_SET_RX_CHAINS |
  790. SCAN_CONFIG_FLAG_SET_ALL_TIMES |
  791. SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
  792. SCAN_CONFIG_FLAG_SET_MAC_ADDR |
  793. SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS|
  794. SCAN_CONFIG_N_CHANNELS(num_channels) |
  795. (type == IWL_SCAN_TYPE_FRAGMENTED ?
  796. SCAN_CONFIG_FLAG_SET_FRAGMENTED :
  797. SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED));
  798. scan_config->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
  799. scan_config->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
  800. scan_config->legacy_rates = iwl_mvm_scan_config_rates(mvm);
  801. scan_config->out_of_channel_time =
  802. cpu_to_le32(scan_timing[type].max_out_time);
  803. scan_config->suspend_time = cpu_to_le32(scan_timing[type].suspend_time);
  804. scan_config->dwell_active = scan_timing[type].dwell_active;
  805. scan_config->dwell_passive = scan_timing[type].dwell_passive;
  806. scan_config->dwell_fragmented = scan_timing[type].dwell_fragmented;
  807. memcpy(&scan_config->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
  808. scan_config->bcast_sta_id = mvm->aux_sta.sta_id;
  809. scan_config->channel_flags = IWL_CHANNEL_FLAG_EBS |
  810. IWL_CHANNEL_FLAG_ACCURATE_EBS |
  811. IWL_CHANNEL_FLAG_EBS_ADD |
  812. IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
  813. band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  814. for (i = 0; i < band->n_channels; i++, j++)
  815. scan_config->channel_array[j] = band->channels[i].hw_value;
  816. band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  817. for (i = 0; i < band->n_channels; i++, j++)
  818. scan_config->channel_array[j] = band->channels[i].hw_value;
  819. cmd.data[0] = scan_config;
  820. cmd.len[0] = cmd_size;
  821. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  822. IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
  823. ret = iwl_mvm_send_cmd(mvm, &cmd);
  824. if (!ret)
  825. mvm->scan_type = type;
  826. kfree(scan_config);
  827. return ret;
  828. }
  829. static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)
  830. {
  831. int i;
  832. for (i = 0; i < mvm->max_scans; i++)
  833. if (mvm->scan_uid_status[i] == status)
  834. return i;
  835. return -ENOENT;
  836. }
  837. static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params *params)
  838. {
  839. return params->n_scan_plans == 1 &&
  840. params->scan_plans[0].iterations == 1;
  841. }
  842. static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
  843. struct iwl_scan_req_umac *cmd,
  844. struct iwl_mvm_scan_params *params)
  845. {
  846. cmd->active_dwell = scan_timing[params->type].dwell_active;
  847. cmd->passive_dwell = scan_timing[params->type].dwell_passive;
  848. cmd->fragmented_dwell = scan_timing[params->type].dwell_fragmented;
  849. cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);
  850. cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);
  851. cmd->scan_priority =
  852. iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
  853. if (iwl_mvm_is_regular_scan(params))
  854. cmd->ooc_priority =
  855. iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
  856. else
  857. cmd->ooc_priority =
  858. iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_2);
  859. }
  860. static void
  861. iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
  862. struct ieee80211_channel **channels,
  863. int n_channels, u32 ssid_bitmap,
  864. struct iwl_scan_req_umac *cmd)
  865. {
  866. struct iwl_scan_channel_cfg_umac *channel_cfg = (void *)&cmd->data;
  867. int i;
  868. for (i = 0; i < n_channels; i++) {
  869. channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
  870. channel_cfg[i].channel_num = channels[i]->hw_value;
  871. channel_cfg[i].iter_count = 1;
  872. channel_cfg[i].iter_interval = 0;
  873. }
  874. }
  875. static u32 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
  876. struct iwl_mvm_scan_params *params)
  877. {
  878. int flags = 0;
  879. if (params->n_ssids == 0)
  880. flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
  881. if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
  882. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
  883. if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
  884. flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
  885. if (iwl_mvm_rrm_scan_needed(mvm))
  886. flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
  887. if (params->pass_all)
  888. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
  889. else
  890. flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
  891. if (!iwl_mvm_is_regular_scan(params))
  892. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
  893. #ifdef CONFIG_IWLWIFI_DEBUGFS
  894. if (mvm->scan_iter_notif_enabled)
  895. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
  896. #endif
  897. return flags;
  898. }
  899. static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  900. struct iwl_mvm_scan_params *params,
  901. int type)
  902. {
  903. struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
  904. struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data +
  905. sizeof(struct iwl_scan_channel_cfg_umac) *
  906. mvm->fw->ucode_capa.n_scan_channels;
  907. int uid, i;
  908. u32 ssid_bitmap = 0;
  909. lockdep_assert_held(&mvm->mutex);
  910. if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
  911. return -EINVAL;
  912. uid = iwl_mvm_scan_uid_by_status(mvm, 0);
  913. if (uid < 0)
  914. return uid;
  915. memset(cmd, 0, ksize(cmd));
  916. iwl_mvm_scan_umac_dwell(mvm, cmd, params);
  917. mvm->scan_uid_status[uid] = type;
  918. cmd->uid = cpu_to_le32(uid);
  919. cmd->general_flags = cpu_to_le32(iwl_mvm_scan_umac_flags(mvm, params));
  920. if (type == IWL_MVM_SCAN_SCHED)
  921. cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);
  922. if (iwl_mvm_scan_use_ebs(mvm, vif))
  923. cmd->channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
  924. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  925. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
  926. cmd->n_channels = params->n_channels;
  927. iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
  928. iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
  929. params->n_channels, ssid_bitmap, cmd);
  930. for (i = 0; i < params->n_scan_plans; i++) {
  931. struct cfg80211_sched_scan_plan *scan_plan =
  932. &params->scan_plans[i];
  933. sec_part->schedule[i].iter_count = scan_plan->iterations;
  934. sec_part->schedule[i].interval =
  935. cpu_to_le16(scan_plan->interval);
  936. }
  937. /*
  938. * If the number of iterations of the last scan plan is set to
  939. * zero, it should run infinitely. However, this is not always the case.
  940. * For example, when regular scan is requested the driver sets one scan
  941. * plan with one iteration.
  942. */
  943. if (!sec_part->schedule[i - 1].iter_count)
  944. sec_part->schedule[i - 1].iter_count = 0xff;
  945. sec_part->delay = cpu_to_le16(params->delay);
  946. sec_part->preq = params->preq;
  947. return 0;
  948. }
  949. static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
  950. {
  951. return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
  952. }
  953. static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
  954. {
  955. /* This looks a bit arbitrary, but the idea is that if we run
  956. * out of possible simultaneous scans and the userspace is
  957. * trying to run a scan type that is already running, we
  958. * return -EBUSY. But if the userspace wants to start a
  959. * different type of scan, we stop the opposite type to make
  960. * space for the new request. The reason is backwards
  961. * compatibility with old wpa_supplicant that wouldn't stop a
  962. * scheduled scan before starting a normal scan.
  963. */
  964. if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
  965. return 0;
  966. /* Use a switch, even though this is a bitmask, so that more
  967. * than one bits set will fall in default and we will warn.
  968. */
  969. switch (type) {
  970. case IWL_MVM_SCAN_REGULAR:
  971. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
  972. return -EBUSY;
  973. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
  974. case IWL_MVM_SCAN_SCHED:
  975. if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
  976. return -EBUSY;
  977. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
  978. case IWL_MVM_SCAN_NETDETECT:
  979. /* No need to stop anything for net-detect since the
  980. * firmware is restarted anyway. This way, any sched
  981. * scans that were running will be restarted when we
  982. * resume.
  983. */
  984. return 0;
  985. default:
  986. WARN_ON(1);
  987. break;
  988. }
  989. return -EIO;
  990. }
  991. int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  992. struct cfg80211_scan_request *req,
  993. struct ieee80211_scan_ies *ies)
  994. {
  995. struct iwl_host_cmd hcmd = {
  996. .len = { iwl_mvm_scan_size(mvm), },
  997. .data = { mvm->scan_cmd, },
  998. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  999. };
  1000. struct iwl_mvm_scan_params params = {};
  1001. int ret;
  1002. struct cfg80211_sched_scan_plan scan_plan = { .iterations = 1 };
  1003. lockdep_assert_held(&mvm->mutex);
  1004. if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
  1005. IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
  1006. return -EBUSY;
  1007. }
  1008. ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
  1009. if (ret)
  1010. return ret;
  1011. /* we should have failed registration if scan_cmd was NULL */
  1012. if (WARN_ON(!mvm->scan_cmd))
  1013. return -ENOMEM;
  1014. if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
  1015. return -ENOBUFS;
  1016. params.n_ssids = req->n_ssids;
  1017. params.flags = req->flags;
  1018. params.n_channels = req->n_channels;
  1019. params.delay = 0;
  1020. params.ssids = req->ssids;
  1021. params.channels = req->channels;
  1022. params.mac_addr = req->mac_addr;
  1023. params.mac_addr_mask = req->mac_addr_mask;
  1024. params.no_cck = req->no_cck;
  1025. params.pass_all = true;
  1026. params.n_match_sets = 0;
  1027. params.match_sets = NULL;
  1028. params.scan_plans = &scan_plan;
  1029. params.n_scan_plans = 1;
  1030. params.type =
  1031. iwl_mvm_get_scan_type(mvm,
  1032. vif->type == NL80211_IFTYPE_P2P_DEVICE);
  1033. iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
  1034. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1035. hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
  1036. ret = iwl_mvm_scan_umac(mvm, vif, &params,
  1037. IWL_MVM_SCAN_REGULAR);
  1038. } else {
  1039. hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
  1040. ret = iwl_mvm_scan_lmac(mvm, vif, &params);
  1041. }
  1042. if (ret)
  1043. return ret;
  1044. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1045. if (ret) {
  1046. /* If the scan failed, it usually means that the FW was unable
  1047. * to allocate the time events. Warn on it, but maybe we
  1048. * should try to send the command again with different params.
  1049. */
  1050. IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
  1051. return ret;
  1052. }
  1053. IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
  1054. mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
  1055. iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
  1056. return 0;
  1057. }
  1058. int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
  1059. struct ieee80211_vif *vif,
  1060. struct cfg80211_sched_scan_request *req,
  1061. struct ieee80211_scan_ies *ies,
  1062. int type)
  1063. {
  1064. struct iwl_host_cmd hcmd = {
  1065. .len = { iwl_mvm_scan_size(mvm), },
  1066. .data = { mvm->scan_cmd, },
  1067. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1068. };
  1069. struct iwl_mvm_scan_params params = {};
  1070. int ret;
  1071. lockdep_assert_held(&mvm->mutex);
  1072. if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
  1073. IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
  1074. return -EBUSY;
  1075. }
  1076. ret = iwl_mvm_check_running_scans(mvm, type);
  1077. if (ret)
  1078. return ret;
  1079. /* we should have failed registration if scan_cmd was NULL */
  1080. if (WARN_ON(!mvm->scan_cmd))
  1081. return -ENOMEM;
  1082. if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
  1083. return -ENOBUFS;
  1084. params.n_ssids = req->n_ssids;
  1085. params.flags = req->flags;
  1086. params.n_channels = req->n_channels;
  1087. params.ssids = req->ssids;
  1088. params.channels = req->channels;
  1089. params.mac_addr = req->mac_addr;
  1090. params.mac_addr_mask = req->mac_addr_mask;
  1091. params.no_cck = false;
  1092. params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
  1093. params.n_match_sets = req->n_match_sets;
  1094. params.match_sets = req->match_sets;
  1095. if (!req->n_scan_plans)
  1096. return -EINVAL;
  1097. params.n_scan_plans = req->n_scan_plans;
  1098. params.scan_plans = req->scan_plans;
  1099. params.type =
  1100. iwl_mvm_get_scan_type(mvm,
  1101. vif->type == NL80211_IFTYPE_P2P_DEVICE);
  1102. /* In theory, LMAC scans can handle a 32-bit delay, but since
  1103. * waiting for over 18 hours to start the scan is a bit silly
  1104. * and to keep it aligned with UMAC scans (which only support
  1105. * 16-bit delays), trim it down to 16-bits.
  1106. */
  1107. if (req->delay > U16_MAX) {
  1108. IWL_DEBUG_SCAN(mvm,
  1109. "delay value is > 16-bits, set to max possible\n");
  1110. params.delay = U16_MAX;
  1111. } else {
  1112. params.delay = req->delay;
  1113. }
  1114. ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
  1115. if (ret)
  1116. return ret;
  1117. iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
  1118. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1119. hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
  1120. ret = iwl_mvm_scan_umac(mvm, vif, &params, IWL_MVM_SCAN_SCHED);
  1121. } else {
  1122. hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
  1123. ret = iwl_mvm_scan_lmac(mvm, vif, &params);
  1124. }
  1125. if (ret)
  1126. return ret;
  1127. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1128. if (!ret) {
  1129. IWL_DEBUG_SCAN(mvm,
  1130. "Sched scan request was sent successfully\n");
  1131. mvm->scan_status |= type;
  1132. } else {
  1133. /* If the scan failed, it usually means that the FW was unable
  1134. * to allocate the time events. Warn on it, but maybe we
  1135. * should try to send the command again with different params.
  1136. */
  1137. IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
  1138. }
  1139. return ret;
  1140. }
  1141. void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
  1142. struct iwl_rx_cmd_buffer *rxb)
  1143. {
  1144. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1145. struct iwl_umac_scan_complete *notif = (void *)pkt->data;
  1146. u32 uid = __le32_to_cpu(notif->uid);
  1147. bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);
  1148. if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))
  1149. return;
  1150. /* if the scan is already stopping, we don't need to notify mac80211 */
  1151. if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {
  1152. ieee80211_scan_completed(mvm->hw, aborted);
  1153. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1154. } else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {
  1155. ieee80211_sched_scan_stopped(mvm->hw);
  1156. }
  1157. mvm->scan_status &= ~mvm->scan_uid_status[uid];
  1158. IWL_DEBUG_SCAN(mvm,
  1159. "Scan completed, uid %u type %u, status %s, EBS status %s\n",
  1160. uid, mvm->scan_uid_status[uid],
  1161. notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
  1162. "completed" : "aborted",
  1163. iwl_mvm_ebs_status_str(notif->ebs_status));
  1164. IWL_DEBUG_SCAN(mvm,
  1165. "Last line %d, Last iteration %d, Time from last iteration %d\n",
  1166. notif->last_schedule, notif->last_iter,
  1167. __le32_to_cpu(notif->time_from_last_iter));
  1168. if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&
  1169. notif->ebs_status != IWL_SCAN_EBS_INACTIVE)
  1170. mvm->last_ebs_successful = false;
  1171. mvm->scan_uid_status[uid] = 0;
  1172. }
  1173. void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
  1174. struct iwl_rx_cmd_buffer *rxb)
  1175. {
  1176. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1177. struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;
  1178. u8 buf[256];
  1179. IWL_DEBUG_SCAN(mvm,
  1180. "UMAC Scan iteration complete: status=0x%x scanned_channels=%d channels list: %s\n",
  1181. notif->status, notif->scanned_channels,
  1182. iwl_mvm_dump_channel_list(notif->results,
  1183. notif->scanned_channels, buf,
  1184. sizeof(buf)));
  1185. }
  1186. static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type)
  1187. {
  1188. struct iwl_umac_scan_abort cmd = {};
  1189. int uid, ret;
  1190. lockdep_assert_held(&mvm->mutex);
  1191. /* We should always get a valid index here, because we already
  1192. * checked that this type of scan was running in the generic
  1193. * code.
  1194. */
  1195. uid = iwl_mvm_scan_uid_by_status(mvm, type);
  1196. if (WARN_ON_ONCE(uid < 0))
  1197. return uid;
  1198. cmd.uid = cpu_to_le32(uid);
  1199. IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
  1200. ret = iwl_mvm_send_cmd_pdu(mvm,
  1201. iwl_cmd_id(SCAN_ABORT_UMAC,
  1202. IWL_ALWAYS_LONG_GROUP, 0),
  1203. 0, sizeof(cmd), &cmd);
  1204. if (!ret)
  1205. mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;
  1206. return ret;
  1207. }
  1208. static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)
  1209. {
  1210. struct iwl_notification_wait wait_scan_done;
  1211. static const u16 scan_done_notif[] = { SCAN_COMPLETE_UMAC,
  1212. SCAN_OFFLOAD_COMPLETE, };
  1213. int ret;
  1214. lockdep_assert_held(&mvm->mutex);
  1215. iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
  1216. scan_done_notif,
  1217. ARRAY_SIZE(scan_done_notif),
  1218. NULL, NULL);
  1219. IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
  1220. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  1221. ret = iwl_mvm_umac_scan_abort(mvm, type);
  1222. else
  1223. ret = iwl_mvm_lmac_scan_abort(mvm);
  1224. if (ret) {
  1225. IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);
  1226. iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
  1227. return ret;
  1228. }
  1229. ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
  1230. return ret;
  1231. }
  1232. int iwl_mvm_scan_size(struct iwl_mvm *mvm)
  1233. {
  1234. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  1235. return sizeof(struct iwl_scan_req_umac) +
  1236. sizeof(struct iwl_scan_channel_cfg_umac) *
  1237. mvm->fw->ucode_capa.n_scan_channels +
  1238. sizeof(struct iwl_scan_req_umac_tail);
  1239. return sizeof(struct iwl_scan_req_lmac) +
  1240. sizeof(struct iwl_scan_channel_cfg_lmac) *
  1241. mvm->fw->ucode_capa.n_scan_channels +
  1242. sizeof(struct iwl_scan_probe_req);
  1243. }
  1244. /*
  1245. * This function is used in nic restart flow, to inform mac80211 about scans
  1246. * that was aborted by restart flow or by an assert.
  1247. */
  1248. void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
  1249. {
  1250. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1251. int uid, i;
  1252. uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);
  1253. if (uid >= 0) {
  1254. ieee80211_scan_completed(mvm->hw, true);
  1255. mvm->scan_uid_status[uid] = 0;
  1256. }
  1257. uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);
  1258. if (uid >= 0 && !mvm->restart_fw) {
  1259. ieee80211_sched_scan_stopped(mvm->hw);
  1260. mvm->scan_uid_status[uid] = 0;
  1261. }
  1262. /* We shouldn't have any UIDs still set. Loop over all the
  1263. * UIDs to make sure there's nothing left there and warn if
  1264. * any is found.
  1265. */
  1266. for (i = 0; i < mvm->max_scans; i++) {
  1267. if (WARN_ONCE(mvm->scan_uid_status[i],
  1268. "UMAC scan UID %d status was not cleaned\n",
  1269. i))
  1270. mvm->scan_uid_status[i] = 0;
  1271. }
  1272. } else {
  1273. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
  1274. ieee80211_scan_completed(mvm->hw, true);
  1275. /* Sched scan will be restarted by mac80211 in
  1276. * restart_hw, so do not report if FW is about to be
  1277. * restarted.
  1278. */
  1279. if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) && !mvm->restart_fw)
  1280. ieee80211_sched_scan_stopped(mvm->hw);
  1281. }
  1282. }
  1283. int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)
  1284. {
  1285. int ret;
  1286. if (!(mvm->scan_status & type))
  1287. return 0;
  1288. if (iwl_mvm_is_radio_killed(mvm)) {
  1289. ret = 0;
  1290. goto out;
  1291. }
  1292. ret = iwl_mvm_scan_stop_wait(mvm, type);
  1293. if (!ret)
  1294. mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;
  1295. out:
  1296. /* Clear the scan status so the next scan requests will
  1297. * succeed and mark the scan as stopping, so that the Rx
  1298. * handler doesn't do anything, as the scan was stopped from
  1299. * above.
  1300. */
  1301. mvm->scan_status &= ~type;
  1302. if (type == IWL_MVM_SCAN_REGULAR) {
  1303. /* Since the rx handler won't do anything now, we have
  1304. * to release the scan reference here.
  1305. */
  1306. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1307. if (notify)
  1308. ieee80211_scan_completed(mvm->hw, true);
  1309. } else if (notify) {
  1310. ieee80211_sched_scan_stopped(mvm->hw);
  1311. }
  1312. return ret;
  1313. }