diff options
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/eeprom_4k.c')
-rw-r--r-- | drivers/net/wireless/ath/ath9k/eeprom_4k.c | 76 |
1 files changed, 15 insertions, 61 deletions
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_4k.c b/drivers/net/wireless/ath/ath9k/eeprom_4k.c index 4773da6dc6f2..5da0826bf1be 100644 --- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c +++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c | |||
@@ -177,74 +177,30 @@ static u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr, | |||
177 | } | 177 | } |
178 | #endif | 178 | #endif |
179 | 179 | ||
180 | |||
181 | #undef SIZE_EEPROM_4K | ||
182 | |||
183 | static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah) | 180 | static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah) |
184 | { | 181 | { |
185 | #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16)) | ||
186 | struct ath_common *common = ath9k_hw_common(ah); | ||
187 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; | 182 | struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k; |
188 | u16 *eepdata, temp, magic, magic2; | 183 | u32 el; |
189 | u32 sum = 0, el; | 184 | bool need_swap; |
190 | bool need_swap = false; | 185 | int i, err; |
191 | int i, addr; | ||
192 | 186 | ||
193 | 187 | err = ath9k_hw_nvram_swap_data(ah, &need_swap, SIZE_EEPROM_4K); | |
194 | if (!ath9k_hw_use_flash(ah)) { | 188 | if (err) |
195 | if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, | 189 | return err; |
196 | &magic)) { | ||
197 | ath_err(common, "Reading Magic # failed\n"); | ||
198 | return false; | ||
199 | } | ||
200 | |||
201 | ath_dbg(common, EEPROM, "Read Magic = 0x%04X\n", magic); | ||
202 | |||
203 | if (magic != AR5416_EEPROM_MAGIC) { | ||
204 | magic2 = swab16(magic); | ||
205 | |||
206 | if (magic2 == AR5416_EEPROM_MAGIC) { | ||
207 | need_swap = true; | ||
208 | eepdata = (u16 *) (&ah->eeprom); | ||
209 | |||
210 | for (addr = 0; addr < EEPROM_4K_SIZE; addr++) { | ||
211 | temp = swab16(*eepdata); | ||
212 | *eepdata = temp; | ||
213 | eepdata++; | ||
214 | } | ||
215 | } else { | ||
216 | ath_err(common, | ||
217 | "Invalid EEPROM Magic. Endianness mismatch.\n"); | ||
218 | return -EINVAL; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | ath_dbg(common, EEPROM, "need_swap = %s\n", | ||
224 | need_swap ? "True" : "False"); | ||
225 | 190 | ||
226 | if (need_swap) | 191 | if (need_swap) |
227 | el = swab16(ah->eeprom.map4k.baseEepHeader.length); | 192 | el = swab16(eep->baseEepHeader.length); |
228 | else | ||
229 | el = ah->eeprom.map4k.baseEepHeader.length; | ||
230 | |||
231 | if (el > sizeof(struct ar5416_eeprom_4k)) | ||
232 | el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16); | ||
233 | else | 193 | else |
234 | el = el / sizeof(u16); | 194 | el = eep->baseEepHeader.length; |
235 | 195 | ||
236 | eepdata = (u16 *)(&ah->eeprom); | 196 | el = min(el / sizeof(u16), SIZE_EEPROM_4K); |
237 | 197 | if (!ath9k_hw_nvram_validate_checksum(ah, el)) | |
238 | for (i = 0; i < el; i++) | 198 | return -EINVAL; |
239 | sum ^= *eepdata++; | ||
240 | 199 | ||
241 | if (need_swap) { | 200 | if (need_swap) { |
242 | u32 integer; | 201 | u32 integer; |
243 | u16 word; | 202 | u16 word; |
244 | 203 | ||
245 | ath_dbg(common, EEPROM, | ||
246 | "EEPROM Endianness is not native.. Changing\n"); | ||
247 | |||
248 | word = swab16(eep->baseEepHeader.length); | 204 | word = swab16(eep->baseEepHeader.length); |
249 | eep->baseEepHeader.length = word; | 205 | eep->baseEepHeader.length = word; |
250 | 206 | ||
@@ -283,17 +239,15 @@ static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah) | |||
283 | } | 239 | } |
284 | } | 240 | } |
285 | 241 | ||
286 | if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER || | 242 | if (!ath9k_hw_nvram_check_version(ah, AR5416_EEP_VER, |
287 | ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) { | 243 | AR5416_EEP_NO_BACK_VER)) |
288 | ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n", | ||
289 | sum, ah->eep_ops->get_eeprom_ver(ah)); | ||
290 | return -EINVAL; | 244 | return -EINVAL; |
291 | } | ||
292 | 245 | ||
293 | return 0; | 246 | return 0; |
294 | #undef EEPROM_4K_SIZE | ||
295 | } | 247 | } |
296 | 248 | ||
249 | #undef SIZE_EEPROM_4K | ||
250 | |||
297 | static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah, | 251 | static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah, |
298 | enum eeprom_param param) | 252 | enum eeprom_param param) |
299 | { | 253 | { |