eeprom.c (cc9b94029e9ef51787af908e9856b1eed314bc00) eeprom.c (68fbe792916cdf6c96def64c1bc50a39443a136a)
1/*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 141 unchanged lines hidden (view full) ---

150
151 if (!ret)
152 ath_dbg(common, EEPROM,
153 "unable to read eeprom region at offset %u\n", off);
154
155 return ret;
156}
157
1/*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 141 unchanged lines hidden (view full) ---

150
151 if (!ret)
152 ath_dbg(common, EEPROM,
153 "unable to read eeprom region at offset %u\n", off);
154
155 return ret;
156}
157
158#ifdef __BIG_ENDIAN
159#define EXPECTED_EEPMISC_ENDIAN AR5416_EEPMISC_BIG_ENDIAN
160#else
161#define EXPECTED_EEPMISC_ENDIAN 0
162#endif
163
158int ath9k_hw_nvram_swap_data(struct ath_hw *ah, bool *swap_needed, int size)
159{
160 u16 magic;
161 u16 *eepdata;
164int ath9k_hw_nvram_swap_data(struct ath_hw *ah, bool *swap_needed, int size)
165{
166 u16 magic;
167 u16 *eepdata;
168 u8 eepmisc;
162 int i;
169 int i;
170 bool needs_byteswap = false;
163 struct ath_common *common = ath9k_hw_common(ah);
164
165 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
166 ath_err(common, "Reading Magic # failed\n");
167 return -EIO;
168 }
169
171 struct ath_common *common = ath9k_hw_common(ah);
172
173 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
174 ath_err(common, "Reading Magic # failed\n");
175 return -EIO;
176 }
177
170 *swap_needed = false;
171 if (swab16(magic) == AR5416_EEPROM_MAGIC) {
178 if (swab16(magic) == AR5416_EEPROM_MAGIC) {
179 needs_byteswap = true;
180 ath_dbg(common, EEPROM,
181 "EEPROM needs byte-swapping to correct endianness.\n");
182 } else if (magic != AR5416_EEPROM_MAGIC) {
183 if (ath9k_hw_use_flash(ah)) {
184 ath_dbg(common, EEPROM,
185 "Ignoring invalid EEPROM magic (0x%04x).\n",
186 magic);
187 } else {
188 ath_err(common,
189 "Invalid EEPROM magic (0x%04x).\n", magic);
190 return -EINVAL;
191 }
192 }
193
194 if (needs_byteswap) {
172 if (ah->ah_flags & AH_NO_EEP_SWAP) {
173 ath_info(common,
174 "Ignoring endianness difference in EEPROM magic bytes.\n");
175 } else {
195 if (ah->ah_flags & AH_NO_EEP_SWAP) {
196 ath_info(common,
197 "Ignoring endianness difference in EEPROM magic bytes.\n");
198 } else {
176 *swap_needed = true;
177 }
178 } else if (magic != AR5416_EEPROM_MAGIC) {
179 if (ath9k_hw_use_flash(ah))
180 return 0;
199 eepdata = (u16 *)(&ah->eeprom);
181
200
182 ath_err(common,
183 "Invalid EEPROM Magic (0x%04x).\n", magic);
184 return -EINVAL;
201 for (i = 0; i < size; i++)
202 eepdata[i] = swab16(eepdata[i]);
203 }
185 }
186
204 }
205
187 eepdata = (u16 *)(&ah->eeprom);
206 *swap_needed = false;
188
207
189 if (*swap_needed) {
190 ath_dbg(common, EEPROM,
191 "EEPROM Endianness is not native.. Changing.\n");
192
193 for (i = 0; i < size; i++)
194 eepdata[i] = swab16(eepdata[i]);
208 eepmisc = ah->eep_ops->get_eepmisc(ah);
209 if ((eepmisc & AR5416_EEPMISC_BIG_ENDIAN) != EXPECTED_EEPMISC_ENDIAN) {
210 if (ah->ah_flags & AH_NO_EEP_SWAP) {
211 ath_info(common,
212 "Ignoring endianness difference in eepmisc register.\n");
213 } else {
214 *swap_needed = true;
215 ath_dbg(common, EEPROM,
216 "EEPROM needs swapping according to the eepmisc register.\n");
217 }
195 }
196
197 return 0;
198}
199
218 }
219
220 return 0;
221}
222
223#undef EXPECTED_EEPMISC_VAL
224
200bool ath9k_hw_nvram_validate_checksum(struct ath_hw *ah, int size)
201{
202 u32 i, sum = 0;
203 u16 *eepdata = (u16 *)(&ah->eeprom);
204 struct ath_common *common = ath9k_hw_common(ah);
205
206 for (i = 0; i < size; i++)
207 sum ^= eepdata[i];

--- 464 unchanged lines hidden ---
225bool ath9k_hw_nvram_validate_checksum(struct ath_hw *ah, int size)
226{
227 u32 i, sum = 0;
228 u16 *eepdata = (u16 *)(&ah->eeprom);
229 struct ath_common *common = ath9k_hw_common(ah);
230
231 for (i = 0; i < size; i++)
232 sum ^= eepdata[i];

--- 464 unchanged lines hidden ---