Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162326AbbKESNY (ORCPT ); Thu, 5 Nov 2015 13:13:24 -0500 Received: from mail-yk0-f174.google.com ([209.85.160.174]:35877 "EHLO mail-yk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964961AbbKESNW (ORCPT ); Thu, 5 Nov 2015 13:13:22 -0500 MIME-Version: 1.0 In-Reply-To: <20151105.110506.1901401372160830603.davem@davemloft.net> References: <20151104232100.GJ14575@oracle.com> <20151105.103126.148818796422971143.davem@davemloft.net> <20151105.110506.1901401372160830603.davem@davemloft.net> Date: Thu, 5 Nov 2015 20:13:21 +0200 Message-ID: Subject: Re: [PATCH v6] i40e: Look up MAC address in Open Firmware or IDPROM From: Andy Shevchenko To: David Miller Cc: Sowmini Varadhan , intel-wired-lan@lists.osuosl.org, netdev , "linux-kernel@vger.kernel.org" , "Kirsher, Jeffrey T" , "Brandeburg, Jesse" , "Nelson, Shannon" , "Wyborny, Carolyn" , "Skidmore, Donald C" , "Vick, Matthew" , "Ronciak, John" , "Williams, Mitch A" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3849 Lines: 135 On Thu, Nov 5, 2015 at 6:05 PM, David Miller wrote: > From: David Miller > Date: Thu, 05 Nov 2015 10:31:26 -0500 (EST) > >> I'll see if I can cook something up. > > How does this look? I like it, though couple of style related comments. > > ==================== > 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_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 > > diff --git a/arch/sparc/kernel/idprom.c b/arch/sparc/kernel/idprom.c > index 6bd7501..f95dd11 100644 > --- a/arch/sparc/kernel/idprom.c > +++ b/arch/sparc/kernel/idprom.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -60,6 +61,12 @@ static void __init display_system_type(unsigned char machtype) > { > } > #endif > + > +unsigned char *arch_get_platform_mac_address(void) > +{ > + return idprom->id_ethaddr; > +} > + > /* Calculate the IDPROM checksum (xor of the data bytes). */ > static unsigned char __init calc_idprom_cksum(struct idprom *idprom) > { > diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h > index eb049c6..37ff4a6 100644 > --- a/include/linux/etherdevice.h > +++ b/include/linux/etherdevice.h > @@ -29,6 +29,9 @@ > #include > > #ifdef __KERNEL__ > +struct device; > +int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr); > +unsigned char *arch_get_platform_get_mac_address(void); > u32 eth_get_headlen(void *data, unsigned int max_len); > __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); > extern const struct header_ops eth_header_ops; > diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c > index 9e63f25..1cb9204f 100644 > --- a/net/ethernet/eth.c > +++ b/net/ethernet/eth.c > @@ -52,6 +52,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -485,3 +487,33 @@ 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; Maybe we can use definition block for this assignment? > + if (dp) > + addr = of_get_mac_address(dp); > + if (!addr) > + addr = arch_get_platform_mac_address(); > + > + if (addr) { What about if (!addr) return -ENODATA; (Yes, ENODATA looks suitable for me) > + ether_addr_copy(mac_addr, addr); > + return 0; > + } > + > + return -ENODEV; > +} > +EXPORT_SYMBOL(eth_platform_get_mac_address); -- With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/