bmi.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _BMI_H_
  18. #define _BMI_H_
  19. #include "core.h"
  20. /*
  21. * Bootloader Messaging Interface (BMI)
  22. *
  23. * BMI is a very simple messaging interface used during initialization
  24. * to read memory, write memory, execute code, and to define an
  25. * application entry PC.
  26. *
  27. * It is used to download an application to QCA988x, to provide
  28. * patches to code that is already resident on QCA988x, and generally
  29. * to examine and modify state. The Host has an opportunity to use
  30. * BMI only once during bootup. Once the Host issues a BMI_DONE
  31. * command, this opportunity ends.
  32. *
  33. * The Host writes BMI requests to mailbox0, and reads BMI responses
  34. * from mailbox0. BMI requests all begin with a command
  35. * (see below for specific commands), and are followed by
  36. * command-specific data.
  37. *
  38. * Flow control:
  39. * The Host can only issue a command once the Target gives it a
  40. * "BMI Command Credit", using AR8K Counter #4. As soon as the
  41. * Target has completed a command, it issues another BMI Command
  42. * Credit (so the Host can issue the next command).
  43. *
  44. * BMI handles all required Target-side cache flushing.
  45. */
  46. /* Maximum data size used for BMI transfers */
  47. #define BMI_MAX_DATA_SIZE 256
  48. /* len = cmd + addr + length */
  49. #define BMI_MAX_CMDBUF_SIZE (BMI_MAX_DATA_SIZE + \
  50. sizeof(u32) + \
  51. sizeof(u32) + \
  52. sizeof(u32))
  53. /* BMI Commands */
  54. enum bmi_cmd_id {
  55. BMI_NO_COMMAND = 0,
  56. BMI_DONE = 1,
  57. BMI_READ_MEMORY = 2,
  58. BMI_WRITE_MEMORY = 3,
  59. BMI_EXECUTE = 4,
  60. BMI_SET_APP_START = 5,
  61. BMI_READ_SOC_REGISTER = 6,
  62. BMI_READ_SOC_WORD = 6,
  63. BMI_WRITE_SOC_REGISTER = 7,
  64. BMI_WRITE_SOC_WORD = 7,
  65. BMI_GET_TARGET_ID = 8,
  66. BMI_GET_TARGET_INFO = 8,
  67. BMI_ROMPATCH_INSTALL = 9,
  68. BMI_ROMPATCH_UNINSTALL = 10,
  69. BMI_ROMPATCH_ACTIVATE = 11,
  70. BMI_ROMPATCH_DEACTIVATE = 12,
  71. BMI_LZ_STREAM_START = 13, /* should be followed by LZ_DATA */
  72. BMI_LZ_DATA = 14,
  73. BMI_NVRAM_PROCESS = 15,
  74. };
  75. #define BMI_NVRAM_SEG_NAME_SZ 16
  76. #define BMI_PARAM_GET_EEPROM_BOARD_ID 0x10
  77. #define BMI_PARAM_GET_FLASH_BOARD_ID 0x8000
  78. #define BMI_PARAM_FLASH_SECTION_ALL 0x10000
  79. #define ATH10K_BMI_BOARD_ID_FROM_OTP_MASK 0x7c00
  80. #define ATH10K_BMI_BOARD_ID_FROM_OTP_LSB 10
  81. #define ATH10K_BMI_CHIP_ID_FROM_OTP_MASK 0x18000
  82. #define ATH10K_BMI_CHIP_ID_FROM_OTP_LSB 15
  83. #define ATH10K_BMI_BOARD_ID_STATUS_MASK 0xff
  84. struct bmi_cmd {
  85. __le32 id; /* enum bmi_cmd_id */
  86. union {
  87. struct {
  88. } done;
  89. struct {
  90. __le32 addr;
  91. __le32 len;
  92. } read_mem;
  93. struct {
  94. __le32 addr;
  95. __le32 len;
  96. u8 payload[0];
  97. } write_mem;
  98. struct {
  99. __le32 addr;
  100. __le32 param;
  101. } execute;
  102. struct {
  103. __le32 addr;
  104. } set_app_start;
  105. struct {
  106. __le32 addr;
  107. } read_soc_reg;
  108. struct {
  109. __le32 addr;
  110. __le32 value;
  111. } write_soc_reg;
  112. struct {
  113. } get_target_info;
  114. struct {
  115. __le32 rom_addr;
  116. __le32 ram_addr; /* or value */
  117. __le32 size;
  118. __le32 activate; /* 0=install, but dont activate */
  119. } rompatch_install;
  120. struct {
  121. __le32 patch_id;
  122. } rompatch_uninstall;
  123. struct {
  124. __le32 count;
  125. __le32 patch_ids[0]; /* length of @count */
  126. } rompatch_activate;
  127. struct {
  128. __le32 count;
  129. __le32 patch_ids[0]; /* length of @count */
  130. } rompatch_deactivate;
  131. struct {
  132. __le32 addr;
  133. } lz_start;
  134. struct {
  135. __le32 len; /* max BMI_MAX_DATA_SIZE */
  136. u8 payload[0]; /* length of @len */
  137. } lz_data;
  138. struct {
  139. u8 name[BMI_NVRAM_SEG_NAME_SZ];
  140. } nvram_process;
  141. u8 payload[BMI_MAX_CMDBUF_SIZE];
  142. };
  143. } __packed;
  144. union bmi_resp {
  145. struct {
  146. u8 payload[0];
  147. } read_mem;
  148. struct {
  149. __le32 result;
  150. } execute;
  151. struct {
  152. __le32 value;
  153. } read_soc_reg;
  154. struct {
  155. __le32 len;
  156. __le32 version;
  157. __le32 type;
  158. } get_target_info;
  159. struct {
  160. __le32 patch_id;
  161. } rompatch_install;
  162. struct {
  163. __le32 patch_id;
  164. } rompatch_uninstall;
  165. struct {
  166. /* 0 = nothing executed
  167. * otherwise = NVRAM segment return value */
  168. __le32 result;
  169. } nvram_process;
  170. u8 payload[BMI_MAX_CMDBUF_SIZE];
  171. } __packed;
  172. struct bmi_target_info {
  173. u32 version;
  174. u32 type;
  175. };
  176. /* in msec */
  177. #define BMI_COMMUNICATION_TIMEOUT_HZ (2 * HZ)
  178. #define BMI_CE_NUM_TO_TARG 0
  179. #define BMI_CE_NUM_TO_HOST 1
  180. void ath10k_bmi_start(struct ath10k *ar);
  181. int ath10k_bmi_done(struct ath10k *ar);
  182. int ath10k_bmi_get_target_info(struct ath10k *ar,
  183. struct bmi_target_info *target_info);
  184. int ath10k_bmi_read_memory(struct ath10k *ar, u32 address,
  185. void *buffer, u32 length);
  186. int ath10k_bmi_write_memory(struct ath10k *ar, u32 address,
  187. const void *buffer, u32 length);
  188. #define ath10k_bmi_read32(ar, item, val) \
  189. ({ \
  190. int ret; \
  191. u32 addr; \
  192. __le32 tmp; \
  193. \
  194. addr = host_interest_item_address(HI_ITEM(item)); \
  195. ret = ath10k_bmi_read_memory(ar, addr, (u8 *)&tmp, 4); \
  196. if (!ret) \
  197. *val = __le32_to_cpu(tmp); \
  198. ret; \
  199. })
  200. #define ath10k_bmi_write32(ar, item, val) \
  201. ({ \
  202. int ret; \
  203. u32 address; \
  204. __le32 v = __cpu_to_le32(val); \
  205. \
  206. address = host_interest_item_address(HI_ITEM(item)); \
  207. ret = ath10k_bmi_write_memory(ar, address, \
  208. (u8 *)&v, sizeof(v)); \
  209. ret; \
  210. })
  211. int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 param, u32 *result);
  212. int ath10k_bmi_lz_stream_start(struct ath10k *ar, u32 address);
  213. int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length);
  214. int ath10k_bmi_fast_download(struct ath10k *ar, u32 address,
  215. const void *buffer, u32 length);
  216. #endif /* _BMI_H_ */