brcm47xx: board detection WNDR3400v2
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.8 / 720-eth-backport.patch
1 commit fa0879e37b59e8e3f130a30a9e6fa515717c5bdd
2 Author: Stefan Hajnoczi <stefanha@gmail.com>
3 Date: Mon Jan 21 01:17:22 2013 +0000
4
5 net: split eth_mac_addr for better error handling
6
7 When we set mac address, software mac address in system and hardware mac
8 address all need to be updated. Current eth_mac_addr() doesn't allow
9 callers to implement error handling nicely.
10
11 This patch split eth_mac_addr() to prepare part and real commit part,
12 then we can prepare first, and try to change hardware address, then do
13 the real commit if hardware address is set successfully.
14
15 Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
16 Signed-off-by: Amos Kong <akong@redhat.com>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
18
19 --- a/include/linux/etherdevice.h
20 +++ b/include/linux/etherdevice.h
21 @@ -40,6 +40,8 @@ extern int eth_header_cache(const struct
22 extern void eth_header_cache_update(struct hh_cache *hh,
23 const struct net_device *dev,
24 const unsigned char *haddr);
25 +extern int eth_prepare_mac_addr_change(struct net_device *dev, void *p);
26 +extern void eth_commit_mac_addr_change(struct net_device *dev, void *p);
27 extern int eth_mac_addr(struct net_device *dev, void *p);
28 extern int eth_change_mtu(struct net_device *dev, int new_mtu);
29 extern int eth_validate_addr(struct net_device *dev);
30 --- a/net/ethernet/eth.c
31 +++ b/net/ethernet/eth.c
32 @@ -278,16 +278,11 @@ void eth_header_cache_update(struct hh_c
33 EXPORT_SYMBOL(eth_header_cache_update);
34
35 /**
36 - * eth_mac_addr - set new Ethernet hardware address
37 + * eth_prepare_mac_addr_change - prepare for mac change
38 * @dev: network device
39 * @p: socket address
40 - *
41 - * Change hardware address of device.
42 - *
43 - * This doesn't change hardware matching, so needs to be overridden
44 - * for most real devices.
45 */
46 -int eth_mac_addr(struct net_device *dev, void *p)
47 +int eth_prepare_mac_addr_change(struct net_device *dev, void *p)
48 {
49 struct sockaddr *addr = p;
50
51 @@ -295,9 +290,43 @@ int eth_mac_addr(struct net_device *dev,
52 return -EBUSY;
53 if (!is_valid_ether_addr(addr->sa_data))
54 return -EADDRNOTAVAIL;
55 + return 0;
56 +}
57 +EXPORT_SYMBOL(eth_prepare_mac_addr_change);
58 +
59 +/**
60 + * eth_commit_mac_addr_change - commit mac change
61 + * @dev: network device
62 + * @p: socket address
63 + */
64 +void eth_commit_mac_addr_change(struct net_device *dev, void *p)
65 +{
66 + struct sockaddr *addr = p;
67 +
68 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
69 /* if device marked as NET_ADDR_RANDOM, reset it */
70 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
71 +}
72 +EXPORT_SYMBOL(eth_commit_mac_addr_change);
73 +
74 +/**
75 + * eth_mac_addr - set new Ethernet hardware address
76 + * @dev: network device
77 + * @p: socket address
78 + *
79 + * Change hardware address of device.
80 + *
81 + * This doesn't change hardware matching, so needs to be overridden
82 + * for most real devices.
83 + */
84 +int eth_mac_addr(struct net_device *dev, void *p)
85 +{
86 + int ret;
87 +
88 + ret = eth_prepare_mac_addr_change(dev, p);
89 + if (ret < 0)
90 + return ret;
91 + eth_commit_mac_addr_change(dev, p);
92 return 0;
93 }
94 EXPORT_SYMBOL(eth_mac_addr);