ath9k_hw: fix clock rate calculations for ANI
authorLuis R. Rodriguez <lrodriguez@atheros.com>
Sat, 12 Jun 2010 04:33:40 +0000 (00:33 -0400)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 14 Jun 2010 19:39:29 +0000 (15:39 -0400)
The clock rate was assumed to be static but it actually
changes depending on the mode of operation, correct this
to help improve the calcuation of the listenTime for ANI.
This change will help adjust ANI more accurately on different
PHY thresholds.

Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath9k/ani.c

index 3da820ffc65eefbaee5023fd3408011948be0541..e879055c058f3fda7a0b5243f9d9e9aee4f09528 100644 (file)
@@ -259,6 +259,27 @@ static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
        }
 }
 
+static u8 ath9k_hw_chan_2_clockrate_mhz(struct ath_hw *ah)
+{
+       struct ath9k_channel *chan = ah->curchan;
+       struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
+       u8 clockrate; /* in MHz */
+
+       if (!ah->curchan) /* should really check for CCK instead */
+               clockrate = ATH9K_CLOCK_RATE_CCK;
+       else if (conf->channel->band == IEEE80211_BAND_2GHZ)
+               clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
+       else if (IS_CHAN_A_FAST_CLOCK(ah, chan))
+               clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
+       else
+               clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
+
+       if (conf_is_ht40(conf))
+               return clockrate * 2;
+
+       return clockrate * 2;
+}
+
 static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
 {
        struct ar5416AniState *aniState;
@@ -278,7 +299,15 @@ static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
                int32_t ccdelta = cycleCount - aniState->cycleCount;
                int32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
                int32_t tfdelta = txFrameCount - aniState->txFrameCount;
-               listenTime = (ccdelta - rfdelta - tfdelta) / 44000;
+               int32_t clock_rate = ath9k_hw_chan_2_clockrate_mhz(ah) * 1000;;
+
+               /*
+                * convert HW counter values to ms using mode
+                * specifix clock rate
+                */
+               clock_rate = ath9k_hw_chan_2_clockrate_mhz(ah) * 1000;;
+
+               listenTime = (ccdelta - rfdelta - tfdelta) / clock_rate;
        }
        aniState->cycleCount = cycleCount;
        aniState->txFrameCount = txFrameCount;