From f35c4a3266bf655a177356e3e9b3a6df1d8e842e Mon Sep 17 00:00:00 2001
From: Jo-Philipp Wich <jow@openwrt.org>
Date: Tue, 7 Feb 2012 21:56:51 +0000
Subject: [PATCH] 8139cp: backport patches to make driver stable again

List of patches that Jo-Philipp groveled out of git.

Redux: defuzzed.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>

SVN-Revision: 30366
---
 .../x86/patches-3.2/001-alix_platform.patch   |  8 ++--
 .../x86/patches-3.2/002-geos_platform.patch   | 12 +----
 .../patches-3.2/005-net5501_platform.patch    | 20 +++------
 .../900-8139cp_napi_gro_flush.patch           | 25 +++++++++++
 .../patches-3.2/901-8139cp_eeprom_delay.patch | 37 +++++++++++++++
 .../902-8139cp_config_rx_mode.patch           | 45 +++++++++++++++++++
 6 files changed, 117 insertions(+), 30 deletions(-)
 create mode 100644 target/linux/x86/patches-3.2/900-8139cp_napi_gro_flush.patch
 create mode 100644 target/linux/x86/patches-3.2/901-8139cp_eeprom_delay.patch
 create mode 100644 target/linux/x86/patches-3.2/902-8139cp_config_rx_mode.patch

diff --git a/target/linux/x86/patches-3.2/001-alix_platform.patch b/target/linux/x86/patches-3.2/001-alix_platform.patch
index 21a5278cc6..de7005b381 100644
--- a/target/linux/x86/patches-3.2/001-alix_platform.patch
+++ b/target/linux/x86/patches-3.2/001-alix_platform.patch
@@ -58,7 +58,7 @@ index dc5f1d3..a24bf8c 100644
  static struct gpio_led alix_leds[] = {
  	{
  		.name = "alix:1",
-@@ -64,17 +106,22 @@ static struct platform_device alix_leds_
+@@ -64,17 +98,22 @@ static struct platform_device alix_leds_
  	.dev.platform_data = &alix_leds_data,
  };
  
@@ -83,7 +83,7 @@ index dc5f1d3..a24bf8c 100644
  	const char *bios_virt;
  	const char *scan_end;
  	const char *p;
-@@ -109,7 +156,8 @@ static int __init alix_present(unsigned
+@@ -109,7 +148,8 @@ static int __init alix_present(unsigned
  			*a = '\0';
  
  		tail = p + alix_sig_len;
@@ -93,7 +93,7 @@ index dc5f1d3..a24bf8c 100644
  			printk(KERN_INFO
  			       "%s: system is recognized as \"%s\"\n",
  			       KBUILD_MODNAME, name);
-@@ -120,6 +169,24 @@ static int __init alix_present(unsigned
+@@ -120,6 +160,24 @@ static int __init alix_present(unsigned
  	return 0;
  }
  
@@ -118,7 +118,7 @@ index dc5f1d3..a24bf8c 100644
  static int __init alix_init(void)
  {
  	const char tinybios_sig[] = "PC Engines ALIX.";
-@@ -128,8 +197,9 @@ static int __init alix_init(void)
+@@ -128,8 +186,9 @@ static int __init alix_init(void)
  	if (!is_geode())
  		return 0;
  
diff --git a/target/linux/x86/patches-3.2/002-geos_platform.patch b/target/linux/x86/patches-3.2/002-geos_platform.patch
index cdb8dc2f14..2f5d32e8e1 100644
--- a/target/linux/x86/patches-3.2/002-geos_platform.patch
+++ b/target/linux/x86/patches-3.2/002-geos_platform.patch
@@ -24,11 +24,9 @@ Cc: Andrew Morton <akpm@linux-foundation.org>
  3 files changed, 136 insertions(+), 0 deletions(-)
  create mode 100644 arch/x86/platform/geode/geos.c
 
-diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
-index 07c3f15..4ee921b 100644
 --- a/arch/x86/Kconfig
 +++ b/arch/x86/Kconfig
-@@ -2168,6 +2168,13 @@ config ALIX
+@@ -2090,6 +2090,13 @@ config ALIX
  
  	  Note: You have to set alix.force=1 for boards with Award BIOS.
  
@@ -42,16 +40,11 @@ index 07c3f15..4ee921b 100644
  endif # X86_32
  
  config AMD_NB
-diff --git a/arch/x86/platform/geode/Makefile b/arch/x86/platform/geode/Makefile
-index 07c9cd0..d8ba564 100644
 --- a/arch/x86/platform/geode/Makefile
 +++ b/arch/x86/platform/geode/Makefile
 @@ -1 +1,2 @@
  obj-$(CONFIG_ALIX)		+= alix.o
 +obj-$(CONFIG_GEOS)		+= geos.o
-diff --git a/arch/x86/platform/geode/geos.c b/arch/x86/platform/geode/geos.c
-new file mode 100644
-index 0000000..c2e6d53
 --- /dev/null
 +++ b/arch/x86/platform/geode/geos.c
 @@ -0,0 +1,128 @@
@@ -183,6 +176,3 @@ index 0000000..c2e6d53
 +MODULE_AUTHOR("Philip Prindeville <philipp@redfish-solutions.com>");
 +MODULE_DESCRIPTION("Traverse Technologies Geos System Setup");
 +MODULE_LICENSE("GPL");
--- 
-1.7.7.4
-
diff --git a/target/linux/x86/patches-3.2/005-net5501_platform.patch b/target/linux/x86/patches-3.2/005-net5501_platform.patch
index 1297214641..290e79a022 100644
--- a/target/linux/x86/patches-3.2/005-net5501_platform.patch
+++ b/target/linux/x86/patches-3.2/005-net5501_platform.patch
@@ -1,8 +1,6 @@
-diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
-index 2f18a15..7a4f34b 100644
 --- a/arch/x86/Kconfig
 +++ b/arch/x86/Kconfig
-@@ -2174,6 +2174,12 @@ config GEOS
+@@ -2097,6 +2097,12 @@ config GEOS
  	---help---
  	  This option enables system support for the Traverse Technologies GEOS.
  
@@ -15,17 +13,12 @@ index 2f18a15..7a4f34b 100644
  endif # X86_32
  
  config AMD_NB
-diff --git a/arch/x86/platform/geode/Makefile b/arch/x86/platform/geode/Makefile
-index d8ba564..5b51194 100644
 --- a/arch/x86/platform/geode/Makefile
 +++ b/arch/x86/platform/geode/Makefile
 @@ -1,2 +1,3 @@
  obj-$(CONFIG_ALIX)		+= alix.o
 +obj-$(CONFIG_NET5501)		+= net5501.o
  obj-$(CONFIG_GEOS)		+= geos.o
-diff --git a/arch/x86/platform/geode/net5501.c b/arch/x86/platform/geode/net5501.c
-new file mode 100644
-index 0000000..66d377e
 --- /dev/null
 +++ b/arch/x86/platform/geode/net5501.c
 @@ -0,0 +1,154 @@
@@ -183,9 +176,6 @@ index 0000000..66d377e
 +MODULE_AUTHOR("Philip Prindeville <philipp@redfish-solutions.com>");
 +MODULE_DESCRIPTION("Soekris net5501 System Setup");
 +MODULE_LICENSE("GPL");
-diff --git a/drivers/leds/leds-net5501.c b/drivers/leds/leds-net5501.c
-deleted file mode 100644
-index 0555d47..0000000
 --- a/drivers/leds/leds-net5501.c
 +++ /dev/null
 @@ -1,97 +0,0 @@
@@ -286,8 +276,8 @@ index 0555d47..0000000
 -arch_initcall(soekris_init);
 -
 -MODULE_LICENSE("GPL");
---- a/drivers/leds/Kconfig	2012-01-29 23:22:59.487891522 -0700
-+++ b/drivers/leds/Kconfig	2012-02-03 10:33:39.650202054 -0700
+--- a/drivers/leds/Kconfig
++++ b/drivers/leds/Kconfig
 @@ -89,16 +89,6 @@ config LEDS_NET48XX
  	  This option enables support for the Soekris net4801 and net4826 error
  	  LED.
@@ -305,8 +295,8 @@ index 0555d47..0000000
  config LEDS_FSG
  	tristate "LED Support for the Freecom FSG-3"
  	depends on LEDS_CLASS
---- a/drivers/leds/Makefile	2012-01-29 23:22:59.487891522 -0700
-+++ b/drivers/leds/Makefile	2012-02-03 10:33:24.468430696 -0700
+--- a/drivers/leds/Makefile
++++ b/drivers/leds/Makefile
 @@ -14,7 +14,6 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532)	+= led
  obj-$(CONFIG_LEDS_S3C24XX)		+= leds-s3c24xx.o
  obj-$(CONFIG_LEDS_AMS_DELTA)		+= leds-ams-delta.o
diff --git a/target/linux/x86/patches-3.2/900-8139cp_napi_gro_flush.patch b/target/linux/x86/patches-3.2/900-8139cp_napi_gro_flush.patch
new file mode 100644
index 0000000000..532cb2ca0d
--- /dev/null
+++ b/target/linux/x86/patches-3.2/900-8139cp_napi_gro_flush.patch
@@ -0,0 +1,25 @@
+From b189e810619a676e6b931a942a3e8387f3d39c21 Mon Sep 17 00:00:00 2001
+From: =?utf8?q?fran=C3=A7ois=20romieu?= <romieu@fr.zoreil.com>
+Date: Sun, 8 Jan 2012 13:41:33 +0000
+Subject: [PATCH] 8139cp: fix missing napi_gro_flush.
+
+The driver uses __napi_complete and napi_gro_receive. Without it, the
+driver hits the BUG_ON(n->gro_list) assertion hard in __napi_complete.
+
+Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
+Tested-by: Marin Glibic <zhilla2@gmail.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+---
+ drivers/net/ethernet/realtek/8139cp.c |    1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
+--- a/drivers/net/ethernet/realtek/8139cp.c
++++ b/drivers/net/ethernet/realtek/8139cp.c
+@@ -563,6 +563,7 @@ rx_next:
+ 		if (cpr16(IntrStatus) & cp_rx_intr_mask)
+ 			goto rx_status_loop;
+ 
++		napi_gro_flush(napi);
+ 		spin_lock_irqsave(&cp->lock, flags);
+ 		__napi_complete(napi);
+ 		cpw16_f(IntrMask, cp_intr_mask);
diff --git a/target/linux/x86/patches-3.2/901-8139cp_eeprom_delay.patch b/target/linux/x86/patches-3.2/901-8139cp_eeprom_delay.patch
new file mode 100644
index 0000000000..388755d266
--- /dev/null
+++ b/target/linux/x86/patches-3.2/901-8139cp_eeprom_delay.patch
@@ -0,0 +1,37 @@
+From 7d03f5a48e4d90854275b06433626243b3b3db17 Mon Sep 17 00:00:00 2001
+From: Jason Wang <jasowang@redhat.com>
+Date: Fri, 30 Dec 2011 23:44:33 +0000
+Subject: [PATCH] 8139cp/8139too: do not read into reserved registers
+
+delay_eeprom() use long read for Cfg9346 register(offset 0x50) which may read
+into the area of reserved register(offset 0x53). Use byte read instead.
+
+Signed-off-by: Jason Wang <jasowang@redhat.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+---
+ drivers/net/ethernet/realtek/8139cp.c  |    2 +-
+ drivers/net/ethernet/realtek/8139too.c |    2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+--- a/drivers/net/ethernet/realtek/8139cp.c
++++ b/drivers/net/ethernet/realtek/8139cp.c
+@@ -1590,7 +1590,7 @@ static int cp_set_mac_address(struct net
+    No extra delay is needed with 33Mhz PCI, but 66Mhz may change this.
+  */
+ 
+-#define eeprom_delay()	readl(ee_addr)
++#define eeprom_delay()	readb(ee_addr)
+ 
+ /* The EEPROM commands include the alway-set leading bit. */
+ #define EE_EXTEND_CMD	(4)
+--- a/drivers/net/ethernet/realtek/8139too.c
++++ b/drivers/net/ethernet/realtek/8139too.c
+@@ -1122,7 +1122,7 @@ static void __devexit rtl8139_remove_one
+    No extra delay is needed with 33Mhz PCI, but 66Mhz may change this.
+  */
+ 
+-#define eeprom_delay()	(void)RTL_R32(Cfg9346)
++#define eeprom_delay()	(void)RTL_R8(Cfg9346)
+ 
+ /* The EEPROM commands include the alway-set leading bit. */
+ #define EE_WRITE_CMD	(5)
diff --git a/target/linux/x86/patches-3.2/902-8139cp_config_rx_mode.patch b/target/linux/x86/patches-3.2/902-8139cp_config_rx_mode.patch
new file mode 100644
index 0000000000..e5c17d16f2
--- /dev/null
+++ b/target/linux/x86/patches-3.2/902-8139cp_config_rx_mode.patch
@@ -0,0 +1,45 @@
+From f872b237c1750221932e715da2552225afe4a95c Mon Sep 17 00:00:00 2001
+From: Jason Wang <jasowang@redhat.com>
+Date: Fri, 30 Dec 2011 23:44:42 +0000
+Subject: [PATCH] 8139cp: properly config rx mode after resuming
+
+Rx mode should be reset after resming, so unconditionally updating rx
+mode rather than conditionally updating based on the value we
+remembered, otherwise unexpected value may be used by the nic after
+resuming.
+
+btw. I find and test this when debugging guest hibernation in qemu, as
+I did not have a 8139cp card in hand, this patch is untested in a
+physical 8139cp card, plase review it carefully.
+
+Signed-off-by: Jason Wang <jasowang@redhat.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+---
+ drivers/net/ethernet/realtek/8139cp.c |    9 +++------
+ 1 files changed, 3 insertions(+), 6 deletions(-)
+
+--- a/drivers/net/ethernet/realtek/8139cp.c
++++ b/drivers/net/ethernet/realtek/8139cp.c
+@@ -860,7 +860,6 @@ static void __cp_set_rx_mode (struct net
+ 	struct cp_private *cp = netdev_priv(dev);
+ 	u32 mc_filter[2];	/* Multicast hash filter */
+ 	int rx_mode;
+-	u32 tmp;
+ 
+ 	/* Note: do not reorder, GCC is clever about common statements. */
+ 	if (dev->flags & IFF_PROMISC) {
+@@ -887,11 +886,9 @@ static void __cp_set_rx_mode (struct net
+ 	}
+ 
+ 	/* We can safely update without stopping the chip. */
+-	tmp = cp_rx_config | rx_mode;
+-	if (cp->rx_config != tmp) {
+-		cpw32_f (RxConfig, tmp);
+-		cp->rx_config = tmp;
+-	}
++	cp->rx_config = cp_rx_config | rx_mode;
++	cpw32_f(RxConfig, cp->rx_config);
++
+ 	cpw32_f (MAR0 + 0, mc_filter[0]);
+ 	cpw32_f (MAR0 + 4, mc_filter[1]);
+ }
-- 
2.30.2