[Xenial snapdragon][PATCH 0/1] Support reading MAC addresses from files for smsc75xx

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Xenial snapdragon][PATCH 0/1] Support reading MAC addresses from files for smsc75xx

Wen-chien Jesse Sung
BugLink: https://launchpad.net/bugs/1779035

Currently the driver reads MAC address from EEPROM. If the content is
invalid, it then generates a random address. On a platform we have,
the EEPROM is not reliable, and a consistent MAC address is required.
One way to overcome this is to read the address from a file if it exists.


Wen-chien Jesse Sung (1):
  UBUNTU: SAUCE: smsc75xx: read MAC address from file if it exists

 drivers/net/usb/smsc75xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

--
2.17.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[Xenial snapdragon][PATCH 1/1] UBUNTU: SAUCE: smsc75xx: read MAC address from file if it exists

Wen-chien Jesse Sung
BugLink: https://launchpad.net/bugs/1779035

When trying to determine which MAC address to use, find if a valid one
is available in the file first.

Signed-off-by: Wen-chien Jesse Sung <[hidden email]>
---
 drivers/net/usb/smsc75xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 7337e6c0e126..b4352d4f58b1 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -29,6 +29,7 @@
 #include <linux/crc32.h>
 #include <linux/usb/usbnet.h>
 #include <linux/slab.h>
+#include <linux/firmware.h>
 #include "smsc75xx.h"
 
 #define SMSC_CHIPNAME "smsc75xx"
@@ -759,8 +760,39 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
  return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
 }
 
+#define MAC_BASENAME "smsc75xx/ethmacaddr"
+
+static int smsc75xx_get_hw_mac(struct usbnet *dev)
+{
+ const struct firmware *fp = NULL;
+ int ret;
+ u8 tmp[32];
+
+ snprintf(tmp, sizeof(tmp), "%s-%s", MAC_BASENAME, dev->udev->devpath);
+ ret = request_firmware(&fp, tmp, &dev->udev->dev);
+ if (!ret) {
+ memset(tmp, 0, sizeof(tmp));
+ memcpy(tmp, fp->data, sizeof(tmp) - 1);
+ sscanf(tmp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+ &dev->net->dev_addr[0],
+ &dev->net->dev_addr[1],
+ &dev->net->dev_addr[2],
+ &dev->net->dev_addr[3],
+ &dev->net->dev_addr[4],
+ &dev->net->dev_addr[5]);
+
+ release_firmware(fp);
+ }
+ return ret;
+}
+
 static void smsc75xx_init_mac_address(struct usbnet *dev)
 {
+ if (!smsc75xx_get_hw_mac(dev) && is_valid_ether_addr(dev->net->dev_addr)) {
+ netif_dbg(dev, ifup, dev->net, "MAC address read from file\n");
+ return;
+ }
+
  /* try reading mac address from EEPROM */
  if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  dev->net->dev_addr) == 0) {
--
2.17.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [Xenial snapdragon][PATCH 1/1] UBUNTU: SAUCE: smsc75xx: read MAC address from file if it exists

Hui Wang
Looks fine to me, this change is safe to other platforms which also use this driver since they don't have the file in that folder.

Acked-by: Hui Wang [hidden email]


On 2018年06月28日 17:01, Wen-chien Jesse Sung wrote:
BugLink: https://launchpad.net/bugs/1779035

When trying to determine which MAC address to use, find if a valid one
is available in the file first.

Signed-off-by: Wen-chien Jesse Sung [hidden email]
---
 drivers/net/usb/smsc75xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 7337e6c0e126..b4352d4f58b1 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -29,6 +29,7 @@
 #include <linux/crc32.h>
 #include <linux/usb/usbnet.h>
 #include <linux/slab.h>
+#include <linux/firmware.h>
 #include "smsc75xx.h"
 
 #define SMSC_CHIPNAME			"smsc75xx"
@@ -759,8 +760,39 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
 	return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
 }
 
+#define MAC_BASENAME	"smsc75xx/ethmacaddr"
+
+static int smsc75xx_get_hw_mac(struct usbnet *dev)
+{
+	const struct firmware *fp = NULL;
+	int ret;
+	u8 tmp[32];
+
+	snprintf(tmp, sizeof(tmp), "%s-%s", MAC_BASENAME, dev->udev->devpath);
+	ret = request_firmware(&fp, tmp, &dev->udev->dev);
+	if (!ret) {
+		memset(tmp, 0, sizeof(tmp));
+		memcpy(tmp, fp->data, sizeof(tmp) - 1);
+		sscanf(tmp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+			&dev->net->dev_addr[0],
+			&dev->net->dev_addr[1],
+			&dev->net->dev_addr[2],
+			&dev->net->dev_addr[3],
+			&dev->net->dev_addr[4],
+			&dev->net->dev_addr[5]);
+
+		release_firmware(fp);
+	}
+	return ret;
+}
+
 static void smsc75xx_init_mac_address(struct usbnet *dev)
 {
+	if (!smsc75xx_get_hw_mac(dev) && is_valid_ether_addr(dev->net->dev_addr)) {
+		netif_dbg(dev, ifup, dev->net, "MAC address read from file\n");
+		return;
+	}
+
 	/* try reading mac address from EEPROM */
 	if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
 			dev->net->dev_addr) == 0) {



--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK/cmnt: [Xenial snapdragon][PATCH 0/1] Support reading MAC addresses from files for smsc75xx

AceLan Kao
In reply to this post by Wen-chien Jesse Sung
Pretty safe and reasonable change.

Acked-By: AceLan Kao <[hidden email]>

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

Re: [Xenial snapdragon][PATCH 1/1] UBUNTU: SAUCE: smsc75xx: read MAC address from file if it exists

Paolo Pisati-5
In reply to this post by Wen-chien Jesse Sung
On Thu, Jun 28, 2018 at 05:01:02PM +0800, Wen-chien Jesse Sung wrote:
> BugLink: https://launchpad.net/bugs/1779035
>
> When trying to determine which MAC address to use, find if a valid one
> is available in the file first.

Acked-by: Paolo Pisati <[hidden email]>
--
bye,
p.

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

APPLIED: [Xenial snapdragon][PATCH 0/1] Support reading MAC addresses from files for smsc75xx

Stefan Bader-2
In reply to this post by Wen-chien Jesse Sung
On 28.06.2018 11:01, Wen-chien Jesse Sung wrote:

> BugLink: https://launchpad.net/bugs/1779035
>
> Currently the driver reads MAC address from EEPROM. If the content is
> invalid, it then generates a random address. On a platform we have,
> the EEPROM is not reliable, and a consistent MAC address is required.
> One way to overcome this is to read the address from a file if it exists.
>
>
> Wen-chien Jesse Sung (1):
>   UBUNTU: SAUCE: smsc75xx: read MAC address from file if it exists
>
>  drivers/net/usb/smsc75xx.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
Applied to xenial/snapdragon.


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (836 bytes) Download Attachment