FreeBSD/Linux Kernel Cross Reference
sys/dev/vx/if_vx_pci.c
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$");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/socket.h>
38
39 #include <net/ethernet.h>
40 #include <net/if.h>
41 #include <net/if_arp.h>
42
43 #include <machine/bus.h>
44 #include <machine/resource.h>
45 #include <sys/bus.h>
46 #include <sys/rman.h>
47
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcireg.h>
50
51 #include <dev/vx/if_vxreg.h>
52 #include <dev/vx/if_vxvar.h>
53
54 static int vx_pci_shutdown(device_t);
55 static int vx_pci_probe(device_t);
56 static int vx_pci_attach(device_t);
57
58 static device_method_t vx_methods[] = {
59 /* Device interface */
60 DEVMETHOD(device_probe, vx_pci_probe),
61 DEVMETHOD(device_attach, vx_pci_attach),
62 DEVMETHOD(device_shutdown, vx_pci_shutdown),
63
64 {0, 0}
65 };
66
67 static driver_t vx_driver = {
68 "vx",
69 vx_methods,
70 sizeof(struct vx_softc)
71 };
72
73 static devclass_t vx_devclass;
74
75 DRIVER_MODULE(vx, pci, vx_driver, vx_devclass, 0, 0);
76 MODULE_DEPEND(vx, pci, 1, 1, 1);
77 MODULE_DEPEND(vx, ether, 1, 1, 1);
78
79 static int
80 vx_pci_shutdown(device_t dev)
81 {
82 struct vx_softc *sc;
83
84 sc = device_get_softc(dev);
85 VX_LOCK(sc);
86 vx_stop(sc);
87 VX_UNLOCK(sc);
88
89 return (0);
90 }
91
92 static int
93 vx_pci_probe(device_t dev)
94 {
95 u_int32_t device_id;
96
97 device_id = pci_read_config(dev, PCIR_DEVVENDOR, 4);
98
99 if (device_id == 0x590010b7ul) {
100 device_set_desc(dev, "3COM 3C590 Etherlink III PCI");
101 return (BUS_PROBE_DEFAULT);
102 }
103 if (device_id == 0x595010b7ul || device_id == 0x595110b7ul ||
104 device_id == 0x595210b7ul) {
105 device_set_desc(dev, "3COM 3C595 Etherlink III PCI");
106 return (BUS_PROBE_DEFAULT);
107 }
108 /*
109 * The (Fast) Etherlink XL adapters are now supported by
110 * the xl driver, which uses bus master DMA and is much
111 * faster. (And which also supports the 3c905B.
112 */
113 if (device_id == 0x900010b7ul || device_id == 0x900110b7ul) {
114 device_set_desc(dev, "3COM 3C900 Etherlink XL PCI");
115 return (BUS_PROBE_LOW_PRIORITY);
116 }
117 if (device_id == 0x905010b7ul || device_id == 0x905110b7ul) {
118 device_set_desc(dev, "3COM 3C905 Etherlink XL PCI");
119 return (BUS_PROBE_LOW_PRIORITY);
120 }
121 return (ENXIO);
122 }
123
124 static int
125 vx_pci_attach(device_t dev)
126 {
127 struct vx_softc *sc;
128 int rid;
129
130 sc = device_get_softc(dev);
131
132 rid = PCIR_BAR(0);
133 sc->vx_res =
134 bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
135
136 if (sc->vx_res == NULL)
137 goto bad;
138
139 sc->vx_bst = rman_get_bustag(sc->vx_res);
140 sc->vx_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 (vx_attach(dev) == 0)
150 goto bad;
151
152 if (bus_setup_intr(dev, sc->vx_irq, INTR_TYPE_NET | INTR_MPSAFE,
153 NULL, vx_intr, sc, &sc->vx_intrhand))
154 goto bad_mtx;
155
156 /* defect check for 3C590 */
157 if ((pci_read_config(dev, PCIR_DEVVENDOR, 4) >> 16) == 0x5900) {
158 GO_WINDOW(0);
159 if (vx_busy_eeprom(sc))
160 goto bad_mtx;
161 CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND,
162 EEPROM_CMD_RD | EEPROM_SOFTINFO2);
163 if (vx_busy_eeprom(sc))
164 goto bad_mtx;
165 if (!(CSR_READ_2(sc, VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY))
166 device_printf(dev,
167 "Warning! Defective early revision adapter!\n");
168 }
169 return (0);
170
171 bad_mtx:
172 mtx_destroy(&sc->vx_mtx);
173 ether_ifdetach(sc->vx_ifp);
174 if_free(sc->vx_ifp);
175 bad:
176 if (sc->vx_intrhand != NULL)
177 bus_teardown_intr(dev, sc->vx_irq, sc->vx_intrhand);
178 if (sc->vx_res != NULL)
179 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->vx_res);
180 if (sc->vx_irq != NULL)
181 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vx_irq);
182 return (ENXIO);
183 }
Cache object: 6e47b0fb446c31dea62c047954138fb7
|