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