31 #include <linux/slab.h>
63 const char *_data,
const u32 *data_itr,
const u32 *data_top)
65 size_t hdr_offset = (
const char *) data_itr - _data;
66 size_t remaining_size = (
void *) data_top - (
void *) data_itr;
67 if (data_itr + 2 > data_top) {
68 dev_err(i1480->
dev,
"fw hdr #%u/%zu: EOF reached in header at "
69 "offset %zu, limit %zu\n",
71 (
const char *) data_itr + 2 - _data,
72 (
const char *) data_top - _data);
79 if (hdr->
length > remaining_size) {
80 dev_err(i1480->
dev,
"fw hdr #%u/%zu: EOF reached in data; "
81 "chunk too long (%zu bytes), only %zu left\n",
82 hdr_cnt, hdr_offset, hdr->
length, remaining_size);
108 int fw_hdrs_load(
struct i1480 *i1480,
struct fw_hdr **phdr,
112 unsigned hdr_cnt = 0;
113 u32 *
data = (
u32 *) _data, *data_itr, *data_top;
118 if (data_size %
sizeof(
u32) != 0)
120 if ((
unsigned long) _data %
sizeof(
u16) != 0)
124 data_top = (
u32 *) (_data + data_size);
125 while (data_itr < data_top) {
129 dev_err(i1480->
dev,
"Cannot allocate fw header "
130 "for chunk #%u\n", hdr_cnt);
133 result = fw_hdr_load(i1480, hdr, hdr_cnt,
134 _data, data_itr, data_top);
137 data_itr += 2 + hdr->
length;
139 prev_hdr = &hdr->
next;
167 ssize_t i1480_fw_cmp(
struct i1480 *i1480,
struct fw_hdr *hdr)
177 result = i1480->
read(i1480, hdr->
address + src_itr, chunk_size);
179 dev_err(i1480->
dev,
"error reading for verification: "
186 if (bin[src_itr +
cnt] != buf[
cnt]) {
188 "src_itr %u cnt %u [0x%02x "
189 "vs 0x%02x]\n", src_itr, cnt,
190 bin[src_itr + cnt], buf[cnt]);
191 result = src_itr + cnt + 1;
213 int mac_fw_hdrs_push(
struct i1480 *i1480,
struct fw_hdr *hdr,
214 const char *
fw_name,
const char *fw_tag)
219 int verif_retry_count;
222 for (hdr_itr = hdr; hdr_itr !=
NULL; hdr_itr = hdr_itr->
next) {
223 verif_retry_count = 0;
225 dev_dbg(dev,
"fw chunk (%zu @ 0x%08lx)\n",
226 hdr_itr->
length *
sizeof(hdr_itr->
bin[0]),
229 hdr_itr->
length*
sizeof(hdr_itr->
bin[0]));
231 dev_err(dev,
"%s fw '%s': write failed (%zuB @ 0x%lx):"
232 " %zd\n", fw_tag, fw_name,
233 hdr_itr->
length *
sizeof(hdr_itr->
bin[0]),
237 result = i1480_fw_cmp(i1480, hdr_itr);
239 dev_err(dev,
"%s fw '%s': verification read "
240 "failed (%zuB @ 0x%lx): %zd\n",
242 hdr_itr->
length *
sizeof(hdr_itr->
bin[0]),
248 dev_err(dev,
"%s fw '%s': WARNING: verification "
249 "failed at 0x%lx: retrying\n",
250 fw_tag, fw_name, hdr_itr->
address + result);
251 if (++verif_retry_count < 3)
253 dev_err(dev,
"%s fw '%s': verification failed at 0x%lx: "
254 "tried %d times\n", fw_tag, fw_name,
255 hdr_itr->
address + result, verif_retry_count);
266 int mac_fw_upload_enable(
struct i1480 *i1480)
274 result = i1480->
read(i1480, reg,
sizeof(
u32));
278 result = i1480->
write(i1480, reg, buffer,
sizeof(
u32));
283 dev_err(i1480->
dev,
"can't enable fw upload mode: %d\n", result);
290 int mac_fw_upload_disable(
struct i1480 *i1480)
293 u32 reg = 0x800000c0;
298 result = i1480->
read(i1480, reg,
sizeof(
u32));
302 result = i1480->
write(i1480, reg, buffer,
sizeof(
u32));
307 dev_err(i1480->
dev,
"can't disable fw upload mode: %d\n", result);
325 int __mac_fw_upload(
struct i1480 *i1480,
const char *fw_name,
335 result = fw_hdrs_load(i1480, &fw_hdrs, fw->
data, fw->
size);
337 dev_err(i1480->
dev,
"%s fw '%s': failed to parse firmware "
338 "file: %d\n", fw_tag, fw_name, result);
341 result = mac_fw_upload_enable(i1480);
343 goto out_hdrs_release;
344 result = mac_fw_hdrs_push(i1480, fw_hdrs, fw_name, fw_tag);
345 mac_fw_upload_disable(i1480);
348 dev_info(i1480->
dev,
"%s fw '%s': uploaded\n", fw_tag, fw_name);
350 dev_err(i1480->
dev,
"%s fw '%s': failed to upload (%d), "
351 "power cycle device\n", fw_tag, fw_name, result);
352 fw_hdrs_free(fw_hdrs);
367 result = __mac_fw_upload(i1480, i1480->
pre_fw_name,
"PRE");
388 int i1480_cmd_reset(
struct i1480 *i1480)
392 struct i1480_evt_reset {
402 result =
i1480_cmd(i1480,
"RESET",
sizeof(*
cmd),
sizeof(*reply));
406 dev_err(i1480->
dev,
"RESET: command execution failed: %u\n",
418 int i1480_fw_is_running_q(
struct i1480 *i1480)
424 for (cnt = 0; cnt < 10; cnt++) {
426 result = i1480->
read(i1480, 0x80080000, 4);
428 dev_err(i1480->
dev,
"Can't read 0x8008000: %d\n", result);
431 if (*val == 0x55555555UL)
434 dev_err(i1480->
dev,
"Timed out waiting for fw to start\n");
453 int result = 0, deprecated_name = 0;
456 result = __mac_fw_upload(i1480, i1480->
mac_fw_name,
"MAC");
464 if (deprecated_name == 1)
466 "WARNING: firmware file name %s is deprecated, "
467 "please rename to %s\n",
469 result = i1480_fw_is_running_q(i1480);
471 goto error_fw_not_running;
474 dev_err(i1480->
dev,
"Cannot setup after MAC fw upload: %d\n",
480 dev_err(i1480->
dev,
"MAC fw '%s': Initialization timed out "
482 goto error_init_timeout;
486 dev_err(i1480->
dev,
"MAC fw '%s': initialization event returns "
487 "wrong size (%zu bytes vs %zu needed)\n",
494 dev_err(i1480->
dev,
"wrong initialization event 0x%02x/%04x/%02x "
495 "received; expected 0x%02x/%04x/00\n",
499 goto error_init_timeout;
501 result = i1480_cmd_reset(i1480);
503 dev_err(i1480->
dev,
"MAC fw '%s': MBOA reset failed (%d)\n",
505 error_fw_not_running: