linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2 0/4] net: mvpp2: fix the mac address retrieval logic
@ 2017-08-25 14:14 Antoine Tenart
  2017-08-25 14:14 ` [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2 Antoine Tenart
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Antoine Tenart @ 2017-08-25 14:14 UTC (permalink / raw)
  To: davem, thomas.petazzoni
  Cc: Antoine Tenart, andrew, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

Hi all,

The MAC address retrieval logic was broken and when using the PPv2
driver on PPv2.2 engines I ended up using the same mac address on all
ports. This series of patches fixes this, and also tackle a possible bug
when defining the mac address in the device tree.

Patch 1/4 can be applied to relevant stable trees (4.12+).

The series applies on net/master (9b4e946ce14e).

Thanks!
Antoine

Since v1:
  - Rebased onto net (was on net-next).

Antoine Tenart (4):
  net: mvpp2: fix the mac address used when using PPv2.2
  net: mvpp2: move the mac retrieval/copy logic into its own function
  net: mvpp2: fix use of the random mac address for PPv2.2
  net: mvpp2: fallback using h/w and random mac if the dt one isn't
    valid

 drivers/net/ethernet/marvell/mvpp2.c | 48 ++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 18 deletions(-)

-- 
2.13.5

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

* [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2
  2017-08-25 14:14 [PATCH net v2 0/4] net: mvpp2: fix the mac address retrieval logic Antoine Tenart
@ 2017-08-25 14:14 ` Antoine Tenart
  2017-08-25 14:19   ` Andrew Lunn
  2017-08-28 18:25   ` David Miller
  2017-08-25 14:14 ` [PATCH net v2 2/4] net: mvpp2: move the mac retrieval/copy logic into its own function Antoine Tenart
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Antoine Tenart @ 2017-08-25 14:14 UTC (permalink / raw)
  To: davem, thomas.petazzoni
  Cc: Antoine Tenart, andrew, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

The mac address is only retrieved from h/w when using PPv2.1. Otherwise
the variable holding it is still checked and used if it contains a valid
value. As the variable isn't initialized to an invalid mac address
value, we end up with random mac addresses which can be the same for all
the ports handled by this PPv2 driver.

Fixes this by initializing the h/w mac address variable to {0}, which is
an invalid mac address value. This way the random assignation fallback
is called and all ports end up with their own addresses.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
Fixes: 2697582144dd ("net: mvpp2: handle misc PPv2.1/PPv2.2 differences")
---
 drivers/net/ethernet/marvell/mvpp2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index 48d21c1e09f2..4d598ca8503a 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -6504,7 +6504,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 	struct resource *res;
 	const char *dt_mac_addr;
 	const char *mac_from;
-	char hw_mac_addr[ETH_ALEN];
+	char hw_mac_addr[ETH_ALEN] = {0};
 	u32 id;
 	int features;
 	int phy_mode;
-- 
2.13.5

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

* [PATCH net v2 2/4] net: mvpp2: move the mac retrieval/copy logic into its own function
  2017-08-25 14:14 [PATCH net v2 0/4] net: mvpp2: fix the mac address retrieval logic Antoine Tenart
  2017-08-25 14:14 ` [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2 Antoine Tenart
@ 2017-08-25 14:14 ` Antoine Tenart
  2017-08-25 14:14 ` [PATCH net v2 3/4] net: mvpp2: fix use of the random mac address for PPv2.2 Antoine Tenart
  2017-08-25 14:14 ` [PATCH net v2 4/4] net: mvpp2: fallback using h/w and random mac if the dt one isn't valid Antoine Tenart
  3 siblings, 0 replies; 10+ messages in thread
From: Antoine Tenart @ 2017-08-25 14:14 UTC (permalink / raw)
  To: davem, thomas.petazzoni
  Cc: Antoine Tenart, andrew, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

The MAC retrieval has a quite complicated logic (which is broken). Moves
it to its own function to prepare for patches fixing its logic, so that
reviews are easier.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
---
 drivers/net/ethernet/marvell/mvpp2.c | 45 +++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index 4d598ca8503a..a1593134ed96 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -6492,6 +6492,31 @@ static int mvpp2_port_init(struct mvpp2_port *port)
 	return err;
 }
 
+static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv,
+				     struct device_node *port_node,
+				     char **mac_from)
+{
+	struct mvpp2_port *port = netdev_priv(dev);
+	char hw_mac_addr[ETH_ALEN] = {0};
+	const char *dt_mac_addr;
+
+	dt_mac_addr = of_get_mac_address(port_node);
+	if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) {
+		*mac_from = "device tree";
+		ether_addr_copy(dev->dev_addr, dt_mac_addr);
+	} else {
+		if (priv->hw_version == MVPP21)
+			mvpp21_get_mac_address(port, hw_mac_addr);
+		if (is_valid_ether_addr(hw_mac_addr)) {
+			*mac_from = "hardware";
+			ether_addr_copy(dev->dev_addr, hw_mac_addr);
+		} else {
+			*mac_from = "random";
+			eth_hw_addr_random(dev);
+		}
+	}
+}
+
 /* Ports initialization */
 static int mvpp2_port_probe(struct platform_device *pdev,
 			    struct device_node *port_node,
@@ -6502,9 +6527,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 	struct mvpp2_port_pcpu *port_pcpu;
 	struct net_device *dev;
 	struct resource *res;
-	const char *dt_mac_addr;
-	const char *mac_from;
-	char hw_mac_addr[ETH_ALEN] = {0};
+	char *mac_from = "";
 	u32 id;
 	int features;
 	int phy_mode;
@@ -6585,21 +6608,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 		goto err_free_irq;
 	}
 
-	dt_mac_addr = of_get_mac_address(port_node);
-	if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) {
-		mac_from = "device tree";
-		ether_addr_copy(dev->dev_addr, dt_mac_addr);
-	} else {
-		if (priv->hw_version == MVPP21)
-			mvpp21_get_mac_address(port, hw_mac_addr);
-		if (is_valid_ether_addr(hw_mac_addr)) {
-			mac_from = "hardware";
-			ether_addr_copy(dev->dev_addr, hw_mac_addr);
-		} else {
-			mac_from = "random";
-			eth_hw_addr_random(dev);
-		}
-	}
+	mvpp2_port_copy_mac_addr(dev, priv, port_node, &mac_from);
 
 	port->tx_ring_size = MVPP2_MAX_TXD;
 	port->rx_ring_size = MVPP2_MAX_RXD;
-- 
2.13.5

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

* [PATCH net v2 3/4] net: mvpp2: fix use of the random mac address for PPv2.2
  2017-08-25 14:14 [PATCH net v2 0/4] net: mvpp2: fix the mac address retrieval logic Antoine Tenart
  2017-08-25 14:14 ` [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2 Antoine Tenart
  2017-08-25 14:14 ` [PATCH net v2 2/4] net: mvpp2: move the mac retrieval/copy logic into its own function Antoine Tenart
@ 2017-08-25 14:14 ` Antoine Tenart
  2017-08-25 14:14 ` [PATCH net v2 4/4] net: mvpp2: fallback using h/w and random mac if the dt one isn't valid Antoine Tenart
  3 siblings, 0 replies; 10+ messages in thread
From: Antoine Tenart @ 2017-08-25 14:14 UTC (permalink / raw)
  To: davem, thomas.petazzoni
  Cc: Antoine Tenart, andrew, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

The MAC retrieval logic is using a variable to store an h/w stored mac
address and checks this mac against invalid ones before using it. But
the mac address is only read from h/w when using PPv2.1. So when using
PPv2.2 it defaults to its init state.

This patches fixes the logic to only check if the h/w mac is valid when
actually retrieving a mac from h/w.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
---
 drivers/net/ethernet/marvell/mvpp2.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index a1593134ed96..162e334fda37 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -6505,15 +6505,17 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv,
 		*mac_from = "device tree";
 		ether_addr_copy(dev->dev_addr, dt_mac_addr);
 	} else {
-		if (priv->hw_version == MVPP21)
+		if (priv->hw_version == MVPP21) {
 			mvpp21_get_mac_address(port, hw_mac_addr);
-		if (is_valid_ether_addr(hw_mac_addr)) {
-			*mac_from = "hardware";
-			ether_addr_copy(dev->dev_addr, hw_mac_addr);
-		} else {
-			*mac_from = "random";
-			eth_hw_addr_random(dev);
+			if (is_valid_ether_addr(hw_mac_addr)) {
+				*mac_from = "hardware";
+				ether_addr_copy(dev->dev_addr, hw_mac_addr);
+				return;
+			}
 		}
+
+		*mac_from = "random";
+		eth_hw_addr_random(dev);
 	}
 }
 
-- 
2.13.5

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

* [PATCH net v2 4/4] net: mvpp2: fallback using h/w and random mac if the dt one isn't valid
  2017-08-25 14:14 [PATCH net v2 0/4] net: mvpp2: fix the mac address retrieval logic Antoine Tenart
                   ` (2 preceding siblings ...)
  2017-08-25 14:14 ` [PATCH net v2 3/4] net: mvpp2: fix use of the random mac address for PPv2.2 Antoine Tenart
@ 2017-08-25 14:14 ` Antoine Tenart
  3 siblings, 0 replies; 10+ messages in thread
From: Antoine Tenart @ 2017-08-25 14:14 UTC (permalink / raw)
  To: davem, thomas.petazzoni
  Cc: Antoine Tenart, andrew, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

When using a mac address described in the device tree, a check is made
to see if it is valid. When it's not, no fallback is defined. This
patches tries to get the mac address from h/w (or use a random one if
the h/w one isn't valid) when the dt mac address isn't valid.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
---
 drivers/net/ethernet/marvell/mvpp2.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index 162e334fda37..2f1284f23e66 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -6504,19 +6504,20 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv,
 	if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) {
 		*mac_from = "device tree";
 		ether_addr_copy(dev->dev_addr, dt_mac_addr);
-	} else {
-		if (priv->hw_version == MVPP21) {
-			mvpp21_get_mac_address(port, hw_mac_addr);
-			if (is_valid_ether_addr(hw_mac_addr)) {
-				*mac_from = "hardware";
-				ether_addr_copy(dev->dev_addr, hw_mac_addr);
-				return;
-			}
-		}
+		return;
+	}
 
-		*mac_from = "random";
-		eth_hw_addr_random(dev);
+	if (priv->hw_version == MVPP21) {
+		mvpp21_get_mac_address(port, hw_mac_addr);
+		if (is_valid_ether_addr(hw_mac_addr)) {
+			*mac_from = "hardware";
+			ether_addr_copy(dev->dev_addr, hw_mac_addr);
+			return;
+		}
 	}
+
+	*mac_from = "random";
+	eth_hw_addr_random(dev);
 }
 
 /* Ports initialization */
-- 
2.13.5

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

* Re: [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2
  2017-08-25 14:14 ` [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2 Antoine Tenart
@ 2017-08-25 14:19   ` Andrew Lunn
  2017-08-25 14:29     ` Antoine Tenart
  2017-08-28 18:25   ` David Miller
  1 sibling, 1 reply; 10+ messages in thread
From: Andrew Lunn @ 2017-08-25 14:19 UTC (permalink / raw)
  To: Antoine Tenart
  Cc: davem, thomas.petazzoni, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

On Fri, Aug 25, 2017 at 04:14:17PM +0200, Antoine Tenart wrote:
> The mac address is only retrieved from h/w when using PPv2.1. Otherwise
> the variable holding it is still checked and used if it contains a valid
> value. As the variable isn't initialized to an invalid mac address
> value, we end up with random mac addresses which can be the same for all
> the ports handled by this PPv2 driver.
> 
> Fixes this by initializing the h/w mac address variable to {0}, which is
> an invalid mac address value. This way the random assignation fallback
> is called and all ports end up with their own addresses.
> 
> Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
> Fixes: 2697582144dd ("net: mvpp2: handle misc PPv2.1/PPv2.2 differences")

Hi Antoine

Is this patch alone sufficient to fix the problem?

Ideally, you want a minimal patch for stable, i.e. -net, and a fuller
fix can go into net-next.

    Andrew

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

* Re: [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2
  2017-08-25 14:19   ` Andrew Lunn
@ 2017-08-25 14:29     ` Antoine Tenart
  2017-08-25 15:42       ` Andrew Lunn
  0 siblings, 1 reply; 10+ messages in thread
From: Antoine Tenart @ 2017-08-25 14:29 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Antoine Tenart, davem, thomas.petazzoni, gregory.clement, nadavh,
	linux, linux-kernel, mw, stefanc, netdev

[-- Attachment #1: Type: text/plain, Size: 1617 bytes --]

Hi Andrew,

On Fri, Aug 25, 2017 at 04:19:39PM +0200, Andrew Lunn wrote:
> On Fri, Aug 25, 2017 at 04:14:17PM +0200, Antoine Tenart wrote:
> > The mac address is only retrieved from h/w when using PPv2.1. Otherwise
> > the variable holding it is still checked and used if it contains a valid
> > value. As the variable isn't initialized to an invalid mac address
> > value, we end up with random mac addresses which can be the same for all
> > the ports handled by this PPv2 driver.
> > 
> > Fixes this by initializing the h/w mac address variable to {0}, which is
> > an invalid mac address value. This way the random assignation fallback
> > is called and all ports end up with their own addresses.
> > 
> > Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
> > Fixes: 2697582144dd ("net: mvpp2: handle misc PPv2.1/PPv2.2 differences")
> 
> Is this patch alone sufficient to fix the problem?

Yes it is.

> Ideally, you want a minimal patch for stable, i.e. -net, and a fuller
> fix can go into net-next.

That was my intention (providing a minimal patch for stable), and I
asked about this approach in the v1. Dave told me to resend the series
to net. Maybe my questions weren't clear enough.

So probably the best way to handle this would have been to send 1/4 to
net and 2-4/4 to net-next (but then there's a dependency between the two
series).

Let's wait for Dave's answer, I'll respin if needed so that it's easy
for him to apply it.

Thanks!
Antoine

-- 
Antoine Ténart, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2
  2017-08-25 14:29     ` Antoine Tenart
@ 2017-08-25 15:42       ` Andrew Lunn
  2017-08-25 15:54         ` Antoine Tenart
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Lunn @ 2017-08-25 15:42 UTC (permalink / raw)
  To: Antoine Tenart
  Cc: davem, thomas.petazzoni, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

> So probably the best way to handle this would have been to send 1/4 to
> net and 2-4/4 to net-next

Correct. 

> (but then there's a dependency between the two series).

Dave merges net into net-next every so often. So you just need to wait
a bit before submitting the net-next parts.

  Andrew

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

* Re: [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2
  2017-08-25 15:42       ` Andrew Lunn
@ 2017-08-25 15:54         ` Antoine Tenart
  0 siblings, 0 replies; 10+ messages in thread
From: Antoine Tenart @ 2017-08-25 15:54 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Antoine Tenart, davem, thomas.petazzoni, gregory.clement, nadavh,
	linux, linux-kernel, mw, stefanc, netdev

[-- Attachment #1: Type: text/plain, Size: 598 bytes --]

On Fri, Aug 25, 2017 at 05:42:47PM +0200, Andrew Lunn wrote:
> > So probably the best way to handle this would have been to send 1/4 to
> > net and 2-4/4 to net-next
> 
> Correct. 
> 
> > (but then there's a dependency between the two series).
> 
> Dave merges net into net-next every so often. So you just need to wait
> a bit before submitting the net-next parts.

I see. So Dave can take patch 1/4 and I'll respin the others once it's
merged into net-next.

Thanks!
Antoine

-- 
Antoine Ténart, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2
  2017-08-25 14:14 ` [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2 Antoine Tenart
  2017-08-25 14:19   ` Andrew Lunn
@ 2017-08-28 18:25   ` David Miller
  1 sibling, 0 replies; 10+ messages in thread
From: David Miller @ 2017-08-28 18:25 UTC (permalink / raw)
  To: antoine.tenart
  Cc: thomas.petazzoni, andrew, gregory.clement, nadavh, linux,
	linux-kernel, mw, stefanc, netdev

From: Antoine Tenart <antoine.tenart@free-electrons.com>
Date: Fri, 25 Aug 2017 16:14:17 +0200

> The mac address is only retrieved from h/w when using PPv2.1. Otherwise
> the variable holding it is still checked and used if it contains a valid
> value. As the variable isn't initialized to an invalid mac address
> value, we end up with random mac addresses which can be the same for all
> the ports handled by this PPv2 driver.
> 
> Fixes this by initializing the h/w mac address variable to {0}, which is
> an invalid mac address value. This way the random assignation fallback
> is called and all ports end up with their own addresses.
> 
> Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
> Fixes: 2697582144dd ("net: mvpp2: handle misc PPv2.1/PPv2.2 differences")

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2017-08-28 18:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25 14:14 [PATCH net v2 0/4] net: mvpp2: fix the mac address retrieval logic Antoine Tenart
2017-08-25 14:14 ` [PATCH net v2 1/4] net: mvpp2: fix the mac address used when using PPv2.2 Antoine Tenart
2017-08-25 14:19   ` Andrew Lunn
2017-08-25 14:29     ` Antoine Tenart
2017-08-25 15:42       ` Andrew Lunn
2017-08-25 15:54         ` Antoine Tenart
2017-08-28 18:25   ` David Miller
2017-08-25 14:14 ` [PATCH net v2 2/4] net: mvpp2: move the mac retrieval/copy logic into its own function Antoine Tenart
2017-08-25 14:14 ` [PATCH net v2 3/4] net: mvpp2: fix use of the random mac address for PPv2.2 Antoine Tenart
2017-08-25 14:14 ` [PATCH net v2 4/4] net: mvpp2: fallback using h/w and random mac if the dt one isn't valid Antoine Tenart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).