mac80211: fix key flush handling in AP+STA
[oweals/openwrt.git] / package / kernel / mac80211 / patches / 330-ath9k-restart-hardware-after-noise-floor-calibration.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Sat, 18 Oct 2014 13:37:32 +0200
3 Subject: [PATCH] ath9k: restart hardware after noise floor calibration
4  failure
5
6 When NF calibration fails, the radio often becomes deaf. The usual
7 hardware hang checks do not detect this, so it's better to issue a reset
8 when that happens.
9
10 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
11 ---
12
13 --- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
14 +++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
15 @@ -657,14 +657,13 @@ static void ar9002_hw_olc_temp_compensat
16                 ar9280_hw_olc_temp_compensation(ah);
17  }
18  
19 -static bool ar9002_hw_calibrate(struct ath_hw *ah,
20 -                               struct ath9k_channel *chan,
21 -                               u8 rxchainmask,
22 -                               bool longcal)
23 +static int ar9002_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
24 +                              u8 rxchainmask, bool longcal)
25  {
26         bool iscaldone = true;
27         struct ath9k_cal_list *currCal = ah->cal_list_curr;
28         bool nfcal, nfcal_pending = false;
29 +       int ret;
30  
31         nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
32         if (ah->caldata)
33 @@ -698,7 +697,9 @@ static bool ar9002_hw_calibrate(struct a
34                          * NF is slow time-variant, so it is OK to use a
35                          * historical value.
36                          */
37 -                       ath9k_hw_loadnf(ah, ah->curchan);
38 +                       ret = ath9k_hw_loadnf(ah, ah->curchan);
39 +                       if (ret < 0)
40 +                               return ret;
41                 }
42  
43                 if (longcal) {
44 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
45 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
46 @@ -121,13 +121,12 @@ static bool ar9003_hw_per_calibration(st
47         return iscaldone;
48  }
49  
50 -static bool ar9003_hw_calibrate(struct ath_hw *ah,
51 -                               struct ath9k_channel *chan,
52 -                               u8 rxchainmask,
53 -                               bool longcal)
54 +static int ar9003_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
55 +                              u8 rxchainmask, bool longcal)
56  {
57         bool iscaldone = true;
58         struct ath9k_cal_list *currCal = ah->cal_list_curr;
59 +       int ret;
60  
61         /*
62          * For given calibration:
63 @@ -163,7 +162,9 @@ static bool ar9003_hw_calibrate(struct a
64                  * NF is slow time-variant, so it is OK to use a historical
65                  * value.
66                  */
67 -               ath9k_hw_loadnf(ah, ah->curchan);
68 +               ret = ath9k_hw_loadnf(ah, ah->curchan);
69 +               if (ret < 0)
70 +                       return ret;
71  
72                 /* start NF calibration, without updating BB NF register */
73                 ath9k_hw_start_nfcal(ah, false);
74 --- a/drivers/net/wireless/ath/ath9k/calib.c
75 +++ b/drivers/net/wireless/ath/ath9k/calib.c
76 @@ -234,7 +234,7 @@ void ath9k_hw_start_nfcal(struct ath_hw 
77         REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
78  }
79  
80 -void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
81 +int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
82  {
83         struct ath9k_nfcal_hist *h = NULL;
84         unsigned i, j;
85 @@ -301,7 +301,7 @@ void ath9k_hw_loadnf(struct ath_hw *ah, 
86                 ath_dbg(common, ANY,
87                         "Timeout while waiting for nf to load: AR_PHY_AGC_CONTROL=0x%x\n",
88                         REG_READ(ah, AR_PHY_AGC_CONTROL));
89 -               return;
90 +               return -ETIMEDOUT;
91         }
92  
93         /*
94 @@ -322,6 +322,8 @@ void ath9k_hw_loadnf(struct ath_hw *ah, 
95                 }
96         }
97         REGWRITE_BUFFER_FLUSH(ah);
98 +
99 +       return 0;
100  }
101  
102  
103 --- a/drivers/net/wireless/ath/ath9k/calib.h
104 +++ b/drivers/net/wireless/ath/ath9k/calib.h
105 @@ -109,7 +109,7 @@ struct ath9k_pacal_info{
106  
107  bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
108  void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update);
109 -void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
110 +int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
111  bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
112  void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
113                                   struct ath9k_channel *chan);
114 --- a/drivers/net/wireless/ath/ath9k/debug.c
115 +++ b/drivers/net/wireless/ath/ath9k/debug.c
116 @@ -863,6 +863,7 @@ static ssize_t read_file_reset(struct fi
117                 [RESET_TYPE_MAC_HANG] = "MAC Hang",
118                 [RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
119                 [RESET_TYPE_MCI] = "MCI Reset",
120 +               [RESET_TYPE_CALIBRATION] = "Calibration error",
121         };
122         char buf[512];
123         unsigned int len = 0;
124 --- a/drivers/net/wireless/ath/ath9k/debug.h
125 +++ b/drivers/net/wireless/ath/ath9k/debug.h
126 @@ -49,6 +49,7 @@ enum ath_reset_type {
127         RESET_TYPE_MAC_HANG,
128         RESET_TYPE_BEACON_STUCK,
129         RESET_TYPE_MCI,
130 +       RESET_TYPE_CALIBRATION,
131         __RESET_TYPE_MAX
132  };
133  
134 --- a/drivers/net/wireless/ath/ath9k/hw-ops.h
135 +++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
136 @@ -41,10 +41,9 @@ static inline void ath9k_hw_set_desc_lin
137         ath9k_hw_ops(ah)->set_desc_link(ds, link);
138  }
139  
140 -static inline bool ath9k_hw_calibrate(struct ath_hw *ah,
141 -                                     struct ath9k_channel *chan,
142 -                                     u8 rxchainmask,
143 -                                     bool longcal)
144 +static inline int ath9k_hw_calibrate(struct ath_hw *ah,
145 +                                    struct ath9k_channel *chan,
146 +                                    u8 rxchainmask, bool longcal)
147  {
148         return ath9k_hw_ops(ah)->calibrate(ah, chan, rxchainmask, longcal);
149  }
150 --- a/drivers/net/wireless/ath/ath9k/hw.h
151 +++ b/drivers/net/wireless/ath/ath9k/hw.h
152 @@ -688,10 +688,8 @@ struct ath_hw_ops {
153                                      bool power_off);
154         void (*rx_enable)(struct ath_hw *ah);
155         void (*set_desc_link)(void *ds, u32 link);
156 -       bool (*calibrate)(struct ath_hw *ah,
157 -                         struct ath9k_channel *chan,
158 -                         u8 rxchainmask,
159 -                         bool longcal);
160 +       int (*calibrate)(struct ath_hw *ah, struct ath9k_channel *chan,
161 +                        u8 rxchainmask, bool longcal);
162         bool (*get_isr)(struct ath_hw *ah, enum ath9k_int *masked,
163                         u32 *sync_cause_p);
164         void (*set_txdesc)(struct ath_hw *ah, void *ds,
165 --- a/drivers/net/wireless/ath/ath9k/link.c
166 +++ b/drivers/net/wireless/ath/ath9k/link.c
167 @@ -371,9 +371,15 @@ void ath_ani_calibrate(unsigned long dat
168  
169         /* Perform calibration if necessary */
170         if (longcal || shortcal) {
171 -               common->ani.caldone =
172 -                       ath9k_hw_calibrate(ah, ah->curchan,
173 -                                          ah->rxchainmask, longcal);
174 +               int ret = ath9k_hw_calibrate(ah, ah->curchan, ah->rxchainmask,
175 +                                            longcal);
176 +               if (ret < 0) {
177 +                       common->ani.caldone = 0;
178 +                       ath9k_queue_reset(sc, RESET_TYPE_CALIBRATION);
179 +                       return;
180 +               }
181 +
182 +               common->ani.caldone = ret;
183         }
184  
185         ath_dbg(common, ANI,