1 /******************************************************************************
3 * Copyright(c) 2003 - 2011 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/firmware.h>
39 #include <linux/etherdevice.h>
40 #include <linux/if_arp.h>
42 #include <net/mac80211.h>
44 #include <asm/div64.h>
46 #include "iwl-eeprom.h"
50 #include "iwl-agn-calib.h"
52 #include "iwl-shared.h"
54 #include "iwl-trans.h"
56 /*****************************************************************************
58 * mac80211 entry point functions
60 *****************************************************************************/
62 static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
65 .types = BIT(NL80211_IFTYPE_STATION),
69 .types = BIT(NL80211_IFTYPE_AP),
73 static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
76 .types = BIT(NL80211_IFTYPE_STATION),
80 static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
83 .types = BIT(NL80211_IFTYPE_STATION),
87 .types = BIT(NL80211_IFTYPE_P2P_GO) |
88 BIT(NL80211_IFTYPE_AP),
92 static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
95 .types = BIT(NL80211_IFTYPE_STATION),
99 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
103 static const struct ieee80211_iface_combination
104 iwlagn_iface_combinations_dualmode[] = {
105 { .num_different_channels = 1,
107 .beacon_int_infra_match = true,
108 .limits = iwlagn_sta_ap_limits,
109 .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
111 { .num_different_channels = 1,
113 .limits = iwlagn_2sta_limits,
114 .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
118 static const struct ieee80211_iface_combination
119 iwlagn_iface_combinations_p2p[] = {
120 { .num_different_channels = 1,
122 .beacon_int_infra_match = true,
123 .limits = iwlagn_p2p_sta_go_limits,
124 .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
126 { .num_different_channels = 1,
128 .limits = iwlagn_p2p_2sta_limits,
129 .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
134 * Not a mac80211 entry point function, but it fits in with all the
135 * other mac80211 functions grouped here.
137 int iwlagn_mac_setup_register(struct iwl_priv *priv,
138 struct iwlagn_ucode_capabilities *capa)
141 struct ieee80211_hw *hw = priv->hw;
142 struct iwl_rxon_context *ctx;
144 hw->rate_control_algorithm = "iwl-agn-rs";
146 /* Tell mac80211 our characteristics */
147 hw->flags = IEEE80211_HW_SIGNAL_DBM |
148 IEEE80211_HW_AMPDU_AGGREGATION |
149 IEEE80211_HW_NEED_DTIM_PERIOD |
150 IEEE80211_HW_SPECTRUM_MGMT |
151 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
154 * Including the following line will crash some AP's. This
155 * workaround removes the stimulus which causes the crash until
156 * the AP software can be fixed.
157 hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
160 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
161 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
163 if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
164 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
165 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
167 if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
168 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
170 hw->sta_data_size = sizeof(struct iwl_station_priv);
171 hw->vif_data_size = sizeof(struct iwl_vif_priv);
173 for_each_context(priv, ctx) {
174 hw->wiphy->interface_modes |= ctx->interface_modes;
175 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
178 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
180 if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
181 hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
182 hw->wiphy->n_iface_combinations =
183 ARRAY_SIZE(iwlagn_iface_combinations_p2p);
184 } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
185 hw->wiphy->iface_combinations =
186 iwlagn_iface_combinations_dualmode;
187 hw->wiphy->n_iface_combinations =
188 ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
191 hw->wiphy->max_remain_on_channel_duration = 1000;
193 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
194 WIPHY_FLAG_DISABLE_BEACON_HINTS |
197 if (trans(priv)->ucode_wowlan.code.len &&
198 device_can_wakeup(bus(priv)->dev)) {
199 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
200 WIPHY_WOWLAN_DISCONNECT |
201 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
202 WIPHY_WOWLAN_RFKILL_RELEASE;
203 if (!iwlagn_mod_params.sw_crypto)
204 hw->wiphy->wowlan.flags |=
205 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
206 WIPHY_WOWLAN_GTK_REKEY_FAILURE;
208 hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
209 hw->wiphy->wowlan.pattern_min_len =
210 IWLAGN_WOWLAN_MIN_PATTERN_LEN;
211 hw->wiphy->wowlan.pattern_max_len =
212 IWLAGN_WOWLAN_MAX_PATTERN_LEN;
215 if (iwlagn_mod_params.power_save)
216 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
218 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
220 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
221 /* we create the 802.11 header and a zero-length SSID element */
222 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
224 /* Default value; 4 EDCA QOS priorities */
227 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
229 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
230 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
231 &priv->bands[IEEE80211_BAND_2GHZ];
232 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
233 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
234 &priv->bands[IEEE80211_BAND_5GHZ];
238 ret = ieee80211_register_hw(priv->hw);
240 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
243 priv->mac80211_registered = 1;
248 static int __iwl_up(struct iwl_priv *priv)
250 struct iwl_rxon_context *ctx;
253 lockdep_assert_held(&priv->shrd->mutex);
255 if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
256 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
260 for_each_context(priv, ctx) {
261 ret = iwlagn_alloc_bcast_station(priv, ctx);
263 iwl_dealloc_bcast_stations(priv);
268 ret = iwlagn_run_init_ucode(priv);
270 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
274 ret = iwlagn_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
276 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
280 ret = iwl_alive_start(priv);
286 set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
288 clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
290 IWL_ERR(priv, "Unable to initialize device.\n");
294 static int iwlagn_mac_start(struct ieee80211_hw *hw)
296 struct iwl_priv *priv = hw->priv;
299 IWL_DEBUG_MAC80211(priv, "enter\n");
301 /* we should be verifying the device is ready to be opened */
302 mutex_lock(&priv->shrd->mutex);
303 ret = __iwl_up(priv);
304 mutex_unlock(&priv->shrd->mutex);
308 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
310 /* Now we should be done, and the READY bit should be set. */
311 if (WARN_ON(!test_bit(STATUS_READY, &priv->shrd->status)))
314 iwlagn_led_enable(priv);
317 IWL_DEBUG_MAC80211(priv, "leave\n");
321 static void iwlagn_mac_stop(struct ieee80211_hw *hw)
323 struct iwl_priv *priv = hw->priv;
325 IWL_DEBUG_MAC80211(priv, "enter\n");
334 flush_workqueue(priv->shrd->workqueue);
336 /* User space software may expect getting rfkill changes
337 * even if interface is down */
338 iwl_write32(bus(priv), CSR_INT, 0xFFFFFFFF);
339 iwl_enable_rfkill_int(priv);
341 IWL_DEBUG_MAC80211(priv, "leave\n");
344 static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
345 struct ieee80211_vif *vif,
346 struct cfg80211_gtk_rekey_data *data)
348 struct iwl_priv *priv = hw->priv;
350 if (iwlagn_mod_params.sw_crypto)
353 IWL_DEBUG_MAC80211(priv, "enter\n");
354 mutex_lock(&priv->shrd->mutex);
356 if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
359 memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
360 memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
362 cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
363 priv->have_rekey_data = true;
366 mutex_unlock(&priv->shrd->mutex);
367 IWL_DEBUG_MAC80211(priv, "leave\n");
370 #ifdef CONFIG_PM_SLEEP
372 static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
373 struct cfg80211_wowlan *wowlan)
375 struct iwl_priv *priv = hw->priv;
376 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
379 if (WARN_ON(!wowlan))
382 IWL_DEBUG_MAC80211(priv, "enter\n");
383 mutex_lock(&priv->shrd->mutex);
385 /* Don't attempt WoWLAN when not associated, tear down instead. */
386 if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
387 !iwl_is_associated_ctx(ctx)) {
392 ret = iwlagn_suspend(priv, hw, wowlan);
396 device_set_wakeup_enable(bus(priv)->dev, true);
398 /* Now let the ucode operate on its own */
399 iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_SET,
400 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
405 priv->shrd->wowlan = false;
406 iwlagn_prepare_restart(priv);
407 ieee80211_restart_hw(priv->hw);
409 mutex_unlock(&priv->shrd->mutex);
410 IWL_DEBUG_MAC80211(priv, "leave\n");
415 static int iwlagn_mac_resume(struct ieee80211_hw *hw)
417 struct iwl_priv *priv = hw->priv;
418 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
419 struct ieee80211_vif *vif;
421 u32 base, status = 0xffffffff;
424 IWL_DEBUG_MAC80211(priv, "enter\n");
425 mutex_lock(&priv->shrd->mutex);
427 iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_CLR,
428 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
430 base = priv->shrd->device_pointers.error_event_table;
431 if (iwlagn_hw_valid_rtc_data_addr(base)) {
432 spin_lock_irqsave(&bus(priv)->reg_lock, flags);
433 ret = iwl_grab_nic_access_silent(bus(priv));
435 iwl_write32(bus(priv), HBUS_TARG_MEM_RADDR, base);
436 status = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
437 iwl_release_nic_access(bus(priv));
439 spin_unlock_irqrestore(&bus(priv)->reg_lock, flags);
441 #ifdef CONFIG_IWLWIFI_DEBUGFS
443 struct iwl_trans *trans = trans(priv);
444 if (!priv->wowlan_sram)
446 kzalloc(trans->ucode_wowlan.data.len,
449 if (priv->wowlan_sram)
450 _iwl_read_targ_mem_words(
451 bus(priv), 0x800000, priv->wowlan_sram,
452 trans->ucode_wowlan.data.len / 4);
457 /* we'll clear ctx->vif during iwlagn_prepare_restart() */
460 priv->shrd->wowlan = false;
462 device_set_wakeup_enable(bus(priv)->dev, false);
464 iwlagn_prepare_restart(priv);
466 memset((void *)&ctx->active, 0, sizeof(ctx->active));
467 iwl_connection_init_rx_config(priv, ctx);
468 iwlagn_set_rxon_chain(priv, ctx);
470 mutex_unlock(&priv->shrd->mutex);
471 IWL_DEBUG_MAC80211(priv, "leave\n");
473 ieee80211_resume_disconnect(vif);
480 static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
482 struct iwl_priv *priv = hw->priv;
484 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
485 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
487 if (iwlagn_tx_skb(priv, skb))
488 dev_kfree_skb_any(skb);
491 static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
492 struct ieee80211_vif *vif,
493 struct ieee80211_key_conf *keyconf,
494 struct ieee80211_sta *sta,
495 u32 iv32, u16 *phase1key)
497 struct iwl_priv *priv = hw->priv;
499 iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
502 static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
503 struct ieee80211_vif *vif,
504 struct ieee80211_sta *sta,
505 struct ieee80211_key_conf *key)
507 struct iwl_priv *priv = hw->priv;
508 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
509 struct iwl_rxon_context *ctx = vif_priv->ctx;
511 bool is_default_wep_key = false;
513 IWL_DEBUG_MAC80211(priv, "enter\n");
515 if (iwlagn_mod_params.sw_crypto) {
516 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
520 switch (key->cipher) {
521 case WLAN_CIPHER_SUITE_TKIP:
522 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
524 case WLAN_CIPHER_SUITE_CCMP:
525 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
532 * We could program these keys into the hardware as well, but we
533 * don't expect much multicast traffic in IBSS and having keys
534 * for more stations is probably more useful.
536 * Mark key TX-only and return 0.
538 if (vif->type == NL80211_IFTYPE_ADHOC &&
539 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
540 key->hw_key_idx = WEP_INVALID_OFFSET;
544 /* If they key was TX-only, accept deletion */
545 if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
548 mutex_lock(&priv->shrd->mutex);
549 iwl_scan_cancel_timeout(priv, 100);
551 BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
554 * If we are getting WEP group key and we didn't receive any key mapping
555 * so far, we are in legacy wep mode (group key only), otherwise we are
557 * In legacy wep mode, we use another host command to the uCode.
559 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
560 key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
562 is_default_wep_key = !ctx->key_mapping_keys;
565 key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
571 if (is_default_wep_key) {
572 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
575 ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
578 * can't add key for RX, but we don't need it
579 * in the device for TX so still return 0
582 key->hw_key_idx = WEP_INVALID_OFFSET;
585 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
588 if (is_default_wep_key)
589 ret = iwl_remove_default_wep_key(priv, ctx, key);
591 ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
593 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
599 mutex_unlock(&priv->shrd->mutex);
600 IWL_DEBUG_MAC80211(priv, "leave\n");
605 static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
606 struct ieee80211_vif *vif,
607 enum ieee80211_ampdu_mlme_action action,
608 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
611 struct iwl_priv *priv = hw->priv;
613 struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
614 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
616 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
619 if (!(priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE))
622 IWL_DEBUG_MAC80211(priv, "enter\n");
623 mutex_lock(&priv->shrd->mutex);
626 case IEEE80211_AMPDU_RX_START:
627 IWL_DEBUG_HT(priv, "start Rx\n");
628 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
630 case IEEE80211_AMPDU_RX_STOP:
631 IWL_DEBUG_HT(priv, "stop Rx\n");
632 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
633 if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
636 case IEEE80211_AMPDU_TX_START:
637 IWL_DEBUG_HT(priv, "start Tx\n");
638 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
640 case IEEE80211_AMPDU_TX_STOP:
641 IWL_DEBUG_HT(priv, "stop Tx\n");
642 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
643 if ((ret == 0) && (priv->agg_tids_count > 0)) {
644 priv->agg_tids_count--;
645 IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
646 priv->agg_tids_count);
648 if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
650 if (!priv->agg_tids_count && priv->cfg->ht_params &&
651 priv->cfg->ht_params->use_rts_for_aggregation) {
653 * switch off RTS/CTS if it was previously enabled
655 sta_priv->lq_sta.lq.general_params.flags &=
656 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
657 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
658 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
661 case IEEE80211_AMPDU_TX_OPERATIONAL:
662 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
664 iwl_trans_tx_agg_setup(trans(priv), ctx->ctxid, iwl_sta_id(sta),
668 * If the limit is 0, then it wasn't initialised yet,
669 * use the default. We can do that since we take the
670 * minimum below, and we don't want to go above our
671 * default due to hardware restrictions.
673 if (sta_priv->max_agg_bufsize == 0)
674 sta_priv->max_agg_bufsize =
675 LINK_QUAL_AGG_FRAME_LIMIT_DEF;
678 * Even though in theory the peer could have different
679 * aggregation reorder buffer sizes for different sessions,
680 * our ucode doesn't allow for that and has a global limit
681 * for each station. Therefore, use the minimum of all the
682 * aggregation sessions and our default value.
684 sta_priv->max_agg_bufsize =
685 min(sta_priv->max_agg_bufsize, buf_size);
687 if (priv->cfg->ht_params &&
688 priv->cfg->ht_params->use_rts_for_aggregation) {
690 * switch to RTS/CTS if it is the prefer protection
691 * method for HT traffic
694 sta_priv->lq_sta.lq.general_params.flags |=
695 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
697 priv->agg_tids_count++;
698 IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
699 priv->agg_tids_count);
701 sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
702 sta_priv->max_agg_bufsize;
704 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
705 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
707 IWL_INFO(priv, "Tx aggregation enabled on ra = %pM tid = %d\n",
712 mutex_unlock(&priv->shrd->mutex);
713 IWL_DEBUG_MAC80211(priv, "leave\n");
717 static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
718 struct ieee80211_vif *vif,
719 struct ieee80211_sta *sta)
721 struct iwl_priv *priv = hw->priv;
722 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
723 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
724 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
728 IWL_DEBUG_MAC80211(priv, "received request to add station %pM\n",
730 mutex_lock(&priv->shrd->mutex);
731 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
733 sta_priv->sta_id = IWL_INVALID_STATION;
735 atomic_set(&sta_priv->pending_frames, 0);
736 if (vif->type == NL80211_IFTYPE_AP)
737 sta_priv->client = true;
739 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
740 is_ap, sta, &sta_id);
742 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
744 /* Should we return success if return code is EEXIST ? */
748 sta_priv->sta_id = sta_id;
750 /* Initialize rate scaling */
751 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
753 iwl_rs_rate_init(priv, sta, sta_id);
755 mutex_unlock(&priv->shrd->mutex);
756 IWL_DEBUG_MAC80211(priv, "leave\n");
761 static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
762 struct ieee80211_channel_switch *ch_switch)
764 struct iwl_priv *priv = hw->priv;
765 const struct iwl_channel_info *ch_info;
766 struct ieee80211_conf *conf = &hw->conf;
767 struct ieee80211_channel *channel = ch_switch->channel;
768 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
771 * When we add support for multiple interfaces, we need to
772 * revisit this. The channel switch command in the device
773 * only affects the BSS context, but what does that really
774 * mean? And what if we get a CSA on the second interface?
775 * This needs a lot of work.
777 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
780 IWL_DEBUG_MAC80211(priv, "enter\n");
782 mutex_lock(&priv->shrd->mutex);
784 if (iwl_is_rfkill(priv->shrd))
787 if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
788 test_bit(STATUS_SCANNING, &priv->shrd->status) ||
789 test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status))
792 if (!iwl_is_associated_ctx(ctx))
795 if (!priv->cfg->lib->set_channel_switch)
798 ch = channel->hw_value;
799 if (le16_to_cpu(ctx->active.channel) == ch)
802 ch_info = iwl_get_channel_info(priv, channel->band, ch);
803 if (!is_channel_valid(ch_info)) {
804 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
808 spin_lock_irq(&priv->shrd->lock);
810 priv->current_ht_config.smps = conf->smps_mode;
812 /* Configure HT40 channels */
813 ctx->ht.enabled = conf_is_ht(conf);
815 iwlagn_config_ht40(conf, ctx);
817 ctx->ht.is_40mhz = false;
819 if ((le16_to_cpu(ctx->staging.channel) != ch))
820 ctx->staging.flags = 0;
822 iwl_set_rxon_channel(priv, channel, ctx);
823 iwl_set_rxon_ht(priv, ht_conf);
824 iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
826 spin_unlock_irq(&priv->shrd->lock);
830 * at this point, staging_rxon has the
831 * configuration for channel switch
833 set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
834 priv->switch_channel = cpu_to_le16(ch);
835 if (priv->cfg->lib->set_channel_switch(priv, ch_switch)) {
836 clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
837 priv->switch_channel = 0;
838 ieee80211_chswitch_done(ctx->vif, false);
842 mutex_unlock(&priv->shrd->mutex);
843 IWL_DEBUG_MAC80211(priv, "leave\n");
846 static void iwlagn_configure_filter(struct ieee80211_hw *hw,
847 unsigned int changed_flags,
848 unsigned int *total_flags,
851 struct iwl_priv *priv = hw->priv;
852 __le32 filter_or = 0, filter_nand = 0;
853 struct iwl_rxon_context *ctx;
855 #define CHK(test, flag) do { \
856 if (*total_flags & (test)) \
857 filter_or |= (flag); \
859 filter_nand |= (flag); \
862 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
863 changed_flags, *total_flags);
865 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
866 /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
867 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
868 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
872 mutex_lock(&priv->shrd->mutex);
874 for_each_context(priv, ctx) {
875 ctx->staging.filter_flags &= ~filter_nand;
876 ctx->staging.filter_flags |= filter_or;
879 * Not committing directly because hardware can perform a scan,
880 * but we'll eventually commit the filter flags change anyway.
884 mutex_unlock(&priv->shrd->mutex);
887 * Receiving all multicast frames is always enabled by the
888 * default flags setup in iwl_connection_init_rx_config()
889 * since we currently do not support programming multicast
890 * filters into the device.
892 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
893 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
896 static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
898 struct iwl_priv *priv = hw->priv;
900 mutex_lock(&priv->shrd->mutex);
901 IWL_DEBUG_MAC80211(priv, "enter\n");
903 if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
904 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
907 if (iwl_is_rfkill(priv->shrd)) {
908 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
913 * mac80211 will not push any more frames for transmit
914 * until the flush is completed
917 IWL_DEBUG_MAC80211(priv, "send flush command\n");
918 if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
919 IWL_ERR(priv, "flush request fail\n");
923 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
924 iwl_trans_wait_tx_queue_empty(trans(priv));
926 mutex_unlock(&priv->shrd->mutex);
927 IWL_DEBUG_MAC80211(priv, "leave\n");
930 static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
931 struct ieee80211_channel *channel,
932 enum nl80211_channel_type channel_type,
935 struct iwl_priv *priv = hw->priv;
936 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
939 if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
942 if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
945 IWL_DEBUG_MAC80211(priv, "enter\n");
946 mutex_lock(&priv->shrd->mutex);
948 if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) {
953 priv->hw_roc_channel = channel;
954 priv->hw_roc_chantype = channel_type;
955 /* convert from ms to TU */
956 priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
957 priv->hw_roc_start_notified = false;
958 cancel_delayed_work(&priv->hw_roc_disable_work);
960 if (!ctx->is_active) {
961 static const struct iwl_qos_info default_qos_data = {
964 .cw_min = cpu_to_le16(3),
965 .cw_max = cpu_to_le16(7),
967 .edca_txop = cpu_to_le16(1504),
970 .cw_min = cpu_to_le16(7),
971 .cw_max = cpu_to_le16(15),
973 .edca_txop = cpu_to_le16(3008),
976 .cw_min = cpu_to_le16(15),
977 .cw_max = cpu_to_le16(1023),
981 .cw_min = cpu_to_le16(15),
982 .cw_max = cpu_to_le16(1023),
988 ctx->is_active = true;
989 ctx->qos_data = default_qos_data;
990 ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
991 memcpy(ctx->staging.node_addr,
992 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
994 memcpy(ctx->staging.bssid_addr,
995 priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
997 err = iwlagn_commit_rxon(priv, ctx);
1000 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
1001 RXON_FILTER_PROMISC_MSK |
1002 RXON_FILTER_CTL2HOST_MSK;
1004 err = iwlagn_commit_rxon(priv, ctx);
1006 iwlagn_disable_roc(priv);
1009 priv->hw_roc_setup = true;
1012 err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
1014 iwlagn_disable_roc(priv);
1017 mutex_unlock(&priv->shrd->mutex);
1018 IWL_DEBUG_MAC80211(priv, "leave\n");
1023 static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
1025 struct iwl_priv *priv = hw->priv;
1027 if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
1030 IWL_DEBUG_MAC80211(priv, "enter\n");
1031 mutex_lock(&priv->shrd->mutex);
1032 iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
1033 iwlagn_disable_roc(priv);
1034 mutex_unlock(&priv->shrd->mutex);
1035 IWL_DEBUG_MAC80211(priv, "leave\n");
1040 static int iwlagn_mac_tx_sync(struct ieee80211_hw *hw,
1041 struct ieee80211_vif *vif,
1043 enum ieee80211_tx_sync_type type)
1045 struct iwl_priv *priv = hw->priv;
1046 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1047 struct iwl_rxon_context *ctx = vif_priv->ctx;
1051 IWL_DEBUG_MAC80211(priv, "enter\n");
1052 mutex_lock(&priv->shrd->mutex);
1054 if (iwl_is_associated_ctx(ctx)) {
1059 if (ctx->preauth_bssid || test_bit(STATUS_SCAN_HW,
1060 &priv->shrd->status)) {
1065 ret = iwl_add_station_common(priv, ctx, bssid, true, NULL, &sta_id);
1069 if (WARN_ON(sta_id != ctx->ap_sta_id)) {
1071 goto out_remove_sta;
1074 memcpy(ctx->bssid, bssid, ETH_ALEN);
1075 ctx->preauth_bssid = true;
1077 ret = iwlagn_commit_rxon(priv, ctx);
1083 iwl_remove_station(priv, sta_id, bssid);
1085 mutex_unlock(&priv->shrd->mutex);
1086 IWL_DEBUG_MAC80211(priv, "leave\n");
1091 static void iwlagn_mac_finish_tx_sync(struct ieee80211_hw *hw,
1092 struct ieee80211_vif *vif,
1094 enum ieee80211_tx_sync_type type)
1096 struct iwl_priv *priv = hw->priv;
1097 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1098 struct iwl_rxon_context *ctx = vif_priv->ctx;
1100 IWL_DEBUG_MAC80211(priv, "enter\n");
1101 mutex_lock(&priv->shrd->mutex);
1103 if (iwl_is_associated_ctx(ctx))
1106 iwl_remove_station(priv, ctx->ap_sta_id, bssid);
1107 ctx->preauth_bssid = false;
1108 /* no need to commit */
1110 mutex_unlock(&priv->shrd->mutex);
1111 IWL_DEBUG_MAC80211(priv, "leave\n");
1114 static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
1115 enum ieee80211_rssi_event rssi_event)
1117 struct iwl_priv *priv = hw->priv;
1119 IWL_DEBUG_MAC80211(priv, "enter\n");
1120 mutex_lock(&priv->shrd->mutex);
1122 if (priv->cfg->bt_params &&
1123 priv->cfg->bt_params->advanced_bt_coexist) {
1124 if (rssi_event == RSSI_EVENT_LOW)
1125 priv->bt_enable_pspoll = true;
1126 else if (rssi_event == RSSI_EVENT_HIGH)
1127 priv->bt_enable_pspoll = false;
1129 iwlagn_send_advance_bt_config(priv);
1131 IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
1132 "ignoring RSSI callback\n");
1135 mutex_unlock(&priv->shrd->mutex);
1136 IWL_DEBUG_MAC80211(priv, "leave\n");
1139 static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
1140 struct ieee80211_sta *sta, bool set)
1142 struct iwl_priv *priv = hw->priv;
1144 queue_work(priv->shrd->workqueue, &priv->beacon_update);
1149 static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
1150 struct ieee80211_vif *vif, u16 queue,
1151 const struct ieee80211_tx_queue_params *params)
1153 struct iwl_priv *priv = hw->priv;
1154 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1155 struct iwl_rxon_context *ctx = vif_priv->ctx;
1156 unsigned long flags;
1162 IWL_DEBUG_MAC80211(priv, "enter\n");
1164 if (!iwl_is_ready_rf(priv->shrd)) {
1165 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1169 if (queue >= AC_NUM) {
1170 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1174 q = AC_NUM - 1 - queue;
1176 spin_lock_irqsave(&priv->shrd->lock, flags);
1178 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1179 cpu_to_le16(params->cw_min);
1180 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1181 cpu_to_le16(params->cw_max);
1182 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1183 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1184 cpu_to_le16((params->txop * 32));
1186 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1188 spin_unlock_irqrestore(&priv->shrd->lock, flags);
1190 IWL_DEBUG_MAC80211(priv, "leave\n");
1194 static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
1196 struct iwl_priv *priv = hw->priv;
1198 return priv->ibss_manager == IWL_IBSS_MANAGER;
1201 static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1203 iwl_connection_init_rx_config(priv, ctx);
1205 iwlagn_set_rxon_chain(priv, ctx);
1207 return iwlagn_commit_rxon(priv, ctx);
1210 static int iwl_setup_interface(struct iwl_priv *priv,
1211 struct iwl_rxon_context *ctx)
1213 struct ieee80211_vif *vif = ctx->vif;
1216 lockdep_assert_held(&priv->shrd->mutex);
1219 * This variable will be correct only when there's just
1220 * a single context, but all code using it is for hardware
1221 * that supports only one context.
1223 priv->iw_mode = vif->type;
1225 ctx->is_active = true;
1227 err = iwl_set_mode(priv, ctx);
1229 if (!ctx->always_active)
1230 ctx->is_active = false;
1234 if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist &&
1235 vif->type == NL80211_IFTYPE_ADHOC) {
1237 * pretend to have high BT traffic as long as we
1238 * are operating in IBSS mode, as this will cause
1239 * the rate scaling etc. to behave as intended.
1241 priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
1247 static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1248 struct ieee80211_vif *vif)
1250 struct iwl_priv *priv = hw->priv;
1251 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1252 struct iwl_rxon_context *tmp, *ctx = NULL;
1254 enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
1256 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
1257 viftype, vif->addr);
1259 cancel_delayed_work_sync(&priv->hw_roc_disable_work);
1261 mutex_lock(&priv->shrd->mutex);
1263 iwlagn_disable_roc(priv);
1265 if (!iwl_is_ready_rf(priv->shrd)) {
1266 IWL_WARN(priv, "Try to add interface when device not ready\n");
1271 for_each_context(priv, tmp) {
1272 u32 possible_modes =
1273 tmp->interface_modes | tmp->exclusive_interface_modes;
1276 /* check if this busy context is exclusive */
1277 if (tmp->exclusive_interface_modes &
1278 BIT(tmp->vif->type)) {
1285 if (!(possible_modes & BIT(viftype)))
1288 /* have maybe usable context w/o interface */
1298 vif_priv->ctx = ctx;
1301 err = iwl_setup_interface(priv, ctx);
1306 priv->iw_mode = NL80211_IFTYPE_STATION;
1308 mutex_unlock(&priv->shrd->mutex);
1310 IWL_DEBUG_MAC80211(priv, "leave\n");
1314 static void iwl_teardown_interface(struct iwl_priv *priv,
1315 struct ieee80211_vif *vif,
1318 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1320 lockdep_assert_held(&priv->shrd->mutex);
1322 if (priv->scan_vif == vif) {
1323 iwl_scan_cancel_timeout(priv, 200);
1324 iwl_force_scan_end(priv);
1328 iwl_set_mode(priv, ctx);
1329 if (!ctx->always_active)
1330 ctx->is_active = false;
1334 * When removing the IBSS interface, overwrite the
1335 * BT traffic load with the stored one from the last
1336 * notification, if any. If this is a device that
1337 * doesn't implement this, this has no effect since
1338 * both values are the same and zero.
1340 if (vif->type == NL80211_IFTYPE_ADHOC)
1341 priv->bt_traffic_load = priv->last_bt_traffic_load;
1344 static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
1345 struct ieee80211_vif *vif)
1347 struct iwl_priv *priv = hw->priv;
1348 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1350 IWL_DEBUG_MAC80211(priv, "enter\n");
1352 mutex_lock(&priv->shrd->mutex);
1354 if (WARN_ON(ctx->vif != vif)) {
1355 struct iwl_rxon_context *tmp;
1356 IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
1357 for_each_context(priv, tmp)
1358 IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
1359 tmp->ctxid, tmp, tmp->vif);
1363 iwl_teardown_interface(priv, vif, false);
1365 mutex_unlock(&priv->shrd->mutex);
1367 IWL_DEBUG_MAC80211(priv, "leave\n");
1371 static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
1372 struct ieee80211_vif *vif,
1373 enum nl80211_iftype newtype, bool newp2p)
1375 struct iwl_priv *priv = hw->priv;
1376 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1377 struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1378 struct iwl_rxon_context *tmp;
1379 enum nl80211_iftype newviftype = newtype;
1380 u32 interface_modes;
1383 IWL_DEBUG_MAC80211(priv, "enter\n");
1385 newtype = ieee80211_iftype_p2p(newtype, newp2p);
1387 mutex_lock(&priv->shrd->mutex);
1389 if (!ctx->vif || !iwl_is_ready_rf(priv->shrd)) {
1391 * Huh? But wait ... this can maybe happen when
1392 * we're in the middle of a firmware restart!
1398 interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
1400 if (!(interface_modes & BIT(newtype))) {
1406 * Refuse a change that should be done by moving from the PAN
1407 * context to the BSS context instead, if the BSS context is
1408 * available and can support the new interface type.
1410 if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif &&
1411 (bss_ctx->interface_modes & BIT(newtype) ||
1412 bss_ctx->exclusive_interface_modes & BIT(newtype))) {
1413 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
1418 if (ctx->exclusive_interface_modes & BIT(newtype)) {
1419 for_each_context(priv, tmp) {
1427 * The current mode switch would be exclusive, but
1428 * another context is active ... refuse the switch.
1436 iwl_teardown_interface(priv, vif, true);
1437 vif->type = newviftype;
1439 err = iwl_setup_interface(priv, ctx);
1442 * We've switched internally, but submitting to the
1443 * device may have failed for some reason. Mask this
1444 * error, because otherwise mac80211 will not switch
1445 * (and set the interface type back) and we'll be
1446 * out of sync with it.
1451 mutex_unlock(&priv->shrd->mutex);
1452 IWL_DEBUG_MAC80211(priv, "leave\n");
1457 static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
1458 struct ieee80211_vif *vif,
1459 struct cfg80211_scan_request *req)
1461 struct iwl_priv *priv = hw->priv;
1464 IWL_DEBUG_MAC80211(priv, "enter\n");
1466 if (req->n_channels == 0)
1469 mutex_lock(&priv->shrd->mutex);
1472 * If an internal scan is in progress, just set
1473 * up the scan_request as per above.
1475 if (priv->scan_type != IWL_SCAN_NORMAL) {
1476 IWL_DEBUG_SCAN(priv,
1477 "SCAN request during internal scan - defer\n");
1478 priv->scan_request = req;
1479 priv->scan_vif = vif;
1482 priv->scan_request = req;
1483 priv->scan_vif = vif;
1485 * mac80211 will only ask for one band at a time
1486 * so using channels[0] here is ok
1488 ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
1489 req->channels[0]->band);
1491 priv->scan_request = NULL;
1492 priv->scan_vif = NULL;
1496 IWL_DEBUG_MAC80211(priv, "leave\n");
1498 mutex_unlock(&priv->shrd->mutex);
1503 static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
1504 struct ieee80211_vif *vif,
1505 struct ieee80211_sta *sta)
1507 struct iwl_priv *priv = hw->priv;
1508 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1511 IWL_DEBUG_MAC80211(priv, "enter: received request to remove "
1512 "station %pM\n", sta->addr);
1513 mutex_lock(&priv->shrd->mutex);
1514 IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
1516 ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
1518 IWL_DEBUG_QUIET_RFKILL(priv, "Error removing station %pM\n",
1520 mutex_unlock(&priv->shrd->mutex);
1521 IWL_DEBUG_MAC80211(priv, "leave\n");
1526 static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1528 unsigned long flags;
1530 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
1531 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
1532 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1533 priv->stations[sta_id].sta.sta.modify_mask = 0;
1534 priv->stations[sta_id].sta.sleep_tx_count = 0;
1535 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1536 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1537 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
1541 static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
1542 struct ieee80211_vif *vif,
1543 enum sta_notify_cmd cmd,
1544 struct ieee80211_sta *sta)
1546 struct iwl_priv *priv = hw->priv;
1547 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1550 IWL_DEBUG_MAC80211(priv, "enter\n");
1553 case STA_NOTIFY_SLEEP:
1554 WARN_ON(!sta_priv->client);
1555 sta_priv->asleep = true;
1556 if (atomic_read(&sta_priv->pending_frames) > 0)
1557 ieee80211_sta_block_awake(hw, sta, true);
1559 case STA_NOTIFY_AWAKE:
1560 WARN_ON(!sta_priv->client);
1561 if (!sta_priv->asleep)
1563 sta_priv->asleep = false;
1564 sta_id = iwl_sta_id(sta);
1565 if (sta_id != IWL_INVALID_STATION)
1566 iwl_sta_modify_ps_wake(priv, sta_id);
1571 IWL_DEBUG_MAC80211(priv, "leave\n");
1574 struct ieee80211_ops iwlagn_hw_ops = {
1575 .tx = iwlagn_mac_tx,
1576 .start = iwlagn_mac_start,
1577 .stop = iwlagn_mac_stop,
1578 #ifdef CONFIG_PM_SLEEP
1579 .suspend = iwlagn_mac_suspend,
1580 .resume = iwlagn_mac_resume,
1582 .add_interface = iwlagn_mac_add_interface,
1583 .remove_interface = iwlagn_mac_remove_interface,
1584 .change_interface = iwlagn_mac_change_interface,
1585 .config = iwlagn_mac_config,
1586 .configure_filter = iwlagn_configure_filter,
1587 .set_key = iwlagn_mac_set_key,
1588 .update_tkip_key = iwlagn_mac_update_tkip_key,
1589 .set_rekey_data = iwlagn_mac_set_rekey_data,
1590 .conf_tx = iwlagn_mac_conf_tx,
1591 .bss_info_changed = iwlagn_bss_info_changed,
1592 .ampdu_action = iwlagn_mac_ampdu_action,
1593 .hw_scan = iwlagn_mac_hw_scan,
1594 .sta_notify = iwlagn_mac_sta_notify,
1595 .sta_add = iwlagn_mac_sta_add,
1596 .sta_remove = iwlagn_mac_sta_remove,
1597 .channel_switch = iwlagn_mac_channel_switch,
1598 .flush = iwlagn_mac_flush,
1599 .tx_last_beacon = iwlagn_mac_tx_last_beacon,
1600 .remain_on_channel = iwlagn_mac_remain_on_channel,
1601 .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
1602 .rssi_callback = iwlagn_mac_rssi_callback,
1603 CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
1604 CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
1605 .tx_sync = iwlagn_mac_tx_sync,
1606 .finish_tx_sync = iwlagn_mac_finish_tx_sync,
1607 .set_tim = iwlagn_mac_set_tim,
1610 /* This function both allocates and initializes hw and priv. */
1611 struct ieee80211_hw *iwl_alloc_all(void)
1613 struct iwl_priv *priv;
1614 /* mac80211 allocates memory for this device instance, including
1615 * space for this driver's private structure */
1616 struct ieee80211_hw *hw;
1618 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);