fwdesc.h 7.0 KB

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