summaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath5k/ath5k.h
diff options
context:
space:
mode:
authorBruno Randolf2010-03-25 06:49:25 +0100
committerJohn W. Linville2010-03-31 20:39:09 +0200
commitb4ea449df90684035985a77763fd1d2ff0eb9dad (patch)
tree4b156d174efda2a11ca7fba59a59617ab3b7de14 /drivers/net/wireless/ath/ath5k/ath5k.h
parentath5k: move ath5k_hw_calibration_poll to base.c (diff)
downloadkernel-qcow2-linux-b4ea449df90684035985a77763fd1d2ff0eb9dad.tar.gz
kernel-qcow2-linux-b4ea449df90684035985a77763fd1d2ff0eb9dad.tar.xz
kernel-qcow2-linux-b4ea449df90684035985a77763fd1d2ff0eb9dad.zip
ath5k: keep beacon RSSI average
Keep an exponentially weighted moving average of the beacon RSSI in our BSS. It will be used by the ANI implementation. The averaging algorithm is copied from rt2x00, Thanks :) Signed-off-by: Bruno Randolf <br1@einfach.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ath/ath5k/ath5k.h')
-rw-r--r--drivers/net/wireless/ath/ath5k/ath5k.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h
index 6334294f5f13..cefd28d5deee 100644
--- a/drivers/net/wireless/ath/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath/ath5k/ath5k.h
@@ -992,6 +992,15 @@ struct ath5k_nfcal_hist
s16 nfval[ATH5K_NF_CAL_HIST_MAX]; /* last few noise floors */
};
+/**
+ * struct avg_val - Helper structure for average calculation
+ * @avg: contains the actual average value
+ * @avg_weight: is used internally during calculation to prevent rounding errors
+ */
+struct ath5k_avg_val {
+ int avg;
+ int avg_weight;
+};
/***************************************\
HARDWARE ABSTRACTION LAYER STRUCTURE
@@ -1096,6 +1105,9 @@ 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;
+
/* noise floor from last periodic calibration */
s32 ah_noise_floor;
@@ -1305,4 +1317,27 @@ 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