Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Sep 2001 18:38:02 -0700
From:      Brooks Davis <brooks@one-eyed-alien.net>
To:        mobile@freebsd.org, audit@freebsd.org
Subject:   call for review/test: wi probe/attach split
Message-ID:  <20010927183802.A16104@Odin.AC.HMC.Edu>

next in thread | raw e-mail | index | archive | help

--jI8keyz6grp/JLjh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I've modified the wi driver to split the pccard and pci probe/attach code
into seperate files to eliminate the current icky NPCI hack.  I've been
able to compile it with both non-pccard and non-pci kernel configs,
but I don't actually have any card supported by wi at the moment so I
can't test it.

I've attached the patch against current and will also update a copy at:

http://people.freebsd.org/~brooks/patches/wi.diff

-- Brooks

Index: sys/conf/files
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/cvs/src/sys/conf/files,v
retrieving revision 1.571
diff -u -r1.571 files
--- sys/conf/files	27 Sep 2001 21:54:26 -0000	1.571
+++ sys/conf/files	28 Sep 2001 01:27:51 -0000
@@ -601,6 +601,9 @@
 dev/wds/wd7000.c		optional wds isa
 dev/wi/if_wi.c			optional wi
 dev/wi/if_wi.c			optional wi pccard
+dev/wi/if_wi_pccard.c		optional wi card
+dev/wi/if_wi_pccard.c		optional wi pccard
+dev/wi/if_wi_pci.c		optional wi pci
 dev/wl/if_wl.c			optional wl isa
 dev/xe/if_xe.c			optional xe card
 fs/deadfs/dead_vnops.c	standard
Index: sys/dev/wi/if_wi.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/cvs/src/sys/dev/wi/if_wi.c,v
retrieving revision 1.61
diff -u -r1.61 if_wi.c
--- sys/dev/wi/if_wi.c	12 Sep 2001 08:37:16 -0000	1.61
+++ sys/dev/wi/if_wi.c	27 Sep 2001 23:25:51 -0000
@@ -66,55 +66,35 @@
 #define WI_HERMES_STATS_WAR	/* Work around stats counter bug. */
 #define WICACHE			/* turn on signal strength cache code */ =20
=20
-#include "pci.h"
-
 #include <sys/param.h>
-#include <sys/systm.h>
 #include <sys/sockio.h>
-#include <sys/mbuf.h>
 #include <sys/proc.h>
 #include <sys/kernel.h>
 #include <sys/socket.h>
-#include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/syslog.h>
 #include <sys/sysctl.h>
=20
 #include <machine/bus.h>
 #include <machine/resource.h>
-#include <machine/md_var.h>
-#include <machine/bus_pio.h>
 #include <sys/rman.h>
=20
-#if NPCI > 0
-#include <pci/pcireg.h>
-#include <pci/pcivar.h>
-#endif
-
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_dl.h>
 #include <net/if_media.h>
-#include <net/if_types.h>
 #include <net/if_ieee80211.h>
=20
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
-#include <netinet/in_var.h>
 #include <netinet/ip.h>
-#include <netinet/if_ether.h>
=20
 #include <net/bpf.h>
=20
-#include <dev/pccard/pccardvar.h>
-#include <dev/pccard/pccarddevs.h>
-
 #include <dev/wi/if_wavelan_ieee.h>
 #include <dev/wi/if_wireg.h>
=20
-#include "card_if.h"
-
 #if !defined(lint)
 static const char rcsid[] =3D
   "$FreeBSD: src/sys/dev/wi/if_wi.c,v 1.61 2001/09/12 08:37:16 julian Exp =
$";
@@ -155,144 +135,14 @@
 	struct mbuf *, unsigned short));
 #endif
=20
-static int wi_generic_attach	__P((device_t));
-static int wi_pccard_match	__P((device_t));
-static int wi_pccard_probe	__P((device_t));
-static int wi_pccard_attach	__P((device_t));
-#if NPCI > 0
-static int wi_pci_probe		__P((device_t));
-static int wi_pci_attach	__P((device_t));
-#endif
-static int wi_pccard_detach	__P((device_t));
-static void wi_shutdown		__P((device_t));
-
-static int wi_alloc		__P((device_t, int));
-static void wi_free		__P((device_t));
-
 static int wi_get_cur_ssid	__P((struct wi_softc *, char *, int *));
 static int wi_media_change	__P((struct ifnet *));
 static void wi_media_status	__P((struct ifnet *, struct ifmediareq *));
=20
-static device_method_t wi_pccard_methods[] =3D {
-	/* Device interface */
-	DEVMETHOD(device_probe,		pccard_compat_probe),
-	DEVMETHOD(device_attach,	pccard_compat_attach),
-	DEVMETHOD(device_detach,	wi_pccard_detach),
-	DEVMETHOD(device_shutdown,	wi_shutdown),
-
-	/* Card interface */
-	DEVMETHOD(card_compat_match,	wi_pccard_match),
-	DEVMETHOD(card_compat_probe,	wi_pccard_probe),
-	DEVMETHOD(card_compat_attach,	wi_pccard_attach),
-
-	{ 0, 0 }
-};
-
-#if NPCI > 0
-static device_method_t wi_pci_methods[] =3D {
-	/* Device interface */
-	DEVMETHOD(device_probe,		wi_pci_probe),
-	DEVMETHOD(device_attach,	wi_pci_attach),
-	DEVMETHOD(device_detach,	wi_pccard_detach),
-	DEVMETHOD(device_shutdown,	wi_shutdown),
-
-	{ 0, 0 }
-};
-#endif
-
-static driver_t wi_pccard_driver =3D {
-	"wi",
-	wi_pccard_methods,
-	sizeof(struct wi_softc)
-};
-
-#if NPCI > 0
-static driver_t wi_pci_driver =3D {
-	"wi",
-	wi_pci_methods,
-	sizeof(struct wi_softc)
-};
-
-static struct {
-	unsigned int vendor,device;
-	char *desc;
-} pci_ids[] =3D {
-	{0x1638, 0x1100,	"PRISM2STA PCI WaveLAN/IEEE 802.11"},
-	{0x1385, 0x4100,	"Netgear MA301 PCI IEEE 802.11b"},
-	{0,	 0,	NULL}
-};
-#endif
-
-static devclass_t wi_devclass;
-
-DRIVER_MODULE(if_wi, pccard, wi_pccard_driver, wi_devclass, 0, 0);
-#if NPCI > 0
-DRIVER_MODULE(if_wi, pci, wi_pci_driver, wi_devclass, 0, 0);
-#endif
-
-static const struct pccard_product wi_pccard_products[] =3D {
-	{ PCCARD_STR_LUCENT_WAVELAN_IEEE,	PCCARD_VENDOR_LUCENT,
-	  PCCARD_PRODUCT_LUCENT_WAVELAN_IEEE,	0,=20
-	  PCCARD_CIS_LUCENT_WAVELAN_IEEE },
-};
-
-static int wi_pccard_match(dev)
-	device_t	dev;
-{
-	const struct pccard_product *pp;
-
-	if ((pp =3D pccard_product_lookup(dev, wi_pccard_products,
-	    sizeof(wi_pccard_products[0]), NULL)) !=3D NULL) {
-		device_set_desc(dev, pp->pp_name);
-		return 0;
-	}
-	return ENXIO;
-}
-
-static int wi_pccard_probe(dev)
-	device_t	dev;
-{
-	struct wi_softc	*sc;
-	int		error;
+devclass_t wi_devclass;
=20
-	sc =3D device_get_softc(dev);
-	sc->wi_gone =3D 0;
-
-	error =3D wi_alloc(dev, 0);
-	if (error)
-		return (error);
-
-	wi_free(dev);
-
-	/* Make sure interrupts are disabled. */
-	CSR_WRITE_2(sc, WI_INT_EN, 0);
-	CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
-
-	return (0);
-}
-
-#if NPCI > 0
-static int
-wi_pci_probe(dev)
-	device_t	dev;
-{
-	struct wi_softc		*sc;
-	int i;
-
-	sc =3D device_get_softc(dev);
-	for(i=3D0; pci_ids[i].vendor !=3D 0; i++) {
-		if ((pci_get_vendor(dev) =3D=3D pci_ids[i].vendor) &&
-			(pci_get_device(dev) =3D=3D pci_ids[i].device)) {
-			sc->wi_prism2 =3D 1;
-			device_set_desc(dev, pci_ids[i].desc);
-			return (0);
-		}
-	}
-	return(ENXIO);
-}
-#endif
-
-static int wi_pccard_detach(dev)
+int
+wi_detach(dev)
 	device_t		dev;
 {
 	struct wi_softc		*sc;
@@ -324,127 +174,7 @@
 	return(0);
 }
=20
-static int wi_pccard_attach(device_t dev)
-{
-	struct wi_softc		*sc;
-	int			error;
-	u_int32_t		flags;
-
-	sc =3D device_get_softc(dev);
-
-	/*
-	 *	XXX: quick hack to support Prism II chip.
-	 *	Currently, we need to set a flags in pccard.conf to specify
-	 *	which type chip is used.
-	 *
-	 *	We need to replace this code in a future.
-	 *	It is better to use CIS than using a flag.
-	 */
-	flags =3D device_get_flags(dev);
-#define	WI_FLAGS_PRISM2	0x10000
-	if (flags & WI_FLAGS_PRISM2) {
-		sc->wi_prism2 =3D 1;
-		if (bootverbose) {
-			device_printf(dev, "found PrismII chip\n");
-		}
-	}
-	else {
-		sc->wi_prism2 =3D 0;
-		if (bootverbose) {
-			device_printf(dev, "found Lucent chip\n");
-		}
-	}
-
-	error =3D wi_alloc(dev, 0);
-	if (error) {
-		device_printf(dev, "wi_alloc() failed! (%d)\n", error);
-		return (error);
-	}
-	return (wi_generic_attach(dev));
-}
-
-#if NPCI > 0
-static int
-wi_pci_attach(device_t dev)
-{
-	struct wi_softc		*sc;
-	u_int32_t		command, wanted;
-	u_int16_t		reg;
-	int			error;
-
-	sc =3D device_get_softc(dev);
-
-	command =3D pci_read_config(dev, PCIR_COMMAND, 4);
-	wanted =3D PCIM_CMD_PORTEN|PCIM_CMD_MEMEN;
-	command |=3D wanted;
-	pci_write_config(dev, PCIR_COMMAND, command, 4);
-	command =3D pci_read_config(dev, PCIR_COMMAND, 4);
-	if ((command & wanted) !=3D wanted) {
-		device_printf(dev, "wi_pci_attach() failed to enable pci!\n");
-		return (ENXIO);
-	}
-
-	error =3D wi_alloc(dev, WI_PCI_IORES);
-	if (error)
-		return (error);
-
-	/* Make sure interrupts are disabled. */
-	CSR_WRITE_2(sc, WI_INT_EN, 0);
-	CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
-
-	/* We have to do a magic PLX poke to enable interrupts */
-	sc->local_rid =3D WI_PCI_LOCALRES;
-	sc->local =3D bus_alloc_resource(dev, SYS_RES_IOPORT,
-		&sc->local_rid, 0, ~0, 1, RF_ACTIVE);
-	sc->wi_localtag =3D rman_get_bustag(sc->local);
-	sc->wi_localhandle =3D rman_get_bushandle(sc->local);
-	command =3D bus_space_read_4(sc->wi_localtag, sc->wi_localhandle,
-		WI_LOCAL_INTCSR);
-	command |=3D WI_LOCAL_INTEN;
-	bus_space_write_4(sc->wi_localtag, sc->wi_localhandle,
-		WI_LOCAL_INTCSR, command);
-	bus_release_resource(dev, SYS_RES_IOPORT, sc->local_rid, sc->local);
-	sc->local =3D NULL;
-
-	sc->mem_rid =3D WI_PCI_MEMRES;
-	sc->mem =3D bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
-				0, ~0, 1, RF_ACTIVE);
-	if (sc->mem =3D=3D NULL) {
-		device_printf(dev, "couldn't allocate memory\n");
-		wi_free(dev);
-		return (ENXIO);
-	}
-	sc->wi_bmemtag =3D rman_get_bustag(sc->mem);
-	sc->wi_bmemhandle =3D rman_get_bushandle(sc->mem);
-
-	/*
-	 * From Linux driver:
-	 * Write COR to enable PC card
-	 * This is a subset of the protocol that the pccard bus code
-	 * would do.
-	 */
-	CSM_WRITE_1(sc, WI_COR_OFFSET, WI_COR_VALUE);=20
-	reg =3D CSM_READ_1(sc, WI_COR_OFFSET);
-
-	CSR_WRITE_2(sc, WI_HFA384X_SWSUPPORT0_OFF, WI_PRISM2STA_MAGIC);
-	reg =3D CSR_READ_2(sc, WI_HFA384X_SWSUPPORT0_OFF);
-	if (reg !=3D WI_PRISM2STA_MAGIC) {
-		device_printf(dev,
-		    "CSR_READ_2(WI_HFA384X_SWSUPPORT0_OFF) "
-		    "wanted %d, got %d\n", WI_PRISM2STA_MAGIC, reg);
-		wi_free(dev);
-		return (ENXIO);
-	}
-
-	error =3D wi_generic_attach(dev);
-	if (error !=3D 0)
-		return (error);
-
-	return (0);
-}
-#endif
-
-static int
+int
 wi_generic_attach(device_t dev)
 {
 	struct wi_softc		*sc;
@@ -1968,7 +1698,7 @@
 	return;
 }
=20
-static int
+int
 wi_alloc(dev, io_rid)
 	device_t		dev;
 	int				io_rid;
@@ -2002,7 +1732,8 @@
 	return (0);
 }
=20
-static void wi_free(dev)
+void
+wi_free(dev)
 	device_t		dev;
 {
 	struct wi_softc		*sc =3D device_get_softc(dev);
@@ -2023,7 +1754,8 @@
 	return;
 }
=20
-static void wi_shutdown(dev)
+void
+wi_shutdown(dev)
 	device_t		dev;
 {
 	struct wi_softc		*sc;
Index: sys/dev/wi/if_wireg.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/cvs/src/sys/dev/wi/if_wireg.h,v
retrieving revision 1.16
diff -u -r1.16 if_wireg.h
--- sys/dev/wi/if_wireg.h	24 Aug 2001 02:14:26 -0000	1.16
+++ sys/dev/wi/if_wireg.h	28 Sep 2001 00:24:56 -0000
@@ -675,3 +675,11 @@
 #define WI_SNAP_WORD0		(WI_SNAP_K1 | (WI_SNAP_K1 << 8))
 #define WI_SNAP_WORD1		(WI_SNAP_K2 | (WI_SNAP_CONTROL << 8))
 #define WI_SNAPHDR_LEN		0x6
+
+int wi_generic_attach		__P((device_t));
+int wi_detach			__P((device_t));
+void wi_shutdown		__P((device_t));
+int wi_alloc			__P((device_t, int));
+void wi_free			__P((device_t));
+
+extern devclass_t wi_devclass;
Index: sys/modules/wi/Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/cvs/src/sys/modules/wi/Makefile,v
retrieving revision 1.11
diff -u -r1.11 Makefile
--- sys/modules/wi/Makefile	28 Aug 2001 05:28:40 -0000	1.11
+++ sys/modules/wi/Makefile	27 Sep 2001 22:34:12 -0000
@@ -3,9 +3,7 @@
 .PATH: ${.CURDIR}/../../dev/wi
=20
 KMOD=3D	if_wi
-SRCS=3D	if_wi.c card_if.h device_if.h bus_if.h pci_if.h pci.h
-
-pci.h:
-	echo "#define NPCI 1" > $@
+SRCS=3D	if_wi.c if_wi_pccard.c if_wi_pci.c \
+	card_if.h device_if.h bus_if.h pci_if.h
=20
 .include <bsd.kmod.mk>
--- sys/dev/wi/if_wi_pccard.c.orig	Thu Sep 27 16:40:05 2001
+++ sys/dev/wi/if_wi_pccard.c	Thu Sep 27 16:19:50 2001
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 1997, 1998, 1999
+ *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for FreeBSD.
+ *
+ * Written by Bill Paul <wpaul@ctr.columbia.edu>
+ * Electrical Engineering Department
+ * Columbia University, New York City
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/bus.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <net/if_media.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <dev/pccard/pccardvar.h>
+#include <dev/pccard/pccarddevs.h>
+
+#include <dev/wi/if_wireg.h>
+
+#if !defined(lint)
+static const char rcsid[] =3D
+  "$FreeBSD$";
+#endif
+
+static int wi_pccard_match	__P((device_t));
+static int wi_pccard_probe	__P((device_t));
+static int wi_pccard_attach	__P((device_t));
+
+static device_method_t wi_pccard_methods[] =3D {
+	/* Device interface */
+	DEVMETHOD(device_probe,		pccard_compat_probe),
+	DEVMETHOD(device_attach,	pccard_compat_attach),
+	DEVMETHOD(device_detach,	wi_detach),
+	DEVMETHOD(device_shutdown,	wi_shutdown),
+
+	/* Card interface */
+	DEVMETHOD(card_compat_match,	wi_pccard_match),
+	DEVMETHOD(card_compat_probe,	wi_pccard_probe),
+	DEVMETHOD(card_compat_attach,	wi_pccard_attach),
+
+	{ 0, 0 }
+};
+
+static driver_t wi_pccard_driver =3D {
+	"wi",
+	wi_pccard_methods,
+	sizeof(struct wi_softc)
+};
+
+DRIVER_MODULE(if_wi, pccard, wi_pccard_driver, wi_devclass, 0, 0);
+
+static const struct pccard_product wi_pccard_products[] =3D {
+	{ PCCARD_STR_LUCENT_WAVELAN_IEEE,	PCCARD_VENDOR_LUCENT,
+	  PCCARD_PRODUCT_LUCENT_WAVELAN_IEEE,	0,=20
+	  PCCARD_CIS_LUCENT_WAVELAN_IEEE },
+};
+
+static int wi_pccard_match(dev)
+	device_t	dev;
+{
+	const struct pccard_product *pp;
+
+	if ((pp =3D pccard_product_lookup(dev, wi_pccard_products,
+	    sizeof(wi_pccard_products[0]), NULL)) !=3D NULL) {
+		device_set_desc(dev, pp->pp_name);
+		return 0;
+	}
+	return ENXIO;
+}
+
+static int wi_pccard_probe(dev)
+	device_t	dev;
+{
+	struct wi_softc	*sc;
+	int		error;
+
+	sc =3D device_get_softc(dev);
+	sc->wi_gone =3D 0;
+
+	error =3D wi_alloc(dev, 0);
+	if (error)
+		return (error);
+
+	wi_free(dev);
+
+	/* Make sure interrupts are disabled. */
+	CSR_WRITE_2(sc, WI_INT_EN, 0);
+	CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
+
+	return (0);
+}
+
+static int wi_pccard_attach(device_t dev)
+{
+	struct wi_softc		*sc;
+	int			error;
+	u_int32_t		flags;
+
+	sc =3D device_get_softc(dev);
+
+	/*
+	 *	XXX: quick hack to support Prism II chip.
+	 *	Currently, we need to set a flags in pccard.conf to specify
+	 *	which type chip is used.
+	 *
+	 *	We need to replace this code in a future.
+	 *	It is better to use CIS than using a flag.
+	 */
+	flags =3D device_get_flags(dev);
+#define	WI_FLAGS_PRISM2	0x10000
+	if (flags & WI_FLAGS_PRISM2) {
+		sc->wi_prism2 =3D 1;
+		if (bootverbose) {
+			device_printf(dev, "found PrismII chip\n");
+		}
+	}
+	else {
+		sc->wi_prism2 =3D 0;
+		if (bootverbose) {
+			device_printf(dev, "found Lucent chip\n");
+		}
+	}
+
+	error =3D wi_alloc(dev, 0);
+	if (error) {
+		device_printf(dev, "wi_alloc() failed! (%d)\n", error);
+		return (error);
+	}
+	return (wi_generic_attach(dev));
+}
--- sys/dev/wi/if_wi_pci.c.orig	Thu Sep 27 16:40:02 2001
+++ sys/dev/wi/if_wi_pci.c	Thu Sep 27 16:22:58 2001
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 1997, 1998, 1999
+ *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for FreeBSD.
+ *
+ * Written by Bill Paul <wpaul@ctr.columbia.edu>
+ * Electrical Engineering Department
+ * Columbia University, New York City
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/bus.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#include <pci/pcireg.h>
+#include <pci/pcivar.h>
+
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <net/if_media.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <dev/wi/if_wireg.h>
+
+#if !defined(lint)
+static const char rcsid[] =3D
+  "$FreeBSD$";
+#endif
+
+static int wi_pci_probe		__P((device_t));
+static int wi_pci_attach	__P((device_t));
+
+static device_method_t wi_pci_methods[] =3D {
+	/* Device interface */
+	DEVMETHOD(device_probe,		wi_pci_probe),
+	DEVMETHOD(device_attach,	wi_pci_attach),
+	DEVMETHOD(device_detach,	wi_detach),
+	DEVMETHOD(device_shutdown,	wi_shutdown),
+
+	{ 0, 0 }
+};
+
+static driver_t wi_pci_driver =3D {
+	"wi",
+	wi_pci_methods,
+	sizeof(struct wi_softc)
+};
+
+static struct {
+	unsigned int vendor,device;
+	char *desc;
+} pci_ids[] =3D {
+	{0x1638, 0x1100,	"PRISM2STA PCI WaveLAN/IEEE 802.11"},
+	{0x1385, 0x4100,	"Netgear MA301 PCI IEEE 802.11b"},
+	{0,	 0,	NULL}
+};
+
+DRIVER_MODULE(if_wi, pci, wi_pci_driver, wi_devclass, 0, 0);
+
+static int
+wi_pci_probe(dev)
+	device_t	dev;
+{
+	struct wi_softc		*sc;
+	int i;
+
+	sc =3D device_get_softc(dev);
+	for(i=3D0; pci_ids[i].vendor !=3D 0; i++) {
+		if ((pci_get_vendor(dev) =3D=3D pci_ids[i].vendor) &&
+			(pci_get_device(dev) =3D=3D pci_ids[i].device)) {
+			sc->wi_prism2 =3D 1;
+			device_set_desc(dev, pci_ids[i].desc);
+			return (0);
+		}
+	}
+	return(ENXIO);
+}
+
+static int
+wi_pci_attach(device_t dev)
+{
+	struct wi_softc		*sc;
+	u_int32_t		command, wanted;
+	u_int16_t		reg;
+	int			error;
+
+	sc =3D device_get_softc(dev);
+
+	command =3D pci_read_config(dev, PCIR_COMMAND, 4);
+	wanted =3D PCIM_CMD_PORTEN|PCIM_CMD_MEMEN;
+	command |=3D wanted;
+	pci_write_config(dev, PCIR_COMMAND, command, 4);
+	command =3D pci_read_config(dev, PCIR_COMMAND, 4);
+	if ((command & wanted) !=3D wanted) {
+		device_printf(dev, "wi_pci_attach() failed to enable pci!\n");
+		return (ENXIO);
+	}
+
+	error =3D wi_alloc(dev, WI_PCI_IORES);
+	if (error)
+		return (error);
+
+	/* Make sure interrupts are disabled. */
+	CSR_WRITE_2(sc, WI_INT_EN, 0);
+	CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
+
+	/* We have to do a magic PLX poke to enable interrupts */
+	sc->local_rid =3D WI_PCI_LOCALRES;
+	sc->local =3D bus_alloc_resource(dev, SYS_RES_IOPORT,
+		&sc->local_rid, 0, ~0, 1, RF_ACTIVE);
+	sc->wi_localtag =3D rman_get_bustag(sc->local);
+	sc->wi_localhandle =3D rman_get_bushandle(sc->local);
+	command =3D bus_space_read_4(sc->wi_localtag, sc->wi_localhandle,
+		WI_LOCAL_INTCSR);
+	command |=3D WI_LOCAL_INTEN;
+	bus_space_write_4(sc->wi_localtag, sc->wi_localhandle,
+		WI_LOCAL_INTCSR, command);
+	bus_release_resource(dev, SYS_RES_IOPORT, sc->local_rid, sc->local);
+	sc->local =3D NULL;
+
+	sc->mem_rid =3D WI_PCI_MEMRES;
+	sc->mem =3D bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
+				0, ~0, 1, RF_ACTIVE);
+	if (sc->mem =3D=3D NULL) {
+		device_printf(dev, "couldn't allocate memory\n");
+		wi_free(dev);
+		return (ENXIO);
+	}
+	sc->wi_bmemtag =3D rman_get_bustag(sc->mem);
+	sc->wi_bmemhandle =3D rman_get_bushandle(sc->mem);
+
+	/*
+	 * From Linux driver:
+	 * Write COR to enable PC card
+	 * This is a subset of the protocol that the pccard bus code
+	 * would do.
+	 */
+	CSM_WRITE_1(sc, WI_COR_OFFSET, WI_COR_VALUE);=20
+	reg =3D CSM_READ_1(sc, WI_COR_OFFSET);
+
+	CSR_WRITE_2(sc, WI_HFA384X_SWSUPPORT0_OFF, WI_PRISM2STA_MAGIC);
+	reg =3D CSR_READ_2(sc, WI_HFA384X_SWSUPPORT0_OFF);
+	if (reg !=3D WI_PRISM2STA_MAGIC) {
+		device_printf(dev,
+		    "CSR_READ_2(WI_HFA384X_SWSUPPORT0_OFF) "
+		    "wanted %d, got %d\n", WI_PRISM2STA_MAGIC, reg);
+		wi_free(dev);
+		return (ENXIO);
+	}
+
+	error =3D wi_generic_attach(dev);
+	if (error !=3D 0)
+		return (error);
+
+	return (0);
+}

--=20
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4

--jI8keyz6grp/JLjh
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7s9R5XY6L6fI4GtQRAsbKAKCUefITfjJ7c6UAXjKIyMoTuj2R7gCfT78I
ITY6usXcZHnt7ArBTCgqJbU=
=eqlr
-----END PGP SIGNATURE-----

--jI8keyz6grp/JLjh--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




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