ARM: LPC32xx: Ethernet driver
Subsystems (3)
PATCH v2 1/1 ARM: LPC32xx: 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 | 1325 +++++++++++++++++++++++++++++++++++++ drivers/net/ethernet/nxp/lpc_eth.h | 335 +++++++++ 6 files changed, 1671 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 +1325 -0
1,325 lines not on this page · raw message
drivers/net/ethernet/nxp/lpc_eth.h new file +335 -0
335 lines not on this page · raw message
Quoted 1 line · Roland Stigge
This patch adds an ethernet driver for the LPC32xx ARM SoC.
Just some style notes:
Quoted 1 line
+++
linux-2.6/drivers/net/ethernet/nxp/lpc_eth.c
[]
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Quoted 20 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +20
-0+#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/errno.h> +#include <linux/ioport.h> +#include <linux/crc32.h> +#include <linux/platform_device.h> +#include <linux/spinlock.h> +#include <linux/ethtool.h> +#include <linux/mii.h> +#include <linux/clk.h> +#include <linux/workqueue.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/skbuff.h> +#include <linux/phy.h>
drivers/net/ethernet/nxp/lpc_eth.c line 48
Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10
-0+#include <linux/dma-mapping.h> + +#include <linux/delay.h> +#include <linux/io.h> +#include <mach/board.h> +#include <mach/platform.h> +#include <mach/hardware.h> +#include "lpc_eth.h" + +#define MODNAME "lpc-net"
lpc-net or lpc_eth?
[]
drivers/net/ethernet/nxp/lpc_eth.c line 117
Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4
-0+/* +* MAC address is provided as a boot parameter (ethaddr) +*/ +static u8 mac_address[6 ] = {0 ,0 ,0 ,0 ,0 ,0 };
[]
Quoted 1 line
+static void
__lpc_set_mac(struct netdata_local *pldat, u8 *mac)
[]
drivers/net/ethernet/nxp/lpc_eth.c line 159
Quoted 3 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +3
-0+pr_debug ("Ethernet MAC address %02x:%02x:%02x:%02x:%02x:%02x\n" , + mac[0 ], mac[1 ], mac[2 ], mac[3 ], mac[4 ], mac[5 ]); +}
pr_debug("MAC address: %pM\n", mac)[]
Review
Quoted 2 lines
(quoted diff) +2
-0+static int lpc_mii_probe(struct net_device *ndev) +{
[]
drivers/net/ethernet/nxp/lpc_eth.c line 484
Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2
-0+if (!phydev) { +pr_err ("%s: no PHY found\n" , ndev->name);
It looks like most of these pr_<level>(...) uses
should be netdev_<level>(ndev, ...)
[]
drivers/net/ethernet/nxp/lpc_eth.c line 648
Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10
-0+static void __lpc_handle_recv (struct net_device *ndev) +{ +struct netdata_local *pldat =netdev_priv (ndev); +struct sk_buff *skb; +int rxconsidx, len, ethst; +struct rx_status_t *prxstat; +u8 *prdbuf; + +/* Get the current RX buffer indexes */ + rxconsidx = (int )readl (LPC_ENET_RXCONSUMEINDEX (pldat->net_base));
Please try to be consistent with space or no space after cast. I think no space is better.
Quoted 5 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4
-0+while (rxconsidx != + (int )readl (LPC_ENET_RXPRODUCEINDEX (pldat->net_base))) { +/* Get pointer to receive status */ + prxstat = (struct rx_status_t *) pldat->rx_stat_v[rxconsidx];
drivers/net/ethernet/nxp/lpc_eth.c line 662
Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10
-0+ len = (prxstat->statusinfo &0x7FF ) +1 ; + +/* Status error? */ + ethst = prxstat->statusinfo; +if ((ethst &0xBF800000 ) ==0x84000000 ) + ethst &= ~0x80000000 ; + +if (ethst &0x80000000 ) { +/* Check statuses */ +if (prxstat->statusinfo & (1 <<28 )) {
Might be better to use a temporary for prxstat->statusinfo
Quoted 15 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +15
-0+/* Overrun error */ + ndev->stats.rx_fifo_errors++; + }else if (prxstat->statusinfo & (1 <<23 )) { +/* CRC error */ + ndev->stats.rx_crc_errors++; + }else if (prxstat->statusinfo & (1 <<25 )) { +/* Length error */ + ndev->stats.rx_length_errors++; + }else if (prxstat->statusinfo &0x80000000 ) { +/* Other error */ + ndev->stats.rx_length_errors++; + } + ndev->stats.rx_errors++; + }else { +/* Packet is good */
drivers/net/ethernet/nxp/lpc_eth.c line 687
Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10
-0+ skb =dev_alloc_skb (len +8 ); +if (!skb) + ndev->stats.rx_dropped++; +else { +skb_reserve (skb,8 ); + prdbuf =skb_put (skb, (len -0 )); + +/* Copy packer from buffer */ + memcpy(prdbuf, + (void *)pldat->rx_buff_v[rxconsidx],
Probably don't need the cast to (void *)
drivers/net/ethernet/nxp/lpc_eth.c line 689
Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +2
-0+ len); +
[]
Review
Quoted 2 lines
(quoted diff) +2
-0+static irqreturn_t __lpc_eth_interrupt(int irq, void *dev_id) +{
[]
drivers/net/ethernet/nxp/lpc_eth.c line 720
Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4
-0+/* Get the interrupt status */ + tmp =readl (LPC_ENET_INTSTATUS (pldat->net_base)); + +while (tmp) {
probably better as
while ((tmp = readl(...)) {[...]
drivers/net/ethernet/nxp/lpc_eth.c line 740
Quoted 3 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +3
-0+/* Recheck the interrupt status */ + tmp =readl (LPC_ENET_INTSTATUS (pldat->net_base)); + }
[]
drivers/net/ethernet/nxp/lpc_eth.c line 753
Quoted 7 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +7
-0+static int lpc_net_close (struct net_device *ndev) +{ +unsigned long flags; +struct netdata_local *pldat =netdev_priv (ndev); + +if (netif_msg_ifdown (pldat)) +dev_dbg (&pldat->pdev->dev,"shutting down %s\n" , ndev->name);
netif_dbg(pltdat, ifdown, ndev, ...)
[]
Quoted 1 line
+static int
lpc_net_drv_probe(struct platform_device *pdev)
[]
drivers/net/ethernet/nxp/lpc_eth.c line 1114
Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8
-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 +pr_err ("%s: IRAM not big enough for net buffers, " +"using SDRAM instead.\n" ,MODNAME );
Please coalesce formats and ignore 80 column limits to make grep easier.
Hi Roland,
Quoted 3 lines · Roland Stigge
This patch adds an ethernet driver for the LPC32xx ARM SoC.
Signed-off-by Roland Stigge <[email protected]>
[snip]
drivers/net/ethernet/nxp/lpc_eth.c line 131
Quoted 13 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +13
-0+static int __init ethaddr (char *s) +{ +int i; +unsigned int r[6 ]; + +sscanf (s,"%x:%x:%x:%x:%x:%x" , + &r[0 ], &r[1 ], &r[2 ], &r[3 ], &r[4 ], &r[5 ]); +for (i =0 ; i <6 ; i++) + mac_address[i] = (u8 )r[i]; + +return 1 ; +} +__setup ("ethaddr=" , ethaddr);
Please use a module_param() instead of a top level kernel parameter.
You may also consider using module_param_array() here. See drivers/net/ethernet/freescale/fec.c for an example. Note, however, that this changes the format the MAC address representation. Instead of "01:02:03:04:05:06", use "0x01,0x02,0x03,0x04,0x05,0x06".
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -David Miller
maintainerFrom: Baruch Siach <[email protected]>
Date: Sun, 26 Feb 2012 03:52:18 +0200
Quoted 9 lines
Hi Roland,
Quoted 3 lines · Roland Stigge
This patch adds an ethernet driver for the LPC32xx ARM SoC.
Signed-off-by Roland Stigge <[email protected]>[snip]
Quoted 15 lines
drivers/net/ethernet/nxp/lpc_eth.c line 131
Quoted 13 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +13
-0+static int __init ethaddr (char *s) +{ +int i; +unsigned int r[6 ]; + +sscanf (s,"%x:%x:%x:%x:%x:%x" , + &r[0 ], &r[1 ], &r[2 ], &r[3 ], &r[4 ], &r[5 ]); +for (i =0 ; i <6 ; i++) + mac_address[i] = (u8 )r[i]; + +return 1 ; +} +__setup ("ethaddr=" , ethaddr);Please use a
module_param()instead of a top level kernel parameter.
Actually, remove this entirely, we don't add module parameters to force the ethernet address. That should be done in userland in some fashion.
We've had many discussions about this recently, and this is the consistent policy we want to enforce in all drivers from now on.