blob: 0533f79cb99810168bc87c32c1a17f87b87ae932 [file] [log] [blame]
Christian Lamparteraae9af62010-09-06 01:06:57 +02001/*
2 * Shared CARL9170 Header
3 *
4 * Firmware descriptor format
5 *
Christian Lamparter85ee5122011-06-30 20:27:47 +02006 * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
Christian Lamparteraae9af62010-09-06 01:06:57 +02007 *
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
22#ifndef __CARL9170_SHARED_FWDESC_H
23#define __CARL9170_SHARED_FWDESC_H
24
25/* NOTE: Don't mess with the order of the flags! */
26enum carl9170fw_feature_list {
27 /* Always set */
28 CARL9170FW_DUMMY_FEATURE,
29
30 /*
31 * Indicates that this image has special boot block which prevents
32 * legacy drivers to drive the firmware.
33 */
34 CARL9170FW_MINIBOOT,
35
36 /* usb registers are initialized by the firmware */
37 CARL9170FW_USB_INIT_FIRMWARE,
38
39 /* command traps & notifications are send through EP2 */
40 CARL9170FW_USB_RESP_EP2,
41
42 /* usb download (app -> fw) stream */
43 CARL9170FW_USB_DOWN_STREAM,
44
45 /* usb upload (fw -> app) stream */
46 CARL9170FW_USB_UP_STREAM,
47
48 /* unusable - reserved to flag non-functional debug firmwares */
49 CARL9170FW_UNUSABLE,
50
51 /* AR9170_CMD_RF_INIT, AR9170_CMD_FREQ_START, AR9170_CMD_FREQUENCY */
52 CARL9170FW_COMMAND_PHY,
53
54 /* AR9170_CMD_EKEY, AR9170_CMD_DKEY */
55 CARL9170FW_COMMAND_CAM,
56
57 /* Firmware has a software Content After Beacon Queueing mechanism */
58 CARL9170FW_WLANTX_CAB,
59
60 /* The firmware is capable of responding to incoming BAR frames */
61 CARL9170FW_HANDLE_BACK_REQ,
62
63 /* GPIO Interrupt | CARL9170_RSP_GPIO */
64 CARL9170FW_GPIO_INTERRUPT,
65
66 /* Firmware PSM support | CARL9170_CMD_PSM */
67 CARL9170FW_PSM,
68
Christian Lamparter5c895692010-09-28 23:00:59 +020069 /* Firmware RX filter | CARL9170_CMD_RX_FILTER */
70 CARL9170FW_RX_FILTER,
71
Christian Lamparter9e09b5c2011-01-22 22:46:49 +010072 /* Wake up on WLAN */
73 CARL9170FW_WOL,
74
Christian Lamparter85ee5122011-06-30 20:27:47 +020075 /* Firmware supports PSM in the 5GHZ Band */
76 CARL9170FW_FIXED_5GHZ_PSM,
77
Christian Lamparter43b52a52011-07-16 17:21:01 +020078 /* HW (ANI, CCA, MIB) tally counters */
79 CARL9170FW_HW_COUNTERS,
80
Christian Lamparter4519a742012-07-07 18:01:53 +020081 /* Firmware will pass BA when BARs are queued */
82 CARL9170FW_RX_BA_FILTER,
83
Christian Lamparter2f10e502016-02-15 21:16:06 +010084 /* Firmware has support to write a byte at a time */
85 CARL9170FW_HAS_WREGB_CMD,
86
87 /* Pattern generator */
88 CARL9170FW_PATTERN_GENERATOR,
89
Christian Lamparteraae9af62010-09-06 01:06:57 +020090 /* KEEP LAST */
91 __CARL9170FW_FEATURE_NUM
92};
93
94#define OTUS_MAGIC "OTAR"
95#define MOTD_MAGIC "MOTD"
96#define FIX_MAGIC "FIX\0"
97#define DBG_MAGIC "DBG\0"
98#define CHK_MAGIC "CHK\0"
Christian Lamparter9e09b5c2011-01-22 22:46:49 +010099#define TXSQ_MAGIC "TXSQ"
Christian Lamparter85ee5122011-06-30 20:27:47 +0200100#define WOL_MAGIC "WOL\0"
Christian Lamparteraae9af62010-09-06 01:06:57 +0200101#define LAST_MAGIC "LAST"
102
103#define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
104#define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
105#define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372)
106
107#define CARL9170FW_GET_DAY(d) (((d) % 31) + 1)
108#define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1)
109#define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10)
110
Christian Lamparter9e09b5c2011-01-22 22:46:49 +0100111#define CARL9170FW_MAGIC_SIZE 4
112
Christian Lamparteraae9af62010-09-06 01:06:57 +0200113struct carl9170fw_desc_head {
Christian Lamparter9e09b5c2011-01-22 22:46:49 +0100114 u8 magic[CARL9170FW_MAGIC_SIZE];
Christian Lamparteraae9af62010-09-06 01:06:57 +0200115 __le16 length;
116 u8 min_ver;
117 u8 cur_ver;
118} __packed;
119#define CARL9170FW_DESC_HEAD_SIZE \
120 (sizeof(struct carl9170fw_desc_head))
121
122#define CARL9170FW_OTUS_DESC_MIN_VER 6
Christian Lamparter85ee5122011-06-30 20:27:47 +0200123#define CARL9170FW_OTUS_DESC_CUR_VER 7
Christian Lamparteraae9af62010-09-06 01:06:57 +0200124struct carl9170fw_otus_desc {
125 struct carl9170fw_desc_head head;
126 __le32 feature_set;
127 __le32 fw_address;
128 __le32 bcn_addr;
129 __le16 bcn_len;
130 __le16 miniboot_size;
131 __le16 tx_frag_len;
132 __le16 rx_max_frame_len;
133 u8 tx_descs;
134 u8 cmd_bufs;
135 u8 api_ver;
136 u8 vif_num;
137} __packed;
138#define CARL9170FW_OTUS_DESC_SIZE \
139 (sizeof(struct carl9170fw_otus_desc))
140
141#define CARL9170FW_MOTD_STRING_LEN 24
142#define CARL9170FW_MOTD_RELEASE_LEN 20
143#define CARL9170FW_MOTD_DESC_MIN_VER 1
144#define CARL9170FW_MOTD_DESC_CUR_VER 2
145struct carl9170fw_motd_desc {
146 struct carl9170fw_desc_head head;
147 __le32 fw_year_month_day;
148 char desc[CARL9170FW_MOTD_STRING_LEN];
149 char release[CARL9170FW_MOTD_RELEASE_LEN];
150} __packed;
151#define CARL9170FW_MOTD_DESC_SIZE \
152 (sizeof(struct carl9170fw_motd_desc))
153
154#define CARL9170FW_FIX_DESC_MIN_VER 1
155#define CARL9170FW_FIX_DESC_CUR_VER 2
156struct carl9170fw_fix_entry {
157 __le32 address;
158 __le32 mask;
159 __le32 value;
160} __packed;
161
162struct carl9170fw_fix_desc {
163 struct carl9170fw_desc_head head;
164 struct carl9170fw_fix_entry data[0];
165} __packed;
166#define CARL9170FW_FIX_DESC_SIZE \
167 (sizeof(struct carl9170fw_fix_desc))
168
169#define CARL9170FW_DBG_DESC_MIN_VER 1
Christian Lamparter5c895692010-09-28 23:00:59 +0200170#define CARL9170FW_DBG_DESC_CUR_VER 3
Christian Lamparteraae9af62010-09-06 01:06:57 +0200171struct carl9170fw_dbg_desc {
172 struct carl9170fw_desc_head head;
173
174 __le32 bogoclock_addr;
175 __le32 counter_addr;
176 __le32 rx_total_addr;
177 __le32 rx_overrun_addr;
Christian Lamparter5c895692010-09-28 23:00:59 +0200178 __le32 rx_filter;
Christian Lamparteraae9af62010-09-06 01:06:57 +0200179
180 /* Put your debugging definitions here */
181} __packed;
182#define CARL9170FW_DBG_DESC_SIZE \
183 (sizeof(struct carl9170fw_dbg_desc))
184
185#define CARL9170FW_CHK_DESC_MIN_VER 1
186#define CARL9170FW_CHK_DESC_CUR_VER 2
187struct carl9170fw_chk_desc {
188 struct carl9170fw_desc_head head;
189 __le32 fw_crc32;
190 __le32 hdr_crc32;
191} __packed;
192#define CARL9170FW_CHK_DESC_SIZE \
193 (sizeof(struct carl9170fw_chk_desc))
194
Christian Lamparter9e09b5c2011-01-22 22:46:49 +0100195#define CARL9170FW_TXSQ_DESC_MIN_VER 1
196#define CARL9170FW_TXSQ_DESC_CUR_VER 1
197struct carl9170fw_txsq_desc {
198 struct carl9170fw_desc_head head;
199
200 __le32 seq_table_addr;
201} __packed;
202#define CARL9170FW_TXSQ_DESC_SIZE \
203 (sizeof(struct carl9170fw_txsq_desc))
204
Christian Lamparter85ee5122011-06-30 20:27:47 +0200205#define CARL9170FW_WOL_DESC_MIN_VER 1
206#define CARL9170FW_WOL_DESC_CUR_VER 1
207struct carl9170fw_wol_desc {
208 struct carl9170fw_desc_head head;
209
210 __le32 supported_triggers; /* CARL9170_WOL_ */
211} __packed;
212#define CARL9170FW_WOL_DESC_SIZE \
213 (sizeof(struct carl9170fw_wol_desc))
214
Christian Lamparteraae9af62010-09-06 01:06:57 +0200215#define CARL9170FW_LAST_DESC_MIN_VER 1
216#define CARL9170FW_LAST_DESC_CUR_VER 2
217struct carl9170fw_last_desc {
218 struct carl9170fw_desc_head head;
219} __packed;
220#define CARL9170FW_LAST_DESC_SIZE \
221 (sizeof(struct carl9170fw_fix_desc))
222
223#define CARL9170FW_DESC_MAX_LENGTH 8192
224
225#define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver) \
226 .head = { \
227 .magic = _magic, \
228 .length = cpu_to_le16(_length), \
229 .min_ver = _min_ver, \
230 .cur_ver = _cur_ver, \
231 }
232
233static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
Christian Lamparter9e09b5c2011-01-22 22:46:49 +0100234 u8 magic[CARL9170FW_MAGIC_SIZE],
235 __le16 length, u8 min_ver, u8 cur_ver)
Christian Lamparteraae9af62010-09-06 01:06:57 +0200236{
237 head->magic[0] = magic[0];
238 head->magic[1] = magic[1];
239 head->magic[2] = magic[2];
240 head->magic[3] = magic[3];
241
242 head->length = length;
243 head->min_ver = min_ver;
244 head->cur_ver = cur_ver;
245}
246
247#define carl9170fw_for_each_hdr(desc, fw_desc) \
248 for (desc = fw_desc; \
Christian Lamparter9e09b5c2011-01-22 22:46:49 +0100249 memcmp(desc->magic, LAST_MAGIC, CARL9170FW_MAGIC_SIZE) && \
Christian Lamparteraae9af62010-09-06 01:06:57 +0200250 le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE && \
251 le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH; \
252 desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
253
254#define CHECK_HDR_VERSION(head, _min_ver) \
255 (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver)) \
256
257static inline bool carl9170fw_supports(__le32 list, u8 feature)
258{
259 return le32_to_cpu(list) & BIT(feature);
260}
261
262static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
Christian Lamparter9e09b5c2011-01-22 22:46:49 +0100263 const u8 descid[CARL9170FW_MAGIC_SIZE],
264 u16 min_len, u8 compatible_revision)
Christian Lamparteraae9af62010-09-06 01:06:57 +0200265{
266 if (descid[0] == head->magic[0] && descid[1] == head->magic[1] &&
267 descid[2] == head->magic[2] && descid[3] == head->magic[3] &&
268 !CHECK_HDR_VERSION(head, compatible_revision) &&
269 (le16_to_cpu(head->length) >= min_len))
270 return true;
271
272 return false;
273}
274
275#define CARL9170FW_MIN_SIZE 32
276#define CARL9170FW_MAX_SIZE 16384
277
278static inline bool carl9170fw_size_check(unsigned int len)
279{
280 return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
281}
282
283#endif /* __CARL9170_SHARED_FWDESC_H */