1 From e592fc748cfc927a3c6ed098a21ece63b1efa682 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Tue, 26 Mar 2013 17:26:38 +0000
4 Subject: [PATCH 004/454] Allow mac address to be set in smsc95xx
6 Signed-off-by: popcornmix <popcornmix@gmail.com>
8 drivers/net/usb/smsc95xx.c | 56 ++++++++++++++++++++++++++++++++++++++
9 1 file changed, 56 insertions(+)
11 --- a/drivers/net/usb/smsc95xx.c
12 +++ b/drivers/net/usb/smsc95xx.c
14 #define SUSPEND_SUSPEND3 (0x08)
15 #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
16 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
17 +#define MAC_ADDR_LEN (6)
19 #define CARRIER_CHECK_DELAY (2 * HZ)
21 @@ -90,6 +91,10 @@ static int packetsize = 2560;
22 module_param(packetsize, int, 0644);
23 MODULE_PARM_DESC(packetsize, "Override the RX URB packet size");
25 +static char *macaddr = ":";
26 +module_param(macaddr, charp, 0);
27 +MODULE_PARM_DESC(macaddr, "MAC address");
29 static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
32 @@ -921,6 +926,53 @@ static int smsc95xx_ioctl(struct net_dev
33 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
36 +/* Check the macaddr module parameter for a MAC address */
37 +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
39 + int i, j, got_num, num;
40 + u8 mtbl[MAC_ADDR_LEN];
42 + if (macaddr[0] == ':')
49 + while (j < MAC_ADDR_LEN) {
50 + if (macaddr[i] && macaddr[i] != ':') {
52 + if ('0' <= macaddr[i] && macaddr[i] <= '9')
53 + num = num * 16 + macaddr[i] - '0';
54 + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
55 + num = num * 16 + 10 + macaddr[i] - 'A';
56 + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
57 + num = num * 16 + 10 + macaddr[i] - 'a';
61 + } else if (got_num == 2) {
62 + mtbl[j++] = (u8) num;
71 + if (j == MAC_ADDR_LEN) {
72 + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
73 + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
74 + mtbl[3], mtbl[4], mtbl[5]);
75 + for (i = 0; i < MAC_ADDR_LEN; i++)
76 + dev_mac[i] = mtbl[i];
83 static void smsc95xx_init_mac_address(struct usbnet *dev)
86 @@ -942,6 +994,10 @@ static void smsc95xx_init_mac_address(st
90 + /* Check module parameters */
91 + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
94 /* no useful static MAC address found. generate a random one */
95 eth_hw_addr_random(dev->net);
96 netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");