2 * Copyright 2010-2011 Christian Lamparter <chunkeey@googlemail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <sys/types.h>
36 void (*func)(const struct carl9170fw_desc_head *, struct carlfw *fw);
39 #define CHECK_FOR_FEATURE(feature_enum) \
40 { .id = feature_enum, .name = #feature_enum, .func = NULL }
42 #define CHECK_FOR_FEATURE_FUNC(feature_enum, _func) \
43 { .id = feature_enum, .name = #feature_enum, .func = _func }
45 static void show_miniboot_info(const struct carl9170fw_desc_head *head,
46 struct carlfw *fw __unused)
48 const struct carl9170fw_otus_desc *otus = (const void *) head;
50 fprintf(stdout, "\t\t\tminiboot size: %d Bytes\n", otus->miniboot_size);
53 static const struct feature_list known_otus_features_v1[] = {
54 CHECK_FOR_FEATURE(CARL9170FW_DUMMY_FEATURE),
55 CHECK_FOR_FEATURE_FUNC(CARL9170FW_MINIBOOT, show_miniboot_info),
56 CHECK_FOR_FEATURE(CARL9170FW_USB_INIT_FIRMWARE),
57 CHECK_FOR_FEATURE(CARL9170FW_USB_RESP_EP2),
58 CHECK_FOR_FEATURE(CARL9170FW_USB_DOWN_STREAM),
59 CHECK_FOR_FEATURE(CARL9170FW_USB_UP_STREAM),
60 CHECK_FOR_FEATURE(CARL9170FW_UNUSABLE),
61 CHECK_FOR_FEATURE(CARL9170FW_COMMAND_PHY),
62 CHECK_FOR_FEATURE(CARL9170FW_COMMAND_CAM),
63 CHECK_FOR_FEATURE(CARL9170FW_WLANTX_CAB),
64 CHECK_FOR_FEATURE(CARL9170FW_HANDLE_BACK_REQ),
65 CHECK_FOR_FEATURE(CARL9170FW_GPIO_INTERRUPT),
66 CHECK_FOR_FEATURE(CARL9170FW_PSM),
67 CHECK_FOR_FEATURE(CARL9170FW_RX_FILTER),
68 CHECK_FOR_FEATURE(CARL9170FW_WOL),
69 CHECK_FOR_FEATURE(CARL9170FW_FIXED_5GHZ_PSM),
70 CHECK_FOR_FEATURE(CARL9170FW_HW_COUNTERS),
71 CHECK_FOR_FEATURE(CARL9170FW_RX_BA_FILTER),
72 CHECK_FOR_FEATURE(CARL9170FW_HAS_WREGB_CMD),
73 CHECK_FOR_FEATURE(CARL9170FW_PATTERN_GENERATOR),
76 static void check_feature_list(const struct carl9170fw_desc_head *head,
78 const struct feature_list *list,
79 const unsigned int entries,
84 for (i = 0; i < entries; i++) {
85 if (!carl9170fw_supports(bitmap, list[i].id))
88 fprintf(stdout, "\t\t%2d = %s\n", list[i].id, list[i].name);
90 list[i].func(head, fw);
94 static void show_otus_desc(const struct carl9170fw_desc_head *head,
97 const struct carl9170fw_otus_desc *otus = (const void *) head;
99 BUILD_BUG_ON(ARRAY_SIZE(known_otus_features_v1) != __CARL9170FW_FEATURE_NUM);
101 fprintf(stdout, "\tFirmware upload pointer: 0x%x\n",
103 fprintf(stdout, "\tBeacon Address: %x, (reserved:%d Bytes)\n",
104 le32_to_cpu(otus->bcn_addr), le16_to_cpu(otus->bcn_len));
105 fprintf(stdout, "\tTX DMA chunk size:%d Bytes, TX DMA chunks:%d\n",
106 otus->tx_frag_len, otus->tx_descs);
107 fprintf(stdout, "\t=> %d Bytes are reserved for the TX queues\n",
108 otus->tx_frag_len * otus->tx_descs);
109 fprintf(stdout, "\tCommand response buffers:%d\n", otus->cmd_bufs);
110 fprintf(stdout, "\tMax. RX stream block size:%d Bytes\n",
111 otus->rx_max_frame_len);
112 fprintf(stdout, "\tSupported Firmware Interfaces: %d\n", otus->vif_num);
113 fprintf(stdout, "\tFirmware API Version: %d\n", otus->api_ver);
114 fprintf(stdout, "\tSupported Features: (raw:%.08x)\n",
115 le32_to_cpu(otus->feature_set));
117 check_feature_list(head, otus->feature_set, known_otus_features_v1,
118 ARRAY_SIZE(known_otus_features_v1), fw);
121 static void show_motd_desc(const struct carl9170fw_desc_head *head,
122 struct carlfw *fw __unused)
124 const struct carl9170fw_motd_desc *motd = (const void *) head;
125 char buf[CARL9170FW_MOTD_STRING_LEN];
126 unsigned int fw_date;
128 fw_date = motd->fw_year_month_day;
129 fprintf(stdout, "\tFirmware Build Date (YYYY-MM-DD): 2%03d-%02d-%02d\n",
130 CARL9170FW_GET_YEAR(fw_date), CARL9170FW_GET_MONTH(fw_date),
131 CARL9170FW_GET_DAY(fw_date));
133 strncpy(buf, motd->desc, CARL9170FW_MOTD_STRING_LEN);
134 fprintf(stdout, "\tFirmware Text:\"%s\"\n", buf);
136 strncpy(buf, motd->release, CARL9170FW_MOTD_STRING_LEN);
137 fprintf(stdout, "\tFirmware Release:\"%s\"\n", buf);
140 static void show_fix_desc(const struct carl9170fw_desc_head *head,
141 struct carlfw *fw __unused)
143 const struct carl9170fw_fix_desc *fix = (const void *) head;
144 const struct carl9170fw_fix_entry *iter;
147 for (i = 0; i < (head->length - sizeof(*head)) / sizeof(*iter); i++) {
148 iter = &fix->data[i];
149 fprintf(stdout, "\t\t%d: 0x%.8x := 0x%.8x (0x%.8x)\n", i,
150 le32_to_cpu(iter->address), le32_to_cpu(iter->value),
151 le32_to_cpu(iter->mask));
155 static void show_dbg_desc(const struct carl9170fw_desc_head *head,
156 struct carlfw *fw __unused)
158 const struct carl9170fw_dbg_desc *dbg = (const void *) head;
160 #define DBG_ADDR(_name, _reg) do { \
161 unsigned int __tmp = le32_to_cpu(dbg->_reg); \
163 fprintf(stdout, "\t\t" _name " = 0x%.8x\n", __tmp); \
166 fprintf(stdout, "\tFirmware Debug Registers/Counters\n");
167 DBG_ADDR("bogoclock ", bogoclock_addr);
168 DBG_ADDR("counter ", counter_addr);
169 DBG_ADDR("rx total ", rx_total_addr);
170 DBG_ADDR("rx overrun ", rx_overrun_addr);
171 DBG_ADDR("rx filer ", rx_filter);
174 static void show_txsq_desc(const struct carl9170fw_desc_head *head,
175 struct carlfw *fw __unused)
177 const struct carl9170fw_txsq_desc *txsq = (const void *) head;
179 fprintf(stdout, "\t\ttx-seq table addr: 0x%x\n",
180 le32_to_cpu(txsq->seq_table_addr));
184 static const struct feature_list wol_triggers_v1[] = {
185 CHECK_FOR_FEATURE(CARL9170_WOL_DISCONNECT),
186 CHECK_FOR_FEATURE(CARL9170_WOL_MAGIC_PKT),
189 static void show_wol_desc(const struct carl9170fw_desc_head *head,
190 struct carlfw *fw __unused)
192 const struct carl9170fw_wol_desc *wol = (const void *) head;
194 fprintf(stdout, "\tSupported WOWLAN triggers: (raw:%.08x)\n",
195 le32_to_cpu(wol->supported_triggers));
197 check_feature_list(head, wol->supported_triggers, wol_triggers_v1,
198 ARRAY_SIZE(wol_triggers_v1), fw);
201 static void show_chk_desc(const struct carl9170fw_desc_head *head,
202 struct carlfw *fw __unused)
204 const struct carl9170fw_chk_desc *chk = (const void *) head;
206 fprintf(stdout, "\tFirmware Descriptor CRC32: %08x\n",
207 le32_to_cpu(chk->hdr_crc32));
208 fprintf(stdout, "\tFirmware Image CRC32: %08x\n",
209 le32_to_cpu(chk->fw_crc32));
212 static void show_pattern_desc(const struct carl9170fw_desc_head *head,
213 struct carlfw *fw __unused)
215 const struct carl9170fw_pattern_desc *pattern = (const void *) head;
216 const struct carl9170fw_pattern_map_entry *map = pattern->patterns;
217 int map_entries = (head->length - sizeof(*pattern)) / sizeof(*map);
220 fprintf(stdout, "\tPattern index register: %08x\n",
221 le32_to_cpu(pattern->soft_pattern));
222 fprintf(stdout, "\tNumber of supported patterns: %08x\n",
223 le32_to_cpu(pattern->num_patterns));
225 for (i = 0; i < map_entries; i++) {
226 fprintf(stdout, "\t\tindex:0x%x, description:%s\n",
227 map[i].index, map[i].name);
231 static void show_last_desc(const struct carl9170fw_desc_head *head,
232 struct carlfw *fw __unused)
235 const struct carl9170fw_last_desc *last __unused = (const void *) head;
240 #define ADD_HANDLER(_magic, _func) \
242 .magic = _magic##_MAGIC, \
243 .min_ver = CARL9170FW_## _magic##_DESC_CUR_VER, \
245 .size = CARL9170FW_## _magic##_DESC_SIZE, \
248 static const struct {
251 void (*func)(const struct carl9170fw_desc_head *, struct carlfw *);
254 ADD_HANDLER(OTUS, show_otus_desc),
255 ADD_HANDLER(TXSQ, show_txsq_desc),
256 ADD_HANDLER(MOTD, show_motd_desc),
257 ADD_HANDLER(DBG, show_dbg_desc),
258 ADD_HANDLER(FIX, show_fix_desc),
259 ADD_HANDLER(CHK, show_chk_desc),
260 ADD_HANDLER(WOL, show_wol_desc),
261 ADD_HANDLER(PATTERN, show_pattern_desc),
262 ADD_HANDLER(LAST, show_last_desc),
265 static const uint8_t otus_magic[4] = { OTUS_MAGIC };
267 static void show_desc_head(struct carl9170fw_desc_head *head)
269 #define P(c) (isprint(c) ? c : ' ')
271 fprintf(stdout, ">\t%c%c%c%c Descriptor: size:%d, compatible:%d, "
273 P(head->magic[0]), P(head->magic[1]), P(head->magic[2]),
274 P(head->magic[3]), le16_to_cpu(head->length), head->min_ver,
278 static void fwinfo_info(void)
280 fprintf(stderr, "Usage:\n");
281 fprintf(stderr, "\tfwinfo FW-FILE\n");
283 fprintf(stderr, "\nDescription:\n");
284 fprintf(stderr, "\tDisplay firmware descriptors information in "
285 "a human readable form.\n");
287 fprintf(stderr, "\nParameteres:\n");
288 fprintf(stderr, "\t 'FW-FILE' = firmware file/base-name\n\n");
291 int main(int argc, char *args[])
293 struct carlfw *fw = NULL;
294 struct carl9170fw_desc_head *fw_desc;
304 fw = carlfw_load(args[1]);
305 if (IS_ERR_OR_NULL(fw)) {
307 fprintf(stderr, "Failed to open firmware \"%s\" (%d).\n",
312 carlfw_get_fw(fw, &len);
313 fprintf(stdout, "General Firmware Statistics:\n");
314 fprintf(stdout, "\tFirmware file size: %u Bytes\n", (unsigned int)len);
315 fprintf(stdout, "\t%d Descriptors in %d Bytes\n",
316 carlfw_get_descs_num(fw), carlfw_get_descs_size(fw));
319 fprintf(stdout, "\nDetailed Descriptor Description:\n");
320 while ((fw_desc = carlfw_desc_next(fw, fw_desc))) {
321 show_desc_head(fw_desc);
323 for (i = 0; i < ARRAY_SIZE(known_magics); i++) {
324 if (carl9170fw_desc_cmp(fw_desc, known_magics[i].magic,
325 known_magics[i].size, known_magics[i].min_ver)) {
326 known_magics[i].func(fw_desc, fw);
331 if (i == ARRAY_SIZE(known_magics))
332 fprintf(stderr, "Unknown Descriptor.\n");
334 fprintf(stdout, "\n");
347 fprintf(stderr, "%s\n", strerror(-err));
352 return err ? EXIT_FAILURE : EXIT_SUCCESS;