kernel: update 3.10 to 3.10.2
[openwrt/staging/pepe2k.git] / target / linux / brcm2708 / patches-3.10 / 006-Allow-mac-address-to-be-set-in-smsc95xx.patch
1 --- a/drivers/net/usb/smsc95xx.c
2 +++ b/drivers/net/usb/smsc95xx.c
3 @@ -61,6 +61,7 @@
4 #define SUSPEND_SUSPEND3 (0x08)
5 #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
6 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
7 +#define MAC_ADDR_LEN (6)
8
9 struct smsc95xx_priv {
10 u32 mac_cr;
11 @@ -76,6 +77,10 @@ static bool turbo_mode = true;
12 module_param(turbo_mode, bool, 0644);
13 MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
14
15 +static char *macaddr = ":";
16 +module_param(macaddr, charp, 0);
17 +MODULE_PARM_DESC(macaddr, "MAC address");
18 +
19 static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
20 u32 *data, int in_pm)
21 {
22 @@ -765,8 +770,59 @@ static int smsc95xx_ioctl(struct net_dev
23 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
24 }
25
26 +/* Check the macaddr module parameter for a MAC address */
27 +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
28 +{
29 + int i, j, got_num, num;
30 + u8 mtbl[MAC_ADDR_LEN];
31 +
32 + if (macaddr[0] == ':')
33 + return 0;
34 +
35 + i = 0;
36 + j = 0;
37 + num = 0;
38 + got_num = 0;
39 + while (j < MAC_ADDR_LEN) {
40 + if (macaddr[i] && macaddr[i] != ':') {
41 + got_num++;
42 + if ('0' <= macaddr[i] && macaddr[i] <= '9')
43 + num = num * 16 + macaddr[i] - '0';
44 + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
45 + num = num * 16 + 10 + macaddr[i] - 'A';
46 + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
47 + num = num * 16 + 10 + macaddr[i] - 'a';
48 + else
49 + break;
50 + i++;
51 + } else if (got_num == 2) {
52 + mtbl[j++] = (u8) num;
53 + num = 0;
54 + got_num = 0;
55 + i++;
56 + } else {
57 + break;
58 + }
59 + }
60 +
61 + if (j == MAC_ADDR_LEN) {
62 + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
63 + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
64 + mtbl[3], mtbl[4], mtbl[5]);
65 + for (i = 0; i < MAC_ADDR_LEN; i++)
66 + dev_mac[i] = mtbl[i];
67 + return 1;
68 + } else {
69 + return 0;
70 + }
71 +}
72 +
73 static void smsc95xx_init_mac_address(struct usbnet *dev)
74 {
75 + /* Check module parameters */
76 + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
77 + return;
78 +
79 /* try reading mac address from EEPROM */
80 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
81 dev->net->dev_addr) == 0) {