kernel: bump 6.1 to 6.1.61
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-6.1 / 950-0083-Allow-mac-address-to-be-set-in-smsc95xx.patch
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
5
6 Signed-off-by: popcornmix <popcornmix@gmail.com>
7
8 SQUASH: smsc95xx: Use dev_mod_addr to set MAC addr
9
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.
15
16 Squash with 96c1def63ee1 ("Allow mac address to be set in smsc95xx").
17
18 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
19 ---
20 drivers/net/usb/smsc95xx.c | 54 ++++++++++++++++++++++++++++++++++++++
21 1 file changed, 54 insertions(+)
22
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");
28
29 +static char *macaddr = ":";
30 +module_param(macaddr, charp, 0);
31 +MODULE_PARM_DESC(macaddr, "MAC address");
32 +
33 static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
34 u32 *data)
35 {
36 @@ -809,6 +813,52 @@ static int smsc95xx_ioctl(struct net_dev
37 return phy_mii_ioctl(netdev->phydev, rq, cmd);
38 }
39
40 +/* Check the macaddr module parameter for a MAC address */
41 +static int smsc95xx_is_macaddr_param(struct usbnet *dev, struct net_device *nd)
42 +{
43 + int i, j, got_num, num;
44 + u8 mtbl[ETH_ALEN];
45 +
46 + if (macaddr[0] == ':')
47 + return 0;
48 +
49 + i = 0;
50 + j = 0;
51 + num = 0;
52 + got_num = 0;
53 + while (j < ETH_ALEN) {
54 + if (macaddr[i] && macaddr[i] != ':') {
55 + got_num++;
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';
62 + else
63 + break;
64 + i++;
65 + } else if (got_num == 2) {
66 + mtbl[j++] = (u8) num;
67 + num = 0;
68 + got_num = 0;
69 + i++;
70 + } else {
71 + break;
72 + }
73 + }
74 +
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);
80 + return 1;
81 + } else {
82 + return 0;
83 + }
84 +}
85 +
86 static void smsc95xx_init_mac_address(struct usbnet *dev)
87 {
88 u8 addr[ETH_ALEN];
89 @@ -832,6 +882,10 @@ static void smsc95xx_init_mac_address(st
90 }
91 }
92
93 + /* Check module parameters */
94 + if (smsc95xx_is_macaddr_param(dev, dev->net))
95 + return;
96 +
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");