Home | History | Annotate | Line # | Download | only in pci
if_gem_pci.c revision 1.29.4.5
      1  1.29.4.5     yamt /*	$NetBSD: if_gem_pci.c,v 1.29.4.5 2010/03/11 15:03:46 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.25      jdc  * 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.29.4.5     yamt __KERNEL_RCSID(0, "$NetBSD: if_gem_pci.c,v 1.29.4.5 2010/03/11 15:03:46 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.1      eeh #include <net/bpf.h>
     57       1.1      eeh 
     58      1.24       ad #include <sys/bus.h>
     59      1.24       ad #include <sys/intr.h>
     60       1.1      eeh 
     61       1.1      eeh #include <dev/mii/mii.h>
     62       1.1      eeh #include <dev/mii/miivar.h>
     63       1.1      eeh #include <dev/mii/mii_bitbang.h>
     64       1.1      eeh 
     65       1.1      eeh #include <dev/ic/gemreg.h>
     66       1.1      eeh #include <dev/ic/gemvar.h>
     67       1.1      eeh 
     68       1.1      eeh #include <dev/pci/pcivar.h>
     69       1.1      eeh #include <dev/pci/pcireg.h>
     70       1.1      eeh #include <dev/pci/pcidevs.h>
     71  1.29.4.5     yamt #include <prop/proplib.h>
     72      1.25      jdc 
     73       1.1      eeh struct gem_pci_softc {
     74       1.1      eeh 	struct	gem_softc	gsc_gem;	/* GEM device */
     75       1.1      eeh 	void			*gsc_ih;
     76  1.29.4.3     yamt 	pci_chipset_tag_t	gsc_pc;
     77  1.29.4.3     yamt 	pci_intr_handle_t	gsc_handle;
     78       1.1      eeh };
     79       1.1      eeh 
     80  1.29.4.3     yamt static bool	gem_pci_estintr(struct gem_pci_softc *);
     81  1.29.4.5     yamt static bool	gem_pci_suspend(device_t, const pmf_qual_t *);
     82  1.29.4.5     yamt static bool	gem_pci_resume(device_t, const pmf_qual_t *);
     83  1.29.4.3     yamt static int	gem_pci_detach(device_t, int);
     84  1.29.4.3     yamt 
     85  1.29.4.3     yamt int	gem_pci_match(device_t, cfdata_t, void *);
     86  1.29.4.3     yamt void	gem_pci_attach(device_t, device_t, void *);
     87  1.29.4.3     yamt 
     88  1.29.4.3     yamt CFATTACH_DECL3_NEW(gem_pci, sizeof(struct gem_pci_softc),
     89  1.29.4.3     yamt     gem_pci_match, gem_pci_attach, gem_pci_detach, NULL, NULL, NULL,
     90  1.29.4.3     yamt     DVF_DETACH_SHUTDOWN);
     91       1.1      eeh 
     92       1.1      eeh /*
     93       1.1      eeh  * Attach routines need to be split out to different bus-specific files.
     94       1.1      eeh  */
     95       1.1      eeh 
     96       1.1      eeh int
     97  1.29.4.3     yamt gem_pci_match(device_t parent, cfdata_t cf, void *aux)
     98       1.1      eeh {
     99       1.1      eeh 	struct pci_attach_args *pa = aux;
    100       1.1      eeh 
    101      1.17     heas 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
    102       1.9     matt 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK ||
    103       1.9     matt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK))
    104       1.1      eeh 		return (1);
    105       1.1      eeh 
    106      1.17     heas 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
    107       1.9     matt 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC ||
    108      1.10     matt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2 ||
    109      1.21  sanjayl 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC3 ||
    110      1.25      jdc  	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC ||
    111      1.23  aymeric 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_K2_GMAC ||
    112  1.29.4.1     yamt 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC ||
    113      1.23  aymeric 	     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC))
    114       1.1      eeh 		return (1);
    115       1.1      eeh 
    116       1.1      eeh 
    117       1.1      eeh 	return (0);
    118       1.1      eeh }
    119       1.1      eeh 
    120      1.25      jdc static inline int
    121      1.25      jdc gempromvalid(u_int8_t* buf)
    122      1.25      jdc {
    123      1.25      jdc 	return buf[0] == 0x18 && buf[1] == 0x00 &&	/* structure length */
    124      1.25      jdc 	    buf[2] == 0x00 &&				/* revision */
    125      1.25      jdc 	    (buf[3] == 0x00 ||				/* hme */
    126      1.25      jdc 	     buf[3] == 0x80) &&				/* qfe */
    127      1.25      jdc 	    buf[4] == PCI_SUBCLASS_NETWORK_ETHERNET &&	/* subclass code */
    128      1.25      jdc 	    buf[5] == PCI_CLASS_NETWORK;		/* class code */
    129      1.25      jdc }
    130      1.25      jdc 
    131      1.25      jdc static inline int
    132      1.25      jdc isshared_pins(u_int8_t* buf)
    133      1.25      jdc {
    134      1.25      jdc 	return buf[0] == 's' && buf[1] == 'h' && buf[2] == 'a' &&
    135      1.25      jdc 	    buf[3] == 'r' && buf[4] == 'e' && buf[5] == 'd' &&
    136      1.25      jdc 	    buf[6] == '-' && buf[7] == 'p' && buf[8] == 'i' &&
    137      1.25      jdc 	    buf[9] == 'n' && buf[10] == 's';
    138      1.25      jdc }
    139      1.25      jdc 
    140      1.25      jdc static inline int
    141      1.25      jdc isserdes(u_int8_t* buf)
    142      1.25      jdc {
    143      1.25      jdc 	return buf[0] == 's' && buf[1] == 'e' && buf[2] == 'r' &&
    144      1.25      jdc 	    buf[3] == 'd' && buf[4] == 'e' && buf[5] == 's';
    145      1.25      jdc }
    146      1.25      jdc 
    147       1.1      eeh void
    148  1.29.4.3     yamt gem_pci_attach(device_t parent, device_t self, void *aux)
    149       1.1      eeh {
    150       1.1      eeh 	struct pci_attach_args *pa = aux;
    151  1.29.4.2     yamt 	struct gem_pci_softc *gsc = device_private(self);
    152       1.1      eeh 	struct gem_softc *sc = &gsc->gsc_gem;
    153       1.2      eeh 	char devinfo[256];
    154  1.29.4.5     yamt 	prop_data_t data;
    155       1.7  thorpej 	uint8_t enaddr[ETHER_ADDR_LEN];
    156      1.25      jdc 	u_int8_t		*enp;
    157      1.25      jdc 	bus_space_handle_t	romh;
    158      1.25      jdc 	u_int8_t		buf[0x0800];
    159      1.25      jdc 	int			dataoff, vpdoff, serdes;
    160  1.29.4.5     yamt 	int i, got_addr = 0;
    161      1.25      jdc #ifdef GEM_DEBUG
    162      1.28   martin 	int j;
    163      1.25      jdc #endif
    164      1.25      jdc 	struct pci_vpd		*vpd;
    165      1.25      jdc 	static const u_int8_t promhdr[] = { 0x55, 0xaa };
    166      1.25      jdc #define PROMHDR_PTR_DATA	0x18
    167      1.25      jdc 	static const u_int8_t promdat[] = {
    168      1.25      jdc 		0x50, 0x43, 0x49, 0x52,		/* "PCIR" */
    169      1.25      jdc 		PCI_VENDOR_SUN & 0xff, PCI_VENDOR_SUN >> 8,
    170      1.25      jdc 		PCI_PRODUCT_SUN_GEMNETWORK & 0xff,
    171      1.25      jdc 		PCI_PRODUCT_SUN_GEMNETWORK >> 8
    172      1.25      jdc 	};
    173      1.25      jdc #define PROMDATA_PTR_VPD	0x08
    174      1.25      jdc #define PROMDATA_DATA2		0x0a
    175       1.2      eeh 
    176      1.14  thorpej 	aprint_naive(": Ethernet controller\n");
    177      1.14  thorpej 
    178  1.29.4.3     yamt 	sc->sc_dev = self;
    179      1.16   itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    180      1.27      jdc 	sc->sc_chiprev = PCI_REVISION(pa->pa_class);
    181      1.27      jdc 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo, sc->sc_chiprev);
    182       1.1      eeh 
    183      1.25      jdc 	/*
    184      1.25      jdc 	 * Some Sun GEMs/ERIs do have their intpin register bogusly set to 0,
    185      1.25      jdc 	 * although it should be 1. correct that.
    186      1.25      jdc 	 */
    187      1.25      jdc 	if (pa->pa_intrpin == 0)
    188      1.25      jdc 		pa->pa_intrpin = 1;
    189      1.25      jdc 
    190      1.25      jdc 	sc->sc_variant = GEM_UNKNOWN;
    191      1.25      jdc 
    192       1.1      eeh 	sc->sc_dmatag = pa->pa_dmat;
    193       1.1      eeh 
    194      1.25      jdc 	sc->sc_flags |= GEM_PCI;
    195      1.25      jdc 
    196      1.25      jdc 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN) {
    197      1.25      jdc 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK)
    198      1.25      jdc 			sc->sc_variant = GEM_SUN_GEM;
    199      1.25      jdc 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK)
    200      1.25      jdc 			sc->sc_variant = GEM_SUN_ERI;
    201      1.25      jdc 	} else if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE) {
    202      1.25      jdc 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC ||
    203      1.25      jdc 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2 ||
    204      1.25      jdc 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC3 ||
    205      1.26  aymeric 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC ||
    206      1.26  aymeric 		     PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC)
    207      1.25      jdc 			sc->sc_variant = GEM_APPLE_GMAC;
    208      1.25      jdc 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_K2_GMAC)
    209      1.25      jdc 			sc->sc_variant = GEM_APPLE_K2_GMAC;
    210      1.25      jdc 	}
    211       1.9     matt 
    212      1.25      jdc 	if (sc->sc_variant == GEM_UNKNOWN) {
    213  1.29.4.3     yamt 		aprint_error_dev(sc->sc_dev, "unknown adaptor\n");
    214      1.25      jdc 		return;
    215      1.25      jdc 	}
    216       1.1      eeh 
    217       1.3  thorpej #define PCI_GEM_BASEADDR	(PCI_MAPREG_START + 0x00)
    218       1.3  thorpej 
    219       1.3  thorpej 	/* XXX Need to check for a 64-bit mem BAR? */
    220       1.3  thorpej 	if (pci_mapreg_map(pa, PCI_GEM_BASEADDR,
    221       1.3  thorpej 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    222  1.29.4.3     yamt 	    &sc->sc_bustag, &sc->sc_h1, NULL, &sc->sc_size) != 0)
    223       1.1      eeh 	{
    224  1.29.4.3     yamt 		aprint_error_dev(sc->sc_dev, "unable to map device registers\n");
    225       1.1      eeh 		return;
    226       1.1      eeh 	}
    227      1.22   martin 	if (bus_space_subregion(sc->sc_bustag, sc->sc_h1,
    228      1.22   martin 	    GEM_PCI_BANK2_OFFSET, GEM_PCI_BANK2_SIZE, &sc->sc_h2)) {
    229  1.29.4.3     yamt 		aprint_error_dev(sc->sc_dev, "unable to create bank 2 subregion\n");
    230      1.22   martin 		return;
    231      1.22   martin 	}
    232       1.1      eeh 
    233  1.29.4.5     yamt 	if ((data = prop_dictionary_get(device_properties(sc->sc_dev),
    234  1.29.4.5     yamt 	    "mac-address")) != NULL) {
    235  1.29.4.5     yamt 		memcpy(enaddr, prop_data_data_nocopy(data), ETHER_ADDR_LEN);
    236  1.29.4.5     yamt 		got_addr = 1;
    237  1.29.4.5     yamt 		if ((data = prop_dictionary_get(device_properties(sc->sc_dev),
    238  1.29.4.5     yamt 	    	    "shared-pins")) != NULL) {
    239  1.29.4.5     yamt 			memcpy(buf, prop_data_data_nocopy(data),
    240  1.29.4.5     yamt 			    prop_data_size(data));
    241  1.29.4.5     yamt 			if (isserdes(buf)) {
    242      1.25      jdc 				sc->sc_flags |= GEM_SERDES;
    243      1.25      jdc 			}
    244      1.25      jdc 		}
    245  1.29.4.5     yamt 	} else {
    246  1.29.4.5     yamt 		/*
    247  1.29.4.5     yamt 		 * Dig out VPD (vital product data) and acquire Ethernet address.
    248  1.29.4.5     yamt 		 * The VPD of gem resides in the PCI PROM (PCI FCode).
    249  1.29.4.5     yamt 		 */
    250  1.29.4.5     yamt 		/*
    251  1.29.4.5     yamt 		 * ``Writing FCode 3.x Programs'' (newer ones, dated 1997 and later)
    252  1.29.4.5     yamt 		 * chapter 2 describes the data structure.
    253  1.29.4.5     yamt 		 */
    254  1.29.4.5     yamt 
    255  1.29.4.5     yamt 		enp = NULL;
    256  1.29.4.5     yamt 
    257  1.29.4.5     yamt 		if (sc->sc_variant == GEM_SUN_GEM &&
    258  1.29.4.5     yamt 		    (bus_space_subregion(sc->sc_bustag, sc->sc_h1,
    259  1.29.4.5     yamt 		    GEM_PCI_ROM_OFFSET, GEM_PCI_ROM_SIZE, &romh)) == 0) {
    260  1.29.4.5     yamt 
    261  1.29.4.5     yamt 			/* read PCI Expansion PROM Header */
    262  1.29.4.5     yamt 			bus_space_read_region_1(sc->sc_bustag,
    263  1.29.4.5     yamt 			    romh, 0, buf, sizeof buf);
    264  1.29.4.5     yamt 
    265  1.29.4.5     yamt 			/* Check for "shared-pins = serdes" in FCode. */
    266  1.29.4.5     yamt 			i = 0;
    267  1.29.4.5     yamt 			serdes = 0;
    268  1.29.4.5     yamt 			while (i < (sizeof buf) - sizeof "serdes") {
    269  1.29.4.5     yamt 				if (!serdes) {
    270  1.29.4.5     yamt 					if (isserdes(&buf[i]))
    271  1.29.4.5     yamt 						serdes = 1;
    272  1.29.4.5     yamt 				} else {
    273  1.29.4.5     yamt 					if (isshared_pins(&buf[i]))
    274  1.29.4.5     yamt 						serdes = 2;
    275      1.25      jdc 				}
    276  1.29.4.5     yamt 				if (serdes == 2) {
    277  1.29.4.5     yamt 					sc->sc_flags |= GEM_SERDES;
    278  1.29.4.5     yamt 					break;
    279      1.25      jdc 				}
    280  1.29.4.5     yamt 				i++;
    281  1.29.4.5     yamt 			}
    282  1.29.4.5     yamt #ifdef GEM_DEBUG
    283  1.29.4.5     yamt 			/* PROM dump */
    284  1.29.4.5     yamt 			printf("%s: PROM dump (0x0000 to %04lx)\n", device_xname(sc->sc_dev),
    285  1.29.4.5     yamt 			    (sizeof buf) - 1);
    286  1.29.4.5     yamt 			i = 0;
    287  1.29.4.5     yamt 			j = 0;
    288  1.29.4.5     yamt 			printf("  %04x  ", i);
    289  1.29.4.5     yamt 			while (i < sizeof buf) {
    290  1.29.4.5     yamt 				printf("%02x ", buf[i]);
    291  1.29.4.5     yamt 				if (i && !(i % 8))
    292  1.29.4.5     yamt 					printf(" ");
    293  1.29.4.5     yamt 				if (i && !(i % 16)) {
    294  1.29.4.5     yamt 					printf(" ");
    295  1.29.4.5     yamt 					while (j < i) {
    296  1.29.4.5     yamt 						if (buf[j] > 31 && buf[j] < 128)
    297  1.29.4.5     yamt 							printf("%c", buf[j]);
    298  1.29.4.5     yamt 						else
    299  1.29.4.5     yamt 							printf(".");
    300  1.29.4.5     yamt 						j++;
    301  1.29.4.5     yamt 					}
    302  1.29.4.5     yamt 					j = i;
    303  1.29.4.5     yamt 					printf("\n  %04x  ", i);
    304  1.29.4.5     yamt 				}
    305  1.29.4.5     yamt 				i++;
    306  1.29.4.5     yamt 			}
    307  1.29.4.5     yamt 			printf("\n");
    308      1.25      jdc #endif
    309      1.25      jdc 
    310  1.29.4.5     yamt 			if (memcmp(buf, promhdr, sizeof promhdr) == 0 &&
    311  1.29.4.5     yamt 			    (dataoff = (buf[PROMHDR_PTR_DATA] |
    312  1.29.4.5     yamt 				(buf[PROMHDR_PTR_DATA + 1] << 8))) >= 0x1c) {
    313  1.29.4.5     yamt 
    314  1.29.4.5     yamt 				/* read PCI Expansion PROM Data */
    315  1.29.4.5     yamt 				bus_space_read_region_1(sc->sc_bustag, romh, dataoff,
    316  1.29.4.5     yamt 				    buf, 64);
    317  1.29.4.5     yamt 				if (memcmp(buf, promdat, sizeof promdat) == 0 &&
    318  1.29.4.5     yamt 				    gempromvalid(buf + PROMDATA_DATA2) &&
    319  1.29.4.5     yamt 				    (vpdoff = (buf[PROMDATA_PTR_VPD] |
    320  1.29.4.5     yamt 					(buf[PROMDATA_PTR_VPD + 1] << 8))) >= 0x1c) {
    321      1.25      jdc 
    322      1.25      jdc 					/*
    323  1.29.4.5     yamt 					 * The VPD of gem is not in PCI 2.2 standard
    324  1.29.4.5     yamt 					 * format.  The length in the resource header
    325  1.29.4.5     yamt 					 * is in big endian, and resources are not
    326  1.29.4.5     yamt 					 * properly terminated (only one resource
    327  1.29.4.5     yamt 					 * and no end tag).
    328      1.25      jdc 					 */
    329  1.29.4.5     yamt 					/* read PCI VPD */
    330  1.29.4.5     yamt 					bus_space_read_region_1(sc->sc_bustag, romh,
    331  1.29.4.5     yamt 					    vpdoff, buf, 64);
    332  1.29.4.5     yamt 					vpd = (void *)(buf + 3);
    333  1.29.4.5     yamt 					if (PCI_VPDRES_ISLARGE(buf[0]) &&
    334  1.29.4.5     yamt 					    PCI_VPDRES_LARGE_NAME(buf[0])
    335  1.29.4.5     yamt 						== PCI_VPDRES_TYPE_VPD &&
    336  1.29.4.5     yamt 					    vpd->vpd_key0 == 0x4e /* N */ &&
    337  1.29.4.5     yamt 					    vpd->vpd_key1 == 0x41 /* A */ &&
    338  1.29.4.5     yamt 					    vpd->vpd_len == ETHER_ADDR_LEN) {
    339  1.29.4.5     yamt 						/*
    340  1.29.4.5     yamt 						 * Ethernet address found
    341  1.29.4.5     yamt 						 */
    342  1.29.4.5     yamt 						enp = buf + 6;
    343  1.29.4.5     yamt 					}
    344      1.25      jdc 				}
    345      1.25      jdc 			}
    346      1.25      jdc 		}
    347      1.25      jdc 
    348  1.29.4.5     yamt 		if (enp) {
    349  1.29.4.5     yamt 			memcpy(enaddr, enp, ETHER_ADDR_LEN);
    350  1.29.4.5     yamt 			got_addr = 1;
    351       1.4  thorpej 		}
    352       1.4  thorpej 	}
    353  1.29.4.5     yamt 	if (!got_addr) {
    354  1.29.4.3     yamt 		printf("%s: no Ethernet address found\n", device_xname(sc->sc_dev));
    355  1.29.4.5     yamt 		/* should we bail here? */
    356  1.29.4.5     yamt 	}
    357       1.1      eeh 
    358  1.29.4.3     yamt 	if (pci_intr_map(pa, &gsc->gsc_handle) != 0) {
    359  1.29.4.3     yamt 		aprint_error_dev(sc->sc_dev, "unable to map interrupt\n");
    360       1.6  thorpej 		return;
    361      1.19    perry 	}
    362  1.29.4.3     yamt 	gsc->gsc_pc = pa->pa_pc;
    363  1.29.4.3     yamt 	gem_pci_estintr(gsc);
    364  1.29.4.3     yamt 
    365  1.29.4.3     yamt 	/* Finish off the attach. */
    366  1.29.4.3     yamt 	gem_attach(sc, enaddr);
    367  1.29.4.3     yamt 
    368  1.29.4.4     yamt 	if (pmf_device_register1(sc->sc_dev,
    369  1.29.4.4     yamt 	    gem_pci_suspend, gem_pci_resume, gem_shutdown))
    370  1.29.4.4     yamt 		pmf_class_network_register(sc->sc_dev, &sc->sc_ethercom.ec_if);
    371  1.29.4.4     yamt 	else
    372  1.29.4.3     yamt 		aprint_error_dev(sc->sc_dev,
    373  1.29.4.3     yamt 		    "could not establish power handlers\n");
    374  1.29.4.3     yamt }
    375  1.29.4.3     yamt 
    376  1.29.4.3     yamt static bool
    377  1.29.4.5     yamt gem_pci_suspend(device_t self, const pmf_qual_t *qual)
    378  1.29.4.3     yamt {
    379  1.29.4.3     yamt 	struct gem_pci_softc *gsc = device_private(self);
    380  1.29.4.3     yamt 
    381  1.29.4.3     yamt 	if (gsc->gsc_ih != NULL) {
    382  1.29.4.3     yamt 		pci_intr_disestablish(gsc->gsc_pc, gsc->gsc_ih);
    383  1.29.4.3     yamt 		gsc->gsc_ih = NULL;
    384  1.29.4.3     yamt 	}
    385  1.29.4.3     yamt 
    386  1.29.4.3     yamt 	return true;
    387  1.29.4.3     yamt }
    388  1.29.4.3     yamt 
    389  1.29.4.3     yamt static bool
    390  1.29.4.3     yamt gem_pci_estintr(struct gem_pci_softc *gsc)
    391  1.29.4.3     yamt {
    392  1.29.4.3     yamt 	struct gem_softc *sc = &gsc->gsc_gem;
    393  1.29.4.3     yamt 	const char *intrstr;
    394  1.29.4.3     yamt 
    395  1.29.4.3     yamt 	intrstr = pci_intr_string(gsc->gsc_pc, gsc->gsc_handle);
    396  1.29.4.3     yamt 	gsc->gsc_ih = pci_intr_establish(gsc->gsc_pc, gsc->gsc_handle, IPL_NET,
    397  1.29.4.3     yamt 	    gem_intr, sc);
    398       1.6  thorpej 	if (gsc->gsc_ih == NULL) {
    399  1.29.4.3     yamt 		aprint_error_dev(sc->sc_dev, "unable to establish interrupt");
    400       1.1      eeh 		if (intrstr != NULL)
    401  1.29.4.5     yamt 			aprint_error(" at %s", intrstr);
    402  1.29.4.5     yamt 		aprint_error("\n");
    403  1.29.4.3     yamt 		return false;
    404       1.1      eeh 	}
    405  1.29.4.3     yamt 	aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
    406  1.29.4.3     yamt 	return true;
    407  1.29.4.3     yamt }
    408       1.6  thorpej 
    409  1.29.4.3     yamt static bool
    410  1.29.4.5     yamt gem_pci_resume(device_t self, const pmf_qual_t *qual)
    411  1.29.4.3     yamt {
    412  1.29.4.3     yamt 	struct gem_pci_softc *gsc = device_private(self);
    413  1.29.4.3     yamt 
    414  1.29.4.3     yamt 	return gem_pci_estintr(gsc);
    415  1.29.4.3     yamt }
    416  1.29.4.3     yamt 
    417  1.29.4.3     yamt static int
    418  1.29.4.3     yamt gem_pci_detach(device_t self, int flags)
    419  1.29.4.3     yamt {
    420  1.29.4.3     yamt 	int rc;
    421  1.29.4.3     yamt 	struct gem_pci_softc *gsc = device_private(self);
    422  1.29.4.3     yamt 	struct gem_softc *sc = &gsc->gsc_gem;
    423  1.29.4.3     yamt 
    424  1.29.4.3     yamt 	switch (sc->sc_att_stage) {
    425  1.29.4.3     yamt 	case GEM_ATT_BACKEND_2:
    426  1.29.4.3     yamt 		pmf_device_deregister(self);
    427  1.29.4.3     yamt 		sc->sc_att_stage = GEM_ATT_FINISHED;
    428  1.29.4.3     yamt 		/*FALLTHROUGH*/
    429  1.29.4.3     yamt 	default:
    430  1.29.4.3     yamt 		if ((rc = gem_detach(sc, flags)) != 0)
    431  1.29.4.3     yamt 			return rc;
    432  1.29.4.3     yamt 		/*FALLTHROUGH*/
    433  1.29.4.3     yamt 	case GEM_ATT_BACKEND_1:
    434  1.29.4.3     yamt 		if (gsc->gsc_ih != NULL)
    435  1.29.4.3     yamt 			pci_intr_disestablish(gsc->gsc_pc, gsc->gsc_ih);
    436  1.29.4.3     yamt 
    437  1.29.4.3     yamt 		bus_space_unmap(sc->sc_bustag, sc->sc_h1, sc->sc_size);
    438  1.29.4.3     yamt 		/*FALLTHROUGH*/
    439  1.29.4.3     yamt 	case GEM_ATT_BACKEND_0:
    440  1.29.4.3     yamt 		sc->sc_att_stage = GEM_ATT_BACKEND_0;
    441  1.29.4.3     yamt 		break;
    442  1.29.4.3     yamt 	}
    443  1.29.4.3     yamt 	return 0;
    444       1.1      eeh }
    445