Skip to content

Commit

Permalink
Disallow resetting to the default mac after kexec (sonic-net#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
byu343 authored and lguohan committed Aug 16, 2017
1 parent a97c5e4 commit 3f60bb5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
75 changes: 75 additions & 0 deletions patch/driver-arista-net-tg3-disallow-broadcom-default-mac.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
For Arista platforms, after calling kexec in fast-reboot, the MAC address
of management interface is reset to 00:10:18:00:00:00. This patch can recover
the MAC with the one previously saved by Arista Aboot.

Index: linux-3.16/drivers/net/ethernet/broadcom/tg3.c
===================================================================
--- linux-3.16.orig/drivers/net/ethernet/broadcom/tg3.c
+++ linux-3.16/drivers/net/ethernet/broadcom/tg3.c
@@ -9329,6 +9329,15 @@ static int tg3_halt(struct tg3 *tp, int
return err;
}

+static inline int is_valid_bcm_ether_addr(const u8 *addr)
+{
+ if (!is_valid_ether_addr(addr))
+ return 0;
+ /* Disallow Broadcom default MAC 00:10:18:00:00:00 to avoid conflicts */
+ return (addr[0] || addr[1] != 0x10 || addr[2] != 0x18 ||
+ addr[3] || addr[4] || addr[5]);
+}
+
static int tg3_set_mac_addr(struct net_device *dev, void *p)
{
struct tg3 *tp = netdev_priv(dev);
@@ -9336,7 +9345,7 @@ static int tg3_set_mac_addr(struct net_d
int err = 0;
bool skip_mac_1 = false;

- if (!is_valid_ether_addr(addr->sa_data))
+ if (!is_valid_bcm_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;

memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
@@ -16990,31 +16999,21 @@ static int tg3_get_device_address(struct
dev->dev_addr[5] = (lo >> 0) & 0xff;

/* Some old bootcode may report a 0 MAC address in SRAM */
- addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
+ addr_ok = is_valid_bcm_ether_addr(&dev->dev_addr[0]);
}
if (!addr_ok) {
- /* Next, try NVRAM. */
- if (!tg3_flag(tp, NO_NVRAM) &&
- !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) &&
- !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) {
- memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2);
- memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo));
- }
- /* Finally just fetch it out of the MAC control regs. */
- else {
- hi = tr32(MAC_ADDR_0_HIGH);
- lo = tr32(MAC_ADDR_0_LOW);
+ hi = tr32(MAC_ADDR_0_HIGH);
+ lo = tr32(MAC_ADDR_0_LOW);

- dev->dev_addr[5] = lo & 0xff;
- dev->dev_addr[4] = (lo >> 8) & 0xff;
- dev->dev_addr[3] = (lo >> 16) & 0xff;
- dev->dev_addr[2] = (lo >> 24) & 0xff;
- dev->dev_addr[1] = hi & 0xff;
- dev->dev_addr[0] = (hi >> 8) & 0xff;
- }
+ dev->dev_addr[5] = lo & 0xff;
+ dev->dev_addr[4] = (lo >> 8) & 0xff;
+ dev->dev_addr[3] = (lo >> 16) & 0xff;
+ dev->dev_addr[2] = (lo >> 24) & 0xff;
+ dev->dev_addr[1] = hi & 0xff;
+ dev->dev_addr[0] = (hi >> 8) & 0xff;
}

- if (!is_valid_ether_addr(&dev->dev_addr[0])) {
+ if (!is_valid_bcm_ether_addr(&dev->dev_addr[0])) {
#ifdef CONFIG_SPARC
if (!tg3_get_default_macaddr_sparc(tp))
return 0;
1 change: 1 addition & 0 deletions patch/series
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ driver-hwmon-pmbus-ucd9200-mlnx.patch
driver-arista-piix4-mux-patch.patch
driver-arista-net-tg3-dma-mask-4g-sb800.patch
driver-arista-net-tg3-access-regs-indirectly.patch
driver-arista-net-tg3-disallow-broadcom-default-mac.patch
driver-pca954x-i2c-mux-force-deselect-on-exit-flag.patch
linux-3.19-mmc-sdhci-Add-a-quirk-for-AMD-SDHC-transfer-mode-reg.patch
linux-3.19-mmc-sdhci-pci-enable-the-clear-transfer-mode-registe.patch
Expand Down

0 comments on commit 3f60bb5

Please sign in to comment.