iwlwifi: removing IWL4965_HT config
[pandora-kernel.git] / drivers / net / wireless / iwlwifi / iwl-4965-rs.c
index 071c7b6..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,16 +153,12 @@ 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;
 #endif
        struct iwl_priv *drv;
@@ -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.
@@ -389,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) +
@@ -626,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)
 {
@@ -634,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
@@ -785,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;
@@ -798,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;
@@ -813,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;
@@ -862,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;
        }
@@ -929,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 */
@@ -943,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);
@@ -959,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);
@@ -971,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++;
@@ -1053,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
@@ -1148,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;
                        }
                }
@@ -1156,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,
@@ -1225,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
@@ -1245,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;
@@ -1295,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 */
 }
 
 /*
@@ -1339,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");
 
@@ -1425,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*/
@@ -1439,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);
@@ -1521,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 */
@@ -1674,9 +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;
-#endif
 
        IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
 
@@ -1697,9 +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
        rs_tl_add_packet(lq_sta, hdr);
-#endif
        /*
         * Select rate-scale / modulation-mode table to work with in
         * the rest of this function:  "search" if searching for better
@@ -1849,6 +1830,8 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
        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)
@@ -1856,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! */
@@ -1884,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;
@@ -1899,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) {
@@ -1944,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);
@@ -1961,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;
 
@@ -1998,9 +1979,7 @@ 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");
@@ -2012,14 +1991,12 @@ 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(priv, 0, lq_sta);
                }
@@ -2136,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;
        }
 
@@ -2166,11 +2143,13 @@ 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();
 }
@@ -2262,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.
@@ -2300,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
@@ -2426,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);
 }
@@ -2617,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
 
 }
 
@@ -2630,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