Home | History | Annotate | Line # | Download | only in pci
if_gem_pci.c revision 1.19.4.4
      1  1.19.4.4     yamt /*	$NetBSD: if_gem_pci.c,v 1.19.4.4 2008/01/21 09:43:54 yamt Exp $ */
      2       1.1      eeh 
      3       1.1      eeh /*
      4      1.17     heas  *
      5       1.1      eeh  * Copyright (C) 2001 Eduardo Horvath.
      6       1.1      eeh  * All rights reserved.
      7       1.1      eeh  *
      8       1.1      eeh  *
      9       1.1      eeh  * Redistribution and use in source and binary forms, with or without
     10       1.1      eeh  * modification, are permitted provided that the following conditions
     11       1.1      eeh  * are met:
     12       1.1      eeh  * 1. Redistributions of source code must retain the above copyright
     13       1.1      eeh  *    notice, this list of conditions and the following disclaimer.
     14       1.1      eeh  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1      eeh  *    notice, this list of conditions and the following disclaimer in the
     16       1.1      eeh  *    documentation and/or other materials provided with the distribution.
     17      1.17     heas  *
     18       1.1      eeh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
     19       1.1      eeh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20       1.1      eeh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21       1.1      eeh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
     22       1.1      eeh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23       1.1      eeh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24       1.1      eeh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25       1.1      eeh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26       1.1      eeh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27       1.1      eeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28       1.1      eeh  * SUCH DAMAGE.
     29       1.1      eeh  *
     30       1.1      eeh  */
     31       1.1      eeh 
     32       1.1      eeh /*
     33  1.19.4.4     yamt  * PCI bindings for Apple GMAC, Sun ERI and Sun GEM Ethernet controllers
     34       1.1      eeh  */
     35       1.8    lukem 
     36       1.8    lukem #include <sys/cdefs.h>
     37  1.19.4.4     yamt __KERNEL_RCSID(0, "$NetBSD: if_gem_pci.c,v 1.19.4.4 2008/01/21 09:43:54 yamt Exp $");
     38       1.1      eeh 
     39       1.1      eeh #include <sys/param.h>
     40      1.17     heas #include <sys/systm.h>
     41       1.1      eeh #include <sys/malloc.h>
     42       1.1      eeh #include <sys/kernel.h>
     43       1.1      eeh #include <sys/socket.h>
     44       1.1      eeh #include <sys/errno.h>
     45       1.1      eeh #include <sys/device.h>
     46       1.1      eeh 
     47       1.1      eeh #include <machine/endian.h>
     48       1.1      eeh 
     49       1.1      eeh #include <uvm/uvm_extern.h>
     50      1.17     heas 
     51       1.1      eeh #include <net/if.h>
     52       1.1      eeh #include <net/if_dl.h>
     53       1.1      eeh #include <net/if_media.h>
     54       1.1      eeh #include <net/if_ether.h>
     55       1.1      eeh 
     56      1.17     heas #if NBPFILTER > 0
     57       1.1      eeh #include <net/bpf.h>
     58      1.17     heas #endif
     59       1.1      eeh 
     60  1.19.4.3     yamt #include <sys/bus.h>
     61  1.19.4.3     yamt #include <sys/intr.h>
     62       1.1      eeh 
     63       1.1      eeh #include <dev/mii/mii.h>
     64       1.1      eeh #include <dev/mii/miivar.h>
     65       1.1      eeh #include <dev/mii/mii_bitbang.h>
     66       1.1      eeh 
     67       1.1      eeh #include <dev/ic/gemreg.h>
     68       1.1      eeh #include <dev/ic/gemvar.h>
     69       1.1      eeh 
     70       1.1      eeh #include <dev/pci/pcivar.h>
     71       1.1      eeh #include <dev/pci/pcireg.h>
     72       1.1      eeh #include <dev/pci/pcidevs.h>
     73       1.1      eeh 
     74       1.4  thorpej /* XXX Should use Properties when that's fleshed out. */
     75       1.4  thorpej #ifdef macppc
     76       1.4  thorpej #include <dev/ofw/openfirm.h>
     77       1.4  thorpej #endif /* macppc */
     78      1.15   martin #ifdef __sparc__
     79      1.15   martin #include <machine/promlib.h>
     80      1.15   martin #endif
     81       1.4  thorpej 
     82  1.19.4.4     yamt #ifndef GEM_USE_LOCAL_MAC_ADDRESS
     83  1.19.4.4     yamt #if defined (macppc) || defined (__sparc__)
     84  1.19.4.4     yamt #define GEM_USE_LOCAL_MAC_ADDRESS	0	/* use system-wide address */
     85  1.19.4.4     yamt #else
     86  1.19.4.4     yamt #define GEM_USE_LOCAL_MAC_ADDRESS	1
     87  1.19.4.4     yamt #endif
     88  1.19.4.4     yamt #endif
     89  1.19.4.4     yamt 
     90  1.19.4.4     yamt 
     91       1.1      eeh struct gem_pci_softc {
     92       1.1      eeh 	struct	gem_softc	gsc_gem;	/* GEM device */
     93       1.1      eeh 	void			*gsc_ih;
     94       1.1      eeh };
     95       1.1      eeh 
     96      1.18    perry int	gem_match_pci(struct device *, struct cfdata *, void *);
     97      1.18    perry void	gem_attach_pci(struct device *, struct device *, void *);
     98       1.1      eeh 
     99      1.12  thorpej CFATTACH_DECL(gem_pci, sizeof(struct gem_pci_softc),
    100      1.13  thorpej     gem_match_pci, gem_attach_pci, NULL, NULL);
    101       1.1      eeh 
    102       1.1      eeh /*
    103       1.1      eeh  * Attach routines need to be split out to different bus-specific files.
    104       1.1      eeh  */
    105       1.1      eeh 
    106       1.1      eeh int
    107       1.1      eeh gem_match_pci(parent, cf, aux)
    108       1.1      eeh 	struct device *parent;
    109       1.1      eeh 	struct cfdata *cf;
    110       1.1      eeh 	void *aux;
    111       1.1      eeh {
    112       1.1      eeh 	struct pci_attach_args *pa = aux;
    113       1.1      eeh 
    114      1.17     heas 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
    115       1.9     matt 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK ||
    116       1.9     matt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK))
    117       1.1      eeh 		return (1);
    118       1.1      eeh 
    119      1.17     heas 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
    120       1.9     matt 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC ||
    121      1.10     matt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2 ||
    122  1.19.4.1     yamt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC3 ||
    123  1.19.4.4     yamt  	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC ||
    124  1.19.4.2     yamt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_K2_GMAC ||
    125  1.19.4.2     yamt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC))
    126       1.1      eeh 		return (1);
    127       1.1      eeh 
    128       1.1      eeh 
    129       1.1      eeh 	return (0);
    130       1.1      eeh }
    131       1.1      eeh 
    132  1.19.4.4     yamt #if GEM_USE_LOCAL_MAC_ADDRESS
    133  1.19.4.4     yamt static inline int
    134  1.19.4.4     yamt gempromvalid(u_int8_t* buf)
    135  1.19.4.4     yamt {
    136  1.19.4.4     yamt 	return buf[0] == 0x18 && buf[1] == 0x00 &&	/* structure length */
    137  1.19.4.4     yamt 	    buf[2] == 0x00 &&				/* revision */
    138  1.19.4.4     yamt 	    (buf[3] == 0x00 ||				/* hme */
    139  1.19.4.4     yamt 	     buf[3] == 0x80) &&				/* qfe */
    140  1.19.4.4     yamt 	    buf[4] == PCI_SUBCLASS_NETWORK_ETHERNET &&	/* subclass code */
    141  1.19.4.4     yamt 	    buf[5] == PCI_CLASS_NETWORK;		/* class code */
    142  1.19.4.4     yamt }
    143  1.19.4.4     yamt 
    144  1.19.4.4     yamt static inline int
    145  1.19.4.4     yamt isshared_pins(u_int8_t* buf)
    146  1.19.4.4     yamt {
    147  1.19.4.4     yamt 	return buf[0] == 's' && buf[1] == 'h' && buf[2] == 'a' &&
    148  1.19.4.4     yamt 	    buf[3] == 'r' && buf[4] == 'e' && buf[5] == 'd' &&
    149  1.19.4.4     yamt 	    buf[6] == '-' && buf[7] == 'p' && buf[8] == 'i' &&
    150  1.19.4.4     yamt 	    buf[9] == 'n' && buf[10] == 's';
    151  1.19.4.4     yamt }
    152  1.19.4.4     yamt #endif
    153  1.19.4.4     yamt 
    154  1.19.4.4     yamt static inline int
    155  1.19.4.4     yamt isserdes(u_int8_t* buf)
    156  1.19.4.4     yamt {
    157  1.19.4.4     yamt 	return buf[0] == 's' && buf[1] == 'e' && buf[2] == 'r' &&
    158  1.19.4.4     yamt 	    buf[3] == 'd' && buf[4] == 'e' && buf[5] == 's';
    159  1.19.4.4     yamt }
    160  1.19.4.4     yamt 
    161       1.1      eeh void
    162       1.1      eeh gem_attach_pci(parent, self, aux)
    163       1.1      eeh 	struct device *parent, *self;
    164       1.1      eeh 	void *aux;
    165       1.1      eeh {
    166       1.1      eeh 	struct pci_attach_args *pa = aux;
    167       1.1      eeh 	struct gem_pci_softc *gsc = (void *)self;
    168       1.1      eeh 	struct gem_softc *sc = &gsc->gsc_gem;
    169       1.6  thorpej 	pci_intr_handle_t ih;
    170       1.1      eeh 	const char *intrstr;
    171       1.2      eeh 	char devinfo[256];
    172       1.7  thorpej 	uint8_t enaddr[ETHER_ADDR_LEN];
    173  1.19.4.4     yamt #if GEM_USE_LOCAL_MAC_ADDRESS
    174  1.19.4.4     yamt 	u_int8_t		*enp;
    175  1.19.4.4     yamt 	bus_space_handle_t	romh;
    176  1.19.4.4     yamt 	u_int8_t		buf[0x0800];
    177  1.19.4.4     yamt 	int			dataoff, vpdoff, serdes;
    178  1.19.4.4     yamt #ifdef GEM_DEBUG
    179  1.19.4.4     yamt 	int i, j;
    180  1.19.4.4     yamt #endif
    181  1.19.4.4     yamt 	struct pci_vpd		*vpd;
    182  1.19.4.4     yamt 	static const u_int8_t promhdr[] = { 0x55, 0xaa };
    183  1.19.4.4     yamt #define PROMHDR_PTR_DATA	0x18
    184  1.19.4.4     yamt 	static const u_int8_t promdat[] = {
    185  1.19.4.4     yamt 		0x50, 0x43, 0x49, 0x52,		/* "PCIR" */
    186  1.19.4.4     yamt 		PCI_VENDOR_SUN & 0xff, PCI_VENDOR_SUN >> 8,
    187  1.19.4.4     yamt 		PCI_PRODUCT_SUN_GEMNETWORK & 0xff,
    188  1.19.4.4     yamt 		PCI_PRODUCT_SUN_GEMNETWORK >> 8
    189  1.19.4.4     yamt 	};
    190  1.19.4.4     yamt #define PROMDATA_PTR_VPD	0x08
    191  1.19.4.4     yamt #define PROMDATA_DATA2		0x0a
    192  1.19.4.4     yamt #endif  /* GEM_USE_LOCAL_MAC_ADDRESS */
    193       1.2      eeh 
    194      1.14  thorpej 	aprint_naive(": Ethernet controller\n");
    195      1.14  thorpej 
    196      1.16   itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    197      1.14  thorpej 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    198      1.14  thorpej 	    PCI_REVISION(pa->pa_class));
    199       1.1      eeh 
    200  1.19.4.4     yamt 	/*
    201  1.19.4.4     yamt 	 * Some Sun GEMs/ERIs do have their intpin register bogusly set to 0,
    202  1.19.4.4     yamt 	 * although it should be 1. correct that.
    203  1.19.4.4     yamt 	 */
    204  1.19.4.4     yamt 	if (pa->pa_intrpin == 0)
    205  1.19.4.4     yamt 		pa->pa_intrpin = 1;
    206  1.19.4.4     yamt 
    207  1.19.4.4     yamt 	sc->sc_variant = GEM_UNKNOWN;
    208  1.19.4.4     yamt 
    209       1.1      eeh 	sc->sc_dmatag = pa->pa_dmat;
    210       1.1      eeh 
    211  1.19.4.4     yamt 	sc->sc_flags |= GEM_PCI;
    212       1.9     matt 
    213  1.19.4.4     yamt 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN) {
    214  1.19.4.4     yamt 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK)
    215  1.19.4.4     yamt 			sc->sc_variant = GEM_SUN_GEM;
    216  1.19.4.4     yamt 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK)
    217  1.19.4.4     yamt 			sc->sc_variant = GEM_SUN_ERI;
    218  1.19.4.4     yamt 	} else if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE) {
    219  1.19.4.4     yamt 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC ||
    220  1.19.4.4     yamt 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2 ||
    221  1.19.4.4     yamt 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC3 ||
    222  1.19.4.4     yamt 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC ||
    223  1.19.4.4     yamt 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC)
    224  1.19.4.4     yamt 			sc->sc_variant = GEM_APPLE_GMAC;
    225  1.19.4.4     yamt 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_K2_GMAC)
    226  1.19.4.4     yamt 			sc->sc_variant = GEM_APPLE_K2_GMAC;
    227  1.19.4.4     yamt 	}
    228  1.19.4.4     yamt 
    229  1.19.4.4     yamt 	if (sc->sc_variant == GEM_UNKNOWN) {
    230  1.19.4.4     yamt 		aprint_error("%s: unknown adaptor\n", sc->sc_dev.dv_xname);
    231  1.19.4.4     yamt 		return;
    232  1.19.4.4     yamt 	}
    233       1.1      eeh 
    234       1.3  thorpej #define PCI_GEM_BASEADDR	(PCI_MAPREG_START + 0x00)
    235       1.3  thorpej 
    236       1.3  thorpej 	/* XXX Need to check for a 64-bit mem BAR? */
    237       1.3  thorpej 	if (pci_mapreg_map(pa, PCI_GEM_BASEADDR,
    238       1.3  thorpej 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    239  1.19.4.1     yamt 	    &sc->sc_bustag, &sc->sc_h1, NULL, NULL) != 0)
    240       1.1      eeh 	{
    241      1.14  thorpej 		aprint_error("%s: unable to map device registers\n",
    242       1.3  thorpej 		    sc->sc_dev.dv_xname);
    243       1.1      eeh 		return;
    244       1.1      eeh 	}
    245  1.19.4.1     yamt 	if (bus_space_subregion(sc->sc_bustag, sc->sc_h1,
    246  1.19.4.1     yamt 	    GEM_PCI_BANK2_OFFSET, GEM_PCI_BANK2_SIZE, &sc->sc_h2)) {
    247  1.19.4.1     yamt 		aprint_error("%s: unable to create bank 2 subregion\n",
    248  1.19.4.1     yamt 		    sc->sc_dev.dv_xname);
    249  1.19.4.1     yamt 		return;
    250  1.19.4.1     yamt 	}
    251       1.1      eeh 
    252  1.19.4.4     yamt #if GEM_USE_LOCAL_MAC_ADDRESS
    253       1.3  thorpej 	/*
    254  1.19.4.4     yamt 	 * Dig out VPD (vital product data) and acquire Ethernet address.
    255  1.19.4.4     yamt 	 * The VPD of gem resides in the PCI PROM (PCI FCode).
    256       1.3  thorpej 	 */
    257  1.19.4.4     yamt 	/*
    258  1.19.4.4     yamt 	 * ``Writing FCode 3.x Programs'' (newer ones, dated 1997 and later)
    259  1.19.4.4     yamt 	 * chapter 2 describes the data structure.
    260  1.19.4.4     yamt 	 */
    261  1.19.4.4     yamt 
    262  1.19.4.4     yamt 	enp = NULL;
    263  1.19.4.4     yamt 
    264  1.19.4.4     yamt 	if (sc->sc_variant == GEM_SUN_GEM &&
    265  1.19.4.4     yamt 	    (bus_space_subregion(sc->sc_bustag, sc->sc_h1,
    266  1.19.4.4     yamt 	    GEM_PCI_ROM_OFFSET, GEM_PCI_ROM_SIZE, &romh)) == 0) {
    267  1.19.4.4     yamt 
    268  1.19.4.4     yamt 		/* read PCI Expansion PROM Header */
    269  1.19.4.4     yamt 		bus_space_read_region_1(sc->sc_bustag,
    270  1.19.4.4     yamt 		    romh, 0, buf, sizeof buf);
    271  1.19.4.4     yamt 
    272  1.19.4.4     yamt 		/* Check for "shared-pins = serdes" in FCode. */
    273  1.19.4.4     yamt 		i = 0;
    274  1.19.4.4     yamt 		serdes = 0;
    275  1.19.4.4     yamt 		while (i < (sizeof buf) - sizeof "serdes") {
    276  1.19.4.4     yamt 			if (!serdes) {
    277  1.19.4.4     yamt 				if (isserdes(&buf[i]))
    278  1.19.4.4     yamt 					serdes = 1;
    279  1.19.4.4     yamt 			} else {
    280  1.19.4.4     yamt 				if (isshared_pins(&buf[i]))
    281  1.19.4.4     yamt 					serdes = 2;
    282  1.19.4.4     yamt 			}
    283  1.19.4.4     yamt 			if (serdes == 2) {
    284  1.19.4.4     yamt 				sc->sc_flags |= GEM_SERDES;
    285  1.19.4.4     yamt 				break;
    286  1.19.4.4     yamt 			}
    287  1.19.4.4     yamt 			i++;
    288  1.19.4.4     yamt 		}
    289  1.19.4.4     yamt #ifdef GEM_DEBUG
    290  1.19.4.4     yamt 		/* PROM dump */
    291  1.19.4.4     yamt 		printf("%s: PROM dump (0x0000 to %04lx)\n", sc->sc_dev.dv_xname,
    292  1.19.4.4     yamt 		    (sizeof buf) - 1);
    293  1.19.4.4     yamt 		i = 0;
    294  1.19.4.4     yamt 		j = 0;
    295  1.19.4.4     yamt 		printf("  %04x  ", i);
    296  1.19.4.4     yamt 		while (i < sizeof buf) {
    297  1.19.4.4     yamt 			printf("%02x ", buf[i]);
    298  1.19.4.4     yamt 			if (i && !(i % 8))
    299  1.19.4.4     yamt 				printf(" ");
    300  1.19.4.4     yamt 			if (i && !(i % 16)) {
    301  1.19.4.4     yamt 				printf(" ");
    302  1.19.4.4     yamt 				while (j < i) {
    303  1.19.4.4     yamt 					if (buf[j] > 31 && buf[j] < 128)
    304  1.19.4.4     yamt 						printf("%c", buf[j]);
    305  1.19.4.4     yamt 					else
    306  1.19.4.4     yamt 						printf(".");
    307  1.19.4.4     yamt 					j++;
    308  1.19.4.4     yamt 				}
    309  1.19.4.4     yamt 				j = i;
    310  1.19.4.4     yamt 				printf("\n  %04x  ", i);
    311  1.19.4.4     yamt 				}
    312  1.19.4.4     yamt 			i++;
    313  1.19.4.4     yamt 		}
    314  1.19.4.4     yamt 		printf("\n");
    315  1.19.4.4     yamt #endif
    316  1.19.4.4     yamt 
    317  1.19.4.4     yamt 		if (memcmp(buf, promhdr, sizeof promhdr) == 0 &&
    318  1.19.4.4     yamt 		    (dataoff = (buf[PROMHDR_PTR_DATA] |
    319  1.19.4.4     yamt 			(buf[PROMHDR_PTR_DATA + 1] << 8))) >= 0x1c) {
    320  1.19.4.4     yamt 
    321  1.19.4.4     yamt 			/* read PCI Expansion PROM Data */
    322  1.19.4.4     yamt 			bus_space_read_region_1(sc->sc_bustag, romh, dataoff,
    323  1.19.4.4     yamt 			    buf, 64);
    324  1.19.4.4     yamt 			if (memcmp(buf, promdat, sizeof promdat) == 0 &&
    325  1.19.4.4     yamt 			    gempromvalid(buf + PROMDATA_DATA2) &&
    326  1.19.4.4     yamt 			    (vpdoff = (buf[PROMDATA_PTR_VPD] |
    327  1.19.4.4     yamt 				(buf[PROMDATA_PTR_VPD + 1] << 8))) >= 0x1c) {
    328  1.19.4.4     yamt 
    329  1.19.4.4     yamt 				/*
    330  1.19.4.4     yamt 				 * The VPD of gem is not in PCI 2.2 standard
    331  1.19.4.4     yamt 				 * format.  The length in the resource header
    332  1.19.4.4     yamt 				 * is in big endian, and resources are not
    333  1.19.4.4     yamt 				 * properly terminated (only one resource
    334  1.19.4.4     yamt 				 * and no end tag).
    335  1.19.4.4     yamt 				 */
    336  1.19.4.4     yamt 				/* read PCI VPD */
    337  1.19.4.4     yamt 				bus_space_read_region_1(sc->sc_bustag, romh,
    338  1.19.4.4     yamt 				    vpdoff, buf, 64);
    339  1.19.4.4     yamt 				vpd = (void *)(buf + 3);
    340  1.19.4.4     yamt 				if (PCI_VPDRES_ISLARGE(buf[0]) &&
    341  1.19.4.4     yamt 				    PCI_VPDRES_LARGE_NAME(buf[0])
    342  1.19.4.4     yamt 					== PCI_VPDRES_TYPE_VPD &&
    343  1.19.4.4     yamt 				    vpd->vpd_key0 == 0x4e /* N */ &&
    344  1.19.4.4     yamt 				    vpd->vpd_key1 == 0x41 /* A */ &&
    345  1.19.4.4     yamt 				    vpd->vpd_len == ETHER_ADDR_LEN) {
    346  1.19.4.4     yamt 					/*
    347  1.19.4.4     yamt 					 * Ethernet address found
    348  1.19.4.4     yamt 					 */
    349  1.19.4.4     yamt 					enp = buf + 6;
    350  1.19.4.4     yamt 				}
    351  1.19.4.4     yamt 			}
    352  1.19.4.4     yamt 		}
    353  1.19.4.4     yamt 	}
    354  1.19.4.4     yamt 
    355  1.19.4.4     yamt 	if (enp)
    356  1.19.4.4     yamt 		memcpy(enaddr, enp, ETHER_ADDR_LEN);
    357  1.19.4.4     yamt 	else
    358  1.19.4.4     yamt #endif  /* GEM_USE_LOCAL_MAC_ADDRESS */
    359       1.1      eeh #ifdef __sparc__
    360       1.3  thorpej 	{
    361  1.19.4.4     yamt 		if (strcmp(prom_getpropstring(PCITAG_NODE(pa->pa_tag),
    362  1.19.4.4     yamt 		    "shared-pins"), "serdes") == 0)
    363  1.19.4.4     yamt 			sc->sc_flags |= GEM_SERDES;
    364      1.15   martin 		prom_getether(PCITAG_NODE(pa->pa_tag), enaddr);
    365       1.3  thorpej 	}
    366  1.19.4.4     yamt #else
    367       1.4  thorpej #ifdef macppc
    368       1.4  thorpej 	{
    369       1.4  thorpej 		int node;
    370  1.19.4.4     yamt 		char sp[6];	/* "serdes" */
    371       1.4  thorpej 
    372       1.4  thorpej 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    373       1.4  thorpej 		if (node == 0) {
    374      1.14  thorpej 			aprint_error("%s: unable to locate OpenFirmware node\n",
    375       1.4  thorpej 			    sc->sc_dev.dv_xname);
    376       1.4  thorpej 			return;
    377       1.4  thorpej 		}
    378       1.4  thorpej 
    379  1.19.4.4     yamt 		OF_getprop(node, "shared-pins", sp, sizeof(sp));
    380  1.19.4.4     yamt 		if (isserdes(sp))
    381  1.19.4.4     yamt 			sc->sc_flags |= GEM_SERDES;
    382       1.7  thorpej 		OF_getprop(node, "local-mac-address", enaddr, sizeof(enaddr));
    383       1.4  thorpej 	}
    384  1.19.4.4     yamt #else
    385  1.19.4.4     yamt 		printf("%s: no Ethernet address found\n", sc->sc_dev.dv_xname);
    386       1.4  thorpej #endif /* macppc */
    387  1.19.4.4     yamt #endif /* __sparc__ */
    388       1.1      eeh 
    389       1.6  thorpej 	if (pci_intr_map(pa, &ih) != 0) {
    390      1.14  thorpej 		aprint_error("%s: unable to map interrupt\n",
    391      1.14  thorpej 		    sc->sc_dev.dv_xname);
    392       1.6  thorpej 		return;
    393      1.19    perry 	}
    394       1.6  thorpej 	intrstr = pci_intr_string(pa->pa_pc, ih);
    395       1.6  thorpej 	gsc->gsc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, gem_intr, sc);
    396       1.6  thorpej 	if (gsc->gsc_ih == NULL) {
    397      1.14  thorpej 		aprint_error("%s: unable to establish interrupt",
    398       1.1      eeh 		    sc->sc_dev.dv_xname);
    399       1.1      eeh 		if (intrstr != NULL)
    400      1.14  thorpej 			aprint_normal(" at %s", intrstr);
    401      1.14  thorpej 		aprint_normal("\n");
    402       1.3  thorpej 		return;
    403       1.1      eeh 	}
    404      1.14  thorpej 	aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    405       1.6  thorpej 
    406       1.7  thorpej 	/* Finish off the attach. */
    407       1.7  thorpej 	gem_attach(sc, enaddr);
    408       1.1      eeh }
    409