Commit 37a0bc39 authored by David S. Miller's avatar David S. Miller

Merge branch 'davinci_emac-read-the-MAC-address-from-nvmem'

Bartosz Golaszewski says:

====================
davinci_emac: read the MAC address from nvmem

This series is part of a bigger series that aims at removing the platform
data structure from the at24 EEPROM driver[1].

We provide a generalized version of of_get_nvmem_mac_address(), switch the
only user of the of_ variant to using it, remove the previous
implementation and use the new routine in the davinci_emac driver.

[1] https://lkml.org/lkml/2018/11/13/884
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 82208d0d 18dbfc81
...@@ -4055,7 +4055,7 @@ static int macb_probe(struct platform_device *pdev) ...@@ -4055,7 +4055,7 @@ static int macb_probe(struct platform_device *pdev)
if (mac) { if (mac) {
ether_addr_copy(bp->dev->dev_addr, mac); ether_addr_copy(bp->dev->dev_addr, mac);
} else { } else {
err = of_get_nvmem_mac_address(np, bp->dev->dev_addr); err = nvmem_get_mac_address(&pdev->dev, bp->dev->dev_addr);
if (err) { if (err) {
if (err == -EPROBE_DEFER) if (err == -EPROBE_DEFER)
goto err_out_free_netdev; goto err_out_free_netdev;
......
...@@ -1912,11 +1912,15 @@ static int davinci_emac_probe(struct platform_device *pdev) ...@@ -1912,11 +1912,15 @@ static int davinci_emac_probe(struct platform_device *pdev)
ether_addr_copy(ndev->dev_addr, priv->mac_addr); ether_addr_copy(ndev->dev_addr, priv->mac_addr);
if (!is_valid_ether_addr(priv->mac_addr)) { if (!is_valid_ether_addr(priv->mac_addr)) {
/* Use random MAC if none passed */ /* Try nvmem if MAC wasn't passed over pdata or DT. */
eth_hw_addr_random(ndev); rc = nvmem_get_mac_address(&pdev->dev, priv->mac_addr);
memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len); if (rc) {
dev_warn(&pdev->dev, "using random MAC addr: %pM\n", /* Use random MAC if still none obtained. */
priv->mac_addr); eth_hw_addr_random(ndev);
memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len);
dev_warn(&pdev->dev, "using random MAC addr: %pM\n",
priv->mac_addr);
}
} }
ndev->netdev_ops = &emac_netdev_ops; ndev->netdev_ops = &emac_netdev_ops;
......
...@@ -81,42 +81,3 @@ const void *of_get_mac_address(struct device_node *np) ...@@ -81,42 +81,3 @@ const void *of_get_mac_address(struct device_node *np)
return of_get_mac_addr(np, "address"); return of_get_mac_addr(np, "address");
} }
EXPORT_SYMBOL(of_get_mac_address); EXPORT_SYMBOL(of_get_mac_address);
/**
* Obtain the MAC address from an nvmem provider named 'mac-address' through
* device tree.
* On success, copies the new address into memory pointed to by addr and
* returns 0. Returns a negative error code otherwise.
* @np: Device tree node containing the nvmem-cells phandle
* @addr: Pointer to receive the MAC address using ether_addr_copy()
*/
int of_get_nvmem_mac_address(struct device_node *np, void *addr)
{
struct nvmem_cell *cell;
const void *mac;
size_t len;
int ret;
cell = of_nvmem_cell_get(np, "mac-address");
if (IS_ERR(cell))
return PTR_ERR(cell);
mac = nvmem_cell_read(cell, &len);
nvmem_cell_put(cell);
if (IS_ERR(mac))
return PTR_ERR(mac);
if (len < ETH_ALEN || !is_valid_ether_addr(mac)) {
ret = -EINVAL;
} else {
ether_addr_copy(addr, mac);
ret = 0;
}
kfree(mac);
return ret;
}
EXPORT_SYMBOL(of_get_nvmem_mac_address);
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
struct device; struct device;
int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr); int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr);
unsigned char *arch_get_platform_mac_address(void); unsigned char *arch_get_platform_mac_address(void);
int nvmem_get_mac_address(struct device *dev, void *addrbuf);
u32 eth_get_headlen(void *data, unsigned int max_len); u32 eth_get_headlen(void *data, unsigned int max_len);
__be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev);
extern const struct header_ops eth_header_ops; extern const struct header_ops eth_header_ops;
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
struct net_device; struct net_device;
extern int of_get_phy_mode(struct device_node *np); extern int of_get_phy_mode(struct device_node *np);
extern const void *of_get_mac_address(struct device_node *np); extern const void *of_get_mac_address(struct device_node *np);
extern int of_get_nvmem_mac_address(struct device_node *np, void *addr);
extern struct net_device *of_find_net_device_by_node(struct device_node *np); extern struct net_device *of_find_net_device_by_node(struct device_node *np);
#else #else
static inline int of_get_phy_mode(struct device_node *np) static inline int of_get_phy_mode(struct device_node *np)
...@@ -26,11 +25,6 @@ static inline const void *of_get_mac_address(struct device_node *np) ...@@ -26,11 +25,6 @@ static inline const void *of_get_mac_address(struct device_node *np)
return NULL; return NULL;
} }
static inline int of_get_nvmem_mac_address(struct device_node *np, void *addr)
{
return -ENODEV;
}
static inline struct net_device *of_find_net_device_by_node(struct device_node *np) static inline struct net_device *of_find_net_device_by_node(struct device_node *np)
{ {
return NULL; return NULL;
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <linux/inet.h> #include <linux/inet.h>
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/nvmem-consumer.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -550,3 +551,40 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) ...@@ -550,3 +551,40 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
return 0; return 0;
} }
EXPORT_SYMBOL(eth_platform_get_mac_address); EXPORT_SYMBOL(eth_platform_get_mac_address);
/**
* Obtain the MAC address from an nvmem cell named 'mac-address' associated
* with given device.
*
* @dev: Device with which the mac-address cell is associated.
* @addrbuf: Buffer to which the MAC address will be copied on success.
*
* Returns 0 on success or a negative error number on failure.
*/
int nvmem_get_mac_address(struct device *dev, void *addrbuf)
{
struct nvmem_cell *cell;
const void *mac;
size_t len;
cell = nvmem_cell_get(dev, "mac-address");
if (IS_ERR(cell))
return PTR_ERR(cell);
mac = nvmem_cell_read(cell, &len);
nvmem_cell_put(cell);
if (IS_ERR(mac))
return PTR_ERR(mac);
if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
kfree(mac);
return -EINVAL;
}
ether_addr_copy(addrbuf, mac);
kfree(mac);
return 0;
}
EXPORT_SYMBOL(nvmem_get_mac_address);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment