* [PATCH v2 0/3] MIPS: OCTEON: fill mac addresses with appended DTB
@ 2016-02-23 22:52 Aaro Koskinen
2016-02-23 22:52 ` [PATCH v2 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Aaro Koskinen @ 2016-02-23 22:52 UTC (permalink / raw)
To: Ralf Baechle, David Daney, linux-mips; +Cc: Aaro Koskinen
Hi,
When using appended DTB, the MAC addresses should be filled in
from the bootinfo.
v2: Use is_valid_ether_addr()
Added Acked-bys.
A.
Aaro Koskinen (3):
MIPS: OCTEON: device_tree_init: use separate pass to fill mac
addresses
MIPS: OCTEON: device_tree_init: don't fill mac if already set
MIPS: OCTEON: device_tree_init: fill mac addresses when using appended
dtb
arch/mips/cavium-octeon/octeon-platform.c | 94 +++++++++++++++++++++++++------
arch/mips/cavium-octeon/setup.c | 8 +++
2 files changed, 86 insertions(+), 16 deletions(-)
--
2.4.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses 2016-02-23 22:52 [PATCH v2 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen @ 2016-02-23 22:52 ` Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb Aaro Koskinen 2 siblings, 0 replies; 6+ messages in thread From: Aaro Koskinen @ 2016-02-23 22:52 UTC (permalink / raw) To: Ralf Baechle, David Daney, linux-mips; +Cc: Aaro Koskinen Use separate pass to fill MAC addresses. This is needed because we want to do this also for the appended DTB. Acked-by: David Daney <david.daney@cavium.com> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> --- arch/mips/cavium-octeon/octeon-platform.c | 86 +++++++++++++++++++++++++------ arch/mips/cavium-octeon/setup.c | 2 + 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/arch/mips/cavium-octeon/octeon-platform.c b/arch/mips/cavium-octeon/octeon-platform.c index d113c8d..a7d9f07 100644 --- a/arch/mips/cavium-octeon/octeon-platform.c +++ b/arch/mips/cavium-octeon/octeon-platform.c @@ -560,7 +560,7 @@ static void __init octeon_fdt_rm_ethernet(int node) fdt_nop_node(initial_boot_params, node); } -static void __init octeon_fdt_pip_port(int iface, int i, int p, int max, u64 *pmac) +static void __init octeon_fdt_pip_port(int iface, int i, int p, int max) { char name_buffer[20]; int eth; @@ -583,10 +583,9 @@ static void __init octeon_fdt_pip_port(int iface, int i, int p, int max, u64 *pm phy_addr = cvmx_helper_board_get_mii_address(ipd_port); octeon_fdt_set_phy(eth, phy_addr); - octeon_fdt_set_mac_addr(eth, pmac); } -static void __init octeon_fdt_pip_iface(int pip, int idx, u64 *pmac) +static void __init octeon_fdt_pip_iface(int pip, int idx) { char name_buffer[20]; int iface; @@ -602,7 +601,73 @@ static void __init octeon_fdt_pip_iface(int pip, int idx, u64 *pmac) count = cvmx_helper_ports_on_interface(idx); for (p = 0; p < 16; p++) - octeon_fdt_pip_port(iface, idx, p, count - 1, pmac); + octeon_fdt_pip_port(iface, idx, p, count - 1); +} + +void __init octeon_fill_mac_addresses(void) +{ + const char *alias_prop; + char name_buffer[20]; + u64 mac_addr_base; + int aliases; + int pip; + int i; + + aliases = fdt_path_offset(initial_boot_params, "/aliases"); + if (aliases < 0) + return; + + mac_addr_base = + ((octeon_bootinfo->mac_addr_base[0] & 0xffull)) << 40 | + ((octeon_bootinfo->mac_addr_base[1] & 0xffull)) << 32 | + ((octeon_bootinfo->mac_addr_base[2] & 0xffull)) << 24 | + ((octeon_bootinfo->mac_addr_base[3] & 0xffull)) << 16 | + ((octeon_bootinfo->mac_addr_base[4] & 0xffull)) << 8 | + (octeon_bootinfo->mac_addr_base[5] & 0xffull); + + for (i = 0; i < 2; i++) { + int mgmt; + + snprintf(name_buffer, sizeof(name_buffer), "mix%d", i); + alias_prop = fdt_getprop(initial_boot_params, aliases, + name_buffer, NULL); + if (!alias_prop) + continue; + mgmt = fdt_path_offset(initial_boot_params, alias_prop); + if (mgmt < 0) + continue; + octeon_fdt_set_mac_addr(mgmt, &mac_addr_base); + } + + alias_prop = fdt_getprop(initial_boot_params, aliases, "pip", NULL); + if (!alias_prop) + return; + + pip = fdt_path_offset(initial_boot_params, alias_prop); + if (pip < 0) + return; + + for (i = 0; i <= 4; i++) { + int iface; + int p; + + snprintf(name_buffer, sizeof(name_buffer), "interface@%d", i); + iface = fdt_subnode_offset(initial_boot_params, pip, + name_buffer); + if (iface < 0) + continue; + for (p = 0; p < 16; p++) { + int eth; + + snprintf(name_buffer, sizeof(name_buffer), + "ethernet@%x", p); + eth = fdt_subnode_offset(initial_boot_params, iface, + name_buffer); + if (eth < 0) + continue; + octeon_fdt_set_mac_addr(eth, &mac_addr_base); + } + } } int __init octeon_prune_device_tree(void) @@ -612,7 +677,6 @@ int __init octeon_prune_device_tree(void) const char *alias_prop; char name_buffer[20]; int aliases; - u64 mac_addr_base; if (fdt_check_header(initial_boot_params)) panic("Corrupt Device Tree."); @@ -623,15 +687,6 @@ int __init octeon_prune_device_tree(void) return -EINVAL; } - - mac_addr_base = - ((octeon_bootinfo->mac_addr_base[0] & 0xffull)) << 40 | - ((octeon_bootinfo->mac_addr_base[1] & 0xffull)) << 32 | - ((octeon_bootinfo->mac_addr_base[2] & 0xffull)) << 24 | - ((octeon_bootinfo->mac_addr_base[3] & 0xffull)) << 16 | - ((octeon_bootinfo->mac_addr_base[4] & 0xffull)) << 8 | - (octeon_bootinfo->mac_addr_base[5] & 0xffull); - if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX)) max_port = 2; else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN68XX)) @@ -660,7 +715,6 @@ int __init octeon_prune_device_tree(void) } else { int phy_addr = cvmx_helper_board_get_mii_address(CVMX_HELPER_BOARD_MGMT_IPD_PORT + i); octeon_fdt_set_phy(mgmt, phy_addr); - octeon_fdt_set_mac_addr(mgmt, &mac_addr_base); } } } @@ -670,7 +724,7 @@ int __init octeon_prune_device_tree(void) int pip = fdt_path_offset(initial_boot_params, pip_path); if (pip >= 0) for (i = 0; i <= 4; i++) - octeon_fdt_pip_iface(pip, i, &mac_addr_base); + octeon_fdt_pip_iface(pip, i); } /* I2C */ diff --git a/arch/mips/cavium-octeon/setup.c b/arch/mips/cavium-octeon/setup.c index cd7101f..ed3063f 100644 --- a/arch/mips/cavium-octeon/setup.c +++ b/arch/mips/cavium-octeon/setup.c @@ -1079,6 +1079,7 @@ void __init prom_free_prom_memory(void) } } +void __init octeon_fill_mac_addresses(void); int octeon_prune_device_tree(void); extern const char __appended_dtb; @@ -1114,6 +1115,7 @@ void __init device_tree_init(void) if (do_prune) { octeon_prune_device_tree(); + octeon_fill_mac_addresses(); pr_info("Using internal Device Tree.\n"); } unflatten_and_copy_device_tree(); -- 2.4.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set 2016-02-23 22:52 [PATCH v2 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen @ 2016-02-23 22:52 ` Aaro Koskinen 2016-02-24 10:25 ` Sergei Shtylyov 2016-02-23 22:52 ` [PATCH v2 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb Aaro Koskinen 2 siblings, 1 reply; 6+ messages in thread From: Aaro Koskinen @ 2016-02-23 22:52 UTC (permalink / raw) To: Ralf Baechle, David Daney, linux-mips; +Cc: Aaro Koskinen Don't fill MAC address if it's already set. This allows DTB to override the bootinfo. Acked-by: David Daney <david.daney@cavium.com> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> --- arch/mips/cavium-octeon/octeon-platform.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/mips/cavium-octeon/octeon-platform.c b/arch/mips/cavium-octeon/octeon-platform.c index a7d9f07..7aeafed 100644 --- a/arch/mips/cavium-octeon/octeon-platform.c +++ b/arch/mips/cavium-octeon/octeon-platform.c @@ -13,6 +13,7 @@ #include <linux/i2c.h> #include <linux/usb.h> #include <linux/dma-mapping.h> +#include <linux/etherdevice.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/slab.h> @@ -525,10 +526,17 @@ static void __init octeon_fdt_set_phy(int eth, int phy_addr) static void __init octeon_fdt_set_mac_addr(int n, u64 *pmac) { + const u8 *old_mac; + int old_len; u8 new_mac[6]; u64 mac = *pmac; int r; + old_mac = fdt_getprop(initial_boot_params, n, "local-mac-address", + &old_len); + if (!old_mac || old_len != 6 || is_valid_ether_addr(old_mac)) + return; + new_mac[0] = (mac >> 40) & 0xff; new_mac[1] = (mac >> 32) & 0xff; new_mac[2] = (mac >> 24) & 0xff; -- 2.4.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set 2016-02-23 22:52 ` [PATCH v2 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen @ 2016-02-24 10:25 ` Sergei Shtylyov 2016-02-24 18:35 ` Aaro Koskinen 0 siblings, 1 reply; 6+ messages in thread From: Sergei Shtylyov @ 2016-02-24 10:25 UTC (permalink / raw) To: Aaro Koskinen, Ralf Baechle, David Daney, linux-mips Hello. On 2/24/2016 1:52 AM, Aaro Koskinen wrote: > Don't fill MAC address if it's already set. This allows DTB to > override the bootinfo. > > Acked-by: David Daney <david.daney@cavium.com> > Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> > --- > arch/mips/cavium-octeon/octeon-platform.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/mips/cavium-octeon/octeon-platform.c b/arch/mips/cavium-octeon/octeon-platform.c > index a7d9f07..7aeafed 100644 > --- a/arch/mips/cavium-octeon/octeon-platform.c > +++ b/arch/mips/cavium-octeon/octeon-platform.c > @@ -13,6 +13,7 @@ > #include <linux/i2c.h> > #include <linux/usb.h> > #include <linux/dma-mapping.h> > +#include <linux/etherdevice.h> > #include <linux/module.h> > #include <linux/mutex.h> > #include <linux/slab.h> > @@ -525,10 +526,17 @@ static void __init octeon_fdt_set_phy(int eth, int phy_addr) > > static void __init octeon_fdt_set_mac_addr(int n, u64 *pmac) > { > + const u8 *old_mac; > + int old_len; > u8 new_mac[6]; > u64 mac = *pmac; > int r; > > + old_mac = fdt_getprop(initial_boot_params, n, "local-mac-address", > + &old_len); > + if (!old_mac || old_len != 6 || is_valid_ether_addr(old_mac)) > + return; So if there's no such prop or the length is not 6, you just return? [...] MBR, Sergei ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set 2016-02-24 10:25 ` Sergei Shtylyov @ 2016-02-24 18:35 ` Aaro Koskinen 0 siblings, 0 replies; 6+ messages in thread From: Aaro Koskinen @ 2016-02-24 18:35 UTC (permalink / raw) To: Sergei Shtylyov; +Cc: Ralf Baechle, David Daney, linux-mips Hi, On Wed, Feb 24, 2016 at 01:25:51PM +0300, Sergei Shtylyov wrote: > On 2/24/2016 1:52 AM, Aaro Koskinen wrote: > >+ old_mac = fdt_getprop(initial_boot_params, n, "local-mac-address", > >+ &old_len); > >+ if (!old_mac || old_len != 6 || is_valid_ether_addr(old_mac)) > >+ return; > > So if there's no such prop or the length is not 6, you just return? Yes, in that case the network drivers will silently switch to use a random address. This is the same behaviour as with "normal" DT boot. A. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb 2016-02-23 22:52 [PATCH v2 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen @ 2016-02-23 22:52 ` Aaro Koskinen 2 siblings, 0 replies; 6+ messages in thread From: Aaro Koskinen @ 2016-02-23 22:52 UTC (permalink / raw) To: Ralf Baechle, David Daney, linux-mips; +Cc: Aaro Koskinen Fill MAC addresses from bootinfo when using appended DTB. Acked-by: David Daney <david.daney@cavium.com> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> --- arch/mips/cavium-octeon/setup.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/mips/cavium-octeon/setup.c b/arch/mips/cavium-octeon/setup.c index ed3063f..f2df1d9 100644 --- a/arch/mips/cavium-octeon/setup.c +++ b/arch/mips/cavium-octeon/setup.c @@ -1089,11 +1089,13 @@ void __init device_tree_init(void) { const void *fdt; bool do_prune; + bool fill_mac; #ifdef CONFIG_MIPS_ELF_APPENDED_DTB if (!fdt_check_header(&__appended_dtb)) { fdt = &__appended_dtb; do_prune = false; + fill_mac = true; pr_info("Using appended Device Tree.\n"); } else #endif @@ -1102,22 +1104,26 @@ void __init device_tree_init(void) if (fdt_check_header(fdt)) panic("Corrupt Device Tree passed to kernel."); do_prune = false; + fill_mac = false; pr_info("Using passed Device Tree.\n"); } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) { fdt = &__dtb_octeon_68xx_begin; do_prune = true; + fill_mac = true; } else { fdt = &__dtb_octeon_3xxx_begin; do_prune = true; + fill_mac = true; } initial_boot_params = (void *)fdt; if (do_prune) { octeon_prune_device_tree(); - octeon_fill_mac_addresses(); pr_info("Using internal Device Tree.\n"); } + if (fill_mac) + octeon_fill_mac_addresses(); unflatten_and_copy_device_tree(); } -- 2.4.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-02-24 18:35 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-02-23 22:52 [PATCH v2 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen 2016-02-24 10:25 ` Sergei Shtylyov 2016-02-24 18:35 ` Aaro Koskinen 2016-02-23 22:52 ` [PATCH v2 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb Aaro Koskinen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox