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 | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * |
| 27 | * Contact Information: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | * |
| 62 | *****************************************************************************/ |
| 63 | #include <linux/kernel.h> |
| 64 | #include <linux/slab.h> |
| 65 | #include <linux/skbuff.h> |
| 66 | #include <linux/netdevice.h> |
| 67 | #include <linux/etherdevice.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 68 | #include <linux/ip.h> |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 69 | #include <linux/if_arp.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 70 | #include <net/mac80211.h> |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 71 | #include <net/ieee80211_radiotap.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 72 | #include <net/tcp.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 73 | |
| 74 | #include "iwl-op-mode.h" |
| 75 | #include "iwl-io.h" |
| 76 | #include "mvm.h" |
| 77 | #include "sta.h" |
| 78 | #include "time-event.h" |
| 79 | #include "iwl-eeprom-parse.h" |
| 80 | #include "fw-api-scan.h" |
| 81 | #include "iwl-phy-db.h" |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 82 | #include "testmode.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 83 | |
| 84 | static const struct ieee80211_iface_limit iwl_mvm_limits[] = { |
| 85 | { |
| 86 | .max = 1, |
Ilan Peer | 8eb3871 | 2013-06-01 20:17:18 +0300 | [diff] [blame] | 87 | .types = BIT(NL80211_IFTYPE_STATION), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 88 | }, |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 89 | { |
| 90 | .max = 1, |
Ilan Peer | 8eb3871 | 2013-06-01 20:17:18 +0300 | [diff] [blame] | 91 | .types = BIT(NL80211_IFTYPE_AP) | |
| 92 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 93 | BIT(NL80211_IFTYPE_P2P_GO), |
| 94 | }, |
| 95 | { |
| 96 | .max = 1, |
| 97 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 98 | }, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { |
| 102 | { |
| 103 | .num_different_channels = 1, |
| 104 | .max_interfaces = 3, |
| 105 | .limits = iwl_mvm_limits, |
| 106 | .n_limits = ARRAY_SIZE(iwl_mvm_limits), |
| 107 | }, |
| 108 | }; |
| 109 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 110 | #ifdef CONFIG_PM_SLEEP |
| 111 | static const struct nl80211_wowlan_tcp_data_token_feature |
| 112 | iwl_mvm_wowlan_tcp_token_feature = { |
| 113 | .min_len = 0, |
| 114 | .max_len = 255, |
| 115 | .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS, |
| 116 | }; |
| 117 | |
| 118 | static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = { |
| 119 | .tok = &iwl_mvm_wowlan_tcp_token_feature, |
| 120 | .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN - |
| 121 | sizeof(struct ethhdr) - |
| 122 | sizeof(struct iphdr) - |
| 123 | sizeof(struct tcphdr), |
| 124 | .data_interval_max = 65535, /* __le16 in API */ |
| 125 | .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN - |
| 126 | sizeof(struct ethhdr) - |
| 127 | sizeof(struct iphdr) - |
| 128 | sizeof(struct tcphdr), |
| 129 | .seq = true, |
| 130 | }; |
| 131 | #endif |
| 132 | |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 133 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 134 | /* |
| 135 | * Use the reserved field to indicate magic values. |
| 136 | * these values will only be used internally by the driver, |
| 137 | * and won't make it to the fw (reserved will be 0). |
| 138 | * BC_FILTER_MAGIC_IP - configure the val of this attribute to |
| 139 | * be the vif's ip address. in case there is not a single |
| 140 | * ip address (0, or more than 1), this attribute will |
| 141 | * be skipped. |
| 142 | * BC_FILTER_MAGIC_MAC - set the val of this attribute to |
| 143 | * the LSB bytes of the vif's mac address |
| 144 | */ |
| 145 | enum { |
| 146 | BC_FILTER_MAGIC_NONE = 0, |
| 147 | BC_FILTER_MAGIC_IP, |
| 148 | BC_FILTER_MAGIC_MAC, |
| 149 | }; |
| 150 | |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 151 | static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = { |
| 152 | { |
| 153 | /* arp */ |
| 154 | .discard = 0, |
| 155 | .frame_type = BCAST_FILTER_FRAME_TYPE_ALL, |
| 156 | .attrs = { |
| 157 | { |
| 158 | /* frame type - arp, hw type - ethernet */ |
| 159 | .offset_type = |
| 160 | BCAST_FILTER_OFFSET_PAYLOAD_START, |
| 161 | .offset = sizeof(rfc1042_header), |
| 162 | .val = cpu_to_be32(0x08060001), |
| 163 | .mask = cpu_to_be32(0xffffffff), |
| 164 | }, |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 165 | { |
| 166 | /* arp dest ip */ |
| 167 | .offset_type = |
| 168 | BCAST_FILTER_OFFSET_PAYLOAD_START, |
| 169 | .offset = sizeof(rfc1042_header) + 2 + |
| 170 | sizeof(struct arphdr) + |
| 171 | ETH_ALEN + sizeof(__be32) + |
| 172 | ETH_ALEN, |
| 173 | .mask = cpu_to_be32(0xffffffff), |
| 174 | /* mark it as special field */ |
| 175 | .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP), |
| 176 | }, |
| 177 | }, |
| 178 | }, |
| 179 | { |
| 180 | /* dhcp offer bcast */ |
| 181 | .discard = 0, |
| 182 | .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4, |
| 183 | .attrs = { |
| 184 | { |
| 185 | /* udp dest port - 68 (bootp client)*/ |
| 186 | .offset_type = BCAST_FILTER_OFFSET_IP_END, |
| 187 | .offset = offsetof(struct udphdr, dest), |
| 188 | .val = cpu_to_be32(0x00440000), |
| 189 | .mask = cpu_to_be32(0xffff0000), |
| 190 | }, |
| 191 | { |
| 192 | /* dhcp - lsb bytes of client hw address */ |
| 193 | .offset_type = BCAST_FILTER_OFFSET_IP_END, |
| 194 | .offset = 38, |
| 195 | .mask = cpu_to_be32(0xffffffff), |
| 196 | /* mark it as special field */ |
| 197 | .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC), |
| 198 | }, |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 199 | }, |
| 200 | }, |
| 201 | /* last filter must be empty */ |
| 202 | {}, |
| 203 | }; |
| 204 | #endif |
| 205 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 206 | void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) |
| 207 | { |
Eliad Peller | 7bb426e | 2014-02-24 12:54:37 +0200 | [diff] [blame] | 208 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 209 | return; |
| 210 | |
| 211 | IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type); |
| 212 | WARN_ON(test_and_set_bit(ref_type, mvm->ref_bitmap)); |
| 213 | iwl_trans_ref(mvm->trans); |
| 214 | } |
| 215 | |
| 216 | void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) |
| 217 | { |
Eliad Peller | 7bb426e | 2014-02-24 12:54:37 +0200 | [diff] [blame] | 218 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 219 | return; |
| 220 | |
| 221 | IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type); |
| 222 | WARN_ON(!test_and_clear_bit(ref_type, mvm->ref_bitmap)); |
| 223 | iwl_trans_unref(mvm->trans); |
| 224 | } |
| 225 | |
| 226 | static void |
| 227 | iwl_mvm_unref_all_except(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref) |
| 228 | { |
| 229 | int i; |
| 230 | |
Eliad Peller | 7bb426e | 2014-02-24 12:54:37 +0200 | [diff] [blame] | 231 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 232 | return; |
| 233 | |
| 234 | for_each_set_bit(i, mvm->ref_bitmap, IWL_MVM_REF_COUNT) { |
| 235 | if (ref == i) |
| 236 | continue; |
| 237 | |
| 238 | IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d\n", i); |
| 239 | clear_bit(i, mvm->ref_bitmap); |
| 240 | iwl_trans_unref(mvm->trans); |
| 241 | } |
| 242 | } |
| 243 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 244 | static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) |
| 245 | { |
| 246 | int i; |
| 247 | |
| 248 | memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); |
| 249 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 250 | mvm->phy_ctxts[i].id = i; |
| 251 | mvm->phy_ctxts[i].ref = 0; |
| 252 | } |
| 253 | } |
| 254 | |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 255 | static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm) |
| 256 | { |
| 257 | /* we create the 802.11 header and SSID element */ |
| 258 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID) |
| 259 | return mvm->fw->ucode_capa.max_probe_length - 24 - 2; |
| 260 | return mvm->fw->ucode_capa.max_probe_length - 24 - 34; |
| 261 | } |
| 262 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 263 | int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) |
| 264 | { |
| 265 | struct ieee80211_hw *hw = mvm->hw; |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 266 | int num_mac, ret, i; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 267 | |
| 268 | /* Tell mac80211 our characteristics */ |
| 269 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 270 | IEEE80211_HW_SPECTRUM_MGMT | |
| 271 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 272 | IEEE80211_HW_QUEUE_CONTROL | |
| 273 | IEEE80211_HW_WANT_MONITOR_VIF | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 274 | IEEE80211_HW_SUPPORTS_PS | |
| 275 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Johannes Berg | d2931bb | 2013-02-05 18:10:04 +0100 | [diff] [blame] | 276 | IEEE80211_HW_AMPDU_AGGREGATION | |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 277 | IEEE80211_HW_TIMING_BEACON_ONLY | |
Emmanuel Grumbach | 147fc9b | 2013-07-28 11:00:52 +0300 | [diff] [blame] | 278 | IEEE80211_HW_CONNECTION_MONITOR | |
| 279 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | |
Alexander Bondar | e8e626a | 2013-10-16 00:21:34 +0200 | [diff] [blame] | 280 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 281 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 282 | hw->queues = mvm->first_agg_queue; |
Ilan Peer | 398e8c6 | 2013-03-13 15:20:35 +0200 | [diff] [blame] | 283 | hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 284 | hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | |
| 285 | IEEE80211_RADIOTAP_MCS_HAVE_STBC; |
| 286 | hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 287 | hw->rate_control_algorithm = "iwl-mvm-rs"; |
| 288 | |
| 289 | /* |
| 290 | * Enable 11w if advertised by firmware and software crypto |
| 291 | * is not enabled (as the firmware will interpret some mgmt |
| 292 | * packets, so enabling it with software crypto isn't safe) |
| 293 | */ |
| 294 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP && |
| 295 | !iwlwifi_mod_params.sw_crypto) |
| 296 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; |
| 297 | |
Matt Chen | 1504f48 | 2014-04-24 18:43:18 +0800 | [diff] [blame] | 298 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT && |
| 299 | IWL_UCODE_API(mvm->fw->ucode_ver) >= 9 && |
| 300 | !iwlwifi_mod_params.uapsd_disable) { |
| 301 | hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD; |
| 302 | hw->uapsd_queues = IWL_UAPSD_AC_INFO; |
| 303 | hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; |
| 304 | } |
Alexander Bondar | e8e626a | 2013-10-16 00:21:34 +0200 | [diff] [blame] | 305 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 306 | hw->sta_data_size = sizeof(struct iwl_mvm_sta); |
| 307 | hw->vif_data_size = sizeof(struct iwl_mvm_vif); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 308 | hw->chanctx_data_size = sizeof(u16); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 309 | |
| 310 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 311 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 312 | BIT(NL80211_IFTYPE_AP) | |
| 313 | BIT(NL80211_IFTYPE_P2P_GO) | |
Emmanuel Grumbach | c13b172 | 2014-03-27 19:12:12 +0200 | [diff] [blame] | 314 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
| 315 | BIT(NL80211_IFTYPE_ADHOC); |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 316 | |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 317 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
| 318 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | |
| 319 | REGULATORY_DISABLE_BEACON_HINTS; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 320 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 321 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD) |
| 322 | hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
| 323 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 324 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_CSA_FLOW) |
| 325 | hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
| 326 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 327 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; |
| 328 | hw->wiphy->n_iface_combinations = |
| 329 | ARRAY_SIZE(iwl_mvm_iface_combinations); |
| 330 | |
Ilan Peer | c451e6d | 2013-02-20 08:41:54 +0200 | [diff] [blame] | 331 | hw->wiphy->max_remain_on_channel_duration = 10000; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 332 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
| 333 | |
| 334 | /* Extract MAC address */ |
| 335 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); |
| 336 | hw->wiphy->addresses = mvm->addresses; |
| 337 | hw->wiphy->n_addresses = 1; |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 338 | |
| 339 | /* Extract additional MAC addresses if available */ |
| 340 | num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? |
| 341 | min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; |
| 342 | |
| 343 | for (i = 1; i < num_mac; i++) { |
| 344 | memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 345 | ETH_ALEN); |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 346 | mvm->addresses[i].addr[5]++; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 347 | hw->wiphy->n_addresses++; |
| 348 | } |
| 349 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 350 | iwl_mvm_reset_phy_ctxts(mvm); |
| 351 | |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 352 | hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); |
| 353 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 354 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
| 355 | |
| 356 | if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 357 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 358 | &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; |
| 359 | if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 360 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 361 | &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; |
| 362 | |
| 363 | hw->wiphy->hw_version = mvm->trans->hw_id; |
| 364 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 365 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 366 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 367 | else |
| 368 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 369 | |
Emmanuel Grumbach | 536a3ee | 2014-03-30 09:11:44 +0300 | [diff] [blame] | 370 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 371 | hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; |
| 372 | hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; |
| 373 | /* we create the 802.11 header and zero length SSID IE. */ |
| 374 | hw->wiphy->max_sched_scan_ie_len = SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 375 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 376 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 377 | NL80211_FEATURE_P2P_GO_OPPPS; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 378 | |
| 379 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 380 | |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 381 | /* currently FW API supports only one optional cipher scheme */ |
Johannes Berg | 9ddca86 | 2014-01-06 09:29:40 +0100 | [diff] [blame] | 382 | if (mvm->fw->cs[0].cipher) { |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 383 | mvm->hw->n_cipher_schemes = 1; |
Johannes Berg | 9ddca86 | 2014-01-06 09:29:40 +0100 | [diff] [blame] | 384 | mvm->hw->cipher_schemes = &mvm->fw->cs[0]; |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 385 | } |
| 386 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 387 | #ifdef CONFIG_PM_SLEEP |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 388 | if (iwl_mvm_is_d0i3_supported(mvm) && |
| 389 | device_can_wakeup(mvm->trans->dev)) { |
| 390 | mvm->wowlan.flags = WIPHY_WOWLAN_ANY; |
| 391 | hw->wiphy->wowlan = &mvm->wowlan; |
| 392 | } else if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len && |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 393 | mvm->trans->ops->d3_suspend && |
| 394 | mvm->trans->ops->d3_resume && |
| 395 | device_can_wakeup(mvm->trans->dev)) { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 396 | mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | |
| 397 | WIPHY_WOWLAN_DISCONNECT | |
| 398 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | |
| 399 | WIPHY_WOWLAN_RFKILL_RELEASE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 400 | if (!iwlwifi_mod_params.sw_crypto) |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 401 | mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
| 402 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | |
| 403 | WIPHY_WOWLAN_4WAY_HANDSHAKE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 404 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 405 | mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; |
| 406 | mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; |
| 407 | mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; |
| 408 | mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support; |
| 409 | hw->wiphy->wowlan = &mvm->wowlan; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 410 | } |
| 411 | #endif |
| 412 | |
Eliad Peller | 7773692 | 2014-01-14 12:35:49 +0200 | [diff] [blame] | 413 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 414 | /* assign default bcast filtering configuration */ |
| 415 | mvm->bcast_filters = iwl_mvm_default_bcast_filters; |
| 416 | #endif |
| 417 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 418 | ret = iwl_mvm_leds_init(mvm); |
| 419 | if (ret) |
| 420 | return ret; |
| 421 | |
Emmanuel Grumbach | b7327d8 | 2013-06-24 15:44:03 +0300 | [diff] [blame] | 422 | ret = ieee80211_register_hw(mvm->hw); |
| 423 | if (ret) |
| 424 | iwl_mvm_leds_exit(mvm); |
| 425 | |
| 426 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 427 | } |
| 428 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 429 | static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm, |
| 430 | struct ieee80211_sta *sta, |
| 431 | struct sk_buff *skb) |
| 432 | { |
| 433 | struct iwl_mvm_sta *mvmsta; |
| 434 | bool defer = false; |
| 435 | |
| 436 | /* |
| 437 | * double check the IN_D0I3 flag both before and after |
| 438 | * taking the spinlock, in order to prevent taking |
| 439 | * the spinlock when not needed. |
| 440 | */ |
| 441 | if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))) |
| 442 | return false; |
| 443 | |
| 444 | spin_lock(&mvm->d0i3_tx_lock); |
| 445 | /* |
| 446 | * testing the flag again ensures the skb dequeue |
| 447 | * loop (on d0i3 exit) hasn't run yet. |
| 448 | */ |
| 449 | if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) |
| 450 | goto out; |
| 451 | |
| 452 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 453 | if (mvmsta->sta_id == IWL_MVM_STATION_COUNT || |
| 454 | mvmsta->sta_id != mvm->d0i3_ap_sta_id) |
| 455 | goto out; |
| 456 | |
| 457 | __skb_queue_tail(&mvm->d0i3_tx, skb); |
| 458 | ieee80211_stop_queues(mvm->hw); |
| 459 | |
| 460 | /* trigger wakeup */ |
| 461 | iwl_mvm_ref(mvm, IWL_MVM_REF_TX); |
| 462 | iwl_mvm_unref(mvm, IWL_MVM_REF_TX); |
| 463 | |
| 464 | defer = true; |
| 465 | out: |
| 466 | spin_unlock(&mvm->d0i3_tx_lock); |
| 467 | return defer; |
| 468 | } |
| 469 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 470 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, |
| 471 | struct ieee80211_tx_control *control, |
| 472 | struct sk_buff *skb) |
| 473 | { |
| 474 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 475 | struct ieee80211_sta *sta = control->sta; |
| 476 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 477 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 478 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 479 | if (iwl_mvm_is_radio_killed(mvm)) { |
| 480 | IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 481 | goto drop; |
| 482 | } |
| 483 | |
Ilan Peer | 398e8c6 | 2013-03-13 15:20:35 +0200 | [diff] [blame] | 484 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 485 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status)) |
| 486 | goto drop; |
| 487 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 488 | /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */ |
| 489 | if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER && |
| 490 | ieee80211_is_mgmt(hdr->frame_control) && |
| 491 | !ieee80211_is_deauth(hdr->frame_control) && |
| 492 | !ieee80211_is_disassoc(hdr->frame_control) && |
| 493 | !ieee80211_is_action(hdr->frame_control))) |
| 494 | sta = NULL; |
| 495 | |
| 496 | if (sta) { |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 497 | if (iwl_mvm_defer_tx(mvm, sta, skb)) |
| 498 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 499 | if (iwl_mvm_tx_skb(mvm, skb, sta)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 500 | goto drop; |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | if (iwl_mvm_tx_skb_non_sta(mvm, skb)) |
| 505 | goto drop; |
| 506 | return; |
| 507 | drop: |
| 508 | ieee80211_free_txskb(hw, skb); |
| 509 | } |
| 510 | |
Emmanuel Grumbach | 205e221 | 2014-02-12 15:15:05 +0200 | [diff] [blame] | 511 | static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg) |
| 512 | { |
| 513 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) |
| 514 | return false; |
| 515 | return true; |
| 516 | } |
| 517 | |
| 518 | static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg) |
| 519 | { |
| 520 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) |
| 521 | return false; |
| 522 | if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG) |
| 523 | return true; |
| 524 | |
| 525 | /* enabled by default */ |
| 526 | return true; |
| 527 | } |
| 528 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 529 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, |
| 530 | struct ieee80211_vif *vif, |
| 531 | enum ieee80211_ampdu_mlme_action action, |
| 532 | struct ieee80211_sta *sta, u16 tid, |
| 533 | u16 *ssn, u8 buf_size) |
| 534 | { |
| 535 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 536 | int ret; |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 537 | bool tx_agg_ref = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 538 | |
| 539 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", |
| 540 | sta->addr, tid, action); |
| 541 | |
| 542 | if (!(mvm->nvm_data->sku_cap_11n_enable)) |
| 543 | return -EACCES; |
| 544 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 545 | /* return from D0i3 before starting a new Tx aggregation */ |
Eliad Peller | 9256c20 | 2014-04-22 13:33:29 +0300 | [diff] [blame] | 546 | switch (action) { |
| 547 | case IEEE80211_AMPDU_TX_START: |
| 548 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 549 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 550 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 551 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 552 | iwl_mvm_ref(mvm, IWL_MVM_REF_TX_AGG); |
| 553 | tx_agg_ref = true; |
| 554 | |
| 555 | /* |
Eliad Peller | 9256c20 | 2014-04-22 13:33:29 +0300 | [diff] [blame] | 556 | * for tx start, wait synchronously until D0i3 exit to |
| 557 | * get the correct sequence number for the tid. |
| 558 | * additionally, some other ampdu actions use direct |
| 559 | * target access, which is not handled automatically |
| 560 | * by the trans layer (unlike commands), so wait for |
| 561 | * d0i3 exit in these cases as well. |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 562 | */ |
| 563 | if (!wait_event_timeout(mvm->d0i3_exit_waitq, |
| 564 | !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), HZ)) { |
| 565 | WARN_ON_ONCE(1); |
| 566 | iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG); |
| 567 | return -EIO; |
| 568 | } |
Eliad Peller | 9256c20 | 2014-04-22 13:33:29 +0300 | [diff] [blame] | 569 | break; |
| 570 | default: |
| 571 | break; |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 572 | } |
| 573 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 574 | mutex_lock(&mvm->mutex); |
| 575 | |
| 576 | switch (action) { |
| 577 | case IEEE80211_AMPDU_RX_START: |
Emmanuel Grumbach | 205e221 | 2014-02-12 15:15:05 +0200 | [diff] [blame] | 578 | if (!iwl_enable_rx_ampdu(mvm->cfg)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 579 | ret = -EINVAL; |
| 580 | break; |
| 581 | } |
| 582 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true); |
| 583 | break; |
| 584 | case IEEE80211_AMPDU_RX_STOP: |
| 585 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false); |
| 586 | break; |
| 587 | case IEEE80211_AMPDU_TX_START: |
Emmanuel Grumbach | 205e221 | 2014-02-12 15:15:05 +0200 | [diff] [blame] | 588 | if (!iwl_enable_tx_ampdu(mvm->cfg)) { |
Emmanuel Grumbach | 5d158ef | 2013-02-19 14:39:58 +0200 | [diff] [blame] | 589 | ret = -EINVAL; |
| 590 | break; |
| 591 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 592 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
| 593 | break; |
| 594 | case IEEE80211_AMPDU_TX_STOP_CONT: |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 595 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
| 596 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 597 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 598 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 599 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 600 | break; |
| 601 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 602 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size); |
| 603 | break; |
| 604 | default: |
| 605 | WARN_ON_ONCE(1); |
| 606 | ret = -EINVAL; |
| 607 | break; |
| 608 | } |
| 609 | mutex_unlock(&mvm->mutex); |
| 610 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 611 | /* |
| 612 | * If the tid is marked as started, we won't use it for offloaded |
| 613 | * traffic on the next D0i3 entry. It's safe to unref. |
| 614 | */ |
| 615 | if (tx_agg_ref) |
| 616 | iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG); |
| 617 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 618 | return ret; |
| 619 | } |
| 620 | |
| 621 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, |
| 622 | struct ieee80211_vif *vif) |
| 623 | { |
| 624 | struct iwl_mvm *mvm = data; |
| 625 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 626 | |
| 627 | mvmvif->uploaded = false; |
| 628 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 629 | |
| 630 | /* does this make sense at all? */ |
| 631 | mvmvif->color++; |
| 632 | |
| 633 | spin_lock_bh(&mvm->time_event_lock); |
| 634 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); |
| 635 | spin_unlock_bh(&mvm->time_event_lock); |
| 636 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 637 | mvmvif->phy_ctxt = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) |
| 641 | { |
Emmanuel Grumbach | 1bd3cbc | 2014-03-18 21:15:06 +0200 | [diff] [blame] | 642 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 643 | static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL }; |
| 644 | |
| 645 | iwl_mvm_fw_error_dump(mvm); |
| 646 | |
| 647 | /* notify the userspace about the error we had */ |
| 648 | kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env); |
| 649 | #endif |
| 650 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 651 | iwl_trans_stop_device(mvm->trans); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 652 | |
| 653 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 654 | |
| 655 | /* just in case one was running */ |
| 656 | ieee80211_remain_on_channel_expired(mvm->hw); |
| 657 | |
| 658 | ieee80211_iterate_active_interfaces_atomic( |
| 659 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 660 | iwl_mvm_cleanup_iterator, mvm); |
| 661 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 662 | mvm->p2p_device_vif = NULL; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 663 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 664 | |
| 665 | iwl_mvm_reset_phy_ctxts(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 666 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 667 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); |
| 668 | |
| 669 | ieee80211_wake_queues(mvm->hw); |
| 670 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 671 | /* cleanup all stale references (scan, roc), but keep the |
| 672 | * ucode_down ref until reconfig is complete */ |
| 673 | iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 674 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 675 | mvm->vif_count = 0; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 676 | mvm->rx_ba_sessions = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) |
| 680 | { |
| 681 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 682 | int ret; |
| 683 | |
| 684 | mutex_lock(&mvm->mutex); |
| 685 | |
| 686 | /* Clean up some internal and mac80211 state on restart */ |
| 687 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 688 | iwl_mvm_restart_cleanup(mvm); |
| 689 | |
| 690 | ret = iwl_mvm_up(mvm); |
| 691 | mutex_unlock(&mvm->mutex); |
| 692 | |
| 693 | return ret; |
| 694 | } |
| 695 | |
| 696 | static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) |
| 697 | { |
| 698 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 699 | int ret; |
| 700 | |
| 701 | mutex_lock(&mvm->mutex); |
| 702 | |
| 703 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 704 | iwl_mvm_d0i3_enable_tx(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 705 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 706 | if (ret) |
| 707 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", |
| 708 | ret); |
| 709 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 710 | /* allow transport/FW low power modes */ |
| 711 | iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 712 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 713 | mutex_unlock(&mvm->mutex); |
| 714 | } |
| 715 | |
| 716 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) |
| 717 | { |
| 718 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 719 | |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 720 | flush_work(&mvm->d0i3_exit_work); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 721 | flush_work(&mvm->async_handlers_wk); |
| 722 | |
| 723 | mutex_lock(&mvm->mutex); |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 724 | |
| 725 | /* disallow low power states when the FW is down */ |
| 726 | iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 727 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 728 | /* async_handlers_wk is now blocked */ |
| 729 | |
| 730 | /* |
| 731 | * The work item could be running or queued if the |
| 732 | * ROC time event stops just as we get here. |
| 733 | */ |
| 734 | cancel_work_sync(&mvm->roc_done_wk); |
| 735 | |
| 736 | iwl_trans_stop_device(mvm->trans); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 737 | |
| 738 | iwl_mvm_async_handlers_purge(mvm); |
| 739 | /* async_handlers_list is empty and will stay empty: HW is stopped */ |
| 740 | |
| 741 | /* the fw is stopped, the aux sta is dead: clean up driver state */ |
| 742 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 743 | |
| 744 | mutex_unlock(&mvm->mutex); |
| 745 | |
| 746 | /* |
| 747 | * The worker might have been waiting for the mutex, let it run and |
| 748 | * discover that its list is now empty. |
| 749 | */ |
| 750 | cancel_work_sync(&mvm->async_handlers_wk); |
| 751 | } |
| 752 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 753 | static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
| 754 | { |
| 755 | u16 i; |
| 756 | |
| 757 | lockdep_assert_held(&mvm->mutex); |
| 758 | |
| 759 | for (i = 0; i < NUM_PHY_CTX; i++) |
| 760 | if (!mvm->phy_ctxts[i].ref) |
| 761 | return &mvm->phy_ctxts[i]; |
| 762 | |
| 763 | IWL_ERR(mvm, "No available PHY context\n"); |
| 764 | return NULL; |
| 765 | } |
| 766 | |
Emmanuel Grumbach | ee9c6cb | 2013-12-04 13:53:39 +0200 | [diff] [blame] | 767 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 768 | s8 tx_power) |
| 769 | { |
| 770 | /* FW is in charge of regulatory enforcement */ |
| 771 | struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = { |
| 772 | .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id, |
| 773 | .pwr_restriction = cpu_to_le16(tx_power), |
| 774 | }; |
| 775 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 776 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, |
Emmanuel Grumbach | ee9c6cb | 2013-12-04 13:53:39 +0200 | [diff] [blame] | 777 | sizeof(reduce_txpwr_cmd), |
| 778 | &reduce_txpwr_cmd); |
| 779 | } |
| 780 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 781 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
| 782 | struct ieee80211_vif *vif) |
| 783 | { |
| 784 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 785 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 786 | int ret; |
| 787 | |
| 788 | /* |
| 789 | * Not much to do here. The stack will not allow interface |
| 790 | * types or combinations that we didn't advertise, so we |
| 791 | * don't really have to check the types. |
| 792 | */ |
| 793 | |
| 794 | mutex_lock(&mvm->mutex); |
| 795 | |
Eliad Peller | e89044d | 2013-07-16 17:33:26 +0300 | [diff] [blame] | 796 | /* Allocate resources for the MAC context, and add it to the fw */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 797 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
| 798 | if (ret) |
| 799 | goto out_unlock; |
| 800 | |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 801 | /* Counting number of interfaces is needed for legacy PM */ |
Ilan Peer | ea183d0 | 2013-07-23 14:41:53 +0300 | [diff] [blame] | 802 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 803 | mvm->vif_count++; |
Ilan Peer | ea183d0 | 2013-07-23 14:41:53 +0300 | [diff] [blame] | 804 | |
| 805 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 806 | * The AP binding flow can be done only after the beacon |
| 807 | * template is configured (which happens only in the mac80211 |
| 808 | * start_ap() flow), and adding the broadcast station can happen |
| 809 | * only after the binding. |
| 810 | * In addition, since modifying the MAC before adding a bcast |
| 811 | * station is not allowed by the FW, delay the adding of MAC context to |
| 812 | * the point where we can also add the bcast station. |
| 813 | * In short: there's not much we can do at this point, other than |
| 814 | * allocating resources :) |
| 815 | */ |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 816 | if (vif->type == NL80211_IFTYPE_AP || |
| 817 | vif->type == NL80211_IFTYPE_ADHOC) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 818 | u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); |
| 819 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 820 | qmask, |
| 821 | ieee80211_vif_type_p2p(vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 822 | if (ret) { |
| 823 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); |
| 824 | goto out_release; |
| 825 | } |
| 826 | |
Emmanuel Grumbach | 77740cb | 2013-06-26 23:51:41 +0300 | [diff] [blame] | 827 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 828 | goto out_unlock; |
| 829 | } |
| 830 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 831 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 832 | if (ret) |
| 833 | goto out_release; |
| 834 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 835 | ret = iwl_mvm_power_update_mac(mvm); |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 836 | if (ret) |
| 837 | goto out_release; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 838 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 839 | /* beacon filtering */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 840 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 841 | if (ret) |
| 842 | goto out_remove_mac; |
| 843 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 844 | if (!mvm->bf_allowed_vif && |
Emmanuel Grumbach | 73e5f2c | 2014-03-30 08:57:30 +0300 | [diff] [blame] | 845 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 846 | mvm->bf_allowed_vif = mvmvif; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 847 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 848 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 849 | } |
| 850 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 851 | /* |
| 852 | * P2P_DEVICE interface does not have a channel context assigned to it, |
| 853 | * so a dedicated PHY context is allocated to it and the corresponding |
| 854 | * MAC context is bound to it at this stage. |
| 855 | */ |
| 856 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 857 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 858 | mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 859 | if (!mvmvif->phy_ctxt) { |
| 860 | ret = -ENOSPC; |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 861 | goto out_free_bf; |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 862 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 863 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 864 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 865 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 866 | if (ret) |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 867 | goto out_unref_phy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 868 | |
| 869 | ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 870 | if (ret) |
| 871 | goto out_unbind; |
| 872 | |
| 873 | /* Save a pointer to p2p device vif, so it can later be used to |
| 874 | * update the p2p device MAC when a GO is started/stopped */ |
| 875 | mvm->p2p_device_vif = vif; |
| 876 | } |
| 877 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 878 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 879 | goto out_unlock; |
| 880 | |
| 881 | out_unbind: |
| 882 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 883 | out_unref_phy: |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 884 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 885 | out_free_bf: |
| 886 | if (mvm->bf_allowed_vif == mvmvif) { |
| 887 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 888 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 889 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 890 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 891 | out_remove_mac: |
| 892 | mvmvif->phy_ctxt = NULL; |
| 893 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 894 | out_release: |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 895 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 896 | mvm->vif_count--; |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 897 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 898 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 899 | out_unlock: |
| 900 | mutex_unlock(&mvm->mutex); |
| 901 | |
| 902 | return ret; |
| 903 | } |
| 904 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 905 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
| 906 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 907 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 908 | u32 tfd_msk = 0, ac; |
| 909 | |
| 910 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 911 | if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE) |
| 912 | tfd_msk |= BIT(vif->hw_queue[ac]); |
| 913 | |
| 914 | if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE) |
| 915 | tfd_msk |= BIT(vif->cab_queue); |
| 916 | |
| 917 | if (tfd_msk) { |
| 918 | mutex_lock(&mvm->mutex); |
| 919 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); |
| 920 | mutex_unlock(&mvm->mutex); |
| 921 | } |
| 922 | |
| 923 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 924 | /* |
| 925 | * Flush the ROC worker which will flush the OFFCHANNEL queue. |
| 926 | * We assume here that all the packets sent to the OFFCHANNEL |
| 927 | * queue are sent in ROC session. |
| 928 | */ |
| 929 | flush_work(&mvm->roc_done_wk); |
| 930 | } else { |
| 931 | /* |
| 932 | * By now, all the AC queues are empty. The AGG queues are |
| 933 | * empty too. We already got all the Tx responses for all the |
| 934 | * packets in the queues. The drain work can have been |
Emmanuel Grumbach | 0742a75 | 2013-06-10 14:10:33 +0300 | [diff] [blame] | 935 | * triggered. Flush it. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 936 | */ |
| 937 | flush_work(&mvm->sta_drained_wk); |
| 938 | } |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, |
| 942 | struct ieee80211_vif *vif) |
| 943 | { |
| 944 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 945 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 946 | |
| 947 | iwl_mvm_prepare_mac_removal(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 948 | |
| 949 | mutex_lock(&mvm->mutex); |
| 950 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 951 | if (mvm->bf_allowed_vif == mvmvif) { |
| 952 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 953 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 954 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 955 | } |
| 956 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 957 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
| 958 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 959 | /* |
| 960 | * 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] | 961 | * interface is be handled as part of the stop_ap flow. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 962 | */ |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 963 | if (vif->type == NL80211_IFTYPE_AP || |
| 964 | vif->type == NL80211_IFTYPE_ADHOC) { |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 965 | #ifdef CONFIG_NL80211_TESTMODE |
| 966 | if (vif == mvm->noa_vif) { |
| 967 | mvm->noa_vif = NULL; |
| 968 | mvm->noa_duration = 0; |
| 969 | } |
| 970 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 971 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 972 | goto out_release; |
| 973 | } |
| 974 | |
| 975 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 976 | mvm->p2p_device_vif = NULL; |
| 977 | iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 978 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 979 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 980 | mvmvif->phy_ctxt = NULL; |
| 981 | } |
| 982 | |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 983 | if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 984 | mvm->vif_count--; |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 985 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 986 | iwl_mvm_power_update_mac(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 987 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 988 | |
| 989 | out_release: |
| 990 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 991 | mutex_unlock(&mvm->mutex); |
| 992 | } |
| 993 | |
| 994 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 995 | { |
| 996 | return 0; |
| 997 | } |
| 998 | |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 999 | struct iwl_mvm_mc_iter_data { |
| 1000 | struct iwl_mvm *mvm; |
| 1001 | int port_id; |
| 1002 | }; |
| 1003 | |
| 1004 | static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, |
| 1005 | struct ieee80211_vif *vif) |
| 1006 | { |
| 1007 | struct iwl_mvm_mc_iter_data *data = _data; |
| 1008 | struct iwl_mvm *mvm = data->mvm; |
| 1009 | struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; |
| 1010 | int ret, len; |
| 1011 | |
| 1012 | /* if we don't have free ports, mcast frames will be dropped */ |
| 1013 | if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) |
| 1014 | return; |
| 1015 | |
| 1016 | if (vif->type != NL80211_IFTYPE_STATION || |
| 1017 | !vif->bss_conf.assoc) |
| 1018 | return; |
| 1019 | |
| 1020 | cmd->port_id = data->port_id++; |
| 1021 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); |
| 1022 | len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); |
| 1023 | |
Emmanuel Grumbach | 1c4abec | 2014-05-08 09:48:10 +0300 | [diff] [blame] | 1024 | 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] | 1025 | if (ret) |
| 1026 | IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); |
| 1027 | } |
| 1028 | |
| 1029 | static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) |
| 1030 | { |
| 1031 | struct iwl_mvm_mc_iter_data iter_data = { |
| 1032 | .mvm = mvm, |
| 1033 | }; |
| 1034 | |
| 1035 | lockdep_assert_held(&mvm->mutex); |
| 1036 | |
| 1037 | if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) |
| 1038 | return; |
| 1039 | |
Emmanuel Grumbach | 1c4abec | 2014-05-08 09:48:10 +0300 | [diff] [blame] | 1040 | ieee80211_iterate_active_interfaces_atomic( |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1041 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1042 | iwl_mvm_mc_iface_iterator, &iter_data); |
| 1043 | } |
| 1044 | |
| 1045 | static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, |
| 1046 | struct netdev_hw_addr_list *mc_list) |
| 1047 | { |
| 1048 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1049 | struct iwl_mcast_filter_cmd *cmd; |
| 1050 | struct netdev_hw_addr *addr; |
| 1051 | int addr_count = netdev_hw_addr_list_count(mc_list); |
| 1052 | bool pass_all = false; |
| 1053 | int len; |
| 1054 | |
| 1055 | if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) { |
| 1056 | pass_all = true; |
| 1057 | addr_count = 0; |
| 1058 | } |
| 1059 | |
| 1060 | len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); |
| 1061 | cmd = kzalloc(len, GFP_ATOMIC); |
| 1062 | if (!cmd) |
| 1063 | return 0; |
| 1064 | |
| 1065 | if (pass_all) { |
| 1066 | cmd->pass_all = 1; |
| 1067 | return (u64)(unsigned long)cmd; |
| 1068 | } |
| 1069 | |
| 1070 | netdev_hw_addr_list_for_each(addr, mc_list) { |
| 1071 | IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", |
| 1072 | cmd->count, addr->addr); |
| 1073 | memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], |
| 1074 | addr->addr, ETH_ALEN); |
| 1075 | cmd->count++; |
| 1076 | } |
| 1077 | |
| 1078 | return (u64)(unsigned long)cmd; |
| 1079 | } |
| 1080 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1081 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, |
| 1082 | unsigned int changed_flags, |
| 1083 | unsigned int *total_flags, |
| 1084 | u64 multicast) |
| 1085 | { |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1086 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1087 | struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; |
| 1088 | |
| 1089 | mutex_lock(&mvm->mutex); |
| 1090 | |
| 1091 | /* replace previous configuration */ |
| 1092 | kfree(mvm->mcast_filter_cmd); |
| 1093 | mvm->mcast_filter_cmd = cmd; |
| 1094 | |
| 1095 | if (!cmd) |
| 1096 | goto out; |
| 1097 | |
| 1098 | iwl_mvm_recalc_multicast(mvm); |
| 1099 | out: |
| 1100 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1101 | *total_flags = 0; |
| 1102 | } |
| 1103 | |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1104 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1105 | struct iwl_bcast_iter_data { |
| 1106 | struct iwl_mvm *mvm; |
| 1107 | struct iwl_bcast_filter_cmd *cmd; |
| 1108 | u8 current_filter; |
| 1109 | }; |
| 1110 | |
| 1111 | static void |
| 1112 | iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, |
| 1113 | const struct iwl_fw_bcast_filter *in_filter, |
| 1114 | struct iwl_fw_bcast_filter *out_filter) |
| 1115 | { |
| 1116 | struct iwl_fw_bcast_filter_attr *attr; |
| 1117 | int i; |
| 1118 | |
| 1119 | memcpy(out_filter, in_filter, sizeof(*out_filter)); |
| 1120 | |
| 1121 | for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { |
| 1122 | attr = &out_filter->attrs[i]; |
| 1123 | |
| 1124 | if (!attr->mask) |
| 1125 | break; |
| 1126 | |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 1127 | switch (attr->reserved1) { |
| 1128 | case cpu_to_le16(BC_FILTER_MAGIC_IP): |
| 1129 | if (vif->bss_conf.arp_addr_cnt != 1) { |
| 1130 | attr->mask = 0; |
| 1131 | continue; |
| 1132 | } |
| 1133 | |
| 1134 | attr->val = vif->bss_conf.arp_addr_list[0]; |
| 1135 | break; |
| 1136 | case cpu_to_le16(BC_FILTER_MAGIC_MAC): |
| 1137 | attr->val = *(__be32 *)&vif->addr[2]; |
| 1138 | break; |
| 1139 | default: |
| 1140 | break; |
| 1141 | } |
| 1142 | attr->reserved1 = 0; |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1143 | out_filter->num_attrs++; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, |
| 1148 | struct ieee80211_vif *vif) |
| 1149 | { |
| 1150 | struct iwl_bcast_iter_data *data = _data; |
| 1151 | struct iwl_mvm *mvm = data->mvm; |
| 1152 | struct iwl_bcast_filter_cmd *cmd = data->cmd; |
| 1153 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1154 | struct iwl_fw_bcast_mac *bcast_mac; |
| 1155 | int i; |
| 1156 | |
| 1157 | if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) |
| 1158 | return; |
| 1159 | |
| 1160 | bcast_mac = &cmd->macs[mvmvif->id]; |
| 1161 | |
Ilan Peer | e48393e | 2014-05-22 11:19:02 +0300 | [diff] [blame] | 1162 | /* |
| 1163 | * enable filtering only for associated stations, but not for P2P |
| 1164 | * Clients |
| 1165 | */ |
| 1166 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p || |
| 1167 | !vif->bss_conf.assoc) |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1168 | return; |
| 1169 | |
| 1170 | bcast_mac->default_discard = 1; |
| 1171 | |
| 1172 | /* copy all configured filters */ |
| 1173 | for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { |
| 1174 | /* |
| 1175 | * Make sure we don't exceed our filters limit. |
| 1176 | * if there is still a valid filter to be configured, |
| 1177 | * be on the safe side and just allow bcast for this mac. |
| 1178 | */ |
| 1179 | if (WARN_ON_ONCE(data->current_filter >= |
| 1180 | ARRAY_SIZE(cmd->filters))) { |
| 1181 | bcast_mac->default_discard = 0; |
| 1182 | bcast_mac->attached_filters = 0; |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | iwl_mvm_set_bcast_filter(vif, |
| 1187 | &mvm->bcast_filters[i], |
| 1188 | &cmd->filters[data->current_filter]); |
| 1189 | |
| 1190 | /* skip current filter if it contains no attributes */ |
| 1191 | if (!cmd->filters[data->current_filter].num_attrs) |
| 1192 | continue; |
| 1193 | |
| 1194 | /* attach the filter to current mac */ |
| 1195 | bcast_mac->attached_filters |= |
| 1196 | cpu_to_le16(BIT(data->current_filter)); |
| 1197 | |
| 1198 | data->current_filter++; |
| 1199 | } |
| 1200 | } |
| 1201 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1202 | bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm, |
| 1203 | struct iwl_bcast_filter_cmd *cmd) |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1204 | { |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1205 | struct iwl_bcast_iter_data iter_data = { |
| 1206 | .mvm = mvm, |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1207 | .cmd = cmd, |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1208 | }; |
| 1209 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1210 | memset(cmd, 0, sizeof(*cmd)); |
| 1211 | cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); |
| 1212 | cmd->max_macs = ARRAY_SIZE(cmd->macs); |
| 1213 | |
| 1214 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1215 | /* use debugfs filters/macs if override is configured */ |
| 1216 | if (mvm->dbgfs_bcast_filtering.override) { |
| 1217 | memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters, |
| 1218 | sizeof(cmd->filters)); |
| 1219 | memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs, |
| 1220 | sizeof(cmd->macs)); |
| 1221 | return true; |
| 1222 | } |
| 1223 | #endif |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1224 | |
| 1225 | /* if no filters are configured, do nothing */ |
| 1226 | if (!mvm->bcast_filters) |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1227 | return false; |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1228 | |
| 1229 | /* configure and attach these filters for each associated sta vif */ |
| 1230 | ieee80211_iterate_active_interfaces( |
| 1231 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1232 | iwl_mvm_bcast_filter_iterator, &iter_data); |
| 1233 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1234 | return true; |
| 1235 | } |
| 1236 | static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, |
| 1237 | struct ieee80211_vif *vif) |
| 1238 | { |
| 1239 | struct iwl_bcast_filter_cmd cmd; |
| 1240 | |
| 1241 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) |
| 1242 | return 0; |
| 1243 | |
| 1244 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) |
| 1245 | return 0; |
| 1246 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1247 | return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1248 | sizeof(cmd), &cmd); |
| 1249 | } |
| 1250 | #else |
| 1251 | static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, |
| 1252 | struct ieee80211_vif *vif) |
| 1253 | { |
| 1254 | return 0; |
| 1255 | } |
| 1256 | #endif |
| 1257 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1258 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
| 1259 | struct ieee80211_vif *vif, |
| 1260 | struct ieee80211_bss_conf *bss_conf, |
| 1261 | u32 changes) |
| 1262 | { |
| 1263 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1264 | int ret; |
| 1265 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 1266 | /* |
| 1267 | * Re-calculate the tsf id, as the master-slave relations depend on the |
| 1268 | * beacon interval, which was not known when the station interface was |
| 1269 | * added. |
| 1270 | */ |
| 1271 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) |
| 1272 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
| 1273 | |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1274 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1275 | if (ret) |
| 1276 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
| 1277 | |
| 1278 | if (changes & BSS_CHANGED_ASSOC) { |
| 1279 | if (bss_conf->assoc) { |
| 1280 | /* add quota for this interface */ |
| 1281 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 1282 | if (ret) { |
| 1283 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 1284 | return; |
| 1285 | } |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 1286 | |
| 1287 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, |
| 1288 | &mvm->status)) { |
| 1289 | /* |
| 1290 | * If we're restarting then the firmware will |
| 1291 | * obviously have lost synchronisation with |
| 1292 | * the AP. It will attempt to synchronise by |
| 1293 | * itself, but we can make it more reliable by |
| 1294 | * scheduling a session protection time event. |
| 1295 | * |
| 1296 | * The firmware needs to receive a beacon to |
| 1297 | * catch up with synchronisation, use 110% of |
| 1298 | * the beacon interval. |
| 1299 | * |
| 1300 | * Set a large maximum delay to allow for more |
| 1301 | * than a single interface. |
| 1302 | */ |
| 1303 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; |
| 1304 | iwl_mvm_protect_session(mvm, vif, dur, dur, |
| 1305 | 5 * dur); |
| 1306 | } |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1307 | |
| 1308 | iwl_mvm_sf_update(mvm, vif, false); |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 1309 | iwl_mvm_power_vif_assoc(mvm, vif); |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 1310 | if (vif->p2p) |
| 1311 | iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1312 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1313 | /* |
| 1314 | * If update fails - SF might be running in associated |
| 1315 | * mode while disassociated - which is forbidden. |
| 1316 | */ |
| 1317 | WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false), |
| 1318 | "Failed to update SF upon disassociation\n"); |
| 1319 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1320 | /* remove AP station now that the MAC is unassoc */ |
| 1321 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); |
| 1322 | if (ret) |
| 1323 | IWL_ERR(mvm, "failed to remove AP station\n"); |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 1324 | |
| 1325 | if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id) |
| 1326 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1327 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 1328 | /* remove quota for this interface */ |
| 1329 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 1330 | if (ret) |
| 1331 | IWL_ERR(mvm, "failed to update quotas\n"); |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 1332 | |
| 1333 | if (vif->p2p) |
| 1334 | iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1335 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1336 | |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1337 | iwl_mvm_recalc_multicast(mvm); |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1338 | iwl_mvm_configure_bcast_filter(mvm, vif); |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1339 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1340 | /* reset rssi values */ |
| 1341 | mvmvif->bf_data.ave_beacon_signal = 0; |
| 1342 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 1343 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | f94045e | 2014-01-06 13:38:55 +0200 | [diff] [blame] | 1344 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, |
| 1345 | IEEE80211_SMPS_AUTOMATIC); |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 1346 | } else if (changes & BSS_CHANGED_BEACON_INFO) { |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 1347 | /* |
| 1348 | * We received a beacon _after_ association so |
| 1349 | * remove the session protection. |
| 1350 | */ |
| 1351 | iwl_mvm_remove_time_event(mvm, mvmvif, |
| 1352 | &mvmvif->time_event_data); |
Johannes Berg | 0229cda | 2014-03-19 18:36:39 +0100 | [diff] [blame] | 1353 | iwl_mvm_sf_update(mvm, vif, false); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1354 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); |
Alexander Bondar | 51498cf | 2013-09-02 17:10:14 +0300 | [diff] [blame] | 1355 | } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | |
| 1356 | BSS_CHANGED_QOS)) { |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1357 | ret = iwl_mvm_power_update_mac(mvm); |
Alexander Bondar | 4bf881f | 2013-05-29 10:19:50 +0300 | [diff] [blame] | 1358 | if (ret) |
| 1359 | IWL_ERR(mvm, "failed to update power mode\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1360 | } |
Matti Gottlieb | 88f2fd7 | 2013-07-09 15:25:46 +0300 | [diff] [blame] | 1361 | if (changes & BSS_CHANGED_TXPOWER) { |
| 1362 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", |
| 1363 | bss_conf->txpower); |
| 1364 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); |
| 1365 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1366 | |
| 1367 | if (changes & BSS_CHANGED_CQM) { |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 1368 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1369 | /* reset cqm events tracking */ |
| 1370 | mvmvif->bf_data.last_cqm_event = 0; |
Avri Altman | fa7b2e7 | 2014-05-20 08:03:24 +0300 | [diff] [blame] | 1371 | if (mvmvif->bf_data.bf_enabled) { |
| 1372 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); |
| 1373 | if (ret) |
| 1374 | IWL_ERR(mvm, |
| 1375 | "failed to update CQM thresholds\n"); |
| 1376 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1377 | } |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 1378 | |
| 1379 | if (changes & BSS_CHANGED_ARP_FILTER) { |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 1380 | IWL_DEBUG_MAC80211(mvm, "arp filter changed\n"); |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 1381 | iwl_mvm_configure_bcast_filter(mvm, vif); |
| 1382 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1383 | } |
| 1384 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1385 | static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, |
| 1386 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1387 | { |
| 1388 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1389 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1390 | int ret; |
| 1391 | |
| 1392 | mutex_lock(&mvm->mutex); |
| 1393 | |
| 1394 | /* Send the beacon template */ |
| 1395 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); |
| 1396 | if (ret) |
| 1397 | goto out_unlock; |
| 1398 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 1399 | /* |
| 1400 | * Re-calculate the tsf id, as the master-slave relations depend on the |
| 1401 | * beacon interval, which was not known when the AP interface was added. |
| 1402 | */ |
| 1403 | if (vif->type == NL80211_IFTYPE_AP) |
| 1404 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
| 1405 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1406 | /* Add the mac context */ |
| 1407 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 1408 | if (ret) |
| 1409 | goto out_unlock; |
| 1410 | |
| 1411 | /* Perform the binding */ |
| 1412 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1413 | if (ret) |
| 1414 | goto out_remove; |
| 1415 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1416 | /* Send the bcast station. At this stage the TBTT and DTIM time events |
| 1417 | * are added and applied to the scheduler */ |
| 1418 | ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 1419 | if (ret) |
| 1420 | goto out_unbind; |
| 1421 | |
Ilan Peer | 5691e21 | 2013-12-31 21:05:50 +0200 | [diff] [blame] | 1422 | /* must be set before quota calculations */ |
| 1423 | mvmvif->ap_ibss_active = true; |
| 1424 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1425 | /* power updated needs to be done before quotas */ |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1426 | iwl_mvm_power_update_mac(mvm); |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1427 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1428 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 1429 | if (ret) |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1430 | goto out_quota_failed; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1431 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1432 | /* 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] | 1433 | if (vif->p2p && mvm->p2p_device_vif) |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1434 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1435 | |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 1436 | iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS); |
| 1437 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 1438 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 1439 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1440 | mutex_unlock(&mvm->mutex); |
| 1441 | return 0; |
| 1442 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1443 | out_quota_failed: |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1444 | iwl_mvm_power_update_mac(mvm); |
Ilan Peer | 5691e21 | 2013-12-31 21:05:50 +0200 | [diff] [blame] | 1445 | mvmvif->ap_ibss_active = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1446 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 1447 | out_unbind: |
| 1448 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 1449 | out_remove: |
| 1450 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 1451 | out_unlock: |
| 1452 | mutex_unlock(&mvm->mutex); |
| 1453 | return ret; |
| 1454 | } |
| 1455 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1456 | static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, |
| 1457 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1458 | { |
| 1459 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1460 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1461 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 1462 | iwl_mvm_prepare_mac_removal(mvm, vif); |
| 1463 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1464 | mutex_lock(&mvm->mutex); |
| 1465 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1466 | mvmvif->ap_ibss_active = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1467 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 1468 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 1469 | |
Eliad Peller | 29a90a4 | 2013-11-05 14:06:29 +0200 | [diff] [blame] | 1470 | iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS); |
| 1471 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1472 | /* 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] | 1473 | if (vif->p2p && mvm->p2p_device_vif) |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1474 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1475 | |
| 1476 | iwl_mvm_update_quotas(mvm, NULL); |
| 1477 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 1478 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1479 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1480 | iwl_mvm_power_update_mac(mvm); |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1481 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1482 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 1483 | |
| 1484 | mutex_unlock(&mvm->mutex); |
| 1485 | } |
| 1486 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1487 | static void |
| 1488 | iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, |
| 1489 | struct ieee80211_vif *vif, |
| 1490 | struct ieee80211_bss_conf *bss_conf, |
| 1491 | u32 changes) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1492 | { |
Ilan Peer | be2056f | 2013-12-04 16:47:14 +0200 | [diff] [blame] | 1493 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 1494 | |
Ilan Peer | be2056f | 2013-12-04 16:47:14 +0200 | [diff] [blame] | 1495 | /* Changes will be applied when the AP/IBSS is started */ |
| 1496 | if (!mvmvif->ap_ibss_active) |
| 1497 | return; |
| 1498 | |
Johannes Berg | 863230da | 2013-12-04 17:08:40 +0100 | [diff] [blame] | 1499 | if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | |
| 1500 | BSS_CHANGED_BANDWIDTH) && |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1501 | iwl_mvm_mac_ctxt_changed(mvm, vif, false)) |
Johannes Berg | 863230da | 2013-12-04 17:08:40 +0100 | [diff] [blame] | 1502 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 1503 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1504 | /* Need to send a new beacon template to the FW */ |
Johannes Berg | 863230da | 2013-12-04 17:08:40 +0100 | [diff] [blame] | 1505 | if (changes & BSS_CHANGED_BEACON && |
| 1506 | iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) |
| 1507 | IWL_WARN(mvm, "Failed updating beacon data\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, |
| 1511 | struct ieee80211_vif *vif, |
| 1512 | struct ieee80211_bss_conf *bss_conf, |
| 1513 | u32 changes) |
| 1514 | { |
| 1515 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1516 | |
| 1517 | mutex_lock(&mvm->mutex); |
| 1518 | |
David Spinadel | 723f02e | 2014-04-27 09:54:54 +0300 | [diff] [blame] | 1519 | if (changes & BSS_CHANGED_IDLE && !bss_conf->idle) |
| 1520 | iwl_mvm_sched_scan_stop(mvm, true); |
| 1521 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1522 | switch (vif->type) { |
| 1523 | case NL80211_IFTYPE_STATION: |
| 1524 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); |
| 1525 | break; |
| 1526 | case NL80211_IFTYPE_AP: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1527 | case NL80211_IFTYPE_ADHOC: |
| 1528 | iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1529 | break; |
| 1530 | default: |
| 1531 | /* shouldn't happen */ |
| 1532 | WARN_ON_ONCE(1); |
| 1533 | } |
| 1534 | |
| 1535 | mutex_unlock(&mvm->mutex); |
| 1536 | } |
| 1537 | |
| 1538 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, |
| 1539 | struct ieee80211_vif *vif, |
| 1540 | struct cfg80211_scan_request *req) |
| 1541 | { |
| 1542 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1543 | int ret; |
| 1544 | |
| 1545 | if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS) |
| 1546 | return -EINVAL; |
| 1547 | |
| 1548 | mutex_lock(&mvm->mutex); |
| 1549 | |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 1550 | switch (mvm->scan_status) { |
| 1551 | case IWL_MVM_SCAN_SCHED: |
David Spinadel | 636a2cd | 2014-05-01 15:57:22 +0300 | [diff] [blame] | 1552 | ret = iwl_mvm_sched_scan_stop(mvm, true); |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 1553 | if (ret) { |
| 1554 | ret = -EBUSY; |
| 1555 | goto out; |
| 1556 | } |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 1557 | break; |
| 1558 | case IWL_MVM_SCAN_NONE: |
| 1559 | break; |
| 1560 | default: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1561 | ret = -EBUSY; |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 1562 | goto out; |
| 1563 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1564 | |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 1565 | iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN); |
| 1566 | |
| 1567 | ret = iwl_mvm_scan_request(mvm, vif, req); |
| 1568 | if (ret) |
| 1569 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 1570 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1571 | mutex_unlock(&mvm->mutex); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1572 | /* make sure to flush the Rx handler before the next scan arrives */ |
| 1573 | iwl_mvm_wait_for_async_handlers(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1574 | return ret; |
| 1575 | } |
| 1576 | |
| 1577 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, |
| 1578 | struct ieee80211_vif *vif) |
| 1579 | { |
| 1580 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1581 | |
| 1582 | mutex_lock(&mvm->mutex); |
| 1583 | |
| 1584 | iwl_mvm_cancel_scan(mvm); |
| 1585 | |
| 1586 | mutex_unlock(&mvm->mutex); |
| 1587 | } |
| 1588 | |
| 1589 | static void |
| 1590 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1591 | struct ieee80211_sta *sta, u16 tids, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1592 | int num_frames, |
| 1593 | enum ieee80211_frame_release_type reason, |
| 1594 | bool more_data) |
| 1595 | { |
| 1596 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1597 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1598 | /* Called when we need to transmit (a) frame(s) from mac80211 */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1599 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1600 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
| 1601 | tids, more_data, false); |
| 1602 | } |
| 1603 | |
| 1604 | static void |
| 1605 | iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, |
| 1606 | struct ieee80211_sta *sta, u16 tids, |
| 1607 | int num_frames, |
| 1608 | enum ieee80211_frame_release_type reason, |
| 1609 | bool more_data) |
| 1610 | { |
| 1611 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1612 | |
| 1613 | /* Called when we need to transmit (a) frame(s) from agg queue */ |
| 1614 | |
| 1615 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
| 1616 | tids, more_data, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
| 1620 | struct ieee80211_vif *vif, |
| 1621 | enum sta_notify_cmd cmd, |
| 1622 | struct ieee80211_sta *sta) |
| 1623 | { |
| 1624 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1625 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1626 | int tid; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1627 | |
| 1628 | switch (cmd) { |
| 1629 | case STA_NOTIFY_SLEEP: |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1630 | if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1631 | ieee80211_sta_block_awake(hw, sta, true); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1632 | spin_lock_bh(&mvmsta->lock); |
| 1633 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { |
| 1634 | struct iwl_mvm_tid_data *tid_data; |
| 1635 | |
| 1636 | tid_data = &mvmsta->tid_data[tid]; |
| 1637 | if (tid_data->state != IWL_AGG_ON && |
| 1638 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 1639 | continue; |
| 1640 | if (iwl_mvm_tid_queued(tid_data) == 0) |
| 1641 | continue; |
| 1642 | ieee80211_sta_set_buffered(sta, tid, true); |
| 1643 | } |
| 1644 | spin_unlock_bh(&mvmsta->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1645 | /* |
| 1646 | * The fw updates the STA to be asleep. Tx packets on the Tx |
| 1647 | * queues to this station will not be transmitted. The fw will |
| 1648 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. |
| 1649 | */ |
| 1650 | break; |
| 1651 | case STA_NOTIFY_AWAKE: |
Emmanuel Grumbach | 881acd8 | 2013-03-19 16:16:00 +0200 | [diff] [blame] | 1652 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1653 | break; |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1654 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1655 | break; |
| 1656 | default: |
| 1657 | break; |
| 1658 | } |
| 1659 | } |
| 1660 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 1661 | static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
| 1662 | struct ieee80211_vif *vif, |
| 1663 | struct ieee80211_sta *sta) |
| 1664 | { |
| 1665 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1666 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; |
| 1667 | |
| 1668 | /* |
| 1669 | * This is called before mac80211 does RCU synchronisation, |
| 1670 | * so here we already invalidate our internal RCU-protected |
| 1671 | * station pointer. The rest of the code will thus no longer |
| 1672 | * be able to find the station this way, and we don't rely |
| 1673 | * on further RCU synchronisation after the sta_state() |
| 1674 | * callback deleted the station. |
| 1675 | */ |
| 1676 | mutex_lock(&mvm->mutex); |
| 1677 | if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) |
| 1678 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 1679 | ERR_PTR(-ENOENT)); |
| 1680 | mutex_unlock(&mvm->mutex); |
| 1681 | } |
| 1682 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1683 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
| 1684 | struct ieee80211_vif *vif, |
| 1685 | struct ieee80211_sta *sta, |
| 1686 | enum ieee80211_sta_state old_state, |
| 1687 | enum ieee80211_sta_state new_state) |
| 1688 | { |
| 1689 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1690 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1691 | int ret; |
| 1692 | |
| 1693 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", |
| 1694 | sta->addr, old_state, new_state); |
| 1695 | |
| 1696 | /* this would be a mac80211 bug ... but don't crash */ |
| 1697 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) |
| 1698 | return -EINVAL; |
| 1699 | |
| 1700 | /* if a STA is being removed, reuse its ID */ |
| 1701 | flush_work(&mvm->sta_drained_wk); |
| 1702 | |
| 1703 | mutex_lock(&mvm->mutex); |
| 1704 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 1705 | new_state == IEEE80211_STA_NONE) { |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 1706 | /* |
| 1707 | * Firmware bug - it'll crash if the beacon interval is less |
| 1708 | * than 16. We can't avoid connecting at all, so refuse the |
| 1709 | * station state change, this will cause mac80211 to abandon |
| 1710 | * attempts to connect to this AP, and eventually wpa_s will |
| 1711 | * blacklist the AP... |
| 1712 | */ |
| 1713 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1714 | vif->bss_conf.beacon_int < 16) { |
| 1715 | IWL_ERR(mvm, |
| 1716 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", |
| 1717 | sta->addr, vif->bss_conf.beacon_int); |
| 1718 | ret = -EINVAL; |
| 1719 | goto out_unlock; |
| 1720 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1721 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
| 1722 | } else if (old_state == IEEE80211_STA_NONE && |
| 1723 | new_state == IEEE80211_STA_AUTH) { |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 1724 | /* |
| 1725 | * EBS may be disabled due to previous failures reported by FW. |
| 1726 | * Reset EBS status here assuming environment has been changed. |
| 1727 | */ |
| 1728 | mvm->last_ebs_successful = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1729 | ret = 0; |
| 1730 | } else if (old_state == IEEE80211_STA_AUTH && |
| 1731 | new_state == IEEE80211_STA_ASSOC) { |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 1732 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
| 1733 | if (ret == 0) |
| 1734 | iwl_mvm_rs_rate_init(mvm, sta, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 1735 | mvmvif->phy_ctxt->channel->band, |
| 1736 | true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1737 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 1738 | new_state == IEEE80211_STA_AUTHORIZED) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1739 | /* enable beacon filtering */ |
Avri Altman | fa7b2e7 | 2014-05-20 08:03:24 +0300 | [diff] [blame] | 1740 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1741 | ret = 0; |
| 1742 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
| 1743 | new_state == IEEE80211_STA_ASSOC) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1744 | /* disable beacon filtering */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1745 | WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1746 | ret = 0; |
| 1747 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 1748 | new_state == IEEE80211_STA_AUTH) { |
| 1749 | ret = 0; |
| 1750 | } else if (old_state == IEEE80211_STA_AUTH && |
| 1751 | new_state == IEEE80211_STA_NONE) { |
| 1752 | ret = 0; |
| 1753 | } else if (old_state == IEEE80211_STA_NONE && |
| 1754 | new_state == IEEE80211_STA_NOTEXIST) { |
| 1755 | ret = iwl_mvm_rm_sta(mvm, vif, sta); |
| 1756 | } else { |
| 1757 | ret = -EIO; |
| 1758 | } |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 1759 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1760 | mutex_unlock(&mvm->mutex); |
| 1761 | |
| 1762 | return ret; |
| 1763 | } |
| 1764 | |
| 1765 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 1766 | { |
| 1767 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1768 | |
| 1769 | mvm->rts_threshold = value; |
| 1770 | |
| 1771 | return 0; |
| 1772 | } |
| 1773 | |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1774 | static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, |
| 1775 | struct ieee80211_vif *vif, |
| 1776 | struct ieee80211_sta *sta, u32 changed) |
| 1777 | { |
| 1778 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1779 | |
| 1780 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1781 | changed & IEEE80211_RC_NSS_CHANGED) |
| 1782 | iwl_mvm_sf_update(mvm, vif, false); |
| 1783 | } |
| 1784 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1785 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
| 1786 | struct ieee80211_vif *vif, u16 ac, |
| 1787 | const struct ieee80211_tx_queue_params *params) |
| 1788 | { |
| 1789 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1790 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1791 | |
| 1792 | mvmvif->queue_params[ac] = *params; |
| 1793 | |
| 1794 | /* |
| 1795 | * No need to update right away, we'll get BSS_CHANGED_QOS |
| 1796 | * The exception is P2P_DEVICE interface which needs immediate update. |
| 1797 | */ |
| 1798 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 1799 | int ret; |
| 1800 | |
| 1801 | mutex_lock(&mvm->mutex); |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 1802 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1803 | mutex_unlock(&mvm->mutex); |
| 1804 | return ret; |
| 1805 | } |
| 1806 | return 0; |
| 1807 | } |
| 1808 | |
| 1809 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, |
| 1810 | struct ieee80211_vif *vif) |
| 1811 | { |
| 1812 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1813 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, |
| 1814 | 200 + vif->bss_conf.beacon_int); |
| 1815 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, |
| 1816 | 100 + vif->bss_conf.beacon_int); |
| 1817 | |
| 1818 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) |
| 1819 | return; |
| 1820 | |
| 1821 | mutex_lock(&mvm->mutex); |
| 1822 | /* Try really hard to protect the session and hear a beacon */ |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 1823 | iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1824 | mutex_unlock(&mvm->mutex); |
| 1825 | } |
| 1826 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1827 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
| 1828 | struct ieee80211_vif *vif, |
| 1829 | struct cfg80211_sched_scan_request *req, |
| 1830 | struct ieee80211_sched_scan_ies *ies) |
| 1831 | { |
| 1832 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1833 | int ret; |
| 1834 | |
| 1835 | mutex_lock(&mvm->mutex); |
| 1836 | |
David Spinadel | b538b8c | 2014-05-13 14:29:36 +0300 | [diff] [blame] | 1837 | if (!iwl_mvm_is_idle(mvm)) { |
David Spinadel | bd5e474 | 2014-04-24 13:15:29 +0300 | [diff] [blame] | 1838 | ret = -EBUSY; |
| 1839 | goto out; |
| 1840 | } |
| 1841 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 1842 | switch (mvm->scan_status) { |
| 1843 | case IWL_MVM_SCAN_OS: |
| 1844 | IWL_DEBUG_SCAN(mvm, "Stopping previous scan for sched_scan\n"); |
| 1845 | ret = iwl_mvm_cancel_scan(mvm); |
| 1846 | if (ret) { |
| 1847 | ret = -EBUSY; |
| 1848 | goto out; |
| 1849 | } |
| 1850 | |
| 1851 | /* |
| 1852 | * iwl_mvm_rx_scan_complete() will be called soon but will |
| 1853 | * not reset the scan status as it won't be IWL_MVM_SCAN_OS |
| 1854 | * any more since we queue the next scan immediately (below). |
| 1855 | * We make sure it is called before the next scan starts by |
| 1856 | * flushing the async-handlers work. |
| 1857 | */ |
| 1858 | break; |
| 1859 | case IWL_MVM_SCAN_NONE: |
| 1860 | break; |
| 1861 | default: |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1862 | ret = -EBUSY; |
| 1863 | goto out; |
| 1864 | } |
| 1865 | |
| 1866 | mvm->scan_status = IWL_MVM_SCAN_SCHED; |
| 1867 | |
| 1868 | ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies); |
| 1869 | if (ret) |
| 1870 | goto err; |
| 1871 | |
| 1872 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1873 | if (ret) |
| 1874 | goto err; |
| 1875 | |
| 1876 | ret = iwl_mvm_sched_scan_start(mvm, req); |
| 1877 | if (!ret) |
| 1878 | goto out; |
| 1879 | err: |
| 1880 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1881 | out: |
| 1882 | mutex_unlock(&mvm->mutex); |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 1883 | /* make sure to flush the Rx handler before the next scan arrives */ |
| 1884 | iwl_mvm_wait_for_async_handlers(mvm); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1885 | return ret; |
| 1886 | } |
| 1887 | |
Johannes Berg | 37e3308 | 2014-02-17 10:48:17 +0100 | [diff] [blame] | 1888 | static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, |
| 1889 | struct ieee80211_vif *vif) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1890 | { |
| 1891 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1892 | int ret; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1893 | |
| 1894 | mutex_lock(&mvm->mutex); |
David Spinadel | 636a2cd | 2014-05-01 15:57:22 +0300 | [diff] [blame] | 1895 | ret = iwl_mvm_sched_scan_stop(mvm, false); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1896 | mutex_unlock(&mvm->mutex); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1897 | iwl_mvm_wait_for_async_handlers(mvm); |
Johannes Berg | 37e3308 | 2014-02-17 10:48:17 +0100 | [diff] [blame] | 1898 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1899 | return ret; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1900 | } |
| 1901 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1902 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
| 1903 | enum set_key_cmd cmd, |
| 1904 | struct ieee80211_vif *vif, |
| 1905 | struct ieee80211_sta *sta, |
| 1906 | struct ieee80211_key_conf *key) |
| 1907 | { |
| 1908 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1909 | int ret; |
| 1910 | |
| 1911 | if (iwlwifi_mod_params.sw_crypto) { |
| 1912 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); |
| 1913 | return -EOPNOTSUPP; |
| 1914 | } |
| 1915 | |
| 1916 | switch (key->cipher) { |
| 1917 | case WLAN_CIPHER_SUITE_TKIP: |
| 1918 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 1919 | /* fall-through */ |
| 1920 | case WLAN_CIPHER_SUITE_CCMP: |
| 1921 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1922 | break; |
| 1923 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1924 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); |
| 1925 | break; |
| 1926 | case WLAN_CIPHER_SUITE_WEP40: |
| 1927 | case WLAN_CIPHER_SUITE_WEP104: |
| 1928 | /* |
| 1929 | * Support for TX only, at least for now, so accept |
| 1930 | * the key and do nothing else. Then mac80211 will |
| 1931 | * pass it for TX but we don't have to use it for RX. |
| 1932 | */ |
| 1933 | return 0; |
| 1934 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 1935 | /* currently FW supports only one optional cipher scheme */ |
| 1936 | if (hw->n_cipher_schemes && |
| 1937 | hw->cipher_schemes->cipher == key->cipher) |
| 1938 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
| 1939 | else |
| 1940 | return -EOPNOTSUPP; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | mutex_lock(&mvm->mutex); |
| 1944 | |
| 1945 | switch (cmd) { |
| 1946 | case SET_KEY: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1947 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
| 1948 | vif->type == NL80211_IFTYPE_AP) && !sta) { |
| 1949 | /* |
| 1950 | * GTK on AP interface is a TX-only key, return 0; |
| 1951 | * on IBSS they're per-station and because we're lazy |
| 1952 | * we don't support them for RX, so do the same. |
| 1953 | */ |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1954 | ret = 0; |
| 1955 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
| 1956 | break; |
| 1957 | } |
| 1958 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1959 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
| 1960 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); |
| 1961 | if (ret) { |
| 1962 | IWL_WARN(mvm, "set key failed\n"); |
| 1963 | /* |
| 1964 | * can't add key for RX, but we don't need it |
| 1965 | * in the device for TX so still return 0 |
| 1966 | */ |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1967 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1968 | ret = 0; |
| 1969 | } |
| 1970 | |
| 1971 | break; |
| 1972 | case DISABLE_KEY: |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1973 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
| 1974 | ret = 0; |
| 1975 | break; |
| 1976 | } |
| 1977 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1978 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
| 1979 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); |
| 1980 | break; |
| 1981 | default: |
| 1982 | ret = -EINVAL; |
| 1983 | } |
| 1984 | |
| 1985 | mutex_unlock(&mvm->mutex); |
| 1986 | return ret; |
| 1987 | } |
| 1988 | |
| 1989 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 1990 | struct ieee80211_vif *vif, |
| 1991 | struct ieee80211_key_conf *keyconf, |
| 1992 | struct ieee80211_sta *sta, |
| 1993 | u32 iv32, u16 *phase1key) |
| 1994 | { |
| 1995 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1996 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1997 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) |
| 1998 | return; |
| 1999 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2000 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
| 2001 | } |
| 2002 | |
| 2003 | |
| 2004 | static int iwl_mvm_roc(struct ieee80211_hw *hw, |
| 2005 | struct ieee80211_vif *vif, |
| 2006 | struct ieee80211_channel *channel, |
Ilan Peer | d339d5c | 2013-02-12 09:34:13 +0200 | [diff] [blame] | 2007 | int duration, |
| 2008 | enum ieee80211_roc_type type) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2009 | { |
| 2010 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2011 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2012 | struct cfg80211_chan_def chandef; |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2013 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
| 2014 | int ret, i; |
| 2015 | |
| 2016 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, |
| 2017 | duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2018 | |
| 2019 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) { |
| 2020 | IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type); |
| 2021 | return -EINVAL; |
| 2022 | } |
| 2023 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2024 | mutex_lock(&mvm->mutex); |
| 2025 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2026 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 2027 | phy_ctxt = &mvm->phy_ctxts[i]; |
| 2028 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) |
| 2029 | continue; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2030 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2031 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { |
| 2032 | /* |
| 2033 | * Unbind the P2P_DEVICE from the current PHY context, |
| 2034 | * and if the PHY context is not used remove it. |
| 2035 | */ |
| 2036 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 2037 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 2038 | goto out_unlock; |
| 2039 | |
| 2040 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 2041 | |
| 2042 | /* Bind the P2P_DEVICE to the current PHY Context */ |
| 2043 | mvmvif->phy_ctxt = phy_ctxt; |
| 2044 | |
| 2045 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 2046 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 2047 | goto out_unlock; |
| 2048 | |
| 2049 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 2050 | goto schedule_time_event; |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /* Need to update the PHY context only if the ROC channel changed */ |
| 2055 | if (channel == mvmvif->phy_ctxt->channel) |
| 2056 | goto schedule_time_event; |
| 2057 | |
| 2058 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
| 2059 | |
| 2060 | /* |
| 2061 | * Change the PHY context configuration as it is currently referenced |
| 2062 | * only by the P2P Device MAC |
| 2063 | */ |
| 2064 | if (mvmvif->phy_ctxt->ref == 1) { |
| 2065 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, |
| 2066 | &chandef, 1, 1); |
| 2067 | if (ret) |
| 2068 | goto out_unlock; |
| 2069 | } else { |
| 2070 | /* |
| 2071 | * The PHY context is shared with other MACs. Need to remove the |
| 2072 | * P2P Device from the binding, allocate an new PHY context and |
| 2073 | * create a new binding |
| 2074 | */ |
| 2075 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 2076 | if (!phy_ctxt) { |
| 2077 | ret = -ENOSPC; |
| 2078 | goto out_unlock; |
| 2079 | } |
| 2080 | |
| 2081 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, |
| 2082 | 1, 1); |
| 2083 | if (ret) { |
| 2084 | IWL_ERR(mvm, "Failed to change PHY context\n"); |
| 2085 | goto out_unlock; |
| 2086 | } |
| 2087 | |
| 2088 | /* Unbind the P2P_DEVICE from the current PHY context */ |
| 2089 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 2090 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 2091 | goto out_unlock; |
| 2092 | |
| 2093 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 2094 | |
| 2095 | /* Bind the P2P_DEVICE to the new allocated PHY context */ |
| 2096 | mvmvif->phy_ctxt = phy_ctxt; |
| 2097 | |
| 2098 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 2099 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 2100 | goto out_unlock; |
| 2101 | |
| 2102 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 2103 | } |
| 2104 | |
| 2105 | schedule_time_event: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2106 | /* Schedule the time events */ |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 2107 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2108 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2109 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2110 | mutex_unlock(&mvm->mutex); |
| 2111 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2112 | return ret; |
| 2113 | } |
| 2114 | |
| 2115 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) |
| 2116 | { |
| 2117 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2118 | |
| 2119 | IWL_DEBUG_MAC80211(mvm, "enter\n"); |
| 2120 | |
| 2121 | mutex_lock(&mvm->mutex); |
| 2122 | iwl_mvm_stop_p2p_roc(mvm); |
| 2123 | mutex_unlock(&mvm->mutex); |
| 2124 | |
| 2125 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
| 2126 | return 0; |
| 2127 | } |
| 2128 | |
| 2129 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, |
| 2130 | struct ieee80211_chanctx_conf *ctx) |
| 2131 | { |
| 2132 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2133 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 2134 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2135 | int ret; |
| 2136 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 2137 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2138 | |
| 2139 | mutex_lock(&mvm->mutex); |
| 2140 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 2141 | if (!phy_ctxt) { |
| 2142 | ret = -ENOSPC; |
| 2143 | goto out; |
| 2144 | } |
| 2145 | |
Eliad Peller | dcbc3e1 | 2013-10-31 14:31:25 +0200 | [diff] [blame] | 2146 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 2147 | ctx->rx_chains_static, |
| 2148 | ctx->rx_chains_dynamic); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2149 | if (ret) { |
| 2150 | IWL_ERR(mvm, "Failed to add PHY context\n"); |
| 2151 | goto out; |
| 2152 | } |
| 2153 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 2154 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2155 | *phy_ctxt_id = phy_ctxt->id; |
| 2156 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2157 | mutex_unlock(&mvm->mutex); |
| 2158 | return ret; |
| 2159 | } |
| 2160 | |
| 2161 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, |
| 2162 | struct ieee80211_chanctx_conf *ctx) |
| 2163 | { |
| 2164 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2165 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 2166 | 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] | 2167 | |
| 2168 | mutex_lock(&mvm->mutex); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2169 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2170 | mutex_unlock(&mvm->mutex); |
| 2171 | } |
| 2172 | |
| 2173 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, |
| 2174 | struct ieee80211_chanctx_conf *ctx, |
| 2175 | u32 changed) |
| 2176 | { |
| 2177 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2178 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 2179 | 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] | 2180 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2181 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
| 2182 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | |
| 2183 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | |
Arik Nemtsov | 2dceeda | 2013-12-29 17:57:53 +0200 | [diff] [blame] | 2184 | IEEE80211_CHANCTX_CHANGE_RADAR | |
| 2185 | IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2186 | "Cannot change PHY. Ref=%d, changed=0x%X\n", |
| 2187 | phy_ctxt->ref, changed)) |
| 2188 | return; |
| 2189 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2190 | mutex_lock(&mvm->mutex); |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 2191 | iwl_mvm_bt_coex_vif_change(mvm); |
Eliad Peller | dcbc3e1 | 2013-10-31 14:31:25 +0200 | [diff] [blame] | 2192 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2193 | ctx->rx_chains_static, |
| 2194 | ctx->rx_chains_dynamic); |
| 2195 | mutex_unlock(&mvm->mutex); |
| 2196 | } |
| 2197 | |
| 2198 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 2199 | struct ieee80211_vif *vif, |
| 2200 | struct ieee80211_chanctx_conf *ctx) |
| 2201 | { |
| 2202 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2203 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 2204 | 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] | 2205 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2206 | int ret; |
| 2207 | |
| 2208 | mutex_lock(&mvm->mutex); |
| 2209 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2210 | mvmvif->phy_ctxt = phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2211 | |
| 2212 | switch (vif->type) { |
| 2213 | case NL80211_IFTYPE_AP: |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 2214 | /* Unless it's a CSA flow we have nothing to do here */ |
| 2215 | if (vif->csa_active) { |
| 2216 | mvmvif->ap_ibss_active = true; |
| 2217 | break; |
| 2218 | } |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2219 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2220 | /* |
| 2221 | * 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] | 2222 | * (in bss_info_changed), similarly for IBSS. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2223 | */ |
| 2224 | ret = 0; |
| 2225 | goto out_unlock; |
| 2226 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2227 | case NL80211_IFTYPE_MONITOR: |
| 2228 | break; |
| 2229 | default: |
| 2230 | ret = -EINVAL; |
| 2231 | goto out_unlock; |
| 2232 | } |
| 2233 | |
| 2234 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 2235 | if (ret) |
| 2236 | goto out_unlock; |
| 2237 | |
| 2238 | /* |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 2239 | * Power state must be updated before quotas, |
| 2240 | * otherwise fw will complain. |
| 2241 | */ |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 2242 | iwl_mvm_power_update_mac(mvm); |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 2243 | |
| 2244 | /* Setting the quota at this stage is only required for monitor |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2245 | * interfaces. For the other types, the bss_info changed flow |
| 2246 | * will handle quota settings. |
| 2247 | */ |
| 2248 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 2249 | mvmvif->monitor_active = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2250 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 2251 | if (ret) |
| 2252 | goto out_remove_binding; |
| 2253 | } |
| 2254 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 2255 | /* Handle binding during CSA */ |
| 2256 | if (vif->type == NL80211_IFTYPE_AP) { |
| 2257 | iwl_mvm_update_quotas(mvm, vif); |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 2258 | iwl_mvm_mac_ctxt_changed(mvm, vif, false); |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 2259 | } |
| 2260 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2261 | goto out_unlock; |
| 2262 | |
| 2263 | out_remove_binding: |
| 2264 | iwl_mvm_binding_remove_vif(mvm, vif); |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 2265 | iwl_mvm_power_update_mac(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2266 | out_unlock: |
| 2267 | mutex_unlock(&mvm->mutex); |
| 2268 | if (ret) |
| 2269 | mvmvif->phy_ctxt = NULL; |
| 2270 | return ret; |
| 2271 | } |
| 2272 | |
| 2273 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 2274 | struct ieee80211_vif *vif, |
| 2275 | struct ieee80211_chanctx_conf *ctx) |
| 2276 | { |
| 2277 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2278 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2279 | |
| 2280 | mutex_lock(&mvm->mutex); |
| 2281 | |
| 2282 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); |
| 2283 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2284 | switch (vif->type) { |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2285 | case NL80211_IFTYPE_ADHOC: |
| 2286 | goto out_unlock; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2287 | case NL80211_IFTYPE_MONITOR: |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 2288 | mvmvif->monitor_active = false; |
| 2289 | iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2290 | break; |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 2291 | case NL80211_IFTYPE_AP: |
| 2292 | /* This part is triggered only during CSA */ |
| 2293 | if (!vif->csa_active || !mvmvif->ap_ibss_active) |
| 2294 | goto out_unlock; |
| 2295 | |
| 2296 | mvmvif->ap_ibss_active = false; |
| 2297 | iwl_mvm_update_quotas(mvm, NULL); |
| 2298 | /*TODO: bt_coex notification here? */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2299 | default: |
| 2300 | break; |
| 2301 | } |
| 2302 | |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 2303 | iwl_mvm_binding_remove_vif(mvm, vif); |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 2304 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2305 | out_unlock: |
| 2306 | mvmvif->phy_ctxt = NULL; |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 2307 | iwl_mvm_power_update_mac(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2308 | mutex_unlock(&mvm->mutex); |
| 2309 | } |
| 2310 | |
| 2311 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, |
| 2312 | struct ieee80211_sta *sta, |
| 2313 | bool set) |
| 2314 | { |
| 2315 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2316 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; |
| 2317 | |
| 2318 | if (!mvm_sta || !mvm_sta->vif) { |
| 2319 | IWL_ERR(mvm, "Station is not associated to a vif\n"); |
| 2320 | return -EINVAL; |
| 2321 | } |
| 2322 | |
| 2323 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); |
| 2324 | } |
| 2325 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2326 | #ifdef CONFIG_NL80211_TESTMODE |
| 2327 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { |
| 2328 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, |
| 2329 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, |
Johannes Berg | f6c6ad4 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 2330 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2331 | }; |
| 2332 | |
| 2333 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, |
| 2334 | struct ieee80211_vif *vif, |
| 2335 | void *data, int len) |
| 2336 | { |
| 2337 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; |
| 2338 | int err; |
| 2339 | u32 noa_duration; |
| 2340 | |
| 2341 | err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy); |
| 2342 | if (err) |
| 2343 | return err; |
| 2344 | |
| 2345 | if (!tb[IWL_MVM_TM_ATTR_CMD]) |
| 2346 | return -EINVAL; |
| 2347 | |
| 2348 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { |
| 2349 | case IWL_MVM_TM_CMD_SET_NOA: |
| 2350 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || |
| 2351 | !vif->bss_conf.enable_beacon || |
| 2352 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) |
| 2353 | return -EINVAL; |
| 2354 | |
| 2355 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); |
| 2356 | if (noa_duration >= vif->bss_conf.beacon_int) |
| 2357 | return -EINVAL; |
| 2358 | |
| 2359 | mvm->noa_duration = noa_duration; |
| 2360 | mvm->noa_vif = vif; |
| 2361 | |
| 2362 | return iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | f6c6ad4 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 2363 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
| 2364 | /* must be associated client vif - ignore authorized */ |
| 2365 | if (!vif || vif->type != NL80211_IFTYPE_STATION || |
| 2366 | !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || |
| 2367 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) |
| 2368 | return -EINVAL; |
| 2369 | |
| 2370 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2371 | return iwl_mvm_enable_beacon_filter(mvm, vif, 0); |
| 2372 | return iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | return -EOPNOTSUPP; |
| 2376 | } |
| 2377 | |
| 2378 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, |
| 2379 | struct ieee80211_vif *vif, |
| 2380 | void *data, int len) |
| 2381 | { |
| 2382 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2383 | int err; |
| 2384 | |
| 2385 | mutex_lock(&mvm->mutex); |
| 2386 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); |
| 2387 | mutex_unlock(&mvm->mutex); |
| 2388 | |
| 2389 | return err; |
| 2390 | } |
| 2391 | #endif |
| 2392 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 2393 | static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw *hw, |
| 2394 | struct ieee80211_vif *vif, |
| 2395 | struct cfg80211_chan_def *chandef) |
| 2396 | { |
| 2397 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2398 | |
| 2399 | mutex_lock(&mvm->mutex); |
| 2400 | if (WARN(mvm->csa_vif && mvm->csa_vif->csa_active, |
| 2401 | "Another CSA is already in progress")) |
| 2402 | goto out_unlock; |
| 2403 | |
| 2404 | IWL_DEBUG_MAC80211(mvm, "CSA started to freq %d\n", |
| 2405 | chandef->center_freq1); |
| 2406 | mvm->csa_vif = vif; |
| 2407 | |
| 2408 | out_unlock: |
| 2409 | mutex_unlock(&mvm->mutex); |
| 2410 | } |
| 2411 | |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 2412 | static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, |
| 2413 | struct ieee80211_vif *vif, u32 queues, bool drop) |
| 2414 | { |
| 2415 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2416 | struct iwl_mvm_vif *mvmvif; |
| 2417 | struct iwl_mvm_sta *mvmsta; |
| 2418 | |
| 2419 | if (!vif || vif->type != NL80211_IFTYPE_STATION) |
| 2420 | return; |
| 2421 | |
| 2422 | mutex_lock(&mvm->mutex); |
| 2423 | mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2424 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id); |
| 2425 | |
| 2426 | if (WARN_ON_ONCE(!mvmsta)) |
| 2427 | goto done; |
| 2428 | |
| 2429 | if (drop) { |
| 2430 | if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true)) |
| 2431 | IWL_ERR(mvm, "flush request fail\n"); |
| 2432 | } else { |
| 2433 | iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 2434 | mvmsta->tfd_queue_msk); |
| 2435 | } |
| 2436 | done: |
| 2437 | mutex_unlock(&mvm->mutex); |
| 2438 | } |
| 2439 | |
Johannes Berg | e520926 | 2014-01-20 23:38:59 +0100 | [diff] [blame] | 2440 | const struct ieee80211_ops iwl_mvm_hw_ops = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2441 | .tx = iwl_mvm_mac_tx, |
| 2442 | .ampdu_action = iwl_mvm_mac_ampdu_action, |
| 2443 | .start = iwl_mvm_mac_start, |
| 2444 | .restart_complete = iwl_mvm_mac_restart_complete, |
| 2445 | .stop = iwl_mvm_mac_stop, |
| 2446 | .add_interface = iwl_mvm_mac_add_interface, |
| 2447 | .remove_interface = iwl_mvm_mac_remove_interface, |
| 2448 | .config = iwl_mvm_mac_config, |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 2449 | .prepare_multicast = iwl_mvm_prepare_multicast, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2450 | .configure_filter = iwl_mvm_configure_filter, |
| 2451 | .bss_info_changed = iwl_mvm_bss_info_changed, |
| 2452 | .hw_scan = iwl_mvm_mac_hw_scan, |
| 2453 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 2454 | .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2455 | .sta_state = iwl_mvm_mac_sta_state, |
| 2456 | .sta_notify = iwl_mvm_mac_sta_notify, |
| 2457 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2458 | .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2459 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 2460 | .sta_rc_update = iwl_mvm_sta_rc_update, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2461 | .conf_tx = iwl_mvm_mac_conf_tx, |
| 2462 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, |
Emmanuel Grumbach | c5b0e7c | 2014-03-24 12:08:53 +0200 | [diff] [blame] | 2463 | .flush = iwl_mvm_mac_flush, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2464 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
| 2465 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2466 | .set_key = iwl_mvm_mac_set_key, |
| 2467 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, |
| 2468 | .remain_on_channel = iwl_mvm_roc, |
| 2469 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2470 | .add_chanctx = iwl_mvm_add_chanctx, |
| 2471 | .remove_chanctx = iwl_mvm_remove_chanctx, |
| 2472 | .change_chanctx = iwl_mvm_change_chanctx, |
| 2473 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, |
| 2474 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, |
| 2475 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2476 | .start_ap = iwl_mvm_start_ap_ibss, |
| 2477 | .stop_ap = iwl_mvm_stop_ap_ibss, |
| 2478 | .join_ibss = iwl_mvm_start_ap_ibss, |
| 2479 | .leave_ibss = iwl_mvm_stop_ap_ibss, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2480 | |
| 2481 | .set_tim = iwl_mvm_set_tim, |
| 2482 | |
Andrei Otcheretianski | bd3398e | 2013-10-22 05:01:12 +0200 | [diff] [blame] | 2483 | .channel_switch_beacon = iwl_mvm_channel_switch_beacon, |
| 2484 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2485 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
| 2486 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2487 | #ifdef CONFIG_PM_SLEEP |
| 2488 | /* look at d3.c */ |
| 2489 | .suspend = iwl_mvm_suspend, |
| 2490 | .resume = iwl_mvm_resume, |
| 2491 | .set_wakeup = iwl_mvm_set_wakeup, |
| 2492 | .set_rekey_data = iwl_mvm_set_rekey_data, |
| 2493 | #if IS_ENABLED(CONFIG_IPV6) |
| 2494 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, |
| 2495 | #endif |
| 2496 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, |
| 2497 | #endif |
| 2498 | }; |