]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless
authorJohn W. Linville <linville@tuxdriver.com>
Wed, 14 Dec 2011 19:35:41 +0000 (14:35 -0500)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 14 Dec 2011 19:35:41 +0000 (14:35 -0500)
Conflicts:
drivers/net/wireless/iwlwifi/iwl-agn.c

1  2 
drivers/net/wireless/ath/ath9k/main.c
drivers/net/wireless/ath/ath9k/rc.c
drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
drivers/net/wireless/iwlwifi/iwl-agn-tx.c
drivers/net/wireless/iwlwifi/iwl-mac80211.c
drivers/ssb/driver_pcicore.c
net/mac80211/agg-tx.c
net/nfc/nci/core.c

index 5007297c9447a63131e23e35ca5fc33f1c43a8ec,d2348a5a7809bd1e2233f39a2b6f192443234f2f..7d920044d031b3370fc91ba44fc825c7796df932
@@@ -118,7 -118,7 +118,7 @@@ void ath9k_ps_restore(struct ath_softc 
        if (--sc->ps_usecount != 0)
                goto unlock;
  
 -      if (sc->ps_idle)
 +      if (sc->ps_idle && (sc->ps_flags & PS_WAIT_FOR_TX_ACK))
                mode = ATH9K_PM_FULL_SLEEP;
        else if (sc->ps_enabled &&
                 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
@@@ -286,7 -286,7 +286,7 @@@ static bool ath_complete_reset(struct a
                        ath_start_ani(common);
        }
  
-       if (ath9k_hw_ops(ah)->antdiv_comb_conf_get && sc->ant_rx != 3) {
+       if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx != 3) {
                struct ath_hw_antcomb_conf div_ant_conf;
                u8 lna_conf;
  
@@@ -332,8 -332,7 +332,8 @@@ static int ath_reset_internal(struct at
                hchan = ah->curchan;
        }
  
 -      if (fastcc && !ath9k_hw_check_alive(ah))
 +      if (fastcc && (ah->chip_fullsleep ||
 +          !ath9k_hw_check_alive(ah)))
                fastcc = false;
  
        if (!ath_prepare_reset(sc, retry_tx, flush))
@@@ -562,6 -561,7 +562,6 @@@ void ath_ani_calibrate(unsigned long da
        /* Long calibration runs independently of short calibration. */
        if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
                longcal = true;
 -              ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
                common->ani.longcal_timer = timestamp;
        }
  
        if (!common->ani.caldone) {
                if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
                        shortcal = true;
 -                      ath_dbg(common, ATH_DBG_ANI,
 -                              "shortcal @%lu\n", jiffies);
                        common->ani.shortcal_timer = timestamp;
                        common->ani.resetcal_timer = timestamp;
                }
        }
  
        /* Verify whether we must check ANI */
 -      if ((timestamp - common->ani.checkani_timer) >=
 -           ah->config.ani_poll_interval) {
 +      if (sc->sc_ah->config.enable_ani
 +          && (timestamp - common->ani.checkani_timer) >=
 +          ah->config.ani_poll_interval) {
                aniflag = true;
                common->ani.checkani_timer = timestamp;
        }
                                                ah->rxchainmask, longcal);
        }
  
 +      ath_dbg(common, ATH_DBG_ANI,
 +              "Calibration @%lu finished: %s %s %s, caldone: %s\n", jiffies,
 +              longcal ? "long" : "", shortcal ? "short" : "",
 +              aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
 +
        ath9k_ps_restore(sc);
  
  set_timer:
        }
  }
  
 -static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
 +static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
 +                          struct ieee80211_vif *vif)
  {
        struct ath_node *an;
        an = (struct ath_node *)sta->drv_priv;
        list_add(&an->list, &sc->nodes);
        spin_unlock(&sc->nodes_lock);
        an->sta = sta;
 +      an->vif = vif;
  #endif
        if (sc->sc_flags & SC_OP_TXAGGR) {
                ath_tx_node_init(sc, an);
@@@ -746,9 -740,6 +746,9 @@@ void ath9k_tasklet(unsigned long data
                if (status & ATH9K_INT_GENTIMER)
                        ath_gen_timer_isr(sc->sc_ah);
  
 +      if (status & ATH9K_INT_MCI)
 +              ath_mci_intr(sc);
 +
  out:
        /* re-enable hardware interrupt */
        ath9k_hw_enable_interrupts(ah);
@@@ -771,8 -762,7 +771,8 @@@ irqreturn_t ath_isr(int irq, void *dev
                ATH9K_INT_BMISS |               \
                ATH9K_INT_CST |                 \
                ATH9K_INT_TSFOOR |              \
 -              ATH9K_INT_GENTIMER)
 +              ATH9K_INT_GENTIMER |            \
 +              ATH9K_INT_MCI)
  
        struct ath_softc *sc = dev;
        struct ath_hw *ah = sc->sc_ah;
@@@ -890,6 -880,82 +890,6 @@@ chip_reset
  #undef SCHED_INTR
  }
  
 -static void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
 -{
 -      struct ath_hw *ah = sc->sc_ah;
 -      struct ath_common *common = ath9k_hw_common(ah);
 -      struct ieee80211_channel *channel = hw->conf.channel;
 -      int r;
 -
 -      ath9k_ps_wakeup(sc);
 -      spin_lock_bh(&sc->sc_pcu_lock);
 -      atomic_set(&ah->intr_ref_cnt, -1);
 -
 -      ath9k_hw_configpcipowersave(ah, false);
 -
 -      if (!ah->curchan)
 -              ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
 -
 -      r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
 -      if (r) {
 -              ath_err(common,
 -                      "Unable to reset channel (%u MHz), reset status %d\n",
 -                      channel->center_freq, r);
 -      }
 -
 -      ath_complete_reset(sc, true);
 -
 -      /* Enable LED */
 -      ath9k_hw_cfg_output(ah, ah->led_pin,
 -                          AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
 -      ath9k_hw_set_gpio(ah, ah->led_pin, 0);
 -
 -      spin_unlock_bh(&sc->sc_pcu_lock);
 -
 -      ath9k_ps_restore(sc);
 -}
 -
 -void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
 -{
 -      struct ath_hw *ah = sc->sc_ah;
 -      struct ieee80211_channel *channel = hw->conf.channel;
 -      int r;
 -
 -      ath9k_ps_wakeup(sc);
 -
 -      ath_cancel_work(sc);
 -
 -      spin_lock_bh(&sc->sc_pcu_lock);
 -
 -      /*
 -       * Keep the LED on when the radio is disabled
 -       * during idle unassociated state.
 -       */
 -      if (!sc->ps_idle) {
 -              ath9k_hw_set_gpio(ah, ah->led_pin, 1);
 -              ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
 -      }
 -
 -      ath_prepare_reset(sc, false, true);
 -
 -      if (!ah->curchan)
 -              ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
 -
 -      r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
 -      if (r) {
 -              ath_err(ath9k_hw_common(sc->sc_ah),
 -                      "Unable to reset channel (%u MHz), reset status %d\n",
 -                      channel->center_freq, r);
 -      }
 -
 -      ath9k_hw_phy_disable(ah);
 -
 -      ath9k_hw_configpcipowersave(ah, true);
 -
 -      spin_unlock_bh(&sc->sc_pcu_lock);
 -      ath9k_ps_restore(sc);
 -}
 -
  static int ath_reset(struct ath_softc *sc, bool retry_tx)
  {
        int r;
@@@ -1025,9 -1091,6 +1025,9 @@@ static int ath9k_start(struct ieee80211
         * and then setup of the interrupt mask.
         */
        spin_lock_bh(&sc->sc_pcu_lock);
 +
 +      atomic_set(&ah->intr_ref_cnt, -1);
 +
        r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
        if (r) {
                ath_err(common,
        if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
                ah->imask |= ATH9K_INT_CST;
  
 +      if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
 +              ah->imask |= ATH9K_INT_MCI;
 +
        sc->sc_flags &= ~SC_OP_INVALID;
        sc->sc_ah->is_monitoring = false;
  
                goto mutex_unlock;
        }
  
 +      if (ah->led_pin >= 0) {
 +              ath9k_hw_cfg_output(ah, ah->led_pin,
 +                                  AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
 +              ath9k_hw_set_gpio(ah, ah->led_pin, 0);
 +      }
 +
 +      /*
 +       * Reset key cache to sane defaults (all entries cleared) instead of
 +       * semi-random values after suspend/resume.
 +       */
 +      ath9k_cmn_init_crypto(sc->sc_ah);
 +
        spin_unlock_bh(&sc->sc_pcu_lock);
  
        if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
            !ah->btcoex_hw.enabled) {
 -              ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
 -                                         AR_STOMP_LOW_WLAN_WGHT);
 +              if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI))
 +                      ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
 +                                                 AR_STOMP_LOW_WLAN_WGHT);
                ath9k_hw_btcoex_enable(ah);
  
                if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
@@@ -1126,13 -1173,6 +1126,13 @@@ static void ath9k_tx(struct ieee80211_h
                }
        }
  
 +      /*
 +       * Cannot tx while the hardware is in full sleep, it first needs a full
 +       * chip reset to recover from that
 +       */
 +      if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP))
 +              goto exit;
 +
        if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
                /*
                 * We are using PS-Poll and mac80211 can request TX while in
@@@ -1179,7 -1219,6 +1179,7 @@@ static void ath9k_stop(struct ieee80211
        struct ath_softc *sc = hw->priv;
        struct ath_hw *ah = sc->sc_ah;
        struct ath_common *common = ath9k_hw_common(ah);
 +      bool prev_idle;
  
        mutex_lock(&sc->mutex);
  
                ath9k_hw_btcoex_disable(ah);
                if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
                        ath9k_btcoex_timer_pause(sc);
 +              ath_mci_flush_profile(&sc->btcoex.mci);
        }
  
        spin_lock_bh(&sc->sc_pcu_lock);
         * before setting the invalid flag. */
        ath9k_hw_disable_interrupts(ah);
  
 -      if (!(sc->sc_flags & SC_OP_INVALID)) {
 -              ath_drain_all_txq(sc, false);
 -              ath_stoprecv(sc);
 -              ath9k_hw_phy_disable(ah);
 -      } else
 -              sc->rx.rxlink = NULL;
 +      spin_unlock_bh(&sc->sc_pcu_lock);
 +
 +      /* we can now sync irq and kill any running tasklets, since we already
 +       * disabled interrupts and not holding a spin lock */
 +      synchronize_irq(sc->irq);
 +      tasklet_kill(&sc->intr_tq);
 +      tasklet_kill(&sc->bcon_tasklet);
 +
 +      prev_idle = sc->ps_idle;
 +      sc->ps_idle = true;
 +
 +      spin_lock_bh(&sc->sc_pcu_lock);
 +
 +      if (ah->led_pin >= 0) {
 +              ath9k_hw_set_gpio(ah, ah->led_pin, 1);
 +              ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
 +      }
 +
 +      ath_prepare_reset(sc, false, true);
  
        if (sc->rx.frag) {
                dev_kfree_skb_any(sc->rx.frag);
                sc->rx.frag = NULL;
        }
  
 -      /* disable HAL and put h/w to sleep */
 -      ath9k_hw_disable(ah);
 +      if (!ah->curchan)
 +              ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
  
 -      spin_unlock_bh(&sc->sc_pcu_lock);
 +      ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
 +      ath9k_hw_phy_disable(ah);
  
 -      /* we can now sync irq and kill any running tasklets, since we already
 -       * disabled interrupts and not holding a spin lock */
 -      synchronize_irq(sc->irq);
 -      tasklet_kill(&sc->intr_tq);
 -      tasklet_kill(&sc->bcon_tasklet);
 +      ath9k_hw_configpcipowersave(ah, true);
  
 -      ath9k_ps_restore(sc);
 +      spin_unlock_bh(&sc->sc_pcu_lock);
  
 -      sc->ps_idle = true;
 -      ath_radio_disable(sc, hw);
 +      ath9k_ps_restore(sc);
  
        sc->sc_flags |= SC_OP_INVALID;
 +      sc->ps_idle = prev_idle;
  
        mutex_unlock(&sc->mutex);
  
@@@ -1588,8 -1616,8 +1588,8 @@@ static int ath9k_config(struct ieee8021
        struct ath_hw *ah = sc->sc_ah;
        struct ath_common *common = ath9k_hw_common(ah);
        struct ieee80211_conf *conf = &hw->conf;
 -      bool disable_radio = false;
  
 +      ath9k_ps_wakeup(sc);
        mutex_lock(&sc->mutex);
  
        /*
         */
        if (changed & IEEE80211_CONF_CHANGE_IDLE) {
                sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
 -              if (!sc->ps_idle) {
 -                      ath_radio_enable(sc, hw);
 -                      ath_dbg(common, ATH_DBG_CONFIG,
 -                              "not-idle: enabling radio\n");
 -              } else {
 -                      disable_radio = true;
 -              }
 +              if (sc->ps_idle)
 +                      ath_cancel_work(sc);
        }
  
        /*
                ath_dbg(common, ATH_DBG_CONFIG,
                        "Set power: %d\n", conf->power_level);
                sc->config.txpowlimit = 2 * conf->power_level;
 -              ath9k_ps_wakeup(sc);
                ath9k_cmn_update_txpow(ah, sc->curtxpow,
                                       sc->config.txpowlimit, &sc->curtxpow);
 -              ath9k_ps_restore(sc);
 -      }
 -
 -      if (disable_radio) {
 -              ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
 -              ath_radio_disable(sc, hw);
        }
  
        mutex_unlock(&sc->mutex);
 +      ath9k_ps_restore(sc);
  
        return 0;
  }
@@@ -1759,7 -1798,7 +1759,7 @@@ static int ath9k_sta_add(struct ieee802
        struct ath_node *an = (struct ath_node *) sta->drv_priv;
        struct ieee80211_key_conf ps_key = { };
  
 -      ath_node_attach(sc, sta);
 +      ath_node_attach(sc, sta, vif);
  
        if (vif->type != NL80211_IFTYPE_AP &&
            vif->type != NL80211_IFTYPE_AP_VLAN)
@@@ -2281,6 -2320,9 +2281,6 @@@ static void ath9k_flush(struct ieee8021
                return;
        }
  
 -      if (drop)
 -              timeout = 1;
 -
        for (j = 0; j < timeout; j++) {
                bool npend = false;
  
                }
  
                if (!npend)
 -                  goto out;
 +                  break;
        }
  
 -      ath9k_ps_wakeup(sc);
 -      spin_lock_bh(&sc->sc_pcu_lock);
 -      drain_txq = ath_drain_all_txq(sc, false);
 -      spin_unlock_bh(&sc->sc_pcu_lock);
 +      if (drop) {
 +              ath9k_ps_wakeup(sc);
 +              spin_lock_bh(&sc->sc_pcu_lock);
 +              drain_txq = ath_drain_all_txq(sc, false);
 +              spin_unlock_bh(&sc->sc_pcu_lock);
  
 -      if (!drain_txq)
 -              ath_reset(sc, false);
 +              if (!drain_txq)
 +                      ath_reset(sc, false);
  
 -      ath9k_ps_restore(sc);
 -      ieee80211_wake_queues(hw);
 +              ath9k_ps_restore(sc);
 +              ieee80211_wake_queues(hw);
 +      }
  
 -out:
        ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
        mutex_unlock(&sc->mutex);
  }
index 888abc2be3a547d6f85ad32723fd2d2910c5582e,cc5703b853bcfe5a9ccfdb8083e43c8b3d8fa51f..528d5f3e868c712a7b2372dc8616e1581205bddc
@@@ -16,7 -16,6 +16,7 @@@
   */
  
  #include <linux/slab.h>
 +#include <linux/export.h>
  
  #include "ath9k.h"
  
@@@ -1271,7 -1270,9 +1271,9 @@@ static void ath_rc_init(struct ath_soft
  
        ath_rc_priv->max_valid_rate = k;
        ath_rc_sort_validrates(rate_table, ath_rc_priv);
-       ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
+       ath_rc_priv->rate_max_phy = (k > 4) ?
+                                       ath_rc_priv->valid_rate_index[k-4] :
+                                       ath_rc_priv->valid_rate_index[k-1];
        ath_rc_priv->rate_table = rate_table;
  
        ath_dbg(common, ATH_DBG_CONFIG,
index 466e4ab544f7b7bb4379e598342b6c75d5833aef,5c7c17c7166ac7a307407ddff67eee59ca148771..d21f535a3b4fdd84fcafd600e2945243958b128d
@@@ -45,8 -45,7 +45,8 @@@ static int iwlagn_disable_bss(struct iw
        send->filter_flags = old_filter;
  
        if (ret)
 -              IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
 +              IWL_DEBUG_QUIET_RFKILL(priv,
 +                      "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
  
        return ret;
  }
@@@ -60,7 -59,7 +60,7 @@@ static int iwlagn_disable_pan(struct iw
        u8 old_dev_type = send->dev_type;
        int ret;
  
 -      iwlagn_init_notification_wait(priv, &disable_wait,
 +      iwl_init_notification_wait(priv->shrd, &disable_wait,
                                      REPLY_WIPAN_DEACTIVATION_COMPLETE,
                                      NULL, NULL);
  
@@@ -74,9 -73,9 +74,9 @@@
  
        if (ret) {
                IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
 -              iwlagn_remove_notification(priv, &disable_wait);
 +              iwl_remove_notification(priv->shrd, &disable_wait);
        } else {
 -              ret = iwlagn_wait_notification(priv, &disable_wait, HZ);
 +              ret = iwl_wait_notification(priv->shrd, &disable_wait, HZ);
                if (ret)
                        IWL_ERR(priv, "Timed out waiting for PAN disable\n");
        }
@@@ -117,7 -116,7 +117,7 @@@ static void iwlagn_update_qos(struct iw
        if (ctx->ht.enabled)
                ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  
 -      IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
 +      IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
                      ctx->qos_data.qos_active,
                      ctx->qos_data.def_qos_parm.qos_flags);
  
                               sizeof(struct iwl_qosparam_cmd),
                               &ctx->qos_data.def_qos_parm);
        if (ret)
 -              IWL_ERR(priv, "Failed to update QoS\n");
 +              IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
  }
  
  static int iwlagn_update_beacon(struct iwl_priv *priv,
@@@ -560,9 -559,6 +560,9 @@@ int iwlagn_mac_config(struct ieee80211_
  
        mutex_lock(&priv->shrd->mutex);
  
 +      if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
 +              goto out;
 +
        if (unlikely(test_bit(STATUS_SCANNING, &priv->shrd->status))) {
                IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
                goto out;
                        if (ctx->ht.enabled) {
                                /* if HT40 is used, it should not change
                                 * after associated except channel switch */
-                               if (iwl_is_associated_ctx(ctx) &&
-                                    !ctx->ht.is_40mhz)
+                               if (!ctx->ht.is_40mhz ||
+                                               !iwl_is_associated_ctx(ctx))
                                        iwlagn_config_ht40(conf, ctx);
                        } else
                                ctx->ht.is_40mhz = false;
@@@ -854,8 -850,7 +854,8 @@@ void iwlagn_bss_info_changed(struct iee
                        if (ctx->last_tx_rejected) {
                                ctx->last_tx_rejected = false;
                                iwl_trans_wake_any_queue(trans(priv),
 -                                                       ctx->ctxid);
 +                                                       ctx->ctxid,
 +                                                       "Disassoc: flush queue");
                        }
                        ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  
index 2fab2e31bf360004f427838d0bbfe57628edf430,df1540ca6102f641ed491cd50899e5eec17b8963..81754cddba73b4763a815d2fa03afff77f74a326
@@@ -91,7 -91,10 +91,10 @@@ static void iwlagn_tx_cmd_build_basic(s
                tx_cmd->tid_tspec = qc[0] & 0xf;
                tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
        } else {
-               tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
+               if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
+                       tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
+               else
+                       tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
        }
  
        iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags);
@@@ -148,7 -151,7 +151,7 @@@ static void iwlagn_tx_cmd_build_rate(st
        if (ieee80211_is_data(fc)) {
                tx_cmd->initial_rate_index = 0;
                tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
 -#ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
 +#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
                if (priv->tm_fixed_rate) {
                        /*
                         * rate overwrite by testmode
                }
  #endif
                return;
 -      }
 +      } else if (ieee80211_is_back_req(fc))
 +              tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  
        /**
         * If the current TX rate stored in mac80211 has the MCS bit set, it's
@@@ -284,19 -286,6 +287,19 @@@ int iwlagn_tx_skb(struct iwl_priv *priv
                IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  #endif
  
 +      if (unlikely(ieee80211_is_probe_resp(fc))) {
 +              struct iwl_wipan_noa_data *noa_data =
 +                      rcu_dereference(priv->noa_data);
 +
 +              if (noa_data &&
 +                  pskb_expand_head(skb, 0, noa_data->length,
 +                                   GFP_ATOMIC) == 0) {
 +                      memcpy(skb_put(skb, noa_data->length),
 +                             noa_data->data, noa_data->length);
 +                      hdr = (struct ieee80211_hdr *)skb->data;
 +              }
 +      }
 +
        hdr_len = ieee80211_hdrlen(fc);
  
        /* For management frames use broadcast id to do not break aggregation */
@@@ -791,7 -780,6 +794,7 @@@ int iwlagn_rx_reply_tx(struct iwl_priv 
                iwl_rx_reply_tx_agg(priv, tx_resp);
  
        if (tx_resp->frame_count == 1) {
 +              IWL_DEBUG_TX_REPLY(priv, "Q %d, ssn %d", txq_id, ssn);
                __skb_queue_head_init(&skbs);
                /*we can free until ssn % q.n_bd not inclusive */
                iwl_trans_reclaim(trans(priv), sta_id, tid, txq_id,
                            iwl_is_associated_ctx(ctx) && ctx->vif &&
                            ctx->vif->type == NL80211_IFTYPE_STATION) {
                                ctx->last_tx_rejected = true;
 -                              iwl_trans_stop_queue(trans(priv), txq_id);
 +                              iwl_trans_stop_queue(trans(priv), txq_id,
 +                                      "Tx on passive channel");
  
                                IWL_DEBUG_TX_REPLY(priv,
                                           "TXQ %d status %s (0x%08x) "
@@@ -922,9 -909,11 +925,9 @@@ int iwlagn_rx_reply_compressed_ba(struc
                           ba_resp->sta_id);
        IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, "
                           "scd_flow = %d, scd_ssn = %d\n",
 -                         ba_resp->tid,
 -                         ba_resp->seq_ctl,
 +                         ba_resp->tid, ba_resp->seq_ctl,
                           (unsigned long long)le64_to_cpu(ba_resp->bitmap),
 -                         ba_resp->scd_flow,
 -                         ba_resp->scd_ssn);
 +                         scd_flow, ba_resp_scd_ssn);
  
        /* Mark that the expected block-ack response arrived */
        agg->wait_for_ba = false;
index b3886d20c272d2ffb66ebd6547377d44ddc91fde,0000000000000000000000000000000000000000..e3944f4e4fd622cada27c13b66278db2ee540120
mode 100644,000000..100644
--- /dev/null
@@@ -1,1627 -1,0 +1,1633 @@@
 +/******************************************************************************
 + *
 + * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
 + *
 + * Portions of this file are derived from the ipw3945 project, as well
 + * as portions of the ieee80211 subsystem header files.
 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms of version 2 of the GNU General Public License as
 + * published by the Free Software Foundation.
 + *
 + * This program is distributed in the hope that it will be useful, but WITHOUT
 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 + * more details.
 + *
 + * You should have received a copy of the GNU General Public License along with
 + * this program; if not, write to the Free Software Foundation, Inc.,
 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 + *
 + * The full GNU General Public License is included in this distribution in the
 + * file called LICENSE.
 + *
 + * Contact Information:
 + *  Intel Linux Wireless <ilw@linux.intel.com>
 + * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 + *
 + *****************************************************************************/
 +#include <linux/kernel.h>
 +#include <linux/module.h>
 +#include <linux/init.h>
 +#include <linux/slab.h>
 +#include <linux/dma-mapping.h>
 +#include <linux/delay.h>
 +#include <linux/sched.h>
 +#include <linux/skbuff.h>
 +#include <linux/netdevice.h>
 +#include <linux/firmware.h>
 +#include <linux/etherdevice.h>
 +#include <linux/if_arp.h>
 +
 +#include <net/mac80211.h>
 +
 +#include <asm/div64.h>
 +
 +#include "iwl-eeprom.h"
 +#include "iwl-dev.h"
 +#include "iwl-core.h"
 +#include "iwl-io.h"
 +#include "iwl-agn-calib.h"
 +#include "iwl-agn.h"
 +#include "iwl-shared.h"
 +#include "iwl-bus.h"
 +#include "iwl-trans.h"
 +
 +/*****************************************************************************
 + *
 + * mac80211 entry point functions
 + *
 + *****************************************************************************/
 +
 +static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
 +      {
 +              .max = 1,
 +              .types = BIT(NL80211_IFTYPE_STATION),
 +      },
 +      {
 +              .max = 1,
 +              .types = BIT(NL80211_IFTYPE_AP),
 +      },
 +};
 +
 +static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
 +      {
 +              .max = 2,
 +              .types = BIT(NL80211_IFTYPE_STATION),
 +      },
 +};
 +
 +static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
 +      {
 +              .max = 1,
 +              .types = BIT(NL80211_IFTYPE_STATION),
 +      },
 +      {
 +              .max = 1,
 +              .types = BIT(NL80211_IFTYPE_P2P_GO) |
 +                       BIT(NL80211_IFTYPE_AP),
 +      },
 +};
 +
 +static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
 +      {
 +              .max = 2,
 +              .types = BIT(NL80211_IFTYPE_STATION),
 +      },
 +      {
 +              .max = 1,
 +              .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
 +      },
 +};
 +
 +static const struct ieee80211_iface_combination
 +iwlagn_iface_combinations_dualmode[] = {
 +      { .num_different_channels = 1,
 +        .max_interfaces = 2,
 +        .beacon_int_infra_match = true,
 +        .limits = iwlagn_sta_ap_limits,
 +        .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
 +      },
 +      { .num_different_channels = 1,
 +        .max_interfaces = 2,
 +        .limits = iwlagn_2sta_limits,
 +        .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
 +      },
 +};
 +
 +static const struct ieee80211_iface_combination
 +iwlagn_iface_combinations_p2p[] = {
 +      { .num_different_channels = 1,
 +        .max_interfaces = 2,
 +        .beacon_int_infra_match = true,
 +        .limits = iwlagn_p2p_sta_go_limits,
 +        .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
 +      },
 +      { .num_different_channels = 1,
 +        .max_interfaces = 2,
 +        .limits = iwlagn_p2p_2sta_limits,
 +        .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
 +      },
 +};
 +
 +/*
 + * Not a mac80211 entry point function, but it fits in with all the
 + * other mac80211 functions grouped here.
 + */
 +int iwlagn_mac_setup_register(struct iwl_priv *priv,
 +                                struct iwlagn_ucode_capabilities *capa)
 +{
 +      int ret;
 +      struct ieee80211_hw *hw = priv->hw;
 +      struct iwl_rxon_context *ctx;
 +
 +      hw->rate_control_algorithm = "iwl-agn-rs";
 +
 +      /* Tell mac80211 our characteristics */
 +      hw->flags = IEEE80211_HW_SIGNAL_DBM |
 +                  IEEE80211_HW_AMPDU_AGGREGATION |
 +                  IEEE80211_HW_NEED_DTIM_PERIOD |
 +                  IEEE80211_HW_SPECTRUM_MGMT |
 +                  IEEE80211_HW_REPORTS_TX_ACK_STATUS;
 +
 +      /*
 +       * Including the following line will crash some AP's.  This
 +       * workaround removes the stimulus which causes the crash until
 +       * the AP software can be fixed.
 +      hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
 +       */
 +
 +      hw->flags |= IEEE80211_HW_SUPPORTS_PS |
 +                   IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
 +
 +      if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
 +              hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
 +                           IEEE80211_HW_SUPPORTS_STATIC_SMPS;
 +
 +      if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
 +              hw->flags |= IEEE80211_HW_MFP_CAPABLE;
 +
 +      hw->sta_data_size = sizeof(struct iwl_station_priv);
 +      hw->vif_data_size = sizeof(struct iwl_vif_priv);
 +
 +      for_each_context(priv, ctx) {
 +              hw->wiphy->interface_modes |= ctx->interface_modes;
 +              hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
 +      }
 +
 +      BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
 +
 +      if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
 +              hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
 +              hw->wiphy->n_iface_combinations =
 +                      ARRAY_SIZE(iwlagn_iface_combinations_p2p);
 +      } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
 +              hw->wiphy->iface_combinations =
 +                      iwlagn_iface_combinations_dualmode;
 +              hw->wiphy->n_iface_combinations =
 +                      ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
 +      }
 +
 +      hw->wiphy->max_remain_on_channel_duration = 1000;
 +
 +      hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
 +                          WIPHY_FLAG_DISABLE_BEACON_HINTS |
 +                          WIPHY_FLAG_IBSS_RSN;
 +
 +      if (trans(priv)->ucode_wowlan.code.len &&
 +          device_can_wakeup(bus(priv)->dev)) {
 +              hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
 +                                        WIPHY_WOWLAN_DISCONNECT |
 +                                        WIPHY_WOWLAN_EAP_IDENTITY_REQ |
 +                                        WIPHY_WOWLAN_RFKILL_RELEASE;
 +              if (!iwlagn_mod_params.sw_crypto)
 +                      hw->wiphy->wowlan.flags |=
 +                              WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
 +                              WIPHY_WOWLAN_GTK_REKEY_FAILURE;
 +
 +              hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
 +              hw->wiphy->wowlan.pattern_min_len =
 +                                      IWLAGN_WOWLAN_MIN_PATTERN_LEN;
 +              hw->wiphy->wowlan.pattern_max_len =
 +                                      IWLAGN_WOWLAN_MAX_PATTERN_LEN;
 +      }
 +
 +      if (iwlagn_mod_params.power_save)
 +              hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
 +      else
 +              hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
 +
 +      hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
 +      /* we create the 802.11 header and a zero-length SSID element */
 +      hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
 +
 +      /* Default value; 4 EDCA QOS priorities */
 +      hw->queues = 4;
 +
 +      hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
 +
 +      if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
 +              priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
 +                      &priv->bands[IEEE80211_BAND_2GHZ];
 +      if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
 +              priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
 +                      &priv->bands[IEEE80211_BAND_5GHZ];
 +
 +      iwl_leds_init(priv);
 +
 +      ret = ieee80211_register_hw(priv->hw);
 +      if (ret) {
 +              IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
 +              return ret;
 +      }
 +      priv->mac80211_registered = 1;
 +
 +      return 0;
 +}
 +
 +static int __iwl_up(struct iwl_priv *priv)
 +{
 +      struct iwl_rxon_context *ctx;
 +      int ret;
 +
 +      lockdep_assert_held(&priv->shrd->mutex);
 +
 +      if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
 +              IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
 +              return -EIO;
 +      }
 +
 +      for_each_context(priv, ctx) {
 +              ret = iwlagn_alloc_bcast_station(priv, ctx);
 +              if (ret) {
 +                      iwl_dealloc_bcast_stations(priv);
 +                      return ret;
 +              }
 +      }
 +
 +      ret = iwlagn_run_init_ucode(priv);
 +      if (ret) {
 +              IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
 +              goto error;
 +      }
 +
 +      ret = iwlagn_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
 +      if (ret) {
 +              IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
 +              goto error;
 +      }
 +
 +      ret = iwl_alive_start(priv);
 +      if (ret)
 +              goto error;
 +      return 0;
 +
 + error:
 +      set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
 +      __iwl_down(priv);
 +      clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
 +
 +      IWL_ERR(priv, "Unable to initialize device.\n");
 +      return ret;
 +}
 +
 +static int iwlagn_mac_start(struct ieee80211_hw *hw)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      int ret;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      /* we should be verifying the device is ready to be opened */
 +      mutex_lock(&priv->shrd->mutex);
 +      ret = __iwl_up(priv);
 +      mutex_unlock(&priv->shrd->mutex);
 +      if (ret)
 +              return ret;
 +
 +      IWL_DEBUG_INFO(priv, "Start UP work done.\n");
 +
 +      /* Now we should be done, and the READY bit should be set. */
 +      if (WARN_ON(!test_bit(STATUS_READY, &priv->shrd->status)))
 +              ret = -EIO;
 +
 +      iwlagn_led_enable(priv);
 +
 +      priv->is_open = 1;
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +      return 0;
 +}
 +
 +static void iwlagn_mac_stop(struct ieee80211_hw *hw)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      if (!priv->is_open)
 +              return;
 +
 +      priv->is_open = 0;
 +
 +      iwl_down(priv);
 +
 +      flush_workqueue(priv->shrd->workqueue);
 +
 +      /* User space software may expect getting rfkill changes
 +       * even if interface is down */
 +      iwl_write32(bus(priv), CSR_INT, 0xFFFFFFFF);
 +      iwl_enable_rfkill_int(priv);
 +
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +}
 +
 +static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
 +                                    struct ieee80211_vif *vif,
 +                                    struct cfg80211_gtk_rekey_data *data)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      if (iwlagn_mod_params.sw_crypto)
 +              return;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
 +              goto out;
 +
 +      memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
 +      memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
 +      priv->replay_ctr =
 +              cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
 +      priv->have_rekey_data = true;
 +
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +}
 +
 +#ifdef CONFIG_PM_SLEEP
 +
 +static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
 +                            struct cfg80211_wowlan *wowlan)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
 +      int ret;
 +
 +      if (WARN_ON(!wowlan))
 +              return -EINVAL;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      /* Don't attempt WoWLAN when not associated, tear down instead. */
 +      if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
 +          !iwl_is_associated_ctx(ctx)) {
 +              ret = 1;
 +              goto out;
 +      }
 +
 +      ret = iwlagn_suspend(priv, hw, wowlan);
 +      if (ret)
 +              goto error;
 +
 +      device_set_wakeup_enable(bus(priv)->dev, true);
 +
 +      /* Now let the ucode operate on its own */
 +      iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_SET,
 +                        CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
 +
 +      goto out;
 +
 + error:
 +      priv->shrd->wowlan = false;
 +      iwlagn_prepare_restart(priv);
 +      ieee80211_restart_hw(priv->hw);
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return ret;
 +}
 +
 +static int iwlagn_mac_resume(struct ieee80211_hw *hw)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
 +      struct ieee80211_vif *vif;
 +      unsigned long flags;
 +      u32 base, status = 0xffffffff;
 +      int ret = -EIO;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_CLR,
 +                        CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
 +
 +      base = priv->shrd->device_pointers.error_event_table;
 +      if (iwlagn_hw_valid_rtc_data_addr(base)) {
 +              spin_lock_irqsave(&bus(priv)->reg_lock, flags);
 +              ret = iwl_grab_nic_access_silent(bus(priv));
 +              if (ret == 0) {
 +                      iwl_write32(bus(priv), HBUS_TARG_MEM_RADDR, base);
 +                      status = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
 +                      iwl_release_nic_access(bus(priv));
 +              }
 +              spin_unlock_irqrestore(&bus(priv)->reg_lock, flags);
 +
 +#ifdef CONFIG_IWLWIFI_DEBUGFS
 +              if (ret == 0) {
 +                      struct iwl_trans *trans = trans(priv);
 +                      if (!priv->wowlan_sram)
 +                              priv->wowlan_sram =
 +                                      kzalloc(trans->ucode_wowlan.data.len,
 +                                              GFP_KERNEL);
 +
 +                      if (priv->wowlan_sram)
 +                              _iwl_read_targ_mem_words(
 +                                      bus(priv), 0x800000, priv->wowlan_sram,
 +                                      trans->ucode_wowlan.data.len / 4);
 +              }
 +#endif
 +      }
 +
 +      /* we'll clear ctx->vif during iwlagn_prepare_restart() */
 +      vif = ctx->vif;
 +
 +      priv->shrd->wowlan = false;
 +
 +      device_set_wakeup_enable(bus(priv)->dev, false);
 +
 +      iwlagn_prepare_restart(priv);
 +
 +      memset((void *)&ctx->active, 0, sizeof(ctx->active));
 +      iwl_connection_init_rx_config(priv, ctx);
 +      iwlagn_set_rxon_chain(priv, ctx);
 +
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      ieee80211_resume_disconnect(vif);
 +
 +      return 1;
 +}
 +
 +#endif
 +
 +static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
 +                   ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
 +
 +      if (iwlagn_tx_skb(priv, skb))
 +              dev_kfree_skb_any(skb);
 +}
 +
 +static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
 +                                     struct ieee80211_vif *vif,
 +                                     struct ieee80211_key_conf *keyconf,
 +                                     struct ieee80211_sta *sta,
 +                                     u32 iv32, u16 *phase1key)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
 +}
 +
 +static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 +                            struct ieee80211_vif *vif,
 +                            struct ieee80211_sta *sta,
 +                            struct ieee80211_key_conf *key)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
 +      struct iwl_rxon_context *ctx = vif_priv->ctx;
 +      int ret;
 +      bool is_default_wep_key = false;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      if (iwlagn_mod_params.sw_crypto) {
 +              IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
 +              return -EOPNOTSUPP;
 +      }
 +
 +      switch (key->cipher) {
 +      case WLAN_CIPHER_SUITE_TKIP:
 +              key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
 +              /* fall through */
 +      case WLAN_CIPHER_SUITE_CCMP:
 +              key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
 +              break;
 +      default:
 +              break;
 +      }
 +
 +      /*
 +       * We could program these keys into the hardware as well, but we
 +       * don't expect much multicast traffic in IBSS and having keys
 +       * for more stations is probably more useful.
 +       *
 +       * Mark key TX-only and return 0.
 +       */
 +      if (vif->type == NL80211_IFTYPE_ADHOC &&
 +          !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
 +              key->hw_key_idx = WEP_INVALID_OFFSET;
 +              return 0;
 +      }
 +
 +      /* If they key was TX-only, accept deletion */
 +      if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
 +              return 0;
 +
 +      mutex_lock(&priv->shrd->mutex);
 +      iwl_scan_cancel_timeout(priv, 100);
 +
 +      BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
 +
 +      /*
 +       * If we are getting WEP group key and we didn't receive any key mapping
 +       * so far, we are in legacy wep mode (group key only), otherwise we are
 +       * in 1X mode.
 +       * In legacy wep mode, we use another host command to the uCode.
 +       */
 +      if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
 +           key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
 +              if (cmd == SET_KEY)
 +                      is_default_wep_key = !ctx->key_mapping_keys;
 +              else
 +                      is_default_wep_key =
 +                              key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
 +      }
 +
 +
 +      switch (cmd) {
 +      case SET_KEY:
 +              if (is_default_wep_key) {
 +                      ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
 +                      break;
 +              }
 +              ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
 +              if (ret) {
 +                      /*
 +                       * can't add key for RX, but we don't need it
 +                       * in the device for TX so still return 0
 +                       */
 +                      ret = 0;
 +                      key->hw_key_idx = WEP_INVALID_OFFSET;
 +              }
 +
 +              IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
 +              break;
 +      case DISABLE_KEY:
 +              if (is_default_wep_key)
 +                      ret = iwl_remove_default_wep_key(priv, ctx, key);
 +              else
 +                      ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
 +
 +              IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
 +              break;
 +      default:
 +              ret = -EINVAL;
 +      }
 +
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return ret;
 +}
 +
 +static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
 +                                 struct ieee80211_vif *vif,
 +                                 enum ieee80211_ampdu_mlme_action action,
 +                                 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
 +                                 u8 buf_size)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      int ret = -EINVAL;
 +      struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
 +      struct iwl_rxon_context *ctx =  iwl_rxon_ctx_from_vif(vif);
 +
 +      IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
 +                   sta->addr, tid);
 +
 +      if (!(priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE))
 +              return -EACCES;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      switch (action) {
 +      case IEEE80211_AMPDU_RX_START:
 +              IWL_DEBUG_HT(priv, "start Rx\n");
 +              ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
 +              break;
 +      case IEEE80211_AMPDU_RX_STOP:
 +              IWL_DEBUG_HT(priv, "stop Rx\n");
 +              ret = iwl_sta_rx_agg_stop(priv, sta, tid);
 +              if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
 +                      ret = 0;
 +              break;
 +      case IEEE80211_AMPDU_TX_START:
 +              IWL_DEBUG_HT(priv, "start Tx\n");
 +              ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
 +              break;
 +      case IEEE80211_AMPDU_TX_STOP:
 +              IWL_DEBUG_HT(priv, "stop Tx\n");
 +              ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
 +              if ((ret == 0) && (priv->agg_tids_count > 0)) {
 +                      priv->agg_tids_count--;
 +                      IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
 +                                   priv->agg_tids_count);
 +              }
 +              if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
 +                      ret = 0;
 +              if (!priv->agg_tids_count && priv->cfg->ht_params &&
 +                  priv->cfg->ht_params->use_rts_for_aggregation) {
 +                      /*
 +                       * switch off RTS/CTS if it was previously enabled
 +                       */
 +                      sta_priv->lq_sta.lq.general_params.flags &=
 +                              ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
 +                      iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
 +                                      &sta_priv->lq_sta.lq, CMD_ASYNC, false);
 +              }
 +              break;
 +      case IEEE80211_AMPDU_TX_OPERATIONAL:
 +              buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
 +
 +              iwl_trans_tx_agg_setup(trans(priv), ctx->ctxid, iwl_sta_id(sta),
 +                              tid, buf_size);
 +
 +              /*
 +               * If the limit is 0, then it wasn't initialised yet,
 +               * use the default. We can do that since we take the
 +               * minimum below, and we don't want to go above our
 +               * default due to hardware restrictions.
 +               */
 +              if (sta_priv->max_agg_bufsize == 0)
 +                      sta_priv->max_agg_bufsize =
 +                              LINK_QUAL_AGG_FRAME_LIMIT_DEF;
 +
 +              /*
 +               * Even though in theory the peer could have different
 +               * aggregation reorder buffer sizes for different sessions,
 +               * our ucode doesn't allow for that and has a global limit
 +               * for each station. Therefore, use the minimum of all the
 +               * aggregation sessions and our default value.
 +               */
 +              sta_priv->max_agg_bufsize =
 +                      min(sta_priv->max_agg_bufsize, buf_size);
 +
 +              if (priv->cfg->ht_params &&
 +                  priv->cfg->ht_params->use_rts_for_aggregation) {
 +                      /*
 +                       * switch to RTS/CTS if it is the prefer protection
 +                       * method for HT traffic
 +                       */
 +
 +                      sta_priv->lq_sta.lq.general_params.flags |=
 +                              LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
 +              }
 +              priv->agg_tids_count++;
 +              IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
 +                           priv->agg_tids_count);
 +
 +              sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
 +                      sta_priv->max_agg_bufsize;
 +
 +              iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
 +                              &sta_priv->lq_sta.lq, CMD_ASYNC, false);
 +
 +              IWL_INFO(priv, "Tx aggregation enabled on ra = %pM tid = %d\n",
 +                       sta->addr, tid);
 +              ret = 0;
 +              break;
 +      }
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +      return ret;
 +}
 +
 +static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
 +                            struct ieee80211_vif *vif,
 +                            struct ieee80211_sta *sta)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
 +      struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
 +      bool is_ap = vif->type == NL80211_IFTYPE_STATION;
 +      int ret = 0;
 +      u8 sta_id;
 +
 +      IWL_DEBUG_MAC80211(priv, "received request to add station %pM\n",
 +                      sta->addr);
 +      mutex_lock(&priv->shrd->mutex);
 +      IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
 +                      sta->addr);
 +      sta_priv->sta_id = IWL_INVALID_STATION;
 +
 +      atomic_set(&sta_priv->pending_frames, 0);
 +      if (vif->type == NL80211_IFTYPE_AP)
 +              sta_priv->client = true;
 +
 +      ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
 +                                   is_ap, sta, &sta_id);
 +      if (ret) {
 +              IWL_ERR(priv, "Unable to add station %pM (%d)\n",
 +                      sta->addr, ret);
 +              /* Should we return success if return code is EEXIST ? */
 +              goto out;
 +      }
 +
 +      sta_priv->sta_id = sta_id;
 +
 +      /* Initialize rate scaling */
 +      IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
 +                     sta->addr);
 +      iwl_rs_rate_init(priv, sta, sta_id);
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return ret;
 +}
 +
 +static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
 +                              struct ieee80211_channel_switch *ch_switch)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      const struct iwl_channel_info *ch_info;
 +      struct ieee80211_conf *conf = &hw->conf;
 +      struct ieee80211_channel *channel = ch_switch->channel;
 +      struct iwl_ht_config *ht_conf = &priv->current_ht_config;
 +      /*
 +       * MULTI-FIXME
 +       * When we add support for multiple interfaces, we need to
 +       * revisit this. The channel switch command in the device
 +       * only affects the BSS context, but what does that really
 +       * mean? And what if we get a CSA on the second interface?
 +       * This needs a lot of work.
 +       */
 +      struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
 +      u16 ch;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (iwl_is_rfkill(priv->shrd))
 +              goto out;
 +
 +      if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
 +          test_bit(STATUS_SCANNING, &priv->shrd->status) ||
 +          test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status))
 +              goto out;
 +
 +      if (!iwl_is_associated_ctx(ctx))
 +              goto out;
 +
 +      if (!priv->cfg->lib->set_channel_switch)
 +              goto out;
 +
 +      ch = channel->hw_value;
 +      if (le16_to_cpu(ctx->active.channel) == ch)
 +              goto out;
 +
 +      ch_info = iwl_get_channel_info(priv, channel->band, ch);
 +      if (!is_channel_valid(ch_info)) {
 +              IWL_DEBUG_MAC80211(priv, "invalid channel\n");
 +              goto out;
 +      }
 +
 +      spin_lock_irq(&priv->shrd->lock);
 +
 +      priv->current_ht_config.smps = conf->smps_mode;
 +
 +      /* Configure HT40 channels */
 +      ctx->ht.enabled = conf_is_ht(conf);
 +      if (ctx->ht.enabled)
 +              iwlagn_config_ht40(conf, ctx);
 +      else
 +              ctx->ht.is_40mhz = false;
 +
 +      if ((le16_to_cpu(ctx->staging.channel) != ch))
 +              ctx->staging.flags = 0;
 +
 +      iwl_set_rxon_channel(priv, channel, ctx);
 +      iwl_set_rxon_ht(priv, ht_conf);
 +      iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
 +
 +      spin_unlock_irq(&priv->shrd->lock);
 +
 +      iwl_set_rate(priv);
 +      /*
 +       * at this point, staging_rxon has the
 +       * configuration for channel switch
 +       */
 +      set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
 +      priv->switch_channel = cpu_to_le16(ch);
 +      if (priv->cfg->lib->set_channel_switch(priv, ch_switch)) {
 +              clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
 +              priv->switch_channel = 0;
 +              ieee80211_chswitch_done(ctx->vif, false);
 +      }
 +
 +out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +}
 +
 +static void iwlagn_configure_filter(struct ieee80211_hw *hw,
 +                                  unsigned int changed_flags,
 +                                  unsigned int *total_flags,
 +                                  u64 multicast)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      __le32 filter_or = 0, filter_nand = 0;
 +      struct iwl_rxon_context *ctx;
 +
 +#define CHK(test, flag)       do { \
 +      if (*total_flags & (test))              \
 +              filter_or |= (flag);            \
 +      else                                    \
 +              filter_nand |= (flag);          \
 +      } while (0)
 +
 +      IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
 +                      changed_flags, *total_flags);
 +
 +      CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
 +      /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
 +      CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
 +      CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
 +
 +#undef CHK
 +
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      for_each_context(priv, ctx) {
 +              ctx->staging.filter_flags &= ~filter_nand;
 +              ctx->staging.filter_flags |= filter_or;
 +
 +              /*
 +               * Not committing directly because hardware can perform a scan,
 +               * but we'll eventually commit the filter flags change anyway.
 +               */
 +      }
 +
 +      mutex_unlock(&priv->shrd->mutex);
 +
 +      /*
 +       * Receiving all multicast frames is always enabled by the
 +       * default flags setup in iwl_connection_init_rx_config()
 +       * since we currently do not support programming multicast
 +       * filters into the device.
 +       */
 +      *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
 +                      FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
 +}
 +
 +static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      mutex_lock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
 +              IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
 +              goto done;
 +      }
 +      if (iwl_is_rfkill(priv->shrd)) {
 +              IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
 +              goto done;
 +      }
 +
 +      /*
 +       * mac80211 will not push any more frames for transmit
 +       * until the flush is completed
 +       */
 +      if (drop) {
 +              IWL_DEBUG_MAC80211(priv, "send flush command\n");
 +              if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
 +                      IWL_ERR(priv, "flush request fail\n");
 +                      goto done;
 +              }
 +      }
 +      IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
 +      iwl_trans_wait_tx_queue_empty(trans(priv));
 +done:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +}
 +
 +static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
 +                                   struct ieee80211_channel *channel,
 +                                   enum nl80211_channel_type channel_type,
 +                                   int duration)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
 +      int err = 0;
 +
 +      if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
 +              return -EOPNOTSUPP;
 +
 +      if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
 +              return -EOPNOTSUPP;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) {
 +              err = -EBUSY;
 +              goto out;
 +      }
 +
 +      priv->hw_roc_channel = channel;
 +      priv->hw_roc_chantype = channel_type;
 +      /* convert from ms to TU */
 +      priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
 +      priv->hw_roc_start_notified = false;
 +      cancel_delayed_work(&priv->hw_roc_disable_work);
 +
 +      if (!ctx->is_active) {
 +              static const struct iwl_qos_info default_qos_data = {
 +                      .def_qos_parm = {
 +                              .ac[0] = {
 +                                      .cw_min = cpu_to_le16(3),
 +                                      .cw_max = cpu_to_le16(7),
 +                                      .aifsn = 2,
 +                                      .edca_txop = cpu_to_le16(1504),
 +                              },
 +                              .ac[1] = {
 +                                      .cw_min = cpu_to_le16(7),
 +                                      .cw_max = cpu_to_le16(15),
 +                                      .aifsn = 2,
 +                                      .edca_txop = cpu_to_le16(3008),
 +                              },
 +                              .ac[2] = {
 +                                      .cw_min = cpu_to_le16(15),
 +                                      .cw_max = cpu_to_le16(1023),
 +                                      .aifsn = 3,
 +                              },
 +                              .ac[3] = {
 +                                      .cw_min = cpu_to_le16(15),
 +                                      .cw_max = cpu_to_le16(1023),
 +                                      .aifsn = 7,
 +                              },
 +                      },
 +              };
 +
 +              ctx->is_active = true;
 +              ctx->qos_data = default_qos_data;
 +              ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
 +              memcpy(ctx->staging.node_addr,
 +                     priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
 +                     ETH_ALEN);
 +              memcpy(ctx->staging.bssid_addr,
 +                     priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
 +                     ETH_ALEN);
 +              err = iwlagn_commit_rxon(priv, ctx);
 +              if (err)
 +                      goto out;
 +              ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
 +                                           RXON_FILTER_PROMISC_MSK |
 +                                           RXON_FILTER_CTL2HOST_MSK;
 +
 +              err = iwlagn_commit_rxon(priv, ctx);
 +              if (err) {
 +                      iwlagn_disable_roc(priv);
 +                      goto out;
 +              }
 +              priv->hw_roc_setup = true;
 +      }
 +
 +      err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
 +      if (err)
 +              iwlagn_disable_roc(priv);
 +
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return err;
 +}
 +
 +static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
 +              return -EOPNOTSUPP;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +      iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
 +      iwlagn_disable_roc(priv);
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return 0;
 +}
 +
 +static int iwlagn_mac_tx_sync(struct ieee80211_hw *hw,
 +                            struct ieee80211_vif *vif,
 +                            const u8 *bssid,
 +                            enum ieee80211_tx_sync_type type)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
 +      struct iwl_rxon_context *ctx = vif_priv->ctx;
 +      int ret;
 +      u8 sta_id;
 +
++      if (ctx->ctxid != IWL_RXON_CTX_PAN)
++              return 0;
++
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (iwl_is_associated_ctx(ctx)) {
 +              ret = 0;
 +              goto out;
 +      }
 +
 +      if (ctx->preauth_bssid || test_bit(STATUS_SCAN_HW,
 +          &priv->shrd->status)) {
 +              ret = -EBUSY;
 +              goto out;
 +      }
 +
 +      ret = iwl_add_station_common(priv, ctx, bssid, true, NULL, &sta_id);
 +      if (ret)
 +              goto out;
 +
 +      if (WARN_ON(sta_id != ctx->ap_sta_id)) {
 +              ret = -EIO;
 +              goto out_remove_sta;
 +      }
 +
 +      memcpy(ctx->bssid, bssid, ETH_ALEN);
 +      ctx->preauth_bssid = true;
 +
 +      ret = iwlagn_commit_rxon(priv, ctx);
 +
 +      if (ret == 0)
 +              goto out;
 +
 + out_remove_sta:
 +      iwl_remove_station(priv, sta_id, bssid);
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return ret;
 +}
 +
 +static void iwlagn_mac_finish_tx_sync(struct ieee80211_hw *hw,
 +                                 struct ieee80211_vif *vif,
 +                                 const u8 *bssid,
 +                                 enum ieee80211_tx_sync_type type)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
 +      struct iwl_rxon_context *ctx = vif_priv->ctx;
 +
++      if (ctx->ctxid != IWL_RXON_CTX_PAN)
++              return;
++
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (iwl_is_associated_ctx(ctx))
 +              goto out;
 +
 +      iwl_remove_station(priv, ctx->ap_sta_id, bssid);
 +      ctx->preauth_bssid = false;
 +      /* no need to commit */
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +}
 +
 +static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
 +                         enum ieee80211_rssi_event rssi_event)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (priv->cfg->bt_params &&
 +                      priv->cfg->bt_params->advanced_bt_coexist) {
 +              if (rssi_event == RSSI_EVENT_LOW)
 +                      priv->bt_enable_pspoll = true;
 +              else if (rssi_event == RSSI_EVENT_HIGH)
 +                      priv->bt_enable_pspoll = false;
 +
 +              iwlagn_send_advance_bt_config(priv);
 +      } else {
 +              IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
 +                              "ignoring RSSI callback\n");
 +      }
 +
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +}
 +
 +static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
 +                         struct ieee80211_sta *sta, bool set)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      queue_work(priv->shrd->workqueue, &priv->beacon_update);
 +
 +      return 0;
 +}
 +
 +static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
 +                  struct ieee80211_vif *vif, u16 queue,
 +                  const struct ieee80211_tx_queue_params *params)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
 +      struct iwl_rxon_context *ctx = vif_priv->ctx;
 +      unsigned long flags;
 +      int q;
 +
 +      if (WARN_ON(!ctx))
 +              return -EINVAL;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      if (!iwl_is_ready_rf(priv->shrd)) {
 +              IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
 +              return -EIO;
 +      }
 +
 +      if (queue >= AC_NUM) {
 +              IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
 +              return 0;
 +      }
 +
 +      q = AC_NUM - 1 - queue;
 +
 +      spin_lock_irqsave(&priv->shrd->lock, flags);
 +
 +      ctx->qos_data.def_qos_parm.ac[q].cw_min =
 +              cpu_to_le16(params->cw_min);
 +      ctx->qos_data.def_qos_parm.ac[q].cw_max =
 +              cpu_to_le16(params->cw_max);
 +      ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
 +      ctx->qos_data.def_qos_parm.ac[q].edca_txop =
 +                      cpu_to_le16((params->txop * 32));
 +
 +      ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
 +
 +      spin_unlock_irqrestore(&priv->shrd->lock, flags);
 +
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +      return 0;
 +}
 +
 +static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +
 +      return priv->ibss_manager == IWL_IBSS_MANAGER;
 +}
 +
 +static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
 +{
 +      iwl_connection_init_rx_config(priv, ctx);
 +
 +      iwlagn_set_rxon_chain(priv, ctx);
 +
 +      return iwlagn_commit_rxon(priv, ctx);
 +}
 +
 +static int iwl_setup_interface(struct iwl_priv *priv,
 +                             struct iwl_rxon_context *ctx)
 +{
 +      struct ieee80211_vif *vif = ctx->vif;
 +      int err;
 +
 +      lockdep_assert_held(&priv->shrd->mutex);
 +
 +      /*
 +       * This variable will be correct only when there's just
 +       * a single context, but all code using it is for hardware
 +       * that supports only one context.
 +       */
 +      priv->iw_mode = vif->type;
 +
 +      ctx->is_active = true;
 +
 +      err = iwl_set_mode(priv, ctx);
 +      if (err) {
 +              if (!ctx->always_active)
 +                      ctx->is_active = false;
 +              return err;
 +      }
 +
 +      if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist &&
 +          vif->type == NL80211_IFTYPE_ADHOC) {
 +              /*
 +               * pretend to have high BT traffic as long as we
 +               * are operating in IBSS mode, as this will cause
 +               * the rate scaling etc. to behave as intended.
 +               */
 +              priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
 +      }
 +
 +      return 0;
 +}
 +
 +static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
 +                           struct ieee80211_vif *vif)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
 +      struct iwl_rxon_context *tmp, *ctx = NULL;
 +      int err;
 +      enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
 +
 +      IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
 +                         viftype, vif->addr);
 +
 +      cancel_delayed_work_sync(&priv->hw_roc_disable_work);
 +
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      iwlagn_disable_roc(priv);
 +
 +      if (!iwl_is_ready_rf(priv->shrd)) {
 +              IWL_WARN(priv, "Try to add interface when device not ready\n");
 +              err = -EINVAL;
 +              goto out;
 +      }
 +
 +      for_each_context(priv, tmp) {
 +              u32 possible_modes =
 +                      tmp->interface_modes | tmp->exclusive_interface_modes;
 +
 +              if (tmp->vif) {
 +                      /* check if this busy context is exclusive */
 +                      if (tmp->exclusive_interface_modes &
 +                                              BIT(tmp->vif->type)) {
 +                              err = -EINVAL;
 +                              goto out;
 +                      }
 +                      continue;
 +              }
 +
 +              if (!(possible_modes & BIT(viftype)))
 +                      continue;
 +
 +              /* have maybe usable context w/o interface */
 +              ctx = tmp;
 +              break;
 +      }
 +
 +      if (!ctx) {
 +              err = -EOPNOTSUPP;
 +              goto out;
 +      }
 +
 +      vif_priv->ctx = ctx;
 +      ctx->vif = vif;
 +
 +      err = iwl_setup_interface(priv, ctx);
 +      if (!err)
 +              goto out;
 +
 +      ctx->vif = NULL;
 +      priv->iw_mode = NL80211_IFTYPE_STATION;
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +      return err;
 +}
 +
 +static void iwl_teardown_interface(struct iwl_priv *priv,
 +                                 struct ieee80211_vif *vif,
 +                                 bool mode_change)
 +{
 +      struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
 +
 +      lockdep_assert_held(&priv->shrd->mutex);
 +
 +      if (priv->scan_vif == vif) {
 +              iwl_scan_cancel_timeout(priv, 200);
 +              iwl_force_scan_end(priv);
 +      }
 +
 +      if (!mode_change) {
 +              iwl_set_mode(priv, ctx);
 +              if (!ctx->always_active)
 +                      ctx->is_active = false;
 +      }
 +
 +      /*
 +       * When removing the IBSS interface, overwrite the
 +       * BT traffic load with the stored one from the last
 +       * notification, if any. If this is a device that
 +       * doesn't implement this, this has no effect since
 +       * both values are the same and zero.
 +       */
 +      if (vif->type == NL80211_IFTYPE_ADHOC)
 +              priv->bt_traffic_load = priv->last_bt_traffic_load;
 +}
 +
 +static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
 +                            struct ieee80211_vif *vif)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (WARN_ON(ctx->vif != vif)) {
 +              struct iwl_rxon_context *tmp;
 +              IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
 +              for_each_context(priv, tmp)
 +                      IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
 +                              tmp->ctxid, tmp, tmp->vif);
 +      }
 +      ctx->vif = NULL;
 +
 +      iwl_teardown_interface(priv, vif, false);
 +
 +      mutex_unlock(&priv->shrd->mutex);
 +
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +}
 +
 +static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
 +                              struct ieee80211_vif *vif,
 +                              enum nl80211_iftype newtype, bool newp2p)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
 +      struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS];
 +      struct iwl_rxon_context *tmp;
 +      enum nl80211_iftype newviftype = newtype;
 +      u32 interface_modes;
 +      int err;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      newtype = ieee80211_iftype_p2p(newtype, newp2p);
 +
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      if (!ctx->vif || !iwl_is_ready_rf(priv->shrd)) {
 +              /*
 +               * Huh? But wait ... this can maybe happen when
 +               * we're in the middle of a firmware restart!
 +               */
 +              err = -EBUSY;
 +              goto out;
 +      }
 +
 +      interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
 +
 +      if (!(interface_modes & BIT(newtype))) {
 +              err = -EBUSY;
 +              goto out;
 +      }
 +
 +      /*
 +       * Refuse a change that should be done by moving from the PAN
 +       * context to the BSS context instead, if the BSS context is
 +       * available and can support the new interface type.
 +       */
 +      if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif &&
 +          (bss_ctx->interface_modes & BIT(newtype) ||
 +           bss_ctx->exclusive_interface_modes & BIT(newtype))) {
 +              BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
 +              err = -EBUSY;
 +              goto out;
 +      }
 +
 +      if (ctx->exclusive_interface_modes & BIT(newtype)) {
 +              for_each_context(priv, tmp) {
 +                      if (ctx == tmp)
 +                              continue;
 +
 +                      if (!tmp->vif)
 +                              continue;
 +
 +                      /*
 +                       * The current mode switch would be exclusive, but
 +                       * another context is active ... refuse the switch.
 +                       */
 +                      err = -EBUSY;
 +                      goto out;
 +              }
 +      }
 +
 +      /* success */
 +      iwl_teardown_interface(priv, vif, true);
 +      vif->type = newviftype;
 +      vif->p2p = newp2p;
 +      err = iwl_setup_interface(priv, ctx);
 +      WARN_ON(err);
 +      /*
 +       * We've switched internally, but submitting to the
 +       * device may have failed for some reason. Mask this
 +       * error, because otherwise mac80211 will not switch
 +       * (and set the interface type back) and we'll be
 +       * out of sync with it.
 +       */
 +      err = 0;
 +
 + out:
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return err;
 +}
 +
 +static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
 +                  struct ieee80211_vif *vif,
 +                  struct cfg80211_scan_request *req)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      int ret;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      if (req->n_channels == 0)
 +              return -EINVAL;
 +
 +      mutex_lock(&priv->shrd->mutex);
 +
 +      /*
 +       * If an internal scan is in progress, just set
 +       * up the scan_request as per above.
 +       */
 +      if (priv->scan_type != IWL_SCAN_NORMAL) {
 +              IWL_DEBUG_SCAN(priv,
 +                             "SCAN request during internal scan - defer\n");
 +              priv->scan_request = req;
 +              priv->scan_vif = vif;
 +              ret = 0;
 +      } else {
 +              priv->scan_request = req;
 +              priv->scan_vif = vif;
 +              /*
 +               * mac80211 will only ask for one band at a time
 +               * so using channels[0] here is ok
 +               */
 +              ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
 +                                      req->channels[0]->band);
 +              if (ret) {
 +                      priv->scan_request = NULL;
 +                      priv->scan_vif = NULL;
 +              }
 +      }
 +
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      mutex_unlock(&priv->shrd->mutex);
 +
 +      return ret;
 +}
 +
 +static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
 +                     struct ieee80211_vif *vif,
 +                     struct ieee80211_sta *sta)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
 +      int ret;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter: received request to remove "
 +                         "station %pM\n", sta->addr);
 +      mutex_lock(&priv->shrd->mutex);
 +      IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
 +                      sta->addr);
 +      ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
 +      if (ret)
 +              IWL_DEBUG_QUIET_RFKILL(priv, "Error removing station %pM\n",
 +                      sta->addr);
 +      mutex_unlock(&priv->shrd->mutex);
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +
 +      return ret;
 +}
 +
 +static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
 +{
 +      unsigned long flags;
 +
 +      spin_lock_irqsave(&priv->shrd->sta_lock, flags);
 +      priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
 +      priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
 +      priv->stations[sta_id].sta.sta.modify_mask = 0;
 +      priv->stations[sta_id].sta.sleep_tx_count = 0;
 +      priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
 +      iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
 +      spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
 +
 +}
 +
 +static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
 +                         struct ieee80211_vif *vif,
 +                         enum sta_notify_cmd cmd,
 +                         struct ieee80211_sta *sta)
 +{
 +      struct iwl_priv *priv = hw->priv;
 +      struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
 +      int sta_id;
 +
 +      IWL_DEBUG_MAC80211(priv, "enter\n");
 +
 +      switch (cmd) {
 +      case STA_NOTIFY_SLEEP:
 +              WARN_ON(!sta_priv->client);
 +              sta_priv->asleep = true;
 +              if (atomic_read(&sta_priv->pending_frames) > 0)
 +                      ieee80211_sta_block_awake(hw, sta, true);
 +              break;
 +      case STA_NOTIFY_AWAKE:
 +              WARN_ON(!sta_priv->client);
 +              if (!sta_priv->asleep)
 +                      break;
 +              sta_priv->asleep = false;
 +              sta_id = iwl_sta_id(sta);
 +              if (sta_id != IWL_INVALID_STATION)
 +                      iwl_sta_modify_ps_wake(priv, sta_id);
 +              break;
 +      default:
 +              break;
 +      }
 +      IWL_DEBUG_MAC80211(priv, "leave\n");
 +}
 +
 +struct ieee80211_ops iwlagn_hw_ops = {
 +      .tx = iwlagn_mac_tx,
 +      .start = iwlagn_mac_start,
 +      .stop = iwlagn_mac_stop,
 +#ifdef CONFIG_PM_SLEEP
 +      .suspend = iwlagn_mac_suspend,
 +      .resume = iwlagn_mac_resume,
 +#endif
 +      .add_interface = iwlagn_mac_add_interface,
 +      .remove_interface = iwlagn_mac_remove_interface,
 +      .change_interface = iwlagn_mac_change_interface,
 +      .config = iwlagn_mac_config,
 +      .configure_filter = iwlagn_configure_filter,
 +      .set_key = iwlagn_mac_set_key,
 +      .update_tkip_key = iwlagn_mac_update_tkip_key,
 +      .set_rekey_data = iwlagn_mac_set_rekey_data,
 +      .conf_tx = iwlagn_mac_conf_tx,
 +      .bss_info_changed = iwlagn_bss_info_changed,
 +      .ampdu_action = iwlagn_mac_ampdu_action,
 +      .hw_scan = iwlagn_mac_hw_scan,
 +      .sta_notify = iwlagn_mac_sta_notify,
 +      .sta_add = iwlagn_mac_sta_add,
 +      .sta_remove = iwlagn_mac_sta_remove,
 +      .channel_switch = iwlagn_mac_channel_switch,
 +      .flush = iwlagn_mac_flush,
 +      .tx_last_beacon = iwlagn_mac_tx_last_beacon,
 +      .remain_on_channel = iwlagn_mac_remain_on_channel,
 +      .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
 +      .rssi_callback = iwlagn_mac_rssi_callback,
 +      CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
 +      CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
 +      .tx_sync = iwlagn_mac_tx_sync,
 +      .finish_tx_sync = iwlagn_mac_finish_tx_sync,
 +      .set_tim = iwlagn_mac_set_tim,
 +};
 +
 +/* This function both allocates and initializes hw and priv. */
 +struct ieee80211_hw *iwl_alloc_all(void)
 +{
 +      struct iwl_priv *priv;
 +      /* mac80211 allocates memory for this device instance, including
 +       *   space for this driver's private structure */
 +      struct ieee80211_hw *hw;
 +
 +      hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
 +      if (!hw)
 +              goto out;
 +
 +      priv = hw->priv;
 +      priv->hw = hw;
 +
 +out:
 +      return hw;
 +}
index 84c934c0a5455950f1244de76ebcfe3b8b5a4aaf,32c535f5ce313383c1f59ae1339dcbea3c4533a0..520e8286db28f92cee618acdbaa00a310e5d41ab
@@@ -10,7 -10,6 +10,7 @@@
  
  #include <linux/ssb/ssb.h>
  #include <linux/pci.h>
 +#include <linux/export.h>
  #include <linux/delay.h>
  #include <linux/ssb/ssb_embedded.h>
  
@@@ -517,10 -516,14 +517,14 @@@ static void ssb_pcicore_pcie_setup_work
  
  static void __devinit ssb_pcicore_init_clientmode(struct ssb_pcicore *pc)
  {
-       ssb_pcicore_fix_sprom_core_index(pc);
+       struct ssb_device *pdev = pc->dev;
+       struct ssb_bus *bus = pdev->bus;
+       if (bus->bustype == SSB_BUSTYPE_PCI)
+               ssb_pcicore_fix_sprom_core_index(pc);
  
        /* Disable PCI interrupts. */
-       ssb_write32(pc->dev, SSB_INTVEC, 0);
+       ssb_write32(pdev, SSB_INTVEC, 0);
  
        /* Additional PCIe always once-executed workarounds */
        if (pc->dev->id.coreid == SSB_DEV_PCIE) {
diff --combined net/mac80211/agg-tx.c
index 5c7f0c3c74cb66ab1f061dcc8fca569eeaf6b836,d448f7a3dbc034498ea2948c0a5ec2e0fc87604b..88754c067f1e55f40d72c01f0548a8cd8e723ef2
@@@ -15,7 -15,6 +15,7 @@@
  
  #include <linux/ieee80211.h>
  #include <linux/slab.h>
 +#include <linux/export.h>
  #include <net/mac80211.h>
  #include "ieee80211_i.h"
  #include "driver-ops.h"
@@@ -55,8 -54,6 +55,8 @@@
   * @ampdu_action function will be called with the action
   * %IEEE80211_AMPDU_TX_STOP. In this case, the call must not fail,
   * and the driver must later call ieee80211_stop_tx_ba_cb_irqsafe().
 + * Note that the sta can get destroyed before the BA tear down is
 + * complete.
   */
  
  static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
        memcpy(mgmt->da, da, ETH_ALEN);
        memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
        if (sdata->vif.type == NL80211_IFTYPE_AP ||
 -          sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
 +          sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
 +          sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
                memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
        else if (sdata->vif.type == NL80211_IFTYPE_STATION)
                memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
 +      else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
 +              memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
  
        mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
                                          IEEE80211_STYPE_ACTION);
@@@ -190,7 -184,6 +190,7 @@@ int ___ieee80211_stop_tx_ba_session(str
  #endif /* CONFIG_MAC80211_HT_DEBUG */
  
        del_timer_sync(&tid_tx->addba_resp_timer);
 +      del_timer_sync(&tid_tx->session_timer);
  
        /*
         * After this packets are no longer handed right through
@@@ -309,6 -302,38 +309,38 @@@ ieee80211_wake_queue_agg(struct ieee802
        __release(agg_queue);
  }
  
+ /*
+  * splice packets from the STA's pending to the local pending,
+  * requires a call to ieee80211_agg_splice_finish later
+  */
+ static void __acquires(agg_queue)
+ ieee80211_agg_splice_packets(struct ieee80211_local *local,
+                            struct tid_ampdu_tx *tid_tx, u16 tid)
+ {
+       int queue = ieee80211_ac_from_tid(tid);
+       unsigned long flags;
+       ieee80211_stop_queue_agg(local, tid);
+       if (WARN(!tid_tx, "TID %d gone but expected when splicing aggregates"
+                         " from the pending queue\n", tid))
+               return;
+       if (!skb_queue_empty(&tid_tx->pending)) {
+               spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
+               /* copy over remaining packets */
+               skb_queue_splice_tail_init(&tid_tx->pending,
+                                          &local->pending[queue]);
+               spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
+       }
+ }
+ static void __releases(agg_queue)
+ ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid)
+ {
+       ieee80211_wake_queue_agg(local, tid);
+ }
  void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
  {
        struct tid_ampdu_tx *tid_tx;
        tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
  
        /*
-        * While we're asking the driver about the aggregation,
-        * stop the AC queue so that we don't have to worry
-        * about frames that came in while we were doing that,
-        * which would require us to put them to the AC pending
-        * afterwards which just makes the code more complex.
+        * Start queuing up packets for this aggregation session.
+        * We're going to release them once the driver is OK with
+        * that.
         */
-       ieee80211_stop_queue_agg(local, tid);
        clear_bit(HT_AGG_STATE_WANT_START, &tid_tx->state);
  
        /*
-        * make sure no packets are being processed to get
-        * valid starting sequence number
+        * Make sure no packets are being processed. This ensures that
+        * we have a valid starting sequence number and that in-flight
+        * packets have been flushed out and no packets for this TID
+        * will go into the driver during the ampdu_action call.
         */
        synchronize_net();
  
                                        " tid %d\n", tid);
  #endif
                spin_lock_bh(&sta->lock);
+               ieee80211_agg_splice_packets(local, tid_tx, tid);
                ieee80211_assign_tid_tx(sta, tid, NULL);
+               ieee80211_agg_splice_finish(local, tid);
                spin_unlock_bh(&sta->lock);
  
-               ieee80211_wake_queue_agg(local, tid);
                kfree_rcu(tid_tx, rcu_head);
                return;
        }
  
-       /* we can take packets again now */
-       ieee80211_wake_queue_agg(local, tid);
        /* activate the timer for the recipient's addBA response */
        mod_timer(&tid_tx->addba_resp_timer, jiffies + ADDBA_RESP_INTERVAL);
  #ifdef CONFIG_MAC80211_HT_DEBUG
                                     tid_tx->timeout);
  }
  
 +/*
 + * After accepting the AddBA Response we activated a timer,
 + * resetting it after each frame that we send.
 + */
 +static void sta_tx_agg_session_timer_expired(unsigned long data)
 +{
 +      /* not an elegant detour, but there is no choice as the timer passes
 +       * only one argument, and various sta_info are needed here, so init
 +       * flow in sta_info_create gives the TID as data, while the timer_to_id
 +       * array gives the sta through container_of */
 +      u8 *ptid = (u8 *)data;
 +      u8 *timer_to_id = ptid - *ptid;
 +      struct sta_info *sta = container_of(timer_to_id, struct sta_info,
 +                                       timer_to_tid[0]);
 +
 +#ifdef CONFIG_MAC80211_HT_DEBUG
 +      printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid);
 +#endif
 +
 +      ieee80211_stop_tx_ba_session(&sta->sta, *ptid);
 +}
 +
  int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
                                  u16 timeout)
  {
               pubsta->addr, tid);
  #endif /* CONFIG_MAC80211_HT_DEBUG */
  
 -      /*
 -       * The aggregation code is not prepared to handle
 -       * anything but STA/AP due to the BSSID handling.
 -       * IBSS could work in the code but isn't supported
 -       * by drivers or the standard.
 -       */
        if (sdata->vif.type != NL80211_IFTYPE_STATION &&
 +          sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
            sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
 -          sdata->vif.type != NL80211_IFTYPE_AP)
 +          sdata->vif.type != NL80211_IFTYPE_AP &&
 +          sdata->vif.type != NL80211_IFTYPE_ADHOC)
                return -EINVAL;
  
        if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
                return -EINVAL;
        }
  
 +      /*
 +       * 802.11n-2009 11.5.1.1: If the initiating STA is an HT STA, is a
 +       * member of an IBSS, and has no other existing Block Ack agreement
 +       * with the recipient STA, then the initiating STA shall transmit a
 +       * Probe Request frame to the recipient STA and shall not transmit an
 +       * ADDBA Request frame unless it receives a Probe Response frame
 +       * from the recipient within dot11ADDBAFailureTimeout.
 +       *
 +       * The probe request mechanism for ADDBA is currently not implemented,
 +       * but we only build up Block Ack session with HT STAs. This information
 +       * is set when we receive a bss info from a probe response or a beacon.
 +       */
 +      if (sta->sdata->vif.type == NL80211_IFTYPE_ADHOC &&
 +          !sta->sta.ht_cap.ht_supported) {
 +#ifdef CONFIG_MAC80211_HT_DEBUG
 +              printk(KERN_DEBUG "BA request denied - IBSS STA %pM"
 +                     "does not advertise HT support\n", pubsta->addr);
 +#endif /* CONFIG_MAC80211_HT_DEBUG */
 +              return -EINVAL;
 +      }
 +
        spin_lock_bh(&sta->lock);
  
        /* we have tried too many times, receiver does not want A-MPDU */
  
        tid_tx->timeout = timeout;
  
 -      /* Tx timer */
 +      /* response timer */
        tid_tx->addba_resp_timer.function = sta_addba_resp_timer_expired;
        tid_tx->addba_resp_timer.data = (unsigned long)&sta->timer_to_tid[tid];
        init_timer(&tid_tx->addba_resp_timer);
  
 +      /* tx timer */
 +      tid_tx->session_timer.function = sta_tx_agg_session_timer_expired;
 +      tid_tx->session_timer.data = (unsigned long)&sta->timer_to_tid[tid];
 +      init_timer(&tid_tx->session_timer);
 +
        /* assign a dialog token */
        sta->ampdu_mlme.dialog_token_allocator++;
        tid_tx->dialog_token = sta->ampdu_mlme.dialog_token_allocator;
  }
  EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  
- /*
-  * splice packets from the STA's pending to the local pending,
-  * requires a call to ieee80211_agg_splice_finish later
-  */
- static void __acquires(agg_queue)
- ieee80211_agg_splice_packets(struct ieee80211_local *local,
-                            struct tid_ampdu_tx *tid_tx, u16 tid)
- {
-       int queue = ieee80211_ac_from_tid(tid);
-       unsigned long flags;
-       ieee80211_stop_queue_agg(local, tid);
-       if (WARN(!tid_tx, "TID %d gone but expected when splicing aggregates"
-                         " from the pending queue\n", tid))
-               return;
-       if (!skb_queue_empty(&tid_tx->pending)) {
-               spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
-               /* copy over remaining packets */
-               skb_queue_splice_tail_init(&tid_tx->pending,
-                                          &local->pending[queue]);
-               spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
-       }
- }
- static void __releases(agg_queue)
- ieee80211_agg_splice_finish(struct ieee80211_local *local, u16 tid)
- {
-       ieee80211_wake_queue_agg(local, tid);
- }
  static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
                                         struct sta_info *sta, u16 tid)
  {
@@@ -601,7 -546,7 +597,7 @@@ void ieee80211_start_tx_ba_cb(struct ie
        }
  
        mutex_lock(&local->sta_mtx);
 -      sta = sta_info_get(sdata, ra);
 +      sta = sta_info_get_bss(sdata, ra);
        if (!sta) {
                mutex_unlock(&local->sta_mtx);
  #ifdef CONFIG_MAC80211_HT_DEBUG
@@@ -730,7 -675,7 +726,7 @@@ void ieee80211_stop_tx_ba_cb(struct iee
  
        mutex_lock(&local->sta_mtx);
  
 -      sta = sta_info_get(sdata, ra);
 +      sta = sta_info_get_bss(sdata, ra);
        if (!sta) {
  #ifdef CONFIG_MAC80211_HT_DEBUG
                printk(KERN_DEBUG "Could not find station: %pM\n", ra);
@@@ -868,11 -813,6 +864,11 @@@ void ieee80211_process_addba_resp(struc
                        ieee80211_agg_tx_operational(local, sta, tid);
  
                sta->ampdu_mlme.addba_req_num[tid] = 0;
 +
 +              if (tid_tx->timeout)
 +                      mod_timer(&tid_tx->session_timer,
 +                                TU_TO_EXP_TIME(tid_tx->timeout));
 +
        } else {
                ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR,
                                                true);
diff --combined net/nfc/nci/core.c
index 37de28e973309f8efa4089e64f74b35041a325ea,25dae3f8f5c2d15e5531caa5bafd59815ade52bb..c55f233a5e2c76bda9184918f909d941afe9e98f
   *
   */
  
 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 +
  #include <linux/types.h>
  #include <linux/workqueue.h>
  #include <linux/completion.h>
 +#include <linux/export.h>
  #include <linux/sched.h>
  #include <linux/bitops.h>
  #include <linux/skbuff.h>
@@@ -71,7 -68,7 +71,7 @@@ static int __nci_request(struct nci_de
        __u32 timeout)
  {
        int rc = 0;
-       unsigned long completion_rc;
+       long completion_rc;
  
        ndev->req_status = NCI_REQ_PEND;
  
@@@ -81,7 -78,7 +81,7 @@@
                                                        &ndev->req_completion,
                                                        timeout);
  
 -      nfc_dbg("wait_for_completion return %ld", completion_rc);
 +      pr_debug("wait_for_completion return %ld\n", completion_rc);
  
        if (completion_rc > 0) {
                switch (ndev->req_status) {
@@@ -98,8 -95,8 +98,8 @@@
                        break;
                }
        } else {
 -              nfc_err("wait_for_completion_interruptible_timeout failed %ld",
 -                      completion_rc);
 +              pr_err("wait_for_completion_interruptible_timeout failed %ld\n",
 +                     completion_rc);
  
                rc = ((completion_rc == 0) ? (-ETIMEDOUT) : (completion_rc));
        }
@@@ -128,10 -125,7 +128,10 @@@ static inline int nci_request(struct nc
  
  static void nci_reset_req(struct nci_dev *ndev, unsigned long opt)
  {
 -      nci_send_cmd(ndev, NCI_OP_CORE_RESET_CMD, 0, NULL);
 +      struct nci_core_reset_cmd cmd;
 +
 +      cmd.reset_type = NCI_RESET_TYPE_RESET_CONFIG;
 +      nci_send_cmd(ndev, NCI_OP_CORE_RESET_CMD, 1, &cmd);
  }
  
  static void nci_init_req(struct nci_dev *ndev, unsigned long opt)
  
  static void nci_init_complete_req(struct nci_dev *ndev, unsigned long opt)
  {
 -      struct nci_core_conn_create_cmd conn_cmd;
        struct nci_rf_disc_map_cmd cmd;
        struct disc_map_config *cfg = cmd.mapping_configs;
        __u8 *num = &cmd.num_mapping_configs;
        int i;
  
 -      /* create static rf connection */
 -      conn_cmd.target_handle = 0;
 -      conn_cmd.num_target_specific_params = 0;
 -      nci_send_cmd(ndev, NCI_OP_CORE_CONN_CREATE_CMD, 2, &conn_cmd);
 -
        /* set rf mapping configurations */
        *num = 0;
  
@@@ -325,6 -325,8 +325,6 @@@ static void nci_cmd_timer(unsigned lon
  {
        struct nci_dev *ndev = (void *) arg;
  
 -      nfc_dbg("entry");
 -
        atomic_set(&ndev->cmd_cnt, 1);
        queue_work(ndev->cmd_wq, &ndev->cmd_work);
  }
@@@ -333,6 -335,8 +333,6 @@@ static int nci_dev_up(struct nfc_dev *n
  {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
  
 -      nfc_dbg("entry");
 -
        return nci_open_device(ndev);
  }
  
@@@ -340,6 -344,8 +340,6 @@@ static int nci_dev_down(struct nfc_dev 
  {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
  
 -      nfc_dbg("entry");
 -
        return nci_close_device(ndev);
  }
  
@@@ -348,18 -354,20 +348,18 @@@ static int nci_start_poll(struct nfc_de
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
        int rc;
  
 -      nfc_dbg("entry");
 -
        if (test_bit(NCI_DISCOVERY, &ndev->flags)) {
 -              nfc_err("unable to start poll, since poll is already active");
 +              pr_err("unable to start poll, since poll is already active\n");
                return -EBUSY;
        }
  
        if (ndev->target_active_prot) {
 -              nfc_err("there is an active target");
 +              pr_err("there is an active target\n");
                return -EBUSY;
        }
  
        if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
 -              nfc_dbg("target is active, implicitly deactivate...");
 +              pr_debug("target is active, implicitly deactivate...\n");
  
                rc = nci_request(ndev, nci_rf_deactivate_req, 0,
                        msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
@@@ -380,8 -388,10 +380,8 @@@ static void nci_stop_poll(struct nfc_de
  {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
  
 -      nfc_dbg("entry");
 -
        if (!test_bit(NCI_DISCOVERY, &ndev->flags)) {
 -              nfc_err("unable to stop poll, since poll is not active");
 +              pr_err("unable to stop poll, since poll is not active\n");
                return;
        }
  
@@@ -394,21 -404,21 +394,21 @@@ static int nci_activate_target(struct n
  {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
  
 -      nfc_dbg("entry, target_idx %d, protocol 0x%x", target_idx, protocol);
 +      pr_debug("target_idx %d, protocol 0x%x\n", target_idx, protocol);
  
        if (!test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
 -              nfc_err("there is no available target to activate");
 +              pr_err("there is no available target to activate\n");
                return -EINVAL;
        }
  
        if (ndev->target_active_prot) {
 -              nfc_err("there is already an active target");
 +              pr_err("there is already an active target\n");
                return -EBUSY;
        }
  
        if (!(ndev->target_available_prots & (1 << protocol))) {
 -              nfc_err("target does not support the requested protocol 0x%x",
 -                      protocol);
 +              pr_err("target does not support the requested protocol 0x%x\n",
 +                     protocol);
                return -EINVAL;
        }
  
@@@ -422,10 -432,10 +422,10 @@@ static void nci_deactivate_target(struc
  {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
  
 -      nfc_dbg("entry, target_idx %d", target_idx);
 +      pr_debug("target_idx %d\n", target_idx);
  
        if (!ndev->target_active_prot) {
 -              nfc_err("unable to deactivate target, no active target");
 +              pr_err("unable to deactivate target, no active target\n");
                return;
        }
  
@@@ -445,10 -455,10 +445,10 @@@ static int nci_data_exchange(struct nfc
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
        int rc;
  
 -      nfc_dbg("entry, target_idx %d, len %d", target_idx, skb->len);
 +      pr_debug("target_idx %d, len %d\n", target_idx, skb->len);
  
        if (!ndev->target_active_prot) {
 -              nfc_err("unable to exchange data, no active target");
 +              pr_err("unable to exchange data, no active target\n");
                return -EINVAL;
        }
  
        ndev->data_exchange_cb = cb;
        ndev->data_exchange_cb_context = cb_context;
  
 -      rc = nci_send_data(ndev, ndev->conn_id, skb);
 +      rc = nci_send_data(ndev, NCI_STATIC_RF_CONN_ID, skb);
        if (rc)
                clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
  
@@@ -491,7 -501,7 +491,7 @@@ struct nci_dev *nci_allocate_device(str
  {
        struct nci_dev *ndev;
  
 -      nfc_dbg("entry, supported_protocols 0x%x", supported_protocols);
 +      pr_debug("supported_protocols 0x%x\n", supported_protocols);
  
        if (!ops->open || !ops->close || !ops->send)
                return NULL;
@@@ -531,6 -541,8 +531,6 @@@ EXPORT_SYMBOL(nci_allocate_device)
   */
  void nci_free_device(struct nci_dev *ndev)
  {
 -      nfc_dbg("entry");
 -
        nfc_free_device(ndev->nfc_dev);
        kfree(ndev);
  }
@@@ -547,6 -559,8 +547,6 @@@ int nci_register_device(struct nci_dev 
        struct device *dev = &ndev->nfc_dev->dev;
        char name[32];
  
 -      nfc_dbg("entry");
 -
        rc = nfc_register_device(ndev->nfc_dev);
        if (rc)
                goto exit;
@@@ -609,6 -623,8 +609,6 @@@ EXPORT_SYMBOL(nci_register_device)
   */
  void nci_unregister_device(struct nci_dev *ndev)
  {
 -      nfc_dbg("entry");
 -
        nci_close_device(ndev);
  
        destroy_workqueue(ndev->cmd_wq);
@@@ -628,7 -644,7 +628,7 @@@ int nci_recv_frame(struct sk_buff *skb
  {
        struct nci_dev *ndev = (struct nci_dev *) skb->dev;
  
 -      nfc_dbg("entry, len %d", skb->len);
 +      pr_debug("len %d\n", skb->len);
  
        if (!ndev || (!test_bit(NCI_UP, &ndev->flags)
                && !test_bit(NCI_INIT, &ndev->flags))) {
@@@ -648,7 -664,7 +648,7 @@@ static int nci_send_frame(struct sk_buf
  {
        struct nci_dev *ndev = (struct nci_dev *) skb->dev;
  
 -      nfc_dbg("entry, len %d", skb->len);
 +      pr_debug("len %d\n", skb->len);
  
        if (!ndev) {
                kfree_skb(skb);
@@@ -667,11 -683,11 +667,11 @@@ int nci_send_cmd(struct nci_dev *ndev, 
        struct nci_ctrl_hdr *hdr;
        struct sk_buff *skb;
  
 -      nfc_dbg("entry, opcode 0x%x, plen %d", opcode, plen);
 +      pr_debug("opcode 0x%x, plen %d\n", opcode, plen);
  
        skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + plen), GFP_KERNEL);
        if (!skb) {
 -              nfc_err("no memory for command");
 +              pr_err("no memory for command\n");
                return -ENOMEM;
        }
  
@@@ -701,7 -717,7 +701,7 @@@ static void nci_tx_work(struct work_str
        struct nci_dev *ndev = container_of(work, struct nci_dev, tx_work);
        struct sk_buff *skb;
  
 -      nfc_dbg("entry, credits_cnt %d", atomic_read(&ndev->credits_cnt));
 +      pr_debug("credits_cnt %d\n", atomic_read(&ndev->credits_cnt));
  
        /* Send queued tx data */
        while (atomic_read(&ndev->credits_cnt)) {
                if (!skb)
                        return;
  
 -              atomic_dec(&ndev->credits_cnt);
 +              /* Check if data flow control is used */
 +              if (atomic_read(&ndev->credits_cnt) !=
 +                              NCI_DATA_FLOW_CONTROL_NOT_USED)
 +                      atomic_dec(&ndev->credits_cnt);
  
 -              nfc_dbg("NCI TX: MT=data, PBF=%d, conn_id=%d, plen=%d",
 -                              nci_pbf(skb->data),
 -                              nci_conn_id(skb->data),
 -                              nci_plen(skb->data));
 +              pr_debug("NCI TX: MT=data, PBF=%d, conn_id=%d, plen=%d\n",
 +                       nci_pbf(skb->data),
 +                       nci_conn_id(skb->data),
 +                       nci_plen(skb->data));
  
                nci_send_frame(skb);
        }
@@@ -746,7 -759,7 +746,7 @@@ static void nci_rx_work(struct work_str
                        break;
  
                default:
 -                      nfc_err("unknown MT 0x%x", nci_mt(skb->data));
 +                      pr_err("unknown MT 0x%x\n", nci_mt(skb->data));
                        kfree_skb(skb);
                        break;
                }
@@@ -760,7 -773,7 +760,7 @@@ static void nci_cmd_work(struct work_st
        struct nci_dev *ndev = container_of(work, struct nci_dev, cmd_work);
        struct sk_buff *skb;
  
 -      nfc_dbg("entry, cmd_cnt %d", atomic_read(&ndev->cmd_cnt));
 +      pr_debug("cmd_cnt %d\n", atomic_read(&ndev->cmd_cnt));
  
        /* Send queued command */
        if (atomic_read(&ndev->cmd_cnt)) {
  
                atomic_dec(&ndev->cmd_cnt);
  
 -              nfc_dbg("NCI TX: MT=cmd, PBF=%d, GID=0x%x, OID=0x%x, plen=%d",
 -                              nci_pbf(skb->data),
 -                              nci_opcode_gid(nci_opcode(skb->data)),
 -                              nci_opcode_oid(nci_opcode(skb->data)),
 -                              nci_plen(skb->data));
 +              pr_debug("NCI TX: MT=cmd, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
 +                       nci_pbf(skb->data),
 +                       nci_opcode_gid(nci_opcode(skb->data)),
 +                       nci_opcode_oid(nci_opcode(skb->data)),
 +                       nci_plen(skb->data));
  
                nci_send_frame(skb);