ath9k: always call ath_reset from workqueue context
[pandora-kernel.git] / drivers / net / wireless / ath / ath9k / main.c
index 2ca351f..9a6db29 100644 (file)
@@ -62,14 +62,12 @@ static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
 
        if (txq->axq_depth || !list_empty(&txq->axq_acq))
                pending = true;
-       else if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
-               pending = !list_empty(&txq->txq_fifo_pending);
 
        spin_unlock_bh(&txq->axq_lock);
        return pending;
 }
 
-bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
+static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
 {
        unsigned long flags;
        bool ret;
@@ -136,7 +134,7 @@ void ath9k_ps_restore(struct ath_softc *sc)
        spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
 }
 
-static void ath_start_ani(struct ath_common *common)
+void ath_start_ani(struct ath_common *common)
 {
        struct ath_hw *ah = common->ah;
        unsigned long timestamp = jiffies_to_msecs(jiffies);
@@ -165,7 +163,7 @@ static void ath_update_survey_nf(struct ath_softc *sc, int channel)
 
        if (chan->noisefloor) {
                survey->filled |= SURVEY_INFO_NOISE_DBM;
-               survey->noise = chan->noisefloor;
+               survey->noise = ath9k_hw_getchan_noise(ah, chan);
        }
 }
 
@@ -219,7 +217,7 @@ static int ath_update_survey_stats(struct ath_softc *sc)
  * by reseting the chip.  To accomplish this we must first cleanup any pending
  * DMA, then restart stuff.
 */
-int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
+static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
                    struct ath9k_channel *hchan)
 {
        struct ath_hw *ah = sc->sc_ah;
@@ -238,6 +236,7 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
        del_timer_sync(&common->ani.timer);
        cancel_work_sync(&sc->paprd_work);
        cancel_work_sync(&sc->hw_check_work);
+       cancel_work_sync(&sc->hw_reset_work);
        cancel_delayed_work_sync(&sc->tx_complete_work);
        cancel_delayed_work_sync(&sc->hw_pll_work);
 
@@ -296,13 +295,15 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
        ath9k_cmn_update_txpow(ah, sc->curtxpow,
                               sc->config.txpowlimit, &sc->curtxpow);
        ath9k_hw_set_interrupts(ah, ah->imask);
+       ath9k_hw_enable_interrupts(ah);
 
        if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) {
                if (sc->sc_flags & SC_OP_BEACONS)
                        ath_set_beacon(sc);
                ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
                ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/2);
-               ath_start_ani(common);
+               if (!common->disable_ani)
+                       ath_start_ani(common);
        }
 
  ps_restore:
@@ -318,7 +319,6 @@ static void ath_paprd_activate(struct ath_softc *sc)
 {
        struct ath_hw *ah = sc->sc_ah;
        struct ath9k_hw_cal_data *caldata = ah->caldata;
-       struct ath_common *common = ath9k_hw_common(ah);
        int chain;
 
        if (!caldata || !caldata->paprd_done)
@@ -327,7 +327,7 @@ static void ath_paprd_activate(struct ath_softc *sc)
        ath9k_ps_wakeup(sc);
        ar9003_paprd_enable(ah, false);
        for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
-               if (!(common->tx_chainmask & BIT(chain)))
+               if (!(ah->txchainmask & BIT(chain)))
                        continue;
 
                ar9003_paprd_populate_single_table(ah, caldata, chain);
@@ -361,7 +361,7 @@ static bool ath_paprd_send_frame(struct ath_softc *sc, struct sk_buff *skb, int
        txctl.paprd = BIT(chain);
 
        if (ath_tx_start(hw, skb, &txctl) != 0) {
-               ath_dbg(common, ATH_DBG_XMIT, "PAPRD TX failed\n");
+               ath_dbg(common, ATH_DBG_CALIBRATE, "PAPRD TX failed\n");
                dev_kfree_skb_any(skb);
                return false;
        }
@@ -370,7 +370,7 @@ static bool ath_paprd_send_frame(struct ath_softc *sc, struct sk_buff *skb, int
                        msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
 
        if (!time_left)
-               ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_CALIBRATE,
+               ath_dbg(common, ATH_DBG_CALIBRATE,
                        "Timeout waiting for paprd training on TX chain %d\n",
                        chain);
 
@@ -394,12 +394,14 @@ void ath_paprd_calibrate(struct work_struct *work)
        if (!caldata)
                return;
 
+       ath9k_ps_wakeup(sc);
+
        if (ar9003_paprd_init_table(ah) < 0)
-               return;
+               goto fail_paprd;
 
        skb = alloc_skb(len, GFP_KERNEL);
        if (!skb)
-               return;
+               goto fail_paprd;
 
        skb_put(skb, len);
        memset(skb->data, 0, len);
@@ -411,9 +413,8 @@ void ath_paprd_calibrate(struct work_struct *work)
        memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
        memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
 
-       ath9k_ps_wakeup(sc);
        for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
-               if (!(common->tx_chainmask & BIT(chain)))
+               if (!(ah->txchainmask & BIT(chain)))
                        continue;
 
                chain_ok = 0;
@@ -431,11 +432,18 @@ void ath_paprd_calibrate(struct work_struct *work)
                if (!ath_paprd_send_frame(sc, skb, chain))
                        goto fail_paprd;
 
-               if (!ar9003_paprd_is_done(ah))
+               if (!ar9003_paprd_is_done(ah)) {
+                       ath_dbg(common, ATH_DBG_CALIBRATE,
+                               "PAPRD not yet done on chain %d\n", chain);
                        break;
+               }
 
-               if (ar9003_paprd_create_curve(ah, caldata, chain) != 0)
+               if (ar9003_paprd_create_curve(ah, caldata, chain)) {
+                       ath_dbg(common, ATH_DBG_CALIBRATE,
+                               "PAPRD create curve failed on chain %d\n",
+                                                                  chain);
                        break;
+               }
 
                chain_ok = 1;
        }
@@ -515,24 +523,19 @@ void ath_ani_calibrate(unsigned long data)
                common->ani.checkani_timer = timestamp;
        }
 
-       /* Skip all processing if there's nothing to do. */
-       if (longcal || shortcal || aniflag) {
-               /* Call ANI routine if necessary */
-               if (aniflag) {
-                       spin_lock_irqsave(&common->cc_lock, flags);
-                       ath9k_hw_ani_monitor(ah, ah->curchan);
-                       ath_update_survey_stats(sc);
-                       spin_unlock_irqrestore(&common->cc_lock, flags);
-               }
+       /* Call ANI routine if necessary */
+       if (aniflag) {
+               spin_lock_irqsave(&common->cc_lock, flags);
+               ath9k_hw_ani_monitor(ah, ah->curchan);
+               ath_update_survey_stats(sc);
+               spin_unlock_irqrestore(&common->cc_lock, flags);
+       }
 
-               /* Perform calibration if necessary */
-               if (longcal || shortcal) {
-                       common->ani.caldone =
-                               ath9k_hw_calibrate(ah,
-                                                  ah->curchan,
-                                                  common->rx_chainmask,
-                                                  longcal);
-               }
+       /* Perform calibration if necessary */
+       if (longcal || shortcal) {
+               common->ani.caldone =
+                       ath9k_hw_calibrate(ah, ah->curchan,
+                                               ah->rxchainmask, longcal);
        }
 
        ath9k_ps_restore(sc);
@@ -543,6 +546,7 @@ set_timer:
        * The interval must be the shortest necessary to satisfy ANI,
        * short calibration and long calibration.
        */
+       ath9k_debug_samp_bb_mac(sc);
        cal_interval = ATH_LONG_CALINTERVAL;
        if (sc->sc_ah->config.enable_ani)
                cal_interval = min(cal_interval,
@@ -562,7 +566,6 @@ set_timer:
 static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
 {
        struct ath_node *an;
-       struct ath_hw *ah = sc->sc_ah;
        an = (struct ath_node *)sta->drv_priv;
 
 #ifdef CONFIG_ATH9K_DEBUGFS
@@ -571,9 +574,6 @@ static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
        spin_unlock(&sc->nodes_lock);
        an->sta = sta;
 #endif
-       if ((ah->caps.hw_caps) & ATH9K_HW_CAP_APM)
-               sc->sc_flags |= SC_OP_ENABLE_APM;
-
        if (sc->sc_flags & SC_OP_TXAGGR) {
                ath_tx_node_init(sc, an);
                an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
@@ -597,69 +597,6 @@ static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
                ath_tx_node_cleanup(sc, an);
 }
 
-void ath_hw_check(struct work_struct *work)
-{
-       struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
-       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-       unsigned long flags;
-       int busy;
-
-       ath9k_ps_wakeup(sc);
-       if (ath9k_hw_check_alive(sc->sc_ah))
-               goto out;
-
-       spin_lock_irqsave(&common->cc_lock, flags);
-       busy = ath_update_survey_stats(sc);
-       spin_unlock_irqrestore(&common->cc_lock, flags);
-
-       ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
-               "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
-       if (busy >= 99) {
-               if (++sc->hw_busy_count >= 3)
-                       ath_reset(sc, true);
-       } else if (busy >= 0)
-               sc->hw_busy_count = 0;
-
-out:
-       ath9k_ps_restore(sc);
-}
-
-static void ath_hw_pll_rx_hang_check(struct ath_softc *sc, u32 pll_sqsum)
-{
-       static int count;
-       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-
-       if (pll_sqsum >= 0x40000) {
-               count++;
-               if (count == 3) {
-                       /* Rx is hung for more than 500ms. Reset it */
-                       ath_dbg(common, ATH_DBG_RESET,
-                               "Possible RX hang, resetting");
-                       ath_reset(sc, true);
-                       count = 0;
-               }
-       } else
-               count = 0;
-}
-
-void ath_hw_pll_work(struct work_struct *work)
-{
-       struct ath_softc *sc = container_of(work, struct ath_softc,
-                                           hw_pll_work.work);
-       u32 pll_sqsum;
-
-       if (AR_SREV_9485(sc->sc_ah)) {
-
-               ath9k_ps_wakeup(sc);
-               pll_sqsum = ar9003_get_pll_sqsum_dvc(sc->sc_ah);
-               ath9k_ps_restore(sc);
-
-               ath_hw_pll_rx_hang_check(sc, pll_sqsum);
-
-               ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/5);
-       }
-}
-
 
 void ath9k_tasklet(unsigned long data)
 {
@@ -672,7 +609,7 @@ void ath9k_tasklet(unsigned long data)
 
        if ((status & ATH9K_INT_FATAL) ||
            (status & ATH9K_INT_BB_WATCHDOG)) {
-               ath_reset(sc, true);
+               ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
                return;
        }
 
@@ -697,8 +634,7 @@ void ath9k_tasklet(unsigned long data)
                 */
                ath_dbg(common, ATH_DBG_PS,
                        "TSFOOR - Sync with next Beacon\n");
-               sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC |
-                               PS_TSFOOR_SYNC;
+               sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
        }
 
        if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
@@ -817,11 +753,9 @@ irqreturn_t ath_isr(int irq, void *dev)
        if (status & ATH9K_INT_TXURN)
                ath9k_hw_updatetxtriglevel(ah, true);
 
-       if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
-               if (status & ATH9K_INT_RXEOL) {
-                       ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
-                       ath9k_hw_set_interrupts(ah, ah->imask);
-               }
+       if (status & ATH9K_INT_RXEOL) {
+               ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
+               ath9k_hw_set_interrupts(ah, ah->imask);
        }
 
        if (status & ATH9K_INT_MIB) {
@@ -868,7 +802,7 @@ chip_reset:
 #undef SCHED_INTR
 }
 
-void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
+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);
@@ -877,8 +811,9 @@ void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
 
        ath9k_ps_wakeup(sc);
        spin_lock_bh(&sc->sc_pcu_lock);
+       atomic_set(&ah->intr_ref_cnt, -1);
 
-       ath9k_hw_configpcipowersave(ah, 0, 0);
+       ath9k_hw_configpcipowersave(ah, false);
 
        if (!ah->curchan)
                ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
@@ -901,6 +836,7 @@ void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
 
        /* Re-Enable  interrupts */
        ath9k_hw_set_interrupts(ah, ah->imask);
+       ath9k_hw_enable_interrupts(ah);
 
        /* Enable LED */
        ath9k_hw_cfg_output(ah, ah->led_pin,
@@ -958,13 +894,13 @@ void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
 
        ath9k_hw_phy_disable(ah);
 
-       ath9k_hw_configpcipowersave(ah, 1, 1);
+       ath9k_hw_configpcipowersave(ah, true);
 
        spin_unlock_bh(&sc->sc_pcu_lock);
        ath9k_ps_restore(sc);
 }
 
-int ath_reset(struct ath_softc *sc, bool retry_tx)
+static int ath_reset(struct ath_softc *sc, bool retry_tx)
 {
        struct ath_hw *ah = sc->sc_ah;
        struct ath_common *common = ath9k_hw_common(ah);
@@ -973,11 +909,12 @@ int ath_reset(struct ath_softc *sc, bool retry_tx)
 
        sc->hw_busy_count = 0;
 
+       ath9k_debug_samp_bb_mac(sc);
        /* Stop ANI */
+
        del_timer_sync(&common->ani.timer);
 
        ath9k_ps_wakeup(sc);
-       spin_lock_bh(&sc->sc_pcu_lock);
 
        ieee80211_stop_queues(hw);
 
@@ -1007,6 +944,7 @@ int ath_reset(struct ath_softc *sc, bool retry_tx)
                ath_set_beacon(sc);     /* restart beacons */
 
        ath9k_hw_set_interrupts(ah, ah->imask);
+       ath9k_hw_enable_interrupts(ah);
 
        if (retry_tx) {
                int i;
@@ -1020,15 +958,94 @@ int ath_reset(struct ath_softc *sc, bool retry_tx)
        }
 
        ieee80211_wake_queues(hw);
-       spin_unlock_bh(&sc->sc_pcu_lock);
 
        /* Start ANI */
-       ath_start_ani(common);
+       if (!common->disable_ani)
+               ath_start_ani(common);
+
        ath9k_ps_restore(sc);
 
        return r;
 }
 
+void ath_reset_work(struct work_struct *work)
+{
+       struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
+
+       spin_lock_bh(&sc->sc_pcu_lock);
+       ath_reset(sc, true);
+       spin_unlock_bh(&sc->sc_pcu_lock);
+}
+
+void ath_hw_check(struct work_struct *work)
+{
+       struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
+       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+       unsigned long flags;
+       int busy;
+
+       ath9k_ps_wakeup(sc);
+       if (ath9k_hw_check_alive(sc->sc_ah))
+               goto out;
+
+       spin_lock_irqsave(&common->cc_lock, flags);
+       busy = ath_update_survey_stats(sc);
+       spin_unlock_irqrestore(&common->cc_lock, flags);
+
+       ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
+               "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
+       if (busy >= 99) {
+               if (++sc->hw_busy_count >= 3) {
+                       spin_lock_bh(&sc->sc_pcu_lock);
+                       ath_reset(sc, true);
+                       spin_unlock_bh(&sc->sc_pcu_lock);
+               }
+
+       } else if (busy >= 0)
+               sc->hw_busy_count = 0;
+
+out:
+       ath9k_ps_restore(sc);
+}
+
+static void ath_hw_pll_rx_hang_check(struct ath_softc *sc, u32 pll_sqsum)
+{
+       static int count;
+       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+
+       if (pll_sqsum >= 0x40000) {
+               count++;
+               if (count == 3) {
+                       /* Rx is hung for more than 500ms. Reset it */
+                       ath_dbg(common, ATH_DBG_RESET,
+                               "Possible RX hang, resetting");
+                       spin_lock_bh(&sc->sc_pcu_lock);
+                       ath_reset(sc, true);
+                       spin_unlock_bh(&sc->sc_pcu_lock);
+                       count = 0;
+               }
+       } else
+               count = 0;
+}
+
+void ath_hw_pll_work(struct work_struct *work)
+{
+       struct ath_softc *sc = container_of(work, struct ath_softc,
+                                           hw_pll_work.work);
+       u32 pll_sqsum;
+
+       if (AR_SREV_9485(sc->sc_ah)) {
+
+               ath9k_ps_wakeup(sc);
+               pll_sqsum = ar9003_get_pll_sqsum_dvc(sc->sc_ah);
+               ath9k_ps_restore(sc);
+
+               ath_hw_pll_rx_hang_check(sc, pll_sqsum);
+
+               ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/5);
+       }
+}
+
 /**********************/
 /* mac80211 callbacks */
 /**********************/
@@ -1056,7 +1073,7 @@ static int ath9k_start(struct ieee80211_hw *hw)
        init_channel = ath9k_cmn_get_curchannel(hw, ah);
 
        /* Reset SERDES registers */
-       ath9k_hw_configpcipowersave(ah, 0, 0);
+       ath9k_hw_configpcipowersave(ah, false);
 
        /*
         * The basic interface to setting the hardware in a good
@@ -1120,6 +1137,7 @@ static int ath9k_start(struct ieee80211_hw *hw)
        /* Disable BMISS interrupt when we're not associated */
        ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
        ath9k_hw_set_interrupts(ah, ah->imask);
+       ath9k_hw_enable_interrupts(ah);
 
        ieee80211_wake_queues(hw);
 
@@ -1131,8 +1149,6 @@ static int ath9k_start(struct ieee80211_hw *hw)
                                           AR_STOMP_LOW_WLAN_WGHT);
                ath9k_hw_btcoex_enable(ah);
 
-               if (common->bus_ops->bt_coex_prep)
-                       common->bus_ops->bt_coex_prep(common);
                if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
                        ath9k_btcoex_timer_resume(sc);
        }
@@ -1222,6 +1238,7 @@ static void ath9k_stop(struct ieee80211_hw *hw)
        cancel_delayed_work_sync(&sc->hw_pll_work);
        cancel_work_sync(&sc->paprd_work);
        cancel_work_sync(&sc->hw_check_work);
+       cancel_work_sync(&sc->hw_reset_work);
 
        if (sc->sc_flags & SC_OP_INVALID) {
                ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
@@ -1261,7 +1278,6 @@ static void ath9k_stop(struct ieee80211_hw *hw)
 
        /* disable HAL and put h/w to sleep */
        ath9k_hw_disable(ah);
-       ath9k_hw_configpcipowersave(ah, 1, 1);
 
        spin_unlock_bh(&sc->sc_pcu_lock);
 
@@ -1412,10 +1428,14 @@ static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
        ath9k_hw_set_interrupts(ah, ah->imask);
 
        /* Set up ANI */
-       if ((iter_data.naps + iter_data.nadhocs) > 0) {
+       if (iter_data.naps > 0) {
                sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
-               sc->sc_flags |= SC_OP_ANI_RUN;
-               ath_start_ani(common);
+
+               if (!common->disable_ani) {
+                       sc->sc_flags |= SC_OP_ANI_RUN;
+                       ath_start_ani(common);
+               }
+
        } else {
                sc->sc_flags &= ~SC_OP_ANI_RUN;
                del_timer_sync(&common->ani.timer);
@@ -1663,6 +1683,7 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
 
        if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
                struct ieee80211_channel *curchan = hw->conf.channel;
+               struct ath9k_channel old_chan;
                int pos = curchan->hw_value;
                int old_pos = -1;
                unsigned long flags;
@@ -1679,14 +1700,24 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
                        "Set channel: %d MHz type: %d\n",
                        curchan->center_freq, conf->channel_type);
 
-               ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
-                                         curchan, conf->channel_type);
-
                /* update survey stats for the old channel before switching */
                spin_lock_irqsave(&common->cc_lock, flags);
                ath_update_survey_stats(sc);
                spin_unlock_irqrestore(&common->cc_lock, flags);
 
+               /*
+                * Preserve the current channel values, before updating
+                * the same channel
+                */
+               if (old_pos == pos) {
+                       memcpy(&old_chan, &sc->sc_ah->channels[pos],
+                               sizeof(struct ath9k_channel));
+                       ah->curchan = &old_chan;
+               }
+
+               ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
+                                         curchan, conf->channel_type);
+
                /*
                 * If the operating channel changes, change the survey in-use flags
                 * along with it.
@@ -1952,50 +1983,38 @@ static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
        struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
        struct ath_vif *avp = (void *)vif->drv_priv;
 
-       switch (sc->sc_ah->opmode) {
-       case NL80211_IFTYPE_ADHOC:
-               /* There can be only one vif available */
+       /*
+        * Skip iteration if primary station vif's bss info
+        * was not changed
+        */
+       if (sc->sc_flags & SC_OP_PRIM_STA_VIF)
+               return;
+
+       if (bss_conf->assoc) {
+               sc->sc_flags |= SC_OP_PRIM_STA_VIF;
+               avp->primary_sta_vif = true;
                memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
                common->curaid = bss_conf->aid;
                ath9k_hw_write_associd(sc->sc_ah);
-               /* configure beacon */
-               if (bss_conf->enable_beacon)
-                       ath_beacon_config(sc, vif);
-               break;
-       case NL80211_IFTYPE_STATION:
-               /*
-                * Skip iteration if primary station vif's bss info
-                * was not changed
-                */
-               if (sc->sc_flags & SC_OP_PRIM_STA_VIF)
-                       break;
-
-               if (bss_conf->assoc) {
-                       sc->sc_flags |= SC_OP_PRIM_STA_VIF;
-                       avp->primary_sta_vif = true;
-                       memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
-                       common->curaid = bss_conf->aid;
-                       ath9k_hw_write_associd(sc->sc_ah);
-                       ath_dbg(common, ATH_DBG_CONFIG,
+               ath_dbg(common, ATH_DBG_CONFIG,
                                "Bss Info ASSOC %d, bssid: %pM\n",
                                bss_conf->aid, common->curbssid);
-                       ath_beacon_config(sc, vif);
-                       /*
-                        * Request a re-configuration of Beacon related timers
-                        * on the receipt of the first Beacon frame (i.e.,
-                        * after time sync with the AP).
-                        */
-                       sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
-                       /* Reset rssi stats */
-                       sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
-                       sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
+               ath_beacon_config(sc, vif);
+               /*
+                * Request a re-configuration of Beacon related timers
+                * on the receipt of the first Beacon frame (i.e.,
+                * after time sync with the AP).
+                */
+               sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
+               /* Reset rssi stats */
+               sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
+               sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
 
+               if (!common->disable_ani) {
                        sc->sc_flags |= SC_OP_ANI_RUN;
                        ath_start_ani(common);
                }
-               break;
-       default:
-               break;
+
        }
 }
 
@@ -2005,6 +2024,9 @@ static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
        struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
        struct ath_vif *avp = (void *)vif->drv_priv;
 
+       if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
+               return;
+
        /* Reconfigure bss info */
        if (avp->primary_sta_vif && !bss_conf->assoc) {
                ath_dbg(common, ATH_DBG_CONFIG,
@@ -2023,8 +2045,7 @@ static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
         * None of station vifs are associated.
         * Clear bssid & aid
         */
-       if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
-           !(sc->sc_flags & SC_OP_PRIM_STA_VIF)) {
+       if (!(sc->sc_flags & SC_OP_PRIM_STA_VIF)) {
                ath9k_hw_write_associd(sc->sc_ah);
                /* Stop ANI */
                sc->sc_flags &= ~SC_OP_ANI_RUN;
@@ -2054,6 +2075,26 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
                        common->curbssid, common->curaid);
        }
 
+       if (changed & BSS_CHANGED_IBSS) {
+               /* There can be only one vif available */
+               memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
+               common->curaid = bss_conf->aid;
+               ath9k_hw_write_associd(sc->sc_ah);
+
+               if (bss_conf->ibss_joined) {
+                       sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
+
+                       if (!common->disable_ani) {
+                               sc->sc_flags |= SC_OP_ANI_RUN;
+                               ath_start_ani(common);
+                       }
+
+               } else {
+                       sc->sc_flags &= ~SC_OP_ANI_RUN;
+                       del_timer_sync(&common->ani.timer);
+               }
+       }
+
        /* Enable transmission of beacons (AP, IBSS, MESH) */
        if ((changed & BSS_CHANGED_BEACON) ||
            ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
@@ -2308,9 +2349,9 @@ static void ath9k_flush(struct ieee80211_hw *hw, bool 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);
+       spin_unlock_bh(&sc->sc_pcu_lock);
        ath9k_ps_restore(sc);
        ieee80211_wake_queues(hw);
 
@@ -2334,7 +2375,7 @@ static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
        return false;
 }
 
-int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
+static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
 {
        struct ath_softc *sc = hw->priv;
        struct ath_hw *ah = sc->sc_ah;
@@ -2373,6 +2414,20 @@ skip:
        return sc->beacon.tx_last;
 }
 
+static int ath9k_get_stats(struct ieee80211_hw *hw,
+                          struct ieee80211_low_level_stats *stats)
+{
+       struct ath_softc *sc = hw->priv;
+       struct ath_hw *ah = sc->sc_ah;
+       struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
+
+       stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
+       stats->dot11RTSFailureCount = mib_stats->rts_bad;
+       stats->dot11FCSErrorCount = mib_stats->fcs_bad;
+       stats->dot11RTSSuccessCount = mib_stats->rts_good;
+       return 0;
+}
+
 struct ieee80211_ops ath9k_ops = {
        .tx                 = ath9k_tx,
        .start              = ath9k_start,
@@ -2397,5 +2452,6 @@ struct ieee80211_ops ath9k_ops = {
        .set_coverage_class = ath9k_set_coverage_class,
        .flush              = ath9k_flush,
        .tx_frames_pending  = ath9k_tx_frames_pending,
-       .tx_last_beacon = ath9k_tx_last_beacon,
+       .tx_last_beacon     = ath9k_tx_last_beacon,
+       .get_stats          = ath9k_get_stats,
 };