carl9170 firmware: update headers for WOL
[carl9170fw.git] / include / shared / fwdesc.h
1 /*
2  * Shared CARL9170 Header
3  *
4  * Firmware descriptor format
5  *
6  * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
7  *
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! */
26 enum 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
69         /* Firmware RX filter | CARL9170_CMD_RX_FILTER */
70         CARL9170FW_RX_FILTER,
71
72         /* Wake up on WLAN */
73         CARL9170FW_WOL,
74
75         /* KEEP LAST */
76         __CARL9170FW_FEATURE_NUM
77 };
78
79 #define OTUS_MAGIC      "OTAR"
80 #define MOTD_MAGIC      "MOTD"
81 #define FIX_MAGIC       "FIX\0"
82 #define DBG_MAGIC       "DBG\0"
83 #define CHK_MAGIC       "CHK\0"
84 #define LAST_MAGIC      "LAST"
85
86 #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
87 #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
88 #define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372)
89
90 #define CARL9170FW_GET_DAY(d) (((d) % 31) + 1)
91 #define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1)
92 #define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10)
93
94 #define CARL9170FW_MAGIC_SIZE                   4
95
96 struct carl9170fw_desc_head {
97         u8      magic[CARL9170FW_MAGIC_SIZE];
98         __le16 length;
99         u8 min_ver;
100         u8 cur_ver;
101 } __packed;
102 #define CARL9170FW_DESC_HEAD_SIZE                       \
103         (sizeof(struct carl9170fw_desc_head))
104
105 #define CARL9170FW_OTUS_DESC_MIN_VER            6
106 #define CARL9170FW_OTUS_DESC_CUR_VER            6
107 struct carl9170fw_otus_desc {
108         struct carl9170fw_desc_head head;
109         __le32 feature_set;
110         __le32 fw_address;
111         __le32 bcn_addr;
112         __le16 bcn_len;
113         __le16 miniboot_size;
114         __le16 tx_frag_len;
115         __le16 rx_max_frame_len;
116         u8 tx_descs;
117         u8 cmd_bufs;
118         u8 api_ver;
119         u8 vif_num;
120 } __packed;
121 #define CARL9170FW_OTUS_DESC_SIZE                       \
122         (sizeof(struct carl9170fw_otus_desc))
123
124 #define CARL9170FW_MOTD_STRING_LEN                      24
125 #define CARL9170FW_MOTD_RELEASE_LEN                     20
126 #define CARL9170FW_MOTD_DESC_MIN_VER                    1
127 #define CARL9170FW_MOTD_DESC_CUR_VER                    2
128 struct carl9170fw_motd_desc {
129         struct carl9170fw_desc_head head;
130         __le32 fw_year_month_day;
131         char desc[CARL9170FW_MOTD_STRING_LEN];
132         char release[CARL9170FW_MOTD_RELEASE_LEN];
133 } __packed;
134 #define CARL9170FW_MOTD_DESC_SIZE                       \
135         (sizeof(struct carl9170fw_motd_desc))
136
137 #define CARL9170FW_FIX_DESC_MIN_VER                     1
138 #define CARL9170FW_FIX_DESC_CUR_VER                     2
139 struct carl9170fw_fix_entry {
140         __le32 address;
141         __le32 mask;
142         __le32 value;
143 } __packed;
144
145 struct carl9170fw_fix_desc {
146         struct carl9170fw_desc_head head;
147         struct carl9170fw_fix_entry data[0];
148 } __packed;
149 #define CARL9170FW_FIX_DESC_SIZE                        \
150         (sizeof(struct carl9170fw_fix_desc))
151
152 #define CARL9170FW_DBG_DESC_MIN_VER                     1
153 #define CARL9170FW_DBG_DESC_CUR_VER                     3
154 struct carl9170fw_dbg_desc {
155         struct carl9170fw_desc_head head;
156
157         __le32 bogoclock_addr;
158         __le32 counter_addr;
159         __le32 rx_total_addr;
160         __le32 rx_overrun_addr;
161         __le32 rx_filter;
162
163         /* Put your debugging definitions here */
164 } __packed;
165 #define CARL9170FW_DBG_DESC_SIZE                        \
166         (sizeof(struct carl9170fw_dbg_desc))
167
168 #define CARL9170FW_CHK_DESC_MIN_VER                     1
169 #define CARL9170FW_CHK_DESC_CUR_VER                     2
170 struct carl9170fw_chk_desc {
171         struct carl9170fw_desc_head head;
172         __le32 fw_crc32;
173         __le32 hdr_crc32;
174 } __packed;
175 #define CARL9170FW_CHK_DESC_SIZE                        \
176         (sizeof(struct carl9170fw_chk_desc))
177
178 #define CARL9170FW_LAST_DESC_MIN_VER                    1
179 #define CARL9170FW_LAST_DESC_CUR_VER                    2
180 struct carl9170fw_last_desc {
181         struct carl9170fw_desc_head head;
182 } __packed;
183 #define CARL9170FW_LAST_DESC_SIZE                       \
184         (sizeof(struct carl9170fw_fix_desc))
185
186 #define CARL9170FW_DESC_MAX_LENGTH                      8192
187
188 #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver)       \
189         .head = {                                                       \
190                 .magic = _magic,                                        \
191                 .length = cpu_to_le16(_length),                         \
192                 .min_ver = _min_ver,                                    \
193                 .cur_ver = _cur_ver,                                    \
194         }
195
196 static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
197                                          u8 magic[CARL9170FW_MAGIC_SIZE],
198                                          __le16 length, u8 min_ver, u8 cur_ver)
199 {
200         head->magic[0] = magic[0];
201         head->magic[1] = magic[1];
202         head->magic[2] = magic[2];
203         head->magic[3] = magic[3];
204
205         head->length = length;
206         head->min_ver = min_ver;
207         head->cur_ver = cur_ver;
208 }
209
210 #define carl9170fw_for_each_hdr(desc, fw_desc)                          \
211         for (desc = fw_desc;                                            \
212              memcmp(desc->magic, LAST_MAGIC, CARL9170FW_MAGIC_SIZE) &&  \
213              le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE &&  \
214              le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH;    \
215              desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
216
217 #define CHECK_HDR_VERSION(head, _min_ver)                               \
218         (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver))  \
219
220 static inline bool carl9170fw_supports(__le32 list, u8 feature)
221 {
222         return le32_to_cpu(list) & BIT(feature);
223 }
224
225 static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
226                                        const u8 descid[CARL9170FW_MAGIC_SIZE],
227                                        u16 min_len, u8 compatible_revision)
228 {
229         if (descid[0] == head->magic[0] && descid[1] == head->magic[1] &&
230             descid[2] == head->magic[2] && descid[3] == head->magic[3] &&
231             !CHECK_HDR_VERSION(head, compatible_revision) &&
232             (le16_to_cpu(head->length) >= min_len))
233                 return true;
234
235         return false;
236 }
237
238 #define CARL9170FW_MIN_SIZE     32
239 #define CARL9170FW_MAX_SIZE     16384
240
241 static inline bool carl9170fw_size_check(unsigned int len)
242 {
243         return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
244 }
245
246 #endif /* __CARL9170_SHARED_FWDESC_H */