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 | * |
| 8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 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 | * |
| 33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 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> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 69 | #include <net/mac80211.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 70 | #include <net/tcp.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 71 | |
| 72 | #include "iwl-op-mode.h" |
| 73 | #include "iwl-io.h" |
| 74 | #include "mvm.h" |
| 75 | #include "sta.h" |
| 76 | #include "time-event.h" |
| 77 | #include "iwl-eeprom-parse.h" |
| 78 | #include "fw-api-scan.h" |
| 79 | #include "iwl-phy-db.h" |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 80 | #include "testmode.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 81 | |
| 82 | static const struct ieee80211_iface_limit iwl_mvm_limits[] = { |
| 83 | { |
| 84 | .max = 1, |
Ilan Peer | 8eb3871 | 2013-06-01 20:17:18 +0300 | [diff] [blame] | 85 | .types = BIT(NL80211_IFTYPE_STATION), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 86 | }, |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 87 | { |
| 88 | .max = 1, |
Ilan Peer | 8eb3871 | 2013-06-01 20:17:18 +0300 | [diff] [blame] | 89 | .types = BIT(NL80211_IFTYPE_AP) | |
| 90 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 91 | BIT(NL80211_IFTYPE_P2P_GO), |
| 92 | }, |
| 93 | { |
| 94 | .max = 1, |
| 95 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 96 | }, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { |
| 100 | { |
| 101 | .num_different_channels = 1, |
| 102 | .max_interfaces = 3, |
| 103 | .limits = iwl_mvm_limits, |
| 104 | .n_limits = ARRAY_SIZE(iwl_mvm_limits), |
| 105 | }, |
| 106 | }; |
| 107 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 108 | #ifdef CONFIG_PM_SLEEP |
| 109 | static const struct nl80211_wowlan_tcp_data_token_feature |
| 110 | iwl_mvm_wowlan_tcp_token_feature = { |
| 111 | .min_len = 0, |
| 112 | .max_len = 255, |
| 113 | .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS, |
| 114 | }; |
| 115 | |
| 116 | static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = { |
| 117 | .tok = &iwl_mvm_wowlan_tcp_token_feature, |
| 118 | .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN - |
| 119 | sizeof(struct ethhdr) - |
| 120 | sizeof(struct iphdr) - |
| 121 | sizeof(struct tcphdr), |
| 122 | .data_interval_max = 65535, /* __le16 in API */ |
| 123 | .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN - |
| 124 | sizeof(struct ethhdr) - |
| 125 | sizeof(struct iphdr) - |
| 126 | sizeof(struct tcphdr), |
| 127 | .seq = true, |
| 128 | }; |
| 129 | #endif |
| 130 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 131 | static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) |
| 132 | { |
| 133 | int i; |
| 134 | |
| 135 | memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); |
| 136 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 137 | mvm->phy_ctxts[i].id = i; |
| 138 | mvm->phy_ctxts[i].ref = 0; |
| 139 | } |
| 140 | } |
| 141 | |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 142 | static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm) |
| 143 | { |
| 144 | /* we create the 802.11 header and SSID element */ |
| 145 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID) |
| 146 | return mvm->fw->ucode_capa.max_probe_length - 24 - 2; |
| 147 | return mvm->fw->ucode_capa.max_probe_length - 24 - 34; |
| 148 | } |
| 149 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 150 | int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) |
| 151 | { |
| 152 | struct ieee80211_hw *hw = mvm->hw; |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 153 | int num_mac, ret, i; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 154 | |
| 155 | /* Tell mac80211 our characteristics */ |
| 156 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 157 | IEEE80211_HW_SPECTRUM_MGMT | |
| 158 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 159 | IEEE80211_HW_QUEUE_CONTROL | |
| 160 | IEEE80211_HW_WANT_MONITOR_VIF | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 161 | IEEE80211_HW_SUPPORTS_PS | |
| 162 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Johannes Berg | d2931bb | 2013-02-05 18:10:04 +0100 | [diff] [blame] | 163 | IEEE80211_HW_AMPDU_AGGREGATION | |
Hila Gonen | d64048e | 2013-03-13 18:00:03 +0200 | [diff] [blame] | 164 | IEEE80211_HW_TIMING_BEACON_ONLY | |
Emmanuel Grumbach | 147fc9b | 2013-07-28 11:00:52 +0300 | [diff] [blame] | 165 | IEEE80211_HW_CONNECTION_MONITOR | |
| 166 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | |
Alexander Bondar | e3c588e | 2013-04-07 14:08:59 +0300 | [diff] [blame] | 167 | IEEE80211_HW_SUPPORTS_STATIC_SMPS | |
| 168 | IEEE80211_HW_SUPPORTS_UAPSD; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 169 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 170 | hw->queues = mvm->first_agg_queue; |
Ilan Peer | 398e8c6 | 2013-03-13 15:20:35 +0200 | [diff] [blame] | 171 | hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 172 | hw->rate_control_algorithm = "iwl-mvm-rs"; |
| 173 | |
| 174 | /* |
| 175 | * Enable 11w if advertised by firmware and software crypto |
| 176 | * is not enabled (as the firmware will interpret some mgmt |
| 177 | * packets, so enabling it with software crypto isn't safe) |
| 178 | */ |
| 179 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP && |
| 180 | !iwlwifi_mod_params.sw_crypto) |
| 181 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; |
| 182 | |
| 183 | hw->sta_data_size = sizeof(struct iwl_mvm_sta); |
| 184 | hw->vif_data_size = sizeof(struct iwl_mvm_vif); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 185 | hw->chanctx_data_size = sizeof(u16); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 186 | |
| 187 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
Johannes Berg | 3c15a0f | 2013-05-31 10:17:19 +0200 | [diff] [blame] | 188 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 189 | BIT(NL80211_IFTYPE_AP) | |
| 190 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 191 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 192 | |
| 193 | hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | |
| 194 | WIPHY_FLAG_DISABLE_BEACON_HINTS | |
| 195 | WIPHY_FLAG_IBSS_RSN; |
| 196 | |
| 197 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; |
| 198 | hw->wiphy->n_iface_combinations = |
| 199 | ARRAY_SIZE(iwl_mvm_iface_combinations); |
| 200 | |
Ilan Peer | c451e6d | 2013-02-20 08:41:54 +0200 | [diff] [blame] | 201 | hw->wiphy->max_remain_on_channel_duration = 10000; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 202 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
Alexander Bondar | e3c588e | 2013-04-07 14:08:59 +0300 | [diff] [blame] | 203 | hw->uapsd_queues = IWL_UAPSD_AC_INFO; |
| 204 | hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 205 | |
| 206 | /* Extract MAC address */ |
| 207 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); |
| 208 | hw->wiphy->addresses = mvm->addresses; |
| 209 | hw->wiphy->n_addresses = 1; |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 210 | |
| 211 | /* Extract additional MAC addresses if available */ |
| 212 | num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? |
| 213 | min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; |
| 214 | |
| 215 | for (i = 1; i < num_mac; i++) { |
| 216 | memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 217 | ETH_ALEN); |
Ilan Peer | 831e85f | 2013-02-07 17:09:09 +0200 | [diff] [blame] | 218 | mvm->addresses[i].addr[5]++; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 219 | hw->wiphy->n_addresses++; |
| 220 | } |
| 221 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 222 | iwl_mvm_reset_phy_ctxts(mvm); |
| 223 | |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 224 | hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); |
| 225 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 226 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
| 227 | |
| 228 | if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 229 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 230 | &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; |
| 231 | if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 232 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 233 | &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; |
| 234 | |
| 235 | hw->wiphy->hw_version = mvm->trans->hw_id; |
| 236 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 237 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 238 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 239 | else |
| 240 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 241 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 242 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) { |
| 243 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 244 | hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; |
| 245 | hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; |
| 246 | /* we create the 802.11 header and zero length SSID IE. */ |
| 247 | hw->wiphy->max_sched_scan_ie_len = |
| 248 | SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; |
| 249 | } |
| 250 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 251 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
| 252 | NL80211_FEATURE_P2P_GO_OPPPS; |
| 253 | |
| 254 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 255 | |
| 256 | #ifdef CONFIG_PM_SLEEP |
| 257 | if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len && |
| 258 | mvm->trans->ops->d3_suspend && |
| 259 | mvm->trans->ops->d3_resume && |
| 260 | device_can_wakeup(mvm->trans->dev)) { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 261 | mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | |
| 262 | WIPHY_WOWLAN_DISCONNECT | |
| 263 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | |
| 264 | WIPHY_WOWLAN_RFKILL_RELEASE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 265 | if (!iwlwifi_mod_params.sw_crypto) |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 266 | mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
| 267 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | |
| 268 | WIPHY_WOWLAN_4WAY_HANDSHAKE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 269 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 270 | mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; |
| 271 | mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; |
| 272 | mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; |
| 273 | mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support; |
| 274 | hw->wiphy->wowlan = &mvm->wowlan; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 275 | } |
| 276 | #endif |
| 277 | |
| 278 | ret = iwl_mvm_leds_init(mvm); |
| 279 | if (ret) |
| 280 | return ret; |
| 281 | |
Emmanuel Grumbach | b7327d8 | 2013-06-24 15:44:03 +0300 | [diff] [blame] | 282 | ret = ieee80211_register_hw(mvm->hw); |
| 283 | if (ret) |
| 284 | iwl_mvm_leds_exit(mvm); |
| 285 | |
| 286 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, |
| 290 | struct ieee80211_tx_control *control, |
| 291 | struct sk_buff *skb) |
| 292 | { |
| 293 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 294 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 295 | if (iwl_mvm_is_radio_killed(mvm)) { |
| 296 | IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 297 | goto drop; |
| 298 | } |
| 299 | |
Ilan Peer | 398e8c6 | 2013-03-13 15:20:35 +0200 | [diff] [blame] | 300 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 301 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status)) |
| 302 | goto drop; |
| 303 | |
| 304 | if (control->sta) { |
| 305 | if (iwl_mvm_tx_skb(mvm, skb, control->sta)) |
| 306 | goto drop; |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | if (iwl_mvm_tx_skb_non_sta(mvm, skb)) |
| 311 | goto drop; |
| 312 | return; |
| 313 | drop: |
| 314 | ieee80211_free_txskb(hw, skb); |
| 315 | } |
| 316 | |
| 317 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, |
| 318 | struct ieee80211_vif *vif, |
| 319 | enum ieee80211_ampdu_mlme_action action, |
| 320 | struct ieee80211_sta *sta, u16 tid, |
| 321 | u16 *ssn, u8 buf_size) |
| 322 | { |
| 323 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 324 | int ret; |
| 325 | |
| 326 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", |
| 327 | sta->addr, tid, action); |
| 328 | |
| 329 | if (!(mvm->nvm_data->sku_cap_11n_enable)) |
| 330 | return -EACCES; |
| 331 | |
| 332 | mutex_lock(&mvm->mutex); |
| 333 | |
| 334 | switch (action) { |
| 335 | case IEEE80211_AMPDU_RX_START: |
| 336 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) { |
| 337 | ret = -EINVAL; |
| 338 | break; |
| 339 | } |
| 340 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true); |
| 341 | break; |
| 342 | case IEEE80211_AMPDU_RX_STOP: |
| 343 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false); |
| 344 | break; |
| 345 | case IEEE80211_AMPDU_TX_START: |
Emmanuel Grumbach | 5d158ef | 2013-02-19 14:39:58 +0200 | [diff] [blame] | 346 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) { |
| 347 | ret = -EINVAL; |
| 348 | break; |
| 349 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 350 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
| 351 | break; |
| 352 | case IEEE80211_AMPDU_TX_STOP_CONT: |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 353 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
| 354 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 355 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 356 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 357 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 358 | break; |
| 359 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 360 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size); |
| 361 | break; |
| 362 | default: |
| 363 | WARN_ON_ONCE(1); |
| 364 | ret = -EINVAL; |
| 365 | break; |
| 366 | } |
| 367 | mutex_unlock(&mvm->mutex); |
| 368 | |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, |
| 373 | struct ieee80211_vif *vif) |
| 374 | { |
| 375 | struct iwl_mvm *mvm = data; |
| 376 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 377 | |
| 378 | mvmvif->uploaded = false; |
| 379 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 380 | |
| 381 | /* does this make sense at all? */ |
| 382 | mvmvif->color++; |
| 383 | |
| 384 | spin_lock_bh(&mvm->time_event_lock); |
| 385 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); |
| 386 | spin_unlock_bh(&mvm->time_event_lock); |
| 387 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 388 | mvmvif->phy_ctxt = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) |
| 392 | { |
| 393 | iwl_trans_stop_device(mvm->trans); |
| 394 | iwl_trans_stop_hw(mvm->trans, false); |
| 395 | |
| 396 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 397 | |
| 398 | /* just in case one was running */ |
| 399 | ieee80211_remain_on_channel_expired(mvm->hw); |
| 400 | |
| 401 | ieee80211_iterate_active_interfaces_atomic( |
| 402 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 403 | iwl_mvm_cleanup_iterator, mvm); |
| 404 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 405 | mvm->p2p_device_vif = NULL; |
| 406 | |
| 407 | iwl_mvm_reset_phy_ctxts(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 408 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 409 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); |
| 410 | |
| 411 | ieee80211_wake_queues(mvm->hw); |
| 412 | |
| 413 | mvm->vif_count = 0; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 414 | mvm->rx_ba_sessions = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) |
| 418 | { |
| 419 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 420 | int ret; |
| 421 | |
| 422 | mutex_lock(&mvm->mutex); |
| 423 | |
| 424 | /* Clean up some internal and mac80211 state on restart */ |
| 425 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 426 | iwl_mvm_restart_cleanup(mvm); |
| 427 | |
| 428 | ret = iwl_mvm_up(mvm); |
| 429 | mutex_unlock(&mvm->mutex); |
| 430 | |
| 431 | return ret; |
| 432 | } |
| 433 | |
| 434 | static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) |
| 435 | { |
| 436 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 437 | int ret; |
| 438 | |
| 439 | mutex_lock(&mvm->mutex); |
| 440 | |
| 441 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 442 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 443 | if (ret) |
| 444 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", |
| 445 | ret); |
| 446 | |
| 447 | mutex_unlock(&mvm->mutex); |
| 448 | } |
| 449 | |
| 450 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) |
| 451 | { |
| 452 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 453 | |
| 454 | flush_work(&mvm->async_handlers_wk); |
| 455 | |
| 456 | mutex_lock(&mvm->mutex); |
| 457 | /* async_handlers_wk is now blocked */ |
| 458 | |
| 459 | /* |
| 460 | * The work item could be running or queued if the |
| 461 | * ROC time event stops just as we get here. |
| 462 | */ |
| 463 | cancel_work_sync(&mvm->roc_done_wk); |
| 464 | |
| 465 | iwl_trans_stop_device(mvm->trans); |
| 466 | iwl_trans_stop_hw(mvm->trans, false); |
| 467 | |
| 468 | iwl_mvm_async_handlers_purge(mvm); |
| 469 | /* async_handlers_list is empty and will stay empty: HW is stopped */ |
| 470 | |
| 471 | /* the fw is stopped, the aux sta is dead: clean up driver state */ |
| 472 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 473 | |
| 474 | mutex_unlock(&mvm->mutex); |
| 475 | |
| 476 | /* |
| 477 | * The worker might have been waiting for the mutex, let it run and |
| 478 | * discover that its list is now empty. |
| 479 | */ |
| 480 | cancel_work_sync(&mvm->async_handlers_wk); |
| 481 | } |
| 482 | |
| 483 | static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac, |
| 484 | struct ieee80211_vif *vif) |
| 485 | { |
| 486 | struct iwl_mvm *mvm = data; |
| 487 | int ret; |
| 488 | |
| 489 | ret = iwl_mvm_power_disable(mvm, vif); |
| 490 | if (ret) |
| 491 | IWL_ERR(mvm, "failed to disable power management\n"); |
| 492 | } |
| 493 | |
| 494 | static void iwl_mvm_power_update_iterator(void *data, u8 *mac, |
| 495 | struct ieee80211_vif *vif) |
| 496 | { |
| 497 | struct iwl_mvm *mvm = data; |
| 498 | |
| 499 | iwl_mvm_power_update_mode(mvm, vif); |
| 500 | } |
| 501 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 502 | static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
| 503 | { |
| 504 | u16 i; |
| 505 | |
| 506 | lockdep_assert_held(&mvm->mutex); |
| 507 | |
| 508 | for (i = 0; i < NUM_PHY_CTX; i++) |
| 509 | if (!mvm->phy_ctxts[i].ref) |
| 510 | return &mvm->phy_ctxts[i]; |
| 511 | |
| 512 | IWL_ERR(mvm, "No available PHY context\n"); |
| 513 | return NULL; |
| 514 | } |
| 515 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 516 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
| 517 | struct ieee80211_vif *vif) |
| 518 | { |
| 519 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 520 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 521 | int ret; |
| 522 | |
| 523 | /* |
| 524 | * Not much to do here. The stack will not allow interface |
| 525 | * types or combinations that we didn't advertise, so we |
| 526 | * don't really have to check the types. |
| 527 | */ |
| 528 | |
| 529 | mutex_lock(&mvm->mutex); |
| 530 | |
Eliad Peller | e89044d | 2013-07-16 17:33:26 +0300 | [diff] [blame] | 531 | /* Allocate resources for the MAC context, and add it to the fw */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 532 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
| 533 | if (ret) |
| 534 | goto out_unlock; |
| 535 | |
| 536 | /* |
Ilan Peer | ea183d0 | 2013-07-23 14:41:53 +0300 | [diff] [blame] | 537 | * TODO: remove this temporary code. |
| 538 | * Currently MVM FW supports power management only on single MAC. |
| 539 | * If new interface added, disable PM on existing interface. |
| 540 | * P2P device is a special case, since it is handled by FW similary to |
| 541 | * scan. If P2P deviced is added, PM remains enabled on existing |
| 542 | * interface. |
| 543 | * Note: the method below does not count the new interface being added |
| 544 | * at this moment. |
| 545 | */ |
| 546 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 547 | mvm->vif_count++; |
| 548 | if (mvm->vif_count > 1) { |
| 549 | IWL_DEBUG_MAC80211(mvm, |
| 550 | "Disable power on existing interfaces\n"); |
| 551 | ieee80211_iterate_active_interfaces_atomic( |
| 552 | mvm->hw, |
| 553 | IEEE80211_IFACE_ITER_NORMAL, |
| 554 | iwl_mvm_pm_disable_iterator, mvm); |
| 555 | } |
| 556 | |
| 557 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 558 | * The AP binding flow can be done only after the beacon |
| 559 | * template is configured (which happens only in the mac80211 |
| 560 | * start_ap() flow), and adding the broadcast station can happen |
| 561 | * only after the binding. |
| 562 | * In addition, since modifying the MAC before adding a bcast |
| 563 | * station is not allowed by the FW, delay the adding of MAC context to |
| 564 | * the point where we can also add the bcast station. |
| 565 | * In short: there's not much we can do at this point, other than |
| 566 | * allocating resources :) |
| 567 | */ |
| 568 | if (vif->type == NL80211_IFTYPE_AP) { |
| 569 | u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); |
| 570 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, |
| 571 | qmask); |
| 572 | if (ret) { |
| 573 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); |
| 574 | goto out_release; |
| 575 | } |
| 576 | |
Emmanuel Grumbach | 77740cb | 2013-06-26 23:51:41 +0300 | [diff] [blame] | 577 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 578 | goto out_unlock; |
| 579 | } |
| 580 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 581 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 582 | if (ret) |
| 583 | goto out_release; |
| 584 | |
| 585 | /* |
| 586 | * Update power state on the new interface. Admittedly, based on |
| 587 | * mac80211 logics this power update will disable power management |
| 588 | */ |
| 589 | iwl_mvm_power_update_mode(mvm, vif); |
| 590 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 591 | /* beacon filtering */ |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 592 | ret = iwl_mvm_disable_beacon_filter(mvm, vif); |
| 593 | if (ret) |
| 594 | goto out_remove_mac; |
| 595 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 596 | if (!mvm->bf_allowed_vif && |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 597 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p && |
| 598 | mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){ |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 599 | mvm->bf_allowed_vif = mvmvif; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 600 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 601 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 602 | } |
| 603 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 604 | /* |
| 605 | * P2P_DEVICE interface does not have a channel context assigned to it, |
| 606 | * so a dedicated PHY context is allocated to it and the corresponding |
| 607 | * MAC context is bound to it at this stage. |
| 608 | */ |
| 609 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 610 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 611 | mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 612 | if (!mvmvif->phy_ctxt) { |
| 613 | ret = -ENOSPC; |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 614 | goto out_free_bf; |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 615 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 616 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 617 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 618 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 619 | if (ret) |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 620 | goto out_unref_phy; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 621 | |
| 622 | ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 623 | if (ret) |
| 624 | goto out_unbind; |
| 625 | |
| 626 | /* Save a pointer to p2p device vif, so it can later be used to |
| 627 | * update the p2p device MAC when a GO is started/stopped */ |
| 628 | mvm->p2p_device_vif = vif; |
| 629 | } |
| 630 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 631 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 632 | goto out_unlock; |
| 633 | |
| 634 | out_unbind: |
| 635 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 636 | out_unref_phy: |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 637 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 638 | out_free_bf: |
| 639 | if (mvm->bf_allowed_vif == mvmvif) { |
| 640 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 641 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 642 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Eliad Peller | bd3351b | 2013-07-16 17:50:17 +0300 | [diff] [blame] | 643 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 644 | out_remove_mac: |
| 645 | mvmvif->phy_ctxt = NULL; |
| 646 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 647 | out_release: |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 648 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 649 | mvm->vif_count--; |
Alexander Bondar | 4bf881f | 2013-05-29 10:19:50 +0300 | [diff] [blame] | 650 | ieee80211_iterate_active_interfaces( |
| 651 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 652 | iwl_mvm_power_update_iterator, mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 653 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 654 | out_unlock: |
| 655 | mutex_unlock(&mvm->mutex); |
| 656 | |
| 657 | return ret; |
| 658 | } |
| 659 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 660 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
| 661 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 662 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 663 | u32 tfd_msk = 0, ac; |
| 664 | |
| 665 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 666 | if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE) |
| 667 | tfd_msk |= BIT(vif->hw_queue[ac]); |
| 668 | |
| 669 | if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE) |
| 670 | tfd_msk |= BIT(vif->cab_queue); |
| 671 | |
| 672 | if (tfd_msk) { |
| 673 | mutex_lock(&mvm->mutex); |
| 674 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); |
| 675 | mutex_unlock(&mvm->mutex); |
| 676 | } |
| 677 | |
| 678 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 679 | /* |
| 680 | * Flush the ROC worker which will flush the OFFCHANNEL queue. |
| 681 | * We assume here that all the packets sent to the OFFCHANNEL |
| 682 | * queue are sent in ROC session. |
| 683 | */ |
| 684 | flush_work(&mvm->roc_done_wk); |
| 685 | } else { |
| 686 | /* |
| 687 | * By now, all the AC queues are empty. The AGG queues are |
| 688 | * empty too. We already got all the Tx responses for all the |
| 689 | * packets in the queues. The drain work can have been |
Emmanuel Grumbach | 0742a75 | 2013-06-10 14:10:33 +0300 | [diff] [blame] | 690 | * triggered. Flush it. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 691 | */ |
| 692 | flush_work(&mvm->sta_drained_wk); |
| 693 | } |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, |
| 697 | struct ieee80211_vif *vif) |
| 698 | { |
| 699 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 700 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 701 | |
| 702 | iwl_mvm_prepare_mac_removal(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 703 | |
| 704 | mutex_lock(&mvm->mutex); |
| 705 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 706 | if (mvm->bf_allowed_vif == mvmvif) { |
| 707 | mvm->bf_allowed_vif = NULL; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 708 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
| 709 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 710 | } |
| 711 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 712 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
| 713 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 714 | /* |
| 715 | * 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] | 716 | * interface is be handled as part of the stop_ap flow. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 717 | */ |
| 718 | if (vif->type == NL80211_IFTYPE_AP) { |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 719 | #ifdef CONFIG_NL80211_TESTMODE |
| 720 | if (vif == mvm->noa_vif) { |
| 721 | mvm->noa_vif = NULL; |
| 722 | mvm->noa_duration = 0; |
| 723 | } |
| 724 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 725 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 726 | goto out_release; |
| 727 | } |
| 728 | |
| 729 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 730 | mvm->p2p_device_vif = NULL; |
| 731 | iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 732 | iwl_mvm_binding_remove_vif(mvm, vif); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 733 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 734 | mvmvif->phy_ctxt = NULL; |
| 735 | } |
| 736 | |
| 737 | /* |
| 738 | * TODO: remove this temporary code. |
| 739 | * Currently MVM FW supports power management only on single MAC. |
| 740 | * Check if only one additional interface remains after removing |
| 741 | * current one. Update power mode on the remaining interface. |
| 742 | */ |
Alexander Bondar | 5ee2b21 | 2013-03-05 10:16:40 +0200 | [diff] [blame] | 743 | if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 744 | mvm->vif_count--; |
| 745 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", |
| 746 | mvm->vif_count); |
| 747 | if (mvm->vif_count == 1) { |
| 748 | ieee80211_iterate_active_interfaces( |
| 749 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 750 | iwl_mvm_power_update_iterator, mvm); |
| 751 | } |
| 752 | |
| 753 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 754 | |
| 755 | out_release: |
| 756 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 757 | mutex_unlock(&mvm->mutex); |
| 758 | } |
| 759 | |
Matti Gottlieb | 88f2fd7 | 2013-07-09 15:25:46 +0300 | [diff] [blame] | 760 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 761 | s8 tx_power) |
| 762 | { |
| 763 | /* FW is in charge of regulatory enforcement */ |
| 764 | struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = { |
| 765 | .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id, |
| 766 | .pwr_restriction = cpu_to_le16(tx_power), |
| 767 | }; |
| 768 | |
| 769 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC, |
| 770 | sizeof(reduce_txpwr_cmd), |
| 771 | &reduce_txpwr_cmd); |
| 772 | } |
| 773 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 774 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 775 | { |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, |
| 780 | unsigned int changed_flags, |
| 781 | unsigned int *total_flags, |
| 782 | u64 multicast) |
| 783 | { |
| 784 | *total_flags = 0; |
| 785 | } |
| 786 | |
Emmanuel Grumbach | 51b6b9e | 2013-05-02 15:01:24 +0300 | [diff] [blame] | 787 | static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm, |
| 788 | struct ieee80211_vif *vif) |
| 789 | { |
| 790 | struct iwl_mcast_filter_cmd mcast_filter_cmd = { |
| 791 | .pass_all = 1, |
| 792 | }; |
| 793 | |
| 794 | memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN); |
| 795 | |
| 796 | return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, |
| 797 | sizeof(mcast_filter_cmd), |
| 798 | &mcast_filter_cmd); |
| 799 | } |
| 800 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 801 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
| 802 | struct ieee80211_vif *vif, |
| 803 | struct ieee80211_bss_conf *bss_conf, |
| 804 | u32 changes) |
| 805 | { |
| 806 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 807 | int ret; |
| 808 | |
| 809 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 810 | if (ret) |
| 811 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
| 812 | |
| 813 | if (changes & BSS_CHANGED_ASSOC) { |
| 814 | if (bss_conf->assoc) { |
| 815 | /* add quota for this interface */ |
| 816 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 817 | if (ret) { |
| 818 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 819 | return; |
| 820 | } |
Emmanuel Grumbach | 51b6b9e | 2013-05-02 15:01:24 +0300 | [diff] [blame] | 821 | iwl_mvm_configure_mcast_filter(mvm, vif); |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 822 | |
| 823 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, |
| 824 | &mvm->status)) { |
| 825 | /* |
| 826 | * If we're restarting then the firmware will |
| 827 | * obviously have lost synchronisation with |
| 828 | * the AP. It will attempt to synchronise by |
| 829 | * itself, but we can make it more reliable by |
| 830 | * scheduling a session protection time event. |
| 831 | * |
| 832 | * The firmware needs to receive a beacon to |
| 833 | * catch up with synchronisation, use 110% of |
| 834 | * the beacon interval. |
| 835 | * |
| 836 | * Set a large maximum delay to allow for more |
| 837 | * than a single interface. |
| 838 | */ |
| 839 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; |
| 840 | iwl_mvm_protect_session(mvm, vif, dur, dur, |
| 841 | 5 * dur); |
| 842 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 843 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 844 | /* remove AP station now that the MAC is unassoc */ |
| 845 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); |
| 846 | if (ret) |
| 847 | IWL_ERR(mvm, "failed to remove AP station\n"); |
| 848 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 849 | /* remove quota for this interface */ |
| 850 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 851 | if (ret) |
| 852 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 853 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 854 | |
| 855 | /* reset rssi values */ |
| 856 | mvmvif->bf_data.ave_beacon_signal = 0; |
| 857 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 858 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD)) { |
| 859 | /* Workaround for FW bug, otherwise FW disables device |
| 860 | * power save upon disassociation |
| 861 | */ |
| 862 | ret = iwl_mvm_power_update_mode(mvm, vif); |
| 863 | if (ret) |
| 864 | IWL_ERR(mvm, "failed to update power mode\n"); |
| 865 | } |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame^] | 866 | iwl_mvm_bt_coex_vif_change(mvm); |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 867 | } else if (changes & BSS_CHANGED_BEACON_INFO) { |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 868 | /* |
| 869 | * We received a beacon _after_ association so |
| 870 | * remove the session protection. |
| 871 | */ |
| 872 | iwl_mvm_remove_time_event(mvm, mvmvif, |
| 873 | &mvmvif->time_event_data); |
Alexander Bondar | e3c588e | 2013-04-07 14:08:59 +0300 | [diff] [blame] | 874 | } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) { |
Alexander Bondar | 4bf881f | 2013-05-29 10:19:50 +0300 | [diff] [blame] | 875 | ret = iwl_mvm_power_update_mode(mvm, vif); |
| 876 | if (ret) |
| 877 | IWL_ERR(mvm, "failed to update power mode\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 878 | } |
Matti Gottlieb | 88f2fd7 | 2013-07-09 15:25:46 +0300 | [diff] [blame] | 879 | if (changes & BSS_CHANGED_TXPOWER) { |
| 880 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", |
| 881 | bss_conf->txpower); |
| 882 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); |
| 883 | } |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 884 | |
| 885 | if (changes & BSS_CHANGED_CQM) { |
| 886 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed"); |
| 887 | /* reset cqm events tracking */ |
| 888 | mvmvif->bf_data.last_cqm_event = 0; |
| 889 | ret = iwl_mvm_update_beacon_filter(mvm, vif); |
| 890 | if (ret) |
| 891 | IWL_ERR(mvm, "failed to update CQM thresholds\n"); |
| 892 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 896 | { |
| 897 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 898 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 899 | int ret; |
| 900 | |
| 901 | mutex_lock(&mvm->mutex); |
| 902 | |
| 903 | /* Send the beacon template */ |
| 904 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); |
| 905 | if (ret) |
| 906 | goto out_unlock; |
| 907 | |
| 908 | /* Add the mac context */ |
| 909 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 910 | if (ret) |
| 911 | goto out_unlock; |
| 912 | |
| 913 | /* Perform the binding */ |
| 914 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 915 | if (ret) |
| 916 | goto out_remove; |
| 917 | |
| 918 | mvmvif->ap_active = true; |
| 919 | |
| 920 | /* Send the bcast station. At this stage the TBTT and DTIM time events |
| 921 | * are added and applied to the scheduler */ |
| 922 | ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 923 | if (ret) |
| 924 | goto out_unbind; |
| 925 | |
| 926 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 927 | if (ret) |
| 928 | goto out_rm_bcast; |
| 929 | |
| 930 | /* Need to update the P2P Device MAC */ |
| 931 | if (vif->p2p && mvm->p2p_device_vif) |
| 932 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); |
| 933 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame^] | 934 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 935 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 936 | mutex_unlock(&mvm->mutex); |
| 937 | return 0; |
| 938 | |
| 939 | out_rm_bcast: |
| 940 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 941 | out_unbind: |
| 942 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 943 | out_remove: |
| 944 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 945 | out_unlock: |
| 946 | mutex_unlock(&mvm->mutex); |
| 947 | return ret; |
| 948 | } |
| 949 | |
| 950 | static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 951 | { |
| 952 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 953 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 954 | |
Johannes Berg | 38a12b5 | 2013-02-22 14:07:56 +0100 | [diff] [blame] | 955 | iwl_mvm_prepare_mac_removal(mvm, vif); |
| 956 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 957 | mutex_lock(&mvm->mutex); |
| 958 | |
| 959 | mvmvif->ap_active = false; |
| 960 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame^] | 961 | iwl_mvm_bt_coex_vif_change(mvm); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 962 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 963 | /* Need to update the P2P Device MAC */ |
| 964 | if (vif->p2p && mvm->p2p_device_vif) |
| 965 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); |
| 966 | |
| 967 | iwl_mvm_update_quotas(mvm, NULL); |
| 968 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 969 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 970 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 971 | |
| 972 | mutex_unlock(&mvm->mutex); |
| 973 | } |
| 974 | |
| 975 | static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm, |
| 976 | struct ieee80211_vif *vif, |
| 977 | struct ieee80211_bss_conf *bss_conf, |
| 978 | u32 changes) |
| 979 | { |
| 980 | /* Need to send a new beacon template to the FW */ |
| 981 | if (changes & BSS_CHANGED_BEACON) { |
| 982 | if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) |
| 983 | IWL_WARN(mvm, "Failed updating beacon data\n"); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, |
| 988 | struct ieee80211_vif *vif, |
| 989 | struct ieee80211_bss_conf *bss_conf, |
| 990 | u32 changes) |
| 991 | { |
| 992 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 993 | |
| 994 | mutex_lock(&mvm->mutex); |
| 995 | |
| 996 | switch (vif->type) { |
| 997 | case NL80211_IFTYPE_STATION: |
| 998 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); |
| 999 | break; |
| 1000 | case NL80211_IFTYPE_AP: |
| 1001 | iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes); |
| 1002 | break; |
| 1003 | default: |
| 1004 | /* shouldn't happen */ |
| 1005 | WARN_ON_ONCE(1); |
| 1006 | } |
| 1007 | |
| 1008 | mutex_unlock(&mvm->mutex); |
| 1009 | } |
| 1010 | |
| 1011 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, |
| 1012 | struct ieee80211_vif *vif, |
| 1013 | struct cfg80211_scan_request *req) |
| 1014 | { |
| 1015 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1016 | int ret; |
| 1017 | |
| 1018 | if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS) |
| 1019 | return -EINVAL; |
| 1020 | |
| 1021 | mutex_lock(&mvm->mutex); |
| 1022 | |
| 1023 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) |
| 1024 | ret = iwl_mvm_scan_request(mvm, vif, req); |
| 1025 | else |
| 1026 | ret = -EBUSY; |
| 1027 | |
| 1028 | mutex_unlock(&mvm->mutex); |
| 1029 | |
| 1030 | return ret; |
| 1031 | } |
| 1032 | |
| 1033 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, |
| 1034 | struct ieee80211_vif *vif) |
| 1035 | { |
| 1036 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1037 | |
| 1038 | mutex_lock(&mvm->mutex); |
| 1039 | |
| 1040 | iwl_mvm_cancel_scan(mvm); |
| 1041 | |
| 1042 | mutex_unlock(&mvm->mutex); |
| 1043 | } |
| 1044 | |
| 1045 | static void |
| 1046 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, |
| 1047 | struct ieee80211_sta *sta, u16 tid, |
| 1048 | int num_frames, |
| 1049 | enum ieee80211_frame_release_type reason, |
| 1050 | bool more_data) |
| 1051 | { |
| 1052 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1053 | |
| 1054 | /* TODO: how do we tell the fw to send frames for a specific TID */ |
| 1055 | |
| 1056 | /* |
| 1057 | * The fw will send EOSP notification when the last frame will be |
| 1058 | * transmitted. |
| 1059 | */ |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1060 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
| 1064 | struct ieee80211_vif *vif, |
| 1065 | enum sta_notify_cmd cmd, |
| 1066 | struct ieee80211_sta *sta) |
| 1067 | { |
| 1068 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1069 | struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv; |
| 1070 | |
| 1071 | switch (cmd) { |
| 1072 | case STA_NOTIFY_SLEEP: |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1073 | if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1074 | ieee80211_sta_block_awake(hw, sta, true); |
| 1075 | /* |
| 1076 | * The fw updates the STA to be asleep. Tx packets on the Tx |
| 1077 | * queues to this station will not be transmitted. The fw will |
| 1078 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. |
| 1079 | */ |
| 1080 | break; |
| 1081 | case STA_NOTIFY_AWAKE: |
Emmanuel Grumbach | 881acd8 | 2013-03-19 16:16:00 +0200 | [diff] [blame] | 1082 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1083 | break; |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1084 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1085 | break; |
| 1086 | default: |
| 1087 | break; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
| 1092 | struct ieee80211_vif *vif, |
| 1093 | struct ieee80211_sta *sta, |
| 1094 | enum ieee80211_sta_state old_state, |
| 1095 | enum ieee80211_sta_state new_state) |
| 1096 | { |
| 1097 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1098 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1099 | int ret; |
| 1100 | |
| 1101 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", |
| 1102 | sta->addr, old_state, new_state); |
| 1103 | |
| 1104 | /* this would be a mac80211 bug ... but don't crash */ |
| 1105 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) |
| 1106 | return -EINVAL; |
| 1107 | |
| 1108 | /* if a STA is being removed, reuse its ID */ |
| 1109 | flush_work(&mvm->sta_drained_wk); |
| 1110 | |
| 1111 | mutex_lock(&mvm->mutex); |
| 1112 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 1113 | new_state == IEEE80211_STA_NONE) { |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 1114 | /* |
| 1115 | * Firmware bug - it'll crash if the beacon interval is less |
| 1116 | * than 16. We can't avoid connecting at all, so refuse the |
| 1117 | * station state change, this will cause mac80211 to abandon |
| 1118 | * attempts to connect to this AP, and eventually wpa_s will |
| 1119 | * blacklist the AP... |
| 1120 | */ |
| 1121 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1122 | vif->bss_conf.beacon_int < 16) { |
| 1123 | IWL_ERR(mvm, |
| 1124 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", |
| 1125 | sta->addr, vif->bss_conf.beacon_int); |
| 1126 | ret = -EINVAL; |
| 1127 | goto out_unlock; |
| 1128 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1129 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
| 1130 | } else if (old_state == IEEE80211_STA_NONE && |
| 1131 | new_state == IEEE80211_STA_AUTH) { |
| 1132 | ret = 0; |
| 1133 | } else if (old_state == IEEE80211_STA_AUTH && |
| 1134 | new_state == IEEE80211_STA_ASSOC) { |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 1135 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
| 1136 | if (ret == 0) |
| 1137 | iwl_mvm_rs_rate_init(mvm, sta, |
| 1138 | mvmvif->phy_ctxt->channel->band); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1139 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 1140 | new_state == IEEE80211_STA_AUTHORIZED) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1141 | /* enable beacon filtering */ |
| 1142 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1143 | ret = 0; |
| 1144 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
| 1145 | new_state == IEEE80211_STA_ASSOC) { |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 1146 | /* disable beacon filtering */ |
| 1147 | WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1148 | ret = 0; |
| 1149 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 1150 | new_state == IEEE80211_STA_AUTH) { |
| 1151 | ret = 0; |
| 1152 | } else if (old_state == IEEE80211_STA_AUTH && |
| 1153 | new_state == IEEE80211_STA_NONE) { |
| 1154 | ret = 0; |
| 1155 | } else if (old_state == IEEE80211_STA_NONE && |
| 1156 | new_state == IEEE80211_STA_NOTEXIST) { |
| 1157 | ret = iwl_mvm_rm_sta(mvm, vif, sta); |
| 1158 | } else { |
| 1159 | ret = -EIO; |
| 1160 | } |
Johannes Berg | 48bc130 | 2013-07-04 15:55:29 +0200 | [diff] [blame] | 1161 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1162 | mutex_unlock(&mvm->mutex); |
| 1163 | |
| 1164 | return ret; |
| 1165 | } |
| 1166 | |
| 1167 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 1168 | { |
| 1169 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1170 | |
| 1171 | mvm->rts_threshold = value; |
| 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
| 1177 | struct ieee80211_vif *vif, u16 ac, |
| 1178 | const struct ieee80211_tx_queue_params *params) |
| 1179 | { |
| 1180 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1181 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1182 | |
| 1183 | mvmvif->queue_params[ac] = *params; |
| 1184 | |
| 1185 | /* |
| 1186 | * No need to update right away, we'll get BSS_CHANGED_QOS |
| 1187 | * The exception is P2P_DEVICE interface which needs immediate update. |
| 1188 | */ |
| 1189 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 1190 | int ret; |
| 1191 | |
| 1192 | mutex_lock(&mvm->mutex); |
| 1193 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 1194 | mutex_unlock(&mvm->mutex); |
| 1195 | return ret; |
| 1196 | } |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, |
| 1201 | struct ieee80211_vif *vif) |
| 1202 | { |
| 1203 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1204 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, |
| 1205 | 200 + vif->bss_conf.beacon_int); |
| 1206 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, |
| 1207 | 100 + vif->bss_conf.beacon_int); |
| 1208 | |
| 1209 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) |
| 1210 | return; |
| 1211 | |
| 1212 | mutex_lock(&mvm->mutex); |
| 1213 | /* Try really hard to protect the session and hear a beacon */ |
Johannes Berg | 016d27e | 2013-05-03 11:16:15 +0200 | [diff] [blame] | 1214 | iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1215 | mutex_unlock(&mvm->mutex); |
| 1216 | } |
| 1217 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1218 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
| 1219 | struct ieee80211_vif *vif, |
| 1220 | struct cfg80211_sched_scan_request *req, |
| 1221 | struct ieee80211_sched_scan_ies *ies) |
| 1222 | { |
| 1223 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1224 | int ret; |
| 1225 | |
| 1226 | mutex_lock(&mvm->mutex); |
| 1227 | |
| 1228 | if (mvm->scan_status != IWL_MVM_SCAN_NONE) { |
| 1229 | IWL_DEBUG_SCAN(mvm, |
| 1230 | "SCHED SCAN request during internal scan - abort\n"); |
| 1231 | ret = -EBUSY; |
| 1232 | goto out; |
| 1233 | } |
| 1234 | |
| 1235 | mvm->scan_status = IWL_MVM_SCAN_SCHED; |
| 1236 | |
| 1237 | ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies); |
| 1238 | if (ret) |
| 1239 | goto err; |
| 1240 | |
| 1241 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1242 | if (ret) |
| 1243 | goto err; |
| 1244 | |
| 1245 | ret = iwl_mvm_sched_scan_start(mvm, req); |
| 1246 | if (!ret) |
| 1247 | goto out; |
| 1248 | err: |
| 1249 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1250 | out: |
| 1251 | mutex_unlock(&mvm->mutex); |
| 1252 | return ret; |
| 1253 | } |
| 1254 | |
| 1255 | static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, |
| 1256 | struct ieee80211_vif *vif) |
| 1257 | { |
| 1258 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1259 | |
| 1260 | mutex_lock(&mvm->mutex); |
| 1261 | iwl_mvm_sched_scan_stop(mvm); |
| 1262 | mutex_unlock(&mvm->mutex); |
| 1263 | } |
| 1264 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1265 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
| 1266 | enum set_key_cmd cmd, |
| 1267 | struct ieee80211_vif *vif, |
| 1268 | struct ieee80211_sta *sta, |
| 1269 | struct ieee80211_key_conf *key) |
| 1270 | { |
| 1271 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1272 | int ret; |
| 1273 | |
| 1274 | if (iwlwifi_mod_params.sw_crypto) { |
| 1275 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); |
| 1276 | return -EOPNOTSUPP; |
| 1277 | } |
| 1278 | |
| 1279 | switch (key->cipher) { |
| 1280 | case WLAN_CIPHER_SUITE_TKIP: |
| 1281 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 1282 | /* fall-through */ |
| 1283 | case WLAN_CIPHER_SUITE_CCMP: |
| 1284 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1285 | break; |
| 1286 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1287 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); |
| 1288 | break; |
| 1289 | case WLAN_CIPHER_SUITE_WEP40: |
| 1290 | case WLAN_CIPHER_SUITE_WEP104: |
| 1291 | /* |
| 1292 | * Support for TX only, at least for now, so accept |
| 1293 | * the key and do nothing else. Then mac80211 will |
| 1294 | * pass it for TX but we don't have to use it for RX. |
| 1295 | */ |
| 1296 | return 0; |
| 1297 | default: |
| 1298 | return -EOPNOTSUPP; |
| 1299 | } |
| 1300 | |
| 1301 | mutex_lock(&mvm->mutex); |
| 1302 | |
| 1303 | switch (cmd) { |
| 1304 | case SET_KEY: |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1305 | if (vif->type == NL80211_IFTYPE_AP && !sta) { |
| 1306 | /* GTK on AP interface is a TX-only key, return 0 */ |
| 1307 | ret = 0; |
| 1308 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
| 1309 | break; |
| 1310 | } |
| 1311 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1312 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
| 1313 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); |
| 1314 | if (ret) { |
| 1315 | IWL_WARN(mvm, "set key failed\n"); |
| 1316 | /* |
| 1317 | * can't add key for RX, but we don't need it |
| 1318 | * in the device for TX so still return 0 |
| 1319 | */ |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1320 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1321 | ret = 0; |
| 1322 | } |
| 1323 | |
| 1324 | break; |
| 1325 | case DISABLE_KEY: |
Johannes Berg | 6caffd4 | 2013-03-06 13:15:21 +0100 | [diff] [blame] | 1326 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
| 1327 | ret = 0; |
| 1328 | break; |
| 1329 | } |
| 1330 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1331 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
| 1332 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); |
| 1333 | break; |
| 1334 | default: |
| 1335 | ret = -EINVAL; |
| 1336 | } |
| 1337 | |
| 1338 | mutex_unlock(&mvm->mutex); |
| 1339 | return ret; |
| 1340 | } |
| 1341 | |
| 1342 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 1343 | struct ieee80211_vif *vif, |
| 1344 | struct ieee80211_key_conf *keyconf, |
| 1345 | struct ieee80211_sta *sta, |
| 1346 | u32 iv32, u16 *phase1key) |
| 1347 | { |
| 1348 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1349 | |
| 1350 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | static int iwl_mvm_roc(struct ieee80211_hw *hw, |
| 1355 | struct ieee80211_vif *vif, |
| 1356 | struct ieee80211_channel *channel, |
Ilan Peer | d339d5c | 2013-02-12 09:34:13 +0200 | [diff] [blame] | 1357 | int duration, |
| 1358 | enum ieee80211_roc_type type) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1359 | { |
| 1360 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1361 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1362 | struct cfg80211_chan_def chandef; |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1363 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
| 1364 | int ret, i; |
| 1365 | |
| 1366 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, |
| 1367 | duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1368 | |
| 1369 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) { |
| 1370 | IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type); |
| 1371 | return -EINVAL; |
| 1372 | } |
| 1373 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1374 | mutex_lock(&mvm->mutex); |
| 1375 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1376 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 1377 | phy_ctxt = &mvm->phy_ctxts[i]; |
| 1378 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) |
| 1379 | continue; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1380 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1381 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { |
| 1382 | /* |
| 1383 | * Unbind the P2P_DEVICE from the current PHY context, |
| 1384 | * and if the PHY context is not used remove it. |
| 1385 | */ |
| 1386 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 1387 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 1388 | goto out_unlock; |
| 1389 | |
| 1390 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 1391 | |
| 1392 | /* Bind the P2P_DEVICE to the current PHY Context */ |
| 1393 | mvmvif->phy_ctxt = phy_ctxt; |
| 1394 | |
| 1395 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1396 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 1397 | goto out_unlock; |
| 1398 | |
| 1399 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 1400 | goto schedule_time_event; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | /* Need to update the PHY context only if the ROC channel changed */ |
| 1405 | if (channel == mvmvif->phy_ctxt->channel) |
| 1406 | goto schedule_time_event; |
| 1407 | |
| 1408 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
| 1409 | |
| 1410 | /* |
| 1411 | * Change the PHY context configuration as it is currently referenced |
| 1412 | * only by the P2P Device MAC |
| 1413 | */ |
| 1414 | if (mvmvif->phy_ctxt->ref == 1) { |
| 1415 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, |
| 1416 | &chandef, 1, 1); |
| 1417 | if (ret) |
| 1418 | goto out_unlock; |
| 1419 | } else { |
| 1420 | /* |
| 1421 | * The PHY context is shared with other MACs. Need to remove the |
| 1422 | * P2P Device from the binding, allocate an new PHY context and |
| 1423 | * create a new binding |
| 1424 | */ |
| 1425 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 1426 | if (!phy_ctxt) { |
| 1427 | ret = -ENOSPC; |
| 1428 | goto out_unlock; |
| 1429 | } |
| 1430 | |
| 1431 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, |
| 1432 | 1, 1); |
| 1433 | if (ret) { |
| 1434 | IWL_ERR(mvm, "Failed to change PHY context\n"); |
| 1435 | goto out_unlock; |
| 1436 | } |
| 1437 | |
| 1438 | /* Unbind the P2P_DEVICE from the current PHY context */ |
| 1439 | ret = iwl_mvm_binding_remove_vif(mvm, vif); |
| 1440 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) |
| 1441 | goto out_unlock; |
| 1442 | |
| 1443 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
| 1444 | |
| 1445 | /* Bind the P2P_DEVICE to the new allocated PHY context */ |
| 1446 | mvmvif->phy_ctxt = phy_ctxt; |
| 1447 | |
| 1448 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1449 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) |
| 1450 | goto out_unlock; |
| 1451 | |
| 1452 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
| 1453 | } |
| 1454 | |
| 1455 | schedule_time_event: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1456 | /* Schedule the time events */ |
Ilan Peer | e635c79 | 2013-02-13 11:05:18 +0200 | [diff] [blame] | 1457 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1458 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1459 | out_unlock: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1460 | mutex_unlock(&mvm->mutex); |
| 1461 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1462 | return ret; |
| 1463 | } |
| 1464 | |
| 1465 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) |
| 1466 | { |
| 1467 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1468 | |
| 1469 | IWL_DEBUG_MAC80211(mvm, "enter\n"); |
| 1470 | |
| 1471 | mutex_lock(&mvm->mutex); |
| 1472 | iwl_mvm_stop_p2p_roc(mvm); |
| 1473 | mutex_unlock(&mvm->mutex); |
| 1474 | |
| 1475 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, |
| 1480 | struct ieee80211_chanctx_conf *ctx) |
| 1481 | { |
| 1482 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1483 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 1484 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1485 | int ret; |
| 1486 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1487 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1488 | |
| 1489 | mutex_lock(&mvm->mutex); |
| 1490 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
| 1491 | if (!phy_ctxt) { |
| 1492 | ret = -ENOSPC; |
| 1493 | goto out; |
| 1494 | } |
| 1495 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1496 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def, |
| 1497 | ctx->rx_chains_static, |
| 1498 | ctx->rx_chains_dynamic); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1499 | if (ret) { |
| 1500 | IWL_ERR(mvm, "Failed to add PHY context\n"); |
| 1501 | goto out; |
| 1502 | } |
| 1503 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1504 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1505 | *phy_ctxt_id = phy_ctxt->id; |
| 1506 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1507 | mutex_unlock(&mvm->mutex); |
| 1508 | return ret; |
| 1509 | } |
| 1510 | |
| 1511 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, |
| 1512 | struct ieee80211_chanctx_conf *ctx) |
| 1513 | { |
| 1514 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1515 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 1516 | 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] | 1517 | |
| 1518 | mutex_lock(&mvm->mutex); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1519 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1520 | mutex_unlock(&mvm->mutex); |
| 1521 | } |
| 1522 | |
| 1523 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, |
| 1524 | struct ieee80211_chanctx_conf *ctx, |
| 1525 | u32 changed) |
| 1526 | { |
| 1527 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1528 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 1529 | 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] | 1530 | |
Ilan Peer | 31d385a | 2013-04-02 10:25:46 +0300 | [diff] [blame] | 1531 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
| 1532 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | |
| 1533 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | |
| 1534 | IEEE80211_CHANCTX_CHANGE_RADAR)), |
| 1535 | "Cannot change PHY. Ref=%d, changed=0x%X\n", |
| 1536 | phy_ctxt->ref, changed)) |
| 1537 | return; |
| 1538 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1539 | mutex_lock(&mvm->mutex); |
| 1540 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def, |
| 1541 | ctx->rx_chains_static, |
| 1542 | ctx->rx_chains_dynamic); |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame^] | 1543 | iwl_mvm_bt_coex_vif_change(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1544 | mutex_unlock(&mvm->mutex); |
| 1545 | } |
| 1546 | |
| 1547 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 1548 | struct ieee80211_vif *vif, |
| 1549 | struct ieee80211_chanctx_conf *ctx) |
| 1550 | { |
| 1551 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1552 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
| 1553 | 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] | 1554 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1555 | int ret; |
| 1556 | |
| 1557 | mutex_lock(&mvm->mutex); |
| 1558 | |
Ilan Peer | fe0f2de | 2013-03-21 10:23:52 +0200 | [diff] [blame] | 1559 | mvmvif->phy_ctxt = phy_ctxt; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1560 | |
| 1561 | switch (vif->type) { |
| 1562 | case NL80211_IFTYPE_AP: |
| 1563 | /* |
| 1564 | * The AP binding flow is handled as part of the start_ap flow |
| 1565 | * (in bss_info_changed). |
| 1566 | */ |
| 1567 | ret = 0; |
| 1568 | goto out_unlock; |
| 1569 | case NL80211_IFTYPE_STATION: |
| 1570 | case NL80211_IFTYPE_ADHOC: |
| 1571 | case NL80211_IFTYPE_MONITOR: |
| 1572 | break; |
| 1573 | default: |
| 1574 | ret = -EINVAL; |
| 1575 | goto out_unlock; |
| 1576 | } |
| 1577 | |
| 1578 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1579 | if (ret) |
| 1580 | goto out_unlock; |
| 1581 | |
| 1582 | /* |
| 1583 | * Setting the quota at this stage is only required for monitor |
| 1584 | * interfaces. For the other types, the bss_info changed flow |
| 1585 | * will handle quota settings. |
| 1586 | */ |
| 1587 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 1588 | mvmvif->monitor_active = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1589 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 1590 | if (ret) |
| 1591 | goto out_remove_binding; |
| 1592 | } |
| 1593 | |
| 1594 | goto out_unlock; |
| 1595 | |
| 1596 | out_remove_binding: |
| 1597 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 1598 | out_unlock: |
| 1599 | mutex_unlock(&mvm->mutex); |
| 1600 | if (ret) |
| 1601 | mvmvif->phy_ctxt = NULL; |
| 1602 | return ret; |
| 1603 | } |
| 1604 | |
| 1605 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 1606 | struct ieee80211_vif *vif, |
| 1607 | struct ieee80211_chanctx_conf *ctx) |
| 1608 | { |
| 1609 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1610 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1611 | |
| 1612 | mutex_lock(&mvm->mutex); |
| 1613 | |
| 1614 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); |
| 1615 | |
| 1616 | if (vif->type == NL80211_IFTYPE_AP) |
| 1617 | goto out_unlock; |
| 1618 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1619 | switch (vif->type) { |
| 1620 | case NL80211_IFTYPE_MONITOR: |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 1621 | mvmvif->monitor_active = false; |
| 1622 | iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1623 | break; |
| 1624 | default: |
| 1625 | break; |
| 1626 | } |
| 1627 | |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 1628 | iwl_mvm_binding_remove_vif(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1629 | out_unlock: |
| 1630 | mvmvif->phy_ctxt = NULL; |
| 1631 | mutex_unlock(&mvm->mutex); |
| 1632 | } |
| 1633 | |
| 1634 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, |
| 1635 | struct ieee80211_sta *sta, |
| 1636 | bool set) |
| 1637 | { |
| 1638 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1639 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; |
| 1640 | |
| 1641 | if (!mvm_sta || !mvm_sta->vif) { |
| 1642 | IWL_ERR(mvm, "Station is not associated to a vif\n"); |
| 1643 | return -EINVAL; |
| 1644 | } |
| 1645 | |
| 1646 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); |
| 1647 | } |
| 1648 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 1649 | #ifdef CONFIG_NL80211_TESTMODE |
| 1650 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { |
| 1651 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, |
| 1652 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, |
Johannes Berg | f6c6ad42 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 1653 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 1654 | }; |
| 1655 | |
| 1656 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, |
| 1657 | struct ieee80211_vif *vif, |
| 1658 | void *data, int len) |
| 1659 | { |
| 1660 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; |
| 1661 | int err; |
| 1662 | u32 noa_duration; |
| 1663 | |
| 1664 | err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy); |
| 1665 | if (err) |
| 1666 | return err; |
| 1667 | |
| 1668 | if (!tb[IWL_MVM_TM_ATTR_CMD]) |
| 1669 | return -EINVAL; |
| 1670 | |
| 1671 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { |
| 1672 | case IWL_MVM_TM_CMD_SET_NOA: |
| 1673 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || |
| 1674 | !vif->bss_conf.enable_beacon || |
| 1675 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) |
| 1676 | return -EINVAL; |
| 1677 | |
| 1678 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); |
| 1679 | if (noa_duration >= vif->bss_conf.beacon_int) |
| 1680 | return -EINVAL; |
| 1681 | |
| 1682 | mvm->noa_duration = noa_duration; |
| 1683 | mvm->noa_vif = vif; |
| 1684 | |
| 1685 | return iwl_mvm_update_quotas(mvm, NULL); |
Johannes Berg | f6c6ad42 | 2013-08-01 14:17:15 +0200 | [diff] [blame] | 1686 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
| 1687 | /* must be associated client vif - ignore authorized */ |
| 1688 | if (!vif || vif->type != NL80211_IFTYPE_STATION || |
| 1689 | !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || |
| 1690 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) |
| 1691 | return -EINVAL; |
| 1692 | |
| 1693 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) |
| 1694 | return iwl_mvm_enable_beacon_filter(mvm, vif); |
| 1695 | return iwl_mvm_disable_beacon_filter(mvm, vif); |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | return -EOPNOTSUPP; |
| 1699 | } |
| 1700 | |
| 1701 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, |
| 1702 | struct ieee80211_vif *vif, |
| 1703 | void *data, int len) |
| 1704 | { |
| 1705 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1706 | int err; |
| 1707 | |
| 1708 | mutex_lock(&mvm->mutex); |
| 1709 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); |
| 1710 | mutex_unlock(&mvm->mutex); |
| 1711 | |
| 1712 | return err; |
| 1713 | } |
| 1714 | #endif |
| 1715 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1716 | struct ieee80211_ops iwl_mvm_hw_ops = { |
| 1717 | .tx = iwl_mvm_mac_tx, |
| 1718 | .ampdu_action = iwl_mvm_mac_ampdu_action, |
| 1719 | .start = iwl_mvm_mac_start, |
| 1720 | .restart_complete = iwl_mvm_mac_restart_complete, |
| 1721 | .stop = iwl_mvm_mac_stop, |
| 1722 | .add_interface = iwl_mvm_mac_add_interface, |
| 1723 | .remove_interface = iwl_mvm_mac_remove_interface, |
| 1724 | .config = iwl_mvm_mac_config, |
| 1725 | .configure_filter = iwl_mvm_configure_filter, |
| 1726 | .bss_info_changed = iwl_mvm_bss_info_changed, |
| 1727 | .hw_scan = iwl_mvm_mac_hw_scan, |
| 1728 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, |
| 1729 | .sta_state = iwl_mvm_mac_sta_state, |
| 1730 | .sta_notify = iwl_mvm_mac_sta_notify, |
| 1731 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, |
| 1732 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
| 1733 | .conf_tx = iwl_mvm_mac_conf_tx, |
| 1734 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1735 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
| 1736 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1737 | .set_key = iwl_mvm_mac_set_key, |
| 1738 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, |
| 1739 | .remain_on_channel = iwl_mvm_roc, |
| 1740 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1741 | .add_chanctx = iwl_mvm_add_chanctx, |
| 1742 | .remove_chanctx = iwl_mvm_remove_chanctx, |
| 1743 | .change_chanctx = iwl_mvm_change_chanctx, |
| 1744 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, |
| 1745 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, |
| 1746 | |
| 1747 | .start_ap = iwl_mvm_start_ap, |
| 1748 | .stop_ap = iwl_mvm_stop_ap, |
| 1749 | |
| 1750 | .set_tim = iwl_mvm_set_tim, |
| 1751 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 1752 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
| 1753 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1754 | #ifdef CONFIG_PM_SLEEP |
| 1755 | /* look at d3.c */ |
| 1756 | .suspend = iwl_mvm_suspend, |
| 1757 | .resume = iwl_mvm_resume, |
| 1758 | .set_wakeup = iwl_mvm_set_wakeup, |
| 1759 | .set_rekey_data = iwl_mvm_set_rekey_data, |
| 1760 | #if IS_ENABLED(CONFIG_IPV6) |
| 1761 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, |
| 1762 | #endif |
| 1763 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, |
| 1764 | #endif |
| 1765 | }; |