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