From: John Holland Date: Thu, 18 Feb 2016 11:10:52 +0000 (+0100) Subject: igb: allow setting MAC address on i211 using a device tree blob X-Git-Tag: v4.1.12-105.0.20170622_2100~60 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f7f6362f9370630c54212dceb86e37e717971662;p=users%2Fjedix%2Flinux-maple.git igb: allow setting MAC address on i211 using a device tree blob The Intel i211 LOM PCIe Ethernet controllers' iNVM operates as an OTP and has no external EEPROM interface [1]. The following allows the driver to pickup the MAC address from a device tree blob when CONFIG_OF has been enabled. [1] http://www.intel.com/content/www/us/en/embedded/products/networking/i211-ethernet-controller-datasheet.html Signed-off-by: John Holland Tested-by: Aaron Brown Signed-off-by: Jeff Kirsher (cherry picked from commit 806ffb1d504927d1449397377eac63bb63489266) Orabug: 26325580 Signed-off-by: Kirtikar Kashyap Reviewed-by: Jack Vogel --- diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 4b72f3b91a83..2c1ef48d6a38 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -50,6 +50,7 @@ #include #include #include +#include "kcompat.h" #ifdef CONFIG_IGB_DCA #include #endif @@ -2442,9 +2443,11 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) break; } - /* copy the MAC address out of the NVM */ - if (hw->mac.ops.read_mac_addr(hw)) - dev_err(&pdev->dev, "NVM Read Error\n"); + if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) { + /* copy the MAC address out of the NVM */ + if (hw->mac.ops.read_mac_addr(hw)) + dev_err(&pdev->dev, "NVM Read Error\n"); + } memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len); diff --git a/drivers/net/ethernet/intel/igb/kcompat.h b/drivers/net/ethernet/intel/igb/kcompat.h new file mode 100644 index 000000000000..63520fc7bb10 --- /dev/null +++ b/drivers/net/ethernet/intel/igb/kcompat.h @@ -0,0 +1,41 @@ +#ifndef _KCOMPAT_H_ +#define _KCOMPAT_H_ + +#include +#include + +#endif + + +#ifdef __KERNEL__ + +unsigned char * __weak arch_get_platform_mac_address(void) +{ + return NULL; +} + +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) +{ + const unsigned char *addr; + struct device_node *dp; + + if (dev_is_pci(dev)) + dp = pci_device_to_OF_node(to_pci_dev(dev)); + else + dp = dev->of_node; + + addr = NULL; + if (dp) + addr = of_get_mac_address(dp); + if (!addr) + addr = arch_get_platform_mac_address(); + + if (!addr) + return -ENODEV; + + ether_addr_copy(mac_addr, addr); + return 0; +} +EXPORT_SYMBOL(eth_platform_get_mac_address); + +#endif