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