if_gem_pci.c (172334) | if_gem_pci.c (174987) |
---|---|
1/*- 2 * Copyright (C) 2001 Eduardo Horvath. | 1/*- 2 * Copyright (C) 2001 Eduardo Horvath. |
3 * Copyright (c) 2007 Marius Strobl <marius@FreeBSD.org> |
|
3 * All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. --- 12 unchanged lines hidden (view full) --- 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * from: NetBSD: if_gem_pci.c,v 1.7 2001/10/18 15:09:15 thorpej Exp 28 */ 29 30#include <sys/cdefs.h> | 4 * All rights reserved. 5 * 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 unchanged lines hidden (view full) --- 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * from: NetBSD: if_gem_pci.c,v 1.7 2001/10/18 15:09:15 thorpej Exp 29 */ 30 31#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem_pci.c 172334 2007-09-26 21:14:18Z marius $"); | 32__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem_pci.c 174987 2007-12-30 01:32:03Z marius $"); |
32 33/* 34 * PCI bindings for Apple GMAC, Sun ERI and Sun GEM Ethernet controllers 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/bus.h> --- 18 unchanged lines hidden (view full) --- 58#include <dev/gem/if_gemreg.h> 59#include <dev/gem/if_gemvar.h> 60 61#include <dev/pci/pcireg.h> 62#include <dev/pci/pcivar.h> 63 64#include "miibus_if.h" 65 | 33 34/* 35 * PCI bindings for Apple GMAC, Sun ERI and Sun GEM Ethernet controllers 36 */ 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/bus.h> --- 18 unchanged lines hidden (view full) --- 59#include <dev/gem/if_gemreg.h> 60#include <dev/gem/if_gemvar.h> 61 62#include <dev/pci/pcireg.h> 63#include <dev/pci/pcivar.h> 64 65#include "miibus_if.h" 66 |
66static int gem_pci_probe(device_t); 67static int gem_pci_attach(device_t); 68static int gem_pci_detach(device_t); 69static int gem_pci_suspend(device_t); 70static int gem_pci_resume(device_t); | 67static int gem_pci_attach(device_t dev); 68static int gem_pci_detach(device_t dev); 69static int gem_pci_probe(device_t dev); 70static int gem_pci_resume(device_t dev); 71static int gem_pci_suspend(device_t dev); |
71 72static device_method_t gem_pci_methods[] = { 73 /* Device interface */ 74 DEVMETHOD(device_probe, gem_pci_probe), 75 DEVMETHOD(device_attach, gem_pci_attach), 76 DEVMETHOD(device_detach, gem_pci_detach), 77 DEVMETHOD(device_suspend, gem_pci_suspend), 78 DEVMETHOD(device_resume, gem_pci_resume), --- 34 unchanged lines hidden (view full) --- 113 { 0x0032106b, GEM_APPLE_GMAC, "Apple UniNorth2 GMAC Ethernet" }, 114 { 0x004c106b, GEM_APPLE_K2_GMAC,"Apple K2 GMAC Ethernet" }, 115 { 0x0051106b, GEM_APPLE_GMAC, "Apple Shasta GMAC Ethernet" }, 116 { 0x006b106b, GEM_APPLE_GMAC, "Apple Intrepid 2 GMAC Ethernet" }, 117 { 0, 0, NULL } 118}; 119 120static int | 72 73static device_method_t gem_pci_methods[] = { 74 /* Device interface */ 75 DEVMETHOD(device_probe, gem_pci_probe), 76 DEVMETHOD(device_attach, gem_pci_attach), 77 DEVMETHOD(device_detach, gem_pci_detach), 78 DEVMETHOD(device_suspend, gem_pci_suspend), 79 DEVMETHOD(device_resume, gem_pci_resume), --- 34 unchanged lines hidden (view full) --- 114 { 0x0032106b, GEM_APPLE_GMAC, "Apple UniNorth2 GMAC Ethernet" }, 115 { 0x004c106b, GEM_APPLE_K2_GMAC,"Apple K2 GMAC Ethernet" }, 116 { 0x0051106b, GEM_APPLE_GMAC, "Apple Shasta GMAC Ethernet" }, 117 { 0x006b106b, GEM_APPLE_GMAC, "Apple Intrepid 2 GMAC Ethernet" }, 118 { 0, 0, NULL } 119}; 120 121static int |
121gem_pci_probe(dev) 122 device_t dev; | 122gem_pci_probe(device_t dev) |
123{ 124 int i; 125 126 for (i = 0; gem_pci_devlist[i].gpd_desc != NULL; i++) { 127 if (pci_get_devid(dev) == gem_pci_devlist[i].gpd_devid) { 128 device_set_desc(dev, gem_pci_devlist[i].gpd_desc); 129 return (BUS_PROBE_DEFAULT); 130 } --- 4 unchanged lines hidden (view full) --- 135 136static struct resource_spec gem_pci_res_spec[] = { 137 { SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE }, 138 { SYS_RES_IRQ, 0, RF_SHAREABLE | RF_ACTIVE }, 139 { -1, 0 } 140}; 141 142static int | 123{ 124 int i; 125 126 for (i = 0; gem_pci_devlist[i].gpd_desc != NULL; i++) { 127 if (pci_get_devid(dev) == gem_pci_devlist[i].gpd_devid) { 128 device_set_desc(dev, gem_pci_devlist[i].gpd_desc); 129 return (BUS_PROBE_DEFAULT); 130 } --- 4 unchanged lines hidden (view full) --- 135 136static struct resource_spec gem_pci_res_spec[] = { 137 { SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE }, 138 { SYS_RES_IRQ, 0, RF_SHAREABLE | RF_ACTIVE }, 139 { -1, 0 } 140}; 141 142static int |
143gem_pci_attach(dev) 144 device_t dev; | 143gem_pci_attach(device_t dev) |
145{ 146 struct gem_softc *sc; 147 int i; 148#if !(defined(__powerpc__) || defined(__sparc64__)) 149 int j; 150#endif 151 152 sc = device_get_softc(dev); --- 8 unchanged lines hidden (view full) --- 161 device_printf(dev, "unknown adaptor\n"); 162 return (ENXIO); 163 } 164 165 pci_enable_busmaster(dev); 166 167 /* 168 * Some Sun GEMs/ERIs do have their intpin register bogusly set to 0, | 144{ 145 struct gem_softc *sc; 146 int i; 147#if !(defined(__powerpc__) || defined(__sparc64__)) 148 int j; 149#endif 150 151 sc = device_get_softc(dev); --- 8 unchanged lines hidden (view full) --- 160 device_printf(dev, "unknown adaptor\n"); 161 return (ENXIO); 162 } 163 164 pci_enable_busmaster(dev); 165 166 /* 167 * Some Sun GEMs/ERIs do have their intpin register bogusly set to 0, |
169 * although it should be 1. correct that. | 168 * although it should be 1. Correct that. |
170 */ 171 if (pci_get_intpin(dev) == 0) 172 pci_set_intpin(dev, 1); 173 174 sc->sc_dev = dev; | 169 */ 170 if (pci_get_intpin(dev) == 0) 171 pci_set_intpin(dev, 1); 172 173 sc->sc_dev = dev; |
175 sc->sc_flags |= GEM_PCI; /* XXX */ | 174 sc->sc_flags |= GEM_PCI; |
176 177 if (bus_alloc_resources(dev, gem_pci_res_spec, sc->sc_res)) { 178 device_printf(dev, "failed to allocate resources\n"); 179 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 180 return (ENXIO); 181 } 182 183 GEM_LOCK_INIT(sc, device_get_nameunit(dev)); --- 36 unchanged lines hidden (view full) --- 220#define GEM_ROM_READ_N(n, sc, offs) \ 221 bus_read_ ## n ((sc)->sc_res[0], GEM_PCI_ROM_OFFSET + (offs)) 222#define GEM_ROM_READ_1(sc, offs) GEM_ROM_READ_N(1, (sc), (offs)) 223#define GEM_ROM_READ_2(sc, offs) GEM_ROM_READ_N(2, (sc), (offs)) 224#define GEM_ROM_READ_4(sc, offs) GEM_ROM_READ_N(4, (sc), (offs)) 225 226 /* Read PCI Expansion ROM header. */ 227 if (GEM_ROM_READ_2(sc, PCI_ROMHDR_SIG) != PCI_ROMHDR_SIG_MAGIC || | 175 176 if (bus_alloc_resources(dev, gem_pci_res_spec, sc->sc_res)) { 177 device_printf(dev, "failed to allocate resources\n"); 178 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 179 return (ENXIO); 180 } 181 182 GEM_LOCK_INIT(sc, device_get_nameunit(dev)); --- 36 unchanged lines hidden (view full) --- 219#define GEM_ROM_READ_N(n, sc, offs) \ 220 bus_read_ ## n ((sc)->sc_res[0], GEM_PCI_ROM_OFFSET + (offs)) 221#define GEM_ROM_READ_1(sc, offs) GEM_ROM_READ_N(1, (sc), (offs)) 222#define GEM_ROM_READ_2(sc, offs) GEM_ROM_READ_N(2, (sc), (offs)) 223#define GEM_ROM_READ_4(sc, offs) GEM_ROM_READ_N(4, (sc), (offs)) 224 225 /* Read PCI Expansion ROM header. */ 226 if (GEM_ROM_READ_2(sc, PCI_ROMHDR_SIG) != PCI_ROMHDR_SIG_MAGIC || |
228 (i = GEM_ROM_READ_2(sc, PCI_ROMHDR_PTR_DATA)) < PCI_ROMHDR_SIZE) { | 227 (i = GEM_ROM_READ_2(sc, PCI_ROMHDR_PTR_DATA)) < 228 PCI_ROMHDR_SIZE) { |
229 device_printf(dev, "unexpected PCI Expansion ROM header\n"); 230 goto fail; 231 } 232 233 /* Read PCI Expansion ROM data. */ 234 if (GEM_ROM_READ_4(sc, i + PCI_ROM_SIG) != PCI_ROM_SIG_MAGIC || 235 GEM_ROM_READ_2(sc, i + PCI_ROM_VENDOR) != pci_get_vendor(dev) || 236 GEM_ROM_READ_2(sc, i + PCI_ROM_DEVICE) != pci_get_device(dev) || | 229 device_printf(dev, "unexpected PCI Expansion ROM header\n"); 230 goto fail; 231 } 232 233 /* Read PCI Expansion ROM data. */ 234 if (GEM_ROM_READ_4(sc, i + PCI_ROM_SIG) != PCI_ROM_SIG_MAGIC || 235 GEM_ROM_READ_2(sc, i + PCI_ROM_VENDOR) != pci_get_vendor(dev) || 236 GEM_ROM_READ_2(sc, i + PCI_ROM_DEVICE) != pci_get_device(dev) || |
237 (j = GEM_ROM_READ_2(sc, i + PCI_ROM_PTR_VPD)) < i + PCI_ROM_SIZE) { | 237 (j = GEM_ROM_READ_2(sc, i + PCI_ROM_PTR_VPD)) < 238 i + PCI_ROM_SIZE) { |
238 device_printf(dev, "unexpected PCI Expansion ROM data\n"); 239 goto fail; 240 } 241 242 /* 243 * Read PCI VPD. 244 * SUNW,pci-gem cards have a single large resource VPD-R tag | 239 device_printf(dev, "unexpected PCI Expansion ROM data\n"); 240 goto fail; 241 } 242 243 /* 244 * Read PCI VPD. 245 * SUNW,pci-gem cards have a single large resource VPD-R tag |
245 * containing one NA. The VPD used is not in PCI 2.2 standard 246 * format however. The length in the resource header is in big | 246 * containing one NA. The VPD used is not in PCI 2.2 standard 247 * format however. The length in the resource header is in big |
247 * endian and the end tag is non-standard (0x79) and followed | 248 * endian and the end tag is non-standard (0x79) and followed |
248 * by an all-zero "checksum" byte. Sun calls this a "Fresh | 249 * by an all-zero "checksum" byte. Sun calls this a "Fresh |
249 * Choice Ethernet" VPD... 250 */ | 250 * Choice Ethernet" VPD... 251 */ |
251 if (PCI_VPDRES_ISLARGE(GEM_ROM_READ_1(sc, j + PCI_VPDRES_BYTE0)) == 0 || 252 PCI_VPDRES_LARGE_NAME(GEM_ROM_READ_1(sc, j + PCI_VPDRES_BYTE0)) != | 252 if (PCI_VPDRES_ISLARGE(GEM_ROM_READ_1(sc, 253 j + PCI_VPDRES_BYTE0)) == 0 || 254 PCI_VPDRES_LARGE_NAME(GEM_ROM_READ_1(sc, 255 j + PCI_VPDRES_BYTE0)) != |
253 PCI_VPDRES_TYPE_VPD || 254 (GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_LEN_LSB) << 8 | 255 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_LEN_MSB)) != 256 PCI_VPD_SIZE + ETHER_ADDR_LEN || 257 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_KEY0) != 258 0x4e /* N */ || 259 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_KEY1) != 260 0x41 /* A */ || --- 4 unchanged lines hidden (view full) --- 265 device_printf(dev, "unexpected PCI VPD\n"); 266 goto fail; 267 } 268 bus_read_region_1(sc->sc_res[0], GEM_PCI_ROM_OFFSET + j + 269 PCI_VPDRES_LARGE_DATA + PCI_VPD_DATA, sc->sc_enaddr, 270 ETHER_ADDR_LEN); 271#endif 272 | 256 PCI_VPDRES_TYPE_VPD || 257 (GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_LEN_LSB) << 8 | 258 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_LEN_MSB)) != 259 PCI_VPD_SIZE + ETHER_ADDR_LEN || 260 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_KEY0) != 261 0x4e /* N */ || 262 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_KEY1) != 263 0x41 /* A */ || --- 4 unchanged lines hidden (view full) --- 268 device_printf(dev, "unexpected PCI VPD\n"); 269 goto fail; 270 } 271 bus_read_region_1(sc->sc_res[0], GEM_PCI_ROM_OFFSET + j + 272 PCI_VPDRES_LARGE_DATA + PCI_VPD_DATA, sc->sc_enaddr, 273 ETHER_ADDR_LEN); 274#endif 275 |
273 /* 274 * call the main configure 275 */ | |
276 if (gem_attach(sc) != 0) { | 276 if (gem_attach(sc) != 0) { |
277 device_printf(dev, "could not be configured\n"); | 277 device_printf(dev, "could not be attached\n"); |
278 goto fail; 279 } 280 281 if (bus_setup_intr(dev, sc->sc_res[1], INTR_TYPE_NET | INTR_MPSAFE, 282 NULL, gem_intr, sc, &sc->sc_ih) != 0) { 283 device_printf(dev, "failed to set up interrupt\n"); 284 gem_detach(sc); 285 goto fail; 286 } 287 return (0); 288 | 278 goto fail; 279 } 280 281 if (bus_setup_intr(dev, sc->sc_res[1], INTR_TYPE_NET | INTR_MPSAFE, 282 NULL, gem_intr, sc, &sc->sc_ih) != 0) { 283 device_printf(dev, "failed to set up interrupt\n"); 284 gem_detach(sc); 285 goto fail; 286 } 287 return (0); 288 |
289fail: | 289 fail: |
290 GEM_LOCK_DESTROY(sc); 291 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 292 return (ENXIO); 293} 294 295static int | 290 GEM_LOCK_DESTROY(sc); 291 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 292 return (ENXIO); 293} 294 295static int |
296gem_pci_detach(dev) 297 device_t dev; | 296gem_pci_detach(device_t dev) |
298{ | 297{ |
299 struct gem_softc *sc = device_get_softc(dev); | 298 struct gem_softc *sc; |
300 | 299 |
300 sc = device_get_softc(dev); |
|
301 bus_teardown_intr(dev, sc->sc_res[1], sc->sc_ih); 302 gem_detach(sc); 303 GEM_LOCK_DESTROY(sc); 304 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 305 return (0); 306} 307 308static int | 301 bus_teardown_intr(dev, sc->sc_res[1], sc->sc_ih); 302 gem_detach(sc); 303 GEM_LOCK_DESTROY(sc); 304 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 305 return (0); 306} 307 308static int |
309gem_pci_suspend(dev) 310 device_t dev; | 309gem_pci_suspend(device_t dev) |
311{ | 310{ |
312 struct gem_softc *sc = device_get_softc(dev); | 311 struct gem_softc *sc; |
313 | 312 |
313 sc = device_get_softc(dev); |
|
314 gem_suspend(sc); 315 return (0); 316} 317 318static int | 314 gem_suspend(sc); 315 return (0); 316} 317 318static int |
319gem_pci_resume(dev) 320 device_t dev; | 319gem_pci_resume(device_t dev) |
321{ | 320{ |
322 struct gem_softc *sc = device_get_softc(dev); | 321 struct gem_softc *sc; |
323 | 322 |
323 sc = device_get_softc(dev); |
|
324 gem_resume(sc); 325 return (0); 326} | 324 gem_resume(sc); 325 return (0); 326} |