if_pflog.c:1.14 if_pfsync.c:1.21 if_an.c:1.70 if_ar.c:1.72 if_arl.c:1.11 amrr.c:1.10 onoe.c:1.10 if_ath.c:1.101 awi.c:1.41 if_bfe.c:1.27 if_bge.c:1.93 if_cm_isa.c:1.7 smc90cx6.c:1.16 if_cnw.c:1.20 if_cp.c:1.25 if_cs.c:1.42 if_ct.c:1.26 if_cx.c:1.46 if_ed.c:1.256 if_em.c:1.68 if_en_pci.c:1.37 midway.c:1.66 if_ep.c:1.143 if_ex.c:1.58 if_fatm.c:1.20 if_fe.c:1.93 if_fwe.c:1.38 if_fwip.c:1.8 if_fxp.c:1.244 if_gem.c:1.33 if_hatm.c:1.25 if_hatm_intr.c:1.20 if_hatm_ioctl.c:1.13 if_hatm_rx.c:1.10 if_hatm_tx.c:1.14 if_hme.c:1.39 if_ie.c:1.104 if_ndis.c:1.101 if_ic.c:1.24 if_ipw.c:1.10 if_iwi.c:1.10 if_ixgb.c:1.13 if_lge.c:1.41 if_lnc.c:1.113 if_my.c:1.31 if_nge.c:1.77 if_nve.c:1.10 if_owi.c:1.12 if_patm.c:1.9 if_patm_intr.c:1.6 if_patm_ioctl.c:1.10 if_patm_tx.c:1.10 pdq_ifsubr.c:1.28 if_plip.c:1.38 if_ral.c:1.12 if_ral_pci.c:1.2 if_ray.c:1.81 if_rayvar.h:1.22 if_re.c:1.49 if_sbni.c:1.21 if_sbsh.c:1.14 if_sn.c:1.48 dp83932.c:1.21 if_snc_pccard.c:1.9 if_sr.c:1.70 if_tx.c:1.91 if_txp.c:1.33 if_aue.c:1.92 if_axe.c:1.32 if_cdce.c:1.8 if_cue.c:1.59 if_kue.c:1.66 if_rue.c:1.23 if_udav.c:1.16 if_ural.c:1.12 if_vge.c:1.16 if_vx.c:1.58 if_wi.c:1.185 if_wi_pci.c:1.26 if_wl.c:1.68 if_xe.c:1.60 if_xe_pccard.c:1.30 if_el.c:1.68 i4b_ipr.c:1.35 i4b_isppp.c:1.31 kern_poll.c:1.20 bridge.c:1.94 bridgestp.c:1.4 if_arcsubr.c:1.27 if_atm.h:1.24 if_atmsubr.c:1.40 if_bridge.c:1.16 if_ef.c:1.35 if_ethersubr.c:1.196 if_faith.c:1.37 if_fddisubr.c:1.100 if_fwsubr.c:1.14 if_gif.c:1.54 if_gre.c:1.34 if_iso88025subr.c:1.70 if_loop.c:1.107 if_ppp.c:1.106 if_spppsubr.c:1.121 if_tap.c:1.57 if_tun.c:1.154 if_vlan.c:1.80 ppp_tty.c:1.67 ieee80211_ioctl.c:1.32 atm_if.c:1.31 ng_eiface.c:1.33 ng_ether.c:1.50 ng_fec.c:1.19 ng_iface.c:1.44 ng_sppp.c:1.9 ip_carp.c:1.30 ip_fastfwd.c:1.30 in6.c:1.53 nd6_nbr.c:1.31 natm.c:1.40 if_dc.c:1.162 if_de.c:1.168 if_pcn.c:1.72 if_rl.c:1.154 if_sf.c:1.84 if_sis.c:1.135 if_sk.c:1.108 if_ste.c:1.86 if_ti.c:1.109 if_tl.c:1.101 if_vr.c:1.106 if_wb.c:1.81 if_xl.c:1.194 from HEAD to RELENG_6: Propagate rename of IFF_OACTIVE and IFF_RUNNING to IFF_DRV_OACTIVE and IFF_DRV_RUNNING, as well as the move from ifnet.if_flags to ifnet.if_drv_flags. Device drivers are now responsible for synchronizing access to these flags, as they are in if_drv_flags. This helps prevent races between the network stack and device driver in maintaining the interface flags field. Many __FreeBSD__ and __FreeBSD_version checks maintained and continued; some less so. Reviewed by: pjd, bz Approved by: re (scottl)
276 lines
7.7 KiB
C
276 lines
7.7 KiB
C
/*-
|
|
* 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 PURPOSE
|
|
* 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.
|
|
*
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
/*
|
|
* 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/systm.h>
|
|
#include <sys/module.h>
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
#include <machine/resource.h>
|
|
#include <machine/clock.h>
|
|
#include <sys/rman.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <net/if.h>
|
|
#include <net/if_arp.h>
|
|
#include <net/ethernet.h>
|
|
#include <net/if_media.h>
|
|
#include <net/if_types.h>
|
|
|
|
#include <net80211/ieee80211_var.h>
|
|
#include <net80211/ieee80211_radiotap.h>
|
|
|
|
#include <dev/wi/if_wavelan_ieee.h>
|
|
#include <dev/wi/if_wireg.h>
|
|
#include <dev/wi/if_wivar.h>
|
|
|
|
static int wi_pci_probe(device_t);
|
|
static int wi_pci_attach(device_t);
|
|
static int wi_pci_suspend(device_t);
|
|
static int wi_pci_resume(device_t);
|
|
|
|
static device_method_t wi_pci_methods[] = {
|
|
/* Device interface */
|
|
DEVMETHOD(device_probe, wi_pci_probe),
|
|
DEVMETHOD(device_attach, wi_pci_attach),
|
|
DEVMETHOD(device_detach, wi_detach),
|
|
DEVMETHOD(device_shutdown, wi_shutdown),
|
|
DEVMETHOD(device_suspend, wi_pci_suspend),
|
|
DEVMETHOD(device_resume, wi_pci_resume),
|
|
|
|
{ 0, 0 }
|
|
};
|
|
|
|
static driver_t wi_pci_driver = {
|
|
"wi",
|
|
wi_pci_methods,
|
|
sizeof(struct wi_softc)
|
|
};
|
|
|
|
static struct {
|
|
unsigned int vendor,device;
|
|
int bus_type;
|
|
char *desc;
|
|
} pci_ids[] = {
|
|
/* Sorted by description */
|
|
{0x10b7, 0x7770, WI_BUS_PCI_PLX, "3Com Airconnect"},
|
|
{0x16ab, 0x1101, WI_BUS_PCI_PLX, "GLPRISM2 WaveLAN"},
|
|
{0x1260, 0x3872, WI_BUS_PCI_NATIVE, "Intersil Prism3"},
|
|
{0x1260, 0x3873, WI_BUS_PCI_NATIVE, "Intersil Prism2.5"},
|
|
{0x16ab, 0x1102, WI_BUS_PCI_PLX, "Linksys WDT11"},
|
|
{0x1385, 0x4100, WI_BUS_PCI_PLX, "Netgear MA301"},
|
|
{0x1638, 0x1100, WI_BUS_PCI_PLX, "PRISM2STA WaveLAN"},
|
|
{0x111a, 0x1023, WI_BUS_PCI_PLX, "Siemens SpeedStream"},
|
|
{0x10b5, 0x9050, WI_BUS_PCI_PLX, "SMC 2602W"},
|
|
{0x16ec, 0x3685, WI_BUS_PCI_PLX, "US Robotics 2415"},
|
|
{0x4033, 0x7001, WI_BUS_PCI_PLX, "Addtron AWA-100 PCI"},
|
|
{0, 0, 0, NULL}
|
|
};
|
|
|
|
DRIVER_MODULE(wi, pci, wi_pci_driver, wi_devclass, 0, 0);
|
|
MODULE_DEPEND(wi, pci, 1, 1, 1);
|
|
MODULE_DEPEND(wi, wlan, 1, 1, 1);
|
|
|
|
static int
|
|
wi_pci_probe(dev)
|
|
device_t dev;
|
|
{
|
|
struct wi_softc *sc;
|
|
int i;
|
|
|
|
sc = device_get_softc(dev);
|
|
for(i=0; pci_ids[i].vendor != 0; i++) {
|
|
if ((pci_get_vendor(dev) == pci_ids[i].vendor) &&
|
|
(pci_get_device(dev) == pci_ids[i].device)) {
|
|
sc->wi_bus_type = pci_ids[i].bus_type;
|
|
device_set_desc(dev, pci_ids[i].desc);
|
|
return (BUS_PROBE_DEFAULT);
|
|
}
|
|
}
|
|
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;
|
|
int timeout;
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
command = pci_read_config(dev, PCIR_COMMAND, 4);
|
|
wanted = PCIM_CMD_PORTEN|PCIM_CMD_MEMEN;
|
|
command |= wanted;
|
|
pci_write_config(dev, PCIR_COMMAND, command, 4);
|
|
command = pci_read_config(dev, PCIR_COMMAND, 4);
|
|
if ((command & wanted) != wanted) {
|
|
device_printf(dev, "wi_pci_attach() failed to enable pci!\n");
|
|
return (ENXIO);
|
|
}
|
|
|
|
if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) {
|
|
error = 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 = WI_PCI_LOCALRES;
|
|
sc->local = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
|
|
&sc->local_rid, RF_ACTIVE);
|
|
sc->wi_localtag = rman_get_bustag(sc->local);
|
|
sc->wi_localhandle = rman_get_bushandle(sc->local);
|
|
command = bus_space_read_4(sc->wi_localtag, sc->wi_localhandle,
|
|
WI_LOCAL_INTCSR);
|
|
command |= 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 = NULL;
|
|
|
|
sc->mem_rid = WI_PCI_MEMRES;
|
|
sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
&sc->mem_rid, RF_ACTIVE);
|
|
if (sc->mem == NULL) {
|
|
device_printf(dev, "couldn't allocate memory\n");
|
|
wi_free(dev);
|
|
return (ENXIO);
|
|
}
|
|
sc->wi_bmemtag = rman_get_bustag(sc->mem);
|
|
sc->wi_bmemhandle = 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);
|
|
reg = CSM_READ_1(sc, WI_COR_OFFSET);
|
|
if (reg != WI_COR_VALUE) {
|
|
device_printf(dev, "CSM_READ_1(WI_COR_OFFSET) "
|
|
"wanted %d, got %d\n", WI_COR_VALUE, reg);
|
|
wi_free(dev);
|
|
return (ENXIO);
|
|
}
|
|
} else {
|
|
error = wi_alloc(dev, WI_PCI_LMEMRES);
|
|
if (error)
|
|
return (error);
|
|
|
|
CSR_WRITE_2(sc, WI_HFA384X_PCICOR_OFF, 0x0080);
|
|
DELAY(250000);
|
|
|
|
CSR_WRITE_2(sc, WI_HFA384X_PCICOR_OFF, 0x0000);
|
|
DELAY(500000);
|
|
|
|
timeout=2000000;
|
|
while ((--timeout > 0) &&
|
|
(CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY))
|
|
DELAY(10);
|
|
|
|
if (timeout == 0) {
|
|
device_printf(dev, "couldn't reset prism2.5 core.\n");
|
|
wi_free(dev);
|
|
return(ENXIO);
|
|
}
|
|
}
|
|
|
|
CSR_WRITE_2(sc, WI_HFA384X_SWSUPPORT0_OFF, WI_PRISM2STA_MAGIC);
|
|
reg = CSR_READ_2(sc, WI_HFA384X_SWSUPPORT0_OFF);
|
|
if (reg != 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 = wi_attach(dev);
|
|
if (error != 0)
|
|
wi_free(dev);
|
|
return (error);
|
|
}
|
|
|
|
static int
|
|
wi_pci_suspend(device_t dev)
|
|
{
|
|
struct wi_softc *sc = device_get_softc(dev);
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
struct ifnet *ifp = ic->ic_ifp;
|
|
|
|
wi_stop(ifp, 1);
|
|
|
|
return (0);
|
|
}
|
|
|
|
static int
|
|
wi_pci_resume(device_t dev)
|
|
{
|
|
struct wi_softc *sc = device_get_softc(dev);
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
struct ifnet *ifp = ic->ic_ifp;
|
|
|
|
if (sc->wi_bus_type != WI_BUS_PCI_NATIVE)
|
|
return (0);
|
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
ifp->if_init(ifp->if_softc);
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
|
ifp->if_start(ifp);
|
|
}
|
|
|
|
return (0);
|
|
}
|