1 /******************************************************************************
3 * Copyright(c) 2003 - 2013 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/dma-mapping.h>
34 #include <linux/delay.h>
35 #include <linux/sched.h>
36 #include <linux/skbuff.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/if_arp.h>
41 #include <net/ieee80211_radiotap.h>
42 #include <net/mac80211.h>
44 #include <asm/div64.h>
47 #include "iwl-trans.h"
48 #include "iwl-op-mode.h"
49 #include "iwl-modparams.h"
55 /*****************************************************************************
57 * mac80211 entry point functions
59 *****************************************************************************/
61 static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
64 .types = BIT(NL80211_IFTYPE_STATION),
68 .types = BIT(NL80211_IFTYPE_AP),
72 static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
75 .types = BIT(NL80211_IFTYPE_STATION),
79 static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
82 .types = BIT(NL80211_IFTYPE_STATION),
86 .types = BIT(NL80211_IFTYPE_P2P_GO) |
87 BIT(NL80211_IFTYPE_AP),
91 static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
94 .types = BIT(NL80211_IFTYPE_STATION),
98 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
102 static const struct ieee80211_iface_combination
103 iwlagn_iface_combinations_dualmode[] = {
104 { .num_different_channels = 1,
106 .beacon_int_infra_match = true,
107 .limits = iwlagn_sta_ap_limits,
108 .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
110 { .num_different_channels = 1,
112 .limits = iwlagn_2sta_limits,
113 .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
117 static const struct ieee80211_iface_combination
118 iwlagn_iface_combinations_p2p[] = {
119 { .num_different_channels = 1,
121 .beacon_int_infra_match = true,
122 .limits = iwlagn_p2p_sta_go_limits,
123 .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
125 { .num_different_channels = 1,
127 .limits = iwlagn_p2p_2sta_limits,
128 .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
133 * Not a mac80211 entry point function, but it fits in with all the
134 * other mac80211 functions grouped here.
136 int iwlagn_mac_setup_register(struct iwl_priv *priv,
137 const struct iwl_ucode_capabilities *capa)
140 struct ieee80211_hw *hw = priv->hw;
141 struct iwl_rxon_context *ctx;
143 hw->rate_control_algorithm = "iwl-agn-rs";
145 /* Tell mac80211 our characteristics */
146 hw->flags = IEEE80211_HW_SIGNAL_DBM |
147 IEEE80211_HW_AMPDU_AGGREGATION |
148 IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC |
149 IEEE80211_HW_SPECTRUM_MGMT |
150 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
151 IEEE80211_HW_QUEUE_CONTROL |
152 IEEE80211_HW_SUPPORTS_PS |
153 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
154 IEEE80211_HW_WANT_MONITOR_VIF;
156 hw->offchannel_tx_hw_queue = IWL_AUX_QUEUE;
157 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
160 * Including the following line will crash some AP's. This
161 * workaround removes the stimulus which causes the crash until
162 * the AP software can be fixed.
163 hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
166 if (priv->nvm_data->sku_cap_11n_enable)
167 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
168 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
171 * Enable 11w if advertised by firmware and software crypto
172 * is not enabled (as the firmware will interpret some mgmt
173 * packets, so enabling it with software crypto isn't safe)
175 if (priv->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
176 !iwlwifi_mod_params.sw_crypto)
177 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
179 hw->sta_data_size = sizeof(struct iwl_station_priv);
180 hw->vif_data_size = sizeof(struct iwl_vif_priv);
182 for_each_context(priv, ctx) {
183 hw->wiphy->interface_modes |= ctx->interface_modes;
184 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
187 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
189 if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
190 hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
191 hw->wiphy->n_iface_combinations =
192 ARRAY_SIZE(iwlagn_iface_combinations_p2p);
193 } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
194 hw->wiphy->iface_combinations =
195 iwlagn_iface_combinations_dualmode;
196 hw->wiphy->n_iface_combinations =
197 ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
200 hw->wiphy->max_remain_on_channel_duration = 500;
202 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
203 WIPHY_FLAG_DISABLE_BEACON_HINTS |
206 #ifdef CONFIG_PM_SLEEP
207 if (priv->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
208 priv->trans->ops->d3_suspend &&
209 priv->trans->ops->d3_resume &&
210 device_can_wakeup(priv->trans->dev)) {
211 priv->wowlan_support.flags = WIPHY_WOWLAN_MAGIC_PKT |
212 WIPHY_WOWLAN_DISCONNECT |
213 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
214 WIPHY_WOWLAN_RFKILL_RELEASE;
215 if (!iwlwifi_mod_params.sw_crypto)
216 priv->wowlan_support.flags |=
217 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
218 WIPHY_WOWLAN_GTK_REKEY_FAILURE;
220 priv->wowlan_support.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
221 priv->wowlan_support.pattern_min_len =
222 IWLAGN_WOWLAN_MIN_PATTERN_LEN;
223 priv->wowlan_support.pattern_max_len =
224 IWLAGN_WOWLAN_MAX_PATTERN_LEN;
225 hw->wiphy->wowlan = &priv->wowlan_support;
229 if (iwlwifi_mod_params.power_save)
230 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
232 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
234 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
235 /* we create the 802.11 header and a max-length SSID element */
236 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 34;
239 * We don't use all queues: 4 and 9 are unused and any
240 * aggregation queue gets mapped down to the AC queue.
242 hw->queues = IWLAGN_FIRST_AMPDU_QUEUE;
244 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
246 if (priv->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
247 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
248 &priv->nvm_data->bands[IEEE80211_BAND_2GHZ];
249 if (priv->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
250 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
251 &priv->nvm_data->bands[IEEE80211_BAND_5GHZ];
253 hw->wiphy->hw_version = priv->trans->hw_id;
257 ret = ieee80211_register_hw(priv->hw);
259 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
263 priv->mac80211_registered = 1;
268 void iwlagn_mac_unregister(struct iwl_priv *priv)
270 if (!priv->mac80211_registered)
273 ieee80211_unregister_hw(priv->hw);
274 priv->mac80211_registered = 0;
277 static int __iwl_up(struct iwl_priv *priv)
279 struct iwl_rxon_context *ctx;
282 lockdep_assert_held(&priv->mutex);
284 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
285 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
289 for_each_context(priv, ctx) {
290 ret = iwlagn_alloc_bcast_station(priv, ctx);
292 iwl_dealloc_bcast_stations(priv);
297 ret = iwl_run_init_ucode(priv);
299 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
303 ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
305 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
309 ret = iwl_alive_start(priv);
315 set_bit(STATUS_EXIT_PENDING, &priv->status);
317 clear_bit(STATUS_EXIT_PENDING, &priv->status);
319 IWL_ERR(priv, "Unable to initialize device.\n");
323 static int iwlagn_mac_start(struct ieee80211_hw *hw)
325 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
328 IWL_DEBUG_MAC80211(priv, "enter\n");
330 /* we should be verifying the device is ready to be opened */
331 mutex_lock(&priv->mutex);
332 ret = __iwl_up(priv);
333 mutex_unlock(&priv->mutex);
337 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
339 /* Now we should be done, and the READY bit should be set. */
340 if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
343 iwlagn_led_enable(priv);
346 IWL_DEBUG_MAC80211(priv, "leave\n");
350 static void iwlagn_mac_stop(struct ieee80211_hw *hw)
352 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
354 IWL_DEBUG_MAC80211(priv, "enter\n");
361 mutex_lock(&priv->mutex);
363 mutex_unlock(&priv->mutex);
365 iwl_cancel_deferred_work(priv);
367 flush_workqueue(priv->workqueue);
369 /* User space software may expect getting rfkill changes
370 * even if interface is down, trans->down will leave the RF
371 * kill interrupt enabled
373 iwl_trans_stop_hw(priv->trans, false);
375 IWL_DEBUG_MAC80211(priv, "leave\n");
378 static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
379 struct ieee80211_vif *vif,
380 struct cfg80211_gtk_rekey_data *data)
382 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
384 if (iwlwifi_mod_params.sw_crypto)
387 IWL_DEBUG_MAC80211(priv, "enter\n");
388 mutex_lock(&priv->mutex);
390 if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
393 memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
394 memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
396 cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
397 priv->have_rekey_data = true;
400 mutex_unlock(&priv->mutex);
401 IWL_DEBUG_MAC80211(priv, "leave\n");
404 #ifdef CONFIG_PM_SLEEP
406 static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
407 struct cfg80211_wowlan *wowlan)
409 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
410 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
413 if (WARN_ON(!wowlan))
416 IWL_DEBUG_MAC80211(priv, "enter\n");
417 mutex_lock(&priv->mutex);
419 /* Don't attempt WoWLAN when not associated, tear down instead. */
420 if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
421 !iwl_is_associated_ctx(ctx)) {
426 ret = iwlagn_suspend(priv, wowlan);
430 /* let the ucode operate on its own */
431 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET,
432 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
434 iwl_trans_d3_suspend(priv->trans, false);
439 priv->wowlan = false;
440 iwlagn_prepare_restart(priv);
441 ieee80211_restart_hw(priv->hw);
443 mutex_unlock(&priv->mutex);
444 IWL_DEBUG_MAC80211(priv, "leave\n");
449 struct iwl_resume_data {
450 struct iwl_priv *priv;
451 struct iwlagn_wowlan_status *cmd;
455 static bool iwl_resume_status_fn(struct iwl_notif_wait_data *notif_wait,
456 struct iwl_rx_packet *pkt, void *data)
458 struct iwl_resume_data *resume_data = data;
459 struct iwl_priv *priv = resume_data->priv;
460 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
462 if (len - 4 != sizeof(*resume_data->cmd)) {
463 IWL_ERR(priv, "rx wrong size data\n");
466 memcpy(resume_data->cmd, pkt->data, sizeof(*resume_data->cmd));
467 resume_data->valid = true;
472 static int iwlagn_mac_resume(struct ieee80211_hw *hw)
474 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
475 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
476 struct ieee80211_vif *vif;
479 enum iwl_d3_status d3_status;
480 struct error_table_start {
481 /* cf. struct iwl_error_event_table */
485 struct iwl_notification_wait status_wait;
486 static const u8 status_cmd[] = {
487 REPLY_WOWLAN_GET_STATUS,
489 struct iwlagn_wowlan_status status_data = {};
490 struct iwl_resume_data resume_data = {
495 struct cfg80211_wowlan_wakeup wakeup = {
498 #ifdef CONFIG_IWLWIFI_DEBUGFS
499 const struct fw_img *img;
502 IWL_DEBUG_MAC80211(priv, "enter\n");
503 mutex_lock(&priv->mutex);
505 /* we'll clear ctx->vif during iwlagn_prepare_restart() */
508 ret = iwl_trans_d3_resume(priv->trans, &d3_status, false);
512 if (d3_status != IWL_D3_STATUS_ALIVE) {
513 IWL_INFO(priv, "Device was reset during suspend\n");
517 /* uCode is no longer operating by itself */
518 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
519 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
521 base = priv->device_pointers.error_event_table;
522 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
523 IWL_WARN(priv, "Invalid error table during resume!\n");
527 iwl_trans_read_mem_bytes(priv->trans, base,
528 &err_info, sizeof(err_info));
530 if (err_info.valid) {
531 IWL_INFO(priv, "error table is valid (%d, 0x%x)\n",
532 err_info.valid, err_info.error_id);
533 if (err_info.error_id == RF_KILL_INDICATOR_FOR_WOWLAN) {
534 wakeup.rfkill_release = true;
535 ieee80211_report_wowlan_wakeup(vif, &wakeup,
541 #ifdef CONFIG_IWLWIFI_DEBUGFS
542 img = &priv->fw->img[IWL_UCODE_WOWLAN];
543 if (!priv->wowlan_sram)
545 kzalloc(img->sec[IWL_UCODE_SECTION_DATA].len,
548 if (priv->wowlan_sram)
549 iwl_trans_read_mem(priv->trans, 0x800000,
551 img->sec[IWL_UCODE_SECTION_DATA].len / 4);
555 * This is very strange. The GET_STATUS command is sent but the device
556 * doesn't reply properly, it seems it doesn't close the RBD so one is
557 * always left open ... As a result, we need to send another command
558 * and have to reset the driver afterwards. As we need to switch to
559 * runtime firmware again that'll happen.
562 iwl_init_notification_wait(&priv->notif_wait, &status_wait, status_cmd,
563 ARRAY_SIZE(status_cmd), iwl_resume_status_fn,
566 iwl_dvm_send_cmd_pdu(priv, REPLY_WOWLAN_GET_STATUS, CMD_ASYNC, 0, NULL);
567 iwl_dvm_send_cmd_pdu(priv, REPLY_ECHO, CMD_ASYNC, 0, NULL);
568 /* an RBD is left open in the firmware now! */
570 ret = iwl_wait_notification(&priv->notif_wait, &status_wait, HZ/5);
574 if (resume_data.valid && priv->contexts[IWL_RXON_CTX_BSS].vif) {
575 u32 reasons = le32_to_cpu(status_data.wakeup_reason);
576 struct cfg80211_wowlan_wakeup *wakeup_report;
578 IWL_INFO(priv, "WoWLAN wakeup reason(s): 0x%.8x\n", reasons);
581 if (reasons & IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET)
582 wakeup.magic_pkt = true;
583 if (reasons & IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH)
584 wakeup.pattern_idx = status_data.pattern_number;
585 if (reasons & (IWLAGN_WOWLAN_WAKEUP_BEACON_MISS |
586 IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE))
587 wakeup.disconnect = true;
588 if (reasons & IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL)
589 wakeup.gtk_rekey_failure = true;
590 if (reasons & IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ)
591 wakeup.eap_identity_req = true;
592 if (reasons & IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE)
593 wakeup.four_way_handshake = true;
594 wakeup_report = &wakeup;
596 wakeup_report = NULL;
599 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
602 priv->wowlan = false;
604 iwlagn_prepare_restart(priv);
606 memset((void *)&ctx->active, 0, sizeof(ctx->active));
607 iwl_connection_init_rx_config(priv, ctx);
608 iwlagn_set_rxon_chain(priv, ctx);
611 mutex_unlock(&priv->mutex);
612 IWL_DEBUG_MAC80211(priv, "leave\n");
614 ieee80211_resume_disconnect(vif);
619 static void iwlagn_mac_set_wakeup(struct ieee80211_hw *hw, bool enabled)
621 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
623 device_set_wakeup_enable(priv->trans->dev, enabled);
627 static void iwlagn_mac_tx(struct ieee80211_hw *hw,
628 struct ieee80211_tx_control *control,
631 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
633 if (iwlagn_tx_skb(priv, control->sta, skb))
634 ieee80211_free_txskb(hw, skb);
637 static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
638 struct ieee80211_vif *vif,
639 struct ieee80211_key_conf *keyconf,
640 struct ieee80211_sta *sta,
641 u32 iv32, u16 *phase1key)
643 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
645 iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
648 static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
649 struct ieee80211_vif *vif,
650 struct ieee80211_sta *sta,
651 struct ieee80211_key_conf *key)
653 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
654 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
655 struct iwl_rxon_context *ctx = vif_priv->ctx;
657 bool is_default_wep_key = false;
659 IWL_DEBUG_MAC80211(priv, "enter\n");
661 if (iwlwifi_mod_params.sw_crypto) {
662 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
666 switch (key->cipher) {
667 case WLAN_CIPHER_SUITE_TKIP:
668 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
670 case WLAN_CIPHER_SUITE_CCMP:
671 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
678 * We could program these keys into the hardware as well, but we
679 * don't expect much multicast traffic in IBSS and having keys
680 * for more stations is probably more useful.
682 * Mark key TX-only and return 0.
684 if (vif->type == NL80211_IFTYPE_ADHOC &&
685 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
686 key->hw_key_idx = WEP_INVALID_OFFSET;
690 /* If they key was TX-only, accept deletion */
691 if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
694 mutex_lock(&priv->mutex);
695 iwl_scan_cancel_timeout(priv, 100);
697 BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
700 * If we are getting WEP group key and we didn't receive any key mapping
701 * so far, we are in legacy wep mode (group key only), otherwise we are
703 * In legacy wep mode, we use another host command to the uCode.
705 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
706 key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
708 is_default_wep_key = !ctx->key_mapping_keys;
711 key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
717 if (is_default_wep_key) {
718 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
721 ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
724 * can't add key for RX, but we don't need it
725 * in the device for TX so still return 0
728 key->hw_key_idx = WEP_INVALID_OFFSET;
731 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
734 if (is_default_wep_key)
735 ret = iwl_remove_default_wep_key(priv, ctx, key);
737 ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
739 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
745 mutex_unlock(&priv->mutex);
746 IWL_DEBUG_MAC80211(priv, "leave\n");
751 static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
752 struct ieee80211_vif *vif,
753 enum ieee80211_ampdu_mlme_action action,
754 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
757 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
759 struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
761 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
764 if (!(priv->nvm_data->sku_cap_11n_enable))
767 IWL_DEBUG_MAC80211(priv, "enter\n");
768 mutex_lock(&priv->mutex);
771 case IEEE80211_AMPDU_RX_START:
772 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
774 IWL_DEBUG_HT(priv, "start Rx\n");
775 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
777 case IEEE80211_AMPDU_RX_STOP:
778 IWL_DEBUG_HT(priv, "stop Rx\n");
779 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
781 case IEEE80211_AMPDU_TX_START:
782 if (!priv->trans->ops->txq_enable)
784 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
786 IWL_DEBUG_HT(priv, "start Tx\n");
787 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
789 case IEEE80211_AMPDU_TX_STOP_FLUSH:
790 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
791 IWL_DEBUG_HT(priv, "Flush Tx\n");
792 ret = iwlagn_tx_agg_flush(priv, vif, sta, tid);
794 case IEEE80211_AMPDU_TX_STOP_CONT:
795 IWL_DEBUG_HT(priv, "stop Tx\n");
796 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
797 if ((ret == 0) && (priv->agg_tids_count > 0)) {
798 priv->agg_tids_count--;
799 IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
800 priv->agg_tids_count);
802 if (!priv->agg_tids_count &&
803 priv->hw_params.use_rts_for_aggregation) {
805 * switch off RTS/CTS if it was previously enabled
807 sta_priv->lq_sta.lq.general_params.flags &=
808 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
809 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
810 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
813 case IEEE80211_AMPDU_TX_OPERATIONAL:
814 ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size);
817 mutex_unlock(&priv->mutex);
818 IWL_DEBUG_MAC80211(priv, "leave\n");
822 static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
823 struct ieee80211_vif *vif,
824 struct ieee80211_sta *sta)
826 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
827 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
828 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
829 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
833 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
835 sta_priv->sta_id = IWL_INVALID_STATION;
837 atomic_set(&sta_priv->pending_frames, 0);
838 if (vif->type == NL80211_IFTYPE_AP)
839 sta_priv->client = true;
841 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
842 is_ap, sta, &sta_id);
844 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
846 /* Should we return success if return code is EEXIST ? */
850 sta_priv->sta_id = sta_id;
855 static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
856 struct ieee80211_vif *vif,
857 struct ieee80211_sta *sta)
859 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
860 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
863 IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr);
865 if (vif->type == NL80211_IFTYPE_STATION) {
867 * Station will be removed from device when the RXON
868 * is set to unassociated -- just deactivate it here
869 * to avoid re-programming it.
872 iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr);
874 ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
876 IWL_DEBUG_QUIET_RFKILL(priv,
877 "Error removing station %pM\n", sta->addr);
882 static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
883 struct ieee80211_vif *vif,
884 struct ieee80211_sta *sta,
885 enum ieee80211_sta_state old_state,
886 enum ieee80211_sta_state new_state)
888 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
889 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
891 NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT,
895 IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n",
896 sta->addr, old_state, new_state);
898 mutex_lock(&priv->mutex);
899 if (vif->type == NL80211_IFTYPE_STATION) {
900 if (old_state == IEEE80211_STA_NOTEXIST &&
901 new_state == IEEE80211_STA_NONE)
903 else if (old_state == IEEE80211_STA_NONE &&
904 new_state == IEEE80211_STA_NOTEXIST)
906 else if (old_state == IEEE80211_STA_AUTH &&
907 new_state == IEEE80211_STA_ASSOC)
910 if (old_state == IEEE80211_STA_AUTH &&
911 new_state == IEEE80211_STA_ASSOC)
913 else if (old_state == IEEE80211_STA_ASSOC &&
914 new_state == IEEE80211_STA_AUTH)
920 ret = iwlagn_mac_sta_add(hw, vif, sta);
924 * Clear the in-progress flag, the AP station entry was added
925 * but we'll initialize LQ only when we've associated (which
926 * would also clear the in-progress flag). This is necessary
927 * in case we never initialize LQ because association fails.
929 spin_lock_bh(&priv->sta_lock);
930 priv->stations[iwl_sta_id(sta)].used &=
931 ~IWL_STA_UCODE_INPROGRESS;
932 spin_unlock_bh(&priv->sta_lock);
935 ret = iwlagn_mac_sta_remove(hw, vif, sta);
938 ret = iwlagn_mac_sta_add(hw, vif, sta);
941 /* Initialize rate scaling */
943 "Initializing rate scaling for station %pM\n",
945 iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
949 /* Initialize rate scaling */
950 ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta);
954 "Initializing rate scaling for station %pM\n",
956 iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
965 * mac80211 might WARN if we fail, but due the way we
966 * (badly) handle hard rfkill, we might fail here
968 if (iwl_is_rfkill(priv))
971 mutex_unlock(&priv->mutex);
972 IWL_DEBUG_MAC80211(priv, "leave\n");
977 static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
978 struct ieee80211_channel_switch *ch_switch)
980 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
981 struct ieee80211_conf *conf = &hw->conf;
982 struct ieee80211_channel *channel = ch_switch->chandef.chan;
983 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
986 * When we add support for multiple interfaces, we need to
987 * revisit this. The channel switch command in the device
988 * only affects the BSS context, but what does that really
989 * mean? And what if we get a CSA on the second interface?
990 * This needs a lot of work.
992 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
995 IWL_DEBUG_MAC80211(priv, "enter\n");
997 mutex_lock(&priv->mutex);
999 if (iwl_is_rfkill(priv))
1002 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
1003 test_bit(STATUS_SCANNING, &priv->status) ||
1004 test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
1007 if (!iwl_is_associated_ctx(ctx))
1010 if (!priv->lib->set_channel_switch)
1013 ch = channel->hw_value;
1014 if (le16_to_cpu(ctx->active.channel) == ch)
1017 priv->current_ht_config.smps = conf->smps_mode;
1019 /* Configure HT40 channels */
1020 switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
1021 case NL80211_CHAN_NO_HT:
1022 case NL80211_CHAN_HT20:
1023 ctx->ht.is_40mhz = false;
1024 ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1026 case NL80211_CHAN_HT40MINUS:
1027 ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1028 ctx->ht.is_40mhz = true;
1030 case NL80211_CHAN_HT40PLUS:
1031 ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1032 ctx->ht.is_40mhz = true;
1036 if ((le16_to_cpu(ctx->staging.channel) != ch))
1037 ctx->staging.flags = 0;
1039 iwl_set_rxon_channel(priv, channel, ctx);
1040 iwl_set_rxon_ht(priv, ht_conf);
1041 iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
1044 * at this point, staging_rxon has the
1045 * configuration for channel switch
1047 set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
1048 priv->switch_channel = cpu_to_le16(ch);
1049 if (priv->lib->set_channel_switch(priv, ch_switch)) {
1050 clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
1051 priv->switch_channel = 0;
1052 ieee80211_chswitch_done(ctx->vif, false);
1056 mutex_unlock(&priv->mutex);
1057 IWL_DEBUG_MAC80211(priv, "leave\n");
1060 void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
1064 * See iwlagn_mac_channel_switch.
1066 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1068 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1071 if (!test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
1075 ieee80211_chswitch_done(ctx->vif, is_success);
1078 static void iwlagn_configure_filter(struct ieee80211_hw *hw,
1079 unsigned int changed_flags,
1080 unsigned int *total_flags,
1083 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1084 __le32 filter_or = 0, filter_nand = 0;
1085 struct iwl_rxon_context *ctx;
1087 #define CHK(test, flag) do { \
1088 if (*total_flags & (test)) \
1089 filter_or |= (flag); \
1091 filter_nand |= (flag); \
1094 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
1095 changed_flags, *total_flags);
1097 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
1098 /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
1099 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
1100 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
1104 mutex_lock(&priv->mutex);
1106 for_each_context(priv, ctx) {
1107 ctx->staging.filter_flags &= ~filter_nand;
1108 ctx->staging.filter_flags |= filter_or;
1111 * Not committing directly because hardware can perform a scan,
1112 * but we'll eventually commit the filter flags change anyway.
1116 mutex_unlock(&priv->mutex);
1119 * Receiving all multicast frames is always enabled by the
1120 * default flags setup in iwl_connection_init_rx_config()
1121 * since we currently do not support programming multicast
1122 * filters into the device.
1124 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
1125 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
1128 static void iwlagn_mac_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1130 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1132 mutex_lock(&priv->mutex);
1133 IWL_DEBUG_MAC80211(priv, "enter\n");
1135 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1136 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
1139 if (iwl_is_rfkill(priv)) {
1140 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
1145 * mac80211 will not push any more frames for transmit
1146 * until the flush is completed
1149 IWL_DEBUG_MAC80211(priv, "send flush command\n");
1150 if (iwlagn_txfifo_flush(priv, 0)) {
1151 IWL_ERR(priv, "flush request fail\n");
1155 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
1156 iwl_trans_wait_tx_queue_empty(priv->trans);
1158 mutex_unlock(&priv->mutex);
1159 IWL_DEBUG_MAC80211(priv, "leave\n");
1162 static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
1163 struct ieee80211_vif *vif,
1164 struct ieee80211_channel *channel,
1166 enum ieee80211_roc_type type)
1168 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1169 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
1172 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
1175 if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
1178 IWL_DEBUG_MAC80211(priv, "enter\n");
1179 mutex_lock(&priv->mutex);
1181 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
1182 /* mac80211 should not scan while ROC or ROC while scanning */
1183 if (WARN_ON_ONCE(priv->scan_type != IWL_SCAN_RADIO_RESET)) {
1188 iwl_scan_cancel_timeout(priv, 100);
1190 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
1196 priv->hw_roc_channel = channel;
1197 /* convert from ms to TU */
1198 priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
1199 priv->hw_roc_start_notified = false;
1200 cancel_delayed_work(&priv->hw_roc_disable_work);
1202 if (!ctx->is_active) {
1203 static const struct iwl_qos_info default_qos_data = {
1206 .cw_min = cpu_to_le16(3),
1207 .cw_max = cpu_to_le16(7),
1209 .edca_txop = cpu_to_le16(1504),
1212 .cw_min = cpu_to_le16(7),
1213 .cw_max = cpu_to_le16(15),
1215 .edca_txop = cpu_to_le16(3008),
1218 .cw_min = cpu_to_le16(15),
1219 .cw_max = cpu_to_le16(1023),
1223 .cw_min = cpu_to_le16(15),
1224 .cw_max = cpu_to_le16(1023),
1230 ctx->is_active = true;
1231 ctx->qos_data = default_qos_data;
1232 ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
1233 memcpy(ctx->staging.node_addr,
1234 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
1236 memcpy(ctx->staging.bssid_addr,
1237 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
1239 err = iwlagn_commit_rxon(priv, ctx);
1242 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
1243 RXON_FILTER_PROMISC_MSK |
1244 RXON_FILTER_CTL2HOST_MSK;
1246 err = iwlagn_commit_rxon(priv, ctx);
1248 iwlagn_disable_roc(priv);
1251 priv->hw_roc_setup = true;
1254 err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
1256 iwlagn_disable_roc(priv);
1259 mutex_unlock(&priv->mutex);
1260 IWL_DEBUG_MAC80211(priv, "leave\n");
1265 static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
1267 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1269 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
1272 IWL_DEBUG_MAC80211(priv, "enter\n");
1273 mutex_lock(&priv->mutex);
1274 iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
1275 iwlagn_disable_roc(priv);
1276 mutex_unlock(&priv->mutex);
1277 IWL_DEBUG_MAC80211(priv, "leave\n");
1282 static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
1283 struct ieee80211_vif *vif,
1284 enum ieee80211_rssi_event rssi_event)
1286 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1288 IWL_DEBUG_MAC80211(priv, "enter\n");
1289 mutex_lock(&priv->mutex);
1291 if (priv->lib->bt_params &&
1292 priv->lib->bt_params->advanced_bt_coexist) {
1293 if (rssi_event == RSSI_EVENT_LOW)
1294 priv->bt_enable_pspoll = true;
1295 else if (rssi_event == RSSI_EVENT_HIGH)
1296 priv->bt_enable_pspoll = false;
1298 iwlagn_send_advance_bt_config(priv);
1300 IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
1301 "ignoring RSSI callback\n");
1304 mutex_unlock(&priv->mutex);
1305 IWL_DEBUG_MAC80211(priv, "leave\n");
1308 static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
1309 struct ieee80211_sta *sta, bool set)
1311 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1313 queue_work(priv->workqueue, &priv->beacon_update);
1318 static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
1319 struct ieee80211_vif *vif, u16 queue,
1320 const struct ieee80211_tx_queue_params *params)
1322 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1323 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1324 struct iwl_rxon_context *ctx = vif_priv->ctx;
1330 IWL_DEBUG_MAC80211(priv, "enter\n");
1332 if (!iwl_is_ready_rf(priv)) {
1333 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1337 if (queue >= AC_NUM) {
1338 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1342 q = AC_NUM - 1 - queue;
1344 mutex_lock(&priv->mutex);
1346 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1347 cpu_to_le16(params->cw_min);
1348 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1349 cpu_to_le16(params->cw_max);
1350 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1351 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1352 cpu_to_le16((params->txop * 32));
1354 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1356 mutex_unlock(&priv->mutex);
1358 IWL_DEBUG_MAC80211(priv, "leave\n");
1362 static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
1364 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1366 return priv->ibss_manager == IWL_IBSS_MANAGER;
1369 static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1371 iwl_connection_init_rx_config(priv, ctx);
1373 iwlagn_set_rxon_chain(priv, ctx);
1375 return iwlagn_commit_rxon(priv, ctx);
1378 static int iwl_setup_interface(struct iwl_priv *priv,
1379 struct iwl_rxon_context *ctx)
1381 struct ieee80211_vif *vif = ctx->vif;
1384 lockdep_assert_held(&priv->mutex);
1387 * This variable will be correct only when there's just
1388 * a single context, but all code using it is for hardware
1389 * that supports only one context.
1391 priv->iw_mode = vif->type;
1393 ctx->is_active = true;
1395 err = iwl_set_mode(priv, ctx);
1397 if (!ctx->always_active)
1398 ctx->is_active = false;
1402 if (priv->lib->bt_params && priv->lib->bt_params->advanced_bt_coexist &&
1403 vif->type == NL80211_IFTYPE_ADHOC) {
1405 * pretend to have high BT traffic as long as we
1406 * are operating in IBSS mode, as this will cause
1407 * the rate scaling etc. to behave as intended.
1409 priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
1412 /* set up queue mappings */
1413 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1414 vif->hw_queue[ac] = ctx->ac_to_queue[ac];
1416 if (vif->type == NL80211_IFTYPE_AP)
1417 vif->cab_queue = ctx->mcast_queue;
1419 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
1424 static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1425 struct ieee80211_vif *vif)
1427 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1428 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1429 struct iwl_rxon_context *tmp, *ctx = NULL;
1431 enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
1434 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
1435 viftype, vif->addr);
1437 cancel_delayed_work_sync(&priv->hw_roc_disable_work);
1439 mutex_lock(&priv->mutex);
1441 iwlagn_disable_roc(priv);
1443 if (!iwl_is_ready_rf(priv)) {
1444 IWL_WARN(priv, "Try to add interface when device not ready\n");
1449 for_each_context(priv, tmp) {
1450 u32 possible_modes =
1451 tmp->interface_modes | tmp->exclusive_interface_modes;
1454 /* On reset we need to add the same interface again */
1455 if (tmp->vif == vif) {
1461 /* check if this busy context is exclusive */
1462 if (tmp->exclusive_interface_modes &
1463 BIT(tmp->vif->type)) {
1470 if (!(possible_modes & BIT(viftype)))
1473 /* have maybe usable context w/o interface */
1483 vif_priv->ctx = ctx;
1487 * In SNIFFER device type, the firmware reports the FCS to
1488 * the host, rather than snipping it off. Unfortunately,
1489 * mac80211 doesn't (yet) provide a per-packet flag for
1490 * this, so that we have to set the hardware flag based
1491 * on the interfaces added. As the monitor interface can
1492 * only be present by itself, and will be removed before
1493 * other interfaces are added, this is safe.
1495 if (vif->type == NL80211_IFTYPE_MONITOR)
1496 priv->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS;
1498 priv->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1500 err = iwl_setup_interface(priv, ctx);
1505 priv->iw_mode = NL80211_IFTYPE_STATION;
1507 mutex_unlock(&priv->mutex);
1509 IWL_DEBUG_MAC80211(priv, "leave\n");
1513 static void iwl_teardown_interface(struct iwl_priv *priv,
1514 struct ieee80211_vif *vif,
1517 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1519 lockdep_assert_held(&priv->mutex);
1521 if (priv->scan_vif == vif) {
1522 iwl_scan_cancel_timeout(priv, 200);
1523 iwl_force_scan_end(priv);
1527 iwl_set_mode(priv, ctx);
1528 if (!ctx->always_active)
1529 ctx->is_active = false;
1533 * When removing the IBSS interface, overwrite the
1534 * BT traffic load with the stored one from the last
1535 * notification, if any. If this is a device that
1536 * doesn't implement this, this has no effect since
1537 * both values are the same and zero.
1539 if (vif->type == NL80211_IFTYPE_ADHOC)
1540 priv->bt_traffic_load = priv->last_bt_traffic_load;
1543 static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
1544 struct ieee80211_vif *vif)
1546 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1547 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1549 IWL_DEBUG_MAC80211(priv, "enter\n");
1551 mutex_lock(&priv->mutex);
1553 if (WARN_ON(ctx->vif != vif)) {
1554 struct iwl_rxon_context *tmp;
1555 IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
1556 for_each_context(priv, tmp)
1557 IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
1558 tmp->ctxid, tmp, tmp->vif);
1562 iwl_teardown_interface(priv, vif, false);
1564 mutex_unlock(&priv->mutex);
1566 IWL_DEBUG_MAC80211(priv, "leave\n");
1570 static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
1571 struct ieee80211_vif *vif,
1572 enum nl80211_iftype newtype, bool newp2p)
1574 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1575 struct iwl_rxon_context *ctx, *tmp;
1576 enum nl80211_iftype newviftype = newtype;
1577 u32 interface_modes;
1580 IWL_DEBUG_MAC80211(priv, "enter\n");
1582 newtype = ieee80211_iftype_p2p(newtype, newp2p);
1584 mutex_lock(&priv->mutex);
1586 ctx = iwl_rxon_ctx_from_vif(vif);
1589 * To simplify this code, only support changes on the
1590 * BSS context. The PAN context is usually reassigned
1591 * by creating/removing P2P interfaces anyway.
1593 if (ctx->ctxid != IWL_RXON_CTX_BSS) {
1598 if (!ctx->vif || !iwl_is_ready_rf(priv)) {
1600 * Huh? But wait ... this can maybe happen when
1601 * we're in the middle of a firmware restart!
1607 /* Check if the switch is supported in the same context */
1608 interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
1609 if (!(interface_modes & BIT(newtype))) {
1614 if (ctx->exclusive_interface_modes & BIT(newtype)) {
1615 for_each_context(priv, tmp) {
1619 if (!tmp->is_active)
1623 * The current mode switch would be exclusive, but
1624 * another context is active ... refuse the switch.
1632 iwl_teardown_interface(priv, vif, true);
1633 vif->type = newviftype;
1635 err = iwl_setup_interface(priv, ctx);
1638 * We've switched internally, but submitting to the
1639 * device may have failed for some reason. Mask this
1640 * error, because otherwise mac80211 will not switch
1641 * (and set the interface type back) and we'll be
1642 * out of sync with it.
1647 mutex_unlock(&priv->mutex);
1648 IWL_DEBUG_MAC80211(priv, "leave\n");
1653 static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
1654 struct ieee80211_vif *vif,
1655 struct cfg80211_scan_request *req)
1657 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1660 IWL_DEBUG_MAC80211(priv, "enter\n");
1662 if (req->n_channels == 0)
1665 mutex_lock(&priv->mutex);
1668 * If an internal scan is in progress, just set
1669 * up the scan_request as per above.
1671 if (priv->scan_type != IWL_SCAN_NORMAL) {
1672 IWL_DEBUG_SCAN(priv,
1673 "SCAN request during internal scan - defer\n");
1674 priv->scan_request = req;
1675 priv->scan_vif = vif;
1678 priv->scan_request = req;
1679 priv->scan_vif = vif;
1681 * mac80211 will only ask for one band at a time
1682 * so using channels[0] here is ok
1684 ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
1685 req->channels[0]->band);
1687 priv->scan_request = NULL;
1688 priv->scan_vif = NULL;
1692 IWL_DEBUG_MAC80211(priv, "leave\n");
1694 mutex_unlock(&priv->mutex);
1699 static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1701 struct iwl_addsta_cmd cmd = {
1702 .mode = STA_CONTROL_MODIFY_MSK,
1703 .station_flags_msk = STA_FLG_PWR_SAVE_MSK,
1704 .sta.sta_id = sta_id,
1707 iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
1710 static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
1711 struct ieee80211_vif *vif,
1712 enum sta_notify_cmd cmd,
1713 struct ieee80211_sta *sta)
1715 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1716 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1719 IWL_DEBUG_MAC80211(priv, "enter\n");
1722 case STA_NOTIFY_SLEEP:
1723 WARN_ON(!sta_priv->client);
1724 sta_priv->asleep = true;
1725 if (atomic_read(&sta_priv->pending_frames) > 0)
1726 ieee80211_sta_block_awake(hw, sta, true);
1728 case STA_NOTIFY_AWAKE:
1729 WARN_ON(!sta_priv->client);
1730 if (!sta_priv->asleep)
1732 sta_priv->asleep = false;
1733 sta_id = iwl_sta_id(sta);
1734 if (sta_id != IWL_INVALID_STATION)
1735 iwl_sta_modify_ps_wake(priv, sta_id);
1740 IWL_DEBUG_MAC80211(priv, "leave\n");
1743 struct ieee80211_ops iwlagn_hw_ops = {
1744 .tx = iwlagn_mac_tx,
1745 .start = iwlagn_mac_start,
1746 .stop = iwlagn_mac_stop,
1747 #ifdef CONFIG_PM_SLEEP
1748 .suspend = iwlagn_mac_suspend,
1749 .resume = iwlagn_mac_resume,
1750 .set_wakeup = iwlagn_mac_set_wakeup,
1752 .add_interface = iwlagn_mac_add_interface,
1753 .remove_interface = iwlagn_mac_remove_interface,
1754 .change_interface = iwlagn_mac_change_interface,
1755 .config = iwlagn_mac_config,
1756 .configure_filter = iwlagn_configure_filter,
1757 .set_key = iwlagn_mac_set_key,
1758 .update_tkip_key = iwlagn_mac_update_tkip_key,
1759 .set_rekey_data = iwlagn_mac_set_rekey_data,
1760 .conf_tx = iwlagn_mac_conf_tx,
1761 .bss_info_changed = iwlagn_bss_info_changed,
1762 .ampdu_action = iwlagn_mac_ampdu_action,
1763 .hw_scan = iwlagn_mac_hw_scan,
1764 .sta_notify = iwlagn_mac_sta_notify,
1765 .sta_state = iwlagn_mac_sta_state,
1766 .channel_switch = iwlagn_mac_channel_switch,
1767 .flush = iwlagn_mac_flush,
1768 .tx_last_beacon = iwlagn_mac_tx_last_beacon,
1769 .remain_on_channel = iwlagn_mac_remain_on_channel,
1770 .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
1771 .rssi_callback = iwlagn_mac_rssi_callback,
1772 .set_tim = iwlagn_mac_set_tim,
1775 /* This function both allocates and initializes hw and priv. */
1776 struct ieee80211_hw *iwl_alloc_all(void)
1778 struct iwl_priv *priv;
1779 struct iwl_op_mode *op_mode;
1780 /* mac80211 allocates memory for this device instance, including
1781 * space for this driver's private structure */
1782 struct ieee80211_hw *hw;
1784 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
1785 sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
1790 priv = IWL_OP_MODE_GET_DVM(op_mode);