Skip to contentSkip to conversation

8139too: move wmb before TX DMA start

PATCH Superseded Andreas Oberritter 2 participants 3 messages Oct 8, 2008

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

PATCH 1/1 8139too: move wmb before TX DMA start

From: Andreas Oberritter <[email protected]>

The write barrier should be used before starting a DMA transfer. This fixes a problem, where almost all packets received on another machine had garbled content. Tested with an RTL8100C on a MIPS machine.

drivers/net/8139too.c +1 -1
index 53bd903..44344af 100644
@@ -1716,13 +1716,13 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
 	}
 
 	spin_lock_irqsave(&tp->lock, flags);
+	wmb();
 	RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
 		   tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
 
 	dev->trans_start = jiffies;
 
 	tp->cur_tx++;
-	wmb();
 
 	if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
 		netif_stop_queue (dev);
#1 lore raw
Quoted 13 lines · Andreas Oberritter

From: Andreas Oberritter <[email protected]>

The write barrier should be used before starting a DMA transfer. This fixes a problem, where almost all packets received on another machine had garbled content. Tested with an RTL8100C on a MIPS machine.

drivers/net/8139too.c +0 -0
index 53bd903..44344af 100644

drivers/net/8139too.c static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev) · line 1719

Quoted 4 lines
drivers/net/8139too.c +1 -0
@@ -1716,13 +1716,13 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
 	}
 
 	spin_lock_irqsave(&tp->lock, flags);
+	wmb();

[...]

All memory barriers need a comment to explain why and what they're doing.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
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

PATCH v2 1/1 8139too: move wmb before TX DMA start

From: Andreas Oberritter <[email protected]>

The write barrier should be used before starting a DMA transfer. This fixes a problem, where almost all packets received on another machine had garbled content. Tested with an RTL8100C on a MIPS machine.

---
Added a comment on Ben's request explaining the reason for the barrier.

drivers/net/8139too.c +6 -1
index 53bd903..3c5fac6 100644
@@ -1716,13 +1716,18 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
 	}
 
 	spin_lock_irqsave(&tp->lock, flags);
+	/*
+	 * Writing to TxStatus triggers a DMA transfer of the data
+	 * copied to tp->tx_buf[entry] above. Use a memory barrier
+	 * to make sure that the device sees the updated data.
+	 */
+	wmb();
 	RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
 		   tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
 
 	dev->trans_start = jiffies;
 
 	tp->cur_tx++;
-	wmb();
 
 	if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
 		netif_stop_queue (dev);