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