2 * Shared CARL9170 Header
4 * Firmware descriptor format
6 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
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.
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.
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/.
22 #ifndef __CARL9170_SHARED_FWDESC_H
23 #define __CARL9170_SHARED_FWDESC_H
25 /* NOTE: Don't mess with the order of the flags! */
26 enum carl9170fw_feature_list {
28 CARL9170FW_DUMMY_FEATURE,
31 * Indicates that this image has special boot block which prevents
32 * legacy drivers to drive the firmware.
36 /* usb registers are initialized by the firmware */
37 CARL9170FW_USB_INIT_FIRMWARE,
39 /* command traps & notifications are send through EP2 */
40 CARL9170FW_USB_RESP_EP2,
42 /* usb download (app -> fw) stream */
43 CARL9170FW_USB_DOWN_STREAM,
45 /* usb upload (fw -> app) stream */
46 CARL9170FW_USB_UP_STREAM,
48 /* unusable - reserved to flag non-functional debug firmwares */
51 /* AR9170_CMD_RF_INIT, AR9170_CMD_FREQ_START, AR9170_CMD_FREQUENCY */
52 CARL9170FW_COMMAND_PHY,
54 /* AR9170_CMD_EKEY, AR9170_CMD_DKEY */
55 CARL9170FW_COMMAND_CAM,
57 /* Firmware has a software Content After Beacon Queueing mechanism */
58 CARL9170FW_WLANTX_CAB,
60 /* The firmware is capable of responding to incoming BAR frames */
61 CARL9170FW_HANDLE_BACK_REQ,
63 /* GPIO Interrupt | CARL9170_RSP_GPIO */
64 CARL9170FW_GPIO_INTERRUPT,
66 /* Firmware PSM support | CARL9170_CMD_PSM */
69 /* Firmware RX filter | CARL9170_CMD_RX_FILTER */
73 __CARL9170FW_FEATURE_NUM
76 #define OTUS_MAGIC "OTAR"
77 #define MOTD_MAGIC "MOTD"
78 #define FIX_MAGIC "FIX\0"
79 #define DBG_MAGIC "DBG\0"
80 #define CHK_MAGIC "CHK\0"
81 #define LAST_MAGIC "LAST"
83 #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
84 #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
85 #define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372)
87 #define CARL9170FW_GET_DAY(d) (((d) % 31) + 1)
88 #define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1)
89 #define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10)
91 struct carl9170fw_desc_head {
97 #define CARL9170FW_DESC_HEAD_SIZE \
98 (sizeof(struct carl9170fw_desc_head))
100 #define CARL9170FW_OTUS_DESC_MIN_VER 6
101 #define CARL9170FW_OTUS_DESC_CUR_VER 6
102 struct carl9170fw_otus_desc {
103 struct carl9170fw_desc_head head;
108 __le16 miniboot_size;
110 __le16 rx_max_frame_len;
116 #define CARL9170FW_OTUS_DESC_SIZE \
117 (sizeof(struct carl9170fw_otus_desc))
119 #define CARL9170FW_MOTD_STRING_LEN 24
120 #define CARL9170FW_MOTD_RELEASE_LEN 20
121 #define CARL9170FW_MOTD_DESC_MIN_VER 1
122 #define CARL9170FW_MOTD_DESC_CUR_VER 2
123 struct carl9170fw_motd_desc {
124 struct carl9170fw_desc_head head;
125 __le32 fw_year_month_day;
126 char desc[CARL9170FW_MOTD_STRING_LEN];
127 char release[CARL9170FW_MOTD_RELEASE_LEN];
129 #define CARL9170FW_MOTD_DESC_SIZE \
130 (sizeof(struct carl9170fw_motd_desc))
132 #define CARL9170FW_FIX_DESC_MIN_VER 1
133 #define CARL9170FW_FIX_DESC_CUR_VER 2
134 struct carl9170fw_fix_entry {
140 struct carl9170fw_fix_desc {
141 struct carl9170fw_desc_head head;
142 struct carl9170fw_fix_entry data[0];
144 #define CARL9170FW_FIX_DESC_SIZE \
145 (sizeof(struct carl9170fw_fix_desc))
147 #define CARL9170FW_DBG_DESC_MIN_VER 1
148 #define CARL9170FW_DBG_DESC_CUR_VER 3
149 struct carl9170fw_dbg_desc {
150 struct carl9170fw_desc_head head;
152 __le32 bogoclock_addr;
154 __le32 rx_total_addr;
155 __le32 rx_overrun_addr;
158 /* Put your debugging definitions here */
160 #define CARL9170FW_DBG_DESC_SIZE \
161 (sizeof(struct carl9170fw_dbg_desc))
163 #define CARL9170FW_CHK_DESC_MIN_VER 1
164 #define CARL9170FW_CHK_DESC_CUR_VER 2
165 struct carl9170fw_chk_desc {
166 struct carl9170fw_desc_head head;
170 #define CARL9170FW_CHK_DESC_SIZE \
171 (sizeof(struct carl9170fw_chk_desc))
173 #define CARL9170FW_LAST_DESC_MIN_VER 1
174 #define CARL9170FW_LAST_DESC_CUR_VER 2
175 struct carl9170fw_last_desc {
176 struct carl9170fw_desc_head head;
178 #define CARL9170FW_LAST_DESC_SIZE \
179 (sizeof(struct carl9170fw_fix_desc))
181 #define CARL9170FW_DESC_MAX_LENGTH 8192
183 #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver) \
186 .length = cpu_to_le16(_length), \
187 .min_ver = _min_ver, \
188 .cur_ver = _cur_ver, \
191 static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
192 u8 magic[4], __le16 length,
193 u8 min_ver, u8 cur_ver)
195 head->magic[0] = magic[0];
196 head->magic[1] = magic[1];
197 head->magic[2] = magic[2];
198 head->magic[3] = magic[3];
200 head->length = length;
201 head->min_ver = min_ver;
202 head->cur_ver = cur_ver;
205 #define carl9170fw_for_each_hdr(desc, fw_desc) \
206 for (desc = fw_desc; \
207 memcmp(desc->magic, LAST_MAGIC, 4) && \
208 le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE && \
209 le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH; \
210 desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
212 #define CHECK_HDR_VERSION(head, _min_ver) \
213 (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver)) \
215 static inline bool carl9170fw_supports(__le32 list, u8 feature)
217 return le32_to_cpu(list) & BIT(feature);
220 static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
221 const u8 descid[4], u16 min_len,
222 u8 compatible_revision)
224 if (descid[0] == head->magic[0] && descid[1] == head->magic[1] &&
225 descid[2] == head->magic[2] && descid[3] == head->magic[3] &&
226 !CHECK_HDR_VERSION(head, compatible_revision) &&
227 (le16_to_cpu(head->length) >= min_len))
233 #define CARL9170FW_MIN_SIZE 32
234 #define CARL9170FW_MAX_SIZE 16384
236 static inline bool carl9170fw_size_check(unsigned int len)
238 return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
241 #endif /* __CARL9170_SHARED_FWDESC_H */