[PATCH 1/2] net: add option to ignore 'local-mac-address' property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Leon M. Busch-George" <leon@xxxxxxxxxxxxx>

Here is the definition of a mac that looks like its address would be
loaded from nvmem:

  mac@0 {
    compatible = "mediatek,eth-mac";
    reg = <0>;
    phy-mode = "2500base-x";
    phy-handle = <&rtl8221b_phy>;

    nvmem-cell-names = "mac-address";
    nvmem-cells = <&macaddr_bdinfo_de00 1>; /* this is ignored */
  };

Because the boot program inserts a 'local-mac-address', which is preferred
over other detection methods, the definition using nvmem is ignored.
By itself, that is only a mild annoyance when dealing with device trees.
After all, the 'local-mac-address' property exists primarily to pass MAC
addresses to the kernel.

But it is also possible for this address to be randomly generated (on each
boot), which turns an annoyance into a hindrance. In such a case, it is no
longer possible to set the correct address from the device tree. This
behaviour has been observed on two types of MT7981B devices from different
vendors (Cudy M3000, Yuncore AX835).

Restore the ability to set addresses through the device tree by adding an
option to ignore the 'local-mac-address' property.

Signed-off-by: Leon M. Busch-George <leon@xxxxxxxxxxxxx>
---
 net/core/of_net.c  | 18 ++++++++++--------
 net/ethernet/eth.c | 10 ++++++----
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/net/core/of_net.c b/net/core/of_net.c
index 93ea425b9248..4cf4171bc7fe 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -104,11 +104,11 @@ EXPORT_SYMBOL(of_get_mac_address_nvmem);
  *
  * Search the device tree for the best MAC address to use.  'mac-address' is
  * checked first, because that is supposed to contain to "most recent" MAC
- * address. If that isn't set, then 'local-mac-address' is checked next,
- * because that is the default address. If that isn't set, then the obsolete
- * 'address' is checked, just in case we're using an old device tree. If any
- * of the above isn't set, then try to get MAC address from nvmem cell named
- * 'mac-address'.
+ * address. If there is no valid 'mac-address' and `ignore-local-mac-address'
+ * isn't set, then 'local-mac-address' is checked next, because that is the
+ * default address. If that isn't set, then the obsolete * 'address' is
+ * checked, just in case we're using an old device tree. If any of the above
+ * isn't set, then try to get MAC address from nvmem cell named 'mac-address'.
  *
  * Note that the 'address' property is supposed to contain a virtual address of
  * the register set, but some DTS files have redefined that property to be the
@@ -134,9 +134,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
 	if (!ret)
 		return 0;
 
-	ret = of_get_mac_addr(np, "local-mac-address", addr);
-	if (!ret)
-		return 0;
+	if (!of_find_property(np, "ignore-local-mac-address", NULL)) {
+		ret = of_get_mac_addr(np, "local-mac-address", addr);
+		if (!ret)
+			return 0;
+	}
 
 	ret = of_get_mac_addr(np, "address", addr);
 	if (!ret)
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 049c3adeb850..8f4efba90d96 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -582,9 +582,10 @@ static int fwnode_get_mac_addr(struct fwnode_handle *fwnode,
  *
  * Search the firmware node for the best MAC address to use.  'mac-address' is
  * checked first, because that is supposed to contain to "most recent" MAC
- * address. If that isn't set, then 'local-mac-address' is checked next,
- * because that is the default address.  If that isn't set, then the obsolete
- * 'address' is checked, just in case we're using an old device tree.
+ * address. If there is no valid 'mac-address' and `ignore-local-mac-address'
+ * isn't set, then 'local-mac-address' is checked next, because that is the
+ * default address. If that isn't set, then the obsolete 'address' is checked,
+ * just in case we're using an old device tree.
  *
  * Note that the 'address' property is supposed to contain a virtual address of
  * the register set, but some DTS files have redefined that property to be the
@@ -600,7 +601,8 @@ static int fwnode_get_mac_addr(struct fwnode_handle *fwnode,
 int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr)
 {
 	if (!fwnode_get_mac_addr(fwnode, "mac-address", addr) ||
-	    !fwnode_get_mac_addr(fwnode, "local-mac-address", addr) ||
+	    (!fwnode_property_present(fwnode, "ignore-local-mac-address") &&
+	      !fwnode_get_mac_addr(fwnode, "local-mac-address", addr)) ||
 	    !fwnode_get_mac_addr(fwnode, "address", addr))
 		return 0;
 
-- 
2.44.0





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux