iwlwifi: add Greenfield support for 11n
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-agn-rs.c
index 3504279..a1b0ff5 100644 (file)
@@ -100,6 +100,7 @@ struct iwl_scale_tbl_info {
        u8 is_fat;      /* 1 = 40 MHz channel width */
        u8 is_dup;      /* 1 = duplicated data streams */
        u8 action;      /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
+       u8 max_search;  /* maximun number of tables we can search */
        s32 *expected_tpt;      /* throughput metrics; expected_tpt_G, etc. */
        u32 current_rate;  /* rate_n_flags, uCode API format */
        struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
@@ -160,6 +161,7 @@ struct iwl_lq_sta {
 #ifdef CONFIG_MAC80211_DEBUGFS
        struct dentry *rs_sta_dbgfs_scale_table_file;
        struct dentry *rs_sta_dbgfs_stats_table_file;
+       struct dentry *rs_sta_dbgfs_rate_scale_data_file;
        struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
        u32 dbg_fixed_rate;
 #endif
@@ -172,7 +174,7 @@ struct iwl_lq_sta {
 };
 
 static void rs_rate_scale_perform(struct iwl_priv *priv,
-                                  struct ieee80211_hdr *hdr,
+                                  struct sk_buff *skb,
                                   struct ieee80211_sta *sta,
                                   struct iwl_lq_sta *lq_sta);
 static void rs_fill_link_cmd(const struct iwl_priv *priv,
@@ -579,6 +581,7 @@ static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
        tbl->is_dup = 0;
        tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
        tbl->lq_type = LQ_NONE;
+       tbl->max_search = IWL_MAX_SEARCH;
 
        /* legacy rate format */
        if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
@@ -612,8 +615,10 @@ static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
                                tbl->lq_type = LQ_MIMO2;
                /* MIMO3 */
                } else {
-                       if (num_of_ant == 3)
+                       if (num_of_ant == 3) {
+                               tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
                                tbl->lq_type = LQ_MIMO3;
+                       }
                }
        }
        return 0;
@@ -647,19 +652,19 @@ static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
        return 1;
 }
 
-/* FIXME:RS: in 4965 we don't use greenfield at all */
-/* FIXME:RS: don't use greenfield for now in TX */
-#if 0
-static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
-{
-       return (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
-               priv->current_ht_config.is_green_field &&
-               !priv->current_ht_config.non_GF_STA_present;
-}
-#endif
-static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
+/* in 4965 we don't use greenfield at all */
+static inline u8 rs_use_green(struct iwl_priv *priv,
+                             struct ieee80211_conf *conf)
 {
-       return 0;
+       u8 is_green;
+
+       if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)
+               is_green = 0;
+       else
+               is_green = (conf_is_ht(conf) &&
+                          priv->current_ht_config.is_green_field &&
+                          !priv->current_ht_config.non_GF_STA_present);
+       return is_green;
 }
 
 /**
@@ -771,6 +776,7 @@ static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
 
                tbl->is_fat = 0;
                tbl->is_SGI = 0;
+               tbl->max_search = IWL_MAX_SEARCH;
        }
 
        rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
@@ -829,7 +835,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
        IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
 
        if (!ieee80211_is_data(hdr->frame_control) ||
-           is_multicast_ether_addr(hdr->addr1))
+           info->flags & IEEE80211_TX_CTL_NO_ACK)
                return;
 
        /* This packet was aggregated but doesn't carry rate scale info */
@@ -995,7 +1001,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
 
        /* See if there's a better rate or modulation mode to try. */
        if (sta && sta->supp_rates[sband->band])
-               rs_rate_scale_perform(priv, hdr, sta, lq_sta);
+               rs_rate_scale_perform(priv, skb, sta, lq_sta);
 out:
        return;
 }
@@ -1026,6 +1032,7 @@ static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
        lq_sta->total_failed = 0;
        lq_sta->total_success = 0;
        lq_sta->flush_timer = jiffies;
+       lq_sta->action_counter = 0;
 }
 
 /*
@@ -1205,10 +1212,10 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
        tbl->lq_type = LQ_MIMO2;
        tbl->is_dup = lq_sta->is_dup;
        tbl->action = 0;
+       tbl->max_search = IWL_MAX_SEARCH;
        rate_mask = lq_sta->active_mimo2_rate;
 
-       if (priv->current_ht_config.supported_chan_width
-                                       == IWL_CHANNEL_WIDTH_40MHZ)
+       if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
                tbl->is_fat = 1;
        else
                tbl->is_fat = 0;
@@ -1271,10 +1278,10 @@ static int rs_switch_to_mimo3(struct iwl_priv *priv,
        tbl->lq_type = LQ_MIMO3;
        tbl->is_dup = lq_sta->is_dup;
        tbl->action = 0;
+       tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
        rate_mask = lq_sta->active_mimo3_rate;
 
-       if (priv->current_ht_config.supported_chan_width
-                                       == IWL_CHANNEL_WIDTH_40MHZ)
+       if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
                tbl->is_fat = 1;
        else
                tbl->is_fat = 0;
@@ -1330,10 +1337,10 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
        tbl->is_dup = lq_sta->is_dup;
        tbl->lq_type = LQ_SISO;
        tbl->action = 0;
+       tbl->max_search = IWL_MAX_SEARCH;
        rate_mask = lq_sta->active_siso_rate;
 
-       if (priv->current_ht_config.supported_chan_width
-           == IWL_CHANNEL_WIDTH_40MHZ)
+       if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
                tbl->is_fat = 1;
        else
                tbl->is_fat = 0;
@@ -1387,15 +1394,15 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
        u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
        u8 tx_chains_num = priv->hw_params.tx_chains_num;
        int ret = 0;
+       u8 update_search_tbl_counter = 0;
 
        for (; ;) {
+               lq_sta->action_counter++;
                switch (tbl->action) {
                case IWL_LEGACY_SWITCH_ANTENNA1:
                case IWL_LEGACY_SWITCH_ANTENNA2:
                        IWL_DEBUG_RATE(priv, "LQ: Legacy toggle Antenna\n");
 
-                       lq_sta->action_counter++;
-
                        if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
                                                        tx_chains_num <= 1) ||
                            (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
@@ -1411,6 +1418,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
 
                        if (rs_toggle_antenna(valid_tx_ant,
                                &search_tbl->current_rate, search_tbl)) {
+                               update_search_tbl_counter = 1;
                                rs_set_expected_tpt_table(lq_sta, search_tbl);
                                goto out;
                        }
@@ -1492,6 +1500,8 @@ out:
        tbl->action++;
        if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
                tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
+       if (update_search_tbl_counter)
+               search_tbl->action = tbl->action;
        return 0;
 
 }
@@ -1514,6 +1524,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
        u8 start_action = tbl->action;
        u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
        u8 tx_chains_num = priv->hw_params.tx_chains_num;
+       u8 update_search_tbl_counter = 0;
        int ret;
 
        for (;;) {
@@ -1534,8 +1545,10 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
 
                        memcpy(search_tbl, tbl, sz);
                        if (rs_toggle_antenna(valid_tx_ant,
-                                      &search_tbl->current_rate, search_tbl))
+                                      &search_tbl->current_rate, search_tbl)) {
+                               update_search_tbl_counter = 1;
                                goto out;
+                       }
                        break;
                case IWL_SISO_SWITCH_MIMO2_AB:
                case IWL_SISO_SWITCH_MIMO2_AC:
@@ -1589,6 +1602,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
                        search_tbl->current_rate =
                                rate_n_flags_from_tbl(priv, search_tbl,
                                                      index, is_green);
+                       update_search_tbl_counter = 1;
                        goto out;
                case IWL_SISO_SWITCH_MIMO3_ABC:
                        IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n");
@@ -1620,6 +1634,9 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
        tbl->action++;
        if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
                tbl->action = IWL_SISO_SWITCH_ANTENNA1;
+       if (update_search_tbl_counter)
+               search_tbl->action = tbl->action;
+
        return 0;
 }
 
@@ -1641,6 +1658,7 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
        u8 start_action = tbl->action;
        u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
        u8 tx_chains_num = priv->hw_params.tx_chains_num;
+       u8 update_search_tbl_counter = 0;
        int ret;
 
        for (;;) {
@@ -1658,8 +1676,10 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
 
                        memcpy(search_tbl, tbl, sz);
                        if (rs_toggle_antenna(valid_tx_ant,
-                                      &search_tbl->current_rate, search_tbl))
+                                      &search_tbl->current_rate, search_tbl)) {
+                               update_search_tbl_counter = 1;
                                goto out;
+                       }
                        break;
                case IWL_MIMO2_SWITCH_SISO_A:
                case IWL_MIMO2_SWITCH_SISO_B:
@@ -1716,6 +1736,7 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
                        search_tbl->current_rate =
                                rate_n_flags_from_tbl(priv, search_tbl,
                                                      index, is_green);
+                       update_search_tbl_counter = 1;
                        goto out;
 
                case IWL_MIMO2_SWITCH_MIMO3_ABC:
@@ -1748,6 +1769,9 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
        tbl->action++;
        if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
                tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
+       if (update_search_tbl_counter)
+               search_tbl->action = tbl->action;
+
        return 0;
 
 }
@@ -1771,6 +1795,7 @@ static int rs_move_mimo3_to_other(struct iwl_priv *priv,
        u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
        u8 tx_chains_num = priv->hw_params.tx_chains_num;
        int ret;
+       u8 update_search_tbl_counter = 0;
 
        for (;;) {
                lq_sta->action_counter++;
@@ -1869,6 +1894,7 @@ static int rs_move_mimo3_to_other(struct iwl_priv *priv,
                        search_tbl->current_rate =
                                rate_n_flags_from_tbl(priv, search_tbl,
                                                      index, is_green);
+                       update_search_tbl_counter = 1;
                        goto out;
                }
                tbl->action++;
@@ -1885,6 +1911,9 @@ static int rs_move_mimo3_to_other(struct iwl_priv *priv,
        tbl->action++;
        if (tbl->action > IWL_MIMO3_SWITCH_GI)
                tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
+       if (update_search_tbl_counter)
+               search_tbl->action = tbl->action;
+
        return 0;
 
 }
@@ -1975,12 +2004,14 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
  * Do rate scaling and search for new modulation mode.
  */
 static void rs_rate_scale_perform(struct iwl_priv *priv,
-                                 struct ieee80211_hdr *hdr,
+                                 struct sk_buff *skb,
                                  struct ieee80211_sta *sta,
                                  struct iwl_lq_sta *lq_sta)
 {
        struct ieee80211_hw *hw = priv->hw;
        struct ieee80211_conf *conf = &hw->conf;
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
        int low = IWL_RATE_INVALID;
        int high = IWL_RATE_INVALID;
        int index;
@@ -2006,11 +2037,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
 
        IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
 
-       /* Send management frames and broadcast/multicast data using
-        * lowest rate. */
+       /* Send management frames and NO_ACK data using lowest rate. */
        /* TODO: this could probably be improved.. */
        if (!ieee80211_is_data(hdr->frame_control) ||
-           is_multicast_ether_addr(hdr->addr1))
+           info->flags & IEEE80211_TX_CTL_NO_ACK)
                return;
 
        if (!sta || !lq_sta)
@@ -2031,6 +2061,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
                active_tbl = 1 - lq_sta->active_tbl;
 
        tbl = &(lq_sta->lq_info[active_tbl]);
+       if (is_legacy(tbl->lq_type))
+               lq_sta->is_green = 0;
+       else
+               lq_sta->is_green = rs_use_green(priv, conf);
        is_green = lq_sta->is_green;
 
        /* current tx rate */
@@ -2328,8 +2362,7 @@ lq_update:
                 * before next round of mode comparisons. */
                tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
                if (is_legacy(tbl1->lq_type) && !conf_is_ht(conf) &&
-                   lq_sta->action_counter >= 1) {
-                       lq_sta->action_counter = 0;
+                   lq_sta->action_counter > tbl1->max_search) {
                        IWL_DEBUG_RATE(priv, "LQ: STAY in legacy table\n");
                        rs_set_stay_in_table(priv, 1, lq_sta);
                }
@@ -2338,7 +2371,7 @@ lq_update:
                 * have been tried and compared, stay in this best modulation
                 * mode for a while before next round of mode comparisons. */
                if (lq_sta->enable_counter &&
-                   (lq_sta->action_counter >= IWL_ACTION_LIMIT)) {
+                   (lq_sta->action_counter >= tbl1->max_search)) {
                        if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
                            (lq_sta->tx_agg_tid_en & (1 << tid)) &&
                            (tid != MAX_TID_COUNT)) {
@@ -2352,7 +2385,6 @@ lq_update:
                                                          lq_sta, sta);
                                }
                        }
-                       lq_sta->action_counter = 0;
                        rs_set_stay_in_table(priv, 0, lq_sta);
                }
        }
@@ -2450,16 +2482,17 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
        if (sta)
                mask_bit = sta->supp_rates[sband->band];
 
-       /* Send management frames and broadcast/multicast data using lowest
-        * rate. */
+       /* Send management frames and NO_ACK data using lowest rate. */
        if (!ieee80211_is_data(hdr->frame_control) ||
-           is_multicast_ether_addr(hdr->addr1) || !sta || !lq_sta) {
+           info->flags & IEEE80211_TX_CTL_NO_ACK || !sta || !lq_sta) {
                if (!mask_bit)
                        info->control.rates[0].idx =
                                        rate_lowest_index(sband, NULL);
                else
                        info->control.rates[0].idx =
                                        rate_lowest_index(sband, sta);
+               if (info->flags & IEEE80211_TX_CTL_NO_ACK)
+                       info->control.rates[0].count = 1;
                return;
        }
 
@@ -2867,7 +2900,8 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
                   ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
                   desc += sprintf(buff+desc, " %s",
                   (tbl->is_fat) ? "40MHz" : "20MHz");
-               desc += sprintf(buff+desc, " %s\n", (tbl->is_SGI) ? "SGI" : "");
+                  desc += sprintf(buff+desc, " %s %s\n", (tbl->is_SGI) ? "SGI" : "",
+                  (lq_sta->is_green) ? "GF enabled" : "");
        }
        desc += sprintf(buff+desc, "last tx rate=0x%X\n",
                lq_sta->last_rate_n_flags);
@@ -2930,13 +2964,14 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
                return -ENOMEM;
 
        for (i = 0; i < LQ_SIZE; i++) {
-               desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
+               desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d GF=%d\n"
                                "rate=0x%X\n",
                                lq_sta->active_tbl == i ? "*" : "x",
                                lq_sta->lq_info[i].lq_type,
                                lq_sta->lq_info[i].is_SGI,
                                lq_sta->lq_info[i].is_fat,
                                lq_sta->lq_info[i].is_dup,
+                               lq_sta->is_green,
                                lq_sta->lq_info[i].current_rate);
                for (j = 0; j < IWL_RATE_COUNT; j++) {
                        desc += sprintf(buff+desc,
@@ -2956,6 +2991,43 @@ static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
        .open = open_file_generic,
 };
 
+static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
+                       char __user *user_buf, size_t count, loff_t *ppos)
+{
+       char buff[120];
+       int desc = 0;
+       ssize_t ret;
+
+       struct iwl_lq_sta *lq_sta = file->private_data;
+       struct iwl_priv *priv;
+       struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
+
+       priv = lq_sta->drv;
+
+       if (is_Ht(tbl->lq_type))
+               desc += sprintf(buff+desc,
+                               "Bit Rate= %d Mb/s\n",
+                               tbl->expected_tpt[lq_sta->last_txrate_idx]);
+       else
+               desc += sprintf(buff+desc,
+                               "Bit Rate= %d Mb/s\n",
+                               iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
+       desc += sprintf(buff+desc,
+                       "Signal Level= %d dBm\tNoise Level= %d dBm\n",
+                       priv->last_rx_rssi, priv->last_rx_noise);
+       desc += sprintf(buff+desc,
+                       "Tsf= 0x%llx\tBeacon time= 0x%08X\n",
+                       priv->last_tsf, priv->last_beacon_time);
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
+       return ret;
+}
+
+static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
+       .read = rs_sta_dbgfs_rate_scale_data_read,
+       .open = open_file_generic,
+};
+
 static void rs_add_debugfs(void *priv, void *priv_sta,
                                        struct dentry *dir)
 {
@@ -2966,6 +3038,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);
+       lq_sta->rs_sta_dbgfs_rate_scale_data_file =
+               debugfs_create_file("rate_scale_data", 0600, dir,
+                       lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
        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);
@@ -2977,6 +3052,7 @@ static void rs_remove_debugfs(void *priv, void *priv_sta)
        struct iwl_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);
+       debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
        debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
 }
 #endif