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; |
| 550 | |
| 551 | iwl_mvm_reset_phy_ctxts(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 552 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 553 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); |
| 554 | |
| 555 | ieee80211_wake_queues(mvm->hw); |
| 556 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame^] | 557 | /* cleanup all stale references (scan, roc), but keep the |
| 558 | * ucode_down ref until reconfig is complete */ |
| 559 | iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 560 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 561 | mvm->vif_count = 0; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 562 | mvm->rx_ba_sessions = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) |
| 566 | { |
| 567 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 568 | int ret; |
| 569 | |
| 570 | mutex_lock(&mvm->mutex); |
| 571 | |
| 572 | /* Clean up some internal and mac80211 state on restart */ |
| 573 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 574 | iwl_mvm_restart_cleanup(mvm); |
| 575 | |
| 576 | ret = iwl_mvm_up(mvm); |
| 577 | mutex_unlock(&mvm->mutex); |
| 578 | |
| 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) |
| 583 | { |
| 584 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 585 | int ret; |
| 586 | |
| 587 | mutex_lock(&mvm->mutex); |
| 588 | |
| 589 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 590 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 591 | if (ret) |
| 592 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", |
| 593 | ret); |
| 594 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame^] | 595 | /* allow transport/FW low power modes */ |
| 596 | iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 597 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 598 | mutex_unlock(&mvm->mutex); |
| 599 | } |
| 600 | |
| 601 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) |
| 602 | { |
| 603 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 604 | |
| 605 | flush_work(&mvm->async_handlers_wk); |
| 606 | |
| 607 | mutex_lock(&mvm->mutex); |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame^] | 608 | |
| 609 | /* disallow low power states when the FW is down */ |
| 610 | iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 611 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 612 | /* async_handlers_wk is now blocked */ |
| 613 | |
| 614 | /* |
| 615 | * The work item could be running or queued if the |
| 616 | * ROC time event stops just as we get here. |
| 617 | */ |
| 618 | cancel_work_sync(&mvm->roc_done_wk); |
| 619 | |
| 620 | iwl_trans_stop_device(mvm->trans); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 621 | |
| 622 | iwl_mvm_async_handlers_purge(mvm); |
| 623 | /* async_handlers_list is empty and will stay empty: HW is stopped */ |
| 624 | |
| 625 | /* the fw is stopped, the aux sta is dead: clean up driver state */ |
| 626 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 627 | |
| 628 | mutex_unlock(&mvm->mutex); |
| 629 | |
| 630 | /* |
| 631 | * The worker might have been waiting for the mutex, let it run and |
| 632 | * discover that its list is now empty. |
| 633 | */ |
| 634 | cancel_work_sync(&mvm->async_handlers_wk); |
| 635 | } |
| 636 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 637 | static void iwl_mvm_power_update_iterator(void *data, u8 *mac, |
| 638 | struct ieee80211_vif *vif) |
| 639 | { |
| 640 | struct iwl_mvm *mvm = data; |
| 641 | |
| 642 | iwl_mvm_power_update_mode(mvm, vif); |
| 643 | } |
| 644 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 645 | static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
| 646 | { |
| 647 | u16 i; |
| 648 | |
| 649 | lockdep_assert_held(&mvm->mutex); |
| 650 | |
| 651 | for (i = 0; i < NUM_PHY_CTX; i++) |
| 652 | if (!mvm->phy_ctxts[i].ref) |
| 653 | return &mvm->phy_ctxts[i]; |
| 654 | |
| 655 | IWL_ERR(mvm, "No available PHY context\n"); |
| 656 | return NULL; |
| 657 | } |
| 658 | |
Emmanuel Grumbach | ee9c6cb | 2013-12-04 13:53:39 +0200 | [diff] [blame] | 659 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 660 | s8 tx_power) |
| 661 | { |
| 662 | /* FW is in charge of regulatory enforcement */ |
| 663 | struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = { |
| 664 | .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id, |
| 665 | .pwr_restriction = cpu_to_le16(tx_power), |
| 666 | }; |
| 667 | |
| 668 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC, |
| 669 | sizeof(reduce_txpwr_cmd), |
| 670 | &reduce_txpwr_cmd); |
| 671 | } |
| 672 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 673 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
| 674 | struct ieee80211_vif *vif) |
| 675 | { |
| 676 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 677 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 678 | int ret; |
| 679 | |
| 680 | /* |
| 681 | * Not much to do here. The stack will not allow interface |
| 682 | * types or combinations that we didn't advertise, so we |
| 683 | * don't really have to check the types. |
| 684 | */ |
| 685 | |
| 686 | mutex_lock(&mvm->mutex); |
| 687 | |
Eliad Peller | e89044d | 2013-07-16 17:33:26 +0300 | [diff] [blame] | 688 | /* Allocate resources for the MAC context, and add it to the fw */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 689 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
| 690 | if (ret) |
| 691 | goto out_unlock; |
| 692 | |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 693 | /* Counting number of interfaces is needed for legacy PM */ |
Ilan Peer | ea183d0 | 2013-07-23 14:41:53 +0300 | [diff] [blame] | 694 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 695 | mvm->vif_count++; |
Ilan Peer | ea183d0 | 2013-07-23 14:41:53 +0300 | [diff] [blame] | 696 | |
| 697 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 698 | * The AP binding flow can be done only after the beacon |
| 699 | * template is configured (which happens only in the mac80211 |
| 700 | * start_ap() flow), and adding the broadcast station can happen |
| 701 | * only after the binding. |
| 702 | * In addition, since modifying the MAC before adding a bcast |
| 703 | * station is not allowed by the FW, delay the adding of MAC context to |
| 704 | * the point where we can also add the bcast station. |
| 705 | * In short: there's not much we can do at this point, other than |
| 706 | * allocating resources :) |
| 707 | */ |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 708 | if (vif->type == NL80211_IFTYPE_AP || |
| 709 | vif->type == NL80211_IFTYPE_ADHOC) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 710 | u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); |
| 711 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, |
| 712 | qmask); |
| 713 | if (ret) { |
| 714 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); |
| 715 | goto out_release; |
| 716 | } |
| 717 | |
Emmanuel Grumbach | 77740cb | 2013-06-26 23:51:41 +0300 | [diff] [blame] | 718 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 719 | goto out_unlock; |
| 720 | } |
| 721 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 722 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 723 | if (ret) |
| 724 | goto out_release; |
| 725 | |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 726 | iwl_mvm_power_disable(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 727 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 728 | /* beacon filtering */ |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 729 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 730 | if (ret) |
| 731 | goto out_remove_mac; |
| 732 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 733 | if (!mvm->bf_allowed_vif && |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 734 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p && |
| 735 | mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){ |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 736 | mvm->bf_allowed_vif = mvmvif; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 737 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 738 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 739 | } |
| 740 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 741 | /* |
| 742 | * P2P_DEVICE interface does not have a channel context assigned to it, |
| 743 | * so a dedicated PHY context is allocated to it and the corresponding |
| 744 | * MAC context is bound to it at this stage. |
| 745 | */ |
| 746 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 747 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 748 | mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 749 | if (!mvmvif->phy_ctxt) { |
| 750 | ret = -ENOSPC; |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 751 | goto out_free_bf; |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 752 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 753 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 754 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 755 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 756 | if (ret) |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 757 | goto out_unref_phy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 758 | |
| 759 | ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 760 | if (ret) |
| 761 | goto out_unbind; |
| 762 | |
| 763 | /* Save a pointer to p2p device vif, so it can later be used to |
| 764 | * update the p2p device MAC when a GO is started/stopped */ |
| 765 | mvm->p2p_device_vif = vif; |
| 766 | } |
| 767 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 768 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 769 | goto out_unlock; |
| 770 | |
| 771 | out_unbind: |
| 772 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 773 | out_unref_phy: |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 774 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 775 | out_free_bf: |
| 776 | if (mvm->bf_allowed_vif == mvmvif) { |
| 777 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 778 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 779 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 780 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 781 | out_remove_mac: |
| 782 | mvmvif->phy_ctxt = NULL; |
| 783 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 784 | out_release: |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 785 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 786 | mvm->vif_count--; |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 787 | |
| 788 | /* TODO: remove this when legacy PM will be discarded */ |
Alexander Bondar | 4bf881f | 2013-05-29 10:19:50 +0300 | [diff] [blame] | 789 | ieee80211_iterate_active_interfaces( |
| 790 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 791 | iwl_mvm_power_update_iterator, mvm); |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 792 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 793 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 794 | out_unlock: |
| 795 | mutex_unlock(&mvm->mutex); |
| 796 | |
| 797 | return ret; |
| 798 | } |
| 799 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 800 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
| 801 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 802 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 803 | u32 tfd_msk = 0, ac; |
| 804 | |
| 805 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 806 | if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE) |
| 807 | tfd_msk |= BIT(vif->hw_queue[ac]); |
| 808 | |
| 809 | if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE) |
| 810 | tfd_msk |= BIT(vif->cab_queue); |
| 811 | |
| 812 | if (tfd_msk) { |
| 813 | mutex_lock(&mvm->mutex); |
| 814 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); |
| 815 | mutex_unlock(&mvm->mutex); |
| 816 | } |
| 817 | |
| 818 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 819 | /* |
| 820 | * Flush the ROC worker which will flush the OFFCHANNEL queue. |
| 821 | * We assume here that all the packets sent to the OFFCHANNEL |
| 822 | * queue are sent in ROC session. |
| 823 | */ |
| 824 | flush_work(&mvm->roc_done_wk); |
| 825 | } else { |
| 826 | /* |
| 827 | * By now, all the AC queues are empty. The AGG queues are |
| 828 | * empty too. We already got all the Tx responses for all the |
| 829 | * packets in the queues. The drain work can have been |
Emmanuel Grumbach | 0742a75 | 2013-06-10 14:10:33 +0300 | [diff] [blame] | 830 | * triggered. Flush it. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 831 | */ |
| 832 | flush_work(&mvm->sta_drained_wk); |
| 833 | } |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, |
| 837 | struct ieee80211_vif *vif) |
| 838 | { |
| 839 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 840 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 841 | |
| 842 | iwl_mvm_prepare_mac_removal(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 843 | |
| 844 | mutex_lock(&mvm->mutex); |
| 845 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 846 | if (mvm->bf_allowed_vif == mvmvif) { |
| 847 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 848 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 849 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 850 | } |
| 851 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 852 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
| 853 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 854 | /* |
| 855 | * 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] | 856 | * interface is be handled as part of the stop_ap flow. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 857 | */ |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 858 | if (vif->type == NL80211_IFTYPE_AP || |
| 859 | vif->type == NL80211_IFTYPE_ADHOC) { |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 860 | #ifdef CONFIG_NL80211_TESTMODE |
| 861 | if (vif == mvm->noa_vif) { |
| 862 | mvm->noa_vif = NULL; |
| 863 | mvm->noa_duration = 0; |
| 864 | } |
| 865 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 866 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 867 | goto out_release; |
| 868 | } |
| 869 | |
| 870 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 871 | mvm->p2p_device_vif = NULL; |
| 872 | iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 873 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 874 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 875 | mvmvif->phy_ctxt = NULL; |
| 876 | } |
| 877 | |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 878 | if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 879 | mvm->vif_count--; |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 880 | |
| 881 | /* TODO: remove this when legacy PM will be discarded */ |
| 882 | ieee80211_iterate_active_interfaces( |
| 883 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 884 | iwl_mvm_power_update_iterator, mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 885 | |
| 886 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 887 | |
| 888 | out_release: |
| 889 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 890 | mutex_unlock(&mvm->mutex); |
| 891 | } |
| 892 | |
| 893 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 894 | { |
| 895 | return 0; |
| 896 | } |
| 897 | |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 898 | struct iwl_mvm_mc_iter_data { |
| 899 | struct iwl_mvm *mvm; |
| 900 | int port_id; |
| 901 | }; |
| 902 | |
| 903 | static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, |
| 904 | struct ieee80211_vif *vif) |
| 905 | { |
| 906 | struct iwl_mvm_mc_iter_data *data = _data; |
| 907 | struct iwl_mvm *mvm = data->mvm; |
| 908 | struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; |
| 909 | int ret, len; |
| 910 | |
| 911 | /* if we don't have free ports, mcast frames will be dropped */ |
| 912 | if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) |
| 913 | return; |
| 914 | |
| 915 | if (vif->type != NL80211_IFTYPE_STATION || |
| 916 | !vif->bss_conf.assoc) |
| 917 | return; |
| 918 | |
| 919 | cmd->port_id = data->port_id++; |
| 920 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); |
| 921 | len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); |
| 922 | |
| 923 | ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd); |
| 924 | if (ret) |
| 925 | IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); |
| 926 | } |
| 927 | |
| 928 | static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) |
| 929 | { |
| 930 | struct iwl_mvm_mc_iter_data iter_data = { |
| 931 | .mvm = mvm, |
| 932 | }; |
| 933 | |
| 934 | lockdep_assert_held(&mvm->mutex); |
| 935 | |
| 936 | if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) |
| 937 | return; |
| 938 | |
| 939 | ieee80211_iterate_active_interfaces( |
| 940 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 941 | iwl_mvm_mc_iface_iterator, &iter_data); |
| 942 | } |
| 943 | |
| 944 | static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, |
| 945 | struct netdev_hw_addr_list *mc_list) |
| 946 | { |
| 947 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 948 | struct iwl_mcast_filter_cmd *cmd; |
| 949 | struct netdev_hw_addr *addr; |
| 950 | int addr_count = netdev_hw_addr_list_count(mc_list); |
| 951 | bool pass_all = false; |
| 952 | int len; |
| 953 | |
| 954 | if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) { |
| 955 | pass_all = true; |
| 956 | addr_count = 0; |
| 957 | } |
| 958 | |
| 959 | len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); |
| 960 | cmd = kzalloc(len, GFP_ATOMIC); |
| 961 | if (!cmd) |
| 962 | return 0; |
| 963 | |
| 964 | if (pass_all) { |
| 965 | cmd->pass_all = 1; |
| 966 | return (u64)(unsigned long)cmd; |
| 967 | } |
| 968 | |
| 969 | netdev_hw_addr_list_for_each(addr, mc_list) { |
| 970 | IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", |
| 971 | cmd->count, addr->addr); |
| 972 | memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], |
| 973 | addr->addr, ETH_ALEN); |
| 974 | cmd->count++; |
| 975 | } |
| 976 | |
| 977 | return (u64)(unsigned long)cmd; |
| 978 | } |
| 979 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 980 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, |
| 981 | unsigned int changed_flags, |
| 982 | unsigned int *total_flags, |
| 983 | u64 multicast) |
| 984 | { |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 985 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 986 | struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; |
| 987 | |
| 988 | mutex_lock(&mvm->mutex); |
| 989 | |
| 990 | /* replace previous configuration */ |
| 991 | kfree(mvm->mcast_filter_cmd); |
| 992 | mvm->mcast_filter_cmd = cmd; |
| 993 | |
| 994 | if (!cmd) |
| 995 | goto out; |
| 996 | |
| 997 | iwl_mvm_recalc_multicast(mvm); |
| 998 | out: |
| 999 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1000 | *total_flags = 0; |
| 1001 | } |
| 1002 | |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1003 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1004 | struct iwl_bcast_iter_data { |
| 1005 | struct iwl_mvm *mvm; |
| 1006 | struct iwl_bcast_filter_cmd *cmd; |
| 1007 | u8 current_filter; |
| 1008 | }; |
| 1009 | |
| 1010 | static void |
| 1011 | iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, |
| 1012 | const struct iwl_fw_bcast_filter *in_filter, |
| 1013 | struct iwl_fw_bcast_filter *out_filter) |
| 1014 | { |
| 1015 | struct iwl_fw_bcast_filter_attr *attr; |
| 1016 | int i; |
| 1017 | |
| 1018 | memcpy(out_filter, in_filter, sizeof(*out_filter)); |
| 1019 | |
| 1020 | for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { |
| 1021 | attr = &out_filter->attrs[i]; |
| 1022 | |
| 1023 | if (!attr->mask) |
| 1024 | break; |
| 1025 | |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 1026 | switch (attr->reserved1) { |
| 1027 | case cpu_to_le16(BC_FILTER_MAGIC_IP): |
| 1028 | if (vif->bss_conf.arp_addr_cnt != 1) { |
| 1029 | attr->mask = 0; |
| 1030 | continue; |
| 1031 | } |
| 1032 | |
| 1033 | attr->val = vif->bss_conf.arp_addr_list[0]; |
| 1034 | break; |
| 1035 | case cpu_to_le16(BC_FILTER_MAGIC_MAC): |
| 1036 | attr->val = *(__be32 *)&vif->addr[2]; |
| 1037 | break; |
| 1038 | default: |
| 1039 | break; |
| 1040 | } |
| 1041 | attr->reserved1 = 0; |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1042 | out_filter->num_attrs++; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, |
| 1047 | struct ieee80211_vif *vif) |
| 1048 | { |
| 1049 | struct iwl_bcast_iter_data *data = _data; |
| 1050 | struct iwl_mvm *mvm = data->mvm; |
| 1051 | struct iwl_bcast_filter_cmd *cmd = data->cmd; |
| 1052 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1053 | struct iwl_fw_bcast_mac *bcast_mac; |
| 1054 | int i; |
| 1055 | |
| 1056 | if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) |
| 1057 | return; |
| 1058 | |
| 1059 | bcast_mac = &cmd->macs[mvmvif->id]; |
| 1060 | |
| 1061 | /* enable filtering only for associated stations */ |
| 1062 | if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc) |
| 1063 | return; |
| 1064 | |
| 1065 | bcast_mac->default_discard = 1; |
| 1066 | |
| 1067 | /* copy all configured filters */ |
| 1068 | for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { |
| 1069 | /* |
| 1070 | * Make sure we don't exceed our filters limit. |
| 1071 | * if there is still a valid filter to be configured, |
| 1072 | * be on the safe side and just allow bcast for this mac. |
| 1073 | */ |
| 1074 | if (WARN_ON_ONCE(data->current_filter >= |
| 1075 | ARRAY_SIZE(cmd->filters))) { |
| 1076 | bcast_mac->default_discard = 0; |
| 1077 | bcast_mac->attached_filters = 0; |
| 1078 | break; |
| 1079 | } |
| 1080 | |
| 1081 | iwl_mvm_set_bcast_filter(vif, |
| 1082 | &mvm->bcast_filters[i], |
| 1083 | &cmd->filters[data->current_filter]); |
| 1084 | |
| 1085 | /* skip current filter if it contains no attributes */ |
| 1086 | if (!cmd->filters[data->current_filter].num_attrs) |
| 1087 | continue; |
| 1088 | |
| 1089 | /* attach the filter to current mac */ |
| 1090 | bcast_mac->attached_filters |= |
| 1091 | cpu_to_le16(BIT(data->current_filter)); |
| 1092 | |
| 1093 | data->current_filter++; |
| 1094 | } |
| 1095 | } |
| 1096 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1097 | bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm, |
| 1098 | struct iwl_bcast_filter_cmd *cmd) |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1099 | { |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1100 | struct iwl_bcast_iter_data iter_data = { |
| 1101 | .mvm = mvm, |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1102 | .cmd = cmd, |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1103 | }; |
| 1104 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1105 | memset(cmd, 0, sizeof(*cmd)); |
| 1106 | cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); |
| 1107 | cmd->max_macs = ARRAY_SIZE(cmd->macs); |
| 1108 | |
| 1109 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1110 | /* use debugfs filters/macs if override is configured */ |
| 1111 | if (mvm->dbgfs_bcast_filtering.override) { |
| 1112 | memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters, |
| 1113 | sizeof(cmd->filters)); |
| 1114 | memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs, |
| 1115 | sizeof(cmd->macs)); |
| 1116 | return true; |
| 1117 | } |
| 1118 | #endif |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1119 | |
| 1120 | /* if no filters are configured, do nothing */ |
| 1121 | if (!mvm->bcast_filters) |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1122 | return false; |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1123 | |
| 1124 | /* configure and attach these filters for each associated sta vif */ |
| 1125 | ieee80211_iterate_active_interfaces( |
| 1126 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1127 | iwl_mvm_bcast_filter_iterator, &iter_data); |
| 1128 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1129 | return true; |
| 1130 | } |
| 1131 | static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, |
| 1132 | struct ieee80211_vif *vif) |
| 1133 | { |
| 1134 | struct iwl_bcast_filter_cmd cmd; |
| 1135 | |
| 1136 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) |
| 1137 | return 0; |
| 1138 | |
| 1139 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) |
| 1140 | return 0; |
| 1141 | |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1142 | return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC, |
| 1143 | sizeof(cmd), &cmd); |
| 1144 | } |
| 1145 | #else |
| 1146 | static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, |
| 1147 | struct ieee80211_vif *vif) |
| 1148 | { |
| 1149 | return 0; |
| 1150 | } |
| 1151 | #endif |
| 1152 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1153 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
| 1154 | struct ieee80211_vif *vif, |
| 1155 | struct ieee80211_bss_conf *bss_conf, |
| 1156 | u32 changes) |
| 1157 | { |
| 1158 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1159 | int ret; |
| 1160 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 1161 | /* |
| 1162 | * Re-calculate the tsf id, as the master-slave relations depend on the |
| 1163 | * beacon interval, which was not known when the station interface was |
| 1164 | * added. |
| 1165 | */ |
| 1166 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) |
| 1167 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
| 1168 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1169 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 1170 | if (ret) |
| 1171 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
| 1172 | |
| 1173 | if (changes & BSS_CHANGED_ASSOC) { |
| 1174 | if (bss_conf->assoc) { |
| 1175 | /* add quota for this interface */ |
| 1176 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 1177 | if (ret) { |
| 1178 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 1179 | return; |
| 1180 | } |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 1181 | |
| 1182 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, |
| 1183 | &mvm->status)) { |
| 1184 | /* |
| 1185 | * If we're restarting then the firmware will |
| 1186 | * obviously have lost synchronisation with |
| 1187 | * the AP. It will attempt to synchronise by |
| 1188 | * itself, but we can make it more reliable by |
| 1189 | * scheduling a session protection time event. |
| 1190 | * |
| 1191 | * The firmware needs to receive a beacon to |
| 1192 | * catch up with synchronisation, use 110% of |
| 1193 | * the beacon interval. |
| 1194 | * |
| 1195 | * Set a large maximum delay to allow for more |
| 1196 | * than a single interface. |
| 1197 | */ |
| 1198 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; |
| 1199 | iwl_mvm_protect_session(mvm, vif, dur, dur, |
| 1200 | 5 * dur); |
| 1201 | } |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1202 | |
| 1203 | iwl_mvm_sf_update(mvm, vif, false); |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 1204 | iwl_mvm_power_vif_assoc(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1205 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1206 | /* |
| 1207 | * If update fails - SF might be running in associated |
| 1208 | * mode while disassociated - which is forbidden. |
| 1209 | */ |
| 1210 | WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false), |
| 1211 | "Failed to update SF upon disassociation\n"); |
| 1212 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1213 | /* remove AP station now that the MAC is unassoc */ |
| 1214 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); |
| 1215 | if (ret) |
| 1216 | IWL_ERR(mvm, "failed to remove AP station\n"); |
| 1217 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 1218 | /* remove quota for this interface */ |
| 1219 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 1220 | if (ret) |
| 1221 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 1222 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1223 | |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1224 | iwl_mvm_recalc_multicast(mvm); |
Eliad Peller | c87163b | 2014-01-08 10:11:11 +0200 | [diff] [blame] | 1225 | iwl_mvm_configure_bcast_filter(mvm, vif); |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 1226 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1227 | /* reset rssi values */ |
| 1228 | mvmvif->bf_data.ave_beacon_signal = 0; |
| 1229 | |
Alexander Bondar | e8e626a | 2013-10-16 00:21:34 +0200 | [diff] [blame] | 1230 | if (!(mvm->fw->ucode_capa.flags & |
| 1231 | IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) { |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 1232 | /* Workaround for FW bug, otherwise FW disables device |
| 1233 | * power save upon disassociation |
| 1234 | */ |
| 1235 | ret = iwl_mvm_power_update_mode(mvm, vif); |
| 1236 | if (ret) |
| 1237 | IWL_ERR(mvm, "failed to update power mode\n"); |
| 1238 | } |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 1239 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | f94045e | 2014-01-06 13:38:55 +0200 | [diff] [blame] | 1240 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, |
| 1241 | IEEE80211_SMPS_AUTOMATIC); |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 1242 | } else if (changes & BSS_CHANGED_BEACON_INFO) { |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 1243 | /* |
| 1244 | * We received a beacon _after_ association so |
| 1245 | * remove the session protection. |
| 1246 | */ |
| 1247 | iwl_mvm_remove_time_event(mvm, mvmvif, |
| 1248 | &mvmvif->time_event_data); |
Alexander Bondar | 51498cf | 2013-09-02 17:10:14 +0300 | [diff] [blame] | 1249 | } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | |
| 1250 | BSS_CHANGED_QOS)) { |
Alexander Bondar | 4bf881f | 2013-05-29 10:19:50 +0300 | [diff] [blame] | 1251 | ret = iwl_mvm_power_update_mode(mvm, vif); |
| 1252 | if (ret) |
| 1253 | IWL_ERR(mvm, "failed to update power mode\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1254 | } |
Matti Gottlieb | 88f2fd7 | 2013-07-09 15:25:46 +0300 | [diff] [blame] | 1255 | if (changes & BSS_CHANGED_TXPOWER) { |
| 1256 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", |
| 1257 | bss_conf->txpower); |
| 1258 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); |
| 1259 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1260 | |
| 1261 | if (changes & BSS_CHANGED_CQM) { |
| 1262 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed"); |
| 1263 | /* reset cqm events tracking */ |
| 1264 | mvmvif->bf_data.last_cqm_event = 0; |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 1265 | ret = iwl_mvm_update_beacon_filter(mvm, vif, false, CMD_SYNC); |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 1266 | if (ret) |
| 1267 | IWL_ERR(mvm, "failed to update CQM thresholds\n"); |
| 1268 | } |
Eliad Peller | 2ee8f02 | 2014-01-13 19:07:09 +0200 | [diff] [blame] | 1269 | |
| 1270 | if (changes & BSS_CHANGED_ARP_FILTER) { |
| 1271 | IWL_DEBUG_MAC80211(mvm, "arp filter changed"); |
| 1272 | iwl_mvm_configure_bcast_filter(mvm, vif); |
| 1273 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1274 | } |
| 1275 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1276 | static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, |
| 1277 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1278 | { |
| 1279 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1280 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1281 | int ret; |
| 1282 | |
| 1283 | mutex_lock(&mvm->mutex); |
| 1284 | |
| 1285 | /* Send the beacon template */ |
| 1286 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); |
| 1287 | if (ret) |
| 1288 | goto out_unlock; |
| 1289 | |
Ilan Peer | 6e97b0d | 2013-12-23 22:18:02 +0200 | [diff] [blame] | 1290 | /* |
| 1291 | * Re-calculate the tsf id, as the master-slave relations depend on the |
| 1292 | * beacon interval, which was not known when the AP interface was added. |
| 1293 | */ |
| 1294 | if (vif->type == NL80211_IFTYPE_AP) |
| 1295 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
| 1296 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1297 | /* Add the mac context */ |
| 1298 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 1299 | if (ret) |
| 1300 | goto out_unlock; |
| 1301 | |
| 1302 | /* Perform the binding */ |
| 1303 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1304 | if (ret) |
| 1305 | goto out_remove; |
| 1306 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1307 | mvmvif->ap_ibss_active = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1308 | |
| 1309 | /* Send the bcast station. At this stage the TBTT and DTIM time events |
| 1310 | * are added and applied to the scheduler */ |
| 1311 | ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 1312 | if (ret) |
| 1313 | goto out_unbind; |
| 1314 | |
Ilan Peer | 5691e21 | 2013-12-31 21:05:50 +0200 | [diff] [blame] | 1315 | /* must be set before quota calculations */ |
| 1316 | mvmvif->ap_ibss_active = true; |
| 1317 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1318 | /* power updated needs to be done before quotas */ |
| 1319 | mvm->bound_vif_cnt++; |
| 1320 | iwl_mvm_power_update_binding(mvm, vif, true); |
| 1321 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1322 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 1323 | if (ret) |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1324 | goto out_quota_failed; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1325 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1326 | /* 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] | 1327 | if (vif->p2p && mvm->p2p_device_vif) |
| 1328 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); |
| 1329 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 1330 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 1331 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1332 | mutex_unlock(&mvm->mutex); |
| 1333 | return 0; |
| 1334 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1335 | out_quota_failed: |
| 1336 | mvm->bound_vif_cnt--; |
| 1337 | iwl_mvm_power_update_binding(mvm, vif, false); |
Ilan Peer | 5691e21 | 2013-12-31 21:05:50 +0200 | [diff] [blame] | 1338 | mvmvif->ap_ibss_active = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1339 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 1340 | out_unbind: |
| 1341 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 1342 | out_remove: |
| 1343 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 1344 | out_unlock: |
| 1345 | mutex_unlock(&mvm->mutex); |
| 1346 | return ret; |
| 1347 | } |
| 1348 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1349 | static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, |
| 1350 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1351 | { |
| 1352 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1353 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1354 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 1355 | iwl_mvm_prepare_mac_removal(mvm, vif); |
| 1356 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1357 | mutex_lock(&mvm->mutex); |
| 1358 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1359 | mvmvif->ap_ibss_active = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1360 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 1361 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 1362 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1363 | /* 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] | 1364 | if (vif->p2p && mvm->p2p_device_vif) |
| 1365 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); |
| 1366 | |
| 1367 | iwl_mvm_update_quotas(mvm, NULL); |
| 1368 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 1369 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 1370 | |
| 1371 | mvm->bound_vif_cnt--; |
| 1372 | iwl_mvm_power_update_binding(mvm, vif, false); |
| 1373 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1374 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 1375 | |
| 1376 | mutex_unlock(&mvm->mutex); |
| 1377 | } |
| 1378 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1379 | static void |
| 1380 | iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, |
| 1381 | struct ieee80211_vif *vif, |
| 1382 | struct ieee80211_bss_conf *bss_conf, |
| 1383 | u32 changes) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1384 | { |
Ilan Peer | be2056f | 2013-12-04 16:47:14 +0200 | [diff] [blame] | 1385 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 1386 | enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT | |
| 1387 | BSS_CHANGED_HT | |
| 1388 | BSS_CHANGED_BANDWIDTH; |
| 1389 | int ret; |
| 1390 | |
Ilan Peer | be2056f | 2013-12-04 16:47:14 +0200 | [diff] [blame] | 1391 | /* Changes will be applied when the AP/IBSS is started */ |
| 1392 | if (!mvmvif->ap_ibss_active) |
| 1393 | return; |
| 1394 | |
Avri Altman | 8a5e366 | 2013-11-12 19:16:03 +0200 | [diff] [blame] | 1395 | if (changes & ht_change) { |
| 1396 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 1397 | if (ret) |
| 1398 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
| 1399 | } |
| 1400 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1401 | /* Need to send a new beacon template to the FW */ |
| 1402 | if (changes & BSS_CHANGED_BEACON) { |
| 1403 | if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) |
| 1404 | IWL_WARN(mvm, "Failed updating beacon data\n"); |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, |
| 1409 | struct ieee80211_vif *vif, |
| 1410 | struct ieee80211_bss_conf *bss_conf, |
| 1411 | u32 changes) |
| 1412 | { |
| 1413 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1414 | |
| 1415 | mutex_lock(&mvm->mutex); |
| 1416 | |
| 1417 | switch (vif->type) { |
| 1418 | case NL80211_IFTYPE_STATION: |
| 1419 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); |
| 1420 | break; |
| 1421 | case NL80211_IFTYPE_AP: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1422 | case NL80211_IFTYPE_ADHOC: |
| 1423 | iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1424 | break; |
| 1425 | default: |
| 1426 | /* shouldn't happen */ |
| 1427 | WARN_ON_ONCE(1); |
| 1428 | } |
| 1429 | |
| 1430 | mutex_unlock(&mvm->mutex); |
| 1431 | } |
| 1432 | |
| 1433 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, |
| 1434 | struct ieee80211_vif *vif, |
| 1435 | struct cfg80211_scan_request *req) |
| 1436 | { |
| 1437 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1438 | int ret; |
| 1439 | |
| 1440 | if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS) |
| 1441 | return -EINVAL; |
| 1442 | |
| 1443 | mutex_lock(&mvm->mutex); |
| 1444 | |
| 1445 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) |
| 1446 | ret = iwl_mvm_scan_request(mvm, vif, req); |
| 1447 | else |
| 1448 | ret = -EBUSY; |
| 1449 | |
| 1450 | mutex_unlock(&mvm->mutex); |
| 1451 | |
| 1452 | return ret; |
| 1453 | } |
| 1454 | |
| 1455 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, |
| 1456 | struct ieee80211_vif *vif) |
| 1457 | { |
| 1458 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1459 | |
| 1460 | mutex_lock(&mvm->mutex); |
| 1461 | |
| 1462 | iwl_mvm_cancel_scan(mvm); |
| 1463 | |
| 1464 | mutex_unlock(&mvm->mutex); |
| 1465 | } |
| 1466 | |
| 1467 | static void |
| 1468 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1469 | struct ieee80211_sta *sta, u16 tids, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1470 | int num_frames, |
| 1471 | enum ieee80211_frame_release_type reason, |
| 1472 | bool more_data) |
| 1473 | { |
| 1474 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1475 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1476 | /* Called when we need to transmit (a) frame(s) from mac80211 */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1477 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1478 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
| 1479 | tids, more_data, false); |
| 1480 | } |
| 1481 | |
| 1482 | static void |
| 1483 | iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, |
| 1484 | struct ieee80211_sta *sta, u16 tids, |
| 1485 | int num_frames, |
| 1486 | enum ieee80211_frame_release_type reason, |
| 1487 | bool more_data) |
| 1488 | { |
| 1489 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1490 | |
| 1491 | /* Called when we need to transmit (a) frame(s) from agg queue */ |
| 1492 | |
| 1493 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
| 1494 | tids, more_data, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
| 1498 | struct ieee80211_vif *vif, |
| 1499 | enum sta_notify_cmd cmd, |
| 1500 | struct ieee80211_sta *sta) |
| 1501 | { |
| 1502 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1503 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1504 | int tid; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1505 | |
| 1506 | switch (cmd) { |
| 1507 | case STA_NOTIFY_SLEEP: |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1508 | if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1509 | ieee80211_sta_block_awake(hw, sta, true); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1510 | spin_lock_bh(&mvmsta->lock); |
| 1511 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { |
| 1512 | struct iwl_mvm_tid_data *tid_data; |
| 1513 | |
| 1514 | tid_data = &mvmsta->tid_data[tid]; |
| 1515 | if (tid_data->state != IWL_AGG_ON && |
| 1516 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 1517 | continue; |
| 1518 | if (iwl_mvm_tid_queued(tid_data) == 0) |
| 1519 | continue; |
| 1520 | ieee80211_sta_set_buffered(sta, tid, true); |
| 1521 | } |
| 1522 | spin_unlock_bh(&mvmsta->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1523 | /* |
| 1524 | * The fw updates the STA to be asleep. Tx packets on the Tx |
| 1525 | * queues to this station will not be transmitted. The fw will |
| 1526 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. |
| 1527 | */ |
| 1528 | break; |
| 1529 | case STA_NOTIFY_AWAKE: |
Emmanuel Grumbach | 881acd8 | 2013-03-19 16:16:00 +0200 | [diff] [blame] | 1530 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1531 | break; |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1532 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1533 | break; |
| 1534 | default: |
| 1535 | break; |
| 1536 | } |
| 1537 | } |
| 1538 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 1539 | static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
| 1540 | struct ieee80211_vif *vif, |
| 1541 | struct ieee80211_sta *sta) |
| 1542 | { |
| 1543 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1544 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; |
| 1545 | |
| 1546 | /* |
| 1547 | * This is called before mac80211 does RCU synchronisation, |
| 1548 | * so here we already invalidate our internal RCU-protected |
| 1549 | * station pointer. The rest of the code will thus no longer |
| 1550 | * be able to find the station this way, and we don't rely |
| 1551 | * on further RCU synchronisation after the sta_state() |
| 1552 | * callback deleted the station. |
| 1553 | */ |
| 1554 | mutex_lock(&mvm->mutex); |
| 1555 | if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) |
| 1556 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 1557 | ERR_PTR(-ENOENT)); |
| 1558 | mutex_unlock(&mvm->mutex); |
| 1559 | } |
| 1560 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1561 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
| 1562 | struct ieee80211_vif *vif, |
| 1563 | struct ieee80211_sta *sta, |
| 1564 | enum ieee80211_sta_state old_state, |
| 1565 | enum ieee80211_sta_state new_state) |
| 1566 | { |
| 1567 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1568 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1569 | int ret; |
| 1570 | |
| 1571 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", |
| 1572 | sta->addr, old_state, new_state); |
| 1573 | |
| 1574 | /* this would be a mac80211 bug ... but don't crash */ |
| 1575 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) |
| 1576 | return -EINVAL; |
| 1577 | |
| 1578 | /* if a STA is being removed, reuse its ID */ |
| 1579 | flush_work(&mvm->sta_drained_wk); |
| 1580 | |
| 1581 | mutex_lock(&mvm->mutex); |
| 1582 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 1583 | new_state == IEEE80211_STA_NONE) { |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 1584 | /* |
| 1585 | * Firmware bug - it'll crash if the beacon interval is less |
| 1586 | * than 16. We can't avoid connecting at all, so refuse the |
| 1587 | * station state change, this will cause mac80211 to abandon |
| 1588 | * attempts to connect to this AP, and eventually wpa_s will |
| 1589 | * blacklist the AP... |
| 1590 | */ |
| 1591 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1592 | vif->bss_conf.beacon_int < 16) { |
| 1593 | IWL_ERR(mvm, |
| 1594 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", |
| 1595 | sta->addr, vif->bss_conf.beacon_int); |
| 1596 | ret = -EINVAL; |
| 1597 | goto out_unlock; |
| 1598 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1599 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
| 1600 | } else if (old_state == IEEE80211_STA_NONE && |
| 1601 | new_state == IEEE80211_STA_AUTH) { |
| 1602 | ret = 0; |
| 1603 | } else if (old_state == IEEE80211_STA_AUTH && |
| 1604 | new_state == IEEE80211_STA_ASSOC) { |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 1605 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
| 1606 | if (ret == 0) |
| 1607 | iwl_mvm_rs_rate_init(mvm, sta, |
Eyal Shapira | b87c217 | 2013-11-09 23:37:55 +0200 | [diff] [blame] | 1608 | mvmvif->phy_ctxt->channel->band, |
| 1609 | true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1610 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 1611 | new_state == IEEE80211_STA_AUTHORIZED) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1612 | /* enable beacon filtering */ |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 1613 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, CMD_SYNC)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1614 | ret = 0; |
| 1615 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
| 1616 | new_state == IEEE80211_STA_ASSOC) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1617 | /* disable beacon filtering */ |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 1618 | WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1619 | ret = 0; |
| 1620 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 1621 | new_state == IEEE80211_STA_AUTH) { |
| 1622 | ret = 0; |
| 1623 | } else if (old_state == IEEE80211_STA_AUTH && |
| 1624 | new_state == IEEE80211_STA_NONE) { |
| 1625 | ret = 0; |
| 1626 | } else if (old_state == IEEE80211_STA_NONE && |
| 1627 | new_state == IEEE80211_STA_NOTEXIST) { |
| 1628 | ret = iwl_mvm_rm_sta(mvm, vif, sta); |
| 1629 | } else { |
| 1630 | ret = -EIO; |
| 1631 | } |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 1632 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1633 | mutex_unlock(&mvm->mutex); |
| 1634 | |
| 1635 | return ret; |
| 1636 | } |
| 1637 | |
| 1638 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 1639 | { |
| 1640 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1641 | |
| 1642 | mvm->rts_threshold = value; |
| 1643 | |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1647 | static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, |
| 1648 | struct ieee80211_vif *vif, |
| 1649 | struct ieee80211_sta *sta, u32 changed) |
| 1650 | { |
| 1651 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1652 | |
| 1653 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1654 | changed & IEEE80211_RC_NSS_CHANGED) |
| 1655 | iwl_mvm_sf_update(mvm, vif, false); |
| 1656 | } |
| 1657 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1658 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
| 1659 | struct ieee80211_vif *vif, u16 ac, |
| 1660 | const struct ieee80211_tx_queue_params *params) |
| 1661 | { |
| 1662 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1663 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1664 | |
| 1665 | mvmvif->queue_params[ac] = *params; |
| 1666 | |
| 1667 | /* |
| 1668 | * No need to update right away, we'll get BSS_CHANGED_QOS |
| 1669 | * The exception is P2P_DEVICE interface which needs immediate update. |
| 1670 | */ |
| 1671 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 1672 | int ret; |
| 1673 | |
| 1674 | mutex_lock(&mvm->mutex); |
| 1675 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 1676 | mutex_unlock(&mvm->mutex); |
| 1677 | return ret; |
| 1678 | } |
| 1679 | return 0; |
| 1680 | } |
| 1681 | |
| 1682 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, |
| 1683 | struct ieee80211_vif *vif) |
| 1684 | { |
| 1685 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1686 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, |
| 1687 | 200 + vif->bss_conf.beacon_int); |
| 1688 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, |
| 1689 | 100 + vif->bss_conf.beacon_int); |
| 1690 | |
| 1691 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) |
| 1692 | return; |
| 1693 | |
| 1694 | mutex_lock(&mvm->mutex); |
| 1695 | /* Try really hard to protect the session and hear a beacon */ |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 1696 | iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1697 | mutex_unlock(&mvm->mutex); |
| 1698 | } |
| 1699 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1700 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
| 1701 | struct ieee80211_vif *vif, |
| 1702 | struct cfg80211_sched_scan_request *req, |
| 1703 | struct ieee80211_sched_scan_ies *ies) |
| 1704 | { |
| 1705 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1706 | int ret; |
| 1707 | |
| 1708 | mutex_lock(&mvm->mutex); |
| 1709 | |
| 1710 | if (mvm->scan_status != IWL_MVM_SCAN_NONE) { |
| 1711 | IWL_DEBUG_SCAN(mvm, |
| 1712 | "SCHED SCAN request during internal scan - abort\n"); |
| 1713 | ret = -EBUSY; |
| 1714 | goto out; |
| 1715 | } |
| 1716 | |
| 1717 | mvm->scan_status = IWL_MVM_SCAN_SCHED; |
| 1718 | |
| 1719 | ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies); |
| 1720 | if (ret) |
| 1721 | goto err; |
| 1722 | |
| 1723 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1724 | if (ret) |
| 1725 | goto err; |
| 1726 | |
| 1727 | ret = iwl_mvm_sched_scan_start(mvm, req); |
| 1728 | if (!ret) |
| 1729 | goto out; |
| 1730 | err: |
| 1731 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1732 | out: |
| 1733 | mutex_unlock(&mvm->mutex); |
| 1734 | return ret; |
| 1735 | } |
| 1736 | |
| 1737 | static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, |
| 1738 | struct ieee80211_vif *vif) |
| 1739 | { |
| 1740 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1741 | |
| 1742 | mutex_lock(&mvm->mutex); |
| 1743 | iwl_mvm_sched_scan_stop(mvm); |
| 1744 | mutex_unlock(&mvm->mutex); |
| 1745 | } |
| 1746 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1747 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
| 1748 | enum set_key_cmd cmd, |
| 1749 | struct ieee80211_vif *vif, |
| 1750 | struct ieee80211_sta *sta, |
| 1751 | struct ieee80211_key_conf *key) |
| 1752 | { |
| 1753 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1754 | int ret; |
| 1755 | |
| 1756 | if (iwlwifi_mod_params.sw_crypto) { |
| 1757 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); |
| 1758 | return -EOPNOTSUPP; |
| 1759 | } |
| 1760 | |
| 1761 | switch (key->cipher) { |
| 1762 | case WLAN_CIPHER_SUITE_TKIP: |
| 1763 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 1764 | /* fall-through */ |
| 1765 | case WLAN_CIPHER_SUITE_CCMP: |
| 1766 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1767 | break; |
| 1768 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1769 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); |
| 1770 | break; |
| 1771 | case WLAN_CIPHER_SUITE_WEP40: |
| 1772 | case WLAN_CIPHER_SUITE_WEP104: |
| 1773 | /* |
| 1774 | * Support for TX only, at least for now, so accept |
| 1775 | * the key and do nothing else. Then mac80211 will |
| 1776 | * pass it for TX but we don't have to use it for RX. |
| 1777 | */ |
| 1778 | return 0; |
| 1779 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 1780 | /* currently FW supports only one optional cipher scheme */ |
| 1781 | if (hw->n_cipher_schemes && |
| 1782 | hw->cipher_schemes->cipher == key->cipher) |
| 1783 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
| 1784 | else |
| 1785 | return -EOPNOTSUPP; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | mutex_lock(&mvm->mutex); |
| 1789 | |
| 1790 | switch (cmd) { |
| 1791 | case SET_KEY: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1792 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
| 1793 | vif->type == NL80211_IFTYPE_AP) && !sta) { |
| 1794 | /* |
| 1795 | * GTK on AP interface is a TX-only key, return 0; |
| 1796 | * on IBSS they're per-station and because we're lazy |
| 1797 | * we don't support them for RX, so do the same. |
| 1798 | */ |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1799 | ret = 0; |
| 1800 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
| 1801 | break; |
| 1802 | } |
| 1803 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1804 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
| 1805 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); |
| 1806 | if (ret) { |
| 1807 | IWL_WARN(mvm, "set key failed\n"); |
| 1808 | /* |
| 1809 | * can't add key for RX, but we don't need it |
| 1810 | * in the device for TX so still return 0 |
| 1811 | */ |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1812 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1813 | ret = 0; |
| 1814 | } |
| 1815 | |
| 1816 | break; |
| 1817 | case DISABLE_KEY: |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1818 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
| 1819 | ret = 0; |
| 1820 | break; |
| 1821 | } |
| 1822 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1823 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
| 1824 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); |
| 1825 | break; |
| 1826 | default: |
| 1827 | ret = -EINVAL; |
| 1828 | } |
| 1829 | |
| 1830 | mutex_unlock(&mvm->mutex); |
| 1831 | return ret; |
| 1832 | } |
| 1833 | |
| 1834 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 1835 | struct ieee80211_vif *vif, |
| 1836 | struct ieee80211_key_conf *keyconf, |
| 1837 | struct ieee80211_sta *sta, |
| 1838 | u32 iv32, u16 *phase1key) |
| 1839 | { |
| 1840 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1841 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1842 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) |
| 1843 | return; |
| 1844 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1845 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
| 1846 | } |
| 1847 | |
| 1848 | |
| 1849 | static int iwl_mvm_roc(struct ieee80211_hw *hw, |
| 1850 | struct ieee80211_vif *vif, |
| 1851 | struct ieee80211_channel *channel, |
Ilan Peer | d339d5c | 2013-02-12 09:34:13 +0200 | [diff] [blame] | 1852 | int duration, |
| 1853 | enum ieee80211_roc_type type) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1854 | { |
| 1855 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1856 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1857 | struct cfg80211_chan_def chandef; |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1858 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
| 1859 | int ret, i; |
| 1860 | |
| 1861 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, |
| 1862 | duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1863 | |
| 1864 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) { |
| 1865 | IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type); |
| 1866 | return -EINVAL; |
| 1867 | } |
| 1868 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1869 | mutex_lock(&mvm->mutex); |
| 1870 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1871 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 1872 | phy_ctxt = &mvm->phy_ctxts[i]; |
| 1873 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) |
| 1874 | continue; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1875 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1876 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { |
| 1877 | /* |
| 1878 | * Unbind the P2P_DEVICE from the current PHY context, |
| 1879 | * and if the PHY context is not used remove it. |
| 1880 | */ |
| 1881 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 1882 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 1883 | goto out_unlock; |
| 1884 | |
| 1885 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 1886 | |
| 1887 | /* Bind the P2P_DEVICE to the current PHY Context */ |
| 1888 | mvmvif->phy_ctxt = phy_ctxt; |
| 1889 | |
| 1890 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1891 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 1892 | goto out_unlock; |
| 1893 | |
| 1894 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 1895 | goto schedule_time_event; |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | /* Need to update the PHY context only if the ROC channel changed */ |
| 1900 | if (channel == mvmvif->phy_ctxt->channel) |
| 1901 | goto schedule_time_event; |
| 1902 | |
| 1903 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
| 1904 | |
| 1905 | /* |
| 1906 | * Change the PHY context configuration as it is currently referenced |
| 1907 | * only by the P2P Device MAC |
| 1908 | */ |
| 1909 | if (mvmvif->phy_ctxt->ref == 1) { |
| 1910 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, |
| 1911 | &chandef, 1, 1); |
| 1912 | if (ret) |
| 1913 | goto out_unlock; |
| 1914 | } else { |
| 1915 | /* |
| 1916 | * The PHY context is shared with other MACs. Need to remove the |
| 1917 | * P2P Device from the binding, allocate an new PHY context and |
| 1918 | * create a new binding |
| 1919 | */ |
| 1920 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 1921 | if (!phy_ctxt) { |
| 1922 | ret = -ENOSPC; |
| 1923 | goto out_unlock; |
| 1924 | } |
| 1925 | |
| 1926 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, |
| 1927 | 1, 1); |
| 1928 | if (ret) { |
| 1929 | IWL_ERR(mvm, "Failed to change PHY context\n"); |
| 1930 | goto out_unlock; |
| 1931 | } |
| 1932 | |
| 1933 | /* Unbind the P2P_DEVICE from the current PHY context */ |
| 1934 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 1935 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 1936 | goto out_unlock; |
| 1937 | |
| 1938 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 1939 | |
| 1940 | /* Bind the P2P_DEVICE to the new allocated PHY context */ |
| 1941 | mvmvif->phy_ctxt = phy_ctxt; |
| 1942 | |
| 1943 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1944 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 1945 | goto out_unlock; |
| 1946 | |
| 1947 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 1948 | } |
| 1949 | |
| 1950 | schedule_time_event: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1951 | /* Schedule the time events */ |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 1952 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1953 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1954 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1955 | mutex_unlock(&mvm->mutex); |
| 1956 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1957 | return ret; |
| 1958 | } |
| 1959 | |
| 1960 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) |
| 1961 | { |
| 1962 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1963 | |
| 1964 | IWL_DEBUG_MAC80211(mvm, "enter\n"); |
| 1965 | |
| 1966 | mutex_lock(&mvm->mutex); |
| 1967 | iwl_mvm_stop_p2p_roc(mvm); |
| 1968 | mutex_unlock(&mvm->mutex); |
| 1969 | |
| 1970 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
| 1974 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, |
| 1975 | struct ieee80211_chanctx_conf *ctx) |
| 1976 | { |
| 1977 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1978 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 1979 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1980 | int ret; |
| 1981 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1982 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1983 | |
| 1984 | mutex_lock(&mvm->mutex); |
| 1985 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 1986 | if (!phy_ctxt) { |
| 1987 | ret = -ENOSPC; |
| 1988 | goto out; |
| 1989 | } |
| 1990 | |
Eliad Peller | dcbc3e1 | 2013-10-31 14:31:25 +0200 | [diff] [blame] | 1991 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1992 | ctx->rx_chains_static, |
| 1993 | ctx->rx_chains_dynamic); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1994 | if (ret) { |
| 1995 | IWL_ERR(mvm, "Failed to add PHY context\n"); |
| 1996 | goto out; |
| 1997 | } |
| 1998 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1999 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2000 | *phy_ctxt_id = phy_ctxt->id; |
| 2001 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2002 | mutex_unlock(&mvm->mutex); |
| 2003 | return ret; |
| 2004 | } |
| 2005 | |
| 2006 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, |
| 2007 | struct ieee80211_chanctx_conf *ctx) |
| 2008 | { |
| 2009 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2010 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 2011 | 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] | 2012 | |
| 2013 | mutex_lock(&mvm->mutex); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2014 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2015 | mutex_unlock(&mvm->mutex); |
| 2016 | } |
| 2017 | |
| 2018 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, |
| 2019 | struct ieee80211_chanctx_conf *ctx, |
| 2020 | u32 changed) |
| 2021 | { |
| 2022 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2023 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 2024 | 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] | 2025 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2026 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
| 2027 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | |
| 2028 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | |
Arik Nemtsov | 2dceeda | 2013-12-29 17:57:53 +0200 | [diff] [blame] | 2029 | IEEE80211_CHANCTX_CHANGE_RADAR | |
| 2030 | IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 2031 | "Cannot change PHY. Ref=%d, changed=0x%X\n", |
| 2032 | phy_ctxt->ref, changed)) |
| 2033 | return; |
| 2034 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2035 | mutex_lock(&mvm->mutex); |
Eliad Peller | dcbc3e1 | 2013-10-31 14:31:25 +0200 | [diff] [blame] | 2036 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2037 | ctx->rx_chains_static, |
| 2038 | ctx->rx_chains_dynamic); |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 2039 | iwl_mvm_bt_coex_vif_change(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2040 | mutex_unlock(&mvm->mutex); |
| 2041 | } |
| 2042 | |
| 2043 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 2044 | struct ieee80211_vif *vif, |
| 2045 | struct ieee80211_chanctx_conf *ctx) |
| 2046 | { |
| 2047 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2048 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 2049 | 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] | 2050 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2051 | int ret; |
| 2052 | |
| 2053 | mutex_lock(&mvm->mutex); |
| 2054 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 2055 | mvmvif->phy_ctxt = phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2056 | |
| 2057 | switch (vif->type) { |
| 2058 | case NL80211_IFTYPE_AP: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2059 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2060 | /* |
| 2061 | * 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] | 2062 | * (in bss_info_changed), similarly for IBSS. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2063 | */ |
| 2064 | ret = 0; |
| 2065 | goto out_unlock; |
| 2066 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2067 | case NL80211_IFTYPE_MONITOR: |
| 2068 | break; |
| 2069 | default: |
| 2070 | ret = -EINVAL; |
| 2071 | goto out_unlock; |
| 2072 | } |
| 2073 | |
| 2074 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 2075 | if (ret) |
| 2076 | goto out_unlock; |
| 2077 | |
| 2078 | /* |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 2079 | * Power state must be updated before quotas, |
| 2080 | * otherwise fw will complain. |
| 2081 | */ |
| 2082 | mvm->bound_vif_cnt++; |
| 2083 | iwl_mvm_power_update_binding(mvm, vif, true); |
| 2084 | |
| 2085 | /* Setting the quota at this stage is only required for monitor |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2086 | * interfaces. For the other types, the bss_info changed flow |
| 2087 | * will handle quota settings. |
| 2088 | */ |
| 2089 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 2090 | mvmvif->monitor_active = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2091 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 2092 | if (ret) |
| 2093 | goto out_remove_binding; |
| 2094 | } |
| 2095 | |
| 2096 | goto out_unlock; |
| 2097 | |
| 2098 | out_remove_binding: |
| 2099 | iwl_mvm_binding_remove_vif(mvm, vif); |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 2100 | mvm->bound_vif_cnt--; |
| 2101 | iwl_mvm_power_update_binding(mvm, vif, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2102 | out_unlock: |
| 2103 | mutex_unlock(&mvm->mutex); |
| 2104 | if (ret) |
| 2105 | mvmvif->phy_ctxt = NULL; |
| 2106 | return ret; |
| 2107 | } |
| 2108 | |
| 2109 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 2110 | struct ieee80211_vif *vif, |
| 2111 | struct ieee80211_chanctx_conf *ctx) |
| 2112 | { |
| 2113 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2114 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2115 | |
| 2116 | mutex_lock(&mvm->mutex); |
| 2117 | |
| 2118 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); |
| 2119 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2120 | switch (vif->type) { |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2121 | case NL80211_IFTYPE_AP: |
| 2122 | case NL80211_IFTYPE_ADHOC: |
| 2123 | goto out_unlock; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2124 | case NL80211_IFTYPE_MONITOR: |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 2125 | mvmvif->monitor_active = false; |
| 2126 | iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2127 | break; |
| 2128 | default: |
| 2129 | break; |
| 2130 | } |
| 2131 | |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 2132 | iwl_mvm_binding_remove_vif(mvm, vif); |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 2133 | mvm->bound_vif_cnt--; |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 2134 | iwl_mvm_power_update_binding(mvm, vif, false); |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 2135 | |
Ilan Peer | a11e144 | 2013-12-31 21:19:55 +0200 | [diff] [blame] | 2136 | out_unlock: |
| 2137 | mvmvif->phy_ctxt = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2138 | mutex_unlock(&mvm->mutex); |
| 2139 | } |
| 2140 | |
| 2141 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, |
| 2142 | struct ieee80211_sta *sta, |
| 2143 | bool set) |
| 2144 | { |
| 2145 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2146 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; |
| 2147 | |
| 2148 | if (!mvm_sta || !mvm_sta->vif) { |
| 2149 | IWL_ERR(mvm, "Station is not associated to a vif\n"); |
| 2150 | return -EINVAL; |
| 2151 | } |
| 2152 | |
| 2153 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); |
| 2154 | } |
| 2155 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2156 | #ifdef CONFIG_NL80211_TESTMODE |
| 2157 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { |
| 2158 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, |
| 2159 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, |
Johannes Berg | f6c6ad4 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 2160 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2161 | }; |
| 2162 | |
| 2163 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, |
| 2164 | struct ieee80211_vif *vif, |
| 2165 | void *data, int len) |
| 2166 | { |
| 2167 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; |
| 2168 | int err; |
| 2169 | u32 noa_duration; |
| 2170 | |
| 2171 | err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy); |
| 2172 | if (err) |
| 2173 | return err; |
| 2174 | |
| 2175 | if (!tb[IWL_MVM_TM_ATTR_CMD]) |
| 2176 | return -EINVAL; |
| 2177 | |
| 2178 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { |
| 2179 | case IWL_MVM_TM_CMD_SET_NOA: |
| 2180 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || |
| 2181 | !vif->bss_conf.enable_beacon || |
| 2182 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) |
| 2183 | return -EINVAL; |
| 2184 | |
| 2185 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); |
| 2186 | if (noa_duration >= vif->bss_conf.beacon_int) |
| 2187 | return -EINVAL; |
| 2188 | |
| 2189 | mvm->noa_duration = noa_duration; |
| 2190 | mvm->noa_vif = vif; |
| 2191 | |
| 2192 | return iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | f6c6ad4 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 2193 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
| 2194 | /* must be associated client vif - ignore authorized */ |
| 2195 | if (!vif || vif->type != NL80211_IFTYPE_STATION || |
| 2196 | !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || |
| 2197 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) |
| 2198 | return -EINVAL; |
| 2199 | |
| 2200 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 2201 | return iwl_mvm_enable_beacon_filter(mvm, vif, |
| 2202 | CMD_SYNC); |
| 2203 | return iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC); |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | return -EOPNOTSUPP; |
| 2207 | } |
| 2208 | |
| 2209 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, |
| 2210 | struct ieee80211_vif *vif, |
| 2211 | void *data, int len) |
| 2212 | { |
| 2213 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2214 | int err; |
| 2215 | |
| 2216 | mutex_lock(&mvm->mutex); |
| 2217 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); |
| 2218 | mutex_unlock(&mvm->mutex); |
| 2219 | |
| 2220 | return err; |
| 2221 | } |
| 2222 | #endif |
| 2223 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2224 | struct ieee80211_ops iwl_mvm_hw_ops = { |
| 2225 | .tx = iwl_mvm_mac_tx, |
| 2226 | .ampdu_action = iwl_mvm_mac_ampdu_action, |
| 2227 | .start = iwl_mvm_mac_start, |
| 2228 | .restart_complete = iwl_mvm_mac_restart_complete, |
| 2229 | .stop = iwl_mvm_mac_stop, |
| 2230 | .add_interface = iwl_mvm_mac_add_interface, |
| 2231 | .remove_interface = iwl_mvm_mac_remove_interface, |
| 2232 | .config = iwl_mvm_mac_config, |
Eliad Peller | e59647e | 2013-11-28 14:08:50 +0200 | [diff] [blame] | 2233 | .prepare_multicast = iwl_mvm_prepare_multicast, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2234 | .configure_filter = iwl_mvm_configure_filter, |
| 2235 | .bss_info_changed = iwl_mvm_bss_info_changed, |
| 2236 | .hw_scan = iwl_mvm_mac_hw_scan, |
| 2237 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 2238 | .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2239 | .sta_state = iwl_mvm_mac_sta_state, |
| 2240 | .sta_notify = iwl_mvm_mac_sta_notify, |
| 2241 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2242 | .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2243 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 2244 | .sta_rc_update = iwl_mvm_sta_rc_update, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2245 | .conf_tx = iwl_mvm_mac_conf_tx, |
| 2246 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 2247 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
| 2248 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2249 | .set_key = iwl_mvm_mac_set_key, |
| 2250 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, |
| 2251 | .remain_on_channel = iwl_mvm_roc, |
| 2252 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2253 | .add_chanctx = iwl_mvm_add_chanctx, |
| 2254 | .remove_chanctx = iwl_mvm_remove_chanctx, |
| 2255 | .change_chanctx = iwl_mvm_change_chanctx, |
| 2256 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, |
| 2257 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, |
| 2258 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 2259 | .start_ap = iwl_mvm_start_ap_ibss, |
| 2260 | .stop_ap = iwl_mvm_stop_ap_ibss, |
| 2261 | .join_ibss = iwl_mvm_start_ap_ibss, |
| 2262 | .leave_ibss = iwl_mvm_stop_ap_ibss, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2263 | |
| 2264 | .set_tim = iwl_mvm_set_tim, |
| 2265 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 2266 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
| 2267 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2268 | #ifdef CONFIG_PM_SLEEP |
| 2269 | /* look at d3.c */ |
| 2270 | .suspend = iwl_mvm_suspend, |
| 2271 | .resume = iwl_mvm_resume, |
| 2272 | .set_wakeup = iwl_mvm_set_wakeup, |
| 2273 | .set_rekey_data = iwl_mvm_set_rekey_data, |
| 2274 | #if IS_ENABLED(CONFIG_IPV6) |
| 2275 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, |
| 2276 | #endif |
| 2277 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, |
| 2278 | #endif |
| 2279 | }; |