diff options
| author | David Daney <ddaney@caviumnetworks.com> | 2010-10-26 18:07:13 -0400 |
|---|---|---|
| committer | Grant Likely <grant.likely@secretlab.ca> | 2010-11-01 01:08:14 -0400 |
| commit | 4b6ba8aacbb3185703b797286547d0f8f3859b02 (patch) | |
| tree | f4e04c3b19d6bf7c7429c0cf678c534838e2990d | |
| parent | 3985c7ce85039adacdf882904ca096f091d39346 (diff) | |
of/net: Move of_get_mac_address() to a common source file.
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>
| -rw-r--r-- | arch/microblaze/include/asm/prom.h | 3 | ||||
| -rw-r--r-- | arch/microblaze/kernel/prom_parse.c | 38 | ||||
| -rw-r--r-- | arch/powerpc/include/asm/prom.h | 3 | ||||
| -rw-r--r-- | arch/powerpc/kernel/prom_parse.c | 38 | ||||
| -rw-r--r-- | arch/powerpc/sysdev/mv64x60_dev.c | 1 | ||||
| -rw-r--r-- | arch/powerpc/sysdev/tsi108_dev.c | 1 | ||||
| -rw-r--r-- | drivers/net/fs_enet/fs_enet-main.c | 1 | ||||
| -rw-r--r-- | drivers/net/gianfar.c | 1 | ||||
| -rw-r--r-- | drivers/net/ucc_geth.c | 1 | ||||
| -rw-r--r-- | drivers/net/xilinx_emaclite.c | 1 | ||||
| -rw-r--r-- | drivers/of/Kconfig | 4 | ||||
| -rw-r--r-- | drivers/of/Makefile | 1 | ||||
| -rw-r--r-- | drivers/of/of_net.c | 48 | ||||
| -rw-r--r-- | include/linux/of_net.h | 15 |
14 files changed, 74 insertions, 82 deletions
diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h index bdc38312ae4a..2e72af078b05 100644 --- a/arch/microblaze/include/asm/prom.h +++ b/arch/microblaze/include/asm/prom.h | |||
| @@ -64,9 +64,6 @@ extern void kdump_move_device_tree(void); | |||
| 64 | /* CPU OF node matching */ | 64 | /* CPU OF node matching */ |
| 65 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); | 65 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); |
| 66 | 66 | ||
| 67 | /* Get the MAC address */ | ||
| 68 | extern const void *of_get_mac_address(struct device_node *np); | ||
| 69 | |||
| 70 | /** | 67 | /** |
| 71 | * of_irq_map_pci - Resolve the interrupt for a PCI device | 68 | * of_irq_map_pci - Resolve the interrupt for a PCI device |
| 72 | * @pdev: the device whose interrupt is to be resolved | 69 | * @pdev: the device whose interrupt is to be resolved |
diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c index 99d9b61cccb5..9ae24f4b882b 100644 --- a/arch/microblaze/kernel/prom_parse.c +++ b/arch/microblaze/kernel/prom_parse.c | |||
| @@ -110,41 +110,3 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, | |||
| 110 | cells = prop ? *(u32 *)prop : of_n_size_cells(dn); | 110 | cells = prop ? *(u32 *)prop : of_n_size_cells(dn); |
| 111 | *size = of_read_number(dma_window, cells); | 111 | *size = of_read_number(dma_window, cells); |
| 112 | } | 112 | } |
| 113 | |||
| 114 | /** | ||
| 115 | * Search the device tree for the best MAC address to use. 'mac-address' is | ||
| 116 | * checked first, because that is supposed to contain to "most recent" MAC | ||
| 117 | * address. If that isn't set, then 'local-mac-address' is checked next, | ||
| 118 | * because that is the default address. If that isn't set, then the obsolete | ||
| 119 | * 'address' is checked, just in case we're using an old device tree. | ||
| 120 | * | ||
| 121 | * Note that the 'address' property is supposed to contain a virtual address of | ||
| 122 | * the register set, but some DTS files have redefined that property to be the | ||
| 123 | * MAC address. | ||
| 124 | * | ||
| 125 | * All-zero MAC addresses are rejected, because those could be properties that | ||
| 126 | * exist in the device tree, but were not set by U-Boot. For example, the | ||
| 127 | * DTS could define 'mac-address' and 'local-mac-address', with zero MAC | ||
| 128 | * addresses. Some older U-Boots only initialized 'local-mac-address'. In | ||
| 129 | * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists | ||
| 130 | * but is all zeros. | ||
| 131 | */ | ||
| 132 | const void *of_get_mac_address(struct device_node *np) | ||
| 133 | { | ||
| 134 | struct property *pp; | ||
| 135 | |||
| 136 | pp = of_find_property(np, "mac-address", NULL); | ||
| 137 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 138 | return pp->value; | ||
| 139 | |||
| 140 | pp = of_find_property(np, "local-mac-address", NULL); | ||
| 141 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 142 | return pp->value; | ||
| 143 | |||
| 144 | pp = of_find_property(np, "address", NULL); | ||
| 145 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 146 | return pp->value; | ||
| 147 | |||
| 148 | return NULL; | ||
| 149 | } | ||
| 150 | EXPORT_SYMBOL(of_get_mac_address); | ||
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h index ae26f2efd089..98264bf0a433 100644 --- a/arch/powerpc/include/asm/prom.h +++ b/arch/powerpc/include/asm/prom.h | |||
| @@ -63,9 +63,6 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); | |||
| 63 | /* cache lookup */ | 63 | /* cache lookup */ |
| 64 | struct device_node *of_find_next_cache_node(struct device_node *np); | 64 | struct device_node *of_find_next_cache_node(struct device_node *np); |
| 65 | 65 | ||
| 66 | /* Get the MAC address */ | ||
| 67 | extern const void *of_get_mac_address(struct device_node *np); | ||
| 68 | |||
| 69 | #ifdef CONFIG_NUMA | 66 | #ifdef CONFIG_NUMA |
| 70 | extern int of_node_to_nid(struct device_node *device); | 67 | extern int of_node_to_nid(struct device_node *device); |
| 71 | #else | 68 | #else |
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c index 88334af038e5..c2b7a07cc3d3 100644 --- a/arch/powerpc/kernel/prom_parse.c +++ b/arch/powerpc/kernel/prom_parse.c | |||
| @@ -117,41 +117,3 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, | |||
| 117 | cells = prop ? *(u32 *)prop : of_n_size_cells(dn); | 117 | cells = prop ? *(u32 *)prop : of_n_size_cells(dn); |
| 118 | *size = of_read_number(dma_window, cells); | 118 | *size = of_read_number(dma_window, cells); |
| 119 | } | 119 | } |
| 120 | |||
| 121 | /** | ||
| 122 | * Search the device tree for the best MAC address to use. 'mac-address' is | ||
| 123 | * checked first, because that is supposed to contain to "most recent" MAC | ||
| 124 | * address. If that isn't set, then 'local-mac-address' is checked next, | ||
| 125 | * because that is the default address. If that isn't set, then the obsolete | ||
| 126 | * 'address' is checked, just in case we're using an old device tree. | ||
| 127 | * | ||
| 128 | * Note that the 'address' property is supposed to contain a virtual address of | ||
| 129 | * the register set, but some DTS files have redefined that property to be the | ||
| 130 | * MAC address. | ||
| 131 | * | ||
| 132 | * All-zero MAC addresses are rejected, because those could be properties that | ||
| 133 | * exist in the device tree, but were not set by U-Boot. For example, the | ||
| 134 | * DTS could define 'mac-address' and 'local-mac-address', with zero MAC | ||
| 135 | * addresses. Some older U-Boots only initialized 'local-mac-address'. In | ||
| 136 | * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists | ||
| 137 | * but is all zeros. | ||
| 138 | */ | ||
| 139 | const void *of_get_mac_address(struct device_node *np) | ||
| 140 | { | ||
| 141 | struct property *pp; | ||
| 142 | |||
| 143 | pp = of_find_property(np, "mac-address", NULL); | ||
| 144 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 145 | return pp->value; | ||
| 146 | |||
| 147 | pp = of_find_property(np, "local-mac-address", NULL); | ||
| 148 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 149 | return pp->value; | ||
| 150 | |||
| 151 | pp = of_find_property(np, "address", NULL); | ||
| 152 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 153 | return pp->value; | ||
| 154 | |||
| 155 | return NULL; | ||
| 156 | } | ||
| 157 | EXPORT_SYMBOL(of_get_mac_address); | ||
diff --git a/arch/powerpc/sysdev/mv64x60_dev.c b/arch/powerpc/sysdev/mv64x60_dev.c index 1398bc454999..feaee402e2d6 100644 --- a/arch/powerpc/sysdev/mv64x60_dev.c +++ b/arch/powerpc/sysdev/mv64x60_dev.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/mv643xx.h> | 16 | #include <linux/mv643xx.h> |
| 17 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/of_platform.h> | 18 | #include <linux/of_platform.h> |
| 19 | #include <linux/of_net.h> | ||
| 19 | #include <linux/dma-mapping.h> | 20 | #include <linux/dma-mapping.h> |
| 20 | 21 | ||
| 21 | #include <asm/prom.h> | 22 | #include <asm/prom.h> |
diff --git a/arch/powerpc/sysdev/tsi108_dev.c b/arch/powerpc/sysdev/tsi108_dev.c index d4d15aaf18fa..c2d675b6392c 100644 --- a/arch/powerpc/sysdev/tsi108_dev.c +++ b/arch/powerpc/sysdev/tsi108_dev.c | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
| 20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
| 21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/of_net.h> | ||
| 22 | #include <asm/tsi108.h> | 23 | #include <asm/tsi108.h> |
| 23 | 24 | ||
| 24 | #include <asm/system.h> | 25 | #include <asm/system.h> |
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c index d684f187de57..7a1f3d0ffa78 100644 --- a/drivers/net/fs_enet/fs_enet-main.c +++ b/drivers/net/fs_enet/fs_enet-main.c | |||
| @@ -40,6 +40,7 @@ | |||
| 40 | #include <linux/of_mdio.h> | 40 | #include <linux/of_mdio.h> |
| 41 | #include <linux/of_platform.h> | 41 | #include <linux/of_platform.h> |
| 42 | #include <linux/of_gpio.h> | 42 | #include <linux/of_gpio.h> |
| 43 | #include <linux/of_net.h> | ||
| 43 | 44 | ||
| 44 | #include <linux/vmalloc.h> | 45 | #include <linux/vmalloc.h> |
| 45 | #include <asm/pgtable.h> | 46 | #include <asm/pgtable.h> |
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c index 49e4ce1246a7..f860072e2f68 100644 --- a/drivers/net/gianfar.c +++ b/drivers/net/gianfar.c | |||
| @@ -95,6 +95,7 @@ | |||
| 95 | #include <linux/phy.h> | 95 | #include <linux/phy.h> |
| 96 | #include <linux/phy_fixed.h> | 96 | #include <linux/phy_fixed.h> |
| 97 | #include <linux/of.h> | 97 | #include <linux/of.h> |
| 98 | #include <linux/of_net.h> | ||
| 98 | 99 | ||
| 99 | #include "gianfar.h" | 100 | #include "gianfar.h" |
| 100 | #include "fsl_pq_mdio.h" | 101 | #include "fsl_pq_mdio.h" |
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c index a4c3f5708246..f7e370fd8ddc 100644 --- a/drivers/net/ucc_geth.c +++ b/drivers/net/ucc_geth.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #include <linux/phy.h> | 28 | #include <linux/phy.h> |
| 29 | #include <linux/workqueue.h> | 29 | #include <linux/workqueue.h> |
| 30 | #include <linux/of_mdio.h> | 30 | #include <linux/of_mdio.h> |
| 31 | #include <linux/of_net.h> | ||
| 31 | #include <linux/of_platform.h> | 32 | #include <linux/of_platform.h> |
| 32 | 33 | ||
| 33 | #include <asm/uaccess.h> | 34 | #include <asm/uaccess.h> |
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index 14f0955eca68..2a34b22ea26a 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <linux/of_device.h> | 24 | #include <linux/of_device.h> |
| 25 | #include <linux/of_platform.h> | 25 | #include <linux/of_platform.h> |
| 26 | #include <linux/of_mdio.h> | 26 | #include <linux/of_mdio.h> |
| 27 | #include <linux/of_net.h> | ||
| 27 | #include <linux/phy.h> | 28 | #include <linux/phy.h> |
| 28 | 29 | ||
| 29 | #define DRIVER_NAME "xilinx_emaclite" | 30 | #define DRIVER_NAME "xilinx_emaclite" |
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index aa675ebd8eb3..e4b93a0a15d2 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig | |||
| @@ -49,6 +49,10 @@ config OF_I2C | |||
| 49 | help | 49 | help |
| 50 | OpenFirmware I2C accessors | 50 | OpenFirmware I2C accessors |
| 51 | 51 | ||
| 52 | config OF_NET | ||
| 53 | depends on NETDEVICES | ||
| 54 | def_bool y | ||
| 55 | |||
| 52 | config OF_SPI | 56 | config OF_SPI |
| 53 | def_tristate SPI | 57 | def_tristate SPI |
| 54 | depends on SPI && !SPARC | 58 | depends on SPI && !SPARC |
diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 7888155bea08..3ab21a0a4907 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile | |||
| @@ -6,5 +6,6 @@ obj-$(CONFIG_OF_IRQ) += irq.o | |||
| 6 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o | 6 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o |
| 7 | obj-$(CONFIG_OF_GPIO) += gpio.o | 7 | obj-$(CONFIG_OF_GPIO) += gpio.o |
| 8 | obj-$(CONFIG_OF_I2C) += of_i2c.o | 8 | obj-$(CONFIG_OF_I2C) += of_i2c.o |
| 9 | obj-$(CONFIG_OF_NET) += of_net.o | ||
| 9 | obj-$(CONFIG_OF_SPI) += of_spi.o | 10 | obj-$(CONFIG_OF_SPI) += of_spi.o |
| 10 | obj-$(CONFIG_OF_MDIO) += of_mdio.o | 11 | 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 index 000000000000..86f334a2769c --- /dev/null +++ b/drivers/of/of_net.c | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | /* | ||
| 2 | * OF helpers for network devices. | ||
| 3 | * | ||
| 4 | * This file is released under the GPLv2 | ||
| 5 | * | ||
| 6 | * Initially copied out of arch/powerpc/kernel/prom_parse.c | ||
| 7 | */ | ||
| 8 | #include <linux/etherdevice.h> | ||
| 9 | #include <linux/kernel.h> | ||
| 10 | #include <linux/of_net.h> | ||
| 11 | |||
| 12 | /** | ||
| 13 | * Search the device tree for the best MAC address to use. 'mac-address' is | ||
| 14 | * checked first, because that is supposed to contain to "most recent" MAC | ||
| 15 | * address. If that isn't set, then 'local-mac-address' is checked next, | ||
| 16 | * because that is the default address. If that isn't set, then the obsolete | ||
| 17 | * 'address' is checked, just in case we're using an old device tree. | ||
| 18 | * | ||
| 19 | * Note that the 'address' property is supposed to contain a virtual address of | ||
| 20 | * the register set, but some DTS files have redefined that property to be the | ||
| 21 | * MAC address. | ||
| 22 | * | ||
| 23 | * All-zero MAC addresses are rejected, because those could be properties that | ||
| 24 | * exist in the device tree, but were not set by U-Boot. For example, the | ||
| 25 | * DTS could define 'mac-address' and 'local-mac-address', with zero MAC | ||
| 26 | * addresses. Some older U-Boots only initialized 'local-mac-address'. In | ||
| 27 | * this case, the real MAC is in 'local-mac-address', and 'mac-address' exists | ||
| 28 | * but is all zeros. | ||
| 29 | */ | ||
| 30 | const void *of_get_mac_address(struct device_node *np) | ||
| 31 | { | ||
| 32 | struct property *pp; | ||
| 33 | |||
| 34 | pp = of_find_property(np, "mac-address", NULL); | ||
| 35 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 36 | return pp->value; | ||
| 37 | |||
| 38 | pp = of_find_property(np, "local-mac-address", NULL); | ||
| 39 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 40 | return pp->value; | ||
| 41 | |||
| 42 | pp = of_find_property(np, "address", NULL); | ||
| 43 | if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) | ||
| 44 | return pp->value; | ||
| 45 | |||
| 46 | return NULL; | ||
| 47 | } | ||
| 48 | EXPORT_SYMBOL(of_get_mac_address); | ||
diff --git a/include/linux/of_net.h b/include/linux/of_net.h new file mode 100644 index 000000000000..e913081fb52a --- /dev/null +++ b/include/linux/of_net.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | /* | ||
| 2 | * OF helpers for network devices. | ||
| 3 | * | ||
| 4 | * This file is released under the GPLv2 | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef __LINUX_OF_NET_H | ||
| 8 | #define __LINUX_OF_NET_H | ||
| 9 | |||
| 10 | #ifdef CONFIG_OF_NET | ||
| 11 | #include <linux/of.h> | ||
| 12 | extern const void *of_get_mac_address(struct device_node *np); | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #endif /* __LINUX_OF_NET_H */ | ||
