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 |
| 25 | * in the file called LICENSE.GPL. |
| 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> |
| 68 | #include <net/mac80211.h> |
| 69 | |
| 70 | #include "iwl-op-mode.h" |
| 71 | #include "iwl-io.h" |
| 72 | #include "mvm.h" |
| 73 | #include "sta.h" |
| 74 | #include "time-event.h" |
| 75 | #include "iwl-eeprom-parse.h" |
| 76 | #include "fw-api-scan.h" |
| 77 | #include "iwl-phy-db.h" |
| 78 | |
| 79 | static const struct ieee80211_iface_limit iwl_mvm_limits[] = { |
| 80 | { |
| 81 | .max = 1, |
| 82 | .types = BIT(NL80211_IFTYPE_STATION) | |
| 83 | BIT(NL80211_IFTYPE_AP), |
| 84 | }, |
| 85 | { |
| 86 | .max = 1, |
| 87 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 88 | BIT(NL80211_IFTYPE_P2P_GO), |
| 89 | }, |
| 90 | { |
| 91 | .max = 1, |
| 92 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 93 | }, |
| 94 | }; |
| 95 | |
| 96 | static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { |
| 97 | { |
| 98 | .num_different_channels = 1, |
| 99 | .max_interfaces = 3, |
| 100 | .limits = iwl_mvm_limits, |
| 101 | .n_limits = ARRAY_SIZE(iwl_mvm_limits), |
| 102 | }, |
| 103 | }; |
| 104 | |
| 105 | int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) |
| 106 | { |
| 107 | struct ieee80211_hw *hw = mvm->hw; |
| 108 | int num_mac, ret; |
| 109 | |
| 110 | /* Tell mac80211 our characteristics */ |
| 111 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 112 | IEEE80211_HW_SPECTRUM_MGMT | |
| 113 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 114 | IEEE80211_HW_QUEUE_CONTROL | |
| 115 | IEEE80211_HW_WANT_MONITOR_VIF | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 116 | IEEE80211_HW_SUPPORTS_PS | |
| 117 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
| 118 | IEEE80211_HW_AMPDU_AGGREGATION; |
| 119 | |
| 120 | hw->queues = IWL_FIRST_AMPDU_QUEUE; |
| 121 | hw->offchannel_tx_hw_queue = IWL_OFFCHANNEL_QUEUE; |
| 122 | hw->rate_control_algorithm = "iwl-mvm-rs"; |
| 123 | |
| 124 | /* |
| 125 | * Enable 11w if advertised by firmware and software crypto |
| 126 | * is not enabled (as the firmware will interpret some mgmt |
| 127 | * packets, so enabling it with software crypto isn't safe) |
| 128 | */ |
| 129 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP && |
| 130 | !iwlwifi_mod_params.sw_crypto) |
| 131 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; |
| 132 | |
| 133 | hw->sta_data_size = sizeof(struct iwl_mvm_sta); |
| 134 | hw->vif_data_size = sizeof(struct iwl_mvm_vif); |
| 135 | hw->chanctx_data_size = sizeof(struct iwl_mvm_phy_ctxt); |
| 136 | |
| 137 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 138 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 139 | BIT(NL80211_IFTYPE_AP) | |
| 140 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 141 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 142 | |
| 143 | hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | |
| 144 | WIPHY_FLAG_DISABLE_BEACON_HINTS | |
| 145 | WIPHY_FLAG_IBSS_RSN; |
| 146 | |
| 147 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; |
| 148 | hw->wiphy->n_iface_combinations = |
| 149 | ARRAY_SIZE(iwl_mvm_iface_combinations); |
| 150 | |
| 151 | hw->wiphy->max_remain_on_channel_duration = 500; |
| 152 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
| 153 | |
| 154 | /* Extract MAC address */ |
| 155 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); |
| 156 | hw->wiphy->addresses = mvm->addresses; |
| 157 | hw->wiphy->n_addresses = 1; |
| 158 | num_mac = mvm->nvm_data->n_hw_addrs; |
| 159 | if (num_mac > 1) { |
| 160 | memcpy(mvm->addresses[1].addr, mvm->addresses[0].addr, |
| 161 | ETH_ALEN); |
| 162 | mvm->addresses[1].addr[5]++; |
| 163 | hw->wiphy->n_addresses++; |
| 164 | } |
| 165 | |
| 166 | /* we create the 802.11 header and a max-length SSID element */ |
| 167 | hw->wiphy->max_scan_ie_len = |
| 168 | mvm->fw->ucode_capa.max_probe_length - 24 - 34; |
| 169 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
| 170 | |
| 171 | if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 172 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 173 | &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; |
| 174 | if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 175 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 176 | &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; |
| 177 | |
| 178 | hw->wiphy->hw_version = mvm->trans->hw_id; |
| 179 | |
| 180 | if (iwlwifi_mod_params.power_save) |
| 181 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 182 | else |
| 183 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 184 | |
| 185 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
| 186 | NL80211_FEATURE_P2P_GO_OPPPS; |
| 187 | |
| 188 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 189 | |
| 190 | #ifdef CONFIG_PM_SLEEP |
| 191 | if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len && |
| 192 | mvm->trans->ops->d3_suspend && |
| 193 | mvm->trans->ops->d3_resume && |
| 194 | device_can_wakeup(mvm->trans->dev)) { |
| 195 | hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | |
| 196 | WIPHY_WOWLAN_DISCONNECT | |
| 197 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | |
| 198 | WIPHY_WOWLAN_RFKILL_RELEASE; |
| 199 | if (!iwlwifi_mod_params.sw_crypto) |
| 200 | hw->wiphy->wowlan.flags |= |
| 201 | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
| 202 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | |
| 203 | WIPHY_WOWLAN_4WAY_HANDSHAKE; |
| 204 | |
| 205 | hw->wiphy->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; |
| 206 | hw->wiphy->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; |
| 207 | hw->wiphy->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; |
| 208 | } |
| 209 | #endif |
| 210 | |
| 211 | ret = iwl_mvm_leds_init(mvm); |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | |
| 215 | return ieee80211_register_hw(mvm->hw); |
| 216 | } |
| 217 | |
| 218 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, |
| 219 | struct ieee80211_tx_control *control, |
| 220 | struct sk_buff *skb) |
| 221 | { |
| 222 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 223 | |
| 224 | if (test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status)) { |
| 225 | IWL_DEBUG_DROP(mvm, "Dropping - RF KILL\n"); |
| 226 | goto drop; |
| 227 | } |
| 228 | |
| 229 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_OFFCHANNEL_QUEUE && |
| 230 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status)) |
| 231 | goto drop; |
| 232 | |
| 233 | if (control->sta) { |
| 234 | if (iwl_mvm_tx_skb(mvm, skb, control->sta)) |
| 235 | goto drop; |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | if (iwl_mvm_tx_skb_non_sta(mvm, skb)) |
| 240 | goto drop; |
| 241 | return; |
| 242 | drop: |
| 243 | ieee80211_free_txskb(hw, skb); |
| 244 | } |
| 245 | |
| 246 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, |
| 247 | struct ieee80211_vif *vif, |
| 248 | enum ieee80211_ampdu_mlme_action action, |
| 249 | struct ieee80211_sta *sta, u16 tid, |
| 250 | u16 *ssn, u8 buf_size) |
| 251 | { |
| 252 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 253 | int ret; |
| 254 | |
| 255 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", |
| 256 | sta->addr, tid, action); |
| 257 | |
| 258 | if (!(mvm->nvm_data->sku_cap_11n_enable)) |
| 259 | return -EACCES; |
| 260 | |
| 261 | mutex_lock(&mvm->mutex); |
| 262 | |
| 263 | switch (action) { |
| 264 | case IEEE80211_AMPDU_RX_START: |
| 265 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) { |
| 266 | ret = -EINVAL; |
| 267 | break; |
| 268 | } |
| 269 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true); |
| 270 | break; |
| 271 | case IEEE80211_AMPDU_RX_STOP: |
| 272 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false); |
| 273 | break; |
| 274 | case IEEE80211_AMPDU_TX_START: |
| 275 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
| 276 | break; |
| 277 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 278 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 279 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 280 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
| 281 | break; |
| 282 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 283 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size); |
| 284 | break; |
| 285 | default: |
| 286 | WARN_ON_ONCE(1); |
| 287 | ret = -EINVAL; |
| 288 | break; |
| 289 | } |
| 290 | mutex_unlock(&mvm->mutex); |
| 291 | |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, |
| 296 | struct ieee80211_vif *vif) |
| 297 | { |
| 298 | struct iwl_mvm *mvm = data; |
| 299 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 300 | |
| 301 | mvmvif->uploaded = false; |
| 302 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 303 | |
| 304 | /* does this make sense at all? */ |
| 305 | mvmvif->color++; |
| 306 | |
| 307 | spin_lock_bh(&mvm->time_event_lock); |
| 308 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); |
| 309 | spin_unlock_bh(&mvm->time_event_lock); |
| 310 | |
| 311 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
| 312 | mvmvif->phy_ctxt = NULL; |
| 313 | } |
| 314 | |
| 315 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) |
| 316 | { |
| 317 | iwl_trans_stop_device(mvm->trans); |
| 318 | iwl_trans_stop_hw(mvm->trans, false); |
| 319 | |
| 320 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 321 | |
| 322 | /* just in case one was running */ |
| 323 | ieee80211_remain_on_channel_expired(mvm->hw); |
| 324 | |
| 325 | ieee80211_iterate_active_interfaces_atomic( |
| 326 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 327 | iwl_mvm_cleanup_iterator, mvm); |
| 328 | |
| 329 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 330 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); |
| 331 | |
| 332 | ieee80211_wake_queues(mvm->hw); |
| 333 | |
| 334 | mvm->vif_count = 0; |
| 335 | } |
| 336 | |
| 337 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) |
| 338 | { |
| 339 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 340 | int ret; |
| 341 | |
| 342 | mutex_lock(&mvm->mutex); |
| 343 | |
| 344 | /* Clean up some internal and mac80211 state on restart */ |
| 345 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 346 | iwl_mvm_restart_cleanup(mvm); |
| 347 | |
| 348 | ret = iwl_mvm_up(mvm); |
| 349 | mutex_unlock(&mvm->mutex); |
| 350 | |
| 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) |
| 355 | { |
| 356 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 357 | int ret; |
| 358 | |
| 359 | mutex_lock(&mvm->mutex); |
| 360 | |
| 361 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 362 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 363 | if (ret) |
| 364 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", |
| 365 | ret); |
| 366 | |
| 367 | mutex_unlock(&mvm->mutex); |
| 368 | } |
| 369 | |
| 370 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) |
| 371 | { |
| 372 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 373 | |
| 374 | flush_work(&mvm->async_handlers_wk); |
| 375 | |
| 376 | mutex_lock(&mvm->mutex); |
| 377 | /* async_handlers_wk is now blocked */ |
| 378 | |
| 379 | /* |
| 380 | * The work item could be running or queued if the |
| 381 | * ROC time event stops just as we get here. |
| 382 | */ |
| 383 | cancel_work_sync(&mvm->roc_done_wk); |
| 384 | |
| 385 | iwl_trans_stop_device(mvm->trans); |
| 386 | iwl_trans_stop_hw(mvm->trans, false); |
| 387 | |
| 388 | iwl_mvm_async_handlers_purge(mvm); |
| 389 | /* async_handlers_list is empty and will stay empty: HW is stopped */ |
| 390 | |
| 391 | /* the fw is stopped, the aux sta is dead: clean up driver state */ |
| 392 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 393 | |
| 394 | mutex_unlock(&mvm->mutex); |
| 395 | |
| 396 | /* |
| 397 | * The worker might have been waiting for the mutex, let it run and |
| 398 | * discover that its list is now empty. |
| 399 | */ |
| 400 | cancel_work_sync(&mvm->async_handlers_wk); |
| 401 | } |
| 402 | |
| 403 | static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac, |
| 404 | struct ieee80211_vif *vif) |
| 405 | { |
| 406 | struct iwl_mvm *mvm = data; |
| 407 | int ret; |
| 408 | |
| 409 | ret = iwl_mvm_power_disable(mvm, vif); |
| 410 | if (ret) |
| 411 | IWL_ERR(mvm, "failed to disable power management\n"); |
| 412 | } |
| 413 | |
| 414 | static void iwl_mvm_power_update_iterator(void *data, u8 *mac, |
| 415 | struct ieee80211_vif *vif) |
| 416 | { |
| 417 | struct iwl_mvm *mvm = data; |
| 418 | |
| 419 | iwl_mvm_power_update_mode(mvm, vif); |
| 420 | } |
| 421 | |
| 422 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
| 423 | struct ieee80211_vif *vif) |
| 424 | { |
| 425 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 426 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 427 | int ret; |
| 428 | |
| 429 | /* |
| 430 | * Not much to do here. The stack will not allow interface |
| 431 | * types or combinations that we didn't advertise, so we |
| 432 | * don't really have to check the types. |
| 433 | */ |
| 434 | |
| 435 | mutex_lock(&mvm->mutex); |
| 436 | |
| 437 | /* Allocate resources for the MAC context, and add it the the fw */ |
| 438 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
| 439 | if (ret) |
| 440 | goto out_unlock; |
| 441 | |
| 442 | /* |
| 443 | * The AP binding flow can be done only after the beacon |
| 444 | * template is configured (which happens only in the mac80211 |
| 445 | * start_ap() flow), and adding the broadcast station can happen |
| 446 | * only after the binding. |
| 447 | * In addition, since modifying the MAC before adding a bcast |
| 448 | * station is not allowed by the FW, delay the adding of MAC context to |
| 449 | * the point where we can also add the bcast station. |
| 450 | * In short: there's not much we can do at this point, other than |
| 451 | * allocating resources :) |
| 452 | */ |
| 453 | if (vif->type == NL80211_IFTYPE_AP) { |
| 454 | u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); |
| 455 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, |
| 456 | qmask); |
| 457 | if (ret) { |
| 458 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); |
| 459 | goto out_release; |
| 460 | } |
| 461 | |
| 462 | goto out_unlock; |
| 463 | } |
| 464 | |
| 465 | /* |
| 466 | * TODO: remove this temporary code. |
| 467 | * Currently MVM FW supports power management only on single MAC. |
| 468 | * Iterate and disable PM on all active interfaces. |
| 469 | * Note: the method below does not count the new interface being added |
| 470 | * at this moment. |
| 471 | */ |
| 472 | mvm->vif_count++; |
| 473 | if (mvm->vif_count > 1) { |
| 474 | IWL_DEBUG_MAC80211(mvm, |
| 475 | "Disable power on existing interfaces\n"); |
Emmanuel Grumbach | 5360cfb | 2013-02-11 15:56:01 +0200 | [diff] [blame] | 476 | ieee80211_iterate_active_interfaces_atomic( |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 477 | mvm->hw, |
| 478 | IEEE80211_IFACE_ITER_NORMAL, |
| 479 | iwl_mvm_pm_disable_iterator, mvm); |
| 480 | } |
| 481 | |
| 482 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 483 | if (ret) |
| 484 | goto out_release; |
| 485 | |
| 486 | /* |
| 487 | * Update power state on the new interface. Admittedly, based on |
| 488 | * mac80211 logics this power update will disable power management |
| 489 | */ |
| 490 | iwl_mvm_power_update_mode(mvm, vif); |
| 491 | |
| 492 | /* |
| 493 | * P2P_DEVICE interface does not have a channel context assigned to it, |
| 494 | * so a dedicated PHY context is allocated to it and the corresponding |
| 495 | * MAC context is bound to it at this stage. |
| 496 | */ |
| 497 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 498 | struct ieee80211_channel *chan; |
| 499 | struct cfg80211_chan_def chandef; |
| 500 | |
| 501 | mvmvif->phy_ctxt = &mvm->phy_ctxt_roc; |
| 502 | |
| 503 | /* |
| 504 | * The channel used here isn't relevant as it's |
| 505 | * going to be overwritten as part of the ROC flow. |
| 506 | * For now use the first channel we have. |
| 507 | */ |
| 508 | chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0]; |
| 509 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT); |
| 510 | ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, |
| 511 | &chandef, 1, 1); |
| 512 | if (ret) |
| 513 | goto out_remove_mac; |
| 514 | |
| 515 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 516 | if (ret) |
| 517 | goto out_remove_phy; |
| 518 | |
| 519 | ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 520 | if (ret) |
| 521 | goto out_unbind; |
| 522 | |
| 523 | /* Save a pointer to p2p device vif, so it can later be used to |
| 524 | * update the p2p device MAC when a GO is started/stopped */ |
| 525 | mvm->p2p_device_vif = vif; |
| 526 | } |
| 527 | |
| 528 | goto out_unlock; |
| 529 | |
| 530 | out_unbind: |
| 531 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 532 | out_remove_phy: |
| 533 | iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt); |
| 534 | out_remove_mac: |
| 535 | mvmvif->phy_ctxt = NULL; |
| 536 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 537 | out_release: |
| 538 | /* |
| 539 | * TODO: remove this temporary code. |
| 540 | * Currently MVM FW supports power management only on single MAC. |
| 541 | * Check if only one additional interface remains after rereasing |
| 542 | * current one. Update power mode on the remaining interface. |
| 543 | */ |
| 544 | mvm->vif_count--; |
| 545 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", |
| 546 | mvm->vif_count); |
| 547 | if (mvm->vif_count == 1) { |
| 548 | ieee80211_iterate_active_interfaces( |
| 549 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 550 | iwl_mvm_power_update_iterator, mvm); |
| 551 | } |
| 552 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 553 | out_unlock: |
| 554 | mutex_unlock(&mvm->mutex); |
| 555 | |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, |
| 560 | struct ieee80211_vif *vif) |
| 561 | { |
| 562 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 563 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 564 | u32 tfd_msk = 0, ac; |
| 565 | |
| 566 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 567 | if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE) |
| 568 | tfd_msk |= BIT(vif->hw_queue[ac]); |
| 569 | |
| 570 | if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE) |
| 571 | tfd_msk |= BIT(vif->cab_queue); |
| 572 | |
| 573 | if (tfd_msk) { |
| 574 | mutex_lock(&mvm->mutex); |
| 575 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); |
| 576 | mutex_unlock(&mvm->mutex); |
| 577 | } |
| 578 | |
| 579 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 580 | /* |
| 581 | * Flush the ROC worker which will flush the OFFCHANNEL queue. |
| 582 | * We assume here that all the packets sent to the OFFCHANNEL |
| 583 | * queue are sent in ROC session. |
| 584 | */ |
| 585 | flush_work(&mvm->roc_done_wk); |
| 586 | } else { |
| 587 | /* |
| 588 | * By now, all the AC queues are empty. The AGG queues are |
| 589 | * empty too. We already got all the Tx responses for all the |
| 590 | * packets in the queues. The drain work can have been |
| 591 | * triggered. Flush it. This work item takes the mutex, so kill |
| 592 | * it before we take it. |
| 593 | */ |
| 594 | flush_work(&mvm->sta_drained_wk); |
| 595 | } |
| 596 | |
| 597 | mutex_lock(&mvm->mutex); |
| 598 | |
| 599 | /* |
| 600 | * For AP/GO interface, the tear down of the resources allocated to the |
| 601 | * interface should be handled as part of the bss_info_changed flow. |
| 602 | */ |
| 603 | if (vif->type == NL80211_IFTYPE_AP) { |
| 604 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 605 | goto out_release; |
| 606 | } |
| 607 | |
| 608 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 609 | mvm->p2p_device_vif = NULL; |
| 610 | iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 611 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 612 | iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt); |
| 613 | mvmvif->phy_ctxt = NULL; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * TODO: remove this temporary code. |
| 618 | * Currently MVM FW supports power management only on single MAC. |
| 619 | * Check if only one additional interface remains after removing |
| 620 | * current one. Update power mode on the remaining interface. |
| 621 | */ |
| 622 | if (mvm->vif_count) |
| 623 | mvm->vif_count--; |
| 624 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", |
| 625 | mvm->vif_count); |
| 626 | if (mvm->vif_count == 1) { |
| 627 | ieee80211_iterate_active_interfaces( |
| 628 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 629 | iwl_mvm_power_update_iterator, mvm); |
| 630 | } |
| 631 | |
| 632 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 633 | |
| 634 | out_release: |
| 635 | iwl_mvm_mac_ctxt_release(mvm, vif); |
| 636 | mutex_unlock(&mvm->mutex); |
| 637 | } |
| 638 | |
| 639 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 640 | { |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, |
| 645 | unsigned int changed_flags, |
| 646 | unsigned int *total_flags, |
| 647 | u64 multicast) |
| 648 | { |
| 649 | *total_flags = 0; |
| 650 | } |
| 651 | |
| 652 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
| 653 | struct ieee80211_vif *vif, |
| 654 | struct ieee80211_bss_conf *bss_conf, |
| 655 | u32 changes) |
| 656 | { |
| 657 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 658 | int ret; |
| 659 | |
| 660 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 661 | if (ret) |
| 662 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
| 663 | |
| 664 | if (changes & BSS_CHANGED_ASSOC) { |
| 665 | if (bss_conf->assoc) { |
| 666 | /* add quota for this interface */ |
| 667 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 668 | if (ret) { |
| 669 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 670 | return; |
| 671 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 672 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 673 | /* remove AP station now that the MAC is unassoc */ |
| 674 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); |
| 675 | if (ret) |
| 676 | IWL_ERR(mvm, "failed to remove AP station\n"); |
| 677 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
| 678 | /* remove quota for this interface */ |
| 679 | ret = iwl_mvm_update_quotas(mvm, NULL); |
| 680 | if (ret) |
| 681 | IWL_ERR(mvm, "failed to update quotas\n"); |
| 682 | } |
Johannes Berg | 210a544 | 2013-01-24 23:48:23 +0100 | [diff] [blame] | 683 | } else if (changes & BSS_CHANGED_DTIM_PERIOD) { |
| 684 | /* |
| 685 | * We received a beacon _after_ association so |
| 686 | * remove the session protection. |
| 687 | */ |
| 688 | iwl_mvm_remove_time_event(mvm, mvmvif, |
| 689 | &mvmvif->time_event_data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 690 | } else if (changes & BSS_CHANGED_PS) { |
| 691 | /* |
| 692 | * TODO: remove this temporary code. |
| 693 | * Currently MVM FW supports power management only on single |
| 694 | * MAC. Avoid power mode update if more than one interface |
| 695 | * is active. |
| 696 | */ |
| 697 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", |
| 698 | mvm->vif_count); |
| 699 | if (mvm->vif_count == 1) { |
| 700 | ret = iwl_mvm_power_update_mode(mvm, vif); |
| 701 | if (ret) |
| 702 | IWL_ERR(mvm, "failed to update power mode\n"); |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 708 | { |
| 709 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 710 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 711 | int ret; |
| 712 | |
| 713 | mutex_lock(&mvm->mutex); |
| 714 | |
| 715 | /* Send the beacon template */ |
| 716 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); |
| 717 | if (ret) |
| 718 | goto out_unlock; |
| 719 | |
| 720 | /* Add the mac context */ |
| 721 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 722 | if (ret) |
| 723 | goto out_unlock; |
| 724 | |
| 725 | /* Perform the binding */ |
| 726 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 727 | if (ret) |
| 728 | goto out_remove; |
| 729 | |
| 730 | mvmvif->ap_active = true; |
| 731 | |
| 732 | /* Send the bcast station. At this stage the TBTT and DTIM time events |
| 733 | * are added and applied to the scheduler */ |
| 734 | ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta); |
| 735 | if (ret) |
| 736 | goto out_unbind; |
| 737 | |
| 738 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 739 | if (ret) |
| 740 | goto out_rm_bcast; |
| 741 | |
| 742 | /* Need to update the P2P Device MAC */ |
| 743 | if (vif->p2p && mvm->p2p_device_vif) |
| 744 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); |
| 745 | |
| 746 | mutex_unlock(&mvm->mutex); |
| 747 | return 0; |
| 748 | |
| 749 | out_rm_bcast: |
| 750 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 751 | out_unbind: |
| 752 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 753 | out_remove: |
| 754 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 755 | out_unlock: |
| 756 | mutex_unlock(&mvm->mutex); |
| 757 | return ret; |
| 758 | } |
| 759 | |
| 760 | static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 761 | { |
| 762 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 763 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 764 | |
| 765 | mutex_lock(&mvm->mutex); |
| 766 | |
| 767 | mvmvif->ap_active = false; |
| 768 | |
| 769 | /* Need to update the P2P Device MAC */ |
| 770 | if (vif->p2p && mvm->p2p_device_vif) |
| 771 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); |
| 772 | |
| 773 | iwl_mvm_update_quotas(mvm, NULL); |
| 774 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
| 775 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 776 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
| 777 | |
| 778 | mutex_unlock(&mvm->mutex); |
| 779 | } |
| 780 | |
| 781 | static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm, |
| 782 | struct ieee80211_vif *vif, |
| 783 | struct ieee80211_bss_conf *bss_conf, |
| 784 | u32 changes) |
| 785 | { |
| 786 | /* Need to send a new beacon template to the FW */ |
| 787 | if (changes & BSS_CHANGED_BEACON) { |
| 788 | if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) |
| 789 | IWL_WARN(mvm, "Failed updating beacon data\n"); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, |
| 794 | struct ieee80211_vif *vif, |
| 795 | struct ieee80211_bss_conf *bss_conf, |
| 796 | u32 changes) |
| 797 | { |
| 798 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 799 | |
| 800 | mutex_lock(&mvm->mutex); |
| 801 | |
| 802 | switch (vif->type) { |
| 803 | case NL80211_IFTYPE_STATION: |
| 804 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); |
| 805 | break; |
| 806 | case NL80211_IFTYPE_AP: |
| 807 | iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes); |
| 808 | break; |
| 809 | default: |
| 810 | /* shouldn't happen */ |
| 811 | WARN_ON_ONCE(1); |
| 812 | } |
| 813 | |
| 814 | mutex_unlock(&mvm->mutex); |
| 815 | } |
| 816 | |
| 817 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, |
| 818 | struct ieee80211_vif *vif, |
| 819 | struct cfg80211_scan_request *req) |
| 820 | { |
| 821 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 822 | int ret; |
| 823 | |
| 824 | if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS) |
| 825 | return -EINVAL; |
| 826 | |
| 827 | mutex_lock(&mvm->mutex); |
| 828 | |
| 829 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) |
| 830 | ret = iwl_mvm_scan_request(mvm, vif, req); |
| 831 | else |
| 832 | ret = -EBUSY; |
| 833 | |
| 834 | mutex_unlock(&mvm->mutex); |
| 835 | |
| 836 | return ret; |
| 837 | } |
| 838 | |
| 839 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, |
| 840 | struct ieee80211_vif *vif) |
| 841 | { |
| 842 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 843 | |
| 844 | mutex_lock(&mvm->mutex); |
| 845 | |
| 846 | iwl_mvm_cancel_scan(mvm); |
| 847 | |
| 848 | mutex_unlock(&mvm->mutex); |
| 849 | } |
| 850 | |
| 851 | static void |
| 852 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, |
| 853 | struct ieee80211_sta *sta, u16 tid, |
| 854 | int num_frames, |
| 855 | enum ieee80211_frame_release_type reason, |
| 856 | bool more_data) |
| 857 | { |
| 858 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 859 | struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv; |
| 860 | |
| 861 | /* TODO: how do we tell the fw to send frames for a specific TID */ |
| 862 | |
| 863 | /* |
| 864 | * The fw will send EOSP notification when the last frame will be |
| 865 | * transmitted. |
| 866 | */ |
| 867 | iwl_mvm_sta_modify_sleep_tx_count(mvm, mvmsta->sta_id, reason, |
| 868 | num_frames); |
| 869 | } |
| 870 | |
| 871 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
| 872 | struct ieee80211_vif *vif, |
| 873 | enum sta_notify_cmd cmd, |
| 874 | struct ieee80211_sta *sta) |
| 875 | { |
| 876 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 877 | struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv; |
| 878 | |
| 879 | switch (cmd) { |
| 880 | case STA_NOTIFY_SLEEP: |
| 881 | if (atomic_read(&mvmsta->pending_frames) > 0) |
| 882 | ieee80211_sta_block_awake(hw, sta, true); |
| 883 | /* |
| 884 | * The fw updates the STA to be asleep. Tx packets on the Tx |
| 885 | * queues to this station will not be transmitted. The fw will |
| 886 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. |
| 887 | */ |
| 888 | break; |
| 889 | case STA_NOTIFY_AWAKE: |
| 890 | if (WARN_ON(mvmsta->sta_id == IWL_INVALID_STATION)) |
| 891 | break; |
| 892 | iwl_mvm_sta_modify_ps_wake(mvm, mvmsta->sta_id); |
| 893 | break; |
| 894 | default: |
| 895 | break; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
| 900 | struct ieee80211_vif *vif, |
| 901 | struct ieee80211_sta *sta, |
| 902 | enum ieee80211_sta_state old_state, |
| 903 | enum ieee80211_sta_state new_state) |
| 904 | { |
| 905 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 906 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 907 | int ret; |
| 908 | |
| 909 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", |
| 910 | sta->addr, old_state, new_state); |
| 911 | |
| 912 | /* this would be a mac80211 bug ... but don't crash */ |
| 913 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) |
| 914 | return -EINVAL; |
| 915 | |
| 916 | /* if a STA is being removed, reuse its ID */ |
| 917 | flush_work(&mvm->sta_drained_wk); |
| 918 | |
| 919 | mutex_lock(&mvm->mutex); |
| 920 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 921 | new_state == IEEE80211_STA_NONE) { |
| 922 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
| 923 | } else if (old_state == IEEE80211_STA_NONE && |
| 924 | new_state == IEEE80211_STA_AUTH) { |
| 925 | ret = 0; |
| 926 | } else if (old_state == IEEE80211_STA_AUTH && |
| 927 | new_state == IEEE80211_STA_ASSOC) { |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 928 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
| 929 | if (ret == 0) |
| 930 | iwl_mvm_rs_rate_init(mvm, sta, |
| 931 | mvmvif->phy_ctxt->channel->band); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 932 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 933 | new_state == IEEE80211_STA_AUTHORIZED) { |
| 934 | ret = 0; |
| 935 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
| 936 | new_state == IEEE80211_STA_ASSOC) { |
| 937 | ret = 0; |
| 938 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 939 | new_state == IEEE80211_STA_AUTH) { |
| 940 | ret = 0; |
| 941 | } else if (old_state == IEEE80211_STA_AUTH && |
| 942 | new_state == IEEE80211_STA_NONE) { |
| 943 | ret = 0; |
| 944 | } else if (old_state == IEEE80211_STA_NONE && |
| 945 | new_state == IEEE80211_STA_NOTEXIST) { |
| 946 | ret = iwl_mvm_rm_sta(mvm, vif, sta); |
| 947 | } else { |
| 948 | ret = -EIO; |
| 949 | } |
| 950 | mutex_unlock(&mvm->mutex); |
| 951 | |
| 952 | return ret; |
| 953 | } |
| 954 | |
| 955 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 956 | { |
| 957 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 958 | |
| 959 | mvm->rts_threshold = value; |
| 960 | |
| 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
| 965 | struct ieee80211_vif *vif, u16 ac, |
| 966 | const struct ieee80211_tx_queue_params *params) |
| 967 | { |
| 968 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 969 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 970 | |
| 971 | mvmvif->queue_params[ac] = *params; |
| 972 | |
| 973 | /* |
| 974 | * No need to update right away, we'll get BSS_CHANGED_QOS |
| 975 | * The exception is P2P_DEVICE interface which needs immediate update. |
| 976 | */ |
| 977 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 978 | int ret; |
| 979 | |
| 980 | mutex_lock(&mvm->mutex); |
| 981 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 982 | mutex_unlock(&mvm->mutex); |
| 983 | return ret; |
| 984 | } |
| 985 | return 0; |
| 986 | } |
| 987 | |
| 988 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, |
| 989 | struct ieee80211_vif *vif) |
| 990 | { |
| 991 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 992 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, |
| 993 | 200 + vif->bss_conf.beacon_int); |
| 994 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, |
| 995 | 100 + vif->bss_conf.beacon_int); |
| 996 | |
| 997 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) |
| 998 | return; |
| 999 | |
| 1000 | mutex_lock(&mvm->mutex); |
| 1001 | /* Try really hard to protect the session and hear a beacon */ |
| 1002 | iwl_mvm_protect_session(mvm, vif, duration, min_duration); |
| 1003 | mutex_unlock(&mvm->mutex); |
| 1004 | } |
| 1005 | |
| 1006 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
| 1007 | enum set_key_cmd cmd, |
| 1008 | struct ieee80211_vif *vif, |
| 1009 | struct ieee80211_sta *sta, |
| 1010 | struct ieee80211_key_conf *key) |
| 1011 | { |
| 1012 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1013 | int ret; |
| 1014 | |
| 1015 | if (iwlwifi_mod_params.sw_crypto) { |
| 1016 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); |
| 1017 | return -EOPNOTSUPP; |
| 1018 | } |
| 1019 | |
| 1020 | switch (key->cipher) { |
| 1021 | case WLAN_CIPHER_SUITE_TKIP: |
| 1022 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 1023 | /* fall-through */ |
| 1024 | case WLAN_CIPHER_SUITE_CCMP: |
| 1025 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1026 | break; |
| 1027 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1028 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); |
| 1029 | break; |
| 1030 | case WLAN_CIPHER_SUITE_WEP40: |
| 1031 | case WLAN_CIPHER_SUITE_WEP104: |
| 1032 | /* |
| 1033 | * Support for TX only, at least for now, so accept |
| 1034 | * the key and do nothing else. Then mac80211 will |
| 1035 | * pass it for TX but we don't have to use it for RX. |
| 1036 | */ |
| 1037 | return 0; |
| 1038 | default: |
| 1039 | return -EOPNOTSUPP; |
| 1040 | } |
| 1041 | |
| 1042 | mutex_lock(&mvm->mutex); |
| 1043 | |
| 1044 | switch (cmd) { |
| 1045 | case SET_KEY: |
| 1046 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
| 1047 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); |
| 1048 | if (ret) { |
| 1049 | IWL_WARN(mvm, "set key failed\n"); |
| 1050 | /* |
| 1051 | * can't add key for RX, but we don't need it |
| 1052 | * in the device for TX so still return 0 |
| 1053 | */ |
| 1054 | ret = 0; |
| 1055 | } |
| 1056 | |
| 1057 | break; |
| 1058 | case DISABLE_KEY: |
| 1059 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
| 1060 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); |
| 1061 | break; |
| 1062 | default: |
| 1063 | ret = -EINVAL; |
| 1064 | } |
| 1065 | |
| 1066 | mutex_unlock(&mvm->mutex); |
| 1067 | return ret; |
| 1068 | } |
| 1069 | |
| 1070 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 1071 | struct ieee80211_vif *vif, |
| 1072 | struct ieee80211_key_conf *keyconf, |
| 1073 | struct ieee80211_sta *sta, |
| 1074 | u32 iv32, u16 *phase1key) |
| 1075 | { |
| 1076 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1077 | |
| 1078 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | static int iwl_mvm_roc(struct ieee80211_hw *hw, |
| 1083 | struct ieee80211_vif *vif, |
| 1084 | struct ieee80211_channel *channel, |
| 1085 | int duration) |
| 1086 | { |
| 1087 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1088 | struct cfg80211_chan_def chandef; |
| 1089 | int ret; |
| 1090 | |
| 1091 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) { |
| 1092 | IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type); |
| 1093 | return -EINVAL; |
| 1094 | } |
| 1095 | |
| 1096 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d)\n", channel->hw_value, |
| 1097 | duration); |
| 1098 | |
| 1099 | mutex_lock(&mvm->mutex); |
| 1100 | |
| 1101 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
| 1102 | ret = iwl_mvm_phy_ctxt_changed(mvm, &mvm->phy_ctxt_roc, |
| 1103 | &chandef, 1, 1); |
| 1104 | |
| 1105 | /* Schedule the time events */ |
| 1106 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration); |
| 1107 | |
| 1108 | mutex_unlock(&mvm->mutex); |
| 1109 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
| 1110 | |
| 1111 | return ret; |
| 1112 | } |
| 1113 | |
| 1114 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) |
| 1115 | { |
| 1116 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1117 | |
| 1118 | IWL_DEBUG_MAC80211(mvm, "enter\n"); |
| 1119 | |
| 1120 | mutex_lock(&mvm->mutex); |
| 1121 | iwl_mvm_stop_p2p_roc(mvm); |
| 1122 | mutex_unlock(&mvm->mutex); |
| 1123 | |
| 1124 | IWL_DEBUG_MAC80211(mvm, "leave\n"); |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, |
| 1129 | struct ieee80211_chanctx_conf *ctx) |
| 1130 | { |
| 1131 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1132 | struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv; |
| 1133 | int ret; |
| 1134 | |
| 1135 | mutex_lock(&mvm->mutex); |
| 1136 | |
| 1137 | IWL_DEBUG_MAC80211(mvm, "Add PHY context\n"); |
| 1138 | ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, &ctx->def, |
| 1139 | ctx->rx_chains_static, |
| 1140 | ctx->rx_chains_dynamic); |
| 1141 | mutex_unlock(&mvm->mutex); |
| 1142 | return ret; |
| 1143 | } |
| 1144 | |
| 1145 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, |
| 1146 | struct ieee80211_chanctx_conf *ctx) |
| 1147 | { |
| 1148 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1149 | struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv; |
| 1150 | |
| 1151 | mutex_lock(&mvm->mutex); |
| 1152 | iwl_mvm_phy_ctxt_remove(mvm, phy_ctxt); |
| 1153 | mutex_unlock(&mvm->mutex); |
| 1154 | } |
| 1155 | |
| 1156 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, |
| 1157 | struct ieee80211_chanctx_conf *ctx, |
| 1158 | u32 changed) |
| 1159 | { |
| 1160 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1161 | struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv; |
| 1162 | |
| 1163 | mutex_lock(&mvm->mutex); |
| 1164 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def, |
| 1165 | ctx->rx_chains_static, |
| 1166 | ctx->rx_chains_dynamic); |
| 1167 | mutex_unlock(&mvm->mutex); |
| 1168 | } |
| 1169 | |
| 1170 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 1171 | struct ieee80211_vif *vif, |
| 1172 | struct ieee80211_chanctx_conf *ctx) |
| 1173 | { |
| 1174 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1175 | struct iwl_mvm_phy_ctxt *phyctx = (void *)ctx->drv_priv; |
| 1176 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1177 | int ret; |
| 1178 | |
| 1179 | mutex_lock(&mvm->mutex); |
| 1180 | |
| 1181 | mvmvif->phy_ctxt = phyctx; |
| 1182 | |
| 1183 | switch (vif->type) { |
| 1184 | case NL80211_IFTYPE_AP: |
| 1185 | /* |
| 1186 | * The AP binding flow is handled as part of the start_ap flow |
| 1187 | * (in bss_info_changed). |
| 1188 | */ |
| 1189 | ret = 0; |
| 1190 | goto out_unlock; |
| 1191 | case NL80211_IFTYPE_STATION: |
| 1192 | case NL80211_IFTYPE_ADHOC: |
| 1193 | case NL80211_IFTYPE_MONITOR: |
| 1194 | break; |
| 1195 | default: |
| 1196 | ret = -EINVAL; |
| 1197 | goto out_unlock; |
| 1198 | } |
| 1199 | |
| 1200 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
| 1201 | if (ret) |
| 1202 | goto out_unlock; |
| 1203 | |
| 1204 | /* |
| 1205 | * Setting the quota at this stage is only required for monitor |
| 1206 | * interfaces. For the other types, the bss_info changed flow |
| 1207 | * will handle quota settings. |
| 1208 | */ |
| 1209 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 1210 | ret = iwl_mvm_update_quotas(mvm, vif); |
| 1211 | if (ret) |
| 1212 | goto out_remove_binding; |
| 1213 | } |
| 1214 | |
| 1215 | goto out_unlock; |
| 1216 | |
| 1217 | out_remove_binding: |
| 1218 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 1219 | out_unlock: |
| 1220 | mutex_unlock(&mvm->mutex); |
| 1221 | if (ret) |
| 1222 | mvmvif->phy_ctxt = NULL; |
| 1223 | return ret; |
| 1224 | } |
| 1225 | |
| 1226 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 1227 | struct ieee80211_vif *vif, |
| 1228 | struct ieee80211_chanctx_conf *ctx) |
| 1229 | { |
| 1230 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1231 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1232 | |
| 1233 | mutex_lock(&mvm->mutex); |
| 1234 | |
| 1235 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); |
| 1236 | |
| 1237 | if (vif->type == NL80211_IFTYPE_AP) |
| 1238 | goto out_unlock; |
| 1239 | |
| 1240 | iwl_mvm_binding_remove_vif(mvm, vif); |
| 1241 | switch (vif->type) { |
| 1242 | case NL80211_IFTYPE_MONITOR: |
| 1243 | iwl_mvm_update_quotas(mvm, vif); |
| 1244 | break; |
| 1245 | default: |
| 1246 | break; |
| 1247 | } |
| 1248 | |
| 1249 | out_unlock: |
| 1250 | mvmvif->phy_ctxt = NULL; |
| 1251 | mutex_unlock(&mvm->mutex); |
| 1252 | } |
| 1253 | |
| 1254 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, |
| 1255 | struct ieee80211_sta *sta, |
| 1256 | bool set) |
| 1257 | { |
| 1258 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1259 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; |
| 1260 | |
| 1261 | if (!mvm_sta || !mvm_sta->vif) { |
| 1262 | IWL_ERR(mvm, "Station is not associated to a vif\n"); |
| 1263 | return -EINVAL; |
| 1264 | } |
| 1265 | |
| 1266 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); |
| 1267 | } |
| 1268 | |
| 1269 | struct ieee80211_ops iwl_mvm_hw_ops = { |
| 1270 | .tx = iwl_mvm_mac_tx, |
| 1271 | .ampdu_action = iwl_mvm_mac_ampdu_action, |
| 1272 | .start = iwl_mvm_mac_start, |
| 1273 | .restart_complete = iwl_mvm_mac_restart_complete, |
| 1274 | .stop = iwl_mvm_mac_stop, |
| 1275 | .add_interface = iwl_mvm_mac_add_interface, |
| 1276 | .remove_interface = iwl_mvm_mac_remove_interface, |
| 1277 | .config = iwl_mvm_mac_config, |
| 1278 | .configure_filter = iwl_mvm_configure_filter, |
| 1279 | .bss_info_changed = iwl_mvm_bss_info_changed, |
| 1280 | .hw_scan = iwl_mvm_mac_hw_scan, |
| 1281 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, |
| 1282 | .sta_state = iwl_mvm_mac_sta_state, |
| 1283 | .sta_notify = iwl_mvm_mac_sta_notify, |
| 1284 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, |
| 1285 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
| 1286 | .conf_tx = iwl_mvm_mac_conf_tx, |
| 1287 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, |
| 1288 | .set_key = iwl_mvm_mac_set_key, |
| 1289 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, |
| 1290 | .remain_on_channel = iwl_mvm_roc, |
| 1291 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, |
| 1292 | |
| 1293 | .add_chanctx = iwl_mvm_add_chanctx, |
| 1294 | .remove_chanctx = iwl_mvm_remove_chanctx, |
| 1295 | .change_chanctx = iwl_mvm_change_chanctx, |
| 1296 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, |
| 1297 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, |
| 1298 | |
| 1299 | .start_ap = iwl_mvm_start_ap, |
| 1300 | .stop_ap = iwl_mvm_stop_ap, |
| 1301 | |
| 1302 | .set_tim = iwl_mvm_set_tim, |
| 1303 | |
| 1304 | #ifdef CONFIG_PM_SLEEP |
| 1305 | /* look at d3.c */ |
| 1306 | .suspend = iwl_mvm_suspend, |
| 1307 | .resume = iwl_mvm_resume, |
| 1308 | .set_wakeup = iwl_mvm_set_wakeup, |
| 1309 | .set_rekey_data = iwl_mvm_set_rekey_data, |
| 1310 | #if IS_ENABLED(CONFIG_IPV6) |
| 1311 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, |
| 1312 | #endif |
| 1313 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, |
| 1314 | #endif |
| 1315 | }; |