scan.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031
  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. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  11. * Copyright(c) 2018 Intel Corporation
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of version 2 of the GNU General Public License as
  15. * published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program
  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. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  37. * Copyright(c) 2018 Intel Corporation
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include <linux/etherdevice.h>
  68. #include <net/mac80211.h>
  69. #include "mvm.h"
  70. #include "fw/api/scan.h"
  71. #include "iwl-io.h"
  72. #define IWL_DENSE_EBS_SCAN_RATIO 5
  73. #define IWL_SPARSE_EBS_SCAN_RATIO 1
  74. #define IWL_SCAN_DWELL_ACTIVE 10
  75. #define IWL_SCAN_DWELL_PASSIVE 110
  76. #define IWL_SCAN_DWELL_FRAGMENTED 44
  77. #define IWL_SCAN_DWELL_EXTENDED 90
  78. #define IWL_SCAN_NUM_OF_FRAGS 3
  79. /* adaptive dwell max budget time [TU] for full scan */
  80. #define IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN 300
  81. /* adaptive dwell max budget time [TU] for directed scan */
  82. #define IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN 100
  83. /* adaptive dwell default APs number */
  84. #define IWL_SCAN_ADWELL_DEFAULT_N_APS 2
  85. /* adaptive dwell default APs number in social channels (1, 6, 11) */
  86. #define IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL 10
  87. struct iwl_mvm_scan_timing_params {
  88. u32 suspend_time;
  89. u32 max_out_time;
  90. };
  91. static struct iwl_mvm_scan_timing_params scan_timing[] = {
  92. [IWL_SCAN_TYPE_UNASSOC] = {
  93. .suspend_time = 0,
  94. .max_out_time = 0,
  95. },
  96. [IWL_SCAN_TYPE_WILD] = {
  97. .suspend_time = 30,
  98. .max_out_time = 120,
  99. },
  100. [IWL_SCAN_TYPE_MILD] = {
  101. .suspend_time = 120,
  102. .max_out_time = 120,
  103. },
  104. [IWL_SCAN_TYPE_FRAGMENTED] = {
  105. .suspend_time = 95,
  106. .max_out_time = 44,
  107. },
  108. };
  109. struct iwl_mvm_scan_params {
  110. /* For CDB this is low band scan type, for non-CDB - type. */
  111. enum iwl_mvm_scan_type type;
  112. enum iwl_mvm_scan_type hb_type;
  113. u32 n_channels;
  114. u16 delay;
  115. int n_ssids;
  116. struct cfg80211_ssid *ssids;
  117. struct ieee80211_channel **channels;
  118. u32 flags;
  119. u8 *mac_addr;
  120. u8 *mac_addr_mask;
  121. bool no_cck;
  122. bool pass_all;
  123. int n_match_sets;
  124. struct iwl_scan_probe_req preq;
  125. struct cfg80211_match_set *match_sets;
  126. int n_scan_plans;
  127. struct cfg80211_sched_scan_plan *scan_plans;
  128. u32 measurement_dwell;
  129. };
  130. static inline void *iwl_mvm_get_scan_req_umac_data(struct iwl_mvm *mvm)
  131. {
  132. struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
  133. if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
  134. return (void *)&cmd->v8.data;
  135. if (iwl_mvm_is_adaptive_dwell_supported(mvm))
  136. return (void *)&cmd->v7.data;
  137. if (iwl_mvm_cdb_scan_api(mvm))
  138. return (void *)&cmd->v6.data;
  139. return (void *)&cmd->v1.data;
  140. }
  141. static inline struct iwl_scan_umac_chan_param *
  142. iwl_mvm_get_scan_req_umac_channel(struct iwl_mvm *mvm)
  143. {
  144. struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
  145. if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
  146. return &cmd->v8.channel;
  147. if (iwl_mvm_is_adaptive_dwell_supported(mvm))
  148. return &cmd->v7.channel;
  149. if (iwl_mvm_cdb_scan_api(mvm))
  150. return &cmd->v6.channel;
  151. return &cmd->v1.channel;
  152. }
  153. static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
  154. {
  155. if (mvm->scan_rx_ant != ANT_NONE)
  156. return mvm->scan_rx_ant;
  157. return iwl_mvm_get_valid_rx_ant(mvm);
  158. }
  159. static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
  160. {
  161. u16 rx_chain;
  162. u8 rx_ant;
  163. rx_ant = iwl_mvm_scan_rx_ant(mvm);
  164. rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
  165. rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
  166. rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
  167. rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
  168. return cpu_to_le16(rx_chain);
  169. }
  170. static __le32 iwl_mvm_scan_rxon_flags(enum nl80211_band band)
  171. {
  172. if (band == NL80211_BAND_2GHZ)
  173. return cpu_to_le32(PHY_BAND_24);
  174. else
  175. return cpu_to_le32(PHY_BAND_5);
  176. }
  177. static inline __le32
  178. iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum nl80211_band band,
  179. bool no_cck)
  180. {
  181. u32 tx_ant;
  182. mvm->scan_last_antenna_idx =
  183. iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
  184. mvm->scan_last_antenna_idx);
  185. tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
  186. if (band == NL80211_BAND_2GHZ && !no_cck)
  187. return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
  188. tx_ant);
  189. else
  190. return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
  191. }
  192. static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
  193. struct ieee80211_vif *vif)
  194. {
  195. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  196. int *global_cnt = data;
  197. if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
  198. mvmvif->phy_ctxt->id < NUM_PHY_CTX)
  199. *global_cnt += 1;
  200. }
  201. static enum iwl_mvm_traffic_load iwl_mvm_get_traffic_load(struct iwl_mvm *mvm)
  202. {
  203. return mvm->tcm.result.global_load;
  204. }
  205. static enum iwl_mvm_traffic_load
  206. iwl_mvm_get_traffic_load_band(struct iwl_mvm *mvm, enum nl80211_band band)
  207. {
  208. return mvm->tcm.result.band_load[band];
  209. }
  210. static enum
  211. iwl_mvm_scan_type _iwl_mvm_get_scan_type(struct iwl_mvm *mvm, bool p2p_device,
  212. enum iwl_mvm_traffic_load load,
  213. bool low_latency)
  214. {
  215. int global_cnt = 0;
  216. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  217. IEEE80211_IFACE_ITER_NORMAL,
  218. iwl_mvm_scan_condition_iterator,
  219. &global_cnt);
  220. if (!global_cnt)
  221. return IWL_SCAN_TYPE_UNASSOC;
  222. if ((load == IWL_MVM_TRAFFIC_HIGH || low_latency) && !p2p_device &&
  223. fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAGMENTED_SCAN))
  224. return IWL_SCAN_TYPE_FRAGMENTED;
  225. if (load >= IWL_MVM_TRAFFIC_MEDIUM || low_latency)
  226. return IWL_SCAN_TYPE_MILD;
  227. return IWL_SCAN_TYPE_WILD;
  228. }
  229. static enum
  230. iwl_mvm_scan_type iwl_mvm_get_scan_type(struct iwl_mvm *mvm, bool p2p_device)
  231. {
  232. enum iwl_mvm_traffic_load load;
  233. bool low_latency;
  234. load = iwl_mvm_get_traffic_load(mvm);
  235. low_latency = iwl_mvm_low_latency(mvm);
  236. return _iwl_mvm_get_scan_type(mvm, p2p_device, load, low_latency);
  237. }
  238. static enum
  239. iwl_mvm_scan_type iwl_mvm_get_scan_type_band(struct iwl_mvm *mvm,
  240. bool p2p_device,
  241. enum nl80211_band band)
  242. {
  243. enum iwl_mvm_traffic_load load;
  244. bool low_latency;
  245. load = iwl_mvm_get_traffic_load_band(mvm, band);
  246. low_latency = iwl_mvm_low_latency_band(mvm, band);
  247. return _iwl_mvm_get_scan_type(mvm, p2p_device, load, low_latency);
  248. }
  249. static int
  250. iwl_mvm_get_measurement_dwell(struct iwl_mvm *mvm,
  251. struct cfg80211_scan_request *req,
  252. struct iwl_mvm_scan_params *params)
  253. {
  254. u32 duration = scan_timing[params->type].max_out_time;
  255. if (!req->duration)
  256. return 0;
  257. if (iwl_mvm_is_cdb_supported(mvm)) {
  258. u32 hb_time = scan_timing[params->hb_type].max_out_time;
  259. duration = min_t(u32, duration, hb_time);
  260. }
  261. if (req->duration_mandatory && req->duration > duration) {
  262. IWL_DEBUG_SCAN(mvm,
  263. "Measurement scan - too long dwell %hu (max out time %u)\n",
  264. req->duration,
  265. duration);
  266. return -EOPNOTSUPP;
  267. }
  268. return min_t(u32, (u32)req->duration, duration);
  269. }
  270. static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
  271. {
  272. /* require rrm scan whenever the fw supports it */
  273. return fw_has_capa(&mvm->fw->ucode_capa,
  274. IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT);
  275. }
  276. static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)
  277. {
  278. int max_probe_len;
  279. max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
  280. /* we create the 802.11 header and SSID element */
  281. max_probe_len -= 24 + 2;
  282. /* DS parameter set element is added on 2.4GHZ band if required */
  283. if (iwl_mvm_rrm_scan_needed(mvm))
  284. max_probe_len -= 3;
  285. return max_probe_len;
  286. }
  287. int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
  288. {
  289. int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);
  290. /* TODO: [BUG] This function should return the maximum allowed size of
  291. * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
  292. * in the same command. So the correct implementation of this function
  293. * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
  294. * command has only 512 bytes and it would leave us with about 240
  295. * bytes for scan IEs, which is clearly not enough. So meanwhile
  296. * we will report an incorrect value. This may result in a failure to
  297. * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
  298. * functions with -ENOBUFS, if a large enough probe will be provided.
  299. */
  300. return max_ie_len;
  301. }
  302. void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
  303. struct iwl_rx_cmd_buffer *rxb)
  304. {
  305. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  306. struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
  307. IWL_DEBUG_SCAN(mvm,
  308. "Scan offload iteration complete: status=0x%x scanned channels=%d\n",
  309. notif->status, notif->scanned_channels);
  310. if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {
  311. IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");
  312. ieee80211_sched_scan_results(mvm->hw);
  313. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
  314. }
  315. }
  316. void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
  317. struct iwl_rx_cmd_buffer *rxb)
  318. {
  319. IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
  320. ieee80211_sched_scan_results(mvm->hw);
  321. }
  322. static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status)
  323. {
  324. switch (status) {
  325. case IWL_SCAN_EBS_SUCCESS:
  326. return "successful";
  327. case IWL_SCAN_EBS_INACTIVE:
  328. return "inactive";
  329. case IWL_SCAN_EBS_FAILED:
  330. case IWL_SCAN_EBS_CHAN_NOT_FOUND:
  331. default:
  332. return "failed";
  333. }
  334. }
  335. void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
  336. struct iwl_rx_cmd_buffer *rxb)
  337. {
  338. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  339. struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;
  340. bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
  341. /* If this happens, the firmware has mistakenly sent an LMAC
  342. * notification during UMAC scans -- warn and ignore it.
  343. */
  344. if (WARN_ON_ONCE(fw_has_capa(&mvm->fw->ucode_capa,
  345. IWL_UCODE_TLV_CAPA_UMAC_SCAN)))
  346. return;
  347. /* scan status must be locked for proper checking */
  348. lockdep_assert_held(&mvm->mutex);
  349. /* We first check if we were stopping a scan, in which case we
  350. * just clear the stopping flag. Then we check if it was a
  351. * firmware initiated stop, in which case we need to inform
  352. * mac80211.
  353. * Note that we can have a stopping and a running scan
  354. * simultaneously, but we can't have two different types of
  355. * scans stopping or running at the same time (since LMAC
  356. * doesn't support it).
  357. */
  358. if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {
  359. WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);
  360. IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
  361. aborted ? "aborted" : "completed",
  362. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  363. IWL_DEBUG_SCAN(mvm,
  364. "Last line %d, Last iteration %d, Time after last iteration %d\n",
  365. scan_notif->last_schedule_line,
  366. scan_notif->last_schedule_iteration,
  367. __le32_to_cpu(scan_notif->time_after_last_iter));
  368. mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;
  369. } else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {
  370. IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",
  371. aborted ? "aborted" : "completed",
  372. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  373. mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;
  374. } else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
  375. WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);
  376. IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
  377. aborted ? "aborted" : "completed",
  378. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  379. IWL_DEBUG_SCAN(mvm,
  380. "Last line %d, Last iteration %d, Time after last iteration %d (FW)\n",
  381. scan_notif->last_schedule_line,
  382. scan_notif->last_schedule_iteration,
  383. __le32_to_cpu(scan_notif->time_after_last_iter));
  384. mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
  385. ieee80211_sched_scan_stopped(mvm->hw);
  386. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  387. } else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
  388. struct cfg80211_scan_info info = {
  389. .aborted = aborted,
  390. };
  391. IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",
  392. aborted ? "aborted" : "completed",
  393. iwl_mvm_ebs_status_str(scan_notif->ebs_status));
  394. mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
  395. ieee80211_scan_completed(mvm->hw, &info);
  396. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  397. cancel_delayed_work(&mvm->scan_timeout_dwork);
  398. iwl_mvm_resume_tcm(mvm);
  399. } else {
  400. IWL_ERR(mvm,
  401. "got scan complete notification but no scan is running\n");
  402. }
  403. mvm->last_ebs_successful =
  404. scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ||
  405. scan_notif->ebs_status == IWL_SCAN_EBS_INACTIVE;
  406. }
  407. static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
  408. {
  409. int i;
  410. for (i = 0; i < PROBE_OPTION_MAX; i++) {
  411. if (!ssid_list[i].len)
  412. break;
  413. if (ssid_list[i].len == ssid_len &&
  414. !memcmp(ssid_list->ssid, ssid, ssid_len))
  415. return i;
  416. }
  417. return -1;
  418. }
  419. /* We insert the SSIDs in an inverted order, because the FW will
  420. * invert it back.
  421. */
  422. static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,
  423. struct iwl_ssid_ie *ssids,
  424. u32 *ssid_bitmap)
  425. {
  426. int i, j;
  427. int index;
  428. /*
  429. * copy SSIDs from match list.
  430. * iwl_config_sched_scan_profiles() uses the order of these ssids to
  431. * config match list.
  432. */
  433. for (i = 0, j = params->n_match_sets - 1;
  434. j >= 0 && i < PROBE_OPTION_MAX;
  435. i++, j--) {
  436. /* skip empty SSID matchsets */
  437. if (!params->match_sets[j].ssid.ssid_len)
  438. continue;
  439. ssids[i].id = WLAN_EID_SSID;
  440. ssids[i].len = params->match_sets[j].ssid.ssid_len;
  441. memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,
  442. ssids[i].len);
  443. }
  444. /* add SSIDs from scan SSID list */
  445. *ssid_bitmap = 0;
  446. for (j = params->n_ssids - 1;
  447. j >= 0 && i < PROBE_OPTION_MAX;
  448. i++, j--) {
  449. index = iwl_ssid_exist(params->ssids[j].ssid,
  450. params->ssids[j].ssid_len,
  451. ssids);
  452. if (index < 0) {
  453. ssids[i].id = WLAN_EID_SSID;
  454. ssids[i].len = params->ssids[j].ssid_len;
  455. memcpy(ssids[i].ssid, params->ssids[j].ssid,
  456. ssids[i].len);
  457. *ssid_bitmap |= BIT(i);
  458. } else {
  459. *ssid_bitmap |= BIT(index);
  460. }
  461. }
  462. }
  463. static int
  464. iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
  465. struct cfg80211_sched_scan_request *req)
  466. {
  467. struct iwl_scan_offload_profile *profile;
  468. struct iwl_scan_offload_profile_cfg *profile_cfg;
  469. struct iwl_scan_offload_blacklist *blacklist;
  470. struct iwl_host_cmd cmd = {
  471. .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
  472. .len[1] = sizeof(*profile_cfg),
  473. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  474. .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
  475. };
  476. int blacklist_len;
  477. int i;
  478. int ret;
  479. if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
  480. return -EIO;
  481. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
  482. blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
  483. else
  484. blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
  485. blacklist = kcalloc(blacklist_len, sizeof(*blacklist), GFP_KERNEL);
  486. if (!blacklist)
  487. return -ENOMEM;
  488. profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
  489. if (!profile_cfg) {
  490. ret = -ENOMEM;
  491. goto free_blacklist;
  492. }
  493. cmd.data[0] = blacklist;
  494. cmd.len[0] = sizeof(*blacklist) * blacklist_len;
  495. cmd.data[1] = profile_cfg;
  496. /* No blacklist configuration */
  497. profile_cfg->num_profiles = req->n_match_sets;
  498. profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
  499. profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
  500. profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
  501. if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
  502. profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
  503. for (i = 0; i < req->n_match_sets; i++) {
  504. profile = &profile_cfg->profiles[i];
  505. profile->ssid_index = i;
  506. /* Support any cipher and auth algorithm */
  507. profile->unicast_cipher = 0xff;
  508. profile->auth_alg = 0xff;
  509. profile->network_type = IWL_NETWORK_TYPE_ANY;
  510. profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
  511. profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
  512. }
  513. IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
  514. ret = iwl_mvm_send_cmd(mvm, &cmd);
  515. kfree(profile_cfg);
  516. free_blacklist:
  517. kfree(blacklist);
  518. return ret;
  519. }
  520. static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
  521. struct cfg80211_sched_scan_request *req)
  522. {
  523. if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
  524. IWL_DEBUG_SCAN(mvm,
  525. "Sending scheduled scan with filtering, n_match_sets %d\n",
  526. req->n_match_sets);
  527. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  528. return false;
  529. }
  530. IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
  531. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
  532. return true;
  533. }
  534. static int iwl_mvm_lmac_scan_abort(struct iwl_mvm *mvm)
  535. {
  536. int ret;
  537. struct iwl_host_cmd cmd = {
  538. .id = SCAN_OFFLOAD_ABORT_CMD,
  539. };
  540. u32 status = CAN_ABORT_STATUS;
  541. ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
  542. if (ret)
  543. return ret;
  544. if (status != CAN_ABORT_STATUS) {
  545. /*
  546. * The scan abort will return 1 for success or
  547. * 2 for "failure". A failure condition can be
  548. * due to simply not being in an active scan which
  549. * can occur if we send the scan abort before the
  550. * microcode has notified us that a scan is completed.
  551. */
  552. IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
  553. ret = -ENOENT;
  554. }
  555. return ret;
  556. }
  557. static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,
  558. struct iwl_scan_req_tx_cmd *tx_cmd,
  559. bool no_cck)
  560. {
  561. tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
  562. TX_CMD_FLG_BT_DIS);
  563. tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
  564. NL80211_BAND_2GHZ,
  565. no_cck);
  566. tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
  567. tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
  568. TX_CMD_FLG_BT_DIS);
  569. tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
  570. NL80211_BAND_5GHZ,
  571. no_cck);
  572. tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
  573. }
  574. static void
  575. iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
  576. struct ieee80211_channel **channels,
  577. int n_channels, u32 ssid_bitmap,
  578. struct iwl_scan_req_lmac *cmd)
  579. {
  580. struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
  581. int i;
  582. for (i = 0; i < n_channels; i++) {
  583. channel_cfg[i].channel_num =
  584. cpu_to_le16(channels[i]->hw_value);
  585. channel_cfg[i].iter_count = cpu_to_le16(1);
  586. channel_cfg[i].iter_interval = 0;
  587. channel_cfg[i].flags =
  588. cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
  589. ssid_bitmap);
  590. }
  591. }
  592. static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
  593. size_t len, u8 *const pos)
  594. {
  595. static const u8 before_ds_params[] = {
  596. WLAN_EID_SSID,
  597. WLAN_EID_SUPP_RATES,
  598. WLAN_EID_REQUEST,
  599. WLAN_EID_EXT_SUPP_RATES,
  600. };
  601. size_t offs;
  602. u8 *newpos = pos;
  603. if (!iwl_mvm_rrm_scan_needed(mvm)) {
  604. memcpy(newpos, ies, len);
  605. return newpos + len;
  606. }
  607. offs = ieee80211_ie_split(ies, len,
  608. before_ds_params,
  609. ARRAY_SIZE(before_ds_params),
  610. 0);
  611. memcpy(newpos, ies, offs);
  612. newpos += offs;
  613. /* Add a placeholder for DS Parameter Set element */
  614. *newpos++ = WLAN_EID_DS_PARAMS;
  615. *newpos++ = 1;
  616. *newpos++ = 0;
  617. memcpy(newpos, ies + offs, len - offs);
  618. newpos += len - offs;
  619. return newpos;
  620. }
  621. #define WFA_TPC_IE_LEN 9
  622. static void iwl_mvm_add_tpc_report_ie(u8 *pos)
  623. {
  624. pos[0] = WLAN_EID_VENDOR_SPECIFIC;
  625. pos[1] = WFA_TPC_IE_LEN - 2;
  626. pos[2] = (WLAN_OUI_MICROSOFT >> 16) & 0xff;
  627. pos[3] = (WLAN_OUI_MICROSOFT >> 8) & 0xff;
  628. pos[4] = WLAN_OUI_MICROSOFT & 0xff;
  629. pos[5] = WLAN_OUI_TYPE_MICROSOFT_TPC;
  630. pos[6] = 0;
  631. /* pos[7] - tx power will be inserted by the FW */
  632. pos[7] = 0;
  633. pos[8] = 0;
  634. }
  635. static void
  636. iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  637. struct ieee80211_scan_ies *ies,
  638. struct iwl_mvm_scan_params *params)
  639. {
  640. struct ieee80211_mgmt *frame = (void *)params->preq.buf;
  641. u8 *pos, *newpos;
  642. const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
  643. params->mac_addr : NULL;
  644. /*
  645. * Unfortunately, right now the offload scan doesn't support randomising
  646. * within the firmware, so until the firmware API is ready we implement
  647. * it in the driver. This means that the scan iterations won't really be
  648. * random, only when it's restarted, but at least that helps a bit.
  649. */
  650. if (mac_addr)
  651. get_random_mask_addr(frame->sa, mac_addr,
  652. params->mac_addr_mask);
  653. else
  654. memcpy(frame->sa, vif->addr, ETH_ALEN);
  655. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  656. eth_broadcast_addr(frame->da);
  657. eth_broadcast_addr(frame->bssid);
  658. frame->seq_ctrl = 0;
  659. pos = frame->u.probe_req.variable;
  660. *pos++ = WLAN_EID_SSID;
  661. *pos++ = 0;
  662. params->preq.mac_header.offset = 0;
  663. params->preq.mac_header.len = cpu_to_le16(24 + 2);
  664. /* Insert ds parameter set element on 2.4 GHz band */
  665. newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
  666. ies->ies[NL80211_BAND_2GHZ],
  667. ies->len[NL80211_BAND_2GHZ],
  668. pos);
  669. params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);
  670. params->preq.band_data[0].len = cpu_to_le16(newpos - pos);
  671. pos = newpos;
  672. memcpy(pos, ies->ies[NL80211_BAND_5GHZ],
  673. ies->len[NL80211_BAND_5GHZ]);
  674. params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);
  675. params->preq.band_data[1].len =
  676. cpu_to_le16(ies->len[NL80211_BAND_5GHZ]);
  677. pos += ies->len[NL80211_BAND_5GHZ];
  678. memcpy(pos, ies->common_ies, ies->common_ie_len);
  679. params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);
  680. if (iwl_mvm_rrm_scan_needed(mvm) &&
  681. !fw_has_capa(&mvm->fw->ucode_capa,
  682. IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) {
  683. iwl_mvm_add_tpc_report_ie(pos + ies->common_ie_len);
  684. params->preq.common_data.len = cpu_to_le16(ies->common_ie_len +
  685. WFA_TPC_IE_LEN);
  686. } else {
  687. params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);
  688. }
  689. }
  690. static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,
  691. struct iwl_scan_req_lmac *cmd,
  692. struct iwl_mvm_scan_params *params)
  693. {
  694. cmd->active_dwell = IWL_SCAN_DWELL_ACTIVE;
  695. cmd->passive_dwell = IWL_SCAN_DWELL_PASSIVE;
  696. cmd->fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
  697. cmd->extended_dwell = IWL_SCAN_DWELL_EXTENDED;
  698. cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);
  699. cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);
  700. cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  701. }
  702. static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,
  703. struct ieee80211_scan_ies *ies,
  704. int n_channels)
  705. {
  706. return ((n_ssids <= PROBE_OPTION_MAX) &&
  707. (n_channels <= mvm->fw->ucode_capa.n_scan_channels) &
  708. (ies->common_ie_len +
  709. ies->len[NL80211_BAND_2GHZ] +
  710. ies->len[NL80211_BAND_5GHZ] <=
  711. iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));
  712. }
  713. static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm,
  714. struct ieee80211_vif *vif)
  715. {
  716. const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;
  717. /* We can only use EBS if:
  718. * 1. the feature is supported;
  719. * 2. the last EBS was successful;
  720. * 3. if only single scan, the single scan EBS API is supported;
  721. * 4. it's not a p2p find operation.
  722. */
  723. return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
  724. mvm->last_ebs_successful && IWL_MVM_ENABLE_EBS &&
  725. vif->type != NL80211_IFTYPE_P2P_DEVICE);
  726. }
  727. static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params *params)
  728. {
  729. return params->n_scan_plans == 1 &&
  730. params->scan_plans[0].iterations == 1;
  731. }
  732. static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
  733. struct iwl_mvm_scan_params *params,
  734. struct ieee80211_vif *vif)
  735. {
  736. int flags = 0;
  737. if (params->n_ssids == 0)
  738. flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
  739. if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
  740. flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
  741. if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
  742. flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
  743. if (iwl_mvm_rrm_scan_needed(mvm) &&
  744. fw_has_capa(&mvm->fw->ucode_capa,
  745. IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
  746. flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
  747. if (params->pass_all)
  748. flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
  749. else
  750. flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
  751. #ifdef CONFIG_IWLWIFI_DEBUGFS
  752. if (mvm->scan_iter_notif_enabled)
  753. flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
  754. #endif
  755. if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
  756. flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
  757. if (iwl_mvm_is_regular_scan(params) &&
  758. vif->type != NL80211_IFTYPE_P2P_DEVICE &&
  759. params->type != IWL_SCAN_TYPE_FRAGMENTED)
  760. flags |= IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL;
  761. return flags;
  762. }
  763. static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  764. struct iwl_mvm_scan_params *params)
  765. {
  766. struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
  767. struct iwl_scan_probe_req *preq =
  768. (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
  769. mvm->fw->ucode_capa.n_scan_channels);
  770. u32 ssid_bitmap = 0;
  771. int i;
  772. lockdep_assert_held(&mvm->mutex);
  773. memset(cmd, 0, ksize(cmd));
  774. if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
  775. return -EINVAL;
  776. iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
  777. cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
  778. cmd->iter_num = cpu_to_le32(1);
  779. cmd->n_channels = (u8)params->n_channels;
  780. cmd->delay = cpu_to_le32(params->delay);
  781. cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params,
  782. vif));
  783. cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
  784. cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
  785. MAC_FILTER_IN_BEACON);
  786. iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
  787. iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
  788. /* this API uses bits 1-20 instead of 0-19 */
  789. ssid_bitmap <<= 1;
  790. for (i = 0; i < params->n_scan_plans; i++) {
  791. struct cfg80211_sched_scan_plan *scan_plan =
  792. &params->scan_plans[i];
  793. cmd->schedule[i].delay =
  794. cpu_to_le16(scan_plan->interval);
  795. cmd->schedule[i].iterations = scan_plan->iterations;
  796. cmd->schedule[i].full_scan_mul = 1;
  797. }
  798. /*
  799. * If the number of iterations of the last scan plan is set to
  800. * zero, it should run infinitely. However, this is not always the case.
  801. * For example, when regular scan is requested the driver sets one scan
  802. * plan with one iteration.
  803. */
  804. if (!cmd->schedule[i - 1].iterations)
  805. cmd->schedule[i - 1].iterations = 0xff;
  806. if (iwl_mvm_scan_use_ebs(mvm, vif)) {
  807. cmd->channel_opt[0].flags =
  808. cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
  809. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  810. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
  811. cmd->channel_opt[0].non_ebs_ratio =
  812. cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
  813. cmd->channel_opt[1].flags =
  814. cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
  815. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  816. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
  817. cmd->channel_opt[1].non_ebs_ratio =
  818. cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
  819. }
  820. iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
  821. params->n_channels, ssid_bitmap, cmd);
  822. *preq = params->preq;
  823. return 0;
  824. }
  825. static int rate_to_scan_rate_flag(unsigned int rate)
  826. {
  827. static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
  828. [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
  829. [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
  830. [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
  831. [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
  832. [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
  833. [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
  834. [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
  835. [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
  836. [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
  837. [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
  838. [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
  839. [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
  840. };
  841. return rate_to_scan_rate[rate];
  842. }
  843. static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
  844. {
  845. struct ieee80211_supported_band *band;
  846. unsigned int rates = 0;
  847. int i;
  848. band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
  849. for (i = 0; i < band->n_bitrates; i++)
  850. rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
  851. band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
  852. for (i = 0; i < band->n_bitrates; i++)
  853. rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
  854. /* Set both basic rates and supported rates */
  855. rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
  856. return cpu_to_le32(rates);
  857. }
  858. static void iwl_mvm_fill_scan_dwell(struct iwl_mvm *mvm,
  859. struct iwl_scan_dwell *dwell)
  860. {
  861. dwell->active = IWL_SCAN_DWELL_ACTIVE;
  862. dwell->passive = IWL_SCAN_DWELL_PASSIVE;
  863. dwell->fragmented = IWL_SCAN_DWELL_FRAGMENTED;
  864. dwell->extended = IWL_SCAN_DWELL_EXTENDED;
  865. }
  866. static void iwl_mvm_fill_channels(struct iwl_mvm *mvm, u8 *channels)
  867. {
  868. struct ieee80211_supported_band *band;
  869. int i, j = 0;
  870. band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
  871. for (i = 0; i < band->n_channels; i++, j++)
  872. channels[j] = band->channels[i].hw_value;
  873. band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
  874. for (i = 0; i < band->n_channels; i++, j++)
  875. channels[j] = band->channels[i].hw_value;
  876. }
  877. static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm *mvm, void *config,
  878. u32 flags, u8 channel_flags)
  879. {
  880. enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, false);
  881. struct iwl_scan_config_v1 *cfg = config;
  882. cfg->flags = cpu_to_le32(flags);
  883. cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
  884. cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
  885. cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
  886. cfg->out_of_channel_time = cpu_to_le32(scan_timing[type].max_out_time);
  887. cfg->suspend_time = cpu_to_le32(scan_timing[type].suspend_time);
  888. iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
  889. memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
  890. cfg->bcast_sta_id = mvm->aux_sta.sta_id;
  891. cfg->channel_flags = channel_flags;
  892. iwl_mvm_fill_channels(mvm, cfg->channel_array);
  893. }
  894. static void iwl_mvm_fill_scan_config(struct iwl_mvm *mvm, void *config,
  895. u32 flags, u8 channel_flags)
  896. {
  897. struct iwl_scan_config *cfg = config;
  898. cfg->flags = cpu_to_le32(flags);
  899. cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
  900. cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
  901. cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
  902. if (iwl_mvm_is_cdb_supported(mvm)) {
  903. enum iwl_mvm_scan_type lb_type, hb_type;
  904. lb_type = iwl_mvm_get_scan_type_band(mvm, false,
  905. NL80211_BAND_2GHZ);
  906. hb_type = iwl_mvm_get_scan_type_band(mvm, false,
  907. NL80211_BAND_5GHZ);
  908. cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
  909. cpu_to_le32(scan_timing[lb_type].max_out_time);
  910. cfg->suspend_time[SCAN_LB_LMAC_IDX] =
  911. cpu_to_le32(scan_timing[lb_type].suspend_time);
  912. cfg->out_of_channel_time[SCAN_HB_LMAC_IDX] =
  913. cpu_to_le32(scan_timing[hb_type].max_out_time);
  914. cfg->suspend_time[SCAN_HB_LMAC_IDX] =
  915. cpu_to_le32(scan_timing[hb_type].suspend_time);
  916. } else {
  917. enum iwl_mvm_scan_type type =
  918. iwl_mvm_get_scan_type(mvm, false);
  919. cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
  920. cpu_to_le32(scan_timing[type].max_out_time);
  921. cfg->suspend_time[SCAN_LB_LMAC_IDX] =
  922. cpu_to_le32(scan_timing[type].suspend_time);
  923. }
  924. iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
  925. memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
  926. cfg->bcast_sta_id = mvm->aux_sta.sta_id;
  927. cfg->channel_flags = channel_flags;
  928. iwl_mvm_fill_channels(mvm, cfg->channel_array);
  929. }
  930. int iwl_mvm_config_scan(struct iwl_mvm *mvm)
  931. {
  932. void *cfg;
  933. int ret, cmd_size;
  934. struct iwl_host_cmd cmd = {
  935. .id = iwl_cmd_id(SCAN_CFG_CMD, IWL_ALWAYS_LONG_GROUP, 0),
  936. };
  937. enum iwl_mvm_scan_type type;
  938. enum iwl_mvm_scan_type hb_type = IWL_SCAN_TYPE_NOT_SET;
  939. int num_channels =
  940. mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels +
  941. mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels;
  942. u32 flags;
  943. u8 channel_flags;
  944. if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
  945. return -ENOBUFS;
  946. if (iwl_mvm_is_cdb_supported(mvm)) {
  947. type = iwl_mvm_get_scan_type_band(mvm, false,
  948. NL80211_BAND_2GHZ);
  949. hb_type = iwl_mvm_get_scan_type_band(mvm, false,
  950. NL80211_BAND_5GHZ);
  951. if (type == mvm->scan_type && hb_type == mvm->hb_scan_type)
  952. return 0;
  953. } else {
  954. type = iwl_mvm_get_scan_type(mvm, false);
  955. if (type == mvm->scan_type)
  956. return 0;
  957. }
  958. if (iwl_mvm_cdb_scan_api(mvm))
  959. cmd_size = sizeof(struct iwl_scan_config);
  960. else
  961. cmd_size = sizeof(struct iwl_scan_config_v1);
  962. cmd_size += mvm->fw->ucode_capa.n_scan_channels;
  963. cfg = kzalloc(cmd_size, GFP_KERNEL);
  964. if (!cfg)
  965. return -ENOMEM;
  966. flags = SCAN_CONFIG_FLAG_ACTIVATE |
  967. SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
  968. SCAN_CONFIG_FLAG_SET_TX_CHAINS |
  969. SCAN_CONFIG_FLAG_SET_RX_CHAINS |
  970. SCAN_CONFIG_FLAG_SET_AUX_STA_ID |
  971. SCAN_CONFIG_FLAG_SET_ALL_TIMES |
  972. SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
  973. SCAN_CONFIG_FLAG_SET_MAC_ADDR |
  974. SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS |
  975. SCAN_CONFIG_N_CHANNELS(num_channels) |
  976. (type == IWL_SCAN_TYPE_FRAGMENTED ?
  977. SCAN_CONFIG_FLAG_SET_FRAGMENTED :
  978. SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED);
  979. channel_flags = IWL_CHANNEL_FLAG_EBS |
  980. IWL_CHANNEL_FLAG_ACCURATE_EBS |
  981. IWL_CHANNEL_FLAG_EBS_ADD |
  982. IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
  983. /*
  984. * Check for fragmented scan on LMAC2 - high band.
  985. * LMAC1 - low band is checked above.
  986. */
  987. if (iwl_mvm_cdb_scan_api(mvm)) {
  988. if (iwl_mvm_is_cdb_supported(mvm))
  989. flags |= (hb_type == IWL_SCAN_TYPE_FRAGMENTED) ?
  990. SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED :
  991. SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED;
  992. iwl_mvm_fill_scan_config(mvm, cfg, flags, channel_flags);
  993. } else {
  994. iwl_mvm_fill_scan_config_v1(mvm, cfg, flags, channel_flags);
  995. }
  996. cmd.data[0] = cfg;
  997. cmd.len[0] = cmd_size;
  998. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  999. IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
  1000. ret = iwl_mvm_send_cmd(mvm, &cmd);
  1001. if (!ret) {
  1002. mvm->scan_type = type;
  1003. mvm->hb_scan_type = hb_type;
  1004. }
  1005. kfree(cfg);
  1006. return ret;
  1007. }
  1008. static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)
  1009. {
  1010. int i;
  1011. for (i = 0; i < mvm->max_scans; i++)
  1012. if (mvm->scan_uid_status[i] == status)
  1013. return i;
  1014. return -ENOENT;
  1015. }
  1016. static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
  1017. struct iwl_scan_req_umac *cmd,
  1018. struct iwl_mvm_scan_params *params)
  1019. {
  1020. struct iwl_mvm_scan_timing_params *timing, *hb_timing;
  1021. u8 active_dwell, passive_dwell;
  1022. timing = &scan_timing[params->type];
  1023. active_dwell = params->measurement_dwell ?
  1024. params->measurement_dwell : IWL_SCAN_DWELL_ACTIVE;
  1025. passive_dwell = params->measurement_dwell ?
  1026. params->measurement_dwell : IWL_SCAN_DWELL_PASSIVE;
  1027. if (iwl_mvm_is_adaptive_dwell_supported(mvm)) {
  1028. cmd->v7.adwell_default_n_aps_social =
  1029. IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL;
  1030. cmd->v7.adwell_default_n_aps =
  1031. IWL_SCAN_ADWELL_DEFAULT_N_APS;
  1032. /* if custom max budget was configured with debugfs */
  1033. if (IWL_MVM_ADWELL_MAX_BUDGET)
  1034. cmd->v7.adwell_max_budget =
  1035. cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET);
  1036. else if (params->ssids && params->ssids[0].ssid_len)
  1037. cmd->v7.adwell_max_budget =
  1038. cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN);
  1039. else
  1040. cmd->v7.adwell_max_budget =
  1041. cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN);
  1042. cmd->v7.scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1043. cmd->v7.max_out_time[SCAN_LB_LMAC_IDX] =
  1044. cpu_to_le32(timing->max_out_time);
  1045. cmd->v7.suspend_time[SCAN_LB_LMAC_IDX] =
  1046. cpu_to_le32(timing->suspend_time);
  1047. if (iwl_mvm_is_cdb_supported(mvm)) {
  1048. hb_timing = &scan_timing[params->hb_type];
  1049. cmd->v7.max_out_time[SCAN_HB_LMAC_IDX] =
  1050. cpu_to_le32(hb_timing->max_out_time);
  1051. cmd->v7.suspend_time[SCAN_HB_LMAC_IDX] =
  1052. cpu_to_le32(hb_timing->suspend_time);
  1053. }
  1054. if (!iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
  1055. cmd->v7.active_dwell = active_dwell;
  1056. cmd->v7.passive_dwell = passive_dwell;
  1057. cmd->v7.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
  1058. } else {
  1059. cmd->v8.active_dwell[SCAN_LB_LMAC_IDX] = active_dwell;
  1060. cmd->v8.passive_dwell[SCAN_LB_LMAC_IDX] = passive_dwell;
  1061. if (iwl_mvm_is_cdb_supported(mvm)) {
  1062. cmd->v8.active_dwell[SCAN_HB_LMAC_IDX] =
  1063. active_dwell;
  1064. cmd->v8.passive_dwell[SCAN_HB_LMAC_IDX] =
  1065. passive_dwell;
  1066. }
  1067. }
  1068. } else {
  1069. cmd->v1.extended_dwell = params->measurement_dwell ?
  1070. params->measurement_dwell : IWL_SCAN_DWELL_EXTENDED;
  1071. cmd->v1.active_dwell = active_dwell;
  1072. cmd->v1.passive_dwell = passive_dwell;
  1073. cmd->v1.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
  1074. if (iwl_mvm_is_cdb_supported(mvm)) {
  1075. hb_timing = &scan_timing[params->hb_type];
  1076. cmd->v6.max_out_time[SCAN_HB_LMAC_IDX] =
  1077. cpu_to_le32(hb_timing->max_out_time);
  1078. cmd->v6.suspend_time[SCAN_HB_LMAC_IDX] =
  1079. cpu_to_le32(hb_timing->suspend_time);
  1080. }
  1081. if (iwl_mvm_cdb_scan_api(mvm)) {
  1082. cmd->v6.scan_priority =
  1083. cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1084. cmd->v6.max_out_time[SCAN_LB_LMAC_IDX] =
  1085. cpu_to_le32(timing->max_out_time);
  1086. cmd->v6.suspend_time[SCAN_LB_LMAC_IDX] =
  1087. cpu_to_le32(timing->suspend_time);
  1088. } else {
  1089. cmd->v1.scan_priority =
  1090. cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1091. cmd->v1.max_out_time =
  1092. cpu_to_le32(timing->max_out_time);
  1093. cmd->v1.suspend_time =
  1094. cpu_to_le32(timing->suspend_time);
  1095. }
  1096. }
  1097. if (iwl_mvm_is_regular_scan(params))
  1098. cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1099. else
  1100. cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_2);
  1101. }
  1102. static void
  1103. iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
  1104. struct ieee80211_channel **channels,
  1105. int n_channels, u32 ssid_bitmap,
  1106. struct iwl_scan_channel_cfg_umac *channel_cfg)
  1107. {
  1108. int i;
  1109. for (i = 0; i < n_channels; i++) {
  1110. channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
  1111. channel_cfg[i].channel_num = channels[i]->hw_value;
  1112. channel_cfg[i].iter_count = 1;
  1113. channel_cfg[i].iter_interval = 0;
  1114. }
  1115. }
  1116. static u16 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
  1117. struct iwl_mvm_scan_params *params,
  1118. struct ieee80211_vif *vif)
  1119. {
  1120. u16 flags = 0;
  1121. if (params->n_ssids == 0)
  1122. flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
  1123. if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
  1124. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
  1125. if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
  1126. flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
  1127. if (iwl_mvm_is_cdb_supported(mvm) &&
  1128. params->hb_type == IWL_SCAN_TYPE_FRAGMENTED)
  1129. flags |= IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED;
  1130. if (iwl_mvm_rrm_scan_needed(mvm) &&
  1131. fw_has_capa(&mvm->fw->ucode_capa,
  1132. IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
  1133. flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
  1134. if (params->pass_all)
  1135. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
  1136. else
  1137. flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
  1138. if (!iwl_mvm_is_regular_scan(params))
  1139. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
  1140. if (params->measurement_dwell)
  1141. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
  1142. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1143. if (mvm->scan_iter_notif_enabled)
  1144. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
  1145. #endif
  1146. if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
  1147. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
  1148. if (iwl_mvm_is_adaptive_dwell_supported(mvm) && IWL_MVM_ADWELL_ENABLE &&
  1149. vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1150. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL;
  1151. /*
  1152. * Extended dwell is relevant only for low band to start with, as it is
  1153. * being used for social channles only (1, 6, 11), so we can check
  1154. * only scan type on low band also for CDB.
  1155. */
  1156. if (iwl_mvm_is_regular_scan(params) &&
  1157. vif->type != NL80211_IFTYPE_P2P_DEVICE &&
  1158. params->type != IWL_SCAN_TYPE_FRAGMENTED &&
  1159. !iwl_mvm_is_adaptive_dwell_supported(mvm) &&
  1160. !iwl_mvm_is_oce_supported(mvm))
  1161. flags |= IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL;
  1162. if (iwl_mvm_is_oce_supported(mvm)) {
  1163. if ((params->flags &
  1164. NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE))
  1165. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE;
  1166. /* Since IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL and
  1167. * NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION shares
  1168. * the same bit, we need to make sure that we use this bit here
  1169. * only when IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL cannot be
  1170. * used. */
  1171. if ((params->flags &
  1172. NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
  1173. !WARN_ON_ONCE(!iwl_mvm_is_adaptive_dwell_supported(mvm)))
  1174. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP;
  1175. if ((params->flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME))
  1176. flags |= IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME;
  1177. }
  1178. return flags;
  1179. }
  1180. static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1181. struct iwl_mvm_scan_params *params,
  1182. int type)
  1183. {
  1184. struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
  1185. struct iwl_scan_umac_chan_param *chan_param;
  1186. void *cmd_data = iwl_mvm_get_scan_req_umac_data(mvm);
  1187. struct iwl_scan_req_umac_tail *sec_part = cmd_data +
  1188. sizeof(struct iwl_scan_channel_cfg_umac) *
  1189. mvm->fw->ucode_capa.n_scan_channels;
  1190. int uid, i;
  1191. u32 ssid_bitmap = 0;
  1192. u8 channel_flags = 0;
  1193. u16 gen_flags;
  1194. struct iwl_mvm_vif *scan_vif = iwl_mvm_vif_from_mac80211(vif);
  1195. chan_param = iwl_mvm_get_scan_req_umac_channel(mvm);
  1196. lockdep_assert_held(&mvm->mutex);
  1197. if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
  1198. return -EINVAL;
  1199. uid = iwl_mvm_scan_uid_by_status(mvm, 0);
  1200. if (uid < 0)
  1201. return uid;
  1202. memset(cmd, 0, ksize(cmd));
  1203. iwl_mvm_scan_umac_dwell(mvm, cmd, params);
  1204. mvm->scan_uid_status[uid] = type;
  1205. cmd->uid = cpu_to_le32(uid);
  1206. gen_flags = iwl_mvm_scan_umac_flags(mvm, params, vif);
  1207. cmd->general_flags = cpu_to_le16(gen_flags);
  1208. if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
  1209. if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED)
  1210. cmd->v8.num_of_fragments[SCAN_LB_LMAC_IDX] =
  1211. IWL_SCAN_NUM_OF_FRAGS;
  1212. if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED)
  1213. cmd->v8.num_of_fragments[SCAN_HB_LMAC_IDX] =
  1214. IWL_SCAN_NUM_OF_FRAGS;
  1215. }
  1216. cmd->scan_start_mac_id = scan_vif->id;
  1217. if (type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT)
  1218. cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);
  1219. if (iwl_mvm_scan_use_ebs(mvm, vif))
  1220. channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
  1221. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  1222. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
  1223. chan_param->flags = channel_flags;
  1224. chan_param->count = params->n_channels;
  1225. iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
  1226. iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
  1227. params->n_channels, ssid_bitmap,
  1228. cmd_data);
  1229. for (i = 0; i < params->n_scan_plans; i++) {
  1230. struct cfg80211_sched_scan_plan *scan_plan =
  1231. &params->scan_plans[i];
  1232. sec_part->schedule[i].iter_count = scan_plan->iterations;
  1233. sec_part->schedule[i].interval =
  1234. cpu_to_le16(scan_plan->interval);
  1235. }
  1236. /*
  1237. * If the number of iterations of the last scan plan is set to
  1238. * zero, it should run infinitely. However, this is not always the case.
  1239. * For example, when regular scan is requested the driver sets one scan
  1240. * plan with one iteration.
  1241. */
  1242. if (!sec_part->schedule[i - 1].iter_count)
  1243. sec_part->schedule[i - 1].iter_count = 0xff;
  1244. sec_part->delay = cpu_to_le16(params->delay);
  1245. sec_part->preq = params->preq;
  1246. return 0;
  1247. }
  1248. static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
  1249. {
  1250. return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
  1251. }
  1252. static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
  1253. {
  1254. bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
  1255. IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
  1256. /* This looks a bit arbitrary, but the idea is that if we run
  1257. * out of possible simultaneous scans and the userspace is
  1258. * trying to run a scan type that is already running, we
  1259. * return -EBUSY. But if the userspace wants to start a
  1260. * different type of scan, we stop the opposite type to make
  1261. * space for the new request. The reason is backwards
  1262. * compatibility with old wpa_supplicant that wouldn't stop a
  1263. * scheduled scan before starting a normal scan.
  1264. */
  1265. if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
  1266. return 0;
  1267. /* Use a switch, even though this is a bitmask, so that more
  1268. * than one bits set will fall in default and we will warn.
  1269. */
  1270. switch (type) {
  1271. case IWL_MVM_SCAN_REGULAR:
  1272. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
  1273. return -EBUSY;
  1274. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
  1275. case IWL_MVM_SCAN_SCHED:
  1276. if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
  1277. return -EBUSY;
  1278. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
  1279. case IWL_MVM_SCAN_NETDETECT:
  1280. /* For non-unified images, there's no need to stop
  1281. * anything for net-detect since the firmware is
  1282. * restarted anyway. This way, any sched scans that
  1283. * were running will be restarted when we resume.
  1284. */
  1285. if (!unified_image)
  1286. return 0;
  1287. /* If this is a unified image and we ran out of scans,
  1288. * we need to stop something. Prefer stopping regular
  1289. * scans, because the results are useless at this
  1290. * point, and we should be able to keep running
  1291. * another scheduled scan while suspended.
  1292. */
  1293. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
  1294. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR,
  1295. true);
  1296. if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
  1297. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED,
  1298. true);
  1299. /* fall through, something is wrong if no scan was
  1300. * running but we ran out of scans.
  1301. */
  1302. default:
  1303. WARN_ON(1);
  1304. break;
  1305. }
  1306. return -EIO;
  1307. }
  1308. #define SCAN_TIMEOUT 20000
  1309. void iwl_mvm_scan_timeout_wk(struct work_struct *work)
  1310. {
  1311. struct delayed_work *delayed_work = to_delayed_work(work);
  1312. struct iwl_mvm *mvm = container_of(delayed_work, struct iwl_mvm,
  1313. scan_timeout_dwork);
  1314. IWL_ERR(mvm, "regular scan timed out\n");
  1315. iwl_force_nmi(mvm->trans);
  1316. }
  1317. static void iwl_mvm_fill_scan_type(struct iwl_mvm *mvm,
  1318. struct iwl_mvm_scan_params *params,
  1319. bool p2p)
  1320. {
  1321. if (iwl_mvm_is_cdb_supported(mvm)) {
  1322. params->type =
  1323. iwl_mvm_get_scan_type_band(mvm, p2p,
  1324. NL80211_BAND_2GHZ);
  1325. params->hb_type =
  1326. iwl_mvm_get_scan_type_band(mvm, p2p,
  1327. NL80211_BAND_5GHZ);
  1328. } else {
  1329. params->type = iwl_mvm_get_scan_type(mvm, p2p);
  1330. }
  1331. }
  1332. int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1333. struct cfg80211_scan_request *req,
  1334. struct ieee80211_scan_ies *ies)
  1335. {
  1336. struct iwl_host_cmd hcmd = {
  1337. .len = { iwl_mvm_scan_size(mvm), },
  1338. .data = { mvm->scan_cmd, },
  1339. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1340. };
  1341. struct iwl_mvm_scan_params params = {};
  1342. int ret;
  1343. struct cfg80211_sched_scan_plan scan_plan = { .iterations = 1 };
  1344. lockdep_assert_held(&mvm->mutex);
  1345. if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
  1346. IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
  1347. return -EBUSY;
  1348. }
  1349. ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
  1350. if (ret)
  1351. return ret;
  1352. /* we should have failed registration if scan_cmd was NULL */
  1353. if (WARN_ON(!mvm->scan_cmd))
  1354. return -ENOMEM;
  1355. if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
  1356. return -ENOBUFS;
  1357. params.n_ssids = req->n_ssids;
  1358. params.flags = req->flags;
  1359. params.n_channels = req->n_channels;
  1360. params.delay = 0;
  1361. params.ssids = req->ssids;
  1362. params.channels = req->channels;
  1363. params.mac_addr = req->mac_addr;
  1364. params.mac_addr_mask = req->mac_addr_mask;
  1365. params.no_cck = req->no_cck;
  1366. params.pass_all = true;
  1367. params.n_match_sets = 0;
  1368. params.match_sets = NULL;
  1369. params.scan_plans = &scan_plan;
  1370. params.n_scan_plans = 1;
  1371. iwl_mvm_fill_scan_type(mvm, &params,
  1372. vif->type == NL80211_IFTYPE_P2P_DEVICE);
  1373. ret = iwl_mvm_get_measurement_dwell(mvm, req, &params);
  1374. if (ret < 0)
  1375. return ret;
  1376. params.measurement_dwell = ret;
  1377. iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
  1378. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1379. hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
  1380. ret = iwl_mvm_scan_umac(mvm, vif, &params,
  1381. IWL_MVM_SCAN_REGULAR);
  1382. } else {
  1383. hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
  1384. ret = iwl_mvm_scan_lmac(mvm, vif, &params);
  1385. }
  1386. if (ret)
  1387. return ret;
  1388. iwl_mvm_pause_tcm(mvm, false);
  1389. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1390. if (ret) {
  1391. /* If the scan failed, it usually means that the FW was unable
  1392. * to allocate the time events. Warn on it, but maybe we
  1393. * should try to send the command again with different params.
  1394. */
  1395. IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
  1396. iwl_mvm_resume_tcm(mvm);
  1397. return ret;
  1398. }
  1399. IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
  1400. mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
  1401. mvm->scan_vif = iwl_mvm_vif_from_mac80211(vif);
  1402. iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
  1403. schedule_delayed_work(&mvm->scan_timeout_dwork,
  1404. msecs_to_jiffies(SCAN_TIMEOUT));
  1405. return 0;
  1406. }
  1407. int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
  1408. struct ieee80211_vif *vif,
  1409. struct cfg80211_sched_scan_request *req,
  1410. struct ieee80211_scan_ies *ies,
  1411. int type)
  1412. {
  1413. struct iwl_host_cmd hcmd = {
  1414. .len = { iwl_mvm_scan_size(mvm), },
  1415. .data = { mvm->scan_cmd, },
  1416. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1417. };
  1418. struct iwl_mvm_scan_params params = {};
  1419. int ret;
  1420. lockdep_assert_held(&mvm->mutex);
  1421. if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
  1422. IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
  1423. return -EBUSY;
  1424. }
  1425. ret = iwl_mvm_check_running_scans(mvm, type);
  1426. if (ret)
  1427. return ret;
  1428. /* we should have failed registration if scan_cmd was NULL */
  1429. if (WARN_ON(!mvm->scan_cmd))
  1430. return -ENOMEM;
  1431. if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
  1432. return -ENOBUFS;
  1433. params.n_ssids = req->n_ssids;
  1434. params.flags = req->flags;
  1435. params.n_channels = req->n_channels;
  1436. params.ssids = req->ssids;
  1437. params.channels = req->channels;
  1438. params.mac_addr = req->mac_addr;
  1439. params.mac_addr_mask = req->mac_addr_mask;
  1440. params.no_cck = false;
  1441. params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
  1442. params.n_match_sets = req->n_match_sets;
  1443. params.match_sets = req->match_sets;
  1444. if (!req->n_scan_plans)
  1445. return -EINVAL;
  1446. params.n_scan_plans = req->n_scan_plans;
  1447. params.scan_plans = req->scan_plans;
  1448. iwl_mvm_fill_scan_type(mvm, &params,
  1449. vif->type == NL80211_IFTYPE_P2P_DEVICE);
  1450. /* In theory, LMAC scans can handle a 32-bit delay, but since
  1451. * waiting for over 18 hours to start the scan is a bit silly
  1452. * and to keep it aligned with UMAC scans (which only support
  1453. * 16-bit delays), trim it down to 16-bits.
  1454. */
  1455. if (req->delay > U16_MAX) {
  1456. IWL_DEBUG_SCAN(mvm,
  1457. "delay value is > 16-bits, set to max possible\n");
  1458. params.delay = U16_MAX;
  1459. } else {
  1460. params.delay = req->delay;
  1461. }
  1462. ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
  1463. if (ret)
  1464. return ret;
  1465. iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
  1466. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1467. hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
  1468. ret = iwl_mvm_scan_umac(mvm, vif, &params, type);
  1469. } else {
  1470. hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
  1471. ret = iwl_mvm_scan_lmac(mvm, vif, &params);
  1472. }
  1473. if (ret)
  1474. return ret;
  1475. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1476. if (!ret) {
  1477. IWL_DEBUG_SCAN(mvm,
  1478. "Sched scan request was sent successfully\n");
  1479. mvm->scan_status |= type;
  1480. } else {
  1481. /* If the scan failed, it usually means that the FW was unable
  1482. * to allocate the time events. Warn on it, but maybe we
  1483. * should try to send the command again with different params.
  1484. */
  1485. IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
  1486. }
  1487. return ret;
  1488. }
  1489. void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
  1490. struct iwl_rx_cmd_buffer *rxb)
  1491. {
  1492. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1493. struct iwl_umac_scan_complete *notif = (void *)pkt->data;
  1494. u32 uid = __le32_to_cpu(notif->uid);
  1495. bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);
  1496. if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))
  1497. return;
  1498. /* if the scan is already stopping, we don't need to notify mac80211 */
  1499. if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {
  1500. struct cfg80211_scan_info info = {
  1501. .aborted = aborted,
  1502. .scan_start_tsf = mvm->scan_start,
  1503. };
  1504. memcpy(info.tsf_bssid, mvm->scan_vif->bssid, ETH_ALEN);
  1505. ieee80211_scan_completed(mvm->hw, &info);
  1506. mvm->scan_vif = NULL;
  1507. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1508. cancel_delayed_work(&mvm->scan_timeout_dwork);
  1509. iwl_mvm_resume_tcm(mvm);
  1510. } else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {
  1511. ieee80211_sched_scan_stopped(mvm->hw);
  1512. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1513. }
  1514. mvm->scan_status &= ~mvm->scan_uid_status[uid];
  1515. IWL_DEBUG_SCAN(mvm,
  1516. "Scan completed, uid %u type %u, status %s, EBS status %s\n",
  1517. uid, mvm->scan_uid_status[uid],
  1518. notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
  1519. "completed" : "aborted",
  1520. iwl_mvm_ebs_status_str(notif->ebs_status));
  1521. IWL_DEBUG_SCAN(mvm,
  1522. "Last line %d, Last iteration %d, Time from last iteration %d\n",
  1523. notif->last_schedule, notif->last_iter,
  1524. __le32_to_cpu(notif->time_from_last_iter));
  1525. if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&
  1526. notif->ebs_status != IWL_SCAN_EBS_INACTIVE)
  1527. mvm->last_ebs_successful = false;
  1528. mvm->scan_uid_status[uid] = 0;
  1529. }
  1530. void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
  1531. struct iwl_rx_cmd_buffer *rxb)
  1532. {
  1533. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1534. struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;
  1535. mvm->scan_start = le64_to_cpu(notif->start_tsf);
  1536. IWL_DEBUG_SCAN(mvm,
  1537. "UMAC Scan iteration complete: status=0x%x scanned_channels=%d\n",
  1538. notif->status, notif->scanned_channels);
  1539. if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {
  1540. IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");
  1541. ieee80211_sched_scan_results(mvm->hw);
  1542. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
  1543. }
  1544. IWL_DEBUG_SCAN(mvm,
  1545. "UMAC Scan iteration complete: scan started at %llu (TSF)\n",
  1546. mvm->scan_start);
  1547. }
  1548. static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type)
  1549. {
  1550. struct iwl_umac_scan_abort cmd = {};
  1551. int uid, ret;
  1552. lockdep_assert_held(&mvm->mutex);
  1553. /* We should always get a valid index here, because we already
  1554. * checked that this type of scan was running in the generic
  1555. * code.
  1556. */
  1557. uid = iwl_mvm_scan_uid_by_status(mvm, type);
  1558. if (WARN_ON_ONCE(uid < 0))
  1559. return uid;
  1560. cmd.uid = cpu_to_le32(uid);
  1561. IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
  1562. ret = iwl_mvm_send_cmd_pdu(mvm,
  1563. iwl_cmd_id(SCAN_ABORT_UMAC,
  1564. IWL_ALWAYS_LONG_GROUP, 0),
  1565. 0, sizeof(cmd), &cmd);
  1566. if (!ret)
  1567. mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;
  1568. return ret;
  1569. }
  1570. static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)
  1571. {
  1572. struct iwl_notification_wait wait_scan_done;
  1573. static const u16 scan_done_notif[] = { SCAN_COMPLETE_UMAC,
  1574. SCAN_OFFLOAD_COMPLETE, };
  1575. int ret;
  1576. lockdep_assert_held(&mvm->mutex);
  1577. iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
  1578. scan_done_notif,
  1579. ARRAY_SIZE(scan_done_notif),
  1580. NULL, NULL);
  1581. IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
  1582. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  1583. ret = iwl_mvm_umac_scan_abort(mvm, type);
  1584. else
  1585. ret = iwl_mvm_lmac_scan_abort(mvm);
  1586. if (ret) {
  1587. IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);
  1588. iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
  1589. return ret;
  1590. }
  1591. ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
  1592. return ret;
  1593. }
  1594. int iwl_mvm_scan_size(struct iwl_mvm *mvm)
  1595. {
  1596. int base_size = IWL_SCAN_REQ_UMAC_SIZE_V1;
  1597. if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
  1598. base_size = IWL_SCAN_REQ_UMAC_SIZE_V8;
  1599. else if (iwl_mvm_is_adaptive_dwell_supported(mvm))
  1600. base_size = IWL_SCAN_REQ_UMAC_SIZE_V7;
  1601. else if (iwl_mvm_cdb_scan_api(mvm))
  1602. base_size = IWL_SCAN_REQ_UMAC_SIZE_V6;
  1603. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  1604. return base_size +
  1605. sizeof(struct iwl_scan_channel_cfg_umac) *
  1606. mvm->fw->ucode_capa.n_scan_channels +
  1607. sizeof(struct iwl_scan_req_umac_tail);
  1608. return sizeof(struct iwl_scan_req_lmac) +
  1609. sizeof(struct iwl_scan_channel_cfg_lmac) *
  1610. mvm->fw->ucode_capa.n_scan_channels +
  1611. sizeof(struct iwl_scan_probe_req);
  1612. }
  1613. /*
  1614. * This function is used in nic restart flow, to inform mac80211 about scans
  1615. * that was aborted by restart flow or by an assert.
  1616. */
  1617. void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
  1618. {
  1619. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1620. int uid, i;
  1621. uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);
  1622. if (uid >= 0) {
  1623. struct cfg80211_scan_info info = {
  1624. .aborted = true,
  1625. };
  1626. ieee80211_scan_completed(mvm->hw, &info);
  1627. mvm->scan_uid_status[uid] = 0;
  1628. }
  1629. uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);
  1630. if (uid >= 0 && !mvm->fw_restart) {
  1631. ieee80211_sched_scan_stopped(mvm->hw);
  1632. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1633. mvm->scan_uid_status[uid] = 0;
  1634. }
  1635. /* We shouldn't have any UIDs still set. Loop over all the
  1636. * UIDs to make sure there's nothing left there and warn if
  1637. * any is found.
  1638. */
  1639. for (i = 0; i < mvm->max_scans; i++) {
  1640. if (WARN_ONCE(mvm->scan_uid_status[i],
  1641. "UMAC scan UID %d status was not cleaned\n",
  1642. i))
  1643. mvm->scan_uid_status[i] = 0;
  1644. }
  1645. } else {
  1646. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
  1647. struct cfg80211_scan_info info = {
  1648. .aborted = true,
  1649. };
  1650. ieee80211_scan_completed(mvm->hw, &info);
  1651. }
  1652. /* Sched scan will be restarted by mac80211 in
  1653. * restart_hw, so do not report if FW is about to be
  1654. * restarted.
  1655. */
  1656. if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) &&
  1657. !mvm->fw_restart) {
  1658. ieee80211_sched_scan_stopped(mvm->hw);
  1659. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1660. }
  1661. }
  1662. }
  1663. int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)
  1664. {
  1665. int ret;
  1666. if (!(mvm->scan_status & type))
  1667. return 0;
  1668. if (iwl_mvm_is_radio_killed(mvm)) {
  1669. ret = 0;
  1670. goto out;
  1671. }
  1672. ret = iwl_mvm_scan_stop_wait(mvm, type);
  1673. if (!ret)
  1674. mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;
  1675. out:
  1676. /* Clear the scan status so the next scan requests will
  1677. * succeed and mark the scan as stopping, so that the Rx
  1678. * handler doesn't do anything, as the scan was stopped from
  1679. * above.
  1680. */
  1681. mvm->scan_status &= ~type;
  1682. if (type == IWL_MVM_SCAN_REGULAR) {
  1683. /* Since the rx handler won't do anything now, we have
  1684. * to release the scan reference here.
  1685. */
  1686. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1687. cancel_delayed_work(&mvm->scan_timeout_dwork);
  1688. if (notify) {
  1689. struct cfg80211_scan_info info = {
  1690. .aborted = true,
  1691. };
  1692. ieee80211_scan_completed(mvm->hw, &info);
  1693. }
  1694. } else if (notify) {
  1695. ieee80211_sched_scan_stopped(mvm->hw);
  1696. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1697. }
  1698. return ret;
  1699. }