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