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
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
10 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
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);
19 -static bool ar9002_hw_calibrate(struct ath_hw *ah,
20 - struct ath9k_channel *chan,
23 +static int ar9002_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
24 + u8 rxchainmask, bool longcal)
26 bool iscaldone = true;
27 struct ath9k_cal_list *currCal = ah->cal_list_curr;
28 bool nfcal, nfcal_pending = false;
31 nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
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
37 - ath9k_hw_loadnf(ah, ah->curchan);
38 + ret = ath9k_hw_loadnf(ah, ah->curchan);
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
50 -static bool ar9003_hw_calibrate(struct ath_hw *ah,
51 - struct ath9k_channel *chan,
54 +static int ar9003_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
55 + u8 rxchainmask, bool longcal)
57 bool iscaldone = true;
58 struct ath9k_cal_list *currCal = ah->cal_list_curr;
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
67 - ath9k_hw_loadnf(ah, ah->curchan);
68 + ret = ath9k_hw_loadnf(ah, ah->curchan);
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);
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)
83 struct ath9k_nfcal_hist *h = NULL;
85 @@ -301,7 +301,7 @@ void ath9k_hw_loadnf(struct ath_hw *ah,
87 "Timeout while waiting for nf to load: AR_PHY_AGC_CONTROL=0x%x\n",
88 REG_READ(ah, AR_PHY_AGC_CONTROL));
94 @@ -322,6 +322,8 @@ void ath9k_hw_loadnf(struct ath_hw *ah,
97 REGWRITE_BUFFER_FLUSH(ah);
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{
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",
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 {
128 RESET_TYPE_BEACON_STUCK,
130 + RESET_TYPE_CALIBRATION,
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);
140 -static inline bool ath9k_hw_calibrate(struct ath_hw *ah,
141 - struct ath9k_channel *chan,
144 +static inline int ath9k_hw_calibrate(struct ath_hw *ah,
145 + struct ath9k_channel *chan,
146 + u8 rxchainmask, bool longcal)
148 return ath9k_hw_ops(ah)->calibrate(ah, chan, rxchainmask, longcal);
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 {
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,
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,
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
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,
177 + common->ani.caldone = 0;
178 + ath9k_queue_reset(sc, RESET_TYPE_CALIBRATION);
182 + common->ani.caldone = ret;