Skip to content

Commit b102abd

Browse files
popcornmixDom Cobley
authored and
Dom Cobley
committed
Allow mac address to be set in smsc95xx
Signed-off-by: popcornmix <[email protected]>
1 parent 2669f2e commit b102abd

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

drivers/net/usb/smsc95xx.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define SMSC95XX_INTERNAL_PHY_ID (1)
4747
#define SMSC95XX_TX_OVERHEAD (8)
4848
#define SMSC95XX_TX_OVERHEAD_CSUM (12)
49+
#define MAC_ADDR_LEN (6)
4950

5051
struct smsc95xx_priv {
5152
u32 mac_cr;
@@ -63,6 +64,10 @@ static int turbo_mode = true;
6364
module_param(turbo_mode, bool, 0644);
6465
MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
6566

67+
static char *macaddr = ":";
68+
module_param(macaddr, charp, 0);
69+
MODULE_PARM_DESC(macaddr, "MAC address");
70+
6671
static int smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data)
6772
{
6873
u32 *buf = kmalloc(4, GFP_KERNEL);
@@ -600,8 +605,59 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
600605
return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
601606
}
602607

608+
/* Check the macaddr module parameter for a MAC address */
609+
static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
610+
{
611+
int i, j, got_num, num;
612+
u8 mtbl[MAC_ADDR_LEN];
613+
614+
if (macaddr[0] == ':')
615+
return 0;
616+
617+
i = 0;
618+
j = 0;
619+
num = 0;
620+
got_num = 0;
621+
while (j < MAC_ADDR_LEN) {
622+
if (macaddr[i] && macaddr[i] != ':') {
623+
got_num++;
624+
if ('0' <= macaddr[i] && macaddr[i] <= '9')
625+
num = num * 16 + macaddr[i] - '0';
626+
else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
627+
num = num * 16 + 10 + macaddr[i] - 'A';
628+
else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
629+
num = num * 16 + 10 + macaddr[i] - 'a';
630+
else
631+
break;
632+
i++;
633+
} else if (got_num == 2) {
634+
mtbl[j++] = (u8) num;
635+
num = 0;
636+
got_num = 0;
637+
i++;
638+
} else {
639+
break;
640+
}
641+
}
642+
643+
if (j == MAC_ADDR_LEN) {
644+
netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
645+
"%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
646+
mtbl[3], mtbl[4], mtbl[5]);
647+
for (i = 0; i < MAC_ADDR_LEN; i++)
648+
dev_mac[i] = mtbl[i];
649+
return 1;
650+
} else {
651+
return 0;
652+
}
653+
}
654+
603655
static void smsc95xx_init_mac_address(struct usbnet *dev)
604656
{
657+
/* Check module parameters */
658+
if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
659+
return;
660+
605661
/* try reading mac address from EEPROM */
606662
if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
607663
dev->net->dev_addr) == 0) {

0 commit comments

Comments
 (0)