Skip to contentSkip to conversation

usbnet: smsc95xx: Add device tree input for MAC address

PATCH In review Dan Murphy 2 participants 9 messages Oct 4, 2013 – Oct 11, 2013

Subsystems (5)
lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

PATCH 1/1 usbnet: smsc95xx: Add device tree input for MAC address

If the smsc95xx does not have a valid MAC address stored within the eeprom then a random number is generated. The MAC can also be set by uBoot but the smsc95xx does not have a way to read this.

Create the binding for the smsc95xx so that uBoot can set the MAC and the code can retrieve the MAC from the modified DTB file.

---
 Documentation/devicetree/bindings/net/smsc95xx.txt |   17 ++++++++++++++
 drivers/net/usb/smsc95xx.c                         |   24 ++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc95xx.txt
Documentation/devicetree/bindings/net/smsc95xx.txt new file +17 -0
new file mode 100644
index 0000000..4c37280
@@ -0,0 +1,17 @@
+* Smart Mixed-Signal Connectivity (SMSC) 95xx Controller
+
+Required properties:
+None
+
+Optional properties:
+- mac-address - Read the mac address that was stored by uBoot
+- local-address - Read the mac address that was stored by uBoot
+- address - Read the mac address that was stored by uBoot
+
+Examples:
+
+smsc0: smsc95xx@0 {
+	/* Filled in by U-Boot */
+	mac-address = [ 00 00 00 00 00 00 ];
+};
+
drivers/net/usb/smsc95xx.c +24 -0
index 3f38ba8..baee0bd 100644
@@ -31,6 +31,9 @@
 #include <linux/crc32.h>
 #include <linux/usb/usbnet.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
+
 #include "smsc95xx.h"
 
 #define SMSC_CHIPNAME			"smsc95xx"
@@ -62,6 +65,8 @@
 #define SUSPEND_ALLMODES		(SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
 					 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
 
+#define SMSC95XX_OF_NAME 	"/smsc95xx@"
+
 struct smsc95xx_priv {
 	u32 mac_cr;
 	u32 hash_hi;
@@ -767,6 +772,25 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
 
 static void smsc95xx_init_mac_address(struct usbnet *dev)
 {
+
+#ifdef CONFIG_OF
+	struct device_node *ap;
+	const char *mac = NULL;
+	char *of_name = SMSC95XX_OF_NAME;
+
+	sprintf(of_name, "%s%i", SMSC95XX_OF_NAME, dev->udev->dev.id);
+	ap = of_find_node_by_path(of_name);
+	if (ap) {
+		mac = of_get_mac_address(ap);
+		if (is_valid_ether_addr(mac)) {
+			/* Device tree has a mac for this so use that */
+			memcpy(dev->net->dev_addr, mac, ETH_ALEN);
+			netif_dbg(dev, ifup, dev->net, "MAC address read from DTB\n");
+			return;
+		}
+	}
+#endif
+
 	/* try reading mac address from EEPROM */
 	if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
 			dev->net->dev_addr) == 0) {
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 6 lines · Dan Murphy

If the smsc95xx does not have a valid MAC address stored within the eeprom then a random number is generated. The MAC can also be set by uBoot but the smsc95xx does not have a way to read this.

Create the binding for the smsc95xx so that uBoot can set the MAC and the code can retrieve the MAC from the modified DTB file.

Suppose there are two smsc95xx usbnet devices connected to usb bus, and one is built-in, another is hotplug device, can your patch handle the situation correctly?

Quoted 83 lines
---
 Documentation/devicetree/bindings/net/smsc95xx.txt |   17 ++++++++++++++
 drivers/net/usb/smsc95xx.c                         |   24 ++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc95xx.txt
Documentation/devicetree/bindings/net/smsc95xx.txt new file +17 -0
new file mode 100644
index 0000000..4c37280
@@ -0,0 +1,17 @@
+* Smart Mixed-Signal Connectivity (SMSC) 95xx Controller
+
+Required properties:
+None
+
+Optional properties:
+- mac-address - Read the mac address that was stored by uBoot
+- local-address - Read the mac address that was stored by uBoot
+- address - Read the mac address that was stored by uBoot
+
+Examples:
+
+smsc0: smsc95xx@0 {
+       /* Filled in by U-Boot */
+       mac-address = [ 00 00 00 00 00 00 ];
+};
+
drivers/net/usb/smsc95xx.c +24 -1
index 3f38ba8..baee0bd 100644
@@ -31,6 +31,9 @@
 #include <linux/crc32.h>
 #include <linux/usb/usbnet.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
+
 #include "smsc95xx.h"
 
 #define SMSC_CHIPNAME                  "smsc95xx"
@@ -62,6 +65,8 @@
 #define SUSPEND_ALLMODES               (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
                                         SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
 
+#define SMSC95XX_OF_NAME       "/smsc95xx@"
+
 struct smsc95xx_priv {
        u32 mac_cr;
        u32 hash_hi;
@@ -767,6 +772,25 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
 
 static void smsc95xx_init_mac_address(struct usbnet *dev)
 {
+
+#ifdef CONFIG_OF
+       struct device_node *ap;
+       const char *mac = NULL;
+       char *of_name = SMSC95XX_OF_NAME;
+
+       sprintf(of_name, "%s%i", SMSC95XX_OF_NAME, dev->udev->dev.id);
+       ap = of_find_node_by_path(of_name);
+       if (ap) {
+               mac = of_get_mac_address(ap);
+               if (is_valid_ether_addr(mac)) {
+                       /* Device tree has a mac for this so use that */
+                       memcpy(dev->net->dev_addr, mac, ETH_ALEN);
+                       netif_dbg(dev, ifup, dev->net, "MAC address read from DTB\n");
+                       return;
+               }
+       }
+#endif
+
        /* try reading mac address from EEPROM */
        if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
                        dev->net->dev_addr) == 0) {
--

1.7.9.5

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Thanks,

Signature · 1 line
Ming Lei
author
#2 lore raw
Quoted 10 lines · Ming Lei
Quoted 6 lines · Dan Murphy

If the smsc95xx does not have a valid MAC address stored within the eeprom then a random number is generated. The MAC can also be set by uBoot but the smsc95xx does not have a way to read this.

Create the binding for the smsc95xx so that uBoot can set the MAC and the code can retrieve the MAC from the modified DTB file.

Suppose there are two smsc95xx usbnet devices connected to usb bus, and one is built-in, another is hotplug device, can your patch handle the situation correctly?

Look at this line in the patch below

sprintf(of_name, "%s%i", SMSC95XX_OF_NAME, dev->udev->dev.id);

I am appending the dev ID of the device to the of_name here. As long as init_mac_address is called, the dev.id and the uBoot entry match then yes.

Quoted 89 lines
Quoted 82 lines
---
 Documentation/devicetree/bindings/net/smsc95xx.txt |   17 ++++++++++++++
 drivers/net/usb/smsc95xx.c                         |   24 ++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc95xx.txt
Documentation/devicetree/bindings/net/smsc95xx.txt new file +17 -0
new file mode 100644
index 0000000..4c37280
@@ -0,0 +1,17 @@
+* Smart Mixed-Signal Connectivity (SMSC) 95xx Controller
+
+Required properties:
+None
+
+Optional properties:
+- mac-address - Read the mac address that was stored by uBoot
+- local-address - Read the mac address that was stored by uBoot
+- address - Read the mac address that was stored by uBoot
+
+Examples:
+
+smsc0: smsc95xx@0 {
+       /* Filled in by U-Boot */
+       mac-address = [ 00 00 00 00 00 00 ];
+};
+
drivers/net/usb/smsc95xx.c +24 -1
index 3f38ba8..baee0bd 100644
@@ -31,6 +31,9 @@
 #include <linux/crc32.h>
 #include <linux/usb/usbnet.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
+
 #include "smsc95xx.h"
 
 #define SMSC_CHIPNAME                  "smsc95xx"
@@ -62,6 +65,8 @@
 #define SUSPEND_ALLMODES               (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
                                         SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
 
+#define SMSC95XX_OF_NAME       "/smsc95xx@"
+
 struct smsc95xx_priv {
        u32 mac_cr;
        u32 hash_hi;
@@ -767,6 +772,25 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
 
 static void smsc95xx_init_mac_address(struct usbnet *dev)
 {
+
+#ifdef CONFIG_OF
+       struct device_node *ap;
+       const char *mac = NULL;
+       char *of_name = SMSC95XX_OF_NAME;
+
+       sprintf(of_name, "%s%i", SMSC95XX_OF_NAME, dev->udev->dev.id);
+       ap = of_find_node_by_path(of_name);
+       if (ap) {
+               mac = of_get_mac_address(ap);
+               if (is_valid_ether_addr(mac)) {
+                       /* Device tree has a mac for this so use that */
+                       memcpy(dev->net->dev_addr, mac, ETH_ALEN);
+                       netif_dbg(dev, ifup, dev->net, "MAC address read from DTB\n");
+                       return;
+               }
+       }
+#endif
+
        /* try reading mac address from EEPROM */
        if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
                        dev->net->dev_addr) == 0) {
--

1.7.9.5

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Thanks,

Signature · 7 lines
------------------
Dan Murphy

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 12 lines · Dan Murphy
Quoted 10 lines · Ming Lei
Quoted 6 lines · Dan Murphy

If the smsc95xx does not have a valid MAC address stored within the eeprom then a random number is generated. The MAC can also be set by uBoot but the smsc95xx does not have a way to read this.

Create the binding for the smsc95xx so that uBoot can set the MAC and the code can retrieve the MAC from the modified DTB file.

Suppose there are two smsc95xx usbnet devices connected to usb bus, and one is built-in, another is hotplug device, can your patch handle the situation correctly?

Quoted 6 lines

Look at this line in the patch below

sprintf(of_name, "%s%i", SMSC95XX_OF_NAME, dev->udev->dev.id);

I am appending the dev ID of the device to the of_name here. As long as init_mac_address is called, the dev.id and the uBoot entry match then yes.

Currently, non-root-hub usb device is created and added into usb bus without any platform(device tree) knowledge, so you can't expect the match here.

Also not mention the two smsc95xx devices may attach to two different usb host controllers(buses).

Thanks,

Signature · 1 line
Ming Lei
author
#4 lore raw
Quoted 12 lines · Ming Lei
Quoted 11 lines · Dan Murphy
Quoted 10 lines · Ming Lei
Quoted 6 lines · Dan Murphy

If the smsc95xx does not have a valid MAC address stored within the eeprom then a random number is generated. The MAC can also be set by uBoot but the smsc95xx does not have a way to read this.

Create the binding for the smsc95xx so that uBoot can set the MAC and the code can retrieve the MAC from the modified DTB file.

Suppose there are two smsc95xx usbnet devices connected to usb bus, and one is built-in, another is hotplug device, can your patch handle the situation correctly?

Quoted 8 lines
Quoted 6 lines

Look at this line in the patch below

sprintf(of_name, "%s%i", SMSC95XX_OF_NAME, dev->udev->dev.id);

I am appending the dev ID of the device to the of_name here. As long as init_mac_address is called, the dev.id and the uBoot entry match then yes.

Currently, non-root-hub usb device is created and added into usb bus without any platform(device tree) knowledge, so you can't expect the match here.

That is correct. Platform/dev tree will have no concept of the PnP USB dongle therefore there should be no entry in either.

I will need to test this issue with a PnP usb->ethernet dongle.

Dan

Quoted 4 lines

Also not mention the two smsc95xx devices may attach to two different usb host controllers(buses).

Thanks,

Signature · 7 lines
------------------
Dan Murphy

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#5 lore raw
In reply to Ming Lei

Ming

Quoted 18 lines · Ming Lei
Quoted 11 lines · Dan Murphy
Quoted 10 lines · Ming Lei
Quoted 6 lines · Dan Murphy

If the smsc95xx does not have a valid MAC address stored within the eeprom then a random number is generated. The MAC can also be set by uBoot but the smsc95xx does not have a way to read this.

Create the binding for the smsc95xx so that uBoot can set the MAC and the code can retrieve the MAC from the modified DTB file.

Suppose there are two smsc95xx usbnet devices connected to usb bus, and one is built-in, another is hotplug device, can your patch handle the situation correctly?

Quoted 6 lines

Look at this line in the patch below

sprintf(of_name, "%s%i", SMSC95XX_OF_NAME, dev->udev->dev.id);

I am appending the dev ID of the device to the of_name here. As long as init_mac_address is called, the dev.id and the uBoot entry match then yes.

Quoted 7 lines

Currently, non-root-hub usb device is created and added into usb bus without any platform(device tree) knowledge, so you can't expect the match here.

Also not mention the two smsc95xx devices may attach to two different usb host controllers(buses).

Thanks,

You are correct I don't expect a match for PnP devices only devices that are hard wired.

After thinking of it I should move the OF code below the EEPROM code as the EEPROM should take preference over the DT code.

I will need to post V2 for that.

Dan

Signature · 2 lines
------------------
Dan Murphy
#6 lore raw
Quoted 6 lines · Dan Murphy

You are correct I don't expect a match for PnP devices only devices that are hard wired.

After thinking of it I should move the OF code below the EEPROM code as the EEPROM should take preference over the DT code.

I will need to post V2 for that.

Your patch still doesn't deal with two smsc95xx devices built in one board.

The problem is a generic one, looks it is better to do it when OF supports discoverable bus.

Thanks,

Signature · 1 line
Ming Lei
author
#7 lore raw
Quoted 8 lines · Ming Lei
Quoted 5 lines · Dan Murphy

You are correct I don't expect a match for PnP devices only devices that are hard wired.

After thinking of it I should move the OF code below the EEPROM code as the EEPROM should take preference over the DT code.

I will need to post V2 for that.

Your patch still doesn't deal with two smsc95xx devices built in one board.

Is there a board that has 2 built in smsc devices?

This is all dependent on what the dev.id is of udev.

Quoted 6 lines

The problem is a generic one, looks it is better to do it when OF supports discoverable bus.

Thanks,

Signature · 2 lines
------------------
Dan Murphy
#8 lore raw
Quoted 2 lines · Dan Murphy

Is there a board that has 2 built in smsc devices?

I don't know, maybe there isn't, but driver should be generic enough, and as I said it is a generic problem, and people are discussing it, so suggest to read previous discussions first before post your V2.

Below link is one I remembered, but I think you can find more:

https://lkml.org/lkml/2013/8/11/100

Quoted 1 line

This is all dependent on what the dev.id is of udev.

I am not sure why it depends on udev, and udev can't see the device util it is added to system.

Thanks,

Signature · 1 line
Ming Lei