From sdegler@degler.net  Fri Dec 28 22:27:12 2001
Return-Path: <sdegler@degler.net>
Received: from degler.net (crusoe.degler.net [66.114.64.229])
	by hub.freebsd.org (Postfix) with ESMTP id 3AB8F37B41E
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 28 Dec 2001 22:27:11 -0800 (PST)
Received: (from sdegler@localhost)
	by degler.net (8.11.6/8.11.0) id fBT6R1h98849;
	Sat, 29 Dec 2001 01:27:01 -0500 (EST)
Message-Id: <200112290627.fBT6R1h98849@degler.net>
Date: Sat, 29 Dec 2001 01:27:01 -0500 (EST)
From: Stephen Degler <sdegler@degler.net>
Reply-To: Stephen Degler <sdegler@degler.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc: sdegler@degler.net
Subject: patches to add support for ethernet on sis 635/735 chipsets
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         33294
>Category:       kern
>Synopsis:       patches to add support for ethernet on sis 635/735 chipsets
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    wpaul
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 28 22:30:00 PST 2001
>Closed-Date:    Sat Jan 12 16:33:04 PST 2002
>Last-Modified:  Sat Jan 12 16:33:26 PST 2002
>Originator:     Stephen Degler
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Very little, at best.
>Environment:
System: FreeBSD crusoe.degler.net 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Fri Dec 7 01:42:27 EST 2001 root@crusoe.degler.net:/usr/src/sys/i386/compile/CRUSOE i386


	
>Description:
	-current (and stable?) do not support embedded ethernet on sis
	635 and 735 chipsets.  I'm judging this based on an ECS K7S5A
	motherboard.  The following patches fix the problems with failure to
	detect the mii interface, and failure to read the mac address.

	The ECS K7S5A uses a Realtek 8201 phy, but I have not added
	explicit support for it.  The ukphy functionality seems to work
	fine.

	These changes were derived from the Linux SiS driver, which is
	the only source of documentation available for the newer chipsets.
	
	Note that the current sis ethernet driver has a bad hack
	to read the mac address for 630 series chipsets.  Looking at
	the NetBSD sources, it should be possible to replace that with
	the newer method, but I don't have the hardware to test with.

	
>How-To-Repeat:
	
	Fire up -current on a SIS 635/735 based system.  See the onboard
	ethernet lose.
>Fix:

	
	These patches are working for me:
==========================================================================
--- if_sis.c.orig	Sat Dec 29 00:17:49 2001
+++ if_sis.c	Sat Dec 29 00:18:13 2001
@@ -147,6 +147,7 @@
 static void sis_read_cmos	__P((struct sis_softc *, device_t, caddr_t,
 							int, int));
 static device_t sis_find_bridge	__P((device_t));
+static void sis_635_reload_mac __P((struct sis_softc *, caddr_t));
 #endif
 
 static int sis_miibus_readreg	__P((device_t, int, int));
@@ -486,6 +487,33 @@
 	pci_write_config(bridge, 0x48, reg & ~0x40, 1);
 	return;
 }
+
+/* force 635/735/745 mac to be reloaded from cmos */
+/* may be possible for 630 types as well avoiding ick above */
+/* not yet tested for that case */
+static void sis_635_reload_mac(sc, dest)
+	struct sis_softc	*sc;
+	caddr_t			dest;
+{
+	u_int32_t i,rxfctl_save;
+
+	rxfctl_save = CSR_READ_4(sc,SIS_RXFILT_CTL);
+	SIS_SETBIT(sc,SIS_CSR,SIS_CSR_RELOAD);
+	CSR_WRITE_4(sc,SIS_CSR,0);
+	/* disable packet filter */
+	CSR_WRITE_4(sc,SIS_RXFILT_CTL,rxfctl_save & ~SIS_RXFILTCTL_ENABLE);
+
+        /* load MAC addr to filter data register */
+        for (i = 0 ; i < 3 ; i++) {
+                CSR_WRITE_4(sc,SIS_RXFILT_CTL,(i << 16));
+		((u_int16_t *)dest)[i] = 
+			(u_int16_t)(CSR_READ_4(sc,SIS_RXFILT_DATA) & 0xffff);
+	}
+	/* enable packet filitering */
+        CSR_WRITE_4(sc,SIS_RXFILT_CTL,rxfctl_save);
+	return;
+}
+
 #endif
 
 static int sis_miibus_readreg(dev, phy, reg)
@@ -516,7 +544,8 @@
 		return(val);
 	}
 
-	if (sc->sis_type == SIS_TYPE_900 && phy != 0)
+	if (sc->sis_type == SIS_TYPE_900 && sc->sis_rev < SIS_REV_635 &&
+		phy != 0)
 		return(0);
 
 	CSR_WRITE_4(sc, SIS_PHYCTL, (phy << 11) | (reg << 6) | SIS_PHYOP_READ);
@@ -556,7 +585,8 @@
 		return(0);
 	}
 
-	if (sc->sis_type == SIS_TYPE_900 && phy != 0)
+	if (sc->sis_type == SIS_TYPE_900 && sc->sis_rev < SIS_REV_635 &&
+		phy != 0)
 		return(0);
 
 	CSR_WRITE_4(sc, SIS_PHYCTL, (data << 16) | (phy << 11) |
@@ -785,6 +815,8 @@
 	if (pci_get_vendor(dev) == NS_VENDORID)
 		sc->sis_type = SIS_TYPE_83815;
 
+        sc->sis_rev = pci_read_config(dev, PCIR_REVID, 1);
+
 	/*
 	 * Handle power management nonsense.
 	 */
@@ -925,13 +957,15 @@
 		 * requires some datasheets that I don't have access
 		 * to at the moment.
 		 */
-		command = pci_read_config(dev, PCIR_REVID, 1);
-		if (command == SIS_REV_630S ||
-		    command == SIS_REV_630E ||
-		    command == SIS_REV_630EA1)
+	
+		if (sc->sis_rev == SIS_REV_630S ||
+		    sc->sis_rev == SIS_REV_630E ||
+		    sc->sis_rev == SIS_REV_630EA1)
 			sis_read_cmos(sc, dev, (caddr_t)&eaddr, 0x9, 6);
+		else if ( sc->sis_rev == SIS_REV_635 )
+			sis_635_reload_mac(sc, (caddr_t)&eaddr);
 		else
-#endif
+#endif /* __i386__ */
 			sis_read_eeprom(sc, (caddr_t)&eaddr,
 			    SIS_EE_NODEADDR, 3, 0);
 		break;
==========================================================================
--- if_sisreg.h.orig	Sat Dec 29 00:18:00 2001
+++ if_sisreg.h	Sat Dec 29 00:18:19 2001
@@ -105,6 +105,7 @@
 #define SIS_CSR_RX_RESET	0x00000020
 #define SIS_CSR_SOFTINTR	0x00000080
 #define SIS_CSR_RESET		0x00000100
+#define SIS_CSR_RELOAD		0x00000400
 
 #define SIS_CFG_BIGENDIAN	0x00000001
 #define SIS_CFG_PERR_DETECT	0x00000008
@@ -381,7 +382,7 @@
 #define SIS_REV_630E		0x0081
 #define SIS_REV_630S		0x0082
 #define SIS_REV_630EA1		0x0083
-
+#define SIS_REV_635		0x0090
 /*
  * NatSemi vendor ID
  */
@@ -412,6 +413,7 @@
 	device_t		sis_miibus;
 	u_int8_t		sis_unit;
 	u_int8_t		sis_type;
+	u_int8_t		sis_rev;
 	u_int8_t		sis_link;
 	struct sis_list_data	sis_ldata;
 	bus_dma_tag_t		sis_parent_tag;
>Release-Note:
>Audit-Trail:

From: SUZUKI Koichi <metal@gc5.so-net.ne.jp>
To: Stephen Degler <sdegler@degler.net>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/33294: patches to add support for ethernet on sis 635/735 chipsets
Date: Sun, 30 Dec 2001 02:50:49 -0800

 Hi,
 
 As I mentiond in kern/30836,
   Mr. Kurosawa wrote the similar patch.
 
      http://homepage2.nifty.com/tkuro/archive/if_sis.diff
 
 Please reffer to his patch,
   when committing Mr Degler's patch.
 
 Thanks.
 
 -- 
 This is my STYLE.
 SUZUKI Koichi
 
Responsible-Changed-From-To: freebsd-bugs->wpaul 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Sun Dec 30 07:12:41 PST 2001 
Responsible-Changed-Why:  
Over to the SIS maintainer (but see also PR kern/30836). 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33294 
State-Changed-From-To: open->closed 
State-Changed-By: wpaul 
State-Changed-When: Sat Jan 12 16:33:04 PST 2002 
State-Changed-Why:  
Slightly modified patch applied to -current and -stable. 

-Bill 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33294 
>Unformatted:
