Skip to contentSkip to conversation

lpc32xx: Added ethernet driver

PATCH Superseded Roland Stigge 3 participants 4 messages Mar 6, 2012 – Mar 7, 2012

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 lpc32xx: Added ethernet driver

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

---

Applies to v3.3-rc6

Changes since v4:
* Removed module parameter (watchdog)
* Removed "volatile" in DMA descriptors
* Fixed DMA descriptor and buffer alignment to 16 bytes
* Fixed arrays of pointers in netdata_local to be pointers to arrays
* Fixed timing of interrupt enabling upon init
* Added smp_wmb()
* Use bool for status_change
* Don't requeue on tx error (and lockdep doesn't find any further bugs)
* Removed unnecessary skb_reserve() and (len - 0) style issue
* Removed setting of last_rx
* Enable interrupts in lpc_eth_poll(), use __netif_tx_lock/__netif_tx_unlock
* Disable interrupt unconditionally in __lpc_eth_interrupt()
* Use WARN in lpc_eth_hard_start_xmit() to make problem more obvious
* Return NETDEV_TX_BUSY in lpc_eth_hard_start_xmit() on error and NETDEV_TX_OK on success
* Removed setting of trans_start
* Removed unnecessary / empty lpc_eth_timeout()
* Fixed error return values of lpc_eth_ethtool_getsettings() and lpc_eth_ethtool_setsettings() (-EOPNOTSUPP)
* Use netif_receive_skb() instead of netif_rx()

Thanks to Ben Hutchings, Kevin Wells, Russell King and Eric Dumazet for reviewing the last version!

 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 | 1611 +++++++++++++++++++++++++++++++++++++
 5 files changed, 1622 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 +1611 -0

1,611 lines not on this page · raw message

maintainer
#1 lore raw

From: Roland Stigge <[email protected]>
Date: Tue, 6 Mar 2012 22:01:04 +0100

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

Quoted 3 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +3 -0
+#define RXSTATUS_STATUS_ERROR \
+	(RXSTATUS_NODESC | RXSTATUS_OVERRUN | RXSTATUS_ALIGN | RXSTATUS_RANGE \
+	 | RXSTATUS_LENGTH | RXSTATUS_SYMBOL | RXSTATUS_CRC)

Should be:

#define RXSTATUS_STATUS_ERROR \
	(RXSTATUS_NODESC | RXSTATUS_OVERRUN | RXSTATUS_ALIGN | RXSTATUS_RANGE | \
	 RXSTATUS_LENGTH | RXSTATUS_SYMBOL | RXSTATUS_CRC)

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

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2 -0
+static int lpc_eth_hard_start_xmit(struct sk_buff *skb,
+	struct net_device *ndev);

Should be:

static int lpc_eth_hard_start_xmit(struct sk_buff *skb,

				   struct net_device *ndev);

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+struct txrx_desc_t {
+	u32 packet;
+	u32 control;
+};
+struct rx_status_t {
+	u32 statusinfo;
+	u32 statushashcrc;
+};

What is the endianness of these descriptors? Based upon the answer to that question use __be32 or __le32 instead of u32.

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

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2 -0
+static void __lpc_eth_clock_enable(struct netdata_local *pldat,
+	int enable)

Should be:

static void __lpc_eth_clock_enable(struct netdata_local *pldat,
int enable)

And you should also use "bool" for enable and pass in true/false at the call sites.

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

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2 -0
+	writel((LPC_MACINT_RXDONEINTEN | LPC_MACINT_TXDONEINTEN),
+		LPC_ENET_INTENABLE(regbase));

Should be:

	writel((LPC_MACINT_RXDONEINTEN | LPC_MACINT_TXDONEINTEN),
	       LPC_ENET_INTENABLE(regbase));

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

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2 -0
+	/* Setup base addresses in hardware to point to buffers and
+	   descriptors */

Should be:

	/* Setup base addresses in hardware to point to buffers and
	 * descriptors.
	 */

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

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2 -0
+	writel((ENET_TX_DESC - 1),
+		LPC_ENET_TXDESCRIPTORNUMBER(pldat->net_base));

All of these writel() calls are improperly indented on the second and any subsequent lines just like the one I pointed out above, fix them all.

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

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2 -0
+MODULE_LICENSE("GPL");
+

Tailing empty line in this file, please remove.

#2 lore raw
In reply to Roland Stigge

Hi Roland,

One more thing I noticed this time:

Quoted 7 lines · Roland Stigge
drivers/net/ethernet/nxp/lpc_eth.c new file +7 -0
+static inline phy_interface_t lpc_phy_interface_mode(void)
+{
+#ifdef CONFIG_ARCH_LPC32XX_MII_SUPPORT
+       return PHY_INTERFACE_MODE_MII;
+#else
+       return PHY_INTERFACE_MODE_RMII;
+#endif

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+}
+
+static inline int use_iram_for_net(void)
+{
+#ifdef CONFIG_ARCH_LPC32XX_IRAM_FOR_NET
+       return 1;
+#else
+       return 0;
+#endif
+}

This should eventually both become run-time options based on the device tree. I don't know if you planned to do that anyway, but if you want the same kernel binary to be used for systems in different configurations, you cannot have compile-time decisions that are exclusive-or. Since you don't support device tree yet but plan to do that in the future, you could add a comment here about it, or you could even prepare it for that case already by passing the device into the functions that will be required for reading the properties.

Arnd

#3 lore raw

Hi Arnd,

Quoted 7 lines · Arnd Bergmann

This should eventually both become run-time options based on the device tree. I don't know if you planned to do that anyway, but if you want the same kernel binary to be used for systems in different configurations, you cannot have compile-time decisions that are exclusive-or. Since you don't support device tree yet but plan to do that in the future, you could add a comment here about it, or you could even prepare it for that case already by passing the device into the functions that will be required for reading the properties.

Good point.

I prefer putting a comment for now, because upon the planned device tree introduction in lpc32xx, an internal change in lpc_eth.c will be necessary anyway, so there is no need to already introduce unused parameters at this point.

Thanks,

Roland