From 0dc329ec85a679989b0ee895f3c78707593feda9 Mon Sep 17 00:00:00 2001 From: Feng Zhang Date: Tue, 18 Jul 2023 18:39:18 +0800 Subject: [PATCH 1/4] Revert "UPSTREAM: Allow mac address to be set in smsc95xx" This reverts commit e5ee7aee65ab2587aad448e07fe0c075db006644. --- drivers/net/usb/smsc95xx.c | 69 ++++++++++---------------------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 635a6a583c97af..b82ae6e926c6da 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -54,7 +54,6 @@ #define SUSPEND_SUSPEND3 (0x08) #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) -#define MAC_ADDR_LEN (6) struct smsc95xx_priv { u32 mac_cr; @@ -73,10 +72,6 @@ static bool turbo_mode = true; module_param(turbo_mode, bool, 0644); MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); -static char *macaddr = ":"; -module_param(macaddr, charp, 0); -MODULE_PARM_DESC(macaddr, "MAC address"); - static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data, int in_pm) { @@ -775,53 +770,6 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) return phy_mii_ioctl(netdev->phydev, rq, cmd); } -/* Check the macaddr module parameter for a MAC address */ -static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac) -{ - int i, j, got_num, num; - u8 mtbl[MAC_ADDR_LEN]; - - if (macaddr[0] == ':') - return 0; - - i = 0; - j = 0; - num = 0; - got_num = 0; - while (j < MAC_ADDR_LEN) { - if (macaddr[i] && macaddr[i] != ':') { - got_num++; - if ('0' <= macaddr[i] && macaddr[i] <= '9') - num = num * 16 + macaddr[i] - '0'; - else if ('A' <= macaddr[i] && macaddr[i] <= 'F') - num = num * 16 + 10 + macaddr[i] - 'A'; - else if ('a' <= macaddr[i] && macaddr[i] <= 'f') - num = num * 16 + 10 + macaddr[i] - 'a'; - else - break; - i++; - } else if (got_num == 2) { - mtbl[j++] = (u8) num; - num = 0; - got_num = 0; - i++; - } else { - break; - } - } - - if (j == MAC_ADDR_LEN) { - netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: " - "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2], - mtbl[3], mtbl[4], mtbl[5]); - for (i = 0; i < MAC_ADDR_LEN; i++) - dev_mac[i] = mtbl[i]; - return 1; - } else { - return 0; - } -} - static void smsc95xx_init_mac_address(struct usbnet *dev) { /* maybe the boot loader passed the MAC address in devicetree */ @@ -848,6 +796,23 @@ static void smsc95xx_init_mac_address(struct usbnet *dev) if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr)) return; +#if defined(__arm64__) || defined(__aarch64__) + /* Generate a MAC address from system serial */ + if (system_serial_low != 0 && system_serial_high != 0) { + *((u32 *) &dev->net->dev_addr[MAC_ADDR_LEN - sizeof(u32)]) = + crc32(system_serial_high, &system_serial_low, sizeof(system_serial_low)); + // Prefix with Microchip Technology Inc's vendor ID + dev->net->dev_addr[0] = 0; + dev->net->dev_addr[1] = 4; + dev->net->dev_addr[2] = 0xa3; + netif_dbg(dev, ifup, dev->net, "Generate MAC address from CPU serial: " + "%02x:%02x:%02x:%02x:%02x:%02x\n", + 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]); + return; + } +#endif + /* no useful static MAC address found. generate a random one */ eth_hw_addr_random(dev->net); netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); From 8bf92e5e37b46b495987556375f523cc7190aca9 Mon Sep 17 00:00:00 2001 From: Feng Zhang Date: Tue, 18 Jul 2023 18:39:34 +0800 Subject: [PATCH 2/4] Revert "net: smsc95xx: persistent MAC address from serial (#85)" This reverts commit 8996729ee6ecadfa7389f5396137cd471086ec18. --- drivers/net/usb/smsc95xx.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index b82ae6e926c6da..e1cd4c2de2d30c 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -22,10 +22,6 @@ #include #include "smsc95xx.h" -#if defined(__arm64__) || defined(__aarch64__) -#include -#endif - #define SMSC_CHIPNAME "smsc95xx" #define SMSC_DRIVER_VERSION "2.0.0" #define HS_USB_PKT_SIZE (512) @@ -792,27 +788,6 @@ static void smsc95xx_init_mac_address(struct usbnet *dev) } } - /* Check module parameters */ - if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr)) - return; - -#if defined(__arm64__) || defined(__aarch64__) - /* Generate a MAC address from system serial */ - if (system_serial_low != 0 && system_serial_high != 0) { - *((u32 *) &dev->net->dev_addr[MAC_ADDR_LEN - sizeof(u32)]) = - crc32(system_serial_high, &system_serial_low, sizeof(system_serial_low)); - // Prefix with Microchip Technology Inc's vendor ID - dev->net->dev_addr[0] = 0; - dev->net->dev_addr[1] = 4; - dev->net->dev_addr[2] = 0xa3; - netif_dbg(dev, ifup, dev->net, "Generate MAC address from CPU serial: " - "%02x:%02x:%02x:%02x:%02x:%02x\n", - 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]); - return; - } -#endif - /* no useful static MAC address found. generate a random one */ eth_hw_addr_random(dev->net); netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); From 4943f7b99cc6f3b1115ae7ecd186e685a4e2bd47 Mon Sep 17 00:00:00 2001 From: popcornmix Date: Tue, 26 Mar 2013 17:26:38 +0000 Subject: [PATCH 3/4] UPSTREAM: Allow mac address to be set in smsc95xx Signed-off-by: popcornmix Signed-off-by: Ken Wang --- drivers/net/usb/smsc95xx.c | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index e1cd4c2de2d30c..2b431b5829ed93 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -50,6 +50,7 @@ #define SUSPEND_SUSPEND3 (0x08) #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) +#define MAC_ADDR_LEN (6) struct smsc95xx_priv { u32 mac_cr; @@ -68,6 +69,10 @@ static bool turbo_mode = true; module_param(turbo_mode, bool, 0644); MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); +static char *macaddr = ":"; +module_param(macaddr, charp, 0); +MODULE_PARM_DESC(macaddr, "MAC address"); + static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data, int in_pm) { @@ -766,6 +771,53 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) return phy_mii_ioctl(netdev->phydev, rq, cmd); } +/* Check the macaddr module parameter for a MAC address */ +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac) +{ + int i, j, got_num, num; + u8 mtbl[MAC_ADDR_LEN]; + + if (macaddr[0] == ':') + return 0; + + i = 0; + j = 0; + num = 0; + got_num = 0; + while (j < MAC_ADDR_LEN) { + if (macaddr[i] && macaddr[i] != ':') { + got_num++; + if ('0' <= macaddr[i] && macaddr[i] <= '9') + num = num * 16 + macaddr[i] - '0'; + else if ('A' <= macaddr[i] && macaddr[i] <= 'F') + num = num * 16 + 10 + macaddr[i] - 'A'; + else if ('a' <= macaddr[i] && macaddr[i] <= 'f') + num = num * 16 + 10 + macaddr[i] - 'a'; + else + break; + i++; + } else if (got_num == 2) { + mtbl[j++] = (u8) num; + num = 0; + got_num = 0; + i++; + } else { + break; + } + } + + if (j == MAC_ADDR_LEN) { + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: " + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2], + mtbl[3], mtbl[4], mtbl[5]); + for (i = 0; i < MAC_ADDR_LEN; i++) + dev_mac[i] = mtbl[i]; + return 1; + } else { + return 0; + } +} + static void smsc95xx_init_mac_address(struct usbnet *dev) { /* maybe the boot loader passed the MAC address in devicetree */ @@ -788,6 +840,10 @@ static void smsc95xx_init_mac_address(struct usbnet *dev) } } + /* Check module parameters */ + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr)) + return; + /* no useful static MAC address found. generate a random one */ eth_hw_addr_random(dev->net); netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); From 1ed18ddb285688a1f611a8bf1aaf668fad0bcd47 Mon Sep 17 00:00:00 2001 From: ZHANG Yuntian Date: Mon, 3 Apr 2023 16:22:53 +0800 Subject: [PATCH 4/4] net: smsc95xx: persistent MAC address from serial (#85) Signed-off-by: ZHANG Yuntian --- drivers/net/usb/smsc95xx.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 2b431b5829ed93..6da85baa6151f0 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -22,6 +22,10 @@ #include #include "smsc95xx.h" +#if defined(__arm64__) || defined(__aarch64__) +#include +#endif + #define SMSC_CHIPNAME "smsc95xx" #define SMSC_DRIVER_VERSION "2.0.0" #define HS_USB_PKT_SIZE (512) @@ -844,6 +848,23 @@ static void smsc95xx_init_mac_address(struct usbnet *dev) if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr)) return; +#if defined(__arm64__) || defined(__aarch64__) + /* Generate a MAC address from system serial */ + if (system_serial_low != 0 && system_serial_high != 0) { + *((u32 *) &dev->net->dev_addr[MAC_ADDR_LEN - sizeof(u32)]) = + crc32(system_serial_high, &system_serial_low, sizeof(system_serial_low)); + // Prefix with Microchip Technology Inc's vendor ID + dev->net->dev_addr[0] = 0; + dev->net->dev_addr[1] = 4; + dev->net->dev_addr[2] = 0xa3; + netif_dbg(dev, ifup, dev->net, "Generate MAC address from CPU serial: " + "%02x:%02x:%02x:%02x:%02x:%02x\n", + 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]); + return; + } +#endif + /* no useful static MAC address found. generate a random one */ eth_hw_addr_random(dev->net); netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");