iwl-agn-ucode.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/sched.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. #include "iwl-io.h"
  36. #include "iwl-agn-hw.h"
  37. /*
  38. * ucode
  39. */
  40. static int iwlagn_load_section(struct iwl_priv *priv, const char *name,
  41. struct fw_desc *image, u32 dst_addr)
  42. {
  43. dma_addr_t phy_addr = image->p_addr;
  44. u32 byte_cnt = image->len;
  45. int ret;
  46. priv->ucode_write_complete = 0;
  47. iwl_write_direct32(priv,
  48. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  49. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  50. iwl_write_direct32(priv,
  51. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  52. iwl_write_direct32(priv,
  53. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  54. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  55. iwl_write_direct32(priv,
  56. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
  57. (iwl_get_dma_hi_addr(phy_addr)
  58. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
  59. iwl_write_direct32(priv,
  60. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  61. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  62. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  63. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  64. iwl_write_direct32(priv,
  65. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  66. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  67. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
  68. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  69. IWL_DEBUG_INFO(priv, "%s uCode section being loaded...\n", name);
  70. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  71. priv->ucode_write_complete, 5 * HZ);
  72. if (ret == -ERESTARTSYS) {
  73. IWL_ERR(priv, "Could not load the %s uCode section due "
  74. "to interrupt\n", name);
  75. return ret;
  76. }
  77. if (!ret) {
  78. IWL_ERR(priv, "Could not load the %s uCode section\n",
  79. name);
  80. return -ETIMEDOUT;
  81. }
  82. return 0;
  83. }
  84. static int iwlagn_load_given_ucode(struct iwl_priv *priv,
  85. struct fw_desc *inst_image,
  86. struct fw_desc *data_image)
  87. {
  88. int ret = 0;
  89. ret = iwlagn_load_section(priv, "INST", inst_image,
  90. IWLAGN_RTC_INST_LOWER_BOUND);
  91. if (ret)
  92. return ret;
  93. return iwlagn_load_section(priv, "DATA", data_image,
  94. IWLAGN_RTC_DATA_LOWER_BOUND);
  95. }
  96. int iwlagn_load_ucode(struct iwl_priv *priv)
  97. {
  98. int ret = 0;
  99. /* check whether init ucode should be loaded, or rather runtime ucode */
  100. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  101. IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n");
  102. ret = iwlagn_load_given_ucode(priv,
  103. &priv->ucode_init, &priv->ucode_init_data);
  104. if (!ret) {
  105. IWL_DEBUG_INFO(priv, "Init ucode load complete.\n");
  106. priv->ucode_type = UCODE_INIT;
  107. }
  108. } else {
  109. IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. "
  110. "Loading runtime ucode...\n");
  111. ret = iwlagn_load_given_ucode(priv,
  112. &priv->ucode_code, &priv->ucode_data);
  113. if (!ret) {
  114. IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n");
  115. priv->ucode_type = UCODE_RT;
  116. }
  117. }
  118. return ret;
  119. }
  120. #define IWL_UCODE_GET(item) \
  121. static u32 iwlagn_ucode_get_##item(const struct iwl_ucode_header *ucode,\
  122. u32 api_ver) \
  123. { \
  124. if (api_ver <= 2) \
  125. return le32_to_cpu(ucode->u.v1.item); \
  126. return le32_to_cpu(ucode->u.v2.item); \
  127. }
  128. static u32 iwlagn_ucode_get_header_size(u32 api_ver)
  129. {
  130. if (api_ver <= 2)
  131. return UCODE_HEADER_SIZE(1);
  132. return UCODE_HEADER_SIZE(2);
  133. }
  134. static u32 iwlagn_ucode_get_build(const struct iwl_ucode_header *ucode,
  135. u32 api_ver)
  136. {
  137. if (api_ver <= 2)
  138. return 0;
  139. return le32_to_cpu(ucode->u.v2.build);
  140. }
  141. static u8 *iwlagn_ucode_get_data(const struct iwl_ucode_header *ucode,
  142. u32 api_ver)
  143. {
  144. if (api_ver <= 2)
  145. return (u8 *) ucode->u.v1.data;
  146. return (u8 *) ucode->u.v2.data;
  147. }
  148. IWL_UCODE_GET(inst_size);
  149. IWL_UCODE_GET(data_size);
  150. IWL_UCODE_GET(init_size);
  151. IWL_UCODE_GET(init_data_size);
  152. IWL_UCODE_GET(boot_size);
  153. struct iwl_ucode_ops iwlagn_ucode = {
  154. .get_header_size = iwlagn_ucode_get_header_size,
  155. .get_build = iwlagn_ucode_get_build,
  156. .get_inst_size = iwlagn_ucode_get_inst_size,
  157. .get_data_size = iwlagn_ucode_get_data_size,
  158. .get_init_size = iwlagn_ucode_get_init_size,
  159. .get_init_data_size = iwlagn_ucode_get_init_data_size,
  160. .get_boot_size = iwlagn_ucode_get_boot_size,
  161. .get_data = iwlagn_ucode_get_data,
  162. };