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