iwlwifi: removing IWL4965_HT config
[pandora-kernel.git] / drivers / net / wireless / iwlwifi / iwl-4965-rs.c
index 67356d9..7f9178b 100644 (file)
@@ -105,8 +105,6 @@ struct iwl4965_scale_tbl_info {
        struct iwl4965_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
 };
 
-#ifdef CONFIG_IWL4965_HT
-
 struct iwl4965_traffic_load {
        unsigned long time_stamp;       /* age of the oldest statistics */
        u32 packet_count[TID_QUEUE_MAX_SIZE];   /* packet count in this time
@@ -118,8 +116,6 @@ struct iwl4965_traffic_load {
        u8 head;                        /* start of the circular buffer */
 };
 
-#endif /* CONFIG_IWL4965_HT */
-
 /**
  * struct iwl4965_lq_sta -- driver's rate scaling private structure
  *
@@ -157,19 +153,15 @@ struct iwl4965_lq_sta {
 
        struct iwl_link_quality_cmd lq;
        struct iwl4965_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
-#ifdef CONFIG_IWL4965_HT
        struct iwl4965_traffic_load load[TID_MAX_LOAD_COUNT];
        u8 tx_agg_tid_en;
-#endif
 #ifdef CONFIG_MAC80211_DEBUGFS
        struct dentry *rs_sta_dbgfs_scale_table_file;
        struct dentry *rs_sta_dbgfs_stats_table_file;
-#ifdef CONFIG_IWL4965_HT
        struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
-#endif
        u32 dbg_fixed_rate;
-       struct iwl_priv *drv;
 #endif
+       struct iwl_priv *drv;
 };
 
 static void rs_rate_scale_perform(struct iwl_priv *priv,
@@ -256,7 +248,6 @@ static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
        return ((ant_type & valid_antenna) == ant_type);
 }
 
-#ifdef CONFIG_IWL4965_HT
 /*
  *     removes the old data from the statistics. All data that is older than
  *     TID_MAX_TIME_DIFF, will be deleted.
@@ -282,14 +273,20 @@ static void rs_tl_rm_old_stats(struct iwl4965_traffic_load *tl, u32 curr_time)
  *     increment traffic load value for tid and also remove
  *     any old values if passed the certain time period
  */
-static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data, u8 tid)
+static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data,
+                            struct ieee80211_hdr *hdr)
 {
        u32 curr_time = jiffies_to_msecs(jiffies);
        u32 time_diff;
        s32 index;
        struct iwl4965_traffic_load *tl = NULL;
+       u16 fc = le16_to_cpu(hdr->frame_control);
+       u8 tid;
 
-       if (tid >= TID_MAX_LOAD_COUNT)
+       if (ieee80211_is_qos_data(fc)) {
+               u8 *qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
+               tid = qc[0] & 0xf;
+       } else
                return;
 
        tl = &lq_data->load[tid];
@@ -360,9 +357,9 @@ static void rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
        unsigned long state;
        DECLARE_MAC_BUF(mac);
 
-       spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+       spin_lock_bh(&sta->lock);
        state = sta->ampdu_mlme.tid_state_tx[tid];
-       spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+       spin_unlock_bh(&sta->lock);
 
        if (state == HT_AGG_STATE_IDLE &&
            rs_tl_get_load(lq_data, tid) > IWL_AGG_LOAD_THRESHOLD) {
@@ -383,8 +380,6 @@ static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
                        rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
 }
 
-#endif /* CONFIG_IWLWIFI_HT */
-
 static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
 {
        return (!!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
@@ -481,7 +476,7 @@ static u32 rate_n_flags_from_tbl(struct iwl4965_scale_tbl_info *tbl,
        u32 rate_n_flags = 0;
 
        if (is_legacy(tbl->lq_type)) {
-               rate_n_flags = iwl4965_rates[index].plcp;
+               rate_n_flags = iwl_rates[index].plcp;
                if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
                        rate_n_flags |= RATE_MCS_CCK_MSK;
 
@@ -493,11 +488,11 @@ static u32 rate_n_flags_from_tbl(struct iwl4965_scale_tbl_info *tbl,
                rate_n_flags = RATE_MCS_HT_MSK;
 
                if (is_siso(tbl->lq_type))
-                       rate_n_flags |= iwl4965_rates[index].plcp_siso;
+                       rate_n_flags |= iwl_rates[index].plcp_siso;
                else if (is_mimo2(tbl->lq_type))
-                       rate_n_flags |= iwl4965_rates[index].plcp_mimo2;
+                       rate_n_flags |= iwl_rates[index].plcp_mimo2;
                else
-                       rate_n_flags |= iwl4965_rates[index].plcp_mimo3;
+                       rate_n_flags |= iwl_rates[index].plcp_mimo3;
        } else {
                IWL_ERROR("Invalid tbl->lq_type %d\n", tbl->lq_type);
        }
@@ -620,7 +615,6 @@ static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
 
 /* FIXME:RS: in 4965 we don't use greenfield at all */
 /* FIXME:RS: don't use greenfield for now in TX */
-/* #ifdef CONFIG_IWL4965_HT */
 #if 0
 static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
 {
@@ -628,12 +622,11 @@ static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf
                priv->current_ht_config.is_green_field &&
                !priv->current_ht_config.non_GF_STA_present);
 }
-#else
+#endif
 static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
 {
        return 0;
 }
-#endif /* CONFIG_IWL4965_HT */
 
 /**
  * rs_get_supported_rates - get the available rates
@@ -662,7 +655,8 @@ static u16 rs_get_supported_rates(struct iwl4965_lq_sta *lq_sta,
        }
 }
 
-static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
+static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
+                               int rate_type)
 {
        u8 high = IWL_RATE_INVALID;
        u8 low = IWL_RATE_INVALID;
@@ -696,7 +690,7 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
 
        low = index;
        while (low != IWL_RATE_INVALID) {
-               low = iwl4965_rates[low].prev_rs;
+               low = iwl_rates[low].prev_rs;
                if (low == IWL_RATE_INVALID)
                        break;
                if (rate_mask & (1 << low))
@@ -706,7 +700,7 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
 
        high = index;
        while (high != IWL_RATE_INVALID) {
-               high = iwl4965_rates[high].next_rs;
+               high = iwl_rates[high].next_rs;
                if (high == IWL_RATE_INVALID)
                        break;
                if (rate_mask & (1 << high))
@@ -763,7 +757,8 @@ static u32 rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
                goto out;
        }
 
-       high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
+       high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask,
+                                       tbl->lq_type);
        low = high_low & 0xff;
 
        if (low == IWL_RATE_INVALID)
@@ -777,8 +772,7 @@ out:
  * mac80211 sends us Tx status
  */
 static void rs_tx_status(void *priv_rate, struct net_device *dev,
-                        struct sk_buff *skb,
-                        struct ieee80211_tx_status *tx_resp)
+                        struct sk_buff *skb)
 {
        int status;
        u8 retries;
@@ -790,6 +784,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
        struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
        struct ieee80211_hw *hw = local_to_hw(local);
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
        struct iwl4965_rate_scale_data *window = NULL;
        struct iwl4965_rate_scale_data *search_win = NULL;
        u32 tx_rate;
@@ -805,11 +800,11 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
                return;
 
        /* This packet was aggregated but doesn't carry rate scale info */
-       if ((tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) &&
-           !(tx_resp->flags & IEEE80211_TX_STATUS_AMPDU))
+       if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
+           !(info->flags & IEEE80211_TX_STAT_AMPDU))
                return;
 
-       retries = tx_resp->retry_count;
+       retries = info->status.retry_count;
 
        if (retries > 15)
                retries = 15;
@@ -854,20 +849,20 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
        if (priv->band == IEEE80211_BAND_5GHZ)
                rs_index -= IWL_FIRST_OFDM_RATE;
 
-       if ((tx_resp->control.tx_rate == NULL) ||
+       if ((info->tx_rate_idx < 0) ||
            (tbl_type.is_SGI ^
-               !!(tx_resp->control.flags & IEEE80211_TXCTL_SHORT_GI)) ||
+               !!(info->flags & IEEE80211_TX_CTL_SHORT_GI)) ||
            (tbl_type.is_fat ^
-               !!(tx_resp->control.flags & IEEE80211_TXCTL_40_MHZ_WIDTH)) ||
+               !!(info->flags & IEEE80211_TX_CTL_40_MHZ_WIDTH)) ||
            (tbl_type.is_dup ^
-               !!(tx_resp->control.flags & IEEE80211_TXCTL_DUP_DATA)) ||
-           (tbl_type.ant_type ^ tx_resp->control.antenna_sel_tx) ||
+               !!(info->flags & IEEE80211_TX_CTL_DUP_DATA)) ||
+           (tbl_type.ant_type ^ info->antenna_sel_tx) ||
            (!!(tx_rate & RATE_MCS_HT_MSK) ^
-               !!(tx_resp->control.flags & IEEE80211_TXCTL_OFDM_HT)) ||
+               !!(info->flags & IEEE80211_TX_CTL_OFDM_HT)) ||
            (!!(tx_rate & RATE_MCS_GF_MSK) ^
-               !!(tx_resp->control.flags & IEEE80211_TXCTL_GREEN_FIELD)) ||
+               !!(info->flags & IEEE80211_TX_CTL_GREEN_FIELD)) ||
            (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate !=
-               tx_resp->control.tx_rate->bitrate)) {
+            hw->wiphy->bands[info->band]->bitrates[info->tx_rate_idx].bitrate)) {
                IWL_DEBUG_RATE("initial rate does not match 0x%x\n", tx_rate);
                goto out;
        }
@@ -921,10 +916,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
        rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
 
        /* Update frame history window with "success" if Tx got ACKed ... */
-       if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
-               status = 1;
-       else
-               status = 0;
+       status = !!(info->flags & IEEE80211_TX_STAT_ACK);
 
        /* If type matches "search" table,
         * add final tx status to "search" history */
@@ -935,10 +927,10 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
                        tpt = search_tbl->expected_tpt[rs_index];
                else
                        tpt = 0;
-               if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU)
+               if (info->flags & IEEE80211_TX_CTL_AMPDU)
                        rs_collect_tx_data(search_win, rs_index, tpt,
-                                          tx_resp->ampdu_ack_len,
-                                          tx_resp->ampdu_ack_map);
+                                          info->status.ampdu_ack_len,
+                                          info->status.ampdu_ack_map);
                else
                        rs_collect_tx_data(search_win, rs_index, tpt,
                                           1, status);
@@ -951,10 +943,10 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
                        tpt = curr_tbl->expected_tpt[rs_index];
                else
                        tpt = 0;
-               if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU)
+               if (info->flags & IEEE80211_TX_CTL_AMPDU)
                        rs_collect_tx_data(window, rs_index, tpt,
-                                          tx_resp->ampdu_ack_len,
-                                          tx_resp->ampdu_ack_map);
+                                          info->status.ampdu_ack_len,
+                                          info->status.ampdu_ack_map);
                else
                        rs_collect_tx_data(window, rs_index, tpt,
                                           1, status);
@@ -963,10 +955,10 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
        /* If not searching for new mode, increment success/failed counter
         * ... these help determine when to start searching again */
        if (lq_sta->stay_in_tbl) {
-               if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) {
-                       lq_sta->total_success += tx_resp->ampdu_ack_map;
+               if (info->flags & IEEE80211_TX_CTL_AMPDU) {
+                       lq_sta->total_success += info->status.ampdu_ack_map;
                        lq_sta->total_failed +=
-                            (tx_resp->ampdu_ack_len - tx_resp->ampdu_ack_map);
+                            (info->status.ampdu_ack_len - info->status.ampdu_ack_map);
                } else {
                        if (status)
                                lq_sta->total_success++;
@@ -990,7 +982,7 @@ out:
  * These control how long we stay using same modulation mode before
  * searching for a new mode.
  */
-static void rs_set_stay_in_table(u8 is_legacy,
+static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
                                 struct iwl4965_lq_sta *lq_sta)
 {
        IWL_DEBUG_RATE("we are staying in the same table\n");
@@ -1045,7 +1037,6 @@ static void rs_set_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
                tbl->expected_tpt = expected_tpt_G;
 }
 
-#ifdef CONFIG_IWL4965_HT
 /*
  * Find starting rate for new "search" high-throughput mode of modulation.
  * Goal is to find lowest expected rate (under perfect conditions) that is
@@ -1079,7 +1070,8 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
        new_rate = high = low = start_hi = IWL_RATE_INVALID;
 
        for (; ;) {
-               high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type);
+               high_low = rs_get_adjacent_rate(priv, rate, rate_mask,
+                                               tbl->lq_type);
 
                low = high_low & 0xff;
                high = (high_low >> 8) & 0xff;
@@ -1139,7 +1131,6 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
 
                        /* Higher rate not available, use the original */
                        } else {
-                               new_rate = rate;
                                break;
                        }
                }
@@ -1147,12 +1138,10 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
 
        return new_rate;
 }
-#endif                         /* CONFIG_IWL4965_HT */
 
 /*
  * Set up search table for MIMO
  */
-#ifdef CONFIG_IWL4965_HT
 static int rs_switch_to_mimo2(struct iwl_priv *priv,
                             struct iwl4965_lq_sta *lq_sta,
                             struct ieee80211_conf *conf,
@@ -1216,16 +1205,6 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
                     tbl->current_rate, is_green);
        return 0;
 }
-#else
-static int rs_switch_to_mimo2(struct iwl_priv *priv,
-                            struct iwl4965_lq_sta *lq_sta,
-                            struct ieee80211_conf *conf,
-                            struct sta_info *sta,
-                            struct iwl4965_scale_tbl_info *tbl, int index)
-{
-       return -1;
-}
-#endif /*CONFIG_IWL4965_HT */
 
 /*
  * Set up search table for SISO
@@ -1236,7 +1215,6 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
                             struct sta_info *sta,
                             struct iwl4965_scale_tbl_info *tbl, int index)
 {
-#ifdef CONFIG_IWL4965_HT
        u16 rate_mask;
        u8 is_green = lq_sta->is_green;
        s32 rate;
@@ -1286,9 +1264,6 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
        IWL_DEBUG_RATE("LQ: Switch to new mcs %X index is green %X\n",
                     tbl->current_rate, is_green);
        return 0;
-#else
-       return -1;
-#endif /*CONFIG_IWL4965_HT */
 }
 
 /*
@@ -1330,7 +1305,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
                                lq_sta->search_better_tbl = 1;
                                goto out;
                        }
-
+                       break;
                case IWL_LEGACY_SWITCH_SISO:
                        IWL_DEBUG_RATE("LQ: Legacy switch to SISO\n");
 
@@ -1416,9 +1391,9 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
                                lq_sta->search_better_tbl = 1;
                                goto out;
                        }
-
+                       break;
                case IWL_SISO_SWITCH_MIMO2:
-                       IWL_DEBUG_RATE("LQ: SISO switch to MIMO\n");
+                       IWL_DEBUG_RATE("LQ: SISO switch to MIMO2\n");
                        memcpy(search_tbl, tbl, sz);
                        search_tbl->is_SGI = 0;
                        search_tbl->ant_type = ANT_AB; /*FIXME:RS*/
@@ -1430,6 +1405,15 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
                        }
                        break;
                case IWL_SISO_SWITCH_GI:
+                       if (!tbl->is_fat &&
+                               !(priv->current_ht_config.sgf &
+                                               HT_SHORT_GI_20MHZ))
+                               break;
+                       if (tbl->is_fat &&
+                               !(priv->current_ht_config.sgf &
+                                               HT_SHORT_GI_40MHZ))
+                               break;
+
                        IWL_DEBUG_RATE("LQ: SISO toggle SGI/NGI\n");
 
                        memcpy(search_tbl, tbl, sz);
@@ -1512,6 +1496,15 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
                        break;
 
                case IWL_MIMO_SWITCH_GI:
+                       if (!tbl->is_fat &&
+                               !(priv->current_ht_config.sgf &
+                                               HT_SHORT_GI_20MHZ))
+                               break;
+                       if (tbl->is_fat &&
+                               !(priv->current_ht_config.sgf &
+                                               HT_SHORT_GI_40MHZ))
+                               break;
+
                        IWL_DEBUG_RATE("LQ: MIMO toggle SGI/NGI\n");
 
                        /* Set up new search table for MIMO */
@@ -1565,7 +1558,9 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
        int i;
        int active_tbl;
        int flush_interval_passed = 0;
+       struct iwl_priv *priv;
 
+       priv = lq_sta->drv;
        active_tbl = lq_sta->active_tbl;
 
        tbl = &(lq_sta->lq_info[active_tbl]);
@@ -1663,10 +1658,8 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
        u8 active_tbl = 0;
        u8 done_search = 0;
        u16 high_low;
-#ifdef CONFIG_IWL4965_HT
+       s32 sr;
        u8 tid = MAX_TID_COUNT;
-       __le16 *qc;
-#endif
 
        IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
 
@@ -1687,13 +1680,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
        }
        lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
 
-#ifdef CONFIG_IWL4965_HT
-       qc = ieee80211_get_qos_ctrl(hdr);
-       if (qc) {
-               tid = (u8)(le16_to_cpu(*qc) & 0xf);
-               rs_tl_add_packet(lq_sta, tid);
-       }
-#endif
+       rs_tl_add_packet(lq_sta, hdr);
        /*
         * Select rate-scale / modulation-mode table to work with in
         * the rest of this function:  "search" if searching for better
@@ -1838,11 +1825,13 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
 
        /* (Else) not in search of better modulation mode, try for better
         * starting rate, while staying in this mode. */
-       high_low = rs_get_adjacent_rate(index, rate_scale_index_msk,
+       high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk,
                                        tbl->lq_type);
        low = high_low & 0xff;
        high = (high_low >> 8) & 0xff;
 
+       sr = window->success_ratio;
+
        /* Collect measured throughputs for current and adjacent rates */
        current_tpt = window->average_tpt;
        if (low != IWL_RATE_INVALID)
@@ -1850,19 +1839,22 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
        if (high != IWL_RATE_INVALID)
                high_tpt = tbl->win[high].average_tpt;
 
-       /* Assume rate increase */
-       scale_action = 1;
+       scale_action = 0;
 
        /* Too many failures, decrease rate */
-       if ((window->success_ratio <= IWL_RATE_DECREASE_TH) ||
-           (current_tpt == 0)) {
+       if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
                IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
                scale_action = -1;
 
        /* No throughput measured yet for adjacent rates; try increase. */
        } else if ((low_tpt == IWL_INVALID_VALUE) &&
-                  (high_tpt == IWL_INVALID_VALUE))
-               scale_action = 1;
+                  (high_tpt == IWL_INVALID_VALUE)) {
+
+               if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
+                       scale_action = 1;
+               else if (low != IWL_RATE_INVALID)
+                       scale_action = -1;
+       }
 
        /* Both adjacent throughputs are measured, but neither one has better
         * throughput; we're using the best rate, don't change it! */
@@ -1878,9 +1870,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
                /* Higher adjacent rate's throughput is measured */
                if (high_tpt != IWL_INVALID_VALUE) {
                        /* Higher rate has better throughput */
-                       if (high_tpt > current_tpt)
+                       if (high_tpt > current_tpt &&
+                                       sr >= IWL_RATE_INCREASE_TH) {
                                scale_action = 1;
-                       else {
+                       else {
                                IWL_DEBUG_RATE
                                    ("decrease rate because of high tpt\n");
                                scale_action = -1;
@@ -1893,23 +1886,17 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
                                IWL_DEBUG_RATE
                                    ("decrease rate because of low tpt\n");
                                scale_action = -1;
-                       } else
+                       } else if (sr >= IWL_RATE_INCREASE_TH) {
                                scale_action = 1;
+                       }
                }
        }
 
        /* Sanity check; asked for decrease, but success rate or throughput
         * has been good at old rate.  Don't change it. */
-       if (scale_action == -1) {
-               if ((low != IWL_RATE_INVALID) &&
-                   ((window->success_ratio > IWL_RATE_HIGH_TH) ||
+       if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
+                   ((sr > IWL_RATE_HIGH_TH) ||
                     (current_tpt > (100 * tbl->expected_tpt[low]))))
-                       scale_action = 0;
-
-       /* Sanity check; asked for increase, but success rate has not been great
-        * even at old rate, higher rate will be worse.  Don't change it. */
-       } else if ((scale_action == 1) &&
-                  (window->success_ratio < IWL_RATE_INCREASE_TH))
                scale_action = 0;
 
        switch (scale_action) {
@@ -1938,7 +1925,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
                    "high %d type %d\n",
                     index, scale_action, low, high, tbl->lq_type);
 
- lq_update:
+lq_update:
        /* Replace uCode's rate table for the destination station. */
        if (update_lq) {
                rate = rate_n_flags_from_tbl(tbl, index, is_green);
@@ -1955,7 +1942,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
         * 2)  Not just finishing up a search
         * 3)  Allowing a new search
         */
-       if (!update_lq && !done_search && !lq_sta->stay_in_tbl) {
+       if (!update_lq && !done_search && !lq_sta->stay_in_tbl && window->counter) {
                /* Save current throughput to compare with "search" throughput*/
                lq_sta->last_tpt = current_tpt;
 
@@ -1992,13 +1979,11 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
                 * before next round of mode comparisons. */
                tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
                if (is_legacy(tbl1->lq_type) &&
-#ifdef CONFIG_IWL4965_HT
                   (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) &&
-#endif
                    (lq_sta->action_counter >= 1)) {
                        lq_sta->action_counter = 0;
                        IWL_DEBUG_RATE("LQ: STAY in legacy table\n");
-                       rs_set_stay_in_table(1, lq_sta);
+                       rs_set_stay_in_table(priv, 1, lq_sta);
                }
 
                /* If we're in an HT mode, and all 3 mode switch actions
@@ -2006,16 +1991,14 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
                 * mode for a while before next round of mode comparisons. */
                if (lq_sta->enable_counter &&
                    (lq_sta->action_counter >= IWL_ACTION_LIMIT)) {
-#ifdef CONFIG_IWL4965_HT
                        if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
                            (lq_sta->tx_agg_tid_en & (1 << tid)) &&
                            (tid != MAX_TID_COUNT)) {
                                IWL_DEBUG_RATE("try to aggregate tid %d\n", tid);
                                rs_tl_turn_on_agg(priv, tid, lq_sta, sta);
                        }
-#endif /*CONFIG_IWL4965_HT */
                        lq_sta->action_counter = 0;
-                       rs_set_stay_in_table(0, lq_sta);
+                       rs_set_stay_in_table(priv, 0, lq_sta);
                }
 
        /*
@@ -2083,7 +2066,7 @@ static void rs_initialize_lq(struct iwl_priv *priv,
                i = 0;
 
        /* FIXME:RS: This is also wrong in 4965 */
-       rate = iwl4965_rates[i].plcp;
+       rate = iwl_rates[i].plcp;
        rate |= RATE_MCS_ANT_B_MSK;
        rate &= ~RATE_MCS_ANT_A_MSK;
 
@@ -2130,7 +2113,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
        fc = le16_to_cpu(hdr->frame_control);
        if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) ||
            !sta || !sta->rate_ctrl_priv) {
-               sel->rate = rate_lowest(local, sband, sta);
+               sel->rate_idx = rate_lowest_index(local, sband, sta);
                goto out;
        }
 
@@ -2145,7 +2128,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
                if (sta_id == IWL_INVALID_STATION) {
                        IWL_DEBUG_RATE("LQ: ADD station %s\n",
                                       print_mac(mac, hdr->addr1));
-                       sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
+                       sta_id = iwl_add_station_flags(priv, hdr->addr1,
                                                        0, CMD_ASYNC, NULL);
                }
                if ((sta_id != IWL_INVALID_STATION)) {
@@ -2160,20 +2143,24 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
 
 done:
        if ((i < 0) || (i > IWL_RATE_COUNT)) {
-               sel->rate = rate_lowest(local, sband, sta);
+               sel->rate_idx = rate_lowest_index(local, sband, sta);
                goto out;
        }
 
-       sel->rate = &priv->ieee_rates[i];
+       if (sband->band == IEEE80211_BAND_5GHZ)
+               i -= IWL_FIRST_OFDM_RATE;
+       sel->rate_idx = i;
 out:
        rcu_read_unlock();
 }
 
-static void *rs_alloc_sta(void *priv, gfp_t gfp)
+static void *rs_alloc_sta(void *priv_rate, gfp_t gfp)
 {
        struct iwl4965_lq_sta *lq_sta;
+       struct iwl_priv *priv;
        int i, j;
 
+       priv = (struct iwl_priv *)priv_rate;
        IWL_DEBUG_RATE("create station rate scale window\n");
 
        lq_sta = kzalloc(sizeof(struct iwl4965_lq_sta), gfp);
@@ -2227,7 +2214,7 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
                if (sta_id == IWL_INVALID_STATION) {
                        IWL_DEBUG_RATE("LQ: ADD station %s\n",
                                       print_mac(mac, sta->addr));
-                       sta_id = iwl4965_add_station_flags(priv, sta->addr,
+                       sta_id = iwl_add_station_flags(priv, sta->addr,
                                                        0, CMD_ASYNC, NULL);
                }
                if ((sta_id != IWL_INVALID_STATION)) {
@@ -2254,7 +2241,6 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
        lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000);
        lq_sta->active_rate_basic = priv->active_rate_basic;
        lq_sta->band = priv->band;
-#ifdef CONFIG_IWL4965_HT
        /*
         * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
         * supp_rates[] does not; shift to convert format, force 9 MBits off.
@@ -2292,7 +2278,6 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
 
        /* as default allow aggregation for all tids */
        lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
-#endif /*CONFIG_IWL4965_HT*/
 #ifdef CONFIG_MAC80211_DEBUGFS
        lq_sta->drv = priv;
 #endif
@@ -2418,6 +2403,7 @@ static void rs_fill_link_cmd(const struct iwl_priv *priv,
                repeat_rate--;
        }
 
+       lq_cmd->agg_params.agg_frame_cnt_limit = 64;
        lq_cmd->agg_params.agg_dis_start_th = 3;
        lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
 }
@@ -2443,10 +2429,12 @@ static void rs_clear(void *priv_rate)
        IWL_DEBUG_RATE("leave\n");
 }
 
-static void rs_free_sta(void *priv, void *priv_sta)
+static void rs_free_sta(void *priv_rate, void *priv_sta)
 {
        struct iwl4965_lq_sta *lq_sta = priv_sta;
+       struct iwl_priv *priv;
 
+       priv = (struct iwl_priv *)priv_rate;
        IWL_DEBUG_RATE("enter\n");
        kfree(lq_sta);
        IWL_DEBUG_RATE("leave\n");
@@ -2462,6 +2450,9 @@ static int open_file_generic(struct inode *inode, struct file *file)
 static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
                                u32 *rate_n_flags, int index)
 {
+       struct iwl_priv *priv;
+
+       priv = lq_sta->drv;
        if (lq_sta->dbg_fixed_rate) {
                if (index < 12) {
                        *rate_n_flags = lq_sta->dbg_fixed_rate;
@@ -2481,10 +2472,12 @@ static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
                        const char __user *user_buf, size_t count, loff_t *ppos)
 {
        struct iwl4965_lq_sta *lq_sta = file->private_data;
+       struct iwl_priv *priv;
        char buf[64];
        int buf_size;
        u32 parsed_rate;
 
+       priv = lq_sta->drv;
        memset(buf, 0, sizeof(buf));
        buf_size = min(count, sizeof(buf) -  1);
        if (copy_from_user(buf, user_buf, buf_size))
@@ -2602,11 +2595,9 @@ static void rs_add_debugfs(void *priv, void *priv_sta,
        lq_sta->rs_sta_dbgfs_stats_table_file =
                debugfs_create_file("rate_stats_table", 0600, dir,
                        lq_sta, &rs_sta_dbgfs_stats_table_ops);
-#ifdef CONFIG_IWL4965_HT
        lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
                debugfs_create_u8("tx_agg_tid_enable", 0600, dir,
                &lq_sta->tx_agg_tid_en);
-#endif
 
 }
 
@@ -2615,9 +2606,7 @@ static void rs_remove_debugfs(void *priv, void *priv_sta)
        struct iwl4965_lq_sta *lq_sta = priv_sta;
        debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
        debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
-#ifdef CONFIG_IWL4965_HT
        debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
-#endif
 }
 #endif
 
@@ -2677,7 +2666,7 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
                int active = lq_sta->active_tbl;
 
                cnt +=
-                   sprintf(&buf[cnt], " %2dMbs: ", iwl4965_rates[i].ieee / 2);
+                   sprintf(&buf[cnt], " %2dMbs: ", iwl_rates[i].ieee / 2);
 
                mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
                for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
@@ -2688,7 +2677,7 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
                samples += lq_sta->lq_info[active].win[i].counter;
                good += lq_sta->lq_info[active].win[i].success_counter;
                success += lq_sta->lq_info[active].win[i].success_counter *
-                          iwl4965_rates[i].ieee;
+                          iwl_rates[i].ieee;
 
                if (lq_sta->lq_info[active].win[i].stamp) {
                        int delta =
@@ -2708,10 +2697,11 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
                i = j;
        }
 
-       /* Display the average rate of all samples taken.
-        *
-        * NOTE:  We multiply # of samples by 2 since the IEEE measurement
-        * added from iwl4965_rates is actually 2X the rate */
+       /*
+        * Display the average rate of all samples taken.
+        * NOTE: We multiply # of samples by 2 since the IEEE measurement
+        * added from iwl_rates is actually 2X the rate.
+        */
        if (samples)
                cnt += sprintf(&buf[cnt],
                         "\nAverage rate is %3d.%02dMbs over last %4dms\n"