]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/mac80211/rc80211_pid_algo.c
Merge branch 'sched-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-omap-h63xx.git] / net / mac80211 / rc80211_pid_algo.c
index 9762803e48762ba6dcc5785d0a80b0dc937d8a64..a914ba73ccf56a3d828fa88a851dc44eebfd8fdb 100644 (file)
@@ -14,8 +14,8 @@
 #include <linux/skbuff.h>
 #include <linux/debugfs.h>
 #include <net/mac80211.h>
-#include "ieee80211_rate.h"
-
+#include "rate.h"
+#include "mesh.h"
 #include "rc80211_pid.h"
 
 
@@ -77,7 +77,7 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
        int cur_sorted, new_sorted, probe, tmp, n_bitrates, band;
        int cur = sta->txrate_idx;
 
-       sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+       sdata = sta->sdata;
        sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
        band = sband->band;
        n_bitrates = sband->n_bitrates;
@@ -148,6 +148,9 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
                                    struct ieee80211_local *local,
                                    struct sta_info *sta)
 {
+#ifdef CONFIG_MAC80211_MESH
+       struct ieee80211_sub_if_data *sdata = sta->sdata;
+#endif
        struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
        struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
        struct ieee80211_supported_band *sband;
@@ -178,7 +181,14 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
                pf = spinfo->last_pf;
        else {
                pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
+#ifdef CONFIG_MAC80211_MESH
+               if (pf == 100 &&
+                   sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
+                       mesh_plink_broken(sta);
+#endif
                pf <<= RC_PID_ARITH_SHIFT;
+               sta->fail_avg = ((pf + (spinfo->last_pf << 3)) / 9)
+                                       >> RC_PID_ARITH_SHIFT;
        }
 
        spinfo->tx_num_xmit = 0;
@@ -227,8 +237,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
 }
 
 static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
-                                      struct sk_buff *skb,
-                                      struct ieee80211_tx_status *status)
+                                      struct sk_buff *skb)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -238,44 +247,47 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
        struct rc_pid_sta_info *spinfo;
        unsigned long period;
        struct ieee80211_supported_band *sband;
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+
+       rcu_read_lock();
 
        sta = sta_info_get(local, hdr->addr1);
        sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
 
        if (!sta)
-               return;
+               goto unlock;
 
        /* Don't update the state if we're not controlling the rate. */
-       sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
-       if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
-               sta->txrate_idx = sdata->bss->max_ratectrl_rateidx;
-               return;
+       sdata = sta->sdata;
+       if (sdata->force_unicast_rateidx > -1) {
+               sta->txrate_idx = sdata->max_ratectrl_rateidx;
+               goto unlock;
        }
 
        /* Ignore all frames that were sent with a different rate than the rate
         * we currently advise mac80211 to use. */
-       if (status->control.tx_rate != &sband->bitrates[sta->txrate_idx])
-               goto ignore;
+       if (info->tx_rate_idx != sta->txrate_idx)
+               goto unlock;
 
        spinfo = sta->rate_ctrl_priv;
        spinfo->tx_num_xmit++;
 
 #ifdef CONFIG_MAC80211_DEBUGFS
-       rate_control_pid_event_tx_status(&spinfo->events, status);
+       rate_control_pid_event_tx_status(&spinfo->events, info);
 #endif
 
        /* We count frames that totally failed to be transmitted as two bad
         * frames, those that made it out but had some retries as one good and
         * one bad frame. */
-       if (status->excessive_retries) {
+       if (info->status.excessive_retries) {
                spinfo->tx_num_failed += 2;
                spinfo->tx_num_xmit++;
-       } else if (status->retry_count) {
+       } else if (info->status.retry_count) {
                spinfo->tx_num_failed++;
                spinfo->tx_num_xmit++;
        }
 
-       if (status->excessive_retries) {
+       if (info->status.excessive_retries) {
                sta->tx_retry_failed++;
                sta->tx_num_consecutive_failures++;
                sta->tx_num_mpdu_fail++;
@@ -283,8 +295,8 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
                sta->tx_num_consecutive_failures = 0;
                sta->tx_num_mpdu_ok++;
        }
-       sta->tx_retry_count += status->retry_count;
-       sta->tx_num_mpdu_fail += status->retry_count;
+       sta->tx_retry_count += info->status.retry_count;
+       sta->tx_num_mpdu_fail += info->status.retry_count;
 
        /* Update PID controller state. */
        period = (HZ * pinfo->sampling_period + 500) / 1000;
@@ -293,8 +305,8 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
        if (time_after(jiffies, spinfo->last_sample + period))
                rate_control_pid_sample(pinfo, local, sta);
 
-ignore:
-       sta_info_put(sta);
+ unlock:
+       rcu_read_unlock();
 }
 
 static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
@@ -309,6 +321,8 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
        int rateidx;
        u16 fc;
 
+       rcu_read_lock();
+
        sta = sta_info_get(local, hdr->addr1);
 
        /* Send management frames and broadcast/multicast data using lowest
@@ -316,16 +330,15 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
        fc = le16_to_cpu(hdr->frame_control);
        if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
            is_multicast_ether_addr(hdr->addr1) || !sta) {
-               sel->rate = rate_lowest(local, sband, sta);
-               if (sta)
-                       sta_info_put(sta);
+               sel->rate_idx = rate_lowest_index(local, sband, sta);
+               rcu_read_unlock();
                return;
        }
 
        /* If a forced rate is in effect, select it. */
        sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
-               sta->txrate_idx = sdata->bss->force_unicast_rateidx;
+       if (sdata->force_unicast_rateidx > -1)
+               sta->txrate_idx = sdata->force_unicast_rateidx;
 
        rateidx = sta->txrate_idx;
 
@@ -334,9 +347,9 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
 
        sta->last_txrate_idx = rateidx;
 
-       sta_info_put(sta);
+       rcu_read_unlock();
 
-       sel->rate = &sband->bitrates[rateidx];
+       sel->rate_idx = rateidx;
 
 #ifdef CONFIG_MAC80211_DEBUGFS
        rate_control_pid_event_tx_rate(
@@ -357,6 +370,7 @@ static void rate_control_pid_rate_init(void *priv, void *priv_sta,
 
        sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
        sta->txrate_idx = rate_lowest_index(local, sband, sta);
+       sta->fail_avg = 0;
 }
 
 static void *rate_control_pid_alloc(struct ieee80211_local *local)
@@ -384,13 +398,25 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
                return NULL;
        }
 
+       pinfo->target = RC_PID_TARGET_PF;
+       pinfo->sampling_period = RC_PID_INTERVAL;
+       pinfo->coeff_p = RC_PID_COEFF_P;
+       pinfo->coeff_i = RC_PID_COEFF_I;
+       pinfo->coeff_d = RC_PID_COEFF_D;
+       pinfo->smoothing_shift = RC_PID_SMOOTHING_SHIFT;
+       pinfo->sharpen_factor = RC_PID_SHARPENING_FACTOR;
+       pinfo->sharpen_duration = RC_PID_SHARPENING_DURATION;
+       pinfo->norm_offset = RC_PID_NORM_OFFSET;
+       pinfo->rinfo = rinfo;
+       pinfo->oldrate = 0;
+
        /* Sort the rates. This is optimized for the most common case (i.e.
         * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed
         * mapping too. */
        for (i = 0; i < sband->n_bitrates; i++) {
                rinfo[i].index = i;
                rinfo[i].rev_index = i;
-               if (pinfo->fast_start)
+               if (RC_PID_FAST_START)
                        rinfo[i].diff = 0;
                else
                        rinfo[i].diff = i * pinfo->norm_offset;
@@ -411,19 +437,6 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
                        break;
        }
 
-       pinfo->target = RC_PID_TARGET_PF;
-       pinfo->sampling_period = RC_PID_INTERVAL;
-       pinfo->coeff_p = RC_PID_COEFF_P;
-       pinfo->coeff_i = RC_PID_COEFF_I;
-       pinfo->coeff_d = RC_PID_COEFF_D;
-       pinfo->smoothing_shift = RC_PID_SMOOTHING_SHIFT;
-       pinfo->sharpen_factor = RC_PID_SHARPENING_FACTOR;
-       pinfo->sharpen_duration = RC_PID_SHARPENING_DURATION;
-       pinfo->norm_offset = RC_PID_NORM_OFFSET;
-       pinfo->fast_start = RC_PID_FAST_START;
-       pinfo->rinfo = rinfo;
-       pinfo->oldrate = 0;
-
 #ifdef CONFIG_MAC80211_DEBUGFS
        de = &pinfo->dentries;
        de->dir = debugfs_create_dir("rc80211_pid",
@@ -451,9 +464,6 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
        de->norm_offset = debugfs_create_u32("norm_offset",
                                             S_IRUSR | S_IWUSR, de->dir,
                                             &pinfo->norm_offset);
-       de->fast_start = debugfs_create_bool("fast_start",
-                                            S_IRUSR | S_IWUSR, de->dir,
-                                            &pinfo->fast_start);
 #endif
 
        return pinfo;
@@ -465,7 +475,6 @@ static void rate_control_pid_free(void *priv)
 #ifdef CONFIG_MAC80211_DEBUGFS
        struct rc_pid_debugfs_entries *de = &pinfo->dentries;
 
-       debugfs_remove(de->fast_start);
        debugfs_remove(de->norm_offset);
        debugfs_remove(de->sharpen_duration);
        debugfs_remove(de->sharpen_factor);
@@ -526,11 +535,6 @@ static struct rate_control_ops mac80211_rcpid = {
 #endif
 };
 
-MODULE_DESCRIPTION("PID controller based rate control algorithm");
-MODULE_AUTHOR("Stefano Brivio");
-MODULE_AUTHOR("Mattias Nissler");
-MODULE_LICENSE("GPL");
-
 int __init rc80211_pid_init(void)
 {
        return ieee80211_rate_control_register(&mac80211_rcpid);
@@ -540,8 +544,3 @@ void rc80211_pid_exit(void)
 {
        ieee80211_rate_control_unregister(&mac80211_rcpid);
 }
-
-#ifdef CONFIG_MAC80211_RC_PID_MODULE
-module_init(rc80211_pid_init);
-module_exit(rc80211_pid_exit);
-#endif