OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 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 |
||
5 | |||
6 | Signed-off-by: popcornmix <popcornmix@gmail.com> |
||
7 | --- |
||
8 | drivers/net/usb/smsc95xx.c | 56 ++++++++++++++++++++++++++++++++++++++ |
||
9 | 1 file changed, 56 insertions(+) |
||
10 | |||
11 | --- a/drivers/net/usb/smsc95xx.c |
||
12 | +++ b/drivers/net/usb/smsc95xx.c |
||
13 | @@ -60,6 +60,7 @@ |
||
14 | #define SUSPEND_SUSPEND3 (0x08) |
||
15 | #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ |
||
16 | SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) |
||
17 | +#define MAC_ADDR_LEN (6) |
||
18 | |||
19 | #define CARRIER_CHECK_DELAY (2 * HZ) |
||
20 | |||
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"); |
||
24 | |||
25 | +static char *macaddr = ":"; |
||
26 | +module_param(macaddr, charp, 0); |
||
27 | +MODULE_PARM_DESC(macaddr, "MAC address"); |
||
28 | + |
||
29 | static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, |
||
30 | u32 *data, int in_pm) |
||
31 | { |
||
32 | @@ -921,6 +926,53 @@ static int smsc95xx_ioctl(struct net_dev |
||
33 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); |
||
34 | } |
||
35 | |||
36 | +/* Check the macaddr module parameter for a MAC address */ |
||
37 | +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac) |
||
38 | +{ |
||
39 | + int i, j, got_num, num; |
||
40 | + u8 mtbl[MAC_ADDR_LEN]; |
||
41 | + |
||
42 | + if (macaddr[0] == ':') |
||
43 | + return 0; |
||
44 | + |
||
45 | + i = 0; |
||
46 | + j = 0; |
||
47 | + num = 0; |
||
48 | + got_num = 0; |
||
49 | + while (j < MAC_ADDR_LEN) { |
||
50 | + if (macaddr[i] && macaddr[i] != ':') { |
||
51 | + got_num++; |
||
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'; |
||
58 | + else |
||
59 | + break; |
||
60 | + i++; |
||
61 | + } else if (got_num == 2) { |
||
62 | + mtbl[j++] = (u8) num; |
||
63 | + num = 0; |
||
64 | + got_num = 0; |
||
65 | + i++; |
||
66 | + } else { |
||
67 | + break; |
||
68 | + } |
||
69 | + } |
||
70 | + |
||
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]; |
||
77 | + return 1; |
||
78 | + } else { |
||
79 | + return 0; |
||
80 | + } |
||
81 | +} |
||
82 | + |
||
83 | static void smsc95xx_init_mac_address(struct usbnet *dev) |
||
84 | { |
||
85 | const u8 *mac_addr; |
||
86 | @@ -942,6 +994,10 @@ static void smsc95xx_init_mac_address(st |
||
87 | } |
||
88 | } |
||
89 | |||
90 | + /* Check module parameters */ |
||
91 | + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr)) |
||
92 | + return; |
||
93 | + |
||
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"); |