diff mbox series

[04/10] bus/dpaa: implement new of API to get MAC address

Message ID 1529574244-18997-4-git-send-email-hemant.agrawal@nxp.com
State Superseded
Headers show
Series [01/10] bus/dpaa: fix phandle support for kernel 4.16 | expand

Commit Message

Hemant Agrawal June 21, 2018, 9:43 a.m. UTC
From: Akhil Goyal <akhil.goyal@nxp.com>


Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>

---
 drivers/bus/dpaa/base/fman/of.c           | 39 +++++++++++++++++++++++++++++++
 drivers/bus/dpaa/include/of.h             |  2 ++
 drivers/bus/dpaa/rte_bus_dpaa_version.map |  8 +++++++
 3 files changed, 49 insertions(+)

-- 
2.7.4
diff mbox series

Patch

diff --git a/drivers/bus/dpaa/base/fman/of.c b/drivers/bus/dpaa/base/fman/of.c
index eb55cb9..a7f3174 100644
--- a/drivers/bus/dpaa/base/fman/of.c
+++ b/drivers/bus/dpaa/base/fman/of.c
@@ -546,3 +546,42 @@  of_device_is_compatible(const struct device_node *dev_node,
 		return true;
 	return false;
 }
+
+static const void *of_get_mac_addr(const struct device_node *np,
+		const char *name)
+{
+	return of_get_property(np, name, NULL);
+}
+
+/**
+ * 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.
+ *
+ * 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
+ * MAC address.
+ *
+ * All-zero MAC addresses are rejected, because those could be properties that
+ * exist in the device tree, but were not set by U-Boot.  For example, the
+ * DTS could define 'mac-address' and 'local-mac-address', with zero MAC
+ * addresses.  Some older U-Boots only initialized 'local-mac-address'.  In
+ * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
+ * but is all zeros.
+ */
+const void *of_get_mac_address(const struct device_node *np)
+{
+	const void *addr;
+
+	addr = of_get_mac_addr(np, "mac-address");
+	if (addr)
+		return addr;
+
+	addr = of_get_mac_addr(np, "local-mac-address");
+	if (addr)
+		return addr;
+
+	return of_get_mac_addr(np, "address");
+}
diff --git a/drivers/bus/dpaa/include/of.h b/drivers/bus/dpaa/include/of.h
index 151be5a..7ea7608 100644
--- a/drivers/bus/dpaa/include/of.h
+++ b/drivers/bus/dpaa/include/of.h
@@ -109,6 +109,8 @@  const struct device_node *of_get_parent(const struct device_node *dev_node);
 const struct device_node *of_get_next_child(const struct device_node *dev_node,
 					    const struct device_node *prev);
 
+const void *of_get_mac_address(const struct device_node *np);
+
 #define for_each_child_node(parent, child) \
 	for (child = of_get_next_child(parent, NULL); child != NULL; \
 			child = of_get_next_child(parent, child))
diff --git a/drivers/bus/dpaa/rte_bus_dpaa_version.map b/drivers/bus/dpaa/rte_bus_dpaa_version.map
index 8d90285..e00c911 100644
--- a/drivers/bus/dpaa/rte_bus_dpaa_version.map
+++ b/drivers/bus/dpaa/rte_bus_dpaa_version.map
@@ -92,3 +92,11 @@  DPDK_18.02 {
 
 	local: *;
 } DPDK_17.11;
+
+DPDK_18.08 {
+	global:
+
+	of_get_mac_address;
+
+	local: *;
+} DPDK_18.02;