2009-08-06 21:25:28 +08:00
|
|
|
/*
|
|
|
|
* This file is part of wl1271
|
|
|
|
*
|
2010-03-26 18:53:21 +08:00
|
|
|
* Copyright (C) 2008-2010 Nokia Corporation
|
2009-08-06 21:25:28 +08:00
|
|
|
*
|
|
|
|
* Contact: Luciano Coelho <luciano.coelho@nokia.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-03-06 22:32:11 +08:00
|
|
|
#include <linux/wl12xx.h>
|
2011-05-28 04:14:23 +08:00
|
|
|
#include <linux/export.h>
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2011-10-07 16:02:42 +08:00
|
|
|
#include "debug.h"
|
2010-11-08 19:20:10 +08:00
|
|
|
#include "acx.h"
|
|
|
|
#include "boot.h"
|
|
|
|
#include "io.h"
|
|
|
|
#include "event.h"
|
2010-10-17 00:45:07 +08:00
|
|
|
#include "rx.h"
|
2011-12-07 04:24:57 +08:00
|
|
|
#include "hw_ops.h"
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-06-18 20:50:21 +08:00
|
|
|
static int wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
|
2009-08-06 21:25:28 +08:00
|
|
|
{
|
|
|
|
u32 cpu_ctrl;
|
2012-06-18 20:50:21 +08:00
|
|
|
int ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* 10.5.0 run the firmware (I) */
|
2012-06-18 20:50:21 +08:00
|
|
|
ret = wlcore_read_reg(wl, REG_ECPU_CONTROL, &cpu_ctrl);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* 10.5.1 run the firmware (II) */
|
|
|
|
cpu_ctrl |= flag;
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_write_reg(wl, REG_ECPU_CONTROL, cpu_ctrl);
|
2012-06-18 20:50:21 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
static int wlcore_boot_parse_fw_ver(struct wl1271 *wl,
|
|
|
|
struct wl1271_static_data *static_data)
|
2011-01-23 14:27:22 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
strncpy(wl->chip.fw_ver_str, static_data->fw_version,
|
|
|
|
sizeof(wl->chip.fw_ver_str));
|
|
|
|
|
|
|
|
/* make sure the string is NULL-terminated */
|
|
|
|
wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
|
|
|
|
|
2011-01-23 14:27:22 +08:00
|
|
|
ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
|
|
|
|
&wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
|
|
|
|
&wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
|
|
|
|
&wl->chip.fw_ver[4]);
|
|
|
|
|
|
|
|
if (ret != 5) {
|
|
|
|
wl1271_warning("fw version incorrect value");
|
|
|
|
memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
|
2012-05-10 17:14:10 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2011-01-23 14:27:22 +08:00
|
|
|
}
|
2011-06-06 19:57:04 +08:00
|
|
|
|
2011-12-07 04:24:57 +08:00
|
|
|
ret = wlcore_identify_fw(wl);
|
|
|
|
if (ret < 0)
|
2012-05-10 17:14:10 +08:00
|
|
|
goto out;
|
|
|
|
out:
|
|
|
|
return ret;
|
2011-01-23 14:27:22 +08:00
|
|
|
}
|
|
|
|
|
2012-06-25 22:46:40 +08:00
|
|
|
static int wlcore_validate_fw_ver(struct wl1271 *wl)
|
|
|
|
{
|
|
|
|
unsigned int *fw_ver = wl->chip.fw_ver;
|
|
|
|
unsigned int *min_ver = wl->min_fw_ver;
|
|
|
|
|
|
|
|
/* the chip must be exactly equal */
|
|
|
|
if (min_ver[FW_VER_CHIP] != fw_ver[FW_VER_CHIP])
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* always check the next digit if all previous ones are equal */
|
|
|
|
|
|
|
|
if (min_ver[FW_VER_IF_TYPE] < fw_ver[FW_VER_IF_TYPE])
|
|
|
|
goto out;
|
|
|
|
else if (min_ver[FW_VER_IF_TYPE] > fw_ver[FW_VER_IF_TYPE])
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (min_ver[FW_VER_MAJOR] < fw_ver[FW_VER_MAJOR])
|
|
|
|
goto out;
|
|
|
|
else if (min_ver[FW_VER_MAJOR] > fw_ver[FW_VER_MAJOR])
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (min_ver[FW_VER_SUBTYPE] < fw_ver[FW_VER_SUBTYPE])
|
|
|
|
goto out;
|
|
|
|
else if (min_ver[FW_VER_SUBTYPE] > fw_ver[FW_VER_SUBTYPE])
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (min_ver[FW_VER_MINOR] < fw_ver[FW_VER_MINOR])
|
|
|
|
goto out;
|
|
|
|
else if (min_ver[FW_VER_MINOR] > fw_ver[FW_VER_MINOR])
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
wl1271_error("Your WiFi FW version (%u.%u.%u.%u.%u) is outdated.\n"
|
|
|
|
"Please use at least FW %u.%u.%u.%u.%u.\n"
|
|
|
|
"You can get more information at:\n"
|
|
|
|
"http://wireless.kernel.org/en/users/Drivers/wl12xx",
|
|
|
|
fw_ver[FW_VER_CHIP], fw_ver[FW_VER_IF_TYPE],
|
|
|
|
fw_ver[FW_VER_MAJOR], fw_ver[FW_VER_SUBTYPE],
|
|
|
|
fw_ver[FW_VER_MINOR], min_ver[FW_VER_CHIP],
|
|
|
|
min_ver[FW_VER_IF_TYPE], min_ver[FW_VER_MAJOR],
|
|
|
|
min_ver[FW_VER_SUBTYPE], min_ver[FW_VER_MINOR]);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
static int wlcore_boot_static_data(struct wl1271 *wl)
|
2009-08-06 21:25:28 +08:00
|
|
|
{
|
2012-03-18 01:41:53 +08:00
|
|
|
struct wl1271_static_data *static_data;
|
2012-05-10 17:14:10 +08:00
|
|
|
size_t len = sizeof(*static_data) + wl->static_data_priv_len;
|
2011-12-07 04:24:57 +08:00
|
|
|
int ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
static_data = kmalloc(len, GFP_KERNEL);
|
2012-03-18 01:41:53 +08:00
|
|
|
if (!static_data) {
|
2012-05-10 17:14:10 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
2012-03-18 01:41:53 +08:00
|
|
|
}
|
|
|
|
|
2012-06-18 17:31:16 +08:00
|
|
|
ret = wlcore_read(wl, wl->cmd_box_addr, static_data, len, false);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_free;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
ret = wlcore_boot_parse_fw_ver(wl, static_data);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_free;
|
2011-01-23 14:27:22 +08:00
|
|
|
|
2012-06-25 22:46:40 +08:00
|
|
|
ret = wlcore_validate_fw_ver(wl);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
ret = wlcore_handle_static_data(wl, static_data);
|
2011-12-07 04:24:57 +08:00
|
|
|
if (ret < 0)
|
2012-05-10 17:14:10 +08:00
|
|
|
goto out_free;
|
2011-12-07 04:24:57 +08:00
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
out_free:
|
|
|
|
kfree(static_data);
|
|
|
|
out:
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
|
|
|
|
size_t fw_data_len, u32 dest)
|
|
|
|
{
|
2011-11-22 02:37:14 +08:00
|
|
|
struct wlcore_partition_set partition;
|
2009-08-06 21:25:28 +08:00
|
|
|
int addr, chunk_num, partition_limit;
|
2009-10-09 02:56:32 +08:00
|
|
|
u8 *p, *chunk;
|
2012-06-18 18:21:55 +08:00
|
|
|
int ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* whal_FwCtrl_LoadFwImageSm() */
|
|
|
|
|
|
|
|
wl1271_debug(DEBUG_BOOT, "starting firmware upload");
|
|
|
|
|
2009-08-11 16:58:27 +08:00
|
|
|
wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
|
|
|
|
fw_data_len, CHUNK_SIZE);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
if ((fw_data_len % 4) != 0) {
|
|
|
|
wl1271_error("firmware length not multiple of four");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2009-10-09 02:56:32 +08:00
|
|
|
chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
|
2009-10-13 17:47:57 +08:00
|
|
|
if (!chunk) {
|
2009-10-09 02:56:32 +08:00
|
|
|
wl1271_error("allocation for firmware upload chunk failed");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2011-11-22 02:37:14 +08:00
|
|
|
memcpy(&partition, &wl->ptable[PART_DOWN], sizeof(partition));
|
2009-10-12 20:08:46 +08:00
|
|
|
partition.mem.start = dest;
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_set_partition(wl, &partition);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* 10.1 set partition limit and chunk num */
|
|
|
|
chunk_num = 0;
|
2011-11-22 02:37:14 +08:00
|
|
|
partition_limit = wl->ptable[PART_DOWN].mem.size;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
while (chunk_num < fw_data_len / CHUNK_SIZE) {
|
|
|
|
/* 10.2 update partition, if needed */
|
|
|
|
addr = dest + (chunk_num + 2) * CHUNK_SIZE;
|
|
|
|
if (addr > partition_limit) {
|
|
|
|
addr = dest + chunk_num * CHUNK_SIZE;
|
|
|
|
partition_limit = chunk_num * CHUNK_SIZE +
|
2011-11-22 02:37:14 +08:00
|
|
|
wl->ptable[PART_DOWN].mem.size;
|
2009-10-12 20:08:46 +08:00
|
|
|
partition.mem.start = addr;
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_set_partition(wl, &partition);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 10.3 upload the chunk */
|
|
|
|
addr = dest + chunk_num * CHUNK_SIZE;
|
|
|
|
p = buf + chunk_num * CHUNK_SIZE;
|
2009-10-09 02:56:32 +08:00
|
|
|
memcpy(chunk, p, CHUNK_SIZE);
|
2009-08-06 21:25:28 +08:00
|
|
|
wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
|
|
|
|
p, addr);
|
2012-06-18 18:21:55 +08:00
|
|
|
ret = wlcore_write(wl, addr, chunk, CHUNK_SIZE, false);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
chunk_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 10.4 upload the last chunk */
|
|
|
|
addr = dest + chunk_num * CHUNK_SIZE;
|
|
|
|
p = buf + chunk_num * CHUNK_SIZE;
|
2009-10-09 02:56:32 +08:00
|
|
|
memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
|
2009-08-11 16:58:27 +08:00
|
|
|
wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
|
2009-08-06 21:25:28 +08:00
|
|
|
fw_data_len % CHUNK_SIZE, p, addr);
|
2012-06-18 18:21:55 +08:00
|
|
|
ret = wlcore_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-06-18 18:21:55 +08:00
|
|
|
out:
|
2009-10-09 02:56:32 +08:00
|
|
|
kfree(chunk);
|
2012-06-18 18:21:55 +08:00
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
|
|
|
|
2012-04-11 16:03:14 +08:00
|
|
|
int wlcore_boot_upload_firmware(struct wl1271 *wl)
|
2009-08-06 21:25:28 +08:00
|
|
|
{
|
|
|
|
u32 chunks, addr, len;
|
2009-10-13 17:47:57 +08:00
|
|
|
int ret = 0;
|
2009-08-06 21:25:28 +08:00
|
|
|
u8 *fw;
|
|
|
|
|
|
|
|
fw = wl->fw;
|
2009-10-15 15:33:29 +08:00
|
|
|
chunks = be32_to_cpup((__be32 *) fw);
|
2009-08-06 21:25:28 +08:00
|
|
|
fw += sizeof(u32);
|
|
|
|
|
|
|
|
wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
|
|
|
|
|
|
|
|
while (chunks--) {
|
2009-10-15 15:33:29 +08:00
|
|
|
addr = be32_to_cpup((__be32 *) fw);
|
2009-08-06 21:25:28 +08:00
|
|
|
fw += sizeof(u32);
|
2009-10-15 15:33:29 +08:00
|
|
|
len = be32_to_cpup((__be32 *) fw);
|
2009-08-06 21:25:28 +08:00
|
|
|
fw += sizeof(u32);
|
|
|
|
|
|
|
|
if (len > 300000) {
|
|
|
|
wl1271_info("firmware chunk too long: %u", len);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
|
|
|
|
chunks, addr, len);
|
2009-10-13 17:47:57 +08:00
|
|
|
ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
|
|
|
|
if (ret != 0)
|
|
|
|
break;
|
2009-08-06 21:25:28 +08:00
|
|
|
fw += len;
|
|
|
|
}
|
|
|
|
|
2009-10-13 17:47:57 +08:00
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
2012-04-11 16:03:14 +08:00
|
|
|
EXPORT_SYMBOL_GPL(wlcore_boot_upload_firmware);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-04-11 16:03:14 +08:00
|
|
|
int wlcore_boot_upload_nvs(struct wl1271 *wl)
|
2009-08-06 21:25:28 +08:00
|
|
|
{
|
|
|
|
size_t nvs_len, burst_len;
|
|
|
|
int i;
|
|
|
|
u32 dest_addr, val;
|
2010-02-18 19:25:42 +08:00
|
|
|
u8 *nvs_ptr, *nvs_aligned;
|
2012-06-18 18:21:55 +08:00
|
|
|
int ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-05-29 23:38:05 +08:00
|
|
|
if (wl->nvs == NULL) {
|
|
|
|
wl1271_error("NVS file is needed during boot");
|
2009-08-06 21:25:28 +08:00
|
|
|
return -ENODEV;
|
2012-05-29 23:38:05 +08:00
|
|
|
}
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2011-11-30 18:30:01 +08:00
|
|
|
if (wl->quirks & WLCORE_QUIRK_LEGACY_NVS) {
|
2011-03-06 22:32:10 +08:00
|
|
|
struct wl1271_nvs_file *nvs =
|
|
|
|
(struct wl1271_nvs_file *)wl->nvs;
|
|
|
|
/*
|
|
|
|
* FIXME: the LEGACY NVS image support (NVS's missing the 5GHz
|
|
|
|
* band configurations) can be removed when those NVS files stop
|
|
|
|
* floating around.
|
|
|
|
*/
|
|
|
|
if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
|
|
|
|
wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
|
2011-08-23 20:56:22 +08:00
|
|
|
if (nvs->general_params.dual_mode_select)
|
2011-03-06 22:32:10 +08:00
|
|
|
wl->enable_11a = true;
|
|
|
|
}
|
2010-08-19 10:41:15 +08:00
|
|
|
|
2011-03-06 22:32:10 +08:00
|
|
|
if (wl->nvs_len != sizeof(struct wl1271_nvs_file) &&
|
|
|
|
(wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
|
|
|
|
wl->enable_11a)) {
|
|
|
|
wl1271_error("nvs size is not as expected: %zu != %zu",
|
|
|
|
wl->nvs_len, sizeof(struct wl1271_nvs_file));
|
|
|
|
kfree(wl->nvs);
|
|
|
|
wl->nvs = NULL;
|
|
|
|
wl->nvs_len = 0;
|
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only the first part of the NVS needs to be uploaded */
|
|
|
|
nvs_len = sizeof(nvs->nvs);
|
|
|
|
nvs_ptr = (u8 *) nvs->nvs;
|
2011-11-30 18:30:01 +08:00
|
|
|
} else {
|
|
|
|
struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
|
|
|
|
|
|
|
|
if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) {
|
|
|
|
if (nvs->general_params.dual_mode_select)
|
|
|
|
wl->enable_11a = true;
|
|
|
|
} else {
|
|
|
|
wl1271_error("nvs size is not as expected: %zu != %zu",
|
|
|
|
wl->nvs_len,
|
|
|
|
sizeof(struct wl128x_nvs_file));
|
|
|
|
kfree(wl->nvs);
|
|
|
|
wl->nvs = NULL;
|
|
|
|
wl->nvs_len = 0;
|
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only the first part of the NVS needs to be uploaded */
|
|
|
|
nvs_len = sizeof(nvs->nvs);
|
|
|
|
nvs_ptr = (u8 *)nvs->nvs;
|
2011-03-06 22:32:10 +08:00
|
|
|
}
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2010-03-18 18:26:39 +08:00
|
|
|
/* update current MAC address to NVS */
|
2011-12-23 15:32:17 +08:00
|
|
|
nvs_ptr[11] = wl->addresses[0].addr[0];
|
|
|
|
nvs_ptr[10] = wl->addresses[0].addr[1];
|
|
|
|
nvs_ptr[6] = wl->addresses[0].addr[2];
|
|
|
|
nvs_ptr[5] = wl->addresses[0].addr[3];
|
|
|
|
nvs_ptr[4] = wl->addresses[0].addr[4];
|
|
|
|
nvs_ptr[3] = wl->addresses[0].addr[5];
|
2010-03-18 18:26:39 +08:00
|
|
|
|
2009-08-06 21:25:28 +08:00
|
|
|
/*
|
|
|
|
* Layout before the actual NVS tables:
|
|
|
|
* 1 byte : burst length.
|
|
|
|
* 2 bytes: destination address.
|
|
|
|
* n bytes: data to burst copy.
|
|
|
|
*
|
|
|
|
* This is ended by a 0 length, then the NVS tables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* FIXME: Do we need to check here whether the LSB is 1? */
|
|
|
|
while (nvs_ptr[0]) {
|
|
|
|
burst_len = nvs_ptr[0];
|
|
|
|
dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
|
|
|
|
|
2010-08-10 12:38:35 +08:00
|
|
|
/*
|
|
|
|
* Due to our new wl1271_translate_reg_addr function,
|
2011-11-29 19:38:37 +08:00
|
|
|
* we need to add the register partition start address
|
|
|
|
* to the destination
|
2010-08-10 12:38:35 +08:00
|
|
|
*/
|
2011-11-29 19:38:37 +08:00
|
|
|
dest_addr += wl->curr_part.reg.start;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* We move our pointer to the data */
|
|
|
|
nvs_ptr += 3;
|
|
|
|
|
|
|
|
for (i = 0; i < burst_len; i++) {
|
2011-10-18 15:23:42 +08:00
|
|
|
if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len)
|
|
|
|
goto out_badnvs;
|
|
|
|
|
2009-08-06 21:25:28 +08:00
|
|
|
val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
|
|
|
|
| (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
|
|
|
|
|
|
|
|
wl1271_debug(DEBUG_BOOT,
|
|
|
|
"nvs burst write 0x%x: 0x%x",
|
|
|
|
dest_addr, val);
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_write32(wl, dest_addr, val);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
nvs_ptr += 4;
|
|
|
|
dest_addr += 4;
|
|
|
|
}
|
2011-10-18 15:23:42 +08:00
|
|
|
|
|
|
|
if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
|
|
|
|
goto out_badnvs;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've reached the first zero length, the first NVS table
|
2010-09-22 15:53:13 +08:00
|
|
|
* is located at an aligned offset which is at least 7 bytes further.
|
2011-03-06 22:32:10 +08:00
|
|
|
* NOTE: The wl->nvs->nvs element must be first, in order to
|
|
|
|
* simplify the casting, we assume it is at the beginning of
|
|
|
|
* the wl->nvs structure.
|
2009-08-06 21:25:28 +08:00
|
|
|
*/
|
2011-03-06 22:32:10 +08:00
|
|
|
nvs_ptr = (u8 *)wl->nvs +
|
|
|
|
ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
|
2011-10-18 15:23:42 +08:00
|
|
|
|
|
|
|
if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
|
|
|
|
goto out_badnvs;
|
|
|
|
|
2011-03-06 22:32:10 +08:00
|
|
|
nvs_len -= nvs_ptr - (u8 *)wl->nvs;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* Now we must set the partition correctly */
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* Copy the NVS tables to a new block to ensure alignment */
|
2010-09-22 15:53:13 +08:00
|
|
|
nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
|
|
|
|
if (!nvs_aligned)
|
|
|
|
return -ENOMEM;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* And finally we upload the NVS tables */
|
2012-06-18 18:21:55 +08:00
|
|
|
ret = wlcore_write_data(wl, REG_CMD_MBOX_ADDRESS, nvs_aligned, nvs_len,
|
|
|
|
false);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
kfree(nvs_aligned);
|
2012-06-18 18:21:55 +08:00
|
|
|
return ret;
|
2011-10-18 15:23:42 +08:00
|
|
|
|
|
|
|
out_badnvs:
|
|
|
|
wl1271_error("nvs data is malformed");
|
|
|
|
return -EILSEQ;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
2012-04-11 16:03:14 +08:00
|
|
|
EXPORT_SYMBOL_GPL(wlcore_boot_upload_nvs);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-04-11 16:03:14 +08:00
|
|
|
int wlcore_boot_run_firmware(struct wl1271 *wl)
|
2009-08-06 21:25:28 +08:00
|
|
|
{
|
|
|
|
int loop, ret;
|
2010-04-28 14:50:02 +08:00
|
|
|
u32 chip_id, intr;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-04-11 16:03:14 +08:00
|
|
|
/* Make sure we have the boot partition */
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-04-11 16:03:14 +08:00
|
|
|
|
2012-06-18 20:50:21 +08:00
|
|
|
ret = wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-06-18 20:50:21 +08:00
|
|
|
ret = wlcore_read_reg(wl, REG_CHIP_ID_B, &chip_id);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
|
|
|
|
|
|
|
|
if (chip_id != wl->chip.id) {
|
|
|
|
wl1271_error("chip id doesn't match after firmware boot");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for init to complete */
|
|
|
|
loop = 0;
|
|
|
|
while (loop++ < INIT_LOOP) {
|
|
|
|
udelay(INIT_LOOP_DELAY);
|
2012-06-18 20:50:21 +08:00
|
|
|
ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2010-04-28 14:50:02 +08:00
|
|
|
if (intr == 0xffffffff) {
|
2009-08-06 21:25:28 +08:00
|
|
|
wl1271_error("error reading hardware complete "
|
|
|
|
"init indication");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
/* check that ACX_INTR_INIT_COMPLETE is enabled */
|
2010-04-28 14:50:02 +08:00
|
|
|
else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK,
|
|
|
|
WL1271_ACX_INTR_INIT_COMPLETE);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-29 19:20:04 +08:00
|
|
|
if (loop > INIT_LOOP) {
|
2009-08-06 21:25:28 +08:00
|
|
|
wl1271_error("timeout waiting for the hardware to "
|
|
|
|
"complete initialization");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get hardware config command mail box */
|
2012-06-18 20:50:21 +08:00
|
|
|
ret = wlcore_read_reg(wl, REG_COMMAND_MAILBOX_PTR, &wl->cmd_box_addr);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2011-11-30 21:02:47 +08:00
|
|
|
wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x", wl->cmd_box_addr);
|
|
|
|
|
2009-08-06 21:25:28 +08:00
|
|
|
/* get hardware config event mail box */
|
2012-06-18 20:50:21 +08:00
|
|
|
ret = wlcore_read_reg(wl, REG_EVENT_MAILBOX_PTR, &wl->mbox_ptr[0]);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2011-11-30 21:02:47 +08:00
|
|
|
wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2011-11-30 21:02:47 +08:00
|
|
|
wl1271_debug(DEBUG_MAILBOX, "MBOX ptrs: 0x%x 0x%x",
|
|
|
|
wl->mbox_ptr[0], wl->mbox_ptr[1]);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
2012-05-10 17:14:10 +08:00
|
|
|
ret = wlcore_boot_static_data(wl);
|
2011-12-07 04:24:57 +08:00
|
|
|
if (ret < 0) {
|
2012-05-10 17:14:10 +08:00
|
|
|
wl1271_error("error getting static data");
|
2011-12-07 04:24:57 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* in case of full asynchronous mode the firmware event must be
|
|
|
|
* ready to receive event from the command mailbox
|
|
|
|
*/
|
|
|
|
|
2009-10-09 02:56:36 +08:00
|
|
|
/* unmask required mbox events */
|
|
|
|
wl->event_mask = BSS_LOSE_EVENT_ID |
|
2012-04-26 15:35:07 +08:00
|
|
|
REGAINED_BSS_EVENT_ID |
|
2009-11-03 02:22:11 +08:00
|
|
|
SCAN_COMPLETE_EVENT_ID |
|
2012-01-31 17:57:19 +08:00
|
|
|
ROLE_STOP_COMPLETE_EVENT_ID |
|
2010-07-08 22:50:00 +08:00
|
|
|
RSSI_SNR_TRIGGER_0_EVENT_ID |
|
2010-07-08 22:50:03 +08:00
|
|
|
PSPOLL_DELIVERY_FAILURE_EVENT_ID |
|
2011-05-10 19:28:27 +08:00
|
|
|
SOFT_GEMINI_SENSE_EVENT_ID |
|
|
|
|
PERIODIC_SCAN_REPORT_EVENT_ID |
|
2011-08-14 18:17:07 +08:00
|
|
|
PERIODIC_SCAN_COMPLETE_EVENT_ID |
|
|
|
|
DUMMY_PACKET_EVENT_ID |
|
|
|
|
PEER_REMOVE_COMPLETE_EVENT_ID |
|
|
|
|
BA_SESSION_RX_CONSTRAINT_EVENT_ID |
|
|
|
|
REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID |
|
|
|
|
INACTIVE_STA_EVENT_ID |
|
2011-09-08 18:01:33 +08:00
|
|
|
MAX_TX_RETRY_EVENT_ID |
|
|
|
|
CHANNEL_SWITCH_COMPLETE_EVENT_ID;
|
2010-10-25 17:17:44 +08:00
|
|
|
|
2009-08-06 21:25:28 +08:00
|
|
|
ret = wl1271_event_unmask(wl);
|
|
|
|
if (ret < 0) {
|
|
|
|
wl1271_error("EVENT mask setting failed");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-30 21:02:47 +08:00
|
|
|
/* set the working partition to its "running" mode offset */
|
2012-06-20 05:48:23 +08:00
|
|
|
ret = wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
|
2009-08-06 21:25:28 +08:00
|
|
|
|
|
|
|
/* firmware startup completed */
|
2012-06-20 05:48:23 +08:00
|
|
|
return ret;
|
2009-08-06 21:25:28 +08:00
|
|
|
}
|
2012-04-11 16:03:14 +08:00
|
|
|
EXPORT_SYMBOL_GPL(wlcore_boot_run_firmware);
|