if_vx_pci.c revision 127135
1/*
2 * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/vx/if_vx_pci.c 127135 2004-03-17 17:50:55Z njl $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/socket.h>
37
38#include <net/if.h>
39#include <net/if_arp.h>
40
41#include <machine/bus_pio.h>
42#include <machine/bus.h>
43#include <machine/resource.h>
44#include <sys/bus.h>
45#include <sys/rman.h>
46
47#include <dev/pci/pcivar.h>
48#include <dev/pci/pcireg.h>
49
50#include <dev/vx/if_vxreg.h>
51#include <dev/vx/if_vxvar.h>
52
53static void vx_pci_shutdown(device_t);
54static int vx_pci_probe(device_t);
55static int vx_pci_attach(device_t);
56
57static device_method_t vx_methods[] = {
58	/* Device interface */
59	DEVMETHOD(device_probe,		vx_pci_probe),
60	DEVMETHOD(device_attach,	vx_pci_attach),
61	DEVMETHOD(device_shutdown,	vx_pci_shutdown),
62
63	{ 0, 0 }
64};
65
66static driver_t vx_driver = {
67	"vx",
68	vx_methods,
69	sizeof(struct vx_softc)
70};
71
72static devclass_t vx_devclass;
73
74DRIVER_MODULE(vx, pci, vx_driver, vx_devclass, 0, 0);
75MODULE_DEPEND(vx, pci, 1, 1, 1);
76MODULE_DEPEND(vx, ether, 1, 1, 1);
77
78static void
79vx_pci_shutdown(
80	device_t dev)
81{
82   struct vx_softc	*sc;
83
84   sc = device_get_softc(dev);
85   vxstop(sc);
86   return;
87}
88
89static int
90vx_pci_probe(
91	device_t dev)
92{
93   u_int32_t		device_id;
94
95   device_id = pci_read_config(dev, PCIR_DEVVENDOR, 4);
96
97   if(device_id == 0x590010b7ul) {
98      device_set_desc(dev, "3COM 3C590 Etherlink III PCI");
99      return(0);
100   }
101   if(device_id == 0x595010b7ul || device_id == 0x595110b7ul ||
102	device_id == 0x595210b7ul) {
103      device_set_desc(dev, "3COM 3C595 Etherlink III PCI");
104      return(0);
105   }
106	/*
107	 * The (Fast) Etherlink XL adapters are now supported by
108	 * the xl driver, which uses bus master DMA and is much
109	 * faster. (And which also supports the 3c905B.
110	 */
111#ifdef VORTEX_ETHERLINK_XL
112   if(device_id == 0x900010b7ul || device_id == 0x900110b7ul) {
113      device_set_desc(dev, "3COM 3C900 Etherlink XL PCI");
114      return(0);
115   }
116   if(device_id == 0x905010b7ul || device_id == 0x905110b7ul) {
117      device_set_desc(dev, "3COM 3C905 Etherlink XL PCI");
118      return(0);
119   }
120#endif
121   return (ENXIO);
122}
123
124static int
125vx_pci_attach(
126	device_t dev)
127{
128    struct vx_softc *sc;
129    int rid;
130
131    sc = device_get_softc(dev);
132
133    rid = PCIR_BAR(0);
134    sc->vx_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
135
136    if (sc->vx_res == NULL)
137	goto bad;
138
139    sc->bst = rman_get_bustag(sc->vx_res);
140    sc->bsh = rman_get_bushandle(sc->vx_res);
141
142    rid = 0;
143    sc->vx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
144	RF_SHAREABLE | RF_ACTIVE);
145
146    if (sc->vx_irq == NULL)
147	goto bad;
148
149    if (bus_setup_intr(dev, sc->vx_irq, INTR_TYPE_NET,
150	vxintr, sc, &sc->vx_intrhand))
151	goto bad;
152
153    if (vxattach(dev) == 0) {
154	goto bad;
155    }
156
157    /* defect check for 3C590 */
158    if ((pci_read_config(dev, PCIR_DEVVENDOR, 4) >> 16) == 0x5900) {
159	GO_WINDOW(0);
160	if (vxbusyeeprom(sc))
161	    goto bad;
162	CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND,
163	    EEPROM_CMD_RD | EEPROM_SOFTINFO2);
164	if (vxbusyeeprom(sc))
165	    goto bad;
166	if (!(CSR_READ_2(sc, VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY)) {
167	    printf("Warning! Defective early revision adapter!\n");
168	}
169    }
170
171    return(0);
172
173bad:
174    if (sc->vx_intrhand != NULL)
175	bus_teardown_intr(dev, sc->vx_irq, sc->vx_intrhand);
176    if (sc->vx_res != NULL)
177	bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->vx_res);
178    if (sc->vx_irq != NULL)
179	bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vx_irq);
180    return(ENXIO);
181}
182