ath9k: Add airtime fairness scheduler
[oweals/openwrt.git] / package / kernel / mac80211 / patches / 554-ath9k-consistently-use-get_eeprom_rev-ah.patch
1 From c763af71bcc2f01bd5ef6e65c7c34b46c7235a16 Mon Sep 17 00:00:00 2001
2 From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
3 Date: Mon, 3 Oct 2016 00:29:11 +0200
4 Subject: [v2 PATCH 5/7] ath9k: consistently use get_eeprom_rev(ah)
5
6 The AR5416_VER_MASK macro does the same as get_eeprom_rev, except that
7 one has to know the actual EEPROM type (and providing a reference to
8 that in a variable named "eep"). Additionally the eeprom_*.c
9 implementations used the same shifting logic multiple times to get the
10 eeprom revision which was also unnecessary duplication of
11 get_eeprom_rev.
12
13 Also use the AR5416_EEP_VER_MINOR_MASK macro where needed and introduce
14 a similar macro (AR5416_EEP_VER_MAJOR_MASK) for the major version.
15 Finally drop AR9287_EEP_VER_MINOR_MASK since it simply duplicates the
16 already defined AR5416_EEP_VER_MINOR_MASK.
17
18 Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
19 ---
20  drivers/net/wireless/ath/ath9k/eeprom.h      |  4 +--
21  drivers/net/wireless/ath/ath9k/eeprom_4k.c   | 32 ++++++++++------------
22  drivers/net/wireless/ath/ath9k/eeprom_9287.c | 19 +++++++------
23  drivers/net/wireless/ath/ath9k/eeprom_def.c  | 41 +++++++++++++++-------------
24  drivers/net/wireless/ath/ath9k/xmit.c        |  3 +-
25  5 files changed, 52 insertions(+), 47 deletions(-)
26
27 --- a/drivers/net/wireless/ath/ath9k/eeprom.h
28 +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
29 @@ -99,7 +99,6 @@
30  #define FBIN2FREQ(x, y)                ((y) ? (2300 + x) : (4800 + 5 * x))
31  #define ath9k_hw_use_flash(_ah)        (!(_ah->ah_flags & AH_USE_EEPROM))
32  
33 -#define AR5416_VER_MASK (eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK)
34  #define OLC_FOR_AR9280_20_LATER (AR_SREV_9280_20_OR_LATER(ah) && \
35                                  ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
36  #define OLC_FOR_AR9287_10_LATER (AR_SREV_9287_11_OR_LATER(ah) && \
37 @@ -121,6 +120,8 @@
38  
39  #define AR5416_EEP_NO_BACK_VER       0x1
40  #define AR5416_EEP_VER               0xE
41 +#define AR5416_EEP_VER_MAJOR_SHIFT   12
42 +#define AR5416_EEP_VER_MAJOR_MASK    0xF000
43  #define AR5416_EEP_VER_MINOR_MASK    0x0FFF
44  #define AR5416_EEP_MINOR_VER_2       0x2
45  #define AR5416_EEP_MINOR_VER_3       0x3
46 @@ -177,7 +178,6 @@
47  #define AR9280_TX_GAIN_TABLE_SIZE 22
48  
49  #define AR9287_EEP_VER               0xE
50 -#define AR9287_EEP_VER_MINOR_MASK    0xFFF
51  #define AR9287_EEP_MINOR_VER_1       0x1
52  #define AR9287_EEP_MINOR_VER_2       0x2
53  #define AR9287_EEP_MINOR_VER_3       0x3
54 --- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
55 +++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
56 @@ -20,12 +20,17 @@
57  
58  static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
59  {
60 -       return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
61 +       u16 version = ah->eeprom.map4k.baseEepHeader.version;
62 +
63 +       return (version & AR5416_EEP_VER_MAJOR_MASK) >>
64 +               AR5416_EEP_VER_MAJOR_SHIFT;
65  }
66  
67  static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
68  {
69 -       return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
70 +       u16 version = ah->eeprom.map4k.baseEepHeader.version;
71 +
72 +       return version & AR5416_EEP_VER_MINOR_MASK;
73  }
74  
75  #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
76 @@ -136,8 +141,8 @@ static u32 ath9k_hw_4k_dump_eeprom(struc
77                 goto out;
78         }
79  
80 -       PR_EEP("Major Version", pBase->version >> 12);
81 -       PR_EEP("Minor Version", pBase->version & 0xFFF);
82 +       PR_EEP("Major Version", ath9k_hw_4k_get_eeprom_ver(ah));
83 +       PR_EEP("Minor Version", ath9k_hw_4k_get_eeprom_rev(ah));
84         PR_EEP("Checksum", pBase->checksum);
85         PR_EEP("Length", pBase->length);
86         PR_EEP("RegDomain1", pBase->regDmn[0]);
87 @@ -314,14 +319,12 @@ static void ath9k_hw_set_4k_power_cal_ta
88  
89         xpdMask = pEepData->modalHeader.xpdGain;
90  
91 -       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
92 -           AR5416_EEP_MINOR_VER_2) {
93 +       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2)
94                 pdGainOverlap_t2 =
95                         pEepData->modalHeader.pdGainOverlap;
96 -       } else {
97 +       else
98                 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
99                                             AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
100 -       }
101  
102         pCalBChans = pEepData->calFreqPier2G;
103         numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
104 @@ -607,10 +610,8 @@ static void ath9k_hw_4k_set_txpower(stru
105  
106         memset(ratesArray, 0, sizeof(ratesArray));
107  
108 -       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
109 -           AR5416_EEP_MINOR_VER_2) {
110 +       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2)
111                 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
112 -       }
113  
114         ath9k_hw_set_4k_power_per_rate_table(ah, chan,
115                                              &ratesArray[0], cfgCtl,
116 @@ -730,8 +731,7 @@ static void ath9k_hw_4k_set_gain(struct
117                 SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF),
118                 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF);
119  
120 -       if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
121 -           AR5416_EEP_MINOR_VER_3) {
122 +       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
123                 txRxAttenLocal = pModal->txRxAttenCh[0];
124  
125                 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
126 @@ -1009,16 +1009,14 @@ static void ath9k_hw_4k_set_board_values
127         REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
128                       pModal->thresh62);
129  
130 -       if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
131 -                                               AR5416_EEP_MINOR_VER_2) {
132 +       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) {
133                 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
134                               pModal->txFrameToDataStart);
135                 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
136                               pModal->txFrameToPaOn);
137         }
138  
139 -       if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
140 -                                               AR5416_EEP_MINOR_VER_3) {
141 +       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
142                 if (IS_CHAN_HT40(chan))
143                         REG_RMW_FIELD(ah, AR_PHY_SETTLING,
144                                       AR_PHY_SETTLING_SWITCH,
145 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
146 +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
147 @@ -22,12 +22,17 @@
148  
149  static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
150  {
151 -       return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
152 +       u16 version = ah->eeprom.map9287.baseEepHeader.version;
153 +
154 +       return (version & AR5416_EEP_VER_MAJOR_MASK) >>
155 +               AR5416_EEP_VER_MAJOR_SHIFT;
156  }
157  
158  static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
159  {
160 -       return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
161 +       u16 version = ah->eeprom.map9287.baseEepHeader.version;
162 +
163 +       return version & AR5416_EEP_VER_MINOR_MASK;
164  }
165  
166  static bool __ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
167 @@ -132,8 +137,8 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
168                 goto out;
169         }
170  
171 -       PR_EEP("Major Version", pBase->version >> 12);
172 -       PR_EEP("Minor Version", pBase->version & 0xFFF);
173 +       PR_EEP("Major Version", ath9k_hw_ar9287_get_eeprom_ver(ah));
174 +       PR_EEP("Minor Version", ath9k_hw_ar9287_get_eeprom_rev(ah));
175         PR_EEP("Checksum", pBase->checksum);
176         PR_EEP("Length", pBase->length);
177         PR_EEP("RegDomain1", pBase->regDmn[0]);
178 @@ -383,8 +388,7 @@ static void ath9k_hw_set_ar9287_power_ca
179  
180         xpdMask = pEepData->modalHeader.xpdGain;
181  
182 -       if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
183 -           AR9287_EEP_MINOR_VER_2)
184 +       if (ath9k_hw_ar9287_get_eeprom_rev(ah) >= AR9287_EEP_MINOR_VER_2)
185                 pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
186         else
187                 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
188 @@ -733,8 +737,7 @@ static void ath9k_hw_ar9287_set_txpower(
189  
190         memset(ratesArray, 0, sizeof(ratesArray));
191  
192 -       if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
193 -           AR9287_EEP_MINOR_VER_2)
194 +       if (ath9k_hw_ar9287_get_eeprom_rev(ah) >= AR9287_EEP_MINOR_VER_2)
195                 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
196  
197         ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
198 --- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
199 +++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
200 @@ -79,12 +79,17 @@ static void ath9k_olc_get_pdadcs(struct
201  
202  static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
203  {
204 -       return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
205 +       u16 version = ah->eeprom.def.baseEepHeader.version;
206 +
207 +       return (version & AR5416_EEP_VER_MAJOR_MASK) >>
208 +               AR5416_EEP_VER_MAJOR_SHIFT;
209  }
210  
211  static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
212  {
213 -       return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
214 +       u16 version = ah->eeprom.def.baseEepHeader.version;
215 +
216 +       return version & AR5416_EEP_VER_MINOR_MASK;
217  }
218  
219  #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
220 @@ -214,8 +219,8 @@ static u32 ath9k_hw_def_dump_eeprom(stru
221                 goto out;
222         }
223  
224 -       PR_EEP("Major Version", pBase->version >> 12);
225 -       PR_EEP("Minor Version", pBase->version & 0xFFF);
226 +       PR_EEP("Major Version", ath9k_hw_def_get_eeprom_ver(ah));
227 +       PR_EEP("Minor Version", ath9k_hw_def_get_eeprom_rev(ah));
228         PR_EEP("Checksum", pBase->checksum);
229         PR_EEP("Length", pBase->length);
230         PR_EEP("RegDomain1", pBase->regDmn[0]);
231 @@ -391,27 +396,27 @@ static u32 ath9k_hw_def_get_eeprom(struc
232         case EEP_TXGAIN_TYPE:
233                 return pBase->txGainType;
234         case EEP_OL_PWRCTRL:
235 -               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
236 +               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19)
237                         return pBase->openLoopPwrCntl ? true : false;
238                 else
239                         return false;
240         case EEP_RC_CHAIN_MASK:
241 -               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
242 +               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19)
243                         return pBase->rcChainMask;
244                 else
245                         return 0;
246         case EEP_DAC_HPWR_5G:
247 -               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
248 +               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_20)
249                         return pBase->dacHiPwrMode_5G;
250                 else
251                         return 0;
252         case EEP_FRAC_N_5G:
253 -               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
254 +               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_22)
255                         return pBase->frac_n_5g;
256                 else
257                         return 0;
258         case EEP_PWR_TABLE_OFFSET:
259 -               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_21)
260 +               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_21)
261                         return pBase->pwr_table_offset;
262                 else
263                         return AR5416_PWR_TABLE_OFFSET_DB;
264 @@ -434,7 +439,7 @@ static void ath9k_hw_def_set_gain(struct
265                                   u8 txRxAttenLocal, int regChainOffset, int i)
266  {
267         ENABLE_REG_RMW_BUFFER(ah);
268 -       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
269 +       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
270                 txRxAttenLocal = pModal->txRxAttenCh[i];
271  
272                 if (AR_SREV_9280_20_OR_LATER(ah)) {
273 @@ -603,7 +608,7 @@ static void ath9k_hw_def_set_board_value
274                               pModal->thresh62);
275         }
276  
277 -       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
278 +       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) {
279                 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
280                               AR_PHY_TX_END_DATA_START,
281                               pModal->txFrameToDataStart);
282 @@ -611,7 +616,7 @@ static void ath9k_hw_def_set_board_value
283                               pModal->txFrameToPaOn);
284         }
285  
286 -       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
287 +       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
288                 if (IS_CHAN_HT40(chan))
289                         REG_RMW_FIELD(ah, AR_PHY_SETTLING,
290                                       AR_PHY_SETTLING_SWITCH,
291 @@ -619,13 +624,14 @@ static void ath9k_hw_def_set_board_value
292         }
293  
294         if (AR_SREV_9280_20_OR_LATER(ah) &&
295 -           AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
296 +           ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19)
297                 REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
298                               AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
299                               pModal->miscBits);
300  
301  
302 -       if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
303 +       if (AR_SREV_9280_20(ah) &&
304 +           ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_20) {
305                 if (IS_CHAN_2GHZ(chan))
306                         REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
307                                         eep->baseEepHeader.dacLpMode);
308 @@ -796,8 +802,7 @@ static void ath9k_hw_set_def_power_cal_t
309  
310         pwr_table_offset = ah->eep_ops->get_eeprom(ah, EEP_PWR_TABLE_OFFSET);
311  
312 -       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
313 -           AR5416_EEP_MINOR_VER_2) {
314 +       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) {
315                 pdGainOverlap_t2 =
316                         pEepData->modalHeader[modalIdx].pdGainOverlap;
317         } else {
318 @@ -1169,10 +1174,8 @@ static void ath9k_hw_def_set_txpower(str
319  
320         memset(ratesArray, 0, sizeof(ratesArray));
321  
322 -       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
323 -           AR5416_EEP_MINOR_VER_2) {
324 +       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2)
325                 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
326 -       }
327  
328         ath9k_hw_set_def_power_per_rate_table(ah, chan,
329                                                &ratesArray[0], cfgCtl,
330 --- a/drivers/net/wireless/ath/ath9k/xmit.c
331 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
332 @@ -1165,8 +1165,9 @@ static u8 ath_get_rate_txpower(struct at
333                 if (is_40) {
334                         u8 power_ht40delta;
335                         struct ar5416_eeprom_def *eep = &ah->eeprom.def;
336 +                       u16 eeprom_rev = ah->eep_ops->get_eeprom_rev(ah);
337  
338 -                       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
339 +                       if (eeprom_rev >= AR5416_EEP_MINOR_VER_2) {
340                                 bool is_2ghz;
341                                 struct modal_eep_header *pmodal;
342