Skip to contentSkip to conversation

bcm63xx_enet: add support Broadcom BCM6345 Ethernet

PATCH Applied Florian Fainelli 4 participants 9 messages Jun 12, 2013 – Jun 14, 2013 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcm63xx_enet: add support Broadcom BCM6345 Ethernet

This patch adds support for the Broadcom BCM6345 SoC Ethernet. BCM6345 has a slightly different and older DMA engine which requires the following modifications:

- the width of the DMA channels on BCM6345 is 64 bytes vs 16 bytes, which means that the helpers enet_dma{c,s} need to account for this channel width and we can no longer use macros

- BCM6345 DMA engine does not have any internal SRAM for transfering buffers

- BCM6345 buffer allocation and flow control is not per-channel but global (done in RSET_ENETDMA)

- the DMA engine bits are right-shifted by 3 compared to other DMA generations

- the DMA enable/interrupt masks are a little different (we need to enabled more bits for 6345)

- some register have the same meaning but are offsetted in the ENET_DMAC space so a lookup table is required to return the proper offset

The MAC itself is identical and requires no modifications to work.

---
Ralf, David,

Once again there are MIPS bits that required some changes, but the major changes are in bcm63xx_enet.c so it would make sense to get them merged via David's net-next tree.

Thank you!

 arch/mips/bcm63xx/dev-enet.c                       |   65 ++++++-
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h   |    3 +-
 .../include/asm/mach-bcm63xx/bcm63xx_dev_enet.h    |   94 +++++++++
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h  |   43 ++++-
 drivers/net/ethernet/broadcom/bcm63xx_enet.c       |  200 ++++++++++++--------
 drivers/net/ethernet/broadcom/bcm63xx_enet.h       |   15 ++
 6 files changed, 329 insertions(+), 91 deletions(-)
arch/mips/bcm63xx/dev-enet.c +63 -2
index 6cbaee0..52bc01d 100644
@@ -9,10 +9,44 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
+#include <linux/export.h>
 #include <bcm63xx_dev_enet.h>
 #include <bcm63xx_io.h>
 #include <bcm63xx_regs.h>
 
+#ifdef BCMCPU_RUNTIME_DETECT
+static const unsigned long bcm6348_regs_enetdmac[] = {
+	[ENETDMAC_CHANCFG]	= ENETDMAC_CHANCFG_REG,
+	[ENETDMAC_IR]		= ENETDMAC_IR_REG,
+	[ENETDMAC_IRMASK]	= ENETDMAC_IRMASK_REG,
+	[ENETDMAC_MAXBURST]	= ENETDMAC_MAXBURST_REG,
+};
+
+static const unsigned long bcm6345_regs_enetdmac[] = {
+	[ENETDMAC_CHANCFG]	= ENETDMA_6345_CHANCFG_REG,
+	[ENETDMAC_IR]		= ENETDMA_6345_IR_REG,
+	[ENETDMAC_IRMASK]	= ENETDMA_6345_IRMASK_REG,
+	[ENETDMAC_MAXBURST]	= ENETDMA_6345_MAXBURST_REG,
+	[ENETDMAC_BUFALLOC]	= ENETDMA_6345_BUFALLOC_REG,
+	[ENETDMAC_RSTART]	= ENETDMA_6345_RSTART_REG,
+	[ENETDMAC_FC]		= ENETDMA_6345_FC_REG,
+	[ENETDMAC_LEN]		= ENETDMA_6345_LEN_REG,
+};
+
+const unsigned long *bcm63xx_regs_enetdmac;
+EXPORT_SYMBOL(bcm63xx_regs_enetdmac);
+
+static __init void bcm63xx_enetdmac_regs_init(void)
+{
+	if (BCMCPU_IS_6345())
+		bcm63xx_regs_enetdmac = bcm6345_regs_enetdmac;
+	else
+		bcm63xx_regs_enetdmac = bcm6348_regs_enetdmac;
+}
+#else
+static __init void bcm63xx_enetdmac_regs_init(void) { }
+#endif
+
 static struct resource shared_res[] = {
 	{
 		.start		= -1, /* filled at runtime */
@@ -137,12 +171,19 @@ static int __init register_shared(void)
 	if (shared_device_registered)
 		return 0;
 
+	bcm63xx_enetdmac_regs_init();
+
 	shared_res[0].start = bcm63xx_regset_address(RSET_ENETDMA);
 	shared_res[0].end = shared_res[0].start;
-	shared_res[0].end += (RSET_ENETDMA_SIZE)  - 1;
+	if (BCMCPU_IS_6345())
+		shared_res[0].end += (RSET_6345_ENETDMA_SIZE) - 1;
+	else
+		shared_res[0].end += (RSET_ENETDMA_SIZE)  - 1;
 
 	if (BCMCPU_IS_6328() || BCMCPU_IS_6362() || BCMCPU_IS_6368())
 		chan_count = 32;
+	else if (BCMCPU_IS_6345())
+		chan_count = 8;
 	else
 		chan_count = 16;
 
@@ -172,7 +213,7 @@ int __init bcm63xx_enet_register(int unit,
 	if (unit > 1)
 		return -ENODEV;
 
-	if (unit == 1 && BCMCPU_IS_6338())
+	if (unit == 1 && (BCMCPU_IS_6338() || BCMCPU_IS_6345()))
 		return -ENODEV;
 
 	ret = register_shared();
@@ -213,6 +254,21 @@ int __init bcm63xx_enet_register(int unit,
 		dpd->phy_interrupt = bcm63xx_get_irq_number(IRQ_ENET_PHY);
 	}
 
+	dpd->dma_chan_en_mask = ENETDMAC_CHANCFG_EN_MASK;
+	dpd->dma_chan_int_mask = ENETDMAC_IR_PKTDONE_MASK;
+	if (BCMCPU_IS_6345()) {
+		dpd->dma_chan_en_mask |= ENETDMAC_CHANCFG_CHAINING_MASK;
+		dpd->dma_chan_en_mask |= ENETDMAC_CHANCFG_WRAP_EN_MASK;
+		dpd->dma_chan_en_mask |= ENETDMAC_CHANCFG_FLOWC_EN_MASK;
+		dpd->dma_chan_int_mask |= ENETDMA_IR_BUFDONE_MASK;
+		dpd->dma_chan_int_mask |= ENETDMA_IR_NOTOWNER_MASK;
+		dpd->dma_chan_width = ENETDMA_6345_CHAN_WIDTH;
+		dpd->dma_desc_shift = ENETDMA_6345_DESC_SHIFT;
+	} else {
+		dpd->dma_has_sram = true;
+		dpd->dma_chan_width = ENETDMA_CHAN_WIDTH;
+	}
+
 	ret = platform_device_register(pdev);
 	if (ret)
 		return ret;
@@ -246,6 +302,11 @@ bcm63xx_enetsw_register(const struct bcm63xx_enetsw_platform_data *pd)
 	else if (BCMCPU_IS_6362() || BCMCPU_IS_6368())
 		enetsw_pd.num_ports = ENETSW_PORTS_6368;
 
+	enetsw_pd.dma_has_sram = true;
+	enetsw_pd.dma_chan_width = ENETDMA_CHAN_WIDTH;
+	enetsw_pd.dma_chan_en_mask = ENETDMAC_CHANCFG_EN_MASK;
+	enetsw_pd.dma_chan_int_mask = ENETDMAC_IR_PKTDONE_MASK;
+
 	ret = platform_device_register(&bcm63xx_enetsw_device);
 	if (ret)
 		return ret;
arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h +2 -1
index 9981f4f..e6e65dc 100644
@@ -174,6 +174,7 @@ enum bcm63xx_regs_set {
 #define BCM_6368_RSET_SPI_SIZE		1804
 #define RSET_ENET_SIZE			2048
 #define RSET_ENETDMA_SIZE		256
+#define RSET_6345_ENETDMA_SIZE		64
 #define RSET_ENETDMAC_SIZE(chans)	(16 * (chans))
 #define RSET_ENETDMAS_SIZE(chans)	(16 * (chans))
 #define RSET_ENETSW_SIZE		65536
@@ -300,7 +301,7 @@ enum bcm63xx_regs_set {
 #define BCM_6345_USBDMA_BASE		(0xfffe2800)
 #define BCM_6345_ENET0_BASE		(0xfffe1800)
 #define BCM_6345_ENETDMA_BASE		(0xfffe2800)
-#define BCM_6345_ENETDMAC_BASE		(0xfffe2900)
+#define BCM_6345_ENETDMAC_BASE		(0xfffe2840)
 #define BCM_6345_ENETDMAS_BASE		(0xfffe2a00)
 #define BCM_6345_ENETSW_BASE		(0xdeadbeef)
 #define BCM_6345_PCMCIA_BASE		(0xfffe2028)
arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_enet.h +94 -0

116 lines not on this page · raw message

arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h +35 -8

88 lines not on this page · raw message

drivers/net/ethernet/broadcom/bcm63xx_enet.c +120 -80

402 lines not on this page · raw message

drivers/net/ethernet/broadcom/bcm63xx_enet.h +15 -0
index 721ffba..f55af43 100644
@@ -339,6 +339,21 @@ struct bcm_enet_priv {
 	/* used to poll switch port state */
 	struct timer_list swphy_poll;
 	spinlock_t enetsw_mdio_lock;
+
+	/* dma channel enable mask */
+	u32 dma_chan_en_mask;
+
+	/* dma channel interrupt mask */
+	u32 dma_chan_int_mask;
+
+	/* DMA engine has internal SRAM */
+	bool dma_has_sram;
+
+	/* dma channel width */
+	unsigned int dma_chan_width;
+
+	/* dma descriptor shift value */
+	unsigned int dma_desc_shift;
 };
 
 
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw

From: Florian Fainelli <[email protected]>
Date: Wed, 12 Jun 2013 20:53:05 +0100

Quoted 1 line

+#ifdef BCMCPU_RUNTIME_DETECT

I want the MIPS folks to fix this brain damange.

This runtime detect thing is just a big mess in a header file using hundreds of lines of CPP stuff to express what is fundamentally a simple (albeit sizable) Kconfig dependency.

And this ifdef virus spreads from that header file now into this driver.

How can it possibly make sense to have this "maybe it's static at build time, maybe it's dynamic" coded into every single piece of code for platform drivers or any other thing related to this set of MIPSs cpus?

It's rediculous, and I refuse to add code to my tree which continues this trend, sorry.

maintainer
#3 lore raw
In reply to a message not in the archive

From: Florian Fainelli <[email protected]>
Date: Thu, 13 Jun 2013 09:58:34 +0100

Quoted 6 lines

2013/6/13 David Miller <[email protected]>:

Quoted 5 lines

From: Florian Fainelli <[email protected]>
Date: Wed, 12 Jun 2013 20:53:05 +0100

Quoted 1 line

+#ifdef BCMCPU_RUNTIME_DETECT

Quoted 7 lines
Quoted 5 lines

I want the MIPS folks to fix this brain damange.

This runtime detect thing is just a big mess in a header file using hundreds of lines of CPP stuff to express what is fundamentally a simple (albeit sizable) Kconfig dependency.

The codebase supporting the Broadcom BCM63xx SoC supports about 6-7

You don't need to explain it to me, I read the code and understand what it's trying to accomplish.

I reject the implementation of it, only.

Quoted 3 lines

No, the ifdefs are kept in the arch/mips/bcm63xx portions of the code specifically for that reason. The driver just needs to take into account a new set of platform_data properties to deal with this.

Fine, it's still terrible.

#4 lore raw

2013/6/13 David Miller <[email protected]>

Quoted 21 lines

From: Florian Fainelli <[email protected]>
Date: Thu, 13 Jun 2013 09:58:34 +0100

Quoted 6 lines

2013/6/13 David Miller <[email protected]>:

Quoted 5 lines

From: Florian Fainelli <[email protected]>
Date: Wed, 12 Jun 2013 20:53:05 +0100

Quoted 1 line

+#ifdef BCMCPU_RUNTIME_DETECT

Quoted 7 lines
Quoted 5 lines

I want the MIPS folks to fix this brain damange.

This runtime detect thing is just a big mess in a header file using hundreds of lines of CPP stuff to express what is fundamentally a simple (albeit sizable) Kconfig dependency.

The codebase supporting the Broadcom BCM63xx SoC supports about 6-7

You don't need to explain it to me, I read the code and understand what it's trying to accomplish.

Quoted 7 lines

I reject the implementation of it, only.

Quoted 3 lines

No, the ifdefs are kept in the arch/mips/bcm63xx portions of the code specifically for that reason. The driver just needs to take into account a new set of platform_data properties to deal with this.

Fine, it's still terrible.

We are in the slow process to switch to Device Tree to precisely eliminate all of this (although not everyone agrees yet on the details). Hopefully you should not see such things in the future.

Thanks

#5 lore raw

2013/6/13 Florian Fainelli <[email protected]>:

Quoted 24 lines

2013/6/13 David Miller <[email protected]>

Quoted 23 lines

From: Florian Fainelli <[email protected]>
Date: Thu, 13 Jun 2013 09:58:34 +0100

Quoted 6 lines

2013/6/13 David Miller <[email protected]>:

Quoted 5 lines

From: Florian Fainelli <[email protected]>
Date: Wed, 12 Jun 2013 20:53:05 +0100

Quoted 1 line

+#ifdef BCMCPU_RUNTIME_DETECT

Quoted 7 lines
Quoted 5 lines

I want the MIPS folks to fix this brain damange.

This runtime detect thing is just a big mess in a header file using hundreds of lines of CPP stuff to express what is fundamentally a simple (albeit sizable) Kconfig dependency.

The codebase supporting the Broadcom BCM63xx SoC supports about 6-7

You don't need to explain it to me, I read the code and understand what it's trying to accomplish.

I reject the implementation of it, only.

You have marked the patch as Rejected in patchwork, so what is the right way to move on with this?

maintainer
#6 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Thu, 13 Jun 2013 10:49:18 +0100

Quoted 3 lines

We are in the slow process to switch to Device Tree to precisely eliminate all of this (although not everyone agrees yet on the details). Hopefully you should not see such things in the future.

Fair enough, I'll put this patch back into my TODO queue.

Acked-by
#7 lore raw
Quoted 8 lines · David Miller

From: Florian Fainelli <[email protected]>
Date: Thu, 13 Jun 2013 10:49:18 +0100

Quoted 3 lines

We are in the slow process to switch to Device Tree to precisely eliminate all of this (although not everyone agrees yet on the details). Hopefully you should not see such things in the future.

Fair enough, I'll put this patch back into my TODO queue.

David is right, one pair of welding goggles isn't enough to cope with the uglyness of this but as a temporary thing I can live with it, so

Dave, feel free to merge this through next-next. I'm going to drop this patch from the MIPS patchwork then.

Ralf

#9 lore raw
In reply to Florian Fainelli
Quoted 3 lines · Florian Fainelli

We are in the slow process to switch to Device Tree to precisely eliminate all of this (although not everyone agrees yet on the details). Hopefully you should not see such things in the future.

I don't see how DT help here (hint: it never does)

if the driver knows at compile time how registers are shuffled, it can remove the indirection

if you use runtime cpu detection or DT, it cannot

in fact, this patch already adds another layer of indirection with that "dma_chan_width" thing that the compiler has no way to optimize out, defeating the purpose of single SOC optimization.

so we might as well force multi SOC support

Signature · 1 line
Maxime
maintainer Applied
#8 lore raw
In reply to Ralf Baechle

From: Ralf Baechle <[email protected]>
Date: Thu, 13 Jun 2013 15:59:21 +0200

Quoted 11 lines · David Miller
Quoted 9 lines

From: Florian Fainelli <[email protected]>
Date: Thu, 13 Jun 2013 10:49:18 +0100

Quoted 3 lines

We are in the slow process to switch to Device Tree to precisely eliminate all of this (although not everyone agrees yet on the details). Hopefully you should not see such things in the future.

Fair enough, I'll put this patch back into my TODO queue.

Quoted 7 lines

David is right, one pair of welding goggles isn't enough to cope with the uglyness of this but as a temporary thing I can live with it, so

Dave, feel free to merge this through next-next. I'm going to drop this patch from the MIPS patchwork then.

Applied to net-next, thanks everyone.