Skip to contentSkip to conversation

lpc32xx: Added ethernet driver

PATCH Superseded Roland Stigge 4 participants 10 messages Mar 5, 2012 – Mar 6, 2012

Subsystems (3)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 lpc32xx: Added ethernet driver

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

---

Applies to v3.3-rc6

Changes since v3:
* Jiffies wraparound fix via msecs_to_jiffies() and time_after()
* Introduces symbolic names for status and control bits of descriptors
* Tx_errors counting only once at one event
* Use of_get_mac_address() and dev_hw_addr_random() to get/generate mac address
* Merged lpc_eth.h into lpc_eth.c since it didn't share defs with other C files
* Added interrupt handling via NAPI
* Removed net_region_start and net_region_size from struct netdata_local
* Removed (actually unused) platform_data
* Put LPC32XX_IRAM_* into another resource
* Use PAGE_ALIGN() for DMA size alignment
* Define suspend/resume conditionally
* Use module_platform_driver()
* Use correct pointer types (pointers, dma_addr_t, phys_addr_t) instead of casts

Thanks to Arnd Bergmann, Ben Hutchings, David Miller, Kevin Wells, Russell King and Joe Perches for reviewing!

 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 | 1642 +++++++++++++++++++++++++++++++++++++
 5 files changed, 1653 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 +1642 -0

1,642 lines not on this page · raw message

#1 lore raw

On Mon, 2012-03-05 at 22:40 +0100, Roland Stigge wrote:
[...]

Quoted 2 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +0 -0

[...]

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

Quoted 6 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +6 -0
+/*
+ * Transmit timeout, default 2.5 seconds.
+ */
+static int watchdog = 2500;
+module_param(watchdog, int, 0400);
+MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");

Why does this need to be a parameter?

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

Quoted 11 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +11 -0
+/*
+ * Structure of a TX/RX descriptors and RX status
+ */
+struct txrx_desc_t {
+	volatile u32 packet;
+	volatile u32 control;
+};
+struct rx_status_t {
+	volatile u32 statusinfo;
+	volatile u32 statushashcrc;
+};

Use of volatile here is probably wrong; see
Documentation/volatile-considered-harmful.txt.

Quoted 14 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +14 -0
+/*
+ * Device driver data structure
+ */
+struct netdata_local {
+	struct platform_device	*pdev;
+	struct net_device	*ndev;
+	spinlock_t		lock;
+	void __iomem		*net_base;
+	u32			msg_enable;
+	struct sk_buff		*skb[ENET_TX_DESC];
+	unsigned int		last_tx_idx;
+	unsigned int		num_used_tx_buffs;
+	struct mii_bus		*mii_bus;
+	struct phy_device	*phy_dev;

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+	struct clk		*clk;
+	dma_addr_t		dma_buff_base_p;
+	void			*dma_buff_base_v;
+	size_t			dma_buff_size;
+	struct txrx_desc_t	*tx_desc_v[ENET_TX_DESC];
+	u32			*tx_stat_v[ENET_TX_DESC];
+	void			*tx_buff_v[ENET_TX_DESC];
+	struct txrx_desc_t	*rx_desc_v[ENET_RX_DESC];
+	struct rx_status_t	*rx_stat_v[ENET_RX_DESC];
+	void			*rx_buff_v[ENET_RX_DESC];

Why are these 6 members defined as arrays of pointers and not single pointers to arrays? It appears that each array element is initialised to point into an array and then never changed; for example tx_desc_v[i] == tx_desc_v[0] + i.

[...]

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

[...]

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+	/* Clear and enable interrupts */
+	writel(0xFFFF, LPC_ENET_INTCLEAR(pldat->net_base));
+	lpc_eth_enable_int(pldat->net_base);
+
+	/* Get the next TX buffer output index */
+	pldat->num_used_tx_buffs = 0;
+	pldat->last_tx_idx =
+		readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));

Doesn't this need to be done *before* enabling interrupts? Also, I think you need an smp_wmb() so that the interrupt handler is guaranteed to see all these writes.

[...]

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

Quoted 7 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +7 -0
+static void lpc_handle_link_change(struct net_device *ndev)
+{
+	struct netdata_local *pldat = netdev_priv(ndev);
+	struct phy_device *phydev = pldat->phy_dev;
+	unsigned long flags;
+
+	int status_change = 0;

This is logically a boolean, so use bool/true/false.

[...]

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

[...]

Quoted 12 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +12 -0
+		/* Any errors occurred? */
+		if (txstat & TXSTATUS_ERROR) {
+			if (txstat & TXSTATUS_UNDERRUN) {
+				/* FIFO underrun */
+				ndev->stats.tx_fifo_errors++;
+			}
+			if (txstat & TXSTATUS_LATECOLL) {
+				/* Late collision */
+				ndev->stats.tx_aborted_errors++;
+			}
+			if (txstat & TXSTATUS_EXCESSCOLL) {
+				/* Excessive collision */

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+				ndev->stats.tx_aborted_errors++;
+			}
+			if (txstat & TXSTATUS_EXCESSDEFER) {
+				/* Defer limit */
+				ndev->stats.tx_aborted_errors++;
+			}
+			ndev->stats.tx_errors++;
+
+			/* Buffer transmit failed, requeue it */
+			lpc_eth_hard_start_xmit(skb, ndev);

It is not the responsibility of an Ethernet network driver to retry transmission. Also, this will deadlock on an SMP system since lpc_eth_hard_start_xmit() will try to acquire pldat->lock which is already held. I suggest you test with lockdep in case there any other such bugs which are being masked by running on a UP system.

[...]

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

[...]

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

Quoted 6 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +6 -0
+			/* Packet is good */
+			skb = dev_alloc_skb(len + 8);
+			if (!skb)
+				ndev->stats.rx_dropped++;
+			else {
+				skb_reserve(skb, 8);

What are you reserving this space for?

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

Quoted 1 line
drivers/net/ethernet/nxp/lpc_eth.c new file +1 -0
+				prdbuf = skb_put(skb, (len - 0));

len - 0??

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+				/* Copy packet from buffer */
+				memcpy(prdbuf,
+					pldat->rx_buff_v[rxconsidx], len);
+
+				/* Pass to upper layer */
+				skb->protocol = eth_type_trans(skb, ndev);
+				netif_rx(skb);
+				ndev->last_rx = jiffies;

Drivers don't need to set last_rx any more.

[...]

Quoted 9 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +9 -0
+static int lpc_eth_poll(struct napi_struct *napi, int budget)
+{
+	struct netdata_local *pldat = container_of(napi,
+			struct netdata_local, napi);
+	struct net_device *ndev = pldat->ndev;
+	unsigned long flags;
+	int rx_done = 0;
+
+	spin_lock_irqsave(&pldat->lock, flags);

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+
+	__lpc_handle_xmit(ndev);
+	rx_done = __lpc_handle_recv(ndev, budget);
+
+	if (rx_done < budget) {
+		napi_complete(napi);
+		lpc_eth_enable_int(pldat->net_base);
+	}
+
+	spin_unlock_irqrestore(&pldat->lock, flags);

This is really sad. You implement NAPI but then take away most of the benefits of that by disabling interrupts.

It looks like you could safely unlock pldat->lock before calling __lpc_handle_recv - nothing else manipulates RX queue state so no lock is required.

As for the TX side, you can probably use the TX queue lock (__netif_tx_lock, __netif_tx_unlock) to serialise with lpc_eth_hard_start_xmit() and avoid taking pldat->lock in either __lpc_handle_xmit() or here.

[...]

Quoted 9 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +9 -0
+	return rx_done;
+}
+
+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;
+

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+	spin_lock(&pldat->lock);
+
+	tmp = readl(LPC_ENET_INTSTATUS(pldat->net_base));
+	/* Clear interrupts */
+	writel(tmp, LPC_ENET_INTCLEAR(pldat->net_base));
+
+	if (likely(napi_schedule_prep(&pldat->napi))) {
+		lpc_eth_disable_int(pldat->net_base);
+		__napi_schedule(&pldat->napi);
+	}

I think you need to mask the interrupt unconditionally here. See my next comment.

Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4 -0
+	spin_unlock(&pldat->lock);
+
+	return IRQ_HANDLED;
+}

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+
+static int lpc_eth_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);
+
+	napi_disable(&pldat->napi);

If an interrupt is received after this returns, napi_schedule_prep() will return false and the interrupt will not be masked.

There is a similar problem in lpc_eth_open() where you enable interrupts before NAPI.

Quoted 16 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +16 -0
+	netif_stop_queue(ndev);
+
+	if (pldat->phy_dev)
+		phy_stop(pldat->phy_dev);
+
+	spin_lock_irqsave(&pldat->lock, flags);
+	__lpc_eth_reset(pldat);
+	netif_carrier_off(ndev);
+	writel(0, LPC_ENET_MAC1(pldat->net_base));
+	writel(0, LPC_ENET_MAC2(pldat->net_base));
+	spin_unlock_irqrestore(&pldat->lock, flags);
+
+	__lpc_eth_clock_enable(pldat, 0);
+
+	return 0;
+}

[...]

Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4 -0
+static int lpc_eth_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
+{
+	struct netdata_local *pldat = netdev_priv(ndev);
+	u32 len, txidx;

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+	u32 *ptxstat;
+	struct txrx_desc_t *ptxrxdesc;
+
+	len = skb->len;
+
+	spin_lock_irq(&pldat->lock);
+
+	if (pldat->num_used_tx_buffs >= (ENET_TX_DESC - 1)) {
+		/* This function should never be called when there are no
+		   buffers, log the error */

So use WARN to make the error really obvious.

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

Quoted 5 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +5 -0
+		netif_stop_queue(ndev);
+		spin_unlock_irq(&pldat->lock);
+		dev_err(&pldat->pdev->dev,
+			"BUG! TX request when no free TX buffers!\n");
+		return 1;

This is not a valid return value; you need to return NETDEV_TX_BUSY.

Quoted 21 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +21 -0
+	}
+
+	/* Get the next TX descriptor index */
+	txidx = readl(LPC_ENET_TXPRODUCEINDEX(pldat->net_base));
+
+	/* Setup control for the transfer */
+	ptxstat = pldat->tx_stat_v[txidx];
+	*ptxstat = 0;
+	ptxrxdesc = pldat->tx_desc_v[txidx];
+	ptxrxdesc->control =
+		(len - 1) | TXDESC_CONTROL_LAST | TXDESC_CONTROL_INT;
+
+	/* Copy data to the DMA buffer */
+	memcpy(pldat->tx_buff_v[txidx], skb->data, len);
+
+	/* Save the buffer and increment the buffer counter */
+	pldat->skb[txidx] = skb;
+	pldat->num_used_tx_buffs++;
+
+	/* Start transmit */
+	txidx++;

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+	if (txidx >= ENET_TX_DESC)
+		txidx = 0;
+	writel(txidx, LPC_ENET_TXPRODUCEINDEX(pldat->net_base));
+
+	/* Stop queue if no more TX buffers */
+	if (pldat->num_used_tx_buffs >= (ENET_TX_DESC - 1))
+		netif_stop_queue(ndev);
+
+	spin_unlock_irq(&pldat->lock);
+	ndev->trans_start = jiffies;

Drivers don't need to set trans_start any more.

drivers/net/ethernet/nxp/lpc_eth.c

Quoted 1 line
drivers/net/ethernet/nxp/lpc_eth.c new file +1 -0
+	return 0;

NETDEV_TX_OK

Quoted 1 line

+}

[...]

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

Quoted 7 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +7 -0
+static void lpc_eth_timeout(struct net_device *ndev)
+{
+	struct netdata_local *pldat = netdev_priv(ndev);
+
+	/* This should never happen and indicates a problem */
+	dev_err(&pldat->pdev->dev, "BUG! TX timeout occurred!\n");
+}

The networking core will print a big fat warning before calling this function, so this message is redundant. Also, timeout isn't necessarily a bug; it can be caused by a misconfigured switch.

[...]

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+static int lpc_eth_ethtool_getsettings(struct net_device *ndev,
+	struct ethtool_cmd *cmd)
+{
+	struct netdata_local *pldat = netdev_priv(ndev);
+	struct phy_device *phydev = pldat->phy_dev;
+
+	if (!phydev)
+		return -ENODEV;

-EOPNOTSUPP

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

Quoted 11 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +11 -0
+	return phy_ethtool_gset(phydev, cmd);
+}
+
+static int lpc_eth_ethtool_setsettings(struct net_device *ndev,
+	struct ethtool_cmd *cmd)
+{
+	struct netdata_local *pldat = netdev_priv(ndev);
+	struct phy_device *phydev = pldat->phy_dev;
+
+	if (!phydev)
+		return -ENODEV;

[...]

-EOPNOTSUPP

Ben.

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.
#2 lore raw
Quoted 2 lines · Ben Hutchings

On Mon, 2012-03-05 at 22:40 +0100, Roland Stigge wrote:
[...]

...

Quoted 10 lines

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+				/* Copy packet from buffer */
+				memcpy(prdbuf,
+					pldat->rx_buff_v[rxconsidx], len);
+
+				/* Pass to upper layer */
+				skb->protocol = eth_type_trans(skb, ndev);
+				netif_rx(skb);
+				ndev->last_rx = jiffies;

Drivers don't need to set last_rx any more.

Also, a NAPI driver should call netif_receive_skb() instead of netif_rx()

netif_rx() is more expensive because of additional queue, while netif_receive_skb() directly calls the upper stacks.

#3 lore raw
Quoted 17 lines · Eric Dumazet
Quoted 2 lines · Ben Hutchings

On Mon, 2012-03-05 at 22:40 +0100, Roland Stigge wrote:
[...]

...

Quoted 10 lines

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+				/* Copy packet from buffer */
+				memcpy(prdbuf,
+					pldat->rx_buff_v[rxconsidx], len);
+
+				/* Pass to upper layer */
+				skb->protocol = eth_type_trans(skb, ndev);
+				netif_rx(skb);
+				ndev->last_rx = jiffies;

Drivers don't need to set last_rx any more.

Quoted 5 lines

Also, a NAPI driver should call netif_receive_skb() instead of netif_rx()

netif_rx() is more expensive because of additional queue, while netif_receive_skb() directly calls the upper stacks.

Yes, but not until the poll function is changed to enable IRQs.

Ben.

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.
#4 lore raw
In reply to Ben Hutchings

Hi Ben,

thank you for your review!

Quoted 24 lines · Ben Hutchings

[...]

Quoted 9 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +9 -0
+static int lpc_eth_poll(struct napi_struct *napi, int budget)
+{
+	struct netdata_local *pldat = container_of(napi,
+			struct netdata_local, napi);
+	struct net_device *ndev = pldat->ndev;
+	unsigned long flags;
+	int rx_done = 0;
+
+	spin_lock_irqsave(&pldat->lock, flags);

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

Quoted 10 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +10 -0
+
+	__lpc_handle_xmit(ndev);
+	rx_done = __lpc_handle_recv(ndev, budget);
+
+	if (rx_done < budget) {
+		napi_complete(napi);
+		lpc_eth_enable_int(pldat->net_base);
+	}
+
+	spin_unlock_irqrestore(&pldat->lock, flags);

This is really sad. You implement NAPI but then take away most of the benefits of that by disabling interrupts.

Quoted 8 lines

It looks like you could safely unlock pldat->lock before calling __lpc_handle_recv - nothing else manipulates RX queue state so no lock is required.

As for the TX side, you can probably use the TX queue lock (__netif_tx_lock, __netif_tx_unlock) to serialise with lpc_eth_hard_start_xmit() and avoid taking pldat->lock in either __lpc_handle_xmit() or here.

Sounds reasonable, and will do it.

However, I implemented it from the example of drivers/net/ethernet/via/via-velocity.c:velocity_poll() - is there a good reason for doing it that way in the velocity driver or is it done incorrectly there, also?

Thanks,

Roland

#6 lore raw

Re: [PATCH v4] lpc32xx: Added ethernet driver: smp_wmb()

In reply to Ben Hutchings
Quoted 4 lines · Ben Hutchings
Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4 -0
+	/* Clear and enable interrupts */
+	writel(0xFFFF, LPC_ENET_INTCLEAR(pldat->net_base));
+	lpc_eth_enable_int(pldat->net_base);
+
Quoted 8 lines

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

Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4 -0
+	/* Get the next TX buffer output index */
+	pldat->num_used_tx_buffs = 0;
+	pldat->last_tx_idx =
+		readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));

Doesn't this need to be done *before* enabling interrupts? Also, I think you need an smp_wmb() so that the interrupt handler is guaranteed to see all these writes.

Do you mean _one_ smp_wmb() directly after lpc_eth_enable_int() (which I'm moving behind the above code?

Note that there is no SMP in LPCs and NXP is not planning to build one AFAIK. However, I'm fine with including smp_wmb() anyway for completeness.

Thanks in advance,

Roland

#5 lore raw
In reply to Roland Stigge

Le mardi 06 mars 2012 ? 09:53 +0100, Roland Stigge a ?crit :

Quoted 7 lines

Sounds reasonable, and will do it.

However, I implemented it from the example of drivers/net/ethernet/via/via-velocity.c:velocity_poll() - is there a good reason for doing it that way in the velocity driver or is it done incorrectly there, also?

Its done in a non efficient way.

It works as is, but its not the right thing to do. The NAPI port was very minimal on via-velocity it seems.

A better way is to hold no locks in the RX handler, allowing calls to netif_receive_skb() [ and potential calls to xmit while handling this incoming skbs ]

Problem of saying "we dont expect to be SMP anyway", is that this let reference material for future drivers that will copy/paste the code, then experience performance problems.

#7 lore raw

Re: [PATCH v4] lpc32xx: Added ethernet driver: smp_wmb()

In reply to Roland Stigge
Quoted 14 lines · Roland Stigge
Quoted 4 lines · Ben Hutchings
Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4 -0
+	/* Clear and enable interrupts */
+	writel(0xFFFF, LPC_ENET_INTCLEAR(pldat->net_base));
+	lpc_eth_enable_int(pldat->net_base);
+
Quoted 8 lines

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

Quoted 4 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +4 -0
+	/* Get the next TX buffer output index */
+	pldat->num_used_tx_buffs = 0;
+	pldat->last_tx_idx =
+		readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));

Doesn't this need to be done *before* enabling interrupts? Also, I think you need an smp_wmb() so that the interrupt handler is guaranteed to see all these writes.

Quoted 2 lines

Do you mean _one_ smp_wmb() directly after lpc_eth_enable_int() (which I'm moving behind the above code?

The sequence should be

	pldat->state = values...;
	smp_wmb();
	enable_interrupts();
Quoted 2 lines

Note that there is no SMP in LPCs and NXP is not planning to build one AFAIK.

Never say never!

Quoted 1 line

However, I'm fine with including smp_wmb() anyway for completeness.

Ben.

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.
#8 lore raw

Re: [PATCH v4] lpc32xx: Added ethernet driver: smp_wmb()

Quoted 15 lines · Ben Hutchings
Quoted 14 lines · Roland Stigge
Quoted 12 lines · Ben Hutchings

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+	/* Clear and enable interrupts */
+	writel(0xFFFF, LPC_ENET_INTCLEAR(pldat->net_base));
+	lpc_eth_enable_int(pldat->net_base);
+
+	/* Get the next TX buffer output index */
+	pldat->num_used_tx_buffs = 0;
+	pldat->last_tx_idx =
+		readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));

Doesn't this need to be done *before* enabling interrupts? Also, I think you need an smp_wmb() so that the interrupt handler is guaranteed to see all these writes.

Quoted 8 lines
Quoted 2 lines

Do you mean _one_ smp_wmb() directly after lpc_eth_enable_int() (which I'm moving behind the above code?

The sequence should be

	pldat->state = values...;
	smp_wmb();
	enable_interrupts();

Is this correct?

"SMP BARRIER PAIRING" and "EXAMPLES OF MEMORY BARRIER SEQUENCES" in Documentation/memory-barriers.txt suggest that there should be some kind of pairing with smp_wmb() to ensure correctness.

#9 lore raw

Re: [PATCH v4] lpc32xx: Added ethernet driver: smp_wmb()

Quoted 25 lines · Russell King - ARM Linux
Quoted 15 lines · Ben Hutchings
Quoted 14 lines · Roland Stigge
Quoted 12 lines · Ben Hutchings

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

Quoted 8 lines
drivers/net/ethernet/nxp/lpc_eth.c new file +8 -0
+	/* Clear and enable interrupts */
+	writel(0xFFFF, LPC_ENET_INTCLEAR(pldat->net_base));
+	lpc_eth_enable_int(pldat->net_base);
+
+	/* Get the next TX buffer output index */
+	pldat->num_used_tx_buffs = 0;
+	pldat->last_tx_idx =
+		readl(LPC_ENET_TXCONSUMEINDEX(pldat->net_base));

Doesn't this need to be done *before* enabling interrupts? Also, I think you need an smp_wmb() so that the interrupt handler is guaranteed to see all these writes.

Quoted 8 lines
Quoted 2 lines

Do you mean _one_ smp_wmb() directly after lpc_eth_enable_int() (which I'm moving behind the above code?

The sequence should be

	pldat->state = values...;
	smp_wmb();
	enable_interrupts();
Quoted 5 lines

Is this correct?

"SMP BARRIER PAIRING" and "EXAMPLES OF MEMORY BARRIER SEQUENCES" in Documentation/memory-barriers.txt suggest that there should be some kind of pairing with smp_wmb() to ensure correctness.

The thread we're synchronising with (the interrupt handler) starts *after* the smp_wmb(). Therefore there is no need for a second barrier.

Ben.

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.