ath9k: implement extended channel utilization statistics via survey
[lede.git] / package / mac80211 / patches / 520-ath9k_common_clockrate.patch
1 --- a/drivers/net/wireless/ath/ath.h
2 +++ b/drivers/net/wireless/ath/ath.h
3 @@ -145,6 +145,8 @@ struct ath_common {
4         DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
5         enum ath_crypt_caps crypt_caps;
6  
7 +       unsigned int clockrate;
8 +
9         struct ath_regulatory regulatory;
10         const struct ath_ops *ops;
11         const struct ath_bus_ops *bus_ops;
12 --- a/drivers/net/wireless/ath/ath9k/hw.c
13 +++ b/drivers/net/wireless/ath/ath9k/hw.c
14 @@ -91,29 +91,32 @@ static void ath9k_hw_ani_cache_ini_regs(
15  /* Helper Functions */
16  /********************/
17  
18 -static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
19 +static void ath9k_hw_set_clockrate(struct ath_hw *ah)
20  {
21         struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
22 +       struct ath_common *common = ath9k_hw_common(ah);
23 +       unsigned int clockrate;
24  
25         if (!ah->curchan) /* should really check for CCK instead */
26 -               return usecs *ATH9K_CLOCK_RATE_CCK;
27 -       if (conf->channel->band == IEEE80211_BAND_2GHZ)
28 -               return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
29 -
30 -       if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
31 -               return usecs * ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
32 +               clockrate = ATH9K_CLOCK_RATE_CCK;
33 +       else if (conf->channel->band == IEEE80211_BAND_2GHZ)
34 +               clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
35 +       else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
36 +               clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
37         else
38 -               return usecs * ATH9K_CLOCK_RATE_5GHZ_OFDM;
39 +               clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
40 +
41 +       if (conf_is_ht40(conf))
42 +               clockrate *= 2;
43 +
44 +       common->clockrate = clockrate;
45  }
46  
47  static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
48  {
49 -       struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
50 +       struct ath_common *common = ath9k_hw_common(ah);
51  
52 -       if (conf_is_ht40(conf))
53 -               return ath9k_hw_mac_clks(ah, usecs) * 2;
54 -       else
55 -               return ath9k_hw_mac_clks(ah, usecs);
56 +       return usecs * common->clockrate;
57  }
58  
59  bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
60 @@ -1168,6 +1171,7 @@ static bool ath9k_hw_channel_change(stru
61                           "Failed to set channel\n");
62                 return false;
63         }
64 +       ath9k_hw_set_clockrate(ah);
65  
66         ah->eep_ops->set_txpower(ah, chan,
67                              ath9k_regd_get_ctl(regulatory, chan),
68 @@ -1380,6 +1384,8 @@ int ath9k_hw_reset(struct ath_hw *ah, st
69         if (r)
70                 return r;
71  
72 +       ath9k_hw_set_clockrate(ah);
73 +
74         ENABLE_REGWRITE_BUFFER(ah);
75  
76         for (i = 0; i < AR_NUM_DCU; i++)
77 --- a/drivers/net/wireless/ath/ath9k/ani.c
78 +++ b/drivers/net/wireless/ath/ath9k/ani.c
79 @@ -465,35 +465,13 @@ static void ath9k_hw_ani_lower_immunity(
80                 ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1);
81  }
82  
83 -static u8 ath9k_hw_chan_2_clockrate_mhz(struct ath_hw *ah)
84 -{
85 -       struct ath9k_channel *chan = ah->curchan;
86 -       struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
87 -       u8 clockrate; /* in MHz */
88 -
89 -       if (!ah->curchan) /* should really check for CCK instead */
90 -               clockrate = ATH9K_CLOCK_RATE_CCK;
91 -       else if (conf->channel->band == IEEE80211_BAND_2GHZ)
92 -               clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
93 -       else if (IS_CHAN_A_FAST_CLOCK(ah, chan))
94 -               clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
95 -       else
96 -               clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
97 -
98 -       if (conf_is_ht40(conf))
99 -               return clockrate * 2;
100 -
101 -       return clockrate;
102 -}
103 -
104  static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
105  {
106 +       struct ath_common *common = ath9k_hw_common(ah);
107         int32_t listen_time;
108 -       int32_t clock_rate;
109  
110         ath9k_hw_update_cycle_counters(ah);
111 -       clock_rate = ath9k_hw_chan_2_clockrate_mhz(ah) * 1000;
112 -       listen_time = ah->listen_time / clock_rate;
113 +       listen_time = ah->listen_time / (common->clockrate * 1000);
114         ah->listen_time = 0;
115  
116         return listen_time;