Skip to contentSkip to conversation

net/macb: fixes after big driver update

PATCH Superseded Nicolas Ferre 3 participants 10 messages Mar 27, 2015 – Mar 30, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover net/macb: fixes after big driver update

The recent modifications to the macb driver lead to issues with the probe function code flow. Here are some attempt to fix them.
The series is written on top of net-next.

Nicolas Ferre (4):
net/macb: only probe queues once and use stored values net/macb: add comment in macb_probe_queues net/macb: fix capabilities configuration net/macb: trivial: correct wording of for caps

 drivers/net/ethernet/cadence/macb.c | 55 +++++++++++++++++++------------------
 drivers/net/ethernet/cadence/macb.h |  1 +
 2 files changed, 30 insertions(+), 26 deletions(-)
Signature · 1 line
2.1.3
#1 lore raw

PATCH 1/4 net/macb: only probe queues once and use stored values

When merging at91_ether and macb driver during 421d9df0628b (net/macb: merge at91_ether driver into macb driver) the probe function has been split. The code dealing with initialization of queues is now moved in macb_init() which needs information computed in the parent macb_probe() function.
So, add the queue_mask information to the private structure and use it when needed in macb_init().

Cc Cyrille Pitchen <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/net/ethernet/cadence/macb.c | 9 ++++-----
 drivers/net/ethernet/cadence/macb.h | 1 +
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb.c +4 -5
index a0a04b3638e6..b710768172d9 100644
@@ -2180,7 +2180,7 @@ static void macb_probe_queues(void __iomem *mem,
 static int macb_init(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
-	unsigned int hw_q, queue_mask, q, num_queues;
+	unsigned int hw_q, q;
 	struct macb *bp = netdev_priv(dev);
 	struct macb_queue *queue;
 	int err;
@@ -2226,10 +2226,8 @@ static int macb_init(struct platform_device *pdev)
 	 * register mapping but we don't want to test the queue index then
 	 * compute the corresponding register offset at run time.
 	 */
-	macb_probe_queues(bp->regs, &queue_mask, &num_queues);
-
-	for (hw_q = 0, q = 0; hw_q < MACB_MAX_QUEUES; ++hw_q) {
-		if (!(queue_mask & (1 << hw_q)))
+	for (hw_q = 0, q = 0; hw_q < bp->num_queues; ++hw_q) {
+		if (!(bp->queue_mask & (1 << hw_q)))
 			continue;
 
 		queue = &bp->queues[q];
@@ -2715,6 +2713,7 @@ static int macb_probe(struct platform_device *pdev)
 	bp->dev = dev;
 	bp->regs = mem;
 	bp->num_queues = num_queues;
+	bp->queue_mask = queue_mask;
 	spin_lock_init(&bp->lock);
 
 	platform_set_drvdata(pdev, dev);
drivers/net/ethernet/cadence/macb.h +1 -0
index bc6e35c40822..0b6afac91bfe 100644
@@ -785,6 +785,7 @@ struct macb {
 	size_t			rx_buffer_size;
 
 	unsigned int		num_queues;
+	unsigned int		queue_mask;
 	struct macb_queue	queues[MACB_MAX_QUEUES];
 
 	spinlock_t		lock;
Signature · 1 line
2.1.3
#5 lore raw

PATCH 2/4 net/macb: add comment in macb_probe_queues

In reply to Nicolas Ferre

As we access the MID register directly, we need to tell why we don't use the macb_is_gem() dedicated function.

---
 drivers/net/ethernet/cadence/macb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb.c +6 -2
index b710768172d9..bc3eab95022f 100644
@@ -2161,9 +2161,13 @@ static void macb_probe_queues(void __iomem *mem,
 	*queue_mask = 0x1;
 	*num_queues = 1;
 
-	/* is it macb or gem ? */
+	/* is it macb or gem ?
+	 *
+	 * We need to read directly from the hardware here because
+	 * we are early in the probe process and don't have the
+	 * MACB_CAPS_MACB_IS_GEM flag positioned
+	 */
 	mid = readl_relaxed(mem + MACB_MID);
-
 	if (MACB_BFEXT(IDNUM, mid) < 0x2)
 		return;
 
Signature · 1 line
2.1.3
#6 lore raw

PATCH 3/4 net/macb: fix capabilities configuration

In reply to Nicolas Ferre

Capabilities configuration by macb_configure_caps() was moved far too late by 421d9df0628b (net/macb: merge at91_ether driver into macb driver) which would lead to badly configured hardware.
So, move this function to early probe and modify its prototype to re-gain its original behavior.
DT data retrieval is also moved to simplify the probe code flow.

Cc Cyrille Pitchen <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/net/ethernet/cadence/macb.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/net/ethernet/cadence/macb.c +18 -18
index bc3eab95022f..64e35a50e5c1 100644
@@ -2132,10 +2132,13 @@ static const struct net_device_ops macb_netdev_ops = {
  * Configure peripheral capacities according to device tree
  * and integration options used
  */
-static void macb_configure_caps(struct macb *bp)
+static void macb_configure_caps(struct macb *bp, const struct macb_config *dt_conf)
 {
 	u32 dcfg;
 
+	if (dt_conf)
+		bp->caps = dt_conf->caps;
+
 	if (MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2)
 		bp->caps |= MACB_CAPS_MACB_IS_GEM;
 
@@ -2313,9 +2316,6 @@ static int macb_init(struct platform_device *pdev)
 
 	macb_or_gem_writel(bp, USRIO, val);
 
-	/* setup capacities */
-	macb_configure_caps(bp);
-
 	/* Set MII management clock divider */
 	val = macb_mdc_clk_div(bp);
 	val |= macb_dbw(bp);
@@ -2720,6 +2720,20 @@ static int macb_probe(struct platform_device *pdev)
 	bp->queue_mask = queue_mask;
 	spin_lock_init(&bp->lock);
 
+	if (np) {
+		const struct of_device_id *match;
+
+		match = of_match_node(macb_dt_ids, np);
+		if (match && match->data) {
+			macb_config = match->data;
+			bp->dma_burst_length = macb_config->dma_burst_length;
+			init = macb_config->init;
+		}
+	}
+
+	/* setup capacities */
+	macb_configure_caps(bp, macb_config);
+
 	platform_set_drvdata(pdev, dev);
 
 	dev->irq = platform_get_irq(pdev, 0);
@@ -2743,20 +2757,6 @@ static int macb_probe(struct platform_device *pdev)
 		bp->phy_interface = err;
 	}
 
-	if (np) {
-		const struct of_device_id *match;
-
-		match = of_match_node(macb_dt_ids, np);
-		if (match)
-			macb_config = match->data;
-	}
-
-	if (macb_config) {
-		bp->caps = macb_config->caps;
-		bp->dma_burst_length = macb_config->dma_burst_length;
-		init = macb_config->init;
-	}
-
 	/* IP specific init */
 	err = init(pdev);
 	if (err)
Signature · 1 line
2.1.3
#9 lore raw

PATCH 4/4 net/macb: trivial: correct wording of for caps

In reply to Nicolas Ferre

As a non-native English speaker, I would correct "capacities" of the macb peripheral to "capabilities": correct me if I'm wrong!

---
 drivers/net/ethernet/cadence/macb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb.c +2 -2
index 64e35a50e5c1..3032ae052755 100644
@@ -2129,7 +2129,7 @@ static const struct net_device_ops macb_netdev_ops = {
 };
 
 /*
- * Configure peripheral capacities according to device tree
+ * Configure peripheral capabilities according to device tree
  * and integration options used
  */
 static void macb_configure_caps(struct macb *bp, const struct macb_config *dt_conf)
@@ -2731,7 +2731,7 @@ static int macb_probe(struct platform_device *pdev)
 		}
 	}
 
-	/* setup capacities */
+	/* setup capabilities */
 	macb_configure_caps(bp, macb_config);
 
 	platform_set_drvdata(pdev, dev);
Signature · 1 line
2.1.3
#2 lore raw

Re: [PATCH 1/4] net/macb: only probe queues once and use stored values

In reply to Nicolas Ferre

Hi Nicolas,

There is a little mistake in this patch, which will prevent the GEM from working properly:

Le 27/03/2015 16:34, Nicolas Ferre a ?crit :

Quoted 29 lines

When merging at91_ether and macb driver during 421d9df0628b (net/macb: merge at91_ether driver into macb driver) the probe function has been split. The code dealing with initialization of queues is now moved in macb_init() which needs information computed in the parent macb_probe() function.
So, add the queue_mask information to the private structure and use it when needed in macb_init().

Cc Cyrille Pitchen <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/net/ethernet/cadence/macb.c | 9 ++++-----
 drivers/net/ethernet/cadence/macb.h | 1 +
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb.c +1 -1
index a0a04b3638e6..b710768172d9 100644
@@ -2180,7 +2180,7 @@ static void macb_probe_queues(void __iomem *mem,
 static int macb_init(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
-	unsigned int hw_q, queue_mask, q, num_queues;
+	unsigned int hw_q, q;
 	struct macb *bp = netdev_priv(dev);
 	struct macb_queue *queue;
 	int err;

drivers/net/ethernet/cadence/macb.c static int macb_init(struct platform_device *pdev) · line 2231

Quoted 10 lines
drivers/net/ethernet/cadence/macb.c +2 -4
@@ -2226,10 +2226,8 @@ static int macb_init(struct platform_device *pdev)
 	 * register mapping but we don't want to test the queue index then
 	 * compute the corresponding register offset at run time.
 	 */
-	macb_probe_queues(bp->regs, &queue_mask, &num_queues);
-
-	for (hw_q = 0, q = 0; hw_q < MACB_MAX_QUEUES; ++hw_q) {
-		if (!(queue_mask & (1 << hw_q)))
+	for (hw_q = 0, q = 0; hw_q < bp->num_queues; ++hw_q) {
+		if (!(bp->queue_mask & (1 << hw_q)))
 			continue;

The exit condition of the for loop must remain "hw_q < MACB_MAX_QUEUES" and should not be replaced by "hw_q < bp->num_queues".
Indeed there can be only 2 queues, for instance queue0 and queue7. So if you change the exit conditon of the loop, queue7 won't be initialized and HRESP errors will occur.

Quoted 16 lines
drivers/net/ethernet/cadence/macb.c +1 -0
 		queue = &bp->queues[q];
@@ -2715,6 +2713,7 @@ static int macb_probe(struct platform_device *pdev)
 	bp->dev = dev;
 	bp->regs = mem;
 	bp->num_queues = num_queues;
+	bp->queue_mask = queue_mask;
 	spin_lock_init(&bp->lock);
 
 	platform_set_drvdata(pdev, dev);
drivers/net/ethernet/cadence/macb.h +0 -0
index bc6e35c40822..0b6afac91bfe 100644

drivers/net/ethernet/cadence/macb.h struct macb { · line 791

Quoted 7 lines
drivers/net/ethernet/cadence/macb.h +1 -0
@@ -785,6 +785,7 @@ struct macb {
 	size_t			rx_buffer_size;
 
 	unsigned int		num_queues;
+	unsigned int		queue_mask;
 	struct macb_queue	queues[MACB_MAX_QUEUES];
 
 	spinlock_t		lock;

Best Regards,

Cyrille

Acked-by on v1 1/4
#4 lore raw

Re: [PATCH 1/4] net/macb: only probe queues once and use stored values

In reply to Nicolas Ferre

Hi Nicolas,

Quoted 6 lines · On Fri, 27 Mar 2015 16:34:09 +0100 Nicolas Ferre <[email protected]>…

When merging at91_ether and macb driver during 421d9df0628b (net/macb: merge at91_ether driver into macb driver) the probe function has been split. The code dealing with initialization of queues is now moved in macb_init() which needs information computed in the parent macb_probe() function.
So, add the queue_mask information to the private structure and use it when needed in macb_init().

Just to be sure: this is not a bug fix, right ? It just improves the initialization process by calling macb_probe_queues only once (in macb_probe).

Anyway, once you've addressed Cyrille's comment, you can add my

Quoted 55 lines
Cc Cyrille Pitchen <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/net/ethernet/cadence/macb.c | 9 ++++-----
 drivers/net/ethernet/cadence/macb.h | 1 +
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb.c +4 -5
index a0a04b3638e6..b710768172d9 100644
@@ -2180,7 +2180,7 @@ static void macb_probe_queues(void __iomem *mem,
 static int macb_init(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
-	unsigned int hw_q, queue_mask, q, num_queues;
+	unsigned int hw_q, q;
 	struct macb *bp = netdev_priv(dev);
 	struct macb_queue *queue;
 	int err;
@@ -2226,10 +2226,8 @@ static int macb_init(struct platform_device *pdev)
 	 * register mapping but we don't want to test the queue index then
 	 * compute the corresponding register offset at run time.
 	 */
-	macb_probe_queues(bp->regs, &queue_mask, &num_queues);
-
-	for (hw_q = 0, q = 0; hw_q < MACB_MAX_QUEUES; ++hw_q) {
-		if (!(queue_mask & (1 << hw_q)))
+	for (hw_q = 0, q = 0; hw_q < bp->num_queues; ++hw_q) {
+		if (!(bp->queue_mask & (1 << hw_q)))
 			continue;
 
 		queue = &bp->queues[q];
@@ -2715,6 +2713,7 @@ static int macb_probe(struct platform_device *pdev)
 	bp->dev = dev;
 	bp->regs = mem;
 	bp->num_queues = num_queues;
+	bp->queue_mask = queue_mask;
 	spin_lock_init(&bp->lock);
 
 	platform_set_drvdata(pdev, dev);
drivers/net/ethernet/cadence/macb.h +1 -0
index bc6e35c40822..0b6afac91bfe 100644
@@ -785,6 +785,7 @@ struct macb {
 	size_t			rx_buffer_size;
 
 	unsigned int		num_queues;
+	unsigned int		queue_mask;
 	struct macb_queue	queues[MACB_MAX_QUEUES];
 
 	spinlock_t		lock;
Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#7 lore raw

Re: [PATCH 3/4] net/macb: fix capabilities configuration

In reply to Nicolas Ferre

Hi Nicolas,

Quoted 3 lines · On Fri, 27 Mar 2015 16:34:11 +0100 Nicolas Ferre <[email protected]>…

Capabilities configuration by macb_configure_caps() was moved far too late by 421d9df0628b (net/macb: merge at91_ether driver into macb driver) which would lead to badly configured hardware.

Indeed, the macb_configure_caps function is called a bit too late, but ...

Quoted 3 lines

So, move this function to early probe and modify its prototype to re-gain its original behavior.
DT data retrieval is also moved to simplify the probe code flow.

... I'm not happy with these changes.
I tried to keep specific init steps of macb and at91_ether separated and you're moving macb_configure_caps call (not required on at91_ether HW) into macb_probe (the common probe part).

How about moving macb_configure_caps a bit earlier in the macb_init function [1] ?

Best Regards,

Boris

[1]http://code.bulix.org/8gyi6b-88141

Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#3 lore raw

Re: [PATCH 1/4] net/macb: only probe queues once and use stored values

In reply to Cyrille Pitchen

Le 27/03/2015 17:24, Cyrille Pitchen a ?crit :

Quoted 43 lines

Hi Nicolas,

There is a little mistake in this patch, which will prevent the GEM from working properly:

Le 27/03/2015 16:34, Nicolas Ferre a ?crit :

Quoted 37 lines

When merging at91_ether and macb driver during 421d9df0628b (net/macb: merge at91_ether driver into macb driver) the probe function has been split. The code dealing with initialization of queues is now moved in macb_init() which needs information computed in the parent macb_probe() function.
So, add the queue_mask information to the private structure and use it when needed in macb_init().

Cc Cyrille Pitchen <[email protected]>
Cc Boris Brezillon <[email protected]>
---
 drivers/net/ethernet/cadence/macb.c | 9 ++++-----
 drivers/net/ethernet/cadence/macb.h | 1 +
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb.c +2 -5
index a0a04b3638e6..b710768172d9 100644
@@ -2180,7 +2180,7 @@ static void macb_probe_queues(void __iomem *mem,
 static int macb_init(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
-	unsigned int hw_q, queue_mask, q, num_queues;
+	unsigned int hw_q, q;
 	struct macb *bp = netdev_priv(dev);
 	struct macb_queue *queue;
 	int err;
@@ -2226,10 +2226,8 @@ static int macb_init(struct platform_device *pdev)
 	 * register mapping but we don't want to test the queue index then
 	 * compute the corresponding register offset at run time.
 	 */
-	macb_probe_queues(bp->regs, &queue_mask, &num_queues);
-
-	for (hw_q = 0, q = 0; hw_q < MACB_MAX_QUEUES; ++hw_q) {
-		if (!(queue_mask & (1 << hw_q)))
+	for (hw_q = 0, q = 0; hw_q < bp->num_queues; ++hw_q) {
Quoted 8 lines

drivers/net/ethernet/cadence/macb.c static int macb_init(struct platform_device *pdev) · line 2231

Quoted 2 lines
drivers/net/ethernet/cadence/macb.c +1 -0
+		if (!(bp->queue_mask & (1 << hw_q)))
 			continue;

The exit condition of the for loop must remain "hw_q < MACB_MAX_QUEUES" and should not be replaced by "hw_q < bp->num_queues".
Indeed there can be only 2 queues, for instance queue0 and queue7. So if you change the exit conditon of the loop, queue7 won't be initialized and HRESP errors will occur.

Absolutely. Sorry to have misunderstood this condition.

I'll re-spin a v2 series.

Bye,

Quoted 28 lines
Quoted 16 lines
drivers/net/ethernet/cadence/macb.c +1 -0
 		queue = &bp->queues[q];
@@ -2715,6 +2713,7 @@ static int macb_probe(struct platform_device *pdev)
 	bp->dev = dev;
 	bp->regs = mem;
 	bp->num_queues = num_queues;
+	bp->queue_mask = queue_mask;
 	spin_lock_init(&bp->lock);
 
 	platform_set_drvdata(pdev, dev);
drivers/net/ethernet/cadence/macb.h +0 -0
index bc6e35c40822..0b6afac91bfe 100644

drivers/net/ethernet/cadence/macb.h struct macb { · line 791

Quoted 7 lines
drivers/net/ethernet/cadence/macb.h +1 -0
@@ -785,6 +785,7 @@ struct macb {
 	size_t			rx_buffer_size;
 
 	unsigned int		num_queues;
+	unsigned int		queue_mask;
 	struct macb_queue	queues[MACB_MAX_QUEUES];
 
 	spinlock_t		lock;

Best Regards,

Cyrille

Signature · 1 line
Nicolas Ferre
#8 lore raw

Re: [PATCH 3/4] net/macb: fix capabilities configuration

In reply to Boris Brezillon

Le 28/03/2015 00:02, Boris Brezillon a ?crit :

Quoted 12 lines

Hi Nicolas,

Quoted 3 lines · On Fri, 27 Mar 2015 16:34:11 +0100 Nicolas Ferre <[email protected]>…

Capabilities configuration by macb_configure_caps() was moved far too late by 421d9df0628b (net/macb: merge at91_ether driver into macb driver) which would lead to badly configured hardware.

Indeed, the macb_configure_caps function is called a bit too late, but ...

Quoted 8 lines
Quoted 3 lines

So, move this function to early probe and modify its prototype to re-gain its original behavior.
DT data retrieval is also moved to simplify the probe code flow.

... I'm not happy with these changes.
I tried to keep specific init steps of macb and at91_ether separated and you're moving macb_configure_caps call (not required on at91_ether HW) into macb_probe (the common probe part).

Well, this function is about configuring the capabilities of the hardware both from the configuration registers and the device tree entries (this last source applies to all flavors of hardware).

I only see advantages to set these flags early (Cf. above).

Quoted 2 lines

How about moving macb_configure_caps a bit earlier in the macb_init function [1] ?

No, it won't be sufficient. The very first function needing the capabilities set is macb_get_hwaddr() which is pretty early in macb_probe().

Bye,

Quoted 6 lines

Best Regards,

Boris

[1]http://code.bulix.org/8gyi6b-88141

Signature · 1 line
Nicolas Ferre