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. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 26 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 27 | * |
| 28 | * Contact Information: |
| 29 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 34 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 42 | * * Redistributions of source code must retain the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer. |
| 44 | * * Redistributions in binary form must reproduce the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer in |
| 46 | * the documentation and/or other materials provided with the |
| 47 | * distribution. |
| 48 | * * Neither the name Intel Corporation nor the names of its |
| 49 | * contributors may be used to endorse or promote products derived |
| 50 | * from this software without specific prior written permission. |
| 51 | * |
| 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 53 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 54 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 55 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 56 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 57 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 58 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 63 | * |
| 64 | *****************************************************************************/ |
| 65 | |
| 66 | #include <linux/etherdevice.h> |
| 67 | #include <net/mac80211.h> |
| 68 | |
| 69 | #include "mvm.h" |
| 70 | #include "iwl-eeprom-parse.h" |
| 71 | #include "fw-api-scan.h" |
| 72 | |
| 73 | #define IWL_PLCP_QUIET_THRESH 1 |
| 74 | #define IWL_ACTIVE_QUIET_TIME 10 |
Haim Dreyfuss | a1ed402 | 2014-12-01 23:30:07 +0200 | [diff] [blame] | 75 | #define IWL_DENSE_EBS_SCAN_RATIO 5 |
| 76 | #define IWL_SPARSE_EBS_SCAN_RATIO 1 |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 77 | |
| 78 | struct iwl_mvm_scan_params { |
| 79 | u32 max_out_time; |
| 80 | u32 suspend_time; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 81 | bool passive_fragmented; |
| 82 | struct _dwell { |
| 83 | u16 passive; |
| 84 | u16 active; |
| 85 | } dwell[IEEE80211_NUM_BANDS]; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 86 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 87 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 88 | enum iwl_umac_scan_uid_type { |
| 89 | IWL_UMAC_SCAN_UID_REG_SCAN = BIT(0), |
| 90 | IWL_UMAC_SCAN_UID_SCHED_SCAN = BIT(1), |
| 91 | IWL_UMAC_SCAN_UID_ALL = IWL_UMAC_SCAN_UID_REG_SCAN | |
| 92 | IWL_UMAC_SCAN_UID_SCHED_SCAN, |
| 93 | }; |
| 94 | |
| 95 | static int iwl_umac_scan_stop(struct iwl_mvm *mvm, |
| 96 | enum iwl_umac_scan_uid_type type, bool notify); |
| 97 | |
| 98 | static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm) |
| 99 | { |
| 100 | if (mvm->scan_rx_ant != ANT_NONE) |
| 101 | return mvm->scan_rx_ant; |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 102 | return iwl_mvm_get_valid_rx_ant(mvm); |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 103 | } |
| 104 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 105 | static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm) |
| 106 | { |
| 107 | u16 rx_chain; |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 108 | u8 rx_ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 109 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 110 | rx_ant = iwl_mvm_scan_rx_ant(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 111 | rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS; |
| 112 | rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS; |
| 113 | rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS; |
| 114 | rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS; |
| 115 | return cpu_to_le16(rx_chain); |
| 116 | } |
| 117 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 118 | static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 119 | { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 120 | if (band == IEEE80211_BAND_2GHZ) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 121 | return cpu_to_le32(PHY_BAND_24); |
| 122 | else |
| 123 | return cpu_to_le32(PHY_BAND_5); |
| 124 | } |
| 125 | |
| 126 | static inline __le32 |
| 127 | iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band, |
| 128 | bool no_cck) |
| 129 | { |
| 130 | u32 tx_ant; |
| 131 | |
| 132 | mvm->scan_last_antenna_idx = |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 133 | iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 134 | mvm->scan_last_antenna_idx); |
| 135 | tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS; |
| 136 | |
| 137 | if (band == IEEE80211_BAND_2GHZ && !no_cck) |
| 138 | return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK | |
| 139 | tx_ant); |
| 140 | else |
| 141 | return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant); |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * We insert the SSIDs in an inverted order, because the FW will |
| 146 | * invert it back. The most prioritized SSID, which is first in the |
| 147 | * request list, is not copied here, but inserted directly to the probe |
| 148 | * request. |
| 149 | */ |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 150 | static void iwl_mvm_scan_fill_ssids(struct iwl_ssid_ie *cmd_ssid, |
| 151 | struct cfg80211_ssid *ssids, |
| 152 | int n_ssids, int first) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 153 | { |
| 154 | int fw_idx, req_idx; |
| 155 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 156 | for (req_idx = n_ssids - 1, fw_idx = 0; req_idx >= first; |
David Spinadel | fe04e83 | 2013-07-04 15:17:48 +0300 | [diff] [blame] | 157 | req_idx--, fw_idx++) { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 158 | cmd_ssid[fw_idx].id = WLAN_EID_SSID; |
| 159 | cmd_ssid[fw_idx].len = ssids[req_idx].ssid_len; |
| 160 | memcpy(cmd_ssid[fw_idx].ssid, |
| 161 | ssids[req_idx].ssid, |
| 162 | ssids[req_idx].ssid_len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * If req->n_ssids > 0, it means we should do an active scan. |
| 168 | * In case of active scan w/o directed scan, we receive a zero-length SSID |
| 169 | * just to notify that this scan is active and not passive. |
| 170 | * In order to notify the FW of the number of SSIDs we wish to scan (including |
| 171 | * the zero-length one), we need to set the corresponding bits in chan->type, |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 172 | * one for each SSID, and set the active bit (first). If the first SSID is |
| 173 | * already included in the probe template, so we need to set only |
| 174 | * req->n_ssids - 1 bits in addition to the first bit. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 175 | */ |
David Spinadel | 3cae073 | 2014-12-29 15:43:48 +0200 | [diff] [blame] | 176 | static u16 iwl_mvm_get_active_dwell(struct iwl_mvm *mvm, |
| 177 | enum ieee80211_band band, int n_ssids) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 178 | { |
David Spinadel | 3cae073 | 2014-12-29 15:43:48 +0200 | [diff] [blame] | 179 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL) |
| 180 | return 10; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 181 | if (band == IEEE80211_BAND_2GHZ) |
David Spinadel | 3974533 | 2014-09-10 16:40:41 +0300 | [diff] [blame] | 182 | return 20 + 3 * (n_ssids + 1); |
| 183 | return 10 + 2 * (n_ssids + 1); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 184 | } |
| 185 | |
David Spinadel | 3cae073 | 2014-12-29 15:43:48 +0200 | [diff] [blame] | 186 | static u16 iwl_mvm_get_passive_dwell(struct iwl_mvm *mvm, |
| 187 | enum ieee80211_band band) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 188 | { |
David Spinadel | 3cae073 | 2014-12-29 15:43:48 +0200 | [diff] [blame] | 189 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL) |
| 190 | return 110; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 191 | return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10; |
| 192 | } |
| 193 | |
| 194 | static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd, |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 195 | struct cfg80211_scan_request *req, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 196 | bool basic_ssid, |
| 197 | struct iwl_mvm_scan_params *params) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 198 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 199 | struct iwl_scan_channel *chan = (struct iwl_scan_channel *) |
| 200 | (cmd->data + le16_to_cpu(cmd->tx_cmd.len)); |
| 201 | int i; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 202 | int type = BIT(req->n_ssids) - 1; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 203 | enum ieee80211_band band = req->channels[0]->band; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 204 | |
| 205 | if (!basic_ssid) |
| 206 | type |= BIT(req->n_ssids); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 207 | |
| 208 | for (i = 0; i < cmd->channel_count; i++) { |
| 209 | chan->channel = cpu_to_le16(req->channels[i]->hw_value); |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 210 | chan->type = cpu_to_le32(type); |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 211 | if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR) |
David Spinadel | bb963c4 | 2013-07-23 14:13:32 +0300 | [diff] [blame] | 212 | chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 213 | chan->active_dwell = cpu_to_le16(params->dwell[band].active); |
| 214 | chan->passive_dwell = cpu_to_le16(params->dwell[band].passive); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 215 | chan->iteration_count = cpu_to_le16(1); |
| 216 | chan++; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Fill in probe request with the following parameters: |
| 222 | * TA is our vif HW address, which mac80211 ensures we have. |
| 223 | * Packet is broadcasted, so this is both SA and DA. |
| 224 | * The probe request IE is made out of two: first comes the most prioritized |
| 225 | * SSID if a directed scan is requested. Second comes whatever extra |
| 226 | * information was given to us as the scan request IE. |
| 227 | */ |
| 228 | static u16 iwl_mvm_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta, |
| 229 | int n_ssids, const u8 *ssid, int ssid_len, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 230 | const u8 *band_ie, int band_ie_len, |
| 231 | const u8 *common_ie, int common_ie_len, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 232 | int left) |
| 233 | { |
| 234 | int len = 0; |
| 235 | u8 *pos = NULL; |
| 236 | |
| 237 | /* Make sure there is enough space for the probe request, |
| 238 | * two mandatory IEs and the data */ |
| 239 | left -= 24; |
| 240 | if (left < 0) |
| 241 | return 0; |
| 242 | |
| 243 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
| 244 | eth_broadcast_addr(frame->da); |
| 245 | memcpy(frame->sa, ta, ETH_ALEN); |
| 246 | eth_broadcast_addr(frame->bssid); |
| 247 | frame->seq_ctrl = 0; |
| 248 | |
| 249 | len += 24; |
| 250 | |
| 251 | /* for passive scans, no need to fill anything */ |
| 252 | if (n_ssids == 0) |
| 253 | return (u16)len; |
| 254 | |
| 255 | /* points to the payload of the request */ |
| 256 | pos = &frame->u.probe_req.variable[0]; |
| 257 | |
| 258 | /* fill in our SSID IE */ |
| 259 | left -= ssid_len + 2; |
| 260 | if (left < 0) |
| 261 | return 0; |
| 262 | *pos++ = WLAN_EID_SSID; |
| 263 | *pos++ = ssid_len; |
| 264 | if (ssid && ssid_len) { /* ssid_len may be == 0 even if ssid is valid */ |
| 265 | memcpy(pos, ssid, ssid_len); |
| 266 | pos += ssid_len; |
| 267 | } |
| 268 | |
| 269 | len += ssid_len + 2; |
| 270 | |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 271 | if (WARN_ON(left < band_ie_len + common_ie_len)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 272 | return len; |
| 273 | |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 274 | if (band_ie && band_ie_len) { |
| 275 | memcpy(pos, band_ie, band_ie_len); |
| 276 | pos += band_ie_len; |
| 277 | len += band_ie_len; |
| 278 | } |
| 279 | |
| 280 | if (common_ie && common_ie_len) { |
| 281 | memcpy(pos, common_ie, common_ie_len); |
| 282 | pos += common_ie_len; |
| 283 | len += common_ie_len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | return (u16)len; |
| 287 | } |
| 288 | |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 289 | static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac, |
| 290 | struct ieee80211_vif *vif) |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 291 | { |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 292 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Haim Dreyfuss | c3f8d0a | 2014-12-02 11:03:16 +0200 | [diff] [blame] | 293 | int *global_cnt = data; |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 294 | |
David Spinadel | 1e2ebe0 | 2014-10-26 15:53:27 +0200 | [diff] [blame] | 295 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt && |
| 296 | mvmvif->phy_ctxt->id < MAX_PHYS) |
Haim Dreyfuss | c3f8d0a | 2014-12-02 11:03:16 +0200 | [diff] [blame] | 297 | *global_cnt += 1; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 301 | struct ieee80211_vif *vif, |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 302 | int n_ssids, u32 flags, |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 303 | struct iwl_mvm_scan_params *params) |
| 304 | { |
Haim Dreyfuss | c3f8d0a | 2014-12-02 11:03:16 +0200 | [diff] [blame] | 305 | int global_cnt = 0; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 306 | enum ieee80211_band band; |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 307 | u8 frag_passive_dwell = 0; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 308 | |
| 309 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
| 310 | IEEE80211_IFACE_ITER_NORMAL, |
| 311 | iwl_mvm_scan_condition_iterator, |
Haim Dreyfuss | c3f8d0a | 2014-12-02 11:03:16 +0200 | [diff] [blame] | 312 | &global_cnt); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 313 | |
Haim Dreyfuss | c3f8d0a | 2014-12-02 11:03:16 +0200 | [diff] [blame] | 314 | if (!global_cnt) |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 315 | goto not_bound; |
| 316 | |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 317 | params->suspend_time = 30; |
Haim Dreyfuss | 44e9cd7 | 2014-12-18 12:34:01 +0200 | [diff] [blame] | 318 | params->max_out_time = 120; |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 319 | |
| 320 | if (iwl_mvm_low_latency(mvm)) { |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 321 | if (mvm->fw->ucode_capa.api[0] & |
| 322 | IWL_UCODE_TLV_API_FRAGMENTED_SCAN) { |
| 323 | params->suspend_time = 105; |
Haim Dreyfuss | c3f8d0a | 2014-12-02 11:03:16 +0200 | [diff] [blame] | 324 | /* |
| 325 | * If there is more than one active interface make |
| 326 | * passive scan more fragmented. |
| 327 | */ |
| 328 | frag_passive_dwell = (global_cnt < 2) ? 40 : 20; |
Haim Dreyfuss | 44e9cd7 | 2014-12-18 12:34:01 +0200 | [diff] [blame] | 329 | params->max_out_time = frag_passive_dwell; |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 330 | } else { |
| 331 | params->suspend_time = 120; |
| 332 | params->max_out_time = 120; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if (frag_passive_dwell && (mvm->fw->ucode_capa.api[0] & |
| 337 | IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) { |
| 338 | /* |
| 339 | * P2P device scan should not be fragmented to avoid negative |
| 340 | * impact on P2P device discovery. Configure max_out_time to be |
| 341 | * equal to dwell time on passive channel. Take a longest |
| 342 | * possible value, one that corresponds to 2GHz band |
| 343 | */ |
| 344 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 345 | u32 passive_dwell = |
David Spinadel | 3cae073 | 2014-12-29 15:43:48 +0200 | [diff] [blame] | 346 | iwl_mvm_get_passive_dwell(mvm, |
| 347 | IEEE80211_BAND_2GHZ); |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 348 | params->max_out_time = passive_dwell; |
| 349 | } else { |
| 350 | params->passive_fragmented = true; |
| 351 | } |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 352 | } |
| 353 | |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 354 | if (flags & NL80211_SCAN_FLAG_LOW_PRIORITY) |
| 355 | params->max_out_time = 200; |
| 356 | |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 357 | not_bound: |
| 358 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 359 | for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) { |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 360 | if (params->passive_fragmented) |
| 361 | params->dwell[band].passive = frag_passive_dwell; |
| 362 | else |
| 363 | params->dwell[band].passive = |
David Spinadel | 3cae073 | 2014-12-29 15:43:48 +0200 | [diff] [blame] | 364 | iwl_mvm_get_passive_dwell(mvm, band); |
| 365 | params->dwell[band].active = iwl_mvm_get_active_dwell(mvm, band, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 366 | n_ssids); |
| 367 | } |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 370 | static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm) |
| 371 | { |
| 372 | /* require rrm scan whenever the fw supports it */ |
| 373 | return mvm->fw->ucode_capa.capa[0] & |
| 374 | IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT; |
| 375 | } |
| 376 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 377 | static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm, |
| 378 | bool is_sched_scan) |
| 379 | { |
| 380 | int max_probe_len; |
| 381 | |
| 382 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) |
| 383 | max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE; |
| 384 | else |
| 385 | max_probe_len = mvm->fw->ucode_capa.max_probe_length; |
| 386 | |
| 387 | /* we create the 802.11 header and SSID element */ |
| 388 | max_probe_len -= 24 + 2; |
| 389 | |
| 390 | /* basic ssid is added only for hw_scan with and old api */ |
| 391 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID) && |
| 392 | !(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) && |
| 393 | !is_sched_scan) |
| 394 | max_probe_len -= 32; |
| 395 | |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 396 | /* DS parameter set element is added on 2.4GHZ band if required */ |
| 397 | if (iwl_mvm_rrm_scan_needed(mvm)) |
| 398 | max_probe_len -= 3; |
| 399 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 400 | return max_probe_len; |
| 401 | } |
| 402 | |
| 403 | int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm, bool is_sched_scan) |
| 404 | { |
| 405 | int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm, is_sched_scan); |
| 406 | |
| 407 | if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) |
| 408 | return max_ie_len; |
| 409 | |
| 410 | /* TODO: [BUG] This function should return the maximum allowed size of |
| 411 | * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs |
| 412 | * in the same command. So the correct implementation of this function |
| 413 | * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan |
| 414 | * command has only 512 bytes and it would leave us with about 240 |
| 415 | * bytes for scan IEs, which is clearly not enough. So meanwhile |
| 416 | * we will report an incorrect value. This may result in a failure to |
| 417 | * issue a scan in unified_scan_lmac and unified_sched_scan_lmac |
| 418 | * functions with -ENOBUFS, if a large enough probe will be provided. |
| 419 | */ |
| 420 | return max_ie_len; |
| 421 | } |
| 422 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 423 | int iwl_mvm_scan_request(struct iwl_mvm *mvm, |
| 424 | struct ieee80211_vif *vif, |
| 425 | struct cfg80211_scan_request *req) |
| 426 | { |
| 427 | struct iwl_host_cmd hcmd = { |
| 428 | .id = SCAN_REQUEST_CMD, |
| 429 | .len = { 0, }, |
| 430 | .data = { mvm->scan_cmd, }, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 431 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 432 | }; |
| 433 | struct iwl_scan_cmd *cmd = mvm->scan_cmd; |
| 434 | int ret; |
| 435 | u32 status; |
| 436 | int ssid_len = 0; |
| 437 | u8 *ssid = NULL; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 438 | bool basic_ssid = !(mvm->fw->ucode_capa.flags & |
| 439 | IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 440 | struct iwl_mvm_scan_params params = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 441 | |
| 442 | lockdep_assert_held(&mvm->mutex); |
Emmanuel Grumbach | 748fa67c | 2014-03-27 10:06:29 +0200 | [diff] [blame] | 443 | |
| 444 | /* we should have failed registration if scan_cmd was NULL */ |
| 445 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 446 | return -ENOMEM; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 447 | |
| 448 | IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n"); |
| 449 | mvm->scan_status = IWL_MVM_SCAN_OS; |
David Spinadel | 0564679 | 2014-06-02 09:59:49 +0300 | [diff] [blame] | 450 | memset(cmd, 0, ksize(cmd)); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 451 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 452 | cmd->channel_count = (u8)req->n_channels; |
| 453 | cmd->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME); |
| 454 | cmd->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH); |
| 455 | cmd->rxchain_sel_flags = iwl_mvm_scan_rx_chain(mvm); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 456 | |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 457 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags, ¶ms); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 458 | cmd->max_out_time = cpu_to_le32(params.max_out_time); |
| 459 | cmd->suspend_time = cpu_to_le32(params.suspend_time); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 460 | if (params.passive_fragmented) |
| 461 | cmd->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 462 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 463 | cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 464 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 465 | MAC_FILTER_IN_BEACON); |
Ilan Peer | d91b06d | 2013-02-11 08:50:45 +0200 | [diff] [blame] | 466 | |
| 467 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
| 468 | cmd->type = cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED); |
| 469 | else |
| 470 | cmd->type = cpu_to_le32(SCAN_TYPE_FORCED); |
| 471 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 472 | cmd->repeats = cpu_to_le32(1); |
| 473 | |
| 474 | /* |
| 475 | * If the user asked for passive scan, don't change to active scan if |
| 476 | * you see any activity on the channel - remain passive. |
| 477 | */ |
| 478 | if (req->n_ssids > 0) { |
| 479 | cmd->passive2active = cpu_to_le16(1); |
David Spinadel | 26e05cc | 2013-07-08 13:12:29 +0300 | [diff] [blame] | 480 | cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 481 | if (basic_ssid) { |
| 482 | ssid = req->ssids[0].ssid; |
| 483 | ssid_len = req->ssids[0].ssid_len; |
| 484 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 485 | } else { |
| 486 | cmd->passive2active = 0; |
David Spinadel | 26e05cc | 2013-07-08 13:12:29 +0300 | [diff] [blame] | 487 | cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 488 | } |
| 489 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 490 | iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->ssids, req->n_ssids, |
| 491 | basic_ssid ? 1 : 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 492 | |
Emmanuel Grumbach | 8e2a866 | 2014-01-28 12:27:31 +0200 | [diff] [blame] | 493 | cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL | |
Emmanuel Grumbach | 3856b78 | 2014-09-22 12:03:41 +0300 | [diff] [blame] | 494 | 3 << TX_CMD_FLG_BT_PRIO_POS); |
| 495 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 496 | cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id; |
| 497 | cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
| 498 | cmd->tx_cmd.rate_n_flags = |
| 499 | iwl_mvm_scan_rate_n_flags(mvm, req->channels[0]->band, |
| 500 | req->no_cck); |
| 501 | |
| 502 | cmd->tx_cmd.len = |
| 503 | cpu_to_le16(iwl_mvm_fill_probe_req( |
| 504 | (struct ieee80211_mgmt *)cmd->data, |
| 505 | vif->addr, |
| 506 | req->n_ssids, ssid, ssid_len, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 507 | req->ie, req->ie_len, NULL, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 508 | mvm->fw->ucode_capa.max_probe_length)); |
| 509 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 510 | iwl_mvm_scan_fill_channels(cmd, req, basic_ssid, ¶ms); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 511 | |
| 512 | cmd->len = cpu_to_le16(sizeof(struct iwl_scan_cmd) + |
| 513 | le16_to_cpu(cmd->tx_cmd.len) + |
| 514 | (cmd->channel_count * sizeof(struct iwl_scan_channel))); |
| 515 | hcmd.len[0] = le16_to_cpu(cmd->len); |
| 516 | |
| 517 | status = SCAN_RESPONSE_OK; |
| 518 | ret = iwl_mvm_send_cmd_status(mvm, &hcmd, &status); |
| 519 | if (!ret && status == SCAN_RESPONSE_OK) { |
| 520 | IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n"); |
| 521 | } else { |
| 522 | /* |
| 523 | * If the scan failed, it usually means that the FW was unable |
| 524 | * to allocate the time events. Warn on it, but maybe we |
| 525 | * should try to send the command again with different params. |
| 526 | */ |
| 527 | IWL_ERR(mvm, "Scan failed! status 0x%x ret %d\n", |
| 528 | status, ret); |
| 529 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 530 | ret = -EIO; |
| 531 | } |
| 532 | return ret; |
| 533 | } |
| 534 | |
| 535 | int iwl_mvm_rx_scan_response(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, |
| 536 | struct iwl_device_cmd *cmd) |
| 537 | { |
| 538 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 539 | struct iwl_cmd_response *resp = (void *)pkt->data; |
| 540 | |
| 541 | IWL_DEBUG_SCAN(mvm, "Scan response received. status 0x%x\n", |
| 542 | le32_to_cpu(resp->status)); |
| 543 | return 0; |
| 544 | } |
| 545 | |
Alexander Bondar | e5d7464 | 2014-12-09 19:15:49 +0200 | [diff] [blame] | 546 | int iwl_mvm_rx_scan_offload_iter_complete_notif(struct iwl_mvm *mvm, |
| 547 | struct iwl_rx_cmd_buffer *rxb, |
| 548 | struct iwl_device_cmd *cmd) |
| 549 | { |
| 550 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 551 | struct iwl_scan_complete_notif *notif = (void *)pkt->data; |
| 552 | |
| 553 | IWL_DEBUG_SCAN(mvm, |
| 554 | "Scan offload iteration complete: status=0x%x scanned channels=%d\n", |
| 555 | notif->status, notif->scanned_channels); |
| 556 | return 0; |
| 557 | } |
| 558 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 559 | int iwl_mvm_rx_scan_complete(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, |
| 560 | struct iwl_device_cmd *cmd) |
| 561 | { |
| 562 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 563 | struct iwl_scan_complete_notif *notif = (void *)pkt->data; |
| 564 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 565 | lockdep_assert_held(&mvm->mutex); |
| 566 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 567 | IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n", |
| 568 | notif->status, notif->scanned_channels); |
| 569 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 570 | if (mvm->scan_status == IWL_MVM_SCAN_OS) |
| 571 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 572 | ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK); |
| 573 | |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 574 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 575 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 579 | int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm, |
| 580 | struct iwl_rx_cmd_buffer *rxb, |
| 581 | struct iwl_device_cmd *cmd) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 582 | { |
| 583 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 584 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 585 | if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) && |
| 586 | !(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 587 | struct iwl_sched_scan_results *notif = (void *)pkt->data; |
| 588 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 589 | if (!(notif->client_bitmap & SCAN_CLIENT_SCHED_SCAN)) |
| 590 | return 0; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 591 | } |
| 592 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 593 | IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n"); |
| 594 | ieee80211_sched_scan_results(mvm->hw); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 599 | static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait, |
| 600 | struct iwl_rx_packet *pkt, void *data) |
| 601 | { |
| 602 | struct iwl_mvm *mvm = |
| 603 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 604 | struct iwl_scan_complete_notif *notif; |
| 605 | u32 *resp; |
| 606 | |
| 607 | switch (pkt->hdr.cmd) { |
| 608 | case SCAN_ABORT_CMD: |
| 609 | resp = (void *)pkt->data; |
| 610 | if (*resp == CAN_ABORT_STATUS) { |
| 611 | IWL_DEBUG_SCAN(mvm, |
| 612 | "Scan can be aborted, wait until completion\n"); |
| 613 | return false; |
| 614 | } |
| 615 | |
Emmanuel Grumbach | 5a3e9f7 | 2013-09-15 14:39:02 +0300 | [diff] [blame] | 616 | /* |
| 617 | * If scan cannot be aborted, it means that we had a |
| 618 | * SCAN_COMPLETE_NOTIFICATION in the pipe and it called |
| 619 | * ieee80211_scan_completed already. |
| 620 | */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 621 | IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n", |
| 622 | *resp); |
| 623 | return true; |
| 624 | |
| 625 | case SCAN_COMPLETE_NOTIFICATION: |
| 626 | notif = (void *)pkt->data; |
| 627 | IWL_DEBUG_SCAN(mvm, "Scan aborted: status 0x%x\n", |
| 628 | notif->status); |
| 629 | return true; |
| 630 | |
| 631 | default: |
| 632 | WARN_ON(1); |
| 633 | return false; |
| 634 | }; |
| 635 | } |
| 636 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 637 | static int iwl_mvm_cancel_regular_scan(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 638 | { |
| 639 | struct iwl_notification_wait wait_scan_abort; |
| 640 | static const u8 scan_abort_notif[] = { SCAN_ABORT_CMD, |
| 641 | SCAN_COMPLETE_NOTIFICATION }; |
| 642 | int ret; |
| 643 | |
| 644 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort, |
| 645 | scan_abort_notif, |
| 646 | ARRAY_SIZE(scan_abort_notif), |
| 647 | iwl_mvm_scan_abort_notif, NULL); |
| 648 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 649 | ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, 0, 0, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 650 | if (ret) { |
| 651 | IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret); |
David Spinadel | 992f81f | 2014-01-09 14:22:55 +0200 | [diff] [blame] | 652 | /* mac80211's state will be cleaned in the nic_restart flow */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 653 | goto out_remove_notif; |
| 654 | } |
| 655 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 656 | return iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, HZ); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 657 | |
| 658 | out_remove_notif: |
| 659 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort); |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 660 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 661 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 662 | |
| 663 | int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm, |
| 664 | struct iwl_rx_cmd_buffer *rxb, |
| 665 | struct iwl_device_cmd *cmd) |
| 666 | { |
| 667 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 668 | u8 status, ebs_status; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 669 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 670 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) { |
| 671 | struct iwl_periodic_scan_complete *scan_notif; |
| 672 | |
| 673 | scan_notif = (void *)pkt->data; |
| 674 | status = scan_notif->status; |
| 675 | ebs_status = scan_notif->ebs_status; |
| 676 | } else { |
| 677 | struct iwl_scan_offload_complete *scan_notif; |
| 678 | |
| 679 | scan_notif = (void *)pkt->data; |
| 680 | status = scan_notif->status; |
| 681 | ebs_status = scan_notif->ebs_status; |
| 682 | } |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 683 | /* scan status must be locked for proper checking */ |
| 684 | lockdep_assert_held(&mvm->mutex); |
| 685 | |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 686 | IWL_DEBUG_SCAN(mvm, |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 687 | "%s completed, status %s, EBS status %s\n", |
| 688 | mvm->scan_status == IWL_MVM_SCAN_SCHED ? |
| 689 | "Scheduled scan" : "Scan", |
| 690 | status == IWL_SCAN_OFFLOAD_COMPLETED ? |
| 691 | "completed" : "aborted", |
| 692 | ebs_status == IWL_SCAN_EBS_SUCCESS ? |
| 693 | "success" : "failed"); |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 694 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 695 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 696 | /* only call mac80211 completion if the stop was initiated by FW */ |
| 697 | if (mvm->scan_status == IWL_MVM_SCAN_SCHED) { |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 698 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 699 | ieee80211_sched_scan_stopped(mvm->hw); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 700 | } else if (mvm->scan_status == IWL_MVM_SCAN_OS) { |
| 701 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 702 | ieee80211_scan_completed(mvm->hw, |
| 703 | status == IWL_SCAN_OFFLOAD_ABORTED); |
Eliad Peller | 4ff7818 | 2014-06-22 14:44:44 +0300 | [diff] [blame] | 704 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 705 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 706 | |
Haim Dreyfuss | 5a4b2af | 2015-01-13 11:54:51 +0200 | [diff] [blame] | 707 | if (ebs_status) |
| 708 | mvm->last_ebs_successful = false; |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 709 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm *mvm, |
| 714 | struct ieee80211_vif *vif, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 715 | struct ieee80211_scan_ies *ies, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 716 | enum ieee80211_band band, |
| 717 | struct iwl_tx_cmd *cmd, |
| 718 | u8 *data) |
| 719 | { |
| 720 | u16 cmd_len; |
| 721 | |
| 722 | cmd->tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL); |
| 723 | cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
| 724 | cmd->sta_id = mvm->aux_sta.sta_id; |
| 725 | |
| 726 | cmd->rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, band, false); |
| 727 | |
| 728 | cmd_len = iwl_mvm_fill_probe_req((struct ieee80211_mgmt *)data, |
| 729 | vif->addr, |
| 730 | 1, NULL, 0, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 731 | ies->ies[band], ies->len[band], |
| 732 | ies->common_ies, ies->common_ie_len, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 733 | SCAN_OFFLOAD_PROBE_REQ_SIZE); |
| 734 | cmd->len = cpu_to_le16(cmd_len); |
| 735 | } |
| 736 | |
| 737 | static void iwl_build_scan_cmd(struct iwl_mvm *mvm, |
| 738 | struct ieee80211_vif *vif, |
| 739 | struct cfg80211_sched_scan_request *req, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 740 | struct iwl_scan_offload_cmd *scan, |
| 741 | struct iwl_mvm_scan_params *params) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 742 | { |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 743 | scan->channel_count = req->n_channels; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 744 | scan->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME); |
| 745 | scan->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH); |
| 746 | scan->good_CRC_th = IWL_GOOD_CRC_TH_DEFAULT; |
| 747 | scan->rx_chain = iwl_mvm_scan_rx_chain(mvm); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 748 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 749 | scan->max_out_time = cpu_to_le32(params->max_out_time); |
| 750 | scan->suspend_time = cpu_to_le32(params->suspend_time); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 751 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 752 | scan->filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 753 | MAC_FILTER_IN_BEACON); |
| 754 | scan->scan_type = cpu_to_le32(SCAN_TYPE_BACKGROUND); |
| 755 | scan->rep_count = cpu_to_le32(1); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 756 | |
| 757 | if (params->passive_fragmented) |
| 758 | scan->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list) |
| 762 | { |
| 763 | int i; |
| 764 | |
| 765 | for (i = 0; i < PROBE_OPTION_MAX; i++) { |
| 766 | if (!ssid_list[i].len) |
| 767 | break; |
| 768 | if (ssid_list[i].len == ssid_len && |
| 769 | !memcmp(ssid_list->ssid, ssid, ssid_len)) |
| 770 | return i; |
| 771 | } |
| 772 | return -1; |
| 773 | } |
| 774 | |
| 775 | static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req, |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 776 | struct iwl_ssid_ie *direct_scan, |
| 777 | u32 *ssid_bitmap, bool basic_ssid) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 778 | { |
| 779 | int i, j; |
| 780 | int index; |
| 781 | |
| 782 | /* |
| 783 | * copy SSIDs from match list. |
| 784 | * iwl_config_sched_scan_profiles() uses the order of these ssids to |
| 785 | * config match list. |
| 786 | */ |
| 787 | for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 788 | /* skip empty SSID matchsets */ |
| 789 | if (!req->match_sets[i].ssid.ssid_len) |
| 790 | continue; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 791 | direct_scan[i].id = WLAN_EID_SSID; |
| 792 | direct_scan[i].len = req->match_sets[i].ssid.ssid_len; |
| 793 | memcpy(direct_scan[i].ssid, req->match_sets[i].ssid.ssid, |
| 794 | direct_scan[i].len); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /* add SSIDs from scan SSID list */ |
| 798 | *ssid_bitmap = 0; |
| 799 | for (j = 0; j < req->n_ssids && i < PROBE_OPTION_MAX; j++) { |
| 800 | index = iwl_ssid_exist(req->ssids[j].ssid, |
| 801 | req->ssids[j].ssid_len, |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 802 | direct_scan); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 803 | if (index < 0) { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 804 | if (!req->ssids[j].ssid_len && basic_ssid) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 805 | continue; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 806 | direct_scan[i].id = WLAN_EID_SSID; |
| 807 | direct_scan[i].len = req->ssids[j].ssid_len; |
| 808 | memcpy(direct_scan[i].ssid, req->ssids[j].ssid, |
| 809 | direct_scan[i].len); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 810 | *ssid_bitmap |= BIT(i + 1); |
| 811 | i++; |
| 812 | } else { |
| 813 | *ssid_bitmap |= BIT(index + 1); |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | static void iwl_build_channel_cfg(struct iwl_mvm *mvm, |
| 819 | struct cfg80211_sched_scan_request *req, |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 820 | u8 *channels_buffer, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 821 | enum ieee80211_band band, |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 822 | int *head, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 823 | u32 ssid_bitmap, |
| 824 | struct iwl_mvm_scan_params *params) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 825 | { |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 826 | u32 n_channels = mvm->fw->ucode_capa.n_scan_channels; |
| 827 | __le32 *type = (__le32 *)channels_buffer; |
| 828 | __le16 *channel_number = (__le16 *)(type + n_channels); |
| 829 | __le16 *iter_count = channel_number + n_channels; |
| 830 | __le32 *iter_interval = (__le32 *)(iter_count + n_channels); |
| 831 | u8 *active_dwell = (u8 *)(iter_interval + n_channels); |
| 832 | u8 *passive_dwell = active_dwell + n_channels; |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 833 | int i, index = 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 834 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 835 | for (i = 0; i < req->n_channels; i++) { |
| 836 | struct ieee80211_channel *chan = req->channels[i]; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 837 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 838 | if (chan->band != band) |
| 839 | continue; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 840 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 841 | index = *head; |
| 842 | (*head)++; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 843 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 844 | channel_number[index] = cpu_to_le16(chan->hw_value); |
| 845 | active_dwell[index] = params->dwell[band].active; |
| 846 | passive_dwell[index] = params->dwell[band].passive; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 847 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 848 | iter_count[index] = cpu_to_le16(1); |
| 849 | iter_interval[index] = 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 850 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 851 | if (!(chan->flags & IEEE80211_CHAN_NO_IR)) |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 852 | type[index] |= |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 853 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE); |
| 854 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 855 | type[index] |= cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL | |
| 856 | IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 857 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 858 | if (chan->flags & IEEE80211_CHAN_NO_HT40) |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 859 | type[index] |= |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 860 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW); |
| 861 | |
| 862 | /* scan for all SSIDs from req->ssids */ |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 863 | type[index] |= cpu_to_le32(ssid_bitmap); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 864 | } |
| 865 | } |
| 866 | |
| 867 | int iwl_mvm_config_sched_scan(struct iwl_mvm *mvm, |
| 868 | struct ieee80211_vif *vif, |
| 869 | struct cfg80211_sched_scan_request *req, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 870 | struct ieee80211_scan_ies *ies) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 871 | { |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 872 | int band_2ghz = mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels; |
| 873 | int band_5ghz = mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels; |
| 874 | int head = 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 875 | u32 ssid_bitmap; |
| 876 | int cmd_len; |
| 877 | int ret; |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 878 | u8 *probes; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 879 | bool basic_ssid = !(mvm->fw->ucode_capa.flags & |
| 880 | IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 881 | |
| 882 | struct iwl_scan_offload_cfg *scan_cfg; |
| 883 | struct iwl_host_cmd cmd = { |
| 884 | .id = SCAN_OFFLOAD_CONFIG_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 885 | }; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 886 | struct iwl_mvm_scan_params params = {}; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 887 | |
| 888 | lockdep_assert_held(&mvm->mutex); |
| 889 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 890 | cmd_len = sizeof(struct iwl_scan_offload_cfg) + |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 891 | mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE + |
Emmanuel Grumbach | 6609253 | 2014-02-20 14:58:30 +0200 | [diff] [blame] | 892 | 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 893 | |
| 894 | scan_cfg = kzalloc(cmd_len, GFP_KERNEL); |
| 895 | if (!scan_cfg) |
| 896 | return -ENOMEM; |
| 897 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 898 | probes = scan_cfg->data + |
| 899 | mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE; |
| 900 | |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 901 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, ¶ms); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 902 | iwl_build_scan_cmd(mvm, vif, req, &scan_cfg->scan_cmd, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 903 | scan_cfg->scan_cmd.len = cpu_to_le16(cmd_len); |
| 904 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 905 | iwl_scan_offload_build_ssid(req, scan_cfg->scan_cmd.direct_scan, |
| 906 | &ssid_bitmap, basic_ssid); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 907 | /* build tx frames for supported bands */ |
| 908 | if (band_2ghz) { |
| 909 | iwl_scan_offload_build_tx_cmd(mvm, vif, ies, |
| 910 | IEEE80211_BAND_2GHZ, |
| 911 | &scan_cfg->scan_cmd.tx_cmd[0], |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 912 | probes); |
| 913 | iwl_build_channel_cfg(mvm, req, scan_cfg->data, |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 914 | IEEE80211_BAND_2GHZ, &head, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 915 | ssid_bitmap, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 916 | } |
| 917 | if (band_5ghz) { |
| 918 | iwl_scan_offload_build_tx_cmd(mvm, vif, ies, |
| 919 | IEEE80211_BAND_5GHZ, |
| 920 | &scan_cfg->scan_cmd.tx_cmd[1], |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 921 | probes + |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 922 | SCAN_OFFLOAD_PROBE_REQ_SIZE); |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 923 | iwl_build_channel_cfg(mvm, req, scan_cfg->data, |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 924 | IEEE80211_BAND_5GHZ, &head, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 925 | ssid_bitmap, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | cmd.data[0] = scan_cfg; |
| 929 | cmd.len[0] = cmd_len; |
| 930 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; |
| 931 | |
| 932 | IWL_DEBUG_SCAN(mvm, "Sending scheduled scan config\n"); |
| 933 | |
| 934 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 935 | kfree(scan_cfg); |
| 936 | return ret; |
| 937 | } |
| 938 | |
| 939 | int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm, |
| 940 | struct cfg80211_sched_scan_request *req) |
| 941 | { |
| 942 | struct iwl_scan_offload_profile *profile; |
| 943 | struct iwl_scan_offload_profile_cfg *profile_cfg; |
| 944 | struct iwl_scan_offload_blacklist *blacklist; |
| 945 | struct iwl_host_cmd cmd = { |
| 946 | .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 947 | .len[1] = sizeof(*profile_cfg), |
| 948 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 949 | .dataflags[1] = IWL_HCMD_DFL_NOCOPY, |
| 950 | }; |
| 951 | int blacklist_len; |
| 952 | int i; |
| 953 | int ret; |
| 954 | |
| 955 | if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES)) |
| 956 | return -EIO; |
| 957 | |
| 958 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL) |
| 959 | blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN; |
| 960 | else |
| 961 | blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN; |
| 962 | |
| 963 | blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL); |
| 964 | if (!blacklist) |
| 965 | return -ENOMEM; |
| 966 | |
| 967 | profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL); |
| 968 | if (!profile_cfg) { |
| 969 | ret = -ENOMEM; |
| 970 | goto free_blacklist; |
| 971 | } |
| 972 | |
| 973 | cmd.data[0] = blacklist; |
| 974 | cmd.len[0] = sizeof(*blacklist) * blacklist_len; |
| 975 | cmd.data[1] = profile_cfg; |
| 976 | |
| 977 | /* No blacklist configuration */ |
| 978 | |
| 979 | profile_cfg->num_profiles = req->n_match_sets; |
| 980 | profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN; |
| 981 | profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN; |
| 982 | profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN; |
David Spinadel | 6e0bbe5 | 2013-12-30 09:59:45 +0200 | [diff] [blame] | 983 | if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len) |
| 984 | profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 985 | |
| 986 | for (i = 0; i < req->n_match_sets; i++) { |
| 987 | profile = &profile_cfg->profiles[i]; |
| 988 | profile->ssid_index = i; |
| 989 | /* Support any cipher and auth algorithm */ |
| 990 | profile->unicast_cipher = 0xff; |
| 991 | profile->auth_alg = 0xff; |
| 992 | profile->network_type = IWL_NETWORK_TYPE_ANY; |
| 993 | profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY; |
| 994 | profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN; |
| 995 | } |
| 996 | |
| 997 | IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n"); |
| 998 | |
| 999 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 1000 | kfree(profile_cfg); |
| 1001 | free_blacklist: |
| 1002 | kfree(blacklist); |
| 1003 | |
| 1004 | return ret; |
| 1005 | } |
| 1006 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1007 | static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm, |
| 1008 | struct cfg80211_sched_scan_request *req) |
| 1009 | { |
| 1010 | if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) { |
| 1011 | IWL_DEBUG_SCAN(mvm, |
| 1012 | "Sending scheduled scan with filtering, n_match_sets %d\n", |
| 1013 | req->n_match_sets); |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
| 1017 | IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n"); |
| 1018 | return true; |
| 1019 | } |
| 1020 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1021 | int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm, |
| 1022 | struct cfg80211_sched_scan_request *req) |
| 1023 | { |
| 1024 | struct iwl_scan_offload_req scan_req = { |
| 1025 | .watchdog = IWL_SCHED_SCAN_WATCHDOG, |
| 1026 | |
| 1027 | .schedule_line[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS, |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 1028 | .schedule_line[0].delay = cpu_to_le16(req->interval / 1000), |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1029 | .schedule_line[0].full_scan_mul = 1, |
| 1030 | |
| 1031 | .schedule_line[1].iterations = 0xff, |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 1032 | .schedule_line[1].delay = cpu_to_le16(req->interval / 1000), |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1033 | .schedule_line[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER, |
| 1034 | }; |
| 1035 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1036 | if (iwl_mvm_scan_pass_all(mvm, req)) |
Eliad Peller | de33fb5 | 2013-11-10 12:59:46 +0200 | [diff] [blame] | 1037 | scan_req.flags |= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1038 | |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 1039 | if (mvm->last_ebs_successful && |
| 1040 | mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) |
| 1041 | scan_req.flags |= |
| 1042 | cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE); |
| 1043 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1044 | return iwl_mvm_send_cmd_pdu(mvm, SCAN_OFFLOAD_REQUEST_CMD, 0, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1045 | sizeof(scan_req), &scan_req); |
| 1046 | } |
| 1047 | |
Luciano Coelho | b141c23 | 2014-10-01 13:22:40 +0300 | [diff] [blame] | 1048 | int iwl_mvm_scan_offload_start(struct iwl_mvm *mvm, |
| 1049 | struct ieee80211_vif *vif, |
| 1050 | struct cfg80211_sched_scan_request *req, |
| 1051 | struct ieee80211_scan_ies *ies) |
| 1052 | { |
| 1053 | int ret; |
| 1054 | |
David Spinadel | b975e55 | 2014-11-17 12:30:05 +0200 | [diff] [blame] | 1055 | if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) { |
| 1056 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1057 | if (ret) |
| 1058 | return ret; |
| 1059 | ret = iwl_mvm_sched_scan_umac(mvm, vif, req, ies); |
| 1060 | } else if ((mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) { |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1061 | mvm->scan_status = IWL_MVM_SCAN_SCHED; |
Luciano Coelho | b141c23 | 2014-10-01 13:22:40 +0300 | [diff] [blame] | 1062 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1063 | if (ret) |
| 1064 | return ret; |
| 1065 | ret = iwl_mvm_unified_sched_scan_lmac(mvm, vif, req, ies); |
| 1066 | } else { |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1067 | mvm->scan_status = IWL_MVM_SCAN_SCHED; |
Luciano Coelho | b141c23 | 2014-10-01 13:22:40 +0300 | [diff] [blame] | 1068 | ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies); |
| 1069 | if (ret) |
| 1070 | return ret; |
| 1071 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1072 | if (ret) |
| 1073 | return ret; |
| 1074 | ret = iwl_mvm_sched_scan_start(mvm, req); |
| 1075 | } |
| 1076 | |
| 1077 | return ret; |
| 1078 | } |
| 1079 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1080 | static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1081 | { |
| 1082 | int ret; |
| 1083 | struct iwl_host_cmd cmd = { |
| 1084 | .id = SCAN_OFFLOAD_ABORT_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1085 | }; |
| 1086 | u32 status; |
| 1087 | |
| 1088 | /* Exit instantly with error when device is not ready |
| 1089 | * to receive scan abort command or it does not perform |
| 1090 | * scheduled scan currently */ |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1091 | if (mvm->scan_status != IWL_MVM_SCAN_SCHED && |
| 1092 | (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) || |
| 1093 | mvm->scan_status != IWL_MVM_SCAN_OS)) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1094 | return -EIO; |
| 1095 | |
| 1096 | ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status); |
| 1097 | if (ret) |
| 1098 | return ret; |
| 1099 | |
| 1100 | if (status != CAN_ABORT_STATUS) { |
| 1101 | /* |
| 1102 | * The scan abort will return 1 for success or |
| 1103 | * 2 for "failure". A failure condition can be |
| 1104 | * due to simply not being in an active scan which |
| 1105 | * can occur if we send the scan abort before the |
| 1106 | * microcode has notified us that a scan is completed. |
| 1107 | */ |
| 1108 | IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1109 | ret = -ENOENT; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | return ret; |
| 1113 | } |
| 1114 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1115 | int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1116 | { |
| 1117 | int ret; |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1118 | struct iwl_notification_wait wait_scan_done; |
| 1119 | static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, }; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1120 | bool sched = mvm->scan_status == IWL_MVM_SCAN_SCHED; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1121 | |
| 1122 | lockdep_assert_held(&mvm->mutex); |
| 1123 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1124 | if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) |
| 1125 | return iwl_umac_scan_stop(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN, |
| 1126 | notify); |
| 1127 | |
Emmanuel Grumbach | 90ea15c | 2015-01-18 21:39:30 +0200 | [diff] [blame] | 1128 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) |
| 1129 | return 0; |
| 1130 | |
| 1131 | if (iwl_mvm_is_radio_killed(mvm)) |
| 1132 | goto out; |
| 1133 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1134 | if (mvm->scan_status != IWL_MVM_SCAN_SCHED && |
| 1135 | (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) || |
| 1136 | mvm->scan_status != IWL_MVM_SCAN_OS)) { |
| 1137 | IWL_DEBUG_SCAN(mvm, "No scan to stop\n"); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1138 | return 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1139 | } |
| 1140 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1141 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done, |
| 1142 | scan_done_notif, |
| 1143 | ARRAY_SIZE(scan_done_notif), |
| 1144 | NULL, NULL); |
| 1145 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1146 | ret = iwl_mvm_send_scan_offload_abort(mvm); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1147 | if (ret) { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1148 | IWL_DEBUG_SCAN(mvm, "Send stop %sscan failed %d\n", |
| 1149 | sched ? "offloaded " : "", ret); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1150 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_done); |
| 1151 | return ret; |
| 1152 | } |
| 1153 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1154 | IWL_DEBUG_SCAN(mvm, "Successfully sent stop %sscan\n", |
| 1155 | sched ? "offloaded " : ""); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1156 | |
| 1157 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ); |
| 1158 | if (ret) |
| 1159 | return ret; |
| 1160 | |
| 1161 | /* |
| 1162 | * Clear the scan status so the next scan requests will succeed. This |
| 1163 | * also ensures the Rx handler doesn't do anything, as the scan was |
Eliad Peller | 4ff7818 | 2014-06-22 14:44:44 +0300 | [diff] [blame] | 1164 | * stopped from above. Since the rx handler won't do anything now, |
| 1165 | * we have to release the scan reference here. |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1166 | */ |
Eliad Peller | 4ff7818 | 2014-06-22 14:44:44 +0300 | [diff] [blame] | 1167 | if (mvm->scan_status == IWL_MVM_SCAN_OS) |
| 1168 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 1169 | |
Emmanuel Grumbach | 90ea15c | 2015-01-18 21:39:30 +0200 | [diff] [blame] | 1170 | out: |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1171 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1172 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1173 | if (notify) { |
| 1174 | if (sched) |
| 1175 | ieee80211_sched_scan_stopped(mvm->hw); |
| 1176 | else |
| 1177 | ieee80211_scan_completed(mvm->hw, true); |
| 1178 | } |
David Spinadel | 636a2cd | 2014-05-01 15:57:22 +0300 | [diff] [blame] | 1179 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1180 | return 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1181 | } |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1182 | |
| 1183 | static void iwl_mvm_unified_scan_fill_tx_cmd(struct iwl_mvm *mvm, |
| 1184 | struct iwl_scan_req_tx_cmd *tx_cmd, |
| 1185 | bool no_cck) |
| 1186 | { |
| 1187 | tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL | |
| 1188 | TX_CMD_FLG_BT_DIS); |
| 1189 | tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, |
| 1190 | IEEE80211_BAND_2GHZ, |
| 1191 | no_cck); |
| 1192 | tx_cmd[0].sta_id = mvm->aux_sta.sta_id; |
| 1193 | |
| 1194 | tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL | |
| 1195 | TX_CMD_FLG_BT_DIS); |
| 1196 | tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, |
| 1197 | IEEE80211_BAND_5GHZ, |
| 1198 | no_cck); |
| 1199 | tx_cmd[1].sta_id = mvm->aux_sta.sta_id; |
| 1200 | } |
| 1201 | |
| 1202 | static void |
| 1203 | iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm, |
| 1204 | struct ieee80211_channel **channels, |
| 1205 | int n_channels, u32 ssid_bitmap, |
| 1206 | struct iwl_scan_req_unified_lmac *cmd) |
| 1207 | { |
| 1208 | struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data; |
| 1209 | int i; |
| 1210 | |
| 1211 | for (i = 0; i < n_channels; i++) { |
| 1212 | channel_cfg[i].channel_num = |
| 1213 | cpu_to_le16(channels[i]->hw_value); |
| 1214 | channel_cfg[i].iter_count = cpu_to_le16(1); |
| 1215 | channel_cfg[i].iter_interval = 0; |
| 1216 | channel_cfg[i].flags = |
| 1217 | cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL | |
| 1218 | ssid_bitmap); |
| 1219 | } |
| 1220 | } |
| 1221 | |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1222 | static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies, |
| 1223 | size_t len, u8 *const pos) |
| 1224 | { |
| 1225 | static const u8 before_ds_params[] = { |
| 1226 | WLAN_EID_SSID, |
| 1227 | WLAN_EID_SUPP_RATES, |
| 1228 | WLAN_EID_REQUEST, |
| 1229 | WLAN_EID_EXT_SUPP_RATES, |
| 1230 | }; |
| 1231 | size_t offs; |
| 1232 | u8 *newpos = pos; |
| 1233 | |
| 1234 | if (!iwl_mvm_rrm_scan_needed(mvm)) { |
| 1235 | memcpy(newpos, ies, len); |
| 1236 | return newpos + len; |
| 1237 | } |
| 1238 | |
| 1239 | offs = ieee80211_ie_split(ies, len, |
| 1240 | before_ds_params, |
| 1241 | ARRAY_SIZE(before_ds_params), |
| 1242 | 0); |
| 1243 | |
| 1244 | memcpy(newpos, ies, offs); |
| 1245 | newpos += offs; |
| 1246 | |
| 1247 | /* Add a placeholder for DS Parameter Set element */ |
| 1248 | *newpos++ = WLAN_EID_DS_PARAMS; |
| 1249 | *newpos++ = 1; |
| 1250 | *newpos++ = 0; |
| 1251 | |
| 1252 | memcpy(newpos, ies + offs, len - offs); |
| 1253 | newpos += len - offs; |
| 1254 | |
| 1255 | return newpos; |
| 1256 | } |
| 1257 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1258 | static void |
| 1259 | iwl_mvm_build_unified_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1260 | struct ieee80211_scan_ies *ies, |
Johannes Berg | effd05a | 2014-11-18 17:21:19 +0100 | [diff] [blame] | 1261 | struct iwl_scan_probe_req *preq, |
| 1262 | const u8 *mac_addr, const u8 *mac_addr_mask) |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1263 | { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1264 | struct ieee80211_mgmt *frame = (struct ieee80211_mgmt *)preq->buf; |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1265 | u8 *pos, *newpos; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1266 | |
Johannes Berg | effd05a | 2014-11-18 17:21:19 +0100 | [diff] [blame] | 1267 | /* |
| 1268 | * Unfortunately, right now the offload scan doesn't support randomising |
| 1269 | * within the firmware, so until the firmware API is ready we implement |
| 1270 | * it in the driver. This means that the scan iterations won't really be |
| 1271 | * random, only when it's restarted, but at least that helps a bit. |
| 1272 | */ |
| 1273 | if (mac_addr) |
| 1274 | get_random_mask_addr(frame->sa, mac_addr, mac_addr_mask); |
| 1275 | else |
| 1276 | memcpy(frame->sa, vif->addr, ETH_ALEN); |
| 1277 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1278 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
| 1279 | eth_broadcast_addr(frame->da); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1280 | eth_broadcast_addr(frame->bssid); |
| 1281 | frame->seq_ctrl = 0; |
| 1282 | |
| 1283 | pos = frame->u.probe_req.variable; |
| 1284 | *pos++ = WLAN_EID_SSID; |
| 1285 | *pos++ = 0; |
| 1286 | |
| 1287 | preq->mac_header.offset = 0; |
| 1288 | preq->mac_header.len = cpu_to_le16(24 + 2); |
| 1289 | |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1290 | /* Insert ds parameter set element on 2.4 GHz band */ |
| 1291 | newpos = iwl_mvm_copy_and_insert_ds_elem(mvm, |
| 1292 | ies->ies[IEEE80211_BAND_2GHZ], |
| 1293 | ies->len[IEEE80211_BAND_2GHZ], |
| 1294 | pos); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1295 | preq->band_data[0].offset = cpu_to_le16(pos - preq->buf); |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1296 | preq->band_data[0].len = cpu_to_le16(newpos - pos); |
| 1297 | pos = newpos; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1298 | |
| 1299 | memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ], |
| 1300 | ies->len[IEEE80211_BAND_5GHZ]); |
| 1301 | preq->band_data[1].offset = cpu_to_le16(pos - preq->buf); |
| 1302 | preq->band_data[1].len = cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]); |
| 1303 | pos += ies->len[IEEE80211_BAND_5GHZ]; |
| 1304 | |
| 1305 | memcpy(pos, ies->common_ies, ies->common_ie_len); |
| 1306 | preq->common_data.offset = cpu_to_le16(pos - preq->buf); |
| 1307 | preq->common_data.len = cpu_to_le16(ies->common_ie_len); |
| 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | iwl_mvm_build_generic_unified_scan_cmd(struct iwl_mvm *mvm, |
| 1312 | struct iwl_scan_req_unified_lmac *cmd, |
| 1313 | struct iwl_mvm_scan_params *params) |
| 1314 | { |
David Spinadel | af91344 | 2014-06-12 19:29:40 +0300 | [diff] [blame] | 1315 | memset(cmd, 0, ksize(cmd)); |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 1316 | cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active; |
| 1317 | cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive; |
| 1318 | if (params->passive_fragmented) |
| 1319 | cmd->fragmented_dwell = |
| 1320 | params->dwell[IEEE80211_BAND_2GHZ].passive; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1321 | cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm); |
| 1322 | cmd->max_out_time = cpu_to_le32(params->max_out_time); |
| 1323 | cmd->suspend_time = cpu_to_le32(params->suspend_time); |
| 1324 | cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1325 | cmd->iter_num = cpu_to_le32(1); |
David Spinadel | af91344 | 2014-06-12 19:29:40 +0300 | [diff] [blame] | 1326 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 1327 | if (iwl_mvm_rrm_scan_needed(mvm)) |
| 1328 | cmd->scan_flags |= |
| 1329 | cpu_to_le32(IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | int iwl_mvm_unified_scan_lmac(struct iwl_mvm *mvm, |
| 1333 | struct ieee80211_vif *vif, |
| 1334 | struct ieee80211_scan_request *req) |
| 1335 | { |
| 1336 | struct iwl_host_cmd hcmd = { |
| 1337 | .id = SCAN_OFFLOAD_REQUEST_CMD, |
| 1338 | .len = { sizeof(struct iwl_scan_req_unified_lmac) + |
| 1339 | sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 1340 | mvm->fw->ucode_capa.n_scan_channels + |
| 1341 | sizeof(struct iwl_scan_probe_req), }, |
| 1342 | .data = { mvm->scan_cmd, }, |
| 1343 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 1344 | }; |
| 1345 | struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd; |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1346 | struct iwl_scan_probe_req *preq; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1347 | struct iwl_mvm_scan_params params = {}; |
| 1348 | u32 flags; |
Johannes Berg | c8660dd | 2014-11-17 15:06:52 +0100 | [diff] [blame] | 1349 | u32 ssid_bitmap = 0; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1350 | int ret, i; |
| 1351 | |
| 1352 | lockdep_assert_held(&mvm->mutex); |
| 1353 | |
| 1354 | /* we should have failed registration if scan_cmd was NULL */ |
| 1355 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 1356 | return -ENOMEM; |
| 1357 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 1358 | if (req->req.n_ssids > PROBE_OPTION_MAX || |
| 1359 | req->ies.common_ie_len + req->ies.len[NL80211_BAND_2GHZ] + |
| 1360 | req->ies.len[NL80211_BAND_5GHZ] > |
| 1361 | iwl_mvm_max_scan_ie_fw_cmd_room(mvm, false) || |
| 1362 | req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) |
| 1363 | return -ENOBUFS; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1364 | |
| 1365 | mvm->scan_status = IWL_MVM_SCAN_OS; |
| 1366 | |
| 1367 | iwl_mvm_scan_calc_params(mvm, vif, req->req.n_ssids, req->req.flags, |
| 1368 | ¶ms); |
| 1369 | |
| 1370 | iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, ¶ms); |
| 1371 | |
| 1372 | cmd->n_channels = (u8)req->req.n_channels; |
| 1373 | |
| 1374 | flags = IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL; |
| 1375 | |
| 1376 | if (req->req.n_ssids == 1 && req->req.ssids[0].ssid_len != 0) |
| 1377 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION; |
| 1378 | |
| 1379 | if (params.passive_fragmented) |
| 1380 | flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED; |
| 1381 | |
| 1382 | if (req->req.n_ssids == 0) |
| 1383 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE; |
| 1384 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 1385 | cmd->scan_flags |= cpu_to_le32(flags); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1386 | |
| 1387 | cmd->flags = iwl_mvm_scan_rxon_flags(req->req.channels[0]->band); |
| 1388 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 1389 | MAC_FILTER_IN_BEACON); |
| 1390 | iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, req->req.no_cck); |
| 1391 | iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->req.ssids, |
| 1392 | req->req.n_ssids, 0); |
| 1393 | |
| 1394 | cmd->schedule[0].delay = 0; |
| 1395 | cmd->schedule[0].iterations = 1; |
| 1396 | cmd->schedule[0].full_scan_mul = 0; |
| 1397 | cmd->schedule[1].delay = 0; |
| 1398 | cmd->schedule[1].iterations = 0; |
| 1399 | cmd->schedule[1].full_scan_mul = 0; |
| 1400 | |
David Spinadel | 1f9c418 | 2014-12-01 23:30:07 +0200 | [diff] [blame] | 1401 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_SINGLE_SCAN_EBS && |
| 1402 | mvm->last_ebs_successful) { |
| 1403 | cmd->channel_opt[0].flags = |
| 1404 | cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS | |
| 1405 | IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE | |
| 1406 | IWL_SCAN_CHANNEL_FLAG_CACHE_ADD); |
| 1407 | cmd->channel_opt[0].non_ebs_ratio = |
| 1408 | cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO); |
| 1409 | cmd->channel_opt[1].flags = |
| 1410 | cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS | |
| 1411 | IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE | |
| 1412 | IWL_SCAN_CHANNEL_FLAG_CACHE_ADD); |
| 1413 | cmd->channel_opt[1].non_ebs_ratio = |
| 1414 | cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO); |
| 1415 | } |
| 1416 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1417 | for (i = 1; i <= req->req.n_ssids; i++) |
| 1418 | ssid_bitmap |= BIT(i); |
| 1419 | |
| 1420 | iwl_mvm_lmac_scan_cfg_channels(mvm, req->req.channels, |
| 1421 | req->req.n_channels, ssid_bitmap, |
| 1422 | cmd); |
| 1423 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1424 | preq = (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 1425 | mvm->fw->ucode_capa.n_scan_channels); |
| 1426 | |
Johannes Berg | effd05a | 2014-11-18 17:21:19 +0100 | [diff] [blame] | 1427 | iwl_mvm_build_unified_scan_probe(mvm, vif, &req->ies, preq, |
| 1428 | req->req.flags & NL80211_SCAN_FLAG_RANDOM_ADDR ? |
| 1429 | req->req.mac_addr : NULL, |
| 1430 | req->req.mac_addr_mask); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1431 | |
| 1432 | ret = iwl_mvm_send_cmd(mvm, &hcmd); |
| 1433 | if (!ret) { |
| 1434 | IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n"); |
| 1435 | } else { |
| 1436 | /* |
| 1437 | * If the scan failed, it usually means that the FW was unable |
| 1438 | * to allocate the time events. Warn on it, but maybe we |
| 1439 | * should try to send the command again with different params. |
| 1440 | */ |
| 1441 | IWL_ERR(mvm, "Scan failed! ret %d\n", ret); |
| 1442 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1443 | ret = -EIO; |
| 1444 | } |
| 1445 | return ret; |
| 1446 | } |
| 1447 | |
| 1448 | int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm, |
| 1449 | struct ieee80211_vif *vif, |
| 1450 | struct cfg80211_sched_scan_request *req, |
| 1451 | struct ieee80211_scan_ies *ies) |
| 1452 | { |
| 1453 | struct iwl_host_cmd hcmd = { |
| 1454 | .id = SCAN_OFFLOAD_REQUEST_CMD, |
| 1455 | .len = { sizeof(struct iwl_scan_req_unified_lmac) + |
| 1456 | sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 1457 | mvm->fw->ucode_capa.n_scan_channels + |
| 1458 | sizeof(struct iwl_scan_probe_req), }, |
| 1459 | .data = { mvm->scan_cmd, }, |
| 1460 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 1461 | }; |
| 1462 | struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd; |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1463 | struct iwl_scan_probe_req *preq; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1464 | struct iwl_mvm_scan_params params = {}; |
| 1465 | int ret; |
| 1466 | u32 flags = 0, ssid_bitmap = 0; |
| 1467 | |
| 1468 | lockdep_assert_held(&mvm->mutex); |
| 1469 | |
| 1470 | /* we should have failed registration if scan_cmd was NULL */ |
| 1471 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 1472 | return -ENOMEM; |
| 1473 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 1474 | if (req->n_ssids > PROBE_OPTION_MAX || |
| 1475 | ies->common_ie_len + ies->len[NL80211_BAND_2GHZ] + |
| 1476 | ies->len[NL80211_BAND_5GHZ] > |
| 1477 | iwl_mvm_max_scan_ie_fw_cmd_room(mvm, true) || |
| 1478 | req->n_channels > mvm->fw->ucode_capa.n_scan_channels) |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1479 | return -ENOBUFS; |
| 1480 | |
| 1481 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, ¶ms); |
| 1482 | |
| 1483 | iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, ¶ms); |
| 1484 | |
| 1485 | cmd->n_channels = (u8)req->n_channels; |
| 1486 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1487 | if (iwl_mvm_scan_pass_all(mvm, req)) |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1488 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL; |
David Spinadel | 7e2a388 | 2014-12-23 14:38:09 +0200 | [diff] [blame] | 1489 | else |
| 1490 | flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1491 | |
| 1492 | if (req->n_ssids == 1 && req->ssids[0].ssid_len != 0) |
| 1493 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION; |
| 1494 | |
| 1495 | if (params.passive_fragmented) |
| 1496 | flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED; |
| 1497 | |
| 1498 | if (req->n_ssids == 0) |
| 1499 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE; |
| 1500 | |
Alexander Bondar | e5d7464 | 2014-12-09 19:15:49 +0200 | [diff] [blame] | 1501 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1502 | if (mvm->scan_iter_notif_enabled) |
| 1503 | flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE; |
| 1504 | #endif |
| 1505 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 1506 | cmd->scan_flags |= cpu_to_le32(flags); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1507 | |
| 1508 | cmd->flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band); |
| 1509 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 1510 | MAC_FILTER_IN_BEACON); |
| 1511 | iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, false); |
| 1512 | iwl_scan_offload_build_ssid(req, cmd->direct_scan, &ssid_bitmap, false); |
| 1513 | |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 1514 | cmd->schedule[0].delay = cpu_to_le16(req->interval / MSEC_PER_SEC); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1515 | cmd->schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS; |
| 1516 | cmd->schedule[0].full_scan_mul = 1; |
| 1517 | |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 1518 | cmd->schedule[1].delay = cpu_to_le16(req->interval / MSEC_PER_SEC); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1519 | cmd->schedule[1].iterations = 0xff; |
| 1520 | cmd->schedule[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER; |
| 1521 | |
David Spinadel | 1f9c418 | 2014-12-01 23:30:07 +0200 | [diff] [blame] | 1522 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT && |
| 1523 | mvm->last_ebs_successful) { |
| 1524 | cmd->channel_opt[0].flags = |
| 1525 | cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS | |
| 1526 | IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE | |
| 1527 | IWL_SCAN_CHANNEL_FLAG_CACHE_ADD); |
| 1528 | cmd->channel_opt[0].non_ebs_ratio = |
| 1529 | cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO); |
| 1530 | cmd->channel_opt[1].flags = |
| 1531 | cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS | |
| 1532 | IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE | |
| 1533 | IWL_SCAN_CHANNEL_FLAG_CACHE_ADD); |
| 1534 | cmd->channel_opt[1].non_ebs_ratio = |
| 1535 | cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO); |
| 1536 | } |
| 1537 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1538 | iwl_mvm_lmac_scan_cfg_channels(mvm, req->channels, req->n_channels, |
| 1539 | ssid_bitmap, cmd); |
| 1540 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1541 | preq = (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 1542 | mvm->fw->ucode_capa.n_scan_channels); |
| 1543 | |
Johannes Berg | effd05a | 2014-11-18 17:21:19 +0100 | [diff] [blame] | 1544 | iwl_mvm_build_unified_scan_probe(mvm, vif, ies, preq, |
| 1545 | req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ? |
| 1546 | req->mac_addr : NULL, |
| 1547 | req->mac_addr_mask); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1548 | |
| 1549 | ret = iwl_mvm_send_cmd(mvm, &hcmd); |
| 1550 | if (!ret) { |
| 1551 | IWL_DEBUG_SCAN(mvm, |
| 1552 | "Sched scan request was sent successfully\n"); |
| 1553 | } else { |
| 1554 | /* |
| 1555 | * If the scan failed, it usually means that the FW was unable |
| 1556 | * to allocate the time events. Warn on it, but maybe we |
| 1557 | * should try to send the command again with different params. |
| 1558 | */ |
| 1559 | IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret); |
| 1560 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1561 | ret = -EIO; |
| 1562 | } |
| 1563 | return ret; |
| 1564 | } |
| 1565 | |
| 1566 | |
| 1567 | int iwl_mvm_cancel_scan(struct iwl_mvm *mvm) |
| 1568 | { |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1569 | if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) |
| 1570 | return iwl_umac_scan_stop(mvm, IWL_UMAC_SCAN_UID_REG_SCAN, |
| 1571 | true); |
| 1572 | |
Emmanuel Grumbach | 9b520d8 | 2014-11-04 15:54:11 +0200 | [diff] [blame] | 1573 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) |
| 1574 | return 0; |
| 1575 | |
| 1576 | if (iwl_mvm_is_radio_killed(mvm)) { |
| 1577 | ieee80211_scan_completed(mvm->hw, true); |
| 1578 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 1579 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1583 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) |
| 1584 | return iwl_mvm_scan_offload_stop(mvm, true); |
| 1585 | return iwl_mvm_cancel_regular_scan(mvm); |
| 1586 | } |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1587 | |
| 1588 | /* UMAC scan API */ |
| 1589 | |
| 1590 | struct iwl_umac_scan_done { |
| 1591 | struct iwl_mvm *mvm; |
| 1592 | enum iwl_umac_scan_uid_type type; |
| 1593 | }; |
| 1594 | |
| 1595 | static int rate_to_scan_rate_flag(unsigned int rate) |
| 1596 | { |
| 1597 | static const int rate_to_scan_rate[IWL_RATE_COUNT] = { |
| 1598 | [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M, |
| 1599 | [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M, |
| 1600 | [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M, |
| 1601 | [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M, |
| 1602 | [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M, |
| 1603 | [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M, |
| 1604 | [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M, |
| 1605 | [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M, |
| 1606 | [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M, |
| 1607 | [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M, |
| 1608 | [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M, |
| 1609 | [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M, |
| 1610 | }; |
| 1611 | |
| 1612 | return rate_to_scan_rate[rate]; |
| 1613 | } |
| 1614 | |
| 1615 | static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm) |
| 1616 | { |
| 1617 | struct ieee80211_supported_band *band; |
| 1618 | unsigned int rates = 0; |
| 1619 | int i; |
| 1620 | |
| 1621 | band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; |
| 1622 | for (i = 0; i < band->n_bitrates; i++) |
| 1623 | rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value); |
| 1624 | band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; |
| 1625 | for (i = 0; i < band->n_bitrates; i++) |
| 1626 | rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value); |
| 1627 | |
| 1628 | /* Set both basic rates and supported rates */ |
| 1629 | rates |= SCAN_CONFIG_SUPPORTED_RATE(rates); |
| 1630 | |
| 1631 | return cpu_to_le32(rates); |
| 1632 | } |
| 1633 | |
| 1634 | int iwl_mvm_config_scan(struct iwl_mvm *mvm) |
| 1635 | { |
| 1636 | |
| 1637 | struct iwl_scan_config *scan_config; |
| 1638 | struct ieee80211_supported_band *band; |
| 1639 | int num_channels = |
| 1640 | mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels + |
| 1641 | mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels; |
| 1642 | int ret, i, j = 0, cmd_size, data_size; |
| 1643 | struct iwl_host_cmd cmd = { |
| 1644 | .id = SCAN_CFG_CMD, |
| 1645 | }; |
| 1646 | |
| 1647 | if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels)) |
| 1648 | return -ENOBUFS; |
| 1649 | |
| 1650 | cmd_size = sizeof(*scan_config) + mvm->fw->ucode_capa.n_scan_channels; |
| 1651 | |
| 1652 | scan_config = kzalloc(cmd_size, GFP_KERNEL); |
| 1653 | if (!scan_config) |
| 1654 | return -ENOMEM; |
| 1655 | |
| 1656 | data_size = cmd_size - sizeof(struct iwl_mvm_umac_cmd_hdr); |
| 1657 | scan_config->hdr.size = cpu_to_le16(data_size); |
| 1658 | scan_config->flags = cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE | |
| 1659 | SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS | |
| 1660 | SCAN_CONFIG_FLAG_SET_TX_CHAINS | |
| 1661 | SCAN_CONFIG_FLAG_SET_RX_CHAINS | |
| 1662 | SCAN_CONFIG_FLAG_SET_ALL_TIMES | |
| 1663 | SCAN_CONFIG_FLAG_SET_LEGACY_RATES | |
| 1664 | SCAN_CONFIG_FLAG_SET_MAC_ADDR | |
| 1665 | SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS| |
| 1666 | SCAN_CONFIG_N_CHANNELS(num_channels)); |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 1667 | scan_config->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm)); |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1668 | scan_config->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm)); |
| 1669 | scan_config->legacy_rates = iwl_mvm_scan_config_rates(mvm); |
| 1670 | scan_config->out_of_channel_time = cpu_to_le32(170); |
| 1671 | scan_config->suspend_time = cpu_to_le32(30); |
| 1672 | scan_config->dwell_active = 20; |
| 1673 | scan_config->dwell_passive = 110; |
| 1674 | scan_config->dwell_fragmented = 20; |
| 1675 | |
| 1676 | memcpy(&scan_config->mac_addr, &mvm->addresses[0].addr, ETH_ALEN); |
| 1677 | |
| 1678 | scan_config->bcast_sta_id = mvm->aux_sta.sta_id; |
| 1679 | scan_config->channel_flags = IWL_CHANNEL_FLAG_EBS | |
| 1680 | IWL_CHANNEL_FLAG_ACCURATE_EBS | |
| 1681 | IWL_CHANNEL_FLAG_EBS_ADD | |
| 1682 | IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE; |
| 1683 | |
| 1684 | band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; |
| 1685 | for (i = 0; i < band->n_channels; i++, j++) |
| 1686 | scan_config->channel_array[j] = band->channels[i].center_freq; |
| 1687 | band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; |
| 1688 | for (i = 0; i < band->n_channels; i++, j++) |
| 1689 | scan_config->channel_array[j] = band->channels[i].center_freq; |
| 1690 | |
| 1691 | cmd.data[0] = scan_config; |
| 1692 | cmd.len[0] = cmd_size; |
| 1693 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; |
| 1694 | |
| 1695 | IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n"); |
| 1696 | |
| 1697 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 1698 | |
| 1699 | kfree(scan_config); |
| 1700 | return ret; |
| 1701 | } |
| 1702 | |
| 1703 | static int iwl_mvm_find_scan_uid(struct iwl_mvm *mvm, u32 uid) |
| 1704 | { |
| 1705 | int i; |
| 1706 | |
| 1707 | for (i = 0; i < IWL_MVM_MAX_SIMULTANEOUS_SCANS; i++) |
| 1708 | if (mvm->scan_uid[i] == uid) |
| 1709 | return i; |
| 1710 | |
| 1711 | return i; |
| 1712 | } |
| 1713 | |
| 1714 | static int iwl_mvm_find_free_scan_uid(struct iwl_mvm *mvm) |
| 1715 | { |
| 1716 | return iwl_mvm_find_scan_uid(mvm, 0); |
| 1717 | } |
| 1718 | |
| 1719 | static bool iwl_mvm_find_scan_type(struct iwl_mvm *mvm, |
| 1720 | enum iwl_umac_scan_uid_type type) |
| 1721 | { |
| 1722 | int i; |
| 1723 | |
| 1724 | for (i = 0; i < IWL_MVM_MAX_SIMULTANEOUS_SCANS; i++) |
| 1725 | if (mvm->scan_uid[i] & type) |
| 1726 | return true; |
| 1727 | |
| 1728 | return false; |
| 1729 | } |
| 1730 | |
| 1731 | static u32 iwl_generate_scan_uid(struct iwl_mvm *mvm, |
| 1732 | enum iwl_umac_scan_uid_type type) |
| 1733 | { |
| 1734 | u32 uid; |
| 1735 | |
| 1736 | /* make sure exactly one bit is on in scan type */ |
| 1737 | WARN_ON(hweight8(type) != 1); |
| 1738 | |
| 1739 | /* |
| 1740 | * Make sure scan uids are unique. If one scan lasts long time while |
| 1741 | * others are completing frequently, the seq number will wrap up and |
| 1742 | * we may have more than one scan with the same uid. |
| 1743 | */ |
| 1744 | do { |
| 1745 | uid = type | (mvm->scan_seq_num << |
| 1746 | IWL_UMAC_SCAN_UID_SEQ_OFFSET); |
| 1747 | mvm->scan_seq_num++; |
| 1748 | } while (iwl_mvm_find_scan_uid(mvm, uid) < |
| 1749 | IWL_MVM_MAX_SIMULTANEOUS_SCANS); |
| 1750 | |
| 1751 | IWL_DEBUG_SCAN(mvm, "Generated scan UID %u\n", uid); |
| 1752 | |
| 1753 | return uid; |
| 1754 | } |
| 1755 | |
| 1756 | static void |
| 1757 | iwl_mvm_build_generic_umac_scan_cmd(struct iwl_mvm *mvm, |
| 1758 | struct iwl_scan_req_umac *cmd, |
| 1759 | struct iwl_mvm_scan_params *params) |
| 1760 | { |
| 1761 | memset(cmd, 0, ksize(cmd)); |
| 1762 | cmd->hdr.size = cpu_to_le16(iwl_mvm_scan_size(mvm) - |
| 1763 | sizeof(struct iwl_mvm_umac_cmd_hdr)); |
| 1764 | cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active; |
| 1765 | cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive; |
| 1766 | if (params->passive_fragmented) |
| 1767 | cmd->fragmented_dwell = |
| 1768 | params->dwell[IEEE80211_BAND_2GHZ].passive; |
| 1769 | cmd->max_out_time = cpu_to_le32(params->max_out_time); |
| 1770 | cmd->suspend_time = cpu_to_le32(params->suspend_time); |
| 1771 | cmd->scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH); |
| 1772 | } |
| 1773 | |
| 1774 | static void |
| 1775 | iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm, |
| 1776 | struct ieee80211_channel **channels, |
| 1777 | int n_channels, u32 ssid_bitmap, |
| 1778 | struct iwl_scan_req_umac *cmd) |
| 1779 | { |
| 1780 | struct iwl_scan_channel_cfg_umac *channel_cfg = (void *)&cmd->data; |
| 1781 | int i; |
| 1782 | |
| 1783 | for (i = 0; i < n_channels; i++) { |
| 1784 | channel_cfg[i].flags = cpu_to_le32(ssid_bitmap); |
| 1785 | channel_cfg[i].channel_num = channels[i]->hw_value; |
| 1786 | channel_cfg[i].iter_count = 1; |
| 1787 | channel_cfg[i].iter_interval = 0; |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | static u32 iwl_mvm_scan_umac_common_flags(struct iwl_mvm *mvm, int n_ssids, |
| 1792 | struct cfg80211_ssid *ssids, |
| 1793 | int fragmented) |
| 1794 | { |
| 1795 | int flags = 0; |
| 1796 | |
| 1797 | if (n_ssids == 0) |
| 1798 | flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE; |
| 1799 | |
| 1800 | if (n_ssids == 1 && ssids[0].ssid_len != 0) |
| 1801 | flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT; |
| 1802 | |
| 1803 | if (fragmented) |
| 1804 | flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED; |
| 1805 | |
| 1806 | if (iwl_mvm_rrm_scan_needed(mvm)) |
| 1807 | flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED; |
| 1808 | |
| 1809 | return flags; |
| 1810 | } |
| 1811 | |
| 1812 | int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1813 | struct ieee80211_scan_request *req) |
| 1814 | { |
| 1815 | struct iwl_host_cmd hcmd = { |
| 1816 | .id = SCAN_REQ_UMAC, |
| 1817 | .len = { iwl_mvm_scan_size(mvm), }, |
| 1818 | .data = { mvm->scan_cmd, }, |
| 1819 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 1820 | }; |
| 1821 | struct iwl_scan_req_umac *cmd = mvm->scan_cmd; |
| 1822 | struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data + |
| 1823 | sizeof(struct iwl_scan_channel_cfg_umac) * |
| 1824 | mvm->fw->ucode_capa.n_scan_channels; |
| 1825 | struct iwl_mvm_scan_params params = {}; |
| 1826 | u32 uid, flags; |
Johannes Berg | c8660dd | 2014-11-17 15:06:52 +0100 | [diff] [blame] | 1827 | u32 ssid_bitmap = 0; |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1828 | int ret, i, uid_idx; |
| 1829 | |
| 1830 | lockdep_assert_held(&mvm->mutex); |
| 1831 | |
| 1832 | uid_idx = iwl_mvm_find_free_scan_uid(mvm); |
| 1833 | if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS) |
| 1834 | return -EBUSY; |
| 1835 | |
| 1836 | /* we should have failed registration if scan_cmd was NULL */ |
| 1837 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 1838 | return -ENOMEM; |
| 1839 | |
| 1840 | if (WARN_ON(req->req.n_ssids > PROBE_OPTION_MAX || |
| 1841 | req->ies.common_ie_len + |
| 1842 | req->ies.len[NL80211_BAND_2GHZ] + |
| 1843 | req->ies.len[NL80211_BAND_5GHZ] + 24 + 2 > |
| 1844 | SCAN_OFFLOAD_PROBE_REQ_SIZE || req->req.n_channels > |
| 1845 | mvm->fw->ucode_capa.n_scan_channels)) |
| 1846 | return -ENOBUFS; |
| 1847 | |
| 1848 | iwl_mvm_scan_calc_params(mvm, vif, req->req.n_ssids, req->req.flags, |
| 1849 | ¶ms); |
| 1850 | |
| 1851 | iwl_mvm_build_generic_umac_scan_cmd(mvm, cmd, ¶ms); |
| 1852 | |
| 1853 | uid = iwl_generate_scan_uid(mvm, IWL_UMAC_SCAN_UID_REG_SCAN); |
| 1854 | mvm->scan_uid[uid_idx] = uid; |
| 1855 | cmd->uid = cpu_to_le32(uid); |
| 1856 | |
| 1857 | cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH); |
| 1858 | |
| 1859 | flags = iwl_mvm_scan_umac_common_flags(mvm, req->req.n_ssids, |
| 1860 | req->req.ssids, |
| 1861 | params.passive_fragmented); |
| 1862 | |
| 1863 | flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL; |
| 1864 | |
| 1865 | cmd->general_flags = cpu_to_le32(flags); |
| 1866 | cmd->n_channels = req->req.n_channels; |
| 1867 | |
| 1868 | for (i = 0; i < req->req.n_ssids; i++) |
| 1869 | ssid_bitmap |= BIT(i); |
| 1870 | |
| 1871 | iwl_mvm_umac_scan_cfg_channels(mvm, req->req.channels, |
| 1872 | req->req.n_channels, ssid_bitmap, cmd); |
| 1873 | |
| 1874 | sec_part->schedule[0].iter_count = 1; |
| 1875 | sec_part->delay = 0; |
| 1876 | |
Johannes Berg | effd05a | 2014-11-18 17:21:19 +0100 | [diff] [blame] | 1877 | iwl_mvm_build_unified_scan_probe(mvm, vif, &req->ies, &sec_part->preq, |
| 1878 | req->req.flags & NL80211_SCAN_FLAG_RANDOM_ADDR ? |
| 1879 | req->req.mac_addr : NULL, |
| 1880 | req->req.mac_addr_mask); |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1881 | |
| 1882 | iwl_mvm_scan_fill_ssids(sec_part->direct_scan, req->req.ssids, |
| 1883 | req->req.n_ssids, 0); |
| 1884 | |
| 1885 | ret = iwl_mvm_send_cmd(mvm, &hcmd); |
| 1886 | if (!ret) { |
| 1887 | IWL_DEBUG_SCAN(mvm, |
| 1888 | "Scan request was sent successfully\n"); |
| 1889 | } else { |
| 1890 | /* |
| 1891 | * If the scan failed, it usually means that the FW was unable |
| 1892 | * to allocate the time events. Warn on it, but maybe we |
| 1893 | * should try to send the command again with different params. |
| 1894 | */ |
| 1895 | IWL_ERR(mvm, "Scan failed! ret %d\n", ret); |
| 1896 | } |
| 1897 | return ret; |
| 1898 | } |
| 1899 | |
| 1900 | int iwl_mvm_sched_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1901 | struct cfg80211_sched_scan_request *req, |
| 1902 | struct ieee80211_scan_ies *ies) |
| 1903 | { |
| 1904 | |
| 1905 | struct iwl_host_cmd hcmd = { |
| 1906 | .id = SCAN_REQ_UMAC, |
| 1907 | .len = { iwl_mvm_scan_size(mvm), }, |
| 1908 | .data = { mvm->scan_cmd, }, |
| 1909 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 1910 | }; |
| 1911 | struct iwl_scan_req_umac *cmd = mvm->scan_cmd; |
| 1912 | struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data + |
| 1913 | sizeof(struct iwl_scan_channel_cfg_umac) * |
| 1914 | mvm->fw->ucode_capa.n_scan_channels; |
| 1915 | struct iwl_mvm_scan_params params = {}; |
| 1916 | u32 uid, flags; |
Johannes Berg | c8660dd | 2014-11-17 15:06:52 +0100 | [diff] [blame] | 1917 | u32 ssid_bitmap = 0; |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1918 | int ret, uid_idx; |
| 1919 | |
| 1920 | lockdep_assert_held(&mvm->mutex); |
| 1921 | |
| 1922 | uid_idx = iwl_mvm_find_free_scan_uid(mvm); |
| 1923 | if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS) |
| 1924 | return -EBUSY; |
| 1925 | |
| 1926 | /* we should have failed registration if scan_cmd was NULL */ |
| 1927 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 1928 | return -ENOMEM; |
| 1929 | |
| 1930 | if (WARN_ON(req->n_ssids > PROBE_OPTION_MAX || |
| 1931 | ies->common_ie_len + ies->len[NL80211_BAND_2GHZ] + |
| 1932 | ies->len[NL80211_BAND_5GHZ] + 24 + 2 > |
| 1933 | SCAN_OFFLOAD_PROBE_REQ_SIZE || req->n_channels > |
| 1934 | mvm->fw->ucode_capa.n_scan_channels)) |
| 1935 | return -ENOBUFS; |
| 1936 | |
| 1937 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags, |
| 1938 | ¶ms); |
| 1939 | |
| 1940 | iwl_mvm_build_generic_umac_scan_cmd(mvm, cmd, ¶ms); |
| 1941 | |
| 1942 | cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE); |
| 1943 | |
| 1944 | uid = iwl_generate_scan_uid(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN); |
| 1945 | mvm->scan_uid[uid_idx] = uid; |
| 1946 | cmd->uid = cpu_to_le32(uid); |
| 1947 | |
| 1948 | cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_LOW); |
| 1949 | |
| 1950 | flags = iwl_mvm_scan_umac_common_flags(mvm, req->n_ssids, req->ssids, |
| 1951 | params.passive_fragmented); |
| 1952 | |
| 1953 | flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC; |
| 1954 | |
| 1955 | if (iwl_mvm_scan_pass_all(mvm, req)) |
| 1956 | flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL; |
| 1957 | else |
| 1958 | flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH; |
| 1959 | |
| 1960 | cmd->general_flags = cpu_to_le32(flags); |
| 1961 | |
| 1962 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT && |
| 1963 | mvm->last_ebs_successful) |
| 1964 | cmd->channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS | |
| 1965 | IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE | |
| 1966 | IWL_SCAN_CHANNEL_FLAG_CACHE_ADD; |
| 1967 | |
| 1968 | cmd->n_channels = req->n_channels; |
| 1969 | |
| 1970 | iwl_scan_offload_build_ssid(req, sec_part->direct_scan, &ssid_bitmap, |
| 1971 | false); |
| 1972 | |
| 1973 | /* This API uses bits 0-19 instead of 1-20. */ |
| 1974 | ssid_bitmap = ssid_bitmap >> 1; |
| 1975 | |
| 1976 | iwl_mvm_umac_scan_cfg_channels(mvm, req->channels, req->n_channels, |
| 1977 | ssid_bitmap, cmd); |
| 1978 | |
| 1979 | sec_part->schedule[0].interval = |
| 1980 | cpu_to_le16(req->interval / MSEC_PER_SEC); |
| 1981 | sec_part->schedule[0].iter_count = 0xff; |
| 1982 | |
| 1983 | sec_part->delay = 0; |
| 1984 | |
Johannes Berg | effd05a | 2014-11-18 17:21:19 +0100 | [diff] [blame] | 1985 | iwl_mvm_build_unified_scan_probe(mvm, vif, ies, &sec_part->preq, |
| 1986 | req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ? |
| 1987 | req->mac_addr : NULL, |
| 1988 | req->mac_addr_mask); |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1989 | |
| 1990 | ret = iwl_mvm_send_cmd(mvm, &hcmd); |
| 1991 | if (!ret) { |
| 1992 | IWL_DEBUG_SCAN(mvm, |
| 1993 | "Sched scan request was sent successfully\n"); |
| 1994 | } else { |
| 1995 | /* |
| 1996 | * If the scan failed, it usually means that the FW was unable |
| 1997 | * to allocate the time events. Warn on it, but maybe we |
| 1998 | * should try to send the command again with different params. |
| 1999 | */ |
| 2000 | IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret); |
| 2001 | } |
| 2002 | return ret; |
| 2003 | } |
| 2004 | |
| 2005 | int iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm, |
| 2006 | struct iwl_rx_cmd_buffer *rxb, |
| 2007 | struct iwl_device_cmd *cmd) |
| 2008 | { |
| 2009 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 2010 | struct iwl_umac_scan_complete *notif = (void *)pkt->data; |
| 2011 | u32 uid = __le32_to_cpu(notif->uid); |
| 2012 | bool sched = !!(uid & IWL_UMAC_SCAN_UID_SCHED_SCAN); |
| 2013 | int uid_idx = iwl_mvm_find_scan_uid(mvm, uid); |
| 2014 | |
David Spinadel | 2992a32 | 2014-11-10 11:16:53 +0200 | [diff] [blame] | 2015 | /* |
| 2016 | * Scan uid may be set to zero in case of scan abort request from above. |
| 2017 | */ |
| 2018 | if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS) |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2019 | return 0; |
| 2020 | |
| 2021 | IWL_DEBUG_SCAN(mvm, |
| 2022 | "Scan completed, uid %u type %s, status %s, EBS status %s\n", |
| 2023 | uid, sched ? "sched" : "regular", |
| 2024 | notif->status == IWL_SCAN_OFFLOAD_COMPLETED ? |
| 2025 | "completed" : "aborted", |
| 2026 | notif->ebs_status == IWL_SCAN_EBS_SUCCESS ? |
| 2027 | "success" : "failed"); |
| 2028 | |
Haim Dreyfuss | 5a4b2af | 2015-01-13 11:54:51 +0200 | [diff] [blame] | 2029 | if (notif->ebs_status) |
| 2030 | mvm->last_ebs_successful = false; |
| 2031 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2032 | mvm->scan_uid[uid_idx] = 0; |
| 2033 | |
| 2034 | if (!sched) { |
| 2035 | ieee80211_scan_completed(mvm->hw, |
| 2036 | notif->status == |
| 2037 | IWL_SCAN_OFFLOAD_ABORTED); |
| 2038 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 2039 | } else if (!iwl_mvm_find_scan_type(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN)) { |
| 2040 | ieee80211_sched_scan_stopped(mvm->hw); |
| 2041 | } else { |
| 2042 | IWL_DEBUG_SCAN(mvm, "Another sched scan is running\n"); |
| 2043 | } |
| 2044 | |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
| 2048 | static bool iwl_scan_umac_done_check(struct iwl_notif_wait_data *notif_wait, |
| 2049 | struct iwl_rx_packet *pkt, void *data) |
| 2050 | { |
| 2051 | struct iwl_umac_scan_done *scan_done = data; |
| 2052 | struct iwl_umac_scan_complete *notif = (void *)pkt->data; |
| 2053 | u32 uid = __le32_to_cpu(notif->uid); |
| 2054 | int uid_idx = iwl_mvm_find_scan_uid(scan_done->mvm, uid); |
| 2055 | |
| 2056 | if (WARN_ON(pkt->hdr.cmd != SCAN_COMPLETE_UMAC)) |
| 2057 | return false; |
| 2058 | |
| 2059 | if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS) |
| 2060 | return false; |
| 2061 | |
| 2062 | /* |
| 2063 | * Clear scan uid of scans that was aborted from above and completed |
Haim Dreyfuss | 5a4b2af | 2015-01-13 11:54:51 +0200 | [diff] [blame] | 2064 | * in FW so the RX handler does nothing. Set last_ebs_successful here if |
| 2065 | * needed. |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2066 | */ |
| 2067 | scan_done->mvm->scan_uid[uid_idx] = 0; |
| 2068 | |
Haim Dreyfuss | 5a4b2af | 2015-01-13 11:54:51 +0200 | [diff] [blame] | 2069 | if (notif->ebs_status) |
| 2070 | scan_done->mvm->last_ebs_successful = false; |
| 2071 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2072 | return !iwl_mvm_find_scan_type(scan_done->mvm, scan_done->type); |
| 2073 | } |
| 2074 | |
| 2075 | static int iwl_umac_scan_abort_one(struct iwl_mvm *mvm, u32 uid) |
| 2076 | { |
| 2077 | struct iwl_umac_scan_abort cmd = { |
| 2078 | .hdr.size = cpu_to_le16(sizeof(struct iwl_umac_scan_abort) - |
| 2079 | sizeof(struct iwl_mvm_umac_cmd_hdr)), |
| 2080 | .uid = cpu_to_le32(uid), |
| 2081 | }; |
| 2082 | |
| 2083 | lockdep_assert_held(&mvm->mutex); |
| 2084 | |
| 2085 | IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid); |
| 2086 | |
| 2087 | return iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_UMAC, 0, sizeof(cmd), &cmd); |
| 2088 | } |
| 2089 | |
| 2090 | static int iwl_umac_scan_stop(struct iwl_mvm *mvm, |
| 2091 | enum iwl_umac_scan_uid_type type, bool notify) |
| 2092 | { |
| 2093 | struct iwl_notification_wait wait_scan_done; |
| 2094 | static const u8 scan_done_notif[] = { SCAN_COMPLETE_UMAC, }; |
| 2095 | struct iwl_umac_scan_done scan_done = { |
| 2096 | .mvm = mvm, |
| 2097 | .type = type, |
| 2098 | }; |
| 2099 | int i, ret = -EIO; |
| 2100 | |
| 2101 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done, |
| 2102 | scan_done_notif, |
| 2103 | ARRAY_SIZE(scan_done_notif), |
| 2104 | iwl_scan_umac_done_check, &scan_done); |
| 2105 | |
| 2106 | IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type); |
| 2107 | |
| 2108 | for (i = 0; i < IWL_MVM_MAX_SIMULTANEOUS_SCANS; i++) { |
| 2109 | if (mvm->scan_uid[i] & type) { |
| 2110 | int err; |
| 2111 | |
| 2112 | if (iwl_mvm_is_radio_killed(mvm) && |
| 2113 | (type & IWL_UMAC_SCAN_UID_REG_SCAN)) { |
| 2114 | ieee80211_scan_completed(mvm->hw, true); |
| 2115 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 2116 | break; |
| 2117 | } |
| 2118 | |
| 2119 | err = iwl_umac_scan_abort_one(mvm, mvm->scan_uid[i]); |
| 2120 | if (!err) |
| 2121 | ret = 0; |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | if (ret) { |
| 2126 | IWL_DEBUG_SCAN(mvm, "Couldn't stop scan\n"); |
| 2127 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_done); |
| 2128 | return ret; |
| 2129 | } |
| 2130 | |
| 2131 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ); |
| 2132 | if (ret) |
| 2133 | return ret; |
| 2134 | |
| 2135 | if (notify) { |
| 2136 | if (type & IWL_UMAC_SCAN_UID_SCHED_SCAN) |
| 2137 | ieee80211_sched_scan_stopped(mvm->hw); |
| 2138 | if (type & IWL_UMAC_SCAN_UID_REG_SCAN) { |
| 2139 | ieee80211_scan_completed(mvm->hw, true); |
| 2140 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | return ret; |
| 2145 | } |
| 2146 | |
| 2147 | int iwl_mvm_scan_size(struct iwl_mvm *mvm) |
| 2148 | { |
| 2149 | if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) |
| 2150 | return sizeof(struct iwl_scan_req_umac) + |
| 2151 | sizeof(struct iwl_scan_channel_cfg_umac) * |
| 2152 | mvm->fw->ucode_capa.n_scan_channels + |
| 2153 | sizeof(struct iwl_scan_req_umac_tail); |
| 2154 | |
| 2155 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) |
| 2156 | return sizeof(struct iwl_scan_req_unified_lmac) + |
| 2157 | sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 2158 | mvm->fw->ucode_capa.n_scan_channels + |
| 2159 | sizeof(struct iwl_scan_probe_req); |
| 2160 | |
| 2161 | return sizeof(struct iwl_scan_cmd) + |
| 2162 | mvm->fw->ucode_capa.max_probe_length + |
| 2163 | mvm->fw->ucode_capa.n_scan_channels * |
| 2164 | sizeof(struct iwl_scan_channel); |
| 2165 | } |