]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
igb: allow setting MAC address on i211 using a device tree blob
authorJohn Holland <jotihojr@gmail.com>
Thu, 18 Feb 2016 11:10:52 +0000 (12:10 +0100)
committerKirtikar Kashyap <kirtikar.kashyap@oracle.com>
Thu, 22 Jun 2017 21:28:30 +0000 (14:28 -0700)
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 <jotihojr@gmail.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
(cherry picked from commit 806ffb1d504927d1449397377eac63bb63489266)

Orabug: 26325580

Signed-off-by: Kirtikar Kashyap <kirtikar.kashyap@oracle.com>
Reviewed-by: Jack Vogel <jack.vogel@oracle.com>
drivers/net/ethernet/intel/igb/igb_main.c
drivers/net/ethernet/intel/igb/kcompat.h [new file with mode: 0644]

index 4b72f3b91a8370b14e49d3256d83f2d0925dc021..2c1ef48d6a38cd930a034dfa057daf58a6257900 100644 (file)
@@ -50,6 +50,7 @@
 #include <linux/aer.h>
 #include <linux/prefetch.h>
 #include <linux/pm_runtime.h>
+#include "kcompat.h"
 #ifdef CONFIG_IGB_DCA
 #include <linux/dca.h>
 #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 (file)
index 0000000..63520fc
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _KCOMPAT_H_
+#define _KCOMPAT_H_
+
+#include <linux/of_net.h>
+#include <linux/pci.h>
+
+#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