1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
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.
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.
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,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
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
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.
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.
64 *****************************************************************************/
66 #include <linux/etherdevice.h>
67 #include <net/mac80211.h>
70 #include "fw-api-scan.h"
72 #define IWL_DENSE_EBS_SCAN_RATIO 5
73 #define IWL_SPARSE_EBS_SCAN_RATIO 1
75 struct iwl_mvm_scan_params
{
78 bool passive_fragmented
;
82 struct cfg80211_ssid
*ssids
;
83 struct ieee80211_channel
**channels
;
84 u16 interval
; /* interval between scans (in secs) */
91 struct iwl_scan_probe_req preq
;
92 struct cfg80211_match_set
*match_sets
;
97 } dwell
[IEEE80211_NUM_BANDS
];
100 u8 full_scan_mul
; /* not used for UMAC */
104 static u8
iwl_mvm_scan_rx_ant(struct iwl_mvm
*mvm
)
106 if (mvm
->scan_rx_ant
!= ANT_NONE
)
107 return mvm
->scan_rx_ant
;
108 return iwl_mvm_get_valid_rx_ant(mvm
);
111 static inline __le16
iwl_mvm_scan_rx_chain(struct iwl_mvm
*mvm
)
116 rx_ant
= iwl_mvm_scan_rx_ant(mvm
);
117 rx_chain
= rx_ant
<< PHY_RX_CHAIN_VALID_POS
;
118 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_MIMO_SEL_POS
;
119 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_SEL_POS
;
120 rx_chain
|= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS
;
121 return cpu_to_le16(rx_chain
);
124 static __le32
iwl_mvm_scan_rxon_flags(enum ieee80211_band band
)
126 if (band
== IEEE80211_BAND_2GHZ
)
127 return cpu_to_le32(PHY_BAND_24
);
129 return cpu_to_le32(PHY_BAND_5
);
133 iwl_mvm_scan_rate_n_flags(struct iwl_mvm
*mvm
, enum ieee80211_band band
,
138 mvm
->scan_last_antenna_idx
=
139 iwl_mvm_next_antenna(mvm
, iwl_mvm_get_valid_tx_ant(mvm
),
140 mvm
->scan_last_antenna_idx
);
141 tx_ant
= BIT(mvm
->scan_last_antenna_idx
) << RATE_MCS_ANT_POS
;
143 if (band
== IEEE80211_BAND_2GHZ
&& !no_cck
)
144 return cpu_to_le32(IWL_RATE_1M_PLCP
| RATE_MCS_CCK_MSK
|
147 return cpu_to_le32(IWL_RATE_6M_PLCP
| tx_ant
);
151 * If req->n_ssids > 0, it means we should do an active scan.
152 * In case of active scan w/o directed scan, we receive a zero-length SSID
153 * just to notify that this scan is active and not passive.
154 * In order to notify the FW of the number of SSIDs we wish to scan (including
155 * the zero-length one), we need to set the corresponding bits in chan->type,
156 * one for each SSID, and set the active bit (first). If the first SSID is
157 * already included in the probe template, so we need to set only
158 * req->n_ssids - 1 bits in addition to the first bit.
160 static u16
iwl_mvm_get_active_dwell(struct iwl_mvm
*mvm
,
161 enum ieee80211_band band
, int n_ssids
)
163 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_BASIC_DWELL
)
165 if (band
== IEEE80211_BAND_2GHZ
)
166 return 20 + 3 * (n_ssids
+ 1);
167 return 10 + 2 * (n_ssids
+ 1);
170 static u16
iwl_mvm_get_passive_dwell(struct iwl_mvm
*mvm
,
171 enum ieee80211_band band
)
173 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_BASIC_DWELL
)
175 return band
== IEEE80211_BAND_2GHZ
? 100 + 20 : 100 + 10;
178 static void iwl_mvm_scan_condition_iterator(void *data
, u8
*mac
,
179 struct ieee80211_vif
*vif
)
181 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
182 int *global_cnt
= data
;
184 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
&& mvmvif
->phy_ctxt
&&
185 mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
189 static void iwl_mvm_scan_calc_dwell(struct iwl_mvm
*mvm
,
190 struct ieee80211_vif
*vif
,
191 struct iwl_mvm_scan_params
*params
)
194 enum ieee80211_band band
;
195 u8 frag_passive_dwell
= 0;
197 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
198 IEEE80211_IFACE_ITER_NORMAL
,
199 iwl_mvm_scan_condition_iterator
,
204 params
->suspend_time
= 30;
205 params
->max_out_time
= 120;
207 if (iwl_mvm_low_latency(mvm
)) {
208 if (mvm
->fw
->ucode_capa
.api
[0] &
209 IWL_UCODE_TLV_API_FRAGMENTED_SCAN
) {
210 params
->suspend_time
= 105;
212 * If there is more than one active interface make
213 * passive scan more fragmented.
215 frag_passive_dwell
= 40;
216 params
->max_out_time
= frag_passive_dwell
;
218 params
->suspend_time
= 120;
219 params
->max_out_time
= 120;
223 if (frag_passive_dwell
&& (mvm
->fw
->ucode_capa
.api
[0] &
224 IWL_UCODE_TLV_API_FRAGMENTED_SCAN
)) {
226 * P2P device scan should not be fragmented to avoid negative
227 * impact on P2P device discovery. Configure max_out_time to be
228 * equal to dwell time on passive channel. Take a longest
229 * possible value, one that corresponds to 2GHz band
231 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
233 iwl_mvm_get_passive_dwell(mvm
,
234 IEEE80211_BAND_2GHZ
);
235 params
->max_out_time
= passive_dwell
;
237 params
->passive_fragmented
= true;
241 if ((params
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
242 (params
->max_out_time
> 200))
243 params
->max_out_time
= 200;
247 for (band
= IEEE80211_BAND_2GHZ
; band
< IEEE80211_NUM_BANDS
; band
++) {
248 if (params
->passive_fragmented
)
249 params
->dwell
[band
].fragmented
= frag_passive_dwell
;
251 params
->dwell
[band
].passive
= iwl_mvm_get_passive_dwell(mvm
,
253 params
->dwell
[band
].active
=
254 iwl_mvm_get_active_dwell(mvm
, band
, params
->n_ssids
);
258 "scan parameters: max_out_time %d, suspend_time %d, passive_fragmented %d\n",
259 params
->max_out_time
, params
->suspend_time
,
260 params
->passive_fragmented
);
262 "dwell[IEEE80211_BAND_2GHZ]: passive %d, active %d, fragmented %d\n",
263 params
->dwell
[IEEE80211_BAND_2GHZ
].passive
,
264 params
->dwell
[IEEE80211_BAND_2GHZ
].active
,
265 params
->dwell
[IEEE80211_BAND_2GHZ
].fragmented
);
267 "dwell[IEEE80211_BAND_5GHZ]: passive %d, active %d, fragmented %d\n",
268 params
->dwell
[IEEE80211_BAND_5GHZ
].passive
,
269 params
->dwell
[IEEE80211_BAND_5GHZ
].active
,
270 params
->dwell
[IEEE80211_BAND_5GHZ
].fragmented
);
273 static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm
*mvm
)
275 /* require rrm scan whenever the fw supports it */
276 return mvm
->fw
->ucode_capa
.capa
[0] &
277 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT
;
280 static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm
*mvm
)
284 max_probe_len
= SCAN_OFFLOAD_PROBE_REQ_SIZE
;
286 /* we create the 802.11 header and SSID element */
287 max_probe_len
-= 24 + 2;
289 /* DS parameter set element is added on 2.4GHZ band if required */
290 if (iwl_mvm_rrm_scan_needed(mvm
))
293 return max_probe_len
;
296 int iwl_mvm_max_scan_ie_len(struct iwl_mvm
*mvm
)
298 int max_ie_len
= iwl_mvm_max_scan_ie_fw_cmd_room(mvm
);
300 /* TODO: [BUG] This function should return the maximum allowed size of
301 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
302 * in the same command. So the correct implementation of this function
303 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
304 * command has only 512 bytes and it would leave us with about 240
305 * bytes for scan IEs, which is clearly not enough. So meanwhile
306 * we will report an incorrect value. This may result in a failure to
307 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
308 * functions with -ENOBUFS, if a large enough probe will be provided.
313 static u8
*iwl_mvm_dump_channel_list(struct iwl_scan_results_notif
*res
,
314 int num_res
, u8
*buf
, size_t buf_size
)
317 u8
*pos
= buf
, *end
= buf
+ buf_size
;
319 for (i
= 0; pos
< end
&& i
< num_res
; i
++)
320 pos
+= snprintf(pos
, end
- pos
, " %u", res
[i
].channel
);
322 /* terminate the string in case the buffer was too short */
323 *(buf
+ buf_size
- 1) = '\0';
328 int iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm
*mvm
,
329 struct iwl_rx_cmd_buffer
*rxb
,
330 struct iwl_device_cmd
*cmd
)
332 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
333 struct iwl_lmac_scan_complete_notif
*notif
= (void *)pkt
->data
;
337 "Scan offload iteration complete: status=0x%x scanned channels=%d channels list: %s\n",
338 notif
->status
, notif
->scanned_channels
,
339 iwl_mvm_dump_channel_list(notif
->results
,
340 notif
->scanned_channels
, buf
,
345 int iwl_mvm_rx_scan_match_found(struct iwl_mvm
*mvm
,
346 struct iwl_rx_cmd_buffer
*rxb
,
347 struct iwl_device_cmd
*cmd
)
349 IWL_DEBUG_SCAN(mvm
, "Scheduled scan results\n");
350 ieee80211_sched_scan_results(mvm
->hw
);
355 int iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm
*mvm
,
356 struct iwl_rx_cmd_buffer
*rxb
,
357 struct iwl_device_cmd
*cmd
)
359 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
360 struct iwl_periodic_scan_complete
*scan_notif
= (void *)pkt
->data
;
361 bool aborted
= (scan_notif
->status
== IWL_SCAN_OFFLOAD_ABORTED
);
362 bool ebs_successful
= (scan_notif
->ebs_status
== IWL_SCAN_EBS_SUCCESS
);
364 /* scan status must be locked for proper checking */
365 lockdep_assert_held(&mvm
->mutex
);
367 /* We first check if we were stopping a scan, in which case we
368 * just clear the stopping flag. Then we check if it was a
369 * firmware initiated stop, in which case we need to inform
371 * Note that we can have a stopping and a running scan
372 * simultaneously, but we can't have two different types of
373 * scans stopping or running at the same time (since LMAC
374 * doesn't support it).
377 if (mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_SCHED
) {
378 WARN_ON_ONCE(mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_REGULAR
);
380 IWL_DEBUG_SCAN(mvm
, "Scheduled scan %s, EBS status %s\n",
381 aborted
? "aborted" : "completed",
382 ebs_successful
? "successful" : "failed");
384 mvm
->scan_status
&= ~IWL_MVM_SCAN_STOPPING_SCHED
;
385 } else if (mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_REGULAR
) {
386 IWL_DEBUG_SCAN(mvm
, "Regular scan %s, EBS status %s\n",
387 aborted
? "aborted" : "completed",
388 ebs_successful
? "successful" : "failed");
390 mvm
->scan_status
&= ~IWL_MVM_SCAN_STOPPING_REGULAR
;
391 } else if (mvm
->scan_status
& IWL_MVM_SCAN_SCHED
) {
392 WARN_ON_ONCE(mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
);
394 IWL_DEBUG_SCAN(mvm
, "Scheduled scan %s, EBS status %s (FW)\n",
395 aborted
? "aborted" : "completed",
396 ebs_successful
? "successful" : "failed");
398 mvm
->scan_status
&= ~IWL_MVM_SCAN_SCHED
;
399 ieee80211_sched_scan_stopped(mvm
->hw
);
400 } else if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
) {
401 IWL_DEBUG_SCAN(mvm
, "Regular scan %s, EBS status %s (FW)\n",
402 aborted
? "aborted" : "completed",
403 ebs_successful
? "successful" : "failed");
405 mvm
->scan_status
&= ~IWL_MVM_SCAN_REGULAR
;
406 ieee80211_scan_completed(mvm
->hw
,
407 scan_notif
->status
== IWL_SCAN_OFFLOAD_ABORTED
);
408 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
411 mvm
->last_ebs_successful
= ebs_successful
;
416 static int iwl_ssid_exist(u8
*ssid
, u8 ssid_len
, struct iwl_ssid_ie
*ssid_list
)
420 for (i
= 0; i
< PROBE_OPTION_MAX
; i
++) {
421 if (!ssid_list
[i
].len
)
423 if (ssid_list
[i
].len
== ssid_len
&&
424 !memcmp(ssid_list
->ssid
, ssid
, ssid_len
))
430 /* We insert the SSIDs in an inverted order, because the FW will
433 static void iwl_scan_build_ssids(struct iwl_mvm_scan_params
*params
,
434 struct iwl_ssid_ie
*ssids
,
441 * copy SSIDs from match list.
442 * iwl_config_sched_scan_profiles() uses the order of these ssids to
445 for (i
= 0, j
= params
->n_match_sets
- 1;
446 j
>= 0 && i
< PROBE_OPTION_MAX
;
448 /* skip empty SSID matchsets */
449 if (!params
->match_sets
[j
].ssid
.ssid_len
)
451 ssids
[i
].id
= WLAN_EID_SSID
;
452 ssids
[i
].len
= params
->match_sets
[j
].ssid
.ssid_len
;
453 memcpy(ssids
[i
].ssid
, params
->match_sets
[j
].ssid
.ssid
,
457 /* add SSIDs from scan SSID list */
459 for (j
= params
->n_ssids
- 1;
460 j
>= 0 && i
< PROBE_OPTION_MAX
;
462 index
= iwl_ssid_exist(params
->ssids
[j
].ssid
,
463 params
->ssids
[j
].ssid_len
,
466 ssids
[i
].id
= WLAN_EID_SSID
;
467 ssids
[i
].len
= params
->ssids
[j
].ssid_len
;
468 memcpy(ssids
[i
].ssid
, params
->ssids
[j
].ssid
,
470 *ssid_bitmap
|= BIT(i
);
472 *ssid_bitmap
|= BIT(index
);
478 iwl_mvm_config_sched_scan_profiles(struct iwl_mvm
*mvm
,
479 struct cfg80211_sched_scan_request
*req
)
481 struct iwl_scan_offload_profile
*profile
;
482 struct iwl_scan_offload_profile_cfg
*profile_cfg
;
483 struct iwl_scan_offload_blacklist
*blacklist
;
484 struct iwl_host_cmd cmd
= {
485 .id
= SCAN_OFFLOAD_UPDATE_PROFILES_CMD
,
486 .len
[1] = sizeof(*profile_cfg
),
487 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
488 .dataflags
[1] = IWL_HCMD_DFL_NOCOPY
,
494 if (WARN_ON(req
->n_match_sets
> IWL_SCAN_MAX_PROFILES
))
497 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SHORT_BL
)
498 blacklist_len
= IWL_SCAN_SHORT_BLACKLIST_LEN
;
500 blacklist_len
= IWL_SCAN_MAX_BLACKLIST_LEN
;
502 blacklist
= kzalloc(sizeof(*blacklist
) * blacklist_len
, GFP_KERNEL
);
506 profile_cfg
= kzalloc(sizeof(*profile_cfg
), GFP_KERNEL
);
512 cmd
.data
[0] = blacklist
;
513 cmd
.len
[0] = sizeof(*blacklist
) * blacklist_len
;
514 cmd
.data
[1] = profile_cfg
;
516 /* No blacklist configuration */
518 profile_cfg
->num_profiles
= req
->n_match_sets
;
519 profile_cfg
->active_clients
= SCAN_CLIENT_SCHED_SCAN
;
520 profile_cfg
->pass_match
= SCAN_CLIENT_SCHED_SCAN
;
521 profile_cfg
->match_notify
= SCAN_CLIENT_SCHED_SCAN
;
522 if (!req
->n_match_sets
|| !req
->match_sets
[0].ssid
.ssid_len
)
523 profile_cfg
->any_beacon_notify
= SCAN_CLIENT_SCHED_SCAN
;
525 for (i
= 0; i
< req
->n_match_sets
; i
++) {
526 profile
= &profile_cfg
->profiles
[i
];
527 profile
->ssid_index
= i
;
528 /* Support any cipher and auth algorithm */
529 profile
->unicast_cipher
= 0xff;
530 profile
->auth_alg
= 0xff;
531 profile
->network_type
= IWL_NETWORK_TYPE_ANY
;
532 profile
->band_selection
= IWL_SCAN_OFFLOAD_SELECT_ANY
;
533 profile
->client_bitmap
= SCAN_CLIENT_SCHED_SCAN
;
536 IWL_DEBUG_SCAN(mvm
, "Sending scheduled scan profile config\n");
538 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
546 static bool iwl_mvm_scan_pass_all(struct iwl_mvm
*mvm
,
547 struct cfg80211_sched_scan_request
*req
)
549 if (req
->n_match_sets
&& req
->match_sets
[0].ssid
.ssid_len
) {
551 "Sending scheduled scan with filtering, n_match_sets %d\n",
556 IWL_DEBUG_SCAN(mvm
, "Sending Scheduled scan without filtering\n");
560 static int iwl_mvm_lmac_scan_abort(struct iwl_mvm
*mvm
)
563 struct iwl_host_cmd cmd
= {
564 .id
= SCAN_OFFLOAD_ABORT_CMD
,
568 ret
= iwl_mvm_send_cmd_status(mvm
, &cmd
, &status
);
572 if (status
!= CAN_ABORT_STATUS
) {
574 * The scan abort will return 1 for success or
575 * 2 for "failure". A failure condition can be
576 * due to simply not being in an active scan which
577 * can occur if we send the scan abort before the
578 * microcode has notified us that a scan is completed.
580 IWL_DEBUG_SCAN(mvm
, "SCAN OFFLOAD ABORT ret %d.\n", status
);
587 static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm
*mvm
,
588 struct iwl_scan_req_tx_cmd
*tx_cmd
,
591 tx_cmd
[0].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
593 tx_cmd
[0].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
596 tx_cmd
[0].sta_id
= mvm
->aux_sta
.sta_id
;
598 tx_cmd
[1].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
600 tx_cmd
[1].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
603 tx_cmd
[1].sta_id
= mvm
->aux_sta
.sta_id
;
607 iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm
*mvm
,
608 struct ieee80211_channel
**channels
,
609 int n_channels
, u32 ssid_bitmap
,
610 struct iwl_scan_req_lmac
*cmd
)
612 struct iwl_scan_channel_cfg_lmac
*channel_cfg
= (void *)&cmd
->data
;
615 for (i
= 0; i
< n_channels
; i
++) {
616 channel_cfg
[i
].channel_num
=
617 cpu_to_le16(channels
[i
]->hw_value
);
618 channel_cfg
[i
].iter_count
= cpu_to_le16(1);
619 channel_cfg
[i
].iter_interval
= 0;
620 channel_cfg
[i
].flags
=
621 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL
|
626 static u8
*iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm
*mvm
, const u8
*ies
,
627 size_t len
, u8
*const pos
)
629 static const u8 before_ds_params
[] = {
633 WLAN_EID_EXT_SUPP_RATES
,
638 if (!iwl_mvm_rrm_scan_needed(mvm
)) {
639 memcpy(newpos
, ies
, len
);
643 offs
= ieee80211_ie_split(ies
, len
,
645 ARRAY_SIZE(before_ds_params
),
648 memcpy(newpos
, ies
, offs
);
651 /* Add a placeholder for DS Parameter Set element */
652 *newpos
++ = WLAN_EID_DS_PARAMS
;
656 memcpy(newpos
, ies
+ offs
, len
- offs
);
657 newpos
+= len
- offs
;
663 iwl_mvm_build_scan_probe(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
664 struct ieee80211_scan_ies
*ies
,
665 struct iwl_mvm_scan_params
*params
)
667 struct ieee80211_mgmt
*frame
= (void *)params
->preq
.buf
;
669 const u8
*mac_addr
= params
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
?
670 params
->mac_addr
: NULL
;
673 * Unfortunately, right now the offload scan doesn't support randomising
674 * within the firmware, so until the firmware API is ready we implement
675 * it in the driver. This means that the scan iterations won't really be
676 * random, only when it's restarted, but at least that helps a bit.
679 get_random_mask_addr(frame
->sa
, mac_addr
,
680 params
->mac_addr_mask
);
682 memcpy(frame
->sa
, vif
->addr
, ETH_ALEN
);
684 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
685 eth_broadcast_addr(frame
->da
);
686 eth_broadcast_addr(frame
->bssid
);
689 pos
= frame
->u
.probe_req
.variable
;
690 *pos
++ = WLAN_EID_SSID
;
693 params
->preq
.mac_header
.offset
= 0;
694 params
->preq
.mac_header
.len
= cpu_to_le16(24 + 2);
696 /* Insert ds parameter set element on 2.4 GHz band */
697 newpos
= iwl_mvm_copy_and_insert_ds_elem(mvm
,
698 ies
->ies
[IEEE80211_BAND_2GHZ
],
699 ies
->len
[IEEE80211_BAND_2GHZ
],
701 params
->preq
.band_data
[0].offset
= cpu_to_le16(pos
- params
->preq
.buf
);
702 params
->preq
.band_data
[0].len
= cpu_to_le16(newpos
- pos
);
705 memcpy(pos
, ies
->ies
[IEEE80211_BAND_5GHZ
],
706 ies
->len
[IEEE80211_BAND_5GHZ
]);
707 params
->preq
.band_data
[1].offset
= cpu_to_le16(pos
- params
->preq
.buf
);
708 params
->preq
.band_data
[1].len
=
709 cpu_to_le16(ies
->len
[IEEE80211_BAND_5GHZ
]);
710 pos
+= ies
->len
[IEEE80211_BAND_5GHZ
];
712 memcpy(pos
, ies
->common_ies
, ies
->common_ie_len
);
713 params
->preq
.common_data
.offset
= cpu_to_le16(pos
- params
->preq
.buf
);
714 params
->preq
.common_data
.len
= cpu_to_le16(ies
->common_ie_len
);
717 static __le32
iwl_mvm_scan_priority(struct iwl_mvm
*mvm
,
718 enum iwl_scan_priority_ext prio
)
720 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_EXT_SCAN_PRIORITY
)
721 return cpu_to_le32(prio
);
723 if (prio
<= IWL_SCAN_PRIORITY_EXT_2
)
724 return cpu_to_le32(IWL_SCAN_PRIORITY_LOW
);
726 if (prio
<= IWL_SCAN_PRIORITY_EXT_4
)
727 return cpu_to_le32(IWL_SCAN_PRIORITY_MEDIUM
);
729 return cpu_to_le32(IWL_SCAN_PRIORITY_HIGH
);
732 static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm
*mvm
,
733 struct iwl_scan_req_lmac
*cmd
,
734 struct iwl_mvm_scan_params
*params
)
736 cmd
->active_dwell
= params
->dwell
[IEEE80211_BAND_2GHZ
].active
;
737 cmd
->passive_dwell
= params
->dwell
[IEEE80211_BAND_2GHZ
].passive
;
738 if (params
->passive_fragmented
)
739 cmd
->fragmented_dwell
=
740 params
->dwell
[IEEE80211_BAND_2GHZ
].fragmented
;
741 cmd
->max_out_time
= cpu_to_le32(params
->max_out_time
);
742 cmd
->suspend_time
= cpu_to_le32(params
->suspend_time
);
743 cmd
->scan_prio
= iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_6
);
746 static inline bool iwl_mvm_scan_fits(struct iwl_mvm
*mvm
, int n_ssids
,
747 struct ieee80211_scan_ies
*ies
,
750 return ((n_ssids
<= PROBE_OPTION_MAX
) &&
751 (n_channels
<= mvm
->fw
->ucode_capa
.n_scan_channels
) &
752 (ies
->common_ie_len
+
753 ies
->len
[NL80211_BAND_2GHZ
] +
754 ies
->len
[NL80211_BAND_5GHZ
] <=
755 iwl_mvm_max_scan_ie_fw_cmd_room(mvm
)));
758 static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm
*mvm
, int n_iterations
)
760 const struct iwl_ucode_capabilities
*capa
= &mvm
->fw
->ucode_capa
;
762 /* We can only use EBS if:
763 * 1. the feature is supported;
764 * 2. the last EBS was successful;
765 * 3. if only single scan, the single scan EBS API is supported.
767 return ((capa
->flags
& IWL_UCODE_TLV_FLAGS_EBS_SUPPORT
) &&
768 mvm
->last_ebs_successful
&&
770 (capa
->api
[0] & IWL_UCODE_TLV_API_SINGLE_SCAN_EBS
)));
773 static int iwl_mvm_scan_total_iterations(struct iwl_mvm_scan_params
*params
)
775 return params
->schedule
[0].iterations
+ params
->schedule
[1].iterations
;
778 static int iwl_mvm_scan_lmac_flags(struct iwl_mvm
*mvm
,
779 struct iwl_mvm_scan_params
*params
)
783 if (params
->n_ssids
== 0)
784 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE
;
786 if (params
->n_ssids
== 1 && params
->ssids
[0].ssid_len
!= 0)
787 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION
;
789 if (params
->passive_fragmented
)
790 flags
|= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED
;
792 if (iwl_mvm_rrm_scan_needed(mvm
))
793 flags
|= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED
;
795 if (params
->pass_all
)
796 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL
;
798 flags
|= IWL_MVM_LMAC_SCAN_FLAG_MATCH
;
800 #ifdef CONFIG_IWLWIFI_DEBUGFS
801 if (mvm
->scan_iter_notif_enabled
)
802 flags
|= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE
;
808 static int iwl_mvm_scan_lmac(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
809 struct iwl_mvm_scan_params
*params
)
811 struct iwl_scan_req_lmac
*cmd
= mvm
->scan_cmd
;
812 struct iwl_scan_probe_req
*preq
=
813 (void *)(cmd
->data
+ sizeof(struct iwl_scan_channel_cfg_lmac
) *
814 mvm
->fw
->ucode_capa
.n_scan_channels
);
816 int n_iterations
= iwl_mvm_scan_total_iterations(params
);
818 lockdep_assert_held(&mvm
->mutex
);
820 memset(cmd
, 0, ksize(cmd
));
822 iwl_mvm_scan_lmac_dwell(mvm
, cmd
, params
);
824 cmd
->rx_chain_select
= iwl_mvm_scan_rx_chain(mvm
);
825 cmd
->iter_num
= cpu_to_le32(1);
826 cmd
->n_channels
= (u8
)params
->n_channels
;
828 cmd
->delay
= cpu_to_le32(params
->delay
);
830 cmd
->scan_flags
= cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm
, params
));
832 cmd
->flags
= iwl_mvm_scan_rxon_flags(params
->channels
[0]->band
);
833 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
834 MAC_FILTER_IN_BEACON
);
835 iwl_mvm_scan_fill_tx_cmd(mvm
, cmd
->tx_cmd
, params
->no_cck
);
836 iwl_scan_build_ssids(params
, cmd
->direct_scan
, &ssid_bitmap
);
838 /* this API uses bits 1-20 instead of 0-19 */
841 cmd
->schedule
[0].delay
= cpu_to_le16(params
->interval
);
842 cmd
->schedule
[0].iterations
= params
->schedule
[0].iterations
;
843 cmd
->schedule
[0].full_scan_mul
= params
->schedule
[0].full_scan_mul
;
844 cmd
->schedule
[1].delay
= cpu_to_le16(params
->interval
);
845 cmd
->schedule
[1].iterations
= params
->schedule
[1].iterations
;
846 cmd
->schedule
[1].full_scan_mul
= params
->schedule
[1].iterations
;
848 if (iwl_mvm_scan_use_ebs(mvm
, n_iterations
)) {
849 cmd
->channel_opt
[0].flags
=
850 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
851 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
852 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
853 cmd
->channel_opt
[0].non_ebs_ratio
=
854 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO
);
855 cmd
->channel_opt
[1].flags
=
856 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
857 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
858 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
859 cmd
->channel_opt
[1].non_ebs_ratio
=
860 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO
);
863 iwl_mvm_lmac_scan_cfg_channels(mvm
, params
->channels
,
864 params
->n_channels
, ssid_bitmap
, cmd
);
866 *preq
= params
->preq
;
871 static int rate_to_scan_rate_flag(unsigned int rate
)
873 static const int rate_to_scan_rate
[IWL_RATE_COUNT
] = {
874 [IWL_RATE_1M_INDEX
] = SCAN_CONFIG_RATE_1M
,
875 [IWL_RATE_2M_INDEX
] = SCAN_CONFIG_RATE_2M
,
876 [IWL_RATE_5M_INDEX
] = SCAN_CONFIG_RATE_5M
,
877 [IWL_RATE_11M_INDEX
] = SCAN_CONFIG_RATE_11M
,
878 [IWL_RATE_6M_INDEX
] = SCAN_CONFIG_RATE_6M
,
879 [IWL_RATE_9M_INDEX
] = SCAN_CONFIG_RATE_9M
,
880 [IWL_RATE_12M_INDEX
] = SCAN_CONFIG_RATE_12M
,
881 [IWL_RATE_18M_INDEX
] = SCAN_CONFIG_RATE_18M
,
882 [IWL_RATE_24M_INDEX
] = SCAN_CONFIG_RATE_24M
,
883 [IWL_RATE_36M_INDEX
] = SCAN_CONFIG_RATE_36M
,
884 [IWL_RATE_48M_INDEX
] = SCAN_CONFIG_RATE_48M
,
885 [IWL_RATE_54M_INDEX
] = SCAN_CONFIG_RATE_54M
,
888 return rate_to_scan_rate
[rate
];
891 static __le32
iwl_mvm_scan_config_rates(struct iwl_mvm
*mvm
)
893 struct ieee80211_supported_band
*band
;
894 unsigned int rates
= 0;
897 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
898 for (i
= 0; i
< band
->n_bitrates
; i
++)
899 rates
|= rate_to_scan_rate_flag(band
->bitrates
[i
].hw_value
);
900 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
901 for (i
= 0; i
< band
->n_bitrates
; i
++)
902 rates
|= rate_to_scan_rate_flag(band
->bitrates
[i
].hw_value
);
904 /* Set both basic rates and supported rates */
905 rates
|= SCAN_CONFIG_SUPPORTED_RATE(rates
);
907 return cpu_to_le32(rates
);
910 int iwl_mvm_config_scan(struct iwl_mvm
*mvm
)
913 struct iwl_scan_config
*scan_config
;
914 struct ieee80211_supported_band
*band
;
916 mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
+
917 mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
;
918 int ret
, i
, j
= 0, cmd_size
, data_size
;
919 struct iwl_host_cmd cmd
= {
923 if (WARN_ON(num_channels
> mvm
->fw
->ucode_capa
.n_scan_channels
))
926 cmd_size
= sizeof(*scan_config
) + mvm
->fw
->ucode_capa
.n_scan_channels
;
928 scan_config
= kzalloc(cmd_size
, GFP_KERNEL
);
932 data_size
= cmd_size
- sizeof(struct iwl_mvm_umac_cmd_hdr
);
933 scan_config
->hdr
.size
= cpu_to_le16(data_size
);
934 scan_config
->flags
= cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE
|
935 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS
|
936 SCAN_CONFIG_FLAG_SET_TX_CHAINS
|
937 SCAN_CONFIG_FLAG_SET_RX_CHAINS
|
938 SCAN_CONFIG_FLAG_SET_ALL_TIMES
|
939 SCAN_CONFIG_FLAG_SET_LEGACY_RATES
|
940 SCAN_CONFIG_FLAG_SET_MAC_ADDR
|
941 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS
|
942 SCAN_CONFIG_N_CHANNELS(num_channels
));
943 scan_config
->tx_chains
= cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm
));
944 scan_config
->rx_chains
= cpu_to_le32(iwl_mvm_scan_rx_ant(mvm
));
945 scan_config
->legacy_rates
= iwl_mvm_scan_config_rates(mvm
);
946 scan_config
->out_of_channel_time
= cpu_to_le32(170);
947 scan_config
->suspend_time
= cpu_to_le32(30);
948 scan_config
->dwell_active
= 20;
949 scan_config
->dwell_passive
= 110;
950 scan_config
->dwell_fragmented
= 20;
952 memcpy(&scan_config
->mac_addr
, &mvm
->addresses
[0].addr
, ETH_ALEN
);
954 scan_config
->bcast_sta_id
= mvm
->aux_sta
.sta_id
;
955 scan_config
->channel_flags
= IWL_CHANNEL_FLAG_EBS
|
956 IWL_CHANNEL_FLAG_ACCURATE_EBS
|
957 IWL_CHANNEL_FLAG_EBS_ADD
|
958 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE
;
960 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
961 for (i
= 0; i
< band
->n_channels
; i
++, j
++)
962 scan_config
->channel_array
[j
] = band
->channels
[i
].hw_value
;
963 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
964 for (i
= 0; i
< band
->n_channels
; i
++, j
++)
965 scan_config
->channel_array
[j
] = band
->channels
[i
].hw_value
;
967 cmd
.data
[0] = scan_config
;
968 cmd
.len
[0] = cmd_size
;
969 cmd
.dataflags
[0] = IWL_HCMD_DFL_NOCOPY
;
971 IWL_DEBUG_SCAN(mvm
, "Sending UMAC scan config\n");
973 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
979 static int iwl_mvm_scan_uid_by_status(struct iwl_mvm
*mvm
, int status
)
983 for (i
= 0; i
< mvm
->max_scans
; i
++)
984 if (mvm
->scan_uid_status
[i
] == status
)
990 static void iwl_mvm_scan_umac_dwell(struct iwl_mvm
*mvm
,
991 struct iwl_scan_req_umac
*cmd
,
992 struct iwl_mvm_scan_params
*params
)
994 cmd
->active_dwell
= params
->dwell
[IEEE80211_BAND_2GHZ
].active
;
995 cmd
->passive_dwell
= params
->dwell
[IEEE80211_BAND_2GHZ
].passive
;
996 if (params
->passive_fragmented
)
997 cmd
->fragmented_dwell
=
998 params
->dwell
[IEEE80211_BAND_2GHZ
].fragmented
;
999 cmd
->max_out_time
= cpu_to_le32(params
->max_out_time
);
1000 cmd
->suspend_time
= cpu_to_le32(params
->suspend_time
);
1001 cmd
->scan_priority
=
1002 iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_6
);
1004 if (iwl_mvm_scan_total_iterations(params
) == 0)
1006 iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_6
);
1009 iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_2
);
1013 iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm
*mvm
,
1014 struct ieee80211_channel
**channels
,
1015 int n_channels
, u32 ssid_bitmap
,
1016 struct iwl_scan_req_umac
*cmd
)
1018 struct iwl_scan_channel_cfg_umac
*channel_cfg
= (void *)&cmd
->data
;
1021 for (i
= 0; i
< n_channels
; i
++) {
1022 channel_cfg
[i
].flags
= cpu_to_le32(ssid_bitmap
);
1023 channel_cfg
[i
].channel_num
= channels
[i
]->hw_value
;
1024 channel_cfg
[i
].iter_count
= 1;
1025 channel_cfg
[i
].iter_interval
= 0;
1029 static u32
iwl_mvm_scan_umac_flags(struct iwl_mvm
*mvm
,
1030 struct iwl_mvm_scan_params
*params
)
1034 if (params
->n_ssids
== 0)
1035 flags
= IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE
;
1037 if (params
->n_ssids
== 1 && params
->ssids
[0].ssid_len
!= 0)
1038 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT
;
1040 if (params
->passive_fragmented
)
1041 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED
;
1043 if (iwl_mvm_rrm_scan_needed(mvm
))
1044 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED
;
1046 if (params
->pass_all
)
1047 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL
;
1049 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_MATCH
;
1051 if (iwl_mvm_scan_total_iterations(params
) > 1)
1052 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC
;
1054 #ifdef CONFIG_IWLWIFI_DEBUGFS
1055 if (mvm
->scan_iter_notif_enabled
)
1056 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE
;
1061 static int iwl_mvm_scan_umac(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1062 struct iwl_mvm_scan_params
*params
,
1065 struct iwl_scan_req_umac
*cmd
= mvm
->scan_cmd
;
1066 struct iwl_scan_req_umac_tail
*sec_part
= (void *)&cmd
->data
+
1067 sizeof(struct iwl_scan_channel_cfg_umac
) *
1068 mvm
->fw
->ucode_capa
.n_scan_channels
;
1070 u32 ssid_bitmap
= 0;
1071 int n_iterations
= iwl_mvm_scan_total_iterations(params
);
1073 lockdep_assert_held(&mvm
->mutex
);
1075 uid
= iwl_mvm_scan_uid_by_status(mvm
, 0);
1079 memset(cmd
, 0, ksize(cmd
));
1080 cmd
->hdr
.size
= cpu_to_le16(iwl_mvm_scan_size(mvm
) -
1081 sizeof(struct iwl_mvm_umac_cmd_hdr
));
1083 iwl_mvm_scan_umac_dwell(mvm
, cmd
, params
);
1085 mvm
->scan_uid_status
[uid
] = type
;
1087 cmd
->uid
= cpu_to_le32(uid
);
1088 cmd
->general_flags
= cpu_to_le32(iwl_mvm_scan_umac_flags(mvm
, params
));
1090 if (iwl_mvm_scan_use_ebs(mvm
, n_iterations
))
1091 cmd
->channel_flags
= IWL_SCAN_CHANNEL_FLAG_EBS
|
1092 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1093 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
;
1095 cmd
->n_channels
= params
->n_channels
;
1097 iwl_scan_build_ssids(params
, sec_part
->direct_scan
, &ssid_bitmap
);
1099 iwl_mvm_umac_scan_cfg_channels(mvm
, params
->channels
,
1100 params
->n_channels
, ssid_bitmap
, cmd
);
1102 /* With UMAC we use only one schedule for now, so use the sum
1103 * of the iterations (with a a maximum of 255).
1105 sec_part
->schedule
[0].iter_count
=
1106 (n_iterations
> 255) ? 255 : n_iterations
;
1107 sec_part
->schedule
[0].interval
= cpu_to_le16(params
->interval
);
1109 sec_part
->delay
= cpu_to_le16(params
->delay
);
1110 sec_part
->preq
= params
->preq
;
1115 static int iwl_mvm_num_scans(struct iwl_mvm
*mvm
)
1117 return hweight32(mvm
->scan_status
& IWL_MVM_SCAN_MASK
);
1120 static int iwl_mvm_check_running_scans(struct iwl_mvm
*mvm
, int type
)
1122 /* This looks a bit arbitrary, but the idea is that if we run
1123 * out of possible simultaneous scans and the userspace is
1124 * trying to run a scan type that is already running, we
1125 * return -EBUSY. But if the userspace wants to start a
1126 * different type of scan, we stop the opposite type to make
1127 * space for the new request. The reason is backwards
1128 * compatibility with old wpa_supplicant that wouldn't stop a
1129 * scheduled scan before starting a normal scan.
1132 if (iwl_mvm_num_scans(mvm
) < mvm
->max_scans
)
1135 /* Use a switch, even though this is a bitmask, so that more
1136 * than one bits set will fall in default and we will warn.
1139 case IWL_MVM_SCAN_REGULAR
:
1140 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR_MASK
)
1142 return iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
, true);
1143 case IWL_MVM_SCAN_SCHED
:
1144 if (mvm
->scan_status
& IWL_MVM_SCAN_SCHED_MASK
)
1146 iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_REGULAR
, true);
1147 case IWL_MVM_SCAN_NETDETECT
:
1148 /* No need to stop anything for net-detect since the
1149 * firmware is restarted anyway. This way, any sched
1150 * scans that were running will be restarted when we
1162 int iwl_mvm_reg_scan_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1163 struct cfg80211_scan_request
*req
,
1164 struct ieee80211_scan_ies
*ies
)
1166 struct iwl_host_cmd hcmd
= {
1167 .len
= { iwl_mvm_scan_size(mvm
), },
1168 .data
= { mvm
->scan_cmd
, },
1169 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
1171 struct iwl_mvm_scan_params params
= {};
1174 lockdep_assert_held(&mvm
->mutex
);
1176 if (iwl_mvm_is_lar_supported(mvm
) && !mvm
->lar_regdom_set
) {
1177 IWL_ERR(mvm
, "scan while LAR regdomain is not set\n");
1181 ret
= iwl_mvm_check_running_scans(mvm
, IWL_MVM_SCAN_REGULAR
);
1185 iwl_mvm_ref(mvm
, IWL_MVM_REF_SCAN
);
1187 /* we should have failed registration if scan_cmd was NULL */
1188 if (WARN_ON(!mvm
->scan_cmd
))
1191 if (!iwl_mvm_scan_fits(mvm
, req
->n_ssids
, ies
, req
->n_channels
))
1194 params
.n_ssids
= req
->n_ssids
;
1195 params
.flags
= req
->flags
;
1196 params
.n_channels
= req
->n_channels
;
1198 params
.interval
= 0;
1199 params
.ssids
= req
->ssids
;
1200 params
.channels
= req
->channels
;
1201 params
.mac_addr
= req
->mac_addr
;
1202 params
.mac_addr_mask
= req
->mac_addr_mask
;
1203 params
.no_cck
= req
->no_cck
;
1204 params
.pass_all
= true;
1205 params
.n_match_sets
= 0;
1206 params
.match_sets
= NULL
;
1208 params
.schedule
[0].iterations
= 1;
1209 params
.schedule
[0].full_scan_mul
= 0;
1210 params
.schedule
[1].iterations
= 0;
1211 params
.schedule
[1].full_scan_mul
= 0;
1213 iwl_mvm_scan_calc_dwell(mvm
, vif
, ¶ms
);
1215 iwl_mvm_build_scan_probe(mvm
, vif
, ies
, ¶ms
);
1217 if (mvm
->fw
->ucode_capa
.capa
[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN
) {
1218 hcmd
.id
= SCAN_REQ_UMAC
;
1219 ret
= iwl_mvm_scan_umac(mvm
, vif
, ¶ms
,
1220 IWL_MVM_SCAN_REGULAR
);
1222 hcmd
.id
= SCAN_OFFLOAD_REQUEST_CMD
;
1223 ret
= iwl_mvm_scan_lmac(mvm
, vif
, ¶ms
);
1229 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1231 IWL_DEBUG_SCAN(mvm
, "Scan request was sent successfully\n");
1232 mvm
->scan_status
|= IWL_MVM_SCAN_REGULAR
;
1234 /* If the scan failed, it usually means that the FW was unable
1235 * to allocate the time events. Warn on it, but maybe we
1236 * should try to send the command again with different params.
1238 IWL_ERR(mvm
, "Scan failed! ret %d\n", ret
);
1242 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1247 int iwl_mvm_sched_scan_start(struct iwl_mvm
*mvm
,
1248 struct ieee80211_vif
*vif
,
1249 struct cfg80211_sched_scan_request
*req
,
1250 struct ieee80211_scan_ies
*ies
,
1253 struct iwl_host_cmd hcmd
= {
1254 .len
= { iwl_mvm_scan_size(mvm
), },
1255 .data
= { mvm
->scan_cmd
, },
1256 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
1258 struct iwl_mvm_scan_params params
= {};
1261 lockdep_assert_held(&mvm
->mutex
);
1263 if (iwl_mvm_is_lar_supported(mvm
) && !mvm
->lar_regdom_set
) {
1264 IWL_ERR(mvm
, "sched-scan while LAR regdomain is not set\n");
1268 ret
= iwl_mvm_check_running_scans(mvm
, type
);
1272 /* we should have failed registration if scan_cmd was NULL */
1273 if (WARN_ON(!mvm
->scan_cmd
))
1276 if (!iwl_mvm_scan_fits(mvm
, req
->n_ssids
, ies
, req
->n_channels
))
1279 params
.n_ssids
= req
->n_ssids
;
1280 params
.flags
= req
->flags
;
1281 params
.n_channels
= req
->n_channels
;
1282 params
.ssids
= req
->ssids
;
1283 params
.channels
= req
->channels
;
1284 params
.mac_addr
= req
->mac_addr
;
1285 params
.mac_addr_mask
= req
->mac_addr_mask
;
1286 params
.no_cck
= false;
1287 params
.pass_all
= iwl_mvm_scan_pass_all(mvm
, req
);
1288 params
.n_match_sets
= req
->n_match_sets
;
1289 params
.match_sets
= req
->match_sets
;
1291 params
.schedule
[0].iterations
= IWL_FAST_SCHED_SCAN_ITERATIONS
;
1292 params
.schedule
[0].full_scan_mul
= 1;
1293 params
.schedule
[1].iterations
= 0xff;
1294 params
.schedule
[1].full_scan_mul
= IWL_FULL_SCAN_MULTIPLIER
;
1296 if (req
->interval
> U16_MAX
) {
1298 "interval value is > 16-bits, set to max possible\n");
1299 params
.interval
= U16_MAX
;
1301 params
.interval
= req
->interval
/ MSEC_PER_SEC
;
1304 /* In theory, LMAC scans can handle a 32-bit delay, but since
1305 * waiting for over 18 hours to start the scan is a bit silly
1306 * and to keep it aligned with UMAC scans (which only support
1307 * 16-bit delays), trim it down to 16-bits.
1309 if (req
->delay
> U16_MAX
) {
1311 "delay value is > 16-bits, set to max possible\n");
1312 params
.delay
= U16_MAX
;
1314 params
.delay
= req
->delay
;
1317 iwl_mvm_scan_calc_dwell(mvm
, vif
, ¶ms
);
1319 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
1323 iwl_mvm_build_scan_probe(mvm
, vif
, ies
, ¶ms
);
1325 if (mvm
->fw
->ucode_capa
.capa
[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN
) {
1326 hcmd
.id
= SCAN_REQ_UMAC
;
1327 ret
= iwl_mvm_scan_umac(mvm
, vif
, ¶ms
, IWL_MVM_SCAN_SCHED
);
1329 hcmd
.id
= SCAN_OFFLOAD_REQUEST_CMD
;
1330 ret
= iwl_mvm_scan_lmac(mvm
, vif
, ¶ms
);
1336 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1339 "Sched scan request was sent successfully\n");
1340 mvm
->scan_status
|= type
;
1342 /* If the scan failed, it usually means that the FW was unable
1343 * to allocate the time events. Warn on it, but maybe we
1344 * should try to send the command again with different params.
1346 IWL_ERR(mvm
, "Sched scan failed! ret %d\n", ret
);
1352 int iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm
*mvm
,
1353 struct iwl_rx_cmd_buffer
*rxb
,
1354 struct iwl_device_cmd
*cmd
)
1356 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1357 struct iwl_umac_scan_complete
*notif
= (void *)pkt
->data
;
1358 u32 uid
= __le32_to_cpu(notif
->uid
);
1359 bool sched
= (mvm
->scan_uid_status
[uid
] == IWL_MVM_SCAN_SCHED
);
1361 /* the status may be already zero in case of scan abort from above */
1362 if (mvm
->scan_uid_status
[uid
] == 0)
1366 "Scan completed, uid %u type %s, status %s, EBS status %s\n",
1367 uid
, sched
? "sched" : "regular",
1368 notif
->status
== IWL_SCAN_OFFLOAD_COMPLETED
?
1369 "completed" : "aborted",
1370 notif
->ebs_status
== IWL_SCAN_EBS_SUCCESS
?
1371 "success" : "failed");
1373 if (notif
->ebs_status
)
1374 mvm
->last_ebs_successful
= false;
1376 mvm
->scan_uid_status
[uid
] = 0;
1379 ieee80211_scan_completed(mvm
->hw
,
1381 IWL_SCAN_OFFLOAD_ABORTED
);
1382 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1383 } else if (iwl_mvm_scan_uid_by_status(mvm
, IWL_MVM_SCAN_SCHED
) < 0) {
1384 ieee80211_sched_scan_stopped(mvm
->hw
);
1386 IWL_DEBUG_SCAN(mvm
, "Another sched scan is running\n");
1392 int iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm
*mvm
,
1393 struct iwl_rx_cmd_buffer
*rxb
,
1394 struct iwl_device_cmd
*cmd
)
1396 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1397 struct iwl_umac_scan_iter_complete_notif
*notif
= (void *)pkt
->data
;
1401 "UMAC Scan iteration complete: status=0x%x scanned_channels=%d channels list: %s\n",
1402 notif
->status
, notif
->scanned_channels
,
1403 iwl_mvm_dump_channel_list(notif
->results
,
1404 notif
->scanned_channels
, buf
,
1409 static int iwl_mvm_umac_scan_abort(struct iwl_mvm
*mvm
, int type
)
1411 struct iwl_umac_scan_abort cmd
= {
1412 .hdr
.size
= cpu_to_le16(sizeof(struct iwl_umac_scan_abort
) -
1413 sizeof(struct iwl_mvm_umac_cmd_hdr
)),
1417 lockdep_assert_held(&mvm
->mutex
);
1419 /* We should always get a valid index here, because we already
1420 * checked that this type of scan was running in the generic
1423 uid
= iwl_mvm_scan_uid_by_status(mvm
, type
);
1424 if (WARN_ON_ONCE(uid
< 0))
1427 cmd
.uid
= cpu_to_le32(uid
);
1429 IWL_DEBUG_SCAN(mvm
, "Sending scan abort, uid %u\n", uid
);
1431 ret
= iwl_mvm_send_cmd_pdu(mvm
, SCAN_ABORT_UMAC
, 0, sizeof(cmd
), &cmd
);
1433 mvm
->scan_uid_status
[uid
] = 0;
1438 static int iwl_mvm_scan_stop_wait(struct iwl_mvm
*mvm
, int type
)
1440 struct iwl_notification_wait wait_scan_done
;
1441 static const u8 scan_done_notif
[] = { SCAN_COMPLETE_UMAC
,
1442 SCAN_OFFLOAD_COMPLETE
, };
1445 lockdep_assert_held(&mvm
->mutex
);
1447 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_done
,
1449 ARRAY_SIZE(scan_done_notif
),
1452 IWL_DEBUG_SCAN(mvm
, "Preparing to stop scan, type %x\n", type
);
1454 if (mvm
->fw
->ucode_capa
.capa
[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN
)
1455 ret
= iwl_mvm_umac_scan_abort(mvm
, type
);
1457 ret
= iwl_mvm_lmac_scan_abort(mvm
);
1460 IWL_DEBUG_SCAN(mvm
, "couldn't stop scan type %d\n", type
);
1461 iwl_remove_notification(&mvm
->notif_wait
, &wait_scan_done
);
1465 ret
= iwl_wait_notification(&mvm
->notif_wait
, &wait_scan_done
, 1 * HZ
);
1470 int iwl_mvm_scan_size(struct iwl_mvm
*mvm
)
1472 if (mvm
->fw
->ucode_capa
.capa
[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN
)
1473 return sizeof(struct iwl_scan_req_umac
) +
1474 sizeof(struct iwl_scan_channel_cfg_umac
) *
1475 mvm
->fw
->ucode_capa
.n_scan_channels
+
1476 sizeof(struct iwl_scan_req_umac_tail
);
1478 return sizeof(struct iwl_scan_req_lmac
) +
1479 sizeof(struct iwl_scan_channel_cfg_lmac
) *
1480 mvm
->fw
->ucode_capa
.n_scan_channels
+
1481 sizeof(struct iwl_scan_probe_req
);
1485 * This function is used in nic restart flow, to inform mac80211 about scans
1486 * that was aborted by restart flow or by an assert.
1488 void iwl_mvm_report_scan_aborted(struct iwl_mvm
*mvm
)
1490 if (mvm
->fw
->ucode_capa
.capa
[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN
) {
1493 uid
= iwl_mvm_scan_uid_by_status(mvm
, IWL_MVM_SCAN_REGULAR
);
1495 ieee80211_scan_completed(mvm
->hw
, true);
1496 mvm
->scan_uid_status
[uid
] = 0;
1498 uid
= iwl_mvm_scan_uid_by_status(mvm
, IWL_MVM_SCAN_SCHED
);
1499 if (uid
>= 0 && !mvm
->restart_fw
) {
1500 ieee80211_sched_scan_stopped(mvm
->hw
);
1501 mvm
->scan_uid_status
[uid
] = 0;
1504 /* We shouldn't have any UIDs still set. Loop over all the
1505 * UIDs to make sure there's nothing left there and warn if
1508 for (i
= 0; i
< mvm
->max_scans
; i
++) {
1509 if (WARN_ONCE(mvm
->scan_uid_status
[i
],
1510 "UMAC scan UID %d status was not cleaned\n",
1512 mvm
->scan_uid_status
[i
] = 0;
1515 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
)
1516 ieee80211_scan_completed(mvm
->hw
, true);
1518 /* Sched scan will be restarted by mac80211 in
1519 * restart_hw, so do not report if FW is about to be
1522 if ((mvm
->scan_status
& IWL_MVM_SCAN_SCHED
) && !mvm
->restart_fw
)
1523 ieee80211_sched_scan_stopped(mvm
->hw
);
1527 int iwl_mvm_scan_stop(struct iwl_mvm
*mvm
, int type
, bool notify
)
1531 if (!(mvm
->scan_status
& type
))
1534 if (iwl_mvm_is_radio_killed(mvm
)) {
1539 ret
= iwl_mvm_scan_stop_wait(mvm
, type
);
1541 mvm
->scan_status
|= type
<< IWL_MVM_SCAN_STOPPING_SHIFT
;
1543 /* Clear the scan status so the next scan requests will
1544 * succeed and mark the scan as stopping, so that the Rx
1545 * handler doesn't do anything, as the scan was stopped from
1548 mvm
->scan_status
&= ~type
;
1550 if (type
== IWL_MVM_SCAN_REGULAR
) {
1551 /* Since the rx handler won't do anything now, we have
1552 * to release the scan reference here.
1554 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1556 ieee80211_scan_completed(mvm
->hw
, true);
1557 } else if (notify
) {
1558 ieee80211_sched_scan_stopped(mvm
->hw
);