ath9k: add a new fix for signal strength / noise measurements (backport of r26798)
[openwrt-10.03/.git] / package / mac80211 / patches / 570-ath9k_noise_dbm_fixup.patch
1 --- a/drivers/net/wireless/ath/ath9k/calib.c
2 +++ b/drivers/net/wireless/ath/ath9k/calib.c
3 @@ -365,6 +365,7 @@ bool ath9k_hw_getnf(struct ath_hw *ah, s
4  
5         if (!caldata) {
6                 chan->noisefloor = nf;
7 +               ah->noise = ath9k_hw_getchan_noise(ah, chan);
8                 return false;
9         }
10  
11 @@ -372,6 +373,7 @@ bool ath9k_hw_getnf(struct ath_hw *ah, s
12         caldata->nfcal_pending = false;
13         ath9k_hw_update_nfcal_hist_buffer(ah, caldata, nfarray);
14         chan->noisefloor = h[0].privNF;
15 +       ah->noise = ath9k_hw_getchan_noise(ah, chan);
16         return true;
17  }
18  
19 @@ -398,10 +400,15 @@ void ath9k_init_nfcal_hist_buffer(struct
20  
21  s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan)
22  {
23 -       if (!ah->curchan || !ah->curchan->noisefloor)
24 -               return ath9k_hw_get_default_nf(ah, chan);
25 +       s8 noise = ATH_DEFAULT_NOISE_FLOOR;
26  
27 -       return ah->curchan->noisefloor;
28 +       if (chan && chan->noisefloor) {
29 +               s8 delta = chan->noisefloor -
30 +                          ath9k_hw_get_default_nf(ah, chan);
31 +               if (delta > 0)
32 +                       noise += delta;
33 +       }
34 +       return noise;
35  }
36  EXPORT_SYMBOL(ath9k_hw_getchan_noise);
37  
38 --- a/drivers/net/wireless/ath/ath9k/hw.c
39 +++ b/drivers/net/wireless/ath/ath9k/hw.c
40 @@ -1286,6 +1286,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st
41                 memset(caldata, 0, sizeof(*caldata));
42                 ath9k_init_nfcal_hist_buffer(ah, chan);
43         }
44 +       ah->noise = ath9k_hw_getchan_noise(ah, chan);
45  
46         if (bChannelChange &&
47             (ah->chip_fullsleep != true) &&
48 --- a/drivers/net/wireless/ath/ath9k/hw.h
49 +++ b/drivers/net/wireless/ath/ath9k/hw.h
50 @@ -677,6 +677,7 @@ struct ath_hw {
51         enum nl80211_iftype opmode;
52         enum ath9k_power_mode power_mode;
53  
54 +       s8 noise;
55         struct ath9k_hw_cal_data *caldata;
56         struct ath9k_pacal_info pacal_info;
57         struct ar5416Stats stats;
58 --- a/drivers/net/wireless/ath/ath9k/main.c
59 +++ b/drivers/net/wireless/ath/ath9k/main.c
60 @@ -165,7 +165,7 @@ static void ath_update_survey_nf(struct 
61  
62         if (chan->noisefloor) {
63                 survey->filled |= SURVEY_INFO_NOISE_DBM;
64 -               survey->noise = chan->noisefloor;
65 +               survey->noise = ath9k_hw_getchan_noise(ah, chan);
66         }
67  }
68  
69 --- a/drivers/net/wireless/ath/ath9k/recv.c
70 +++ b/drivers/net/wireless/ath/ath9k/recv.c
71 @@ -956,6 +956,8 @@ static int ath9k_rx_skb_preprocess(struc
72                                    struct ieee80211_rx_status *rx_status,
73                                    bool *decrypt_error)
74  {
75 +       struct ath_hw *ah = common->ah;
76 +
77         memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
78  
79         /*
80 @@ -976,7 +978,7 @@ static int ath9k_rx_skb_preprocess(struc
81  
82         rx_status->band = hw->conf.channel->band;
83         rx_status->freq = hw->conf.channel->center_freq;
84 -       rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
85 +       rx_status->signal = ah->noise + rx_stats->rs_rssi;
86         rx_status->antenna = rx_stats->rs_antenna;
87         rx_status->flag |= RX_FLAG_MACTIME_MPDU;
88