All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB
@ 2016-02-22 22:39 Aaro Koskinen
  2016-02-22 22:39 ` [PATCH 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Aaro Koskinen @ 2016-02-22 22:39 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.

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 | 95 +++++++++++++++++++++++++------
 arch/mips/cavium-octeon/setup.c           |  8 +++
 2 files changed, 87 insertions(+), 16 deletions(-)

-- 
2.4.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses
  2016-02-22 22:39 [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen
@ 2016-02-22 22:39 ` Aaro Koskinen
  2016-02-22 22:39 ` [PATCH 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Aaro Koskinen @ 2016-02-22 22:39 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.

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 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set
  2016-02-22 22:39 [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen
  2016-02-22 22:39 ` [PATCH 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen
@ 2016-02-22 22:39 ` Aaro Koskinen
  2016-02-22 23:10   ` Florian Fainelli
  2016-02-22 22:39 ` [PATCH 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb Aaro Koskinen
  2016-02-23  2:03 ` [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB David Daney
  3 siblings, 1 reply; 6+ messages in thread
From: Aaro Koskinen @ 2016-02-22 22:39 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.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 arch/mips/cavium-octeon/octeon-platform.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/mips/cavium-octeon/octeon-platform.c b/arch/mips/cavium-octeon/octeon-platform.c
index a7d9f07..c5de792 100644
--- a/arch/mips/cavium-octeon/octeon-platform.c
+++ b/arch/mips/cavium-octeon/octeon-platform.c
@@ -525,10 +525,19 @@ 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 || old_mac[0] || old_mac[1] ||
+					old_mac[2] || old_mac[3] ||
+					old_mac[4] || old_mac[5])
+		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

* [PATCH 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb
  2016-02-22 22:39 [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen
  2016-02-22 22:39 ` [PATCH 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen
  2016-02-22 22:39 ` [PATCH 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen
@ 2016-02-22 22:39 ` Aaro Koskinen
  2016-02-23  2:03 ` [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB David Daney
  3 siblings, 0 replies; 6+ messages in thread
From: Aaro Koskinen @ 2016-02-22 22:39 UTC (permalink / raw)
  To: Ralf Baechle, David Daney, linux-mips; +Cc: Aaro Koskinen

Fill MAC addresses from bootinfo when using appended DTB.

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

* Re: [PATCH 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set
  2016-02-22 22:39 ` [PATCH 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen
@ 2016-02-22 23:10   ` Florian Fainelli
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2016-02-22 23:10 UTC (permalink / raw)
  To: Aaro Koskinen, Ralf Baechle, David Daney, linux-mips

On 22/02/16 14:39, Aaro Koskinen wrote:
> Don't fill MAC address if it's already set. This allows DTB to
> override the bootinfo.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
> ---
>  arch/mips/cavium-octeon/octeon-platform.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/arch/mips/cavium-octeon/octeon-platform.c b/arch/mips/cavium-octeon/octeon-platform.c
> index a7d9f07..c5de792 100644
> --- a/arch/mips/cavium-octeon/octeon-platform.c
> +++ b/arch/mips/cavium-octeon/octeon-platform.c
> @@ -525,10 +525,19 @@ 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 || old_mac[0] || old_mac[1] ||
> +					old_mac[2] || old_mac[3] ||
> +					old_mac[4] || old_mac[5])

There is nothing that tells you that these are valid MAC addresses
though, although unlikely, the FW could be handing you bad addresses,
might be better to use is_valid_ether_addr() here?
-- 
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB
  2016-02-22 22:39 [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen
                   ` (2 preceding siblings ...)
  2016-02-22 22:39 ` [PATCH 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb Aaro Koskinen
@ 2016-02-23  2:03 ` David Daney
  3 siblings, 0 replies; 6+ messages in thread
From: David Daney @ 2016-02-23  2:03 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: Ralf Baechle, linux-mips

Acked-by: David Daney <david.daney@cavium.com>

On 02/22/2016 02:39 PM, Aaro Koskinen wrote:
> Hi,
>
> When using appended DTB, the MAC addresses should be filled in
> from the bootinfo.
>
> 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 | 95 +++++++++++++++++++++++++------
>   arch/mips/cavium-octeon/setup.c           |  8 +++
>   2 files changed, 87 insertions(+), 16 deletions(-)
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-23  2:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-22 22:39 [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB Aaro Koskinen
2016-02-22 22:39 ` [PATCH 1/3] MIPS: OCTEON: device_tree_init: use separate pass to fill mac addresses Aaro Koskinen
2016-02-22 22:39 ` [PATCH 2/3] MIPS: OCTEON: device_tree_init: don't fill mac if already set Aaro Koskinen
2016-02-22 23:10   ` Florian Fainelli
2016-02-22 22:39 ` [PATCH 3/3] MIPS: OCTEON: device_tree_init: fill mac addresses when using appended dtb Aaro Koskinen
2016-02-23  2:03 ` [PATCH 0/3] MIPS: OCTEON: fill mac addresses with appended DTB David Daney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.