Skip to contentSkip to conversation

calexda/xgmac bug fixes

PATCH In review Ben Dooks 4 participants 9 messages Feb 10, 2013 – Feb 12, 2013

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

The following are a couple of bugs that I ran in to trying to test the highbank architecture in big endian mode.

Branch available at:

git://git.baserock.org/delta/linux baserock/bjdooks/calxeda-xgmac

author
#1 lore raw

PATCH 1/2 net: calexdaxgmac: fix printing of hardware version

The current driver attempts to print netdev_info() before registering the network device and allowing the name to be set. Change this print to be after the network deviec has been registered, and thus has been allocated a network device name.

Fix the following issue:

calxedaxgmac fff50000.ethernet (unregistered net_device): h/w version is 0x1012

---
 drivers/net/ethernet/calxeda/xgmac.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/calxeda/xgmac.c +3 -3
index f7f0290..f91d9b2 100644
@@ -1715,9 +1715,6 @@ static int xgmac_probe(struct platform_device *pdev)
 		goto err_io;
 	}
 
-	uid = readl(priv->base + XGMAC_VERSION);
-	netdev_info(ndev, "h/w version is 0x%x\n", uid);
-
 	writel(0, priv->base + XGMAC_DMA_INTR_ENA);
 	ndev->irq = platform_get_irq(pdev, 0);
 	if (ndev->irq == -ENXIO) {
@@ -1771,6 +1768,9 @@ static int xgmac_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_reg;
 
+	uid = readl(priv->base + XGMAC_VERSION);
+	netdev_info(ndev, "h/w version is 0x%x\n", uid);
+
 	return 0;
 
 err_reg:
Signature · 1 line
1.7.10.4
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net: calexdaxgmac: fix printing of hardware version

Quoted 3 lines · Ben Dooks

The current driver attempts to print netdev_info() before registering the network device and allowing the name to be set. Change this print to be after the network deviec has been registered, and thus has been allocated

You missed the typo pointed out on the first version sent to lakml.

Quoted 7 lines

a network device name.

Fix the following issue:

calxedaxgmac fff50000.ethernet (unregistered net_device): h/w version is 0x1012

Otherwise,

Quoted 29 lines
---
 drivers/net/ethernet/calxeda/xgmac.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/calxeda/xgmac.c +3 -3
index f7f0290..f91d9b2 100644
@@ -1715,9 +1715,6 @@ static int xgmac_probe(struct platform_device *pdev)
 		goto err_io;
 	}
 
-	uid = readl(priv->base + XGMAC_VERSION);
-	netdev_info(ndev, "h/w version is 0x%x\n", uid);
-
 	writel(0, priv->base + XGMAC_DMA_INTR_ENA);
 	ndev->irq = platform_get_irq(pdev, 0);
 	if (ndev->irq == -ENXIO) {
@@ -1771,6 +1768,9 @@ static int xgmac_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_reg;
 
+	uid = readl(priv->base + XGMAC_VERSION);
+	netdev_info(ndev, "h/w version is 0x%x\n", uid);
+
 	return 0;
 
 err_reg:
author
#3 lore raw

Re: [PATCH 1/2] net: calexdaxgmac: fix printing of hardware version

Quoted 6 lines · Rob Herring
Quoted 3 lines · Ben Dooks

The current driver attempts to print netdev_info() before registering the network device and allowing the name to be set. Change this print to be after the network deviec has been registered, and thus has been allocated

You missed the typo pointed out on the first version sent to lakml.

Oops, sorry.

Quoted 11 lines
Quoted 7 lines

a network device name.

Fix the following issue:

calxedaxgmac fff50000.ethernet (unregistered net_device): h/w version is 0x1012

Otherwise,

Thanks.

Signature · 2 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius
author
#4 lore raw

PATCH 2/2 net: calexdaxgmac: fixup endian issues after __raw IO function change

In reply to Ben Dooks

When changing to __raw acccessors in 0ec6d343f7bcf9e0944aa9ff65287b987ec00c0f ("net: calxedaxgmac: use raw i/o accessors in rx and tx paths"), the driver is now broken on big endian systems as the readl/writel have an implict endian swap in them.

Change all the places where the __raw calls are used to correctly convert the constants in big endian format to the little endian data that the peripheral expects to see.

---
 drivers/net/ethernet/calxeda/xgmac.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/calxeda/xgmac.c +7 -3
index f91d9b2..96fd538 100644
@@ -1202,7 +1202,8 @@ static int xgmac_poll(struct napi_struct *napi, int budget)
 
 	if (work_done < budget) {
 		napi_complete(napi);
-		__raw_writel(DMA_INTR_DEFAULT_MASK, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_DEFAULT_MASK),
+			     priv->base + XGMAC_DMA_INTR_ENA);
 	}
 	return work_done;
 }
@@ -1348,7 +1349,7 @@ static irqreturn_t xgmac_pmt_interrupt(int irq, void *dev_id)
 	void __iomem *ioaddr = priv->base;
 
 	intr_status = __raw_readl(ioaddr + XGMAC_INT_STAT);
-	if (intr_status & XGMAC_INT_STAT_PMT) {
+	if (intr_status & le32_to_cpu((__force __le32)XGMAC_INT_STAT_PMT)) {
 		netdev_dbg(priv->dev, "received Magic frame\n");
 		/* clear the PMT bits 5 and 6 by reading the PMT */
 		readl(ioaddr + XGMAC_PMT);
@@ -1369,6 +1370,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
 	intr_status &= __raw_readl(priv->base + XGMAC_DMA_INTR_ENA);
 	__raw_writel(intr_status, priv->base + XGMAC_DMA_STATUS);
 
+	intr_status = (__force u32)cpu_to_le32(intr_status);
+
 	/* It displays the DMA process states (CSR5 register) */
 	/* ABNORMAL interrupts */
 	if (unlikely(intr_status & DMA_STATUS_AIS)) {
@@ -1403,7 +1406,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
 
 	/* TX/RX NORMAL interrupts */
 	if (intr_status & (DMA_STATUS_RI | DMA_STATUS_TU | DMA_STATUS_TI)) {
-		__raw_writel(DMA_INTR_ABNORMAL, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_ABNORMAL),
+			     priv->base + XGMAC_DMA_INTR_ENA);
 		napi_schedule(&priv->napi);
 	}
 
Signature · 1 line
1.7.10.4
#5 lore raw

Re: [PATCH 2/2] net: calexdaxgmac: fixup endian issues after __raw IO function change

Quoted 8 lines · Ben Dooks

When changing to __raw acccessors in 0ec6d343f7bcf9e0944aa9ff65287b987ec00c0f ("net: calxedaxgmac: use raw i/o accessors in rx and tx paths"), the driver is now broken on big endian systems as the readl/writel have an implict endian swap in them.

Change all the places where the __raw calls are used to correctly convert the constants in big endian format to the little endian data that the peripheral expects to see.

This is a bit ugly. The correct fix is really to enable the _relaxed accessors on more arches.

Perhaps a local definition of readl_relaxed and writel_relaxed would be a cleaner temporary solution.

Rob

Quoted 49 lines
---
 drivers/net/ethernet/calxeda/xgmac.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/calxeda/xgmac.c +7 -3
index f91d9b2..96fd538 100644
@@ -1202,7 +1202,8 @@ static int xgmac_poll(struct napi_struct *napi, int budget)
 
 	if (work_done < budget) {
 		napi_complete(napi);
-		__raw_writel(DMA_INTR_DEFAULT_MASK, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_DEFAULT_MASK),
+			     priv->base + XGMAC_DMA_INTR_ENA);
 	}
 	return work_done;
 }
@@ -1348,7 +1349,7 @@ static irqreturn_t xgmac_pmt_interrupt(int irq, void *dev_id)
 	void __iomem *ioaddr = priv->base;
 
 	intr_status = __raw_readl(ioaddr + XGMAC_INT_STAT);
-	if (intr_status & XGMAC_INT_STAT_PMT) {
+	if (intr_status & le32_to_cpu((__force __le32)XGMAC_INT_STAT_PMT)) {
 		netdev_dbg(priv->dev, "received Magic frame\n");
 		/* clear the PMT bits 5 and 6 by reading the PMT */
 		readl(ioaddr + XGMAC_PMT);
@@ -1369,6 +1370,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
 	intr_status &= __raw_readl(priv->base + XGMAC_DMA_INTR_ENA);
 	__raw_writel(intr_status, priv->base + XGMAC_DMA_STATUS);
 
+	intr_status = (__force u32)cpu_to_le32(intr_status);
+
 	/* It displays the DMA process states (CSR5 register) */
 	/* ABNORMAL interrupts */
 	if (unlikely(intr_status & DMA_STATUS_AIS)) {
@@ -1403,7 +1406,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
 
 	/* TX/RX NORMAL interrupts */
 	if (intr_status & (DMA_STATUS_RI | DMA_STATUS_TU | DMA_STATUS_TI)) {
-		__raw_writel(DMA_INTR_ABNORMAL, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_ABNORMAL),
+			     priv->base + XGMAC_DMA_INTR_ENA);
 		napi_schedule(&priv->napi);
 	}
 
#6 lore raw

Re: [PATCH 2/2] net: calexdaxgmac: fixup endian issues after __raw IO function change

In reply to Ben Dooks
Quoted 8 lines · Ben Dooks

When changing to __raw acccessors in 0ec6d343f7bcf9e0944aa9ff65287b987ec00c0f ("net: calxedaxgmac: use raw i/o accessors in rx and tx paths"), the driver is now broken on big endian systems as the readl/writel have an implict endian swap in them.

Change all the places where the __raw calls are used to correctly convert the constants in big endian format to the little endian data that the peripheral expects to see.

You are using le32_to_cpu() and cpu_to_le32() the wrong way round, and then putting casts on the wrong side, i.e. it should be:

	value = le32_to_cpu((__force __le32)__raw_readl(addr));
	__raw_writel((__force u32)cpu_to_le32(value), addr);

(I do wonder why __raw I/O functions aren't declared to take/return __le types... it would avoid the need to cast altogether.)

Quoted 29 lines
---
 drivers/net/ethernet/calxeda/xgmac.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/calxeda/xgmac.c +3 -2
index f91d9b2..96fd538 100644
@@ -1202,7 +1202,8 @@ static int xgmac_poll(struct napi_struct *napi, int budget)
 
 	if (work_done < budget) {
 		napi_complete(napi);
-		__raw_writel(DMA_INTR_DEFAULT_MASK, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_DEFAULT_MASK),
+			     priv->base + XGMAC_DMA_INTR_ENA);
 	}
 	return work_done;
 }
@@ -1348,7 +1349,7 @@ static irqreturn_t xgmac_pmt_interrupt(int irq, void *dev_id)
 	void __iomem *ioaddr = priv->base;
 
 	intr_status = __raw_readl(ioaddr + XGMAC_INT_STAT);
-	if (intr_status & XGMAC_INT_STAT_PMT) {
+	if (intr_status & le32_to_cpu((__force __le32)XGMAC_INT_STAT_PMT)) {
 		netdev_dbg(priv->dev, "received Magic frame\n");
 		/* clear the PMT bits 5 and 6 by reading the PMT */
 		readl(ioaddr + XGMAC_PMT);

drivers/net/ethernet/calxeda/xgmac.c static irqreturn_t xgmac_interrupt(int irq, void *dev_id) · line 1373

Quoted 4 lines
drivers/net/ethernet/calxeda/xgmac.c +1 -0
@@ -1369,6 +1370,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
 	intr_status &= __raw_readl(priv->base + XGMAC_DMA_INTR_ENA);
 	__raw_writel(intr_status, priv->base + XGMAC_DMA_STATUS);
 
+	intr_status = (__force u32)cpu_to_le32(intr_status);

Perhaps intr_status should be split into two variables, for native and little-endian order.

Ben.

Quoted 13 lines
drivers/net/ethernet/calxeda/xgmac.c +2 -1
 	/* It displays the DMA process states (CSR5 register) */
 	/* ABNORMAL interrupts */
 	if (unlikely(intr_status & DMA_STATUS_AIS)) {
@@ -1403,7 +1406,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
 
 	/* TX/RX NORMAL interrupts */
 	if (intr_status & (DMA_STATUS_RI | DMA_STATUS_TU | DMA_STATUS_TI)) {
-		__raw_writel(DMA_INTR_ABNORMAL, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_ABNORMAL),
+			     priv->base + XGMAC_DMA_INTR_ENA);
 		napi_schedule(&priv->napi);
 	}
 
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
author
#7 lore raw

Re: [PATCH 2/2] net: calexdaxgmac: fixup endian issues after __raw IO function change

Quoted 10 lines · Ben Hutchings
Quoted 8 lines · Ben Dooks

When changing to __raw acccessors in 0ec6d343f7bcf9e0944aa9ff65287b987ec00c0f ("net: calxedaxgmac: use raw i/o accessors in rx and tx paths"), the driver is now broken on big endian systems as the readl/writel have an implict endian swap in them.

Change all the places where the __raw calls are used to correctly convert the constants in big endian format to the little endian data that the peripheral expects to see.

Quoted 8 lines

You are using le32_to_cpu() and cpu_to_le32() the wrong way round, and then putting casts on the wrong side, i.e. it should be:

	value = le32_to_cpu((__force __le32)__raw_readl(addr));
	__raw_writel((__force u32)cpu_to_le32(value), addr);

(I do wonder why __raw I/O functions aren't declared to take/return __le types... it would avoid the need to cast altogether.)

Because they do things with the order the cpu is working in, the read{x} and write{x} transfer cpu to bus-endian so returning an __le type would not be correct.

I think you are right about the conversions, it is a headache trying to think through.

It may be easier to provide _relaxed IO variants for all systems so that we can avoid this in future.

Quoted 32 lines
Quoted 32 lines
---
  drivers/net/ethernet/calxeda/xgmac.c |   10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/calxeda/xgmac.c +3 -2
index f91d9b2..96fd538 100644
@@ -1202,7 +1202,8 @@ static int xgmac_poll(struct napi_struct *napi, int budget)
 
  	if (work_done<  budget) {
  		napi_complete(napi);
-		__raw_writel(DMA_INTR_DEFAULT_MASK, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_DEFAULT_MASK),
+			     priv->base + XGMAC_DMA_INTR_ENA);
  	}
  	return work_done;
  }
@@ -1348,7 +1349,7 @@ static irqreturn_t xgmac_pmt_interrupt(int irq, void *dev_id)
  	void __iomem *ioaddr = priv->base;
 
  	intr_status = __raw_readl(ioaddr + XGMAC_INT_STAT);
-	if (intr_status&  XGMAC_INT_STAT_PMT) {
+	if (intr_status&  le32_to_cpu((__force __le32)XGMAC_INT_STAT_PMT)) {
  		netdev_dbg(priv->dev, "received Magic frame\n");
  		/* clear the PMT bits 5 and 6 by reading the PMT */
  		readl(ioaddr + XGMAC_PMT);
@@ -1369,6 +1370,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
  	intr_status&= __raw_readl(priv->base + XGMAC_DMA_INTR_ENA);
  	__raw_writel(intr_status, priv->base + XGMAC_DMA_STATUS);
 
Quoted 6 lines

drivers/net/ethernet/calxeda/xgmac.c static irqreturn_t xgmac_interrupt(int irq, void *dev_id) · line 1373

Quoted 1 line
drivers/net/ethernet/calxeda/xgmac.c +1 -0
+	intr_status = (__force u32)cpu_to_le32(intr_status);

Perhaps intr_status should be split into two variables, for native and little-endian order.

Ben.

That would be a possibility, although it would end up changing more code.

Quoted 14 lines
Quoted 13 lines
drivers/net/ethernet/calxeda/xgmac.c +2 -1
  	/* It displays the DMA process states (CSR5 register) */
  	/* ABNORMAL interrupts */
  	if (unlikely(intr_status&  DMA_STATUS_AIS)) {
@@ -1403,7 +1406,8 @@ static irqreturn_t xgmac_interrupt(int irq, void *dev_id)
 
  	/* TX/RX NORMAL interrupts */
  	if (intr_status&  (DMA_STATUS_RI | DMA_STATUS_TU | DMA_STATUS_TI)) {
-		__raw_writel(DMA_INTR_ABNORMAL, priv->base + XGMAC_DMA_INTR_ENA);
+		__raw_writel(le32_to_cpu((__force __le32)DMA_INTR_ABNORMAL),
+			     priv->base + XGMAC_DMA_INTR_ENA);
  		napi_schedule(&priv->napi);
  	}
 
Signature · 2 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius
#8 lore raw

RE: [PATCH 2/2] net: calexdaxgmac: fixup endian issues after __raw IO function change

Quoted 6 lines
Quoted 6 lines

You are using le32_to_cpu() and cpu_to_le32() the wrong way round, and then putting casts on the wrong side, i.e. it should be:

	value = le32_to_cpu((__force __le32)__raw_readl(addr));
	__raw_writel((__force u32)cpu_to_le32(value), addr);
Quoted 6 lines
Quoted 2 lines

(I do wonder why __raw I/O functions aren't declared to take/return __le types... it would avoid the need to cast altogether.)

Because they do things with the order the cpu is working in, the read{x} and write{x} transfer cpu to bus-endian so returning an __le type would not be correct.

Surely you want to arrange to use the byte-swapping memory read/write instructions, rather than byteswapping the value.

Particularly on ppc which doesn't have a byteswap instruction but can do byteswapping memory accesses.

David