1 From 0e31738ef78a814fcd2a55f2d57a21d322794da1 Mon Sep 17 00:00:00 2001
2 From: Mathias Kresin <dev@kresin.me>
3 Date: Fri, 26 Aug 2016 09:16:53 +0200
4 Subject: rt2x00: add support for mac addr from device tree
6 On some devices the EEPROMs of Ralink Wi-Fi chips have a default Ralink
7 MAC address set (RT3062F: 00:0C:43:30:62:00, RT3060F:
8 00:0C:43:30:60:00). Using multiple of these devices in the same network
9 can cause nasty issues.
11 Allow to override the MAC in the EEPROM with (a known good) one set in
12 the device tree to bypass the issue.
14 Signed-off-by: Mathias Kresin <dev@kresin.me>
16 drivers/net/wireless/ralink/rt2x00/rt2400pci.c | 5 +----
17 drivers/net/wireless/ralink/rt2x00/rt2500pci.c | 5 +----
18 drivers/net/wireless/ralink/rt2x00/rt2500usb.c | 5 +----
19 drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 5 +----
20 drivers/net/wireless/ralink/rt2x00/rt2x00.h | 1 +
21 drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 16 ++++++++++++++++
22 drivers/net/wireless/ralink/rt2x00/rt61pci.c | 5 +----
23 drivers/net/wireless/ralink/rt2x00/rt73usb.c | 5 +----
24 8 files changed, 23 insertions(+), 24 deletions(-)
26 --- a/drivers/net/wireless/ralink/rt2x00/rt2400pci.c
27 +++ b/drivers/net/wireless/ralink/rt2x00/rt2400pci.c
28 @@ -1459,10 +1459,7 @@ static int rt2400pci_validate_eeprom(str
29 * Start validation of the data that has been read.
31 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
32 - if (!is_valid_ether_addr(mac)) {
33 - eth_random_addr(mac);
34 - rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
36 + rt2x00lib_set_mac_address(rt2x00dev, mac);
38 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
40 --- a/drivers/net/wireless/ralink/rt2x00/rt2500pci.c
41 +++ b/drivers/net/wireless/ralink/rt2x00/rt2500pci.c
42 @@ -1585,10 +1585,7 @@ static int rt2500pci_validate_eeprom(str
43 * Start validation of the data that has been read.
45 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
46 - if (!is_valid_ether_addr(mac)) {
47 - eth_random_addr(mac);
48 - rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
50 + rt2x00lib_set_mac_address(rt2x00dev, mac);
52 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
54 --- a/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
55 +++ b/drivers/net/wireless/ralink/rt2x00/rt2500usb.c
56 @@ -1349,10 +1349,7 @@ static int rt2500usb_validate_eeprom(str
57 * Start validation of the data that has been read.
59 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
60 - if (!is_valid_ether_addr(mac)) {
61 - eth_random_addr(mac);
62 - rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
64 + rt2x00lib_set_mac_address(rt2x00dev, mac);
66 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
68 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
69 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
70 @@ -7531,10 +7531,7 @@ static int rt2800_validate_eeprom(struct
71 * Start validation of the data that has been read.
73 mac = rt2800_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
74 - if (!is_valid_ether_addr(mac)) {
75 - eth_random_addr(mac);
76 - rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
78 + rt2x00lib_set_mac_address(rt2x00dev, mac);
80 rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word);
82 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
83 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
84 @@ -1416,6 +1416,7 @@ static inline void rt2x00debug_dump_fram
86 u32 rt2x00lib_get_bssidx(struct rt2x00_dev *rt2x00dev,
87 struct ieee80211_vif *vif);
88 +void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr);
91 * Interrupt context handlers.
92 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
93 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
95 #include <linux/module.h>
96 #include <linux/slab.h>
97 #include <linux/log2.h>
98 +#include <linux/of.h>
99 +#include <linux/of_net.h>
102 #include "rt2x00lib.h"
103 @@ -931,6 +933,21 @@ static void rt2x00lib_rate(struct ieee80
104 entry->flags |= IEEE80211_RATE_SHORT_PREAMBLE;
107 +void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr)
109 + const char *mac_addr;
111 + mac_addr = of_get_mac_address(rt2x00dev->dev->of_node);
113 + ether_addr_copy(eeprom_mac_addr, mac_addr);
115 + if (!is_valid_ether_addr(eeprom_mac_addr)) {
116 + eth_random_addr(eeprom_mac_addr);
117 + rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", eeprom_mac_addr);
120 +EXPORT_SYMBOL_GPL(rt2x00lib_set_mac_address);
122 static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
123 struct hw_mode_spec *spec)
125 --- a/drivers/net/wireless/ralink/rt2x00/rt61pci.c
126 +++ b/drivers/net/wireless/ralink/rt2x00/rt61pci.c
127 @@ -2413,10 +2413,7 @@ static int rt61pci_validate_eeprom(struc
128 * Start validation of the data that has been read.
130 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
131 - if (!is_valid_ether_addr(mac)) {
132 - eth_random_addr(mac);
133 - rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
135 + rt2x00lib_set_mac_address(rt2x00dev, mac);
137 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
138 if (word == 0xffff) {
139 --- a/drivers/net/wireless/ralink/rt2x00/rt73usb.c
140 +++ b/drivers/net/wireless/ralink/rt2x00/rt73usb.c
141 @@ -1766,10 +1766,7 @@ static int rt73usb_validate_eeprom(struc
142 * Start validation of the data that has been read.
144 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
145 - if (!is_valid_ether_addr(mac)) {
146 - eth_random_addr(mac);
147 - rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
149 + rt2x00lib_set_mac_address(rt2x00dev, mac);
151 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
152 if (word == 0xffff) {