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