fwdesc.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Shared CARL9170 Header
  3. *
  4. * Firmware descriptor format
  5. *
  6. * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; see the file COPYING. If not, see
  19. * http://www.gnu.org/licenses/.
  20. */
  21. #ifndef __CARL9170_SHARED_FWDESC_H
  22. #define __CARL9170_SHARED_FWDESC_H
  23. /* NOTE: Don't mess with the order of the flags! */
  24. enum carl9170fw_feature_list {
  25. /* Always set */
  26. CARL9170FW_DUMMY_FEATURE,
  27. /*
  28. * Indicates that this image has special boot block which prevents
  29. * legacy drivers to drive the firmware.
  30. */
  31. CARL9170FW_MINIBOOT,
  32. /* usb registers are initialized by the firmware */
  33. CARL9170FW_USB_INIT_FIRMWARE,
  34. /* command traps & notifications are send through EP2 */
  35. CARL9170FW_USB_RESP_EP2,
  36. /* usb download (app -> fw) stream */
  37. CARL9170FW_USB_DOWN_STREAM,
  38. /* usb upload (fw -> app) stream */
  39. CARL9170FW_USB_UP_STREAM,
  40. /* unusable - reserved to flag non-functional debug firmwares */
  41. CARL9170FW_UNUSABLE,
  42. /* AR9170_CMD_RF_INIT, AR9170_CMD_FREQ_START, AR9170_CMD_FREQUENCY */
  43. CARL9170FW_COMMAND_PHY,
  44. /* AR9170_CMD_EKEY, AR9170_CMD_DKEY */
  45. CARL9170FW_COMMAND_CAM,
  46. /* Firmware has a software Content After Beacon Queueing mechanism */
  47. CARL9170FW_WLANTX_CAB,
  48. /* The firmware is capable of responding to incoming BAR frames */
  49. CARL9170FW_HANDLE_BACK_REQ,
  50. /* GPIO Interrupt | CARL9170_RSP_GPIO */
  51. CARL9170FW_GPIO_INTERRUPT,
  52. /* Firmware PSM support | CARL9170_CMD_PSM */
  53. CARL9170FW_PSM,
  54. /* Firmware RX filter | CARL9170_CMD_RX_FILTER */
  55. CARL9170FW_RX_FILTER,
  56. /* Wake up on WLAN */
  57. CARL9170FW_WOL,
  58. /* Firmware supports PSM in the 5GHZ Band */
  59. CARL9170FW_FIXED_5GHZ_PSM,
  60. /* HW (ANI, CCA, MIB) tally counters */
  61. CARL9170FW_HW_COUNTERS,
  62. /* Firmware will pass BA when BARs are queued */
  63. CARL9170FW_RX_BA_FILTER,
  64. /* Firmware has support to write a byte at a time */
  65. CARL9170FW_HAS_WREGB_CMD,
  66. /* Pattern generator */
  67. CARL9170FW_PATTERN_GENERATOR,
  68. /* KEEP LAST */
  69. __CARL9170FW_FEATURE_NUM
  70. };
  71. #define OTUS_MAGIC "OTAR"
  72. #define MOTD_MAGIC "MOTD"
  73. #define FIX_MAGIC "FIX\0"
  74. #define DBG_MAGIC "DBG\0"
  75. #define CHK_MAGIC "CHK\0"
  76. #define TXSQ_MAGIC "TXSQ"
  77. #define WOL_MAGIC "WOL\0"
  78. #define LAST_MAGIC "LAST"
  79. #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
  80. #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
  81. #define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372)
  82. #define CARL9170FW_GET_DAY(d) (((d) % 31) + 1)
  83. #define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1)
  84. #define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10)
  85. #define CARL9170FW_MAGIC_SIZE 4
  86. struct carl9170fw_desc_head {
  87. u8 magic[CARL9170FW_MAGIC_SIZE];
  88. __le16 length;
  89. u8 min_ver;
  90. u8 cur_ver;
  91. } __packed;
  92. #define CARL9170FW_DESC_HEAD_SIZE \
  93. (sizeof(struct carl9170fw_desc_head))
  94. #define CARL9170FW_OTUS_DESC_MIN_VER 6
  95. #define CARL9170FW_OTUS_DESC_CUR_VER 7
  96. struct carl9170fw_otus_desc {
  97. struct carl9170fw_desc_head head;
  98. __le32 feature_set;
  99. __le32 fw_address;
  100. __le32 bcn_addr;
  101. __le16 bcn_len;
  102. __le16 miniboot_size;
  103. __le16 tx_frag_len;
  104. __le16 rx_max_frame_len;
  105. u8 tx_descs;
  106. u8 cmd_bufs;
  107. u8 api_ver;
  108. u8 vif_num;
  109. } __packed;
  110. #define CARL9170FW_OTUS_DESC_SIZE \
  111. (sizeof(struct carl9170fw_otus_desc))
  112. #define CARL9170FW_MOTD_STRING_LEN 24
  113. #define CARL9170FW_MOTD_RELEASE_LEN 20
  114. #define CARL9170FW_MOTD_DESC_MIN_VER 1
  115. #define CARL9170FW_MOTD_DESC_CUR_VER 2
  116. struct carl9170fw_motd_desc {
  117. struct carl9170fw_desc_head head;
  118. __le32 fw_year_month_day;
  119. char desc[CARL9170FW_MOTD_STRING_LEN];
  120. char release[CARL9170FW_MOTD_RELEASE_LEN];
  121. } __packed;
  122. #define CARL9170FW_MOTD_DESC_SIZE \
  123. (sizeof(struct carl9170fw_motd_desc))
  124. #define CARL9170FW_FIX_DESC_MIN_VER 1
  125. #define CARL9170FW_FIX_DESC_CUR_VER 2
  126. struct carl9170fw_fix_entry {
  127. __le32 address;
  128. __le32 mask;
  129. __le32 value;
  130. } __packed;
  131. struct carl9170fw_fix_desc {
  132. struct carl9170fw_desc_head head;
  133. struct carl9170fw_fix_entry data[0];
  134. } __packed;
  135. #define CARL9170FW_FIX_DESC_SIZE \
  136. (sizeof(struct carl9170fw_fix_desc))
  137. #define CARL9170FW_DBG_DESC_MIN_VER 1
  138. #define CARL9170FW_DBG_DESC_CUR_VER 3
  139. struct carl9170fw_dbg_desc {
  140. struct carl9170fw_desc_head head;
  141. __le32 bogoclock_addr;
  142. __le32 counter_addr;
  143. __le32 rx_total_addr;
  144. __le32 rx_overrun_addr;
  145. __le32 rx_filter;
  146. /* Put your debugging definitions here */
  147. } __packed;
  148. #define CARL9170FW_DBG_DESC_SIZE \
  149. (sizeof(struct carl9170fw_dbg_desc))
  150. #define CARL9170FW_CHK_DESC_MIN_VER 1
  151. #define CARL9170FW_CHK_DESC_CUR_VER 2
  152. struct carl9170fw_chk_desc {
  153. struct carl9170fw_desc_head head;
  154. __le32 fw_crc32;
  155. __le32 hdr_crc32;
  156. } __packed;
  157. #define CARL9170FW_CHK_DESC_SIZE \
  158. (sizeof(struct carl9170fw_chk_desc))
  159. #define CARL9170FW_TXSQ_DESC_MIN_VER 1
  160. #define CARL9170FW_TXSQ_DESC_CUR_VER 1
  161. struct carl9170fw_txsq_desc {
  162. struct carl9170fw_desc_head head;
  163. __le32 seq_table_addr;
  164. } __packed;
  165. #define CARL9170FW_TXSQ_DESC_SIZE \
  166. (sizeof(struct carl9170fw_txsq_desc))
  167. #define CARL9170FW_WOL_DESC_MIN_VER 1
  168. #define CARL9170FW_WOL_DESC_CUR_VER 1
  169. struct carl9170fw_wol_desc {
  170. struct carl9170fw_desc_head head;
  171. __le32 supported_triggers; /* CARL9170_WOL_ */
  172. } __packed;
  173. #define CARL9170FW_WOL_DESC_SIZE \
  174. (sizeof(struct carl9170fw_wol_desc))
  175. #define CARL9170FW_LAST_DESC_MIN_VER 1
  176. #define CARL9170FW_LAST_DESC_CUR_VER 2
  177. struct carl9170fw_last_desc {
  178. struct carl9170fw_desc_head head;
  179. } __packed;
  180. #define CARL9170FW_LAST_DESC_SIZE \
  181. (sizeof(struct carl9170fw_fix_desc))
  182. #define CARL9170FW_DESC_MAX_LENGTH 8192
  183. #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver) \
  184. .head = { \
  185. .magic = _magic, \
  186. .length = cpu_to_le16(_length), \
  187. .min_ver = _min_ver, \
  188. .cur_ver = _cur_ver, \
  189. }
  190. static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
  191. u8 magic[CARL9170FW_MAGIC_SIZE],
  192. __le16 length, u8 min_ver, u8 cur_ver)
  193. {
  194. head->magic[0] = magic[0];
  195. head->magic[1] = magic[1];
  196. head->magic[2] = magic[2];
  197. head->magic[3] = magic[3];
  198. head->length = length;
  199. head->min_ver = min_ver;
  200. head->cur_ver = cur_ver;
  201. }
  202. #define carl9170fw_for_each_hdr(desc, fw_desc) \
  203. for (desc = fw_desc; \
  204. memcmp(desc->magic, LAST_MAGIC, CARL9170FW_MAGIC_SIZE) && \
  205. le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE && \
  206. le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH; \
  207. desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
  208. #define CHECK_HDR_VERSION(head, _min_ver) \
  209. (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver)) \
  210. static inline bool carl9170fw_supports(__le32 list, u8 feature)
  211. {
  212. return le32_to_cpu(list) & BIT(feature);
  213. }
  214. static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
  215. const u8 descid[CARL9170FW_MAGIC_SIZE],
  216. u16 min_len, u8 compatible_revision)
  217. {
  218. if (descid[0] == head->magic[0] && descid[1] == head->magic[1] &&
  219. descid[2] == head->magic[2] && descid[3] == head->magic[3] &&
  220. !CHECK_HDR_VERSION(head, compatible_revision) &&
  221. (le16_to_cpu(head->length) >= min_len))
  222. return true;
  223. return false;
  224. }
  225. #define CARL9170FW_MIN_SIZE 32
  226. #define CARL9170FW_MAX_SIZE 16384
  227. static inline bool carl9170fw_size_check(unsigned int len)
  228. {
  229. return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
  230. }
  231. #endif /* __CARL9170_SHARED_FWDESC_H */