diff options
author | David S. Miller <davem@davemloft.net> | 2015-11-05 17:34:57 +0100 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-01-06 22:31:56 +0100 |
commit | c7f5d105495a38ed09e70d825f75d9d7d5407264 (patch) | |
tree | 2c111b9bb5bb557400914e31839f0d41b1018da3 /net/ethernet/eth.c | |
parent | net: move ndo_features_check() close to ndo_start_xmit() (diff) | |
download | linux-c7f5d105495a38ed09e70d825f75d9d7d5407264.tar.xz linux-c7f5d105495a38ed09e70d825f75d9d7d5407264.zip |
net: Add eth_platform_get_mac_address() helper.
A repeating pattern in drivers has become to use OF node information
and, if not found, platform specific host information to extract the
ethernet address for a given device.
Currently this is done with a call to of_get_mac_address() and then
some ifdef'd stuff for SPARC.
Consolidate this into a portable routine, and provide the
arch_get_platform_mac_address() weak function hook for all
architectures to implement if they want.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ethernet/eth.c')
-rw-r--r-- | net/ethernet/eth.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 9e63f252a89e..103871784e50 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -52,6 +52,8 @@ #include <linux/errno.h> #include <linux/init.h> #include <linux/if_ether.h> +#include <linux/of_net.h> +#include <linux/pci.h> #include <net/dst.h> #include <net/arp.h> #include <net/sock.h> @@ -485,3 +487,32 @@ static int __init eth_offload_init(void) } fs_initcall(eth_offload_init); + +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); |