]> git.karo-electronics.de Git - linux-beck.git/commitdiff
rt2x00: add support for mac addr from device tree
authorMathias Kresin <dev@kresin.me>
Fri, 26 Aug 2016 07:16:53 +0000 (09:16 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Wed, 9 Nov 2016 01:28:31 +0000 (03:28 +0200)
On some devices the EEPROMs of Ralink Wi-Fi chips have a default Ralink
MAC address set (RT3062F: 00:0C:43:30:62:00, RT3060F:
00:0C:43:30:60:00). Using multiple of these devices in the same network
can cause nasty issues.

Allow to override the MAC in the EEPROM with (a known good) one set in
the device tree to bypass the issue.

Signed-off-by: Mathias Kresin <dev@kresin.me>
Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/ralink/rt2x00/rt2400pci.c
drivers/net/wireless/ralink/rt2x00/rt2500pci.c
drivers/net/wireless/ralink/rt2x00/rt2500usb.c
drivers/net/wireless/ralink/rt2x00/rt2800lib.c
drivers/net/wireless/ralink/rt2x00/rt2x00.h
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
drivers/net/wireless/ralink/rt2x00/rt61pci.c
drivers/net/wireless/ralink/rt2x00/rt73usb.c

index 155f343981fe29679d278b0621d3cf7ce64b2a77..085c5b423bdfa8e4992be6b12047b3b86191a375 100644 (file)
@@ -1459,10 +1459,7 @@ static int rt2400pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
         * Start validation of the data that has been read.
         */
        mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
-       if (!is_valid_ether_addr(mac)) {
-               eth_random_addr(mac);
-               rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
-       }
+       rt2x00lib_set_mac_address(rt2x00dev, mac);
 
        rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
        if (word == 0xffff) {
index 2553cdd7406623cde30a99531e4d86a74ae4836e..9832fd50c7935e39c27653b1ad935ab6dd0176fc 100644 (file)
@@ -1585,10 +1585,7 @@ static int rt2500pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
         * Start validation of the data that has been read.
         */
        mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
-       if (!is_valid_ether_addr(mac)) {
-               eth_random_addr(mac);
-               rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
-       }
+       rt2x00lib_set_mac_address(rt2x00dev, mac);
 
        rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
        if (word == 0xffff) {
index 2d64611de300146d98bcc254171f961e3af26831..cd3ab5a9e98da6d25d8d978b28d593afe0033818 100644 (file)
@@ -1349,10 +1349,7 @@ static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
         * Start validation of the data that has been read.
         */
        mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
-       if (!is_valid_ether_addr(mac)) {
-               eth_random_addr(mac);
-               rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
-       }
+       rt2x00lib_set_mac_address(rt2x00dev, mac);
 
        rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
        if (word == 0xffff) {
index bf3f0a39908c816efa508db2458ec276a15679a1..59c49af217458b74612f18ff581e48fef9e03441 100644 (file)
@@ -6919,10 +6919,7 @@ static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
         * Start validation of the data that has been read.
         */
        mac = rt2800_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
-       if (!is_valid_ether_addr(mac)) {
-               eth_random_addr(mac);
-               rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
-       }
+       rt2x00lib_set_mac_address(rt2x00dev, mac);
 
        rt2800_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word);
        if (word == 0xffff) {
index f68d492129c6f7189e5116486ffbd2c97c866ec2..aa3d4ceef4adf57bc1dde39099c90cca01c39067 100644 (file)
@@ -1403,6 +1403,7 @@ static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  */
 u32 rt2x00lib_get_bssidx(struct rt2x00_dev *rt2x00dev,
                         struct ieee80211_vif *vif);
+void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr);
 
 /*
  * Interrupt context handlers.
index 4e0c5653054bbdc9d313872760c2994f681fd191..d659250613606baeb13fc92d1cc7cbd699fb63ec 100644 (file)
@@ -26,6 +26,8 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/log2.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
 
 #include "rt2x00.h"
 #include "rt2x00lib.h"
@@ -931,6 +933,21 @@ static void rt2x00lib_rate(struct ieee80211_rate *entry,
                entry->flags |= IEEE80211_RATE_SHORT_PREAMBLE;
 }
 
+void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr)
+{
+       const char *mac_addr;
+
+       mac_addr = of_get_mac_address(rt2x00dev->dev->of_node);
+       if (mac_addr)
+               ether_addr_copy(eeprom_mac_addr, mac_addr);
+
+       if (!is_valid_ether_addr(eeprom_mac_addr)) {
+               eth_random_addr(eeprom_mac_addr);
+               rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", eeprom_mac_addr);
+       }
+}
+EXPORT_SYMBOL_GPL(rt2x00lib_set_mac_address);
+
 static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
                                    struct hw_mode_spec *spec)
 {
index 03013eb2f6429d89d96c01013d4ac4a5213b1550..5306a3b2622d0233b2114ab1b1c14217cd2e11fd 100644 (file)
@@ -2413,10 +2413,7 @@ static int rt61pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
         * Start validation of the data that has been read.
         */
        mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
-       if (!is_valid_ether_addr(mac)) {
-               eth_random_addr(mac);
-               rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
-       }
+       rt2x00lib_set_mac_address(rt2x00dev, mac);
 
        rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
        if (word == 0xffff) {
index c1397a6d3cee06b7df0fb216a5f7047adfd0caa1..1a29c4d205a5ec6272371940185efe07848eb7d2 100644 (file)
@@ -1766,10 +1766,7 @@ static int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
         * Start validation of the data that has been read.
         */
        mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
-       if (!is_valid_ether_addr(mac)) {
-               eth_random_addr(mac);
-               rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
-       }
+       rt2x00lib_set_mac_address(rt2x00dev, mac);
 
        rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
        if (word == 0xffff) {