Skip to content

Commit

Permalink
Added mac address parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Featherston committed Oct 14, 2015
1 parent 481a309 commit 2206bf2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions drivers/net/usb/smsc95xx.c
Expand Up @@ -76,6 +76,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_PARM_DESC(macaddr, "MAC address");
module_param(macaddr, charp, 0);

static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
u32 *data, int in_pm)
{
Expand Down Expand Up @@ -765,6 +769,37 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
}

static void get_mac_addr(struct net_device *net, u8 *mac)
{
int i;
int j;
int got_num;
int num;

i = j = num = got_num = 0;
while (j < ETH_ALEN) {
if (macaddr[i]) {
int digit;

got_num = 1;
digit = hex_to_bin(macaddr[i]);
if (digit >= 0)
num = num * 16 + digit;
else if (':' == macaddr[i])
got_num = 2;
else
break;
} else if (got_num)
got_num = 2;
else
break;
if (2 == got_num) {
net->dev_addr[j++] = num;
}
i++;
}
}

static void smsc95xx_init_mac_address(struct usbnet *dev)
{
/* try reading mac address from EEPROM */
Expand All @@ -777,6 +812,12 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
}
}

if (macaddr[0] != ':'){
get_mac_addr(dev->net, macaddr);
if (is_valid_ether_addr(dev->net->dev_addr))
return;
}

/* no eeprom, or eeprom values are invalid. generate random MAC */
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 2206bf2

Please sign in to comment.