1 From 46f9261fd0c133038cc5adbdb91085a1791414c9 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] Allow mac address to be set in smsc95xx
6 Signed-off-by: popcornmix <popcornmix@gmail.com>
8 SQUASH: smsc95xx: Use dev_mod_addr to set MAC addr
10 Since adeef3e32146 ("net: constify netdev->dev_addr") it has been
11 illegal to write to the dev_addr MAC address field. Later commits
12 have added explicit checks that it hasn't been modified by nefarious
13 means. The dev_addr_mod helper function is the accepted way to change
14 the dev_addr field, so use it.
16 Squash with 96c1def63ee1 ("Allow mac address to be set in smsc95xx").
18 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
20 drivers/net/usb/smsc95xx.c | 54 ++++++++++++++++++++++++++++++++++++++
21 1 file changed, 54 insertions(+)
23 --- a/drivers/net/usb/smsc95xx.c
24 +++ b/drivers/net/usb/smsc95xx.c
25 @@ -87,6 +87,10 @@ static int packetsize = 2560;
26 module_param(packetsize, int, 0644);
27 MODULE_PARM_DESC(packetsize, "Override the RX URB packet size");
29 +static char *macaddr = ":";
30 +module_param(macaddr, charp, 0);
31 +MODULE_PARM_DESC(macaddr, "MAC address");
33 static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
36 @@ -809,6 +813,52 @@ static int smsc95xx_ioctl(struct net_dev
37 return phy_mii_ioctl(netdev->phydev, rq, cmd);
40 +/* Check the macaddr module parameter for a MAC address */
41 +static int smsc95xx_is_macaddr_param(struct usbnet *dev, struct net_device *nd)
43 + int i, j, got_num, num;
46 + if (macaddr[0] == ':')
53 + while (j < ETH_ALEN) {
54 + if (macaddr[i] && macaddr[i] != ':') {
56 + if ('0' <= macaddr[i] && macaddr[i] <= '9')
57 + num = num * 16 + macaddr[i] - '0';
58 + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
59 + num = num * 16 + 10 + macaddr[i] - 'A';
60 + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
61 + num = num * 16 + 10 + macaddr[i] - 'a';
65 + } else if (got_num == 2) {
66 + mtbl[j++] = (u8) num;
75 + if (j == ETH_ALEN) {
76 + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
77 + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
78 + mtbl[3], mtbl[4], mtbl[5]);
79 + dev_addr_mod(nd, 0, mtbl, ETH_ALEN);
86 static void smsc95xx_init_mac_address(struct usbnet *dev)
89 @@ -832,6 +882,10 @@ static void smsc95xx_init_mac_address(st
93 + /* Check module parameters */
94 + if (smsc95xx_is_macaddr_param(dev, dev->net))
97 /* no useful static MAC address found. generate a random one */
98 eth_hw_addr_random(dev->net);
99 netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");