blob: 84a39c30c3d3ad70b8d61d0de1a5795f873b5c39 [file] [log] [blame]
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001/*
2 * Intel Wireless WiMAX Connection 2400m
3 * Firmware uploader
4 *
5 *
6 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 *
35 * Intel Corporation <linux-wimax@intel.com>
36 * Yanir Lubetkin <yanirx.lubetkin@intel.com>
37 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
38 * - Initial implementation
39 *
40 *
41 * THE PROCEDURE
42 *
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -070043 * The 2400m and derived devices work in two modes: boot-mode or
44 * normal mode. In boot mode we can execute only a handful of commands
45 * targeted at uploading the firmware and launching it.
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -080046 *
47 * The 2400m enters boot mode when it is first connected to the
48 * system, when it crashes and when you ask it to reboot. There are
49 * two submodes of the boot mode: signed and non-signed. Signed takes
50 * firmwares signed with a certain private key, non-signed takes any
51 * firmware. Normal hardware takes only signed firmware.
52 *
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -070053 * On boot mode, in USB, we write to the device using the bulk out
54 * endpoint and read from it in the notification endpoint. In SDIO we
55 * talk to it via the write address and read from the read address.
56 *
57 * Upon entrance to boot mode, the device sends (preceeded with a few
58 * zero length packets (ZLPs) on the notification endpoint in USB) a
59 * reboot barker (4 le32 words with the same value). We ack it by
60 * sending the same barker to the device. The device acks with a
61 * reboot ack barker (4 le32 words with value I2400M_ACK_BARKER) and
62 * then is fully booted. At this point we can upload the firmware.
63 *
64 * Note that different iterations of the device and EEPROM
65 * configurations will send different [re]boot barkers; these are
66 * collected in i2400m_barker_db along with the firmware
67 * characteristics they require.
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -080068 *
69 * This process is accomplished by the i2400m_bootrom_init()
70 * function. All the device interaction happens through the
71 * i2400m_bm_cmd() [boot mode command]. Special return values will
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -070072 * indicate if the device did reset during the process.
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -080073 *
74 * After this, we read the MAC address and then (if needed)
75 * reinitialize the device. We need to read it ahead of time because
76 * in the future, we might not upload the firmware until userspace
77 * 'ifconfig up's the device.
78 *
79 * We can then upload the firmware file. The file is composed of a BCF
80 * header (basic data, keys and signatures) and a list of write
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -070081 * commands and payloads. Optionally more BCF headers might follow the
82 * main payload. We first upload the header [i2400m_dnload_init()] and
83 * then pass the commands and payloads verbatim to the i2400m_bm_cmd()
84 * function [i2400m_dnload_bcf()]. Then we tell the device to jump to
85 * the new firmware [i2400m_dnload_finalize()].
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -080086 *
87 * Once firmware is uploaded, we are good to go :)
88 *
89 * When we don't know in which mode we are, we first try by sending a
90 * warm reset request that will take us to boot-mode. If we time out
91 * waiting for a reboot barker, that means maybe we are already in
92 * boot mode, so we send a reboot barker.
93 *
94 * COMMAND EXECUTION
95 *
96 * This code (and process) is single threaded; for executing commands,
97 * we post a URB to the notification endpoint, post the command, wait
98 * for data on the notification buffer. We don't need to worry about
99 * others as we know we are the only ones in there.
100 *
101 * BACKEND IMPLEMENTATION
102 *
103 * This code is bus-generic; the bus-specific driver provides back end
104 * implementations to send a boot mode command to the device and to
105 * read an acknolwedgement from it (or an asynchronous notification)
106 * from it.
107 *
108 * ROADMAP
109 *
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700110 * i2400m_barker_db_init Called by i2400m_driver_init()
111 * i2400m_barker_db_add
112 *
113 * i2400m_barker_db_exit Called by i2400m_driver_exit()
114 *
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800115 * i2400m_dev_bootstrap Called by __i2400m_dev_start()
116 * request_firmware
117 * i2400m_fw_check
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -0700118 * i2400m_fw_hdr_check
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800119 * i2400m_fw_dnload
120 * release_firmware
121 *
122 * i2400m_fw_dnload
123 * i2400m_bootrom_init
124 * i2400m_bm_cmd
125 * i2400m->bus_reset
126 * i2400m_dnload_init
127 * i2400m_dnload_init_signed
128 * i2400m_dnload_init_nonsigned
129 * i2400m_download_chunk
130 * i2400m_bm_cmd
131 * i2400m_dnload_bcf
132 * i2400m_bm_cmd
133 * i2400m_dnload_finalize
134 * i2400m_bm_cmd
135 *
136 * i2400m_bm_cmd
137 * i2400m->bus_bm_cmd_send()
138 * i2400m->bus_bm_wait_for_ack
139 * __i2400m_bm_ack_verify
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700140 * i2400m_is_boot_barker
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800141 *
142 * i2400m_bm_cmd_prepare Used by bus-drivers to prep
143 * commands before sending
144 */
145#include <linux/firmware.h>
146#include <linux/sched.h>
147#include <linux/usb.h>
148#include "i2400m.h"
149
150
151#define D_SUBMODULE fw
152#include "debug-levels.h"
153
154
155static const __le32 i2400m_ACK_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800156 cpu_to_le32(I2400M_ACK_BARKER),
157 cpu_to_le32(I2400M_ACK_BARKER),
158 cpu_to_le32(I2400M_ACK_BARKER),
159 cpu_to_le32(I2400M_ACK_BARKER)
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800160};
161
162
163/**
164 * Prepare a boot-mode command for delivery
165 *
166 * @cmd: pointer to bootrom header to prepare
167 *
168 * Computes checksum if so needed. After calling this function, DO NOT
169 * modify the command or header as the checksum won't work anymore.
170 *
171 * We do it from here because some times we cannot do it in the
172 * original context the command was sent (it is a const), so when we
173 * copy it to our staging buffer, we add the checksum there.
174 */
175void i2400m_bm_cmd_prepare(struct i2400m_bootrom_header *cmd)
176{
177 if (i2400m_brh_get_use_checksum(cmd)) {
178 int i;
179 u32 checksum = 0;
180 const u32 *checksum_ptr = (void *) cmd->payload;
181 for (i = 0; i < cmd->data_size / 4; i++)
182 checksum += cpu_to_le32(*checksum_ptr++);
183 checksum += cmd->command + cmd->target_addr + cmd->data_size;
184 cmd->block_checksum = cpu_to_le32(checksum);
185 }
186}
187EXPORT_SYMBOL_GPL(i2400m_bm_cmd_prepare);
188
189
190/*
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700191 * Database of known barkers.
192 *
193 * A barker is what the device sends indicating he is ready to be
194 * bootloaded. Different versions of the device will send different
195 * barkers. Depending on the barker, it might mean the device wants
196 * some kind of firmware or the other.
197 */
198static struct i2400m_barker_db {
199 __le32 data[4];
200} *i2400m_barker_db;
201static size_t i2400m_barker_db_used, i2400m_barker_db_size;
202
203
204static
205int i2400m_zrealloc_2x(void **ptr, size_t *_count, size_t el_size,
206 gfp_t gfp_flags)
207{
208 size_t old_count = *_count,
209 new_count = old_count ? 2 * old_count : 2,
210 old_size = el_size * old_count,
211 new_size = el_size * new_count;
212 void *nptr = krealloc(*ptr, new_size, gfp_flags);
213 if (nptr) {
214 /* zero the other half or the whole thing if old_count
215 * was zero */
216 if (old_size == 0)
217 memset(nptr, 0, new_size);
218 else
219 memset(nptr + old_size, 0, old_size);
220 *_count = new_count;
221 *ptr = nptr;
222 return 0;
223 } else
224 return -ENOMEM;
225}
226
227
228/*
229 * Add a barker to the database
230 *
231 * This cannot used outside of this module and only at at module_init
232 * time. This is to avoid the need to do locking.
233 */
234static
235int i2400m_barker_db_add(u32 barker_id)
236{
237 int result;
238
239 struct i2400m_barker_db *barker;
240 if (i2400m_barker_db_used >= i2400m_barker_db_size) {
241 result = i2400m_zrealloc_2x(
242 (void **) &i2400m_barker_db, &i2400m_barker_db_size,
243 sizeof(i2400m_barker_db[0]), GFP_KERNEL);
244 if (result < 0)
245 return result;
246 }
247 barker = i2400m_barker_db + i2400m_barker_db_used++;
248 barker->data[0] = le32_to_cpu(barker_id);
249 barker->data[1] = le32_to_cpu(barker_id);
250 barker->data[2] = le32_to_cpu(barker_id);
251 barker->data[3] = le32_to_cpu(barker_id);
252 return 0;
253}
254
255
256void i2400m_barker_db_exit(void)
257{
258 kfree(i2400m_barker_db);
259 i2400m_barker_db = NULL;
260 i2400m_barker_db_size = 0;
261 i2400m_barker_db_used = 0;
262}
263
264
265/*
266 * Helper function to add all the known stable barkers to the barker
267 * database.
268 */
269static
270int i2400m_barker_db_known_barkers(void)
271{
272 int result;
273
274 result = i2400m_barker_db_add(I2400M_NBOOT_BARKER);
275 if (result < 0)
276 goto error_add;
277 result = i2400m_barker_db_add(I2400M_SBOOT_BARKER);
278 if (result < 0)
279 goto error_add;
280error_add:
281 return result;
282}
283
284
285/*
286 * Initialize the barker database
287 *
288 * This can only be used from the module_init function for this
289 * module; this is to avoid the need to do locking.
290 *
291 * @options: command line argument with extra barkers to
292 * recognize. This is a comma-separated list of 32-bit hex
293 * numbers. They are appended to the existing list. Setting 0
294 * cleans the existing list and starts a new one.
295 */
296int i2400m_barker_db_init(const char *_options)
297{
298 int result;
299 char *options = NULL, *options_orig, *token;
300
301 i2400m_barker_db = NULL;
302 i2400m_barker_db_size = 0;
303 i2400m_barker_db_used = 0;
304
305 result = i2400m_barker_db_known_barkers();
306 if (result < 0)
307 goto error_add;
308 /* parse command line options from i2400m.barkers */
309 if (_options != NULL) {
310 unsigned barker;
311
312 options_orig = kstrdup(_options, GFP_KERNEL);
313 if (options_orig == NULL)
314 goto error_parse;
315 options = options_orig;
316
317 while ((token = strsep(&options, ",")) != NULL) {
318 if (*token == '\0') /* eat joint commas */
319 continue;
320 if (sscanf(token, "%x", &barker) != 1
321 || barker > 0xffffffff) {
322 printk(KERN_ERR "%s: can't recognize "
323 "i2400m.barkers value '%s' as "
324 "a 32-bit number\n",
325 __func__, token);
326 result = -EINVAL;
327 goto error_parse;
328 }
329 if (barker == 0) {
330 /* clean list and start new */
331 i2400m_barker_db_exit();
332 continue;
333 }
334 result = i2400m_barker_db_add(barker);
335 if (result < 0)
336 goto error_add;
337 }
338 kfree(options_orig);
339 }
340 return 0;
341
342error_parse:
343error_add:
344 kfree(i2400m_barker_db);
345 return result;
346}
347
348
349/*
350 * Recognize a boot barker
351 *
352 * @buf: buffer where the boot barker.
353 * @buf_size: size of the buffer (has to be 16 bytes). It is passed
354 * here so the function can check it for the caller.
355 *
356 * Note that as a side effect, upon identifying the obtained boot
357 * barker, this function will set i2400m->barker to point to the right
358 * barker database entry. Subsequent calls to the function will result
359 * in verifying that the same type of boot barker is returned when the
360 * device [re]boots (as long as the same device instance is used).
361 *
362 * Return: 0 if @buf matches a known boot barker. -ENOENT if the
363 * buffer in @buf doesn't match any boot barker in the database or
364 * -EILSEQ if the buffer doesn't have the right size.
365 */
366int i2400m_is_boot_barker(struct i2400m *i2400m,
367 const void *buf, size_t buf_size)
368{
369 int result;
370 struct device *dev = i2400m_dev(i2400m);
371 struct i2400m_barker_db *barker;
372 int i;
373
374 result = -ENOENT;
375 if (buf_size != sizeof(i2400m_barker_db[i].data))
376 return result;
377
378 /* Short circuit if we have already discovered the barker
379 * associated with the device. */
380 if (i2400m->barker
381 && !memcmp(buf, i2400m->barker, sizeof(i2400m->barker->data))) {
382 unsigned index = (i2400m->barker - i2400m_barker_db)
383 / sizeof(*i2400m->barker);
384 d_printf(2, dev, "boot barker cache-confirmed #%u/%08x\n",
385 index, le32_to_cpu(i2400m->barker->data[0]));
386 return 0;
387 }
388
389 for (i = 0; i < i2400m_barker_db_used; i++) {
390 barker = &i2400m_barker_db[i];
391 BUILD_BUG_ON(sizeof(barker->data) != 16);
392 if (memcmp(buf, barker->data, sizeof(barker->data)))
393 continue;
394
395 if (i2400m->barker == NULL) {
396 i2400m->barker = barker;
397 d_printf(1, dev, "boot barker set to #%u/%08x\n",
398 i, le32_to_cpu(barker->data[0]));
399 if (barker->data[0] == le32_to_cpu(I2400M_NBOOT_BARKER))
400 i2400m->sboot = 0;
401 else
402 i2400m->sboot = 1;
403 } else if (i2400m->barker != barker) {
404 dev_err(dev, "HW inconsistency: device "
405 "reports a different boot barker "
406 "than set (from %08x to %08x)\n",
407 le32_to_cpu(i2400m->barker->data[0]),
408 le32_to_cpu(barker->data[0]));
409 result = -EIO;
410 } else
411 d_printf(2, dev, "boot barker confirmed #%u/%08x\n",
412 i, le32_to_cpu(barker->data[0]));
413 result = 0;
414 break;
415 }
416 return result;
417}
418EXPORT_SYMBOL_GPL(i2400m_is_boot_barker);
419
420
421/*
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800422 * Verify the ack data received
423 *
424 * Given a reply to a boot mode command, chew it and verify everything
425 * is ok.
426 *
427 * @opcode: opcode which generated this ack. For error messages.
428 * @ack: pointer to ack data we received
429 * @ack_size: size of that data buffer
430 * @flags: I2400M_BM_CMD_* flags we called the command with.
431 *
432 * Way too long function -- maybe it should be further split
433 */
434static
435ssize_t __i2400m_bm_ack_verify(struct i2400m *i2400m, int opcode,
436 struct i2400m_bootrom_header *ack,
437 size_t ack_size, int flags)
438{
439 ssize_t result = -ENOMEM;
440 struct device *dev = i2400m_dev(i2400m);
441
442 d_fnstart(8, dev, "(i2400m %p opcode %d ack %p size %zu)\n",
443 i2400m, opcode, ack, ack_size);
444 if (ack_size < sizeof(*ack)) {
445 result = -EIO;
446 dev_err(dev, "boot-mode cmd %d: HW BUG? notification didn't "
447 "return enough data (%zu bytes vs %zu expected)\n",
448 opcode, ack_size, sizeof(*ack));
449 goto error_ack_short;
450 }
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700451 result = i2400m_is_boot_barker(i2400m, ack, ack_size);
452 if (result >= 0) {
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800453 result = -ERESTARTSYS;
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700454 d_printf(6, dev, "boot-mode cmd %d: HW boot barker\n", opcode);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800455 goto error_reboot;
456 }
457 if (ack_size == sizeof(i2400m_ACK_BARKER)
458 && memcmp(ack, i2400m_ACK_BARKER, sizeof(*ack)) == 0) {
459 result = -EISCONN;
460 d_printf(3, dev, "boot-mode cmd %d: HW reboot ack barker\n",
461 opcode);
462 goto error_reboot_ack;
463 }
464 result = 0;
465 if (flags & I2400M_BM_CMD_RAW)
466 goto out_raw;
467 ack->data_size = le32_to_cpu(ack->data_size);
468 ack->target_addr = le32_to_cpu(ack->target_addr);
469 ack->block_checksum = le32_to_cpu(ack->block_checksum);
470 d_printf(5, dev, "boot-mode cmd %d: notification for opcode %u "
471 "response %u csum %u rr %u da %u\n",
472 opcode, i2400m_brh_get_opcode(ack),
473 i2400m_brh_get_response(ack),
474 i2400m_brh_get_use_checksum(ack),
475 i2400m_brh_get_response_required(ack),
476 i2400m_brh_get_direct_access(ack));
477 result = -EIO;
478 if (i2400m_brh_get_signature(ack) != 0xcbbc) {
479 dev_err(dev, "boot-mode cmd %d: HW BUG? wrong signature "
480 "0x%04x\n", opcode, i2400m_brh_get_signature(ack));
481 goto error_ack_signature;
482 }
483 if (opcode != -1 && opcode != i2400m_brh_get_opcode(ack)) {
484 dev_err(dev, "boot-mode cmd %d: HW BUG? "
485 "received response for opcode %u, expected %u\n",
486 opcode, i2400m_brh_get_opcode(ack), opcode);
487 goto error_ack_opcode;
488 }
489 if (i2400m_brh_get_response(ack) != 0) { /* failed? */
490 dev_err(dev, "boot-mode cmd %d: error; hw response %u\n",
491 opcode, i2400m_brh_get_response(ack));
492 goto error_ack_failed;
493 }
494 if (ack_size < ack->data_size + sizeof(*ack)) {
495 dev_err(dev, "boot-mode cmd %d: SW BUG "
496 "driver provided only %zu bytes for %zu bytes "
497 "of data\n", opcode, ack_size,
498 (size_t) le32_to_cpu(ack->data_size) + sizeof(*ack));
499 goto error_ack_short_buffer;
500 }
501 result = ack_size;
502 /* Don't you love this stack of empty targets? Well, I don't
503 * either, but it helps track exactly who comes in here and
504 * why :) */
505error_ack_short_buffer:
506error_ack_failed:
507error_ack_opcode:
508error_ack_signature:
509out_raw:
510error_reboot_ack:
511error_reboot:
512error_ack_short:
513 d_fnend(8, dev, "(i2400m %p opcode %d ack %p size %zu) = %d\n",
514 i2400m, opcode, ack, ack_size, (int) result);
515 return result;
516}
517
518
519/**
520 * i2400m_bm_cmd - Execute a boot mode command
521 *
522 * @cmd: buffer containing the command data (pointing at the header).
523 * This data can be ANYWHERE (for USB, we will copy it to an
524 * specific buffer). Make sure everything is in proper little
525 * endian.
526 *
527 * A raw buffer can be also sent, just cast it and set flags to
528 * I2400M_BM_CMD_RAW.
529 *
530 * This function will generate a checksum for you if the
531 * checksum bit in the command is set (unless I2400M_BM_CMD_RAW
532 * is set).
533 *
534 * You can use the i2400m->bm_cmd_buf to stage your commands and
535 * send them.
536 *
537 * If NULL, no command is sent (we just wait for an ack).
538 *
539 * @cmd_size: size of the command. Will be auto padded to the
540 * bus-specific drivers padding requirements.
541 *
542 * @ack: buffer where to place the acknowledgement. If it is a regular
543 * command response, all fields will be returned with the right,
544 * native endianess.
545 *
546 * You *cannot* use i2400m->bm_ack_buf for this buffer.
547 *
548 * @ack_size: size of @ack, 16 aligned; you need to provide at least
549 * sizeof(*ack) bytes and then enough to contain the return data
550 * from the command
551 *
552 * @flags: see I2400M_BM_CMD_* above.
553 *
554 * @returns: bytes received by the notification; if < 0, an errno code
555 * denoting an error or:
556 *
557 * -ERESTARTSYS The device has rebooted
558 *
559 * Executes a boot-mode command and waits for a response, doing basic
560 * validation on it; if a zero length response is received, it retries
561 * waiting for a response until a non-zero one is received (timing out
562 * after %I2400M_BOOT_RETRIES retries).
563 */
564static
565ssize_t i2400m_bm_cmd(struct i2400m *i2400m,
566 const struct i2400m_bootrom_header *cmd, size_t cmd_size,
567 struct i2400m_bootrom_header *ack, size_t ack_size,
568 int flags)
569{
570 ssize_t result = -ENOMEM, rx_bytes;
571 struct device *dev = i2400m_dev(i2400m);
572 int opcode = cmd == NULL ? -1 : i2400m_brh_get_opcode(cmd);
573
574 d_fnstart(6, dev, "(i2400m %p cmd %p size %zu ack %p size %zu)\n",
575 i2400m, cmd, cmd_size, ack, ack_size);
576 BUG_ON(ack_size < sizeof(*ack));
577 BUG_ON(i2400m->boot_mode == 0);
578
579 if (cmd != NULL) { /* send the command */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800580 result = i2400m->bus_bm_cmd_send(i2400m, cmd, cmd_size, flags);
581 if (result < 0)
582 goto error_cmd_send;
583 if ((flags & I2400M_BM_CMD_RAW) == 0)
584 d_printf(5, dev,
585 "boot-mode cmd %d csum %u rr %u da %u: "
586 "addr 0x%04x size %u block csum 0x%04x\n",
587 opcode, i2400m_brh_get_use_checksum(cmd),
588 i2400m_brh_get_response_required(cmd),
589 i2400m_brh_get_direct_access(cmd),
590 cmd->target_addr, cmd->data_size,
591 cmd->block_checksum);
592 }
593 result = i2400m->bus_bm_wait_for_ack(i2400m, ack, ack_size);
594 if (result < 0) {
595 dev_err(dev, "boot-mode cmd %d: error waiting for an ack: %d\n",
596 opcode, (int) result); /* bah, %zd doesn't work */
597 goto error_wait_for_ack;
598 }
599 rx_bytes = result;
600 /* verify the ack and read more if neccessary [result is the
601 * final amount of bytes we get in the ack] */
602 result = __i2400m_bm_ack_verify(i2400m, opcode, ack, ack_size, flags);
603 if (result < 0)
604 goto error_bad_ack;
605 /* Don't you love this stack of empty targets? Well, I don't
606 * either, but it helps track exactly who comes in here and
607 * why :) */
608 result = rx_bytes;
609error_bad_ack:
610error_wait_for_ack:
611error_cmd_send:
612 d_fnend(6, dev, "(i2400m %p cmd %p size %zu ack %p size %zu) = %d\n",
613 i2400m, cmd, cmd_size, ack, ack_size, (int) result);
614 return result;
615}
616
617
618/**
619 * i2400m_download_chunk - write a single chunk of data to the device's memory
620 *
621 * @i2400m: device descriptor
622 * @buf: the buffer to write
623 * @buf_len: length of the buffer to write
624 * @addr: address in the device memory space
625 * @direct: bootrom write mode
626 * @do_csum: should a checksum validation be performed
627 */
628static int i2400m_download_chunk(struct i2400m *i2400m, const void *chunk,
629 size_t __chunk_len, unsigned long addr,
630 unsigned int direct, unsigned int do_csum)
631{
632 int ret;
Inaky Perez-Gonzalez8593a192009-05-20 16:53:30 -0700633 size_t chunk_len = ALIGN(__chunk_len, I2400M_PL_ALIGN);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800634 struct device *dev = i2400m_dev(i2400m);
635 struct {
636 struct i2400m_bootrom_header cmd;
637 u8 cmd_payload[chunk_len];
638 } __attribute__((packed)) *buf;
639 struct i2400m_bootrom_header ack;
640
641 d_fnstart(5, dev, "(i2400m %p chunk %p __chunk_len %zu addr 0x%08lx "
642 "direct %u do_csum %u)\n", i2400m, chunk, __chunk_len,
643 addr, direct, do_csum);
644 buf = i2400m->bm_cmd_buf;
645 memcpy(buf->cmd_payload, chunk, __chunk_len);
646 memset(buf->cmd_payload + __chunk_len, 0xad, chunk_len - __chunk_len);
647
648 buf->cmd.command = i2400m_brh_command(I2400M_BRH_WRITE,
649 __chunk_len & 0x3 ? 0 : do_csum,
650 __chunk_len & 0xf ? 0 : direct);
651 buf->cmd.target_addr = cpu_to_le32(addr);
652 buf->cmd.data_size = cpu_to_le32(__chunk_len);
653 ret = i2400m_bm_cmd(i2400m, &buf->cmd, sizeof(buf->cmd) + chunk_len,
654 &ack, sizeof(ack), 0);
655 if (ret >= 0)
656 ret = 0;
657 d_fnend(5, dev, "(i2400m %p chunk %p __chunk_len %zu addr 0x%08lx "
658 "direct %u do_csum %u) = %d\n", i2400m, chunk, __chunk_len,
659 addr, direct, do_csum, ret);
660 return ret;
661}
662
663
664/*
665 * Download a BCF file's sections to the device
666 *
667 * @i2400m: device descriptor
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -0700668 * @bcf: pointer to firmware data (first header followed by the
669 * payloads). Assumed verified and consistent.
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800670 * @bcf_len: length (in bytes) of the @bcf buffer.
671 *
672 * Returns: < 0 errno code on error or the offset to the jump instruction.
673 *
674 * Given a BCF file, downloads each section (a command and a payload)
675 * to the device's address space. Actually, it just executes each
676 * command i the BCF file.
677 *
678 * The section size has to be aligned to 4 bytes AND the padding has
679 * to be taken from the firmware file, as the signature takes it into
680 * account.
681 */
682static
683ssize_t i2400m_dnload_bcf(struct i2400m *i2400m,
684 const struct i2400m_bcf_hdr *bcf, size_t bcf_len)
685{
686 ssize_t ret;
687 struct device *dev = i2400m_dev(i2400m);
688 size_t offset, /* iterator offset */
689 data_size, /* Size of the data payload */
690 section_size, /* Size of the whole section (cmd + payload) */
691 section = 1;
692 const struct i2400m_bootrom_header *bh;
693 struct i2400m_bootrom_header ack;
694
695 d_fnstart(3, dev, "(i2400m %p bcf %p bcf_len %zu)\n",
696 i2400m, bcf, bcf_len);
697 /* Iterate over the command blocks in the BCF file that start
698 * after the header */
699 offset = le32_to_cpu(bcf->header_len) * sizeof(u32);
700 while (1) { /* start sending the file */
701 bh = (void *) bcf + offset;
702 data_size = le32_to_cpu(bh->data_size);
703 section_size = ALIGN(sizeof(*bh) + data_size, 4);
704 d_printf(7, dev,
705 "downloading section #%zu (@%zu %zu B) to 0x%08x\n",
706 section, offset, sizeof(*bh) + data_size,
707 le32_to_cpu(bh->target_addr));
708 if (i2400m_brh_get_opcode(bh) == I2400M_BRH_SIGNED_JUMP) {
709 /* Secure boot needs to stop here */
710 d_printf(5, dev, "signed jump found @%zu\n", offset);
711 break;
712 }
713 if (offset + section_size == bcf_len)
714 /* Non-secure boot stops here */
715 break;
716 if (offset + section_size > bcf_len) {
717 dev_err(dev, "fw %s: bad section #%zu, "
718 "end (@%zu) beyond EOF (@%zu)\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000719 i2400m->fw_name, section,
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800720 offset + section_size, bcf_len);
721 ret = -EINVAL;
722 goto error_section_beyond_eof;
723 }
724 __i2400m_msleep(20);
725 ret = i2400m_bm_cmd(i2400m, bh, section_size,
726 &ack, sizeof(ack), I2400M_BM_CMD_RAW);
727 if (ret < 0) {
728 dev_err(dev, "fw %s: section #%zu (@%zu %zu B) "
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000729 "failed %d\n", i2400m->fw_name, section,
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800730 offset, sizeof(*bh) + data_size, (int) ret);
731 goto error_send;
732 }
733 offset += section_size;
734 section++;
735 }
736 ret = offset;
737error_section_beyond_eof:
738error_send:
739 d_fnend(3, dev, "(i2400m %p bcf %p bcf_len %zu) = %d\n",
740 i2400m, bcf, bcf_len, (int) ret);
741 return ret;
742}
743
744
745/*
Inaky Perez-Gonzalez32742e62009-09-03 15:56:40 -0700746 * Indicate if the device emitted a reboot barker that indicates
747 * "signed boot"
748 */
749static
750unsigned i2400m_boot_is_signed(struct i2400m *i2400m)
751{
752 return likely(i2400m->sboot);
753}
754
755
756/*
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800757 * Do the final steps of uploading firmware
758 *
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -0700759 * @bcf_hdr: BCF header we are actually using
760 * @bcf: pointer to the firmware image (which matches the first header
761 * that is followed by the actual payloads).
762 * @offset: [byte] offset into @bcf for the command we need to send.
763 *
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800764 * Depending on the boot mode (signed vs non-signed), different
765 * actions need to be taken.
766 */
767static
768int i2400m_dnload_finalize(struct i2400m *i2400m,
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -0700769 const struct i2400m_bcf_hdr *bcf_hdr,
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800770 const struct i2400m_bcf_hdr *bcf, size_t offset)
771{
772 int ret = 0;
773 struct device *dev = i2400m_dev(i2400m);
774 struct i2400m_bootrom_header *cmd, ack;
775 struct {
776 struct i2400m_bootrom_header cmd;
777 u8 cmd_pl[0];
778 } __attribute__((packed)) *cmd_buf;
779 size_t signature_block_offset, signature_block_size;
780
781 d_fnstart(3, dev, "offset %zu\n", offset);
782 cmd = (void *) bcf + offset;
Inaky Perez-Gonzalez32742e62009-09-03 15:56:40 -0700783 if (i2400m_boot_is_signed(i2400m) == 0) {
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800784 struct i2400m_bootrom_header jump_ack;
Dirk Brandewieead68232009-05-12 06:22:27 -0700785 d_printf(1, dev, "unsecure boot, jumping to 0x%08x\n",
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800786 le32_to_cpu(cmd->target_addr));
Cindy H Kao8d8fe192009-08-18 19:27:18 -0700787 cmd_buf = i2400m->bm_cmd_buf;
788 memcpy(&cmd_buf->cmd, cmd, sizeof(*cmd));
789 cmd = &cmd_buf->cmd;
790 /* now cmd points to the actual bootrom_header in cmd_buf */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800791 i2400m_brh_set_opcode(cmd, I2400M_BRH_JUMP);
792 cmd->data_size = 0;
793 ret = i2400m_bm_cmd(i2400m, cmd, sizeof(*cmd),
794 &jump_ack, sizeof(jump_ack), 0);
795 } else {
Dirk Brandewieead68232009-05-12 06:22:27 -0700796 d_printf(1, dev, "secure boot, jumping to 0x%08x\n",
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800797 le32_to_cpu(cmd->target_addr));
798 cmd_buf = i2400m->bm_cmd_buf;
799 memcpy(&cmd_buf->cmd, cmd, sizeof(*cmd));
800 signature_block_offset =
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -0700801 sizeof(*bcf_hdr)
802 + le32_to_cpu(bcf_hdr->key_size) * sizeof(u32)
803 + le32_to_cpu(bcf_hdr->exponent_size) * sizeof(u32);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800804 signature_block_size =
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -0700805 le32_to_cpu(bcf_hdr->modulus_size) * sizeof(u32);
806 memcpy(cmd_buf->cmd_pl,
807 (void *) bcf_hdr + signature_block_offset,
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800808 signature_block_size);
809 ret = i2400m_bm_cmd(i2400m, &cmd_buf->cmd,
810 sizeof(cmd_buf->cmd) + signature_block_size,
811 &ack, sizeof(ack), I2400M_BM_CMD_RAW);
812 }
813 d_fnend(3, dev, "returning %d\n", ret);
814 return ret;
815}
816
817
818/**
819 * i2400m_bootrom_init - Reboots a powered device into boot mode
820 *
821 * @i2400m: device descriptor
822 * @flags:
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700823 * I2400M_BRI_SOFT: a reboot barker has been seen
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800824 * already, so don't wait for it.
825 *
826 * I2400M_BRI_NO_REBOOT: Don't send a reboot command, but wait
827 * for a reboot barker notification. This is a one shot; if
828 * the state machine needs to send a reboot command it will.
829 *
830 * Returns:
831 *
832 * < 0 errno code on error, 0 if ok.
833 *
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800834 * Description:
835 *
836 * Tries hard enough to put the device in boot-mode. There are two
837 * main phases to this:
838 *
839 * a. (1) send a reboot command and (2) get a reboot barker
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700840 *
841 * b. (1) echo/ack the reboot sending the reboot barker back and (2)
842 * getting an ack barker in return
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800843 *
844 * We want to skip (a) in some cases [soft]. The state machine is
845 * horrible, but it is basically: on each phase, send what has to be
846 * sent (if any), wait for the answer and act on the answer. We might
847 * have to backtrack and retry, so we keep a max tries counter for
848 * that.
849 *
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700850 * It sucks because we don't know ahead of time which is going to be
851 * the reboot barker (the device might send different ones depending
852 * on its EEPROM config) and once the device reboots and waits for the
853 * echo/ack reboot barker being sent back, it doesn't understand
854 * anything else. So we can be left at the point where we don't know
855 * what to send to it -- cold reset and bus reset seem to have little
856 * effect. So the function iterates (in this case) through all the
857 * known barkers and tries them all until an ACK is
858 * received. Otherwise, it gives up.
859 *
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800860 * If we get a timeout after sending a warm reset, we do it again.
861 */
862int i2400m_bootrom_init(struct i2400m *i2400m, enum i2400m_bri flags)
863{
864 int result;
865 struct device *dev = i2400m_dev(i2400m);
866 struct i2400m_bootrom_header *cmd;
867 struct i2400m_bootrom_header ack;
Dirk Brandewiec3083652009-08-13 13:48:29 -0700868 int count = i2400m->bus_bm_retries;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800869 int ack_timeout_cnt = 1;
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700870 unsigned i;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800871
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700872 BUILD_BUG_ON(sizeof(*cmd) != sizeof(i2400m_barker_db[0].data));
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800873 BUILD_BUG_ON(sizeof(ack) != sizeof(i2400m_ACK_BARKER));
874
875 d_fnstart(4, dev, "(i2400m %p flags 0x%08x)\n", i2400m, flags);
876 result = -ENOMEM;
877 cmd = i2400m->bm_cmd_buf;
878 if (flags & I2400M_BRI_SOFT)
879 goto do_reboot_ack;
880do_reboot:
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700881 ack_timeout_cnt = 1;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800882 if (--count < 0)
883 goto error_timeout;
884 d_printf(4, dev, "device reboot: reboot command [%d # left]\n",
885 count);
886 if ((flags & I2400M_BRI_NO_REBOOT) == 0)
887 i2400m->bus_reset(i2400m, I2400M_RT_WARM);
888 result = i2400m_bm_cmd(i2400m, NULL, 0, &ack, sizeof(ack),
889 I2400M_BM_CMD_RAW);
890 flags &= ~I2400M_BRI_NO_REBOOT;
891 switch (result) {
892 case -ERESTARTSYS:
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700893 /*
894 * at this point, i2400m_bm_cmd(), through
895 * __i2400m_bm_ack_process(), has updated
896 * i2400m->barker and we are good to go.
897 */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800898 d_printf(4, dev, "device reboot: got reboot barker\n");
899 break;
900 case -EISCONN: /* we don't know how it got here...but we follow it */
901 d_printf(4, dev, "device reboot: got ack barker - whatever\n");
902 goto do_reboot;
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700903 case -ETIMEDOUT:
904 /*
905 * Device has timed out, we might be in boot mode
906 * already and expecting an ack; if we don't know what
907 * the barker is, we just send them all. Cold reset
908 * and bus reset don't work. Beats me.
909 */
910 if (i2400m->barker != NULL) {
911 dev_err(dev, "device boot: reboot barker timed out, "
912 "trying (set) %08x echo/ack\n",
913 le32_to_cpu(i2400m->barker->data[0]));
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700914 goto do_reboot_ack;
915 }
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700916 for (i = 0; i < i2400m_barker_db_used; i++) {
917 struct i2400m_barker_db *barker = &i2400m_barker_db[i];
918 memcpy(cmd, barker->data, sizeof(barker->data));
919 result = i2400m_bm_cmd(i2400m, cmd, sizeof(*cmd),
920 &ack, sizeof(ack),
921 I2400M_BM_CMD_RAW);
922 if (result == -EISCONN) {
923 dev_warn(dev, "device boot: got ack barker "
924 "after sending echo/ack barker "
925 "#%d/%08x; rebooting j.i.c.\n",
926 i, le32_to_cpu(barker->data[0]));
927 flags &= ~I2400M_BRI_NO_REBOOT;
928 goto do_reboot;
929 }
930 }
931 dev_err(dev, "device boot: tried all the echo/acks, could "
932 "not get device to respond; giving up");
933 result = -ESHUTDOWN;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800934 case -EPROTO:
935 case -ESHUTDOWN: /* dev is gone */
936 case -EINTR: /* user cancelled */
937 goto error_dev_gone;
938 default:
939 dev_err(dev, "device reboot: error %d while waiting "
940 "for reboot barker - rebooting\n", result);
Inaky Perez-Gonzalez923d7082009-09-04 14:50:59 -0700941 d_dump(1, dev, &ack, result);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800942 goto do_reboot;
943 }
944 /* At this point we ack back with 4 REBOOT barkers and expect
945 * 4 ACK barkers. This is ugly, as we send a raw command --
946 * hence the cast. _bm_cmd() will catch the reboot ack
947 * notification and report it as -EISCONN. */
948do_reboot_ack:
949 d_printf(4, dev, "device reboot ack: sending ack [%d # left]\n", count);
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700950 memcpy(cmd, i2400m->barker->data, sizeof(i2400m->barker->data));
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800951 result = i2400m_bm_cmd(i2400m, cmd, sizeof(*cmd),
952 &ack, sizeof(ack), I2400M_BM_CMD_RAW);
953 switch (result) {
954 case -ERESTARTSYS:
955 d_printf(4, dev, "reboot ack: got reboot barker - retrying\n");
956 if (--count < 0)
957 goto error_timeout;
958 goto do_reboot_ack;
959 case -EISCONN:
960 d_printf(4, dev, "reboot ack: got ack barker - good\n");
961 break;
962 case -ETIMEDOUT: /* no response, maybe it is the other type? */
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700963 if (ack_timeout_cnt-- < 0) {
964 d_printf(4, dev, "reboot ack timedout: retrying\n");
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800965 goto do_reboot_ack;
966 } else {
967 dev_err(dev, "reboot ack timedout too long: "
968 "trying reboot\n");
969 goto do_reboot;
970 }
971 break;
972 case -EPROTO:
973 case -ESHUTDOWN: /* dev is gone */
974 goto error_dev_gone;
975 default:
976 dev_err(dev, "device reboot ack: error %d while waiting for "
977 "reboot ack barker - rebooting\n", result);
978 goto do_reboot;
979 }
980 d_printf(2, dev, "device reboot ack: got ack barker - boot done\n");
981 result = 0;
982exit_timeout:
983error_dev_gone:
984 d_fnend(4, dev, "(i2400m %p flags 0x%08x) = %d\n",
985 i2400m, flags, result);
986 return result;
987
988error_timeout:
Inaky Perez-Gonzalez6e053d62009-06-05 09:31:26 +0800989 dev_err(dev, "Timed out waiting for reboot ack\n");
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800990 result = -ETIMEDOUT;
991 goto exit_timeout;
992}
993
994
995/*
996 * Read the MAC addr
997 *
998 * The position this function reads is fixed in device memory and
999 * always available, even without firmware.
1000 *
1001 * Note we specify we want to read only six bytes, but provide space
1002 * for 16, as we always get it rounded up.
1003 */
1004int i2400m_read_mac_addr(struct i2400m *i2400m)
1005{
1006 int result;
1007 struct device *dev = i2400m_dev(i2400m);
1008 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
1009 struct i2400m_bootrom_header *cmd;
1010 struct {
1011 struct i2400m_bootrom_header ack;
1012 u8 ack_pl[16];
1013 } __attribute__((packed)) ack_buf;
1014
1015 d_fnstart(5, dev, "(i2400m %p)\n", i2400m);
1016 cmd = i2400m->bm_cmd_buf;
1017 cmd->command = i2400m_brh_command(I2400M_BRH_READ, 0, 1);
1018 cmd->target_addr = cpu_to_le32(0x00203fe8);
1019 cmd->data_size = cpu_to_le32(6);
1020 result = i2400m_bm_cmd(i2400m, cmd, sizeof(*cmd),
1021 &ack_buf.ack, sizeof(ack_buf), 0);
1022 if (result < 0) {
1023 dev_err(dev, "BM: read mac addr failed: %d\n", result);
1024 goto error_read_mac;
1025 }
1026 d_printf(2, dev,
1027 "mac addr is %02x:%02x:%02x:%02x:%02x:%02x\n",
1028 ack_buf.ack_pl[0], ack_buf.ack_pl[1],
1029 ack_buf.ack_pl[2], ack_buf.ack_pl[3],
1030 ack_buf.ack_pl[4], ack_buf.ack_pl[5]);
1031 if (i2400m->bus_bm_mac_addr_impaired == 1) {
1032 ack_buf.ack_pl[0] = 0x00;
1033 ack_buf.ack_pl[1] = 0x16;
1034 ack_buf.ack_pl[2] = 0xd3;
1035 get_random_bytes(&ack_buf.ack_pl[3], 3);
1036 dev_err(dev, "BM is MAC addr impaired, faking MAC addr to "
1037 "mac addr is %02x:%02x:%02x:%02x:%02x:%02x\n",
1038 ack_buf.ack_pl[0], ack_buf.ack_pl[1],
1039 ack_buf.ack_pl[2], ack_buf.ack_pl[3],
1040 ack_buf.ack_pl[4], ack_buf.ack_pl[5]);
1041 result = 0;
1042 }
1043 net_dev->addr_len = ETH_ALEN;
1044 memcpy(net_dev->perm_addr, ack_buf.ack_pl, ETH_ALEN);
1045 memcpy(net_dev->dev_addr, ack_buf.ack_pl, ETH_ALEN);
1046error_read_mac:
1047 d_fnend(5, dev, "(i2400m %p) = %d\n", i2400m, result);
1048 return result;
1049}
1050
1051
1052/*
1053 * Initialize a non signed boot
1054 *
1055 * This implies sending some magic values to the device's memory. Note
1056 * we convert the values to little endian in the same array
1057 * declaration.
1058 */
1059static
1060int i2400m_dnload_init_nonsigned(struct i2400m *i2400m)
1061{
Dirk Brandewie7308a0c2009-05-21 11:56:34 -07001062 unsigned i = 0;
1063 int ret = 0;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001064 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001065 d_fnstart(5, dev, "(i2400m %p)\n", i2400m);
Dirk Brandewie7308a0c2009-05-21 11:56:34 -07001066 if (i2400m->bus_bm_pokes_table) {
1067 while (i2400m->bus_bm_pokes_table[i].address) {
1068 ret = i2400m_download_chunk(
1069 i2400m,
1070 &i2400m->bus_bm_pokes_table[i].data,
1071 sizeof(i2400m->bus_bm_pokes_table[i].data),
1072 i2400m->bus_bm_pokes_table[i].address, 1, 1);
1073 if (ret < 0)
1074 break;
1075 i++;
1076 }
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001077 }
1078 d_fnend(5, dev, "(i2400m %p) = %d\n", i2400m, ret);
1079 return ret;
1080}
1081
1082
1083/*
1084 * Initialize the signed boot process
1085 *
1086 * @i2400m: device descriptor
1087 *
1088 * @bcf_hdr: pointer to the firmware header; assumes it is fully in
1089 * memory (it has gone through basic validation).
1090 *
1091 * Returns: 0 if ok, < 0 errno code on error, -ERESTARTSYS if the hw
1092 * rebooted.
1093 *
1094 * This writes the firmware BCF header to the device using the
1095 * HASH_PAYLOAD_ONLY command.
1096 */
1097static
1098int i2400m_dnload_init_signed(struct i2400m *i2400m,
1099 const struct i2400m_bcf_hdr *bcf_hdr)
1100{
1101 int ret;
1102 struct device *dev = i2400m_dev(i2400m);
1103 struct {
1104 struct i2400m_bootrom_header cmd;
1105 struct i2400m_bcf_hdr cmd_pl;
1106 } __attribute__((packed)) *cmd_buf;
1107 struct i2400m_bootrom_header ack;
1108
1109 d_fnstart(5, dev, "(i2400m %p bcf_hdr %p)\n", i2400m, bcf_hdr);
1110 cmd_buf = i2400m->bm_cmd_buf;
1111 cmd_buf->cmd.command =
1112 i2400m_brh_command(I2400M_BRH_HASH_PAYLOAD_ONLY, 0, 0);
1113 cmd_buf->cmd.target_addr = 0;
1114 cmd_buf->cmd.data_size = cpu_to_le32(sizeof(cmd_buf->cmd_pl));
1115 memcpy(&cmd_buf->cmd_pl, bcf_hdr, sizeof(*bcf_hdr));
1116 ret = i2400m_bm_cmd(i2400m, &cmd_buf->cmd, sizeof(*cmd_buf),
1117 &ack, sizeof(ack), 0);
1118 if (ret >= 0)
1119 ret = 0;
1120 d_fnend(5, dev, "(i2400m %p bcf_hdr %p) = %d\n", i2400m, bcf_hdr, ret);
1121 return ret;
1122}
1123
1124
1125/*
1126 * Initialize the firmware download at the device size
1127 *
1128 * Multiplex to the one that matters based on the device's mode
1129 * (signed or non-signed).
1130 */
1131static
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001132int i2400m_dnload_init(struct i2400m *i2400m,
1133 const struct i2400m_bcf_hdr *bcf_hdr)
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001134{
1135 int result;
1136 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001137
Inaky Perez-Gonzalez32742e62009-09-03 15:56:40 -07001138 if (i2400m_boot_is_signed(i2400m)) {
1139 d_printf(1, dev, "signed boot\n");
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001140 result = i2400m_dnload_init_signed(i2400m, bcf_hdr);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001141 if (result == -ERESTARTSYS)
1142 return result;
1143 if (result < 0)
Inaky Perez-Gonzalez32742e62009-09-03 15:56:40 -07001144 dev_err(dev, "firmware %s: signed boot download "
1145 "initialization failed: %d\n",
1146 i2400m->fw_name, result);
1147 } else {
1148 /* non-signed boot process without pokes */
1149 d_printf(1, dev, "non-signed boot\n");
1150 result = i2400m_dnload_init_nonsigned(i2400m);
1151 if (result == -ERESTARTSYS)
1152 return result;
1153 if (result < 0)
1154 dev_err(dev, "firmware %s: non-signed download "
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001155 "initialization failed: %d\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001156 i2400m->fw_name, result);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001157 }
1158 return result;
1159}
1160
1161
1162/*
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001163 * Run consistency tests on the firmware file and load up headers
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001164 *
1165 * Check for the firmware being made for the i2400m device,
1166 * etc...These checks are mostly informative, as the device will make
1167 * them too; but the driver's response is more informative on what
1168 * went wrong.
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001169 *
1170 * This will also look at all the headers present on the firmware
1171 * file, and update i2400m->fw_bcf_hdr to point to them.
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001172 */
1173static
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001174int i2400m_fw_hdr_check(struct i2400m *i2400m,
1175 const struct i2400m_bcf_hdr *bcf_hdr,
1176 size_t index, size_t offset)
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001177{
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001178 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001179
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001180 unsigned module_type, header_len, major_version, minor_version,
1181 module_id, module_vendor, date, size;
1182
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001183 module_type = bcf_hdr->module_type;
1184 header_len = sizeof(u32) * le32_to_cpu(bcf_hdr->header_len);
1185 major_version = (le32_to_cpu(bcf_hdr->header_version) & 0xffff0000)
1186 >> 16;
1187 minor_version = le32_to_cpu(bcf_hdr->header_version) & 0x0000ffff;
1188 module_id = le32_to_cpu(bcf_hdr->module_id);
1189 module_vendor = le32_to_cpu(bcf_hdr->module_vendor);
1190 date = le32_to_cpu(bcf_hdr->date);
1191 size = sizeof(u32) * le32_to_cpu(bcf_hdr->size);
1192
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001193 d_printf(1, dev, "firmware %s #%zd@%08zx: BCF header "
1194 "type:vendor:id 0x%x:%x:%x v%u.%u (%u/%u B) built %08x\n",
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001195 i2400m->fw_name, index, offset,
1196 module_type, module_vendor, module_id,
1197 major_version, minor_version, header_len, size, date);
1198
1199 /* Hard errors */
1200 if (major_version != 1) {
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001201 dev_err(dev, "firmware %s #%zd@%08zx: major header version "
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001202 "v%u.%u not supported\n",
1203 i2400m->fw_name, index, offset,
1204 major_version, minor_version);
1205 return -EBADF;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001206 }
1207
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001208 if (module_type != 6) { /* built for the right hardware? */
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001209 dev_err(dev, "firmware %s #%zd@%08zx: unexpected module "
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001210 "type 0x%x; aborting\n",
1211 i2400m->fw_name, index, offset,
1212 module_type);
1213 return -EBADF;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001214 }
1215
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001216 if (module_vendor != 0x8086) {
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001217 dev_err(dev, "firmware %s #%zd@%08zx: unexpected module "
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001218 "vendor 0x%x; aborting\n",
1219 i2400m->fw_name, index, offset, module_vendor);
1220 return -EBADF;
Inaky Perez-Gonzalezfabce1a2009-09-04 14:53:43 -07001221 }
1222
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001223 if (date < 0x20080300)
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001224 dev_warn(dev, "firmware %s #%zd@%08zx: build date %08x "
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001225 "too old; unsupported\n",
1226 i2400m->fw_name, index, offset, date);
1227 return 0;
1228}
1229
1230
1231/*
1232 * Run consistency tests on the firmware file and load up headers
1233 *
1234 * Check for the firmware being made for the i2400m device,
1235 * etc...These checks are mostly informative, as the device will make
1236 * them too; but the driver's response is more informative on what
1237 * went wrong.
1238 *
1239 * This will also look at all the headers present on the firmware
1240 * file, and update i2400m->fw_hdrs to point to them.
1241 */
1242static
1243int i2400m_fw_check(struct i2400m *i2400m, const void *bcf, size_t bcf_size)
1244{
1245 int result;
1246 struct device *dev = i2400m_dev(i2400m);
1247 size_t headers = 0;
1248 const struct i2400m_bcf_hdr *bcf_hdr;
1249 const void *itr, *next, *top;
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001250 size_t slots = 0, used_slots = 0;
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001251
1252 for (itr = bcf, top = itr + bcf_size;
1253 itr < top;
1254 headers++, itr = next) {
1255 size_t leftover, offset, header_len, size;
1256
1257 leftover = top - itr;
1258 offset = itr - (const void *) bcf;
1259 if (leftover <= sizeof(*bcf_hdr)) {
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001260 dev_err(dev, "firmware %s: %zu B left at @%zx, "
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001261 "not enough for BCF header\n",
1262 i2400m->fw_name, leftover, offset);
1263 break;
1264 }
1265 bcf_hdr = itr;
1266 /* Only the first header is supposed to be followed by
1267 * payload */
1268 header_len = sizeof(u32) * le32_to_cpu(bcf_hdr->header_len);
1269 size = sizeof(u32) * le32_to_cpu(bcf_hdr->size);
1270 if (headers == 0)
1271 next = itr + size;
1272 else
1273 next = itr + header_len;
1274
1275 result = i2400m_fw_hdr_check(i2400m, bcf_hdr, headers, offset);
1276 if (result < 0)
1277 continue;
1278 if (used_slots + 1 >= slots) {
1279 /* +1 -> we need to account for the one we'll
1280 * occupy and at least an extra one for
1281 * always being NULL */
1282 result = i2400m_zrealloc_2x(
1283 (void **) &i2400m->fw_hdrs, &slots,
1284 sizeof(i2400m->fw_hdrs[0]),
1285 GFP_KERNEL);
1286 if (result < 0)
1287 goto error_zrealloc;
1288 }
1289 i2400m->fw_hdrs[used_slots] = bcf_hdr;
1290 used_slots++;
1291 }
1292 if (headers == 0) {
1293 dev_err(dev, "firmware %s: no usable headers found\n",
1294 i2400m->fw_name);
1295 result = -EBADF;
1296 } else
1297 result = 0;
1298error_zrealloc:
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001299 return result;
1300}
1301
1302
1303/*
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001304 * Match a barker to a BCF header module ID
1305 *
1306 * The device sends a barker which tells the firmware loader which
1307 * header in the BCF file has to be used. This does the matching.
1308 */
1309static
1310unsigned i2400m_bcf_hdr_match(struct i2400m *i2400m,
1311 const struct i2400m_bcf_hdr *bcf_hdr)
1312{
1313 u32 barker = le32_to_cpu(i2400m->barker->data[0])
1314 & 0x7fffffff;
1315 u32 module_id = le32_to_cpu(bcf_hdr->module_id)
1316 & 0x7fffffff; /* high bit used for something else */
1317
1318 /* special case for 5x50 */
1319 if (barker == I2400M_SBOOT_BARKER && module_id == 0)
1320 return 1;
1321 if (module_id == barker)
1322 return 1;
1323 return 0;
1324}
1325
1326static
1327const struct i2400m_bcf_hdr *i2400m_bcf_hdr_find(struct i2400m *i2400m)
1328{
1329 struct device *dev = i2400m_dev(i2400m);
1330 const struct i2400m_bcf_hdr **bcf_itr, *bcf_hdr;
1331 unsigned i = 0;
1332 u32 barker = le32_to_cpu(i2400m->barker->data[0]);
1333
1334 d_printf(2, dev, "finding BCF header for barker %08x\n", barker);
1335 if (barker == I2400M_NBOOT_BARKER) {
1336 bcf_hdr = i2400m->fw_hdrs[0];
1337 d_printf(1, dev, "using BCF header #%u/%08x for non-signed "
1338 "barker\n", 0, le32_to_cpu(bcf_hdr->module_id));
1339 return bcf_hdr;
1340 }
1341 for (bcf_itr = i2400m->fw_hdrs; *bcf_itr != NULL; bcf_itr++, i++) {
1342 bcf_hdr = *bcf_itr;
1343 if (i2400m_bcf_hdr_match(i2400m, bcf_hdr)) {
1344 d_printf(1, dev, "hit on BCF hdr #%u/%08x\n",
1345 i, le32_to_cpu(bcf_hdr->module_id));
1346 return bcf_hdr;
1347 } else
1348 d_printf(1, dev, "miss on BCF hdr #%u/%08x\n",
1349 i, le32_to_cpu(bcf_hdr->module_id));
1350 }
1351 dev_err(dev, "cannot find a matching BCF header for barker %08x\n",
1352 barker);
1353 return NULL;
1354}
1355
1356
1357/*
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001358 * Download the firmware to the device
1359 *
1360 * @i2400m: device descriptor
1361 * @bcf: pointer to loaded (and minimally verified for consistency)
1362 * firmware
1363 * @bcf_size: size of the @bcf buffer (header plus payloads)
1364 *
1365 * The process for doing this is described in this file's header.
1366 *
1367 * Note we only reinitialize boot-mode if the flags say so. Some hw
1368 * iterations need it, some don't. In any case, if we loop, we always
1369 * need to reinitialize the boot room, hence the flags modification.
1370 */
1371static
1372int i2400m_fw_dnload(struct i2400m *i2400m, const struct i2400m_bcf_hdr *bcf,
1373 size_t bcf_size, enum i2400m_bri flags)
1374{
1375 int ret = 0;
1376 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalezecddfd52009-06-03 16:13:14 +08001377 int count = i2400m->bus_bm_retries;
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001378 const struct i2400m_bcf_hdr *bcf_hdr;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001379
1380 d_fnstart(5, dev, "(i2400m %p bcf %p size %zu)\n",
1381 i2400m, bcf, bcf_size);
1382 i2400m->boot_mode = 1;
Inaky Perez-Gonzalezb4013f92009-06-03 09:45:55 +08001383 wmb(); /* Make sure other readers see it */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001384hw_reboot:
1385 if (count-- == 0) {
1386 ret = -ERESTARTSYS;
1387 dev_err(dev, "device rebooted too many times, aborting\n");
1388 goto error_too_many_reboots;
1389 }
1390 if (flags & I2400M_BRI_MAC_REINIT) {
1391 ret = i2400m_bootrom_init(i2400m, flags);
1392 if (ret < 0) {
1393 dev_err(dev, "bootrom init failed: %d\n", ret);
1394 goto error_bootrom_init;
1395 }
1396 }
1397 flags |= I2400M_BRI_MAC_REINIT;
1398
1399 /*
1400 * Initialize the download, push the bytes to the device and
1401 * then jump to the new firmware. Note @ret is passed with the
1402 * offset of the jump instruction to _dnload_finalize()
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001403 *
1404 * Note we need to use the BCF header in the firmware image
1405 * that matches the barker that the device sent when it
1406 * rebooted, so it has to be passed along.
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001407 */
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001408 ret = -EBADF;
1409 bcf_hdr = i2400m_bcf_hdr_find(i2400m);
1410 if (bcf_hdr == NULL)
1411 goto error_bcf_hdr_find;
1412
1413 ret = i2400m_dnload_init(i2400m, bcf_hdr);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001414 if (ret == -ERESTARTSYS)
1415 goto error_dev_rebooted;
1416 if (ret < 0)
1417 goto error_dnload_init;
1418
1419 ret = i2400m_dnload_bcf(i2400m, bcf, bcf_size);
1420 if (ret == -ERESTARTSYS)
1421 goto error_dev_rebooted;
1422 if (ret < 0) {
1423 dev_err(dev, "fw %s: download failed: %d\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001424 i2400m->fw_name, ret);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001425 goto error_dnload_bcf;
1426 }
1427
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001428 ret = i2400m_dnload_finalize(i2400m, bcf_hdr, bcf, ret);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001429 if (ret == -ERESTARTSYS)
1430 goto error_dev_rebooted;
1431 if (ret < 0) {
1432 dev_err(dev, "fw %s: "
1433 "download finalization failed: %d\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001434 i2400m->fw_name, ret);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001435 goto error_dnload_finalize;
1436 }
1437
1438 d_printf(2, dev, "fw %s successfully uploaded\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001439 i2400m->fw_name);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001440 i2400m->boot_mode = 0;
Inaky Perez-Gonzalezb4013f92009-06-03 09:45:55 +08001441 wmb(); /* Make sure i2400m_msg_to_dev() sees boot_mode */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001442error_dnload_finalize:
1443error_dnload_bcf:
1444error_dnload_init:
Inaky Perez-Gonzalez10607c82009-09-09 17:11:57 -07001445error_bcf_hdr_find:
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001446error_bootrom_init:
1447error_too_many_reboots:
1448 d_fnend(5, dev, "(i2400m %p bcf %p size %zu) = %d\n",
1449 i2400m, bcf, bcf_size, ret);
1450 return ret;
1451
1452error_dev_rebooted:
1453 dev_err(dev, "device rebooted, %d tries left\n", count);
1454 /* we got the notification already, no need to wait for it again */
1455 flags |= I2400M_BRI_SOFT;
1456 goto hw_reboot;
1457}
1458
1459
1460/**
1461 * i2400m_dev_bootstrap - Bring the device to a known state and upload firmware
1462 *
1463 * @i2400m: device descriptor
1464 *
1465 * Returns: >= 0 if ok, < 0 errno code on error.
1466 *
1467 * This sets up the firmware upload environment, loads the firmware
1468 * file from disk, verifies and then calls the firmware upload process
1469 * per se.
1470 *
1471 * Can be called either from probe, or after a warm reset. Can not be
1472 * called from within an interrupt. All the flow in this code is
1473 * single-threade; all I/Os are synchronous.
1474 */
1475int i2400m_dev_bootstrap(struct i2400m *i2400m, enum i2400m_bri flags)
1476{
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001477 int ret, itr;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001478 struct device *dev = i2400m_dev(i2400m);
1479 const struct firmware *fw;
1480 const struct i2400m_bcf_hdr *bcf; /* Firmware data */
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001481 const char *fw_name;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001482
1483 d_fnstart(5, dev, "(i2400m %p)\n", i2400m);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001484
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001485 /* Load firmware files to memory. */
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001486 for (itr = 0, bcf = NULL, ret = -ENOENT; ; itr++) {
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001487 fw_name = i2400m->bus_fw_names[itr];
1488 if (fw_name == NULL) {
1489 dev_err(dev, "Could not find a usable firmware image\n");
1490 ret = -ENOENT;
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001491 break;
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001492 }
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001493 d_printf(1, dev, "trying firmware %s (%d)\n", fw_name, itr);
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001494 ret = request_firmware(&fw, fw_name, dev);
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001495 if (ret < 0) {
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001496 dev_err(dev, "fw %s: cannot load file: %d\n",
1497 fw_name, ret);
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001498 continue;
1499 }
1500 bcf = (void *) fw->data;
1501 i2400m->fw_name = fw_name;
1502 ret = i2400m_fw_check(i2400m, bcf, fw->size);
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001503 if (ret >= 0)
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001504 ret = i2400m_fw_dnload(i2400m, bcf, fw->size, flags);
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001505 if (ret < 0)
1506 dev_err(dev, "%s: cannot use: %d, skipping\n",
1507 fw_name, ret);
1508 kfree(i2400m->fw_hdrs);
1509 i2400m->fw_hdrs = NULL;
Inaky Perez-Gonzalezebc5f622009-09-03 15:53:30 -07001510 release_firmware(fw);
Inaky Perez-Gonzalezbfc44182009-09-04 17:07:21 -07001511 if (ret >= 0) /* firmware loaded succesfully */
1512 break;
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001513 }
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001514 d_fnend(5, dev, "(i2400m %p) = %d\n", i2400m, ret);
1515 return ret;
1516}
1517EXPORT_SYMBOL_GPL(i2400m_dev_bootstrap);