04714f81692ce07b5c1f2e91190b64184b6c4068
[openwrt/staging/yousong.git] / package / kernel / mac80211 / patches / 556-ath9k-define-all-EEPROM-fields-in-Little-Endian-form.patch
1 From 7e1047f3cf8dcdb4825f3c785f7f708d07508096 Mon Sep 17 00:00:00 2001
2 From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
3 Date: Mon, 3 Oct 2016 00:29:13 +0200
4 Subject: [v2 PATCH 7/7] ath9k: define all EEPROM fields in Little Endian format
5
6 The ar9300_eeprom logic is already using only 8-bit (endian neutral),
7 __le16 and __le32 fields to state explicitly how the values should be
8 interpreted.
9 All other EEPROM implementations (4k, 9287 and def) were using u16 and
10 u32 fields with additional logic to swap the values (read from the
11 original EEPROM) so they match the current CPUs endianness.
12
13 The EEPROM format defaults to "all values are Little Endian", indicated
14 by the absence of the AR5416_EEPMISC_BIG_ENDIAN in the u8 EEPMISC
15 register. If we detect that the EEPROM indicates Big Endian mode
16 (AR5416_EEPMISC_BIG_ENDIAN is set in the EEPMISC register) then we'll
17 swap the values to convert them into Little Endian. This is done by
18 activating the EEPMISC based logic in ath9k_hw_nvram_swap_data even if
19 AH_NO_EEP_SWAP is set (this makes ath9k behave like the FreeBSD driver,
20 which also does not have a flag to enable swapping based on the
21 AR5416_EEPMISC_BIG_ENDIAN bit). Before this logic was only used to
22 enable swapping when "current CPU endianness != EEPROM endianness".
23
24 After changing all relevant fields to __le16 and __le32 sparse was used
25 to check that all code which reads any of these fields uses
26 le{16,32}_to_cpu.
27
28 Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
29 ---
30 drivers/net/wireless/ath/ath9k/eeprom.c | 27 ++-----
31 drivers/net/wireless/ath/ath9k/eeprom.h | 75 ++++++++++--------
32 drivers/net/wireless/ath/ath9k/eeprom_4k.c | 94 +++++++++-------------
33 drivers/net/wireless/ath/ath9k/eeprom_9287.c | 98 ++++++++++-------------
34 drivers/net/wireless/ath/ath9k/eeprom_def.c | 114 ++++++++++++---------------
35 5 files changed, 174 insertions(+), 234 deletions(-)
36
37 --- a/drivers/net/wireless/ath/ath9k/eeprom.c
38 +++ b/drivers/net/wireless/ath/ath9k/eeprom.c
39 @@ -155,17 +155,10 @@ bool ath9k_hw_nvram_read(struct ath_hw *
40 return ret;
41 }
42
43 -#ifdef __BIG_ENDIAN
44 -#define EXPECTED_EEPMISC_ENDIAN AR5416_EEPMISC_BIG_ENDIAN
45 -#else
46 -#define EXPECTED_EEPMISC_ENDIAN 0
47 -#endif
48 -
49 int ath9k_hw_nvram_swap_data(struct ath_hw *ah, bool *swap_needed, int size)
50 {
51 u16 magic;
52 u16 *eepdata;
53 - u8 eepmisc;
54 int i;
55 bool needs_byteswap = false;
56 struct ath_common *common = ath9k_hw_common(ah);
57 @@ -203,25 +196,17 @@ int ath9k_hw_nvram_swap_data(struct ath_
58 }
59 }
60
61 - *swap_needed = false;
62 -
63 - eepmisc = ah->eep_ops->get_eepmisc(ah);
64 - if ((eepmisc & AR5416_EEPMISC_BIG_ENDIAN) != EXPECTED_EEPMISC_ENDIAN) {
65 - if (ah->ah_flags & AH_NO_EEP_SWAP) {
66 - ath_info(common,
67 - "Ignoring endianness difference in eepmisc register.\n");
68 - } else {
69 - *swap_needed = true;
70 - ath_dbg(common, EEPROM,
71 - "EEPROM needs swapping according to the eepmisc register.\n");
72 - }
73 + if (ah->eep_ops->get_eepmisc(ah) & AR5416_EEPMISC_BIG_ENDIAN) {
74 + *swap_needed = true;
75 + ath_dbg(common, EEPROM,
76 + "Big Endian EEPROM detected according to EEPMISC register.\n");
77 + } else {
78 + *swap_needed = false;
79 }
80
81 return 0;
82 }
83
84 -#undef EXPECTED_EEPMISC_VAL
85 -
86 bool ath9k_hw_nvram_validate_checksum(struct ath_hw *ah, int size)
87 {
88 u32 i, sum = 0;
89 --- a/drivers/net/wireless/ath/ath9k/eeprom.h
90 +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
91 @@ -23,6 +23,17 @@
92 #include <net/cfg80211.h>
93 #include "ar9003_eeprom.h"
94
95 +/* helpers to swap EEPROM fields, which are stored as __le16 or __le32. Since
96 + * we are 100% sure about it we __force these to u16/u32 for the swab calls to
97 + * silence the sparse checks. These macros are used when we have a Big Endian
98 + * EEPROM (according to AR5416_EEPMISC_BIG_ENDIAN) and need to convert the
99 + * fields to __le16/__le32.
100 + */
101 +#define EEPROM_FIELD_SWAB16(field) \
102 + (field = (__force __le16)swab16((__force u16)field))
103 +#define EEPROM_FIELD_SWAB32(field) \
104 + (field = (__force __le32)swab32((__force u32)field))
105 +
106 #ifdef __BIG_ENDIAN
107 #define AR5416_EEPROM_MAGIC 0x5aa5
108 #else
109 @@ -270,19 +281,19 @@ enum ath9k_hal_freq_band {
110 };
111
112 struct base_eep_header {
113 - u16 length;
114 - u16 checksum;
115 - u16 version;
116 + __le16 length;
117 + __le16 checksum;
118 + __le16 version;
119 u8 opCapFlags;
120 u8 eepMisc;
121 - u16 regDmn[2];
122 + __le16 regDmn[2];
123 u8 macAddr[6];
124 u8 rxMask;
125 u8 txMask;
126 - u16 rfSilent;
127 - u16 blueToothOptions;
128 - u16 deviceCap;
129 - u32 binBuildNumber;
130 + __le16 rfSilent;
131 + __le16 blueToothOptions;
132 + __le16 deviceCap;
133 + __le32 binBuildNumber;
134 u8 deviceType;
135 u8 pwdclkind;
136 u8 fastClk5g;
137 @@ -300,33 +311,33 @@ struct base_eep_header {
138 } __packed;
139
140 struct base_eep_header_4k {
141 - u16 length;
142 - u16 checksum;
143 - u16 version;
144 + __le16 length;
145 + __le16 checksum;
146 + __le16 version;
147 u8 opCapFlags;
148 u8 eepMisc;
149 - u16 regDmn[2];
150 + __le16 regDmn[2];
151 u8 macAddr[6];
152 u8 rxMask;
153 u8 txMask;
154 - u16 rfSilent;
155 - u16 blueToothOptions;
156 - u16 deviceCap;
157 - u32 binBuildNumber;
158 + __le16 rfSilent;
159 + __le16 blueToothOptions;
160 + __le16 deviceCap;
161 + __le32 binBuildNumber;
162 u8 deviceType;
163 u8 txGainType;
164 } __packed;
165
166
167 struct spur_chan {
168 - u16 spurChan;
169 + __le16 spurChan;
170 u8 spurRangeLow;
171 u8 spurRangeHigh;
172 } __packed;
173
174 struct modal_eep_header {
175 - u32 antCtrlChain[AR5416_MAX_CHAINS];
176 - u32 antCtrlCommon;
177 + __le32 antCtrlChain[AR5416_MAX_CHAINS];
178 + __le32 antCtrlCommon;
179 u8 antennaGainCh[AR5416_MAX_CHAINS];
180 u8 switchSettling;
181 u8 txRxAttenCh[AR5416_MAX_CHAINS];
182 @@ -361,7 +372,7 @@ struct modal_eep_header {
183 u8 db_ch1;
184 u8 lna_ctl;
185 u8 miscBits;
186 - u16 xpaBiasLvlFreq[3];
187 + __le16 xpaBiasLvlFreq[3];
188 u8 futureModal[6];
189
190 struct spur_chan spurChans[AR_EEPROM_MODAL_SPURS];
191 @@ -375,8 +386,8 @@ struct calDataPerFreqOpLoop {
192 } __packed;
193
194 struct modal_eep_4k_header {
195 - u32 antCtrlChain[AR5416_EEP4K_MAX_CHAINS];
196 - u32 antCtrlCommon;
197 + __le32 antCtrlChain[AR5416_EEP4K_MAX_CHAINS];
198 + __le32 antCtrlCommon;
199 u8 antennaGainCh[AR5416_EEP4K_MAX_CHAINS];
200 u8 switchSettling;
201 u8 txRxAttenCh[AR5416_EEP4K_MAX_CHAINS];
202 @@ -440,19 +451,19 @@ struct modal_eep_4k_header {
203 } __packed;
204
205 struct base_eep_ar9287_header {
206 - u16 length;
207 - u16 checksum;
208 - u16 version;
209 + __le16 length;
210 + __le16 checksum;
211 + __le16 version;
212 u8 opCapFlags;
213 u8 eepMisc;
214 - u16 regDmn[2];
215 + __le16 regDmn[2];
216 u8 macAddr[6];
217 u8 rxMask;
218 u8 txMask;
219 - u16 rfSilent;
220 - u16 blueToothOptions;
221 - u16 deviceCap;
222 - u32 binBuildNumber;
223 + __le16 rfSilent;
224 + __le16 blueToothOptions;
225 + __le16 deviceCap;
226 + __le32 binBuildNumber;
227 u8 deviceType;
228 u8 openLoopPwrCntl;
229 int8_t pwrTableOffset;
230 @@ -462,8 +473,8 @@ struct base_eep_ar9287_header {
231 } __packed;
232
233 struct modal_eep_ar9287_header {
234 - u32 antCtrlChain[AR9287_MAX_CHAINS];
235 - u32 antCtrlCommon;
236 + __le32 antCtrlChain[AR9287_MAX_CHAINS];
237 + __le32 antCtrlCommon;
238 int8_t antennaGainCh[AR9287_MAX_CHAINS];
239 u8 switchSettling;
240 u8 txRxAttenCh[AR9287_MAX_CHAINS];
241 --- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
242 +++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
243 @@ -20,7 +20,7 @@
244
245 static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
246 {
247 - u16 version = ah->eeprom.map4k.baseEepHeader.version;
248 + u16 version = le16_to_cpu(ah->eeprom.map4k.baseEepHeader.version);
249
250 return (version & AR5416_EEP_VER_MAJOR_MASK) >>
251 AR5416_EEP_VER_MAJOR_SHIFT;
252 @@ -28,7 +28,7 @@ static int ath9k_hw_4k_get_eeprom_ver(st
253
254 static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
255 {
256 - u16 version = ah->eeprom.map4k.baseEepHeader.version;
257 + u16 version = le16_to_cpu(ah->eeprom.map4k.baseEepHeader.version);
258
259 return version & AR5416_EEP_VER_MINOR_MASK;
260 }
261 @@ -76,8 +76,8 @@ static bool ath9k_hw_4k_fill_eeprom(stru
262 static u32 ath9k_dump_4k_modal_eeprom(char *buf, u32 len, u32 size,
263 struct modal_eep_4k_header *modal_hdr)
264 {
265 - PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
266 - PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
267 + PR_EEP("Chain0 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[0]));
268 + PR_EEP("Ant. Common Control", le32_to_cpu(modal_hdr->antCtrlCommon));
269 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
270 PR_EEP("Switch Settle", modal_hdr->switchSettling);
271 PR_EEP("Chain0 TxRxAtten", modal_hdr->txRxAttenCh[0]);
272 @@ -132,6 +132,7 @@ static u32 ath9k_hw_4k_dump_eeprom(struc
273 {
274 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
275 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
276 + u32 binBuildNumber = le32_to_cpu(pBase->binBuildNumber);
277
278 if (!dump_base_hdr) {
279 len += scnprintf(buf + len, size - len,
280 @@ -143,10 +144,10 @@ static u32 ath9k_hw_4k_dump_eeprom(struc
281
282 PR_EEP("Major Version", ath9k_hw_4k_get_eeprom_ver(ah));
283 PR_EEP("Minor Version", ath9k_hw_4k_get_eeprom_rev(ah));
284 - PR_EEP("Checksum", pBase->checksum);
285 - PR_EEP("Length", pBase->length);
286 - PR_EEP("RegDomain1", pBase->regDmn[0]);
287 - PR_EEP("RegDomain2", pBase->regDmn[1]);
288 + PR_EEP("Checksum", le16_to_cpu(pBase->checksum));
289 + PR_EEP("Length", le16_to_cpu(pBase->length));
290 + PR_EEP("RegDomain1", le16_to_cpu(pBase->regDmn[0]));
291 + PR_EEP("RegDomain2", le16_to_cpu(pBase->regDmn[1]));
292 PR_EEP("TX Mask", pBase->txMask);
293 PR_EEP("RX Mask", pBase->rxMask);
294 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
295 @@ -160,9 +161,9 @@ static u32 ath9k_hw_4k_dump_eeprom(struc
296 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
297 AR5416_OPFLAGS_N_5G_HT40));
298 PR_EEP("Big Endian", !!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN));
299 - PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
300 - PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
301 - PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
302 + PR_EEP("Cal Bin Major Ver", (binBuildNumber >> 24) & 0xFF);
303 + PR_EEP("Cal Bin Minor Ver", (binBuildNumber >> 16) & 0xFF);
304 + PR_EEP("Cal Bin Build", (binBuildNumber >> 8) & 0xFF);
305 PR_EEP("TX Gain type", pBase->txGainType);
306
307 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
308 @@ -194,54 +195,31 @@ static int ath9k_hw_4k_check_eeprom(stru
309 return err;
310
311 if (need_swap)
312 - el = swab16(eep->baseEepHeader.length);
313 + el = swab16((__force u16)eep->baseEepHeader.length);
314 else
315 - el = eep->baseEepHeader.length;
316 + el = le16_to_cpu(eep->baseEepHeader.length);
317
318 el = min(el / sizeof(u16), SIZE_EEPROM_4K);
319 if (!ath9k_hw_nvram_validate_checksum(ah, el))
320 return -EINVAL;
321
322 if (need_swap) {
323 - u32 integer;
324 - u16 word;
325 -
326 - word = swab16(eep->baseEepHeader.length);
327 - eep->baseEepHeader.length = word;
328 -
329 - word = swab16(eep->baseEepHeader.checksum);
330 - eep->baseEepHeader.checksum = word;
331 -
332 - word = swab16(eep->baseEepHeader.version);
333 - eep->baseEepHeader.version = word;
334 -
335 - word = swab16(eep->baseEepHeader.regDmn[0]);
336 - eep->baseEepHeader.regDmn[0] = word;
337 -
338 - word = swab16(eep->baseEepHeader.regDmn[1]);
339 - eep->baseEepHeader.regDmn[1] = word;
340 -
341 - word = swab16(eep->baseEepHeader.rfSilent);
342 - eep->baseEepHeader.rfSilent = word;
343 -
344 - word = swab16(eep->baseEepHeader.blueToothOptions);
345 - eep->baseEepHeader.blueToothOptions = word;
346 -
347 - word = swab16(eep->baseEepHeader.deviceCap);
348 - eep->baseEepHeader.deviceCap = word;
349 -
350 - integer = swab32(eep->modalHeader.antCtrlCommon);
351 - eep->modalHeader.antCtrlCommon = integer;
352 -
353 - for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
354 - integer = swab32(eep->modalHeader.antCtrlChain[i]);
355 - eep->modalHeader.antCtrlChain[i] = integer;
356 - }
357 -
358 - for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
359 - word = swab16(eep->modalHeader.spurChans[i].spurChan);
360 - eep->modalHeader.spurChans[i].spurChan = word;
361 - }
362 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.length);
363 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.checksum);
364 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.version);
365 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[0]);
366 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[1]);
367 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.rfSilent);
368 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.blueToothOptions);
369 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.deviceCap);
370 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlCommon);
371 +
372 + for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++)
373 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
374 +
375 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
376 + EEPROM_FIELD_SWAB16(
377 + eep->modalHeader.spurChans[i].spurChan);
378 }
379
380 if (!ath9k_hw_nvram_check_version(ah, AR5416_EEP_VER,
381 @@ -270,13 +248,13 @@ static u32 ath9k_hw_4k_get_eeprom(struct
382 case EEP_MAC_MSW:
383 return get_unaligned_be16(pBase->macAddr + 4);
384 case EEP_REG_0:
385 - return pBase->regDmn[0];
386 + return le16_to_cpu(pBase->regDmn[0]);
387 case EEP_OP_CAP:
388 - return pBase->deviceCap;
389 + return le16_to_cpu(pBase->deviceCap);
390 case EEP_OP_MODE:
391 return pBase->opCapFlags;
392 case EEP_RF_SILENT:
393 - return pBase->rfSilent;
394 + return le16_to_cpu(pBase->rfSilent);
395 case EEP_OB_2:
396 return pModal->ob_0;
397 case EEP_DB_2:
398 @@ -724,7 +702,7 @@ static void ath9k_hw_4k_set_gain(struct
399 {
400 ENABLE_REG_RMW_BUFFER(ah);
401 REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0,
402 - pModal->antCtrlChain[0], 0);
403 + le32_to_cpu(pModal->antCtrlChain[0]), 0);
404
405 REG_RMW(ah, AR_PHY_TIMING_CTRL4(0),
406 SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
407 @@ -790,7 +768,7 @@ static void ath9k_hw_4k_set_board_values
408 pModal = &eep->modalHeader;
409 txRxAttenLocal = 23;
410
411 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
412 + REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
413
414 /* Single chain for 4K EEPROM*/
415 ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal);
416 @@ -1054,7 +1032,7 @@ static void ath9k_hw_4k_set_board_values
417
418 static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
419 {
420 - return ah->eeprom.map4k.modalHeader.spurChans[i].spurChan;
421 + return le16_to_cpu(ah->eeprom.map4k.modalHeader.spurChans[i].spurChan);
422 }
423
424 static u8 ath9k_hw_4k_get_eepmisc(struct ath_hw *ah)
425 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
426 +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
427 @@ -22,7 +22,7 @@
428
429 static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
430 {
431 - u16 version = ah->eeprom.map9287.baseEepHeader.version;
432 + u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
433
434 return (version & AR5416_EEP_VER_MAJOR_MASK) >>
435 AR5416_EEP_VER_MAJOR_SHIFT;
436 @@ -30,7 +30,7 @@ static int ath9k_hw_ar9287_get_eeprom_ve
437
438 static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
439 {
440 - u16 version = ah->eeprom.map9287.baseEepHeader.version;
441 + u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
442
443 return version & AR5416_EEP_VER_MINOR_MASK;
444 }
445 @@ -79,9 +79,9 @@ static bool ath9k_hw_ar9287_fill_eeprom(
446 static u32 ar9287_dump_modal_eeprom(char *buf, u32 len, u32 size,
447 struct modal_eep_ar9287_header *modal_hdr)
448 {
449 - PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
450 - PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
451 - PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
452 + PR_EEP("Chain0 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[0]));
453 + PR_EEP("Chain1 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[1]));
454 + PR_EEP("Ant. Common Control", le32_to_cpu(modal_hdr->antCtrlCommon));
455 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
456 PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
457 PR_EEP("Switch Settle", modal_hdr->switchSettling);
458 @@ -128,6 +128,7 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
459 {
460 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
461 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
462 + u32 binBuildNumber = le32_to_cpu(pBase->binBuildNumber);
463
464 if (!dump_base_hdr) {
465 len += scnprintf(buf + len, size - len,
466 @@ -139,10 +140,10 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
467
468 PR_EEP("Major Version", ath9k_hw_ar9287_get_eeprom_ver(ah));
469 PR_EEP("Minor Version", ath9k_hw_ar9287_get_eeprom_rev(ah));
470 - PR_EEP("Checksum", pBase->checksum);
471 - PR_EEP("Length", pBase->length);
472 - PR_EEP("RegDomain1", pBase->regDmn[0]);
473 - PR_EEP("RegDomain2", pBase->regDmn[1]);
474 + PR_EEP("Checksum", le16_to_cpu(pBase->checksum));
475 + PR_EEP("Length", le16_to_cpu(pBase->length));
476 + PR_EEP("RegDomain1", le16_to_cpu(pBase->regDmn[0]));
477 + PR_EEP("RegDomain2", le16_to_cpu(pBase->regDmn[1]));
478 PR_EEP("TX Mask", pBase->txMask);
479 PR_EEP("RX Mask", pBase->rxMask);
480 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
481 @@ -156,9 +157,9 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
482 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
483 AR5416_OPFLAGS_N_5G_HT40));
484 PR_EEP("Big Endian", !!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN));
485 - PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
486 - PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
487 - PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
488 + PR_EEP("Cal Bin Major Ver", (binBuildNumber >> 24) & 0xFF);
489 + PR_EEP("Cal Bin Minor Ver", (binBuildNumber >> 16) & 0xFF);
490 + PR_EEP("Cal Bin Build", (binBuildNumber >> 8) & 0xFF);
491 PR_EEP("Power Table Offset", pBase->pwrTableOffset);
492 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
493
494 @@ -182,8 +183,7 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
495
496 static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
497 {
498 - u32 el, integer;
499 - u16 word;
500 + u32 el;
501 int i, err;
502 bool need_swap;
503 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
504 @@ -193,51 +193,31 @@ static int ath9k_hw_ar9287_check_eeprom(
505 return err;
506
507 if (need_swap)
508 - el = swab16(eep->baseEepHeader.length);
509 + el = swab16((__force u16)eep->baseEepHeader.length);
510 else
511 - el = eep->baseEepHeader.length;
512 + el = le16_to_cpu(eep->baseEepHeader.length);
513
514 el = min(el / sizeof(u16), SIZE_EEPROM_AR9287);
515 if (!ath9k_hw_nvram_validate_checksum(ah, el))
516 return -EINVAL;
517
518 if (need_swap) {
519 - word = swab16(eep->baseEepHeader.length);
520 - eep->baseEepHeader.length = word;
521 -
522 - word = swab16(eep->baseEepHeader.checksum);
523 - eep->baseEepHeader.checksum = word;
524 -
525 - word = swab16(eep->baseEepHeader.version);
526 - eep->baseEepHeader.version = word;
527 -
528 - word = swab16(eep->baseEepHeader.regDmn[0]);
529 - eep->baseEepHeader.regDmn[0] = word;
530 -
531 - word = swab16(eep->baseEepHeader.regDmn[1]);
532 - eep->baseEepHeader.regDmn[1] = word;
533 -
534 - word = swab16(eep->baseEepHeader.rfSilent);
535 - eep->baseEepHeader.rfSilent = word;
536 -
537 - word = swab16(eep->baseEepHeader.blueToothOptions);
538 - eep->baseEepHeader.blueToothOptions = word;
539 -
540 - word = swab16(eep->baseEepHeader.deviceCap);
541 - eep->baseEepHeader.deviceCap = word;
542 -
543 - integer = swab32(eep->modalHeader.antCtrlCommon);
544 - eep->modalHeader.antCtrlCommon = integer;
545 -
546 - for (i = 0; i < AR9287_MAX_CHAINS; i++) {
547 - integer = swab32(eep->modalHeader.antCtrlChain[i]);
548 - eep->modalHeader.antCtrlChain[i] = integer;
549 - }
550 -
551 - for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
552 - word = swab16(eep->modalHeader.spurChans[i].spurChan);
553 - eep->modalHeader.spurChans[i].spurChan = word;
554 - }
555 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.length);
556 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.checksum);
557 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.version);
558 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[0]);
559 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[1]);
560 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.rfSilent);
561 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.blueToothOptions);
562 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.deviceCap);
563 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlCommon);
564 +
565 + for (i = 0; i < AR9287_MAX_CHAINS; i++)
566 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
567 +
568 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
569 + EEPROM_FIELD_SWAB16(
570 + eep->modalHeader.spurChans[i].spurChan);
571 }
572
573 if (!ath9k_hw_nvram_check_version(ah, AR9287_EEP_VER,
574 @@ -267,13 +247,13 @@ static u32 ath9k_hw_ar9287_get_eeprom(st
575 case EEP_MAC_MSW:
576 return get_unaligned_be16(pBase->macAddr + 4);
577 case EEP_REG_0:
578 - return pBase->regDmn[0];
579 + return le16_to_cpu(pBase->regDmn[0]);
580 case EEP_OP_CAP:
581 - return pBase->deviceCap;
582 + return le16_to_cpu(pBase->deviceCap);
583 case EEP_OP_MODE:
584 return pBase->opCapFlags;
585 case EEP_RF_SILENT:
586 - return pBase->rfSilent;
587 + return le16_to_cpu(pBase->rfSilent);
588 case EEP_TX_MASK:
589 return pBase->txMask;
590 case EEP_RX_MASK:
591 @@ -878,13 +858,13 @@ static void ath9k_hw_ar9287_set_board_va
592
593 pModal = &eep->modalHeader;
594
595 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
596 + REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
597
598 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
599 regChainOffset = i * 0x1000;
600
601 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
602 - pModal->antCtrlChain[i]);
603 + le32_to_cpu(pModal->antCtrlChain[i]));
604
605 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
606 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
607 @@ -982,7 +962,9 @@ static void ath9k_hw_ar9287_set_board_va
608 static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
609 u16 i, bool is2GHz)
610 {
611 - return ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
612 + __le16 spur_ch = ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
613 +
614 + return le16_to_cpu(spur_ch);
615 }
616
617 static u8 ath9k_hw_ar9287_get_eepmisc(struct ath_hw *ah)
618 --- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
619 +++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
620 @@ -79,7 +79,7 @@ static void ath9k_olc_get_pdadcs(struct
621
622 static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
623 {
624 - u16 version = ah->eeprom.def.baseEepHeader.version;
625 + u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
626
627 return (version & AR5416_EEP_VER_MAJOR_MASK) >>
628 AR5416_EEP_VER_MAJOR_SHIFT;
629 @@ -87,7 +87,7 @@ static int ath9k_hw_def_get_eeprom_ver(s
630
631 static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
632 {
633 - u16 version = ah->eeprom.def.baseEepHeader.version;
634 + u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
635
636 return version & AR5416_EEP_VER_MINOR_MASK;
637 }
638 @@ -135,10 +135,10 @@ static bool ath9k_hw_def_fill_eeprom(str
639 static u32 ath9k_def_dump_modal_eeprom(char *buf, u32 len, u32 size,
640 struct modal_eep_header *modal_hdr)
641 {
642 - PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
643 - PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
644 - PR_EEP("Chain2 Ant. Control", modal_hdr->antCtrlChain[2]);
645 - PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
646 + PR_EEP("Chain0 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[0]));
647 + PR_EEP("Chain1 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[1]));
648 + PR_EEP("Chain2 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[2]));
649 + PR_EEP("Ant. Common Control", le32_to_cpu(modal_hdr->antCtrlCommon));
650 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
651 PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
652 PR_EEP("Chain2 Ant. Gain", modal_hdr->antennaGainCh[2]);
653 @@ -194,9 +194,9 @@ static u32 ath9k_def_dump_modal_eeprom(c
654 PR_EEP("Chain1 OutputBias", modal_hdr->ob_ch1);
655 PR_EEP("Chain1 DriverBias", modal_hdr->db_ch1);
656 PR_EEP("LNA Control", modal_hdr->lna_ctl);
657 - PR_EEP("XPA Bias Freq0", modal_hdr->xpaBiasLvlFreq[0]);
658 - PR_EEP("XPA Bias Freq1", modal_hdr->xpaBiasLvlFreq[1]);
659 - PR_EEP("XPA Bias Freq2", modal_hdr->xpaBiasLvlFreq[2]);
660 + PR_EEP("XPA Bias Freq0", le16_to_cpu(modal_hdr->xpaBiasLvlFreq[0]));
661 + PR_EEP("XPA Bias Freq1", le16_to_cpu(modal_hdr->xpaBiasLvlFreq[1]));
662 + PR_EEP("XPA Bias Freq2", le16_to_cpu(modal_hdr->xpaBiasLvlFreq[2]));
663
664 return len;
665 }
666 @@ -206,6 +206,7 @@ static u32 ath9k_hw_def_dump_eeprom(stru
667 {
668 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
669 struct base_eep_header *pBase = &eep->baseEepHeader;
670 + u32 binBuildNumber = le32_to_cpu(pBase->binBuildNumber);
671
672 if (!dump_base_hdr) {
673 len += scnprintf(buf + len, size - len,
674 @@ -221,10 +222,10 @@ static u32 ath9k_hw_def_dump_eeprom(stru
675
676 PR_EEP("Major Version", ath9k_hw_def_get_eeprom_ver(ah));
677 PR_EEP("Minor Version", ath9k_hw_def_get_eeprom_rev(ah));
678 - PR_EEP("Checksum", pBase->checksum);
679 - PR_EEP("Length", pBase->length);
680 - PR_EEP("RegDomain1", pBase->regDmn[0]);
681 - PR_EEP("RegDomain2", pBase->regDmn[1]);
682 + PR_EEP("Checksum", le16_to_cpu(pBase->checksum));
683 + PR_EEP("Length", le16_to_cpu(pBase->length));
684 + PR_EEP("RegDomain1", le16_to_cpu(pBase->regDmn[0]));
685 + PR_EEP("RegDomain2", le16_to_cpu(pBase->regDmn[1]));
686 PR_EEP("TX Mask", pBase->txMask);
687 PR_EEP("RX Mask", pBase->rxMask);
688 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
689 @@ -238,9 +239,9 @@ static u32 ath9k_hw_def_dump_eeprom(stru
690 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
691 AR5416_OPFLAGS_N_5G_HT40));
692 PR_EEP("Big Endian", !!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN));
693 - PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
694 - PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
695 - PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
696 + PR_EEP("Cal Bin Major Ver", (binBuildNumber >> 24) & 0xFF);
697 + PR_EEP("Cal Bin Minor Ver", (binBuildNumber >> 16) & 0xFF);
698 + PR_EEP("Cal Bin Build", (binBuildNumber >> 8) & 0xFF);
699 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
700
701 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
702 @@ -273,61 +274,40 @@ static int ath9k_hw_def_check_eeprom(str
703 return err;
704
705 if (need_swap)
706 - el = swab16(eep->baseEepHeader.length);
707 + el = swab16((__force u16)eep->baseEepHeader.length);
708 else
709 - el = eep->baseEepHeader.length;
710 + el = le16_to_cpu(eep->baseEepHeader.length);
711
712 el = min(el / sizeof(u16), SIZE_EEPROM_DEF);
713 if (!ath9k_hw_nvram_validate_checksum(ah, el))
714 return -EINVAL;
715
716 if (need_swap) {
717 - u32 integer, j;
718 - u16 word;
719 + u32 j;
720
721 - word = swab16(eep->baseEepHeader.length);
722 - eep->baseEepHeader.length = word;
723 -
724 - word = swab16(eep->baseEepHeader.checksum);
725 - eep->baseEepHeader.checksum = word;
726 -
727 - word = swab16(eep->baseEepHeader.version);
728 - eep->baseEepHeader.version = word;
729 -
730 - word = swab16(eep->baseEepHeader.regDmn[0]);
731 - eep->baseEepHeader.regDmn[0] = word;
732 -
733 - word = swab16(eep->baseEepHeader.regDmn[1]);
734 - eep->baseEepHeader.regDmn[1] = word;
735 -
736 - word = swab16(eep->baseEepHeader.rfSilent);
737 - eep->baseEepHeader.rfSilent = word;
738 -
739 - word = swab16(eep->baseEepHeader.blueToothOptions);
740 - eep->baseEepHeader.blueToothOptions = word;
741 -
742 - word = swab16(eep->baseEepHeader.deviceCap);
743 - eep->baseEepHeader.deviceCap = word;
744 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.length);
745 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.checksum);
746 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.version);
747 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[0]);
748 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[1]);
749 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.rfSilent);
750 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.blueToothOptions);
751 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.deviceCap);
752
753 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
754 struct modal_eep_header *pModal =
755 &eep->modalHeader[j];
756 - integer = swab32(pModal->antCtrlCommon);
757 - pModal->antCtrlCommon = integer;
758 + EEPROM_FIELD_SWAB32(pModal->antCtrlCommon);
759
760 - for (i = 0; i < AR5416_MAX_CHAINS; i++) {
761 - integer = swab32(pModal->antCtrlChain[i]);
762 - pModal->antCtrlChain[i] = integer;
763 - }
764 - for (i = 0; i < 3; i++) {
765 - word = swab16(pModal->xpaBiasLvlFreq[i]);
766 - pModal->xpaBiasLvlFreq[i] = word;
767 - }
768 + for (i = 0; i < AR5416_MAX_CHAINS; i++)
769 + EEPROM_FIELD_SWAB32(pModal->antCtrlChain[i]);
770
771 - for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
772 - word = swab16(pModal->spurChans[i].spurChan);
773 - pModal->spurChans[i].spurChan = word;
774 - }
775 + for (i = 0; i < 3; i++)
776 + EEPROM_FIELD_SWAB16(pModal->xpaBiasLvlFreq[i]);
777 +
778 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
779 + EEPROM_FIELD_SWAB16(
780 + pModal->spurChans[i].spurChan);
781 }
782 }
783
784 @@ -337,7 +317,7 @@ static int ath9k_hw_def_check_eeprom(str
785
786 /* Enable fixup for AR_AN_TOP2 if necessary */
787 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
788 - ((eep->baseEepHeader.version & 0xff) > 0x0a) &&
789 + ((le16_to_cpu(eep->baseEepHeader.version) & 0xff) > 0x0a) &&
790 (eep->baseEepHeader.pwdclkind == 0))
791 ah->need_an_top2_fixup = true;
792
793 @@ -370,13 +350,13 @@ static u32 ath9k_hw_def_get_eeprom(struc
794 case EEP_MAC_MSW:
795 return get_unaligned_be16(pBase->macAddr + 4);
796 case EEP_REG_0:
797 - return pBase->regDmn[0];
798 + return le16_to_cpu(pBase->regDmn[0]);
799 case EEP_OP_CAP:
800 - return pBase->deviceCap;
801 + return le16_to_cpu(pBase->deviceCap);
802 case EEP_OP_MODE:
803 return pBase->opCapFlags;
804 case EEP_RF_SILENT:
805 - return pBase->rfSilent;
806 + return le16_to_cpu(pBase->rfSilent);
807 case EEP_OB_5:
808 return pModal[0].ob;
809 case EEP_DB_5:
810 @@ -490,11 +470,13 @@ static void ath9k_hw_def_set_board_value
811 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
812 int i, regChainOffset;
813 u8 txRxAttenLocal;
814 + u32 antCtrlCommon;
815
816 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
817 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
818 + antCtrlCommon = le32_to_cpu(pModal->antCtrlCommon);
819
820 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
821 + REG_WRITE(ah, AR_PHY_SWITCH_COM, antCtrlCommon & 0xffff);
822
823 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
824 if (AR_SREV_9280(ah)) {
825 @@ -508,7 +490,7 @@ static void ath9k_hw_def_set_board_value
826 regChainOffset = i * 0x1000;
827
828 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
829 - pModal->antCtrlChain[i]);
830 + le32_to_cpu(pModal->antCtrlChain[i]));
831
832 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
833 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
834 @@ -655,7 +637,7 @@ static void ath9k_hw_def_set_board_value
835 static void ath9k_hw_def_set_addac(struct ath_hw *ah,
836 struct ath9k_channel *chan)
837 {
838 -#define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
839 +#define XPA_LVL_FREQ(cnt) (le16_to_cpu(pModal->xpaBiasLvlFreq[cnt]))
840 struct modal_eep_header *pModal;
841 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
842 u8 biaslevel;
843 @@ -1315,7 +1297,9 @@ static void ath9k_hw_def_set_txpower(str
844
845 static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
846 {
847 - return ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
848 + __le16 spch = ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
849 +
850 + return le16_to_cpu(spch);
851 }
852
853 static u8 ath9k_hw_def_get_eepmisc(struct ath_hw *ah)