netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 2.6.11-rc3 1/5] r8169: endianness fixes
@ 2005-02-11 23:39 Francois Romieu
  2005-02-11 23:41 ` [patch 2.6.11-rc3 2/5] r8169: merge of Realtek's code Francois Romieu
  2005-02-13 17:49 ` [patch 2.6.11-rc3 1/5] r8169: endianness fixes Jeff Garzik
  0 siblings, 2 replies; 8+ messages in thread
From: Francois Romieu @ 2005-02-11 23:39 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: akpm, jdmason, netdev

Endianness fixes

- rtl8169_rx_csum() forgot to convert the descriptor to cpu order,
- same thing for rtl8169_rx_vlan_skb() but this one is more tricky as
  the layout of the (u32) word in the 8169 descriptor calls for a
  second level of swap at the vlan tag level (u16). The old code only
  did the second part (in an endian-dependant way, how fun).
- rtl8169_tx_vlan_tag(): this time the (u32 descriptor level) cpu_to_le32
  is issued in rtl8169_start_xmit but the (u16 vlan tag level) cpu_to_be16
  is not right any more.

Summary: avoid even calls to cpu_to_{b/l}eXX on a given piece of data.

The change has no effect on x86. Now sparc64 talks to x86.

Pinpointed-by: Jon Mason <jdmason@us.ibm.com>
Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>

diff -puN drivers/net/r8169.c~r8169-350 drivers/net/r8169.c
--- a/drivers/net/r8169.c~r8169-350	2005-02-05 21:04:12.000000000 +0100
+++ b/drivers/net/r8169.c	2005-02-12 00:25:12.992726954 +0100
@@ -698,7 +698,7 @@ static inline u32 rtl8169_tx_vlan_tag(st
 				      struct sk_buff *skb)
 {
 	return (tp->vlgrp && vlan_tx_tag_present(skb)) ?
-		TxVlanTag | cpu_to_be16(vlan_tx_tag_get(skb)) : 0x00;
+		TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00;
 }
 
 static void rtl8169_vlan_rx_register(struct net_device *dev,
@@ -733,12 +733,12 @@ static void rtl8169_vlan_rx_kill_vid(str
 static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc,
 			       struct sk_buff *skb)
 {
-	u32 opts2 = desc->opts2;
+	u32 opts2 = le32_to_cpu(desc->opts2);
 	int ret;
 
 	if (tp->vlgrp && (opts2 & RxVlanTag)) {
 		rtl8169_rx_hwaccel_skb(skb, tp->vlgrp,
-				       be16_to_cpu(opts2 & 0xffff));
+				       swab16(opts2 & 0xffff));
 		ret = 0;
 	} else
 		ret = -1;
@@ -2084,7 +2084,7 @@ rtl8169_tx_interrupt(struct net_device *
 
 static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc)
 {
-	u32 opts1 = desc->opts1;
+	u32 opts1 = le32_to_cpu(desc->opts1);
 	u32 status = opts1 & RxProtoMask;
 
 	if (((status == RxProtoTCP) && !(opts1 & TCPFail)) ||

_

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch 2.6.11-rc3 2/5] r8169: merge of Realtek's code
  2005-02-11 23:39 [patch 2.6.11-rc3 1/5] r8169: endianness fixes Francois Romieu
@ 2005-02-11 23:41 ` Francois Romieu
  2005-02-11 23:42   ` [patch 2.6.11-rc3 3/5] r8169: typo in debugging code Francois Romieu
  2005-02-13 17:49 ` [patch 2.6.11-rc3 1/5] r8169: endianness fixes Jeff Garzik
  1 sibling, 1 reply; 8+ messages in thread
From: Francois Romieu @ 2005-02-11 23:41 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: akpm, jdmason, rich, netdev

Merge of Realtek's code
- code dedicated to a new phy (spotted by Richard Dawe);
- C+ register fiddling seems required for both RTL_GIGA_MAC_VER_{D/E};
- apart from being reserved, register at address 0xe2 is named 'IntrMitigate';
- bump version number.
  A bunch of people do not use the vanilla kernel module simply because
  Realtek's driver has a higher revision number. This is not an issue per
  se but their driver is buggy due to some partial merge of in-kernel code.

Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
Signed-off-by: Richard Dawe <rich@phekda.gotadsl.co.uk>

diff -puN drivers/net/r8169.c~r8169-360 drivers/net/r8169.c
--- a/drivers/net/r8169.c~r8169-360	2005-02-05 21:04:17.000000000 +0100
+++ b/drivers/net/r8169.c	2005-02-12 00:25:10.895067209 +0100
@@ -41,6 +41,13 @@ VERSION 1.6LK	<2004/04/14>
 	- Suspend/resume
 	- Endianness
 	- Misc Rx/Tx bugs
+
+VERSION 2.2LK	<2005/01/25>
+
+	- RX csum, TX csum/SG, TSO
+	- VLAN
+	- baby (< 7200) Jumbo frames support
+	- Merge of Realtek's version 2.2 (new phy)
 */
 
 #include <linux/module.h>
@@ -62,7 +69,7 @@ VERSION 1.6LK	<2004/04/14>
 #include <asm/io.h>
 #include <asm/irq.h>
 
-#define RTL8169_VERSION "1.6LK"
+#define RTL8169_VERSION "2.2LK"
 #define MODULENAME "r8169"
 #define PFX MODULENAME ": "
 
@@ -149,6 +156,7 @@ enum phy_version {
 	RTL_GIGA_PHY_VER_E = 0x05, /* PHY Reg 0x03 bit0-3 == 0x0000 */
 	RTL_GIGA_PHY_VER_F = 0x06, /* PHY Reg 0x03 bit0-3 == 0x0001 */
 	RTL_GIGA_PHY_VER_G = 0x07, /* PHY Reg 0x03 bit0-3 == 0x0002 */
+	RTL_GIGA_PHY_VER_H = 0x08, /* PHY Reg 0x03 bit0-3 == 0x0003 */
 };
 
 
@@ -162,7 +170,8 @@ const static struct {
 } rtl_chip_info[] = {
 	_R("RTL8169",		RTL_GIGA_MAC_VER_B, 0xff7e1880),
 	_R("RTL8169s/8110s",	RTL_GIGA_MAC_VER_D, 0xff7e1880),
-	_R("RTL8169s/8110s",	RTL_GIGA_MAC_VER_E, 0xff7e1880)
+	_R("RTL8169s/8110s",	RTL_GIGA_MAC_VER_E, 0xff7e1880),
+	_R("RTL8169s/8110s",	RTL_GIGA_MAC_VER_X, 0xff7e1880),
 };
 #undef _R
 
@@ -208,6 +217,7 @@ enum RTL8169_registers {
 	PHYstatus = 0x6C,
 	RxMaxSize = 0xDA,
 	CPlusCmd = 0xE0,
+	IntrMitigate = 0xE2,
 	RxDescAddrLow = 0xE4,
 	RxDescAddrHigh = 0xE8,
 	EarlyTxThres = 0xEC,
@@ -407,7 +417,7 @@ struct rtl8169_private {
 	struct work_struct task;
 };
 
-MODULE_AUTHOR("Realtek");
+MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@oss.sgi.com>");
 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
 module_param_array(media, int, &num_media, 0);
 module_param(rx_copybreak, int, 0);
@@ -1002,7 +1012,7 @@ static void rtl8169_hw_phy_config(struct
 
 	if (tp->mac_version <= RTL_GIGA_MAC_VER_B)
 		return;
-	if (tp->phy_version >= RTL_GIGA_PHY_VER_F) 
+	if (tp->phy_version >= RTL_GIGA_PHY_VER_H)
 		return;
 
 	dprintk("MAC version != 0 && PHY version == 0 or 1\n");
@@ -1010,6 +1020,18 @@ static void rtl8169_hw_phy_config(struct
 
 	/* Shazam ! */
 
+	if (tp->mac_version == RTL_GIGA_MAC_VER_X) {
+		mdio_write(ioaddr, 31, 0x0001);
+		mdio_write(ioaddr,  9, 0x273a);
+		mdio_write(ioaddr, 14, 0x7bfb);
+		mdio_write(ioaddr, 27, 0x841e);
+
+		mdio_write(ioaddr, 31, 0x0002);
+		mdio_write(ioaddr,  1, 0x90d0);
+		mdio_write(ioaddr, 31, 0x0000);
+		return;
+	}
+
 	// phy config for RTL8169s mac_version C chip
 	mdio_write(ioaddr, 31, 0x0001);			//w 31 2 0 1
 	mdio_write(ioaddr, 21, 0x1000);			//w 21 15 0 1000
@@ -1038,7 +1060,7 @@ static void rtl8169_phy_timer(unsigned l
 	unsigned long timeout = RTL8169_PHY_TIMEOUT;
 
 	assert(tp->mac_version > RTL_GIGA_MAC_VER_B);
-	assert(tp->phy_version < RTL_GIGA_PHY_VER_G);
+	assert(tp->phy_version < RTL_GIGA_PHY_VER_H);
 
 	if (!(tp->phy_1000_ctrl_reg & PHY_Cap_1000_Full))
 		return;
@@ -1073,7 +1095,7 @@ static inline void rtl8169_delete_timer(
 	struct timer_list *timer = &tp->timer;
 
 	if ((tp->mac_version <= RTL_GIGA_MAC_VER_B) ||
-	    (tp->phy_version >= RTL_GIGA_PHY_VER_G))
+	    (tp->phy_version >= RTL_GIGA_PHY_VER_H))
 		return;
 
 	del_timer_sync(timer);
@@ -1085,7 +1107,7 @@ static inline void rtl8169_request_timer
 	struct timer_list *timer = &tp->timer;
 
 	if ((tp->mac_version <= RTL_GIGA_MAC_VER_B) ||
-	    (tp->phy_version >= RTL_GIGA_PHY_VER_G))
+	    (tp->phy_version >= RTL_GIGA_PHY_VER_H))
 		return;
 
 	init_timer(timer);
@@ -1563,13 +1585,20 @@ rtl8169_hw_start(struct net_device *dev)
 	tp->cp_cmd |= RTL_R16(CPlusCmd);
 	RTL_W16(CPlusCmd, tp->cp_cmd);
 
-	if (tp->mac_version == RTL_GIGA_MAC_VER_D) {
+	if ((tp->mac_version == RTL_GIGA_MAC_VER_D) ||
+	    (tp->mac_version == RTL_GIGA_MAC_VER_E)) {
 		dprintk(KERN_INFO PFX "Set MAC Reg C+CR Offset 0xE0. "
 			"Bit-3 and bit-14 MUST be 1\n");
 		tp->cp_cmd |= (1 << 14) | PCIMulRW;
 		RTL_W16(CPlusCmd, tp->cp_cmd);
 	}
 
+	/*
+	 * Undocumented corner. Supposedly:
+	 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets
+	 */
+	RTL_W16(IntrMitigate, 0x0000);
+
 	RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr & DMA_32BIT_MASK));
 	RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr >> 32));
 	RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr & DMA_32BIT_MASK));

_

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch 2.6.11-rc3 3/5] r8169: typo in debugging code
  2005-02-11 23:41 ` [patch 2.6.11-rc3 2/5] r8169: merge of Realtek's code Francois Romieu
@ 2005-02-11 23:42   ` Francois Romieu
  2005-02-11 23:44     ` [patch 2.6.11-rc3 4/5] r8169: screaming irq when the device is closed Francois Romieu
  0 siblings, 1 reply; 8+ messages in thread
From: Francois Romieu @ 2005-02-11 23:42 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: akpm, jdmason, netdev

Typo in debugging code.

Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>

diff -puN drivers/net/r8169.c~r8169-370 drivers/net/r8169.c
--- a/drivers/net/r8169.c~r8169-370	2005-02-05 21:04:22.000000000 +0100
+++ b/drivers/net/r8169.c	2005-02-12 00:25:04.364126556 +0100
@@ -79,7 +79,7 @@ VERSION 2.2LK	<2005/01/25>
 	        printk( "Assertion failed! %s,%s,%s,line=%d\n",	\
         	#expr,__FILE__,__FUNCTION__,__LINE__);		\
         }
-#define dprintk(fmt, args...)	do { printk(PFX fmt, ## args) } while (0)
+#define dprintk(fmt, args...)	do { printk(PFX fmt, ## args); } while (0)
 #else
 #define assert(expr) do {} while (0)
 #define dprintk(fmt, args...)	do {} while (0)

_

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch 2.6.11-rc3 4/5] r8169: screaming irq when the device is closed
  2005-02-11 23:42   ` [patch 2.6.11-rc3 3/5] r8169: typo in debugging code Francois Romieu
@ 2005-02-11 23:44     ` Francois Romieu
  2005-02-11 23:45       ` [patch 2.6.11-rc3 5/5] r8169: synchronization and balancing " Francois Romieu
  0 siblings, 1 reply; 8+ messages in thread
From: Francois Romieu @ 2005-02-11 23:44 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: akpm, jdmason, netdev

Close the race for a screaming irq when the device is closed.

- rtl8169_interrupt() try to properly IRQ_HANDLE an interrupt even when
  the network device is going down. As a benefit, rtl8169_poll() does not
  need to care about the close race any more;
- factor code with rtl8169_irq_mask_and_ack();
- rtl8169_init_board(): mitigate some really unexpected events.

Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>

diff -puN drivers/net/r8169.c~r8169-380 drivers/net/r8169.c
--- a/drivers/net/r8169.c~r8169-380	2005-02-05 21:04:32.000000000 +0100
+++ b/drivers/net/r8169.c	2005-02-12 00:25:00.002833963 +0100
@@ -490,6 +490,13 @@ static int mdio_read(void __iomem *ioadd
 	return value;
 }
 
+static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr)
+{
+	RTL_W16(IntrMask, 0x0000);
+
+	RTL_W16(IntrStatus, 0xffff);
+}
+
 static unsigned int rtl8169_tbi_reset_pending(void __iomem *ioaddr)
 {
 	return RTL_R32(TBICSR) & TBIReset;
@@ -1234,6 +1241,9 @@ rtl8169_init_board(struct pci_dev *pdev,
 		goto err_out_free_res;
 	}
 
+	// Unneeded ? Don't mess with Mrs. Murphy.
+	rtl8169_irq_mask_and_ack(ioaddr);
+
 	// Soft reset the chip. 
 	RTL_W8(ChipCmd, CmdReset);
 
@@ -1540,7 +1550,7 @@ err_free_irq:
 static void rtl8169_hw_reset(void __iomem *ioaddr)
 {
 	/* Disable interrupts */
-	RTL_W16(IntrMask, 0x0000);
+	rtl8169_irq_mask_and_ack(ioaddr);
 
 	/* Reset the chipset */
 	RTL_W8(ChipCmd, CmdReset);
@@ -1824,9 +1834,7 @@ static void rtl8169_wait_for_quiescence(
 	/* Wait for any pending NAPI task to complete */
 	netif_poll_disable(dev);
 
-	RTL_W16(IntrMask, 0x0000);
-
-	RTL_W16(IntrStatus, 0xffff);
+	rtl8169_irq_mask_and_ack(ioaddr);
 
 	netif_poll_enable(dev);
 }
@@ -2244,12 +2252,9 @@ rtl8169_interrupt(int irq, void *dev_ins
 	struct rtl8169_private *tp = netdev_priv(dev);
 	int boguscnt = max_interrupt_work;
 	void __iomem *ioaddr = tp->mmio_addr;
-	int status = 0;
+	int status;
 	int handled = 0;
 
-	if (unlikely(!netif_running(dev)))
-		goto out;
-
 	do {
 		status = RTL_R16(IntrStatus);
 
@@ -2259,6 +2264,9 @@ rtl8169_interrupt(int irq, void *dev_ins
 
 		handled = 1;
 
+		if (unlikely(!netif_running(dev)))
+			goto out_asic_stop;
+
 		status &= tp->intr_mask;
 		RTL_W16(IntrStatus,
 			(status & RxFIFOOver) ? (status | RxOverflow) : status);
@@ -2306,6 +2314,12 @@ rtl8169_interrupt(int irq, void *dev_ins
 	}
 out:
 	return IRQ_RETVAL(handled);
+
+out_asic_stop:
+	RTL_W8(ChipCmd, 0x00);
+	rtl8169_irq_mask_and_ack(ioaddr);
+	RTL_R16(CPlusCmd);
+	goto out;
 }
 
 #ifdef CONFIG_R8169_NAPI
@@ -2321,7 +2335,7 @@ static int rtl8169_poll(struct net_devic
 	*budget -= work_done;
 	dev->quota -= work_done;
 
-	if ((work_done < work_to_do) || !netif_running(dev)) {
+	if (work_done < work_to_do) {
 		netif_rx_complete(dev);
 		tp->intr_mask = 0xffff;
 		/*

_

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch 2.6.11-rc3 5/5] r8169: synchronization and balancing when the device is closed
  2005-02-11 23:44     ` [patch 2.6.11-rc3 4/5] r8169: screaming irq when the device is closed Francois Romieu
@ 2005-02-11 23:45       ` Francois Romieu
  2005-02-14 17:16         ` Jon Mason
  0 siblings, 1 reply; 8+ messages in thread
From: Francois Romieu @ 2005-02-11 23:45 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: akpm, jdmason, netdev

rtl8169_close synchronization and balancing

- use synchronize_kernel() to sync with the xmit thread (kindly suggested
  by davem);
- balance the netif_poll_disable issued in rtl8169_down.

Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>

diff -puN drivers/net/r8169.c~r8169-390 drivers/net/r8169.c
--- a/drivers/net/r8169.c~r8169-390	2005-02-12 00:06:40.381648524 +0100
+++ b/drivers/net/r8169.c	2005-02-12 00:06:48.015420988 +0100
@@ -2382,8 +2382,7 @@ static void rtl8169_down(struct net_devi
 	netif_poll_disable(dev);
 
 	/* Give a racing hard_start_xmit a few cycles to complete. */
-	set_current_state(TASK_UNINTERRUPTIBLE);
-	schedule_timeout(1);
+	synchronize_kernel();
 
 	rtl8169_tx_clear(tp);
 
@@ -2399,6 +2398,8 @@ static int rtl8169_close(struct net_devi
 
 	free_irq(dev->irq, dev);
 
+	netif_poll_enable(dev);
+
 	pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
 			    tp->RxPhyAddr);
 	pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,

_

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.11-rc3 1/5] r8169: endianness fixes
  2005-02-11 23:39 [patch 2.6.11-rc3 1/5] r8169: endianness fixes Francois Romieu
  2005-02-11 23:41 ` [patch 2.6.11-rc3 2/5] r8169: merge of Realtek's code Francois Romieu
@ 2005-02-13 17:49 ` Jeff Garzik
  1 sibling, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2005-02-13 17:49 UTC (permalink / raw)
  To: Francois Romieu; +Cc: akpm, jdmason, netdev

applied 1-5

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.11-rc3 5/5] r8169: synchronization and balancing when the device is closed
  2005-02-11 23:45       ` [patch 2.6.11-rc3 5/5] r8169: synchronization and balancing " Francois Romieu
@ 2005-02-14 17:16         ` Jon Mason
  2005-02-14 19:31           ` Francois Romieu
  0 siblings, 1 reply; 8+ messages in thread
From: Jon Mason @ 2005-02-14 17:16 UTC (permalink / raw)
  To: Francois Romieu; +Cc: Jeff Garzik, akpm, netdev

[...]
> @@ -2399,6 +2398,8 @@ static int rtl8169_close(struct net_devi
>  
>   free_irq(dev->irq, dev);
>  
> + netif_poll_enable(dev);
> +
>   pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
>         tp->RxPhyAddr);
>   pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
> 
> _

Dumb question....Why is this needed?  dev_close has already checked for the 
bit before it calls the rtl8169_close routine (and it was already ripped out 
by netif_poll_disable in rtl8169_down).  

-- 
Jon Mason
jdmason@us.ibm.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 2.6.11-rc3 5/5] r8169: synchronization and balancing when the device is closed
  2005-02-14 17:16         ` Jon Mason
@ 2005-02-14 19:31           ` Francois Romieu
  0 siblings, 0 replies; 8+ messages in thread
From: Francois Romieu @ 2005-02-14 19:31 UTC (permalink / raw)
  To: Jon Mason; +Cc: Jeff Garzik, akpm, netdev

Jon Mason <jdmason@us.ibm.com> :
> [...]
> > @@ -2399,6 +2398,8 @@ static int rtl8169_close(struct net_devi
> >  
> >   free_irq(dev->irq, dev);
> >  
> > + netif_poll_enable(dev);
> > +
> >   pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
> >         tp->RxPhyAddr);
> >   pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
> > 
> > _
> 
> Dumb question....Why is this needed?  dev_close has already checked for the 

dev_open() after dev_close(): netif_rx_schedule_prep() always fails in
rtl8169_interrupt() and the device can not be scheduled for poll. Sucky.

So, if someone wants to push it before 2.6.11 goes out...

-- 
Ueimor

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-02-14 19:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-11 23:39 [patch 2.6.11-rc3 1/5] r8169: endianness fixes Francois Romieu
2005-02-11 23:41 ` [patch 2.6.11-rc3 2/5] r8169: merge of Realtek's code Francois Romieu
2005-02-11 23:42   ` [patch 2.6.11-rc3 3/5] r8169: typo in debugging code Francois Romieu
2005-02-11 23:44     ` [patch 2.6.11-rc3 4/5] r8169: screaming irq when the device is closed Francois Romieu
2005-02-11 23:45       ` [patch 2.6.11-rc3 5/5] r8169: synchronization and balancing " Francois Romieu
2005-02-14 17:16         ` Jon Mason
2005-02-14 19:31           ` Francois Romieu
2005-02-13 17:49 ` [patch 2.6.11-rc3 1/5] r8169: endianness fixes Jeff Garzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).