Commit b3ae52b6 authored by Hauke Mehrtens's avatar Hauke Mehrtens Committed by Ralf Baechle

SSB: Change fallback sprom to callback mechanism.

Some embedded devices like the Netgear WNDR3300 have two SSB based cards
without an own sprom on the pci bus. We have to provide two different
fallback sproms for these and this was not possible with the old solution.
In the bcm47xx architecture the sprom data is stored in the nvram in the
main flash storage. The architecture code will be able to fill the sprom
with the stored data based on the bus where the device was found.

The bcm63xx code should do the same thing as before, just using the new
API.
Acked-by: default avatarMichael Buesch <mb@bu3sch.de>
Cc: netdev@vger.kernel.org
Cc: linux-wireless@vger.kernel.org
Cc: Florian Fainelli <florian@openwrt.org>
Signed-off-by: default avatarHauke Mehrtens <hauke@hauke-m.de>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/2362/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent b7f720d6
...@@ -643,6 +643,17 @@ static struct ssb_sprom bcm63xx_sprom = { ...@@ -643,6 +643,17 @@ static struct ssb_sprom bcm63xx_sprom = {
.boardflags_lo = 0x2848, .boardflags_lo = 0x2848,
.boardflags_hi = 0x0000, .boardflags_hi = 0x0000,
}; };
int bcm63xx_get_fallback_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
{
if (bus->bustype == SSB_BUSTYPE_PCI) {
memcpy(out, &bcm63xx_sprom, sizeof(struct ssb_sprom));
return 0;
} else {
printk(KERN_ERR PFX "unable to fill SPROM for given bustype.\n");
return -EINVAL;
}
}
#endif #endif
/* /*
...@@ -793,8 +804,9 @@ void __init board_prom_init(void) ...@@ -793,8 +804,9 @@ void __init board_prom_init(void)
if (!board_get_mac_address(bcm63xx_sprom.il0mac)) { if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN); memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN); memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
if (ssb_arch_set_fallback_sprom(&bcm63xx_sprom) < 0) if (ssb_arch_register_fallback_sprom(
printk(KERN_ERR "failed to register fallback SPROM\n"); &bcm63xx_get_fallback_sprom) < 0)
printk(KERN_ERR PFX "failed to register fallback SPROM\n");
} }
#endif #endif
} }
......
...@@ -662,7 +662,6 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out, ...@@ -662,7 +662,6 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out,
static int ssb_pci_sprom_get(struct ssb_bus *bus, static int ssb_pci_sprom_get(struct ssb_bus *bus,
struct ssb_sprom *sprom) struct ssb_sprom *sprom)
{ {
const struct ssb_sprom *fallback;
int err; int err;
u16 *buf; u16 *buf;
...@@ -707,10 +706,17 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus, ...@@ -707,10 +706,17 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus,
if (err) { if (err) {
/* All CRC attempts failed. /* All CRC attempts failed.
* Maybe there is no SPROM on the device? * Maybe there is no SPROM on the device?
* If we have a fallback, use that. */ * Now we ask the arch code if there is some sprom
fallback = ssb_get_fallback_sprom(); * available for this device in some other storage */
if (fallback) { err = ssb_fill_sprom_with_fallback(bus, sprom);
memcpy(sprom, fallback, sizeof(*sprom)); if (err) {
ssb_printk(KERN_WARNING PFX "WARNING: Using"
" fallback SPROM failed (err %d)\n",
err);
} else {
ssb_dprintk(KERN_DEBUG PFX "Using SPROM"
" revision %d provided by"
" platform.\n", sprom->revision);
err = 0; err = 0;
goto out_free; goto out_free;
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <linux/slab.h> #include <linux/slab.h>
static const struct ssb_sprom *fallback_sprom; static int(*get_fallback_sprom)(struct ssb_bus *dev, struct ssb_sprom *out);
static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len,
...@@ -145,36 +145,43 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus, ...@@ -145,36 +145,43 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus,
} }
/** /**
* ssb_arch_set_fallback_sprom - Set a fallback SPROM for use if no SPROM is found. * ssb_arch_register_fallback_sprom - Registers a method providing a
* fallback SPROM if no SPROM is found.
* *
* @sprom: The SPROM data structure to register. * @sprom_callback: The callback function.
* *
* With this function the architecture implementation may register a fallback * With this function the architecture implementation may register a
* SPROM data structure. The fallback is only used for PCI based SSB devices, * callback handler which fills the SPROM data structure. The fallback is
* where no valid SPROM can be found in the shadow registers. * only used for PCI based SSB devices, where no valid SPROM can be found
* in the shadow registers.
* *
* This function is useful for weird architectures that have a half-assed SSB device * This function is useful for weird architectures that have a half-assed
* hardwired to their PCI bus. * SSB device hardwired to their PCI bus.
* *
* Note that it does only work with PCI attached SSB devices. PCMCIA devices currently * Note that it does only work with PCI attached SSB devices. PCMCIA
* don't use this fallback. * devices currently don't use this fallback.
* Architectures must provide the SPROM for native SSB devices anyway, * Architectures must provide the SPROM for native SSB devices anyway, so
* so the fallback also isn't used for native devices. * the fallback also isn't used for native devices.
* *
* This function is available for architecture code, only. So it is not exported. * This function is available for architecture code, only. So it is not
* exported.
*/ */
int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom) int ssb_arch_register_fallback_sprom(int (*sprom_callback)(struct ssb_bus *bus,
struct ssb_sprom *out))
{ {
if (fallback_sprom) if (get_fallback_sprom)
return -EEXIST; return -EEXIST;
fallback_sprom = sprom; get_fallback_sprom = sprom_callback;
return 0; return 0;
} }
const struct ssb_sprom *ssb_get_fallback_sprom(void) int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, struct ssb_sprom *out)
{ {
return fallback_sprom; if (!get_fallback_sprom)
return -ENOENT;
return get_fallback_sprom(bus, out);
} }
/* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */ /* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */
......
...@@ -171,7 +171,8 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus, ...@@ -171,7 +171,8 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus,
const char *buf, size_t count, const char *buf, size_t count,
int (*sprom_check_crc)(const u16 *sprom, size_t size), int (*sprom_check_crc)(const u16 *sprom, size_t size),
int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom)); int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom));
extern const struct ssb_sprom *ssb_get_fallback_sprom(void); extern int ssb_fill_sprom_with_fallback(struct ssb_bus *bus,
struct ssb_sprom *out);
/* core.c */ /* core.c */
......
...@@ -404,7 +404,9 @@ extern bool ssb_is_sprom_available(struct ssb_bus *bus); ...@@ -404,7 +404,9 @@ extern bool ssb_is_sprom_available(struct ssb_bus *bus);
/* Set a fallback SPROM. /* Set a fallback SPROM.
* See kdoc at the function definition for complete documentation. */ * See kdoc at the function definition for complete documentation. */
extern int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom); extern int ssb_arch_register_fallback_sprom(
int (*sprom_callback)(struct ssb_bus *bus,
struct ssb_sprom *out));
/* Suspend a SSB bus. /* Suspend a SSB bus.
* Call this from the parent bus suspend routine. */ * Call this from the parent bus suspend routine. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment