eeprom.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Intel Wireless Multicomm 3200 WiFi driver
  3. *
  4. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Intel Corporation nor the names of its
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. *
  33. * Intel Corporation <ilw@linux.intel.com>
  34. * Samuel Ortiz <samuel.ortiz@intel.com>
  35. * Zhu Yi <yi.zhu@intel.com>
  36. *
  37. */
  38. #include <linux/kernel.h>
  39. #include <linux/slab.h>
  40. #include "iwm.h"
  41. #include "umac.h"
  42. #include "commands.h"
  43. #include "eeprom.h"
  44. static struct iwm_eeprom_entry eeprom_map[] = {
  45. [IWM_EEPROM_SIG] =
  46. {"Signature", IWM_EEPROM_SIG_OFF, IWM_EEPROM_SIG_LEN},
  47. [IWM_EEPROM_VERSION] =
  48. {"Version", IWM_EEPROM_VERSION_OFF, IWM_EEPROM_VERSION_LEN},
  49. [IWM_EEPROM_OEM_HW_VERSION] =
  50. {"OEM HW version", IWM_EEPROM_OEM_HW_VERSION_OFF,
  51. IWM_EEPROM_OEM_HW_VERSION_LEN},
  52. [IWM_EEPROM_MAC_VERSION] =
  53. {"MAC version", IWM_EEPROM_MAC_VERSION_OFF, IWM_EEPROM_MAC_VERSION_LEN},
  54. [IWM_EEPROM_CARD_ID] =
  55. {"Card ID", IWM_EEPROM_CARD_ID_OFF, IWM_EEPROM_CARD_ID_LEN},
  56. [IWM_EEPROM_RADIO_CONF] =
  57. {"Radio config", IWM_EEPROM_RADIO_CONF_OFF, IWM_EEPROM_RADIO_CONF_LEN},
  58. [IWM_EEPROM_SKU_CAP] =
  59. {"SKU capabilities", IWM_EEPROM_SKU_CAP_OFF, IWM_EEPROM_SKU_CAP_LEN},
  60. [IWM_EEPROM_FAT_CHANNELS_CAP] =
  61. {"HT channels capabilities", IWM_EEPROM_FAT_CHANNELS_CAP_OFF,
  62. IWM_EEPROM_FAT_CHANNELS_CAP_LEN},
  63. [IWM_EEPROM_CALIB_RXIQ_OFFSET] =
  64. {"RX IQ offset", IWM_EEPROM_CALIB_RXIQ_OFF, IWM_EEPROM_INDIRECT_LEN},
  65. [IWM_EEPROM_CALIB_RXIQ] =
  66. {"Calib RX IQ", 0, IWM_EEPROM_CALIB_RXIQ_LEN},
  67. };
  68. static int iwm_eeprom_read(struct iwm_priv *iwm, u8 eeprom_id)
  69. {
  70. int ret;
  71. u32 entry_size, chunk_size, data_offset = 0, addr_offset = 0;
  72. u32 addr;
  73. struct iwm_udma_wifi_cmd udma_cmd;
  74. struct iwm_umac_cmd umac_cmd;
  75. struct iwm_umac_cmd_eeprom_proxy eeprom_cmd;
  76. if (eeprom_id > (IWM_EEPROM_LAST - 1))
  77. return -EINVAL;
  78. entry_size = eeprom_map[eeprom_id].length;
  79. if (eeprom_id >= IWM_EEPROM_INDIRECT_DATA) {
  80. /* indirect data */
  81. u32 off_id = eeprom_id - IWM_EEPROM_INDIRECT_DATA +
  82. IWM_EEPROM_INDIRECT_OFFSET;
  83. eeprom_map[eeprom_id].offset =
  84. *(u16 *)(iwm->eeprom + eeprom_map[off_id].offset) << 1;
  85. }
  86. addr = eeprom_map[eeprom_id].offset;
  87. udma_cmd.eop = 1;
  88. udma_cmd.credit_group = 0x4;
  89. udma_cmd.ra_tid = UMAC_HDI_ACT_TBL_IDX_HOST_CMD;
  90. udma_cmd.lmac_offset = 0;
  91. umac_cmd.id = UMAC_CMD_OPCODE_EEPROM_PROXY;
  92. umac_cmd.resp = 1;
  93. while (entry_size > 0) {
  94. chunk_size = min_t(u32, entry_size, IWM_MAX_EEPROM_DATA_LEN);
  95. eeprom_cmd.hdr.type =
  96. cpu_to_le32(IWM_UMAC_CMD_EEPROM_TYPE_READ);
  97. eeprom_cmd.hdr.offset = cpu_to_le32(addr + addr_offset);
  98. eeprom_cmd.hdr.len = cpu_to_le32(chunk_size);
  99. ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd,
  100. &umac_cmd, &eeprom_cmd,
  101. sizeof(struct iwm_umac_cmd_eeprom_proxy));
  102. if (ret < 0) {
  103. IWM_ERR(iwm, "Couldn't read eeprom\n");
  104. return ret;
  105. }
  106. ret = iwm_notif_handle(iwm, UMAC_CMD_OPCODE_EEPROM_PROXY,
  107. IWM_SRC_UMAC, 2*HZ);
  108. if (ret < 0) {
  109. IWM_ERR(iwm, "Did not get any eeprom answer\n");
  110. return ret;
  111. }
  112. data_offset += chunk_size;
  113. addr_offset += chunk_size;
  114. entry_size -= chunk_size;
  115. }
  116. return 0;
  117. }
  118. u8 *iwm_eeprom_access(struct iwm_priv *iwm, u8 eeprom_id)
  119. {
  120. if (!iwm->eeprom)
  121. return ERR_PTR(-ENODEV);
  122. return iwm->eeprom + eeprom_map[eeprom_id].offset;
  123. }
  124. int iwm_eeprom_fat_channels(struct iwm_priv *iwm)
  125. {
  126. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  127. struct ieee80211_supported_band *band;
  128. u16 *channels, i;
  129. channels = (u16 *)iwm_eeprom_access(iwm, IWM_EEPROM_FAT_CHANNELS_CAP);
  130. if (IS_ERR(channels))
  131. return PTR_ERR(channels);
  132. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  133. band->ht_cap.ht_supported = true;
  134. for (i = 0; i < IWM_EEPROM_FAT_CHANNELS_24; i++)
  135. if (!(channels[i] & IWM_EEPROM_FAT_CHANNEL_ENABLED))
  136. band->ht_cap.ht_supported = false;
  137. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  138. band->ht_cap.ht_supported = true;
  139. for (i = IWM_EEPROM_FAT_CHANNELS_24; i < IWM_EEPROM_FAT_CHANNELS; i++)
  140. if (!(channels[i] & IWM_EEPROM_FAT_CHANNEL_ENABLED))
  141. band->ht_cap.ht_supported = false;
  142. return 0;
  143. }
  144. u32 iwm_eeprom_wireless_mode(struct iwm_priv *iwm)
  145. {
  146. u16 sku_cap;
  147. u32 wireless_mode = 0;
  148. sku_cap = *((u16 *)iwm_eeprom_access(iwm, IWM_EEPROM_SKU_CAP));
  149. if (sku_cap & IWM_EEPROM_SKU_CAP_BAND_24GHZ)
  150. wireless_mode |= WIRELESS_MODE_11G;
  151. if (sku_cap & IWM_EEPROM_SKU_CAP_BAND_52GHZ)
  152. wireless_mode |= WIRELESS_MODE_11A;
  153. if (sku_cap & IWM_EEPROM_SKU_CAP_11N_ENABLE)
  154. wireless_mode |= WIRELESS_MODE_11N;
  155. return wireless_mode;
  156. }
  157. int iwm_eeprom_init(struct iwm_priv *iwm)
  158. {
  159. int i, ret = 0;
  160. char name[32];
  161. iwm->eeprom = kzalloc(IWM_EEPROM_LEN, GFP_KERNEL);
  162. if (!iwm->eeprom)
  163. return -ENOMEM;
  164. for (i = IWM_EEPROM_FIRST; i < IWM_EEPROM_LAST; i++) {
  165. ret = iwm_eeprom_read(iwm, i);
  166. if (ret < 0) {
  167. IWM_ERR(iwm, "Couldn't read eeprom entry #%d: %s\n",
  168. i, eeprom_map[i].name);
  169. break;
  170. }
  171. }
  172. IWM_DBG_BOOT(iwm, DBG, "EEPROM dump:\n");
  173. for (i = IWM_EEPROM_FIRST; i < IWM_EEPROM_LAST; i++) {
  174. memset(name, 0, 32);
  175. sprintf(name, "%s: ", eeprom_map[i].name);
  176. IWM_HEXDUMP(iwm, DBG, BOOT, name,
  177. iwm->eeprom + eeprom_map[i].offset,
  178. eeprom_map[i].length);
  179. }
  180. return ret;
  181. }
  182. void iwm_eeprom_exit(struct iwm_priv *iwm)
  183. {
  184. kfree(iwm->eeprom);
  185. }