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 | #include <linux/kernel.h> |
| 66 | #include <linux/slab.h> |
| 67 | #include <linux/skbuff.h> |
| 68 | #include <linux/netdevice.h> |
| 69 | #include <linux/etherdevice.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 70 | #include <linux/ip.h> |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 71 | #include <linux/if_arp.h> |
Johannes Berg | aadede6 | 2014-10-09 17:01:36 +0200 | [diff] [blame] | 72 | #include <linux/devcoredump.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 73 | #include <net/mac80211.h> |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 74 | #include <net/ieee80211_radiotap.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 75 | #include <net/tcp.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 76 | |
| 77 | #include "iwl-op-mode.h" |
| 78 | #include "iwl-io.h" |
| 79 | #include "mvm.h" |
| 80 | #include "sta.h" |
| 81 | #include "time-event.h" |
| 82 | #include "iwl-eeprom-parse.h" |
| 83 | #include "fw-api-scan.h" |
| 84 | #include "iwl-phy-db.h" |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 85 | #include "testmode.h" |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 86 | #include "iwl-fw-error-dump.h" |
| 87 | #include "iwl-prph.h" |
Eran Harary | 363039b | 2014-12-02 15:19:22 +0200 | [diff] [blame] | 88 | #include "iwl-csr.h" |
Arik Nemtsov | 88931cc | 2014-03-05 12:26:15 +0200 | [diff] [blame] | 89 | #include "iwl-nvm-parse.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 90 | |
| 91 | static const struct ieee80211_iface_limit iwl_mvm_limits[] = { |
| 92 | { |
| 93 | .max = 1, |
Ilan Peer | 8eb3871 | 2013-06-01 20:17:18 +0300 | [diff] [blame] | 94 | .types = BIT(NL80211_IFTYPE_STATION), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 95 | }, |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 96 | { |
| 97 | .max = 1, |
Ilan Peer | 8eb3871 | 2013-06-01 20:17:18 +0300 | [diff] [blame] | 98 | .types = BIT(NL80211_IFTYPE_AP) | |
| 99 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 100 | BIT(NL80211_IFTYPE_P2P_GO), |
| 101 | }, |
| 102 | { |
| 103 | .max = 1, |
| 104 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 105 | }, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { |
| 109 | { |
Emmanuel Grumbach | 2624a5c | 2014-12-16 13:02:03 +0200 | [diff] [blame] | 110 | .num_different_channels = 2, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 111 | .max_interfaces = 3, |
| 112 | .limits = iwl_mvm_limits, |
| 113 | .n_limits = ARRAY_SIZE(iwl_mvm_limits), |
| 114 | }, |
| 115 | }; |
| 116 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_PM_SLEEP |
| 118 | static const struct nl80211_wowlan_tcp_data_token_feature |
| 119 | iwl_mvm_wowlan_tcp_token_feature = { |
| 120 | .min_len = 0, |
| 121 | .max_len = 255, |
| 122 | .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS, |
| 123 | }; |
| 124 | |
| 125 | static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = { |
| 126 | .tok = &iwl_mvm_wowlan_tcp_token_feature, |
| 127 | .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN - |
| 128 | sizeof(struct ethhdr) - |
| 129 | sizeof(struct iphdr) - |
| 130 | sizeof(struct tcphdr), |
| 131 | .data_interval_max = 65535, /* __le16 in API */ |
| 132 | .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN - |
| 133 | sizeof(struct ethhdr) - |
| 134 | sizeof(struct iphdr) - |
| 135 | sizeof(struct tcphdr), |
| 136 | .seq = true, |
| 137 | }; |
| 138 | #endif |
| 139 | |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 140 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 141 | /* |
| 142 | * Use the reserved field to indicate magic values. |
| 143 | * these values will only be used internally by the driver, |
| 144 | * and won't make it to the fw (reserved will be 0). |
| 145 | * BC_FILTER_MAGIC_IP - configure the val of this attribute to |
| 146 | * be the vif's ip address. in case there is not a single |
| 147 | * ip address (0, or more than 1), this attribute will |
| 148 | * be skipped. |
| 149 | * BC_FILTER_MAGIC_MAC - set the val of this attribute to |
| 150 | * the LSB bytes of the vif's mac address |
| 151 | */ |
| 152 | enum { |
| 153 | BC_FILTER_MAGIC_NONE = 0, |
| 154 | BC_FILTER_MAGIC_IP, |
| 155 | BC_FILTER_MAGIC_MAC, |
| 156 | }; |
| 157 | |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 158 | static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = { |
| 159 | { |
| 160 | /* arp */ |
| 161 | .discard = 0, |
| 162 | .frame_type = BCAST_FILTER_FRAME_TYPE_ALL, |
| 163 | .attrs = { |
| 164 | { |
| 165 | /* frame type - arp, hw type - ethernet */ |
| 166 | .offset_type = |
| 167 | BCAST_FILTER_OFFSET_PAYLOAD_START, |
| 168 | .offset = sizeof(rfc1042_header), |
| 169 | .val = cpu_to_be32(0x08060001), |
| 170 | .mask = cpu_to_be32(0xffffffff), |
| 171 | }, |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 172 | { |
| 173 | /* arp dest ip */ |
| 174 | .offset_type = |
| 175 | BCAST_FILTER_OFFSET_PAYLOAD_START, |
| 176 | .offset = sizeof(rfc1042_header) + 2 + |
| 177 | sizeof(struct arphdr) + |
| 178 | ETH_ALEN + sizeof(__be32) + |
| 179 | ETH_ALEN, |
| 180 | .mask = cpu_to_be32(0xffffffff), |
| 181 | /* mark it as special field */ |
| 182 | .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP), |
| 183 | }, |
| 184 | }, |
| 185 | }, |
| 186 | { |
| 187 | /* dhcp offer bcast */ |
| 188 | .discard = 0, |
| 189 | .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4, |
| 190 | .attrs = { |
| 191 | { |
| 192 | /* udp dest port - 68 (bootp client)*/ |
| 193 | .offset_type = BCAST_FILTER_OFFSET_IP_END, |
| 194 | .offset = offsetof(struct udphdr, dest), |
| 195 | .val = cpu_to_be32(0x00440000), |
| 196 | .mask = cpu_to_be32(0xffff0000), |
| 197 | }, |
| 198 | { |
| 199 | /* dhcp - lsb bytes of client hw address */ |
| 200 | .offset_type = BCAST_FILTER_OFFSET_IP_END, |
| 201 | .offset = 38, |
| 202 | .mask = cpu_to_be32(0xffffffff), |
| 203 | /* mark it as special field */ |
| 204 | .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC), |
| 205 | }, |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 206 | }, |
| 207 | }, |
| 208 | /* last filter must be empty */ |
| 209 | {}, |
| 210 | }; |
| 211 | #endif |
| 212 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 213 | void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) |
| 214 | { |
Eliad Peller | 7bb426e | 2014-02-24 12:54:37 +0200 | [diff] [blame] | 215 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 216 | return; |
| 217 | |
| 218 | IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 219 | spin_lock_bh(&mvm->refs_lock); |
| 220 | mvm->refs[ref_type]++; |
| 221 | spin_unlock_bh(&mvm->refs_lock); |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 222 | iwl_trans_ref(mvm->trans); |
| 223 | } |
| 224 | |
| 225 | void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) |
| 226 | { |
Eliad Peller | 7bb426e | 2014-02-24 12:54:37 +0200 | [diff] [blame] | 227 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 228 | return; |
| 229 | |
| 230 | IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 231 | spin_lock_bh(&mvm->refs_lock); |
| 232 | WARN_ON(!mvm->refs[ref_type]--); |
| 233 | spin_unlock_bh(&mvm->refs_lock); |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 234 | iwl_trans_unref(mvm->trans); |
| 235 | } |
| 236 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 237 | static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm, |
| 238 | enum iwl_mvm_ref_type except_ref) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 239 | { |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 240 | int i, j; |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 241 | |
Eliad Peller | 7bb426e | 2014-02-24 12:54:37 +0200 | [diff] [blame] | 242 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 243 | return; |
| 244 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 245 | spin_lock_bh(&mvm->refs_lock); |
| 246 | for (i = 0; i < IWL_MVM_REF_COUNT; i++) { |
| 247 | if (except_ref == i || !mvm->refs[i]) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 248 | continue; |
| 249 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 250 | IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n", |
| 251 | i, mvm->refs[i]); |
| 252 | for (j = 0; j < mvm->refs[i]; j++) |
| 253 | iwl_trans_unref(mvm->trans); |
| 254 | mvm->refs[i] = 0; |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 255 | } |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 256 | spin_unlock_bh(&mvm->refs_lock); |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Eliad Peller | f4cf868 | 2014-11-04 16:57:06 +0200 | [diff] [blame] | 259 | bool iwl_mvm_ref_taken(struct iwl_mvm *mvm) |
| 260 | { |
| 261 | int i; |
| 262 | bool taken = false; |
| 263 | |
| 264 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
| 265 | return true; |
| 266 | |
| 267 | spin_lock_bh(&mvm->refs_lock); |
| 268 | for (i = 0; i < IWL_MVM_REF_COUNT; i++) { |
| 269 | if (mvm->refs[i]) { |
| 270 | taken = true; |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | spin_unlock_bh(&mvm->refs_lock); |
| 275 | |
| 276 | return taken; |
| 277 | } |
| 278 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 279 | int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) |
Gregory Greenman | d40fc48 | 2014-06-25 14:08:50 +0200 | [diff] [blame] | 280 | { |
| 281 | iwl_mvm_ref(mvm, ref_type); |
| 282 | |
| 283 | if (!wait_event_timeout(mvm->d0i3_exit_waitq, |
| 284 | !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), |
| 285 | HZ)) { |
| 286 | WARN_ON_ONCE(1); |
| 287 | iwl_mvm_unref(mvm, ref_type); |
| 288 | return -EIO; |
| 289 | } |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 294 | static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) |
| 295 | { |
| 296 | int i; |
| 297 | |
| 298 | memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); |
| 299 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 300 | mvm->phy_ctxts[i].id = i; |
| 301 | mvm->phy_ctxts[i].ref = 0; |
| 302 | } |
| 303 | } |
| 304 | |
Arik Nemtsov | 88931cc | 2014-03-05 12:26:15 +0200 | [diff] [blame] | 305 | struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, |
| 306 | const char *alpha2) |
| 307 | { |
| 308 | struct ieee80211_regdomain *regd = NULL; |
| 309 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 310 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 311 | struct iwl_mcc_update_resp *resp; |
| 312 | |
| 313 | IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); |
| 314 | |
| 315 | mutex_lock(&mvm->mutex); |
| 316 | |
| 317 | /* change "99" to "ZZ" for the FW */ |
| 318 | if (alpha2[0] == '9' && alpha2[1] == '9') |
| 319 | alpha2 = "ZZ"; |
| 320 | |
| 321 | resp = iwl_mvm_update_mcc(mvm, alpha2); |
| 322 | if (IS_ERR_OR_NULL(resp)) { |
| 323 | IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", |
| 324 | PTR_RET(resp)); |
| 325 | goto out_unlock; |
| 326 | } |
| 327 | |
Arik Nemtsov | 162ee3c | 2014-06-10 11:25:35 +0300 | [diff] [blame] | 328 | regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, |
Arik Nemtsov | 88931cc | 2014-03-05 12:26:15 +0200 | [diff] [blame] | 329 | __le32_to_cpu(resp->n_channels), |
| 330 | resp->channels, |
| 331 | __le16_to_cpu(resp->mcc)); |
| 332 | kfree(resp); |
| 333 | if (IS_ERR_OR_NULL(regd)) { |
| 334 | IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", |
| 335 | PTR_RET(resp)); |
| 336 | goto out_unlock; |
| 337 | } |
| 338 | |
| 339 | IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x)\n", |
| 340 | regd->alpha2, regd->alpha2[0], regd->alpha2[1]); |
| 341 | mvm->lar_regdom_set = true; |
| 342 | |
| 343 | out_unlock: |
| 344 | mutex_unlock(&mvm->mutex); |
| 345 | return regd; |
| 346 | } |
| 347 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 348 | int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) |
| 349 | { |
| 350 | struct ieee80211_hw *hw = mvm->hw; |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 351 | int num_mac, ret, i; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 352 | |
| 353 | /* Tell mac80211 our characteristics */ |
| 354 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 355 | IEEE80211_HW_SPECTRUM_MGMT | |
| 356 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 357 | IEEE80211_HW_QUEUE_CONTROL | |
| 358 | IEEE80211_HW_WANT_MONITOR_VIF | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 359 | IEEE80211_HW_SUPPORTS_PS | |
| 360 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Johannes Berg | d2931bb | 2013-02-05 18:10:04 +0100 | [diff] [blame] | 361 | IEEE80211_HW_AMPDU_AGGREGATION | |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 362 | IEEE80211_HW_TIMING_BEACON_ONLY | |
Emmanuel Grumbach | 147fc9b | 2013-07-28 11:00:52 +0300 | [diff] [blame] | 363 | IEEE80211_HW_CONNECTION_MONITOR | |
Ido Yariv | b71d9c8 | 2014-07-23 09:31:14 -0400 | [diff] [blame] | 364 | IEEE80211_HW_CHANCTX_STA_CSA | |
| 365 | IEEE80211_HW_SUPPORTS_CLONED_SKBS; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 366 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 367 | hw->queues = mvm->first_agg_queue; |
Ilan Peer | 398e8c6 | 2013-03-13 15:20:35 +0200 | [diff] [blame] | 368 | hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 369 | hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | |
| 370 | IEEE80211_RADIOTAP_MCS_HAVE_STBC; |
Eyal Shapira | 339b308 | 2014-11-18 16:43:55 +0200 | [diff] [blame] | 371 | hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | |
| 372 | IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 373 | hw->rate_control_algorithm = "iwl-mvm-rs"; |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 374 | hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; |
| 375 | hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 376 | |
| 377 | /* |
| 378 | * Enable 11w if advertised by firmware and software crypto |
| 379 | * is not enabled (as the firmware will interpret some mgmt |
| 380 | * packets, so enabling it with software crypto isn't safe) |
| 381 | */ |
| 382 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP && |
| 383 | !iwlwifi_mod_params.sw_crypto) |
| 384 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; |
| 385 | |
Luciano Coelho | 1f94038 | 2015-02-10 13:03:38 +0200 | [diff] [blame] | 386 | hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS; |
| 387 | hw->wiphy->features |= |
| 388 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | |
| 389 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 390 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 391 | hw->sta_data_size = sizeof(struct iwl_mvm_sta); |
| 392 | hw->vif_data_size = sizeof(struct iwl_mvm_vif); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 393 | hw->chanctx_data_size = sizeof(u16); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 394 | |
| 395 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 396 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 397 | BIT(NL80211_IFTYPE_AP) | |
| 398 | BIT(NL80211_IFTYPE_P2P_GO) | |
Emmanuel Grumbach | c13b172 | 2014-03-27 19:12:12 +0200 | [diff] [blame] | 399 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
| 400 | BIT(NL80211_IFTYPE_ADHOC); |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 401 | |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 402 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
| 403 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | |
| 404 | REGULATORY_DISABLE_BEACON_HINTS; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 405 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 406 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD) |
| 407 | hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
| 408 | |
Emmanuel Grumbach | 94bbed7 | 2014-11-24 08:53:33 +0200 | [diff] [blame] | 409 | hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 410 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 411 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; |
| 412 | hw->wiphy->n_iface_combinations = |
| 413 | ARRAY_SIZE(iwl_mvm_iface_combinations); |
| 414 | |
Ilan Peer | c451e6d | 2013-02-20 08:41:54 +0200 | [diff] [blame] | 415 | hw->wiphy->max_remain_on_channel_duration = 10000; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 416 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
Emmanuel Grumbach | f1a6854 | 2014-12-16 12:31:13 +0200 | [diff] [blame] | 417 | /* we can compensate an offset of up to 3 channels = 15 MHz */ |
| 418 | hw->wiphy->max_adj_channel_rssi_comp = 3 * 5; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 419 | |
| 420 | /* Extract MAC address */ |
| 421 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); |
| 422 | hw->wiphy->addresses = mvm->addresses; |
| 423 | hw->wiphy->n_addresses = 1; |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 424 | |
| 425 | /* Extract additional MAC addresses if available */ |
| 426 | num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? |
| 427 | min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; |
| 428 | |
| 429 | for (i = 1; i < num_mac; i++) { |
| 430 | memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 431 | ETH_ALEN); |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 432 | mvm->addresses[i].addr[5]++; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 433 | hw->wiphy->n_addresses++; |
| 434 | } |
| 435 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 436 | iwl_mvm_reset_phy_ctxts(mvm); |
| 437 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 438 | hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false); |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 439 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 440 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
| 441 | |
| 442 | if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 443 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 444 | &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 445 | if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 446 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 447 | &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; |
| 448 | |
Eyal Shapira | 3d44eeb | 2015-01-16 22:37:04 +0200 | [diff] [blame] | 449 | if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_BEAMFORMER) |
| 450 | hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |= |
| 451 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; |
| 452 | } |
| 453 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 454 | hw->wiphy->hw_version = mvm->trans->hw_id; |
| 455 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 456 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 457 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 458 | else |
| 459 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 460 | |
Emmanuel Grumbach | 6efaaf3 | 2014-09-01 10:03:21 +0300 | [diff] [blame] | 461 | if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) { |
| 462 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 463 | hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; |
| 464 | hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; |
| 465 | /* we create the 802.11 header and zero length SSID IE. */ |
| 466 | hw->wiphy->max_sched_scan_ie_len = |
| 467 | SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; |
| 468 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 469 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 470 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 471 | NL80211_FEATURE_LOW_PRIORITY_SCAN | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 472 | NL80211_FEATURE_P2P_GO_OPPPS | |
| 473 | NL80211_FEATURE_DYNAMIC_SMPS | |
Emmanuel Grumbach | 9b5452f | 2014-10-07 10:38:53 +0300 | [diff] [blame] | 474 | NL80211_FEATURE_STATIC_SMPS | |
| 475 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 476 | |
Andrei Otcheretianski | f1daa00 | 2014-07-01 12:54:25 +0300 | [diff] [blame] | 477 | if (mvm->fw->ucode_capa.capa[0] & |
| 478 | IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT) |
| 479 | hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; |
Assaf Krauss | 226bcd4 | 2014-03-13 08:12:15 +0200 | [diff] [blame] | 480 | if (mvm->fw->ucode_capa.capa[0] & |
| 481 | IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT) |
| 482 | hw->wiphy->features |= NL80211_FEATURE_QUIET; |
Andrei Otcheretianski | f1daa00 | 2014-07-01 12:54:25 +0300 | [diff] [blame] | 483 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 484 | if (mvm->fw->ucode_capa.capa[0] & |
| 485 | IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT) |
| 486 | hw->wiphy->features |= |
| 487 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; |
| 488 | |
| 489 | if (mvm->fw->ucode_capa.capa[0] & |
| 490 | IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT) |
| 491 | hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; |
| 492 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 493 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 494 | |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 495 | /* currently FW API supports only one optional cipher scheme */ |
Johannes Berg | 9ddca86 | 2014-01-06 09:29:40 +0100 | [diff] [blame] | 496 | if (mvm->fw->cs[0].cipher) { |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 497 | mvm->hw->n_cipher_schemes = 1; |
Johannes Berg | 9ddca86 | 2014-01-06 09:29:40 +0100 | [diff] [blame] | 498 | mvm->hw->cipher_schemes = &mvm->fw->cs[0]; |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 499 | } |
| 500 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 501 | #ifdef CONFIG_PM_SLEEP |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 502 | if (iwl_mvm_is_d0i3_supported(mvm) && |
| 503 | device_can_wakeup(mvm->trans->dev)) { |
| 504 | mvm->wowlan.flags = WIPHY_WOWLAN_ANY; |
| 505 | hw->wiphy->wowlan = &mvm->wowlan; |
Eliad Peller | 9174244 | 2014-12-09 15:54:46 +0200 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len && |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 509 | mvm->trans->ops->d3_suspend && |
| 510 | mvm->trans->ops->d3_resume && |
| 511 | device_can_wakeup(mvm->trans->dev)) { |
Eliad Peller | 9174244 | 2014-12-09 15:54:46 +0200 | [diff] [blame] | 512 | mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | |
| 513 | WIPHY_WOWLAN_DISCONNECT | |
| 514 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | |
| 515 | WIPHY_WOWLAN_RFKILL_RELEASE | |
| 516 | WIPHY_WOWLAN_NET_DETECT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 517 | if (!iwlwifi_mod_params.sw_crypto) |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 518 | mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
| 519 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | |
| 520 | WIPHY_WOWLAN_4WAY_HANDSHAKE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 521 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 522 | mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; |
| 523 | mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; |
| 524 | mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; |
Luciano Coelho | c55385f | 2014-10-24 10:39:51 +0300 | [diff] [blame] | 525 | mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 526 | mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support; |
| 527 | hw->wiphy->wowlan = &mvm->wowlan; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 528 | } |
| 529 | #endif |
| 530 | |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 531 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 532 | /* assign default bcast filtering configuration */ |
| 533 | mvm->bcast_filters = iwl_mvm_default_bcast_filters; |
| 534 | #endif |
| 535 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 536 | ret = iwl_mvm_leds_init(mvm); |
| 537 | if (ret) |
| 538 | return ret; |
| 539 | |
Arik Nemtsov | d8f1c51 | 2014-05-11 18:13:04 +0300 | [diff] [blame] | 540 | if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) { |
| 541 | IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); |
| 542 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
| 543 | } |
| 544 | |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 545 | if (mvm->fw->ucode_capa.capa[0] & |
| 546 | IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) { |
| 547 | IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); |
| 548 | hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; |
| 549 | } |
| 550 | |
Emmanuel Grumbach | b7327d8 | 2013-06-24 15:44:03 +0300 | [diff] [blame] | 551 | ret = ieee80211_register_hw(mvm->hw); |
| 552 | if (ret) |
| 553 | iwl_mvm_leds_exit(mvm); |
| 554 | |
| 555 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 556 | } |
| 557 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 558 | static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm, |
| 559 | struct ieee80211_sta *sta, |
| 560 | struct sk_buff *skb) |
| 561 | { |
| 562 | struct iwl_mvm_sta *mvmsta; |
| 563 | bool defer = false; |
| 564 | |
| 565 | /* |
| 566 | * double check the IN_D0I3 flag both before and after |
| 567 | * taking the spinlock, in order to prevent taking |
| 568 | * the spinlock when not needed. |
| 569 | */ |
| 570 | if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))) |
| 571 | return false; |
| 572 | |
| 573 | spin_lock(&mvm->d0i3_tx_lock); |
| 574 | /* |
| 575 | * testing the flag again ensures the skb dequeue |
| 576 | * loop (on d0i3 exit) hasn't run yet. |
| 577 | */ |
| 578 | if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) |
| 579 | goto out; |
| 580 | |
| 581 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 582 | if (mvmsta->sta_id == IWL_MVM_STATION_COUNT || |
| 583 | mvmsta->sta_id != mvm->d0i3_ap_sta_id) |
| 584 | goto out; |
| 585 | |
| 586 | __skb_queue_tail(&mvm->d0i3_tx, skb); |
| 587 | ieee80211_stop_queues(mvm->hw); |
| 588 | |
| 589 | /* trigger wakeup */ |
| 590 | iwl_mvm_ref(mvm, IWL_MVM_REF_TX); |
| 591 | iwl_mvm_unref(mvm, IWL_MVM_REF_TX); |
| 592 | |
| 593 | defer = true; |
| 594 | out: |
| 595 | spin_unlock(&mvm->d0i3_tx_lock); |
| 596 | return defer; |
| 597 | } |
| 598 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 599 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, |
| 600 | struct ieee80211_tx_control *control, |
| 601 | struct sk_buff *skb) |
| 602 | { |
| 603 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 604 | struct ieee80211_sta *sta = control->sta; |
| 605 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 606 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 607 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 608 | if (iwl_mvm_is_radio_killed(mvm)) { |
| 609 | IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 610 | goto drop; |
| 611 | } |
| 612 | |
Ilan Peer | 398e8c6 | 2013-03-13 15:20:35 +0200 | [diff] [blame] | 613 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && |
Matti Gottlieb | a6cc516 | 2014-09-29 11:46:04 +0300 | [diff] [blame] | 614 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && |
| 615 | !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 616 | goto drop; |
| 617 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 618 | /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */ |
| 619 | if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER && |
| 620 | ieee80211_is_mgmt(hdr->frame_control) && |
| 621 | !ieee80211_is_deauth(hdr->frame_control) && |
| 622 | !ieee80211_is_disassoc(hdr->frame_control) && |
| 623 | !ieee80211_is_action(hdr->frame_control))) |
| 624 | sta = NULL; |
| 625 | |
| 626 | if (sta) { |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 627 | if (iwl_mvm_defer_tx(mvm, sta, skb)) |
| 628 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 629 | if (iwl_mvm_tx_skb(mvm, skb, sta)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 630 | goto drop; |
| 631 | return; |
| 632 | } |
| 633 | |
| 634 | if (iwl_mvm_tx_skb_non_sta(mvm, skb)) |
| 635 | goto drop; |
| 636 | return; |
| 637 | drop: |
| 638 | ieee80211_free_txskb(hw, skb); |
| 639 | } |
| 640 | |
Emmanuel Grumbach | 205e221 | 2014-02-12 15:15:05 +0200 | [diff] [blame] | 641 | static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg) |
| 642 | { |
| 643 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) |
| 644 | return false; |
| 645 | return true; |
| 646 | } |
| 647 | |
| 648 | static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg) |
| 649 | { |
| 650 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) |
| 651 | return false; |
| 652 | if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG) |
| 653 | return true; |
| 654 | |
| 655 | /* enabled by default */ |
| 656 | return true; |
| 657 | } |
| 658 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 659 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, |
| 660 | struct ieee80211_vif *vif, |
| 661 | enum ieee80211_ampdu_mlme_action action, |
| 662 | struct ieee80211_sta *sta, u16 tid, |
| 663 | u16 *ssn, u8 buf_size) |
| 664 | { |
| 665 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 666 | int ret; |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 667 | bool tx_agg_ref = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 668 | |
| 669 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", |
| 670 | sta->addr, tid, action); |
| 671 | |
| 672 | if (!(mvm->nvm_data->sku_cap_11n_enable)) |
| 673 | return -EACCES; |
| 674 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 675 | /* return from D0i3 before starting a new Tx aggregation */ |
Eliad Peller | 9256c20 | 2014-04-22 13:33:29 +0300 | [diff] [blame] | 676 | switch (action) { |
| 677 | case IEEE80211_AMPDU_TX_START: |
| 678 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 679 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 680 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 681 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 682 | /* |
Eliad Peller | 9256c20 | 2014-04-22 13:33:29 +0300 | [diff] [blame] | 683 | * for tx start, wait synchronously until D0i3 exit to |
| 684 | * get the correct sequence number for the tid. |
| 685 | * additionally, some other ampdu actions use direct |
| 686 | * target access, which is not handled automatically |
| 687 | * by the trans layer (unlike commands), so wait for |
| 688 | * d0i3 exit in these cases as well. |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 689 | */ |
Gregory Greenman | d40fc48 | 2014-06-25 14:08:50 +0200 | [diff] [blame] | 690 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG); |
| 691 | if (ret) |
| 692 | return ret; |
| 693 | |
| 694 | tx_agg_ref = true; |
Eliad Peller | 9256c20 | 2014-04-22 13:33:29 +0300 | [diff] [blame] | 695 | break; |
| 696 | default: |
| 697 | break; |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 698 | } |
| 699 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 700 | mutex_lock(&mvm->mutex); |
| 701 | |
| 702 | switch (action) { |
| 703 | case IEEE80211_AMPDU_RX_START: |
Emmanuel Grumbach | 205e221 | 2014-02-12 15:15:05 +0200 | [diff] [blame] | 704 | if (!iwl_enable_rx_ampdu(mvm->cfg)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 705 | ret = -EINVAL; |
| 706 | break; |
| 707 | } |
| 708 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true); |
| 709 | break; |
| 710 | case IEEE80211_AMPDU_RX_STOP: |
| 711 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false); |
| 712 | break; |
| 713 | case IEEE80211_AMPDU_TX_START: |
Emmanuel Grumbach | 205e221 | 2014-02-12 15:15:05 +0200 | [diff] [blame] | 714 | if (!iwl_enable_tx_ampdu(mvm->cfg)) { |
Emmanuel Grumbach | 5d158ef | 2013-02-19 14:39:58 +0200 | [diff] [blame] | 715 | ret = -EINVAL; |
| 716 | break; |
| 717 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 718 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
| 719 | break; |
| 720 | case IEEE80211_AMPDU_TX_STOP_CONT: |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 721 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
| 722 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 723 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 724 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 725 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 726 | break; |
| 727 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 728 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size); |
| 729 | break; |
| 730 | default: |
| 731 | WARN_ON_ONCE(1); |
| 732 | ret = -EINVAL; |
| 733 | break; |
| 734 | } |
| 735 | mutex_unlock(&mvm->mutex); |
| 736 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 737 | /* |
| 738 | * If the tid is marked as started, we won't use it for offloaded |
| 739 | * traffic on the next D0i3 entry. It's safe to unref. |
| 740 | */ |
| 741 | if (tx_agg_ref) |
| 742 | iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG); |
| 743 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 744 | return ret; |
| 745 | } |
| 746 | |
| 747 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, |
| 748 | struct ieee80211_vif *vif) |
| 749 | { |
| 750 | struct iwl_mvm *mvm = data; |
| 751 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 752 | |
| 753 | mvmvif->uploaded = false; |
| 754 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 755 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 756 | spin_lock_bh(&mvm->time_event_lock); |
| 757 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); |
| 758 | spin_unlock_bh(&mvm->time_event_lock); |
| 759 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 760 | mvmvif->phy_ctxt = NULL; |
Emmanuel Grumbach | 8a275ba | 2014-07-13 09:12:11 +0300 | [diff] [blame] | 761 | memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Johannes Berg | aadede6 | 2014-10-09 17:01:36 +0200 | [diff] [blame] | 764 | static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count, |
| 765 | const void *data, size_t datalen) |
| 766 | { |
| 767 | const struct iwl_mvm_dump_ptrs *dump_ptrs = data; |
| 768 | ssize_t bytes_read; |
| 769 | ssize_t bytes_read_trans; |
| 770 | |
| 771 | if (offset < dump_ptrs->op_mode_len) { |
| 772 | bytes_read = min_t(ssize_t, count, |
| 773 | dump_ptrs->op_mode_len - offset); |
| 774 | memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset, |
| 775 | bytes_read); |
| 776 | offset += bytes_read; |
| 777 | count -= bytes_read; |
| 778 | |
| 779 | if (count == 0) |
| 780 | return bytes_read; |
| 781 | } else { |
| 782 | bytes_read = 0; |
| 783 | } |
| 784 | |
| 785 | if (!dump_ptrs->trans_ptr) |
| 786 | return bytes_read; |
| 787 | |
| 788 | offset -= dump_ptrs->op_mode_len; |
| 789 | bytes_read_trans = min_t(ssize_t, count, |
| 790 | dump_ptrs->trans_ptr->len - offset); |
| 791 | memcpy(buffer + bytes_read, |
| 792 | (u8 *)dump_ptrs->trans_ptr->data + offset, |
| 793 | bytes_read_trans); |
| 794 | |
| 795 | return bytes_read + bytes_read_trans; |
| 796 | } |
| 797 | |
| 798 | static void iwl_mvm_free_coredump(const void *data) |
| 799 | { |
| 800 | const struct iwl_mvm_dump_ptrs *fw_error_dump = data; |
| 801 | |
| 802 | vfree(fw_error_dump->op_mode_ptr); |
| 803 | vfree(fw_error_dump->trans_ptr); |
| 804 | kfree(fw_error_dump); |
| 805 | } |
| 806 | |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 807 | static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm, |
| 808 | struct iwl_fw_error_dump_data **dump_data) |
| 809 | { |
| 810 | struct iwl_fw_error_dump_fifo *fifo_hdr; |
| 811 | u32 *fifo_data; |
| 812 | u32 fifo_len; |
| 813 | unsigned long flags; |
| 814 | int i, j; |
| 815 | |
| 816 | if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags)) |
| 817 | return; |
| 818 | |
| 819 | /* Pull RXF data from all RXFs */ |
| 820 | for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) { |
| 821 | /* |
| 822 | * Keep aside the additional offset that might be needed for |
| 823 | * next RXF |
| 824 | */ |
| 825 | u32 offset_diff = RXF_DIFF_FROM_PREV * i; |
| 826 | |
| 827 | fifo_hdr = (void *)(*dump_data)->data; |
| 828 | fifo_data = (void *)fifo_hdr->data; |
| 829 | fifo_len = mvm->shared_mem_cfg.rxfifo_size[i]; |
| 830 | |
| 831 | /* No need to try to read the data if the length is 0 */ |
| 832 | if (fifo_len == 0) |
| 833 | continue; |
| 834 | |
| 835 | /* Add a TLV for the RXF */ |
| 836 | (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF); |
| 837 | (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr)); |
| 838 | |
| 839 | fifo_hdr->fifo_num = cpu_to_le32(i); |
| 840 | fifo_hdr->available_bytes = |
| 841 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 842 | RXF_RD_D_SPACE + |
| 843 | offset_diff)); |
| 844 | fifo_hdr->wr_ptr = |
| 845 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 846 | RXF_RD_WR_PTR + |
| 847 | offset_diff)); |
| 848 | fifo_hdr->rd_ptr = |
| 849 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 850 | RXF_RD_RD_PTR + |
| 851 | offset_diff)); |
| 852 | fifo_hdr->fence_ptr = |
| 853 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 854 | RXF_RD_FENCE_PTR + |
| 855 | offset_diff)); |
| 856 | fifo_hdr->fence_mode = |
| 857 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 858 | RXF_SET_FENCE_MODE + |
| 859 | offset_diff)); |
| 860 | |
| 861 | /* Lock fence */ |
| 862 | iwl_trans_write_prph(mvm->trans, |
| 863 | RXF_SET_FENCE_MODE + offset_diff, 0x1); |
| 864 | /* Set fence pointer to the same place like WR pointer */ |
| 865 | iwl_trans_write_prph(mvm->trans, |
| 866 | RXF_LD_WR2FENCE + offset_diff, 0x1); |
| 867 | /* Set fence offset */ |
| 868 | iwl_trans_write_prph(mvm->trans, |
| 869 | RXF_LD_FENCE_OFFSET_ADDR + offset_diff, |
| 870 | 0x0); |
| 871 | |
| 872 | /* Read FIFO */ |
| 873 | fifo_len /= sizeof(u32); /* Size in DWORDS */ |
| 874 | for (j = 0; j < fifo_len; j++) |
| 875 | fifo_data[j] = iwl_trans_read_prph(mvm->trans, |
| 876 | RXF_FIFO_RD_FENCE_INC + |
| 877 | offset_diff); |
| 878 | *dump_data = iwl_fw_error_next_data(*dump_data); |
| 879 | } |
| 880 | |
| 881 | /* Pull TXF data from all TXFs */ |
| 882 | for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) { |
| 883 | /* Mark the number of TXF we're pulling now */ |
| 884 | iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i); |
| 885 | |
| 886 | fifo_hdr = (void *)(*dump_data)->data; |
| 887 | fifo_data = (void *)fifo_hdr->data; |
| 888 | fifo_len = mvm->shared_mem_cfg.txfifo_size[i]; |
| 889 | |
| 890 | /* No need to try to read the data if the length is 0 */ |
| 891 | if (fifo_len == 0) |
| 892 | continue; |
| 893 | |
| 894 | /* Add a TLV for the FIFO */ |
| 895 | (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF); |
| 896 | (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr)); |
| 897 | |
| 898 | fifo_hdr->fifo_num = cpu_to_le32(i); |
| 899 | fifo_hdr->available_bytes = |
| 900 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 901 | TXF_FIFO_ITEM_CNT)); |
| 902 | fifo_hdr->wr_ptr = |
| 903 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 904 | TXF_WR_PTR)); |
| 905 | fifo_hdr->rd_ptr = |
| 906 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 907 | TXF_RD_PTR)); |
| 908 | fifo_hdr->fence_ptr = |
| 909 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 910 | TXF_FENCE_PTR)); |
| 911 | fifo_hdr->fence_mode = |
| 912 | cpu_to_le32(iwl_trans_read_prph(mvm->trans, |
| 913 | TXF_LOCK_FENCE)); |
| 914 | |
| 915 | /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */ |
| 916 | iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR, |
| 917 | TXF_WR_PTR); |
| 918 | |
| 919 | /* Dummy-read to advance the read pointer to the head */ |
| 920 | iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA); |
| 921 | |
| 922 | /* Read FIFO */ |
| 923 | fifo_len /= sizeof(u32); /* Size in DWORDS */ |
| 924 | for (j = 0; j < fifo_len; j++) |
| 925 | fifo_data[j] = iwl_trans_read_prph(mvm->trans, |
| 926 | TXF_READ_MODIFY_DATA); |
| 927 | *dump_data = iwl_fw_error_next_data(*dump_data); |
| 928 | } |
| 929 | |
| 930 | iwl_trans_release_nic_access(mvm->trans, &flags); |
| 931 | } |
| 932 | |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 933 | void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm) |
| 934 | { |
| 935 | if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert || |
| 936 | !mvm->fw_dump_desc) |
| 937 | return; |
| 938 | |
| 939 | kfree(mvm->fw_dump_desc); |
| 940 | mvm->fw_dump_desc = NULL; |
| 941 | } |
| 942 | |
Emmanuel Grumbach | 4bfa47f | 2014-09-11 16:19:43 +0300 | [diff] [blame] | 943 | void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm) |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 944 | { |
| 945 | struct iwl_fw_error_dump_file *dump_file; |
| 946 | struct iwl_fw_error_dump_data *dump_data; |
| 947 | struct iwl_fw_error_dump_info *dump_info; |
Emmanuel Grumbach | a549b29 | 2014-12-09 14:47:57 +0200 | [diff] [blame] | 948 | struct iwl_fw_error_dump_mem *dump_mem; |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 949 | struct iwl_fw_error_dump_trigger_desc *dump_trig; |
Emmanuel Grumbach | 48eb7b3 | 2014-07-08 19:45:17 +0300 | [diff] [blame] | 950 | struct iwl_mvm_dump_ptrs *fw_error_dump; |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 951 | u32 sram_len, sram_ofs; |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 952 | u32 file_len, fifo_data_len = 0; |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 953 | u32 smem_len = mvm->cfg->smem_len; |
Ido Yariv | 8613832 | 2014-12-10 12:39:27 -0500 | [diff] [blame] | 954 | u32 sram2_len = mvm->cfg->dccm2_len; |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 955 | |
| 956 | lockdep_assert_held(&mvm->mutex); |
| 957 | |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 958 | /* W/A for 8000 HW family A-step */ |
Ido Yariv | 8613832 | 2014-12-10 12:39:27 -0500 | [diff] [blame] | 959 | if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 && |
| 960 | CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) { |
| 961 | if (smem_len) |
| 962 | smem_len = 0x38000; |
| 963 | |
| 964 | if (sram2_len) |
| 965 | sram2_len = 0x10000; |
| 966 | } |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 967 | |
Johannes Berg | aadede6 | 2014-10-09 17:01:36 +0200 | [diff] [blame] | 968 | fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL); |
Emmanuel Grumbach | 48eb7b3 | 2014-07-08 19:45:17 +0300 | [diff] [blame] | 969 | if (!fw_error_dump) |
| 970 | return; |
| 971 | |
Liad Kaufman | f53bf4c | 2014-12-01 10:44:18 +0200 | [diff] [blame] | 972 | /* SRAM - include stack CCM if driver knows the values for it */ |
| 973 | if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) { |
| 974 | const struct fw_img *img; |
| 975 | |
| 976 | img = &mvm->fw->img[mvm->cur_ucode]; |
| 977 | sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 978 | sram_len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 979 | } else { |
| 980 | sram_ofs = mvm->cfg->dccm_offset; |
| 981 | sram_len = mvm->cfg->dccm_len; |
| 982 | } |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 983 | |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 984 | /* reading RXF/TXF sizes */ |
| 985 | if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) { |
| 986 | struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg; |
| 987 | int i; |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 988 | |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 989 | fifo_data_len = 0; |
| 990 | |
| 991 | /* Count RXF size */ |
| 992 | for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) { |
| 993 | if (!mem_cfg->rxfifo_size[i]) |
| 994 | continue; |
| 995 | |
| 996 | /* Add header info */ |
| 997 | fifo_data_len += mem_cfg->rxfifo_size[i] + |
| 998 | sizeof(*dump_data) + |
| 999 | sizeof(struct iwl_fw_error_dump_fifo); |
| 1000 | } |
| 1001 | |
| 1002 | for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) { |
| 1003 | if (!mem_cfg->txfifo_size[i]) |
| 1004 | continue; |
| 1005 | |
| 1006 | /* Add header info */ |
| 1007 | fifo_data_len += mem_cfg->txfifo_size[i] + |
| 1008 | sizeof(*dump_data) + |
| 1009 | sizeof(struct iwl_fw_error_dump_fifo); |
| 1010 | } |
| 1011 | } |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1012 | |
| 1013 | file_len = sizeof(*dump_file) + |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 1014 | sizeof(*dump_data) * 2 + |
Emmanuel Grumbach | a549b29 | 2014-12-09 14:47:57 +0200 | [diff] [blame] | 1015 | sram_len + sizeof(*dump_mem) + |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 1016 | fifo_data_len + |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1017 | sizeof(*dump_info); |
| 1018 | |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 1019 | if (mvm->fw_dump_desc) |
| 1020 | file_len += sizeof(*dump_data) + sizeof(*dump_trig) + |
| 1021 | mvm->fw_dump_desc->len; |
| 1022 | |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 1023 | /* Make room for the SMEM, if it exists */ |
| 1024 | if (smem_len) |
Emmanuel Grumbach | a549b29 | 2014-12-09 14:47:57 +0200 | [diff] [blame] | 1025 | file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len; |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 1026 | |
Ido Yariv | 8613832 | 2014-12-10 12:39:27 -0500 | [diff] [blame] | 1027 | /* Make room for the secondary SRAM, if it exists */ |
| 1028 | if (sram2_len) |
| 1029 | file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len; |
| 1030 | |
Emmanuel Grumbach | 5bfe6f5 | 2014-06-25 16:21:43 +0300 | [diff] [blame] | 1031 | dump_file = vzalloc(file_len); |
Emmanuel Grumbach | 48eb7b3 | 2014-07-08 19:45:17 +0300 | [diff] [blame] | 1032 | if (!dump_file) { |
| 1033 | kfree(fw_error_dump); |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 1034 | iwl_mvm_free_fw_dump_desc(mvm); |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1035 | return; |
Emmanuel Grumbach | 48eb7b3 | 2014-07-08 19:45:17 +0300 | [diff] [blame] | 1036 | } |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1037 | |
Emmanuel Grumbach | 48eb7b3 | 2014-07-08 19:45:17 +0300 | [diff] [blame] | 1038 | fw_error_dump->op_mode_ptr = dump_file; |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1039 | |
| 1040 | dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER); |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1041 | dump_data = (void *)dump_file->data; |
| 1042 | |
| 1043 | dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO); |
| 1044 | dump_data->len = cpu_to_le32(sizeof(*dump_info)); |
| 1045 | dump_info = (void *) dump_data->data; |
| 1046 | dump_info->device_family = |
| 1047 | mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ? |
| 1048 | cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) : |
| 1049 | cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8); |
Ido Yariv | 435da2c | 2014-12-11 16:11:01 -0500 | [diff] [blame] | 1050 | dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev)); |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1051 | memcpy(dump_info->fw_human_readable, mvm->fw->human_readable, |
| 1052 | sizeof(dump_info->fw_human_readable)); |
| 1053 | strncpy(dump_info->dev_human_readable, mvm->cfg->name, |
| 1054 | sizeof(dump_info->dev_human_readable)); |
| 1055 | strncpy(dump_info->bus_human_readable, mvm->dev->bus->name, |
| 1056 | sizeof(dump_info->bus_human_readable)); |
| 1057 | |
| 1058 | dump_data = iwl_fw_error_next_data(dump_data); |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 1059 | /* We only dump the FIFOs if the FW is in error state */ |
| 1060 | if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) |
| 1061 | iwl_mvm_dump_fifos(mvm, &dump_data); |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1062 | |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 1063 | if (mvm->fw_dump_desc) { |
| 1064 | dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO); |
| 1065 | dump_data->len = cpu_to_le32(sizeof(*dump_trig) + |
| 1066 | mvm->fw_dump_desc->len); |
| 1067 | dump_trig = (void *)dump_data->data; |
| 1068 | memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc, |
| 1069 | sizeof(*dump_trig) + mvm->fw_dump_desc->len); |
| 1070 | |
| 1071 | /* now we can free this copy */ |
| 1072 | iwl_mvm_free_fw_dump_desc(mvm); |
| 1073 | dump_data = iwl_fw_error_next_data(dump_data); |
| 1074 | } |
| 1075 | |
Emmanuel Grumbach | a549b29 | 2014-12-09 14:47:57 +0200 | [diff] [blame] | 1076 | dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM); |
| 1077 | dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem)); |
| 1078 | dump_mem = (void *)dump_data->data; |
| 1079 | dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM); |
| 1080 | dump_mem->offset = cpu_to_le32(sram_ofs); |
| 1081 | iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data, |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1082 | sram_len); |
| 1083 | |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 1084 | if (smem_len) { |
| 1085 | dump_data = iwl_fw_error_next_data(dump_data); |
Emmanuel Grumbach | e06d843 | 2014-12-09 14:36:41 +0200 | [diff] [blame] | 1086 | dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM); |
| 1087 | dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem)); |
| 1088 | dump_mem = (void *)dump_data->data; |
| 1089 | dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM); |
| 1090 | dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset); |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 1091 | iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset, |
Emmanuel Grumbach | e06d843 | 2014-12-09 14:36:41 +0200 | [diff] [blame] | 1092 | dump_mem->data, smem_len); |
Liad Kaufman | addfaad | 2014-12-02 11:16:04 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
Ido Yariv | 8613832 | 2014-12-10 12:39:27 -0500 | [diff] [blame] | 1095 | if (sram2_len) { |
| 1096 | dump_data = iwl_fw_error_next_data(dump_data); |
| 1097 | dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM); |
| 1098 | dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem)); |
| 1099 | dump_mem = (void *)dump_data->data; |
| 1100 | dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM); |
| 1101 | dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset); |
| 1102 | iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset, |
| 1103 | dump_mem->data, sram2_len); |
| 1104 | } |
| 1105 | |
Emmanuel Grumbach | 48eb7b3 | 2014-07-08 19:45:17 +0300 | [diff] [blame] | 1106 | fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans); |
| 1107 | fw_error_dump->op_mode_len = file_len; |
| 1108 | if (fw_error_dump->trans_ptr) |
| 1109 | file_len += fw_error_dump->trans_ptr->len; |
| 1110 | dump_file->file_len = cpu_to_le32(file_len); |
Emmanuel Grumbach | 4bfa47f | 2014-09-11 16:19:43 +0300 | [diff] [blame] | 1111 | |
Johannes Berg | aadede6 | 2014-10-09 17:01:36 +0200 | [diff] [blame] | 1112 | dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0, |
| 1113 | GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump); |
Emmanuel Grumbach | d2709ad | 2015-01-29 14:58:06 +0200 | [diff] [blame] | 1114 | |
| 1115 | clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status); |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1116 | } |
Emmanuel Grumbach | 655e6d6 | 2014-06-25 14:08:58 +0300 | [diff] [blame] | 1117 | |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 1118 | struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = { |
| 1119 | .trig_desc = { |
| 1120 | .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT), |
| 1121 | }, |
| 1122 | }; |
| 1123 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1124 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) |
| 1125 | { |
Johannes Berg | 58629d9 | 2014-11-06 09:40:50 +0100 | [diff] [blame] | 1126 | /* clear the D3 reconfig, we only need it to avoid dumping a |
| 1127 | * firmware coredump on reconfiguration, we shouldn't do that |
| 1128 | * on D3->D0 transition |
| 1129 | */ |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 1130 | if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) { |
| 1131 | mvm->fw_dump_desc = &iwl_mvm_dump_desc_assert; |
Johannes Berg | 58629d9 | 2014-11-06 09:40:50 +0100 | [diff] [blame] | 1132 | iwl_mvm_fw_error_dump(mvm); |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 1133 | } |
Emmanuel Grumbach | 1bd3cbc | 2014-03-18 21:15:06 +0200 | [diff] [blame] | 1134 | |
Eliad Peller | 744cb69 | 2014-12-10 18:44:13 +0200 | [diff] [blame] | 1135 | /* cleanup all stale references (scan, roc), but keep the |
| 1136 | * ucode_down ref until reconfig is complete |
| 1137 | */ |
| 1138 | iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 1139 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1140 | iwl_trans_stop_device(mvm->trans); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1141 | |
| 1142 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Luciano Coelho | b187330 | 2014-08-08 17:12:07 +0300 | [diff] [blame] | 1143 | mvm->ps_disabled = false; |
Emmanuel Grumbach | 31b8b34 | 2014-11-02 15:48:09 +0200 | [diff] [blame] | 1144 | mvm->calibrating = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1145 | |
| 1146 | /* just in case one was running */ |
| 1147 | ieee80211_remain_on_channel_expired(mvm->hw); |
| 1148 | |
| 1149 | ieee80211_iterate_active_interfaces_atomic( |
| 1150 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 1151 | iwl_mvm_cleanup_iterator, mvm); |
| 1152 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1153 | mvm->p2p_device_vif = NULL; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 1154 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1155 | |
| 1156 | iwl_mvm_reset_phy_ctxts(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1157 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 1158 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1159 | memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained)); |
Emmanuel Grumbach | 8a275ba | 2014-07-13 09:12:11 +0300 | [diff] [blame] | 1160 | memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); |
| 1161 | memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old)); |
| 1162 | memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); |
| 1163 | memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old)); |
| 1164 | memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk)); |
| 1165 | memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1166 | |
| 1167 | ieee80211_wake_queues(mvm->hw); |
| 1168 | |
Eliad Peller | 228670b | 2014-08-10 17:00:15 +0300 | [diff] [blame] | 1169 | /* clear any stale d0i3 state */ |
| 1170 | clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status); |
| 1171 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1172 | mvm->vif_count = 0; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 1173 | mvm->rx_ba_sessions = 0; |
Emmanuel Grumbach | d2709ad | 2015-01-29 14:58:06 +0200 | [diff] [blame] | 1174 | mvm->fw_dbg_conf = FW_DBG_INVALID; |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 1175 | |
| 1176 | /* keep statistics ticking */ |
| 1177 | iwl_mvm_accu_radio_stats(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1180 | int __iwl_mvm_mac_start(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1181 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1182 | int ret; |
| 1183 | |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1184 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1185 | |
| 1186 | /* Clean up some internal and mac80211 state on restart */ |
| 1187 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 1188 | iwl_mvm_restart_cleanup(mvm); |
| 1189 | |
| 1190 | ret = iwl_mvm_up(mvm); |
Johannes Berg | c47af22 | 2014-04-30 16:34:45 +0200 | [diff] [blame] | 1191 | |
| 1192 | if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1193 | /* Something went wrong - we need to finish some cleanup |
| 1194 | * that normally iwl_mvm_mac_restart_complete() below |
| 1195 | * would do. |
| 1196 | */ |
| 1197 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 1198 | iwl_mvm_d0i3_enable_tx(mvm, NULL); |
| 1199 | } |
| 1200 | |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1201 | return ret; |
| 1202 | } |
| 1203 | |
| 1204 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) |
| 1205 | { |
| 1206 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1207 | int ret; |
| 1208 | |
Eliad Peller | 37948fc | 2014-12-11 10:48:18 +0200 | [diff] [blame] | 1209 | /* Some hw restart cleanups must not hold the mutex */ |
| 1210 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1211 | /* |
| 1212 | * Make sure we are out of d0i3. This is needed |
| 1213 | * to make sure the reference accounting is correct |
| 1214 | * (and there is no stale d0i3_exit_work). |
| 1215 | */ |
| 1216 | wait_event_timeout(mvm->d0i3_exit_waitq, |
| 1217 | !test_bit(IWL_MVM_STATUS_IN_D0I3, |
| 1218 | &mvm->status), |
| 1219 | HZ); |
| 1220 | } |
| 1221 | |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1222 | mutex_lock(&mvm->mutex); |
| 1223 | ret = __iwl_mvm_mac_start(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1224 | mutex_unlock(&mvm->mutex); |
| 1225 | |
| 1226 | return ret; |
| 1227 | } |
| 1228 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 1229 | static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1230 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1231 | int ret; |
| 1232 | |
| 1233 | mutex_lock(&mvm->mutex); |
| 1234 | |
| 1235 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 1236 | iwl_mvm_d0i3_enable_tx(mvm, NULL); |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 1237 | ret = iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1238 | if (ret) |
| 1239 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", |
| 1240 | ret); |
| 1241 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 1242 | /* allow transport/FW low power modes */ |
| 1243 | iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 1244 | |
Arik Nemtsov | cbd2ae2 | 2014-09-14 19:13:54 +0300 | [diff] [blame] | 1245 | /* |
| 1246 | * If we have TDLS peers, remove them. We don't know the last seqno/PN |
| 1247 | * of packets the FW sent out, so we must reconnect. |
| 1248 | */ |
| 1249 | iwl_mvm_teardown_tdls_peers(mvm); |
| 1250 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1251 | mutex_unlock(&mvm->mutex); |
| 1252 | } |
| 1253 | |
Eliad Peller | 088070a2 | 2014-10-20 18:42:58 +0300 | [diff] [blame] | 1254 | static void iwl_mvm_resume_complete(struct iwl_mvm *mvm) |
| 1255 | { |
| 1256 | bool exit_now; |
| 1257 | |
| 1258 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
| 1259 | return; |
| 1260 | |
| 1261 | mutex_lock(&mvm->d0i3_suspend_mutex); |
| 1262 | __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags); |
| 1263 | exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP, |
| 1264 | &mvm->d0i3_suspend_flags); |
| 1265 | mutex_unlock(&mvm->d0i3_suspend_mutex); |
| 1266 | |
| 1267 | if (exit_now) { |
| 1268 | IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n"); |
| 1269 | _iwl_mvm_exit_d0i3(mvm); |
| 1270 | } |
Eliad Peller | 6735943 | 2014-12-09 15:23:54 +0200 | [diff] [blame] | 1271 | |
| 1272 | if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND) |
| 1273 | if (!wait_event_timeout(mvm->d0i3_exit_waitq, |
| 1274 | !test_bit(IWL_MVM_STATUS_IN_D0I3, |
| 1275 | &mvm->status), |
| 1276 | HZ)) |
| 1277 | WARN_ONCE(1, "D0i3 exit on resume timed out\n"); |
Eliad Peller | 088070a2 | 2014-10-20 18:42:58 +0300 | [diff] [blame] | 1278 | } |
| 1279 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 1280 | static void |
| 1281 | iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, |
| 1282 | enum ieee80211_reconfig_type reconfig_type) |
| 1283 | { |
| 1284 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1285 | |
| 1286 | switch (reconfig_type) { |
| 1287 | case IEEE80211_RECONFIG_TYPE_RESTART: |
| 1288 | iwl_mvm_restart_complete(mvm); |
| 1289 | break; |
| 1290 | case IEEE80211_RECONFIG_TYPE_SUSPEND: |
Eliad Peller | 088070a2 | 2014-10-20 18:42:58 +0300 | [diff] [blame] | 1291 | iwl_mvm_resume_complete(mvm); |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 1292 | break; |
| 1293 | } |
| 1294 | } |
| 1295 | |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1296 | void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1297 | { |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1298 | lockdep_assert_held(&mvm->mutex); |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 1299 | |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 1300 | /* firmware counters are obviously reset now, but we shouldn't |
| 1301 | * partially track so also clear the fw_reset_accu counters. |
| 1302 | */ |
| 1303 | memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); |
| 1304 | |
Eliad Peller | 0a79a0c0 | 2014-12-04 10:27:20 +0200 | [diff] [blame] | 1305 | /* |
| 1306 | * Disallow low power states when the FW is down by taking |
| 1307 | * the UCODE_DOWN ref. in case of ongoing hw restart the |
| 1308 | * ref is already taken, so don't take it again. |
| 1309 | */ |
| 1310 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 1311 | iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 1312 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1313 | /* async_handlers_wk is now blocked */ |
| 1314 | |
| 1315 | /* |
| 1316 | * The work item could be running or queued if the |
| 1317 | * ROC time event stops just as we get here. |
| 1318 | */ |
| 1319 | cancel_work_sync(&mvm->roc_done_wk); |
| 1320 | |
| 1321 | iwl_trans_stop_device(mvm->trans); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1322 | |
| 1323 | iwl_mvm_async_handlers_purge(mvm); |
| 1324 | /* async_handlers_list is empty and will stay empty: HW is stopped */ |
| 1325 | |
| 1326 | /* the fw is stopped, the aux sta is dead: clean up driver state */ |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 1327 | iwl_mvm_del_aux_sta(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1328 | |
Eliad Peller | 0a79a0c0 | 2014-12-04 10:27:20 +0200 | [diff] [blame] | 1329 | /* |
| 1330 | * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete() |
| 1331 | * won't be called in this case). |
| 1332 | */ |
| 1333 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 1334 | |
Luciano Coelho | bc44886 | 2014-08-20 11:49:11 +0300 | [diff] [blame] | 1335 | mvm->ucode_loaded = false; |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1336 | } |
Luciano Coelho | bc44886 | 2014-08-20 11:49:11 +0300 | [diff] [blame] | 1337 | |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1338 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) |
| 1339 | { |
| 1340 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1341 | |
| 1342 | flush_work(&mvm->d0i3_exit_work); |
| 1343 | flush_work(&mvm->async_handlers_wk); |
Emmanuel Grumbach | d2709ad | 2015-01-29 14:58:06 +0200 | [diff] [blame] | 1344 | cancel_delayed_work_sync(&mvm->fw_dump_wk); |
Emmanuel Grumbach | b6eaa45 | 2015-01-29 14:58:20 +0200 | [diff] [blame] | 1345 | iwl_mvm_free_fw_dump_desc(mvm); |
Luciano Coelho | a0a0924 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 1346 | |
| 1347 | mutex_lock(&mvm->mutex); |
| 1348 | __iwl_mvm_mac_stop(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1349 | mutex_unlock(&mvm->mutex); |
| 1350 | |
| 1351 | /* |
| 1352 | * The worker might have been waiting for the mutex, let it run and |
| 1353 | * discover that its list is now empty. |
| 1354 | */ |
| 1355 | cancel_work_sync(&mvm->async_handlers_wk); |
| 1356 | } |
| 1357 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1358 | static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
| 1359 | { |
| 1360 | u16 i; |
| 1361 | |
| 1362 | lockdep_assert_held(&mvm->mutex); |
| 1363 | |
| 1364 | for (i = 0; i < NUM_PHY_CTX; i++) |
| 1365 | if (!mvm->phy_ctxts[i].ref) |
| 1366 | return &mvm->phy_ctxts[i]; |
| 1367 | |
| 1368 | IWL_ERR(mvm, "No available PHY context\n"); |
| 1369 | return NULL; |
| 1370 | } |
| 1371 | |
Emmanuel Grumbach | ee9c6cb | 2013-12-04 13:53:39 +0200 | [diff] [blame] | 1372 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1373 | s8 tx_power) |
| 1374 | { |
| 1375 | /* FW is in charge of regulatory enforcement */ |
| 1376 | struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = { |
| 1377 | .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id, |
| 1378 | .pwr_restriction = cpu_to_le16(tx_power), |
| 1379 | }; |
| 1380 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1381 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, |
Emmanuel Grumbach | ee9c6cb | 2013-12-04 13:53:39 +0200 | [diff] [blame] | 1382 | sizeof(reduce_txpwr_cmd), |
| 1383 | &reduce_txpwr_cmd); |
| 1384 | } |
| 1385 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1386 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
| 1387 | struct ieee80211_vif *vif) |
| 1388 | { |
| 1389 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1390 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1391 | int ret; |
| 1392 | |
Emmanuel Grumbach | aa5e183 | 2015-03-07 19:35:37 +0200 | [diff] [blame] | 1393 | mvmvif->mvm = mvm; |
| 1394 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1395 | /* |
Gregory Greenman | d40fc48 | 2014-06-25 14:08:50 +0200 | [diff] [blame] | 1396 | * make sure D0i3 exit is completed, otherwise a target access |
| 1397 | * during tx queue configuration could be done when still in |
| 1398 | * D0i3 state. |
| 1399 | */ |
| 1400 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF); |
| 1401 | if (ret) |
| 1402 | return ret; |
| 1403 | |
| 1404 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1405 | * Not much to do here. The stack will not allow interface |
| 1406 | * types or combinations that we didn't advertise, so we |
| 1407 | * don't really have to check the types. |
| 1408 | */ |
| 1409 | |
| 1410 | mutex_lock(&mvm->mutex); |
| 1411 | |
Johannes Berg | 33cef92 | 2015-01-21 21:41:29 +0100 | [diff] [blame] | 1412 | /* make sure that beacon statistics don't go backwards with FW reset */ |
| 1413 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 1414 | mvmvif->beacon_stats.accu_num_beacons += |
| 1415 | mvmvif->beacon_stats.num_beacons; |
| 1416 | |
Eliad Peller | e89044d | 2013-07-16 17:33:26 +0300 | [diff] [blame] | 1417 | /* Allocate resources for the MAC context, and add it to the fw */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1418 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
| 1419 | if (ret) |
| 1420 | goto out_unlock; |
| 1421 | |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 1422 | /* Counting number of interfaces is needed for legacy PM */ |
Ilan Peer | ea183d0 | 2013-07-23 14:41:53 +0300 | [diff] [blame] | 1423 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 1424 | mvm->vif_count++; |
Ilan Peer | ea183d0 | 2013-07-23 14:41:53 +0300 | [diff] [blame] | 1425 | |
| 1426 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1427 | * The AP binding flow can be done only after the beacon |
| 1428 | * template is configured (which happens only in the mac80211 |
| 1429 | * start_ap() flow), and adding the broadcast station can happen |
| 1430 | * only after the binding. |
| 1431 | * In addition, since modifying the MAC before adding a bcast |
| 1432 | * station is not allowed by the FW, delay the adding of MAC context to |
| 1433 | * the point where we can also add the bcast station. |
| 1434 | * In short: there's not much we can do at this point, other than |
| 1435 | * allocating resources :) |
| 1436 | */ |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1437 | if (vif->type == NL80211_IFTYPE_AP || |
| 1438 | vif->type == NL80211_IFTYPE_ADHOC) { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1439 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1440 | if (ret) { |
| 1441 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); |
| 1442 | goto out_release; |
| 1443 | } |
| 1444 | |
Emmanuel Grumbach | 77740cb | 2013-06-26 23:51:41 +0300 | [diff] [blame] | 1445 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1446 | goto out_unlock; |
| 1447 | } |
| 1448 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1449 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 1450 | if (ret) |
| 1451 | goto out_release; |
| 1452 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1453 | ret = iwl_mvm_power_update_mac(mvm); |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 1454 | if (ret) |
Luciano Coelho | fd66fc1 | 2015-01-27 15:06:57 +0200 | [diff] [blame] | 1455 | goto out_remove_mac; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1456 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1457 | /* beacon filtering */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1458 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 1459 | if (ret) |
| 1460 | goto out_remove_mac; |
| 1461 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1462 | if (!mvm->bf_allowed_vif && |
Emmanuel Grumbach | 73e5f2c | 2014-03-30 08:57:30 +0300 | [diff] [blame] | 1463 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1464 | mvm->bf_allowed_vif = mvmvif; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1465 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 1466 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1469 | /* |
| 1470 | * P2P_DEVICE interface does not have a channel context assigned to it, |
| 1471 | * so a dedicated PHY context is allocated to it and the corresponding |
| 1472 | * MAC context is bound to it at this stage. |
| 1473 | */ |
| 1474 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1475 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1476 | mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 1477 | if (!mvmvif->phy_ctxt) { |
| 1478 | ret = -ENOSPC; |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 1479 | goto out_free_bf; |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1480 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1481 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1482 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1483 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1484 | if (ret) |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1485 | goto out_unref_phy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1486 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1487 | ret = iwl_mvm_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1488 | if (ret) |
| 1489 | goto out_unbind; |
| 1490 | |
| 1491 | /* Save a pointer to p2p device vif, so it can later be used to |
| 1492 | * update the p2p device MAC when a GO is started/stopped */ |
| 1493 | mvm->p2p_device_vif = vif; |
| 1494 | } |
| 1495 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 1496 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1497 | goto out_unlock; |
| 1498 | |
| 1499 | out_unbind: |
| 1500 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1501 | out_unref_phy: |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1502 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 1503 | out_free_bf: |
| 1504 | if (mvm->bf_allowed_vif == mvmvif) { |
| 1505 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1506 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 1507 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 1508 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1509 | out_remove_mac: |
| 1510 | mvmvif->phy_ctxt = NULL; |
| 1511 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 1512 | out_release: |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 1513 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 1514 | mvm->vif_count--; |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 1515 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1516 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 1517 | out_unlock: |
| 1518 | mutex_unlock(&mvm->mutex); |
| 1519 | |
Gregory Greenman | d40fc48 | 2014-06-25 14:08:50 +0200 | [diff] [blame] | 1520 | iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF); |
| 1521 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1522 | return ret; |
| 1523 | } |
| 1524 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 1525 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
| 1526 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1527 | { |
Arik Nemtsov | d92b732e | 2014-09-21 19:00:42 +0300 | [diff] [blame] | 1528 | u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1529 | |
| 1530 | if (tfd_msk) { |
| 1531 | mutex_lock(&mvm->mutex); |
| 1532 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); |
| 1533 | mutex_unlock(&mvm->mutex); |
| 1534 | } |
| 1535 | |
| 1536 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 1537 | /* |
| 1538 | * Flush the ROC worker which will flush the OFFCHANNEL queue. |
| 1539 | * We assume here that all the packets sent to the OFFCHANNEL |
| 1540 | * queue are sent in ROC session. |
| 1541 | */ |
| 1542 | flush_work(&mvm->roc_done_wk); |
| 1543 | } else { |
| 1544 | /* |
| 1545 | * By now, all the AC queues are empty. The AGG queues are |
| 1546 | * empty too. We already got all the Tx responses for all the |
| 1547 | * packets in the queues. The drain work can have been |
Emmanuel Grumbach | 0742a75 | 2013-06-10 14:10:33 +0300 | [diff] [blame] | 1548 | * triggered. Flush it. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1549 | */ |
| 1550 | flush_work(&mvm->sta_drained_wk); |
| 1551 | } |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, |
| 1555 | struct ieee80211_vif *vif) |
| 1556 | { |
| 1557 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1558 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1559 | |
| 1560 | iwl_mvm_prepare_mac_removal(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1561 | |
| 1562 | mutex_lock(&mvm->mutex); |
| 1563 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1564 | if (mvm->bf_allowed_vif == mvmvif) { |
| 1565 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1566 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 1567 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1568 | } |
| 1569 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 1570 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
| 1571 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1572 | /* |
| 1573 | * For AP/GO interface, the tear down of the resources allocated to the |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 1574 | * interface is be handled as part of the stop_ap flow. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1575 | */ |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1576 | if (vif->type == NL80211_IFTYPE_AP || |
| 1577 | vif->type == NL80211_IFTYPE_ADHOC) { |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 1578 | #ifdef CONFIG_NL80211_TESTMODE |
| 1579 | if (vif == mvm->noa_vif) { |
| 1580 | mvm->noa_vif = NULL; |
| 1581 | mvm->noa_duration = 0; |
| 1582 | } |
| 1583 | #endif |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1584 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1585 | goto out_release; |
| 1586 | } |
| 1587 | |
| 1588 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 1589 | mvm->p2p_device_vif = NULL; |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1590 | iwl_mvm_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1591 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1592 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1593 | mvmvif->phy_ctxt = NULL; |
| 1594 | } |
| 1595 | |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 1596 | if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1597 | mvm->vif_count--; |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 1598 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1599 | iwl_mvm_power_update_mac(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1600 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 1601 | |
| 1602 | out_release: |
| 1603 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 1604 | mutex_unlock(&mvm->mutex); |
| 1605 | } |
| 1606 | |
| 1607 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 1608 | { |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1612 | struct iwl_mvm_mc_iter_data { |
| 1613 | struct iwl_mvm *mvm; |
| 1614 | int port_id; |
| 1615 | }; |
| 1616 | |
| 1617 | static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, |
| 1618 | struct ieee80211_vif *vif) |
| 1619 | { |
| 1620 | struct iwl_mvm_mc_iter_data *data = _data; |
| 1621 | struct iwl_mvm *mvm = data->mvm; |
| 1622 | struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; |
| 1623 | int ret, len; |
| 1624 | |
| 1625 | /* if we don't have free ports, mcast frames will be dropped */ |
| 1626 | if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) |
| 1627 | return; |
| 1628 | |
| 1629 | if (vif->type != NL80211_IFTYPE_STATION || |
| 1630 | !vif->bss_conf.assoc) |
| 1631 | return; |
| 1632 | |
| 1633 | cmd->port_id = data->port_id++; |
| 1634 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); |
| 1635 | len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); |
| 1636 | |
Emmanuel Grumbach | 1c4abec | 2014-05-08 09:48:10 +0300 | [diff] [blame] | 1637 | ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd); |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1638 | if (ret) |
| 1639 | IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); |
| 1640 | } |
| 1641 | |
| 1642 | static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) |
| 1643 | { |
| 1644 | struct iwl_mvm_mc_iter_data iter_data = { |
| 1645 | .mvm = mvm, |
| 1646 | }; |
| 1647 | |
| 1648 | lockdep_assert_held(&mvm->mutex); |
| 1649 | |
| 1650 | if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) |
| 1651 | return; |
| 1652 | |
Emmanuel Grumbach | 1c4abec | 2014-05-08 09:48:10 +0300 | [diff] [blame] | 1653 | ieee80211_iterate_active_interfaces_atomic( |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1654 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1655 | iwl_mvm_mc_iface_iterator, &iter_data); |
| 1656 | } |
| 1657 | |
| 1658 | static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, |
| 1659 | struct netdev_hw_addr_list *mc_list) |
| 1660 | { |
| 1661 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1662 | struct iwl_mcast_filter_cmd *cmd; |
| 1663 | struct netdev_hw_addr *addr; |
Max Stepanov | f3bd58f | 2014-08-04 13:55:01 +0300 | [diff] [blame] | 1664 | int addr_count; |
| 1665 | bool pass_all; |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1666 | int len; |
| 1667 | |
Max Stepanov | f3bd58f | 2014-08-04 13:55:01 +0300 | [diff] [blame] | 1668 | addr_count = netdev_hw_addr_list_count(mc_list); |
| 1669 | pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || |
| 1670 | IWL_MVM_FW_MCAST_FILTER_PASS_ALL; |
| 1671 | if (pass_all) |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1672 | addr_count = 0; |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1673 | |
| 1674 | len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); |
| 1675 | cmd = kzalloc(len, GFP_ATOMIC); |
| 1676 | if (!cmd) |
| 1677 | return 0; |
| 1678 | |
| 1679 | if (pass_all) { |
| 1680 | cmd->pass_all = 1; |
| 1681 | return (u64)(unsigned long)cmd; |
| 1682 | } |
| 1683 | |
| 1684 | netdev_hw_addr_list_for_each(addr, mc_list) { |
| 1685 | IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", |
| 1686 | cmd->count, addr->addr); |
| 1687 | memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], |
| 1688 | addr->addr, ETH_ALEN); |
| 1689 | cmd->count++; |
| 1690 | } |
| 1691 | |
| 1692 | return (u64)(unsigned long)cmd; |
| 1693 | } |
| 1694 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1695 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, |
| 1696 | unsigned int changed_flags, |
| 1697 | unsigned int *total_flags, |
| 1698 | u64 multicast) |
| 1699 | { |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1700 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1701 | struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; |
| 1702 | |
| 1703 | mutex_lock(&mvm->mutex); |
| 1704 | |
| 1705 | /* replace previous configuration */ |
| 1706 | kfree(mvm->mcast_filter_cmd); |
| 1707 | mvm->mcast_filter_cmd = cmd; |
| 1708 | |
| 1709 | if (!cmd) |
| 1710 | goto out; |
| 1711 | |
| 1712 | iwl_mvm_recalc_multicast(mvm); |
| 1713 | out: |
| 1714 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1715 | *total_flags = 0; |
| 1716 | } |
| 1717 | |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1718 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1719 | struct iwl_bcast_iter_data { |
| 1720 | struct iwl_mvm *mvm; |
| 1721 | struct iwl_bcast_filter_cmd *cmd; |
| 1722 | u8 current_filter; |
| 1723 | }; |
| 1724 | |
| 1725 | static void |
| 1726 | iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, |
| 1727 | const struct iwl_fw_bcast_filter *in_filter, |
| 1728 | struct iwl_fw_bcast_filter *out_filter) |
| 1729 | { |
| 1730 | struct iwl_fw_bcast_filter_attr *attr; |
| 1731 | int i; |
| 1732 | |
| 1733 | memcpy(out_filter, in_filter, sizeof(*out_filter)); |
| 1734 | |
| 1735 | for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { |
| 1736 | attr = &out_filter->attrs[i]; |
| 1737 | |
| 1738 | if (!attr->mask) |
| 1739 | break; |
| 1740 | |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 1741 | switch (attr->reserved1) { |
| 1742 | case cpu_to_le16(BC_FILTER_MAGIC_IP): |
| 1743 | if (vif->bss_conf.arp_addr_cnt != 1) { |
| 1744 | attr->mask = 0; |
| 1745 | continue; |
| 1746 | } |
| 1747 | |
| 1748 | attr->val = vif->bss_conf.arp_addr_list[0]; |
| 1749 | break; |
| 1750 | case cpu_to_le16(BC_FILTER_MAGIC_MAC): |
| 1751 | attr->val = *(__be32 *)&vif->addr[2]; |
| 1752 | break; |
| 1753 | default: |
| 1754 | break; |
| 1755 | } |
| 1756 | attr->reserved1 = 0; |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1757 | out_filter->num_attrs++; |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, |
| 1762 | struct ieee80211_vif *vif) |
| 1763 | { |
| 1764 | struct iwl_bcast_iter_data *data = _data; |
| 1765 | struct iwl_mvm *mvm = data->mvm; |
| 1766 | struct iwl_bcast_filter_cmd *cmd = data->cmd; |
| 1767 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1768 | struct iwl_fw_bcast_mac *bcast_mac; |
| 1769 | int i; |
| 1770 | |
| 1771 | if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) |
| 1772 | return; |
| 1773 | |
| 1774 | bcast_mac = &cmd->macs[mvmvif->id]; |
| 1775 | |
Ilan Peer | e48393e | 2014-05-22 11:19:02 +0300 | [diff] [blame] | 1776 | /* |
| 1777 | * enable filtering only for associated stations, but not for P2P |
| 1778 | * Clients |
| 1779 | */ |
| 1780 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p || |
| 1781 | !vif->bss_conf.assoc) |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1782 | return; |
| 1783 | |
| 1784 | bcast_mac->default_discard = 1; |
| 1785 | |
| 1786 | /* copy all configured filters */ |
| 1787 | for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { |
| 1788 | /* |
| 1789 | * Make sure we don't exceed our filters limit. |
| 1790 | * if there is still a valid filter to be configured, |
| 1791 | * be on the safe side and just allow bcast for this mac. |
| 1792 | */ |
| 1793 | if (WARN_ON_ONCE(data->current_filter >= |
| 1794 | ARRAY_SIZE(cmd->filters))) { |
| 1795 | bcast_mac->default_discard = 0; |
| 1796 | bcast_mac->attached_filters = 0; |
| 1797 | break; |
| 1798 | } |
| 1799 | |
| 1800 | iwl_mvm_set_bcast_filter(vif, |
| 1801 | &mvm->bcast_filters[i], |
| 1802 | &cmd->filters[data->current_filter]); |
| 1803 | |
| 1804 | /* skip current filter if it contains no attributes */ |
| 1805 | if (!cmd->filters[data->current_filter].num_attrs) |
| 1806 | continue; |
| 1807 | |
| 1808 | /* attach the filter to current mac */ |
| 1809 | bcast_mac->attached_filters |= |
| 1810 | cpu_to_le16(BIT(data->current_filter)); |
| 1811 | |
| 1812 | data->current_filter++; |
| 1813 | } |
| 1814 | } |
| 1815 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1816 | bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm, |
| 1817 | struct iwl_bcast_filter_cmd *cmd) |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1818 | { |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1819 | struct iwl_bcast_iter_data iter_data = { |
| 1820 | .mvm = mvm, |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1821 | .cmd = cmd, |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1822 | }; |
| 1823 | |
Max Stepanov | 3b8983b | 2014-10-15 11:27:16 +0300 | [diff] [blame] | 1824 | if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL) |
| 1825 | return false; |
| 1826 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1827 | memset(cmd, 0, sizeof(*cmd)); |
| 1828 | cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); |
| 1829 | cmd->max_macs = ARRAY_SIZE(cmd->macs); |
| 1830 | |
| 1831 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1832 | /* use debugfs filters/macs if override is configured */ |
| 1833 | if (mvm->dbgfs_bcast_filtering.override) { |
| 1834 | memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters, |
| 1835 | sizeof(cmd->filters)); |
| 1836 | memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs, |
| 1837 | sizeof(cmd->macs)); |
| 1838 | return true; |
| 1839 | } |
| 1840 | #endif |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1841 | |
| 1842 | /* if no filters are configured, do nothing */ |
| 1843 | if (!mvm->bcast_filters) |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1844 | return false; |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1845 | |
| 1846 | /* configure and attach these filters for each associated sta vif */ |
| 1847 | ieee80211_iterate_active_interfaces( |
| 1848 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1849 | iwl_mvm_bcast_filter_iterator, &iter_data); |
| 1850 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1851 | return true; |
| 1852 | } |
| 1853 | static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, |
| 1854 | struct ieee80211_vif *vif) |
| 1855 | { |
| 1856 | struct iwl_bcast_filter_cmd cmd; |
| 1857 | |
| 1858 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) |
| 1859 | return 0; |
| 1860 | |
| 1861 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) |
| 1862 | return 0; |
| 1863 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1864 | return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1865 | sizeof(cmd), &cmd); |
| 1866 | } |
| 1867 | #else |
| 1868 | static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, |
| 1869 | struct ieee80211_vif *vif) |
| 1870 | { |
| 1871 | return 0; |
| 1872 | } |
| 1873 | #endif |
| 1874 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1875 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
| 1876 | struct ieee80211_vif *vif, |
| 1877 | struct ieee80211_bss_conf *bss_conf, |
| 1878 | u32 changes) |
| 1879 | { |
| 1880 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1881 | int ret; |
| 1882 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 1883 | /* |
| 1884 | * Re-calculate the tsf id, as the master-slave relations depend on the |
| 1885 | * beacon interval, which was not known when the station interface was |
| 1886 | * added. |
| 1887 | */ |
| 1888 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) |
| 1889 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
| 1890 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1891 | /* |
| 1892 | * If we're not associated yet, take the (new) BSSID before associating |
| 1893 | * so the firmware knows. If we're already associated, then use the old |
| 1894 | * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC |
| 1895 | * branch for disassociation below. |
| 1896 | */ |
| 1897 | if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) |
| 1898 | memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); |
| 1899 | |
| 1900 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1901 | if (ret) |
| 1902 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
| 1903 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1904 | /* after sending it once, adopt mac80211 data */ |
| 1905 | memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); |
| 1906 | mvmvif->associated = bss_conf->assoc; |
| 1907 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1908 | if (changes & BSS_CHANGED_ASSOC) { |
| 1909 | if (bss_conf->assoc) { |
Johannes Berg | 33cef92 | 2015-01-21 21:41:29 +0100 | [diff] [blame] | 1910 | /* clear statistics to get clean beacon counter */ |
| 1911 | iwl_mvm_request_statistics(mvm, true); |
| 1912 | memset(&mvmvif->beacon_stats, 0, |
| 1913 | sizeof(mvmvif->beacon_stats)); |
| 1914 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1915 | /* add quota for this interface */ |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 1916 | ret = iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1917 | if (ret) { |
| 1918 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 1919 | return; |
| 1920 | } |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 1921 | |
| 1922 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, |
| 1923 | &mvm->status)) { |
| 1924 | /* |
| 1925 | * If we're restarting then the firmware will |
| 1926 | * obviously have lost synchronisation with |
| 1927 | * the AP. It will attempt to synchronise by |
| 1928 | * itself, but we can make it more reliable by |
| 1929 | * scheduling a session protection time event. |
| 1930 | * |
| 1931 | * The firmware needs to receive a beacon to |
| 1932 | * catch up with synchronisation, use 110% of |
| 1933 | * the beacon interval. |
| 1934 | * |
| 1935 | * Set a large maximum delay to allow for more |
| 1936 | * than a single interface. |
| 1937 | */ |
| 1938 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; |
| 1939 | iwl_mvm_protect_session(mvm, vif, dur, dur, |
Liad Kaufman | d20d37b | 2014-07-06 17:14:39 +0300 | [diff] [blame] | 1940 | 5 * dur, false); |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 1941 | } |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1942 | |
| 1943 | iwl_mvm_sf_update(mvm, vif, false); |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 1944 | iwl_mvm_power_vif_assoc(mvm, vif); |
Emmanuel Grumbach | 697162a | 2014-07-30 15:56:42 +0300 | [diff] [blame] | 1945 | if (vif->p2p) { |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 1946 | iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT); |
Emmanuel Grumbach | 697162a | 2014-07-30 15:56:42 +0300 | [diff] [blame] | 1947 | iwl_mvm_update_smps(mvm, vif, |
| 1948 | IWL_MVM_SMPS_REQ_PROT, |
| 1949 | IEEE80211_SMPS_DYNAMIC); |
| 1950 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1951 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1952 | /* |
| 1953 | * If update fails - SF might be running in associated |
| 1954 | * mode while disassociated - which is forbidden. |
| 1955 | */ |
| 1956 | WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false), |
| 1957 | "Failed to update SF upon disassociation\n"); |
| 1958 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1959 | /* remove AP station now that the MAC is unassoc */ |
| 1960 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); |
| 1961 | if (ret) |
| 1962 | IWL_ERR(mvm, "failed to remove AP station\n"); |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 1963 | |
| 1964 | if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id) |
| 1965 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1966 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 1967 | /* remove quota for this interface */ |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 1968 | ret = iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1969 | if (ret) |
| 1970 | IWL_ERR(mvm, "failed to update quotas\n"); |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 1971 | |
| 1972 | if (vif->p2p) |
| 1973 | iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT); |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 1974 | |
| 1975 | /* this will take the cleared BSSID from bss_conf */ |
| 1976 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
| 1977 | if (ret) |
| 1978 | IWL_ERR(mvm, |
| 1979 | "failed to update MAC %pM (clear after unassoc)\n", |
| 1980 | vif->addr); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1981 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1982 | |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1983 | iwl_mvm_recalc_multicast(mvm); |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1984 | iwl_mvm_configure_bcast_filter(mvm, vif); |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1985 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1986 | /* reset rssi values */ |
| 1987 | mvmvif->bf_data.ave_beacon_signal = 0; |
| 1988 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 1989 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | f94045e | 2014-01-06 13:38:55 +0200 | [diff] [blame] | 1990 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, |
| 1991 | IEEE80211_SMPS_AUTOMATIC); |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 1992 | } else if (changes & BSS_CHANGED_BEACON_INFO) { |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 1993 | /* |
| 1994 | * We received a beacon _after_ association so |
| 1995 | * remove the session protection. |
| 1996 | */ |
| 1997 | iwl_mvm_remove_time_event(mvm, mvmvif, |
| 1998 | &mvmvif->time_event_data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1999 | } |
Eran Harary | cc87d32 | 2014-07-15 14:04:23 +0300 | [diff] [blame] | 2000 | |
| 2001 | if (changes & BSS_CHANGED_BEACON_INFO) { |
| 2002 | iwl_mvm_sf_update(mvm, vif, false); |
| 2003 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); |
| 2004 | } |
| 2005 | |
Johannes Berg | 1bc10d3 | 2014-08-26 14:25:46 +0200 | [diff] [blame] | 2006 | if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) { |
| 2007 | ret = iwl_mvm_power_update_mac(mvm); |
| 2008 | if (ret) |
| 2009 | IWL_ERR(mvm, "failed to update power mode\n"); |
| 2010 | } |
| 2011 | |
Matti Gottlieb | 88f2fd7 | 2013-07-09 15:25:46 +0300 | [diff] [blame] | 2012 | if (changes & BSS_CHANGED_TXPOWER) { |
| 2013 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", |
| 2014 | bss_conf->txpower); |
| 2015 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); |
| 2016 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 2017 | |
| 2018 | if (changes & BSS_CHANGED_CQM) { |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 2019 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 2020 | /* reset cqm events tracking */ |
| 2021 | mvmvif->bf_data.last_cqm_event = 0; |
Avri Altman | fa7b2e7 | 2014-05-20 08:03:24 +0300 | [diff] [blame] | 2022 | if (mvmvif->bf_data.bf_enabled) { |
| 2023 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); |
| 2024 | if (ret) |
| 2025 | IWL_ERR(mvm, |
| 2026 | "failed to update CQM thresholds\n"); |
| 2027 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 2028 | } |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 2029 | |
| 2030 | if (changes & BSS_CHANGED_ARP_FILTER) { |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 2031 | IWL_DEBUG_MAC80211(mvm, "arp filter changed\n"); |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 2032 | iwl_mvm_configure_bcast_filter(mvm, vif); |
| 2033 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2034 | } |
| 2035 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2036 | static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, |
| 2037 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2038 | { |
| 2039 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2040 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2041 | int ret; |
| 2042 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 2043 | /* |
| 2044 | * iwl_mvm_mac_ctxt_add() might read directly from the device |
| 2045 | * (the system time), so make sure it is available. |
| 2046 | */ |
| 2047 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP); |
| 2048 | if (ret) |
| 2049 | return ret; |
| 2050 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2051 | mutex_lock(&mvm->mutex); |
| 2052 | |
| 2053 | /* Send the beacon template */ |
| 2054 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); |
| 2055 | if (ret) |
| 2056 | goto out_unlock; |
| 2057 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 2058 | /* |
| 2059 | * Re-calculate the tsf id, as the master-slave relations depend on the |
| 2060 | * beacon interval, which was not known when the AP interface was added. |
| 2061 | */ |
| 2062 | if (vif->type == NL80211_IFTYPE_AP) |
| 2063 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
| 2064 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2065 | /* Add the mac context */ |
| 2066 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 2067 | if (ret) |
| 2068 | goto out_unlock; |
| 2069 | |
| 2070 | /* Perform the binding */ |
| 2071 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 2072 | if (ret) |
| 2073 | goto out_remove; |
| 2074 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2075 | /* Send the bcast station. At this stage the TBTT and DTIM time events |
| 2076 | * are added and applied to the scheduler */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2077 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2078 | if (ret) |
| 2079 | goto out_unbind; |
| 2080 | |
Ilan Peer | 5691e21 | 2013-12-31 21:05:50 +0200 | [diff] [blame] | 2081 | /* must be set before quota calculations */ |
| 2082 | mvmvif->ap_ibss_active = true; |
| 2083 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2084 | /* power updated needs to be done before quotas */ |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 2085 | iwl_mvm_power_update_mac(mvm); |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2086 | |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 2087 | ret = iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2088 | if (ret) |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2089 | goto out_quota_failed; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2090 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2091 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2092 | if (vif->p2p && mvm->p2p_device_vif) |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 2093 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2094 | |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 2095 | iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS); |
| 2096 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 2097 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 2098 | |
Arik Nemtsov | f697267 | 2014-06-15 16:03:55 +0300 | [diff] [blame] | 2099 | /* we don't support TDLS during DCM */ |
| 2100 | if (iwl_mvm_phy_ctx_count(mvm) > 1) |
| 2101 | iwl_mvm_teardown_tdls_peers(mvm); |
| 2102 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2103 | mutex_unlock(&mvm->mutex); |
| 2104 | return 0; |
| 2105 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2106 | out_quota_failed: |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 2107 | iwl_mvm_power_update_mac(mvm); |
Ilan Peer | 5691e21 | 2013-12-31 21:05:50 +0200 | [diff] [blame] | 2108 | mvmvif->ap_ibss_active = false; |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2109 | iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2110 | out_unbind: |
| 2111 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 2112 | out_remove: |
| 2113 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 2114 | out_unlock: |
| 2115 | mutex_unlock(&mvm->mutex); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 2116 | iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2117 | return ret; |
| 2118 | } |
| 2119 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2120 | static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, |
| 2121 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2122 | { |
| 2123 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2124 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2125 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 2126 | iwl_mvm_prepare_mac_removal(mvm, vif); |
| 2127 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2128 | mutex_lock(&mvm->mutex); |
| 2129 | |
Andrei Otcheretianski | 664322f | 2014-06-05 16:40:36 +0300 | [diff] [blame] | 2130 | /* Handle AP stop while in CSA */ |
Andrei Otcheretianski | 7f0a7c6 | 2014-05-04 11:48:12 +0300 | [diff] [blame] | 2131 | if (rcu_access_pointer(mvm->csa_vif) == vif) { |
| 2132 | iwl_mvm_remove_time_event(mvm, mvmvif, |
| 2133 | &mvmvif->time_event_data); |
Andrei Otcheretianski | 664322f | 2014-06-05 16:40:36 +0300 | [diff] [blame] | 2134 | RCU_INIT_POINTER(mvm->csa_vif, NULL); |
Andrei Otcheretianski | 7f0a7c6 | 2014-05-04 11:48:12 +0300 | [diff] [blame] | 2135 | } |
Andrei Otcheretianski | 664322f | 2014-06-05 16:40:36 +0300 | [diff] [blame] | 2136 | |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 2137 | if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { |
| 2138 | RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); |
| 2139 | mvm->csa_tx_block_bcn_timeout = 0; |
| 2140 | } |
| 2141 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2142 | mvmvif->ap_ibss_active = false; |
David Spinadel | 1c87bba | 2014-02-27 16:41:52 +0200 | [diff] [blame] | 2143 | mvm->ap_last_beacon_gp2 = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2144 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 2145 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 2146 | |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 2147 | iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS); |
| 2148 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2149 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2150 | if (vif->p2p && mvm->p2p_device_vif) |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 2151 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2152 | |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 2153 | iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2154 | iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2155 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2156 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 2157 | iwl_mvm_power_update_mac(mvm); |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2158 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2159 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 2160 | |
| 2161 | mutex_unlock(&mvm->mutex); |
| 2162 | } |
| 2163 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2164 | static void |
| 2165 | iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, |
| 2166 | struct ieee80211_vif *vif, |
| 2167 | struct ieee80211_bss_conf *bss_conf, |
| 2168 | u32 changes) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2169 | { |
Ilan Peer | be2056f | 2013-12-04 16:47:14 +0200 | [diff] [blame] | 2170 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 2171 | |
Ilan Peer | be2056f | 2013-12-04 16:47:14 +0200 | [diff] [blame] | 2172 | /* Changes will be applied when the AP/IBSS is started */ |
| 2173 | if (!mvmvif->ap_ibss_active) |
| 2174 | return; |
| 2175 | |
Johannes Berg | 863230da | 2013-12-04 17:08:40 +0100 | [diff] [blame] | 2176 | if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | |
Johannes Berg | f7d8b70 | 2014-09-09 15:49:19 +0200 | [diff] [blame] | 2177 | BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 2178 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) |
Johannes Berg | 863230da | 2013-12-04 17:08:40 +0100 | [diff] [blame] | 2179 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 2180 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2181 | /* Need to send a new beacon template to the FW */ |
Johannes Berg | 863230da | 2013-12-04 17:08:40 +0100 | [diff] [blame] | 2182 | if (changes & BSS_CHANGED_BEACON && |
| 2183 | iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) |
| 2184 | IWL_WARN(mvm, "Failed updating beacon data\n"); |
Haim Dreyfuss | 79b7a69 | 2014-09-14 12:40:00 +0300 | [diff] [blame] | 2185 | |
| 2186 | if (changes & BSS_CHANGED_TXPOWER) { |
| 2187 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", |
| 2188 | bss_conf->txpower); |
| 2189 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); |
| 2190 | } |
| 2191 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, |
| 2195 | struct ieee80211_vif *vif, |
| 2196 | struct ieee80211_bss_conf *bss_conf, |
| 2197 | u32 changes) |
| 2198 | { |
| 2199 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2200 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 2201 | /* |
| 2202 | * iwl_mvm_bss_info_changed_station() might call |
| 2203 | * iwl_mvm_protect_session(), which reads directly from |
| 2204 | * the device (the system time), so make sure it is available. |
| 2205 | */ |
| 2206 | if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED)) |
| 2207 | return; |
| 2208 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2209 | mutex_lock(&mvm->mutex); |
| 2210 | |
David Spinadel | 723f02e | 2014-04-27 09:54:54 +0300 | [diff] [blame] | 2211 | if (changes & BSS_CHANGED_IDLE && !bss_conf->idle) |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 2212 | iwl_mvm_scan_offload_stop(mvm, true); |
David Spinadel | 723f02e | 2014-04-27 09:54:54 +0300 | [diff] [blame] | 2213 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2214 | switch (vif->type) { |
| 2215 | case NL80211_IFTYPE_STATION: |
| 2216 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); |
| 2217 | break; |
| 2218 | case NL80211_IFTYPE_AP: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2219 | case NL80211_IFTYPE_ADHOC: |
| 2220 | iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2221 | break; |
| 2222 | default: |
| 2223 | /* shouldn't happen */ |
| 2224 | WARN_ON_ONCE(1); |
| 2225 | } |
| 2226 | |
| 2227 | mutex_unlock(&mvm->mutex); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 2228 | iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2229 | } |
| 2230 | |
Eliad Peller | 4660dfb | 2014-06-22 18:15:59 +0300 | [diff] [blame] | 2231 | static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm, |
| 2232 | enum iwl_scan_status scan_type) |
| 2233 | { |
| 2234 | int ret; |
| 2235 | bool wait_for_handlers = false; |
| 2236 | |
| 2237 | mutex_lock(&mvm->mutex); |
| 2238 | |
| 2239 | if (mvm->scan_status != scan_type) { |
| 2240 | ret = 0; |
| 2241 | /* make sure there are no pending notifications */ |
| 2242 | wait_for_handlers = true; |
| 2243 | goto out; |
| 2244 | } |
| 2245 | |
| 2246 | switch (scan_type) { |
| 2247 | case IWL_MVM_SCAN_SCHED: |
| 2248 | ret = iwl_mvm_scan_offload_stop(mvm, true); |
| 2249 | break; |
| 2250 | case IWL_MVM_SCAN_OS: |
| 2251 | ret = iwl_mvm_cancel_scan(mvm); |
| 2252 | break; |
| 2253 | case IWL_MVM_SCAN_NONE: |
| 2254 | default: |
| 2255 | WARN_ON_ONCE(1); |
| 2256 | ret = -EINVAL; |
| 2257 | break; |
| 2258 | } |
| 2259 | if (ret) |
| 2260 | goto out; |
| 2261 | |
| 2262 | wait_for_handlers = true; |
| 2263 | out: |
| 2264 | mutex_unlock(&mvm->mutex); |
| 2265 | |
| 2266 | /* make sure we consume the completion notification */ |
| 2267 | if (wait_for_handlers) |
| 2268 | iwl_mvm_wait_for_async_handlers(mvm); |
| 2269 | |
| 2270 | return ret; |
| 2271 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2272 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, |
| 2273 | struct ieee80211_vif *vif, |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 2274 | struct ieee80211_scan_request *hw_req) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2275 | { |
| 2276 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 2277 | struct cfg80211_scan_request *req = &hw_req->req; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2278 | int ret; |
| 2279 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 2280 | if (req->n_channels == 0 || |
| 2281 | req->n_channels > mvm->fw->ucode_capa.n_scan_channels) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2282 | return -EINVAL; |
| 2283 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2284 | if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { |
| 2285 | ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED); |
| 2286 | if (ret) |
| 2287 | return ret; |
| 2288 | } |
Eliad Peller | 4660dfb | 2014-06-22 18:15:59 +0300 | [diff] [blame] | 2289 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2290 | mutex_lock(&mvm->mutex); |
| 2291 | |
Arik Nemtsov | 88931cc | 2014-03-05 12:26:15 +0200 | [diff] [blame] | 2292 | if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) { |
| 2293 | IWL_ERR(mvm, "scan while LAR regdomain is not set\n"); |
| 2294 | ret = -EBUSY; |
| 2295 | goto out; |
| 2296 | } |
| 2297 | |
Eliad Peller | 4660dfb | 2014-06-22 18:15:59 +0300 | [diff] [blame] | 2298 | if (mvm->scan_status != IWL_MVM_SCAN_NONE) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2299 | ret = -EBUSY; |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 2300 | goto out; |
| 2301 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2302 | |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 2303 | iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN); |
| 2304 | |
David Spinadel | b975e55 | 2014-11-17 12:30:05 +0200 | [diff] [blame] | 2305 | if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2306 | ret = iwl_mvm_scan_umac(mvm, vif, hw_req); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 2307 | else |
Luciano Coelho | 1f94038 | 2015-02-10 13:03:38 +0200 | [diff] [blame] | 2308 | ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 2309 | |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 2310 | if (ret) |
| 2311 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 2312 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2313 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2314 | return ret; |
| 2315 | } |
| 2316 | |
| 2317 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, |
| 2318 | struct ieee80211_vif *vif) |
| 2319 | { |
| 2320 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2321 | |
| 2322 | mutex_lock(&mvm->mutex); |
| 2323 | |
| 2324 | iwl_mvm_cancel_scan(mvm); |
| 2325 | |
| 2326 | mutex_unlock(&mvm->mutex); |
| 2327 | } |
| 2328 | |
| 2329 | static void |
| 2330 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2331 | struct ieee80211_sta *sta, u16 tids, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2332 | int num_frames, |
| 2333 | enum ieee80211_frame_release_type reason, |
| 2334 | bool more_data) |
| 2335 | { |
| 2336 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2337 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2338 | /* Called when we need to transmit (a) frame(s) from mac80211 */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2339 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2340 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
| 2341 | tids, more_data, false); |
| 2342 | } |
| 2343 | |
| 2344 | static void |
| 2345 | iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, |
| 2346 | struct ieee80211_sta *sta, u16 tids, |
| 2347 | int num_frames, |
| 2348 | enum ieee80211_frame_release_type reason, |
| 2349 | bool more_data) |
| 2350 | { |
| 2351 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2352 | |
| 2353 | /* Called when we need to transmit (a) frame(s) from agg queue */ |
| 2354 | |
| 2355 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
| 2356 | tids, more_data, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
| 2360 | struct ieee80211_vif *vif, |
| 2361 | enum sta_notify_cmd cmd, |
| 2362 | struct ieee80211_sta *sta) |
| 2363 | { |
| 2364 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2365 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2366 | int tid; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2367 | |
| 2368 | switch (cmd) { |
| 2369 | case STA_NOTIFY_SLEEP: |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 2370 | if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2371 | ieee80211_sta_block_awake(hw, sta, true); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2372 | spin_lock_bh(&mvmsta->lock); |
| 2373 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { |
| 2374 | struct iwl_mvm_tid_data *tid_data; |
| 2375 | |
| 2376 | tid_data = &mvmsta->tid_data[tid]; |
| 2377 | if (tid_data->state != IWL_AGG_ON && |
| 2378 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 2379 | continue; |
| 2380 | if (iwl_mvm_tid_queued(tid_data) == 0) |
| 2381 | continue; |
| 2382 | ieee80211_sta_set_buffered(sta, tid, true); |
| 2383 | } |
| 2384 | spin_unlock_bh(&mvmsta->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2385 | /* |
| 2386 | * The fw updates the STA to be asleep. Tx packets on the Tx |
| 2387 | * queues to this station will not be transmitted. The fw will |
| 2388 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. |
| 2389 | */ |
| 2390 | break; |
| 2391 | case STA_NOTIFY_AWAKE: |
Emmanuel Grumbach | 881acd8 | 2013-03-19 16:16:00 +0200 | [diff] [blame] | 2392 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2393 | break; |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 2394 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2395 | break; |
| 2396 | default: |
| 2397 | break; |
| 2398 | } |
| 2399 | } |
| 2400 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 2401 | static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
| 2402 | struct ieee80211_vif *vif, |
| 2403 | struct ieee80211_sta *sta) |
| 2404 | { |
| 2405 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2406 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 2407 | |
| 2408 | /* |
| 2409 | * This is called before mac80211 does RCU synchronisation, |
| 2410 | * so here we already invalidate our internal RCU-protected |
| 2411 | * station pointer. The rest of the code will thus no longer |
| 2412 | * be able to find the station this way, and we don't rely |
| 2413 | * on further RCU synchronisation after the sta_state() |
| 2414 | * callback deleted the station. |
| 2415 | */ |
| 2416 | mutex_lock(&mvm->mutex); |
| 2417 | if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) |
| 2418 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 2419 | ERR_PTR(-ENOENT)); |
| 2420 | mutex_unlock(&mvm->mutex); |
| 2421 | } |
| 2422 | |
Johannes Berg | bd1ba66 | 2014-11-13 20:53:45 +0100 | [diff] [blame] | 2423 | static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2424 | const u8 *bssid) |
| 2425 | { |
| 2426 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) |
| 2427 | return; |
| 2428 | |
| 2429 | if (iwlwifi_mod_params.uapsd_disable) { |
| 2430 | vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
| 2431 | return; |
| 2432 | } |
| 2433 | |
| 2434 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
| 2435 | } |
| 2436 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2437 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
| 2438 | struct ieee80211_vif *vif, |
| 2439 | struct ieee80211_sta *sta, |
| 2440 | enum ieee80211_sta_state old_state, |
| 2441 | enum ieee80211_sta_state new_state) |
| 2442 | { |
| 2443 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2444 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2445 | int ret; |
| 2446 | |
| 2447 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", |
| 2448 | sta->addr, old_state, new_state); |
| 2449 | |
| 2450 | /* this would be a mac80211 bug ... but don't crash */ |
| 2451 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) |
| 2452 | return -EINVAL; |
| 2453 | |
| 2454 | /* if a STA is being removed, reuse its ID */ |
| 2455 | flush_work(&mvm->sta_drained_wk); |
| 2456 | |
| 2457 | mutex_lock(&mvm->mutex); |
| 2458 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 2459 | new_state == IEEE80211_STA_NONE) { |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 2460 | /* |
| 2461 | * Firmware bug - it'll crash if the beacon interval is less |
| 2462 | * than 16. We can't avoid connecting at all, so refuse the |
| 2463 | * station state change, this will cause mac80211 to abandon |
| 2464 | * attempts to connect to this AP, and eventually wpa_s will |
| 2465 | * blacklist the AP... |
| 2466 | */ |
| 2467 | if (vif->type == NL80211_IFTYPE_STATION && |
| 2468 | vif->bss_conf.beacon_int < 16) { |
| 2469 | IWL_ERR(mvm, |
| 2470 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", |
| 2471 | sta->addr, vif->bss_conf.beacon_int); |
| 2472 | ret = -EINVAL; |
| 2473 | goto out_unlock; |
| 2474 | } |
Arik Nemtsov | cf7b491 | 2014-05-15 11:44:40 +0300 | [diff] [blame] | 2475 | |
| 2476 | if (sta->tdls && |
| 2477 | (vif->p2p || |
Arik Nemtsov | fa3d07e | 2014-05-15 18:59:32 +0300 | [diff] [blame] | 2478 | iwl_mvm_tdls_sta_count(mvm, NULL) == |
| 2479 | IWL_MVM_TDLS_STA_COUNT || |
Arik Nemtsov | cf7b491 | 2014-05-15 11:44:40 +0300 | [diff] [blame] | 2480 | iwl_mvm_phy_ctx_count(mvm) > 1)) { |
| 2481 | IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); |
| 2482 | ret = -EBUSY; |
| 2483 | goto out_unlock; |
| 2484 | } |
| 2485 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2486 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
Arik Nemtsov | fa3d07e | 2014-05-15 18:59:32 +0300 | [diff] [blame] | 2487 | if (sta->tdls && ret == 0) |
| 2488 | iwl_mvm_recalc_tdls_state(mvm, vif, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2489 | } else if (old_state == IEEE80211_STA_NONE && |
| 2490 | new_state == IEEE80211_STA_AUTH) { |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 2491 | /* |
| 2492 | * EBS may be disabled due to previous failures reported by FW. |
| 2493 | * Reset EBS status here assuming environment has been changed. |
| 2494 | */ |
| 2495 | mvm->last_ebs_successful = true; |
Johannes Berg | bd1ba66 | 2014-11-13 20:53:45 +0100 | [diff] [blame] | 2496 | iwl_mvm_check_uapsd(mvm, vif, sta->addr); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2497 | ret = 0; |
| 2498 | } else if (old_state == IEEE80211_STA_AUTH && |
| 2499 | new_state == IEEE80211_STA_ASSOC) { |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 2500 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
| 2501 | if (ret == 0) |
| 2502 | iwl_mvm_rs_rate_init(mvm, sta, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 2503 | mvmvif->phy_ctxt->channel->band, |
| 2504 | true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2505 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 2506 | new_state == IEEE80211_STA_AUTHORIZED) { |
Arik Nemtsov | f59e0e3c | 2014-06-10 19:56:27 +0300 | [diff] [blame] | 2507 | |
| 2508 | /* we don't support TDLS during DCM */ |
| 2509 | if (iwl_mvm_phy_ctx_count(mvm) > 1) |
| 2510 | iwl_mvm_teardown_tdls_peers(mvm); |
| 2511 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 2512 | /* enable beacon filtering */ |
Avri Altman | fa7b2e7 | 2014-05-20 08:03:24 +0300 | [diff] [blame] | 2513 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2514 | ret = 0; |
| 2515 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
| 2516 | new_state == IEEE80211_STA_ASSOC) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 2517 | /* disable beacon filtering */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2518 | WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2519 | ret = 0; |
| 2520 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 2521 | new_state == IEEE80211_STA_AUTH) { |
| 2522 | ret = 0; |
| 2523 | } else if (old_state == IEEE80211_STA_AUTH && |
| 2524 | new_state == IEEE80211_STA_NONE) { |
| 2525 | ret = 0; |
| 2526 | } else if (old_state == IEEE80211_STA_NONE && |
| 2527 | new_state == IEEE80211_STA_NOTEXIST) { |
| 2528 | ret = iwl_mvm_rm_sta(mvm, vif, sta); |
Arik Nemtsov | fa3d07e | 2014-05-15 18:59:32 +0300 | [diff] [blame] | 2529 | if (sta->tdls) |
| 2530 | iwl_mvm_recalc_tdls_state(mvm, vif, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2531 | } else { |
| 2532 | ret = -EIO; |
| 2533 | } |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 2534 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2535 | mutex_unlock(&mvm->mutex); |
| 2536 | |
Liad Kaufman | 9c126cd | 2014-10-06 19:08:56 +0200 | [diff] [blame] | 2537 | if (sta->tdls && ret == 0) { |
| 2538 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 2539 | new_state == IEEE80211_STA_NONE) |
| 2540 | ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); |
| 2541 | else if (old_state == IEEE80211_STA_NONE && |
| 2542 | new_state == IEEE80211_STA_NOTEXIST) |
| 2543 | ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); |
| 2544 | } |
| 2545 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2546 | return ret; |
| 2547 | } |
| 2548 | |
| 2549 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 2550 | { |
| 2551 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2552 | |
| 2553 | mvm->rts_threshold = value; |
| 2554 | |
| 2555 | return 0; |
| 2556 | } |
| 2557 | |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 2558 | static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, |
| 2559 | struct ieee80211_vif *vif, |
| 2560 | struct ieee80211_sta *sta, u32 changed) |
| 2561 | { |
| 2562 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2563 | |
| 2564 | if (vif->type == NL80211_IFTYPE_STATION && |
| 2565 | changed & IEEE80211_RC_NSS_CHANGED) |
| 2566 | iwl_mvm_sf_update(mvm, vif, false); |
| 2567 | } |
| 2568 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2569 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
| 2570 | struct ieee80211_vif *vif, u16 ac, |
| 2571 | const struct ieee80211_tx_queue_params *params) |
| 2572 | { |
| 2573 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2574 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2575 | |
| 2576 | mvmvif->queue_params[ac] = *params; |
| 2577 | |
| 2578 | /* |
| 2579 | * No need to update right away, we'll get BSS_CHANGED_QOS |
| 2580 | * The exception is P2P_DEVICE interface which needs immediate update. |
| 2581 | */ |
| 2582 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 2583 | int ret; |
| 2584 | |
| 2585 | mutex_lock(&mvm->mutex); |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 2586 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2587 | mutex_unlock(&mvm->mutex); |
| 2588 | return ret; |
| 2589 | } |
| 2590 | return 0; |
| 2591 | } |
| 2592 | |
| 2593 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, |
| 2594 | struct ieee80211_vif *vif) |
| 2595 | { |
| 2596 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2597 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, |
| 2598 | 200 + vif->bss_conf.beacon_int); |
| 2599 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, |
| 2600 | 100 + vif->bss_conf.beacon_int); |
| 2601 | |
| 2602 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) |
| 2603 | return; |
| 2604 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 2605 | /* |
| 2606 | * iwl_mvm_protect_session() reads directly from the device |
| 2607 | * (the system time), so make sure it is available. |
| 2608 | */ |
| 2609 | if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX)) |
| 2610 | return; |
| 2611 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2612 | mutex_lock(&mvm->mutex); |
| 2613 | /* Try really hard to protect the session and hear a beacon */ |
Liad Kaufman | d20d37b | 2014-07-06 17:14:39 +0300 | [diff] [blame] | 2614 | iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2615 | mutex_unlock(&mvm->mutex); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 2616 | |
| 2617 | iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2618 | } |
| 2619 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2620 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
| 2621 | struct ieee80211_vif *vif, |
| 2622 | struct cfg80211_sched_scan_request *req, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 2623 | struct ieee80211_scan_ies *ies) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2624 | { |
| 2625 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2626 | int ret; |
| 2627 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2628 | if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { |
| 2629 | ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS); |
| 2630 | if (ret) |
| 2631 | return ret; |
| 2632 | } |
Eliad Peller | 4660dfb | 2014-06-22 18:15:59 +0300 | [diff] [blame] | 2633 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2634 | mutex_lock(&mvm->mutex); |
| 2635 | |
Arik Nemtsov | 88931cc | 2014-03-05 12:26:15 +0200 | [diff] [blame] | 2636 | if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) { |
| 2637 | IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n"); |
| 2638 | ret = -EBUSY; |
| 2639 | goto out; |
| 2640 | } |
| 2641 | |
Luciano Coelho | 1f94038 | 2015-02-10 13:03:38 +0200 | [diff] [blame] | 2642 | if (!vif->bss_conf.idle) { |
David Spinadel | bd5e474 | 2014-04-24 13:15:29 +0300 | [diff] [blame] | 2643 | ret = -EBUSY; |
| 2644 | goto out; |
| 2645 | } |
| 2646 | |
Eliad Peller | 4660dfb | 2014-06-22 18:15:59 +0300 | [diff] [blame] | 2647 | if (mvm->scan_status != IWL_MVM_SCAN_NONE) { |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2648 | ret = -EBUSY; |
| 2649 | goto out; |
| 2650 | } |
| 2651 | |
Luciano Coelho | b141c23 | 2014-10-01 13:22:40 +0300 | [diff] [blame] | 2652 | ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2653 | if (ret) |
Luciano Coelho | b141c23 | 2014-10-01 13:22:40 +0300 | [diff] [blame] | 2654 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2655 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2656 | out: |
| 2657 | mutex_unlock(&mvm->mutex); |
| 2658 | return ret; |
| 2659 | } |
| 2660 | |
Johannes Berg | 37e3308 | 2014-02-17 10:48:17 +0100 | [diff] [blame] | 2661 | static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, |
| 2662 | struct ieee80211_vif *vif) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2663 | { |
| 2664 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 2665 | int ret; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2666 | |
| 2667 | mutex_lock(&mvm->mutex); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 2668 | ret = iwl_mvm_scan_offload_stop(mvm, false); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2669 | mutex_unlock(&mvm->mutex); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 2670 | iwl_mvm_wait_for_async_handlers(mvm); |
Johannes Berg | 37e3308 | 2014-02-17 10:48:17 +0100 | [diff] [blame] | 2671 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 2672 | return ret; |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 2673 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2674 | } |
| 2675 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2676 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
| 2677 | enum set_key_cmd cmd, |
| 2678 | struct ieee80211_vif *vif, |
| 2679 | struct ieee80211_sta *sta, |
| 2680 | struct ieee80211_key_conf *key) |
| 2681 | { |
| 2682 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2683 | int ret; |
| 2684 | |
| 2685 | if (iwlwifi_mod_params.sw_crypto) { |
| 2686 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); |
| 2687 | return -EOPNOTSUPP; |
| 2688 | } |
| 2689 | |
| 2690 | switch (key->cipher) { |
| 2691 | case WLAN_CIPHER_SUITE_TKIP: |
| 2692 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 2693 | /* fall-through */ |
| 2694 | case WLAN_CIPHER_SUITE_CCMP: |
| 2695 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 2696 | break; |
| 2697 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 2698 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); |
| 2699 | break; |
| 2700 | case WLAN_CIPHER_SUITE_WEP40: |
| 2701 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2702 | /* For non-client mode, only use WEP keys for TX as we probably |
| 2703 | * don't have a station yet anyway and would then have to keep |
| 2704 | * track of the keys, linking them to each of the clients/peers |
| 2705 | * as they appear. For now, don't do that, for performance WEP |
| 2706 | * offload doesn't really matter much, but we need it for some |
| 2707 | * other offload features in client mode. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2708 | */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2709 | if (vif->type != NL80211_IFTYPE_STATION) |
| 2710 | return 0; |
| 2711 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2712 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 2713 | /* currently FW supports only one optional cipher scheme */ |
| 2714 | if (hw->n_cipher_schemes && |
| 2715 | hw->cipher_schemes->cipher == key->cipher) |
| 2716 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
| 2717 | else |
| 2718 | return -EOPNOTSUPP; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | mutex_lock(&mvm->mutex); |
| 2722 | |
| 2723 | switch (cmd) { |
| 2724 | case SET_KEY: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2725 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
| 2726 | vif->type == NL80211_IFTYPE_AP) && !sta) { |
| 2727 | /* |
| 2728 | * GTK on AP interface is a TX-only key, return 0; |
| 2729 | * on IBSS they're per-station and because we're lazy |
| 2730 | * we don't support them for RX, so do the same. |
| 2731 | */ |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 2732 | ret = 0; |
| 2733 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
| 2734 | break; |
| 2735 | } |
| 2736 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2737 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
| 2738 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); |
| 2739 | if (ret) { |
| 2740 | IWL_WARN(mvm, "set key failed\n"); |
| 2741 | /* |
| 2742 | * can't add key for RX, but we don't need it |
| 2743 | * in the device for TX so still return 0 |
| 2744 | */ |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 2745 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2746 | ret = 0; |
| 2747 | } |
| 2748 | |
| 2749 | break; |
| 2750 | case DISABLE_KEY: |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 2751 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
| 2752 | ret = 0; |
| 2753 | break; |
| 2754 | } |
| 2755 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2756 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
| 2757 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); |
| 2758 | break; |
| 2759 | default: |
| 2760 | ret = -EINVAL; |
| 2761 | } |
| 2762 | |
| 2763 | mutex_unlock(&mvm->mutex); |
| 2764 | return ret; |
| 2765 | } |
| 2766 | |
| 2767 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 2768 | struct ieee80211_vif *vif, |
| 2769 | struct ieee80211_key_conf *keyconf, |
| 2770 | struct ieee80211_sta *sta, |
| 2771 | u32 iv32, u16 *phase1key) |
| 2772 | { |
| 2773 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2774 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2775 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) |
| 2776 | return; |
| 2777 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2778 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
| 2779 | } |
| 2780 | |
| 2781 | |
Ariej Marjieh | b112889 | 2014-07-16 21:11:12 +0300 | [diff] [blame] | 2782 | static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, |
| 2783 | struct iwl_rx_packet *pkt, void *data) |
| 2784 | { |
| 2785 | struct iwl_mvm *mvm = |
| 2786 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 2787 | struct iwl_hs20_roc_res *resp; |
| 2788 | int resp_len = iwl_rx_packet_payload_len(pkt); |
| 2789 | struct iwl_mvm_time_event_data *te_data = data; |
| 2790 | |
| 2791 | if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) |
| 2792 | return true; |
| 2793 | |
| 2794 | if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { |
| 2795 | IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); |
| 2796 | return true; |
| 2797 | } |
| 2798 | |
| 2799 | resp = (void *)pkt->data; |
| 2800 | |
| 2801 | IWL_DEBUG_TE(mvm, |
| 2802 | "Aux ROC: Recieved response from ucode: status=%d uid=%d\n", |
| 2803 | resp->status, resp->event_unique_id); |
| 2804 | |
| 2805 | te_data->uid = le32_to_cpu(resp->event_unique_id); |
| 2806 | IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", |
| 2807 | te_data->uid); |
| 2808 | |
| 2809 | spin_lock_bh(&mvm->time_event_lock); |
| 2810 | list_add_tail(&te_data->list, &mvm->aux_roc_te_list); |
| 2811 | spin_unlock_bh(&mvm->time_event_lock); |
| 2812 | |
| 2813 | return true; |
| 2814 | } |
| 2815 | |
| 2816 | #define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000 |
| 2817 | static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, |
| 2818 | struct ieee80211_channel *channel, |
| 2819 | struct ieee80211_vif *vif, |
| 2820 | int duration) |
| 2821 | { |
| 2822 | int res, time_reg = DEVICE_SYSTEM_TIME_REG; |
| 2823 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2824 | struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; |
| 2825 | static const u8 time_event_response[] = { HOT_SPOT_CMD }; |
| 2826 | struct iwl_notification_wait wait_time_event; |
| 2827 | struct iwl_hs20_roc_req aux_roc_req = { |
| 2828 | .action = cpu_to_le32(FW_CTXT_ACTION_ADD), |
| 2829 | .id_and_color = |
| 2830 | cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), |
| 2831 | .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), |
| 2832 | /* Set the channel info data */ |
| 2833 | .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ? |
| 2834 | PHY_BAND_24 : PHY_BAND_5, |
| 2835 | .channel_info.channel = channel->hw_value, |
| 2836 | .channel_info.width = PHY_VHT_CHANNEL_MODE20, |
| 2837 | /* Set the time and duration */ |
| 2838 | .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)), |
| 2839 | .apply_time_max_delay = |
| 2840 | cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)), |
| 2841 | .duration = cpu_to_le32(MSEC_TO_TU(duration)), |
| 2842 | }; |
| 2843 | |
| 2844 | /* Set the node address */ |
| 2845 | memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN); |
| 2846 | |
Matti Gottlieb | a6cc516 | 2014-09-29 11:46:04 +0300 | [diff] [blame] | 2847 | lockdep_assert_held(&mvm->mutex); |
| 2848 | |
| 2849 | spin_lock_bh(&mvm->time_event_lock); |
| 2850 | |
| 2851 | if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { |
| 2852 | spin_unlock_bh(&mvm->time_event_lock); |
| 2853 | return -EIO; |
| 2854 | } |
| 2855 | |
Ariej Marjieh | b112889 | 2014-07-16 21:11:12 +0300 | [diff] [blame] | 2856 | te_data->vif = vif; |
| 2857 | te_data->duration = duration; |
| 2858 | te_data->id = HOT_SPOT_CMD; |
| 2859 | |
Ariej Marjieh | b112889 | 2014-07-16 21:11:12 +0300 | [diff] [blame] | 2860 | spin_unlock_bh(&mvm->time_event_lock); |
| 2861 | |
| 2862 | /* |
| 2863 | * Use a notification wait, which really just processes the |
| 2864 | * command response and doesn't wait for anything, in order |
| 2865 | * to be able to process the response and get the UID inside |
| 2866 | * the RX path. Using CMD_WANT_SKB doesn't work because it |
| 2867 | * stores the buffer and then wakes up this thread, by which |
| 2868 | * time another notification (that the time event started) |
| 2869 | * might already be processed unsuccessfully. |
| 2870 | */ |
| 2871 | iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, |
| 2872 | time_event_response, |
| 2873 | ARRAY_SIZE(time_event_response), |
| 2874 | iwl_mvm_rx_aux_roc, te_data); |
| 2875 | |
| 2876 | res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req), |
| 2877 | &aux_roc_req); |
| 2878 | |
| 2879 | if (res) { |
| 2880 | IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); |
| 2881 | iwl_remove_notification(&mvm->notif_wait, &wait_time_event); |
| 2882 | goto out_clear_te; |
| 2883 | } |
| 2884 | |
| 2885 | /* No need to wait for anything, so just pass 1 (0 isn't valid) */ |
| 2886 | res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); |
| 2887 | /* should never fail */ |
| 2888 | WARN_ON_ONCE(res); |
| 2889 | |
| 2890 | if (res) { |
| 2891 | out_clear_te: |
| 2892 | spin_lock_bh(&mvm->time_event_lock); |
| 2893 | iwl_mvm_te_clear_data(mvm, te_data); |
| 2894 | spin_unlock_bh(&mvm->time_event_lock); |
| 2895 | } |
| 2896 | |
| 2897 | return res; |
| 2898 | } |
| 2899 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2900 | static int iwl_mvm_roc(struct ieee80211_hw *hw, |
| 2901 | struct ieee80211_vif *vif, |
| 2902 | struct ieee80211_channel *channel, |
Ilan Peer | d339d5c | 2013-02-12 09:34:13 +0200 | [diff] [blame] | 2903 | int duration, |
| 2904 | enum ieee80211_roc_type type) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2905 | { |
| 2906 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2907 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2908 | struct cfg80211_chan_def chandef; |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2909 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
| 2910 | int ret, i; |
| 2911 | |
| 2912 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, |
| 2913 | duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2914 | |
Matti Gottlieb | a6cc516 | 2014-09-29 11:46:04 +0300 | [diff] [blame] | 2915 | mutex_lock(&mvm->mutex); |
| 2916 | |
Ariej Marjieh | b112889 | 2014-07-16 21:11:12 +0300 | [diff] [blame] | 2917 | switch (vif->type) { |
| 2918 | case NL80211_IFTYPE_STATION: |
Luciano Coelho | 5ac6c72 | 2014-10-21 16:12:18 +0300 | [diff] [blame] | 2919 | if (mvm->fw->ucode_capa.capa[0] & |
| 2920 | IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) { |
| 2921 | /* Use aux roc framework (HS20) */ |
| 2922 | ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, |
| 2923 | vif, duration); |
| 2924 | goto out_unlock; |
| 2925 | } |
| 2926 | IWL_ERR(mvm, "hotspot not supported\n"); |
| 2927 | ret = -EINVAL; |
Matti Gottlieb | a6cc516 | 2014-09-29 11:46:04 +0300 | [diff] [blame] | 2928 | goto out_unlock; |
Ariej Marjieh | b112889 | 2014-07-16 21:11:12 +0300 | [diff] [blame] | 2929 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2930 | /* handle below */ |
| 2931 | break; |
| 2932 | default: |
| 2933 | IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); |
Matti Gottlieb | a6cc516 | 2014-09-29 11:46:04 +0300 | [diff] [blame] | 2934 | ret = -EINVAL; |
| 2935 | goto out_unlock; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2936 | } |
| 2937 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2938 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 2939 | phy_ctxt = &mvm->phy_ctxts[i]; |
| 2940 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) |
| 2941 | continue; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2942 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2943 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { |
| 2944 | /* |
| 2945 | * Unbind the P2P_DEVICE from the current PHY context, |
| 2946 | * and if the PHY context is not used remove it. |
| 2947 | */ |
| 2948 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 2949 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 2950 | goto out_unlock; |
| 2951 | |
| 2952 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 2953 | |
| 2954 | /* Bind the P2P_DEVICE to the current PHY Context */ |
| 2955 | mvmvif->phy_ctxt = phy_ctxt; |
| 2956 | |
| 2957 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 2958 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 2959 | goto out_unlock; |
| 2960 | |
| 2961 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 2962 | goto schedule_time_event; |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | /* Need to update the PHY context only if the ROC channel changed */ |
| 2967 | if (channel == mvmvif->phy_ctxt->channel) |
| 2968 | goto schedule_time_event; |
| 2969 | |
| 2970 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
| 2971 | |
| 2972 | /* |
| 2973 | * Change the PHY context configuration as it is currently referenced |
| 2974 | * only by the P2P Device MAC |
| 2975 | */ |
| 2976 | if (mvmvif->phy_ctxt->ref == 1) { |
| 2977 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, |
| 2978 | &chandef, 1, 1); |
| 2979 | if (ret) |
| 2980 | goto out_unlock; |
| 2981 | } else { |
| 2982 | /* |
| 2983 | * The PHY context is shared with other MACs. Need to remove the |
| 2984 | * P2P Device from the binding, allocate an new PHY context and |
| 2985 | * create a new binding |
| 2986 | */ |
| 2987 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 2988 | if (!phy_ctxt) { |
| 2989 | ret = -ENOSPC; |
| 2990 | goto out_unlock; |
| 2991 | } |
| 2992 | |
| 2993 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, |
| 2994 | 1, 1); |
| 2995 | if (ret) { |
| 2996 | IWL_ERR(mvm, "Failed to change PHY context\n"); |
| 2997 | goto out_unlock; |
| 2998 | } |
| 2999 | |
| 3000 | /* Unbind the P2P_DEVICE from the current PHY context */ |
| 3001 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 3002 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 3003 | goto out_unlock; |
| 3004 | |
| 3005 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 3006 | |
| 3007 | /* Bind the P2P_DEVICE to the new allocated PHY context */ |
| 3008 | mvmvif->phy_ctxt = phy_ctxt; |
| 3009 | |
| 3010 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 3011 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 3012 | goto out_unlock; |
| 3013 | |
| 3014 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 3015 | } |
| 3016 | |
| 3017 | schedule_time_event: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3018 | /* Schedule the time events */ |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 3019 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3020 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 3021 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3022 | mutex_unlock(&mvm->mutex); |
| 3023 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3024 | return ret; |
| 3025 | } |
| 3026 | |
| 3027 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) |
| 3028 | { |
| 3029 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3030 | |
| 3031 | IWL_DEBUG_MAC80211(mvm, "enter\n"); |
| 3032 | |
| 3033 | mutex_lock(&mvm->mutex); |
Matti Gottlieb | bf5da87 | 2014-11-16 10:25:12 +0200 | [diff] [blame] | 3034 | iwl_mvm_stop_roc(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3035 | mutex_unlock(&mvm->mutex); |
| 3036 | |
| 3037 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
| 3038 | return 0; |
| 3039 | } |
| 3040 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3041 | static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, |
| 3042 | struct ieee80211_chanctx_conf *ctx) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3043 | { |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3044 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 3045 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3046 | int ret; |
| 3047 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3048 | lockdep_assert_held(&mvm->mutex); |
| 3049 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 3050 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3051 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3052 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 3053 | if (!phy_ctxt) { |
| 3054 | ret = -ENOSPC; |
| 3055 | goto out; |
| 3056 | } |
| 3057 | |
Eliad Peller | dcbc3e1 | 2013-10-31 14:31:25 +0200 | [diff] [blame] | 3058 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 3059 | ctx->rx_chains_static, |
| 3060 | ctx->rx_chains_dynamic); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3061 | if (ret) { |
| 3062 | IWL_ERR(mvm, "Failed to add PHY context\n"); |
| 3063 | goto out; |
| 3064 | } |
| 3065 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 3066 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3067 | *phy_ctxt_id = phy_ctxt->id; |
| 3068 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3069 | return ret; |
| 3070 | } |
| 3071 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3072 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, |
| 3073 | struct ieee80211_chanctx_conf *ctx) |
| 3074 | { |
| 3075 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3076 | int ret; |
| 3077 | |
| 3078 | mutex_lock(&mvm->mutex); |
| 3079 | ret = __iwl_mvm_add_chanctx(mvm, ctx); |
| 3080 | mutex_unlock(&mvm->mutex); |
| 3081 | |
| 3082 | return ret; |
| 3083 | } |
| 3084 | |
| 3085 | static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, |
| 3086 | struct ieee80211_chanctx_conf *ctx) |
| 3087 | { |
| 3088 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 3089 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; |
| 3090 | |
| 3091 | lockdep_assert_held(&mvm->mutex); |
| 3092 | |
| 3093 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); |
| 3094 | } |
| 3095 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3096 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, |
| 3097 | struct ieee80211_chanctx_conf *ctx) |
| 3098 | { |
| 3099 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3100 | |
| 3101 | mutex_lock(&mvm->mutex); |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3102 | __iwl_mvm_remove_chanctx(mvm, ctx); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3103 | mutex_unlock(&mvm->mutex); |
| 3104 | } |
| 3105 | |
| 3106 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, |
| 3107 | struct ieee80211_chanctx_conf *ctx, |
| 3108 | u32 changed) |
| 3109 | { |
| 3110 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3111 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 3112 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3113 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 3114 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
| 3115 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | |
| 3116 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | |
Arik Nemtsov | 2dceeda | 2013-12-29 17:57:53 +0200 | [diff] [blame] | 3117 | IEEE80211_CHANCTX_CHANGE_RADAR | |
| 3118 | IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 3119 | "Cannot change PHY. Ref=%d, changed=0x%X\n", |
| 3120 | phy_ctxt->ref, changed)) |
| 3121 | return; |
| 3122 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3123 | mutex_lock(&mvm->mutex); |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 3124 | iwl_mvm_bt_coex_vif_change(mvm); |
Eliad Peller | dcbc3e1 | 2013-10-31 14:31:25 +0200 | [diff] [blame] | 3125 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3126 | ctx->rx_chains_static, |
| 3127 | ctx->rx_chains_dynamic); |
| 3128 | mutex_unlock(&mvm->mutex); |
| 3129 | } |
| 3130 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3131 | static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, |
| 3132 | struct ieee80211_vif *vif, |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3133 | struct ieee80211_chanctx_conf *ctx, |
| 3134 | bool switching_chanctx) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3135 | { |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3136 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 3137 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3138 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3139 | int ret; |
| 3140 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3141 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3142 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 3143 | mvmvif->phy_ctxt = phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3144 | |
| 3145 | switch (vif->type) { |
| 3146 | case NL80211_IFTYPE_AP: |
Luciano Coelho | 4741dd0 | 2014-11-10 11:10:13 +0200 | [diff] [blame] | 3147 | /* only needed if we're switching chanctx (i.e. during CSA) */ |
| 3148 | if (switching_chanctx) { |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3149 | mvmvif->ap_ibss_active = true; |
| 3150 | break; |
| 3151 | } |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 3152 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3153 | /* |
| 3154 | * The AP binding flow is handled as part of the start_ap flow |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 3155 | * (in bss_info_changed), similarly for IBSS. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3156 | */ |
| 3157 | ret = 0; |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3158 | goto out; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3159 | case NL80211_IFTYPE_STATION: |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 3160 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3161 | case NL80211_IFTYPE_MONITOR: |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 3162 | /* always disable PS when a monitor interface is active */ |
| 3163 | mvmvif->ps_disabled = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3164 | break; |
| 3165 | default: |
| 3166 | ret = -EINVAL; |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3167 | goto out; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 3171 | if (ret) |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3172 | goto out; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3173 | |
| 3174 | /* |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 3175 | * Power state must be updated before quotas, |
| 3176 | * otherwise fw will complain. |
| 3177 | */ |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 3178 | iwl_mvm_power_update_mac(mvm); |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 3179 | |
| 3180 | /* Setting the quota at this stage is only required for monitor |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3181 | * interfaces. For the other types, the bss_info changed flow |
| 3182 | * will handle quota settings. |
| 3183 | */ |
| 3184 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 3185 | mvmvif->monitor_active = true; |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 3186 | ret = iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3187 | if (ret) |
| 3188 | goto out_remove_binding; |
| 3189 | } |
| 3190 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3191 | /* Handle binding during CSA */ |
Luciano Coelho | a57c688 | 2014-11-10 11:10:16 +0200 | [diff] [blame] | 3192 | if (vif->type == NL80211_IFTYPE_AP) { |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 3193 | iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 3194 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3195 | } |
| 3196 | |
Luciano Coelho | 4741dd0 | 2014-11-10 11:10:13 +0200 | [diff] [blame] | 3197 | if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) { |
Luciano Coelho | 686e7fe | 2014-11-10 11:10:21 +0200 | [diff] [blame] | 3198 | u32 duration = 2 * vif->bss_conf.beacon_int; |
| 3199 | |
| 3200 | /* iwl_mvm_protect_session() reads directly from the |
| 3201 | * device (the system time), so make sure it is |
| 3202 | * available. |
| 3203 | */ |
| 3204 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA); |
| 3205 | if (ret) |
| 3206 | goto out_remove_binding; |
| 3207 | |
| 3208 | /* Protect the session to make sure we hear the first |
| 3209 | * beacon on the new channel. |
| 3210 | */ |
| 3211 | iwl_mvm_protect_session(mvm, vif, duration, duration, |
| 3212 | vif->bss_conf.beacon_int / 2, |
| 3213 | true); |
| 3214 | |
| 3215 | iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA); |
| 3216 | |
Luciano Coelho | a57c688 | 2014-11-10 11:10:16 +0200 | [diff] [blame] | 3217 | iwl_mvm_update_quotas(mvm, NULL); |
Luciano Coelho | 0ce04ce | 2014-05-08 16:03:39 +0300 | [diff] [blame] | 3218 | } |
| 3219 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3220 | goto out; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3221 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3222 | out_remove_binding: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3223 | iwl_mvm_binding_remove_vif(mvm, vif); |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 3224 | iwl_mvm_power_update_mac(mvm); |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3225 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3226 | if (ret) |
| 3227 | mvmvif->phy_ctxt = NULL; |
| 3228 | return ret; |
| 3229 | } |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3230 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 3231 | struct ieee80211_vif *vif, |
| 3232 | struct ieee80211_chanctx_conf *ctx) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3233 | { |
| 3234 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3235 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3236 | |
| 3237 | mutex_lock(&mvm->mutex); |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3238 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3239 | mutex_unlock(&mvm->mutex); |
| 3240 | |
| 3241 | return ret; |
| 3242 | } |
| 3243 | |
| 3244 | static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, |
| 3245 | struct ieee80211_vif *vif, |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3246 | struct ieee80211_chanctx_conf *ctx, |
| 3247 | bool switching_chanctx) |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3248 | { |
| 3249 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3250 | struct ieee80211_vif *disabled_vif = NULL; |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3251 | |
| 3252 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3253 | |
| 3254 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); |
| 3255 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3256 | switch (vif->type) { |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 3257 | case NL80211_IFTYPE_ADHOC: |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3258 | goto out; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3259 | case NL80211_IFTYPE_MONITOR: |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 3260 | mvmvif->monitor_active = false; |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 3261 | mvmvif->ps_disabled = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3262 | break; |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3263 | case NL80211_IFTYPE_AP: |
| 3264 | /* This part is triggered only during CSA */ |
Luciano Coelho | 4741dd0 | 2014-11-10 11:10:13 +0200 | [diff] [blame] | 3265 | if (!switching_chanctx || !mvmvif->ap_ibss_active) |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3266 | goto out; |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3267 | |
Andrei Otcheretianski | 7ef0aab | 2014-11-10 11:10:11 +0200 | [diff] [blame] | 3268 | mvmvif->csa_countdown = false; |
| 3269 | |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3270 | /* Set CS bit on all the stations */ |
| 3271 | iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); |
| 3272 | |
| 3273 | /* Save blocked iface, the timeout is set on the next beacon */ |
| 3274 | rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); |
| 3275 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3276 | mvmvif->ap_ibss_active = false; |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3277 | break; |
| 3278 | case NL80211_IFTYPE_STATION: |
| 3279 | if (!switching_chanctx) |
| 3280 | break; |
| 3281 | |
| 3282 | disabled_vif = vif; |
| 3283 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 3284 | iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3285 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3286 | default: |
| 3287 | break; |
| 3288 | } |
| 3289 | |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3290 | iwl_mvm_update_quotas(mvm, disabled_vif); |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 3291 | iwl_mvm_binding_remove_vif(mvm, vif); |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 3292 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3293 | out: |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 3294 | mvmvif->phy_ctxt = NULL; |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 3295 | iwl_mvm_power_update_mac(mvm); |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 3299 | struct ieee80211_vif *vif, |
| 3300 | struct ieee80211_chanctx_conf *ctx) |
| 3301 | { |
| 3302 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3303 | |
| 3304 | mutex_lock(&mvm->mutex); |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3305 | __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3306 | mutex_unlock(&mvm->mutex); |
| 3307 | } |
| 3308 | |
Luciano Coelho | 50cc957 | 2014-11-10 11:10:08 +0200 | [diff] [blame] | 3309 | static int |
| 3310 | iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, |
| 3311 | struct ieee80211_vif_chanctx_switch *vifs) |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3312 | { |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3313 | int ret; |
| 3314 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3315 | mutex_lock(&mvm->mutex); |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3316 | __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3317 | __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); |
| 3318 | |
| 3319 | ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); |
| 3320 | if (ret) { |
| 3321 | IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); |
| 3322 | goto out_reassign; |
| 3323 | } |
| 3324 | |
Luciano Coelho | f0c9778 | 2014-03-05 15:41:48 +0200 | [diff] [blame] | 3325 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, |
| 3326 | true); |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3327 | if (ret) { |
| 3328 | IWL_ERR(mvm, |
| 3329 | "failed to assign new_ctx during channel switch\n"); |
| 3330 | goto out_remove; |
| 3331 | } |
| 3332 | |
Arik Nemtsov | f697267 | 2014-06-15 16:03:55 +0300 | [diff] [blame] | 3333 | /* we don't support TDLS during DCM - can be caused by channel switch */ |
| 3334 | if (iwl_mvm_phy_ctx_count(mvm) > 1) |
| 3335 | iwl_mvm_teardown_tdls_peers(mvm); |
| 3336 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3337 | goto out; |
| 3338 | |
| 3339 | out_remove: |
| 3340 | __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); |
| 3341 | |
| 3342 | out_reassign: |
Luciano Coelho | 6fd1fb6 | 2014-11-10 11:10:10 +0200 | [diff] [blame] | 3343 | if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3344 | IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); |
| 3345 | goto out_restart; |
| 3346 | } |
| 3347 | |
Luciano Coelho | 6fd1fb6 | 2014-11-10 11:10:10 +0200 | [diff] [blame] | 3348 | if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, |
| 3349 | true)) { |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3350 | IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); |
| 3351 | goto out_restart; |
| 3352 | } |
| 3353 | |
| 3354 | goto out; |
| 3355 | |
| 3356 | out_restart: |
| 3357 | /* things keep failing, better restart the hw */ |
| 3358 | iwl_mvm_nic_restart(mvm, false); |
| 3359 | |
| 3360 | out: |
| 3361 | mutex_unlock(&mvm->mutex); |
Luciano Coelho | 50cc957 | 2014-11-10 11:10:08 +0200 | [diff] [blame] | 3362 | |
| 3363 | return ret; |
| 3364 | } |
| 3365 | |
Luciano Coelho | 48a256e | 2014-11-10 11:10:09 +0200 | [diff] [blame] | 3366 | static int |
| 3367 | iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, |
| 3368 | struct ieee80211_vif_chanctx_switch *vifs) |
| 3369 | { |
| 3370 | int ret; |
| 3371 | |
| 3372 | mutex_lock(&mvm->mutex); |
| 3373 | __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); |
| 3374 | |
| 3375 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, |
| 3376 | true); |
| 3377 | if (ret) { |
| 3378 | IWL_ERR(mvm, |
| 3379 | "failed to assign new_ctx during channel switch\n"); |
| 3380 | goto out_reassign; |
| 3381 | } |
| 3382 | |
| 3383 | goto out; |
| 3384 | |
| 3385 | out_reassign: |
| 3386 | if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, |
| 3387 | true)) { |
| 3388 | IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); |
| 3389 | goto out_restart; |
| 3390 | } |
| 3391 | |
| 3392 | goto out; |
| 3393 | |
| 3394 | out_restart: |
| 3395 | /* things keep failing, better restart the hw */ |
| 3396 | iwl_mvm_nic_restart(mvm, false); |
| 3397 | |
| 3398 | out: |
| 3399 | mutex_unlock(&mvm->mutex); |
| 3400 | |
| 3401 | return ret; |
| 3402 | } |
| 3403 | |
Luciano Coelho | 50cc957 | 2014-11-10 11:10:08 +0200 | [diff] [blame] | 3404 | static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, |
| 3405 | struct ieee80211_vif_chanctx_switch *vifs, |
| 3406 | int n_vifs, |
| 3407 | enum ieee80211_chanctx_switch_mode mode) |
| 3408 | { |
| 3409 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3410 | int ret; |
| 3411 | |
| 3412 | /* we only support a single-vif right now */ |
| 3413 | if (n_vifs > 1) |
| 3414 | return -EOPNOTSUPP; |
| 3415 | |
| 3416 | switch (mode) { |
| 3417 | case CHANCTX_SWMODE_SWAP_CONTEXTS: |
| 3418 | ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs); |
| 3419 | break; |
| 3420 | case CHANCTX_SWMODE_REASSIGN_VIF: |
Luciano Coelho | 48a256e | 2014-11-10 11:10:09 +0200 | [diff] [blame] | 3421 | ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs); |
Luciano Coelho | 50cc957 | 2014-11-10 11:10:08 +0200 | [diff] [blame] | 3422 | break; |
| 3423 | default: |
| 3424 | ret = -EOPNOTSUPP; |
| 3425 | break; |
| 3426 | } |
| 3427 | |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3428 | return ret; |
| 3429 | } |
| 3430 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3431 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, |
| 3432 | struct ieee80211_sta *sta, |
| 3433 | bool set) |
| 3434 | { |
| 3435 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 3436 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3437 | |
| 3438 | if (!mvm_sta || !mvm_sta->vif) { |
| 3439 | IWL_ERR(mvm, "Station is not associated to a vif\n"); |
| 3440 | return -EINVAL; |
| 3441 | } |
| 3442 | |
| 3443 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); |
| 3444 | } |
| 3445 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 3446 | #ifdef CONFIG_NL80211_TESTMODE |
| 3447 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { |
| 3448 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, |
| 3449 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, |
Johannes Berg | f6c6ad42 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 3450 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 3451 | }; |
| 3452 | |
| 3453 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, |
| 3454 | struct ieee80211_vif *vif, |
| 3455 | void *data, int len) |
| 3456 | { |
| 3457 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; |
| 3458 | int err; |
| 3459 | u32 noa_duration; |
| 3460 | |
| 3461 | err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy); |
| 3462 | if (err) |
| 3463 | return err; |
| 3464 | |
| 3465 | if (!tb[IWL_MVM_TM_ATTR_CMD]) |
| 3466 | return -EINVAL; |
| 3467 | |
| 3468 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { |
| 3469 | case IWL_MVM_TM_CMD_SET_NOA: |
| 3470 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || |
| 3471 | !vif->bss_conf.enable_beacon || |
| 3472 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) |
| 3473 | return -EINVAL; |
| 3474 | |
| 3475 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); |
| 3476 | if (noa_duration >= vif->bss_conf.beacon_int) |
| 3477 | return -EINVAL; |
| 3478 | |
| 3479 | mvm->noa_duration = noa_duration; |
| 3480 | mvm->noa_vif = vif; |
| 3481 | |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 3482 | return iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | f6c6ad42 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 3483 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
| 3484 | /* must be associated client vif - ignore authorized */ |
| 3485 | if (!vif || vif->type != NL80211_IFTYPE_STATION || |
| 3486 | !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || |
| 3487 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) |
| 3488 | return -EINVAL; |
| 3489 | |
| 3490 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 3491 | return iwl_mvm_enable_beacon_filter(mvm, vif, 0); |
| 3492 | return iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | return -EOPNOTSUPP; |
| 3496 | } |
| 3497 | |
| 3498 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, |
| 3499 | struct ieee80211_vif *vif, |
| 3500 | void *data, int len) |
| 3501 | { |
| 3502 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3503 | int err; |
| 3504 | |
| 3505 | mutex_lock(&mvm->mutex); |
| 3506 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); |
| 3507 | mutex_unlock(&mvm->mutex); |
| 3508 | |
| 3509 | return err; |
| 3510 | } |
| 3511 | #endif |
| 3512 | |
Luciano Coelho | 622e3f9 | 2014-11-10 11:10:17 +0200 | [diff] [blame] | 3513 | static void iwl_mvm_channel_switch(struct ieee80211_hw *hw, |
| 3514 | struct ieee80211_vif *vif, |
| 3515 | struct ieee80211_channel_switch *chsw) |
| 3516 | { |
| 3517 | /* By implementing this operation, we prevent mac80211 from |
| 3518 | * starting its own channel switch timer, so that we can call |
| 3519 | * ieee80211_chswitch_done() ourselves at the right time |
| 3520 | * (which is when the absence time event starts). |
| 3521 | */ |
| 3522 | |
| 3523 | IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), |
| 3524 | "dummy channel switch op\n"); |
| 3525 | } |
| 3526 | |
Luciano Coelho | f028905 | 2014-11-10 11:10:06 +0200 | [diff] [blame] | 3527 | static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, |
| 3528 | struct ieee80211_vif *vif, |
| 3529 | struct ieee80211_channel_switch *chsw) |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3530 | { |
| 3531 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Andrei Otcheretianski | 664322f | 2014-06-05 16:40:36 +0300 | [diff] [blame] | 3532 | struct ieee80211_vif *csa_vif; |
Luciano Coelho | f6c3482 | 2014-11-10 11:10:12 +0200 | [diff] [blame] | 3533 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3534 | u32 apply_time; |
Luciano Coelho | f028905 | 2014-11-10 11:10:06 +0200 | [diff] [blame] | 3535 | int ret; |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3536 | |
| 3537 | mutex_lock(&mvm->mutex); |
Andrei Otcheretianski | 664322f | 2014-06-05 16:40:36 +0300 | [diff] [blame] | 3538 | |
Luciano Coelho | 6b20d77 | 2014-11-10 11:10:07 +0200 | [diff] [blame] | 3539 | IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", |
Luciano Coelho | f028905 | 2014-11-10 11:10:06 +0200 | [diff] [blame] | 3540 | chsw->chandef.center_freq1); |
Luciano Coelho | 6b20d77 | 2014-11-10 11:10:07 +0200 | [diff] [blame] | 3541 | |
Emmanuel Grumbach | f35d9c5 | 2015-02-10 10:49:51 +0200 | [diff] [blame] | 3542 | iwl_fw_dbg_trigger_simple_stop(mvm, vif, FW_DBG_TRIGGER_CHANNEL_SWITCH, |
| 3543 | NULL, 0); |
| 3544 | |
Luciano Coelho | 6b20d77 | 2014-11-10 11:10:07 +0200 | [diff] [blame] | 3545 | switch (vif->type) { |
| 3546 | case NL80211_IFTYPE_AP: |
| 3547 | csa_vif = |
| 3548 | rcu_dereference_protected(mvm->csa_vif, |
| 3549 | lockdep_is_held(&mvm->mutex)); |
| 3550 | if (WARN_ONCE(csa_vif && csa_vif->csa_active, |
| 3551 | "Another CSA is already in progress")) { |
| 3552 | ret = -EBUSY; |
| 3553 | goto out_unlock; |
| 3554 | } |
| 3555 | |
| 3556 | rcu_assign_pointer(mvm->csa_vif, vif); |
Andrei Otcheretianski | 7ef0aab | 2014-11-10 11:10:11 +0200 | [diff] [blame] | 3557 | |
Andrei Otcheretianski | 7ef0aab | 2014-11-10 11:10:11 +0200 | [diff] [blame] | 3558 | if (WARN_ONCE(mvmvif->csa_countdown, |
| 3559 | "Previous CSA countdown didn't complete")) { |
| 3560 | ret = -EBUSY; |
| 3561 | goto out_unlock; |
| 3562 | } |
| 3563 | |
Luciano Coelho | 6b20d77 | 2014-11-10 11:10:07 +0200 | [diff] [blame] | 3564 | break; |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3565 | case NL80211_IFTYPE_STATION: |
Luciano Coelho | 4500e13 | 2014-11-10 11:10:15 +0200 | [diff] [blame] | 3566 | /* Schedule the time event to a bit before beacon 1, |
| 3567 | * to make sure we're in the new channel when the |
| 3568 | * GO/AP arrives. |
| 3569 | */ |
| 3570 | apply_time = chsw->device_timestamp + |
| 3571 | ((vif->bss_conf.beacon_int * (chsw->count - 1) - |
| 3572 | IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3573 | |
| 3574 | if (chsw->block_tx) |
| 3575 | iwl_mvm_csa_client_absent(mvm, vif); |
| 3576 | |
Luciano Coelho | 4500e13 | 2014-11-10 11:10:15 +0200 | [diff] [blame] | 3577 | iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3578 | apply_time); |
Luciano Coelho | c6e0a3e0 | 2014-11-10 11:10:18 +0200 | [diff] [blame] | 3579 | if (mvmvif->bf_data.bf_enabled) { |
| 3580 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
| 3581 | if (ret) |
| 3582 | goto out_unlock; |
| 3583 | } |
| 3584 | |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3585 | break; |
Luciano Coelho | 6b20d77 | 2014-11-10 11:10:07 +0200 | [diff] [blame] | 3586 | default: |
| 3587 | break; |
| 3588 | } |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3589 | |
Luciano Coelho | f6c3482 | 2014-11-10 11:10:12 +0200 | [diff] [blame] | 3590 | mvmvif->ps_disabled = true; |
| 3591 | |
| 3592 | ret = iwl_mvm_power_update_ps(mvm); |
| 3593 | if (ret) |
| 3594 | goto out_unlock; |
Luciano Coelho | f028905 | 2014-11-10 11:10:06 +0200 | [diff] [blame] | 3595 | |
Arik Nemtsov | e198f5e | 2014-09-14 19:13:54 +0300 | [diff] [blame] | 3596 | /* we won't be on this channel any longer */ |
| 3597 | iwl_mvm_teardown_tdls_peers(mvm); |
| 3598 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3599 | out_unlock: |
| 3600 | mutex_unlock(&mvm->mutex); |
Luciano Coelho | f028905 | 2014-11-10 11:10:06 +0200 | [diff] [blame] | 3601 | |
| 3602 | return ret; |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3603 | } |
| 3604 | |
Luciano Coelho | f6c3482 | 2014-11-10 11:10:12 +0200 | [diff] [blame] | 3605 | static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, |
| 3606 | struct ieee80211_vif *vif) |
| 3607 | { |
| 3608 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3609 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3610 | int ret; |
| 3611 | |
| 3612 | mutex_lock(&mvm->mutex); |
| 3613 | |
Luciano Coelho | a57c688 | 2014-11-10 11:10:16 +0200 | [diff] [blame] | 3614 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 3615 | struct iwl_mvm_sta *mvmsta; |
| 3616 | |
| 3617 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, |
| 3618 | mvmvif->ap_sta_id); |
| 3619 | |
| 3620 | if (WARN_ON(!mvmsta)) { |
| 3621 | ret = -EIO; |
| 3622 | goto out_unlock; |
| 3623 | } |
| 3624 | |
| 3625 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); |
| 3626 | |
| 3627 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
Luciano Coelho | c6e0a3e0 | 2014-11-10 11:10:18 +0200 | [diff] [blame] | 3628 | |
| 3629 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); |
| 3630 | if (ret) |
| 3631 | goto out_unlock; |
Luciano Coelho | 686e7fe | 2014-11-10 11:10:21 +0200 | [diff] [blame] | 3632 | |
| 3633 | iwl_mvm_stop_session_protection(mvm, vif); |
Luciano Coelho | a57c688 | 2014-11-10 11:10:16 +0200 | [diff] [blame] | 3634 | } |
| 3635 | |
Luciano Coelho | f6c3482 | 2014-11-10 11:10:12 +0200 | [diff] [blame] | 3636 | mvmvif->ps_disabled = false; |
| 3637 | |
| 3638 | ret = iwl_mvm_power_update_ps(mvm); |
| 3639 | |
Luciano Coelho | a57c688 | 2014-11-10 11:10:16 +0200 | [diff] [blame] | 3640 | out_unlock: |
Luciano Coelho | f6c3482 | 2014-11-10 11:10:12 +0200 | [diff] [blame] | 3641 | mutex_unlock(&mvm->mutex); |
| 3642 | |
| 3643 | return ret; |
| 3644 | } |
| 3645 | |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 3646 | static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, |
| 3647 | struct ieee80211_vif *vif, u32 queues, bool drop) |
| 3648 | { |
| 3649 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3650 | struct iwl_mvm_vif *mvmvif; |
| 3651 | struct iwl_mvm_sta *mvmsta; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 3652 | struct ieee80211_sta *sta; |
| 3653 | int i; |
| 3654 | u32 msk = 0; |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 3655 | |
| 3656 | if (!vif || vif->type != NL80211_IFTYPE_STATION) |
| 3657 | return; |
| 3658 | |
| 3659 | mutex_lock(&mvm->mutex); |
| 3660 | mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 3661 | |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 3662 | /* flush the AP-station and all TDLS peers */ |
| 3663 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 3664 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 3665 | lockdep_is_held(&mvm->mutex)); |
| 3666 | if (IS_ERR_OR_NULL(sta)) |
| 3667 | continue; |
| 3668 | |
| 3669 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 3670 | if (mvmsta->vif != vif) |
| 3671 | continue; |
| 3672 | |
| 3673 | /* make sure only TDLS peers or the AP are flushed */ |
| 3674 | WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls); |
| 3675 | |
| 3676 | msk |= mvmsta->tfd_queue_msk; |
Johannes Berg | 480acbc | 2014-10-10 08:59:27 +0200 | [diff] [blame] | 3677 | } |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 3678 | |
Emmanuel Grumbach | 6d440b2 | 2015-01-20 09:25:19 +0200 | [diff] [blame] | 3679 | if (drop) { |
| 3680 | if (iwl_mvm_flush_tx_path(mvm, msk, true)) |
| 3681 | IWL_ERR(mvm, "flush request fail\n"); |
| 3682 | mutex_unlock(&mvm->mutex); |
| 3683 | } else { |
| 3684 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 480acbc | 2014-10-10 08:59:27 +0200 | [diff] [blame] | 3685 | |
Emmanuel Grumbach | 6d440b2 | 2015-01-20 09:25:19 +0200 | [diff] [blame] | 3686 | /* this can take a while, and we may need/want other operations |
| 3687 | * to succeed while doing this, so do it without the mutex held |
| 3688 | */ |
| 3689 | iwl_trans_wait_tx_queue_empty(mvm->trans, msk); |
| 3690 | } |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 3691 | } |
| 3692 | |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 3693 | static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, |
| 3694 | struct survey_info *survey) |
| 3695 | { |
| 3696 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3697 | int ret; |
| 3698 | |
| 3699 | memset(survey, 0, sizeof(*survey)); |
| 3700 | |
| 3701 | /* only support global statistics right now */ |
| 3702 | if (idx != 0) |
| 3703 | return -ENOENT; |
| 3704 | |
| 3705 | if (!(mvm->fw->ucode_capa.capa[0] & |
| 3706 | IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) |
| 3707 | return -ENOENT; |
| 3708 | |
| 3709 | mutex_lock(&mvm->mutex); |
| 3710 | |
| 3711 | if (mvm->ucode_loaded) { |
Johannes Berg | 33cef92 | 2015-01-21 21:41:29 +0100 | [diff] [blame] | 3712 | ret = iwl_mvm_request_statistics(mvm, false); |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 3713 | if (ret) |
| 3714 | goto out; |
| 3715 | } |
| 3716 | |
| 3717 | survey->filled = SURVEY_INFO_TIME | |
| 3718 | SURVEY_INFO_TIME_RX | |
| 3719 | SURVEY_INFO_TIME_TX | |
| 3720 | SURVEY_INFO_TIME_SCAN; |
| 3721 | survey->time = mvm->accu_radio_stats.on_time_rf + |
| 3722 | mvm->radio_stats.on_time_rf; |
| 3723 | do_div(survey->time, USEC_PER_MSEC); |
| 3724 | |
| 3725 | survey->time_rx = mvm->accu_radio_stats.rx_time + |
| 3726 | mvm->radio_stats.rx_time; |
| 3727 | do_div(survey->time_rx, USEC_PER_MSEC); |
| 3728 | |
| 3729 | survey->time_tx = mvm->accu_radio_stats.tx_time + |
| 3730 | mvm->radio_stats.tx_time; |
| 3731 | do_div(survey->time_tx, USEC_PER_MSEC); |
| 3732 | |
| 3733 | survey->time_scan = mvm->accu_radio_stats.on_time_scan + |
| 3734 | mvm->radio_stats.on_time_scan; |
| 3735 | do_div(survey->time_scan, USEC_PER_MSEC); |
| 3736 | |
| 3737 | out: |
| 3738 | mutex_unlock(&mvm->mutex); |
| 3739 | return ret; |
| 3740 | } |
| 3741 | |
Johannes Berg | 33cef92 | 2015-01-21 21:41:29 +0100 | [diff] [blame] | 3742 | static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, |
| 3743 | struct ieee80211_vif *vif, |
| 3744 | struct ieee80211_sta *sta, |
| 3745 | struct station_info *sinfo) |
| 3746 | { |
| 3747 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3748 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3749 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 3750 | |
| 3751 | if (!(mvm->fw->ucode_capa.capa[0] & |
| 3752 | IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) |
| 3753 | return; |
| 3754 | |
| 3755 | /* if beacon filtering isn't on mac80211 does it anyway */ |
| 3756 | if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) |
| 3757 | return; |
| 3758 | |
| 3759 | if (!vif->bss_conf.assoc) |
| 3760 | return; |
| 3761 | |
| 3762 | mutex_lock(&mvm->mutex); |
| 3763 | |
| 3764 | if (mvmvif->ap_sta_id != mvmsta->sta_id) |
| 3765 | goto unlock; |
| 3766 | |
| 3767 | if (iwl_mvm_request_statistics(mvm, false)) |
| 3768 | goto unlock; |
| 3769 | |
| 3770 | sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons + |
| 3771 | mvmvif->beacon_stats.accu_num_beacons; |
| 3772 | sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX); |
| 3773 | if (mvmvif->beacon_stats.avg_signal) { |
| 3774 | /* firmware only reports a value after RXing a few beacons */ |
| 3775 | sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal; |
| 3776 | sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG); |
| 3777 | } |
| 3778 | unlock: |
| 3779 | mutex_unlock(&mvm->mutex); |
| 3780 | } |
| 3781 | |
Johannes Berg | e520926 | 2014-01-20 23:38:59 +0100 | [diff] [blame] | 3782 | const struct ieee80211_ops iwl_mvm_hw_ops = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3783 | .tx = iwl_mvm_mac_tx, |
| 3784 | .ampdu_action = iwl_mvm_mac_ampdu_action, |
| 3785 | .start = iwl_mvm_mac_start, |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 3786 | .reconfig_complete = iwl_mvm_mac_reconfig_complete, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3787 | .stop = iwl_mvm_mac_stop, |
| 3788 | .add_interface = iwl_mvm_mac_add_interface, |
| 3789 | .remove_interface = iwl_mvm_mac_remove_interface, |
| 3790 | .config = iwl_mvm_mac_config, |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 3791 | .prepare_multicast = iwl_mvm_prepare_multicast, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3792 | .configure_filter = iwl_mvm_configure_filter, |
| 3793 | .bss_info_changed = iwl_mvm_bss_info_changed, |
| 3794 | .hw_scan = iwl_mvm_mac_hw_scan, |
| 3795 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 3796 | .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3797 | .sta_state = iwl_mvm_mac_sta_state, |
| 3798 | .sta_notify = iwl_mvm_mac_sta_notify, |
| 3799 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3800 | .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3801 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 3802 | .sta_rc_update = iwl_mvm_sta_rc_update, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3803 | .conf_tx = iwl_mvm_mac_conf_tx, |
| 3804 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, |
Arik Nemtsov | 07ecd89 | 2014-05-20 18:16:42 +0300 | [diff] [blame] | 3805 | .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 3806 | .flush = iwl_mvm_mac_flush, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 3807 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
| 3808 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3809 | .set_key = iwl_mvm_mac_set_key, |
| 3810 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, |
| 3811 | .remain_on_channel = iwl_mvm_roc, |
| 3812 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3813 | .add_chanctx = iwl_mvm_add_chanctx, |
| 3814 | .remove_chanctx = iwl_mvm_remove_chanctx, |
| 3815 | .change_chanctx = iwl_mvm_change_chanctx, |
| 3816 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, |
| 3817 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, |
Luciano Coelho | b08c1d9 | 2014-05-20 23:31:05 +0300 | [diff] [blame] | 3818 | .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3819 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 3820 | .start_ap = iwl_mvm_start_ap_ibss, |
| 3821 | .stop_ap = iwl_mvm_stop_ap_ibss, |
| 3822 | .join_ibss = iwl_mvm_start_ap_ibss, |
| 3823 | .leave_ibss = iwl_mvm_stop_ap_ibss, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3824 | |
| 3825 | .set_tim = iwl_mvm_set_tim, |
| 3826 | |
Luciano Coelho | 622e3f9 | 2014-11-10 11:10:17 +0200 | [diff] [blame] | 3827 | .channel_switch = iwl_mvm_channel_switch, |
Luciano Coelho | f028905 | 2014-11-10 11:10:06 +0200 | [diff] [blame] | 3828 | .pre_channel_switch = iwl_mvm_pre_channel_switch, |
Luciano Coelho | f6c3482 | 2014-11-10 11:10:12 +0200 | [diff] [blame] | 3829 | .post_channel_switch = iwl_mvm_post_channel_switch, |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 3830 | |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 3831 | .tdls_channel_switch = iwl_mvm_tdls_channel_switch, |
| 3832 | .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, |
| 3833 | .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, |
| 3834 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 3835 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
| 3836 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3837 | #ifdef CONFIG_PM_SLEEP |
| 3838 | /* look at d3.c */ |
| 3839 | .suspend = iwl_mvm_suspend, |
| 3840 | .resume = iwl_mvm_resume, |
| 3841 | .set_wakeup = iwl_mvm_set_wakeup, |
| 3842 | .set_rekey_data = iwl_mvm_set_rekey_data, |
| 3843 | #if IS_ENABLED(CONFIG_IPV6) |
| 3844 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, |
| 3845 | #endif |
| 3846 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, |
| 3847 | #endif |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 3848 | .get_survey = iwl_mvm_mac_get_survey, |
Johannes Berg | 33cef92 | 2015-01-21 21:41:29 +0100 | [diff] [blame] | 3849 | .sta_statistics = iwl_mvm_mac_sta_statistics, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3850 | }; |