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