Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fwdesc.h
Go to the documentation of this file.
1 /*
2  * Shared CARL9170 Header
3  *
4  * Firmware descriptor format
5  *
6  * Copyright 2009-2011 Christian Lamparter <[email protected]>
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! */
27  /* Always set */
29 
30  /*
31  * Indicates that this image has special boot block which prevents
32  * legacy drivers to drive the firmware.
33  */
35 
36  /* usb registers are initialized by the firmware */
38 
39  /* command traps & notifications are send through EP2 */
41 
42  /* usb download (app -> fw) stream */
44 
45  /* usb upload (fw -> app) stream */
47 
48  /* unusable - reserved to flag non-functional debug firmwares */
50 
51  /* AR9170_CMD_RF_INIT, AR9170_CMD_FREQ_START, AR9170_CMD_FREQUENCY */
53 
54  /* AR9170_CMD_EKEY, AR9170_CMD_DKEY */
56 
57  /* Firmware has a software Content After Beacon Queueing mechanism */
59 
60  /* The firmware is capable of responding to incoming BAR frames */
62 
63  /* GPIO Interrupt | CARL9170_RSP_GPIO */
65 
66  /* Firmware PSM support | CARL9170_CMD_PSM */
68 
69  /* Firmware RX filter | CARL9170_CMD_RX_FILTER */
71 
72  /* Wake up on WLAN */
74 
75  /* Firmware supports PSM in the 5GHZ Band */
77 
78  /* HW (ANI, CCA, MIB) tally counters */
80 
81  /* Firmware will pass BA when BARs are queued */
83 
84  /* KEEP LAST */
86 };
87 
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 LAST_MAGIC "LAST"
96 
97 #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
98 #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
99 #define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372)
100 
101 #define CARL9170FW_GET_DAY(d) (((d) % 31) + 1)
102 #define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1)
103 #define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10)
104 
105 #define CARL9170FW_MAGIC_SIZE 4
106 
112 } __packed;
113 #define CARL9170FW_DESC_HEAD_SIZE \
114  (sizeof(struct carl9170fw_desc_head))
115 
116 #define CARL9170FW_OTUS_DESC_MIN_VER 6
117 #define CARL9170FW_OTUS_DESC_CUR_VER 7
131 } __packed;
132 #define CARL9170FW_OTUS_DESC_SIZE \
133  (sizeof(struct carl9170fw_otus_desc))
134 
135 #define CARL9170FW_MOTD_STRING_LEN 24
136 #define CARL9170FW_MOTD_RELEASE_LEN 20
137 #define CARL9170FW_MOTD_DESC_MIN_VER 1
138 #define CARL9170FW_MOTD_DESC_CUR_VER 2
144 } __packed;
145 #define CARL9170FW_MOTD_DESC_SIZE \
146  (sizeof(struct carl9170fw_motd_desc))
147 
148 #define CARL9170FW_FIX_DESC_MIN_VER 1
149 #define CARL9170FW_FIX_DESC_CUR_VER 2
154 } __packed;
155 
159 } __packed;
160 #define CARL9170FW_FIX_DESC_SIZE \
161  (sizeof(struct carl9170fw_fix_desc))
162 
163 #define CARL9170FW_DBG_DESC_MIN_VER 1
164 #define CARL9170FW_DBG_DESC_CUR_VER 3
167 
173 
174  /* Put your debugging definitions here */
175 } __packed;
176 #define CARL9170FW_DBG_DESC_SIZE \
177  (sizeof(struct carl9170fw_dbg_desc))
178 
179 #define CARL9170FW_CHK_DESC_MIN_VER 1
180 #define CARL9170FW_CHK_DESC_CUR_VER 2
185 } __packed;
186 #define CARL9170FW_CHK_DESC_SIZE \
187  (sizeof(struct carl9170fw_chk_desc))
188 
189 #define CARL9170FW_TXSQ_DESC_MIN_VER 1
190 #define CARL9170FW_TXSQ_DESC_CUR_VER 1
193 
195 } __packed;
196 #define CARL9170FW_TXSQ_DESC_SIZE \
197  (sizeof(struct carl9170fw_txsq_desc))
198 
199 #define CARL9170FW_WOL_DESC_MIN_VER 1
200 #define CARL9170FW_WOL_DESC_CUR_VER 1
203 
204  __le32 supported_triggers; /* CARL9170_WOL_ */
205 } __packed;
206 #define CARL9170FW_WOL_DESC_SIZE \
207  (sizeof(struct carl9170fw_wol_desc))
208 
209 #define CARL9170FW_LAST_DESC_MIN_VER 1
210 #define CARL9170FW_LAST_DESC_CUR_VER 2
213 } __packed;
214 #define CARL9170FW_LAST_DESC_SIZE \
215  (sizeof(struct carl9170fw_fix_desc))
216 
217 #define CARL9170FW_DESC_MAX_LENGTH 8192
218 
219 #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver) \
220  .head = { \
221  .magic = _magic, \
222  .length = cpu_to_le16(_length), \
223  .min_ver = _min_ver, \
224  .cur_ver = _cur_ver, \
225  }
226 
227 static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
230 {
231  head->magic[0] = magic[0];
232  head->magic[1] = magic[1];
233  head->magic[2] = magic[2];
234  head->magic[3] = magic[3];
235 
236  head->length = length;
237  head->min_ver = min_ver;
238  head->cur_ver = cur_ver;
239 }
240 
241 #define carl9170fw_for_each_hdr(desc, fw_desc) \
242  for (desc = fw_desc; \
243  memcmp(desc->magic, LAST_MAGIC, CARL9170FW_MAGIC_SIZE) && \
244  le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE && \
245  le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH; \
246  desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
247 
248 #define CHECK_HDR_VERSION(head, _min_ver) \
249  (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver)) \
250 
251 static inline bool carl9170fw_supports(__le32 list, u8 feature)
252 {
253  return le32_to_cpu(list) & BIT(feature);
254 }
255 
256 static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
257  const u8 descid[CARL9170FW_MAGIC_SIZE],
258  u16 min_len, u8 compatible_revision)
259 {
260  if (descid[0] == head->magic[0] && descid[1] == head->magic[1] &&
261  descid[2] == head->magic[2] && descid[3] == head->magic[3] &&
262  !CHECK_HDR_VERSION(head, compatible_revision) &&
263  (le16_to_cpu(head->length) >= min_len))
264  return true;
265 
266  return false;
267 }
268 
269 #define CARL9170FW_MIN_SIZE 32
270 #define CARL9170FW_MAX_SIZE 16384
271 
272 static inline bool carl9170fw_size_check(unsigned int len)
273 {
274  return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
275 }
276 
277 #endif /* __CARL9170_SHARED_FWDESC_H */