ath5k: Use generic EWMA library
authorBruno Randolf <br1@einfach.org>
Tue, 16 Nov 2010 01:58:43 +0000 (10:58 +0900)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 18 Nov 2010 19:22:19 +0000 (14:22 -0500)
Remove ath5k's private moving average implementation in favour of the generic
library version.

Signed-off-by: Bruno Randolf <br1@einfach.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath5k/Kconfig
drivers/net/wireless/ath/ath5k/ani.c
drivers/net/wireless/ath/ath5k/ath5k.h
drivers/net/wireless/ath/ath5k/base.c
drivers/net/wireless/ath/ath5k/debug.c

index eb83b7b4d0e3c96339b114166c26adbc5a164c11..47844575caa3e2426e0a64bc2583179477accea7 100644 (file)
@@ -4,6 +4,7 @@ config ATH5K
        select MAC80211_LEDS
        select LEDS_CLASS
        select NEW_LEDS
+       select AVERAGE
        ---help---
          This module adds support for wireless adapters based on
          Atheros 5xxx chipset.
index f1419198a479511f995b9e290b2316b0181bd677..db98a853ff35c0600d7adc8296b40796cd17e6c5 100644 (file)
@@ -216,7 +216,7 @@ static void
 ath5k_ani_raise_immunity(struct ath5k_hw *ah, struct ath5k_ani_state *as,
                         bool ofdm_trigger)
 {
-       int rssi = ah->ah_beacon_rssi_avg.avg;
+       int rssi = ewma_read(&ah->ah_beacon_rssi_avg);
 
        ATH5K_DBG_UNLIMIT(ah->ah_sc, ATH5K_DEBUG_ANI, "raise immunity (%s)",
                ofdm_trigger ? "ODFM" : "CCK");
@@ -301,7 +301,7 @@ ath5k_ani_raise_immunity(struct ath5k_hw *ah, struct ath5k_ani_state *as,
 static void
 ath5k_ani_lower_immunity(struct ath5k_hw *ah, struct ath5k_ani_state *as)
 {
-       int rssi = ah->ah_beacon_rssi_avg.avg;
+       int rssi = ewma_read(&ah->ah_beacon_rssi_avg);
 
        ATH5K_DBG_UNLIMIT(ah->ah_sc, ATH5K_DEBUG_ANI, "lower immunity");
 
index 308b79e1ff0887a6c70e9c43ec0963c3b80b09ba..2718136e488610f00095d4a0e7c47f2de0d4d701 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <linux/io.h>
 #include <linux/types.h>
+#include <linux/average.h>
 #include <net/mac80211.h>
 
 /* RX/TX descriptor hw structs
@@ -1102,7 +1103,7 @@ struct ath5k_hw {
        struct ath5k_nfcal_hist ah_nfcal_hist;
 
        /* average beacon RSSI in our BSS (used by ANI) */
-       struct ath5k_avg_val    ah_beacon_rssi_avg;
+       struct ewma             ah_beacon_rssi_avg;
 
        /* noise floor from last periodic calibration */
        s32                     ah_noise_floor;
@@ -1315,27 +1316,4 @@ static inline u32 ath5k_hw_bitswap(u32 val, unsigned int bits)
        return retval;
 }
 
-#define AVG_SAMPLES    8
-#define AVG_FACTOR     1000
-
-/**
- * ath5k_moving_average -  Exponentially weighted moving average
- * @avg: average structure
- * @val: current value
- *
- * This implementation make use of a struct ath5k_avg_val to prevent rounding
- * errors.
- */
-static inline struct ath5k_avg_val
-ath5k_moving_average(const struct ath5k_avg_val avg, const int val)
-{
-       struct ath5k_avg_val new;
-       new.avg_weight = avg.avg_weight  ?
-               (((avg.avg_weight * ((AVG_SAMPLES) - 1)) +
-                       (val * (AVG_FACTOR))) / (AVG_SAMPLES)) :
-               (val * (AVG_FACTOR));
-       new.avg = new.avg_weight / (AVG_FACTOR);
-       return new;
-}
-
 #endif
index 13735cc899a53c2d1a9ac610966c3e21700c2461..7f783d9462aa2049afb125832b34a269fc2897e1 100644 (file)
@@ -1301,8 +1301,7 @@ ath5k_update_beacon_rssi(struct ath5k_softc *sc, struct sk_buff *skb, int rssi)
            memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) != 0)
                return;
 
-       ah->ah_beacon_rssi_avg = ath5k_moving_average(ah->ah_beacon_rssi_avg,
-                                                     rssi);
+       ewma_add(&ah->ah_beacon_rssi_avg, rssi);
 
        /* in IBSS mode we should keep RSSI statistics per neighbour */
        /* le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS */
@@ -2556,6 +2555,7 @@ ath5k_reset(struct ath5k_softc *sc, struct ieee80211_channel *chan)
        ah->ah_cal_next_full = jiffies;
        ah->ah_cal_next_ani = jiffies;
        ah->ah_cal_next_nf = jiffies;
+       ewma_init(&ah->ah_beacon_rssi_avg, 1000, 8);
 
        /*
         * Change channels and update the h/w rate map if we're switching;
index 54dcf77e96466ead8a8abde7ab3b0bbc0e083acf..7d785cb60ce0a02a426f065a97f42c2fbdf2f101 100644 (file)
@@ -719,7 +719,7 @@ static ssize_t read_file_ani(struct file *file, char __user *user_buf,
                        st->mib_intr);
        len += snprintf(buf+len, sizeof(buf)-len,
                        "beacon RSSI average:\t%d\n",
-                       sc->ah->ah_beacon_rssi_avg.avg);
+                       (int)ewma_read(&sc->ah->ah_beacon_rssi_avg));
 
 #define CC_PRINT(_struct, _field) \
        _struct._field, \