brcm2708: update against latest rpi-3.10.y branch
[openwrt.git] / target / linux / brcm2708 / patches-3.10 / 0008-Allow-mac-address-to-be-set-in-smsc95xx.patch
1 From bd5ea6c71eb31d1c65f718a2938ea9a4272c8b8e 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 008/174] 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 @@ -61,6 +61,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  struct smsc95xx_priv {
20         u32 mac_cr;
21 @@ -76,6 +77,10 @@ static bool turbo_mode = true;
22  module_param(turbo_mode, bool, 0644);
23  MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
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 @@ -765,8 +770,59 @@ 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 +       /* Check module parameters */
86 +       if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
87 +               return;
88 +
89         /* try reading mac address from EEPROM */
90         if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
91                         dev->net->dev_addr) == 0) {