Skip to contentSkip to conversation

lpc32xx: Added ethernet driver

PATCH Superseded Roland Stigge 4 participants 5 messages Feb 27, 2012 – Mar 1, 2012

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 lpc32xx: Added ethernet driver

This patch adds an ethernet driver for the LPC32xx ARM SoC.

---
 drivers/net/ethernet/Kconfig       |    1 
 drivers/net/ethernet/Makefile      |    1 
 drivers/net/ethernet/nxp/Kconfig   |    8 
 drivers/net/ethernet/nxp/Makefile  |    1 
 drivers/net/ethernet/nxp/lpc_eth.c | 1311 +++++++++++++++++++++++++++++++++++++
 drivers/net/ethernet/nxp/lpc_eth.h |  336 +++++++++
 6 files changed, 1658 insertions(+)
drivers/net/ethernet/Kconfig +1 -0
@@ -126,6 +126,7 @@ config NET_NETX
 
 source "drivers/net/ethernet/nuvoton/Kconfig"
 source "drivers/net/ethernet/nvidia/Kconfig"
+source "drivers/net/ethernet/nxp/Kconfig"
 source "drivers/net/ethernet/octeon/Kconfig"
 source "drivers/net/ethernet/oki-semi/Kconfig"
 
drivers/net/ethernet/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_NET_VENDOR_NATSEMI) += nats
 obj-$(CONFIG_NET_NETX) += netx-eth.o
 obj-$(CONFIG_NET_VENDOR_NUVOTON) += nuvoton/
 obj-$(CONFIG_NET_VENDOR_NVIDIA) += nvidia/
+obj-$(CONFIG_LPC_ENET) += nxp/
 obj-$(CONFIG_OCTEON_MGMT_ETHERNET) += octeon/
 obj-$(CONFIG_NET_VENDOR_OKI) += oki-semi/
 obj-$(CONFIG_ETHOC) += ethoc.o
drivers/net/ethernet/nxp/Kconfig new file +8 -0
@@ -0,0 +1,8 @@
+config LPC_ENET
+        tristate "NXP ethernet MAC on LPC devices"
+        depends on ARCH_LPC32XX
+        select PHYLIB
+        help
+	  Say Y or M here if you want to use the NXP ethernet MAC included on
+	  some NXP LPC devices. You can safely enable this option for LPC32xx
+	  SoC. Also available as a module.
drivers/net/ethernet/nxp/Makefile new file +1 -0
@@ -0,0 +1 @@
+obj-$(CONFIG_LPC_ENET) += lpc_eth.o
drivers/net/ethernet/nxp/lpc_eth.c new file +1311 -0

1,311 lines not on this page · raw message

drivers/net/ethernet/nxp/lpc_eth.h new file +336 -0

336 lines not on this page · raw message

#1 lore raw
Quoted 1 line · Roland Stigge

This patch adds an ethernet driver for the LPC32xx ARM SoC.

This looks nicer to me, thanks.
Just a few more trivial comments.

[]

Quoted 1 line

+++ linux-2.6/drivers/net/ethernet/nxp/lpc_eth.c

[]

drivers/net/ethernet/nxp/lpc_eth.c line 381

Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4 -0
+static int lpc_mdio_read(struct mii_bus *bus, int phy_id, int phyreg)
+{
+	struct netdata_local *pldat = bus->priv;
+	unsigned long timeout = jiffies + ((HZ * 100) / 1000); /* 100mS */

msecs_to_jiffies?

drivers/net/ethernet/nxp/lpc_eth.c line 566

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2 -0
+static void __lpc_handle_xmit(struct net_device *ndev)
+{

[]

drivers/net/ethernet/nxp/lpc_eth.c line 590

Quoted 3 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +3 -0
+		/* Any errors occurred? */
+		if (txstat & 0x80000000) {
+			if (txstat & 0x20000000) {

It might be clearer to use #defines

drivers/net/ethernet/nxp/lpc_eth.c line 598

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+				/* FIFO underrun */
+				ndev->stats.tx_fifo_errors++;
+				ndev->stats.tx_errors++;
+			}
+			if (txstat & 0x10000000) {
+				/* Late collision */
+				ndev->stats.tx_aborted_errors++;
+				ndev->stats.tx_errors++;

double counting tx_errors?

#2 lore raw
In reply to Roland Stigge
Quoted 12 lines

This patch adds an ethernet driver for the LPC32xx ARM SoC.

---

drivers/net/ethernet/Kconfig       |    1 
drivers/net/ethernet/Makefile      |    1 
drivers/net/ethernet/nxp/Kconfig   |    8 
drivers/net/ethernet/nxp/Makefile  |    1 
drivers/net/ethernet/nxp/lpc_eth.c | 1311 +++++++++++++++++++++++++++++++++++++
drivers/net/ethernet/nxp/lpc_eth.h |  336 +++++++++
6 files changed, 1658 insertions(+)

...

drivers/net/ethernet/nxp/lpc_eth.c line 65

Quoted 11 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +11 -0
+#define ENET_MAXF_SIZE 1536
+#define ENET_RX_DESC 48
+#define ENET_TX_DESC 16
+
+/*
+ * FIXME
+ * Dynamic buffer allocation as needed
+ * Check/fix ethtool support
+ * Better MAC address support
+ * Better DMA allocation support (dma pool)
+ */

Although the packet buffers are handled correctly, the number of MAC DMA descriptors are hard coded to the ENET_RX_DESC and ENET_TX_DESC size values. There is also a 'funky' scheme for doing virt<>phy address translation for the descriptors.

I'm ok with releasing this driver "as is" with its current quirks, but I do think these fixmes need to be fixed at some time.

#3 lore raw
In reply to Roland Stigge
Quoted 11 lines · Roland Stigge

This patch adds an ethernet driver for the LPC32xx ARM SoC.

---
 drivers/net/ethernet/Kconfig       |    1 
 drivers/net/ethernet/Makefile      |    1 
 drivers/net/ethernet/nxp/Kconfig   |    8 
 drivers/net/ethernet/nxp/Makefile  |    1 
 drivers/net/ethernet/nxp/lpc_eth.c | 1311 +++++++++++++++++++++++++++++++++++++
 drivers/net/ethernet/nxp/lpc_eth.h |  336 +++++++++

Just merge the header into the implementation file, it's not used an an interface between two .c files.

drivers/net/ethernet/Makefile obj-$(CONFIG_NET_VENDOR_NATSEMI) += nats · line 53

Quoted 10 lines
drivers/net/ethernet/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_NET_VENDOR_NATSEMI) += nats
 obj-$(CONFIG_NET_NETX) += netx-eth.o
 obj-$(CONFIG_NET_VENDOR_NUVOTON) += nuvoton/
 obj-$(CONFIG_NET_VENDOR_NVIDIA) += nvidia/
+obj-$(CONFIG_LPC_ENET) += nxp/
 obj-$(CONFIG_OCTEON_MGMT_ETHERNET) += octeon/
 obj-$(CONFIG_NET_VENDOR_OKI) += oki-semi/
 obj-$(CONFIG_ETHOC) += ethoc.o

Are you sure that npx is actually the origin of this controller? If they only licensed the IP themselves, it would be better to list it under the name of the actual creator so that the next person who has the same core can find it.

Quoted 22 lines
drivers/net/ethernet/Makefile +22 -0
+static irqreturn_t __lpc_eth_interrupt(int irq, void *dev_id)
+{
+	struct net_device *ndev = dev_id;
+	struct netdata_local *pldat = netdev_priv(ndev);
+	u32 tmp;
+	unsigned long flags;
+
+	spin_lock_irqsave(&pldat->lock, flags);
+
+	while ((tmp = readl(LPC_ENET_INTSTATUS(pldat->net_base)))) {
+		/* Clear interrupts */
+		writel(tmp, LPC_ENET_INTCLEAR(pldat->net_base));
+
+		/* Transmit complete? */
+		if (tmp & (LPC_MACINT_TXUNDERRUNINTEN |
+				LPC_MACINT_TXERRORINTEN |
+				LPC_MACINT_TXFINISHEDINTEN |
+				LPC_MACINT_TXDONEINTEN))
+			__lpc_handle_xmit(ndev);
+
+		/* Receive buffer available */
+		if (tmp & (LPC_MACINT_RXOVERRUNINTEN |

drivers/net/ethernet/Makefile

Quoted 10 lines
drivers/net/ethernet/Makefile +10 -0
+				LPC_MACINT_RXERRORONINT |
+				LPC_MACINT_RXFINISHEDINTEN |
+				LPC_MACINT_RXDONEINTEN))
+			__lpc_handle_recv(ndev);
+	}
+
+	spin_unlock_irqrestore(&pldat->lock, flags);
+
+	return IRQ_HANDLED;
+}

Why do you handle receive and transmit directly in the irq handler, rather than using napi?

drivers/net/ethernet/Makefile

Quoted 3 lines
drivers/net/ethernet/Makefile +3 -0
+	/* Save resources */
+	pldat->net_region_start = res->start;
+	pldat->net_region_size = res->end - res->start + 1;

This does not seem to be needed really. It's only printed in debug output and copied into ndev->base_addr, which is also unused.

drivers/net/ethernet/Makefile

Quoted 6 lines
drivers/net/ethernet/Makefile +6 -0
+	/* Save board specific configuration */
+	pldat->ncfg = (struct lpc_net_cfg *)pdev->dev.platform_data;
+	if (pldat->ncfg == NULL) {
+		dev_err(&pdev->dev, "error requesting interrupt.\n");
+		pldat->ncfg = &__lpc_local_net_config;
+	}

I would recommend dropping all the platform_data logic from this driver. The board support that you added doesn't actually set it and once you move to device tree probing, it will be obsolete anyway.

drivers/net/ethernet/Makefile

Quoted 9 lines
drivers/net/ethernet/Makefile +9 -0
+	if (use_iram_for_net()) {
+		dma_handle = (dma_addr_t)LPC32XX_IRAM_BASE;
+		if (pldat->dma_buff_size <= lpc32xx_return_iram_size())
+			pldat->dma_buff_base_v =
+				(u32)io_p2v(LPC32XX_IRAM_BASE);
+		else
+			netdev_err(ndev,
+				"IRAM not big enough for net buffers, using SDRAM instead.\n");
+	}

Can you put this into another resource? It doesn't seem appropriate to use constants from a platform specific header file here.

drivers/net/ethernet/Makefile

Quoted 6 lines
drivers/net/ethernet/Makefile +6 -0
+	if (pldat->dma_buff_base_v == 0) {
+		pldat->dma_buff_size += 4096; /* Allows room for alignment */
+
+		/* Align on the next highest page entry size */
+		pldat->dma_buff_size &= 0Xfffff000;
+		pldat->dma_buff_size += 0X00001000;

PAGE_ALIGN()

Quoted 4 lines
drivers/net/ethernet/Makefile +4 -0
+		/* Allocate a chunk of memory for the DMA ethernet buffers
+		   and descriptors */
+		pldat->dma_buff_base_v =
+			(u32)dma_alloc_coherent(&pldat->pdev->dev,

drivers/net/ethernet/Makefile

Quoted 10 lines
drivers/net/ethernet/Makefile +10 -0
+						pldat->dma_buff_size,
+						&dma_handle, GFP_KERNEL);
+
+		if (pldat->dma_buff_base_v == (u32)NULL) {
+			dev_err(&pdev->dev, "error getting DMA region.\n");
+			ret = -ENOMEM;
+			goto err_out_free_irq;
+		}
+	}
+	pldat->dma_buff_base_p = (u32)dma_handle;

Please use correct types here and remove all the typecasts. Virtual addresses use pointers and dma addresses are dma_addr_t.

drivers/net/ethernet/Makefile

Quoted 8 lines
drivers/net/ethernet/Makefile +8 -0
+static int lpc_net_drv_suspend(struct platform_device *pdev,
+	pm_message_t state)
+{
+}
+
+static int lpc_net_drv_resume(struct platform_device *pdev)
+{
+}

Define these conditionally?

drivers/net/ethernet/Makefile

Quoted 12 lines
drivers/net/ethernet/Makefile +12 -0
+static int __init lpc_net_init(void)
+{
+	return platform_driver_register(&lpc_net_driver);
+}
+
+static void __exit lpc_net_cleanup(void)
+{
+	platform_driver_unregister(&lpc_net_driver);
+}
+
+module_init(lpc_net_init);
+module_exit(lpc_net_cleanup);

You can use module_platform_driver() now.

Arnd

#4 lore raw
Quoted 4 lines · Arnd Bergmann

Are you sure that npx is actually the origin of this controller? If they only licensed the IP themselves, it would be better to list it under the name of the actual creator so that the next person who has the same core can find it.

I have no hint for another origin of this core (see manual). However, as soon as we get new info on this, we can move the driver easily.

Thanks to all of you for your suggestions, I will include all the suggested changes an repost an updated driver.

Roland