blob: 92d4d605dc2d9bb02c09100677cacc06434ee226 [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 *
43 * (this is decribed for USB, but for SDIO is similar)
44 *
45 * The 2400m works in two modes: boot-mode or normal mode. In boot
46 * mode we can execute only a handful of commands targeted at
47 * uploading the firmware and launching it.
48 *
49 * The 2400m enters boot mode when it is first connected to the
50 * system, when it crashes and when you ask it to reboot. There are
51 * two submodes of the boot mode: signed and non-signed. Signed takes
52 * firmwares signed with a certain private key, non-signed takes any
53 * firmware. Normal hardware takes only signed firmware.
54 *
55 * Upon entrance to boot mode, the device sends a few zero length
56 * packets (ZLPs) on the notification endpoint, then a reboot barker
57 * (4 le32 words with value I2400M_{S,N}BOOT_BARKER). We ack it by
58 * sending the same barker on the bulk out endpoint. The device acks
59 * with a reboot ack barker (4 le32 words with value 0xfeedbabe) and
60 * then the device is fully rebooted. At this point we can upload the
61 * firmware.
62 *
63 * This process is accomplished by the i2400m_bootrom_init()
64 * function. All the device interaction happens through the
65 * i2400m_bm_cmd() [boot mode command]. Special return values will
66 * indicate if the device resets.
67 *
68 * After this, we read the MAC address and then (if needed)
69 * reinitialize the device. We need to read it ahead of time because
70 * in the future, we might not upload the firmware until userspace
71 * 'ifconfig up's the device.
72 *
73 * We can then upload the firmware file. The file is composed of a BCF
74 * header (basic data, keys and signatures) and a list of write
75 * commands and payloads. We first upload the header
76 * [i2400m_dnload_init()] and then pass the commands and payloads
77 * verbatim to the i2400m_bm_cmd() function
78 * [i2400m_dnload_bcf()]. Then we tell the device to jump to the new
79 * firmware [i2400m_dnload_finalize()].
80 *
81 * Once firmware is uploaded, we are good to go :)
82 *
83 * When we don't know in which mode we are, we first try by sending a
84 * warm reset request that will take us to boot-mode. If we time out
85 * waiting for a reboot barker, that means maybe we are already in
86 * boot mode, so we send a reboot barker.
87 *
88 * COMMAND EXECUTION
89 *
90 * This code (and process) is single threaded; for executing commands,
91 * we post a URB to the notification endpoint, post the command, wait
92 * for data on the notification buffer. We don't need to worry about
93 * others as we know we are the only ones in there.
94 *
95 * BACKEND IMPLEMENTATION
96 *
97 * This code is bus-generic; the bus-specific driver provides back end
98 * implementations to send a boot mode command to the device and to
99 * read an acknolwedgement from it (or an asynchronous notification)
100 * from it.
101 *
102 * ROADMAP
103 *
104 * i2400m_dev_bootstrap Called by __i2400m_dev_start()
105 * request_firmware
106 * i2400m_fw_check
107 * i2400m_fw_dnload
108 * release_firmware
109 *
110 * i2400m_fw_dnload
111 * i2400m_bootrom_init
112 * i2400m_bm_cmd
113 * i2400m->bus_reset
114 * i2400m_dnload_init
115 * i2400m_dnload_init_signed
116 * i2400m_dnload_init_nonsigned
117 * i2400m_download_chunk
118 * i2400m_bm_cmd
119 * i2400m_dnload_bcf
120 * i2400m_bm_cmd
121 * i2400m_dnload_finalize
122 * i2400m_bm_cmd
123 *
124 * i2400m_bm_cmd
125 * i2400m->bus_bm_cmd_send()
126 * i2400m->bus_bm_wait_for_ack
127 * __i2400m_bm_ack_verify
128 *
129 * i2400m_bm_cmd_prepare Used by bus-drivers to prep
130 * commands before sending
131 */
132#include <linux/firmware.h>
133#include <linux/sched.h>
134#include <linux/usb.h>
135#include "i2400m.h"
136
137
138#define D_SUBMODULE fw
139#include "debug-levels.h"
140
141
142static const __le32 i2400m_ACK_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800143 cpu_to_le32(I2400M_ACK_BARKER),
144 cpu_to_le32(I2400M_ACK_BARKER),
145 cpu_to_le32(I2400M_ACK_BARKER),
146 cpu_to_le32(I2400M_ACK_BARKER)
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800147};
148
149
150/**
151 * Prepare a boot-mode command for delivery
152 *
153 * @cmd: pointer to bootrom header to prepare
154 *
155 * Computes checksum if so needed. After calling this function, DO NOT
156 * modify the command or header as the checksum won't work anymore.
157 *
158 * We do it from here because some times we cannot do it in the
159 * original context the command was sent (it is a const), so when we
160 * copy it to our staging buffer, we add the checksum there.
161 */
162void i2400m_bm_cmd_prepare(struct i2400m_bootrom_header *cmd)
163{
164 if (i2400m_brh_get_use_checksum(cmd)) {
165 int i;
166 u32 checksum = 0;
167 const u32 *checksum_ptr = (void *) cmd->payload;
168 for (i = 0; i < cmd->data_size / 4; i++)
169 checksum += cpu_to_le32(*checksum_ptr++);
170 checksum += cmd->command + cmd->target_addr + cmd->data_size;
171 cmd->block_checksum = cpu_to_le32(checksum);
172 }
173}
174EXPORT_SYMBOL_GPL(i2400m_bm_cmd_prepare);
175
176
177/*
178 * Verify the ack data received
179 *
180 * Given a reply to a boot mode command, chew it and verify everything
181 * is ok.
182 *
183 * @opcode: opcode which generated this ack. For error messages.
184 * @ack: pointer to ack data we received
185 * @ack_size: size of that data buffer
186 * @flags: I2400M_BM_CMD_* flags we called the command with.
187 *
188 * Way too long function -- maybe it should be further split
189 */
190static
191ssize_t __i2400m_bm_ack_verify(struct i2400m *i2400m, int opcode,
192 struct i2400m_bootrom_header *ack,
193 size_t ack_size, int flags)
194{
195 ssize_t result = -ENOMEM;
196 struct device *dev = i2400m_dev(i2400m);
197
198 d_fnstart(8, dev, "(i2400m %p opcode %d ack %p size %zu)\n",
199 i2400m, opcode, ack, ack_size);
200 if (ack_size < sizeof(*ack)) {
201 result = -EIO;
202 dev_err(dev, "boot-mode cmd %d: HW BUG? notification didn't "
203 "return enough data (%zu bytes vs %zu expected)\n",
204 opcode, ack_size, sizeof(*ack));
205 goto error_ack_short;
206 }
207 if (ack_size == sizeof(i2400m_NBOOT_BARKER)
208 && memcmp(ack, i2400m_NBOOT_BARKER, sizeof(*ack)) == 0) {
209 result = -ERESTARTSYS;
210 i2400m->sboot = 0;
211 d_printf(6, dev, "boot-mode cmd %d: "
212 "HW non-signed boot barker\n", opcode);
213 goto error_reboot;
214 }
215 if (ack_size == sizeof(i2400m_SBOOT_BARKER)
216 && memcmp(ack, i2400m_SBOOT_BARKER, sizeof(*ack)) == 0) {
217 result = -ERESTARTSYS;
218 i2400m->sboot = 1;
219 d_printf(6, dev, "boot-mode cmd %d: HW signed reboot barker\n",
220 opcode);
221 goto error_reboot;
222 }
223 if (ack_size == sizeof(i2400m_ACK_BARKER)
224 && memcmp(ack, i2400m_ACK_BARKER, sizeof(*ack)) == 0) {
225 result = -EISCONN;
226 d_printf(3, dev, "boot-mode cmd %d: HW reboot ack barker\n",
227 opcode);
228 goto error_reboot_ack;
229 }
230 result = 0;
231 if (flags & I2400M_BM_CMD_RAW)
232 goto out_raw;
233 ack->data_size = le32_to_cpu(ack->data_size);
234 ack->target_addr = le32_to_cpu(ack->target_addr);
235 ack->block_checksum = le32_to_cpu(ack->block_checksum);
236 d_printf(5, dev, "boot-mode cmd %d: notification for opcode %u "
237 "response %u csum %u rr %u da %u\n",
238 opcode, i2400m_brh_get_opcode(ack),
239 i2400m_brh_get_response(ack),
240 i2400m_brh_get_use_checksum(ack),
241 i2400m_brh_get_response_required(ack),
242 i2400m_brh_get_direct_access(ack));
243 result = -EIO;
244 if (i2400m_brh_get_signature(ack) != 0xcbbc) {
245 dev_err(dev, "boot-mode cmd %d: HW BUG? wrong signature "
246 "0x%04x\n", opcode, i2400m_brh_get_signature(ack));
247 goto error_ack_signature;
248 }
249 if (opcode != -1 && opcode != i2400m_brh_get_opcode(ack)) {
250 dev_err(dev, "boot-mode cmd %d: HW BUG? "
251 "received response for opcode %u, expected %u\n",
252 opcode, i2400m_brh_get_opcode(ack), opcode);
253 goto error_ack_opcode;
254 }
255 if (i2400m_brh_get_response(ack) != 0) { /* failed? */
256 dev_err(dev, "boot-mode cmd %d: error; hw response %u\n",
257 opcode, i2400m_brh_get_response(ack));
258 goto error_ack_failed;
259 }
260 if (ack_size < ack->data_size + sizeof(*ack)) {
261 dev_err(dev, "boot-mode cmd %d: SW BUG "
262 "driver provided only %zu bytes for %zu bytes "
263 "of data\n", opcode, ack_size,
264 (size_t) le32_to_cpu(ack->data_size) + sizeof(*ack));
265 goto error_ack_short_buffer;
266 }
267 result = ack_size;
268 /* Don't you love this stack of empty targets? Well, I don't
269 * either, but it helps track exactly who comes in here and
270 * why :) */
271error_ack_short_buffer:
272error_ack_failed:
273error_ack_opcode:
274error_ack_signature:
275out_raw:
276error_reboot_ack:
277error_reboot:
278error_ack_short:
279 d_fnend(8, dev, "(i2400m %p opcode %d ack %p size %zu) = %d\n",
280 i2400m, opcode, ack, ack_size, (int) result);
281 return result;
282}
283
284
285/**
286 * i2400m_bm_cmd - Execute a boot mode command
287 *
288 * @cmd: buffer containing the command data (pointing at the header).
289 * This data can be ANYWHERE (for USB, we will copy it to an
290 * specific buffer). Make sure everything is in proper little
291 * endian.
292 *
293 * A raw buffer can be also sent, just cast it and set flags to
294 * I2400M_BM_CMD_RAW.
295 *
296 * This function will generate a checksum for you if the
297 * checksum bit in the command is set (unless I2400M_BM_CMD_RAW
298 * is set).
299 *
300 * You can use the i2400m->bm_cmd_buf to stage your commands and
301 * send them.
302 *
303 * If NULL, no command is sent (we just wait for an ack).
304 *
305 * @cmd_size: size of the command. Will be auto padded to the
306 * bus-specific drivers padding requirements.
307 *
308 * @ack: buffer where to place the acknowledgement. If it is a regular
309 * command response, all fields will be returned with the right,
310 * native endianess.
311 *
312 * You *cannot* use i2400m->bm_ack_buf for this buffer.
313 *
314 * @ack_size: size of @ack, 16 aligned; you need to provide at least
315 * sizeof(*ack) bytes and then enough to contain the return data
316 * from the command
317 *
318 * @flags: see I2400M_BM_CMD_* above.
319 *
320 * @returns: bytes received by the notification; if < 0, an errno code
321 * denoting an error or:
322 *
323 * -ERESTARTSYS The device has rebooted
324 *
325 * Executes a boot-mode command and waits for a response, doing basic
326 * validation on it; if a zero length response is received, it retries
327 * waiting for a response until a non-zero one is received (timing out
328 * after %I2400M_BOOT_RETRIES retries).
329 */
330static
331ssize_t i2400m_bm_cmd(struct i2400m *i2400m,
332 const struct i2400m_bootrom_header *cmd, size_t cmd_size,
333 struct i2400m_bootrom_header *ack, size_t ack_size,
334 int flags)
335{
336 ssize_t result = -ENOMEM, rx_bytes;
337 struct device *dev = i2400m_dev(i2400m);
338 int opcode = cmd == NULL ? -1 : i2400m_brh_get_opcode(cmd);
339
340 d_fnstart(6, dev, "(i2400m %p cmd %p size %zu ack %p size %zu)\n",
341 i2400m, cmd, cmd_size, ack, ack_size);
342 BUG_ON(ack_size < sizeof(*ack));
343 BUG_ON(i2400m->boot_mode == 0);
344
345 if (cmd != NULL) { /* send the command */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800346 result = i2400m->bus_bm_cmd_send(i2400m, cmd, cmd_size, flags);
347 if (result < 0)
348 goto error_cmd_send;
349 if ((flags & I2400M_BM_CMD_RAW) == 0)
350 d_printf(5, dev,
351 "boot-mode cmd %d csum %u rr %u da %u: "
352 "addr 0x%04x size %u block csum 0x%04x\n",
353 opcode, i2400m_brh_get_use_checksum(cmd),
354 i2400m_brh_get_response_required(cmd),
355 i2400m_brh_get_direct_access(cmd),
356 cmd->target_addr, cmd->data_size,
357 cmd->block_checksum);
358 }
359 result = i2400m->bus_bm_wait_for_ack(i2400m, ack, ack_size);
360 if (result < 0) {
361 dev_err(dev, "boot-mode cmd %d: error waiting for an ack: %d\n",
362 opcode, (int) result); /* bah, %zd doesn't work */
363 goto error_wait_for_ack;
364 }
365 rx_bytes = result;
366 /* verify the ack and read more if neccessary [result is the
367 * final amount of bytes we get in the ack] */
368 result = __i2400m_bm_ack_verify(i2400m, opcode, ack, ack_size, flags);
369 if (result < 0)
370 goto error_bad_ack;
371 /* Don't you love this stack of empty targets? Well, I don't
372 * either, but it helps track exactly who comes in here and
373 * why :) */
374 result = rx_bytes;
375error_bad_ack:
376error_wait_for_ack:
377error_cmd_send:
378 d_fnend(6, dev, "(i2400m %p cmd %p size %zu ack %p size %zu) = %d\n",
379 i2400m, cmd, cmd_size, ack, ack_size, (int) result);
380 return result;
381}
382
383
384/**
385 * i2400m_download_chunk - write a single chunk of data to the device's memory
386 *
387 * @i2400m: device descriptor
388 * @buf: the buffer to write
389 * @buf_len: length of the buffer to write
390 * @addr: address in the device memory space
391 * @direct: bootrom write mode
392 * @do_csum: should a checksum validation be performed
393 */
394static int i2400m_download_chunk(struct i2400m *i2400m, const void *chunk,
395 size_t __chunk_len, unsigned long addr,
396 unsigned int direct, unsigned int do_csum)
397{
398 int ret;
Inaky Perez-Gonzalez8593a192009-05-20 16:53:30 -0700399 size_t chunk_len = ALIGN(__chunk_len, I2400M_PL_ALIGN);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800400 struct device *dev = i2400m_dev(i2400m);
401 struct {
402 struct i2400m_bootrom_header cmd;
403 u8 cmd_payload[chunk_len];
404 } __attribute__((packed)) *buf;
405 struct i2400m_bootrom_header ack;
406
407 d_fnstart(5, dev, "(i2400m %p chunk %p __chunk_len %zu addr 0x%08lx "
408 "direct %u do_csum %u)\n", i2400m, chunk, __chunk_len,
409 addr, direct, do_csum);
410 buf = i2400m->bm_cmd_buf;
411 memcpy(buf->cmd_payload, chunk, __chunk_len);
412 memset(buf->cmd_payload + __chunk_len, 0xad, chunk_len - __chunk_len);
413
414 buf->cmd.command = i2400m_brh_command(I2400M_BRH_WRITE,
415 __chunk_len & 0x3 ? 0 : do_csum,
416 __chunk_len & 0xf ? 0 : direct);
417 buf->cmd.target_addr = cpu_to_le32(addr);
418 buf->cmd.data_size = cpu_to_le32(__chunk_len);
419 ret = i2400m_bm_cmd(i2400m, &buf->cmd, sizeof(buf->cmd) + chunk_len,
420 &ack, sizeof(ack), 0);
421 if (ret >= 0)
422 ret = 0;
423 d_fnend(5, dev, "(i2400m %p chunk %p __chunk_len %zu addr 0x%08lx "
424 "direct %u do_csum %u) = %d\n", i2400m, chunk, __chunk_len,
425 addr, direct, do_csum, ret);
426 return ret;
427}
428
429
430/*
431 * Download a BCF file's sections to the device
432 *
433 * @i2400m: device descriptor
434 * @bcf: pointer to firmware data (followed by the payloads). Assumed
435 * verified and consistent.
436 * @bcf_len: length (in bytes) of the @bcf buffer.
437 *
438 * Returns: < 0 errno code on error or the offset to the jump instruction.
439 *
440 * Given a BCF file, downloads each section (a command and a payload)
441 * to the device's address space. Actually, it just executes each
442 * command i the BCF file.
443 *
444 * The section size has to be aligned to 4 bytes AND the padding has
445 * to be taken from the firmware file, as the signature takes it into
446 * account.
447 */
448static
449ssize_t i2400m_dnload_bcf(struct i2400m *i2400m,
450 const struct i2400m_bcf_hdr *bcf, size_t bcf_len)
451{
452 ssize_t ret;
453 struct device *dev = i2400m_dev(i2400m);
454 size_t offset, /* iterator offset */
455 data_size, /* Size of the data payload */
456 section_size, /* Size of the whole section (cmd + payload) */
457 section = 1;
458 const struct i2400m_bootrom_header *bh;
459 struct i2400m_bootrom_header ack;
460
461 d_fnstart(3, dev, "(i2400m %p bcf %p bcf_len %zu)\n",
462 i2400m, bcf, bcf_len);
463 /* Iterate over the command blocks in the BCF file that start
464 * after the header */
465 offset = le32_to_cpu(bcf->header_len) * sizeof(u32);
466 while (1) { /* start sending the file */
467 bh = (void *) bcf + offset;
468 data_size = le32_to_cpu(bh->data_size);
469 section_size = ALIGN(sizeof(*bh) + data_size, 4);
470 d_printf(7, dev,
471 "downloading section #%zu (@%zu %zu B) to 0x%08x\n",
472 section, offset, sizeof(*bh) + data_size,
473 le32_to_cpu(bh->target_addr));
474 if (i2400m_brh_get_opcode(bh) == I2400M_BRH_SIGNED_JUMP) {
475 /* Secure boot needs to stop here */
476 d_printf(5, dev, "signed jump found @%zu\n", offset);
477 break;
478 }
479 if (offset + section_size == bcf_len)
480 /* Non-secure boot stops here */
481 break;
482 if (offset + section_size > bcf_len) {
483 dev_err(dev, "fw %s: bad section #%zu, "
484 "end (@%zu) beyond EOF (@%zu)\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000485 i2400m->fw_name, section,
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800486 offset + section_size, bcf_len);
487 ret = -EINVAL;
488 goto error_section_beyond_eof;
489 }
490 __i2400m_msleep(20);
491 ret = i2400m_bm_cmd(i2400m, bh, section_size,
492 &ack, sizeof(ack), I2400M_BM_CMD_RAW);
493 if (ret < 0) {
494 dev_err(dev, "fw %s: section #%zu (@%zu %zu B) "
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000495 "failed %d\n", i2400m->fw_name, section,
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800496 offset, sizeof(*bh) + data_size, (int) ret);
497 goto error_send;
498 }
499 offset += section_size;
500 section++;
501 }
502 ret = offset;
503error_section_beyond_eof:
504error_send:
505 d_fnend(3, dev, "(i2400m %p bcf %p bcf_len %zu) = %d\n",
506 i2400m, bcf, bcf_len, (int) ret);
507 return ret;
508}
509
510
511/*
512 * Do the final steps of uploading firmware
513 *
514 * Depending on the boot mode (signed vs non-signed), different
515 * actions need to be taken.
516 */
517static
518int i2400m_dnload_finalize(struct i2400m *i2400m,
519 const struct i2400m_bcf_hdr *bcf, size_t offset)
520{
521 int ret = 0;
522 struct device *dev = i2400m_dev(i2400m);
523 struct i2400m_bootrom_header *cmd, ack;
524 struct {
525 struct i2400m_bootrom_header cmd;
526 u8 cmd_pl[0];
527 } __attribute__((packed)) *cmd_buf;
528 size_t signature_block_offset, signature_block_size;
529
530 d_fnstart(3, dev, "offset %zu\n", offset);
531 cmd = (void *) bcf + offset;
532 if (i2400m->sboot == 0) {
533 struct i2400m_bootrom_header jump_ack;
Dirk Brandewieead68232009-05-12 06:22:27 -0700534 d_printf(1, dev, "unsecure boot, jumping to 0x%08x\n",
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800535 le32_to_cpu(cmd->target_addr));
Cindy H Kao8d8fe192009-08-18 19:27:18 -0700536 cmd_buf = i2400m->bm_cmd_buf;
537 memcpy(&cmd_buf->cmd, cmd, sizeof(*cmd));
538 cmd = &cmd_buf->cmd;
539 /* now cmd points to the actual bootrom_header in cmd_buf */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800540 i2400m_brh_set_opcode(cmd, I2400M_BRH_JUMP);
541 cmd->data_size = 0;
542 ret = i2400m_bm_cmd(i2400m, cmd, sizeof(*cmd),
543 &jump_ack, sizeof(jump_ack), 0);
544 } else {
Dirk Brandewieead68232009-05-12 06:22:27 -0700545 d_printf(1, dev, "secure boot, jumping to 0x%08x\n",
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800546 le32_to_cpu(cmd->target_addr));
547 cmd_buf = i2400m->bm_cmd_buf;
548 memcpy(&cmd_buf->cmd, cmd, sizeof(*cmd));
549 signature_block_offset =
550 sizeof(*bcf)
551 + le32_to_cpu(bcf->key_size) * sizeof(u32)
552 + le32_to_cpu(bcf->exponent_size) * sizeof(u32);
553 signature_block_size =
554 le32_to_cpu(bcf->modulus_size) * sizeof(u32);
555 memcpy(cmd_buf->cmd_pl, (void *) bcf + signature_block_offset,
556 signature_block_size);
557 ret = i2400m_bm_cmd(i2400m, &cmd_buf->cmd,
558 sizeof(cmd_buf->cmd) + signature_block_size,
559 &ack, sizeof(ack), I2400M_BM_CMD_RAW);
560 }
561 d_fnend(3, dev, "returning %d\n", ret);
562 return ret;
563}
564
565
566/**
567 * i2400m_bootrom_init - Reboots a powered device into boot mode
568 *
569 * @i2400m: device descriptor
570 * @flags:
571 * I2400M_BRI_SOFT: a reboot notification has been seen
572 * already, so don't wait for it.
573 *
574 * I2400M_BRI_NO_REBOOT: Don't send a reboot command, but wait
575 * for a reboot barker notification. This is a one shot; if
576 * the state machine needs to send a reboot command it will.
577 *
578 * Returns:
579 *
580 * < 0 errno code on error, 0 if ok.
581 *
582 * i2400m->sboot set to 0 for unsecure boot process, 1 for secure
583 * boot process.
584 *
585 * Description:
586 *
587 * Tries hard enough to put the device in boot-mode. There are two
588 * main phases to this:
589 *
590 * a. (1) send a reboot command and (2) get a reboot barker
591 * b. (1) ack the reboot sending a reboot barker and (2) getting an
592 * ack barker in return
593 *
594 * We want to skip (a) in some cases [soft]. The state machine is
595 * horrible, but it is basically: on each phase, send what has to be
596 * sent (if any), wait for the answer and act on the answer. We might
597 * have to backtrack and retry, so we keep a max tries counter for
598 * that.
599 *
600 * If we get a timeout after sending a warm reset, we do it again.
601 */
602int i2400m_bootrom_init(struct i2400m *i2400m, enum i2400m_bri flags)
603{
604 int result;
605 struct device *dev = i2400m_dev(i2400m);
606 struct i2400m_bootrom_header *cmd;
607 struct i2400m_bootrom_header ack;
Dirk Brandewiec3083652009-08-13 13:48:29 -0700608 int count = i2400m->bus_bm_retries;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800609 int ack_timeout_cnt = 1;
610
611 BUILD_BUG_ON(sizeof(*cmd) != sizeof(i2400m_NBOOT_BARKER));
612 BUILD_BUG_ON(sizeof(ack) != sizeof(i2400m_ACK_BARKER));
613
614 d_fnstart(4, dev, "(i2400m %p flags 0x%08x)\n", i2400m, flags);
615 result = -ENOMEM;
616 cmd = i2400m->bm_cmd_buf;
617 if (flags & I2400M_BRI_SOFT)
618 goto do_reboot_ack;
619do_reboot:
620 if (--count < 0)
621 goto error_timeout;
622 d_printf(4, dev, "device reboot: reboot command [%d # left]\n",
623 count);
624 if ((flags & I2400M_BRI_NO_REBOOT) == 0)
625 i2400m->bus_reset(i2400m, I2400M_RT_WARM);
626 result = i2400m_bm_cmd(i2400m, NULL, 0, &ack, sizeof(ack),
627 I2400M_BM_CMD_RAW);
628 flags &= ~I2400M_BRI_NO_REBOOT;
629 switch (result) {
630 case -ERESTARTSYS:
631 d_printf(4, dev, "device reboot: got reboot barker\n");
632 break;
633 case -EISCONN: /* we don't know how it got here...but we follow it */
634 d_printf(4, dev, "device reboot: got ack barker - whatever\n");
635 goto do_reboot;
636 case -ETIMEDOUT: /* device has timed out, we might be in boot
637 * mode already and expecting an ack, let's try
638 * that */
639 dev_info(dev, "warm reset timed out, trying an ack\n");
640 goto do_reboot_ack;
641 case -EPROTO:
642 case -ESHUTDOWN: /* dev is gone */
643 case -EINTR: /* user cancelled */
644 goto error_dev_gone;
645 default:
646 dev_err(dev, "device reboot: error %d while waiting "
647 "for reboot barker - rebooting\n", result);
648 goto do_reboot;
649 }
650 /* At this point we ack back with 4 REBOOT barkers and expect
651 * 4 ACK barkers. This is ugly, as we send a raw command --
652 * hence the cast. _bm_cmd() will catch the reboot ack
653 * notification and report it as -EISCONN. */
654do_reboot_ack:
655 d_printf(4, dev, "device reboot ack: sending ack [%d # left]\n", count);
656 if (i2400m->sboot == 0)
657 memcpy(cmd, i2400m_NBOOT_BARKER,
658 sizeof(i2400m_NBOOT_BARKER));
659 else
660 memcpy(cmd, i2400m_SBOOT_BARKER,
661 sizeof(i2400m_SBOOT_BARKER));
662 result = i2400m_bm_cmd(i2400m, cmd, sizeof(*cmd),
663 &ack, sizeof(ack), I2400M_BM_CMD_RAW);
664 switch (result) {
665 case -ERESTARTSYS:
666 d_printf(4, dev, "reboot ack: got reboot barker - retrying\n");
667 if (--count < 0)
668 goto error_timeout;
669 goto do_reboot_ack;
670 case -EISCONN:
671 d_printf(4, dev, "reboot ack: got ack barker - good\n");
672 break;
673 case -ETIMEDOUT: /* no response, maybe it is the other type? */
674 if (ack_timeout_cnt-- >= 0) {
675 d_printf(4, dev, "reboot ack timedout: "
676 "trying the other type?\n");
677 i2400m->sboot = !i2400m->sboot;
678 goto do_reboot_ack;
679 } else {
680 dev_err(dev, "reboot ack timedout too long: "
681 "trying reboot\n");
682 goto do_reboot;
683 }
684 break;
685 case -EPROTO:
686 case -ESHUTDOWN: /* dev is gone */
687 goto error_dev_gone;
688 default:
689 dev_err(dev, "device reboot ack: error %d while waiting for "
690 "reboot ack barker - rebooting\n", result);
691 goto do_reboot;
692 }
693 d_printf(2, dev, "device reboot ack: got ack barker - boot done\n");
694 result = 0;
695exit_timeout:
696error_dev_gone:
697 d_fnend(4, dev, "(i2400m %p flags 0x%08x) = %d\n",
698 i2400m, flags, result);
699 return result;
700
701error_timeout:
Inaky Perez-Gonzalez6e053d62009-06-05 09:31:26 +0800702 dev_err(dev, "Timed out waiting for reboot ack\n");
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800703 result = -ETIMEDOUT;
704 goto exit_timeout;
705}
706
707
708/*
709 * Read the MAC addr
710 *
711 * The position this function reads is fixed in device memory and
712 * always available, even without firmware.
713 *
714 * Note we specify we want to read only six bytes, but provide space
715 * for 16, as we always get it rounded up.
716 */
717int i2400m_read_mac_addr(struct i2400m *i2400m)
718{
719 int result;
720 struct device *dev = i2400m_dev(i2400m);
721 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
722 struct i2400m_bootrom_header *cmd;
723 struct {
724 struct i2400m_bootrom_header ack;
725 u8 ack_pl[16];
726 } __attribute__((packed)) ack_buf;
727
728 d_fnstart(5, dev, "(i2400m %p)\n", i2400m);
729 cmd = i2400m->bm_cmd_buf;
730 cmd->command = i2400m_brh_command(I2400M_BRH_READ, 0, 1);
731 cmd->target_addr = cpu_to_le32(0x00203fe8);
732 cmd->data_size = cpu_to_le32(6);
733 result = i2400m_bm_cmd(i2400m, cmd, sizeof(*cmd),
734 &ack_buf.ack, sizeof(ack_buf), 0);
735 if (result < 0) {
736 dev_err(dev, "BM: read mac addr failed: %d\n", result);
737 goto error_read_mac;
738 }
739 d_printf(2, dev,
740 "mac addr is %02x:%02x:%02x:%02x:%02x:%02x\n",
741 ack_buf.ack_pl[0], ack_buf.ack_pl[1],
742 ack_buf.ack_pl[2], ack_buf.ack_pl[3],
743 ack_buf.ack_pl[4], ack_buf.ack_pl[5]);
744 if (i2400m->bus_bm_mac_addr_impaired == 1) {
745 ack_buf.ack_pl[0] = 0x00;
746 ack_buf.ack_pl[1] = 0x16;
747 ack_buf.ack_pl[2] = 0xd3;
748 get_random_bytes(&ack_buf.ack_pl[3], 3);
749 dev_err(dev, "BM is MAC addr impaired, faking MAC addr to "
750 "mac addr is %02x:%02x:%02x:%02x:%02x:%02x\n",
751 ack_buf.ack_pl[0], ack_buf.ack_pl[1],
752 ack_buf.ack_pl[2], ack_buf.ack_pl[3],
753 ack_buf.ack_pl[4], ack_buf.ack_pl[5]);
754 result = 0;
755 }
756 net_dev->addr_len = ETH_ALEN;
757 memcpy(net_dev->perm_addr, ack_buf.ack_pl, ETH_ALEN);
758 memcpy(net_dev->dev_addr, ack_buf.ack_pl, ETH_ALEN);
759error_read_mac:
760 d_fnend(5, dev, "(i2400m %p) = %d\n", i2400m, result);
761 return result;
762}
763
764
765/*
766 * Initialize a non signed boot
767 *
768 * This implies sending some magic values to the device's memory. Note
769 * we convert the values to little endian in the same array
770 * declaration.
771 */
772static
773int i2400m_dnload_init_nonsigned(struct i2400m *i2400m)
774{
Dirk Brandewie7308a0c2009-05-21 11:56:34 -0700775 unsigned i = 0;
776 int ret = 0;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800777 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800778 d_fnstart(5, dev, "(i2400m %p)\n", i2400m);
Dirk Brandewie7308a0c2009-05-21 11:56:34 -0700779 if (i2400m->bus_bm_pokes_table) {
780 while (i2400m->bus_bm_pokes_table[i].address) {
781 ret = i2400m_download_chunk(
782 i2400m,
783 &i2400m->bus_bm_pokes_table[i].data,
784 sizeof(i2400m->bus_bm_pokes_table[i].data),
785 i2400m->bus_bm_pokes_table[i].address, 1, 1);
786 if (ret < 0)
787 break;
788 i++;
789 }
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800790 }
791 d_fnend(5, dev, "(i2400m %p) = %d\n", i2400m, ret);
792 return ret;
793}
794
795
796/*
797 * Initialize the signed boot process
798 *
799 * @i2400m: device descriptor
800 *
801 * @bcf_hdr: pointer to the firmware header; assumes it is fully in
802 * memory (it has gone through basic validation).
803 *
804 * Returns: 0 if ok, < 0 errno code on error, -ERESTARTSYS if the hw
805 * rebooted.
806 *
807 * This writes the firmware BCF header to the device using the
808 * HASH_PAYLOAD_ONLY command.
809 */
810static
811int i2400m_dnload_init_signed(struct i2400m *i2400m,
812 const struct i2400m_bcf_hdr *bcf_hdr)
813{
814 int ret;
815 struct device *dev = i2400m_dev(i2400m);
816 struct {
817 struct i2400m_bootrom_header cmd;
818 struct i2400m_bcf_hdr cmd_pl;
819 } __attribute__((packed)) *cmd_buf;
820 struct i2400m_bootrom_header ack;
821
822 d_fnstart(5, dev, "(i2400m %p bcf_hdr %p)\n", i2400m, bcf_hdr);
823 cmd_buf = i2400m->bm_cmd_buf;
824 cmd_buf->cmd.command =
825 i2400m_brh_command(I2400M_BRH_HASH_PAYLOAD_ONLY, 0, 0);
826 cmd_buf->cmd.target_addr = 0;
827 cmd_buf->cmd.data_size = cpu_to_le32(sizeof(cmd_buf->cmd_pl));
828 memcpy(&cmd_buf->cmd_pl, bcf_hdr, sizeof(*bcf_hdr));
829 ret = i2400m_bm_cmd(i2400m, &cmd_buf->cmd, sizeof(*cmd_buf),
830 &ack, sizeof(ack), 0);
831 if (ret >= 0)
832 ret = 0;
833 d_fnend(5, dev, "(i2400m %p bcf_hdr %p) = %d\n", i2400m, bcf_hdr, ret);
834 return ret;
835}
836
837
838/*
839 * Initialize the firmware download at the device size
840 *
841 * Multiplex to the one that matters based on the device's mode
842 * (signed or non-signed).
843 */
844static
845int i2400m_dnload_init(struct i2400m *i2400m, const struct i2400m_bcf_hdr *bcf)
846{
847 int result;
848 struct device *dev = i2400m_dev(i2400m);
849 u32 module_id = le32_to_cpu(bcf->module_id);
850
851 if (i2400m->sboot == 0
852 && (module_id & I2400M_BCF_MOD_ID_POKES) == 0) {
853 /* non-signed boot process without pokes */
854 result = i2400m_dnload_init_nonsigned(i2400m);
855 if (result == -ERESTARTSYS)
856 return result;
857 if (result < 0)
858 dev_err(dev, "fw %s: non-signed download "
859 "initialization failed: %d\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000860 i2400m->fw_name, result);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800861 } else if (i2400m->sboot == 0
862 && (module_id & I2400M_BCF_MOD_ID_POKES)) {
863 /* non-signed boot process with pokes, nothing to do */
864 result = 0;
865 } else { /* signed boot process */
866 result = i2400m_dnload_init_signed(i2400m, bcf);
867 if (result == -ERESTARTSYS)
868 return result;
869 if (result < 0)
870 dev_err(dev, "fw %s: signed boot download "
871 "initialization failed: %d\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000872 i2400m->fw_name, result);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800873 }
874 return result;
875}
876
877
878/*
879 * Run quick consistency tests on the firmware file
880 *
881 * Check for the firmware being made for the i2400m device,
882 * etc...These checks are mostly informative, as the device will make
883 * them too; but the driver's response is more informative on what
884 * went wrong.
885 */
886static
887int i2400m_fw_check(struct i2400m *i2400m,
888 const struct i2400m_bcf_hdr *bcf,
889 size_t bcf_size)
890{
891 int result;
892 struct device *dev = i2400m_dev(i2400m);
893 unsigned module_type, header_len, major_version, minor_version,
894 module_id, module_vendor, date, size;
895
896 /* Check hard errors */
897 result = -EINVAL;
898 if (bcf_size < sizeof(*bcf)) { /* big enough header? */
899 dev_err(dev, "firmware %s too short: "
900 "%zu B vs %zu (at least) expected\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000901 i2400m->fw_name, bcf_size, sizeof(*bcf));
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800902 goto error;
903 }
904
905 module_type = bcf->module_type;
906 header_len = sizeof(u32) * le32_to_cpu(bcf->header_len);
907 major_version = le32_to_cpu(bcf->header_version) & 0xffff0000 >> 16;
908 minor_version = le32_to_cpu(bcf->header_version) & 0x0000ffff;
909 module_id = le32_to_cpu(bcf->module_id);
910 module_vendor = le32_to_cpu(bcf->module_vendor);
911 date = le32_to_cpu(bcf->date);
912 size = sizeof(u32) * le32_to_cpu(bcf->size);
913
914 if (bcf_size != size) { /* annoyingly paranoid */
915 dev_err(dev, "firmware %s: bad size, got "
916 "%zu B vs %u expected\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000917 i2400m->fw_name, bcf_size, size);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800918 goto error;
919 }
920
921 d_printf(2, dev, "type 0x%x id 0x%x vendor 0x%x; header v%u.%u (%zu B) "
922 "date %08x (%zu B)\n",
923 module_type, module_id, module_vendor,
924 major_version, minor_version, (size_t) header_len,
925 date, (size_t) size);
926
927 if (module_type != 6) { /* built for the right hardware? */
928 dev_err(dev, "bad fw %s: unexpected module type 0x%x; "
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000929 "aborting\n", i2400m->fw_name, module_type);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800930 goto error;
931 }
932
933 /* Check soft-er errors */
934 result = 0;
935 if (module_vendor != 0x8086)
936 dev_err(dev, "bad fw %s? unexpected vendor 0x%04x\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000937 i2400m->fw_name, module_vendor);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800938 if (date < 0x20080300)
939 dev_err(dev, "bad fw %s? build date too old %08x\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000940 i2400m->fw_name, date);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800941error:
942 return result;
943}
944
945
946/*
947 * Download the firmware to the device
948 *
949 * @i2400m: device descriptor
950 * @bcf: pointer to loaded (and minimally verified for consistency)
951 * firmware
952 * @bcf_size: size of the @bcf buffer (header plus payloads)
953 *
954 * The process for doing this is described in this file's header.
955 *
956 * Note we only reinitialize boot-mode if the flags say so. Some hw
957 * iterations need it, some don't. In any case, if we loop, we always
958 * need to reinitialize the boot room, hence the flags modification.
959 */
960static
961int i2400m_fw_dnload(struct i2400m *i2400m, const struct i2400m_bcf_hdr *bcf,
962 size_t bcf_size, enum i2400m_bri flags)
963{
964 int ret = 0;
965 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalezecddfd52009-06-03 16:13:14 +0800966 int count = i2400m->bus_bm_retries;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800967
968 d_fnstart(5, dev, "(i2400m %p bcf %p size %zu)\n",
969 i2400m, bcf, bcf_size);
970 i2400m->boot_mode = 1;
Inaky Perez-Gonzalezb4013f92009-06-03 09:45:55 +0800971 wmb(); /* Make sure other readers see it */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -0800972hw_reboot:
973 if (count-- == 0) {
974 ret = -ERESTARTSYS;
975 dev_err(dev, "device rebooted too many times, aborting\n");
976 goto error_too_many_reboots;
977 }
978 if (flags & I2400M_BRI_MAC_REINIT) {
979 ret = i2400m_bootrom_init(i2400m, flags);
980 if (ret < 0) {
981 dev_err(dev, "bootrom init failed: %d\n", ret);
982 goto error_bootrom_init;
983 }
984 }
985 flags |= I2400M_BRI_MAC_REINIT;
986
987 /*
988 * Initialize the download, push the bytes to the device and
989 * then jump to the new firmware. Note @ret is passed with the
990 * offset of the jump instruction to _dnload_finalize()
991 */
992 ret = i2400m_dnload_init(i2400m, bcf); /* Init device's dnload */
993 if (ret == -ERESTARTSYS)
994 goto error_dev_rebooted;
995 if (ret < 0)
996 goto error_dnload_init;
997
998 ret = i2400m_dnload_bcf(i2400m, bcf, bcf_size);
999 if (ret == -ERESTARTSYS)
1000 goto error_dev_rebooted;
1001 if (ret < 0) {
1002 dev_err(dev, "fw %s: download failed: %d\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001003 i2400m->fw_name, ret);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001004 goto error_dnload_bcf;
1005 }
1006
1007 ret = i2400m_dnload_finalize(i2400m, bcf, ret);
1008 if (ret == -ERESTARTSYS)
1009 goto error_dev_rebooted;
1010 if (ret < 0) {
1011 dev_err(dev, "fw %s: "
1012 "download finalization failed: %d\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001013 i2400m->fw_name, ret);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001014 goto error_dnload_finalize;
1015 }
1016
1017 d_printf(2, dev, "fw %s successfully uploaded\n",
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001018 i2400m->fw_name);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001019 i2400m->boot_mode = 0;
Inaky Perez-Gonzalezb4013f92009-06-03 09:45:55 +08001020 wmb(); /* Make sure i2400m_msg_to_dev() sees boot_mode */
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001021error_dnload_finalize:
1022error_dnload_bcf:
1023error_dnload_init:
1024error_bootrom_init:
1025error_too_many_reboots:
1026 d_fnend(5, dev, "(i2400m %p bcf %p size %zu) = %d\n",
1027 i2400m, bcf, bcf_size, ret);
1028 return ret;
1029
1030error_dev_rebooted:
1031 dev_err(dev, "device rebooted, %d tries left\n", count);
1032 /* we got the notification already, no need to wait for it again */
1033 flags |= I2400M_BRI_SOFT;
1034 goto hw_reboot;
1035}
1036
1037
1038/**
1039 * i2400m_dev_bootstrap - Bring the device to a known state and upload firmware
1040 *
1041 * @i2400m: device descriptor
1042 *
1043 * Returns: >= 0 if ok, < 0 errno code on error.
1044 *
1045 * This sets up the firmware upload environment, loads the firmware
1046 * file from disk, verifies and then calls the firmware upload process
1047 * per se.
1048 *
1049 * Can be called either from probe, or after a warm reset. Can not be
1050 * called from within an interrupt. All the flow in this code is
1051 * single-threade; all I/Os are synchronous.
1052 */
1053int i2400m_dev_bootstrap(struct i2400m *i2400m, enum i2400m_bri flags)
1054{
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001055 int ret = 0, itr = 0;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001056 struct device *dev = i2400m_dev(i2400m);
1057 const struct firmware *fw;
1058 const struct i2400m_bcf_hdr *bcf; /* Firmware data */
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001059 const char *fw_name;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001060
1061 d_fnstart(5, dev, "(i2400m %p)\n", i2400m);
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001062
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001063 /* Load firmware files to memory. */
1064 itr = 0;
1065 while(1) {
1066 fw_name = i2400m->bus_fw_names[itr];
1067 if (fw_name == NULL) {
1068 dev_err(dev, "Could not find a usable firmware image\n");
1069 ret = -ENOENT;
1070 goto error_no_fw;
1071 }
1072 ret = request_firmware(&fw, fw_name, dev);
1073 if (ret == 0)
1074 break; /* got it */
1075 if (ret < 0)
1076 dev_err(dev, "fw %s: cannot load file: %d\n",
1077 fw_name, ret);
1078 itr++;
1079 }
1080
1081 bcf = (void *) fw->data;
1082 i2400m->fw_name = fw_name;
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001083 ret = i2400m_fw_check(i2400m, bcf, fw->size);
1084 if (ret < 0)
1085 goto error_fw_bad;
1086 ret = i2400m_fw_dnload(i2400m, bcf, fw->size, flags);
1087error_fw_bad:
1088 release_firmware(fw);
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +00001089error_no_fw:
Inaky Perez-Gonzalez467cc392008-12-20 16:57:46 -08001090 d_fnend(5, dev, "(i2400m %p) = %d\n", i2400m, ret);
1091 return ret;
1092}
1093EXPORT_SYMBOL_GPL(i2400m_dev_bootstrap);