/* * Copyright (C) 2004 Florian Schirmer <[email protected]> * Copyright (C) 2006 Felix Fietkau <[email protected]> * Copyright (C) 2006 Michael Buesch <[email protected]> * Copyright (C) 2010 Waldemar Brodkorb <[email protected]> * Copyright (C) 2010-2012 Hauke Mehrtens <[email protected]> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * 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., * 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/bcm47xx_nvram.h> #include <linux/bcm47xx_sprom.h> #include <linux/bcma/bcma.h> #include <linux/etherdevice.h> #include <linux/if_ether.h> #include <linux/ssb/ssb.h> static void create_key(const char *prefix, const char *postfix, const char *name, char *buf, int len) { … } static int get_nvram_var(const char *prefix, const char *postfix, const char *name, char *buf, int len, bool fallback) { … } #define NVRAM_READ_VAL … NVRAM_READ_VAL NVRAM_READ_VAL NVRAM_READ_VAL NVRAM_READ_VAL #undef NVRAM_READ_VAL static void nvram_read_u32_2(const char *prefix, const char *name, u16 *val_lo, u16 *val_hi, bool fallback) { … } static void nvram_read_leddc(const char *prefix, const char *name, u8 *leddc_on_time, u8 *leddc_off_time, bool fallback) { … } static void nvram_read_macaddr(const char *prefix, const char *name, u8 val[6], bool fallback) { … } static void nvram_read_alpha2(const char *prefix, const char *name, char val[2], bool fallback) { … } /* This is one-function-only macro, it uses local "sprom" variable! */ #define ENTRY … /* * Special version of filling function that can be safely called for any SPROM * revision. For every NVRAM to SPROM mapping it contains bitmask of revisions * for which the mapping is valid. * It obviously requires some hexadecimal/bitmasks knowledge, but allows * writing cleaner code (easy revisions handling). * Note that while SPROM revision 0 was never used, we still keep BIT(0) * reserved for it, just to keep numbering sane. */ static void bcm47xx_sprom_fill_auto(struct ssb_sprom *sprom, const char *prefix, bool fallback) { … } #undef ENTRY /* It's specififc, uses local variable, don't use it (again). */ static void bcm47xx_fill_sprom_path_r4589(struct ssb_sprom *sprom, const char *prefix, bool fallback) { … } static void bcm47xx_fill_sprom_path_r45(struct ssb_sprom *sprom, const char *prefix, bool fallback) { … } static bool bcm47xx_is_valid_mac(u8 *mac) { … } static int bcm47xx_increase_mac_addr(u8 *mac, u8 num) { … } static int mac_addr_used = …; static void bcm47xx_fill_sprom_ethernet(struct ssb_sprom *sprom, const char *prefix, bool fallback) { … } static void bcm47xx_fill_board_data(struct ssb_sprom *sprom, const char *prefix, bool fallback) { … } void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix, bool fallback) { … } #if IS_BUILTIN(CONFIG_SSB) && IS_ENABLED(CONFIG_SSB_SPROM) static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out) { … } #endif #if IS_BUILTIN(CONFIG_BCMA) /* * Having many NVRAM entries for PCI devices led to repeating prefixes like * pci/1/1/ all the time and wasting flash space. So at some point Broadcom * decided to introduce prefixes like 0: 1: 2: etc. * If we find e.g. devpath0=pci/2/1 or devpath0=pci/2/1/ we should use 0: * instead of pci/2/1/. */ static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size) { … } static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) { … } #endif static unsigned int bcm47xx_sprom_registered; /* * On bcm47xx we need to register SPROM fallback handler very early, so we can't * use anything like platform device / driver for this. */ int bcm47xx_sprom_register_fallbacks(void) { … } fs_initcall(bcm47xx_sprom_register_fallbacks);