Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
net: smsc95xx: persistent MAC address from serial (torvalds#85)
Browse files Browse the repository at this point in the history
Signed-off-by: ZHANG Yuntian <[email protected]>
  • Loading branch information
RadxaYuntian authored and vamrs-feng committed Jul 18, 2023
1 parent 4943f7b commit 1ed18dd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/net/usb/smsc95xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <linux/phy.h>
#include "smsc95xx.h"

#if defined(__arm64__) || defined(__aarch64__)
#include <asm/system_info.h>
#endif

#define SMSC_CHIPNAME "smsc95xx"
#define SMSC_DRIVER_VERSION "2.0.0"
#define HS_USB_PKT_SIZE (512)
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 1ed18dd

Please sign in to comment.