555-ath9k-Make-the-EEPROM-swapping-check-use-the-eepmisc.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. From 1f796f9265c10384a274ac330f671ef4ac6d56e5 Mon Sep 17 00:00:00 2001
  2. From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
  3. Date: Mon, 3 Oct 2016 00:29:12 +0200
  4. Subject: [v2 PATCH 6/7] ath9k: Make the EEPROM swapping check use the eepmisc
  5. register
  6. There are two ways of swapping the EEPROM data in the ath9k driver:
  7. 1) swab16 based on the first two EEPROM "magic" bytes (same for all
  8. EEPROM formats)
  9. 2) field and EEPROM format specific swab16/swab32 (different for
  10. eeprom_def, eeprom_4k and eeprom_9287)
  11. The result of the first check was used to also enable the second swap.
  12. This behavior seems incorrect, since the data may only be byte-swapped
  13. (afterwards the data could be in the correct endianness).
  14. Thus we introduce a separate check based on the "eepmisc" register
  15. (which is part of the EEPROM data). When bit 0 is set, then the EEPROM
  16. format specific values are in "big endian". This is also done by the
  17. FreeBSD kernel, see [0] for example.
  18. This allows us to parse EEPROMs with the "correct" magic bytes but
  19. swapped EEPROM format specific values. These EEPROMs (mostly found in
  20. lantiq and broadcom based big endian MIPS based devices) only worked
  21. due to platform specific "hacks" which swapped the EEPROM so the
  22. magic was inverted, which also enabled the format specific swapping.
  23. With this patch the old behavior is still supported, but neither
  24. recommended nor needed anymore.
  25. [0]
  26. https://github.com/freebsd/freebsd/blob/50719b56d9ce8d7d4beb53b16e9edb2e9a4a7a18/sys/dev/ath/ath_hal/ah_eeprom_9287.c#L351
  27. Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
  28. ---
  29. drivers/net/wireless/ath/ath9k/eeprom.c | 57 ++++++++++++++++++++++++---------
  30. 1 file changed, 41 insertions(+), 16 deletions(-)
  31. --- a/drivers/net/wireless/ath/ath9k/eeprom.c
  32. +++ b/drivers/net/wireless/ath/ath9k/eeprom.c
  33. @@ -155,11 +155,19 @@ bool ath9k_hw_nvram_read(struct ath_hw *
  34. return ret;
  35. }
  36. +#ifdef __BIG_ENDIAN
  37. +#define EXPECTED_EEPMISC_ENDIAN AR5416_EEPMISC_BIG_ENDIAN
  38. +#else
  39. +#define EXPECTED_EEPMISC_ENDIAN 0
  40. +#endif
  41. +
  42. int ath9k_hw_nvram_swap_data(struct ath_hw *ah, bool *swap_needed, int size)
  43. {
  44. u16 magic;
  45. u16 *eepdata;
  46. + u8 eepmisc;
  47. int i;
  48. + bool needs_byteswap = false;
  49. struct ath_common *common = ath9k_hw_common(ah);
  50. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  51. @@ -167,36 +175,53 @@ int ath9k_hw_nvram_swap_data(struct ath_
  52. return -EIO;
  53. }
  54. - *swap_needed = false;
  55. if (swab16(magic) == AR5416_EEPROM_MAGIC) {
  56. + needs_byteswap = true;
  57. + ath_dbg(common, EEPROM,
  58. + "EEPROM needs byte-swapping to correct endianness.\n");
  59. + } else if (magic != AR5416_EEPROM_MAGIC) {
  60. + if (ath9k_hw_use_flash(ah)) {
  61. + ath_dbg(common, EEPROM,
  62. + "Ignoring invalid EEPROM magic (0x%04x).\n",
  63. + magic);
  64. + } else {
  65. + ath_err(common,
  66. + "Invalid EEPROM magic (0x%04x).\n", magic);
  67. + return -EINVAL;
  68. + }
  69. + }
  70. +
  71. + if (needs_byteswap) {
  72. if (ah->ah_flags & AH_NO_EEP_SWAP) {
  73. ath_info(common,
  74. "Ignoring endianness difference in EEPROM magic bytes.\n");
  75. } else {
  76. - *swap_needed = true;
  77. - }
  78. - } else if (magic != AR5416_EEPROM_MAGIC) {
  79. - if (ath9k_hw_use_flash(ah))
  80. - return 0;
  81. + eepdata = (u16 *)(&ah->eeprom);
  82. - ath_err(common,
  83. - "Invalid EEPROM Magic (0x%04x).\n", magic);
  84. - return -EINVAL;
  85. + for (i = 0; i < size; i++)
  86. + eepdata[i] = swab16(eepdata[i]);
  87. + }
  88. }
  89. - eepdata = (u16 *)(&ah->eeprom);
  90. -
  91. - if (*swap_needed) {
  92. - ath_dbg(common, EEPROM,
  93. - "EEPROM Endianness is not native.. Changing.\n");
  94. + *swap_needed = false;
  95. - for (i = 0; i < size; i++)
  96. - eepdata[i] = swab16(eepdata[i]);
  97. + eepmisc = ah->eep_ops->get_eepmisc(ah);
  98. + if ((eepmisc & AR5416_EEPMISC_BIG_ENDIAN) != EXPECTED_EEPMISC_ENDIAN) {
  99. + if (ah->ah_flags & AH_NO_EEP_SWAP) {
  100. + ath_info(common,
  101. + "Ignoring endianness difference in eepmisc register.\n");
  102. + } else {
  103. + *swap_needed = true;
  104. + ath_dbg(common, EEPROM,
  105. + "EEPROM needs swapping according to the eepmisc register.\n");
  106. + }
  107. }
  108. return 0;
  109. }
  110. +#undef EXPECTED_EEPMISC_VAL
  111. +
  112. bool ath9k_hw_nvram_validate_checksum(struct ath_hw *ah, int size)
  113. {
  114. u32 i, sum = 0;