2 * Shared CARL9170 Header
4 * Firmware descriptor format
6 * Copyright 2009-2011 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 */
75 /* Firmware supports PSM in the 5GHZ Band */
76 CARL9170FW_FIXED_5GHZ_PSM,
78 /* HW (ANI, CCA, MIB) tally counters */
79 CARL9170FW_HW_COUNTERS,
81 /* Radar pattern generator */
82 CARL9170FW_RADAR_PATTERN_GENERATOR,
85 __CARL9170FW_FEATURE_NUM
88 #define OTUS_MAGIC "OTAR"
89 #define MOTD_MAGIC "MOTD"
90 #define FIX_MAGIC "FIX\0"
91 #define DBG_MAGIC "DBG\0"
92 #define CHK_MAGIC "CHK\0"
93 #define TXSQ_MAGIC "TXSQ"
94 #define WOL_MAGIC "WOL\0"
95 #define RADAR_MAGIC "RDR\0"
96 #define LAST_MAGIC "LAST"
98 #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
99 #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
100 #define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372)
102 #define CARL9170FW_GET_DAY(d) (((d) % 31) + 1)
103 #define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1)
104 #define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10)
106 #define CARL9170FW_MAGIC_SIZE 4
108 struct carl9170fw_desc_head {
109 u8 magic[CARL9170FW_MAGIC_SIZE];
114 #define CARL9170FW_DESC_HEAD_SIZE \
115 (sizeof(struct carl9170fw_desc_head))
117 #define CARL9170FW_OTUS_DESC_MIN_VER 6
118 #define CARL9170FW_OTUS_DESC_CUR_VER 7
119 struct carl9170fw_otus_desc {
120 struct carl9170fw_desc_head head;
125 __le16 miniboot_size;
127 __le16 rx_max_frame_len;
133 #define CARL9170FW_OTUS_DESC_SIZE \
134 (sizeof(struct carl9170fw_otus_desc))
136 #define CARL9170FW_MOTD_STRING_LEN 24
137 #define CARL9170FW_MOTD_RELEASE_LEN 20
138 #define CARL9170FW_MOTD_DESC_MIN_VER 1
139 #define CARL9170FW_MOTD_DESC_CUR_VER 2
140 struct carl9170fw_motd_desc {
141 struct carl9170fw_desc_head head;
142 __le32 fw_year_month_day;
143 char desc[CARL9170FW_MOTD_STRING_LEN];
144 char release[CARL9170FW_MOTD_RELEASE_LEN];
146 #define CARL9170FW_MOTD_DESC_SIZE \
147 (sizeof(struct carl9170fw_motd_desc))
149 #define CARL9170FW_FIX_DESC_MIN_VER 1
150 #define CARL9170FW_FIX_DESC_CUR_VER 2
151 struct carl9170fw_fix_entry {
157 struct carl9170fw_fix_desc {
158 struct carl9170fw_desc_head head;
159 struct carl9170fw_fix_entry data[0];
161 #define CARL9170FW_FIX_DESC_SIZE \
162 (sizeof(struct carl9170fw_fix_desc))
164 #define CARL9170FW_DBG_DESC_MIN_VER 1
165 #define CARL9170FW_DBG_DESC_CUR_VER 3
166 struct carl9170fw_dbg_desc {
167 struct carl9170fw_desc_head head;
169 __le32 bogoclock_addr;
171 __le32 rx_total_addr;
172 __le32 rx_overrun_addr;
175 /* Put your debugging definitions here */
177 #define CARL9170FW_DBG_DESC_SIZE \
178 (sizeof(struct carl9170fw_dbg_desc))
180 #define CARL9170FW_RADAR_MAP_NAME_LEN 15
181 struct carl9170fw_radar_map_entry {
183 char name[CARL9170FW_RADAR_MAP_NAME_LEN];
186 #define CARL9170FW_RADAR_DESC_MIN_VER 1
187 #define CARL9170FW_RADAR_DESC_CUR_VER 1
188 struct carl9170fw_radar_desc {
189 struct carl9170fw_desc_head head;
193 struct carl9170fw_radar_map_entry radars[0];
194 /* Put your debugging definitions here */
196 #define CARL9170FW_RADAR_DESC_SIZE \
197 (sizeof(struct carl9170fw_radar_desc))
199 #define CARL9170FW_CHK_DESC_MIN_VER 1
200 #define CARL9170FW_CHK_DESC_CUR_VER 2
201 struct carl9170fw_chk_desc {
202 struct carl9170fw_desc_head head;
206 #define CARL9170FW_CHK_DESC_SIZE \
207 (sizeof(struct carl9170fw_chk_desc))
209 #define CARL9170FW_TXSQ_DESC_MIN_VER 1
210 #define CARL9170FW_TXSQ_DESC_CUR_VER 1
211 struct carl9170fw_txsq_desc {
212 struct carl9170fw_desc_head head;
214 __le32 seq_table_addr;
216 #define CARL9170FW_TXSQ_DESC_SIZE \
217 (sizeof(struct carl9170fw_txsq_desc))
219 #define CARL9170FW_WOL_DESC_MIN_VER 1
220 #define CARL9170FW_WOL_DESC_CUR_VER 1
221 struct carl9170fw_wol_desc {
222 struct carl9170fw_desc_head head;
224 __le32 supported_triggers; /* CARL9170_WOL_ */
226 #define CARL9170FW_WOL_DESC_SIZE \
227 (sizeof(struct carl9170fw_wol_desc))
229 #define CARL9170FW_LAST_DESC_MIN_VER 1
230 #define CARL9170FW_LAST_DESC_CUR_VER 2
231 struct carl9170fw_last_desc {
232 struct carl9170fw_desc_head head;
234 #define CARL9170FW_LAST_DESC_SIZE \
235 (sizeof(struct carl9170fw_fix_desc))
237 #define CARL9170FW_DESC_MAX_LENGTH 8192
239 #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver) \
242 .length = cpu_to_le16(_length), \
243 .min_ver = _min_ver, \
244 .cur_ver = _cur_ver, \
247 static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
248 u8 magic[CARL9170FW_MAGIC_SIZE],
249 __le16 length, u8 min_ver, u8 cur_ver)
251 head->magic[0] = magic[0];
252 head->magic[1] = magic[1];
253 head->magic[2] = magic[2];
254 head->magic[3] = magic[3];
256 head->length = length;
257 head->min_ver = min_ver;
258 head->cur_ver = cur_ver;
261 #define carl9170fw_for_each_hdr(desc, fw_desc) \
262 for (desc = fw_desc; \
263 memcmp(desc->magic, LAST_MAGIC, CARL9170FW_MAGIC_SIZE) && \
264 le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE && \
265 le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH; \
266 desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
268 #define CHECK_HDR_VERSION(head, _min_ver) \
269 (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver)) \
271 static inline bool carl9170fw_supports(__le32 list, u8 feature)
273 return le32_to_cpu(list) & BIT(feature);
276 static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
277 const u8 descid[CARL9170FW_MAGIC_SIZE],
278 u16 min_len, u8 compatible_revision)
280 if (descid[0] == head->magic[0] && descid[1] == head->magic[1] &&
281 descid[2] == head->magic[2] && descid[3] == head->magic[3] &&
282 !CHECK_HDR_VERSION(head, compatible_revision) &&
283 (le16_to_cpu(head->length) >= min_len))
289 #define CARL9170FW_MIN_SIZE 32
290 #define CARL9170FW_MAX_SIZE 16384
292 static inline bool carl9170fw_size_check(unsigned int len)
294 return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
297 #endif /* __CARL9170_SHARED_FWDESC_H */