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