Skip to content

Commit 1de3abc

Browse files
committed
Allow mac address to be set in smsc95xx
Signed-off-by: popcornmix <popcornmix@gmail.com>
1 parent ae72db2 commit 1de3abc

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎drivers/net/usb/smsc95xx.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#define SUSPEND_SUSPEND3 (0x08)
4949
#define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
5050
SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
51+
#define MAC_ADDR_LEN (6)
5152

5253
#define CARRIER_CHECK_DELAY (2 * HZ)
5354

@@ -78,6 +79,10 @@ static int packetsize = 2560;
7879
module_param(packetsize, int, 0644);
7980
MODULE_PARM_DESC(packetsize, "Override the RX URB packet size");
8081

82+
static char *macaddr = ":";
83+
module_param(macaddr, charp, 0);
84+
MODULE_PARM_DESC(macaddr, "MAC address");
85+
8186
static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
8287
u32 *data, int in_pm)
8388
{
@@ -907,6 +912,53 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
907912
return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
908913
}
909914

915+
/* Check the macaddr module parameter for a MAC address */
916+
static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
917+
{
918+
int i, j, got_num, num;
919+
u8 mtbl[MAC_ADDR_LEN];
920+
921+
if (macaddr[0] == ':')
922+
return 0;
923+
924+
i = 0;
925+
j = 0;
926+
num = 0;
927+
got_num = 0;
928+
while (j < MAC_ADDR_LEN) {
929+
if (macaddr[i] && macaddr[i] != ':') {
930+
got_num++;
931+
if ('0' <= macaddr[i] && macaddr[i] <= '9')
932+
num = num * 16 + macaddr[i] - '0';
933+
else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
934+
num = num * 16 + 10 + macaddr[i] - 'A';
935+
else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
936+
num = num * 16 + 10 + macaddr[i] - 'a';
937+
else
938+
break;
939+
i++;
940+
} else if (got_num == 2) {
941+
mtbl[j++] = (u8) num;
942+
num = 0;
943+
got_num = 0;
944+
i++;
945+
} else {
946+
break;
947+
}
948+
}
949+
950+
if (j == MAC_ADDR_LEN) {
951+
netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
952+
"%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
953+
mtbl[3], mtbl[4], mtbl[5]);
954+
for (i = 0; i < MAC_ADDR_LEN; i++)
955+
dev_mac[i] = mtbl[i];
956+
return 1;
957+
} else {
958+
return 0;
959+
}
960+
}
961+
910962
static void smsc95xx_init_mac_address(struct usbnet *dev)
911963
{
912964
const u8 *mac_addr;
@@ -928,6 +980,10 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
928980
}
929981
}
930982

983+
/* Check module parameters */
984+
if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
985+
return;
986+
931987
/* no useful static MAC address found. generate a random one */
932988
eth_hw_addr_random(dev->net);
933989
netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");

0 commit comments

Comments
 (0)