Fresh pull from upstream
[librecmc/librecmc.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 +               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);
361  
362 -               for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
363 -                       integer = swab32(eep->modalHeader.antCtrlChain[i]);
364 -                       eep->modalHeader.antCtrlChain[i] = integer;
365 -               }
366 +               for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++)
367 +                       EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
368  
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;
372 -               }
373 +               for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
374 +                       EEPROM_FIELD_SWAB16(
375 +                               eep->modalHeader.spurChans[i].spurChan);
376         }
377  
378         if (!ath9k_hw_nvram_check_version(ah, AR5416_EEP_VER,
379 @@ -270,13 +248,13 @@ static u32 ath9k_hw_4k_get_eeprom(struct
380         case EEP_MAC_MSW:
381                 return get_unaligned_be16(pBase->macAddr + 4);
382         case EEP_REG_0:
383 -               return pBase->regDmn[0];
384 +               return le16_to_cpu(pBase->regDmn[0]);
385         case EEP_OP_CAP:
386 -               return pBase->deviceCap;
387 +               return le16_to_cpu(pBase->deviceCap);
388         case EEP_OP_MODE:
389                 return pBase->opCapFlags;
390         case EEP_RF_SILENT:
391 -               return pBase->rfSilent;
392 +               return le16_to_cpu(pBase->rfSilent);
393         case EEP_OB_2:
394                 return pModal->ob_0;
395         case EEP_DB_2:
396 @@ -724,7 +702,7 @@ static void ath9k_hw_4k_set_gain(struct
397  {
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);
402  
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;
407         txRxAttenLocal = 23;
408  
409 -       REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
410 +       REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
411  
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
415  
416  static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
417  {
418 -       return ah->eeprom.map4k.modalHeader.spurChans[i].spurChan;
419 +       return le16_to_cpu(ah->eeprom.map4k.modalHeader.spurChans[i].spurChan);
420  }
421  
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
425 @@ -22,7 +22,7 @@
426  
427  static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
428  {
429 -       u16 version = ah->eeprom.map9287.baseEepHeader.version;
430 +       u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
431  
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
435  
436  static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
437  {
438 -       u16 version = ah->eeprom.map9287.baseEepHeader.version;
439 +       u16 version = le16_to_cpu(ah->eeprom.map9287.baseEepHeader.version);
440  
441         return version & AR5416_EEP_VER_MINOR_MASK;
442  }
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)
446  {
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
457  {
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);
461  
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
465  
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);
491  
492 @@ -182,8 +183,7 @@ static u32 ath9k_hw_ar9287_dump_eeprom(s
493  
494  static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
495  {
496 -       u32 el, integer;
497 -       u16 word;
498 +       u32 el;
499         int i, err;
500         bool need_swap;
501         struct ar9287_eeprom *eep = &ah->eeprom.map9287;
502 @@ -193,51 +193,31 @@ static int ath9k_hw_ar9287_check_eeprom(
503                 return err;
504  
505         if (need_swap)
506 -               el = swab16(eep->baseEepHeader.length);
507 +               el = swab16((__force u16)eep->baseEepHeader.length);
508         else
509 -               el = eep->baseEepHeader.length;
510 +               el = le16_to_cpu(eep->baseEepHeader.length);
511  
512         el = min(el / sizeof(u16), SIZE_EEPROM_AR9287);
513         if (!ath9k_hw_nvram_validate_checksum(ah, el))
514                 return -EINVAL;
515  
516         if (need_swap) {
517 -               word = swab16(eep->baseEepHeader.length);
518 -               eep->baseEepHeader.length = word;
519 -
520 -               word = swab16(eep->baseEepHeader.checksum);
521 -               eep->baseEepHeader.checksum = word;
522 -
523 -               word = swab16(eep->baseEepHeader.version);
524 -               eep->baseEepHeader.version = word;
525 -
526 -               word = swab16(eep->baseEepHeader.regDmn[0]);
527 -               eep->baseEepHeader.regDmn[0] = word;
528 -
529 -               word = swab16(eep->baseEepHeader.regDmn[1]);
530 -               eep->baseEepHeader.regDmn[1] = word;
531 -
532 -               word = swab16(eep->baseEepHeader.rfSilent);
533 -               eep->baseEepHeader.rfSilent = word;
534 -
535 -               word = swab16(eep->baseEepHeader.blueToothOptions);
536 -               eep->baseEepHeader.blueToothOptions = word;
537 -
538 -               word = swab16(eep->baseEepHeader.deviceCap);
539 -               eep->baseEepHeader.deviceCap = word;
540 -
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);
552  
553 -               for (i = 0; i < AR9287_MAX_CHAINS; i++) {
554 -                       integer = swab32(eep->modalHeader.antCtrlChain[i]);
555 -                       eep->modalHeader.antCtrlChain[i] = integer;
556 -               }
557 +               for (i = 0; i < AR9287_MAX_CHAINS; i++)
558 +                       EEPROM_FIELD_SWAB32(eep->modalHeader.antCtrlChain[i]);
559  
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;
563 -               }
564 +               for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
565 +                       EEPROM_FIELD_SWAB16(
566 +                               eep->modalHeader.spurChans[i].spurChan);
567         }
568  
569         if (!ath9k_hw_nvram_check_version(ah, AR9287_EEP_VER,
570 @@ -267,13 +247,13 @@ static u32 ath9k_hw_ar9287_get_eeprom(st
571         case EEP_MAC_MSW:
572                 return get_unaligned_be16(pBase->macAddr + 4);
573         case EEP_REG_0:
574 -               return pBase->regDmn[0];
575 +               return le16_to_cpu(pBase->regDmn[0]);
576         case EEP_OP_CAP:
577 -               return pBase->deviceCap;
578 +               return le16_to_cpu(pBase->deviceCap);
579         case EEP_OP_MODE:
580                 return pBase->opCapFlags;
581         case EEP_RF_SILENT:
582 -               return pBase->rfSilent;
583 +               return le16_to_cpu(pBase->rfSilent);
584         case EEP_TX_MASK:
585                 return pBase->txMask;
586         case EEP_RX_MASK:
587 @@ -878,13 +858,13 @@ static void ath9k_hw_ar9287_set_board_va
588  
589         pModal = &eep->modalHeader;
590  
591 -       REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
592 +       REG_WRITE(ah, AR_PHY_SWITCH_COM, le32_to_cpu(pModal->antCtrlCommon));
593  
594         for (i = 0; i < AR9287_MAX_CHAINS; i++) {
595                 regChainOffset = i * 0x1000;
596  
597                 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
598 -                         pModal->antCtrlChain[i]);
599 +                         le32_to_cpu(pModal->antCtrlChain[i]));
600  
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,
605                                             u16 i, bool is2GHz)
606  {
607 -       return ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
608 +       __le16 spur_ch = ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
609 +
610 +       return le16_to_cpu(spur_ch);
611  }
612  
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
617  
618  static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
619  {
620 -       u16 version = ah->eeprom.def.baseEepHeader.version;
621 +       u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
622  
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
626  
627  static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
628  {
629 -       u16 version = ah->eeprom.def.baseEepHeader.version;
630 +       u16 version = le16_to_cpu(ah->eeprom.def.baseEepHeader.version);
631  
632         return version & AR5416_EEP_VER_MINOR_MASK;
633  }
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)
637  {
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]));
659  
660         return len;
661  }
662 @@ -206,6 +206,7 @@ static u32 ath9k_hw_def_dump_eeprom(stru
663  {
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);
667  
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
671  
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);
696  
697         len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
698 @@ -273,61 +274,40 @@ static int ath9k_hw_def_check_eeprom(str
699                 return err;
700  
701         if (need_swap)
702 -               el = swab16(eep->baseEepHeader.length);
703 +               el = swab16((__force u16)eep->baseEepHeader.length);
704         else
705 -               el = eep->baseEepHeader.length;
706 +               el = le16_to_cpu(eep->baseEepHeader.length);
707  
708         el = min(el / sizeof(u16), SIZE_EEPROM_DEF);
709         if (!ath9k_hw_nvram_validate_checksum(ah, el))
710                 return -EINVAL;
711  
712         if (need_swap) {
713 -               u32 integer, j;
714 -               u16 word;
715 -
716 -               word = swab16(eep->baseEepHeader.length);
717 -               eep->baseEepHeader.length = word;
718 -
719 -               word = swab16(eep->baseEepHeader.checksum);
720 -               eep->baseEepHeader.checksum = word;
721 -
722 -               word = swab16(eep->baseEepHeader.version);
723 -               eep->baseEepHeader.version = word;
724 -
725 -               word = swab16(eep->baseEepHeader.regDmn[0]);
726 -               eep->baseEepHeader.regDmn[0] = word;
727 -
728 -               word = swab16(eep->baseEepHeader.regDmn[1]);
729 -               eep->baseEepHeader.regDmn[1] = word;
730 -
731 -               word = swab16(eep->baseEepHeader.rfSilent);
732 -               eep->baseEepHeader.rfSilent = word;
733 -
734 -               word = swab16(eep->baseEepHeader.blueToothOptions);
735 -               eep->baseEepHeader.blueToothOptions = word;
736 +               u32 j;
737  
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);
748  
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);
755  
756 -                       for (i = 0; i < AR5416_MAX_CHAINS; i++) {
757 -                               integer = swab32(pModal->antCtrlChain[i]);
758 -                               pModal->antCtrlChain[i] = integer;
759 -                       }
760 -                       for (i = 0; i < 3; i++) {
761 -                               word = swab16(pModal->xpaBiasLvlFreq[i]);
762 -                               pModal->xpaBiasLvlFreq[i] = word;
763 -                       }
764 +                       for (i = 0; i < AR5416_MAX_CHAINS; i++)
765 +                               EEPROM_FIELD_SWAB32(pModal->antCtrlChain[i]);
766  
767 -                       for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
768 -                               word = swab16(pModal->spurChans[i].spurChan);
769 -                               pModal->spurChans[i].spurChan = word;
770 -                       }
771 +                       for (i = 0; i < 3; i++)
772 +                               EEPROM_FIELD_SWAB16(pModal->xpaBiasLvlFreq[i]);
773 +
774 +                       for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++)
775 +                               EEPROM_FIELD_SWAB16(
776 +                                       pModal->spurChans[i].spurChan);
777                 }
778         }
779  
780 @@ -337,7 +317,7 @@ static int ath9k_hw_def_check_eeprom(str
781  
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;
788  
789 @@ -370,13 +350,13 @@ static u32 ath9k_hw_def_get_eeprom(struc
790         case EEP_MAC_MSW:
791                 return get_unaligned_be16(pBase->macAddr + 4);
792         case EEP_REG_0:
793 -               return pBase->regDmn[0];
794 +               return le16_to_cpu(pBase->regDmn[0]);
795         case EEP_OP_CAP:
796 -               return pBase->deviceCap;
797 +               return le16_to_cpu(pBase->deviceCap);
798         case EEP_OP_MODE:
799                 return pBase->opCapFlags;
800         case EEP_RF_SILENT:
801 -               return pBase->rfSilent;
802 +               return le16_to_cpu(pBase->rfSilent);
803         case EEP_OB_5:
804                 return pModal[0].ob;
805         case EEP_DB_5:
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;
809         u8 txRxAttenLocal;
810 +       u32 antCtrlCommon;
811  
812         pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
813         txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
814 +       antCtrlCommon = le32_to_cpu(pModal->antCtrlCommon);
815  
816 -       REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
817 +       REG_WRITE(ah, AR_PHY_SWITCH_COM, antCtrlCommon & 0xffff);
818  
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;
823  
824                 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
825 -                         pModal->antCtrlChain[i]);
826 +                         le32_to_cpu(pModal->antCtrlChain[i]));
827  
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)
833  {
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;
838         u8 biaslevel;
839 @@ -1315,7 +1297,9 @@ static void ath9k_hw_def_set_txpower(str
840  
841  static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
842  {
843 -       return ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
844 +       __le16 spch = ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
845 +
846 +       return le16_to_cpu(spch);
847  }
848  
849  static u8 ath9k_hw_def_get_eepmisc(struct ath_hw *ah)