Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
Merge pull request torvalds#146 from vamrs-feng/pr_some_change
Browse files Browse the repository at this point in the history
Associate the mac address with the board.

Signed-off-by: Stephen Chen <stephen@radxa.com>
  • Loading branch information
RadxaStephen authored Jul 6, 2023
2 parents 6ebeb96 + e5ee7ae commit 8befe32
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 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 @@ -50,6 +54,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;
Expand All @@ -68,6 +73,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)
{
Expand Down Expand Up @@ -766,6 +775,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 */
Expand All @@ -788,6 +844,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");
Expand Down

0 comments on commit 8befe32

Please sign in to comment.