scan.c 45 KB

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