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;
353 - for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
354 - integer = swab32(eep->modalHeader.antCtrlChain[i]);
355 - eep->modalHeader.antCtrlChain[i] = integer;
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;
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);
372 + for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++)
373 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
375 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
376 + EEPROM_FIELD_SWAB16(
377 + eep->modalHeader.spurChans[i].spurChan);
380 if (!ath9k_hw_nvram_check_version(ah, AR5416_EEP_VER,
381 @@ -270,13 +248,13 @@ static u32 ath9k_hw_4k_get_eeprom(struct
383 return get_unaligned_be16(pBase->macAddr + 4);
385 - return pBase->regDmn[0];
386 + return le16_to_cpu(pBase->regDmn[0]);
388 - return pBase->deviceCap;
389 + return le16_to_cpu(pBase->deviceCap);
391 return pBase->opCapFlags;
393 - return pBase->rfSilent;
394 + return le16_to_cpu(pBase->rfSilent);
398 @@ -724,7 +702,7 @@ static void ath9k_hw_4k_set_gain(struct
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);
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;
411 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
412 + REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
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
418 static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
420 - return ah->eeprom.map4k.modalHeader.spurChans[i].spurChan;
421 + return le16_to_cpu(ah->eeprom.map4k.modalHeader.spurChans[i].spurChan);
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
429 static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
431 - u16 version = ah->eeprom.map9287.baseEepHeader.version;
432 + u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
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
438 static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
440 - u16 version = ah->eeprom.map9287.baseEepHeader.version;
441 + u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
443 return version & AR5416_EEP_VER_MINOR_MASK;
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)
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
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);
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
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);
494 @@ -182,8 +183,7 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
496 static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
503 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
504 @@ -193,51 +193,31 @@ static int ath9k_hw_ar9287_check_eeprom(
508 - el = swab16(eep->baseEepHeader.length);
509 + el = swab16((__force u16)eep->baseEepHeader.length);
511 - el = eep->baseEepHeader.length;
512 + el = le16_to_cpu(eep->baseEepHeader.length);
514 el = min(el / sizeof(u16), SIZE_EEPROM_AR9287);
515 if (!ath9k_hw_nvram_validate_checksum(ah, el))
519 - word = swab16(eep->baseEepHeader.length);
520 - eep->baseEepHeader.length = word;
522 - word = swab16(eep->baseEepHeader.checksum);
523 - eep->baseEepHeader.checksum = word;
525 - word = swab16(eep->baseEepHeader.version);
526 - eep->baseEepHeader.version = word;
528 - word = swab16(eep->baseEepHeader.regDmn[0]);
529 - eep->baseEepHeader.regDmn[0] = word;
531 - word = swab16(eep->baseEepHeader.regDmn[1]);
532 - eep->baseEepHeader.regDmn[1] = word;
534 - word = swab16(eep->baseEepHeader.rfSilent);
535 - eep->baseEepHeader.rfSilent = word;
537 - word = swab16(eep->baseEepHeader.blueToothOptions);
538 - eep->baseEepHeader.blueToothOptions = word;
540 - word = swab16(eep->baseEepHeader.deviceCap);
541 - eep->baseEepHeader.deviceCap = word;
543 - integer = swab32(eep->modalHeader.antCtrlCommon);
544 - eep->modalHeader.antCtrlCommon = integer;
546 - for (i = 0; i < AR9287_MAX_CHAINS; i++) {
547 - integer = swab32(eep->modalHeader.antCtrlChain[i]);
548 - eep->modalHeader.antCtrlChain[i] = integer;
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;
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);
565 + for (i = 0; i < AR9287_MAX_CHAINS; i++)
566 + EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
568 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
569 + EEPROM_FIELD_SWAB16(
570 + eep->modalHeader.spurChans[i].spurChan);
573 if (!ath9k_hw_nvram_check_version(ah, AR9287_EEP_VER,
574 @@ -267,13 +247,13 @@ static u32 ath9k_hw_ar9287_get_eeprom(st
576 return get_unaligned_be16(pBase->macAddr + 4);
578 - return pBase->regDmn[0];
579 + return le16_to_cpu(pBase->regDmn[0]);
581 - return pBase->deviceCap;
582 + return le16_to_cpu(pBase->deviceCap);
584 return pBase->opCapFlags;
586 - return pBase->rfSilent;
587 + return le16_to_cpu(pBase->rfSilent);
589 return pBase->txMask;
591 @@ -878,13 +858,13 @@ static void ath9k_hw_ar9287_set_board_va
593 pModal = &eep->modalHeader;
595 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
596 + REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
598 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
599 regChainOffset = i * 0x1000;
601 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
602 - pModal->antCtrlChain[i]);
603 + le32_to_cpu(pModal->antCtrlChain[i]));
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,
611 - return ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
612 + __le16 spur_ch = ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
614 + return le16_to_cpu(spur_ch);
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
622 static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
624 - u16 version = ah->eeprom.def.baseEepHeader.version;
625 + u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
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
631 static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
633 - u16 version = ah->eeprom.def.baseEepHeader.version;
634 + u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
636 return version & AR5416_EEP_VER_MINOR_MASK;
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)
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]));
666 @@ -206,6 +206,7 @@ static u32 ath9k_hw_def_dump_eeprom(stru
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);
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
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);
701 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
702 @@ -273,61 +274,40 @@ static int ath9k_hw_def_check_eeprom(str
706 - el = swab16(eep->baseEepHeader.length);
707 + el = swab16((__force u16)eep->baseEepHeader.length);
709 - el = eep->baseEepHeader.length;
710 + el = le16_to_cpu(eep->baseEepHeader.length);
712 el = min(el / sizeof(u16), SIZE_EEPROM_DEF);
713 if (!ath9k_hw_nvram_validate_checksum(ah, el))
721 - word = swab16(eep->baseEepHeader.length);
722 - eep->baseEepHeader.length = word;
724 - word = swab16(eep->baseEepHeader.checksum);
725 - eep->baseEepHeader.checksum = word;
727 - word = swab16(eep->baseEepHeader.version);
728 - eep->baseEepHeader.version = word;
730 - word = swab16(eep->baseEepHeader.regDmn[0]);
731 - eep->baseEepHeader.regDmn[0] = word;
733 - word = swab16(eep->baseEepHeader.regDmn[1]);
734 - eep->baseEepHeader.regDmn[1] = word;
736 - word = swab16(eep->baseEepHeader.rfSilent);
737 - eep->baseEepHeader.rfSilent = word;
739 - word = swab16(eep->baseEepHeader.blueToothOptions);
740 - eep->baseEepHeader.blueToothOptions = word;
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);
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);
760 - for (i = 0; i < AR5416_MAX_CHAINS; i++) {
761 - integer = swab32(pModal->antCtrlChain[i]);
762 - pModal->antCtrlChain[i] = integer;
764 - for (i = 0; i < 3; i++) {
765 - word = swab16(pModal->xpaBiasLvlFreq[i]);
766 - pModal->xpaBiasLvlFreq[i] = word;
768 + for (i = 0; i < AR5416_MAX_CHAINS; i++)
769 + EEPROM_FIELD_SWAB32(pModal->antCtrlChain[i]);
771 - for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
772 - word = swab16(pModal->spurChans[i].spurChan);
773 - pModal->spurChans[i].spurChan = word;
775 + for (i = 0; i < 3; i++)
776 + EEPROM_FIELD_SWAB16(pModal->xpaBiasLvlFreq[i]);
778 + for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
779 + EEPROM_FIELD_SWAB16(
780 + pModal->spurChans[i].spurChan);
784 @@ -337,7 +317,7 @@ static int ath9k_hw_def_check_eeprom(str
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;
793 @@ -370,13 +350,13 @@ static u32 ath9k_hw_def_get_eeprom(struc
795 return get_unaligned_be16(pBase->macAddr + 4);
797 - return pBase->regDmn[0];
798 + return le16_to_cpu(pBase->regDmn[0]);
800 - return pBase->deviceCap;
801 + return le16_to_cpu(pBase->deviceCap);
803 return pBase->opCapFlags;
805 - return pBase->rfSilent;
806 + return le16_to_cpu(pBase->rfSilent);
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;
816 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
817 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
818 + antCtrlCommon = le32_to_cpu(pModal->antCtrlCommon);
820 - REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
821 + REG_WRITE(ah, AR_PHY_SWITCH_COM, antCtrlCommon & 0xffff);
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;
828 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
829 - pModal->antCtrlChain[i]);
830 + le32_to_cpu(pModal->antCtrlChain[i]));
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)
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;
843 @@ -1315,7 +1297,9 @@ static void ath9k_hw_def_set_txpower(str
845 static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
847 - return ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
848 + __le16 spch = ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
850 + return le16_to_cpu(spch);
853 static u8 ath9k_hw_def_get_eepmisc(struct ath_hw *ah)