From: Joe Perches <joe@perches.com>
To: David Miller <davem@davemloft.net>, netdev@vger.kernel.org
Cc: sowmini.varadhan@oracle.com
Subject: Re: [PATCH v2] net: Add eth_platform_get_mac_address() helper.
Date: Wed, 06 Jan 2016 15:12:46 -0800 [thread overview]
Message-ID: <1452121966.24575.52.camel@perches.com> (raw)
In-Reply-To: <20160106.163309.111867454969344145.davem@davemloft.net>
On Wed, 2016-01-06 at 16:33 -0500, David Miller wrote:
> 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.
[]
> diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.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;
WARN_ON_ONCE ?
> +}
> +
> +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);
Couldn't some oddball arch have an unaligned addr?
next prev parent reply other threads:[~2016-01-06 23:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-06 21:33 [PATCH v2] net: Add eth_platform_get_mac_address() helper David Miller
2016-01-06 21:45 ` Sowmini Varadhan
2016-01-06 23:12 ` Joe Perches [this message]
2016-01-06 23:26 ` Bjørn Mork
2016-01-06 23:32 ` Joe Perches
2016-01-06 23:41 ` Bjørn Mork
2016-01-07 0:01 ` David Miller
2016-01-07 0:02 ` Joe Perches
2016-01-13 0:49 ` Sowmini Varadhan
2016-01-13 0:59 ` Kirsher, Jeffrey T
2016-01-13 2:40 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452121966.24575.52.camel@perches.com \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=sowmini.varadhan@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).