File tree Expand file tree Collapse file tree 6 files changed +49
-51
lines changed Expand file tree Collapse file tree 6 files changed +49
-51
lines changed Original file line number Diff line number Diff line change @@ -4055,7 +4055,7 @@ static int macb_probe(struct platform_device *pdev)
4055
4055
if (mac ) {
4056
4056
ether_addr_copy (bp -> dev -> dev_addr , mac );
4057
4057
} else {
4058
- err = of_get_nvmem_mac_address ( np , bp -> dev -> dev_addr );
4058
+ err = nvmem_get_mac_address ( & pdev -> dev , bp -> dev -> dev_addr );
4059
4059
if (err ) {
4060
4060
if (err == - EPROBE_DEFER )
4061
4061
goto err_out_free_netdev ;
Original file line number Diff line number Diff line change @@ -1912,11 +1912,15 @@ static int davinci_emac_probe(struct platform_device *pdev)
1912
1912
ether_addr_copy (ndev -> dev_addr , priv -> mac_addr );
1913
1913
1914
1914
if (!is_valid_ether_addr (priv -> mac_addr )) {
1915
- /* Use random MAC if none passed */
1916
- eth_hw_addr_random (ndev );
1917
- memcpy (priv -> mac_addr , ndev -> dev_addr , ndev -> addr_len );
1918
- dev_warn (& pdev -> dev , "using random MAC addr: %pM\n" ,
1919
- priv -> mac_addr );
1915
+ /* Try nvmem if MAC wasn't passed over pdata or DT. */
1916
+ rc = nvmem_get_mac_address (& pdev -> dev , priv -> mac_addr );
1917
+ if (rc ) {
1918
+ /* Use random MAC if still none obtained. */
1919
+ eth_hw_addr_random (ndev );
1920
+ memcpy (priv -> mac_addr , ndev -> dev_addr , ndev -> addr_len );
1921
+ dev_warn (& pdev -> dev , "using random MAC addr: %pM\n" ,
1922
+ priv -> mac_addr );
1923
+ }
1920
1924
}
1921
1925
1922
1926
ndev -> netdev_ops = & emac_netdev_ops ;
Original file line number Diff line number Diff line change @@ -81,42 +81,3 @@ const void *of_get_mac_address(struct device_node *np)
81
81
return of_get_mac_addr (np , "address" );
82
82
}
83
83
EXPORT_SYMBOL (of_get_mac_address );
84
-
85
- /**
86
- * Obtain the MAC address from an nvmem provider named 'mac-address' through
87
- * device tree.
88
- * On success, copies the new address into memory pointed to by addr and
89
- * returns 0. Returns a negative error code otherwise.
90
- * @np: Device tree node containing the nvmem-cells phandle
91
- * @addr: Pointer to receive the MAC address using ether_addr_copy()
92
- */
93
- int of_get_nvmem_mac_address (struct device_node * np , void * addr )
94
- {
95
- struct nvmem_cell * cell ;
96
- const void * mac ;
97
- size_t len ;
98
- int ret ;
99
-
100
- cell = of_nvmem_cell_get (np , "mac-address" );
101
- if (IS_ERR (cell ))
102
- return PTR_ERR (cell );
103
-
104
- mac = nvmem_cell_read (cell , & len );
105
-
106
- nvmem_cell_put (cell );
107
-
108
- if (IS_ERR (mac ))
109
- return PTR_ERR (mac );
110
-
111
- if (len < ETH_ALEN || !is_valid_ether_addr (mac )) {
112
- ret = - EINVAL ;
113
- } else {
114
- ether_addr_copy (addr , mac );
115
- ret = 0 ;
116
- }
117
-
118
- kfree (mac );
119
-
120
- return ret ;
121
- }
122
- EXPORT_SYMBOL (of_get_nvmem_mac_address );
Original file line number Diff line number Diff line change 32
32
struct device ;
33
33
int eth_platform_get_mac_address (struct device * dev , u8 * mac_addr );
34
34
unsigned char * arch_get_platform_mac_address (void );
35
+ int nvmem_get_mac_address (struct device * dev , void * addrbuf );
35
36
u32 eth_get_headlen (void * data , unsigned int max_len );
36
37
__be16 eth_type_trans (struct sk_buff * skb , struct net_device * dev );
37
38
extern const struct header_ops eth_header_ops ;
Original file line number Diff line number Diff line change 13
13
struct net_device ;
14
14
extern int of_get_phy_mode (struct device_node * np );
15
15
extern const void * of_get_mac_address (struct device_node * np );
16
- extern int of_get_nvmem_mac_address (struct device_node * np , void * addr );
17
16
extern struct net_device * of_find_net_device_by_node (struct device_node * np );
18
17
#else
19
18
static inline int of_get_phy_mode (struct device_node * np )
@@ -26,11 +25,6 @@ static inline const void *of_get_mac_address(struct device_node *np)
26
25
return NULL ;
27
26
}
28
27
29
- static inline int of_get_nvmem_mac_address (struct device_node * np , void * addr )
30
- {
31
- return - ENODEV ;
32
- }
33
-
34
28
static inline struct net_device * of_find_net_device_by_node (struct device_node * np )
35
29
{
36
30
return NULL ;
Original file line number Diff line number Diff line change 47
47
#include <linux/inet.h>
48
48
#include <linux/ip.h>
49
49
#include <linux/netdevice.h>
50
+ #include <linux/nvmem-consumer.h>
50
51
#include <linux/etherdevice.h>
51
52
#include <linux/skbuff.h>
52
53
#include <linux/errno.h>
@@ -550,3 +551,40 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
550
551
return 0 ;
551
552
}
552
553
EXPORT_SYMBOL (eth_platform_get_mac_address );
554
+
555
+ /**
556
+ * Obtain the MAC address from an nvmem cell named 'mac-address' associated
557
+ * with given device.
558
+ *
559
+ * @dev: Device with which the mac-address cell is associated.
560
+ * @addrbuf: Buffer to which the MAC address will be copied on success.
561
+ *
562
+ * Returns 0 on success or a negative error number on failure.
563
+ */
564
+ int nvmem_get_mac_address (struct device * dev , void * addrbuf )
565
+ {
566
+ struct nvmem_cell * cell ;
567
+ const void * mac ;
568
+ size_t len ;
569
+
570
+ cell = nvmem_cell_get (dev , "mac-address" );
571
+ if (IS_ERR (cell ))
572
+ return PTR_ERR (cell );
573
+
574
+ mac = nvmem_cell_read (cell , & len );
575
+ nvmem_cell_put (cell );
576
+
577
+ if (IS_ERR (mac ))
578
+ return PTR_ERR (mac );
579
+
580
+ if (len != ETH_ALEN || !is_valid_ether_addr (mac )) {
581
+ kfree (mac );
582
+ return - EINVAL ;
583
+ }
584
+
585
+ ether_addr_copy (addrbuf , mac );
586
+ kfree (mac );
587
+
588
+ return 0 ;
589
+ }
590
+ EXPORT_SYMBOL (nvmem_get_mac_address );
You can’t perform that action at this time.
0 commit comments