aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2014-07-28 18:08:01 -0400
committerRalf Baechle <ralf@linux-mips.org>2014-07-30 13:25:15 -0400
commit103c0bf3ff46486466bc9138d70c25133d516003 (patch)
tree56f1a2d28257a5a33c4845627e4003301227b41f /arch
parent316cad5c1d4daee998cd1f83ccdb437f6f20d45c (diff)
MIPS: BCM47XX: fixup broken MAC addresses in nvram
The address prefix 00:90:4C is used by Broadcom in their initial configuration. When a mac address with the prefix 00:90:4C is used all devices from the same series are sharing the same mac address. To prevent mac address collisions we replace them with a mac address based on the base address. To generate such addresses we take the main mac address from et0macaddr and increase it by two for the first wifi device and by 3 for the second one. This matches the printed mac address on the device. The main mac address increased by one is used as wan address by the vendor code. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> Cc: zajec5@gmail.com Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/7489/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/bcm47xx/sprom.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/arch/mips/bcm47xx/sprom.c b/arch/mips/bcm47xx/sprom.c
index da4cdb16844e..41226b68de3d 100644
--- a/arch/mips/bcm47xx/sprom.c
+++ b/arch/mips/bcm47xx/sprom.c
@@ -28,6 +28,8 @@
28 28
29#include <bcm47xx.h> 29#include <bcm47xx.h>
30#include <bcm47xx_nvram.h> 30#include <bcm47xx_nvram.h>
31#include <linux/if_ether.h>
32#include <linux/etherdevice.h>
31 33
32static void create_key(const char *prefix, const char *postfix, 34static void create_key(const char *prefix, const char *postfix,
33 const char *name, char *buf, int len) 35 const char *name, char *buf, int len)
@@ -631,6 +633,33 @@ static void bcm47xx_fill_sprom_path_r45(struct ssb_sprom *sprom,
631 } 633 }
632} 634}
633 635
636static bool bcm47xx_is_valid_mac(u8 *mac)
637{
638 return mac && !(mac[0] == 0x00 && mac[1] == 0x90 && mac[2] == 0x4c);
639}
640
641static int bcm47xx_increase_mac_addr(u8 *mac, u8 num)
642{
643 u8 *oui = mac + ETH_ALEN/2 - 1;
644 u8 *p = mac + ETH_ALEN - 1;
645
646 do {
647 (*p) += num;
648 if (*p > num)
649 break;
650 p--;
651 num = 1;
652 } while (p != oui);
653
654 if (p == oui) {
655 pr_err("unable to fetch mac address\n");
656 return -ENOENT;
657 }
658 return 0;
659}
660
661static int mac_addr_used = 2;
662
634static void bcm47xx_fill_sprom_ethernet(struct ssb_sprom *sprom, 663static void bcm47xx_fill_sprom_ethernet(struct ssb_sprom *sprom,
635 const char *prefix, bool fallback) 664 const char *prefix, bool fallback)
636{ 665{
@@ -648,6 +677,25 @@ static void bcm47xx_fill_sprom_ethernet(struct ssb_sprom *sprom,
648 677
649 nvram_read_macaddr(prefix, "macaddr", sprom->il0mac, fallback); 678 nvram_read_macaddr(prefix, "macaddr", sprom->il0mac, fallback);
650 nvram_read_macaddr(prefix, "il0macaddr", sprom->il0mac, fallback); 679 nvram_read_macaddr(prefix, "il0macaddr", sprom->il0mac, fallback);
680
681 /* The address prefix 00:90:4C is used by Broadcom in their initial
682 configuration. When a mac address with the prefix 00:90:4C is used
683 all devices from the same series are sharing the same mac address.
684 To prevent mac address collisions we replace them with a mac address
685 based on the base address. */
686 if (!bcm47xx_is_valid_mac(sprom->il0mac)) {
687 u8 mac[6];
688
689 nvram_read_macaddr(NULL, "et0macaddr", mac, false);
690 if (bcm47xx_is_valid_mac(mac)) {
691 int err = bcm47xx_increase_mac_addr(mac, mac_addr_used);
692
693 if (!err) {
694 ether_addr_copy(sprom->il0mac, mac);
695 mac_addr_used++;
696 }
697 }
698 }
651} 699}
652 700
653static void bcm47xx_fill_board_data(struct ssb_sprom *sprom, const char *prefix, 701static void bcm47xx_fill_board_data(struct ssb_sprom *sprom, const char *prefix,