2 * Firmware Descriptor definitions
4 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; see the file COPYING. If not, see
17 * http://www.gnu.org/licenses/.
20 #ifndef __CARL9170_SHARED_FWDESC_H
21 #define __CARL9170_SHARED_FWDESC_H
23 /* NOTE: Don't mess with the order of the flags! */
24 enum carl9170fw_feature_list {
26 CARL9170FW_DUMMY_FEATURE,
29 * Indicates that this image has special boot block which prevents
30 * legacy drivers to drive the firmware.
34 /* usb registers are initialized by the firmware */
35 CARL9170FW_USB_INIT_FIRMWARE,
37 /* command traps & notifications are send through EP2 */
38 CARL9170FW_USB_RESP_EP2,
40 /* usb download (app -> fw) stream */
41 CARL9170FW_USB_DOWN_STREAM,
43 /* usb upload (fw -> app) stream */
44 CARL9170FW_USB_UP_STREAM,
46 /* unusable - reserved to flag non-functional debug firmwares */
49 /* AR9170_CMD_RF_INIT, AR9170_CMD_FREQ_START, AR9170_CMD_FREQUENCY */
50 CARL9170FW_COMMAND_PHY,
52 /* AR9170_CMD_EKEY, AR9170_CMD_DKEY */
53 CARL9170FW_COMMAND_CAM,
55 /* Firmware has a software Content After Beacon Queueing mechanism */
56 CARL9170FW_WLANTX_CAB,
58 /* The firmware is capable of responding to incoming BAR frames */
59 CARL9170FW_HANDLE_BACK_REQ,
61 /* GPIO Interrupt | CARL9170_RSP_GPIO */
62 CARL9170FW_GPIO_INTERRUPT,
64 /* Firmware PSM support | CARL9170_CMD_PSM */
68 __CARL9170FW_FEATURE_NUM
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 LAST_MAGIC "LAST"
78 #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
79 #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
80 #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)
86 struct carl9170fw_desc_head {
92 #define CARL9170FW_DESC_HEAD_SIZE \
93 (sizeof(struct carl9170fw_desc_head))
95 #define CARL9170FW_OTUS_DESC_MIN_VER 4
96 #define CARL9170FW_OTUS_DESC_CUR_VER 4
97 struct carl9170fw_otus_desc {
98 struct carl9170fw_desc_head head;
103 __le16 miniboot_size;
105 __le16 rx_max_frame_len;
111 #define CARL9170FW_OTUS_DESC_SIZE \
112 (sizeof(struct carl9170fw_otus_desc))
114 #define CARL9170FW_MOTD_STRING_LEN 24
115 #define CARL9170FW_MOTD_RELEASE_LEN 20
116 #define CARL9170FW_MOTD_DESC_MIN_VER 1
117 #define CARL9170FW_MOTD_DESC_CUR_VER 2
118 struct carl9170fw_motd_desc {
119 struct carl9170fw_desc_head head;
120 __le32 fw_year_month_day;
121 char desc[CARL9170FW_MOTD_STRING_LEN];
122 char release[CARL9170FW_MOTD_RELEASE_LEN];
124 #define CARL9170FW_MOTD_DESC_SIZE \
125 (sizeof(struct carl9170fw_motd_desc))
127 #define CARL9170FW_FIX_DESC_MIN_VER 1
128 #define CARL9170FW_FIX_DESC_CUR_VER 2
129 struct carl9170fw_fix_entry {
135 struct carl9170fw_fix_desc {
136 struct carl9170fw_desc_head head;
137 struct carl9170fw_fix_entry data[0];
139 #define CARL9170FW_FIX_DESC_SIZE \
140 (sizeof(struct carl9170fw_fix_desc))
142 #define CARL9170FW_DBG_DESC_MIN_VER 1
143 #define CARL9170FW_DBG_DESC_CUR_VER 2
144 struct carl9170fw_dbg_desc {
145 struct carl9170fw_desc_head head;
147 __le32 bogoclock_addr;
149 __le32 rx_total_addr;
150 __le32 rx_overrun_addr;
152 /* Put your debugging definitions here */
154 #define CARL9170FW_DBG_DESC_SIZE \
155 (sizeof(struct carl9170fw_dbg_desc))
157 #define CARL9170FW_CHK_DESC_MIN_VER 1
158 #define CARL9170FW_CHK_DESC_CUR_VER 2
159 struct carl9170fw_chk_desc {
160 struct carl9170fw_desc_head head;
164 #define CARL9170FW_CHK_DESC_SIZE \
165 (sizeof(struct carl9170fw_chk_desc))
167 #define CARL9170FW_LAST_DESC_MIN_VER 1
168 #define CARL9170FW_LAST_DESC_CUR_VER 2
169 struct carl9170fw_last_desc {
170 struct carl9170fw_desc_head head;
172 #define CARL9170FW_LAST_DESC_SIZE \
173 (sizeof(struct carl9170fw_fix_desc))
175 #define CARL9170FW_DESC_MAX_LENGTH 8192
177 #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver) \
180 .length = cpu_to_le16(_length), \
181 .min_ver = _min_ver, \
182 .cur_ver = _cur_ver, \
185 static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
186 u8 magic[4], __le16 length,
187 u8 min_ver, u8 cur_ver)
189 head->magic[0] = magic[0];
190 head->magic[1] = magic[1];
191 head->magic[2] = magic[2];
192 head->magic[3] = magic[3];
194 head->length = length;
195 head->min_ver = min_ver;
196 head->cur_ver = cur_ver;
199 #define carl9170fw_for_each_hdr(desc, fw_desc) \
200 for (desc = fw_desc; \
201 memcmp(desc->magic, LAST_MAGIC, 4) && \
202 le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE && \
203 le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH; \
204 desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
206 #define CHECK_HDR_VERSION(head, _min_ver) \
207 (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver)) \
209 static inline bool carl9170fw_supports(__le32 list, u8 feature)
211 return le32_to_cpu(list) & BIT(feature);
214 static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
215 const u8 descid[4], u16 min_len,
216 u8 compatible_revision)
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))
227 #define CARL9170FW_MIN_SIZE 32
228 #define CARL9170FW_MAX_SIZE 16384
230 static inline bool carl9170fw_size_check(unsigned int len)
232 return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
235 #endif /* __CARL9170_SHARED_FWDESC_H */