ath9k: Add support for AR9287 based chipsets.
[pandora-kernel.git] / drivers / net / wireless / ath / ath9k / main.c
index 52dfa43..1c648db 100644 (file)
@@ -462,9 +462,10 @@ static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
 
        if (sc->sc_flags & SC_OP_TXAGGR) {
                ath_tx_node_init(sc, an);
-               an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
+               an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
                                     sta->ht_cap.ampdu_factor);
                an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
+               an->last_rssi = ATH_RSSI_DUMMY_MARKER;
        }
 }
 
@@ -887,8 +888,7 @@ static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
 static void setup_ht_cap(struct ath_softc *sc,
                         struct ieee80211_sta_ht_cap *ht_info)
 {
-#define        ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3       /* 2 ^ 16 */
-#define        ATH9K_HT_CAP_MPDUDENSITY_8 0x6          /* 8 usec */
+       u8 tx_streams, rx_streams;
 
        ht_info->ht_supported = true;
        ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
@@ -896,26 +896,27 @@ static void setup_ht_cap(struct ath_softc *sc,
                       IEEE80211_HT_CAP_SGI_40 |
                       IEEE80211_HT_CAP_DSSSCCK40;
 
-       ht_info->ampdu_factor = ATH9K_HT_CAP_MAXRXAMPDU_65536;
-       ht_info->ampdu_density = ATH9K_HT_CAP_MPDUDENSITY_8;
+       ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
+       ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
 
        /* set up supported mcs set */
        memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
+       tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
+       rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
 
-       switch(sc->rx_chainmask) {
-       case 1:
-               ht_info->mcs.rx_mask[0] = 0xff;
-               break;
-       case 3:
-       case 5:
-       case 7:
-       default:
-               ht_info->mcs.rx_mask[0] = 0xff;
-               ht_info->mcs.rx_mask[1] = 0xff;
-               break;
+       if (tx_streams != rx_streams) {
+               DPRINTF(sc, ATH_DBG_CONFIG, "TX streams %d, RX streams: %d\n",
+                       tx_streams, rx_streams);
+               ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
+               ht_info->mcs.tx_params |= ((tx_streams - 1) <<
+                               IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
        }
 
-       ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
+       ht_info->mcs.rx_mask[0] = 0xff;
+       if (rx_streams >= 2)
+               ht_info->mcs.rx_mask[1] = 0xff;
+
+       ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
 }
 
 static void ath9k_bss_assoc_info(struct ath_softc *sc,
@@ -1256,6 +1257,7 @@ void ath_detach(struct ath_softc *sc)
        ath_deinit_leds(sc);
        cancel_work_sync(&sc->chan_work);
        cancel_delayed_work_sync(&sc->wiphy_work);
+       cancel_delayed_work_sync(&sc->tx_complete_work);
 
        for (i = 0; i < sc->num_sec_wiphy; i++) {
                struct ath_wiphy *aphy = sc->sec_wiphy[i];
@@ -1282,7 +1284,6 @@ void ath_detach(struct ath_softc *sc)
 
        ath9k_hw_detach(sc->sc_ah);
        ath9k_exit_debug(sc);
-       ath9k_ps_restore(sc);
 }
 
 static int ath9k_reg_notifier(struct wiphy *wiphy,
@@ -1313,6 +1314,7 @@ static int ath_init(u16 devid, struct ath_softc *sc)
        spin_lock_init(&sc->sc_resetlock);
        spin_lock_init(&sc->sc_serial_rw);
        spin_lock_init(&sc->ani_lock);
+       spin_lock_init(&sc->sc_pm_lock);
        mutex_init(&sc->mutex);
        tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
        tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
@@ -1538,7 +1540,8 @@ void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
        hw->max_rates = 4;
        hw->channel_change_time = 5000;
        hw->max_listen_interval = 10;
-       hw->max_rate_tries = ATH_11N_TXMAXTRY;
+       /* Hardware supports 10 but we use 4 */
+       hw->max_rate_tries = 4;
        hw->sta_data_size = sizeof(struct ath_node);
        hw->vif_data_size = sizeof(struct ath_vif);
 
@@ -1975,6 +1978,8 @@ static int ath9k_start(struct ieee80211_hw *hw)
 
        ieee80211_wake_queues(hw);
 
+       queue_delayed_work(sc->hw->workqueue, &sc->tx_complete_work, 0);
+
 mutex_unlock:
        mutex_unlock(&sc->mutex);
 
@@ -2094,8 +2099,6 @@ static void ath9k_stop(struct ieee80211_hw *hw)
 
        mutex_lock(&sc->mutex);
 
-       ieee80211_stop_queues(hw);
-
        if (ath9k_wiphy_started(sc)) {
                mutex_unlock(&sc->mutex);
                return; /* another wiphy still in use */
@@ -2253,9 +2256,28 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
        struct ath_softc *sc = aphy->sc;
        struct ieee80211_conf *conf = &hw->conf;
        struct ath_hw *ah = sc->sc_ah;
+       bool all_wiphys_idle = false, disable_radio = false;
 
        mutex_lock(&sc->mutex);
 
+       /* Leave this as the first check */
+       if (changed & IEEE80211_CONF_CHANGE_IDLE) {
+
+               spin_lock_bh(&sc->wiphy_lock);
+               all_wiphys_idle =  ath9k_all_wiphys_idle(sc);
+               spin_unlock_bh(&sc->wiphy_lock);
+
+               if (conf->flags & IEEE80211_CONF_IDLE){
+                       if (all_wiphys_idle)
+                               disable_radio = true;
+               }
+               else if (all_wiphys_idle) {
+                       ath_radio_enable(sc);
+                       DPRINTF(sc, ATH_DBG_CONFIG,
+                               "not-idle: enabling radio\n");
+               }
+       }
+
        if (changed & IEEE80211_CONF_CHANGE_PS) {
                if (conf->flags & IEEE80211_CONF_PS) {
                        if (!(ah->caps.hw_caps &
@@ -2323,6 +2345,11 @@ skip_chan_change:
        if (changed & IEEE80211_CONF_CHANGE_POWER)
                sc->config.txpowlimit = 2 * conf->power_level;
 
+       if (disable_radio) {
+               DPRINTF(sc, ATH_DBG_CONFIG, "idle: disabling radio\n");
+               ath_radio_disable(sc);
+       }
+
        mutex_unlock(&sc->mutex);
 
        return 0;
@@ -2642,19 +2669,11 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
        case IEEE80211_AMPDU_RX_STOP:
                break;
        case IEEE80211_AMPDU_TX_START:
-               ret = ath_tx_aggr_start(sc, sta, tid, ssn);
-               if (ret < 0)
-                       DPRINTF(sc, ATH_DBG_FATAL,
-                               "Unable to start TX aggregation\n");
-               else
-                       ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
+               ath_tx_aggr_start(sc, sta, tid, ssn);
+               ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
                break;
        case IEEE80211_AMPDU_TX_STOP:
-               ret = ath_tx_aggr_stop(sc, sta, tid);
-               if (ret < 0)
-                       DPRINTF(sc, ATH_DBG_FATAL,
-                               "Unable to stop TX aggregation\n");
-
+               ath_tx_aggr_stop(sc, sta, tid);
                ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
                break;
        case IEEE80211_AMPDU_TX_OPERATIONAL:
@@ -2732,7 +2751,8 @@ static struct {
        { AR_SREV_VERSION_9100,         "9100" },
        { AR_SREV_VERSION_9160,         "9160" },
        { AR_SREV_VERSION_9280,         "9280" },
-       { AR_SREV_VERSION_9285,         "9285" }
+       { AR_SREV_VERSION_9285,         "9285" },
+       { AR_SREV_VERSION_9287,         "9287" }
 };
 
 static struct {