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