2008-03-10 23:26:32 +07:00
|
|
|
/*
|
|
|
|
* Sonics Silicon Backplane
|
|
|
|
* Common SPROM support routines
|
|
|
|
*
|
2011-07-05 01:50:05 +07:00
|
|
|
* Copyright (C) 2005-2008 Michael Buesch <m@bues.ch>
|
2008-03-10 23:26:32 +07:00
|
|
|
* Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
|
|
|
|
* Copyright (C) 2005 Stefano Brivio <st3@riseup.net>
|
|
|
|
* Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
|
|
|
|
* Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
|
|
|
|
*
|
|
|
|
* Licensed under the GNU/GPL. See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ssb_private.h"
|
|
|
|
|
2009-11-24 02:58:06 +07:00
|
|
|
#include <linux/ctype.h>
|
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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-11-24 02:58:06 +07:00
|
|
|
|
2008-03-10 23:26:32 +07:00
|
|
|
|
2011-05-11 04:31:30 +07:00
|
|
|
static int(*get_fallback_sprom)(struct ssb_bus *dev, struct ssb_sprom *out);
|
2009-02-27 22:59:05 +07:00
|
|
|
|
|
|
|
|
2008-03-10 23:26:32 +07:00
|
|
|
static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len,
|
|
|
|
size_t sprom_size_words)
|
|
|
|
{
|
|
|
|
int i, pos = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < sprom_size_words; i++)
|
2020-03-11 16:17:39 +07:00
|
|
|
pos += scnprintf(buf + pos, buf_len - pos - 1,
|
2008-03-10 23:26:32 +07:00
|
|
|
"%04X", swab16(sprom[i]) & 0xFFFF);
|
2020-03-11 16:17:39 +07:00
|
|
|
pos += scnprintf(buf + pos, buf_len - pos - 1, "\n");
|
2008-03-10 23:26:32 +07:00
|
|
|
|
|
|
|
return pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hex2sprom(u16 *sprom, const char *dump, size_t len,
|
|
|
|
size_t sprom_size_words)
|
|
|
|
{
|
2009-11-24 02:58:06 +07:00
|
|
|
char c, tmp[5] = { 0 };
|
|
|
|
int err, cnt = 0;
|
2008-03-10 23:26:32 +07:00
|
|
|
unsigned long parsed;
|
|
|
|
|
2009-11-24 02:58:06 +07:00
|
|
|
/* Strip whitespace at the end. */
|
|
|
|
while (len) {
|
|
|
|
c = dump[len - 1];
|
|
|
|
if (!isspace(c) && c != '\0')
|
|
|
|
break;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
/* Length must match exactly. */
|
|
|
|
if (len != sprom_size_words * 4)
|
2008-03-10 23:26:32 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
while (cnt < sprom_size_words) {
|
|
|
|
memcpy(tmp, dump, 4);
|
|
|
|
dump += 4;
|
2013-06-01 04:35:23 +07:00
|
|
|
err = kstrtoul(tmp, 16, &parsed);
|
2009-11-24 02:58:06 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
2008-03-10 23:26:32 +07:00
|
|
|
sprom[cnt++] = swab16((u16)parsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Common sprom device-attribute show-handler */
|
|
|
|
ssize_t ssb_attr_sprom_show(struct ssb_bus *bus, char *buf,
|
|
|
|
int (*sprom_read)(struct ssb_bus *bus, u16 *sprom))
|
|
|
|
{
|
|
|
|
u16 *sprom;
|
|
|
|
int err = -ENOMEM;
|
|
|
|
ssize_t count = 0;
|
|
|
|
size_t sprom_size_words = bus->sprom_size;
|
|
|
|
|
|
|
|
sprom = kcalloc(sprom_size_words, sizeof(u16), GFP_KERNEL);
|
|
|
|
if (!sprom)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Use interruptible locking, as the SPROM write might
|
|
|
|
* be holding the lock for several seconds. So allow userspace
|
2020-04-25 00:50:43 +07:00
|
|
|
* to cancel operation.
|
|
|
|
*/
|
2008-03-10 23:26:32 +07:00
|
|
|
err = -ERESTARTSYS;
|
|
|
|
if (mutex_lock_interruptible(&bus->sprom_mutex))
|
|
|
|
goto out_kfree;
|
|
|
|
err = sprom_read(bus, sprom);
|
|
|
|
mutex_unlock(&bus->sprom_mutex);
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
count = sprom2hex(sprom, buf, PAGE_SIZE, sprom_size_words);
|
|
|
|
|
|
|
|
out_kfree:
|
|
|
|
kfree(sprom);
|
|
|
|
out:
|
|
|
|
return err ? err : count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Common sprom device-attribute store-handler */
|
|
|
|
ssize_t ssb_attr_sprom_store(struct ssb_bus *bus,
|
|
|
|
const char *buf, size_t count,
|
|
|
|
int (*sprom_check_crc)(const u16 *sprom, size_t size),
|
|
|
|
int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom))
|
|
|
|
{
|
|
|
|
u16 *sprom;
|
|
|
|
int res = 0, err = -ENOMEM;
|
|
|
|
size_t sprom_size_words = bus->sprom_size;
|
2009-11-24 02:12:13 +07:00
|
|
|
struct ssb_freeze_context freeze;
|
2008-03-10 23:26:32 +07:00
|
|
|
|
|
|
|
sprom = kcalloc(bus->sprom_size, sizeof(u16), GFP_KERNEL);
|
|
|
|
if (!sprom)
|
|
|
|
goto out;
|
|
|
|
err = hex2sprom(sprom, buf, count, sprom_size_words);
|
|
|
|
if (err) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out_kfree;
|
|
|
|
}
|
|
|
|
err = sprom_check_crc(sprom, sprom_size_words);
|
|
|
|
if (err) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out_kfree;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use interruptible locking, as the SPROM write might
|
|
|
|
* be holding the lock for several seconds. So allow userspace
|
2020-04-25 00:50:43 +07:00
|
|
|
* to cancel operation.
|
|
|
|
*/
|
2008-03-10 23:26:32 +07:00
|
|
|
err = -ERESTARTSYS;
|
|
|
|
if (mutex_lock_interruptible(&bus->sprom_mutex))
|
|
|
|
goto out_kfree;
|
2009-11-24 02:12:13 +07:00
|
|
|
err = ssb_devices_freeze(bus, &freeze);
|
2008-03-10 23:26:32 +07:00
|
|
|
if (err) {
|
2018-08-01 02:56:38 +07:00
|
|
|
pr_err("SPROM write: Could not freeze all devices\n");
|
2008-03-10 23:26:32 +07:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
res = sprom_write(bus, sprom);
|
2009-11-24 02:12:13 +07:00
|
|
|
err = ssb_devices_thaw(&freeze);
|
2008-03-10 23:26:32 +07:00
|
|
|
if (err)
|
2018-08-01 02:56:38 +07:00
|
|
|
pr_err("SPROM write: Could not thaw all devices\n");
|
2008-03-10 23:26:32 +07:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&bus->sprom_mutex);
|
|
|
|
out_kfree:
|
|
|
|
kfree(sprom);
|
|
|
|
out:
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
return err ? err : count;
|
|
|
|
}
|
2009-02-27 22:59:05 +07:00
|
|
|
|
|
|
|
/**
|
2011-05-11 04:31:30 +07:00
|
|
|
* ssb_arch_register_fallback_sprom - Registers a method providing a
|
|
|
|
* fallback SPROM if no SPROM is found.
|
2009-02-27 22:59:05 +07:00
|
|
|
*
|
2011-05-11 04:31:30 +07:00
|
|
|
* @sprom_callback: The callback function.
|
2009-02-27 22:59:05 +07:00
|
|
|
*
|
2011-05-11 04:31:30 +07:00
|
|
|
* With this function the architecture implementation may register a
|
|
|
|
* callback handler which fills the SPROM data structure. The fallback is
|
|
|
|
* only used for PCI based SSB devices, where no valid SPROM can be found
|
|
|
|
* in the shadow registers.
|
2009-02-27 22:59:05 +07:00
|
|
|
*
|
2011-05-11 04:31:30 +07:00
|
|
|
* This function is useful for weird architectures that have a half-assed
|
|
|
|
* SSB device hardwired to their PCI bus.
|
2009-02-27 22:59:05 +07:00
|
|
|
*
|
2011-05-11 04:31:30 +07:00
|
|
|
* Note that it does only work with PCI attached SSB devices. PCMCIA
|
|
|
|
* devices currently don't use this fallback.
|
|
|
|
* Architectures must provide the SPROM for native SSB devices anyway, so
|
|
|
|
* the fallback also isn't used for native devices.
|
2009-02-27 22:59:05 +07:00
|
|
|
*
|
2011-05-11 04:31:30 +07:00
|
|
|
* This function is available for architecture code, only. So it is not
|
|
|
|
* exported.
|
2009-02-27 22:59:05 +07:00
|
|
|
*/
|
2011-05-11 04:31:30 +07:00
|
|
|
int ssb_arch_register_fallback_sprom(int (*sprom_callback)(struct ssb_bus *bus,
|
|
|
|
struct ssb_sprom *out))
|
2009-02-27 22:59:05 +07:00
|
|
|
{
|
2011-05-11 04:31:30 +07:00
|
|
|
if (get_fallback_sprom)
|
2009-02-27 22:59:05 +07:00
|
|
|
return -EEXIST;
|
2011-05-11 04:31:30 +07:00
|
|
|
get_fallback_sprom = sprom_callback;
|
2009-02-27 22:59:05 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-11 04:31:30 +07:00
|
|
|
int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, struct ssb_sprom *out)
|
2009-02-27 22:59:05 +07:00
|
|
|
{
|
2011-05-11 04:31:30 +07:00
|
|
|
if (!get_fallback_sprom)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
return get_fallback_sprom(bus, out);
|
2009-02-27 22:59:05 +07:00
|
|
|
}
|
2010-04-01 02:39:35 +07:00
|
|
|
|
|
|
|
/* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */
|
|
|
|
bool ssb_is_sprom_available(struct ssb_bus *bus)
|
|
|
|
{
|
|
|
|
/* status register only exists on chipcomon rev >= 11 and we need check
|
2020-04-25 00:50:43 +07:00
|
|
|
* for >= 31 only
|
|
|
|
*/
|
2010-04-01 02:39:35 +07:00
|
|
|
/* this routine differs from specs as we do not access SPROM directly
|
2020-04-25 00:50:43 +07:00
|
|
|
* on PCMCIA
|
|
|
|
*/
|
2010-04-01 02:39:35 +07:00
|
|
|
if (bus->bustype == SSB_BUSTYPE_PCI &&
|
2011-03-31 08:57:33 +07:00
|
|
|
bus->chipco.dev && /* can be unavailable! */
|
2010-04-01 02:39:35 +07:00
|
|
|
bus->chipco.dev->id.revision >= 31)
|
|
|
|
return bus->chipco.capabilities & SSB_CHIPCO_CAP_SPROM;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|