Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Jun 2008 22:15:24 GMT
From:      Julian Elischer <julian@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 143059 for review
Message-ID:  <200806062215.m56MFObC006044@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=143059

Change 143059 by julian@julian_trafmon1 on 2008/06/06 22:15:12

	IFC@143055

Affected files ...

.. //depot/projects/vimage-commit/src/sys/arm/conf/GUMSTIX#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/conf/GUMSTIX.hints#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/include/intr.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/files.pxa#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/if_smc_smi.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxa_gpio.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxa_icu.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxa_machdep.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxa_obio.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxa_smi.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxa_space.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxa_timer.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxareg.h#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/pxavar.h#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/std.pxa#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/uart_bus_pxa.c#1 branch
.. //depot/projects/vimage-commit/src/sys/arm/xscale/pxa/uart_cpu_pxa.c#1 branch
.. //depot/projects/vimage-commit/src/sys/compat/linux/linux_mib.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/conf/files#2 integrate
.. //depot/projects/vimage-commit/src/sys/conf/options.arm#2 integrate
.. //depot/projects/vimage-commit/src/sys/contrib/pf/net/pf_ioctl.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/bktr/bktr_i2c.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/cs/if_cs.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/cs/if_cs_isa.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/cs/if_cs_pccard.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/cs/if_csreg.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/cs/if_csvar.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/ichsmb/ichsmb.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/ichsmb/ichsmb_pci.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/ichsmb/ichsmb_var.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/ie/if_ie.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/ie/if_ie_isa.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/if_ndis/if_ndis.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/if_ndis/if_ndisvar.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/iicbus/iicsmb.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/mii/miidevs#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/mii/smcphy.c#1 branch
.. //depot/projects/vimage-commit/src/sys/dev/si/si.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/si/si.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/smbus/smb.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/smc/if_smc.c#1 branch
.. //depot/projects/vimage-commit/src/sys/dev/smc/if_smcreg.h#1 branch
.. //depot/projects/vimage-commit/src/sys/dev/smc/if_smcvar.h#1 branch
.. //depot/projects/vimage-commit/src/sys/dev/usb/ubsa.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/usb/usbdevs#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/xe/if_xe.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/xe/if_xe_pccard.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/dev/xe/if_xevar.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/fs/devfs/devfs_vnops.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/kern/tty_tty.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/nlm/nlm_prot_impl.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/pci/amdpm.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/pci/amdsmb.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/pci/intpm.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/pci/nfsmb.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/pci/viapm.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/powerpc/aim/trap.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/security/audit/audit.c#2 integrate
.. //depot/projects/vimage-commit/src/sys/sys/ttydefaults.h#2 integrate
.. //depot/projects/vimage-commit/src/sys/vm/vm_page.c#2 integrate

Differences ...

==== //depot/projects/vimage-commit/src/sys/arm/include/intr.h#2 (text+ko) ====

@@ -32,7 +32,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/arm/include/intr.h,v 1.8 2008/04/20 23:29:06 cognet Exp $
+ * $FreeBSD: src/sys/arm/include/intr.h,v 1.9 2008/06/06 05:08:09 benno Exp $
  *
  */
 
@@ -41,6 +41,9 @@
 
 #ifdef CPU_XSCALE_81342
 #define NIRQ		128
+#elif defined(CPU_XSCALE_PXA2X0)
+#include <arm/xscale/pxa/pxareg.h>
+#define	NIRQ		IRQ_GPIO_MAX
 #elif defined(CPU_ARM9)
 #define NIRQ		64
 #else

==== //depot/projects/vimage-commit/src/sys/compat/linux/linux_mib.c#2 (text+ko) ====

@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/compat/linux/linux_mib.c,v 1.29 2007/01/14 16:07:01 netchild Exp $");
+__FBSDID("$FreeBSD: src/sys/compat/linux/linux_mib.c,v 1.30 2008/06/03 17:50:13 rdivacky Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -82,8 +82,8 @@
 	    0, 0, linux_sysctl_osname, "A",
 	    "Linux kernel OS name");
 
-static char	linux_osrelease[LINUX_MAX_UTSNAME] = "2.4.2";
-static int	linux_use_linux26 = 0;
+static char	linux_osrelease[LINUX_MAX_UTSNAME] = "2.6.16";
+static int	linux_use_linux26 = 1;
 
 static int
 linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)

==== //depot/projects/vimage-commit/src/sys/conf/files#2 (text+ko) ====

@@ -1,4 +1,4 @@
-# $FreeBSD: src/sys/conf/files,v 1.1306 2008/05/27 06:41:49 ed Exp $
+# $FreeBSD: src/sys/conf/files,v 1.1307 2008/06/06 05:00:49 benno Exp $
 #
 # The long compile-with and dependency lines are required because of
 # limitations in config: backslash-newline doesn't work in strings, and
@@ -901,6 +901,7 @@
 dev/mii/rlswitch.c		optional rlswitch
 # XXX rue only?
 dev/mii/ruephy.c		optional miibus | ruephy
+dev/mii/smcphy.c		optional miibus | smcphy
 dev/mii/tdkphy.c		optional miibus | tdkphy
 dev/mii/tlphy.c			optional miibus | tlphy
 dev/mii/ukphy.c			optional miibus | mii
@@ -1104,6 +1105,7 @@
 dev/smbus/smbconf.c		optional smbus
 dev/smbus/smbus.c		optional smbus
 dev/smbus/smbus_if.m		optional smbus
+dev/smc/if_smc.c		optional smc
 dev/sn/if_sn.c			optional sn
 dev/sn/if_sn_isa.c		optional sn isa
 dev/sn/if_sn_pccard.c		optional sn pccard

==== //depot/projects/vimage-commit/src/sys/conf/options.arm#2 (text+ko) ====

@@ -1,4 +1,4 @@
-#$FreeBSD: src/sys/conf/options.arm,v 1.19 2007/10/31 07:28:45 kevlo Exp $
+#$FreeBSD: src/sys/conf/options.arm,v 1.20 2008/06/06 05:08:09 benno Exp $
 ARM9_CACHE_WRITE_THROUGH	opt_global.h
 ARM_CACHE_LOCK_ENABLE	opt_global.h
 ARMFPE			opt_global.h
@@ -14,6 +14,7 @@
 CPU_XSCALE_80321	opt_global.h
 CPU_XSCALE_81342	opt_global.h
 CPU_XSCALE_IXP425	opt_global.h
+CPU_XSCALE_PXA2X0	opt_global.h
 FLASHADDR		opt_global.h
 KERNPHYSADDR		opt_global.h
 KERNVIRTADDR		opt_global.h

==== //depot/projects/vimage-commit/src/sys/contrib/pf/net/pf_ioctl.c#2 (text+ko) ====

@@ -40,7 +40,7 @@
 #include "opt_inet6.h"
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/contrib/pf/net/pf_ioctl.c,v 1.32 2008/05/09 23:02:55 julian Exp $");
+__FBSDID("$FreeBSD: src/sys/contrib/pf/net/pf_ioctl.c,v 1.33 2008/06/05 19:30:20 mlaier Exp $");
 #endif
 
 #ifdef __FreeBSD__
@@ -1532,7 +1532,7 @@
 		}
 
 #ifdef __FreeBSD__ /* ROUTEING */
-		if (rule->rtableid > 0 && rule->rtableid < rt_numfibs)
+		if (rule->rtableid > 0 && rule->rtableid > rt_numfibs)
 #else
 		if (rule->rtableid > 0 && !rtable_exists(rule->rtableid))
 #endif
@@ -1795,7 +1795,7 @@
 
 			if (newrule->rtableid > 0 &&
 #ifdef __FreeBSD__ /* ROUTING */
-			    newrule->rtableid < rt_numfibs)
+			    newrule->rtableid > rt_numfibs)
 #else
 			    !rtable_exists(newrule->rtableid))
 #endif

==== //depot/projects/vimage-commit/src/sys/dev/bktr/bktr_i2c.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/bktr/bktr_i2c.c,v 1.29 2006/12/31 19:42:47 jmg Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/bktr/bktr_i2c.c,v 1.30 2008/06/06 18:40:38 jhb Exp $");
 
 /*
  * I2C support for the bti2c chipset.
@@ -128,18 +128,22 @@
 	switch (index) {
 	case SMB_REQUEST_BUS:
 		/* XXX test & set */
+		mtx_lock(&Giant);
 		if (!sc->bus_owned) {
 			sc->bus_owned = 1;
 		} else
 			error = EWOULDBLOCK;
+		mtx_unlock(&Giant);
 		break;
 
 	case SMB_RELEASE_BUS:
 		/* XXX test & set */
+		mtx_lock(&Giant);
 		if (sc->bus_owned) {
 			sc->bus_owned = 0;
 		} else
 			error = EINVAL;
+		mtx_unlock(&Giant);
 		break;
 
 	default:
@@ -161,18 +165,22 @@
 	switch (index) {
 	case IIC_REQUEST_BUS:
 		/* XXX test & set */
+		mtx_lock(&Giant);
 		if (!sc->bus_owned) {
 			sc->bus_owned = 1;
 		} else
 			error = EWOULDBLOCK;
+		mtx_unlock(&Giant);
 		break;
 
 	case IIC_RELEASE_BUS:
 		/* XXX test & set */
+		mtx_lock(&Giant);
 		if (sc->bus_owned) {
 			sc->bus_owned = 0;
 		} else
 			error = EINVAL;
+		mtx_unlock(&Giant);
 		break;
 
 	default:
@@ -184,8 +192,10 @@
 
 int bti2c_iic_reset(device_t dev, u_char speed, u_char addr, u_char * oldaddr)
 {
+	mtx_lock(&Giant);
 	if (oldaddr)
 		*oldaddr = 0;			/* XXX */
+	mtx_unlock(&Giant);
 
 	return (IIC_ENOADDR);
 }
@@ -195,12 +205,14 @@
 	struct bktr_softc *sc  = (struct bktr_softc *)device_get_softc(dev);
 	int clock;
 
+	mtx_lock(&Giant);
 	clock = INL(sc, BKTR_I2C_DATA_CTL) & 0x2;
 
 	if (val)
 		OUTL(sc, BKTR_I2C_DATA_CTL, clock | 1);
 	else
 		OUTL(sc, BKTR_I2C_DATA_CTL, clock);
+	mtx_unlock(&Giant);
 
 	return;
 }
@@ -210,12 +222,14 @@
 	struct bktr_softc *sc  = (struct bktr_softc *)device_get_softc(dev);
 	int data;
 
+	mtx_lock(&Giant);
 	data = INL(sc, BKTR_I2C_DATA_CTL) & 0x1;
 
 	if (val)
 		OUTL(sc, BKTR_I2C_DATA_CTL, 0x2 | data);
 	else
 		OUTL(sc, BKTR_I2C_DATA_CTL, data);
+	mtx_unlock(&Giant);
 
 	return;
 }
@@ -224,8 +238,12 @@
 bti2c_iic_getsda(device_t dev)
 {
 	struct bktr_softc *sc  = (struct bktr_softc *)device_get_softc(dev);
+	int retval;
 
-	return (INL(sc,BKTR_I2C_DATA_CTL) & 0x1);
+	mtx_lock(&Giant);
+	retval = INL(sc,BKTR_I2C_DATA_CTL) & 0x1;
+	mtx_unlock(&Giant);
+	return (retval);
 }
 
 int
@@ -239,6 +257,8 @@
 {
 	u_long		x;
 
+	mtx_lock(&Giant);
+
 	/* clear status bits */
 	OUTL(sc, BKTR_INT_STAT, (BT848_INT_RACK | BT848_INT_I2CDONE));
 
@@ -257,9 +277,11 @@
 	if ( !x || !( INL(sc, BKTR_INT_STAT) & BT848_INT_RACK) ) {
 		BTI2C_DEBUG(printf("%c%c", (!x)?'+':'-',
 			(!( INL(sc, BKTR_INT_STAT) & BT848_INT_RACK))?'+':'-'));
+		mtx_unlock(&Giant);
 		return (SMB_ENOACK);
 	}
 	BTI2C_DEBUG(printf("+"));
+	mtx_unlock(&Giant);
 
 	/* return OK */
 	return( 0 );
@@ -305,6 +327,7 @@
 	struct bktr_softc *sc  = (struct bktr_softc *)device_get_softc(dev);
 	u_long		x;
 
+	mtx_lock(&Giant);
 	/* clear status bits */
 	OUTL(sc,BKTR_INT_STAT, (BT848_INT_RACK | BT848_INT_I2CDONE));
 
@@ -322,11 +345,13 @@
 	if ( !x || !(INL(sc,BKTR_INT_STAT) & BT848_INT_RACK) ) {
 		BTI2C_DEBUG(printf("r%c%c", (!x)?'+':'-',
 			(!( INL(sc,BKTR_INT_STAT) & BT848_INT_RACK))?'+':'-'));
+		mtx_unlock(&Giant);
 		return (SMB_ENOACK);
 	}
 
 	*byte = (char)((INL(sc,BKTR_I2C_DATA_CTL) >> 8) & 0xff);
 	BTI2C_DEBUG(printf("r%x+", *byte));
+	mtx_unlock(&Giant);
 
 	return (0);
 }

==== //depot/projects/vimage-commit/src/sys/dev/cs/if_cs.c#2 (text+ko) ====

@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/cs/if_cs.c,v 1.45 2006/09/15 15:16:10 glebius Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/cs/if_cs.c,v 1.53 2008/06/06 17:27:19 imp Exp $");
 
 /*
  *
@@ -73,11 +73,13 @@
 #endif
 
 static void	cs_init(void *);
+static void	cs_init_locked(struct cs_softc *);
 static int	cs_ioctl(struct ifnet *, u_long, caddr_t);
 static void	cs_start(struct ifnet *);
+static void	cs_start_locked(struct ifnet *);
 static void	cs_stop(struct cs_softc *);
 static void	cs_reset(struct cs_softc *);
-static void	cs_watchdog(struct ifnet *);
+static void	cs_watchdog(void *);
 
 static int	cs_mediachange(struct ifnet *);
 static void	cs_mediastatus(struct ifnet *, struct ifmediareq *);
@@ -92,23 +94,17 @@
 static int	get_eeprom_cksum(int, int, uint16_t *);
 static int	wait_eeprom_ready( struct cs_softc *);
 static void	control_dc_dc( struct cs_softc *, int );
-static int	send_test_pkt( struct cs_softc * );
 static int	enable_tp(struct cs_softc *);
 static int	enable_aui(struct cs_softc *);
 static int	enable_bnc(struct cs_softc *);
 static int      cs_duplex_auto(struct cs_softc *);
 
 devclass_t cs_devclass;
+driver_intr_t	csintr;
 
 /* sysctl vars */
 SYSCTL_NODE(_hw, OID_AUTO, cs, CTLFLAG_RD, 0, "cs device parameters");
 
-int	cs_debug = 0;
-TUNABLE_INT("hw.cs.debug", &cs_debug);
-SYSCTL_INT(_hw_cs, OID_AUTO, debug, CTLFLAG_RW,
-    &cs_debug, 0,
-  "cs debug");
-
 int	cs_ignore_cksum_failure = 0;
 TUNABLE_INT("hw.cs.ignore_checksum_failure", &cs_ignore_cksum_failure);
 SYSCTL_INT(_hw_cs, OID_AUTO, ignore_checksum_failure, CTLFLAG_RW,
@@ -119,15 +115,24 @@
 TUNABLE_INT("hw.cs.recv_delay", &cs_recv_delay);
 SYSCTL_INT(_hw_cs, OID_AUTO, recv_delay, CTLFLAG_RW, &cs_recv_delay, 570, "");
 
+static int cs8900_eeint2irq[16] = {
+	 10,  11,  12,   5, 255, 255, 255, 255,
+	255, 255, 255, 255, 255, 255, 255, 255 
+};
+
+static int cs8900_irq2eeint[16] = {
+	255, 255, 255, 255, 255,   3, 255, 255,
+	255,   0,   1,   2, 255, 255, 255, 255
+};
+
 static int
 get_eeprom_data(struct cs_softc *sc, int off, int len, uint16_t *buffer)
 {
 	int i;
 
 #ifdef CS_DEBUG
-	printf(CS_NAME":EEPROM data from %x for %x:\n", off, len);
+	device_printf(sc->dev, "EEPROM data from %x for %x:\n", off, len);
 #endif
-
 	for (i=0; i < len; i++) {
 		if (wait_eeprom_ready(sc) < 0)
 			return (-1);
@@ -138,8 +143,7 @@
 		buffer[i] = cs_readreg(sc, PP_EEData);
 
 #ifdef CS_DEBUG
-		printf("%02x %02x ",(unsigned char)buffer[i],
-		    (unsigned char)buffer[i] >> 8);
+		printf("%04x ",buffer[i]);
 #endif
 	}
 
@@ -158,20 +162,34 @@
 	for (i = 0; i < len; i++)
 		cksum += buffer[i];
 	cksum &= 0xffff;
-	if (cksum==0)
-		return (0);
-	if (cs_ignore_cksum_failure) {
-		printf(CS_NAME": checksum mismatch, ignoring\n");
+	if (cksum == 0 || cs_ignore_cksum_failure)
 		return (0);
-	}
 	return (-1);
 }
 
 static int
 wait_eeprom_ready(struct cs_softc *sc)
 {
-	DELAY(30000);	/* XXX should we do some checks here ? */
-	return (0);
+	int i;
+
+	/*
+	 * From the CS8900A datasheet, section 3.5.2:
+	 * "Before issuing any command to the EEPROM, the host must wait
+	 * for the SIBUSY bit (Register 16, SelfST, bit 8) to clear.  After
+	 * each command has been issued, the host must wait again for SIBUSY
+	 * to clear."
+	 *
+	 * Before we issue the command, we should be !busy, so that will
+	 * be fast.  The datasheet suggests that clock out from the part
+	 * per word will be on the order of 25us, which is consistant with
+	 * the 1MHz serial clock and 16bits...  We should never hit 100,
+	 * let alone 15,000 here.  The original code did an unconditional
+	 * 30ms DELAY here.  Bad Kharma.  cs_readreg takes ~2us.
+	 */
+	for (i = 0; i < 15000; i++)	/* 30ms max */
+		if (!(cs_readreg(sc, PP_SelfST) & SI_BUSY))
+			return (0);
+	return (1);
 }
 
 static void
@@ -184,7 +202,6 @@
 	else
 		self_control &= ~HCB1;
 	cs_writereg(sc, PP_SelfCTL, self_control);
-
 	DELAY(500000);
 }
 
@@ -197,7 +214,7 @@
 	cs_writereg(sc, PP_AutoNegCTL,
 	    RE_NEG_NOW | ALLOW_FDX | AUTO_NEG_ENABLE);
 	for (i=0; cs_readreg(sc, PP_AutoNegST) & AUTO_NEG_BUSY; i++) {
-		if (i > 40000) {
+		if (i > 4000) {
 			device_printf(sc->dev,
 			    "full/half duplex auto negotiation timeout\n");
 			error = ETIMEDOUT;
@@ -205,7 +222,6 @@
 		}
 		DELAY(1000);
 	}
-	DELAY(1000000);
 	return (error);
 }
 
@@ -215,91 +231,26 @@
 
 	cs_writereg(sc, PP_LineCTL, sc->line_ctl & ~AUI_ONLY);
 	control_dc_dc(sc, 0);
-	DELAY( 150000 );
-
-	if ((cs_readreg(sc, PP_LineST) & LINK_OK)==0) {
-		device_printf(sc->dev, "failed to enable TP\n");
-		return (EINVAL);
-	}
-
 	return (0);
 }
 
-/*
- * XXX This was rewritten from Linux driver without any tests.
- */
 static int
-send_test_pkt(struct cs_softc *sc)
-{
-	char test_packet[] = { 0,0,0,0,0,0, 0,0,0,0,0,0,
-				0, 46,  /* A 46 in network order */
-				0, 0,   /* DSAP=0 & SSAP=0 fields */
-				0xf3, 0 /* Control (Test Req + P bit set) */ };
-	int i;
-	u_char ether_address_backup[ETHER_ADDR_LEN];
-
-	for (i = 0; i < ETHER_ADDR_LEN; i++)
-		ether_address_backup[i] = sc->enaddr[i];
-
-	cs_writereg(sc, PP_LineCTL, cs_readreg(sc, PP_LineCTL) | SERIAL_TX_ON);
-	bcopy(test_packet, sc->enaddr, ETHER_ADDR_LEN);
-	bcopy(test_packet+ETHER_ADDR_LEN, 
-	    sc->enaddr, ETHER_ADDR_LEN);
-	cs_outw(sc, TX_CMD_PORT, sc->send_cmd);
-	cs_outw(sc, TX_LEN_PORT, sizeof(test_packet));
-
-	/* Wait for chip to allocate memory */
-	DELAY(50000);
-	if (!(cs_readreg(sc, PP_BusST) & READY_FOR_TX_NOW)) {
-		for (i = 0; i < ETHER_ADDR_LEN; i++)
-			sc->enaddr[i] = ether_address_backup[i];
-		return (0);
-	}
-
-	outsw(sc->nic_addr + TX_FRAME_PORT, test_packet, sizeof(test_packet));
-
-	DELAY(30000);
-
-	for (i = 0; i < ETHER_ADDR_LEN; i++)
-		sc->enaddr[i] = ether_address_backup[i];
-	if ((cs_readreg(sc, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK)
-		return (1);
-	return (0);
-}
-
-/*
- * XXX This was rewritten from Linux driver without any tests.
- */
-static int
 enable_aui(struct cs_softc *sc)
 {
 
-	control_dc_dc(sc, 0);
 	cs_writereg(sc, PP_LineCTL,
 	    (sc->line_ctl & ~AUTO_AUI_10BASET) | AUI_ONLY);
-
-	if (!send_test_pkt(sc)) {
-		device_printf(sc->dev, "failed to enable AUI\n");
-		return (EINVAL);
-	}
+	control_dc_dc(sc, 0);
 	return (0);
 }
 
-/*
- * XXX This was rewritten from Linux driver without any tests.
- */
 static int
 enable_bnc(struct cs_softc *sc)
 {
 
-	control_dc_dc(sc, 1);
 	cs_writereg(sc, PP_LineCTL,
 	    (sc->line_ctl & ~AUTO_AUI_10BASET) | AUI_ONLY);
-
-	if (!send_test_pkt(sc)) {
-		device_printf(sc->dev, "failed to enable BNC\n");
-		return (EINVAL);
-	}
+	control_dc_dc(sc, 1);
 	return (0);
 }
 
@@ -316,6 +267,7 @@
 	uint16_t eeprom_buff[CHKSUM_LEN];
 	int chip_type, pp_isaint, pp_isadma;
 
+	sc->dev = dev;
 	error = cs_alloc_port(dev, 0, CS_89x0_IO_PORTS);
 	if (error)
 		return (error);
@@ -348,7 +300,7 @@
 
 	sc->chip_type = chip_type;
 
-	if(chip_type==CS8900) {
+	if (chip_type == CS8900) {
 		pp_isaint = PP_CS8900_ISAINT;
 		pp_isadma = PP_CS8900_ISADMA;
 		sc->send_cmd = TX_CS8900_AFTER_ALL;
@@ -366,7 +318,7 @@
 	sc->isa_config   = 0;
 
 	/*
-	 * If no interrupt specified (or "?"), use what the board tells us.
+	 * If no interrupt specified, use what the board tells us.
 	 */
 	error = bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, &junk);
 
@@ -375,101 +327,63 @@
 	 */
 	if((cs_readreg(sc, PP_SelfST) & EEPROM_PRESENT) == 0) {
 		device_printf(dev, "No EEPROM, assuming defaults.\n");
+	} else if (get_eeprom_data(sc,START_EEPROM_DATA,CHKSUM_LEN, eeprom_buff)<0) {
+		device_printf(dev, "EEPROM read failed, assuming defaults.\n");
+	} else if (get_eeprom_cksum(START_EEPROM_DATA,CHKSUM_LEN, eeprom_buff)<0) {
+		device_printf(dev, "EEPROM cheksum bad, assuming defaults.\n");
 	} else {
-		if (get_eeprom_data(sc,START_EEPROM_DATA,CHKSUM_LEN, eeprom_buff)<0) {
-			device_printf(dev, "EEPROM read failed, "
-				"assuming defaults.\n");
-		} else {
-			if (get_eeprom_cksum(START_EEPROM_DATA,CHKSUM_LEN, eeprom_buff)<0) {
-				device_printf(dev, "EEPROM cheksum bad, "
-					"assuming defaults.\n");
+		sc->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET/2];
+		sc->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET/2];
+		sc->isa_config = eeprom_buff[ISA_CNF_OFFSET/2];
+		for (i=0; i<ETHER_ADDR_LEN/2; i++) {
+			sc->enaddr[i*2] = eeprom_buff[i];
+			sc->enaddr[i*2+1] = eeprom_buff[i] >> 8;
+		}
+		/*
+		 * If no interrupt specified, use what the
+		 * board tells us.
+		 */
+		if (error) {
+			irq = sc->isa_config & INT_NO_MASK;
+			error = 0;
+			if (chip_type == CS8900) {
+				irq = cs8900_eeint2irq[irq];
 			} else {
-				sc->auto_neg_cnf =
-				    eeprom_buff[AUTO_NEG_CNF_OFFSET/2];
-				sc->adapter_cnf =
-				    eeprom_buff[ADAPTER_CNF_OFFSET/2];
-				sc->isa_config =
-				    eeprom_buff[ISA_CNF_OFFSET/2];
-    
-				for (i=0; i<ETHER_ADDR_LEN/2; i++) {
-					sc->enaddr[i*2]=
-					    eeprom_buff[i];
-					sc->enaddr[i*2+1]=
-					    eeprom_buff[i] >> 8;
-				}
-
-				/*
-				 * If no interrupt specified,
-				 * use what the board tells us.
-				 */
-				if (error) {
-					irq = sc->isa_config & INT_NO_MASK;
-					error = 0;
-					if (chip_type==CS8900) {
-						switch(irq) {
-						case 0:
-							irq=10;
-							break;
-						case 1:
-							irq=11;
-							break;
-						case 2:
-							irq=12;
-							break;
-						case 3:
-							irq=5;
-							break;
-						 default:
-							device_printf(dev, "invalid irq in EEPROM.\n");
-							error=EINVAL;
-						}
-					} else {
-						if (irq>CS8920_NO_INTS) {
-							device_printf(dev, "invalid irq in EEPROM.\n");
-							error=EINVAL;
-						}
-					}
-					if (!error)
-						bus_set_resource(dev, SYS_RES_IRQ, 0,
-								irq, 1);
-				}
+				if (irq > CS8920_NO_INTS)
+					irq = 255;
+			}
+			if (irq == 255) {
+				device_printf(dev, "invalid irq in EEPROM.\n");
+				error = EINVAL;
 			}
+			if (!error)
+				bus_set_resource(dev, SYS_RES_IRQ, 0,
+				    irq, 1);
 		}
 	}
 
-	if (!error) {
+	if (!error && !(sc->flags & CS_NO_IRQ)) {
 		if (chip_type == CS8900) {
-			switch(irq) {
-				case  5:
-					irq = 3;
-					break;
-				case 10:
-					irq = 0;
-					break;
-				case 11:
-					irq = 1;
-					break;
-				case 12:
-					irq = 2;
-					break;
-				default:
-					error=EINVAL;
-			}
+			if (irq >= 0 || irq < 16)
+				irq = cs8900_irq2eeint[irq];
+			else
+				irq = 255;
 		} else {
-			if (irq > CS8920_NO_INTS) {
-				error = EINVAL;
-			}
+			if (irq > CS8920_NO_INTS)
+				irq = 255;
 		}
+		if (irq == 255)
+			error = EINVAL;
 	}
 
-	if (!error) {
-		if (!(sc->flags & CS_NO_IRQ))
-			cs_writereg(sc, pp_isaint, irq);
-	} else {
+	if (error) {
 	       	device_printf(dev, "Unknown or invalid irq\n");
-		return (ENXIO);
+		return (error);
 	}
 
+	if (!(sc->flags & CS_NO_IRQ))
+		cs_writereg(sc, pp_isaint, irq);
+
 	/*
 	 * Temporary disabled
 	 *
@@ -483,8 +397,8 @@
 
 	if (bootverbose)
 		 device_printf(dev, "CS89%c0%s rev %c media%s%s%s\n",
-			chip_type==CS8900 ? '0' : '2',
-			chip_type==CS8920M ? "M" : "",
+			chip_type == CS8900 ? '0' : '2',
+			chip_type == CS8920M ? "M" : "",
 			chip_revision,
 			(sc->adapter_cnf & A_CNF_10B_T) ? " TP"  : "",
 			(sc->adapter_cnf & A_CNF_AUI)   ? " AUI" : "",
@@ -502,7 +416,8 @@
 /*
  * Allocate a port resource with the given resource id.
  */
-int cs_alloc_port(device_t dev, int rid, int size)
+int
+cs_alloc_port(device_t dev, int rid, int size)
 {
 	struct cs_softc *sc = device_get_softc(dev);
 	struct resource *res;
@@ -513,38 +428,19 @@
 		return (ENOENT);
 	sc->port_rid = rid;
 	sc->port_res = res;
-	sc->port_used = size;
 	return (0);
 }
 
 /*
- * Allocate a memory resource with the given resource id.
- */
-int cs_alloc_memory(device_t dev, int rid, int size)
-{
-	struct cs_softc *sc = device_get_softc(dev);
-	struct resource *res;
-
-	res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
-	    0ul, ~0ul, size, RF_ACTIVE);
-	if (res == NULL)
-		return (ENOENT);
-	sc->mem_rid = rid;
-	sc->mem_res = res;
-	sc->mem_used = size;
-	return (0);
-}
-
-/*
  * Allocate an irq resource with the given resource id.
  */
-int cs_alloc_irq(device_t dev, int rid, int flags)
+int
+cs_alloc_irq(device_t dev, int rid)
 {
 	struct cs_softc *sc = device_get_softc(dev);
 	struct resource *res;
 
-	res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
-	    (RF_ACTIVE | flags));
+	res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
 	if (res == NULL)
 		return (ENOENT);
 	sc->irq_rid = rid;
@@ -555,7 +451,8 @@
 /*
  * Release all resources
  */
-void cs_release_resources(device_t dev)
+void
+cs_release_resources(device_t dev)
 {
 	struct cs_softc *sc = device_get_softc(dev);
 
@@ -564,11 +461,6 @@
 		    sc->port_rid, sc->port_res);
 		sc->port_res = 0;
 	}
-	if (sc->mem_res) {
-		bus_release_resource(dev, SYS_RES_MEMORY,
-		    sc->mem_rid, sc->mem_res);
-		sc->mem_res = 0;
-	}
 	if (sc->irq_res) {
 		bus_release_resource(dev, SYS_RES_IRQ,
 		    sc->irq_rid, sc->irq_res);
@@ -582,7 +474,7 @@
 int
 cs_attach(device_t dev)
 {
-	int media=0;
+	int error, media=0;
 	struct cs_softc *sc = device_get_softc(dev);;
 	struct ifnet *ifp;
 
@@ -591,28 +483,26 @@
 	ifp = sc->ifp = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
 		device_printf(dev, "can not if_alloc()\n");
-		return (0);
+		cs_release_resources(dev);
+		return (ENOMEM);
 	}
 
-	cs_stop( sc );
+	mtx_init(&sc->lock, device_get_nameunit(dev), MTX_NETWORK_LOCK,
+	    MTX_DEF);
+	callout_init_mtx(&sc->timer, &sc->lock, 0);
+
+	CS_LOCK(sc);
+	cs_stop(sc);
+	CS_UNLOCK(sc);
 
 	ifp->if_softc=sc;
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
 	ifp->if_start=cs_start;
 	ifp->if_ioctl=cs_ioctl;
-	ifp->if_watchdog=cs_watchdog;
 	ifp->if_init=cs_init;
-	ifp->if_snd.ifq_maxlen= IFQ_MAXLEN;
-	/*
-	 *  MIB DATA
-	 */
-	/*
-	ifp->if_linkmib=&sc->mibdata;
-	ifp->if_linkmiblen=sizeof sc->mibdata;
-	*/
+	IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
 
-	ifp->if_flags=(IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
-	    IFF_NEEDSGIANT);
+	ifp->if_flags=(IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
 
 	/*
 	 * this code still in progress (DMA support)
@@ -633,7 +523,10 @@
 	sc->buffer=malloc(ETHER_MAX_LEN-ETHER_CRC_LEN,M_DEVBUF,M_NOWAIT);
 	if (sc->buffer == NULL) {
 		device_printf(sc->dev, "Couldn't allocate memory for NIC\n");
-		return(0);
+		if_free(ifp);
+		mtx_destroy(&sc->lock);
+		cs_release_resources(dev);
+		return(ENOMEM);
 	}
 
 	/*
@@ -684,6 +577,17 @@
 
 	ether_ifattach(ifp, sc->enaddr);
 
+  	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
+	    NULL, csintr, sc, &sc->irq_handle);
+	if (error) {
+		ether_ifdetach(ifp);
+		free(sc->buffer, M_DEVBUF);
+		if_free(ifp);
+		mtx_destroy(&sc->lock);
+		cs_release_resources(dev);
+		return (error);
+	}
+
 	return (0);
 }
 
@@ -696,11 +600,16 @@
 	sc = device_get_softc(dev);
 	ifp = sc->ifp;
 
+	CS_LOCK(sc);
 	cs_stop(sc);
-	ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+	CS_UNLOCK(sc);
+	callout_drain(&sc->timer);
 	ether_ifdetach(ifp);
+	bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
 	cs_release_resources(dev);
+	free(sc->buffer, M_DEVBUF);
 	if_free(ifp);
+	mtx_destroy(&sc->lock);
 	return (0);
 }
 
@@ -711,17 +620,24 @@
 cs_init(void *xsc)
 {
 	struct cs_softc *sc=(struct cs_softc *)xsc;
+
+	CS_LOCK(sc);
+	cs_init_locked(sc);
+	CS_UNLOCK(sc);
+}
+
+static void
+cs_init_locked(struct cs_softc *sc)
+{
 	struct ifnet *ifp = sc->ifp;
-	int i, s, rx_cfg;
+	int i, rx_cfg;
 
 	/*
-	 * reset whatchdog timer
+	 * reset watchdog timer
 	 */
-	ifp->if_timer=0;
+	sc->tx_timeout = 0;
 	sc->buf_len = 0;
 	
-	s=splimp();
-
 	/*
 	 * Hardware initialization of cs
 	 */
@@ -773,13 +689,12 @@
 	 */
 	sc->ifp->if_drv_flags |= IFF_DRV_RUNNING;
 	sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+	callout_reset(&sc->timer, hz, cs_watchdog, sc);
 
 	/*
 	 * Start sending process
 	 */
-	cs_start(ifp);
-
-	(void) splx(s);
+	cs_start_locked(ifp);
 }
 
 /*
@@ -869,6 +784,7 @@
 	device_printf(sc->dev, "Interrupt.\n");
 #endif
 
+	CS_LOCK(sc);
 	while ((status=cs_inw(sc, ISQ_PORT))) {
 
 #ifdef CS_DEBUG
@@ -886,18 +802,18 @@
 			else

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806062215.m56MFObC006044>