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
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
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.
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".
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
28 Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
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(-)
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 *
44 -#define EXPECTED_EEPMISC_ENDIAN AR5416_EEPMISC_BIG_ENDIAN
46 -#define EXPECTED_EEPMISC_ENDIAN 0
49 int ath9k_hw_nvram_swap_data(struct ath_hw *ah, bool *swap_needed, int size)
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_
61 - *swap_needed = false;
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) {
67 - "Ignoring endianness difference in eepmisc register.\n");
69 - *swap_needed = true;
70 - ath_dbg(common, EEPROM,
71 - "EEPROM needs swapping according to the eepmisc register.\n");
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");
78 + *swap_needed = false;
84 -#undef EXPECTED_EEPMISC_VAL
86 bool ath9k_hw_nvram_validate_checksum(struct ath_hw *ah, int size)
89 --- a/drivers/net/wireless/ath/ath9k/eeprom.h
90 +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
92 #include <net/cfg80211.h>
93 #include "ar9003_eeprom.h"
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.
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))
107 #define AR5416_EEPROM_MAGIC 0x5aa5
109 @@ -270,19 +281,19 @@ enum ath9k_hal_freq_band {
112 struct base_eep_header {
127 - u16 blueToothOptions;
129 - u32 binBuildNumber;
131 + __le16 blueToothOptions;
133 + __le32 binBuildNumber;
137 @@ -300,33 +311,33 @@ struct base_eep_header {
140 struct base_eep_header_4k {
155 - u16 blueToothOptions;
157 - u32 binBuildNumber;
159 + __le16 blueToothOptions;
161 + __le32 binBuildNumber;
174 struct modal_eep_header {
175 - u32 antCtrlChain[AR5416_MAX_CHAINS];
177 + __le32 antCtrlChain[AR5416_MAX_CHAINS];
178 + __le32 antCtrlCommon;
179 u8 antennaGainCh[AR5416_MAX_CHAINS];
181 u8 txRxAttenCh[AR5416_MAX_CHAINS];
182 @@ -361,7 +372,7 @@ struct modal_eep_header {
186 - u16 xpaBiasLvlFreq[3];
187 + __le16 xpaBiasLvlFreq[3];
190 struct spur_chan spurChans[AR_EEPROM_MODAL_SPURS];
191 @@ -375,8 +386,8 @@ struct calDataPerFreqOpLoop {
194 struct modal_eep_4k_header {
195 - u32 antCtrlChain[AR5416_EEP4K_MAX_CHAINS];
197 + __le32 antCtrlChain[AR5416_EEP4K_MAX_CHAINS];
198 + __le32 antCtrlCommon;
199 u8 antennaGainCh[AR5416_EEP4K_MAX_CHAINS];
201 u8 txRxAttenCh[AR5416_EEP4K_MAX_CHAINS];
202 @@ -440,19 +451,19 @@ struct modal_eep_4k_header {
205 struct base_eep_ar9287_header {
220 - u16 blueToothOptions;
222 - u32 binBuildNumber;
224 + __le16 blueToothOptions;
226 + __le32 binBuildNumber;
229 int8_t pwrTableOffset;
230 @@ -462,8 +473,8 @@ struct base_eep_ar9287_header {
233 struct modal_eep_ar9287_header {
234 - u32 antCtrlChain[AR9287_MAX_CHAINS];
236 + __le32 antCtrlChain[AR9287_MAX_CHAINS];
237 + __le32 antCtrlCommon;
238 int8_t antennaGainCh[AR9287_MAX_CHAINS];
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
245 static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
247 - u16 version = ah->eeprom.map4k.baseEepHeader.version;
248 + u16 version = le16_to_cpu(ah->eeprom.map4k.baseEepHeader.version);
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
254 static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
256 - u16 version = ah->eeprom.map4k.baseEepHeader.version;
257 + u16 version = le16_to_cpu(ah->eeprom.map4k.baseEepHeader.version);
259 return version & AR5416_EEP_VER_MINOR_MASK;
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)
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
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);
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
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);
307 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
308 @@ -194,54 +195,31 @@ static int ath9k_hw_4k_check_eeprom(stru
312 - el = swab16(eep->baseEepHeader.length);
313 + el = swab16((__force u16)eep->baseEepHeader.length);
315 - el = eep->baseEepHeader.length;
316 + el = le16_to_cpu(eep->baseEepHeader.length);
318 el = min(el / sizeof(u16), SIZE_EEPROM_4K);
319 if (!ath9k_hw_nvram_validate_checksum(ah, el))
326 - word = swab16(eep->baseEepHeader.length);
327 - eep->baseEepHeader.length = word;
329 - word = swab16(eep->baseEepHeader.checksum);
330 - eep->baseEepHeader.checksum = word;
332 - word = swab16(eep->baseEepHeader.version);
333 - eep->baseEepHeader.version = word;
335 - word = swab16(eep->baseEepHeader.regDmn[0]);
336 - eep->baseEepHeader.regDmn[0] = word;
338 - word = swab16(eep->baseEepHeader.regDmn[1]);
339 - eep->baseEepHeader.regDmn[1] = word;
341 - word = swab16(eep->baseEepHeader.rfSilent);
342 - eep->baseEepHeader.rfSilent = word;
344 - word = swab16(eep->baseEepHeader.blueToothOptions);
345 - eep->baseEepHeader.blueToothOptions = word;
347 - word = swab16(eep->baseEepHeader.deviceCap);
348 - eep->baseEepHeader.deviceCap = word;
350 - integer = swab32(eep->modalHeader.antCtrlCommon);
351 - eep->modalHeader.antCtrlCommon = integer;
352 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.length);
353 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.checksum);
354 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.version);
355 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[0]);
356 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[1]);
357 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.rfSilent);
358 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.blueToothOptions);
359 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.deviceCap);
360 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlCommon);
362 - for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
363 - integer = swab32(eep->modalHeader.antCtrlChain[i]);
364 - eep->modalHeader.antCtrlChain[i] = integer;
366 + for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++)
367 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
369 - for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
370 - word = swab16(eep->modalHeader.spurChans[i].spurChan);
371 - eep->modalHeader.spurChans[i].spurChan = word;
373 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
374 + EEPROM_FIELD_SWAB16(
375 + eep->modalHeader.spurChans[i].spurChan);
378 if (!ath9k_hw_nvram_check_version(ah, AR5416_EEP_VER,
379 @@ -270,13 +248,13 @@ static u32 ath9k_hw_4k_get_eeprom(struct
381 return get_unaligned_be16(pBase->macAddr + 4);
383 - return pBase->regDmn[0];
384 + return le16_to_cpu(pBase->regDmn[0]);
386 - return pBase->deviceCap;
387 + return le16_to_cpu(pBase->deviceCap);
389 return pBase->opCapFlags;
391 - return pBase->rfSilent;
392 + return le16_to_cpu(pBase->rfSilent);
396 @@ -724,7 +702,7 @@ static void ath9k_hw_4k_set_gain(struct
398 ENABLE_REG_RMW_BUFFER(ah);
399 REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0,
400 - pModal->antCtrlChain[0], 0);
401 + le32_to_cpu(pModal->antCtrlChain[0]), 0);
403 REG_RMW(ah, AR_PHY_TIMING_CTRL4(0),
404 SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
405 @@ -790,7 +768,7 @@ static void ath9k_hw_4k_set_board_values
406 pModal = &eep->modalHeader;
409 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
410 + REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
412 /* Single chain for 4K EEPROM*/
413 ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal);
414 @@ -1054,7 +1032,7 @@ static void ath9k_hw_4k_set_board_values
416 static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
418 - return ah->eeprom.map4k.modalHeader.spurChans[i].spurChan;
419 + return le16_to_cpu(ah->eeprom.map4k.modalHeader.spurChans[i].spurChan);
422 static u8 ath9k_hw_4k_get_eepmisc(struct ath_hw *ah)
423 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
424 +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
427 static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
429 - u16 version = ah->eeprom.map9287.baseEepHeader.version;
430 + u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
432 return (version & AR5416_EEP_VER_MAJOR_MASK) >>
433 AR5416_EEP_VER_MAJOR_SHIFT;
434 @@ -30,7 +30,7 @@ static int ath9k_hw_ar9287_get_eeprom_ve
436 static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
438 - u16 version = ah->eeprom.map9287.baseEepHeader.version;
439 + u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
441 return version & AR5416_EEP_VER_MINOR_MASK;
443 @@ -79,9 +79,9 @@ static bool ath9k_hw_ar9287_fill_eeprom(
444 static u32 ar9287_dump_modal_eeprom(char *buf, u32 len, u32 size,
445 struct modal_eep_ar9287_header *modal_hdr)
447 - PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
448 - PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
449 - PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
450 + PR_EEP("Chain0 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[0]));
451 + PR_EEP("Chain1 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[1]));
452 + PR_EEP("Ant. Common Control", le32_to_cpu(modal_hdr->antCtrlCommon));
453 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
454 PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
455 PR_EEP("Switch Settle", modal_hdr->switchSettling);
456 @@ -128,6 +128,7 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
458 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
459 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
460 + u32 binBuildNumber = le32_to_cpu(pBase->binBuildNumber);
462 if (!dump_base_hdr) {
463 len += scnprintf(buf + len, size - len,
464 @@ -139,10 +140,10 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
466 PR_EEP("Major Version", ath9k_hw_ar9287_get_eeprom_ver(ah));
467 PR_EEP("Minor Version", ath9k_hw_ar9287_get_eeprom_rev(ah));
468 - PR_EEP("Checksum", pBase->checksum);
469 - PR_EEP("Length", pBase->length);
470 - PR_EEP("RegDomain1", pBase->regDmn[0]);
471 - PR_EEP("RegDomain2", pBase->regDmn[1]);
472 + PR_EEP("Checksum", le16_to_cpu(pBase->checksum));
473 + PR_EEP("Length", le16_to_cpu(pBase->length));
474 + PR_EEP("RegDomain1", le16_to_cpu(pBase->regDmn[0]));
475 + PR_EEP("RegDomain2", le16_to_cpu(pBase->regDmn[1]));
476 PR_EEP("TX Mask", pBase->txMask);
477 PR_EEP("RX Mask", pBase->rxMask);
478 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
479 @@ -156,9 +157,9 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
480 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
481 AR5416_OPFLAGS_N_5G_HT40));
482 PR_EEP("Big Endian", !!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN));
483 - PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
484 - PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
485 - PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
486 + PR_EEP("Cal Bin Major Ver", (binBuildNumber >> 24) & 0xFF);
487 + PR_EEP("Cal Bin Minor Ver", (binBuildNumber >> 16) & 0xFF);
488 + PR_EEP("Cal Bin Build", (binBuildNumber >> 8) & 0xFF);
489 PR_EEP("Power Table Offset", pBase->pwrTableOffset);
490 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
492 @@ -182,8 +183,7 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
494 static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
501 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
502 @@ -193,51 +193,31 @@ static int ath9k_hw_ar9287_check_eeprom(
506 - el = swab16(eep->baseEepHeader.length);
507 + el = swab16((__force u16)eep->baseEepHeader.length);
509 - el = eep->baseEepHeader.length;
510 + el = le16_to_cpu(eep->baseEepHeader.length);
512 el = min(el / sizeof(u16), SIZE_EEPROM_AR9287);
513 if (!ath9k_hw_nvram_validate_checksum(ah, el))
517 - word = swab16(eep->baseEepHeader.length);
518 - eep->baseEepHeader.length = word;
520 - word = swab16(eep->baseEepHeader.checksum);
521 - eep->baseEepHeader.checksum = word;
523 - word = swab16(eep->baseEepHeader.version);
524 - eep->baseEepHeader.version = word;
526 - word = swab16(eep->baseEepHeader.regDmn[0]);
527 - eep->baseEepHeader.regDmn[0] = word;
529 - word = swab16(eep->baseEepHeader.regDmn[1]);
530 - eep->baseEepHeader.regDmn[1] = word;
532 - word = swab16(eep->baseEepHeader.rfSilent);
533 - eep->baseEepHeader.rfSilent = word;
535 - word = swab16(eep->baseEepHeader.blueToothOptions);
536 - eep->baseEepHeader.blueToothOptions = word;
538 - word = swab16(eep->baseEepHeader.deviceCap);
539 - eep->baseEepHeader.deviceCap = word;
541 - integer = swab32(eep->modalHeader.antCtrlCommon);
542 - eep->modalHeader.antCtrlCommon = integer;
543 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.length);
544 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.checksum);
545 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.version);
546 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[0]);
547 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[1]);
548 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.rfSilent);
549 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.blueToothOptions);
550 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.deviceCap);
551 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlCommon);
553 - for (i = 0; i < AR9287_MAX_CHAINS; i++) {
554 - integer = swab32(eep->modalHeader.antCtrlChain[i]);
555 - eep->modalHeader.antCtrlChain[i] = integer;
557 + for (i = 0; i < AR9287_MAX_CHAINS; i++)
558 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
560 - for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
561 - word = swab16(eep->modalHeader.spurChans[i].spurChan);
562 - eep->modalHeader.spurChans[i].spurChan = word;
564 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
565 + EEPROM_FIELD_SWAB16(
566 + eep->modalHeader.spurChans[i].spurChan);
569 if (!ath9k_hw_nvram_check_version(ah, AR9287_EEP_VER,
570 @@ -267,13 +247,13 @@ static u32 ath9k_hw_ar9287_get_eeprom(st
572 return get_unaligned_be16(pBase->macAddr + 4);
574 - return pBase->regDmn[0];
575 + return le16_to_cpu(pBase->regDmn[0]);
577 - return pBase->deviceCap;
578 + return le16_to_cpu(pBase->deviceCap);
580 return pBase->opCapFlags;
582 - return pBase->rfSilent;
583 + return le16_to_cpu(pBase->rfSilent);
585 return pBase->txMask;
587 @@ -878,13 +858,13 @@ static void ath9k_hw_ar9287_set_board_va
589 pModal = &eep->modalHeader;
591 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
592 + REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
594 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
595 regChainOffset = i * 0x1000;
597 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
598 - pModal->antCtrlChain[i]);
599 + le32_to_cpu(pModal->antCtrlChain[i]));
601 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
602 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
603 @@ -982,7 +962,9 @@ static void ath9k_hw_ar9287_set_board_va
604 static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
607 - return ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
608 + __le16 spur_ch = ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
610 + return le16_to_cpu(spur_ch);
613 static u8 ath9k_hw_ar9287_get_eepmisc(struct ath_hw *ah)
614 --- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
615 +++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
616 @@ -79,7 +79,7 @@ static void ath9k_olc_get_pdadcs(struct
618 static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
620 - u16 version = ah->eeprom.def.baseEepHeader.version;
621 + u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
623 return (version & AR5416_EEP_VER_MAJOR_MASK) >>
624 AR5416_EEP_VER_MAJOR_SHIFT;
625 @@ -87,7 +87,7 @@ static int ath9k_hw_def_get_eeprom_ver(s
627 static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
629 - u16 version = ah->eeprom.def.baseEepHeader.version;
630 + u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
632 return version & AR5416_EEP_VER_MINOR_MASK;
634 @@ -135,10 +135,10 @@ static bool ath9k_hw_def_fill_eeprom(str
635 static u32 ath9k_def_dump_modal_eeprom(char *buf, u32 len, u32 size,
636 struct modal_eep_header *modal_hdr)
638 - PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
639 - PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
640 - PR_EEP("Chain2 Ant. Control", modal_hdr->antCtrlChain[2]);
641 - PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
642 + PR_EEP("Chain0 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[0]));
643 + PR_EEP("Chain1 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[1]));
644 + PR_EEP("Chain2 Ant. Control", le16_to_cpu(modal_hdr->antCtrlChain[2]));
645 + PR_EEP("Ant. Common Control", le32_to_cpu(modal_hdr->antCtrlCommon));
646 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
647 PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
648 PR_EEP("Chain2 Ant. Gain", modal_hdr->antennaGainCh[2]);
649 @@ -194,9 +194,9 @@ static u32 ath9k_def_dump_modal_eeprom(c
650 PR_EEP("Chain1 OutputBias", modal_hdr->ob_ch1);
651 PR_EEP("Chain1 DriverBias", modal_hdr->db_ch1);
652 PR_EEP("LNA Control", modal_hdr->lna_ctl);
653 - PR_EEP("XPA Bias Freq0", modal_hdr->xpaBiasLvlFreq[0]);
654 - PR_EEP("XPA Bias Freq1", modal_hdr->xpaBiasLvlFreq[1]);
655 - PR_EEP("XPA Bias Freq2", modal_hdr->xpaBiasLvlFreq[2]);
656 + PR_EEP("XPA Bias Freq0", le16_to_cpu(modal_hdr->xpaBiasLvlFreq[0]));
657 + PR_EEP("XPA Bias Freq1", le16_to_cpu(modal_hdr->xpaBiasLvlFreq[1]));
658 + PR_EEP("XPA Bias Freq2", le16_to_cpu(modal_hdr->xpaBiasLvlFreq[2]));
662 @@ -206,6 +206,7 @@ static u32 ath9k_hw_def_dump_eeprom(stru
664 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
665 struct base_eep_header *pBase = &eep->baseEepHeader;
666 + u32 binBuildNumber = le32_to_cpu(pBase->binBuildNumber);
668 if (!dump_base_hdr) {
669 len += scnprintf(buf + len, size - len,
670 @@ -221,10 +222,10 @@ static u32 ath9k_hw_def_dump_eeprom(stru
672 PR_EEP("Major Version", ath9k_hw_def_get_eeprom_ver(ah));
673 PR_EEP("Minor Version", ath9k_hw_def_get_eeprom_rev(ah));
674 - PR_EEP("Checksum", pBase->checksum);
675 - PR_EEP("Length", pBase->length);
676 - PR_EEP("RegDomain1", pBase->regDmn[0]);
677 - PR_EEP("RegDomain2", pBase->regDmn[1]);
678 + PR_EEP("Checksum", le16_to_cpu(pBase->checksum));
679 + PR_EEP("Length", le16_to_cpu(pBase->length));
680 + PR_EEP("RegDomain1", le16_to_cpu(pBase->regDmn[0]));
681 + PR_EEP("RegDomain2", le16_to_cpu(pBase->regDmn[1]));
682 PR_EEP("TX Mask", pBase->txMask);
683 PR_EEP("RX Mask", pBase->rxMask);
684 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
685 @@ -238,9 +239,9 @@ static u32 ath9k_hw_def_dump_eeprom(stru
686 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
687 AR5416_OPFLAGS_N_5G_HT40));
688 PR_EEP("Big Endian", !!(pBase->eepMisc & AR5416_EEPMISC_BIG_ENDIAN));
689 - PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
690 - PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
691 - PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
692 + PR_EEP("Cal Bin Major Ver", (binBuildNumber >> 24) & 0xFF);
693 + PR_EEP("Cal Bin Minor Ver", (binBuildNumber >> 16) & 0xFF);
694 + PR_EEP("Cal Bin Build", (binBuildNumber >> 8) & 0xFF);
695 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
697 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
698 @@ -273,61 +274,40 @@ static int ath9k_hw_def_check_eeprom(str
702 - el = swab16(eep->baseEepHeader.length);
703 + el = swab16((__force u16)eep->baseEepHeader.length);
705 - el = eep->baseEepHeader.length;
706 + el = le16_to_cpu(eep->baseEepHeader.length);
708 el = min(el / sizeof(u16), SIZE_EEPROM_DEF);
709 if (!ath9k_hw_nvram_validate_checksum(ah, el))
716 - word = swab16(eep->baseEepHeader.length);
717 - eep->baseEepHeader.length = word;
719 - word = swab16(eep->baseEepHeader.checksum);
720 - eep->baseEepHeader.checksum = word;
722 - word = swab16(eep->baseEepHeader.version);
723 - eep->baseEepHeader.version = word;
725 - word = swab16(eep->baseEepHeader.regDmn[0]);
726 - eep->baseEepHeader.regDmn[0] = word;
728 - word = swab16(eep->baseEepHeader.regDmn[1]);
729 - eep->baseEepHeader.regDmn[1] = word;
731 - word = swab16(eep->baseEepHeader.rfSilent);
732 - eep->baseEepHeader.rfSilent = word;
734 - word = swab16(eep->baseEepHeader.blueToothOptions);
735 - eep->baseEepHeader.blueToothOptions = word;
738 - word = swab16(eep->baseEepHeader.deviceCap);
739 - eep->baseEepHeader.deviceCap = word;
740 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.length);
741 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.checksum);
742 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.version);
743 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[0]);
744 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.regDmn[1]);
745 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.rfSilent);
746 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.blueToothOptions);
747 + EEPROM_FIELD_SWAB16(eep->baseEepHeader.deviceCap);
749 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
750 struct modal_eep_header *pModal =
751 &eep->modalHeader[j];
752 - integer = swab32(pModal->antCtrlCommon);
753 - pModal->antCtrlCommon = integer;
754 + EEPROM_FIELD_SWAB32(pModal->antCtrlCommon);
756 - for (i = 0; i < AR5416_MAX_CHAINS; i++) {
757 - integer = swab32(pModal->antCtrlChain[i]);
758 - pModal->antCtrlChain[i] = integer;
760 - for (i = 0; i < 3; i++) {
761 - word = swab16(pModal->xpaBiasLvlFreq[i]);
762 - pModal->xpaBiasLvlFreq[i] = word;
764 + for (i = 0; i < AR5416_MAX_CHAINS; i++)
765 + EEPROM_FIELD_SWAB32(pModal->antCtrlChain[i]);
767 - for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
768 - word = swab16(pModal->spurChans[i].spurChan);
769 - pModal->spurChans[i].spurChan = word;
771 + for (i = 0; i < 3; i++)
772 + EEPROM_FIELD_SWAB16(pModal->xpaBiasLvlFreq[i]);
774 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
775 + EEPROM_FIELD_SWAB16(
776 + pModal->spurChans[i].spurChan);
780 @@ -337,7 +317,7 @@ static int ath9k_hw_def_check_eeprom(str
782 /* Enable fixup for AR_AN_TOP2 if necessary */
783 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
784 - ((eep->baseEepHeader.version & 0xff) > 0x0a) &&
785 + ((le16_to_cpu(eep->baseEepHeader.version) & 0xff) > 0x0a) &&
786 (eep->baseEepHeader.pwdclkind == 0))
787 ah->need_an_top2_fixup = true;
789 @@ -370,13 +350,13 @@ static u32 ath9k_hw_def_get_eeprom(struc
791 return get_unaligned_be16(pBase->macAddr + 4);
793 - return pBase->regDmn[0];
794 + return le16_to_cpu(pBase->regDmn[0]);
796 - return pBase->deviceCap;
797 + return le16_to_cpu(pBase->deviceCap);
799 return pBase->opCapFlags;
801 - return pBase->rfSilent;
802 + return le16_to_cpu(pBase->rfSilent);
806 @@ -490,11 +470,13 @@ static void ath9k_hw_def_set_board_value
807 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
808 int i, regChainOffset;
812 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
813 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
814 + antCtrlCommon = le32_to_cpu(pModal->antCtrlCommon);
816 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
817 + REG_WRITE(ah, AR_PHY_SWITCH_COM, antCtrlCommon & 0xffff);
819 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
820 if (AR_SREV_9280(ah)) {
821 @@ -508,7 +490,7 @@ static void ath9k_hw_def_set_board_value
822 regChainOffset = i * 0x1000;
824 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
825 - pModal->antCtrlChain[i]);
826 + le32_to_cpu(pModal->antCtrlChain[i]));
828 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
829 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
830 @@ -655,7 +637,7 @@ static void ath9k_hw_def_set_board_value
831 static void ath9k_hw_def_set_addac(struct ath_hw *ah,
832 struct ath9k_channel *chan)
834 -#define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
835 +#define XPA_LVL_FREQ(cnt) (le16_to_cpu(pModal->xpaBiasLvlFreq[cnt]))
836 struct modal_eep_header *pModal;
837 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
839 @@ -1315,7 +1297,9 @@ static void ath9k_hw_def_set_txpower(str
841 static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
843 - return ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
844 + __le16 spch = ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
846 + return le16_to_cpu(spch);
849 static u8 ath9k_hw_def_get_eepmisc(struct ath_hw *ah)