if_vx_pci.c revision 127135
1252867Sdelphij/* 2252867Sdelphij * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp> 3252867Sdelphij * All rights reserved. 4252867Sdelphij * 5252867Sdelphij * Redistribution and use in source and binary forms, with or without 6252867Sdelphij * modification, are permitted provided that the following conditions 7252867Sdelphij * are met: 8252867Sdelphij * 1. Redistributions of source code must retain the above copyright 9252867Sdelphij * notice, this list of conditions and the following disclaimer. 10252867Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 11252867Sdelphij * notice, this list of conditions and the following disclaimer in the 12252867Sdelphij * documentation and/or other materials provided with the distribution. 13252867Sdelphij * 3. Neither the name of the author nor the names of any co-contributors 14252867Sdelphij * may be used to endorse or promote products derived from this software 15252867Sdelphij * without specific prior written permission. 16252867Sdelphij * 17252867Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18252867Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19252867Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20252867Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21252867Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22252867Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23252867Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24252867Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25252867Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26252867Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27252867Sdelphij * SUCH DAMAGE. 28252867Sdelphij */ 29252867Sdelphij 30252867Sdelphij#include <sys/cdefs.h> 31252867Sdelphij__FBSDID("$FreeBSD: head/sys/dev/vx/if_vx_pci.c 127135 2004-03-17 17:50:55Z njl $"); 32252867Sdelphij 33252867Sdelphij#include <sys/param.h> 34252867Sdelphij#include <sys/systm.h> 35252867Sdelphij#include <sys/kernel.h> 36252867Sdelphij#include <sys/socket.h> 37252867Sdelphij 38252867Sdelphij#include <net/if.h> 39252867Sdelphij#include <net/if_arp.h> 40252867Sdelphij 41252867Sdelphij#include <machine/bus_pio.h> 42252867Sdelphij#include <machine/bus.h> 43252867Sdelphij#include <machine/resource.h> 44252867Sdelphij#include <sys/bus.h> 45252867Sdelphij#include <sys/rman.h> 46252867Sdelphij 47252867Sdelphij#include <dev/pci/pcivar.h> 48252867Sdelphij#include <dev/pci/pcireg.h> 49252867Sdelphij 50252867Sdelphij#include <dev/vx/if_vxreg.h> 51252867Sdelphij#include <dev/vx/if_vxvar.h> 52252867Sdelphij 53252867Sdelphijstatic void vx_pci_shutdown(device_t); 54252867Sdelphijstatic int vx_pci_probe(device_t); 55252867Sdelphijstatic int vx_pci_attach(device_t); 56252867Sdelphij 57252867Sdelphijstatic device_method_t vx_methods[] = { 58252867Sdelphij /* Device interface */ 59252867Sdelphij DEVMETHOD(device_probe, vx_pci_probe), 60252867Sdelphij DEVMETHOD(device_attach, vx_pci_attach), 61252867Sdelphij DEVMETHOD(device_shutdown, vx_pci_shutdown), 62252867Sdelphij 63252867Sdelphij { 0, 0 } 64252867Sdelphij}; 65252867Sdelphij 66252867Sdelphijstatic driver_t vx_driver = { 67252867Sdelphij "vx", 68252867Sdelphij vx_methods, 69252867Sdelphij sizeof(struct vx_softc) 70252867Sdelphij}; 71252867Sdelphij 72252867Sdelphijstatic devclass_t vx_devclass; 73252867Sdelphij 74252867SdelphijDRIVER_MODULE(vx, pci, vx_driver, vx_devclass, 0, 0); 75252867SdelphijMODULE_DEPEND(vx, pci, 1, 1, 1); 76252867SdelphijMODULE_DEPEND(vx, ether, 1, 1, 1); 77252867Sdelphij 78252867Sdelphijstatic void 79252867Sdelphijvx_pci_shutdown( 80252867Sdelphij device_t dev) 81252867Sdelphij{ 82252867Sdelphij struct vx_softc *sc; 83252867Sdelphij 84252867Sdelphij sc = device_get_softc(dev); 85252867Sdelphij vxstop(sc); 86252867Sdelphij return; 87252867Sdelphij} 88252867Sdelphij 89252867Sdelphijstatic int 90252867Sdelphijvx_pci_probe( 91252867Sdelphij device_t dev) 92252867Sdelphij{ 93252867Sdelphij u_int32_t device_id; 94252867Sdelphij 95252867Sdelphij device_id = pci_read_config(dev, PCIR_DEVVENDOR, 4); 96252867Sdelphij 97252867Sdelphij if(device_id == 0x590010b7ul) { 98252867Sdelphij device_set_desc(dev, "3COM 3C590 Etherlink III PCI"); 99252867Sdelphij return(0); 100252867Sdelphij } 101252867Sdelphij if(device_id == 0x595010b7ul || device_id == 0x595110b7ul || 102252867Sdelphij device_id == 0x595210b7ul) { 103252867Sdelphij device_set_desc(dev, "3COM 3C595 Etherlink III PCI"); 104252867Sdelphij return(0); 105252867Sdelphij } 106252867Sdelphij /* 107252867Sdelphij * The (Fast) Etherlink XL adapters are now supported by 108252867Sdelphij * the xl driver, which uses bus master DMA and is much 109252867Sdelphij * faster. (And which also supports the 3c905B. 110252867Sdelphij */ 111252867Sdelphij#ifdef VORTEX_ETHERLINK_XL 112252867Sdelphij if(device_id == 0x900010b7ul || device_id == 0x900110b7ul) { 113252867Sdelphij device_set_desc(dev, "3COM 3C900 Etherlink XL PCI"); 114252867Sdelphij return(0); 115252867Sdelphij } 116252867Sdelphij if(device_id == 0x905010b7ul || device_id == 0x905110b7ul) { 117252867Sdelphij device_set_desc(dev, "3COM 3C905 Etherlink XL PCI"); 118252867Sdelphij return(0); 119252867Sdelphij } 120252867Sdelphij#endif 121252867Sdelphij return (ENXIO); 122252867Sdelphij} 123252867Sdelphij 124252867Sdelphijstatic int 125252867Sdelphijvx_pci_attach( 126252867Sdelphij device_t dev) 127252867Sdelphij{ 128252867Sdelphij struct vx_softc *sc; 129252867Sdelphij int rid; 130252867Sdelphij 131252867Sdelphij sc = device_get_softc(dev); 132252867Sdelphij 133252867Sdelphij rid = PCIR_BAR(0); 134252867Sdelphij sc->vx_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); 135252867Sdelphij 136252867Sdelphij if (sc->vx_res == NULL) 137252867Sdelphij goto bad; 138252867Sdelphij 139252867Sdelphij sc->bst = rman_get_bustag(sc->vx_res); 140252867Sdelphij sc->bsh = rman_get_bushandle(sc->vx_res); 141252867Sdelphij 142252867Sdelphij rid = 0; 143252867Sdelphij sc->vx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 144252867Sdelphij RF_SHAREABLE | RF_ACTIVE); 145252867Sdelphij 146252867Sdelphij if (sc->vx_irq == NULL) 147252867Sdelphij goto bad; 148252867Sdelphij 149252867Sdelphij if (bus_setup_intr(dev, sc->vx_irq, INTR_TYPE_NET, 150252867Sdelphij vxintr, sc, &sc->vx_intrhand)) 151252867Sdelphij goto bad; 152252867Sdelphij 153252867Sdelphij if (vxattach(dev) == 0) { 154252867Sdelphij goto bad; 155252867Sdelphij } 156284792Sdelphij 157252867Sdelphij /* defect check for 3C590 */ 158284792Sdelphij if ((pci_read_config(dev, PCIR_DEVVENDOR, 4) >> 16) == 0x5900) { 159284792Sdelphij GO_WINDOW(0); 160252867Sdelphij if (vxbusyeeprom(sc)) 161252867Sdelphij goto bad; 162252867Sdelphij CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND, 163252867Sdelphij EEPROM_CMD_RD | EEPROM_SOFTINFO2); 164252867Sdelphij if (vxbusyeeprom(sc)) 165252867Sdelphij goto bad; 166252867Sdelphij if (!(CSR_READ_2(sc, VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY)) { 167252867Sdelphij printf("Warning! Defective early revision adapter!\n"); 168252867Sdelphij } 169252867Sdelphij } 170252867Sdelphij 171252867Sdelphij return(0); 172252867Sdelphij 173252867Sdelphijbad: 174252867Sdelphij if (sc->vx_intrhand != NULL) 175252867Sdelphij bus_teardown_intr(dev, sc->vx_irq, sc->vx_intrhand); 176252867Sdelphij if (sc->vx_res != NULL) 177252867Sdelphij bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->vx_res); 178252867Sdelphij if (sc->vx_irq != NULL) 179252867Sdelphij bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vx_irq); 180252867Sdelphij return(ENXIO); 181252867Sdelphij} 182252867Sdelphij