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