]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
of/net: Move of_get_mac_address() to a common source file.
authorDavid Daney <ddaney@caviumnetworks.com>
Tue, 26 Oct 2010 22:07:13 +0000 (15:07 -0700)
committerGrant Likely <grant.likely@secretlab.ca>
Mon, 1 Nov 2010 05:08:14 +0000 (01:08 -0400)
There are two identical implementations of of_get_mac_address(), one
each in arch/powerpc/kernel/prom_parse.c and
arch/microblaze/kernel/prom_parse.c.  Move this function to a new
common file of_net.{c,h} and adjust all the callers to include the new
header.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
[grant.likely@secretlab.ca: protect header with #ifdef]
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
14 files changed:
arch/microblaze/include/asm/prom.h
arch/microblaze/kernel/prom_parse.c
arch/powerpc/include/asm/prom.h
arch/powerpc/kernel/prom_parse.c
arch/powerpc/sysdev/mv64x60_dev.c
arch/powerpc/sysdev/tsi108_dev.c
drivers/net/fs_enet/fs_enet-main.c
drivers/net/gianfar.c
drivers/net/ucc_geth.c
drivers/net/xilinx_emaclite.c
drivers/of/Kconfig
drivers/of/Makefile
drivers/of/of_net.c [new file with mode: 0644]
include/linux/of_net.h [new file with mode: 0644]

index bdc38312ae4ae00b677328c1eab1524f3cfd75a8..2e72af078b059dadd7512967aa14d6bf51d0bd0f 100644 (file)
@@ -64,9 +64,6 @@ extern void kdump_move_device_tree(void);
 /* CPU OF node matching */
 struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
 
-/* Get the MAC address */
-extern const void *of_get_mac_address(struct device_node *np);
-
 /**
  * of_irq_map_pci - Resolve the interrupt for a PCI device
  * @pdev:      the device whose interrupt is to be resolved
index 99d9b61cccb592cb34985bf79fb777b0521a36bf..9ae24f4b882bfe792e6657c867c8af32b00908ee 100644 (file)
@@ -110,41 +110,3 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
        cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
        *size = of_read_number(dma_window, cells);
 }
-
-/**
- * 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(struct device_node *np)
-{
-       struct property *pp;
-
-       pp = of_find_property(np, "mac-address", NULL);
-       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-               return pp->value;
-
-       pp = of_find_property(np, "local-mac-address", NULL);
-       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-               return pp->value;
-
-       pp = of_find_property(np, "address", NULL);
-       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-               return pp->value;
-
-       return NULL;
-}
-EXPORT_SYMBOL(of_get_mac_address);
index ae26f2efd089c80d92f0c9b50ea434dd43464f91..98264bf0a433a3c2ed77e8914b129c5a10a8b765 100644 (file)
@@ -63,9 +63,6 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
 /* cache lookup */
 struct device_node *of_find_next_cache_node(struct device_node *np);
 
-/* Get the MAC address */
-extern const void *of_get_mac_address(struct device_node *np);
-
 #ifdef CONFIG_NUMA
 extern int of_node_to_nid(struct device_node *device);
 #else
index 88334af038e58453dc2fc8d5cbb12bad0fc175e9..c2b7a07cc3d3f54aeb22f7abe061c3ab6943708c 100644 (file)
@@ -117,41 +117,3 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
        cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
        *size = of_read_number(dma_window, cells);
 }
-
-/**
- * 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(struct device_node *np)
-{
-       struct property *pp;
-
-       pp = of_find_property(np, "mac-address", NULL);
-       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-               return pp->value;
-
-       pp = of_find_property(np, "local-mac-address", NULL);
-       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-               return pp->value;
-
-       pp = of_find_property(np, "address", NULL);
-       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-               return pp->value;
-
-       return NULL;
-}
-EXPORT_SYMBOL(of_get_mac_address);
index 1398bc454999b2b10fae54972e5e92c69689b3eb..feaee402e2d6ff6e43dbb9c4d9dd3c10b05c72d1 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/mv643xx.h>
 #include <linux/platform_device.h>
 #include <linux/of_platform.h>
+#include <linux/of_net.h>
 #include <linux/dma-mapping.h>
 
 #include <asm/prom.h>
index d4d15aaf18fabaeef8f13dc2f1b790b0c96458aa..c2d675b6392cb0b050eb82c16b74a46dd6aa4a90 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
+#include <linux/of_net.h>
 #include <asm/tsi108.h>
 
 #include <asm/system.h>
index d684f187de57714f4b38a2e7e8bf58771234d0a5..7a1f3d0ffa789918b75419741824b24fd84e4e10 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 #include <linux/of_gpio.h>
+#include <linux/of_net.h>
 
 #include <linux/vmalloc.h>
 #include <asm/pgtable.h>
index 49e4ce1246a75e01c30a623de0031707fe0273c9..f860072e2f6804c4a6f4ec5d7c4b7b7fa7f444e9 100644 (file)
@@ -95,6 +95,7 @@
 #include <linux/phy.h>
 #include <linux/phy_fixed.h>
 #include <linux/of.h>
+#include <linux/of_net.h>
 
 #include "gianfar.h"
 #include "fsl_pq_mdio.h"
index a4c3f5708246e9038ac716c4b8e9b7b06abeb28e..f7e370fd8ddc36e4361851fc7f0e0966879231dc 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/phy.h>
 #include <linux/workqueue.h>
 #include <linux/of_mdio.h>
+#include <linux/of_net.h>
 #include <linux/of_platform.h>
 
 #include <asm/uaccess.h>
index 14f0955eca68b37ed8f776fd83390339cacf1351..2a34b22ea26a5363663ab5aa38f38dd265173df7 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
 #include <linux/of_mdio.h>
+#include <linux/of_net.h>
 #include <linux/phy.h>
 
 #define DRIVER_NAME "xilinx_emaclite"
index aa675ebd8eb3cd9636de7b69add0cfe73a134995..e4b93a0a15d2c13d310bd1f831eb14985f6880fb 100644 (file)
@@ -49,6 +49,10 @@ config OF_I2C
        help
          OpenFirmware I2C accessors
 
+config OF_NET
+       depends on NETDEVICES
+       def_bool y
+
 config OF_SPI
        def_tristate SPI
        depends on SPI && !SPARC
index 7888155bea08dacb3317c0d25cc66a34a0d952ed..3ab21a0a4907defc5c3470f40c1d0ed74d6db731 100644 (file)
@@ -6,5 +6,6 @@ obj-$(CONFIG_OF_IRQ)    += irq.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
 obj-$(CONFIG_OF_I2C)   += of_i2c.o
+obj-$(CONFIG_OF_NET)   += of_net.o
 obj-$(CONFIG_OF_SPI)   += of_spi.o
 obj-$(CONFIG_OF_MDIO)  += of_mdio.o
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
new file mode 100644 (file)
index 0000000..86f334a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * OF helpers for network devices.
+ *
+ * This file is released under the GPLv2
+ *
+ * Initially copied out of arch/powerpc/kernel/prom_parse.c
+ */
+#include <linux/etherdevice.h>
+#include <linux/kernel.h>
+#include <linux/of_net.h>
+
+/**
+ * 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(struct device_node *np)
+{
+       struct property *pp;
+
+       pp = of_find_property(np, "mac-address", NULL);
+       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
+               return pp->value;
+
+       pp = of_find_property(np, "local-mac-address", NULL);
+       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
+               return pp->value;
+
+       pp = of_find_property(np, "address", NULL);
+       if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
+               return pp->value;
+
+       return NULL;
+}
+EXPORT_SYMBOL(of_get_mac_address);
diff --git a/include/linux/of_net.h b/include/linux/of_net.h
new file mode 100644 (file)
index 0000000..e913081
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * OF helpers for network devices.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_NET_H
+#define __LINUX_OF_NET_H
+
+#ifdef CONFIG_OF_NET
+#include <linux/of.h>
+extern const void *of_get_mac_address(struct device_node *np);
+#endif
+
+#endif /* __LINUX_OF_NET_H */