All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] net: usb: asix: allow optionally getting mac address from device tree
@ 2018-07-03 15:06 ` Marcel Ziswiler
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Ziswiler @ 2018-07-03 15:06 UTC (permalink / raw)
  To: netdev
  Cc: Oliver Neukum, Marcel Ziswiler, linux-usb, David S. Miller,
	Dean Jenkins, linux-kernel, Andrey Konovalov

From: Marcel Ziswiler <marcel.ziswiler@toradex.com>

For Embedded use where e.g. AX88772B chips may be used without external
EEPROMs the boot loader may choose to pass the MAC address to be used
via device tree. Therefore, allow for optionally getting the MAC
address from device tree data e.g. as follows (excerpt from a T30 based
board, local-mac-address to be filled in by boot loader):

/* EHCI instance 1: USB2_DP/N -> AX88772B */
usb@7d004000 {
	status = "okay";
	#address-cells = <1>;
	#size-cells = <0>;
	asix@1 {
		reg = <1>;
		local-mac-address = [00 00 00 00 00 00];
	};
};

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

---

Changes in v2:
- Use eth_platform_get_mac_address() as suggested by Andrew.

 drivers/net/usb/asix_devices.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 3d4f7959dabb..8f41c6bda8e5 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -691,24 +691,32 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 	u32 phyid;
 	struct asix_common_private *priv;
 
-	usbnet_get_endpoints(dev,intf);
+	usbnet_get_endpoints(dev, intf);
 
-	/* Get the MAC address */
-	if (dev->driver_info->data & FLAG_EEPROM_MAC) {
-		for (i = 0; i < (ETH_ALEN >> 1); i++) {
-			ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x04 + i,
-					    0, 2, buf + i * 2, 0);
-			if (ret < 0)
-				break;
-		}
+	/* Maybe the boot loader passed the MAC address via device tree */
+	if (!eth_platform_get_mac_address(&dev->udev->dev, buf)) {
+		netif_dbg(dev, ifup, dev->net,
+			  "MAC address read from device tree");
 	} else {
-		ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
-				0, 0, ETH_ALEN, buf, 0);
-	}
+		/* Try getting the MAC address from EEPROM */
+		if (dev->driver_info->data & FLAG_EEPROM_MAC) {
+			for (i = 0; i < (ETH_ALEN >> 1); i++) {
+				ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM,
+						    0x04 + i, 0, 2, buf + i * 2,
+						    0);
+				if (ret < 0)
+					break;
+			}
+		} else {
+			ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
+					    0, 0, ETH_ALEN, buf, 0);
+		}
 
-	if (ret < 0) {
-		netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
-		return ret;
+		if (ret < 0) {
+			netdev_dbg(dev->net, "Failed to read MAC address: %d\n",
+				   ret);
+			return ret;
+		}
 	}
 
 	asix_set_netdev_dev_addr(dev, buf);
-- 
2.14.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [v2] net: usb: asix: allow optionally getting mac address from device tree
@ 2018-07-03 15:06 ` Marcel Ziswiler
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Ziswiler @ 2018-07-03 15:06 UTC (permalink / raw)
  To: netdev
  Cc: Oliver Neukum, Marcel Ziswiler, linux-usb, David S. Miller,
	Dean Jenkins, linux-kernel, Andrey Konovalov

From: Marcel Ziswiler <marcel.ziswiler@toradex.com>

For Embedded use where e.g. AX88772B chips may be used without external
EEPROMs the boot loader may choose to pass the MAC address to be used
via device tree. Therefore, allow for optionally getting the MAC
address from device tree data e.g. as follows (excerpt from a T30 based
board, local-mac-address to be filled in by boot loader):

/* EHCI instance 1: USB2_DP/N -> AX88772B */
usb@7d004000 {
	status = "okay";
	#address-cells = <1>;
	#size-cells = <0>;
	asix@1 {
		reg = <1>;
		local-mac-address = [00 00 00 00 00 00];
	};
};

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
---

Changes in v2:
- Use eth_platform_get_mac_address() as suggested by Andrew.

 drivers/net/usb/asix_devices.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 3d4f7959dabb..8f41c6bda8e5 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -691,24 +691,32 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 	u32 phyid;
 	struct asix_common_private *priv;
 
-	usbnet_get_endpoints(dev,intf);
+	usbnet_get_endpoints(dev, intf);
 
-	/* Get the MAC address */
-	if (dev->driver_info->data & FLAG_EEPROM_MAC) {
-		for (i = 0; i < (ETH_ALEN >> 1); i++) {
-			ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x04 + i,
-					    0, 2, buf + i * 2, 0);
-			if (ret < 0)
-				break;
-		}
+	/* Maybe the boot loader passed the MAC address via device tree */
+	if (!eth_platform_get_mac_address(&dev->udev->dev, buf)) {
+		netif_dbg(dev, ifup, dev->net,
+			  "MAC address read from device tree");
 	} else {
-		ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
-				0, 0, ETH_ALEN, buf, 0);
-	}
+		/* Try getting the MAC address from EEPROM */
+		if (dev->driver_info->data & FLAG_EEPROM_MAC) {
+			for (i = 0; i < (ETH_ALEN >> 1); i++) {
+				ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM,
+						    0x04 + i, 0, 2, buf + i * 2,
+						    0);
+				if (ret < 0)
+					break;
+			}
+		} else {
+			ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
+					    0, 0, ETH_ALEN, buf, 0);
+		}
 
-	if (ret < 0) {
-		netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
-		return ret;
+		if (ret < 0) {
+			netdev_dbg(dev->net, "Failed to read MAC address: %d\n",
+				   ret);
+			return ret;
+		}
 	}
 
 	asix_set_netdev_dev_addr(dev, buf);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] net: usb: asix: allow optionally getting mac address from device tree
@ 2018-07-04 13:10   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-07-04 13:10 UTC (permalink / raw)
  To: marcel
  Cc: netdev, oneukum, marcel.ziswiler, linux-usb, Dean_Jenkins,
	linux-kernel, andreyknvl

From: Marcel Ziswiler <marcel@ziswiler.com>
Date: Tue,  3 Jul 2018 17:06:49 +0200

> From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> 
> For Embedded use where e.g. AX88772B chips may be used without external
> EEPROMs the boot loader may choose to pass the MAC address to be used
> via device tree. Therefore, allow for optionally getting the MAC
> address from device tree data e.g. as follows (excerpt from a T30 based
> board, local-mac-address to be filled in by boot loader):
> 
> /* EHCI instance 1: USB2_DP/N -> AX88772B */
> usb@7d004000 {
> 	status = "okay";
> 	#address-cells = <1>;
> 	#size-cells = <0>;
> 	asix@1 {
> 		reg = <1>;
> 		local-mac-address = [00 00 00 00 00 00];
> 	};
> };
> 
> Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

Applied to net-next.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [v2] net: usb: asix: allow optionally getting mac address from device tree
@ 2018-07-04 13:10   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-07-04 13:10 UTC (permalink / raw)
  To: marcel
  Cc: netdev, oneukum, marcel.ziswiler, linux-usb, Dean_Jenkins,
	linux-kernel, andreyknvl

From: Marcel Ziswiler <marcel@ziswiler.com>
Date: Tue,  3 Jul 2018 17:06:49 +0200

> From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> 
> For Embedded use where e.g. AX88772B chips may be used without external
> EEPROMs the boot loader may choose to pass the MAC address to be used
> via device tree. Therefore, allow for optionally getting the MAC
> address from device tree data e.g. as follows (excerpt from a T30 based
> board, local-mac-address to be filled in by boot loader):
> 
> /* EHCI instance 1: USB2_DP/N -> AX88772B */
> usb@7d004000 {
> 	status = "okay";
> 	#address-cells = <1>;
> 	#size-cells = <0>;
> 	asix@1 {
> 		reg = <1>;
> 		local-mac-address = [00 00 00 00 00 00];
> 	};
> };
> 
> Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

Applied to net-next.
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-04 13:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-03 15:06 [PATCH v2] net: usb: asix: allow optionally getting mac address from device tree Marcel Ziswiler
2018-07-03 15:06 ` [v2] " Marcel Ziswiler
2018-07-04 13:10 ` [PATCH v2] " David Miller
2018-07-04 13:10   ` [v2] " David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.