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