scan.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040
  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. bool low_latency;
  718. if (iwl_mvm_is_cdb_supported(mvm))
  719. low_latency = iwl_mvm_low_latency_band(mvm, NL80211_BAND_5GHZ);
  720. else
  721. low_latency = iwl_mvm_low_latency(mvm);
  722. /* We can only use EBS if:
  723. * 1. the feature is supported;
  724. * 2. the last EBS was successful;
  725. * 3. if only single scan, the single scan EBS API is supported;
  726. * 4. it's not a p2p find operation.
  727. * 5. we are not in low latency mode,
  728. * or if fragmented ebs is supported by the FW
  729. */
  730. return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
  731. mvm->last_ebs_successful && IWL_MVM_ENABLE_EBS &&
  732. vif->type != NL80211_IFTYPE_P2P_DEVICE &&
  733. (!low_latency || iwl_mvm_is_frag_ebs_supported(mvm)));
  734. }
  735. static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params *params)
  736. {
  737. return params->n_scan_plans == 1 &&
  738. params->scan_plans[0].iterations == 1;
  739. }
  740. static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
  741. struct iwl_mvm_scan_params *params,
  742. struct ieee80211_vif *vif)
  743. {
  744. int flags = 0;
  745. if (params->n_ssids == 0)
  746. flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
  747. if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
  748. flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
  749. if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
  750. flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
  751. if (iwl_mvm_rrm_scan_needed(mvm) &&
  752. fw_has_capa(&mvm->fw->ucode_capa,
  753. IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
  754. flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
  755. if (params->pass_all)
  756. flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
  757. else
  758. flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
  759. #ifdef CONFIG_IWLWIFI_DEBUGFS
  760. if (mvm->scan_iter_notif_enabled)
  761. flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
  762. #endif
  763. if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
  764. flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
  765. if (iwl_mvm_is_regular_scan(params) &&
  766. vif->type != NL80211_IFTYPE_P2P_DEVICE &&
  767. params->type != IWL_SCAN_TYPE_FRAGMENTED)
  768. flags |= IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL;
  769. return flags;
  770. }
  771. static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  772. struct iwl_mvm_scan_params *params)
  773. {
  774. struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
  775. struct iwl_scan_probe_req *preq =
  776. (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
  777. mvm->fw->ucode_capa.n_scan_channels);
  778. u32 ssid_bitmap = 0;
  779. int i;
  780. lockdep_assert_held(&mvm->mutex);
  781. memset(cmd, 0, ksize(cmd));
  782. if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
  783. return -EINVAL;
  784. iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
  785. cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
  786. cmd->iter_num = cpu_to_le32(1);
  787. cmd->n_channels = (u8)params->n_channels;
  788. cmd->delay = cpu_to_le32(params->delay);
  789. cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params,
  790. vif));
  791. cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
  792. cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
  793. MAC_FILTER_IN_BEACON);
  794. iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
  795. iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
  796. /* this API uses bits 1-20 instead of 0-19 */
  797. ssid_bitmap <<= 1;
  798. for (i = 0; i < params->n_scan_plans; i++) {
  799. struct cfg80211_sched_scan_plan *scan_plan =
  800. &params->scan_plans[i];
  801. cmd->schedule[i].delay =
  802. cpu_to_le16(scan_plan->interval);
  803. cmd->schedule[i].iterations = scan_plan->iterations;
  804. cmd->schedule[i].full_scan_mul = 1;
  805. }
  806. /*
  807. * If the number of iterations of the last scan plan is set to
  808. * zero, it should run infinitely. However, this is not always the case.
  809. * For example, when regular scan is requested the driver sets one scan
  810. * plan with one iteration.
  811. */
  812. if (!cmd->schedule[i - 1].iterations)
  813. cmd->schedule[i - 1].iterations = 0xff;
  814. if (iwl_mvm_scan_use_ebs(mvm, vif)) {
  815. cmd->channel_opt[0].flags =
  816. cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
  817. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  818. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
  819. cmd->channel_opt[0].non_ebs_ratio =
  820. cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
  821. cmd->channel_opt[1].flags =
  822. cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
  823. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  824. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
  825. cmd->channel_opt[1].non_ebs_ratio =
  826. cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
  827. }
  828. iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
  829. params->n_channels, ssid_bitmap, cmd);
  830. *preq = params->preq;
  831. return 0;
  832. }
  833. static int rate_to_scan_rate_flag(unsigned int rate)
  834. {
  835. static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
  836. [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
  837. [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
  838. [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
  839. [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
  840. [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
  841. [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
  842. [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
  843. [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
  844. [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
  845. [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
  846. [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
  847. [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
  848. };
  849. return rate_to_scan_rate[rate];
  850. }
  851. static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
  852. {
  853. struct ieee80211_supported_band *band;
  854. unsigned int rates = 0;
  855. int i;
  856. band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
  857. for (i = 0; i < band->n_bitrates; i++)
  858. rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
  859. band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
  860. for (i = 0; i < band->n_bitrates; i++)
  861. rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
  862. /* Set both basic rates and supported rates */
  863. rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
  864. return cpu_to_le32(rates);
  865. }
  866. static void iwl_mvm_fill_scan_dwell(struct iwl_mvm *mvm,
  867. struct iwl_scan_dwell *dwell)
  868. {
  869. dwell->active = IWL_SCAN_DWELL_ACTIVE;
  870. dwell->passive = IWL_SCAN_DWELL_PASSIVE;
  871. dwell->fragmented = IWL_SCAN_DWELL_FRAGMENTED;
  872. dwell->extended = IWL_SCAN_DWELL_EXTENDED;
  873. }
  874. static void iwl_mvm_fill_channels(struct iwl_mvm *mvm, u8 *channels)
  875. {
  876. struct ieee80211_supported_band *band;
  877. int i, j = 0;
  878. band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
  879. for (i = 0; i < band->n_channels; i++, j++)
  880. channels[j] = band->channels[i].hw_value;
  881. band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
  882. for (i = 0; i < band->n_channels; i++, j++)
  883. channels[j] = band->channels[i].hw_value;
  884. }
  885. static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm *mvm, void *config,
  886. u32 flags, u8 channel_flags)
  887. {
  888. enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, false);
  889. struct iwl_scan_config_v1 *cfg = config;
  890. cfg->flags = cpu_to_le32(flags);
  891. cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
  892. cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
  893. cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
  894. cfg->out_of_channel_time = cpu_to_le32(scan_timing[type].max_out_time);
  895. cfg->suspend_time = cpu_to_le32(scan_timing[type].suspend_time);
  896. iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
  897. memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
  898. cfg->bcast_sta_id = mvm->aux_sta.sta_id;
  899. cfg->channel_flags = channel_flags;
  900. iwl_mvm_fill_channels(mvm, cfg->channel_array);
  901. }
  902. static void iwl_mvm_fill_scan_config(struct iwl_mvm *mvm, void *config,
  903. u32 flags, u8 channel_flags)
  904. {
  905. struct iwl_scan_config *cfg = config;
  906. cfg->flags = cpu_to_le32(flags);
  907. cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
  908. cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
  909. cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
  910. if (iwl_mvm_is_cdb_supported(mvm)) {
  911. enum iwl_mvm_scan_type lb_type, hb_type;
  912. lb_type = iwl_mvm_get_scan_type_band(mvm, false,
  913. NL80211_BAND_2GHZ);
  914. hb_type = iwl_mvm_get_scan_type_band(mvm, false,
  915. NL80211_BAND_5GHZ);
  916. cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
  917. cpu_to_le32(scan_timing[lb_type].max_out_time);
  918. cfg->suspend_time[SCAN_LB_LMAC_IDX] =
  919. cpu_to_le32(scan_timing[lb_type].suspend_time);
  920. cfg->out_of_channel_time[SCAN_HB_LMAC_IDX] =
  921. cpu_to_le32(scan_timing[hb_type].max_out_time);
  922. cfg->suspend_time[SCAN_HB_LMAC_IDX] =
  923. cpu_to_le32(scan_timing[hb_type].suspend_time);
  924. } else {
  925. enum iwl_mvm_scan_type type =
  926. iwl_mvm_get_scan_type(mvm, false);
  927. cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
  928. cpu_to_le32(scan_timing[type].max_out_time);
  929. cfg->suspend_time[SCAN_LB_LMAC_IDX] =
  930. cpu_to_le32(scan_timing[type].suspend_time);
  931. }
  932. iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
  933. memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
  934. cfg->bcast_sta_id = mvm->aux_sta.sta_id;
  935. cfg->channel_flags = channel_flags;
  936. iwl_mvm_fill_channels(mvm, cfg->channel_array);
  937. }
  938. int iwl_mvm_config_scan(struct iwl_mvm *mvm)
  939. {
  940. void *cfg;
  941. int ret, cmd_size;
  942. struct iwl_host_cmd cmd = {
  943. .id = iwl_cmd_id(SCAN_CFG_CMD, IWL_ALWAYS_LONG_GROUP, 0),
  944. };
  945. enum iwl_mvm_scan_type type;
  946. enum iwl_mvm_scan_type hb_type = IWL_SCAN_TYPE_NOT_SET;
  947. int num_channels =
  948. mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels +
  949. mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels;
  950. u32 flags;
  951. u8 channel_flags;
  952. if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
  953. return -ENOBUFS;
  954. if (iwl_mvm_is_cdb_supported(mvm)) {
  955. type = iwl_mvm_get_scan_type_band(mvm, false,
  956. NL80211_BAND_2GHZ);
  957. hb_type = iwl_mvm_get_scan_type_band(mvm, false,
  958. NL80211_BAND_5GHZ);
  959. if (type == mvm->scan_type && hb_type == mvm->hb_scan_type)
  960. return 0;
  961. } else {
  962. type = iwl_mvm_get_scan_type(mvm, false);
  963. if (type == mvm->scan_type)
  964. return 0;
  965. }
  966. if (iwl_mvm_cdb_scan_api(mvm))
  967. cmd_size = sizeof(struct iwl_scan_config);
  968. else
  969. cmd_size = sizeof(struct iwl_scan_config_v1);
  970. cmd_size += mvm->fw->ucode_capa.n_scan_channels;
  971. cfg = kzalloc(cmd_size, GFP_KERNEL);
  972. if (!cfg)
  973. return -ENOMEM;
  974. flags = SCAN_CONFIG_FLAG_ACTIVATE |
  975. SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
  976. SCAN_CONFIG_FLAG_SET_TX_CHAINS |
  977. SCAN_CONFIG_FLAG_SET_RX_CHAINS |
  978. SCAN_CONFIG_FLAG_SET_AUX_STA_ID |
  979. SCAN_CONFIG_FLAG_SET_ALL_TIMES |
  980. SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
  981. SCAN_CONFIG_FLAG_SET_MAC_ADDR |
  982. SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS |
  983. SCAN_CONFIG_N_CHANNELS(num_channels) |
  984. (type == IWL_SCAN_TYPE_FRAGMENTED ?
  985. SCAN_CONFIG_FLAG_SET_FRAGMENTED :
  986. SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED);
  987. channel_flags = IWL_CHANNEL_FLAG_EBS |
  988. IWL_CHANNEL_FLAG_ACCURATE_EBS |
  989. IWL_CHANNEL_FLAG_EBS_ADD |
  990. IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
  991. /*
  992. * Check for fragmented scan on LMAC2 - high band.
  993. * LMAC1 - low band is checked above.
  994. */
  995. if (iwl_mvm_cdb_scan_api(mvm)) {
  996. if (iwl_mvm_is_cdb_supported(mvm))
  997. flags |= (hb_type == IWL_SCAN_TYPE_FRAGMENTED) ?
  998. SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED :
  999. SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED;
  1000. iwl_mvm_fill_scan_config(mvm, cfg, flags, channel_flags);
  1001. } else {
  1002. iwl_mvm_fill_scan_config_v1(mvm, cfg, flags, channel_flags);
  1003. }
  1004. cmd.data[0] = cfg;
  1005. cmd.len[0] = cmd_size;
  1006. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  1007. IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
  1008. ret = iwl_mvm_send_cmd(mvm, &cmd);
  1009. if (!ret) {
  1010. mvm->scan_type = type;
  1011. mvm->hb_scan_type = hb_type;
  1012. }
  1013. kfree(cfg);
  1014. return ret;
  1015. }
  1016. static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)
  1017. {
  1018. int i;
  1019. for (i = 0; i < mvm->max_scans; i++)
  1020. if (mvm->scan_uid_status[i] == status)
  1021. return i;
  1022. return -ENOENT;
  1023. }
  1024. static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
  1025. struct iwl_scan_req_umac *cmd,
  1026. struct iwl_mvm_scan_params *params)
  1027. {
  1028. struct iwl_mvm_scan_timing_params *timing, *hb_timing;
  1029. u8 active_dwell, passive_dwell;
  1030. timing = &scan_timing[params->type];
  1031. active_dwell = params->measurement_dwell ?
  1032. params->measurement_dwell : IWL_SCAN_DWELL_ACTIVE;
  1033. passive_dwell = params->measurement_dwell ?
  1034. params->measurement_dwell : IWL_SCAN_DWELL_PASSIVE;
  1035. if (iwl_mvm_is_adaptive_dwell_supported(mvm)) {
  1036. cmd->v7.adwell_default_n_aps_social =
  1037. IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL;
  1038. cmd->v7.adwell_default_n_aps =
  1039. IWL_SCAN_ADWELL_DEFAULT_N_APS;
  1040. /* if custom max budget was configured with debugfs */
  1041. if (IWL_MVM_ADWELL_MAX_BUDGET)
  1042. cmd->v7.adwell_max_budget =
  1043. cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET);
  1044. else if (params->ssids && params->ssids[0].ssid_len)
  1045. cmd->v7.adwell_max_budget =
  1046. cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN);
  1047. else
  1048. cmd->v7.adwell_max_budget =
  1049. cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN);
  1050. cmd->v7.scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1051. cmd->v7.max_out_time[SCAN_LB_LMAC_IDX] =
  1052. cpu_to_le32(timing->max_out_time);
  1053. cmd->v7.suspend_time[SCAN_LB_LMAC_IDX] =
  1054. cpu_to_le32(timing->suspend_time);
  1055. if (iwl_mvm_is_cdb_supported(mvm)) {
  1056. hb_timing = &scan_timing[params->hb_type];
  1057. cmd->v7.max_out_time[SCAN_HB_LMAC_IDX] =
  1058. cpu_to_le32(hb_timing->max_out_time);
  1059. cmd->v7.suspend_time[SCAN_HB_LMAC_IDX] =
  1060. cpu_to_le32(hb_timing->suspend_time);
  1061. }
  1062. if (!iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
  1063. cmd->v7.active_dwell = active_dwell;
  1064. cmd->v7.passive_dwell = passive_dwell;
  1065. cmd->v7.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
  1066. } else {
  1067. cmd->v8.active_dwell[SCAN_LB_LMAC_IDX] = active_dwell;
  1068. cmd->v8.passive_dwell[SCAN_LB_LMAC_IDX] = passive_dwell;
  1069. if (iwl_mvm_is_cdb_supported(mvm)) {
  1070. cmd->v8.active_dwell[SCAN_HB_LMAC_IDX] =
  1071. active_dwell;
  1072. cmd->v8.passive_dwell[SCAN_HB_LMAC_IDX] =
  1073. passive_dwell;
  1074. }
  1075. }
  1076. } else {
  1077. cmd->v1.extended_dwell = params->measurement_dwell ?
  1078. params->measurement_dwell : IWL_SCAN_DWELL_EXTENDED;
  1079. cmd->v1.active_dwell = active_dwell;
  1080. cmd->v1.passive_dwell = passive_dwell;
  1081. cmd->v1.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
  1082. if (iwl_mvm_is_cdb_supported(mvm)) {
  1083. hb_timing = &scan_timing[params->hb_type];
  1084. cmd->v6.max_out_time[SCAN_HB_LMAC_IDX] =
  1085. cpu_to_le32(hb_timing->max_out_time);
  1086. cmd->v6.suspend_time[SCAN_HB_LMAC_IDX] =
  1087. cpu_to_le32(hb_timing->suspend_time);
  1088. }
  1089. if (iwl_mvm_cdb_scan_api(mvm)) {
  1090. cmd->v6.scan_priority =
  1091. cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1092. cmd->v6.max_out_time[SCAN_LB_LMAC_IDX] =
  1093. cpu_to_le32(timing->max_out_time);
  1094. cmd->v6.suspend_time[SCAN_LB_LMAC_IDX] =
  1095. cpu_to_le32(timing->suspend_time);
  1096. } else {
  1097. cmd->v1.scan_priority =
  1098. cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1099. cmd->v1.max_out_time =
  1100. cpu_to_le32(timing->max_out_time);
  1101. cmd->v1.suspend_time =
  1102. cpu_to_le32(timing->suspend_time);
  1103. }
  1104. }
  1105. if (iwl_mvm_is_regular_scan(params))
  1106. cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
  1107. else
  1108. cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_2);
  1109. }
  1110. static void
  1111. iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
  1112. struct ieee80211_channel **channels,
  1113. int n_channels, u32 ssid_bitmap,
  1114. struct iwl_scan_channel_cfg_umac *channel_cfg)
  1115. {
  1116. int i;
  1117. for (i = 0; i < n_channels; i++) {
  1118. channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
  1119. channel_cfg[i].channel_num = channels[i]->hw_value;
  1120. channel_cfg[i].iter_count = 1;
  1121. channel_cfg[i].iter_interval = 0;
  1122. }
  1123. }
  1124. static u16 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
  1125. struct iwl_mvm_scan_params *params,
  1126. struct ieee80211_vif *vif)
  1127. {
  1128. u16 flags = 0;
  1129. if (params->n_ssids == 0)
  1130. flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
  1131. if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
  1132. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
  1133. if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
  1134. flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
  1135. if (iwl_mvm_is_cdb_supported(mvm) &&
  1136. params->hb_type == IWL_SCAN_TYPE_FRAGMENTED)
  1137. flags |= IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED;
  1138. if (iwl_mvm_rrm_scan_needed(mvm) &&
  1139. fw_has_capa(&mvm->fw->ucode_capa,
  1140. IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
  1141. flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
  1142. if (params->pass_all)
  1143. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
  1144. else
  1145. flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
  1146. if (!iwl_mvm_is_regular_scan(params))
  1147. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
  1148. if (params->measurement_dwell)
  1149. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
  1150. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1151. if (mvm->scan_iter_notif_enabled)
  1152. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
  1153. #endif
  1154. if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
  1155. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
  1156. if (iwl_mvm_is_adaptive_dwell_supported(mvm) && IWL_MVM_ADWELL_ENABLE &&
  1157. vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1158. flags |= IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL;
  1159. /*
  1160. * Extended dwell is relevant only for low band to start with, as it is
  1161. * being used for social channles only (1, 6, 11), so we can check
  1162. * only scan type on low band also for CDB.
  1163. */
  1164. if (iwl_mvm_is_regular_scan(params) &&
  1165. vif->type != NL80211_IFTYPE_P2P_DEVICE &&
  1166. params->type != IWL_SCAN_TYPE_FRAGMENTED &&
  1167. !iwl_mvm_is_adaptive_dwell_supported(mvm) &&
  1168. !iwl_mvm_is_oce_supported(mvm))
  1169. flags |= IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL;
  1170. if (iwl_mvm_is_oce_supported(mvm)) {
  1171. if ((params->flags &
  1172. NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE))
  1173. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE;
  1174. /* Since IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL and
  1175. * NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION shares
  1176. * the same bit, we need to make sure that we use this bit here
  1177. * only when IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL cannot be
  1178. * used. */
  1179. if ((params->flags &
  1180. NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
  1181. !WARN_ON_ONCE(!iwl_mvm_is_adaptive_dwell_supported(mvm)))
  1182. flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP;
  1183. if ((params->flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME))
  1184. flags |= IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME;
  1185. }
  1186. return flags;
  1187. }
  1188. static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1189. struct iwl_mvm_scan_params *params,
  1190. int type)
  1191. {
  1192. struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
  1193. struct iwl_scan_umac_chan_param *chan_param;
  1194. void *cmd_data = iwl_mvm_get_scan_req_umac_data(mvm);
  1195. struct iwl_scan_req_umac_tail *sec_part = cmd_data +
  1196. sizeof(struct iwl_scan_channel_cfg_umac) *
  1197. mvm->fw->ucode_capa.n_scan_channels;
  1198. int uid, i;
  1199. u32 ssid_bitmap = 0;
  1200. u8 channel_flags = 0;
  1201. u16 gen_flags;
  1202. struct iwl_mvm_vif *scan_vif = iwl_mvm_vif_from_mac80211(vif);
  1203. chan_param = iwl_mvm_get_scan_req_umac_channel(mvm);
  1204. lockdep_assert_held(&mvm->mutex);
  1205. if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
  1206. return -EINVAL;
  1207. uid = iwl_mvm_scan_uid_by_status(mvm, 0);
  1208. if (uid < 0)
  1209. return uid;
  1210. memset(cmd, 0, ksize(cmd));
  1211. iwl_mvm_scan_umac_dwell(mvm, cmd, params);
  1212. mvm->scan_uid_status[uid] = type;
  1213. cmd->uid = cpu_to_le32(uid);
  1214. gen_flags = iwl_mvm_scan_umac_flags(mvm, params, vif);
  1215. cmd->general_flags = cpu_to_le16(gen_flags);
  1216. if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
  1217. if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED)
  1218. cmd->v8.num_of_fragments[SCAN_LB_LMAC_IDX] =
  1219. IWL_SCAN_NUM_OF_FRAGS;
  1220. if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED)
  1221. cmd->v8.num_of_fragments[SCAN_HB_LMAC_IDX] =
  1222. IWL_SCAN_NUM_OF_FRAGS;
  1223. }
  1224. cmd->scan_start_mac_id = scan_vif->id;
  1225. if (type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT)
  1226. cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);
  1227. if (iwl_mvm_scan_use_ebs(mvm, vif))
  1228. channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
  1229. IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
  1230. IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
  1231. chan_param->flags = channel_flags;
  1232. chan_param->count = params->n_channels;
  1233. iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
  1234. iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
  1235. params->n_channels, ssid_bitmap,
  1236. cmd_data);
  1237. for (i = 0; i < params->n_scan_plans; i++) {
  1238. struct cfg80211_sched_scan_plan *scan_plan =
  1239. &params->scan_plans[i];
  1240. sec_part->schedule[i].iter_count = scan_plan->iterations;
  1241. sec_part->schedule[i].interval =
  1242. cpu_to_le16(scan_plan->interval);
  1243. }
  1244. /*
  1245. * If the number of iterations of the last scan plan is set to
  1246. * zero, it should run infinitely. However, this is not always the case.
  1247. * For example, when regular scan is requested the driver sets one scan
  1248. * plan with one iteration.
  1249. */
  1250. if (!sec_part->schedule[i - 1].iter_count)
  1251. sec_part->schedule[i - 1].iter_count = 0xff;
  1252. sec_part->delay = cpu_to_le16(params->delay);
  1253. sec_part->preq = params->preq;
  1254. return 0;
  1255. }
  1256. static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
  1257. {
  1258. return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
  1259. }
  1260. static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
  1261. {
  1262. bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
  1263. IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
  1264. /* This looks a bit arbitrary, but the idea is that if we run
  1265. * out of possible simultaneous scans and the userspace is
  1266. * trying to run a scan type that is already running, we
  1267. * return -EBUSY. But if the userspace wants to start a
  1268. * different type of scan, we stop the opposite type to make
  1269. * space for the new request. The reason is backwards
  1270. * compatibility with old wpa_supplicant that wouldn't stop a
  1271. * scheduled scan before starting a normal scan.
  1272. */
  1273. if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
  1274. return 0;
  1275. /* Use a switch, even though this is a bitmask, so that more
  1276. * than one bits set will fall in default and we will warn.
  1277. */
  1278. switch (type) {
  1279. case IWL_MVM_SCAN_REGULAR:
  1280. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
  1281. return -EBUSY;
  1282. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
  1283. case IWL_MVM_SCAN_SCHED:
  1284. if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
  1285. return -EBUSY;
  1286. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
  1287. case IWL_MVM_SCAN_NETDETECT:
  1288. /* For non-unified images, there's no need to stop
  1289. * anything for net-detect since the firmware is
  1290. * restarted anyway. This way, any sched scans that
  1291. * were running will be restarted when we resume.
  1292. */
  1293. if (!unified_image)
  1294. return 0;
  1295. /* If this is a unified image and we ran out of scans,
  1296. * we need to stop something. Prefer stopping regular
  1297. * scans, because the results are useless at this
  1298. * point, and we should be able to keep running
  1299. * another scheduled scan while suspended.
  1300. */
  1301. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
  1302. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR,
  1303. true);
  1304. if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
  1305. return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED,
  1306. true);
  1307. /* fall through, something is wrong if no scan was
  1308. * running but we ran out of scans.
  1309. */
  1310. default:
  1311. WARN_ON(1);
  1312. break;
  1313. }
  1314. return -EIO;
  1315. }
  1316. #define SCAN_TIMEOUT 20000
  1317. void iwl_mvm_scan_timeout_wk(struct work_struct *work)
  1318. {
  1319. struct delayed_work *delayed_work = to_delayed_work(work);
  1320. struct iwl_mvm *mvm = container_of(delayed_work, struct iwl_mvm,
  1321. scan_timeout_dwork);
  1322. IWL_ERR(mvm, "regular scan timed out\n");
  1323. iwl_force_nmi(mvm->trans);
  1324. }
  1325. static void iwl_mvm_fill_scan_type(struct iwl_mvm *mvm,
  1326. struct iwl_mvm_scan_params *params,
  1327. bool p2p)
  1328. {
  1329. if (iwl_mvm_is_cdb_supported(mvm)) {
  1330. params->type =
  1331. iwl_mvm_get_scan_type_band(mvm, p2p,
  1332. NL80211_BAND_2GHZ);
  1333. params->hb_type =
  1334. iwl_mvm_get_scan_type_band(mvm, p2p,
  1335. NL80211_BAND_5GHZ);
  1336. } else {
  1337. params->type = iwl_mvm_get_scan_type(mvm, p2p);
  1338. }
  1339. }
  1340. int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1341. struct cfg80211_scan_request *req,
  1342. struct ieee80211_scan_ies *ies)
  1343. {
  1344. struct iwl_host_cmd hcmd = {
  1345. .len = { iwl_mvm_scan_size(mvm), },
  1346. .data = { mvm->scan_cmd, },
  1347. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1348. };
  1349. struct iwl_mvm_scan_params params = {};
  1350. int ret;
  1351. struct cfg80211_sched_scan_plan scan_plan = { .iterations = 1 };
  1352. lockdep_assert_held(&mvm->mutex);
  1353. if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
  1354. IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
  1355. return -EBUSY;
  1356. }
  1357. ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
  1358. if (ret)
  1359. return ret;
  1360. /* we should have failed registration if scan_cmd was NULL */
  1361. if (WARN_ON(!mvm->scan_cmd))
  1362. return -ENOMEM;
  1363. if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
  1364. return -ENOBUFS;
  1365. params.n_ssids = req->n_ssids;
  1366. params.flags = req->flags;
  1367. params.n_channels = req->n_channels;
  1368. params.delay = 0;
  1369. params.ssids = req->ssids;
  1370. params.channels = req->channels;
  1371. params.mac_addr = req->mac_addr;
  1372. params.mac_addr_mask = req->mac_addr_mask;
  1373. params.no_cck = req->no_cck;
  1374. params.pass_all = true;
  1375. params.n_match_sets = 0;
  1376. params.match_sets = NULL;
  1377. params.scan_plans = &scan_plan;
  1378. params.n_scan_plans = 1;
  1379. iwl_mvm_fill_scan_type(mvm, &params,
  1380. vif->type == NL80211_IFTYPE_P2P_DEVICE);
  1381. ret = iwl_mvm_get_measurement_dwell(mvm, req, &params);
  1382. if (ret < 0)
  1383. return ret;
  1384. params.measurement_dwell = ret;
  1385. iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
  1386. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1387. hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
  1388. ret = iwl_mvm_scan_umac(mvm, vif, &params,
  1389. IWL_MVM_SCAN_REGULAR);
  1390. } else {
  1391. hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
  1392. ret = iwl_mvm_scan_lmac(mvm, vif, &params);
  1393. }
  1394. if (ret)
  1395. return ret;
  1396. iwl_mvm_pause_tcm(mvm, false);
  1397. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1398. if (ret) {
  1399. /* If the scan failed, it usually means that the FW was unable
  1400. * to allocate the time events. Warn on it, but maybe we
  1401. * should try to send the command again with different params.
  1402. */
  1403. IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
  1404. iwl_mvm_resume_tcm(mvm);
  1405. return ret;
  1406. }
  1407. IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
  1408. mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
  1409. mvm->scan_vif = iwl_mvm_vif_from_mac80211(vif);
  1410. iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
  1411. schedule_delayed_work(&mvm->scan_timeout_dwork,
  1412. msecs_to_jiffies(SCAN_TIMEOUT));
  1413. return 0;
  1414. }
  1415. int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
  1416. struct ieee80211_vif *vif,
  1417. struct cfg80211_sched_scan_request *req,
  1418. struct ieee80211_scan_ies *ies,
  1419. int type)
  1420. {
  1421. struct iwl_host_cmd hcmd = {
  1422. .len = { iwl_mvm_scan_size(mvm), },
  1423. .data = { mvm->scan_cmd, },
  1424. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1425. };
  1426. struct iwl_mvm_scan_params params = {};
  1427. int ret;
  1428. lockdep_assert_held(&mvm->mutex);
  1429. if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
  1430. IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
  1431. return -EBUSY;
  1432. }
  1433. ret = iwl_mvm_check_running_scans(mvm, type);
  1434. if (ret)
  1435. return ret;
  1436. /* we should have failed registration if scan_cmd was NULL */
  1437. if (WARN_ON(!mvm->scan_cmd))
  1438. return -ENOMEM;
  1439. if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
  1440. return -ENOBUFS;
  1441. params.n_ssids = req->n_ssids;
  1442. params.flags = req->flags;
  1443. params.n_channels = req->n_channels;
  1444. params.ssids = req->ssids;
  1445. params.channels = req->channels;
  1446. params.mac_addr = req->mac_addr;
  1447. params.mac_addr_mask = req->mac_addr_mask;
  1448. params.no_cck = false;
  1449. params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
  1450. params.n_match_sets = req->n_match_sets;
  1451. params.match_sets = req->match_sets;
  1452. if (!req->n_scan_plans)
  1453. return -EINVAL;
  1454. params.n_scan_plans = req->n_scan_plans;
  1455. params.scan_plans = req->scan_plans;
  1456. iwl_mvm_fill_scan_type(mvm, &params,
  1457. vif->type == NL80211_IFTYPE_P2P_DEVICE);
  1458. /* In theory, LMAC scans can handle a 32-bit delay, but since
  1459. * waiting for over 18 hours to start the scan is a bit silly
  1460. * and to keep it aligned with UMAC scans (which only support
  1461. * 16-bit delays), trim it down to 16-bits.
  1462. */
  1463. if (req->delay > U16_MAX) {
  1464. IWL_DEBUG_SCAN(mvm,
  1465. "delay value is > 16-bits, set to max possible\n");
  1466. params.delay = U16_MAX;
  1467. } else {
  1468. params.delay = req->delay;
  1469. }
  1470. ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
  1471. if (ret)
  1472. return ret;
  1473. iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
  1474. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1475. hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
  1476. ret = iwl_mvm_scan_umac(mvm, vif, &params, type);
  1477. } else {
  1478. hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
  1479. ret = iwl_mvm_scan_lmac(mvm, vif, &params);
  1480. }
  1481. if (ret)
  1482. return ret;
  1483. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1484. if (!ret) {
  1485. IWL_DEBUG_SCAN(mvm,
  1486. "Sched scan request was sent successfully\n");
  1487. mvm->scan_status |= type;
  1488. } else {
  1489. /* If the scan failed, it usually means that the FW was unable
  1490. * to allocate the time events. Warn on it, but maybe we
  1491. * should try to send the command again with different params.
  1492. */
  1493. IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
  1494. }
  1495. return ret;
  1496. }
  1497. void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
  1498. struct iwl_rx_cmd_buffer *rxb)
  1499. {
  1500. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1501. struct iwl_umac_scan_complete *notif = (void *)pkt->data;
  1502. u32 uid = __le32_to_cpu(notif->uid);
  1503. bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);
  1504. if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))
  1505. return;
  1506. /* if the scan is already stopping, we don't need to notify mac80211 */
  1507. if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {
  1508. struct cfg80211_scan_info info = {
  1509. .aborted = aborted,
  1510. .scan_start_tsf = mvm->scan_start,
  1511. };
  1512. memcpy(info.tsf_bssid, mvm->scan_vif->bssid, ETH_ALEN);
  1513. ieee80211_scan_completed(mvm->hw, &info);
  1514. mvm->scan_vif = NULL;
  1515. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1516. cancel_delayed_work(&mvm->scan_timeout_dwork);
  1517. iwl_mvm_resume_tcm(mvm);
  1518. } else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {
  1519. ieee80211_sched_scan_stopped(mvm->hw);
  1520. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1521. }
  1522. mvm->scan_status &= ~mvm->scan_uid_status[uid];
  1523. IWL_DEBUG_SCAN(mvm,
  1524. "Scan completed, uid %u type %u, status %s, EBS status %s\n",
  1525. uid, mvm->scan_uid_status[uid],
  1526. notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
  1527. "completed" : "aborted",
  1528. iwl_mvm_ebs_status_str(notif->ebs_status));
  1529. IWL_DEBUG_SCAN(mvm,
  1530. "Last line %d, Last iteration %d, Time from last iteration %d\n",
  1531. notif->last_schedule, notif->last_iter,
  1532. __le32_to_cpu(notif->time_from_last_iter));
  1533. if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&
  1534. notif->ebs_status != IWL_SCAN_EBS_INACTIVE)
  1535. mvm->last_ebs_successful = false;
  1536. mvm->scan_uid_status[uid] = 0;
  1537. }
  1538. void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
  1539. struct iwl_rx_cmd_buffer *rxb)
  1540. {
  1541. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1542. struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;
  1543. mvm->scan_start = le64_to_cpu(notif->start_tsf);
  1544. IWL_DEBUG_SCAN(mvm,
  1545. "UMAC Scan iteration complete: status=0x%x scanned_channels=%d\n",
  1546. notif->status, notif->scanned_channels);
  1547. if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {
  1548. IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");
  1549. ieee80211_sched_scan_results(mvm->hw);
  1550. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
  1551. }
  1552. IWL_DEBUG_SCAN(mvm,
  1553. "UMAC Scan iteration complete: scan started at %llu (TSF)\n",
  1554. mvm->scan_start);
  1555. }
  1556. static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type)
  1557. {
  1558. struct iwl_umac_scan_abort cmd = {};
  1559. int uid, ret;
  1560. lockdep_assert_held(&mvm->mutex);
  1561. /* We should always get a valid index here, because we already
  1562. * checked that this type of scan was running in the generic
  1563. * code.
  1564. */
  1565. uid = iwl_mvm_scan_uid_by_status(mvm, type);
  1566. if (WARN_ON_ONCE(uid < 0))
  1567. return uid;
  1568. cmd.uid = cpu_to_le32(uid);
  1569. IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
  1570. ret = iwl_mvm_send_cmd_pdu(mvm,
  1571. iwl_cmd_id(SCAN_ABORT_UMAC,
  1572. IWL_ALWAYS_LONG_GROUP, 0),
  1573. 0, sizeof(cmd), &cmd);
  1574. if (!ret)
  1575. mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;
  1576. return ret;
  1577. }
  1578. static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)
  1579. {
  1580. struct iwl_notification_wait wait_scan_done;
  1581. static const u16 scan_done_notif[] = { SCAN_COMPLETE_UMAC,
  1582. SCAN_OFFLOAD_COMPLETE, };
  1583. int ret;
  1584. lockdep_assert_held(&mvm->mutex);
  1585. iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
  1586. scan_done_notif,
  1587. ARRAY_SIZE(scan_done_notif),
  1588. NULL, NULL);
  1589. IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
  1590. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  1591. ret = iwl_mvm_umac_scan_abort(mvm, type);
  1592. else
  1593. ret = iwl_mvm_lmac_scan_abort(mvm);
  1594. if (ret) {
  1595. IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);
  1596. iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
  1597. return ret;
  1598. }
  1599. ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
  1600. return ret;
  1601. }
  1602. int iwl_mvm_scan_size(struct iwl_mvm *mvm)
  1603. {
  1604. int base_size = IWL_SCAN_REQ_UMAC_SIZE_V1;
  1605. if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
  1606. base_size = IWL_SCAN_REQ_UMAC_SIZE_V8;
  1607. else if (iwl_mvm_is_adaptive_dwell_supported(mvm))
  1608. base_size = IWL_SCAN_REQ_UMAC_SIZE_V7;
  1609. else if (iwl_mvm_cdb_scan_api(mvm))
  1610. base_size = IWL_SCAN_REQ_UMAC_SIZE_V6;
  1611. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  1612. return base_size +
  1613. sizeof(struct iwl_scan_channel_cfg_umac) *
  1614. mvm->fw->ucode_capa.n_scan_channels +
  1615. sizeof(struct iwl_scan_req_umac_tail);
  1616. return sizeof(struct iwl_scan_req_lmac) +
  1617. sizeof(struct iwl_scan_channel_cfg_lmac) *
  1618. mvm->fw->ucode_capa.n_scan_channels +
  1619. sizeof(struct iwl_scan_probe_req);
  1620. }
  1621. /*
  1622. * This function is used in nic restart flow, to inform mac80211 about scans
  1623. * that was aborted by restart flow or by an assert.
  1624. */
  1625. void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
  1626. {
  1627. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1628. int uid, i;
  1629. uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);
  1630. if (uid >= 0) {
  1631. struct cfg80211_scan_info info = {
  1632. .aborted = true,
  1633. };
  1634. ieee80211_scan_completed(mvm->hw, &info);
  1635. mvm->scan_uid_status[uid] = 0;
  1636. }
  1637. uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);
  1638. if (uid >= 0 && !mvm->fw_restart) {
  1639. ieee80211_sched_scan_stopped(mvm->hw);
  1640. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1641. mvm->scan_uid_status[uid] = 0;
  1642. }
  1643. /* We shouldn't have any UIDs still set. Loop over all the
  1644. * UIDs to make sure there's nothing left there and warn if
  1645. * any is found.
  1646. */
  1647. for (i = 0; i < mvm->max_scans; i++) {
  1648. if (WARN_ONCE(mvm->scan_uid_status[i],
  1649. "UMAC scan UID %d status was not cleaned\n",
  1650. i))
  1651. mvm->scan_uid_status[i] = 0;
  1652. }
  1653. } else {
  1654. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
  1655. struct cfg80211_scan_info info = {
  1656. .aborted = true,
  1657. };
  1658. ieee80211_scan_completed(mvm->hw, &info);
  1659. }
  1660. /* Sched scan will be restarted by mac80211 in
  1661. * restart_hw, so do not report if FW is about to be
  1662. * restarted.
  1663. */
  1664. if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) &&
  1665. !mvm->fw_restart) {
  1666. ieee80211_sched_scan_stopped(mvm->hw);
  1667. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1668. }
  1669. }
  1670. }
  1671. int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)
  1672. {
  1673. int ret;
  1674. if (!(mvm->scan_status & type))
  1675. return 0;
  1676. if (iwl_mvm_is_radio_killed(mvm)) {
  1677. ret = 0;
  1678. goto out;
  1679. }
  1680. ret = iwl_mvm_scan_stop_wait(mvm, type);
  1681. if (!ret)
  1682. mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;
  1683. out:
  1684. /* Clear the scan status so the next scan requests will
  1685. * succeed and mark the scan as stopping, so that the Rx
  1686. * handler doesn't do anything, as the scan was stopped from
  1687. * above.
  1688. */
  1689. mvm->scan_status &= ~type;
  1690. if (type == IWL_MVM_SCAN_REGULAR) {
  1691. /* Since the rx handler won't do anything now, we have
  1692. * to release the scan reference here.
  1693. */
  1694. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1695. cancel_delayed_work(&mvm->scan_timeout_dwork);
  1696. if (notify) {
  1697. struct cfg80211_scan_info info = {
  1698. .aborted = true,
  1699. };
  1700. ieee80211_scan_completed(mvm->hw, &info);
  1701. }
  1702. } else if (notify) {
  1703. ieee80211_sched_scan_stopped(mvm->hw);
  1704. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
  1705. }
  1706. return ret;
  1707. }