Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4055,7 +4055,7 @@ static int macb_probe(struct platform_device *pdev)
	if (mac) {
		ether_addr_copy(bp->dev->dev_addr, mac);
	} 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 == -EPROBE_DEFER)
				goto err_out_free_netdev;
+9 −5
Original line number Diff line number Diff line
@@ -1912,12 +1912,16 @@ static int davinci_emac_probe(struct platform_device *pdev)
		ether_addr_copy(ndev->dev_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. */
		rc = nvmem_get_mac_address(&pdev->dev, priv->mac_addr);
		if (rc) {
			/* Use random MAC if still none obtained. */
			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->ethtool_ops = &ethtool_ops;
+0 −39
Original line number Diff line number Diff line
@@ -81,42 +81,3 @@ const void *of_get_mac_address(struct device_node *np)
	return of_get_mac_addr(np, "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);
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
struct device;
int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr);
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);
__be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev);
extern const struct header_ops eth_header_ops;
+0 −6
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
struct net_device;
extern int of_get_phy_mode(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);
#else
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)
	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)
{
	return NULL;
Loading