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