if_gem_pci.c (174987) | if_gem_pci.c (177560) |
---|---|
1/*- 2 * Copyright (C) 2001 Eduardo Horvath. 3 * Copyright (c) 2007 Marius Strobl <marius@FreeBSD.org> 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 --- 15 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> | 1/*- 2 * Copyright (C) 2001 Eduardo Horvath. 3 * Copyright (c) 2007 Marius Strobl <marius@FreeBSD.org> 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 --- 15 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> |
32__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem_pci.c 174987 2007-12-30 01:32:03Z marius $"); | 32__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem_pci.c 177560 2008-03-24 17:23:53Z marius $"); |
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> 41#include <sys/kernel.h> 42#include <sys/lock.h> | 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> 41#include <sys/kernel.h> 42#include <sys/lock.h> |
43#include <sys/malloc.h> |
|
43#include <sys/module.h> 44#include <sys/mutex.h> 45#include <sys/resource.h> 46#include <sys/rman.h> 47#include <sys/socket.h> 48 49#include <net/ethernet.h> 50#include <net/if.h> --- 78 unchanged lines hidden (view full) --- 129 return (BUS_PROBE_DEFAULT); 130 } 131 } 132 133 return (ENXIO); 134} 135 136static struct resource_spec gem_pci_res_spec[] = { | 44#include <sys/module.h> 45#include <sys/mutex.h> 46#include <sys/resource.h> 47#include <sys/rman.h> 48#include <sys/socket.h> 49 50#include <net/ethernet.h> 51#include <net/if.h> --- 78 unchanged lines hidden (view full) --- 130 return (BUS_PROBE_DEFAULT); 131 } 132 } 133 134 return (ENXIO); 135} 136 137static 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 }, | 138 { SYS_RES_IRQ, 0, RF_SHAREABLE | RF_ACTIVE }, /* GEM_RES_INTR */ 139 { SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE }, /* GEM_RES_BANK1 */ |
139 { -1, 0 } 140}; 141 142static int 143gem_pci_attach(device_t dev) 144{ 145 struct gem_softc *sc; 146 int i; --- 29 unchanged lines hidden (view full) --- 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)); 183 | 140 { -1, 0 } 141}; 142 143static int 144gem_pci_attach(device_t dev) 145{ 146 struct gem_softc *sc; 147 int i; --- 29 unchanged lines hidden (view full) --- 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)); 184 |
185 /* 186 * Derive GEM_RES_BANK2 from GEM_RES_BANK1. This seemed cleaner 187 * with the old way of using copies of the bus tag and handle in 188 * the softc along with bus_space_*()... 189 */ 190 sc->sc_res[GEM_RES_BANK2] = malloc(sizeof(*sc->sc_res[GEM_RES_BANK2]), 191 M_DEVBUF, M_NOWAIT | M_ZERO); 192 if (sc->sc_res[GEM_RES_BANK2] == NULL) { 193 device_printf(dev, "failed to allocate bank2 resource\n"); 194 goto fail; 195 } 196 rman_set_bustag(sc->sc_res[GEM_RES_BANK2], 197 rman_get_bustag(sc->sc_res[GEM_RES_BANK1])); 198 bus_space_subregion(rman_get_bustag(sc->sc_res[GEM_RES_BANK1]), 199 rman_get_bushandle(sc->sc_res[GEM_RES_BANK1]), 200 GEM_PCI_BANK2_OFFSET, GEM_PCI_BANK2_SIZE, 201 &sc->sc_res[GEM_RES_BANK2]->r_bushandle); 202 |
|
184#if defined(__powerpc__) || defined(__sparc64__) 185 OF_getetheraddr(dev, sc->sc_enaddr); 186#else 187 /* 188 * Dig out VPD (vital product data) and read NA (network address). 189 * The VPD of GEM resides in the PCI Expansion ROM (PCI FCode) and 190 * can't be accessed via the PCI capability pointer. 191 * ``Writing FCode 3.x Programs'' (newer ones, dated 1997 and later) --- 19 unchanged lines hidden (view full) --- 211#define PCI_VPDRES_LARGE_LEN_MSB 0x02 212#define PCI_VPDRES_LARGE_DATA 0x03 213#define PCI_VPD_SIZE 0x03 214#define PCI_VPD_KEY0 0x00 215#define PCI_VPD_KEY1 0x01 216#define PCI_VPD_LEN 0x02 217#define PCI_VPD_DATA 0x03 218 | 203#if defined(__powerpc__) || defined(__sparc64__) 204 OF_getetheraddr(dev, sc->sc_enaddr); 205#else 206 /* 207 * Dig out VPD (vital product data) and read NA (network address). 208 * The VPD of GEM resides in the PCI Expansion ROM (PCI FCode) and 209 * can't be accessed via the PCI capability pointer. 210 * ``Writing FCode 3.x Programs'' (newer ones, dated 1997 and later) --- 19 unchanged lines hidden (view full) --- 230#define PCI_VPDRES_LARGE_LEN_MSB 0x02 231#define PCI_VPDRES_LARGE_DATA 0x03 232#define PCI_VPD_SIZE 0x03 233#define PCI_VPD_KEY0 0x00 234#define PCI_VPD_KEY1 0x01 235#define PCI_VPD_LEN 0x02 236#define PCI_VPD_DATA 0x03 237 |
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)) | 238#define GEM_ROM_READ_1(sc, offs) \ 239 GEM_BANK1_READ_1((sc), GEM_PCI_ROM_OFFSET + (offs)) 240#define GEM_ROM_READ_2(sc, offs) \ 241 GEM_BANK1_READ_2((sc), GEM_PCI_ROM_OFFSET + (offs)) 242#define GEM_ROM_READ_4(sc, offs) \ 243 GEM_BANK1_READ_4((sc), GEM_PCI_ROM_OFFSET + (offs)) |
224 225 /* Read PCI Expansion ROM header. */ 226 if (GEM_ROM_READ_2(sc, PCI_ROMHDR_SIG) != PCI_ROMHDR_SIG_MAGIC || 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 } --- 15 unchanged lines hidden (view full) --- 247 * format however. The length in the resource header is in big 248 * endian and the end tag is non-standard (0x79) and followed 249 * by an all-zero "checksum" byte. Sun calls this a "Fresh 250 * Choice Ethernet" VPD... 251 */ 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, | 244 245 /* Read PCI Expansion ROM header. */ 246 if (GEM_ROM_READ_2(sc, PCI_ROMHDR_SIG) != PCI_ROMHDR_SIG_MAGIC || 247 (i = GEM_ROM_READ_2(sc, PCI_ROMHDR_PTR_DATA)) < 248 PCI_ROMHDR_SIZE) { 249 device_printf(dev, "unexpected PCI Expansion ROM header\n"); 250 goto fail; 251 } --- 15 unchanged lines hidden (view full) --- 267 * format however. The length in the resource header is in big 268 * endian and the end tag is non-standard (0x79) and followed 269 * by an all-zero "checksum" byte. Sun calls this a "Fresh 270 * Choice Ethernet" VPD... 271 */ 272 if (PCI_VPDRES_ISLARGE(GEM_ROM_READ_1(sc, 273 j + PCI_VPDRES_BYTE0)) == 0 || 274 PCI_VPDRES_LARGE_NAME(GEM_ROM_READ_1(sc, |
255 j + PCI_VPDRES_BYTE0)) != 256 PCI_VPDRES_TYPE_VPD || | 275 j + PCI_VPDRES_BYTE0)) != 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 */ || 264 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_LEN) != 265 ETHER_ADDR_LEN || 266 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_DATA + 267 ETHER_ADDR_LEN) != 0x79) { 268 device_printf(dev, "unexpected PCI VPD\n"); 269 goto fail; 270 } | 276 (GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_LEN_LSB) << 8 | 277 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_LEN_MSB)) != 278 PCI_VPD_SIZE + ETHER_ADDR_LEN || 279 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_KEY0) != 280 0x4e /* N */ || 281 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_KEY1) != 282 0x41 /* A */ || 283 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_LEN) != 284 ETHER_ADDR_LEN || 285 GEM_ROM_READ_1(sc, j + PCI_VPDRES_LARGE_DATA + PCI_VPD_DATA + 286 ETHER_ADDR_LEN) != 0x79) { 287 device_printf(dev, "unexpected PCI VPD\n"); 288 goto fail; 289 } |
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); | 290 bus_read_region_1(sc->sc_res[GEM_RES_BANK1], 291 GEM_PCI_ROM_OFFSET + j + PCI_VPDRES_LARGE_DATA + PCI_VPD_DATA, 292 sc->sc_enaddr, ETHER_ADDR_LEN); |
274#endif 275 276 if (gem_attach(sc) != 0) { 277 device_printf(dev, "could not be attached\n"); 278 goto fail; 279 } 280 | 293#endif 294 295 if (gem_attach(sc) != 0) { 296 device_printf(dev, "could not be attached\n"); 297 goto fail; 298 } 299 |
281 if (bus_setup_intr(dev, sc->sc_res[1], INTR_TYPE_NET | INTR_MPSAFE, 282 NULL, gem_intr, sc, &sc->sc_ih) != 0) { | 300 if (bus_setup_intr(dev, sc->sc_res[GEM_RES_INTR], INTR_TYPE_NET | 301 INTR_MPSAFE, 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 289 fail: | 302 device_printf(dev, "failed to set up interrupt\n"); 303 gem_detach(sc); 304 goto fail; 305 } 306 return (0); 307 308 fail: |
309 if (sc->sc_res[GEM_RES_BANK2] != NULL) 310 free(sc->sc_res[GEM_RES_BANK2], M_DEVBUF); |
|
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(device_t dev) 297{ 298 struct gem_softc *sc; 299 300 sc = device_get_softc(dev); | 311 GEM_LOCK_DESTROY(sc); 312 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 313 return (ENXIO); 314} 315 316static int 317gem_pci_detach(device_t dev) 318{ 319 struct gem_softc *sc; 320 321 sc = device_get_softc(dev); |
301 bus_teardown_intr(dev, sc->sc_res[1], sc->sc_ih); | 322 bus_teardown_intr(dev, sc->sc_res[GEM_RES_INTR], sc->sc_ih); |
302 gem_detach(sc); | 323 gem_detach(sc); |
324 free(sc->sc_res[GEM_RES_BANK2], M_DEVBUF); |
|
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(device_t dev) 310{ --- 16 unchanged lines hidden --- | 325 GEM_LOCK_DESTROY(sc); 326 bus_release_resources(dev, gem_pci_res_spec, sc->sc_res); 327 return (0); 328} 329 330static int 331gem_pci_suspend(device_t dev) 332{ --- 16 unchanged lines hidden --- |