]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/net/wireless/iwlwifi/iwl-3945-rs.c
iwlwifi: update copyright year to 2009
[mv-sheeva.git] / drivers / net / wireless / iwlwifi / iwl-3945-rs.c
index 9b60a0c5de5f3f55bf45bd7acf8594e3973f172a..25b4356fcc1c106e5aee927a65aa77ecd1ed56ee 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
+ * Copyright(c) 2005 - 2009 Intel Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -36,6 +36,7 @@
 
 #include <linux/workqueue.h>
 
+#include "iwl-commands.h"
 #include "iwl-3945.h"
 
 #define RS_NAME "iwl-3945-rs"
@@ -51,6 +52,7 @@ struct iwl3945_rate_scale_data {
 
 struct iwl3945_rs_sta {
        spinlock_t lock;
+       struct iwl_priv *priv;
        s32 *expected_tpt;
        unsigned long last_partial_flush;
        unsigned long last_flush;
@@ -62,7 +64,7 @@ struct iwl3945_rs_sta {
        u8 start_rate;
        u8 ibss_sta_added;
        struct timer_list rate_scale_flush;
-       struct iwl3945_rate_scale_data win[IWL_RATE_COUNT];
+       struct iwl3945_rate_scale_data win[IWL_RATE_COUNT_3945];
 #ifdef CONFIG_MAC80211_DEBUGFS
        struct dentry *rs_sta_dbgfs_stats_table_file;
 #endif
@@ -71,19 +73,19 @@ struct iwl3945_rs_sta {
        int last_txrate_idx;
 };
 
-static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT] = {
+static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT_3945] = {
        7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202
 };
 
-static s32 iwl3945_expected_tpt_g_prot[IWL_RATE_COUNT] = {
+static s32 iwl3945_expected_tpt_g_prot[IWL_RATE_COUNT_3945] = {
        7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125
 };
 
-static s32 iwl3945_expected_tpt_a[IWL_RATE_COUNT] = {
+static s32 iwl3945_expected_tpt_a[IWL_RATE_COUNT_3945] = {
        0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186
 };
 
-static s32 iwl3945_expected_tpt_b[IWL_RATE_COUNT] = {
+static s32 iwl3945_expected_tpt_b[IWL_RATE_COUNT_3945] = {
        7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
@@ -119,7 +121,7 @@ static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = {
 #define IWL_RATE_MAX_WINDOW          62
 #define IWL_RATE_FLUSH          (3*HZ)
 #define IWL_RATE_WIN_FLUSH       (HZ/2)
-#define IWL_RATE_HIGH_TH          11520
+#define IWL39_RATE_HIGH_TH          11520
 #define IWL_SUCCESS_UP_TH         8960
 #define IWL_SUCCESS_DOWN_TH      10880
 #define IWL_RATE_MIN_FAILURE_TH       8
@@ -165,7 +167,7 @@ static void iwl3945_clear_window(struct iwl3945_rate_scale_data *window)
        window->success_counter = 0;
        window->success_ratio = -1;
        window->counter = 0;
-       window->average_tpt = IWL_INV_TPT;
+       window->average_tpt = IWL_INVALID_VALUE;
        window->stamp = 0;
 }
 
@@ -181,13 +183,14 @@ static int iwl3945_rate_scale_flush_windows(struct iwl3945_rs_sta *rs_sta)
        int unflushed = 0;
        int i;
        unsigned long flags;
+       struct iwl_priv *priv = rs_sta->priv;
 
        /*
         * For each rate, if we have collected data on that rate
         * and it has been more than IWL_RATE_WIN_FLUSH
         * since we flushed, clear out the gathered statistics
         */
-       for (i = 0; i < IWL_RATE_COUNT; i++) {
+       for (i = 0; i < IWL_RATE_COUNT_3945; i++) {
                if (!rs_sta->win[i].counter)
                        continue;
 
@@ -213,6 +216,7 @@ static int iwl3945_rate_scale_flush_windows(struct iwl3945_rs_sta *rs_sta)
 static void iwl3945_bg_rate_scale_flush(unsigned long data)
 {
        struct iwl3945_rs_sta *rs_sta = (void *)data;
+       struct iwl_priv *priv = rs_sta->priv;
        int unflushed = 0;
        unsigned long flags;
        u32 packet_count, duration, pps;
@@ -286,6 +290,7 @@ static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta,
 {
        unsigned long flags;
        s32 fail_count;
+       struct iwl_priv *priv = rs_sta->priv;
 
        if (!retries) {
                IWL_DEBUG_RATE("leave: retries == 0 -- should be at least 1\n");
@@ -329,7 +334,7 @@ static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta,
                window->average_tpt = ((window->success_ratio *
                                rs_sta->expected_tpt[index] + 64) / 128);
        else
-               window->average_tpt = IWL_INV_TPT;
+               window->average_tpt = IWL_INVALID_VALUE;
 
        spin_unlock_irqrestore(&rs_sta->lock, flags);
 
@@ -339,7 +344,7 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
                         struct ieee80211_sta *sta, void *priv_sta)
 {
        struct iwl3945_rs_sta *rs_sta = priv_sta;
-       struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_r;
+       struct iwl_priv *priv = (struct iwl_priv *)priv_r;
        int i;
 
        IWL_DEBUG_RATE("enter\n");
@@ -379,10 +384,11 @@ static void rs_free(void *priv)
        return;
 }
 
-static void *rs_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
+static void *rs_alloc_sta(void *iwl_priv, struct ieee80211_sta *sta, gfp_t gfp)
 {
        struct iwl3945_rs_sta *rs_sta;
        struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
+       struct iwl_priv *priv = iwl_priv;
        int i;
 
        /*
@@ -402,6 +408,8 @@ static void *rs_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
 
        spin_lock_init(&rs_sta->lock);
 
+       rs_sta->priv = priv;
+
        rs_sta->start_rate = IWL_RATE_INVALID;
 
        /* default to just 802.11b */
@@ -417,7 +425,7 @@ static void *rs_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
        rs_sta->rate_scale_flush.data = (unsigned long)rs_sta;
        rs_sta->rate_scale_flush.function = &iwl3945_bg_rate_scale_flush;
 
-       for (i = 0; i < IWL_RATE_COUNT; i++)
+       for (i = 0; i < IWL_RATE_COUNT_3945; i++)
                iwl3945_clear_window(&rs_sta->win[i]);
 
        IWL_DEBUG_RATE("leave\n");
@@ -425,11 +433,12 @@ static void *rs_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
        return rs_sta;
 }
 
-static void rs_free_sta(void *priv, struct ieee80211_sta *sta,
+static void rs_free_sta(void *iwl_priv, struct ieee80211_sta *sta,
                        void *priv_sta)
 {
        struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
        struct iwl3945_rs_sta *rs_sta = priv_sta;
+       struct iwl_priv *priv = rs_sta->priv;
 
        psta->rs_sta = NULL;
 
@@ -443,7 +452,7 @@ static void rs_free_sta(void *priv, struct ieee80211_sta *sta,
 /**
  * rs_tx_status - Update rate control values based on Tx results
  *
- * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by
+ * NOTE: Uses iwl_priv->retry_rate for the # of retries attempted by
  * the hardware for each rate.
  */
 static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband,
@@ -453,7 +462,7 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
        s8 retries = 0, current_count;
        int scale_rate_index, first_index, last_index;
        unsigned long flags;
-       struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate;
+       struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
        struct iwl3945_rs_sta *rs_sta = priv_sta;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
 
@@ -462,7 +471,7 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
        retries = info->status.rates[0].count;
 
        first_index = sband->bitrates[info->status.rates[0].idx].hw_value;
-       if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) {
+       if ((first_index < 0) || (first_index >= IWL_RATE_COUNT_3945)) {
                IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index);
                return;
        }
@@ -547,6 +556,7 @@ static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta,
 {
        u8 high = IWL_RATE_INVALID;
        u8 low = IWL_RATE_INVALID;
+       struct iwl_priv *priv = rs_sta->priv;
 
        /* 802.11A walks to the next literal adjacent rate in
         * the rate table */
@@ -565,7 +575,8 @@ static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta,
 
                /* Find the next rate that is in the rate mask */
                i = index + 1;
-               for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
+               for (mask = (1 << i); i < IWL_RATE_COUNT_3945;
+                    i++, mask <<= 1) {
                        if (rate_mask & mask) {
                                high = i;
                                break;
@@ -631,19 +642,23 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
        int index;
        struct iwl3945_rs_sta *rs_sta = priv_sta;
        struct iwl3945_rate_scale_data *window = NULL;
-       int current_tpt = IWL_INV_TPT;
-       int low_tpt = IWL_INV_TPT;
-       int high_tpt = IWL_INV_TPT;
+       int current_tpt = IWL_INVALID_VALUE;
+       int low_tpt = IWL_INVALID_VALUE;
+       int high_tpt = IWL_INVALID_VALUE;
        u32 fail_count;
        s8 scale_action = 0;
        unsigned long flags;
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
-       u16 fc, rate_mask;
-       struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_r;
+       u16 fc;
+       u16 rate_mask = 0;
+       struct iwl_priv *priv = (struct iwl_priv *)priv_r;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
 
        IWL_DEBUG_RATE("enter\n");
 
+       if (sta)
+               rate_mask = sta->supp_rates[sband->band];
+
        /* Send management frames and broadcast/multicast data using lowest
         * rate. */
        fc = le16_to_cpu(hdr->frame_control);
@@ -651,12 +666,16 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
            is_multicast_ether_addr(hdr->addr1) ||
            !sta || !priv_sta) {
                IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
-               info->control.rates[0].idx = rate_lowest_index(sband, sta);
+               if (!rate_mask)
+                       info->control.rates[0].idx =
+                                       rate_lowest_index(sband, NULL);
+               else
+                       info->control.rates[0].idx =
+                                       rate_lowest_index(sband, sta);
                return;
        }
 
-       rate_mask = sta->supp_rates[sband->band];
-       index = min(rs_sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT - 1);
+       index = min(rs_sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT_3945 - 1);
 
        if (sband->band == IEEE80211_BAND_5GHZ)
                rate_mask = rate_mask << IWL_FIRST_OFDM_RATE;
@@ -726,16 +745,18 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
        if ((window->success_ratio < IWL_RATE_DECREASE_TH) || !current_tpt) {
                IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
                scale_action = -1;
-       } else if ((low_tpt == IWL_INV_TPT) && (high_tpt == IWL_INV_TPT))
+       } else if ((low_tpt == IWL_INVALID_VALUE) &&
+                  (high_tpt == IWL_INVALID_VALUE))
                scale_action = 1;
-       else if ((low_tpt != IWL_INV_TPT) && (high_tpt != IWL_INV_TPT) &&
+       else if ((low_tpt != IWL_INVALID_VALUE) &&
+                (high_tpt != IWL_INVALID_VALUE) &&
                 (low_tpt < current_tpt) && (high_tpt < current_tpt)) {
                IWL_DEBUG_RATE("No action -- low [%d] & high [%d] < "
                               "current_tpt [%d]\n",
                               low_tpt, high_tpt, current_tpt);
                scale_action = 0;
        } else {
-               if (high_tpt != IWL_INV_TPT) {
+               if (high_tpt != IWL_INVALID_VALUE) {
                        if (high_tpt > current_tpt)
                                scale_action = 1;
                        else {
@@ -743,7 +764,7 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
                                    ("decrease rate because of high tpt\n");
                                scale_action = -1;
                        }
-               } else if (low_tpt != IWL_INV_TPT) {
+               } else if (low_tpt != IWL_INVALID_VALUE) {
                        if (low_tpt > current_tpt) {
                                IWL_DEBUG_RATE
                                    ("decrease rate because of low tpt\n");
@@ -817,7 +838,7 @@ static ssize_t iwl3945_sta_dbgfs_stats_table_read(struct file *file,
                        lq_sta->tx_packets,
                        lq_sta->last_txrate_idx,
                        lq_sta->start_rate, jiffies_to_msecs(lq_sta->flush_time));
-       for (j = 0; j < IWL_RATE_COUNT; j++) {
+       for (j = 0; j < IWL_RATE_COUNT_3945; j++) {
                desc += sprintf(buff+desc,
                                "counter=%d success=%d %%=%d\n",
                                lq_sta->win[j].counter,
@@ -869,7 +890,7 @@ static struct rate_control_ops rs_ops = {
 
 void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
 {
-       struct iwl3945_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        s32 rssi = 0;
        unsigned long flags;
        struct iwl3945_rs_sta *rs_sta;
@@ -880,7 +901,7 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
 
        rcu_read_lock();
 
-       sta = ieee80211_find_sta(hw, priv->stations[sta_id].sta.sta.addr);
+       sta = ieee80211_find_sta(hw, priv->stations_39[sta_id].sta.sta.addr);
        if (!sta) {
                rcu_read_unlock();
                return;
@@ -895,7 +916,7 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
        switch (priv->band) {
        case IEEE80211_BAND_2GHZ:
                /* TODO: this always does G, not a regression */
-               if (priv->active_rxon.flags & RXON_FLG_TGG_PROTECT_MSK) {
+               if (priv->active39_rxon.flags & RXON_FLG_TGG_PROTECT_MSK) {
                        rs_sta->tgg = 1;
                        rs_sta->expected_tpt = iwl3945_expected_tpt_g_prot;
                } else